alternative to assert
[gtkD.git] / gtkD / src / gtk / Menu.d
blobf9e329bd7e12e60ea6c87ae1e88ea63bf8c06211
1 /*
2 * This file is part of gtkD.
4 * gtkD is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU Lesser General Public License as published by
6 * the Free Software Foundation; either version 2.1 of the License, or
7 * (at your option) any later version.
9 * gtkD is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public License
15 * along with gtkD; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 // generated automatically - do not change
20 // find conversion definition on APILookup.txt
21 // implement new conversion functionalities on the wrap.utils pakage
24 * Conversion parameters:
25 * inFile = GtkMenu.html
26 * outPack = gtk
27 * outFile = Menu
28 * strct = GtkMenu
29 * realStrct=
30 * ctorStrct=
31 * clss = Menu
32 * interf =
33 * class Code: Yes
34 * interface Code: No
35 * template for:
36 * extend =
37 * implements:
38 * prefixes:
39 * - gtk_menu_
40 * - gtk_
41 * omit structs:
42 * omit prefixes:
43 * omit code:
44 * imports:
45 * - glib.Str
46 * - gtk.Widget
47 * - gdk.Screen
48 * - gtk.AccelGroup
49 * - glib.ListG
50 * - gtk.MenuItem
51 * structWrap:
52 * - GList* -> ListG
53 * - GdkScreen* -> Screen
54 * - GtkAccelGroup* -> AccelGroup
55 * - GtkWidget* -> Widget
56 * module aliases:
57 * local aliases:
60 module gtk.Menu;
62 version(noAssert)
64 version(Tango)
66 import tango.io.Stdout; // use the tango loging?
70 private import gtkc.gtktypes;
72 private import gtkc.gtk;
75 private import glib.Str;
76 private import gtk.Widget;
77 private import gdk.Screen;
78 private import gtk.AccelGroup;
79 private import glib.ListG;
80 private import gtk.MenuItem;
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 * Example1.Connecting the popup signal handler.
99 * /+* connect our handler which will popup the menu +/
100 * g_signal_connect_swapped (window, "button_press_event",
101 * G_CALLBACK (my_popup_handler), menu);
102 * Example2.Signal handler which displays a popup menu.
103 * static gint
104 * my_popup_handler (GtkWidget *widget, GdkEvent *event)
106 * GtkMenu *menu;
107 * GdkEventButton *event_button;
108 * g_return_val_if_fail (widget != NULL, FALSE);
109 * g_return_val_if_fail (GTK_IS_MENU (widget), FALSE);
110 * g_return_val_if_fail (event != NULL, FALSE);
111 * /+* The "widget" is the menu that was supplied when
112 * * g_signal_connect_swapped() was called.
113 * +/
114 * menu = GTK_MENU (widget);
115 * if (event->type == GDK_BUTTON_PRESS)
117 * event_button = (GdkEventButton *) event;
118 * if (event_button->button == 3)
120 * gtk_menu_popup (menu, NULL, NULL, NULL, NULL,
121 * event_button->button, event_button->time);
122 * return TRUE;
125 * return FALSE;
128 private import gtk.MenuShell;
129 public class Menu : MenuShell
132 /** the main Gtk struct */
133 protected GtkMenu* gtkMenu;
136 public GtkMenu* getMenuStruct()
138 return gtkMenu;
142 /** the main Gtk struct as a void* */
143 protected void* getStruct()
145 return cast(void*)gtkMenu;
149 * Sets our main struct and passes it to the parent class
151 public this (GtkMenu* gtkMenu)
153 version(noAssert)
155 if ( gtkMenu is null )
157 int zero = 0;
158 version(Tango)
160 Stdout("struct gtkMenu is null on constructor").newline;
162 else
164 printf("struct gtkMenu is null on constructor");
166 zero = zero / zero;
169 else
171 assert(gtkMenu !is null, "struct gtkMenu is null on constructor");
173 super(cast(GtkMenuShell*)gtkMenu);
174 this.gtkMenu = gtkMenu;
177 public void append(Widget widget)
179 super.append(widget);
183 * Popups up this menu
184 * @param button ??? you can pass a button number here
185 * @param activateTime ??? you can pass the time from an event here
187 void popup(guint button, guint32 activateTime)
189 popup(null, null, null, null, button, activateTime);
193 * Creates and append a submenu to this menu.
194 * This menu item that actualy has the sub menu is also created.
195 * @param label the sub menu item label
196 * @return the new menu
198 Menu appendSubmenu(char[] label)
200 MenuItem item = new MenuItem(label);
201 append(item);
202 Menu submenu = new Menu();
203 item.setSubmenu(submenu);
204 return submenu;
207 void appendSubmenu(char[] label, Menu submenu)
209 MenuItem item = new MenuItem(label);
210 append(item);
211 item.setSubmenu(submenu);
214 Menu prependSubmenu(char[] label)
216 MenuItem item = new MenuItem(label);
217 prepend(item);
218 Menu submenu = new Menu();
219 item.setSubmenu(submenu);
220 return submenu;
227 // imports for the signal processing
228 private import gobject.Signals;
229 private import gtkc.gdktypes;
230 int[char[]] connectedSignals;
232 void delegate(GtkScrollType, Menu)[] onMoveScrollListeners;
233 void addOnMoveScroll(void delegate(GtkScrollType, Menu) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
235 if ( !("move-scroll" in connectedSignals) )
237 Signals.connectData(
238 getStruct(),
239 "move-scroll",
240 cast(GCallback)&callBackMoveScroll,
241 cast(void*)this,
242 null,
243 connectFlags);
244 connectedSignals["move-scroll"] = 1;
246 onMoveScrollListeners ~= dlg;
248 extern(C) static void callBackMoveScroll(GtkMenu* menuStruct, GtkScrollType arg1, Menu menu)
250 bool consumed = false;
252 foreach ( void delegate(GtkScrollType, Menu) dlg ; menu.onMoveScrollListeners )
254 dlg(arg1, menu);
257 return consumed;
263 * Creates a new GtkMenu.
264 * Returns:
265 * a new GtkMenu.
267 public this ()
269 // GtkWidget* gtk_menu_new (void);
270 this(cast(GtkMenu*)gtk_menu_new() );
274 * Sets the GdkScreen on which the menu will be displayed.
275 * menu:
276 * a GtkMenu.
277 * screen:
278 * a GdkScreen, or NULL if the screen should be
279 * determined by the widget the menu is attached to.
280 * Since 2.2
282 public void setScreen(Screen screen)
284 // void gtk_menu_set_screen (GtkMenu *menu, GdkScreen *screen);
285 gtk_menu_set_screen(gtkMenu, (screen is null) ? null : screen.getScreenStruct());
292 * Moves a GtkMenuItem to a new position within the GtkMenu.
293 * menu:
294 * a GtkMenu.
295 * child:
296 * the GtkMenuItem to move.
297 * position:
298 * the new position to place child. Positions are numbered from
299 * 0 to n-1.
301 public void reorderChild(Widget child, int position)
303 // void gtk_menu_reorder_child (GtkMenu *menu, GtkWidget *child, gint position);
304 gtk_menu_reorder_child(gtkMenu, (child is null) ? null : child.getWidgetStruct(), position);
308 * Adds a new GtkMenuItem to a (table) menu. The number of 'cells' that
309 * an item will occupy is specified by left_attach, right_attach,
310 * top_attach and bottom_attach. These each represent the leftmost,
311 * rightmost, uppermost and lower column and row numbers of the table.
312 * (Columns and rows are indexed from zero).
313 * Note that this function is not related to gtk_menu_detach().
314 * menu:
315 * a GtkMenu.
316 * child:
317 * a GtkMenuItem.
318 * left_attach:
319 * The column number to attach the left side of the item to.
320 * right_attach:
321 * The column number to attach the right side of the item to.
322 * top_attach:
323 * The row number to attach the top of the item to.
324 * bottom_attach:
325 * The row number to attach the bottom of the item to.
326 * Since 2.4
328 public void attach(Widget child, uint leftAttach, uint rightAttach, uint topAttach, uint bottomAttach)
330 // void gtk_menu_attach (GtkMenu *menu, GtkWidget *child, guint left_attach, guint right_attach, guint top_attach, guint bottom_attach);
331 gtk_menu_attach(gtkMenu, (child is null) ? null : child.getWidgetStruct(), leftAttach, rightAttach, topAttach, bottomAttach);
335 * Displays a menu and makes it available for selection. Applications can use
336 * this function to display context-sensitive menus, and will typically supply
337 * NULL for the parent_menu_shell, parent_menu_item, func and data
338 * parameters. The default menu positioning function will position the menu
339 * at the current mouse cursor position.
340 * The button parameter should be the mouse button pressed to initiate
341 * the menu popup. If the menu popup was initiated by something other than
342 * a mouse button press, such as a mouse button release or a keypress,
343 * button should be 0.
344 * The activate_time parameter should be the time stamp of the event that
345 * initiated the popup. If such an event is not available, use
346 * gtk_get_current_event_time() instead.
347 * menu:
348 * a GtkMenu.
349 * parent_menu_shell:
350 * the menu shell containing the triggering menu item, or NULL
351 * parent_menu_item:
352 * the menu item whose activation triggered the popup, or NULL
353 * func:
354 * a user supplied function used to position the menu, or NULL
355 * data:
356 * user supplied data to be passed to func.
357 * button:
358 * the mouse button which was pressed to initiate the event.
359 * activate_time:
360 * the time at which the activation event occurred.
362 public void popup(Widget parentMenuShell, Widget parentMenuItem, GtkMenuPositionFunc func, void* data, uint button, uint activateTime)
364 // void gtk_menu_popup (GtkMenu *menu, GtkWidget *parent_menu_shell, GtkWidget *parent_menu_item, GtkMenuPositionFunc func, gpointer data, guint button, guint32 activate_time);
365 gtk_menu_popup(gtkMenu, (parentMenuShell is null) ? null : parentMenuShell.getWidgetStruct(), (parentMenuItem is null) ? null : parentMenuItem.getWidgetStruct(), func, data, button, activateTime);
369 * Set the GtkAccelGroup which holds global accelerators for the menu.
370 * This accelerator group needs to also be added to all windows that
371 * this menu is being used in with gtk_window_add_accel_group(), in order
372 * for those windows to support all the accelerators contained in this group.
373 * menu:
374 * a GtkMenu.
375 * accel_group:
376 * the GtkAccelGroup to be associated with the menu.
378 public void setAccelGroup(AccelGroup accelGroup)
380 // void gtk_menu_set_accel_group (GtkMenu *menu, GtkAccelGroup *accel_group);
381 gtk_menu_set_accel_group(gtkMenu, (accelGroup is null) ? null : accelGroup.getAccelGroupStruct());
385 * Gets the GtkAccelGroup which holds global accelerators for the menu.
386 * See gtk_menu_set_accel_group().
387 * menu:
388 * a GtkMenu.
389 * Returns:
390 * the GtkAccelGroup associated with the menu.
392 public AccelGroup getAccelGroup()
394 // GtkAccelGroup* gtk_menu_get_accel_group (GtkMenu *menu);
395 return new AccelGroup( gtk_menu_get_accel_group(gtkMenu) );
399 * Sets an accelerator path for this menu from which accelerator paths
400 * for its immediate children, its menu items, can be constructed.
401 * The main purpose of this function is to spare the programmer the
402 * inconvenience of having to call gtk_menu_item_set_accel_path() on
403 * each menu item that should support runtime user changable accelerators.
404 * Instead, by just calling gtk_menu_set_accel_path() on their parent,
405 * each menu item of this menu, that contains a label describing its purpose,
406 * automatically gets an accel path assigned. For example, a menu containing
407 * menu items "New" and "Exit", will, after
408 * gtk_menu_set_accel_path (menu, "<Gnumeric-Sheet>/File");
409 * has been called, assign its items the accel paths:
410 * "<Gnumeric-Sheet>/File/New" and "<Gnumeric-Sheet>/File/Exit".
411 * Assigning accel paths to menu items then enables the user to change
412 * their accelerators at runtime. More details about accelerator paths
413 * and their default setups can be found at gtk_accel_map_add_entry().
414 * menu:
415 * a valid GtkMenu
416 * accel_path:
417 * a valid accelerator path
419 public void setAccelPath(char[] accelPath)
421 // void gtk_menu_set_accel_path (GtkMenu *menu, const gchar *accel_path);
422 gtk_menu_set_accel_path(gtkMenu, Str.toStringz(accelPath));
426 * Sets the title string for the menu. The title is displayed when the menu
427 * is shown as a tearoff menu. If title is NULL, the menu will see if it is
428 * attached to a parent menu item, and if so it will try to use the same text as
429 * that menu item's label.
430 * menu:
431 * a GtkMenu
432 * title:
433 * a string containing the title for the menu.
435 public void setTitle(char[] title)
437 // void gtk_menu_set_title (GtkMenu *menu, const gchar *title);
438 gtk_menu_set_title(gtkMenu, Str.toStringz(title));
442 * Returns whether the menu is torn off. See
443 * gtk_menu_set_tearoff_state().
444 * menu:
445 * a GtkMenu
446 * Returns:
447 * TRUE if the menu is currently torn off.
449 public int getTearoffState()
451 // gboolean gtk_menu_get_tearoff_state (GtkMenu *menu);
452 return gtk_menu_get_tearoff_state(gtkMenu);
456 * Returns the title of the menu. See gtk_menu_set_title().
457 * menu:
458 * a GtkMenu
459 * Returns:
460 * the title of the menu, or NULL if the menu has no
461 * title set on it. This string is owned by the widget and should
462 * not be modified or freed.
464 public char[] getTitle()
466 // const gchar* gtk_menu_get_title (GtkMenu *menu);
467 return Str.toString(gtk_menu_get_title(gtkMenu) );
471 * Removes the menu from the screen.
472 * menu:
473 * a GtkMenu.
475 public void popdown()
477 // void gtk_menu_popdown (GtkMenu *menu);
478 gtk_menu_popdown(gtkMenu);
482 * Repositions the menu according to its position function.
483 * menu:
484 * a GtkMenu.
486 public void reposition()
488 // void gtk_menu_reposition (GtkMenu *menu);
489 gtk_menu_reposition(gtkMenu);
493 * Returns the selected menu item from the menu. This is used by the
494 * GtkOptionMenu.
495 * menu:
496 * a GtkMenu.
497 * Returns:
498 * the GtkMenuItem that was last selected in the menu. If a
499 * selection has not yet been made, the first menu item is selected.
501 public Widget getActive()
503 // GtkWidget* gtk_menu_get_active (GtkMenu *menu);
504 return new Widget( gtk_menu_get_active(gtkMenu) );
508 * Selects the specified menu item within the menu. This is used by the
509 * GtkOptionMenu and should not be used by anyone else.
510 * menu:
511 * a GtkMenu.
512 * index_:
513 * the index of the menu item to select. Index values are from
514 * 0 to n-1.
516 public void setActive(uint index)
518 // void gtk_menu_set_active (GtkMenu *menu, guint index_);
519 gtk_menu_set_active(gtkMenu, index);
523 * Changes the tearoff state of the menu. A menu is normally displayed
524 * as drop down menu which persists as long as the menu is active. It can
525 * also be displayed as a tearoff menu which persists until it is closed
526 * or reattached.
527 * menu:
528 * a GtkMenu.
529 * torn_off:
530 * If TRUE, menu is displayed as a tearoff menu.
532 public void setTearoffState(int tornOff)
534 // void gtk_menu_set_tearoff_state (GtkMenu *menu, gboolean torn_off);
535 gtk_menu_set_tearoff_state(gtkMenu, tornOff);
539 * Attaches the menu to the widget and provides a callback function that will
540 * be invoked when the menu calls gtk_menu_detach() during its destruction.
541 * menu:
542 * a GtkMenu.
543 * attach_widget:
544 * the GtkWidget that the menu will be attached to.
545 * detacher:
546 * the user supplied callback function that will be called when
547 * the menu calls gtk_menu_detach().
549 public void attachToWidget(Widget attachWidget, GtkMenuDetachFunc detacher)
551 // void gtk_menu_attach_to_widget (GtkMenu *menu, GtkWidget *attach_widget, GtkMenuDetachFunc detacher);
552 gtk_menu_attach_to_widget(gtkMenu, (attachWidget is null) ? null : attachWidget.getWidgetStruct(), detacher);
556 * Detaches the menu from the widget to which it had been attached.
557 * This function will call the callback function, detacher, provided
558 * when the gtk_menu_attach_to_widget() function was called.
559 * menu:
560 * a GtkMenu.
562 public void detach()
564 // void gtk_menu_detach (GtkMenu *menu);
565 gtk_menu_detach(gtkMenu);
569 * Returns the GtkWidget that the menu is attached to.
570 * menu:
571 * a GtkMenu.
572 * Returns:
573 * the GtkWidget that the menu is attached to.
575 public Widget getAttachWidget()
577 // GtkWidget* gtk_menu_get_attach_widget (GtkMenu *menu);
578 return new Widget( gtk_menu_get_attach_widget(gtkMenu) );
582 * Returns a list of the menus which are attached to this widget.
583 * This list is owned by GTK+ and must not be modified.
584 * widget:
585 * a GtkWidget
586 * Returns:
587 * the list of menus attached to his widget.
588 * Since 2.6
590 public static ListG getForAttachWidget(Widget widget)
592 // GList* gtk_menu_get_for_attach_widget (GtkWidget *widget);
593 return new ListG( gtk_menu_get_for_attach_widget((widget is null) ? null : widget.getWidgetStruct()) );
599 * Informs GTK+ on which monitor a menu should be popped up.
600 * See gdk_screen_get_monitor_geometry().
601 * This function should be called from a GtkMenuPositionFunc if the
602 * menu should not appear on the same monitor as the pointer. This
603 * information can't be reliably inferred from the coordinates returned
604 * by a GtkMenuPositionFunc, since, for very long menus, these coordinates
605 * may extend beyond the monitor boundaries or even the screen boundaries.
606 * menu:
607 * a GtkMenu
608 * monitor_num:
609 * the number of the monitor on which the menu should
610 * be popped up
611 * Since 2.4
612 * Property Details
613 * The "tearoff-state" property
614 * "tearoff-state" gboolean : Read / Write
615 * A boolean that indicates whether the menu is torn-off.
616 * Default value: FALSE
617 * Since 2.6
619 public void setMonitor(int monitorNum)
621 // void gtk_menu_set_monitor (GtkMenu *menu, gint monitor_num);
622 gtk_menu_set_monitor(gtkMenu, monitorNum);