public virtual int GetWidth(Graphics g, RibbonThemaSettingsBase settings, RibbonItemSize size)
        {
            switch (size)
            {
            case RibbonItemSize.Big:
            {
                return(this.ControlItems.Select(i => i.GetWidth(g, settings, size)).Sum() + Math.Max(0, this.ControlItems.Count - 1) * RibbonGroup.GroupPadding);
            }

            case RibbonItemSize.Small:
            case RibbonItemSize.Compact:
            {
                int width       = 0;
                int totalGroups = this.ControlItems.Count / 3 + (this.ControlItems.Count % 3 == 0 ? 0 : 1);
                for (int i = 0; i < totalGroups; i++)
                {
                    int start = i * 3;
                    int end   = Math.Min(i * 3 + 2, this.ControlItems.Count - 1);
                    width += Enumerable.Range(start, end - start + 1).Select(j => this.ControlItems[j].GetWidth(g, settings, size)).Max();
                }
                return(width + Math.Max(0, totalGroups - 1) * RibbonGroup.GroupPadding);
            }

            default:
                throw new NotSupportedException();
            }
        }
Beispiel #2
0
        /// <summary>
        /// Получить SplitButton (основная команда + все вложенные команды) для дескриптора функции
        /// </summary>
        /// <param name="descriptor">Дескриптор функции - класс, реализующий интерфейс <see cref="IIntellectualEntityDescriptor"/></param>
        /// <param name="orientation">Ориентация кнопки</param>
        /// <param name="size">Размер кнопки</param>
        private static RibbonSplitButton GetSplitButton(
            IIntellectualEntityDescriptor descriptor,
            Orientation orientation = Orientation.Vertical,
            RibbonItemSize size     = RibbonItemSize.Large)
        {
            // Создаем SplitButton
            var risSplitBtn = new RibbonSplitButton
            {
                Text            = "RibbonSplitButton",
                Orientation     = orientation,
                Size            = size,
                ShowImage       = true,
                ShowText        = true,
                ListButtonStyle = Autodesk.Private.Windows.RibbonListButtonStyle.SplitButton,
                ResizeStyle     = RibbonItemResizeStyles.NoResize,
                ListStyle       = RibbonSplitButtonListStyle.List
            };

            // Добавляем в него первую функцию, которую делаем основной
            var ribBtn = GetBigButton(descriptor, orientation);

            if (ribBtn != null)
            {
                risSplitBtn.Items.Add(ribBtn);
                risSplitBtn.Current = ribBtn;
            }

            // Вложенные команды
            GetBigButtonsForSubFunctions(descriptor, orientation).ForEach(b => risSplitBtn.Items.Add(b));

            return(risSplitBtn);
        }
Beispiel #3
0
        /// <summary> 在选项面板中添加一个按钮 </summary>
        /// <param name="commandName">按钮所对应的命令名,命令后不能加空格</param>
        /// <param name="buttonText">按钮的名称</param>
        /// <param name="description">按钮的功能描述</param>
        /// <param name="size">图片显示为大图像还是小图像 </param>
        /// <param name="largeImage"> 按钮所对应的图像,其像素大小为 32*32 </param>
        /// <param name="smallImage">按钮所对应的图像,其像素大小为 16*16 </param>
        private static RibbonButton CreateButton(string commandName, string buttonText,
                                                 string description  = null,
                                                 RibbonItemSize size = RibbonItemSize.Large, BitmapImage largeImage = null, BitmapImage smallImage = null)
        {
            //create button1
            var ribButton = new RibbonButton
            {
                Text        = buttonText,
                Description = description,
                ShowText    = true,
                Orientation = Orientation.Vertical, // 竖向则文字显示在图片正文,水平则文字显示在图片右边
                //
                Image      = smallImage,
                LargeImage = largeImage,
                Size       = size, // 按钮图片是显示为大图标还是正常小图标。
                ShowImage  = true,
                //
                AllowInStatusBar = true,
                AllowInToolBar   = true,

                // HelpTopic = "帮助",
                // HelpSource = new Uri("www.baidu.com"),

                //pay attention to the SPACE(or line feed) after the command name
                CommandParameter = commandName + "\n", // "Circle ",
                CommandHandler   = new AdskCommandHandler()
            };

            //
            return(ribButton);
        }
Beispiel #4
0
        /// <summary>
        /// Helper for creating a UI button
        /// </summary>
        /// <param name="buttonText">Text to display</param>
        /// <param name="icon">Icon to display</param>
        /// <param name="size">Small or Large</param>
        /// <param name="command">Command string to be called on button press</param>
        /// <returns></returns>
        public static RibbonButton CreateButton(string buttonText, Bitmap icon, RibbonItemSize size, string command, Func <bool> canExecute)
        {
            RibbonButton newButton = new RibbonButton();

            newButton.ShowText         = true;
            newButton.ShowImage        = true;
            newButton.Text             = buttonText;
            newButton.Name             = buttonText;
            newButton.Size             = size;
            newButton.CommandHandler   = new RibbonCommandHandler(canExecute);
            newButton.CommandParameter = "._" + command + " ";

            switch (size)
            {
            case RibbonItemSize.Standard:
                newButton.Orientation = Orientation.Horizontal;
                newButton.Image       = LoadImage(icon);
                break;

            case RibbonItemSize.Large:
                newButton.Orientation = Orientation.Vertical;
                newButton.LargeImage  = LoadImage(icon);
                break;

            default:
                throw new ArgumentOutOfRangeException(nameof(size), size, null);
            }

            return(newButton);
        }
