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  = GtkMenuItem.html
27  * outPack = gtk
28  * outFile = MenuItem
29  * strct   = GtkMenuItem
30  * realStrct=
31  * ctorStrct=
32  * clss    = MenuItem
33  * interf  = 
34  * class Code: Yes
35  * interface Code: No
36  * template for:
37  * extend  = 
38  * implements:
39  * 	- ActivatableIF
40  * prefixes:
41  * 	- gtk_menu_item_
42  * omit structs:
43  * omit prefixes:
44  * omit code:
45  * 	- gtk_menu_item_new_with_label
46  * 	- gtk_menu_item_new_with_mnemonic
47  * omit signals:
48  * imports:
49  * 	- glib.Str
50  * 	- gtk.AccelGroup
51  * 	- gtk.Widget
52  * 	- gtk.ActivatableT
53  * 	- gtk.ActivatableIF
54  * structWrap:
55  * 	- GtkWidget* -> Widget
56  * module aliases:
57  * local aliases:
58  * 	- activate -> itemActivate
59  * overrides:
60  */
61 
62 module gtk.MenuItem;
63 
64 public  import gtkc.gtktypes;
65 
66 private import gtkc.gtk;
67 private import glib.ConstructionException;
68 private import gobject.ObjectG;
69 
70 private import gobject.Signals;
71 public  import gtkc.gdktypes;
72 private import glib.Str;
73 private import gtk.AccelGroup;
74 private import gtk.Widget;
75 private import gtk.ActivatableT;
76 private import gtk.ActivatableIF;
77 
78 
79 private import gtk.Bin;
80 
81 /**
82  * The GtkMenuItem widget and the derived widgets are the only valid
83  * children for menus. Their function is to correctly handle highlighting,
84  * alignment, events and submenus.
85  *
86  * As a GtkMenuItem derives from GtkBin it can hold any valid child widget,
87  * although only a few are really useful.
88  *
89  * By default, a GtkMenuItem sets a GtkAccelLabel as its child.
90  * GtkMenuItem has direct functions to set the label and its mnemonic.
91  * For more advanced label settings, you can fetch the child widget from the GtkBin.
92  *
93  * $(DDOC_COMMENT example)
94  *
95  * GtkMenuItem as GtkBuildable
96  *
97  * The GtkMenuItem implementation of the GtkBuildable interface
98  * supports adding a submenu by specifying "submenu" as the "type"
99  * attribute of a <child> element.
100  *
101  * $(DDOC_COMMENT example)
102  */
103 public class MenuItem : Bin, ActivatableIF
104 {
105 	
106 	/** the main Gtk struct */
107 	protected GtkMenuItem* gtkMenuItem;
108 	
109 	
110 	/** Get the main Gtk struct */
111 	public GtkMenuItem* getMenuItemStruct()
112 	{
113 		return gtkMenuItem;
114 	}
115 	
116 	
117 	/** the main Gtk struct as a void* */
118 	protected override void* getStruct()
119 	{
120 		return cast(void*)gtkMenuItem;
121 	}
122 	
123 	/**
124 	 * Sets our main struct and passes it to the parent class
125 	 */
126 	public this (GtkMenuItem* gtkMenuItem)
127 	{
128 		super(cast(GtkBin*)gtkMenuItem);
129 		this.gtkMenuItem = gtkMenuItem;
130 	}
131 	
132 	protected override void setStruct(GObject* obj)
133 	{
134 		super.setStruct(obj);
135 		gtkMenuItem = cast(GtkMenuItem*)obj;
136 	}
137 	
138 	/** store the action code passed in by the applcation */
139 	private string actionLabel;
140 	
141 	// add the Activatable capabilities
142 	mixin ActivatableT!(GtkMenuItem);
143 	
144 	/** Gets the application set action code */
145 	public string getActionName()
146 	{
147 		if ( actionLabel is null )
148 		{
149 			actionLabel = "";
150 		}
151 		return actionLabel;
152 	}
153 	
154 	/**
155 	 * Creates a new menu item with a label and a listener and a action.
156 	 * used for backward compatibily with DUI.
157 	 */
158 	this(string label, void delegate(MenuItem)dlg, string action)
159 	{
160 		this(label);
161 		this.actionLabel = action;
162 		addOnActivate(dlg);
163 	}
164 	
165 	/**
166 	 * Creates a new Item associated with a "activate" delegate and with a action code
167 	 * and optionally accelGroup
168 	 */
169 	public this(void delegate(MenuItem) dlg, string label, string action,
170 	bool mnemonic=true,
171 	AccelGroup accelGroup=null,
172 	char accelKey='\0',
173 	GdkModifierType modifierType=GdkModifierType.CONTROL_MASK,
174 	GtkAccelFlags accelFlags=GtkAccelFlags.VISIBLE
175 	)
176 	{
177 		this(label, mnemonic);
178 		this.actionLabel = action;
179 		addOnActivate(dlg);
180 		if ( accelGroup !is null && accelKey != '\0' )
181 		{
182 			addAccelerator("activate",accelGroup,accelKey,modifierType,accelFlags);
183 		}
184 	}
185 	
186 	/**
187 	 * Creates a new Item associated with a "activate" delegate
188 	 */
189 	public this(void delegate(MenuItem) dlg, string label, bool mnemonic=true)
190 	{
191 		this(label, mnemonic);
192 		addOnActivate(dlg);
193 	}
194 	
195 	/**
196 	 * Creates a new GtkMenuItem whose child is a GtkLabel.
197 	 * Params:
198 	 *  label = the text for the label
199 	 *  mnemonic = if true the label
200 	 *  will be created using gtk_label_new_with_mnemonic(), so underscores
201 	 *  in label indicate the mnemonic for the menu item.
202 	 * Throws: ConstructionException GTK+ fails to create the object.
203 	 */
204 	public this (string label, bool mnemonic=true)
205 	{
206 		GtkMenuItem* p;
207 		
208 		if ( mnemonic )
209 		{
210 			// GtkWidget* gtk_menu_item_new_with_mnemonic (const gchar *label);
211 			p = cast(GtkMenuItem*)gtk_menu_item_new_with_mnemonic(Str.toStringz(label));
212 		}
213 		else
214 		{
215 			// GtkWidget* gtk_menu_item_new_with_label (const gchar *label);
216 			p = cast(GtkMenuItem*)gtk_menu_item_new_with_label(Str.toStringz(label));
217 		}
218 		
219 		if(p is null)
220 		{
221 			throw new ConstructionException("null returned by gtk_menu_item_new_with_");
222 		}
223 		
224 		this(p);
225 		
226 		setName(label);
227 	}
228 	
229 	/**
230 	 */
231 	int[string] connectedSignals;
232 	
233 	void delegate(MenuItem)[] onActivateListeners;
234 	/**
235 	 * Emitted when the item is activated.
236 	 */
237 	void addOnActivate(void delegate(MenuItem) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
238 	{
239 		if ( !("activate" in connectedSignals) )
240 		{
241 			Signals.connectData(
242 			getStruct(),
243 			"activate",
244 			cast(GCallback)&callBackActivate,
245 			cast(void*)this,
246 			null,
247 			connectFlags);
248 			connectedSignals["activate"] = 1;
249 		}
250 		onActivateListeners ~= dlg;
251 	}
252 	extern(C) static void callBackActivate(GtkMenuItem* menuitemStruct, MenuItem _menuItem)
253 	{
254 		foreach ( void delegate(MenuItem) dlg ; _menuItem.onActivateListeners )
255 		{
256 			dlg(_menuItem);
257 		}
258 	}
259 	
260 	void delegate(MenuItem)[] onActivateItemListeners;
261 	/**
262 	 * Emitted when the item is activated, but also if the menu item has a
263 	 * submenu. For normal applications, the relevant signal is
264 	 * "activate".
265 	 */
266 	void addOnActivateItem(void delegate(MenuItem) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
267 	{
268 		if ( !("activate-item" in connectedSignals) )
269 		{
270 			Signals.connectData(
271 			getStruct(),
272 			"activate-item",
273 			cast(GCallback)&callBackActivateItem,
274 			cast(void*)this,
275 			null,
276 			connectFlags);
277 			connectedSignals["activate-item"] = 1;
278 		}
279 		onActivateItemListeners ~= dlg;
280 	}
281 	extern(C) static void callBackActivateItem(GtkMenuItem* menuitemStruct, MenuItem _menuItem)
282 	{
283 		foreach ( void delegate(MenuItem) dlg ; _menuItem.onActivateItemListeners )
284 		{
285 			dlg(_menuItem);
286 		}
287 	}
288 	
289 	void delegate(MenuItem)[] onDeselectListeners;
290 	/**
291 	 */
292 	void addOnDeselect(void delegate(MenuItem) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
293 	{
294 		if ( !("deselect" in connectedSignals) )
295 		{
296 			Signals.connectData(
297 			getStruct(),
298 			"deselect",
299 			cast(GCallback)&callBackDeselect,
300 			cast(void*)this,
301 			null,
302 			connectFlags);
303 			connectedSignals["deselect"] = 1;
304 		}
305 		onDeselectListeners ~= dlg;
306 	}
307 	extern(C) static void callBackDeselect(GtkMenuItem* menuitemStruct, MenuItem _menuItem)
308 	{
309 		foreach ( void delegate(MenuItem) dlg ; _menuItem.onDeselectListeners )
310 		{
311 			dlg(_menuItem);
312 		}
313 	}
314 	
315 	void delegate(MenuItem)[] onSelectListeners;
316 	/**
317 	 */
318 	void addOnSelect(void delegate(MenuItem) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
319 	{
320 		if ( !("select" in connectedSignals) )
321 		{
322 			Signals.connectData(
323 			getStruct(),
324 			"select",
325 			cast(GCallback)&callBackSelect,
326 			cast(void*)this,
327 			null,
328 			connectFlags);
329 			connectedSignals["select"] = 1;
330 		}
331 		onSelectListeners ~= dlg;
332 	}
333 	extern(C) static void callBackSelect(GtkMenuItem* menuitemStruct, MenuItem _menuItem)
334 	{
335 		foreach ( void delegate(MenuItem) dlg ; _menuItem.onSelectListeners )
336 		{
337 			dlg(_menuItem);
338 		}
339 	}
340 	
341 	void delegate(gint, MenuItem)[] onToggleSizeAllocateListeners;
342 	/**
343 	 */
344 	void addOnToggleSizeAllocate(void delegate(gint, MenuItem) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
345 	{
346 		if ( !("toggle-size-allocate" in connectedSignals) )
347 		{
348 			Signals.connectData(
349 			getStruct(),
350 			"toggle-size-allocate",
351 			cast(GCallback)&callBackToggleSizeAllocate,
352 			cast(void*)this,
353 			null,
354 			connectFlags);
355 			connectedSignals["toggle-size-allocate"] = 1;
356 		}
357 		onToggleSizeAllocateListeners ~= dlg;
358 	}
359 	extern(C) static void callBackToggleSizeAllocate(GtkMenuItem* menuitemStruct, gint arg1, MenuItem _menuItem)
360 	{
361 		foreach ( void delegate(gint, MenuItem) dlg ; _menuItem.onToggleSizeAllocateListeners )
362 		{
363 			dlg(arg1, _menuItem);
364 		}
365 	}
366 	
367 	void delegate(void*, MenuItem)[] onToggleSizeRequestListeners;
368 	/**
369 	 * See Also
370 	 * GtkBin, GtkMenuShell
371 	 */
372 	void addOnToggleSizeRequest(void delegate(void*, MenuItem) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
373 	{
374 		if ( !("toggle-size-request" in connectedSignals) )
375 		{
376 			Signals.connectData(
377 			getStruct(),
378 			"toggle-size-request",
379 			cast(GCallback)&callBackToggleSizeRequest,
380 			cast(void*)this,
381 			null,
382 			connectFlags);
383 			connectedSignals["toggle-size-request"] = 1;
384 		}
385 		onToggleSizeRequestListeners ~= dlg;
386 	}
387 	extern(C) static void callBackToggleSizeRequest(GtkMenuItem* menuitemStruct, void* arg1, MenuItem _menuItem)
388 	{
389 		foreach ( void delegate(void*, MenuItem) dlg ; _menuItem.onToggleSizeRequestListeners )
390 		{
391 			dlg(arg1, _menuItem);
392 		}
393 	}
394 	
395 	
396 	/**
397 	 * Creates a new GtkMenuItem.
398 	 * Throws: ConstructionException GTK+ fails to create the object.
399 	 */
400 	public this ()
401 	{
402 		// GtkWidget * gtk_menu_item_new (void);
403 		auto p = gtk_menu_item_new();
404 		if(p is null)
405 		{
406 			throw new ConstructionException("null returned by gtk_menu_item_new()");
407 		}
408 		this(cast(GtkMenuItem*) p);
409 	}
410 	
411 	/**
412 	 * Warning
413 	 * gtk_menu_item_set_right_justified has been deprecated since version 3.2 and should not be used in newly-written code. If you insist on using it, use
414 	 *  gtk_widget_set_hexpand() and gtk_widget_set_halign().
415 	 * Sets whether the menu item appears justified at the right
416 	 * side of a menu bar. This was traditionally done for "Help"
417 	 * menu items, but is now considered a bad idea. (If the widget
418 	 * layout is reversed for a right-to-left language like Hebrew
419 	 * or Arabic, right-justified-menu-items appear at the left.)
420 	 * Params:
421 	 * rightJustified = if TRUE the menu item will appear at the
422 	 * far right if added to a menu bar
423 	 */
424 	public void setRightJustified(int rightJustified)
425 	{
426 		// void gtk_menu_item_set_right_justified (GtkMenuItem *menu_item,  gboolean right_justified);
427 		gtk_menu_item_set_right_justified(gtkMenuItem, rightJustified);
428 	}
429 	
430 	/**
431 	 * Warning
432 	 * gtk_menu_item_get_right_justified has been deprecated since version 3.2 and should not be used in newly-written code. See gtk_menu_item_set_right_justified()
433 	 * Gets whether the menu item appears justified at the right
434 	 * side of the menu bar.
435 	 * Returns: TRUE if the menu item will appear at the far right if added to a menu bar.
436 	 */
437 	public int getRightJustified()
438 	{
439 		// gboolean gtk_menu_item_get_right_justified (GtkMenuItem *menu_item);
440 		return gtk_menu_item_get_right_justified(gtkMenuItem);
441 	}
442 	
443 	/**
444 	 * Sets text on the menu_item label
445 	 * Since 2.16
446 	 * Returns: The text in the menu_item label. This is the internal string used by the label, and must not be modified.
447 	 */
448 	public string getLabel()
449 	{
450 		// const gchar * gtk_menu_item_get_label (GtkMenuItem *menu_item);
451 		return Str.toString(gtk_menu_item_get_label(gtkMenuItem));
452 	}
453 	
454 	/**
455 	 * Sets text on the menu_item label
456 	 * Since 2.16
457 	 * Params:
458 	 * label = the text you want to set
459 	 */
460 	public void setLabel(string label)
461 	{
462 		// void gtk_menu_item_set_label (GtkMenuItem *menu_item,  const gchar *label);
463 		gtk_menu_item_set_label(gtkMenuItem, Str.toStringz(label));
464 	}
465 	
466 	/**
467 	 * Checks if an underline in the text indicates the next character
468 	 * should be used for the mnemonic accelerator key.
469 	 * Since 2.16
470 	 * Returns: TRUE if an embedded underline in the label indicates the mnemonic accelerator key.
471 	 */
472 	public int getUseUnderline()
473 	{
474 		// gboolean gtk_menu_item_get_use_underline (GtkMenuItem *menu_item);
475 		return gtk_menu_item_get_use_underline(gtkMenuItem);
476 	}
477 	
478 	/**
479 	 * If true, an underline in the text indicates the next character
480 	 * should be used for the mnemonic accelerator key.
481 	 * Since 2.16
482 	 * Params:
483 	 * setting = TRUE if underlines in the text indicate mnemonics
484 	 */
485 	public void setUseUnderline(int setting)
486 	{
487 		// void gtk_menu_item_set_use_underline (GtkMenuItem *menu_item,  gboolean setting);
488 		gtk_menu_item_set_use_underline(gtkMenuItem, setting);
489 	}
490 	
491 	/**
492 	 * Sets or replaces the menu item's submenu, or removes it when a NULL
493 	 * submenu is passed.
494 	 * Params:
495 	 * submenu = the submenu, or NULL. [allow-none]
496 	 */
497 	public void setSubmenu(Widget submenu)
498 	{
499 		// void gtk_menu_item_set_submenu (GtkMenuItem *menu_item,  GtkWidget *submenu);
500 		gtk_menu_item_set_submenu(gtkMenuItem, (submenu is null) ? null : submenu.getWidgetStruct());
501 	}
502 	
503 	/**
504 	 * Gets the submenu underneath this menu item, if any.
505 	 * See gtk_menu_item_set_submenu().
506 	 * Returns: submenu for this menu item, or NULL if none. [transfer none]
507 	 */
508 	public Widget getSubmenu()
509 	{
510 		// GtkWidget * gtk_menu_item_get_submenu (GtkMenuItem *menu_item);
511 		auto p = gtk_menu_item_get_submenu(gtkMenuItem);
512 		
513 		if(p is null)
514 		{
515 			return null;
516 		}
517 		
518 		return ObjectG.getDObject!(Widget)(cast(GtkWidget*) p);
519 	}
520 	
521 	/**
522 	 * Set the accelerator path on menu_item, through which runtime
523 	 * changes of the menu item's accelerator caused by the user can be
524 	 * identified and saved to persistent storage (see gtk_accel_map_save()
525 	 * on this). To set up a default accelerator for this menu item, call
526 	 * gtk_accel_map_add_entry() with the same accel_path. See also
527 	 * gtk_accel_map_add_entry() on the specifics of accelerator paths,
528 	 * and gtk_menu_set_accel_path() for a more convenient variant of
529 	 * this function.
530 	 * This function is basically a convenience wrapper that handles
531 	 * calling gtk_widget_set_accel_path() with the appropriate accelerator
532 	 * group for the menu item.
533 	 * Note that you do need to set an accelerator on the parent menu with
534 	 * gtk_menu_set_accel_group() for this to work.
535 	 * Note that accel_path string will be stored in a GQuark.
536 	 * Therefore, if you pass a static string, you can save some memory
537 	 * by interning it first with g_intern_static_string().
538 	 * Params:
539 	 * accelPath = accelerator path, corresponding to this menu
540 	 * item's functionality, or NULL to unset the current path. [allow-none]
541 	 */
542 	public void setAccelPath(string accelPath)
543 	{
544 		// void gtk_menu_item_set_accel_path (GtkMenuItem *menu_item,  const gchar *accel_path);
545 		gtk_menu_item_set_accel_path(gtkMenuItem, Str.toStringz(accelPath));
546 	}
547 	
548 	/**
549 	 * Retrieve the accelerator path that was previously set on menu_item.
550 	 * See gtk_menu_item_set_accel_path() for details.
551 	 * Since 2.14
552 	 * Returns: the accelerator path corresponding to this menu item's functionality, or NULL if not set
553 	 */
554 	public string getAccelPath()
555 	{
556 		// const gchar * gtk_menu_item_get_accel_path (GtkMenuItem *menu_item);
557 		return Str.toString(gtk_menu_item_get_accel_path(gtkMenuItem));
558 	}
559 	
560 	/**
561 	 * Emits the "select" signal on the given item. Behaves
562 	 * exactly like gtk_item_select.
563 	 */
564 	public void select()
565 	{
566 		// void gtk_menu_item_select (GtkMenuItem *menu_item);
567 		gtk_menu_item_select(gtkMenuItem);
568 	}
569 	
570 	/**
571 	 * Emits the "deselect" signal on the given item. Behaves
572 	 * exactly like gtk_item_deselect.
573 	 */
574 	public void deselect()
575 	{
576 		// void gtk_menu_item_deselect (GtkMenuItem *menu_item);
577 		gtk_menu_item_deselect(gtkMenuItem);
578 	}
579 	
580 	/**
581 	 * Emits the "activate" signal on the given item
582 	 */
583 	public void itemActivate()
584 	{
585 		// void gtk_menu_item_activate (GtkMenuItem *menu_item);
586 		gtk_menu_item_activate(gtkMenuItem);
587 	}
588 	
589 	/**
590 	 * Emits the "toggle-size-request" signal on the given item.
591 	 * Params:
592 	 * requisition = the requisition to use as signal data. [inout]
593 	 */
594 	public void toggleSizeRequest(ref int requisition)
595 	{
596 		// void gtk_menu_item_toggle_size_request (GtkMenuItem *menu_item,  gint *requisition);
597 		gtk_menu_item_toggle_size_request(gtkMenuItem, &requisition);
598 	}
599 	
600 	/**
601 	 * Emits the "toggle-size-allocate" signal on the given item.
602 	 * Params:
603 	 * allocation = the allocation to use as signal data.
604 	 */
605 	public void toggleSizeAllocate(int allocation)
606 	{
607 		// void gtk_menu_item_toggle_size_allocate (GtkMenuItem *menu_item,  gint allocation);
608 		gtk_menu_item_toggle_size_allocate(gtkMenuItem, allocation);
609 	}
610 	
611 	/**
612 	 * Returns whether the menu_item reserves space for
613 	 * the submenu indicator, regardless if it has a submenu
614 	 * or not.
615 	 * Returns: TRUE if menu_item always reserves space for the submenu indicator Since 3.0
616 	 */
617 	public int getReserveIndicator()
618 	{
619 		// gboolean gtk_menu_item_get_reserve_indicator (GtkMenuItem *menu_item);
620 		return gtk_menu_item_get_reserve_indicator(gtkMenuItem);
621 	}
622 	
623 	/**
624 	 * Sets whether the menu_item should reserve space for
625 	 * the submenu indicator, regardless if it actually has
626 	 * a submenu or not.
627 	 * There should be little need for applications to call
628 	 * this functions.
629 	 * Params:
630 	 * reserve = the new value
631 	 * Since 3.0
632 	 */
633 	public void setReserveIndicator(int reserve)
634 	{
635 		// void gtk_menu_item_set_reserve_indicator (GtkMenuItem *menu_item,  gboolean reserve);
636 		gtk_menu_item_set_reserve_indicator(gtkMenuItem, reserve);
637 	}
638 }