1 /* 2 * This file is part of gtkD. 3 * 4 * gtkD is free software; you can redistribute it and/or modify 5 * it under the terms of the GNU Lesser General Public License 6 * as published by the Free Software Foundation; either version 3 7 * of the License, or (at your option) any later version, with 8 * some exceptions, please read the COPYING file. 9 * 10 * gtkD is distributed in the hope that it will be useful, 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 * GNU Lesser General Public License for more details. 14 * 15 * You should have received a copy of the GNU Lesser General Public License 16 * along with gtkD; if not, write to the Free Software 17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110, USA 18 */ 19 20 // generated automatically - do not change 21 // find conversion definition on APILookup.txt 22 // implement new conversion functionalities on the wrap.utils pakage 23 24 /* 25 * Conversion parameters: 26 * inFile = GtkMenuShell.html 27 * outPack = gtk 28 * outFile = MenuShell 29 * strct = GtkMenuShell 30 * realStrct= 31 * ctorStrct= 32 * clss = MenuShell 33 * interf = 34 * class Code: No 35 * interface Code: No 36 * template for: 37 * extend = 38 * implements: 39 * prefixes: 40 * - gtk_menu_shell_ 41 * omit structs: 42 * omit prefixes: 43 * omit code: 44 * omit signals: 45 * imports: 46 * - glib.Str 47 * - gio.MenuModel 48 * - gtk.Widget 49 * structWrap: 50 * - GMenuModel* -> MenuModel 51 * - GtkWidget* -> Widget 52 * module aliases: 53 * local aliases: 54 * overrides: 55 */ 56 57 module gtk.MenuShell; 58 59 public import gtkc.gtktypes; 60 61 private import gtkc.gtk; 62 private import glib.ConstructionException; 63 private import gobject.ObjectG; 64 65 private import gobject.Signals; 66 public import gtkc.gdktypes; 67 68 private import glib.Str; 69 private import gio.MenuModel; 70 private import gtk.Widget; 71 72 73 74 private import gtk.Container; 75 76 /** 77 * A GtkMenuShell is the abstract base class used to derive the 78 * GtkMenu and GtkMenuBar subclasses. 79 * 80 * A GtkMenuShell is a container of GtkMenuItem objects arranged 81 * in a list which can be navigated, selected, and activated by the 82 * user to perform application functions. A GtkMenuItem can have a 83 * submenu associated with it, allowing for nested hierarchical menus. 84 * 85 * Terminology 86 * 87 * A menu item can be "selected", this means that it is displayed 88 * in the prelight state, and if it has a submenu, that submenu 89 * will be popped up. 90 * 91 * A menu is "active" when it is visible onscreen and the user 92 * is selecting from it. A menubar is not active until the user 93 * clicks on one of its menuitems. When a menu is active, 94 * passing the mouse over a submenu will pop it up. 95 * 96 * There is also is a concept of the current menu and a current 97 * menu item. The current menu item is the selected menu item 98 * that is furthest down in the hierarchy. (Every active menu shell 99 * does not necessarily contain a selected menu item, but if 100 * it does, then the parent menu shell must also contain 101 * a selected menu item.) The current menu is the menu that 102 * contains the current menu item. It will always have a GTK 103 * grab and receive all key presses. 104 */ 105 public class MenuShell : Container 106 { 107 108 /** the main Gtk struct */ 109 protected GtkMenuShell* gtkMenuShell; 110 111 112 public GtkMenuShell* getMenuShellStruct() 113 { 114 return gtkMenuShell; 115 } 116 117 118 /** the main Gtk struct as a void* */ 119 protected override void* getStruct() 120 { 121 return cast(void*)gtkMenuShell; 122 } 123 124 /** 125 * Sets our main struct and passes it to the parent class 126 */ 127 public this (GtkMenuShell* gtkMenuShell) 128 { 129 super(cast(GtkContainer*)gtkMenuShell); 130 this.gtkMenuShell = gtkMenuShell; 131 } 132 133 protected override void setStruct(GObject* obj) 134 { 135 super.setStruct(obj); 136 gtkMenuShell = cast(GtkMenuShell*)obj; 137 } 138 139 /** 140 */ 141 int[string] connectedSignals; 142 143 void delegate(gboolean, MenuShell)[] onActivateCurrentListeners; 144 /** 145 * An action signal that activates the current menu item within 146 * the menu shell. 147 */ 148 void addOnActivateCurrent(void delegate(gboolean, MenuShell) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 149 { 150 if ( !("activate-current" in connectedSignals) ) 151 { 152 Signals.connectData( 153 getStruct(), 154 "activate-current", 155 cast(GCallback)&callBackActivateCurrent, 156 cast(void*)this, 157 null, 158 connectFlags); 159 connectedSignals["activate-current"] = 1; 160 } 161 onActivateCurrentListeners ~= dlg; 162 } 163 extern(C) static void callBackActivateCurrent(GtkMenuShell* menushellStruct, gboolean forceHide, MenuShell _menuShell) 164 { 165 foreach ( void delegate(gboolean, MenuShell) dlg ; _menuShell.onActivateCurrentListeners ) 166 { 167 dlg(forceHide, _menuShell); 168 } 169 } 170 171 void delegate(MenuShell)[] onCancelListeners; 172 /** 173 * An action signal which cancels the selection within the menu shell. 174 * Causes the "selection-done" signal to be emitted. 175 */ 176 void addOnCancel(void delegate(MenuShell) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 177 { 178 if ( !("cancel" in connectedSignals) ) 179 { 180 Signals.connectData( 181 getStruct(), 182 "cancel", 183 cast(GCallback)&callBackCancel, 184 cast(void*)this, 185 null, 186 connectFlags); 187 connectedSignals["cancel"] = 1; 188 } 189 onCancelListeners ~= dlg; 190 } 191 extern(C) static void callBackCancel(GtkMenuShell* menushellStruct, MenuShell _menuShell) 192 { 193 foreach ( void delegate(MenuShell) dlg ; _menuShell.onCancelListeners ) 194 { 195 dlg(_menuShell); 196 } 197 } 198 199 void delegate(GtkDirectionType, MenuShell)[] onCycleFocusListeners; 200 /** 201 * A keybinding signal which moves the focus in the 202 * given direction. 203 */ 204 void addOnCycleFocus(void delegate(GtkDirectionType, MenuShell) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 205 { 206 if ( !("cycle-focus" in connectedSignals) ) 207 { 208 Signals.connectData( 209 getStruct(), 210 "cycle-focus", 211 cast(GCallback)&callBackCycleFocus, 212 cast(void*)this, 213 null, 214 connectFlags); 215 connectedSignals["cycle-focus"] = 1; 216 } 217 onCycleFocusListeners ~= dlg; 218 } 219 extern(C) static void callBackCycleFocus(GtkMenuShell* menushellStruct, GtkDirectionType direction, MenuShell _menuShell) 220 { 221 foreach ( void delegate(GtkDirectionType, MenuShell) dlg ; _menuShell.onCycleFocusListeners ) 222 { 223 dlg(direction, _menuShell); 224 } 225 } 226 227 void delegate(MenuShell)[] onDeactivateListeners; 228 /** 229 * This signal is emitted when a menu shell is deactivated. 230 */ 231 void addOnDeactivate(void delegate(MenuShell) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 232 { 233 if ( !("deactivate" in connectedSignals) ) 234 { 235 Signals.connectData( 236 getStruct(), 237 "deactivate", 238 cast(GCallback)&callBackDeactivate, 239 cast(void*)this, 240 null, 241 connectFlags); 242 connectedSignals["deactivate"] = 1; 243 } 244 onDeactivateListeners ~= dlg; 245 } 246 extern(C) static void callBackDeactivate(GtkMenuShell* menushellStruct, MenuShell _menuShell) 247 { 248 foreach ( void delegate(MenuShell) dlg ; _menuShell.onDeactivateListeners ) 249 { 250 dlg(_menuShell); 251 } 252 } 253 254 void delegate(Widget, gint, MenuShell)[] onInsertListeners; 255 /** 256 * The ::insert signal is emitted when a new GtkMenuItem is added to 257 * a GtkMenuShell. A separate signal is used instead of 258 * GtkContainer::add because of the need for an additional position 259 * parameter. 260 * The inverse of this signal is the GtkContainer::removed signal. 261 * Since 3.2 262 */ 263 void addOnInsert(void delegate(Widget, gint, MenuShell) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 264 { 265 if ( !("insert" in connectedSignals) ) 266 { 267 Signals.connectData( 268 getStruct(), 269 "insert", 270 cast(GCallback)&callBackInsert, 271 cast(void*)this, 272 null, 273 connectFlags); 274 connectedSignals["insert"] = 1; 275 } 276 onInsertListeners ~= dlg; 277 } 278 extern(C) static void callBackInsert(GtkMenuShell* menuShellStruct, GtkWidget* child, gint position, MenuShell _menuShell) 279 { 280 foreach ( void delegate(Widget, gint, MenuShell) dlg ; _menuShell.onInsertListeners ) 281 { 282 dlg(ObjectG.getDObject!(Widget)(child), position, _menuShell); 283 } 284 } 285 286 void delegate(GtkMenuDirectionType, MenuShell)[] onMoveCurrentListeners; 287 /** 288 * An keybinding signal which moves the current menu item 289 * in the direction specified by direction. 290 */ 291 void addOnMoveCurrent(void delegate(GtkMenuDirectionType, MenuShell) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 292 { 293 if ( !("move-current" in connectedSignals) ) 294 { 295 Signals.connectData( 296 getStruct(), 297 "move-current", 298 cast(GCallback)&callBackMoveCurrent, 299 cast(void*)this, 300 null, 301 connectFlags); 302 connectedSignals["move-current"] = 1; 303 } 304 onMoveCurrentListeners ~= dlg; 305 } 306 extern(C) static void callBackMoveCurrent(GtkMenuShell* menushellStruct, GtkMenuDirectionType direction, MenuShell _menuShell) 307 { 308 foreach ( void delegate(GtkMenuDirectionType, MenuShell) dlg ; _menuShell.onMoveCurrentListeners ) 309 { 310 dlg(direction, _menuShell); 311 } 312 } 313 314 bool delegate(gint, MenuShell)[] onMoveSelectedListeners; 315 /** 316 * The ::move-selected signal is emitted to move the selection to 317 * another item. 318 * TRUE to stop the signal emission, FALSE to continue 319 * Since 2.12 320 */ 321 void addOnMoveSelected(bool delegate(gint, MenuShell) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 322 { 323 if ( !("move-selected" in connectedSignals) ) 324 { 325 Signals.connectData( 326 getStruct(), 327 "move-selected", 328 cast(GCallback)&callBackMoveSelected, 329 cast(void*)this, 330 null, 331 connectFlags); 332 connectedSignals["move-selected"] = 1; 333 } 334 onMoveSelectedListeners ~= dlg; 335 } 336 extern(C) static gboolean callBackMoveSelected(GtkMenuShell* menuShellStruct, gint distance, MenuShell _menuShell) 337 { 338 foreach ( bool delegate(gint, MenuShell) dlg ; _menuShell.onMoveSelectedListeners ) 339 { 340 if ( dlg(distance, _menuShell) ) 341 { 342 return 1; 343 } 344 } 345 346 return 0; 347 } 348 349 void delegate(MenuShell)[] onSelectionDoneListeners; 350 /** 351 * This signal is emitted when a selection has been 352 * completed within a menu shell. 353 */ 354 void addOnSelectionDone(void delegate(MenuShell) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 355 { 356 if ( !("selection-done" in connectedSignals) ) 357 { 358 Signals.connectData( 359 getStruct(), 360 "selection-done", 361 cast(GCallback)&callBackSelectionDone, 362 cast(void*)this, 363 null, 364 connectFlags); 365 connectedSignals["selection-done"] = 1; 366 } 367 onSelectionDoneListeners ~= dlg; 368 } 369 extern(C) static void callBackSelectionDone(GtkMenuShell* menushellStruct, MenuShell _menuShell) 370 { 371 foreach ( void delegate(MenuShell) dlg ; _menuShell.onSelectionDoneListeners ) 372 { 373 dlg(_menuShell); 374 } 375 } 376 377 378 /** 379 * Adds a new GtkMenuItem to the end of the menu shell's 380 * item list. 381 * Params: 382 * child = The GtkMenuItem to add 383 */ 384 public void append(Widget child) 385 { 386 // void gtk_menu_shell_append (GtkMenuShell *menu_shell, GtkWidget *child); 387 gtk_menu_shell_append(gtkMenuShell, (child is null) ? null : child.getWidgetStruct()); 388 } 389 390 /** 391 * Adds a new GtkMenuItem to the beginning of the menu shell's 392 * item list. 393 * Params: 394 * child = The GtkMenuItem to add 395 */ 396 public void prepend(Widget child) 397 { 398 // void gtk_menu_shell_prepend (GtkMenuShell *menu_shell, GtkWidget *child); 399 gtk_menu_shell_prepend(gtkMenuShell, (child is null) ? null : child.getWidgetStruct()); 400 } 401 402 /** 403 * Adds a new GtkMenuItem to the menu shell's item list 404 * at the position indicated by position. 405 * Params: 406 * child = The GtkMenuItem to add 407 * position = The position in the item list where child 408 * is added. Positions are numbered from 0 to n-1 409 */ 410 public void insert(Widget child, int position) 411 { 412 // void gtk_menu_shell_insert (GtkMenuShell *menu_shell, GtkWidget *child, gint position); 413 gtk_menu_shell_insert(gtkMenuShell, (child is null) ? null : child.getWidgetStruct(), position); 414 } 415 416 /** 417 * Deactivates the menu shell. 418 * Typically this results in the menu shell being erased 419 * from the screen. 420 */ 421 public void deactivate() 422 { 423 // void gtk_menu_shell_deactivate (GtkMenuShell *menu_shell); 424 gtk_menu_shell_deactivate(gtkMenuShell); 425 } 426 427 /** 428 * Selects the menu item from the menu shell. 429 * Params: 430 * menuItem = The GtkMenuItem to select 431 */ 432 public void selectItem(Widget menuItem) 433 { 434 // void gtk_menu_shell_select_item (GtkMenuShell *menu_shell, GtkWidget *menu_item); 435 gtk_menu_shell_select_item(gtkMenuShell, (menuItem is null) ? null : menuItem.getWidgetStruct()); 436 } 437 438 /** 439 * Select the first visible or selectable child of the menu shell; 440 * don't select tearoff items unless the only item is a tearoff 441 * item. 442 * Since 2.2 443 * Params: 444 * searchSensitive = if TRUE, search for the first selectable 445 * menu item, otherwise select nothing if 446 * the first item isn't sensitive. This 447 * should be FALSE if the menu is being 448 * popped up initially. 449 */ 450 public void selectFirst(int searchSensitive) 451 { 452 // void gtk_menu_shell_select_first (GtkMenuShell *menu_shell, gboolean search_sensitive); 453 gtk_menu_shell_select_first(gtkMenuShell, searchSensitive); 454 } 455 456 /** 457 * Deselects the currently selected item from the menu shell, 458 * if any. 459 */ 460 public void deselect() 461 { 462 // void gtk_menu_shell_deselect (GtkMenuShell *menu_shell); 463 gtk_menu_shell_deselect(gtkMenuShell); 464 } 465 466 /** 467 * Activates the menu item within the menu shell. 468 * Params: 469 * menuItem = the GtkMenuItem to activate 470 * forceDeactivate = if TRUE, force the deactivation of the 471 * menu shell after the menu item is activated 472 */ 473 public void activateItem(Widget menuItem, int forceDeactivate) 474 { 475 // void gtk_menu_shell_activate_item (GtkMenuShell *menu_shell, GtkWidget *menu_item, gboolean force_deactivate); 476 gtk_menu_shell_activate_item(gtkMenuShell, (menuItem is null) ? null : menuItem.getWidgetStruct(), forceDeactivate); 477 } 478 479 /** 480 * Cancels the selection within the menu shell. 481 * Since 2.4 482 */ 483 public void cancel() 484 { 485 // void gtk_menu_shell_cancel (GtkMenuShell *menu_shell); 486 gtk_menu_shell_cancel(gtkMenuShell); 487 } 488 489 /** 490 * If take_focus is TRUE (the default) the menu shell will take 491 * the keyboard focus so that it will receive all keyboard events 492 * which is needed to enable keyboard navigation in menus. 493 * Setting take_focus to FALSE is useful only for special applications 494 * like virtual keyboard implementations which should not take keyboard 495 * focus. 496 * The take_focus state of a menu or menu bar is automatically 497 * propagated to submenus whenever a submenu is popped up, so you 498 * don't have to worry about recursively setting it for your entire 499 * menu hierarchy. Only when programmatically picking a submenu and 500 * popping it up manually, the take_focus property of the submenu 501 * needs to be set explicitely. 502 * Since 2.8 503 * Params: 504 * takeFocus = TRUE if the menu shell should take the keyboard 505 * focus on popup 506 */ 507 public void setTakeFocus(int takeFocus) 508 { 509 // void gtk_menu_shell_set_take_focus (GtkMenuShell *menu_shell, gboolean take_focus); 510 gtk_menu_shell_set_take_focus(gtkMenuShell, takeFocus); 511 } 512 513 /** 514 * Returns TRUE if the menu shell will take the keyboard focus on popup. 515 * Since 2.8 516 * Returns: TRUE if the menu shell will take the keyboard focus on popup. 517 */ 518 public int getTakeFocus() 519 { 520 // gboolean gtk_menu_shell_get_take_focus (GtkMenuShell *menu_shell); 521 return gtk_menu_shell_get_take_focus(gtkMenuShell); 522 } 523 524 /** 525 * Gets the currently selected item. 526 * Returns: the currently selected item. [transfer none] Since 3.0 527 */ 528 public Widget getSelectedItem() 529 { 530 // GtkWidget * gtk_menu_shell_get_selected_item (GtkMenuShell *menu_shell); 531 auto p = gtk_menu_shell_get_selected_item(gtkMenuShell); 532 533 if(p is null) 534 { 535 return null; 536 } 537 538 return ObjectG.getDObject!(Widget)(cast(GtkWidget*) p); 539 } 540 541 /** 542 * Gets the parent menu shell. 543 * The parent menu shell of a submenu is the GtkMenu or GtkMenuBar 544 * from which it was opened up. 545 * Returns: the parent GtkMenuShell. [transfer none] Since 3.0 546 */ 547 public Widget getParentShell() 548 { 549 // GtkWidget * gtk_menu_shell_get_parent_shell (GtkMenuShell *menu_shell); 550 auto p = gtk_menu_shell_get_parent_shell(gtkMenuShell); 551 552 if(p is null) 553 { 554 return null; 555 } 556 557 return ObjectG.getDObject!(Widget)(cast(GtkWidget*) p); 558 } 559 560 /** 561 * Establishes a binding between a GtkMenuShell and a GMenuModel. 562 * The contents of shell are removed and then refilled with menu items 563 * according to model. When model changes, shell is updated. 564 * Calling this function twice on shell with different model will 565 * cause the first binding to be replaced with a binding to the new 566 * model. If model is NULL then any previous binding is undone and 567 * all children are removed. 568 * with_separators determines if toplevel items (eg: sections) have 569 * separators inserted between them. This is typically desired for 570 * menus but doesn't make sense for menubars. 571 * If action_namespace is non-NULL then the effect is as if all 572 * actions mentioned in the model have their names prefixed with the 573 * namespace, plus a dot. For example, if the action "quit" is 574 * mentioned and action_namespace is "app" then the effective action 575 * name is "app.quit". 576 * This function uses GtkActionable to define the action name and 577 * target values on the created menu items. If you want to use an 578 * action group other than "app" and "win", or if you want to use a 579 * GtkMenuShell outside of a GtkApplicationWindow, then you will need 580 * to attach your own action group to the widget hierarchy using 581 * gtk_widget_insert_action_group(). As an example, if you created a 582 * group with a "quit" action and inserted it with the name "mygroup" 583 * then you would use the action name "mygroup.quit" in your 584 * GMenuModel. 585 * For most cases you are probably better off using 586 * gtk_menu_new_from_model() or gtk_menu_bar_new_from_model() or just 587 * directly passing the GMenuModel to gtk_application_set_app_menu() or 588 * gtk_application_set_menu_bar(). 589 * Params: 590 * model = the GMenuModel to bind to or NULL to remove 591 * binding. [allow-none] 592 * actionNamespace = the namespace for actions in model. [allow-none] 593 * withSeparators = TRUE if toplevel items in shell should have 594 * separators between them 595 * Since 3.6 596 */ 597 public void bindModel(MenuModel model, string actionNamespace, int withSeparators) 598 { 599 // void gtk_menu_shell_bind_model (GtkMenuShell *menu_shell, GMenuModel *model, const gchar *action_namespace, gboolean with_separators); 600 gtk_menu_shell_bind_model(gtkMenuShell, (model is null) ? null : model.getMenuModelStruct(), Str.toStringz(actionNamespace), withSeparators); 601 } 602 }