1 /** 2 * Menu module. 3 * 4 * License: 5 * MIT. See LICENSE for full details. 6 */ 7 module tkd.widget.menu.menubar; 8 9 /** 10 * Imports. 11 */ 12 import tkd.element.uielement; 13 import tkd.window.window; 14 15 /** 16 * A menubar is the bar across the top of a window holding the menu items. 17 * 18 * Example: 19 * --- 20 * // Add a menu bar to a window. 21 * auto menuBar = new MenuBar(mainWindow) 22 * .pack(); 23 * 24 * // Add a menu to the menu bar. 25 * auto menu = new Menu(menuBar, "Menu 1") 26 * .addEntry("Entry 1", delegate(CommandArgs args){ ... }) 27 * .addEntry("Entry 2", delegate(CommandArgs args){ ... }) 28 * .addSeparator() 29 * .addEntry("Entry 3", delegate(CommandArgs args){ ... }); 30 * --- 31 * 32 * Additional_Events: 33 * Additional events that can also be bound to using the $(LINK2 ../../element/uielement.html#UiElement.bind, bind) method. 34 * $(P 35 * <<MenuSelect>>, 36 * <<PrevWindow>>, 37 * <Alt-Key>, 38 * <Button>, 39 * <ButtonRelease>, 40 * <Enter> 41 * <Key-Down>, 42 * <Key-Escape>, 43 * <Key-F10>, 44 * <Key-Left>, 45 * <Key-Return>, 46 * <Key-Right>, 47 * <Key-Tab>, 48 * <Key-Up>, 49 * <Key-space>, 50 * <Key>, 51 * <Leave>, 52 * <Motion>, 53 * ) 54 * 55 * See_Also: 56 * $(LINK2 ../../element/uielement.html, tkd.element.uielement) 57 */ 58 class MenuBar : UiElement 59 { 60 /** 61 * Construct the widget. 62 * 63 * Params: 64 * parent = The parent of this widget. 65 * 66 * See_Also: 67 * $(LINK2 ../../tkdapplication.html#Window, tkd.tkdapplication.Window) 68 */ 69 public this(Window parent) 70 { 71 super(parent); 72 73 this._elementId = "menubar"; 74 this._tk.eval("menu %s -tearoff 0", this.id); 75 this._tk.eval("%s configure -menu %s", parent.id, this.id); 76 } 77 78 /** 79 * Disable a child menu. The indexes start at zero for the left-most menu 80 * and increase as you go right. 81 * 82 * Params: 83 * index = The index of the menu to disable. 84 * 85 * Returns: 86 * This widget to aid method chaining. 87 */ 88 public auto disableMenu(this T)(int index) 89 { 90 this._tk.eval("%s entryconfigure %s -state disable", this.id, index); 91 92 return cast(T) this; 93 } 94 95 /** 96 * Enable a disabled child menu. The indexes start at zero for the 97 * left-most menu and increase as you go right. 98 * 99 * Params: 100 * index = The index of the menu to enable. 101 * 102 * Returns: 103 * This widget to aid method chaining. 104 */ 105 public auto enableMenu(this T)(int index) 106 { 107 this._tk.eval("%s entryconfigure %s -state normal", this.id, index); 108 109 return cast(T) this; 110 } 111 }