// TODO
        internal CommandBarItem[] this[Keys shortcut]
        {
            get
            {
                ArrayList list = new ArrayList();

                foreach (CommandBarItem item in items)
                {
                    CommandBarButtonBase buttonBase = item as CommandBarButtonBase;
                    if (buttonBase != null)
                    {
                        if ((buttonBase.Shortcut == shortcut) && (buttonBase.Enabled) && (buttonBase.Visible))
                        {
                            list.Add(buttonBase);
                        }
                    }
                }

                foreach (CommandBarItem item in items)
                {
                    CommandBarMenu menu = item as CommandBarMenu;
                    if (menu != null)
                    {
                        list.AddRange(menu.Items[shortcut]);
                    }
                }

                CommandBarItem[] array = new CommandBarItem[list.Count];
                list.CopyTo(array, 0);
                return(array);
            }
        }
        // TODO Only used in CommandBar.PreProcessMnemonic
        internal CommandBarItem[] this[char mnemonic]
        {
            get
            {
                ArrayList list = new ArrayList();

                foreach (CommandBarItem item in items)
                {
                    if ((item.Visible) && (item.Enabled))
                    {
                        string text = item.Text;
                        for (int i = 0; i < text.Length; i++)
                        {
                            if ((text[i] == '&') && (i + 1 < text.Length) && (text[i + 1] != '&'))
                            {
                                if (mnemonic == Char.ToUpper(text[i + 1], CultureInfo.InvariantCulture))
                                {
                                    list.Add(item);
                                }
                            }
                        }
                    }
                }

                CommandBarItem[] array = new CommandBarItem[list.Count];
                list.CopyTo(array, 0);
                return(array);
            }
        }
Пример #3
0
        private void NotifyNeedTextW(ref Message message)
        {
            if ((this.Style != CommandBarStyle.Menu) && (Marshal.SystemDefaultCharSize == 2))
            {
                // this code is a duplicate of NotifyNeedTextA
                NativeMethods.TOOLTIPTEXT toolTipText = (NativeMethods.TOOLTIPTEXT)message.GetLParam(typeof(NativeMethods.TOOLTIPTEXT));
                CommandBarItem            item        = (CommandBarItem)items[(int)toolTipText.hdr.idFrom];
                toolTipText.szText = item.Text;

                CommandBarButtonBase buttonBase = item as CommandBarButton;
                if ((buttonBase != null) && (buttonBase.Shortcut != Keys.None))
                {
                    toolTipText.szText += " (" + TypeDescriptor.GetConverter(typeof(Keys)).ConvertToString(null, CultureInfo.InvariantCulture, buttonBase.Shortcut) + ")";
                }

                toolTipText.hinst = IntPtr.Zero;
                if (RightToLeft == RightToLeft.Yes)
                {
                    toolTipText.uFlags |= NativeMethods.TTF_RTLREADING;
                }

                Marshal.StructureToPtr(toolTipText, message.LParam, true);
                message.Result = (IntPtr)1;
            }
        }
Пример #4
0
        public void Show(Control control, Point point)
        {
            CommandBarItemCollection chevronItems = new CommandBarItemCollection();
            Size size = ClientSize;

            for (int i = 0; i < items.Count; i++)
            {
                NativeMethods.RECT rect = new NativeMethods.RECT();
                NativeMethods.SendMessage(Handle, NativeMethods.TB_GETITEMRECT, i, ref rect);
                if (rect.right > size.Width)
                {
                    CommandBarItem item = items[i];
                    if (item.Visible)
                    {
                        if ((!(item is CommandBarSeparator)) || (chevronItems.Count != 0))
                        {
                            chevronItems.Add(item);
                        }
                    }
                }
            }

            this.contextMenu.Mnemonics = false;
            this.contextMenu.Items.Clear();
            this.contextMenu.Items.AddRange(chevronItems);
            this.contextMenu.Show(control, point);
        }
