123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129 |
- using FastReport.Utils;
- using System.Windows;
- using System.Windows.Forms;
- namespace FastReport.Design.RibbonDesigner
- {
- internal static class RibbonExtensions
- {
- public static double Measure(this Control c)
- {
- c.control.Measure(new Size(double.PositiveInfinity, double.PositiveInfinity));
- return c.control.DesiredSize.Width;
- }
- public static void AddItems(this Control ctl, params IToolbarItem[] items)
- {
- // convert item.BeginGroup to a separator
- foreach (var item in items)
- {
- if (item.BeginGroup && ctl.Controls.Count > 0)
- ctl.Controls.Add(new ToolStripSeparator(true));
- ctl.Controls.Add(item as ToolStripItem);
- }
- }
- public static void AddPanels(this Control ctl, params PanelBase[] panels)
- {
- foreach (var panel in panels)
- ctl.Controls.Add(panel);
- }
- public static void UpdateDpiDependencies(this Control ctl)
- {
- ctl.SuspendLayout();
- foreach (var c in ctl.Controls)
- {
- if (c is ToolStripItem item)
- {
- if (item.ImageIndex != -1)
- item.Image = ctl.GetImage(item.ImageIndex);
- }
- }
- ctl.ResumeLayout();
- }
- public static void UpdateUIStyle(this Control ctl, UIStyle style)
- {
- var renderer = UIStyleUtils.GetToolStripRenderer(style);
- if (ctl is ToolStripItem item)
- item.ApplyStyle(renderer);
- foreach (Control c in ctl.Controls)
- {
- c.UpdateUIStyle(style);
- }
- }
- public static void MakeBig(this ToolStripButton btn, int maxWidth = 80)
- {
- btn.ImageSize = new System.Drawing.Size(32, 32);
- btn.Vertical = true;
- btn.DisplayStyle = ToolStripItemDisplayStyle.ImageAndText;
- btn.control.VerticalAlignment = VerticalAlignment.Stretch;
- btn.control.VerticalContentAlignment = VerticalAlignment.Stretch;
- btn.control.MaxWidth = maxWidth;
- }
- public static void MakeBig(this ToolStripDropDownButtonBase btn, int maxWidth = 80)
- {
- btn.ImageSize = new System.Drawing.Size(32, 32);
- btn.Vertical = true;
- btn.DisplayStyle = ToolStripItemDisplayStyle.ImageAndText;
- btn.control.VerticalAlignment = VerticalAlignment.Stretch;
- btn.control.VerticalContentAlignment = VerticalAlignment.Stretch;
- btn.control.MaxWidth = maxWidth;
- }
- public static void CollapseTo(this PanelBase panel, ToolbarLayoutDropDownButton button, bool isGroup = true)
- {
- var parent = panel.Parent;
- if (parent == null)
- return;
- int index = parent.Controls.IndexOf(panel);
- if (index != -1)
- {
- parent.Controls.Remove(panel);
- parent.Controls.Add(button);
- parent.Controls.SetChildIndex(button, index);
- button.DropDown.Items.Clear();
- button.DropDown.Items.Add(new ToolStripControlHost(panel));
- panel.control.Margin = new Thickness(10);
- button.control.HorizontalAlignment = System.Windows.HorizontalAlignment.Stretch;
- if (isGroup && parent is RibbonGroup group)
- {
- button.control.Margin = new Thickness(0, 3, 0, 16);
- button.Text = group.Caption.Text;
- group.Caption.Visible = false;
- }
- }
- }
- public static void ExpandTo(this ToolbarLayoutDropDownButton button, PanelBase panel, bool isGroup = true)
- {
- var parent = button.Parent;
- if (parent == null)
- return;
- int index = parent.Controls.IndexOf(button);
- if (index != -1)
- {
- button.DropDown.Items.Clear();
- parent.Controls.Remove(button);
- parent.Controls.Add(panel);
- parent.Controls.SetChildIndex(panel, index);
- panel.control.Margin = new Thickness(0);
- if (isGroup && parent is RibbonGroup group)
- {
- panel.VerticalAlignment = VerticalAlignment.Center;
- panel.control.Margin = new Thickness(0, 3, 0, 16);
- group.Caption.Visible = true;
- }
- }
- }
- }
- }
|