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