Пример #5
0
        private void CommandBarItem_PropertyChanged(object sender, PropertyChangedEventArgs e)
        {
            if (this.IsHandleCreated)
            {
                CommandBarItem item  = (CommandBarItem)sender;
                int            index = this.Items.IndexOf(item);
                if (index != -1)
                {
                    switch (e.PropertyName)
                    {
                    case "IsVisible":
                        this.UpdateItems();
                        break;

                    case "Image":
                        this.UpdateImageList();
                        break;

                    default:
                        NativeMethods.TBBUTTONINFO buttonInfo = GetButtonInfo(index);
                        NativeMethods.SendMessage(this.Handle, NativeMethods.TB_SETBUTTONINFO, index, ref buttonInfo);
                        this.UpdateSize();
                        break;
                    }
                }
            }
        }
        public void Add(CommandBarItem item)
        {
            this.items.Add(item);

            if (this.commandBar != null)
            {
                this.commandBar.AddItem(item);
            }
        }
        public void Insert(int index, CommandBarItem item)
        {
            items.Insert(index, item);

            if (this.commandBar != null)
            {
                this.commandBar.AddItem(item);
            }
        }
Пример #8
0
            public MenuBarItem(CommandBarItem item, Size imageSize, Font font, bool mnemonics)
            {
                this.item      = item;
                this.imageSize = imageSize;
                this.font      = font;
                this.mnemonics = mnemonics;

                this.UpdateItems();
            }
        public void RemoveAt(int index)
        {
            CommandBarItem item = (CommandBarItem)this.items[index];

            items.RemoveAt(index);

            if (this.commandBar != null)
            {
                this.commandBar.RemoveItem(item);
            }
        }
        public void Remove(CommandBarItem item)
        {
            if (this.items.Contains(item))
            {
                this.items.Remove(item);

                if (this.commandBar != null)
                {
                    this.commandBar.RemoveItem(item);
                }
            }
        }
Пример #11
0
        private bool PerformClick(CommandBarItem item)
        {
            Application.DoEvents();

            CommandBarControl control = item as CommandBarControl;

            if (control != null)
            {
                control.PerformClick(EventArgs.Empty);
                return(true);
            }

            return(false);
        }
Пример #12
0
        private void NotifyCustomDrawToolBar(ref Message m)
        {
            m.Result = (IntPtr)NativeMethods.CDRF_DODEFAULT;

            NativeMethods.DLLVERSIONINFO dvi = new NativeMethods.DLLVERSIONINFO();
            dvi.cbSize = Marshal.SizeOf(typeof(NativeMethods.DLLVERSIONINFO));
            NativeMethods.DllGetVersion(ref dvi);
            if (dvi.dwMajorVersion < 6)
            {
                NativeMethods.LPNMTBCUSTOMDRAW tbcd = (NativeMethods.LPNMTBCUSTOMDRAW)m.GetLParam(typeof(NativeMethods.LPNMTBCUSTOMDRAW));
                NativeMethods.RECT             rc   = tbcd.nmcd.rc;

                Rectangle rectangle = new Rectangle(rc.left, rc.top, rc.right - rc.left, rc.bottom - rc.top);

                Graphics       graphics = Graphics.FromHdc(tbcd.nmcd.hdc);
                CommandBarItem item     = items[(int)tbcd.nmcd.dwItemSpec];

                bool hot      = ((tbcd.nmcd.uItemState & NativeMethods.CDIS_HOT) != 0);
                bool selected = ((tbcd.nmcd.uItemState & NativeMethods.CDIS_SELECTED) != 0);
                bool disabled = ((tbcd.nmcd.uItemState & NativeMethods.CDIS_DISABLED) != 0);

                CommandBarCheckBox checkBox = item as CommandBarCheckBox;
                if ((checkBox != null) && (checkBox.IsChecked))
                {
                    ControlPaint.DrawBorder3D(graphics, rectangle, Border3DStyle.SunkenOuter);
                }
                else if (selected)
                {
                    ControlPaint.DrawBorder3D(graphics, rectangle, Border3DStyle.SunkenOuter);
                }
                else if (hot)
                {
                    ControlPaint.DrawBorder3D(graphics, rectangle, Border3DStyle.RaisedInner);
                }

                Image image = item.Image;
                if (image != null)
                {
                    Size  size  = image.Size;
                    Point point = new Point(rc.left + ((rc.right - rc.left - size.Width) / 2), rc.top + ((rc.bottom - rc.top - size.Height) / 2));
                    NativeMethods.DrawImage(graphics, image, point, disabled);
                }

                m.Result = (IntPtr)NativeMethods.CDRF_SKIPDEFAULT;
            }
        }
 public int IndexOf(CommandBarItem item)
 {
     return(this.items.IndexOf(item));
 }
 public bool Contains(CommandBarItem item)
 {
     return(this.items.Contains(item));
 }
