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 module gtk.Menu; 26 27 private import gdk.Device; 28 private import gdk.Event; 29 private import gdk.MonitorG; 30 private import gdk.Screen; 31 private import gdk.Window; 32 private import gio.MenuModel; 33 private import glib.ConstructionException; 34 private import glib.ListG; 35 private import glib.Str; 36 private import gobject.ObjectG; 37 private import gobject.Signals; 38 private import gtk.AccelGroup; 39 private import gtk.MenuItem; 40 private import gtk.MenuShell; 41 private import gtk.Widget; 42 private import gtk.c.functions; 43 public import gtk.c.types; 44 public import gtkc.gtktypes; 45 private import std.algorithm; 46 47 48 /** 49 * A #GtkMenu is a #GtkMenuShell that implements a drop down menu 50 * consisting of a list of #GtkMenuItem objects which can be navigated 51 * and activated by the user to perform application functions. 52 * 53 * A #GtkMenu is most commonly dropped down by activating a 54 * #GtkMenuItem in a #GtkMenuBar or popped up by activating a 55 * #GtkMenuItem in another #GtkMenu. 56 * 57 * A #GtkMenu can also be popped up by activating a #GtkComboBox. 58 * Other composite widgets such as the #GtkNotebook can pop up a 59 * #GtkMenu as well. 60 * 61 * Applications can display a #GtkMenu as a popup menu by calling the 62 * gtk_menu_popup() function. The example below shows how an application 63 * can pop up a menu when the 3rd mouse button is pressed. 64 * 65 * ## Connecting the popup signal handler. 66 * 67 * |[<!-- language="C" --> 68 * // connect our handler which will popup the menu 69 * g_signal_connect_swapped (window, "button_press_event", 70 * G_CALLBACK (my_popup_handler), menu); 71 * ]| 72 * 73 * ## Signal handler which displays a popup menu. 74 * 75 * |[<!-- language="C" --> 76 * static gint 77 * my_popup_handler (GtkWidget *widget, GdkEvent *event) 78 * { 79 * GtkMenu *menu; 80 * GdkEventButton *event_button; 81 * 82 * g_return_val_if_fail (widget != NULL, FALSE); 83 * g_return_val_if_fail (GTK_IS_MENU (widget), FALSE); 84 * g_return_val_if_fail (event != NULL, FALSE); 85 * 86 * // The "widget" is the menu that was supplied when 87 * // g_signal_connect_swapped() was called. 88 * menu = GTK_MENU (widget); 89 * 90 * if (event->type == GDK_BUTTON_PRESS) 91 * { 92 * event_button = (GdkEventButton *) event; 93 * if (event_button->button == GDK_BUTTON_SECONDARY) 94 * { 95 * gtk_menu_popup (menu, NULL, NULL, NULL, NULL, 96 * event_button->button, event_button->time); 97 * return TRUE; 98 * } 99 * } 100 * 101 * return FALSE; 102 * } 103 * ]| 104 * 105 * # CSS nodes 106 * 107 * |[<!-- language="plain" --> 108 * menu 109 * ├── arrow.top 110 * ├── <child> 111 * ┊ 112 * ├── <child> 113 * ╰── arrow.bottom 114 * ]| 115 * 116 * The main CSS node of GtkMenu has name menu, and there are two subnodes 117 * with name arrow, for scrolling menu arrows. These subnodes get the 118 * .top and .bottom style classes. 119 */ 120 public class Menu : MenuShell 121 { 122 /** the main Gtk struct */ 123 protected GtkMenu* gtkMenu; 124 125 /** Get the main Gtk struct */ 126 public GtkMenu* getMenuStruct(bool transferOwnership = false) 127 { 128 if (transferOwnership) 129 ownedRef = false; 130 return gtkMenu; 131 } 132 133 /** the main Gtk struct as a void* */ 134 protected override void* getStruct() 135 { 136 return cast(void*)gtkMenu; 137 } 138 139 /** 140 * Sets our main struct and passes it to the parent class. 141 */ 142 public this (GtkMenu* gtkMenu, bool ownedRef = false) 143 { 144 this.gtkMenu = gtkMenu; 145 super(cast(GtkMenuShell*)gtkMenu, ownedRef); 146 } 147 148 /** 149 * Popups up this menu 150 * Params: 151 * button = you can pass a button number here 152 * activateTime = you can pass the time from an event here 153 */ 154 void popup(uint button, uint activateTime) 155 { 156 popup(null, null, null, null, button, activateTime); 157 } 158 159 /** 160 * Creates and append a submenu to this menu. 161 * This menu item that actualy has the sub menu is also created. 162 * Params: 163 * label = the sub menu item label 164 * Returns: the new menu 165 */ 166 Menu appendSubmenu(string label) 167 { 168 MenuItem item = new MenuItem(label); 169 append(item); 170 Menu submenu = new Menu(); 171 item.setSubmenu(submenu); 172 return submenu; 173 } 174 175 /** */ 176 void appendSubmenu(string label, Menu submenu) 177 { 178 MenuItem item = new MenuItem(label); 179 append(item); 180 item.setSubmenu(submenu); 181 } 182 183 /** */ 184 Menu prependSubmenu(string label) 185 { 186 MenuItem item = new MenuItem(label); 187 prepend(item); 188 Menu submenu = new Menu(); 189 item.setSubmenu(submenu); 190 return submenu; 191 } 192 193 /** 194 */ 195 196 /** */ 197 public static GType getType() 198 { 199 return gtk_menu_get_type(); 200 } 201 202 /** 203 * Creates a new #GtkMenu 204 * 205 * Returns: a new #GtkMenu 206 * 207 * Throws: ConstructionException GTK+ fails to create the object. 208 */ 209 public this() 210 { 211 auto p = gtk_menu_new(); 212 213 if(p is null) 214 { 215 throw new ConstructionException("null returned by new"); 216 } 217 218 this(cast(GtkMenu*) p); 219 } 220 221 /** 222 * Creates a #GtkMenu and populates it with menu items and 223 * submenus according to @model. 224 * 225 * The created menu items are connected to actions found in the 226 * #GtkApplicationWindow to which the menu belongs - typically 227 * by means of being attached to a widget (see gtk_menu_attach_to_widget()) 228 * that is contained within the #GtkApplicationWindows widget hierarchy. 229 * 230 * Actions can also be added using gtk_widget_insert_action_group() on the menu's 231 * attach widget or on any of its parent widgets. 232 * 233 * Params: 234 * model = a #GMenuModel 235 * 236 * Returns: a new #GtkMenu 237 * 238 * Since: 3.4 239 * 240 * Throws: ConstructionException GTK+ fails to create the object. 241 */ 242 public this(MenuModel model) 243 { 244 auto p = gtk_menu_new_from_model((model is null) ? null : model.getMenuModelStruct()); 245 246 if(p is null) 247 { 248 throw new ConstructionException("null returned by new_from_model"); 249 } 250 251 this(cast(GtkMenu*) p); 252 } 253 254 /** 255 * Returns a list of the menus which are attached to this widget. 256 * This list is owned by GTK+ and must not be modified. 257 * 258 * Params: 259 * widget = a #GtkWidget 260 * 261 * Returns: the list 262 * of menus attached to his widget. 263 * 264 * Since: 2.6 265 */ 266 public static ListG getForAttachWidget(Widget widget) 267 { 268 auto p = gtk_menu_get_for_attach_widget((widget is null) ? null : widget.getWidgetStruct()); 269 270 if(p is null) 271 { 272 return null; 273 } 274 275 return new ListG(cast(GList*) p); 276 } 277 278 /** 279 * Adds a new #GtkMenuItem to a (table) menu. The number of “cells” that 280 * an item will occupy is specified by @left_attach, @right_attach, 281 * @top_attach and @bottom_attach. These each represent the leftmost, 282 * rightmost, uppermost and lower column and row numbers of the table. 283 * (Columns and rows are indexed from zero). 284 * 285 * Note that this function is not related to gtk_menu_detach(). 286 * 287 * Params: 288 * child = a #GtkMenuItem 289 * leftAttach = The column number to attach the left side of the item to 290 * rightAttach = The column number to attach the right side of the item to 291 * topAttach = The row number to attach the top of the item to 292 * bottomAttach = The row number to attach the bottom of the item to 293 * 294 * Since: 2.4 295 */ 296 public void attach(Widget child, uint leftAttach, uint rightAttach, uint topAttach, uint bottomAttach) 297 { 298 gtk_menu_attach(gtkMenu, (child is null) ? null : child.getWidgetStruct(), leftAttach, rightAttach, topAttach, bottomAttach); 299 } 300 301 /** 302 * Attaches the menu to the widget and provides a callback function 303 * that will be invoked when the menu calls gtk_menu_detach() during 304 * its destruction. 305 * 306 * If the menu is attached to the widget then it will be destroyed 307 * when the widget is destroyed, as if it was a child widget. 308 * An attached menu will also move between screens correctly if the 309 * widgets moves between screens. 310 * 311 * Params: 312 * attachWidget = the #GtkWidget that the menu will be attached to 313 * detacher = the user supplied callback function 314 * that will be called when the menu calls gtk_menu_detach() 315 */ 316 public void attachToWidget(Widget attachWidget, GtkMenuDetachFunc detacher) 317 { 318 gtk_menu_attach_to_widget(gtkMenu, (attachWidget is null) ? null : attachWidget.getWidgetStruct(), detacher); 319 } 320 321 /** 322 * Detaches the menu from the widget to which it had been attached. 323 * This function will call the callback function, @detacher, provided 324 * when the gtk_menu_attach_to_widget() function was called. 325 */ 326 public void detach() 327 { 328 gtk_menu_detach(gtkMenu); 329 } 330 331 /** 332 * Gets the #GtkAccelGroup which holds global accelerators for the 333 * menu. See gtk_menu_set_accel_group(). 334 * 335 * Returns: the #GtkAccelGroup associated with the menu 336 */ 337 public AccelGroup getAccelGroup() 338 { 339 auto p = gtk_menu_get_accel_group(gtkMenu); 340 341 if(p is null) 342 { 343 return null; 344 } 345 346 return ObjectG.getDObject!(AccelGroup)(cast(GtkAccelGroup*) p); 347 } 348 349 /** 350 * Retrieves the accelerator path set on the menu. 351 * 352 * Returns: the accelerator path set on the menu. 353 * 354 * Since: 2.14 355 */ 356 public string getAccelPath() 357 { 358 return Str.toString(gtk_menu_get_accel_path(gtkMenu)); 359 } 360 361 /** 362 * Returns the selected menu item from the menu. This is used by the 363 * #GtkComboBox. 364 * 365 * Returns: the #GtkMenuItem that was last selected 366 * in the menu. If a selection has not yet been made, the 367 * first menu item is selected. 368 */ 369 public Widget getActive() 370 { 371 auto p = gtk_menu_get_active(gtkMenu); 372 373 if(p is null) 374 { 375 return null; 376 } 377 378 return ObjectG.getDObject!(Widget)(cast(GtkWidget*) p); 379 } 380 381 /** 382 * Returns the #GtkWidget that the menu is attached to. 383 * 384 * Returns: the #GtkWidget that the menu is attached to 385 */ 386 public Widget getAttachWidget() 387 { 388 auto p = gtk_menu_get_attach_widget(gtkMenu); 389 390 if(p is null) 391 { 392 return null; 393 } 394 395 return ObjectG.getDObject!(Widget)(cast(GtkWidget*) p); 396 } 397 398 /** 399 * Retrieves the number of the monitor on which to show the menu. 400 * 401 * Returns: the number of the monitor on which the menu should 402 * be popped up or -1, if no monitor has been set 403 * 404 * Since: 2.14 405 */ 406 public int getMonitor() 407 { 408 return gtk_menu_get_monitor(gtkMenu); 409 } 410 411 /** 412 * Returns whether the menu reserves space for toggles and 413 * icons, regardless of their actual presence. 414 * 415 * Returns: Whether the menu reserves toggle space 416 * 417 * Since: 2.18 418 */ 419 public bool getReserveToggleSize() 420 { 421 return gtk_menu_get_reserve_toggle_size(gtkMenu) != 0; 422 } 423 424 /** 425 * Returns whether the menu is torn off. 426 * See gtk_menu_set_tearoff_state(). 427 * 428 * Returns: %TRUE if the menu is currently torn off. 429 */ 430 public bool getTearoffState() 431 { 432 return gtk_menu_get_tearoff_state(gtkMenu) != 0; 433 } 434 435 /** 436 * Returns the title of the menu. See gtk_menu_set_title(). 437 * 438 * Returns: the title of the menu, or %NULL if the menu 439 * has no title set on it. This string is owned by GTK+ 440 * and should not be modified or freed. 441 */ 442 public string getTitle() 443 { 444 return Str.toString(gtk_menu_get_title(gtkMenu)); 445 } 446 447 /** 448 * Places @menu on the given monitor. 449 * 450 * Params: 451 * monitor = the monitor to place the menu on 452 * 453 * Since: 3.22 454 */ 455 public void placeOnMonitor(MonitorG monitor) 456 { 457 gtk_menu_place_on_monitor(gtkMenu, (monitor is null) ? null : monitor.getMonitorGStruct()); 458 } 459 460 /** 461 * Removes the menu from the screen. 462 */ 463 public void popdown() 464 { 465 gtk_menu_popdown(gtkMenu); 466 } 467 468 /** 469 * Displays a menu and makes it available for selection. 470 * 471 * Applications can use this function to display context-sensitive 472 * menus, and will typically supply %NULL for the @parent_menu_shell, 473 * @parent_menu_item, @func and @data parameters. The default menu 474 * positioning function will position the menu at the current mouse 475 * cursor position. 476 * 477 * The @button parameter should be the mouse button pressed to initiate 478 * the menu popup. If the menu popup was initiated by something other 479 * than a mouse button press, such as a mouse button release or a keypress, 480 * @button should be 0. 481 * 482 * The @activate_time parameter is used to conflict-resolve initiation 483 * of concurrent requests for mouse/keyboard grab requests. To function 484 * properly, this needs to be the timestamp of the user event (such as 485 * a mouse click or key press) that caused the initiation of the popup. 486 * Only if no such event is available, gtk_get_current_event_time() can 487 * be used instead. 488 * 489 * Note that this function does not work very well on GDK backends that 490 * do not have global coordinates, such as Wayland or Mir. You should 491 * probably use one of the gtk_menu_popup_at_ variants, which do not 492 * have this problem. 493 * 494 * Deprecated: Please use gtk_menu_popup_at_widget(), 495 * gtk_menu_popup_at_pointer(). or gtk_menu_popup_at_rect() instead 496 * 497 * Params: 498 * parentMenuShell = the menu shell containing the 499 * triggering menu item, or %NULL 500 * parentMenuItem = the menu item whose activation 501 * triggered the popup, or %NULL 502 * func = a user supplied function used to position 503 * the menu, or %NULL 504 * data = user supplied data to be passed to @func. 505 * button = the mouse button which was pressed to initiate the event. 506 * activateTime = the time at which the activation event occurred. 507 */ 508 public void popup(Widget parentMenuShell, Widget parentMenuItem, GtkMenuPositionFunc func, void* data, uint button, uint activateTime) 509 { 510 gtk_menu_popup(gtkMenu, (parentMenuShell is null) ? null : parentMenuShell.getWidgetStruct(), (parentMenuItem is null) ? null : parentMenuItem.getWidgetStruct(), func, data, button, activateTime); 511 } 512 513 /** 514 * Displays @menu and makes it available for selection. 515 * 516 * See gtk_menu_popup_at_widget () to pop up a menu at a widget. 517 * gtk_menu_popup_at_rect () also allows you to position a menu at an arbitrary 518 * rectangle. 519 * 520 * @menu will be positioned at the pointer associated with @trigger_event. 521 * 522 * Properties that influence the behaviour of this function are 523 * #GtkMenu:anchor-hints, #GtkMenu:rect-anchor-dx, #GtkMenu:rect-anchor-dy, and 524 * #GtkMenu:menu-type-hint. Connect to the #GtkMenu::popped-up signal to find 525 * out how it was actually positioned. 526 * 527 * Params: 528 * triggerEvent = the #GdkEvent that initiated this request or 529 * %NULL if it's the current event 530 * 531 * Since: 3.22 532 */ 533 public void popupAtPointer(Event triggerEvent) 534 { 535 gtk_menu_popup_at_pointer(gtkMenu, (triggerEvent is null) ? null : triggerEvent.getEventStruct()); 536 } 537 538 /** 539 * Displays @menu and makes it available for selection. 540 * 541 * See gtk_menu_popup_at_widget () and gtk_menu_popup_at_pointer (), which 542 * handle more common cases for popping up menus. 543 * 544 * @menu will be positioned at @rect, aligning their anchor points. @rect is 545 * relative to the top-left corner of @rect_window. @rect_anchor and 546 * @menu_anchor determine anchor points on @rect and @menu to pin together. 547 * @menu can optionally be offset by #GtkMenu:rect-anchor-dx and 548 * #GtkMenu:rect-anchor-dy. 549 * 550 * Anchors should be specified under the assumption that the text direction is 551 * left-to-right; they will be flipped horizontally automatically if the text 552 * direction is right-to-left. 553 * 554 * Other properties that influence the behaviour of this function are 555 * #GtkMenu:anchor-hints and #GtkMenu:menu-type-hint. Connect to the 556 * #GtkMenu::popped-up signal to find out how it was actually positioned. 557 * 558 * Params: 559 * rectWindow = the #GdkWindow @rect is relative to 560 * rect = the #GdkRectangle to align @menu with 561 * rectAnchor = the point on @rect to align with @menu's anchor point 562 * menuAnchor = the point on @menu to align with @rect's anchor point 563 * triggerEvent = the #GdkEvent that initiated this request or 564 * %NULL if it's the current event 565 * 566 * Since: 3.22 567 */ 568 public void popupAtRect(Window rectWindow, GdkRectangle* rect, GdkGravity rectAnchor, GdkGravity menuAnchor, Event triggerEvent) 569 { 570 gtk_menu_popup_at_rect(gtkMenu, (rectWindow is null) ? null : rectWindow.getWindowStruct(), rect, rectAnchor, menuAnchor, (triggerEvent is null) ? null : triggerEvent.getEventStruct()); 571 } 572 573 /** 574 * Displays @menu and makes it available for selection. 575 * 576 * See gtk_menu_popup_at_pointer () to pop up a menu at the master pointer. 577 * gtk_menu_popup_at_rect () also allows you to position a menu at an arbitrary 578 * rectangle. 579 * 580 * ![](popup-anchors.png) 581 * 582 * @menu will be positioned at @widget, aligning their anchor points. 583 * @widget_anchor and @menu_anchor determine anchor points on @widget and @menu 584 * to pin together. @menu can optionally be offset by #GtkMenu:rect-anchor-dx 585 * and #GtkMenu:rect-anchor-dy. 586 * 587 * Anchors should be specified under the assumption that the text direction is 588 * left-to-right; they will be flipped horizontally automatically if the text 589 * direction is right-to-left. 590 * 591 * Other properties that influence the behaviour of this function are 592 * #GtkMenu:anchor-hints and #GtkMenu:menu-type-hint. Connect to the 593 * #GtkMenu::popped-up signal to find out how it was actually positioned. 594 * 595 * Params: 596 * widget = the #GtkWidget to align @menu with 597 * widgetAnchor = the point on @widget to align with @menu's anchor point 598 * menuAnchor = the point on @menu to align with @widget's anchor point 599 * triggerEvent = the #GdkEvent that initiated this request or 600 * %NULL if it's the current event 601 * 602 * Since: 3.22 603 */ 604 public void popupAtWidget(Widget widget, GdkGravity widgetAnchor, GdkGravity menuAnchor, Event triggerEvent) 605 { 606 gtk_menu_popup_at_widget(gtkMenu, (widget is null) ? null : widget.getWidgetStruct(), widgetAnchor, menuAnchor, (triggerEvent is null) ? null : triggerEvent.getEventStruct()); 607 } 608 609 /** 610 * Displays a menu and makes it available for selection. 611 * 612 * Applications can use this function to display context-sensitive menus, 613 * and will typically supply %NULL for the @parent_menu_shell, 614 * @parent_menu_item, @func, @data and @destroy parameters. The default 615 * menu positioning function will position the menu at the current position 616 * of @device (or its corresponding pointer). 617 * 618 * The @button parameter should be the mouse button pressed to initiate 619 * the menu popup. If the menu popup was initiated by something other than 620 * a mouse button press, such as a mouse button release or a keypress, 621 * @button should be 0. 622 * 623 * The @activate_time parameter is used to conflict-resolve initiation of 624 * concurrent requests for mouse/keyboard grab requests. To function 625 * properly, this needs to be the time stamp of the user event (such as 626 * a mouse click or key press) that caused the initiation of the popup. 627 * Only if no such event is available, gtk_get_current_event_time() can 628 * be used instead. 629 * 630 * Note that this function does not work very well on GDK backends that 631 * do not have global coordinates, such as Wayland or Mir. You should 632 * probably use one of the gtk_menu_popup_at_ variants, which do not 633 * have this problem. 634 * 635 * Deprecated: Please use gtk_menu_popup_at_widget(), 636 * gtk_menu_popup_at_pointer(). or gtk_menu_popup_at_rect() instead 637 * 638 * Params: 639 * device = a #GdkDevice 640 * parentMenuShell = the menu shell containing the triggering 641 * menu item, or %NULL 642 * parentMenuItem = the menu item whose activation triggered 643 * the popup, or %NULL 644 * func = a user supplied function used to position the menu, 645 * or %NULL 646 * data = user supplied data to be passed to @func 647 * destroy = destroy notify for @data 648 * button = the mouse button which was pressed to initiate the event 649 * activateTime = the time at which the activation event occurred 650 * 651 * Since: 3.0 652 */ 653 public void popupForDevice(Device device, Widget parentMenuShell, Widget parentMenuItem, GtkMenuPositionFunc func, void* data, GDestroyNotify destroy, uint button, uint activateTime) 654 { 655 gtk_menu_popup_for_device(gtkMenu, (device is null) ? null : device.getDeviceStruct(), (parentMenuShell is null) ? null : parentMenuShell.getWidgetStruct(), (parentMenuItem is null) ? null : parentMenuItem.getWidgetStruct(), func, data, destroy, button, activateTime); 656 } 657 658 /** 659 * Moves @child to a new @position in the list of @menu 660 * children. 661 * 662 * Params: 663 * child = the #GtkMenuItem to move 664 * position = the new position to place @child. 665 * Positions are numbered from 0 to n - 1 666 */ 667 public void reorderChild(Widget child, int position) 668 { 669 gtk_menu_reorder_child(gtkMenu, (child is null) ? null : child.getWidgetStruct(), position); 670 } 671 672 /** 673 * Repositions the menu according to its position function. 674 */ 675 public void reposition() 676 { 677 gtk_menu_reposition(gtkMenu); 678 } 679 680 /** 681 * Set the #GtkAccelGroup which holds global accelerators for the 682 * menu. This accelerator group needs to also be added to all windows 683 * that this menu is being used in with gtk_window_add_accel_group(), 684 * in order for those windows to support all the accelerators 685 * contained in this group. 686 * 687 * Params: 688 * accelGroup = the #GtkAccelGroup to be associated 689 * with the menu. 690 */ 691 public void setAccelGroup(AccelGroup accelGroup) 692 { 693 gtk_menu_set_accel_group(gtkMenu, (accelGroup is null) ? null : accelGroup.getAccelGroupStruct()); 694 } 695 696 /** 697 * Sets an accelerator path for this menu from which accelerator paths 698 * for its immediate children, its menu items, can be constructed. 699 * The main purpose of this function is to spare the programmer the 700 * inconvenience of having to call gtk_menu_item_set_accel_path() on 701 * each menu item that should support runtime user changable accelerators. 702 * Instead, by just calling gtk_menu_set_accel_path() on their parent, 703 * each menu item of this menu, that contains a label describing its 704 * purpose, automatically gets an accel path assigned. 705 * 706 * For example, a menu containing menu items “New” and “Exit”, will, after 707 * `gtk_menu_set_accel_path (menu, "<Gnumeric-Sheet>/File");` has been 708 * called, assign its items the accel paths: `"<Gnumeric-Sheet>/File/New"` 709 * and `"<Gnumeric-Sheet>/File/Exit"`. 710 * 711 * Assigning accel paths to menu items then enables the user to change 712 * their accelerators at runtime. More details about accelerator paths 713 * and their default setups can be found at gtk_accel_map_add_entry(). 714 * 715 * Note that @accel_path string will be stored in a #GQuark. Therefore, 716 * if you pass a static string, you can save some memory by interning 717 * it first with g_intern_static_string(). 718 * 719 * Params: 720 * accelPath = a valid accelerator path, or %NULL to unset the path 721 */ 722 public void setAccelPath(string accelPath) 723 { 724 gtk_menu_set_accel_path(gtkMenu, Str.toStringz(accelPath)); 725 } 726 727 /** 728 * Selects the specified menu item within the menu. This is used by 729 * the #GtkComboBox and should not be used by anyone else. 730 * 731 * Params: 732 * index = the index of the menu item to select. Index values are 733 * from 0 to n-1 734 */ 735 public void setActive(uint index) 736 { 737 gtk_menu_set_active(gtkMenu, index); 738 } 739 740 /** 741 * Informs GTK+ on which monitor a menu should be popped up. 742 * See gdk_monitor_get_geometry(). 743 * 744 * This function should be called from a #GtkMenuPositionFunc 745 * if the menu should not appear on the same monitor as the pointer. 746 * This information can’t be reliably inferred from the coordinates 747 * returned by a #GtkMenuPositionFunc, since, for very long menus, 748 * these coordinates may extend beyond the monitor boundaries or even 749 * the screen boundaries. 750 * 751 * Params: 752 * monitorNum = the number of the monitor on which the menu should 753 * be popped up 754 * 755 * Since: 2.4 756 */ 757 public void setMonitor(int monitorNum) 758 { 759 gtk_menu_set_monitor(gtkMenu, monitorNum); 760 } 761 762 /** 763 * Sets whether the menu should reserve space for drawing toggles 764 * or icons, regardless of their actual presence. 765 * 766 * Params: 767 * reserveToggleSize = whether to reserve size for toggles 768 * 769 * Since: 2.18 770 */ 771 public void setReserveToggleSize(bool reserveToggleSize) 772 { 773 gtk_menu_set_reserve_toggle_size(gtkMenu, reserveToggleSize); 774 } 775 776 /** 777 * Sets the #GdkScreen on which the menu will be displayed. 778 * 779 * Params: 780 * screen = a #GdkScreen, or %NULL if the screen should be 781 * determined by the widget the menu is attached to 782 * 783 * Since: 2.2 784 */ 785 public void setScreen(Screen screen) 786 { 787 gtk_menu_set_screen(gtkMenu, (screen is null) ? null : screen.getScreenStruct()); 788 } 789 790 /** 791 * Changes the tearoff state of the menu. A menu is normally 792 * displayed as drop down menu which persists as long as the menu is 793 * active. It can also be displayed as a tearoff menu which persists 794 * until it is closed or reattached. 795 * 796 * Params: 797 * tornOff = If %TRUE, menu is displayed as a tearoff menu. 798 */ 799 public void setTearoffState(bool tornOff) 800 { 801 gtk_menu_set_tearoff_state(gtkMenu, tornOff); 802 } 803 804 /** 805 * Sets the title string for the menu. 806 * 807 * The title is displayed when the menu is shown as a tearoff 808 * menu. If @title is %NULL, the menu will see if it is attached 809 * to a parent menu item, and if so it will try to use the same 810 * text as that menu item’s label. 811 * 812 * Params: 813 * title = a string containing the title for the menu, or %NULL to 814 * inherit the title of the parent menu item, if any 815 */ 816 public void setTitle(string title) 817 { 818 gtk_menu_set_title(gtkMenu, Str.toStringz(title)); 819 } 820 821 /** */ 822 gulong addOnMoveScroll(void delegate(GtkScrollType, Menu) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 823 { 824 return Signals.connect(this, "move-scroll", dlg, connectFlags ^ ConnectFlags.SWAPPED); 825 } 826 827 /** 828 * Emitted when the position of @menu is finalized after being popped up 829 * using gtk_menu_popup_at_rect (), gtk_menu_popup_at_widget (), or 830 * gtk_menu_popup_at_pointer (). 831 * 832 * @menu might be flipped over the anchor rectangle in order to keep it 833 * on-screen, in which case @flipped_x and @flipped_y will be set to %TRUE 834 * accordingly. 835 * 836 * @flipped_rect is the ideal position of @menu after any possible flipping, 837 * but before any possible sliding. @final_rect is @flipped_rect, but possibly 838 * translated in the case that flipping is still ineffective in keeping @menu 839 * on-screen. 840 * 841 * ![](popup-slide.png) 842 * 843 * The blue menu is @menu's ideal position, the green menu is @flipped_rect, 844 * and the red menu is @final_rect. 845 * 846 * See gtk_menu_popup_at_rect (), gtk_menu_popup_at_widget (), 847 * gtk_menu_popup_at_pointer (), #GtkMenu:anchor-hints, 848 * #GtkMenu:rect-anchor-dx, #GtkMenu:rect-anchor-dy, and 849 * #GtkMenu:menu-type-hint. 850 * 851 * Params: 852 * flippedRect = the position of @menu after any possible 853 * flipping or %NULL if the backend can't obtain it 854 * finalRect = the final position of @menu or %NULL if the 855 * backend can't obtain it 856 * flippedX = %TRUE if the anchors were flipped horizontally 857 * flippedY = %TRUE if the anchors were flipped vertically 858 * 859 * Since: 3.22 860 */ 861 gulong addOnPoppedUp(void delegate(void*, void*, bool, bool, Menu) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 862 { 863 return Signals.connect(this, "popped-up", dlg, connectFlags ^ ConnectFlags.SWAPPED); 864 } 865 }