Beispiel #5
0
        public override int GetHeight(Graphics g, RibbonThemaSettingsBase settings, RibbonItemSize itemSize)
        {
            switch (itemSize)
            {
            case RibbonItemSize.Big:
            case RibbonItemSize.Small:
            case RibbonItemSize.Compact:
            case RibbonItemSize.ToolStrip:
                return(0);

            default: throw new NotSupportedException();
            }
        }
        public bool CanCompactTo(RibbonItemSize oldSize, RibbonItemSize newSize)
        {
            if (IsSizeEnabled(oldSize) && IsSizeEnabled(newSize))
            {
                switch (oldSize)
                {
                case RibbonItemSize.Big: return(newSize != RibbonItemSize.Big);

                case RibbonItemSize.Small: return(newSize == RibbonItemSize.Compact);
                }
            }
            return(false);
        }
Beispiel #7
0
        private static void AddButton(RibbonPanel panel, MethodInfo method, RibbonItemSize size)
        {
            string      commandName;
            string      buttonText;
            string      description;
            BitmapImage largeImage;
            BitmapImage smallImage;

            GetMethodElements(method, out commandName, out buttonText, out description, out largeImage, out smallImage);
            //
            var ribButton = CreateButton(commandName, buttonText, description, size, largeImage);

            panel.Source.Items.Add(ribButton);
        }
        public int GetUpdatedWidth(RibbonItemSize size)
        {
            switch (size)
            {
            case RibbonItemSize.Big: return(this.UpdatedBigSize);

            case RibbonItemSize.Small: return(this.UpdatedSmallSize);

            case RibbonItemSize.Compact: return(this.UpdatedCompactSize);

            default:
                throw new NotSupportedException();
            }
        }
Beispiel #9
0
 public RibbonButtonEX(string name, RibbonItemSize size, Orientation orient, string cmd)
     : base()
 {
     this.Name             = name; //按钮的名称
     this.Text             = name;
     this.ShowText         = true; //显示文字
     this.MouseEntered    += this_MouseEntered;
     this.MouseLeft       += this_MouseLeft;
     this.Size             = size;                       //按钮尺寸
     this.Orientation      = orient;                     //按钮排列方式
     this.CommandHandler   = new RibbonCommandHandler(); //给按钮关联命令
     this.CommandParameter = cmd + " ";
     this.ShowImage        = true;                       //显示图片
 }
Beispiel #10
0
        public static RibbonButton CreateButton(string buttonText, Bitmap icon, RibbonItemSize size, string command)
        {
            RibbonButton newButton = new RibbonButton();

            newButton.ShowText         = true;
            newButton.ShowImage        = true;
            newButton.Text             = buttonText;
            newButton.Name             = buttonText;
            newButton.Image            = Core.Utilities.LoadImage(icon);
            newButton.Size             = size;
            newButton.CommandHandler   = new RibbonCommandHandler();
            newButton.CommandParameter = "._" + command + " ";

            return(newButton);
        }
Beispiel #11
0
        public override int GetWidth(Graphics g, RibbonThemaSettingsBase settings, RibbonItemSize itemSize)
        {
            switch (itemSize)
            {
            case RibbonItemSize.Big: return(GetBigWidth(g, settings));

            case RibbonItemSize.Small: return(GetSmallWidth(g, settings));

            case RibbonItemSize.Compact: return(GetCompactWidth(g, settings));

            case RibbonItemSize.ToolStrip: return(GetToolStripWidth(g, settings));

            default: throw new NotSupportedException();
            }
        }
        public virtual bool IsSizeEnabled(RibbonItemSize size)
        {
            switch (size)
            {
            case RibbonItemSize.Big:
                switch (this.Policy)
                {
                case RibbonControlSizingPolicy.Big: return(true);

                case RibbonControlSizingPolicy.BigSmall: return(true);

                case RibbonControlSizingPolicy.BigCompact: return(true);

                default: return(false);
                }

            case RibbonItemSize.Small:
                switch (this.Policy)
                {
                case RibbonControlSizingPolicy.BigSmall: return(true);

                case RibbonControlSizingPolicy.BigCompact: return(true);

                case RibbonControlSizingPolicy.Small: return(true);

                case RibbonControlSizingPolicy.SmallCompact: return(true);

                default: return(false);
                }

            case RibbonItemSize.Compact:
                switch (this.Policy)
                {
                case RibbonControlSizingPolicy.BigCompact: return(true);

                case RibbonControlSizingPolicy.SmallCompact: return(true);

                case RibbonControlSizingPolicy.Compact: return(true);

                default: return(false);
                }

            default: return(false);
            }
        }