Пример #15
0
        private NativeMethods.TBBUTTONINFO GetButtonInfo(int index)
        {
            CommandBarItem item = items[index];

            NativeMethods.TBBUTTONINFO buttonInfo = new NativeMethods.TBBUTTONINFO();
            buttonInfo.cbSize = Marshal.SizeOf(buttonInfo);

            buttonInfo.dwMask    = NativeMethods.TBIF_IMAGE | NativeMethods.TBIF_STATE | NativeMethods.TBIF_STYLE | NativeMethods.TBIF_COMMAND;
            buttonInfo.idCommand = index;
            buttonInfo.iImage    = NativeMethods.I_IMAGECALLBACK;
            buttonInfo.fsStyle   = NativeMethods.BTNS_BUTTON | NativeMethods.BTNS_AUTOSIZE;
            buttonInfo.fsState   = 0;
            buttonInfo.cx        = 0;
            buttonInfo.lParam    = IntPtr.Zero;
            buttonInfo.lpszText  = string.Empty;
            buttonInfo.cchText   = 0;

            if (!item.Visible)
            {
                buttonInfo.fsState |= NativeMethods.TBSTATE_HIDDEN;
            }

            CommandBarComboBox comboBox = item as CommandBarComboBox;

            if (comboBox != null)
            {
                buttonInfo.cx     = (short)(comboBox.Width + 4);
                buttonInfo.dwMask = NativeMethods.TBIF_SIZE;
            }

            if (item is CommandBarSeparator)
            {
                buttonInfo.fsStyle |= NativeMethods.BTNS_SEP;
            }
            else
            {
                if (item.Enabled)
                {
                    buttonInfo.fsState |= NativeMethods.TBSTATE_ENABLED;
                }

                CommandBarMenu menu = item as CommandBarMenu;
                if ((menu != null) && (menu.Items.Count > 0))
                {
                    buttonInfo.fsStyle |= NativeMethods.BTNS_DROPDOWN;
                }

                if (style == CommandBarStyle.ToolBar)
                {
                    if (item is CommandBarMenu)
                    {
                        buttonInfo.fsStyle |= NativeMethods.BTNS_WHOLEDROPDOWN;
                    }
                }

                CommandBarCheckBox checkBox = item as CommandBarCheckBox;
                if ((checkBox != null) && (checkBox.IsChecked))
                {
                    buttonInfo.fsState |= NativeMethods.TBSTATE_CHECKED;
                }
            }

            if (item is CommandBarSeparator)
            {
                buttonInfo.iImage = NativeMethods.I_IMAGENONE;
            }
            else if (item.Image != null)
            {
                buttonInfo.iImage = index;
            }

            if ((this.Style == CommandBarStyle.Menu) && (item.Text != null) && (item.Text.Length != 0))
            {
                buttonInfo.dwMask  |= NativeMethods.TBIF_TEXT;
                buttonInfo.lpszText = item.Text + '\0';
                buttonInfo.cchText  = item.Text.Length;
            }

            return(buttonInfo);
        }
Пример #16
0
 internal void RemoveItem(CommandBarItem item)
 {
     item.PropertyChanged -= new PropertyChangedEventHandler(this.CommandBarItem_PropertyChanged);
     this.UpdateItems();
 }