123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206 |
- using FastReport.Forms;
- using FastReport.Utils;
- using System.Collections;
- using System.Windows;
- using System.Windows.Forms;
- namespace FastReport.Design.RibbonDesigner
- {
- internal enum GroupState
- {
- Normal,
- Reduced,
- Collapsed
- }
- internal enum GroupPriority
- {
- Low,
- Medium,
- High
- }
- internal class RibbonGroup : GridPanel, IDesignerPlugin
- {
- private Hashtable cachedWidths = new Hashtable();
- public Designer Designer { get; }
- public StackedPanel Panel { get; }
- public Label Caption { get; }
- private GroupState state;
- public GroupState State
- {
- get => state;
- set
- {
- state = value;
- UpdateState();
- control.UpdateLayout();
- }
- }
- public double GroupWidth
- {
- get
- {
- if (!cachedWidths.ContainsKey(state))
- cachedWidths[state] = this.Measure();
- return (double)cachedWidths[state];
- }
- }
- public ToolbarLayoutDropDownButton CollapsedButton { get; }
- public string CollapsedImageName { get; set; }
- public GroupPriority Priority { get; set; }
- private ControlStorageService storage;
- /// <summary>
- /// Gets storage service.
- /// </summary>
- public ControlStorageService Storage
- {
- get
- {
- if (storage == null)
- storage = new ControlStorageService(this, "Designer," + Name);
- return storage;
- }
- }
- public override string Text
- {
- get => base.Text;
- set
- {
- base.Text = value;
- Caption.Text = value;
- CollapsedButton.Text = value;
- }
- }
- public override bool Visible
- {
- get => base.Visible;
- set
- {
- if (value != Visible)
- {
- base.Visible = value;
- control.Visibility = value ? Visibility.Visible : Visibility.Collapsed;
- cachedWidths.Clear();
- control.UpdateLayout();
- (Parent as Ribbon).UpdateLayout();
- }
- }
- }
- #region IDesignerPlugin
- public string PluginName => Name;
- /// <inheritdoc/>
- public virtual void SaveState()
- {
- }
- /// <inheritdoc/>
- public virtual void RestoreState()
- {
- }
- /// <inheritdoc/>
- public virtual void SelectionChanged()
- {
- }
- /// <inheritdoc/>
- public virtual void UpdateContent()
- {
- }
- /// <inheritdoc/>
- public void Lock()
- {
- }
- /// <inheritdoc/>
- public void Unlock()
- {
- UpdateContent();
- }
- /// <inheritdoc/>
- public virtual void Localize()
- {
- cachedWidths.Clear();
- }
- /// <inheritdoc/>
- public virtual DesignerOptionsPage GetOptionsPage()
- {
- return null;
- }
- /// <inheritdoc/>
- public virtual void UpdateUIStyle()
- {
- Panel.UpdateUIStyle(Designer.UIStyle);
- CollapsedButton.UpdateUIStyle(Designer.UIStyle);
- }
- /// <inheritdoc/>
- public virtual void UpdateDpiDependencies()
- {
- RibbonExtensions.UpdateDpiDependencies(this);
- Panel.UpdateDpiDependencies();
- if (!string.IsNullOrEmpty(CollapsedImageName))
- CollapsedButton.Image = Designer.GetImage(CollapsedImageName);
- }
- #endregion
- public virtual void UpdateState()
- {
- if (State == GroupState.Collapsed)
- {
- Panel.CollapseTo(CollapsedButton);
- }
- else
- {
- CollapsedButton.ExpandTo(Panel);
- }
- }
- public void SetItemText(ToolStripItem item, string text)
- {
- if (text.EndsWith("..."))
- text = text.Substring(0, text.Length - 3);
- item.ToolTipText = text;
- item.Text = text;
- }
- public RibbonGroup(Designer designer)
- {
- Designer = designer;
- state = GroupState.Normal;
- control.Margin = new Thickness(4, 1, 4, 1);
- Caption = new RibbonGroupCaption();
- this.Controls.Add(Caption);
- Panel = new StackedPanel() { Vertical = false };
- Panel.control.Margin = new Thickness(0, 3, 0, 16);
- this.Controls.Add(Panel);
- CollapsedButton = new ToolbarLayoutDropDownButton();
- CollapsedButton.MakeBig();
- CollapsedButton.DropDownOpening += (s, e) => UpdateDpiDependencies();
- }
- }
- }
|