Beispiel #13
0
        public static RibbonToggleButton CreateWindowToggle(string buttonText, Bitmap icon, RibbonItemSize size, Dictionary <string, UIElement> views, string windowId)
        {
            RibbonToggleButton result = new RibbonToggleButton
            {
                ShowText  = true,
                ShowImage = true,
                Text      = buttonText,
                Name      = buttonText,
                Size      = size,
            };

            switch (size)
            {
            case RibbonItemSize.Large:
                result.LargeImage  = LoadImage(new Bitmap(icon, new System.Drawing.Size(32, 32)));
                result.Orientation = Orientation.Vertical;
                break;

            case RibbonItemSize.Standard:
                result.Image       = LoadImage(new Bitmap(icon, new System.Drawing.Size(16, 16)));
                result.Orientation = Orientation.Horizontal;
                break;

            default:
                throw new ArgumentOutOfRangeException(nameof(size), size, null);
            }

            //TODO: Confirm this wont get accidentally garbage collected
            PaletteSet paletteSet = new PaletteSet("JPP", new Guid(windowId))
            {
                Size  = new System.Drawing.Size(600, 800),
                Style = (PaletteSetStyles)((int)PaletteSetStyles.ShowAutoHideButton +
                                           (int)PaletteSetStyles.ShowCloseButton),
                DockEnabled = (DockSides)((int)DockSides.Left + (int)DockSides.Right)
            };

            foreach (var view in views)
            {
                var viewHost = BuildElementHost(view.Value);
                paletteSet.Add(view.Key, viewHost);
            }


            paletteSet.KeepFocus = false;

            bool pendingChange = false;
            bool ignoreChange  = false;

            result.CheckStateChanged += (sender, args) =>
            {
                if (!ignoreChange)
                {
                    pendingChange      = true;
                    paletteSet.Visible = result.CheckState == true;

                    foreach (var view in views)
                    {
                        if (!(view.Value is HostedUserControl hostedView))
                        {
                            continue;
                        }

                        if (paletteSet.Visible)
                        {
                            hostedView.Show();
                        }
                        else
                        {
                            hostedView.Hide();
                        }
                    }
                    pendingChange = false;
                }
            };

            paletteSet.StateChanged += (sender, args) =>
            {
                if (!pendingChange)
                {
                    ignoreChange      = true;
                    result.CheckState = !paletteSet.Visible;
                    ignoreChange      = false;
                }
            };

            return(result);
        }
Beispiel #14
0
 /// <summary>
 /// Helper for creating a UI button
 /// </summary>
 /// <param name="buttonText">Text to display</param>
 /// <param name="icon">Icon to display</param>
 /// <param name="size">Small or Large</param>
 /// <param name="command">Command string to be called on button press</param>
 /// <returns></returns>
 public static RibbonButton CreateButton(string buttonText, Bitmap icon, RibbonItemSize size, string command)
 {
     return(CreateButton(buttonText, icon, size, command, () => true));
 }
 public override int GetHeight(System.Drawing.Graphics g, RibbonThemaSettingsBase settings, RibbonItemSize itemSize)
 {
     if (itemSize != RibbonItemSize.MenuItem)
     {
         throw new NotSupportedException();
     }
     return(3);
 }
Beispiel #16
0
        /// <summary>
        /// 给面板添加下拉组合按钮
        /// </summary>
        /// <param name="panelSource"></param>
        /// <param name="text"></param>
        /// <param name="size"></param>
        /// <param name="orient"></param>
        /// <returns></returns>
        public static RibbonSplitButton AddSplitButton(this RibbonPanelSource panelSource, string text, RibbonItemSize size, Orientation orient)
        {
            RibbonSplitButton splitBtn = new RibbonSplitButton();

            splitBtn.Text        = text;
            splitBtn.ShowText    = true;
            splitBtn.Size        = size;
            splitBtn.ShowImage   = true;
            splitBtn.Orientation = orient;
            panelSource.Items.Add(splitBtn);
            return(splitBtn);
        }
Beispiel #17
0
 public abstract int GetHeight(Graphics g, RibbonThemaSettingsBase settings, RibbonItemSize itemSize);
Beispiel #18
0
        public override int GetWidth(System.Drawing.Graphics g, RibbonThemaSettingsBase settings, RibbonItemSize itemSize)
        {
            if (itemSize != RibbonItemSize.MenuItem)
            {
                throw new NotSupportedException();
            }
            SizeF size = g.MeasureString(this.Name, settings.Font);

            return(this.UpdatedMenuIconAreaSize.Width + 2 * MenuButtonLeftPadding + (int)size.Width + (this.DropDown != null ? MenuDropDownArrowArea : 0));
        }