alternative to assert
[gtkD.git] / gtkD / src / gtk / MenuItem.d
blob100c921375a0cbb2165327a2a76e90a0c357600e
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 = GtkMenuItem.html
26 * outPack = gtk
27 * outFile = MenuItem
28 * strct = GtkMenuItem
29 * realStrct=
30 * ctorStrct=
31 * clss = MenuItem
32 * interf =
33 * class Code: Yes
34 * interface Code: No
35 * template for:
36 * extend =
37 * implements:
38 * prefixes:
39 * - gtk_menu_item_
40 * - gtk_
41 * omit structs:
42 * omit prefixes:
43 * omit code:
44 * - gtk_menu_item_activate
45 * - gtk_menu_item_new_with_label
46 * - gtk_menu_item_new_with_mnemonic
47 * imports:
48 * - glib.Str
49 * - gtk.Widget
50 * - gtk.AccelGroup
51 * structWrap:
52 * - GtkWidget* -> Widget
53 * module aliases:
54 * local aliases:
57 module gtk.MenuItem;
59 version(noAssert)
61 version(Tango)
63 import tango.io.Stdout; // use the tango loging?
67 private import gtkc.gtktypes;
69 private import gtkc.gtk;
72 private import glib.Str;
73 private import gtk.Widget;
74 private import gtk.AccelGroup;
79 /**
80 * Description
81 * The GtkMenuItem widget and the derived widgets are the only valid
82 * childs for menus. Their function is to correctly handle highlighting,
83 * alignment, events and submenus.
84 * As it derives from GtkBin it can hold any valid child widget, altough
85 * only a few are really useful.
87 private import gtk.Item;
88 public class MenuItem : Item
91 /** the main Gtk struct */
92 protected GtkMenuItem* gtkMenuItem;
95 public GtkMenuItem* getMenuItemStruct()
97 return gtkMenuItem;
101 /** the main Gtk struct as a void* */
102 protected void* getStruct()
104 return cast(void*)gtkMenuItem;
108 * Sets our main struct and passes it to the parent class
110 public this (GtkMenuItem* gtkMenuItem)
112 version(noAssert)
114 if ( gtkMenuItem is null )
116 int zero = 0;
117 version(Tango)
119 Stdout("struct gtkMenuItem is null on constructor").newline;
121 else
123 printf("struct gtkMenuItem is null on constructor");
125 zero = zero / zero;
128 else
130 assert(gtkMenuItem !is null, "struct gtkMenuItem is null on constructor");
132 super(cast(GtkItem*)gtkMenuItem);
133 this.gtkMenuItem = gtkMenuItem;
137 /** store the action code passed in by the applcation */
138 private char[] actionLabel;
140 /** Gets the application set action code */
141 public char[] getActionName()
143 if ( actionLabel is null )
145 actionLabel = "";
147 return actionLabel;
151 * Creates a new menu item with a label and a listener and a action.
152 * used for backward compatibily with DUI.
154 this(char[] label, void delegate(MenuItem)dlg, char[] action)
156 this(label);
157 this.actionLabel = action;
158 addOnActivate(dlg);
164 * Creates a new Item associated with a "activate" delegate and with a action code
165 * and optionally accelGroup
167 public this(void delegate(MenuItem) dlg, char[] label, char[] action,
168 bool mnemonic=true,
169 AccelGroup accelGroup=null,
170 char accelKey='\0',
171 GdkModifierType modifierType=GdkModifierType.CONTROL_MASK,
172 GtkAccelFlags accelFlags=GtkAccelFlags.VISIBLE
175 this(label, mnemonic);
176 this.actionLabel = action;
177 addOnActivate(dlg);
178 if ( accelGroup !is null && accelKey != '\0' )
180 addAccelerator("activate",accelGroup,accelKey,modifierType,accelFlags);
187 * Creates a new Item associated with a "activate" delegate
189 public this(void delegate(MenuItem) dlg, char[] label, bool mnemonic=true)
191 this(label, mnemonic);
192 addOnActivate(dlg);
196 * Creates a new GtkMenuItem whose child is a GtkLabel.
197 * If mnemonic is true the label
198 * will be created using gtk_label_new_with_mnemonic(), so underscores
199 * in label indicate the mnemonic for the menu item.
200 * label:
201 * the text for the label
202 * Returns:
203 * the newly created GtkMenuItem
205 public this (char[] label, bool mnemonic=true)
207 if ( mnemonic )
209 // GtkWidget* gtk_menu_item_new_with_mnemonic (const gchar *label);
210 this(cast(GtkMenuItem*)gtk_menu_item_new_with_mnemonic(Str.toStringz(label)) );
212 else
214 // GtkWidget* gtk_menu_item_new_with_label (const gchar *label);
215 this(cast(GtkMenuItem*)gtk_menu_item_new_with_label(Str.toStringz(label)) );
217 setName(label);
221 * Emits the "activate" signal on the given item
222 * menu_item:
223 * the menu item
225 public void itemActivate()
227 // void gtk_menu_item_activate (GtkMenuItem *menu_item);
228 gtk_menu_item_activate(gtkMenuItem);
235 // imports for the signal processing
236 private import gobject.Signals;
237 private import gtkc.gdktypes;
238 int[char[]] connectedSignals;
240 void delegate(MenuItem)[] onActivateListeners;
241 void addOnActivate(void delegate(MenuItem) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
243 if ( !("activate" in connectedSignals) )
245 Signals.connectData(
246 getStruct(),
247 "activate",
248 cast(GCallback)&callBackActivate,
249 cast(void*)this,
250 null,
251 connectFlags);
252 connectedSignals["activate"] = 1;
254 onActivateListeners ~= dlg;
256 extern(C) static void callBackActivate(GtkMenuItem* menuitemStruct, MenuItem menuItem)
258 bool consumed = false;
260 foreach ( void delegate(MenuItem) dlg ; menuItem.onActivateListeners )
262 dlg(menuItem);
265 return consumed;
268 void delegate(MenuItem)[] onActivateItemListeners;
269 void addOnActivateItem(void delegate(MenuItem) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
271 if ( !("activate-item" in connectedSignals) )
273 Signals.connectData(
274 getStruct(),
275 "activate-item",
276 cast(GCallback)&callBackActivateItem,
277 cast(void*)this,
278 null,
279 connectFlags);
280 connectedSignals["activate-item"] = 1;
282 onActivateItemListeners ~= dlg;
284 extern(C) static void callBackActivateItem(GtkMenuItem* menuitemStruct, MenuItem menuItem)
286 bool consumed = false;
288 foreach ( void delegate(MenuItem) dlg ; menuItem.onActivateItemListeners )
290 dlg(menuItem);
293 return consumed;
296 void delegate(gint, MenuItem)[] onToggleSizeAllocateListeners;
297 void addOnToggleSizeAllocate(void delegate(gint, MenuItem) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
299 if ( !("toggle-size-allocate" in connectedSignals) )
301 Signals.connectData(
302 getStruct(),
303 "toggle-size-allocate",
304 cast(GCallback)&callBackToggleSizeAllocate,
305 cast(void*)this,
306 null,
307 connectFlags);
308 connectedSignals["toggle-size-allocate"] = 1;
310 onToggleSizeAllocateListeners ~= dlg;
312 extern(C) static void callBackToggleSizeAllocate(GtkMenuItem* menuitemStruct, gint arg1, MenuItem menuItem)
314 bool consumed = false;
316 foreach ( void delegate(gint, MenuItem) dlg ; menuItem.onToggleSizeAllocateListeners )
318 dlg(arg1, menuItem);
321 return consumed;
324 void delegate(gpointer, MenuItem)[] onToggleSizeRequestListeners;
325 void addOnToggleSizeRequest(void delegate(gpointer, MenuItem) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
327 if ( !("toggle-size-request" in connectedSignals) )
329 Signals.connectData(
330 getStruct(),
331 "toggle-size-request",
332 cast(GCallback)&callBackToggleSizeRequest,
333 cast(void*)this,
334 null,
335 connectFlags);
336 connectedSignals["toggle-size-request"] = 1;
338 onToggleSizeRequestListeners ~= dlg;
340 extern(C) static void callBackToggleSizeRequest(GtkMenuItem* menuitemStruct, gpointer arg1, MenuItem menuItem)
342 bool consumed = false;
344 foreach ( void delegate(gpointer, MenuItem) dlg ; menuItem.onToggleSizeRequestListeners )
346 dlg(arg1, menuItem);
349 return consumed;
355 * Creates a new GtkMenuItem.
356 * Returns:
357 * the newly created GtkMenuItem
359 public this ()
361 // GtkWidget* gtk_menu_item_new (void);
362 this(cast(GtkMenuItem*)gtk_menu_item_new() );
368 * Sets whether the menu item appears justified at the right
369 * side of a menu bar. This was traditionally done for "Help" menu
370 * items, but is now considered a bad idea. (If the widget
371 * layout is reversed for a right-to-left language like Hebrew
372 * or Arabic, right-justified-menu-items appear at the left.)
373 * menu_item:
374 * a GtkMenuItem.
375 * right_justified:
376 * if TRUE the menu item will appear at the
377 * far right if added to a menu bar.
379 public void setRightJustified(int rightJustified)
381 // void gtk_menu_item_set_right_justified (GtkMenuItem *menu_item, gboolean right_justified);
382 gtk_menu_item_set_right_justified(gtkMenuItem, rightJustified);
386 * Sets the widget submenu, or changes it.
387 * menu_item:
388 * the menu item widget
389 * submenu:
390 * the submenu
392 public void setSubmenu(Widget submenu)
394 // void gtk_menu_item_set_submenu (GtkMenuItem *menu_item, GtkWidget *submenu);
395 gtk_menu_item_set_submenu(gtkMenuItem, (submenu is null) ? null : submenu.getWidgetStruct());
399 * Set the accelerator path on menu_item, through which runtime changes of the
400 * menu item's accelerator caused by the user can be identified and saved to
401 * persistant storage (see gtk_accel_map_save() on this).
402 * To setup a default accelerator for this menu item, call
403 * gtk_accel_map_add_entry() with the same accel_path.
404 * See also gtk_accel_map_add_entry() on the specifics of accelerator paths,
405 * and gtk_menu_set_accel_path() for a more convenient variant of this function.
406 * This function is basically a convenience wrapper that handles calling
407 * gtk_widget_set_accel_path() with the appropriate accelerator group for
408 * the menu item.
409 * Note that you do need to set an accelerator on the parent menu with
410 * gtk_menu_set_accel_group() for this to work.
411 * menu_item:
412 * a valid GtkMenuItem
413 * accel_path:
414 * accelerator path, corresponding to this menu item's
415 * functionality, or NULL to unset the current path.
417 public void setAccelPath(char[] accelPath)
419 // void gtk_menu_item_set_accel_path (GtkMenuItem *menu_item, const gchar *accel_path);
420 gtk_menu_item_set_accel_path(gtkMenuItem, Str.toStringz(accelPath));
424 * Removes the widget's submenu.
425 * menu_item:
426 * the menu item widget
428 public void removeSubmenu()
430 // void gtk_menu_item_remove_submenu (GtkMenuItem *menu_item);
431 gtk_menu_item_remove_submenu(gtkMenuItem);
435 * Emits the "select" signal on the given item. Behaves exactly like
436 * gtk_item_select.
437 * menu_item:
438 * the menu item
440 public void select()
442 // void gtk_menu_item_select (GtkMenuItem *menu_item);
443 gtk_menu_item_select(gtkMenuItem);
447 * Emits the "deselect" signal on the given item. Behaves exactly like
448 * gtk_item_deselect.
449 * menu_item:
450 * the menu item
452 public void deselect()
454 // void gtk_menu_item_deselect (GtkMenuItem *menu_item);
455 gtk_menu_item_deselect(gtkMenuItem);
460 * Emits the "toggle_size_request" signal on the given item.
461 * menu_item:
462 * the menu item
463 * requisition:
464 * the requisition to use as signal data.
466 public void toggleSizeRequest(int* requisition)
468 // void gtk_menu_item_toggle_size_request (GtkMenuItem *menu_item, gint *requisition);
469 gtk_menu_item_toggle_size_request(gtkMenuItem, requisition);
473 * Emits the "toggle_size_allocate" signal on the given item.
474 * menu_item:
475 * the menu item.
476 * allocation:
477 * the allocation to use as signal data.
479 public void toggleSizeAllocate(int allocation)
481 // void gtk_menu_item_toggle_size_allocate (GtkMenuItem *menu_item, gint allocation);
482 gtk_menu_item_toggle_size_allocate(gtkMenuItem, allocation);
487 * Gets whether the menu item appears justified at the right
488 * side of the menu bar.
489 * menu_item:
490 * a GtkMenuItem
491 * Returns:
492 * TRUE if the menu item will appear at the
493 * far right if added to a menu bar.
495 public int getRightJustified()
497 // gboolean gtk_menu_item_get_right_justified (GtkMenuItem *menu_item);
498 return gtk_menu_item_get_right_justified(gtkMenuItem);
502 * Gets the submenu underneath this menu item, if any. See
503 * gtk_menu_item_set_submenu().
504 * menu_item:
505 * a GtkMenuItem
506 * Returns:
507 * submenu for this menu item, or NULL if none.
508 * Style Property Details
509 * The "arrow-spacing" style property
510 * "arrow-spacing" gint : Read
511 * Space between label and arrow.
512 * Allowed values: >= 0
513 * Default value: 10
515 public Widget getSubmenu()
517 // GtkWidget* gtk_menu_item_get_submenu (GtkMenuItem *menu_item);
518 return new Widget( gtk_menu_item_get_submenu(gtkMenuItem) );