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 = GtkMenu.html 27 * outPack = gtk 28 * outFile = Menu 29 * strct = GtkMenu 30 * realStrct= 31 * ctorStrct= 32 * clss = Menu 33 * interf = 34 * class Code: Yes 35 * interface Code: No 36 * template for: 37 * extend = 38 * implements: 39 * prefixes: 40 * - gtk_menu_ 41 * - gtk_ 42 * omit structs: 43 * omit prefixes: 44 * omit code: 45 * omit signals: 46 * imports: 47 * - glib.Str 48 * - gtk.Widget 49 * - gdk.Screen 50 * - gtk.AccelGroup 51 * - glib.ListG 52 * - gtk.MenuItem 53 * structWrap: 54 * - GList* -> ListG 55 * - GdkScreen* -> Screen 56 * - GtkAccelGroup* -> AccelGroup 57 * - GtkWidget* -> Widget 58 * module aliases: 59 * local aliases: 60 * overrides: 61 */ 62 63 module gtk.Menu; 64 65 public import gtkc.gtktypes; 66 67 private import gtkc.gtk; 68 private import glib.ConstructionException; 69 private import gobject.ObjectG; 70 71 private import gobject.Signals; 72 public import gtkc.gdktypes; 73 74 private import glib.Str; 75 private import gtk.Widget; 76 private import gdk.Screen; 77 private import gtk.AccelGroup; 78 private import glib.ListG; 79 private import gtk.MenuItem; 80 81 82 83 private import gtk.MenuShell; 84 85 /** 86 * Description 87 * A GtkMenu is a GtkMenuShell that implements a drop down menu consisting of 88 * a list of GtkMenuItem objects which can be navigated and activated by the 89 * user to perform application functions. 90 * A GtkMenu is most commonly dropped down by activating a GtkMenuItem in a 91 * GtkMenuBar or popped up by activating a GtkMenuItem in another GtkMenu. 92 * A GtkMenu can also be popped up by activating a GtkOptionMenu. 93 * Other composite widgets such as the GtkNotebook can pop up a GtkMenu 94 * as well. 95 * Applications can display a GtkMenu as a popup menu by calling the 96 * gtk_menu_popup() function. The example below shows how an application 97 * can pop up a menu when the 3rd mouse button is pressed. 98 * $(DDOC_COMMENT example) 99 * $(DDOC_COMMENT example) 100 */ 101 public class Menu : MenuShell 102 { 103 104 /** the main Gtk struct */ 105 protected GtkMenu* gtkMenu; 106 107 108 public GtkMenu* getMenuStruct() 109 { 110 return gtkMenu; 111 } 112 113 114 /** the main Gtk struct as a void* */ 115 protected override void* getStruct() 116 { 117 return cast(void*)gtkMenu; 118 } 119 120 /** 121 * Sets our main struct and passes it to the parent class 122 */ 123 public this (GtkMenu* gtkMenu) 124 { 125 super(cast(GtkMenuShell*)gtkMenu); 126 this.gtkMenu = gtkMenu; 127 } 128 129 protected override void setStruct(GObject* obj) 130 { 131 super.setStruct(obj); 132 gtkMenu = cast(GtkMenu*)obj; 133 } 134 135 /** 136 * Popups up this menu 137 * Params: 138 * button = you can pass a button number here 139 * activateTime = you can pass the time from an event here 140 */ 141 void popup(guint button, guint32 activateTime) 142 { 143 popup(null, null, null, null, button, activateTime); 144 } 145 146 /** 147 * Creates and append a submenu to this menu. 148 * This menu item that actualy has the sub menu is also created. 149 * Params: 150 * label = the sub menu item label 151 * Returns: the new menu 152 */ 153 Menu appendSubmenu(string label) 154 { 155 MenuItem item = new MenuItem(label); 156 append(item); 157 Menu submenu = new Menu(); 158 item.setSubmenu(submenu); 159 return submenu; 160 } 161 162 /** */ 163 void appendSubmenu(string label, Menu submenu) 164 { 165 MenuItem item = new MenuItem(label); 166 append(item); 167 item.setSubmenu(submenu); 168 } 169 170 /** */ 171 Menu prependSubmenu(string label) 172 { 173 MenuItem item = new MenuItem(label); 174 prepend(item); 175 Menu submenu = new Menu(); 176 item.setSubmenu(submenu); 177 return submenu; 178 } 179 180 /** 181 */ 182 int[string] connectedSignals; 183 184 void delegate(GtkScrollType, Menu)[] onMoveScrollListeners; 185 /** 186 */ 187 void addOnMoveScroll(void delegate(GtkScrollType, Menu) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 188 { 189 if ( !("move-scroll" in connectedSignals) ) 190 { 191 Signals.connectData( 192 getStruct(), 193 "move-scroll", 194 cast(GCallback)&callBackMoveScroll, 195 cast(void*)this, 196 null, 197 connectFlags); 198 connectedSignals["move-scroll"] = 1; 199 } 200 onMoveScrollListeners ~= dlg; 201 } 202 extern(C) static void callBackMoveScroll(GtkMenu* menuStruct, GtkScrollType arg1, Menu _menu) 203 { 204 foreach ( void delegate(GtkScrollType, Menu) dlg ; _menu.onMoveScrollListeners ) 205 { 206 dlg(arg1, _menu); 207 } 208 } 209 210 211 /** 212 * Creates a new GtkMenu. 213 * Throws: ConstructionException GTK+ fails to create the object. 214 */ 215 public this () 216 { 217 // GtkWidget * gtk_menu_new (void); 218 auto p = gtk_menu_new(); 219 if(p is null) 220 { 221 throw new ConstructionException("null returned by gtk_menu_new()"); 222 } 223 this(cast(GtkMenu*) p); 224 } 225 226 /** 227 * Sets the GdkScreen on which the menu will be displayed. 228 * Since 2.2 229 * Params: 230 * screen = a GdkScreen, or NULL if the screen should be 231 * determined by the widget the menu is attached to. [allow-none] 232 */ 233 public void setScreen(Screen screen) 234 { 235 // void gtk_menu_set_screen (GtkMenu *menu, GdkScreen *screen); 236 gtk_menu_set_screen(gtkMenu, (screen is null) ? null : screen.getScreenStruct()); 237 } 238 239 /** 240 * Moves a GtkMenuItem to a new position within the GtkMenu. 241 * Params: 242 * child = the GtkMenuItem to move. 243 * position = the new position to place child. Positions are numbered from 244 * 0 to n-1. 245 */ 246 public void reorderChild(Widget child, int position) 247 { 248 // void gtk_menu_reorder_child (GtkMenu *menu, GtkWidget *child, gint position); 249 gtk_menu_reorder_child(gtkMenu, (child is null) ? null : child.getWidgetStruct(), position); 250 } 251 252 /** 253 * Adds a new GtkMenuItem to a (table) menu. The number of 'cells' that 254 * an item will occupy is specified by left_attach, right_attach, 255 * top_attach and bottom_attach. These each represent the leftmost, 256 * rightmost, uppermost and lower column and row numbers of the table. 257 * (Columns and rows are indexed from zero). 258 * Note that this function is not related to gtk_menu_detach(). 259 * Since 2.4 260 * Params: 261 * child = a GtkMenuItem. 262 * leftAttach = The column number to attach the left side of the item to. 263 * rightAttach = The column number to attach the right side of the item to. 264 * topAttach = The row number to attach the top of the item to. 265 * bottomAttach = The row number to attach the bottom of the item to. 266 */ 267 public void attach(Widget child, uint leftAttach, uint rightAttach, uint topAttach, uint bottomAttach) 268 { 269 // void gtk_menu_attach (GtkMenu *menu, GtkWidget *child, guint left_attach, guint right_attach, guint top_attach, guint bottom_attach); 270 gtk_menu_attach(gtkMenu, (child is null) ? null : child.getWidgetStruct(), leftAttach, rightAttach, topAttach, bottomAttach); 271 } 272 273 /** 274 * Displays a menu and makes it available for selection. Applications can use 275 * this function to display context-sensitive menus, and will typically supply 276 * NULL for the parent_menu_shell, parent_menu_item, func and data 277 * parameters. The default menu positioning function will position the menu 278 * at the current mouse cursor position. 279 * The button parameter should be the mouse button pressed to initiate 280 * the menu popup. If the menu popup was initiated by something other than 281 * a mouse button press, such as a mouse button release or a keypress, 282 * button should be 0. 283 * The activate_time parameter is used to conflict-resolve initiation of 284 * concurrent requests for mouse/keyboard grab requests. To function 285 * properly, this needs to be the time stamp of the user event (such as 286 * a mouse click or key press) that caused the initiation of the popup. 287 * Only if no such event is available, gtk_get_current_event_time() can 288 * be used instead. 289 * Params: 290 * parentMenuShell = the menu shell containing the triggering menu item, or NULL. [allow-none] 291 * parentMenuItem = the menu item whose activation triggered the popup, or NULL. [allow-none] 292 * func = a user supplied function used to position the menu, or NULL. [allow-none] 293 * data = user supplied data to be passed to func. [allow-none] 294 * button = the mouse button which was pressed to initiate the event. 295 * activateTime = the time at which the activation event occurred. 296 */ 297 public void popup(Widget parentMenuShell, Widget parentMenuItem, GtkMenuPositionFunc func, void* data, uint button, uint activateTime) 298 { 299 // void gtk_menu_popup (GtkMenu *menu, GtkWidget *parent_menu_shell, GtkWidget *parent_menu_item, GtkMenuPositionFunc func, gpointer data, guint button, guint32 activate_time); 300 gtk_menu_popup(gtkMenu, (parentMenuShell is null) ? null : parentMenuShell.getWidgetStruct(), (parentMenuItem is null) ? null : parentMenuItem.getWidgetStruct(), func, data, button, activateTime); 301 } 302 303 /** 304 * Set the GtkAccelGroup which holds global accelerators for the menu. 305 * This accelerator group needs to also be added to all windows that 306 * this menu is being used in with gtk_window_add_accel_group(), in order 307 * for those windows to support all the accelerators contained in this group. 308 * Params: 309 * accelGroup = . [allow-none] 310 */ 311 public void setAccelGroup(AccelGroup accelGroup) 312 { 313 // void gtk_menu_set_accel_group (GtkMenu *menu, GtkAccelGroup *accel_group); 314 gtk_menu_set_accel_group(gtkMenu, (accelGroup is null) ? null : accelGroup.getAccelGroupStruct()); 315 } 316 317 /** 318 * Gets the GtkAccelGroup which holds global accelerators for the 319 * menu. See gtk_menu_set_accel_group(). 320 * Gets the GtkAccelGroup which holds global accelerators for the menu. 321 * See gtk_menu_set_accel_group(). 322 * Returns: the GtkAccelGroup associated with the menu. [transfer none] 323 */ 324 public AccelGroup getAccelGroup() 325 { 326 // GtkAccelGroup * gtk_menu_get_accel_group (GtkMenu *menu); 327 auto p = gtk_menu_get_accel_group(gtkMenu); 328 329 if(p is null) 330 { 331 return null; 332 } 333 334 return ObjectG.getDObject!(AccelGroup)(cast(GtkAccelGroup*) p); 335 } 336 337 /** 338 * Sets an accelerator path for this menu from which accelerator paths 339 * for its immediate children, its menu items, can be constructed. 340 * The main purpose of this function is to spare the programmer the 341 * inconvenience of having to call gtk_menu_item_set_accel_path() on 342 * each menu item that should support runtime user changable accelerators. 343 * Instead, by just calling gtk_menu_set_accel_path() on their parent, 344 * each menu item of this menu, that contains a label describing its purpose, 345 * automatically gets an accel path assigned. For example, a menu containing 346 * menu items "New" and "Exit", will, after 347 * gtk_menu_set_accel_path (menu, "<Gnumeric-Sheet>/File"); 348 * Params: 349 * accelPath = a valid accelerator path. [allow-none] 350 */ 351 public void setAccelPath(string accelPath) 352 { 353 // void gtk_menu_set_accel_path (GtkMenu *menu, const gchar *accel_path); 354 gtk_menu_set_accel_path(gtkMenu, Str.toStringz(accelPath)); 355 } 356 357 /** 358 * Retrieves the accelerator path set on the menu. 359 * Since 2.14 360 * Returns: the accelerator path set on the menu. 361 */ 362 public string getAccelPath() 363 { 364 // const gchar * gtk_menu_get_accel_path (GtkMenu *menu); 365 return Str.toString(gtk_menu_get_accel_path(gtkMenu)); 366 } 367 368 /** 369 * Sets the title string for the menu. The title is displayed when the menu 370 * is shown as a tearoff menu. If title is NULL, the menu will see if it is 371 * attached to a parent menu item, and if so it will try to use the same text as 372 * that menu item's label. 373 * Params: 374 * title = a string containing the title for the menu. 375 */ 376 public void setTitle(string title) 377 { 378 // void gtk_menu_set_title (GtkMenu *menu, const gchar *title); 379 gtk_menu_set_title(gtkMenu, Str.toStringz(title)); 380 } 381 382 /** 383 * Returns the title of the menu. See gtk_menu_set_title(). 384 * Returns: the title of the menu, or NULL if the menu has no title set on it. This string is owned by the widget and should not be modified or freed. 385 */ 386 public string getTitle() 387 { 388 // const gchar * gtk_menu_get_title (GtkMenu *menu); 389 return Str.toString(gtk_menu_get_title(gtkMenu)); 390 } 391 392 /** 393 * Informs GTK+ on which monitor a menu should be popped up. 394 * See gdk_screen_get_monitor_geometry(). 395 * This function should be called from a GtkMenuPositionFunc if the 396 * menu should not appear on the same monitor as the pointer. This 397 * information can't be reliably inferred from the coordinates returned 398 * by a GtkMenuPositionFunc, since, for very long menus, these coordinates 399 * may extend beyond the monitor boundaries or even the screen boundaries. 400 * Since 2.4 401 * Params: 402 * monitorNum = the number of the monitor on which the menu should 403 * be popped up 404 */ 405 public void setMonitor(int monitorNum) 406 { 407 // void gtk_menu_set_monitor (GtkMenu *menu, gint monitor_num); 408 gtk_menu_set_monitor(gtkMenu, monitorNum); 409 } 410 411 /** 412 * Retrieves the number of the monitor on which to show the menu. 413 * Since 2.14 414 * Returns: the number of the monitor on which the menu should be popped up or -1, if no monitor has been set 415 */ 416 public int getMonitor() 417 { 418 // gint gtk_menu_get_monitor (GtkMenu *menu); 419 return gtk_menu_get_monitor(gtkMenu); 420 } 421 422 /** 423 * Returns whether the menu is torn off. See 424 * gtk_menu_set_tearoff_state(). 425 * Returns: TRUE if the menu is currently torn off. 426 */ 427 public int getTearoffState() 428 { 429 // gboolean gtk_menu_get_tearoff_state (GtkMenu *menu); 430 return gtk_menu_get_tearoff_state(gtkMenu); 431 } 432 433 /** 434 * Sets whether the menu should reserve space for drawing toggles 435 * or icons, regardless of their actual presence. 436 * Since 2.18 437 * Params: 438 * reserveToggleSize = whether to reserve size for toggles 439 */ 440 public void setReserveToggleSize(int reserveToggleSize) 441 { 442 // void gtk_menu_set_reserve_toggle_size (GtkMenu *menu, gboolean reserve_toggle_size); 443 gtk_menu_set_reserve_toggle_size(gtkMenu, reserveToggleSize); 444 } 445 446 /** 447 * Returns whether the menu reserves space for toggles and 448 * icons, regardless of their actual presence. 449 * Since 2.18 450 * Returns: Whether the menu reserves toggle space 451 */ 452 public int getReserveToggleSize() 453 { 454 // gboolean gtk_menu_get_reserve_toggle_size (GtkMenu *menu); 455 return gtk_menu_get_reserve_toggle_size(gtkMenu); 456 } 457 458 /** 459 * Removes the menu from the screen. 460 */ 461 public void popdown() 462 { 463 // void gtk_menu_popdown (GtkMenu *menu); 464 gtk_menu_popdown(gtkMenu); 465 } 466 467 /** 468 * Repositions the menu according to its position function. 469 */ 470 public void reposition() 471 { 472 // void gtk_menu_reposition (GtkMenu *menu); 473 gtk_menu_reposition(gtkMenu); 474 } 475 476 /** 477 * Returns the selected menu item from the menu. This is used by the 478 * GtkOptionMenu. 479 * Returns the selected menu item from the menu. This is used by the 480 * GtkOptionMenu. 481 * Returns: the GtkMenuItem that was last selected in the menu. If a selection has not yet been made, the first menu item is selected. [transfer none] 482 */ 483 public Widget getActive() 484 { 485 // GtkWidget * gtk_menu_get_active (GtkMenu *menu); 486 auto p = gtk_menu_get_active(gtkMenu); 487 488 if(p is null) 489 { 490 return null; 491 } 492 493 return ObjectG.getDObject!(Widget)(cast(GtkWidget*) p); 494 } 495 496 /** 497 * Selects the specified menu item within the menu. This is used by the 498 * GtkOptionMenu and should not be used by anyone else. 499 * Params: 500 * index = the index of the menu item to select. Index values are from 501 * 0 to n-1. 502 */ 503 public void setActive(uint index) 504 { 505 // void gtk_menu_set_active (GtkMenu *menu, guint index_); 506 gtk_menu_set_active(gtkMenu, index); 507 } 508 509 /** 510 * Changes the tearoff state of the menu. A menu is normally displayed 511 * as drop down menu which persists as long as the menu is active. It can 512 * also be displayed as a tearoff menu which persists until it is closed 513 * or reattached. 514 * Params: 515 * tornOff = If TRUE, menu is displayed as a tearoff menu. 516 */ 517 public void setTearoffState(int tornOff) 518 { 519 // void gtk_menu_set_tearoff_state (GtkMenu *menu, gboolean torn_off); 520 gtk_menu_set_tearoff_state(gtkMenu, tornOff); 521 } 522 523 /** 524 * Attaches the menu to the widget and provides a callback function that will 525 * be invoked when the menu calls gtk_menu_detach() during its destruction. 526 * Params: 527 * attachWidget = the GtkWidget that the menu will be attached to. 528 * detacher = the user supplied callback function that will be called when 529 * the menu calls gtk_menu_detach(). 530 */ 531 public void attachToWidget(Widget attachWidget, GtkMenuDetachFunc detacher) 532 { 533 // void gtk_menu_attach_to_widget (GtkMenu *menu, GtkWidget *attach_widget, GtkMenuDetachFunc detacher); 534 gtk_menu_attach_to_widget(gtkMenu, (attachWidget is null) ? null : attachWidget.getWidgetStruct(), detacher); 535 } 536 537 /** 538 * Detaches the menu from the widget to which it had been attached. 539 * This function will call the callback function, detacher, provided 540 * when the gtk_menu_attach_to_widget() function was called. 541 */ 542 public void detach() 543 { 544 // void gtk_menu_detach (GtkMenu *menu); 545 gtk_menu_detach(gtkMenu); 546 } 547 548 /** 549 * Returns the GtkWidget that the menu is attached to. 550 * Returns the GtkWidget that the menu is attached to. 551 * Returns: the GtkWidget that the menu is attached to. [transfer none] 552 */ 553 public Widget getAttachWidget() 554 { 555 // GtkWidget * gtk_menu_get_attach_widget (GtkMenu *menu); 556 auto p = gtk_menu_get_attach_widget(gtkMenu); 557 558 if(p is null) 559 { 560 return null; 561 } 562 563 return ObjectG.getDObject!(Widget)(cast(GtkWidget*) p); 564 } 565 566 /** 567 * Returns a list of the menus which are attached to this widget. 568 * This list is owned by GTK+ and must not be modified. 569 * Since 2.6 570 * Params: 571 * widget = a GtkWidget 572 * Returns: the list of menus attached to his widget. [element-type GtkWidget][transfer none] 573 */ 574 public static ListG getForAttachWidget(Widget widget) 575 { 576 // GList * gtk_menu_get_for_attach_widget (GtkWidget *widget); 577 auto p = gtk_menu_get_for_attach_widget((widget is null) ? null : widget.getWidgetStruct()); 578 579 if(p is null) 580 { 581 return null; 582 } 583 584 return ObjectG.getDObject!(ListG)(cast(GList*) p); 585 } 586 }