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
53 * - GdkScreen* -> Screen
54 * - GtkAccelGroup* -> AccelGroup
55 * - GtkWidget* -> Widget
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
;
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
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.
104 * my_popup_handler (GtkWidget *widget, GdkEvent *event)
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.
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);
128 private import gtk
.MenuShell
;
129 public class Menu
: MenuShell
132 /** the main Gtk struct */
133 protected GtkMenu
* gtkMenu
;
136 public GtkMenu
* getMenuStruct()
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
)
155 if ( gtkMenu
is null )
160 Stdout("struct gtkMenu is null on constructor").newline
;
164 printf("struct gtkMenu is null on constructor");
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
);
202 Menu submenu
= new Menu();
203 item
.setSubmenu(submenu
);
207 void appendSubmenu(char[] label
, Menu submenu
)
209 MenuItem item
= new MenuItem(label
);
211 item
.setSubmenu(submenu
);
214 Menu
prependSubmenu(char[] label
)
216 MenuItem item
= new MenuItem(label
);
218 Menu submenu
= new Menu();
219 item
.setSubmenu(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
) )
240 cast(GCallback
)&callBackMoveScroll
,
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
)
263 * Creates a new GtkMenu.
269 // GtkWidget* gtk_menu_new (void);
270 this(cast(GtkMenu
*)gtk_menu_new() );
274 * Sets the GdkScreen on which the menu will be displayed.
278 * a GdkScreen, or NULL if the screen should be
279 * determined by the widget the menu is attached to.
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.
296 * the GtkMenuItem to move.
298 * the new position to place child. Positions are numbered from
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().
319 * The column number to attach the left side of the item to.
321 * The column number to attach the right side of the item to.
323 * The row number to attach the top of the item to.
325 * The row number to attach the bottom of the item to.
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.
350 * the menu shell containing the triggering menu item, or NULL
352 * the menu item whose activation triggered the popup, or NULL
354 * a user supplied function used to position the menu, or NULL
356 * user supplied data to be passed to func.
358 * the mouse button which was pressed to initiate the event.
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.
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().
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().
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.
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().
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().
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.
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.
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
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.
513 * the index of the menu item to select. Index values are from
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
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.
544 * the GtkWidget that the menu will be attached to.
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.
564 // void gtk_menu_detach (GtkMenu *menu);
565 gtk_menu_detach(gtkMenu
);
569 * Returns the GtkWidget that the menu is attached to.
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.
587 * the list of menus attached to his widget.
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.
609 * the number of the monitor on which the menu should
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
619 public void setMonitor(int monitorNum
)
621 // void gtk_menu_set_monitor (GtkMenu *menu, gint monitor_num);
622 gtk_menu_set_monitor(gtkMenu
, monitorNum
);