Ejemplo n.º 1
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[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;
            }
        }
        // TODO Only used in CommandBar.PreProcessMnemonic
        internal CommandBarItem[] this[char mnemonic]
        {
            get
            {
                ArrayList list = new ArrayList();

                foreach (CommandBarItem item in items)
                {
                    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);
            }
        }
Ejemplo n.º 3
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.IsVisible)
                    {
                        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);
        }
Ejemplo n.º 4
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;
                    }
                }
            }
        }
Ejemplo n.º 5
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 Add(CommandBarItem item)
        {
            this.items.Add(item);

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

            if (this.commandBar != null)
            {
                this.commandBar.AddItem(item);
            }
//// clear hashes
            keyItems.Clear();
        }
        public void RemoveAt(int index)
        {
            CommandBarItem item = (CommandBarItem)this.items[index];

            items.RemoveAt(index);

            if (this.commandBar != null)
            {
                this.commandBar.RemoveItem(item);
            }
//// clear hash table of shortcut items
            keyItems.Clear();
        }
        public void Remove(CommandBarItem item)
        {
            if (this.items.Contains(item))
            {
                this.items.Remove(item);

                if (this.commandBar != null)
                {
                    this.commandBar.RemoveItem(item);
                }
//// clear our hashes to simplify things - they will be reconstructed
                keyItems.Clear();
            }
        }
Ejemplo n.º 10
0
        private bool PerformClick(CommandBarItem item)
        {
            Application.DoEvents();

            CommandBarControl control = item as CommandBarControl;

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

            return(false);
        }
        internal CommandBarItem[] this[Keys shortcut]
        {
            get
            {
//// try to get result immediately
                if (keyItems[shortcut] == null)
                {
                    ArrayList list = new ArrayList();

                    foreach (CommandBarItem item in items)
                    {
                        CommandBarButtonBase buttonBase = item as CommandBarButtonBase;
                        if (buttonBase != null)
                        {
                            if ((buttonBase.Shortcut == shortcut) && (buttonBase.IsEnabled) && (buttonBase.IsVisible))
                            {
                                list.Add(buttonBase);
                            }
                        }
//// combine array lookup - better to make hashtable to speed up lookup - now it is too long
                        CommandBarMenu menu = item as CommandBarMenu;
                        if (menu != null)
                        {
                            list.AddRange(menu.Items[shortcut]);
                        }
                    }
//// too many calls - for every possible message in underlying windows

                    /*
                     * 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);
//// add new array to list
                    keyItems.Add(shortcut, array);
                }
                return((CommandBarItem[])keyItems[shortcut]);
            }
        }
Ejemplo n.º 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);
//// Alex:graphics and image must be released - lots of calls
                using (Graphics graphics = Graphics.FromHdc(tbcd.nmcd.hdc)) {
                    CommandBarItem item = items[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);
                    }
//// Alex: don't create references unnecessarily - lots of calls
                    if (item.Image != null)
                    {
                        Size  size  = item.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, item.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));
 }
Ejemplo n.º 15
0
        private NativeMethods.TBBUTTONINFO GetButtonInfo(int index)
        {
            CommandBarItem item = items[index];

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

            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.pszText   = IntPtr.Zero;
            buttonInfo.cchText   = 0;

            if (!item.IsVisible)
            {
                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.IsEnabled)
                {
                    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.pszText = Marshal.StringToHGlobalUni(item.Text + "\0");
                buttonInfo.cchText = item.Text.Length;
            }

            return(buttonInfo);
        }
Ejemplo n.º 16
0
 internal void RemoveItem(CommandBarItem item)
 {
     item.PropertyChanged -= new PropertyChangedEventHandler(this.CommandBarItem_PropertyChanged);
     this.UpdateItems();
 }