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  = GtkMenuShell.html
27  * outPack = gtk
28  * outFile = MenuShell
29  * strct   = GtkMenuShell
30  * realStrct=
31  * ctorStrct=
32  * clss    = MenuShell
33  * interf  = 
34  * class Code: No
35  * interface Code: No
36  * template for:
37  * extend  = 
38  * implements:
39  * prefixes:
40  * 	- gtk_menu_shell_
41  * omit structs:
42  * omit prefixes:
43  * omit code:
44  * omit signals:
45  * imports:
46  * 	- glib.Str
47  * 	- gio.MenuModel
48  * 	- gtk.Widget
49  * structWrap:
50  * 	- GMenuModel* -> MenuModel
51  * 	- GtkWidget* -> Widget
52  * module aliases:
53  * local aliases:
54  * overrides:
55  */
56 
57 module gtk.MenuShell;
58 
59 public  import gtkc.gtktypes;
60 
61 private import gtkc.gtk;
62 private import glib.ConstructionException;
63 private import gobject.ObjectG;
64 
65 private import gobject.Signals;
66 public  import gtkc.gdktypes;
67 private import glib.Str;
68 private import gio.MenuModel;
69 private import gtk.Widget;
70 
71 
72 private import gtk.Container;
73 
74 /**
75  * A GtkMenuShell is the abstract base class used to derive the
76  * GtkMenu and GtkMenuBar subclasses.
77  *
78  * A GtkMenuShell is a container of GtkMenuItem objects arranged
79  * in a list which can be navigated, selected, and activated by the
80  * user to perform application functions. A GtkMenuItem can have a
81  * submenu associated with it, allowing for nested hierarchical menus.
82  *
83  * Terminology
84  *
85  * A menu item can be "selected", this means that it is displayed
86  * in the prelight state, and if it has a submenu, that submenu
87  * will be popped up.
88  *
89  * A menu is "active" when it is visible onscreen and the user
90  * is selecting from it. A menubar is not active until the user
91  * clicks on one of its menuitems. When a menu is active,
92  * passing the mouse over a submenu will pop it up.
93  *
94  * There is also is a concept of the current menu and a current
95  * menu item. The current menu item is the selected menu item
96  * that is furthest down in the hierarchy. (Every active menu shell
97  * does not necessarily contain a selected menu item, but if
98  * it does, then the parent menu shell must also contain
99  * a selected menu item.) The current menu is the menu that
100  * contains the current menu item. It will always have a GTK
101  * grab and receive all key presses.
102  */
103 public class MenuShell : Container
104 {
105 	
106 	/** the main Gtk struct */
107 	protected GtkMenuShell* gtkMenuShell;
108 	
109 	
110 	/** Get the main Gtk struct */
111 	public GtkMenuShell* getMenuShellStruct()
112 	{
113 		return gtkMenuShell;
114 	}
115 	
116 	
117 	/** the main Gtk struct as a void* */
118 	protected override void* getStruct()
119 	{
120 		return cast(void*)gtkMenuShell;
121 	}
122 	
123 	/**
124 	 * Sets our main struct and passes it to the parent class
125 	 */
126 	public this (GtkMenuShell* gtkMenuShell)
127 	{
128 		super(cast(GtkContainer*)gtkMenuShell);
129 		this.gtkMenuShell = gtkMenuShell;
130 	}
131 	
132 	protected override void setStruct(GObject* obj)
133 	{
134 		super.setStruct(obj);
135 		gtkMenuShell = cast(GtkMenuShell*)obj;
136 	}
137 	
138 	/**
139 	 */
140 	int[string] connectedSignals;
141 	
142 	void delegate(gboolean, MenuShell)[] onActivateCurrentListeners;
143 	/**
144 	 * An action signal that activates the current menu item within
145 	 * the menu shell.
146 	 */
147 	void addOnActivateCurrent(void delegate(gboolean, MenuShell) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
148 	{
149 		if ( !("activate-current" in connectedSignals) )
150 		{
151 			Signals.connectData(
152 			getStruct(),
153 			"activate-current",
154 			cast(GCallback)&callBackActivateCurrent,
155 			cast(void*)this,
156 			null,
157 			connectFlags);
158 			connectedSignals["activate-current"] = 1;
159 		}
160 		onActivateCurrentListeners ~= dlg;
161 	}
162 	extern(C) static void callBackActivateCurrent(GtkMenuShell* menushellStruct, gboolean forceHide, MenuShell _menuShell)
163 	{
164 		foreach ( void delegate(gboolean, MenuShell) dlg ; _menuShell.onActivateCurrentListeners )
165 		{
166 			dlg(forceHide, _menuShell);
167 		}
168 	}
169 	
170 	void delegate(MenuShell)[] onCancelListeners;
171 	/**
172 	 * An action signal which cancels the selection within the menu shell.
173 	 * Causes the "selection-done" signal to be emitted.
174 	 */
175 	void addOnCancel(void delegate(MenuShell) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
176 	{
177 		if ( !("cancel" in connectedSignals) )
178 		{
179 			Signals.connectData(
180 			getStruct(),
181 			"cancel",
182 			cast(GCallback)&callBackCancel,
183 			cast(void*)this,
184 			null,
185 			connectFlags);
186 			connectedSignals["cancel"] = 1;
187 		}
188 		onCancelListeners ~= dlg;
189 	}
190 	extern(C) static void callBackCancel(GtkMenuShell* menushellStruct, MenuShell _menuShell)
191 	{
192 		foreach ( void delegate(MenuShell) dlg ; _menuShell.onCancelListeners )
193 		{
194 			dlg(_menuShell);
195 		}
196 	}
197 	
198 	void delegate(GtkDirectionType, MenuShell)[] onCycleFocusListeners;
199 	/**
200 	 * A keybinding signal which moves the focus in the
201 	 * given direction.
202 	 */
203 	void addOnCycleFocus(void delegate(GtkDirectionType, MenuShell) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
204 	{
205 		if ( !("cycle-focus" in connectedSignals) )
206 		{
207 			Signals.connectData(
208 			getStruct(),
209 			"cycle-focus",
210 			cast(GCallback)&callBackCycleFocus,
211 			cast(void*)this,
212 			null,
213 			connectFlags);
214 			connectedSignals["cycle-focus"] = 1;
215 		}
216 		onCycleFocusListeners ~= dlg;
217 	}
218 	extern(C) static void callBackCycleFocus(GtkMenuShell* menushellStruct, GtkDirectionType direction, MenuShell _menuShell)
219 	{
220 		foreach ( void delegate(GtkDirectionType, MenuShell) dlg ; _menuShell.onCycleFocusListeners )
221 		{
222 			dlg(direction, _menuShell);
223 		}
224 	}
225 	
226 	void delegate(MenuShell)[] onDeactivateListeners;
227 	/**
228 	 * This signal is emitted when a menu shell is deactivated.
229 	 */
230 	void addOnDeactivate(void delegate(MenuShell) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
231 	{
232 		if ( !("deactivate" in connectedSignals) )
233 		{
234 			Signals.connectData(
235 			getStruct(),
236 			"deactivate",
237 			cast(GCallback)&callBackDeactivate,
238 			cast(void*)this,
239 			null,
240 			connectFlags);
241 			connectedSignals["deactivate"] = 1;
242 		}
243 		onDeactivateListeners ~= dlg;
244 	}
245 	extern(C) static void callBackDeactivate(GtkMenuShell* menushellStruct, MenuShell _menuShell)
246 	{
247 		foreach ( void delegate(MenuShell) dlg ; _menuShell.onDeactivateListeners )
248 		{
249 			dlg(_menuShell);
250 		}
251 	}
252 	
253 	void delegate(Widget, gint, MenuShell)[] onInsertListeners;
254 	/**
255 	 * The ::insert signal is emitted when a new GtkMenuItem is added to
256 	 * a GtkMenuShell. A separate signal is used instead of
257 	 * GtkContainer::add because of the need for an additional position
258 	 * parameter.
259 	 * The inverse of this signal is the GtkContainer::removed signal.
260 	 * Since 3.2
261 	 */
262 	void addOnInsert(void delegate(Widget, gint, MenuShell) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
263 	{
264 		if ( !("insert" in connectedSignals) )
265 		{
266 			Signals.connectData(
267 			getStruct(),
268 			"insert",
269 			cast(GCallback)&callBackInsert,
270 			cast(void*)this,
271 			null,
272 			connectFlags);
273 			connectedSignals["insert"] = 1;
274 		}
275 		onInsertListeners ~= dlg;
276 	}
277 	extern(C) static void callBackInsert(GtkMenuShell* menuShellStruct, GtkWidget* child, gint position, MenuShell _menuShell)
278 	{
279 		foreach ( void delegate(Widget, gint, MenuShell) dlg ; _menuShell.onInsertListeners )
280 		{
281 			dlg(ObjectG.getDObject!(Widget)(child), position, _menuShell);
282 		}
283 	}
284 	
285 	void delegate(GtkMenuDirectionType, MenuShell)[] onMoveCurrentListeners;
286 	/**
287 	 * An keybinding signal which moves the current menu item
288 	 * in the direction specified by direction.
289 	 */
290 	void addOnMoveCurrent(void delegate(GtkMenuDirectionType, MenuShell) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
291 	{
292 		if ( !("move-current" in connectedSignals) )
293 		{
294 			Signals.connectData(
295 			getStruct(),
296 			"move-current",
297 			cast(GCallback)&callBackMoveCurrent,
298 			cast(void*)this,
299 			null,
300 			connectFlags);
301 			connectedSignals["move-current"] = 1;
302 		}
303 		onMoveCurrentListeners ~= dlg;
304 	}
305 	extern(C) static void callBackMoveCurrent(GtkMenuShell* menushellStruct, GtkMenuDirectionType direction, MenuShell _menuShell)
306 	{
307 		foreach ( void delegate(GtkMenuDirectionType, MenuShell) dlg ; _menuShell.onMoveCurrentListeners )
308 		{
309 			dlg(direction, _menuShell);
310 		}
311 	}
312 	
313 	bool delegate(gint, MenuShell)[] onMoveSelectedListeners;
314 	/**
315 	 * The ::move-selected signal is emitted to move the selection to
316 	 * another item.
317 	 * TRUE to stop the signal emission, FALSE to continue
318 	 * Since 2.12
319 	 */
320 	void addOnMoveSelected(bool delegate(gint, MenuShell) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
321 	{
322 		if ( !("move-selected" in connectedSignals) )
323 		{
324 			Signals.connectData(
325 			getStruct(),
326 			"move-selected",
327 			cast(GCallback)&callBackMoveSelected,
328 			cast(void*)this,
329 			null,
330 			connectFlags);
331 			connectedSignals["move-selected"] = 1;
332 		}
333 		onMoveSelectedListeners ~= dlg;
334 	}
335 	extern(C) static gboolean callBackMoveSelected(GtkMenuShell* menuShellStruct, gint distance, MenuShell _menuShell)
336 	{
337 		foreach ( bool delegate(gint, MenuShell) dlg ; _menuShell.onMoveSelectedListeners )
338 		{
339 			if ( dlg(distance, _menuShell) )
340 			{
341 				return 1;
342 			}
343 		}
344 		
345 		return 0;
346 	}
347 	
348 	void delegate(MenuShell)[] onSelectionDoneListeners;
349 	/**
350 	 * This signal is emitted when a selection has been
351 	 * completed within a menu shell.
352 	 */
353 	void addOnSelectionDone(void delegate(MenuShell) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
354 	{
355 		if ( !("selection-done" in connectedSignals) )
356 		{
357 			Signals.connectData(
358 			getStruct(),
359 			"selection-done",
360 			cast(GCallback)&callBackSelectionDone,
361 			cast(void*)this,
362 			null,
363 			connectFlags);
364 			connectedSignals["selection-done"] = 1;
365 		}
366 		onSelectionDoneListeners ~= dlg;
367 	}
368 	extern(C) static void callBackSelectionDone(GtkMenuShell* menushellStruct, MenuShell _menuShell)
369 	{
370 		foreach ( void delegate(MenuShell) dlg ; _menuShell.onSelectionDoneListeners )
371 		{
372 			dlg(_menuShell);
373 		}
374 	}
375 	
376 	
377 	/**
378 	 * Adds a new GtkMenuItem to the end of the menu shell's
379 	 * item list.
380 	 * Params:
381 	 * child = The GtkMenuItem to add
382 	 */
383 	public void append(Widget child)
384 	{
385 		// void gtk_menu_shell_append (GtkMenuShell *menu_shell,  GtkWidget *child);
386 		gtk_menu_shell_append(gtkMenuShell, (child is null) ? null : child.getWidgetStruct());
387 	}
388 	
389 	/**
390 	 * Adds a new GtkMenuItem to the beginning of the menu shell's
391 	 * item list.
392 	 * Params:
393 	 * child = The GtkMenuItem to add
394 	 */
395 	public void prepend(Widget child)
396 	{
397 		// void gtk_menu_shell_prepend (GtkMenuShell *menu_shell,  GtkWidget *child);
398 		gtk_menu_shell_prepend(gtkMenuShell, (child is null) ? null : child.getWidgetStruct());
399 	}
400 	
401 	/**
402 	 * Adds a new GtkMenuItem to the menu shell's item list
403 	 * at the position indicated by position.
404 	 * Params:
405 	 * child = The GtkMenuItem to add
406 	 * position = The position in the item list where child
407 	 * is added. Positions are numbered from 0 to n-1
408 	 */
409 	public void insert(Widget child, int position)
410 	{
411 		// void gtk_menu_shell_insert (GtkMenuShell *menu_shell,  GtkWidget *child,  gint position);
412 		gtk_menu_shell_insert(gtkMenuShell, (child is null) ? null : child.getWidgetStruct(), position);
413 	}
414 	
415 	/**
416 	 * Deactivates the menu shell.
417 	 * Typically this results in the menu shell being erased
418 	 * from the screen.
419 	 */
420 	public void deactivate()
421 	{
422 		// void gtk_menu_shell_deactivate (GtkMenuShell *menu_shell);
423 		gtk_menu_shell_deactivate(gtkMenuShell);
424 	}
425 	
426 	/**
427 	 * Selects the menu item from the menu shell.
428 	 * Params:
429 	 * menuItem = The GtkMenuItem to select
430 	 */
431 	public void selectItem(Widget menuItem)
432 	{
433 		// void gtk_menu_shell_select_item (GtkMenuShell *menu_shell,  GtkWidget *menu_item);
434 		gtk_menu_shell_select_item(gtkMenuShell, (menuItem is null) ? null : menuItem.getWidgetStruct());
435 	}
436 	
437 	/**
438 	 * Select the first visible or selectable child of the menu shell;
439 	 * don't select tearoff items unless the only item is a tearoff
440 	 * item.
441 	 * Since 2.2
442 	 * Params:
443 	 * searchSensitive = if TRUE, search for the first selectable
444 	 * menu item, otherwise select nothing if
445 	 * the first item isn't sensitive. This
446 	 * should be FALSE if the menu is being
447 	 * popped up initially.
448 	 */
449 	public void selectFirst(int searchSensitive)
450 	{
451 		// void gtk_menu_shell_select_first (GtkMenuShell *menu_shell,  gboolean search_sensitive);
452 		gtk_menu_shell_select_first(gtkMenuShell, searchSensitive);
453 	}
454 	
455 	/**
456 	 * Deselects the currently selected item from the menu shell,
457 	 * if any.
458 	 */
459 	public void deselect()
460 	{
461 		// void gtk_menu_shell_deselect (GtkMenuShell *menu_shell);
462 		gtk_menu_shell_deselect(gtkMenuShell);
463 	}
464 	
465 	/**
466 	 * Activates the menu item within the menu shell.
467 	 * Params:
468 	 * menuItem = the GtkMenuItem to activate
469 	 * forceDeactivate = if TRUE, force the deactivation of the
470 	 * menu shell after the menu item is activated
471 	 */
472 	public void activateItem(Widget menuItem, int forceDeactivate)
473 	{
474 		// void gtk_menu_shell_activate_item (GtkMenuShell *menu_shell,  GtkWidget *menu_item,  gboolean force_deactivate);
475 		gtk_menu_shell_activate_item(gtkMenuShell, (menuItem is null) ? null : menuItem.getWidgetStruct(), forceDeactivate);
476 	}
477 	
478 	/**
479 	 * Cancels the selection within the menu shell.
480 	 * Since 2.4
481 	 */
482 	public void cancel()
483 	{
484 		// void gtk_menu_shell_cancel (GtkMenuShell *menu_shell);
485 		gtk_menu_shell_cancel(gtkMenuShell);
486 	}
487 	
488 	/**
489 	 * If take_focus is TRUE (the default) the menu shell will take
490 	 * the keyboard focus so that it will receive all keyboard events
491 	 * which is needed to enable keyboard navigation in menus.
492 	 * Setting take_focus to FALSE is useful only for special applications
493 	 * like virtual keyboard implementations which should not take keyboard
494 	 * focus.
495 	 * The take_focus state of a menu or menu bar is automatically
496 	 * propagated to submenus whenever a submenu is popped up, so you
497 	 * don't have to worry about recursively setting it for your entire
498 	 * menu hierarchy. Only when programmatically picking a submenu and
499 	 * popping it up manually, the take_focus property of the submenu
500 	 * needs to be set explicitely.
501 	 * Since 2.8
502 	 * Params:
503 	 * takeFocus = TRUE if the menu shell should take the keyboard
504 	 * focus on popup
505 	 */
506 	public void setTakeFocus(int takeFocus)
507 	{
508 		// void gtk_menu_shell_set_take_focus (GtkMenuShell *menu_shell,  gboolean take_focus);
509 		gtk_menu_shell_set_take_focus(gtkMenuShell, takeFocus);
510 	}
511 	
512 	/**
513 	 * Returns TRUE if the menu shell will take the keyboard focus on popup.
514 	 * Since 2.8
515 	 * Returns: TRUE if the menu shell will take the keyboard focus on popup.
516 	 */
517 	public int getTakeFocus()
518 	{
519 		// gboolean gtk_menu_shell_get_take_focus (GtkMenuShell *menu_shell);
520 		return gtk_menu_shell_get_take_focus(gtkMenuShell);
521 	}
522 	
523 	/**
524 	 * Gets the currently selected item.
525 	 * Returns: the currently selected item. [transfer none] Since 3.0
526 	 */
527 	public Widget getSelectedItem()
528 	{
529 		// GtkWidget * gtk_menu_shell_get_selected_item (GtkMenuShell *menu_shell);
530 		auto p = gtk_menu_shell_get_selected_item(gtkMenuShell);
531 		
532 		if(p is null)
533 		{
534 			return null;
535 		}
536 		
537 		return ObjectG.getDObject!(Widget)(cast(GtkWidget*) p);
538 	}
539 	
540 	/**
541 	 * Gets the parent menu shell.
542 	 * The parent menu shell of a submenu is the GtkMenu or GtkMenuBar
543 	 * from which it was opened up.
544 	 * Returns: the parent GtkMenuShell. [transfer none] Since 3.0
545 	 */
546 	public Widget getParentShell()
547 	{
548 		// GtkWidget * gtk_menu_shell_get_parent_shell (GtkMenuShell *menu_shell);
549 		auto p = gtk_menu_shell_get_parent_shell(gtkMenuShell);
550 		
551 		if(p is null)
552 		{
553 			return null;
554 		}
555 		
556 		return ObjectG.getDObject!(Widget)(cast(GtkWidget*) p);
557 	}
558 	
559 	/**
560 	 * Establishes a binding between a GtkMenuShell and a GMenuModel.
561 	 * The contents of shell are removed and then refilled with menu items
562 	 * according to model. When model changes, shell is updated.
563 	 * Calling this function twice on shell with different model will
564 	 * cause the first binding to be replaced with a binding to the new
565 	 * model. If model is NULL then any previous binding is undone and
566 	 * all children are removed.
567 	 * with_separators determines if toplevel items (eg: sections) have
568 	 * separators inserted between them. This is typically desired for
569 	 * menus but doesn't make sense for menubars.
570 	 * If action_namespace is non-NULL then the effect is as if all
571 	 * actions mentioned in the model have their names prefixed with the
572 	 * namespace, plus a dot. For example, if the action "quit" is
573 	 * mentioned and action_namespace is "app" then the effective action
574 	 * name is "app.quit".
575 	 * This function uses GtkActionable to define the action name and
576 	 * target values on the created menu items. If you want to use an
577 	 * action group other than "app" and "win", or if you want to use a
578 	 * GtkMenuShell outside of a GtkApplicationWindow, then you will need
579 	 * to attach your own action group to the widget hierarchy using
580 	 * gtk_widget_insert_action_group(). As an example, if you created a
581 	 * group with a "quit" action and inserted it with the name "mygroup"
582 	 * then you would use the action name "mygroup.quit" in your
583 	 * GMenuModel.
584 	 * For most cases you are probably better off using
585 	 * gtk_menu_new_from_model() or gtk_menu_bar_new_from_model() or just
586 	 * directly passing the GMenuModel to gtk_application_set_app_menu() or
587 	 * gtk_application_set_menu_bar().
588 	 * Params:
589 	 * model = the GMenuModel to bind to or NULL to remove
590 	 * binding. [allow-none]
591 	 * actionNamespace = the namespace for actions in model. [allow-none]
592 	 * withSeparators = TRUE if toplevel items in shell should have
593 	 * separators between them
594 	 * Since 3.6
595 	 */
596 	public void bindModel(MenuModel model, string actionNamespace, int withSeparators)
597 	{
598 		// void gtk_menu_shell_bind_model (GtkMenuShell *menu_shell,  GMenuModel *model,  const gchar *action_namespace,  gboolean with_separators);
599 		gtk_menu_shell_bind_model(gtkMenuShell, (model is null) ? null : model.getMenuModelStruct(), Str.toStringz(actionNamespace), withSeparators);
600 	}
601 }