public CommandBarMenu AddMenu(string text, EventHandler dropDownHandler) { CommandBarMenu menu = this.AddMenu(text); menu.DropDown += dropDownHandler; return(menu); }
public CommandBarMenu AddMenu(string text) { CommandBarMenu menu = new CommandBarMenu(text); this.Add(menu); return(menu); }
public CommandBarMenu AddMenu(Image image, string text) { CommandBarMenu menu = this.AddMenu(text); menu.Image = image; return(menu); }
// 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); } }
protected override void OnPopup(EventArgs e) { CommandBarMenu menu = this.item as CommandBarMenu; if (menu != null) { menu.PerformDropDown(EventArgs.Empty); } base.OnPopup(e); this.UpdateItems(); }
private void UpdateItems() { this.OwnerDraw = true; CommandBarSeparator separator = this.item as CommandBarSeparator; if (separator != null) { this.Text = "-"; } else { this.Text = (this.mnemonics) ? this.item.Text : this.item.Text.Replace("&", ""); } CommandBarMenu menu = this.item as CommandBarMenu; if (menu != null) { this.MenuItems.Clear(); Size imageSize = GetImageSize(menu.Items); int visibleItemCount = 0; foreach (CommandBarItem item in menu.Items) { this.MenuItems.Add(new MenuBarItem(item, imageSize, font, mnemonics)); visibleItemCount += (item.Visible) ? 1 : 0; } this.Enabled = (visibleItemCount == 0) ? false : this.item.Enabled; } else { this.Enabled = this.item.Enabled; } this.Visible = this.item.Visible; }
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); }
private void TrackDropDown(int index) { while (index >= 0) { this.trackNextItem = -1; this.BeginUpdate(); CommandBarMenu menu = this.items[index] as CommandBarMenu; if (menu != null) { menu.PerformDropDown(EventArgs.Empty); this.contextMenu.Items.Clear(); this.contextMenu.Items.AddRange(menu.Items); // = menu.Items; this.contextMenu.Mnemonics = true; } else { this.contextMenu.Items.Clear(); // .Items = new CommandBarItemCollection(); this.contextMenu.Mnemonics = true; } // Item state NativeMethods.SendMessage(this.Handle, NativeMethods.TB_PRESSBUTTON, index, -1); // Trick to get the first menu item selected NativeMethods.PostMessage(this.Handle, NativeMethods.WM_KEYDOWN, (int)Keys.Down, 1); NativeMethods.PostMessage(this.Handle, NativeMethods.WM_KEYUP, (int)Keys.Down, 1); this.SetState(State.HotTracking, index); // Hook NativeMethods.HookProc hookProc = new NativeMethods.HookProc(DropDownHook); GCHandle hookProcHandle = GCHandle.Alloc(hookProc); this.hookHandle = NativeMethods.SetWindowsHookEx(NativeMethods.WH_MSGFILTER, hookProc, IntPtr.Zero, NativeMethods.GetCurrentThreadId()); if (this.hookHandle == IntPtr.Zero) { throw new SecurityException(); } // Ask for position NativeMethods.RECT rect = new NativeMethods.RECT(); NativeMethods.SendMessage(Handle, NativeMethods.TB_GETRECT, index, ref rect); Point position = new Point(rect.left, rect.bottom); this.EndUpdate(); this.Update(); this.contextMenu.Show(this, position); // Unhook NativeMethods.UnhookWindowsHookEx(hookHandle); hookProcHandle.Free(); this.hookHandle = IntPtr.Zero; // Item state NativeMethods.SendMessage(Handle, NativeMethods.TB_PRESSBUTTON, index, 0); this.SetState(trackEscapePressed ? State.Hot : State.None, index); index = trackNextItem; } }