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 module gtk.Application;
26 
27 private import gio.ActionGroupIF;
28 private import gio.ActionGroupT;
29 private import gio.ActionMapIF;
30 private import gio.ActionMapT;
31 private import gio.Application : GioApplication = Application;
32 private import gio.Menu;
33 private import gio.MenuModel;
34 private import glib.ConstructionException;
35 private import glib.ListG;
36 private import glib.Str;
37 private import glib.Variant;
38 private import gobject.ObjectG;
39 private import gobject.Signals;
40 private import gtk.Window;
41 private import gtkc.gtk;
42 public  import gtkc.gtktypes;
43 private import std.algorithm;
44 
45 
46 /**
47  * #GtkApplication is a class that handles many important aspects
48  * of a GTK+ application in a convenient fashion, without enforcing
49  * a one-size-fits-all application model.
50  * 
51  * Currently, GtkApplication handles GTK+ initialization, application
52  * uniqueness, session management, provides some basic scriptability and
53  * desktop shell integration by exporting actions and menus and manages a
54  * list of toplevel windows whose life-cycle is automatically tied to the
55  * life-cycle of your application.
56  * 
57  * While GtkApplication works fine with plain #GtkWindows, it is recommended
58  * to use it together with #GtkApplicationWindow.
59  * 
60  * When GDK threads are enabled, GtkApplication will acquire the GDK
61  * lock when invoking actions that arrive from other processes.  The GDK
62  * lock is not touched for local action invocations.  In order to have
63  * actions invoked in a predictable context it is therefore recommended
64  * that the GDK lock be held while invoking actions locally with
65  * g_action_group_activate_action().  The same applies to actions
66  * associated with #GtkApplicationWindow and to the “activate” and
67  * “open” #GApplication methods.
68  * 
69  * ## Automatic resources ## {#automatic-resources}
70  * 
71  * #GtkApplication will automatically load menus from the #GtkBuilder
72  * resource located at "gtk/menus.ui", relative to the application's
73  * resource base path (see g_application_set_resource_base_path()).  The
74  * menu with the ID "app-menu" is taken as the application's app menu
75  * and the menu with the ID "menubar" is taken as the application's
76  * menubar.  Additional menus (most interesting submenus) can be named
77  * and accessed via gtk_application_get_menu_by_id() which allows for
78  * dynamic population of a part of the menu structure.
79  * 
80  * If the resources "gtk/menus-appmenu.ui" or "gtk/menus-traditional.ui" are
81  * present then these files will be used in preference, depending on the value
82  * of gtk_application_prefers_app_menu(). If the resource "gtk/menus-common.ui"
83  * is present it will be loaded as well. This is useful for storing items that
84  * are referenced from both "gtk/menus-appmenu.ui" and
85  * "gtk/menus-traditional.ui".
86  * 
87  * It is also possible to provide the menus manually using
88  * gtk_application_set_app_menu() and gtk_application_set_menubar().
89  * 
90  * #GtkApplication will also automatically setup an icon search path for
91  * the default icon theme by appending "icons" to the resource base
92  * path.  This allows your application to easily store its icons as
93  * resources.  See gtk_icon_theme_add_resource_path() for more
94  * information.
95  * 
96  * If there is a resource located at "gtk/help-overlay.ui" which
97  * defines a #GtkShortcutsWindow with ID "help_overlay" then GtkApplication
98  * associates an instance of this shortcuts window with each
99  * #GtkApplicationWindow and sets up keyboard accelerators (Control-F1
100  * and Control-?) to open it. To create a menu item that displays the
101  * shortcuts window, associate the item with the action win.show-help-overlay.
102  * 
103  * ## A simple application ## {#gtkapplication}
104  * 
105  * [A simple example](https://git.gnome.org/browse/gtk+/tree/examples/bp/bloatpad.c)
106  * 
107  * GtkApplication optionally registers with a session manager
108  * of the users session (if you set the #GtkApplication:register-session
109  * property) and offers various functionality related to the session
110  * life-cycle.
111  * 
112  * An application can block various ways to end the session with
113  * the gtk_application_inhibit() function. Typical use cases for
114  * this kind of inhibiting are long-running, uninterruptible operations,
115  * such as burning a CD or performing a disk backup. The session
116  * manager may not honor the inhibitor, but it can be expected to
117  * inform the user about the negative consequences of ending the
118  * session while inhibitors are present.
119  * 
120  * ## See Also ## {#seealso}
121  * [HowDoI: Using GtkApplication](https://wiki.gnome.org/HowDoI/GtkApplication),
122  * [Getting Started with GTK+: Basics](https://developer.gnome.org/gtk3/stable/gtk-getting-started.html#id-1.2.3.3)
123  */
124 public class Application : GioApplication
125 {
126 	/** the main Gtk struct */
127 	protected GtkApplication* gtkApplication;
128 
129 	/** Get the main Gtk struct */
130 	public GtkApplication* getGtkApplicationStruct(bool transferOwnership = false)
131 	{
132 		if (transferOwnership)
133 			ownedRef = false;
134 		return gtkApplication;
135 	}
136 
137 	/** the main Gtk struct as a void* */
138 	protected override void* getStruct()
139 	{
140 		return cast(void*)gtkApplication;
141 	}
142 
143 	protected override void setStruct(GObject* obj)
144 	{
145 		gtkApplication = cast(GtkApplication*)obj;
146 		super.setStruct(obj);
147 	}
148 
149 	/**
150 	 * Sets our main struct and passes it to the parent class.
151 	 */
152 	public this (GtkApplication* gtkApplication, bool ownedRef = false)
153 	{
154 		this.gtkApplication = gtkApplication;
155 		super(cast(GApplication*)gtkApplication, ownedRef);
156 	}
157 
158 	/**
159 	 * Sets zero or more keyboard accelerators that will trigger the
160 	 * given action. The first item in accels will be the primary
161 	 * accelerator, which may be displayed in the UI.
162 	 *
163 	 * To remove all accelerators for an action, use an empty
164 	 * array for accels.
165 	 *
166 	 * Params:
167 	 *     detailedActionName = a detailed action name, specifying an action
168 	 *         and target to associate accelerators with
169 	 *     accels = a list of accelerators in the format
170 	 *         understood by gtk_accelerator_parse()
171 	 *
172 	 * Since: 3.12
173 	 */
174 	public void setAccelsForAction(string detailedActionName, string[] accels)
175 	{
176 		char** accel;
177 		
178 		if (accels)
179 			accel = Str.toStringzArray(accels);
180 		else
181 			accel = [cast(char*)null].ptr;
182 		
183 		gtk_application_set_accels_for_action(gtkApplication, Str.toStringz(detailedActionName), accel);
184 	}
185 
186 	/**
187 	 */
188 
189 	/** */
190 	public static GType getType()
191 	{
192 		return gtk_application_get_type();
193 	}
194 
195 	/**
196 	 * Creates a new #GtkApplication instance.
197 	 *
198 	 * When using #GtkApplication, it is not necessary to call gtk_init()
199 	 * manually. It is called as soon as the application gets registered as
200 	 * the primary instance.
201 	 *
202 	 * Concretely, gtk_init() is called in the default handler for the
203 	 * #GApplication::startup signal. Therefore, #GtkApplication subclasses should
204 	 * chain up in their #GApplication::startup handler before using any GTK+ API.
205 	 *
206 	 * Note that commandline arguments are not passed to gtk_init().
207 	 * All GTK+ functionality that is available via commandline arguments
208 	 * can also be achieved by setting suitable environment variables
209 	 * such as `G_DEBUG`, so this should not be a big
210 	 * problem. If you absolutely must support GTK+ commandline arguments,
211 	 * you can explicitly call gtk_init() before creating the application
212 	 * instance.
213 	 *
214 	 * If non-%NULL, the application ID must be valid.  See
215 	 * g_application_id_is_valid().
216 	 *
217 	 * If no application ID is given then some features (most notably application
218 	 * uniqueness) will be disabled. A null application ID is only allowed with
219 	 * GTK+ 3.6 or later.
220 	 *
221 	 * Params:
222 	 *     applicationId = The application ID.
223 	 *     flags = the application flags
224 	 *
225 	 * Returns: a new #GtkApplication instance
226 	 *
227 	 * Since: 3.0
228 	 *
229 	 * Throws: ConstructionException GTK+ fails to create the object.
230 	 */
231 	public this(string applicationId, GApplicationFlags flags)
232 	{
233 		auto p = gtk_application_new(Str.toStringz(applicationId), flags);
234 		
235 		if(p is null)
236 		{
237 			throw new ConstructionException("null returned by new");
238 		}
239 		
240 		this(cast(GtkApplication*) p, true);
241 	}
242 
243 	/**
244 	 * Installs an accelerator that will cause the named action
245 	 * to be activated when the key combination specificed by @accelerator
246 	 * is pressed.
247 	 *
248 	 * @accelerator must be a string that can be parsed by gtk_accelerator_parse(),
249 	 * e.g. "<Primary>q" or “<Control><Alt>p”.
250 	 *
251 	 * @action_name must be the name of an action as it would be used
252 	 * in the app menu, i.e. actions that have been added to the application
253 	 * are referred to with an “app.” prefix, and window-specific actions
254 	 * with a “win.” prefix.
255 	 *
256 	 * GtkApplication also extracts accelerators out of “accel” attributes
257 	 * in the #GMenuModels passed to gtk_application_set_app_menu() and
258 	 * gtk_application_set_menubar(), which is usually more convenient
259 	 * than calling this function for each accelerator.
260 	 *
261 	 * Deprecated: Use gtk_application_set_accels_for_action() instead
262 	 *
263 	 * Params:
264 	 *     accelerator = accelerator string
265 	 *     actionName = the name of the action to activate
266 	 *     parameter = parameter to pass when activating the action,
267 	 *         or %NULL if the action does not accept an activation parameter
268 	 *
269 	 * Since: 3.4
270 	 */
271 	public void addAccelerator(string accelerator, string actionName, Variant parameter)
272 	{
273 		gtk_application_add_accelerator(gtkApplication, Str.toStringz(accelerator), Str.toStringz(actionName), (parameter is null) ? null : parameter.getVariantStruct());
274 	}
275 
276 	/**
277 	 * Adds a window to @application.
278 	 *
279 	 * This call can only happen after the @application has started;
280 	 * typically, you should add new application windows in response
281 	 * to the emission of the #GApplication::activate signal.
282 	 *
283 	 * This call is equivalent to setting the #GtkWindow:application
284 	 * property of @window to @application.
285 	 *
286 	 * Normally, the connection between the application and the window
287 	 * will remain until the window is destroyed, but you can explicitly
288 	 * remove it with gtk_application_remove_window().
289 	 *
290 	 * GTK+ will keep the @application running as long as it has
291 	 * any windows.
292 	 *
293 	 * Params:
294 	 *     window = a #GtkWindow
295 	 *
296 	 * Since: 3.0
297 	 */
298 	public void addWindow(Window window)
299 	{
300 		gtk_application_add_window(gtkApplication, (window is null) ? null : window.getWindowStruct());
301 	}
302 
303 	/**
304 	 * Gets the accelerators that are currently associated with
305 	 * the given action.
306 	 *
307 	 * Params:
308 	 *     detailedActionName = a detailed action name, specifying an action
309 	 *         and target to obtain accelerators for
310 	 *
311 	 * Returns: accelerators for @detailed_action_name, as
312 	 *     a %NULL-terminated array. Free with g_strfreev() when no longer needed
313 	 *
314 	 * Since: 3.12
315 	 */
316 	public string[] getAccelsForAction(string detailedActionName)
317 	{
318 		auto retStr = gtk_application_get_accels_for_action(gtkApplication, Str.toStringz(detailedActionName));
319 		
320 		scope(exit) Str.freeStringArray(retStr);
321 		return Str.toStringArray(retStr);
322 	}
323 
324 	/**
325 	 * Returns the list of actions (possibly empty) that @accel maps to.
326 	 * Each item in the list is a detailed action name in the usual form.
327 	 *
328 	 * This might be useful to discover if an accel already exists in
329 	 * order to prevent installation of a conflicting accelerator (from
330 	 * an accelerator editor or a plugin system, for example). Note that
331 	 * having more than one action per accelerator may not be a bad thing
332 	 * and might make sense in cases where the actions never appear in the
333 	 * same context.
334 	 *
335 	 * In case there are no actions for a given accelerator, an empty array
336 	 * is returned.  %NULL is never returned.
337 	 *
338 	 * It is a programmer error to pass an invalid accelerator string.
339 	 * If you are unsure, check it with gtk_accelerator_parse() first.
340 	 *
341 	 * Params:
342 	 *     accel = an accelerator that can be parsed by gtk_accelerator_parse()
343 	 *
344 	 * Returns: a %NULL-terminated array of actions for @accel
345 	 *
346 	 * Since: 3.14
347 	 */
348 	public string[] getActionsForAccel(string accel)
349 	{
350 		auto retStr = gtk_application_get_actions_for_accel(gtkApplication, Str.toStringz(accel));
351 		
352 		scope(exit) Str.freeStringArray(retStr);
353 		return Str.toStringArray(retStr);
354 	}
355 
356 	/**
357 	 * Gets the “active” window for the application.
358 	 *
359 	 * The active window is the one that was most recently focused (within
360 	 * the application).  This window may not have the focus at the moment
361 	 * if another application has it — this is just the most
362 	 * recently-focused window within this application.
363 	 *
364 	 * Returns: the active window
365 	 *
366 	 * Since: 3.6
367 	 */
368 	public Window getActiveWindow()
369 	{
370 		auto p = gtk_application_get_active_window(gtkApplication);
371 		
372 		if(p is null)
373 		{
374 			return null;
375 		}
376 		
377 		return ObjectG.getDObject!(Window)(cast(GtkWindow*) p);
378 	}
379 
380 	/**
381 	 * Returns the menu model that has been set with
382 	 * gtk_application_set_app_menu().
383 	 *
384 	 * Returns: the application menu of @application
385 	 *     or %NULL if no application menu has been set.
386 	 *
387 	 * Since: 3.4
388 	 */
389 	public MenuModel getAppMenu()
390 	{
391 		auto p = gtk_application_get_app_menu(gtkApplication);
392 		
393 		if(p is null)
394 		{
395 			return null;
396 		}
397 		
398 		return ObjectG.getDObject!(MenuModel)(cast(GMenuModel*) p);
399 	}
400 
401 	/**
402 	 * Gets a menu from automatically loaded resources.
403 	 * See [Automatic resources][automatic-resources]
404 	 * for more information.
405 	 *
406 	 * Params:
407 	 *     id = the id of the menu to look up
408 	 *
409 	 * Returns: Gets the menu with the
410 	 *     given id from the automatically loaded resources
411 	 *
412 	 * Since: 3.14
413 	 */
414 	public Menu getMenuById(string id)
415 	{
416 		auto p = gtk_application_get_menu_by_id(gtkApplication, Str.toStringz(id));
417 		
418 		if(p is null)
419 		{
420 			return null;
421 		}
422 		
423 		return ObjectG.getDObject!(Menu)(cast(GMenu*) p);
424 	}
425 
426 	/**
427 	 * Returns the menu model that has been set with
428 	 * gtk_application_set_menubar().
429 	 *
430 	 * Returns: the menubar for windows of @application
431 	 *
432 	 * Since: 3.4
433 	 */
434 	public MenuModel getMenubar()
435 	{
436 		auto p = gtk_application_get_menubar(gtkApplication);
437 		
438 		if(p is null)
439 		{
440 			return null;
441 		}
442 		
443 		return ObjectG.getDObject!(MenuModel)(cast(GMenuModel*) p);
444 	}
445 
446 	/**
447 	 * Returns the #GtkApplicationWindow with the given ID.
448 	 *
449 	 * The ID of a #GtkApplicationWindow can be retrieved with
450 	 * gtk_application_window_get_id().
451 	 *
452 	 * Params:
453 	 *     id = an identifier number
454 	 *
455 	 * Returns: the window with ID @id, or
456 	 *     %NULL if there is no window with this ID
457 	 *
458 	 * Since: 3.6
459 	 */
460 	public Window getWindowById(uint id)
461 	{
462 		auto p = gtk_application_get_window_by_id(gtkApplication, id);
463 		
464 		if(p is null)
465 		{
466 			return null;
467 		}
468 		
469 		return ObjectG.getDObject!(Window)(cast(GtkWindow*) p);
470 	}
471 
472 	/**
473 	 * Gets a list of the #GtkWindows associated with @application.
474 	 *
475 	 * The list is sorted by most recently focused window, such that the first
476 	 * element is the currently focused window. (Useful for choosing a parent
477 	 * for a transient window.)
478 	 *
479 	 * The list that is returned should not be modified in any way. It will
480 	 * only remain valid until the next focus change or window creation or
481 	 * deletion.
482 	 *
483 	 * Returns: a #GList of #GtkWindow
484 	 *
485 	 * Since: 3.0
486 	 */
487 	public ListG getWindows()
488 	{
489 		auto p = gtk_application_get_windows(gtkApplication);
490 		
491 		if(p is null)
492 		{
493 			return null;
494 		}
495 		
496 		return new ListG(cast(GList*) p);
497 	}
498 
499 	/**
500 	 * Inform the session manager that certain types of actions should be
501 	 * inhibited. This is not guaranteed to work on all platforms and for
502 	 * all types of actions.
503 	 *
504 	 * Applications should invoke this method when they begin an operation
505 	 * that should not be interrupted, such as creating a CD or DVD. The
506 	 * types of actions that may be blocked are specified by the @flags
507 	 * parameter. When the application completes the operation it should
508 	 * call gtk_application_uninhibit() to remove the inhibitor. Note that
509 	 * an application can have multiple inhibitors, and all of them must
510 	 * be individually removed. Inhibitors are also cleared when the
511 	 * application exits.
512 	 *
513 	 * Applications should not expect that they will always be able to block
514 	 * the action. In most cases, users will be given the option to force
515 	 * the action to take place.
516 	 *
517 	 * Reasons should be short and to the point.
518 	 *
519 	 * If @window is given, the session manager may point the user to
520 	 * this window to find out more about why the action is inhibited.
521 	 *
522 	 * Params:
523 	 *     window = a #GtkWindow, or %NULL
524 	 *     flags = what types of actions should be inhibited
525 	 *     reason = a short, human-readable string that explains
526 	 *         why these operations are inhibited
527 	 *
528 	 * Returns: A non-zero cookie that is used to uniquely identify this
529 	 *     request. It should be used as an argument to gtk_application_uninhibit()
530 	 *     in order to remove the request. If the platform does not support
531 	 *     inhibiting or the request failed for some reason, 0 is returned.
532 	 *
533 	 * Since: 3.4
534 	 */
535 	public uint inhibit(Window window, GtkApplicationInhibitFlags flags, string reason)
536 	{
537 		return gtk_application_inhibit(gtkApplication, (window is null) ? null : window.getWindowStruct(), flags, Str.toStringz(reason));
538 	}
539 
540 	/**
541 	 * Determines if any of the actions specified in @flags are
542 	 * currently inhibited (possibly by another application).
543 	 *
544 	 * Params:
545 	 *     flags = what types of actions should be queried
546 	 *
547 	 * Returns: %TRUE if any of the actions specified in @flags are inhibited
548 	 *
549 	 * Since: 3.4
550 	 */
551 	public bool isInhibited(GtkApplicationInhibitFlags flags)
552 	{
553 		return gtk_application_is_inhibited(gtkApplication, flags) != 0;
554 	}
555 
556 	/**
557 	 * Lists the detailed action names which have associated accelerators.
558 	 * See gtk_application_set_accels_for_action().
559 	 *
560 	 * Returns: a %NULL-terminated array of strings,
561 	 *     free with g_strfreev() when done
562 	 *
563 	 * Since: 3.12
564 	 */
565 	public string[] listActionDescriptions()
566 	{
567 		auto retStr = gtk_application_list_action_descriptions(gtkApplication);
568 		
569 		scope(exit) Str.freeStringArray(retStr);
570 		return Str.toStringArray(retStr);
571 	}
572 
573 	/**
574 	 * Determines if the desktop environment in which the application is
575 	 * running would prefer an application menu be shown.
576 	 *
577 	 * If this function returns %TRUE then the application should call
578 	 * gtk_application_set_app_menu() with the contents of an application
579 	 * menu, which will be shown by the desktop environment.  If it returns
580 	 * %FALSE then you should consider using an alternate approach, such as
581 	 * a menubar.
582 	 *
583 	 * The value returned by this function is purely advisory and you are
584 	 * free to ignore it.  If you call gtk_application_set_app_menu() even
585 	 * if the desktop environment doesn't support app menus, then a fallback
586 	 * will be provided.
587 	 *
588 	 * Applications are similarly free not to set an app menu even if the
589 	 * desktop environment wants to show one.  In that case, a fallback will
590 	 * also be created by the desktop environment (GNOME, for example, uses
591 	 * a menu with only a "Quit" item in it).
592 	 *
593 	 * The value returned by this function never changes.  Once it returns a
594 	 * particular value, it is guaranteed to always return the same value.
595 	 *
596 	 * You may only call this function after the application has been
597 	 * registered and after the base startup handler has run.  You're most
598 	 * likely to want to use this from your own startup handler.  It may
599 	 * also make sense to consult this function while constructing UI (in
600 	 * activate, open or an action activation handler) in order to determine
601 	 * if you should show a gear menu or not.
602 	 *
603 	 * This function will return %FALSE on Mac OS and a default app menu
604 	 * will be created automatically with the "usual" contents of that menu
605 	 * typical to most Mac OS applications.  If you call
606 	 * gtk_application_set_app_menu() anyway, then this menu will be
607 	 * replaced with your own.
608 	 *
609 	 * Returns: %TRUE if you should set an app menu
610 	 *
611 	 * Since: 3.14
612 	 */
613 	public bool prefersAppMenu()
614 	{
615 		return gtk_application_prefers_app_menu(gtkApplication) != 0;
616 	}
617 
618 	/**
619 	 * Removes an accelerator that has been previously added
620 	 * with gtk_application_add_accelerator().
621 	 *
622 	 * Deprecated: Use gtk_application_set_accels_for_action() instead
623 	 *
624 	 * Params:
625 	 *     actionName = the name of the action to activate
626 	 *     parameter = parameter to pass when activating the action,
627 	 *         or %NULL if the action does not accept an activation parameter
628 	 *
629 	 * Since: 3.4
630 	 */
631 	public void removeAccelerator(string actionName, Variant parameter)
632 	{
633 		gtk_application_remove_accelerator(gtkApplication, Str.toStringz(actionName), (parameter is null) ? null : parameter.getVariantStruct());
634 	}
635 
636 	/**
637 	 * Remove a window from @application.
638 	 *
639 	 * If @window belongs to @application then this call is equivalent to
640 	 * setting the #GtkWindow:application property of @window to
641 	 * %NULL.
642 	 *
643 	 * The application may stop running as a result of a call to this
644 	 * function.
645 	 *
646 	 * Params:
647 	 *     window = a #GtkWindow
648 	 *
649 	 * Since: 3.0
650 	 */
651 	public void removeWindow(Window window)
652 	{
653 		gtk_application_remove_window(gtkApplication, (window is null) ? null : window.getWindowStruct());
654 	}
655 
656 	/**
657 	 * Sets or unsets the application menu for @application.
658 	 *
659 	 * This can only be done in the primary instance of the application,
660 	 * after it has been registered.  #GApplication::startup is a good place
661 	 * to call this.
662 	 *
663 	 * The application menu is a single menu containing items that typically
664 	 * impact the application as a whole, rather than acting on a specific
665 	 * window or document.  For example, you would expect to see
666 	 * “Preferences” or “Quit” in an application menu, but not “Save” or
667 	 * “Print”.
668 	 *
669 	 * If supported, the application menu will be rendered by the desktop
670 	 * environment.
671 	 *
672 	 * Use the base #GActionMap interface to add actions, to respond to the user
673 	 * selecting these menu items.
674 	 *
675 	 * Params:
676 	 *     appMenu = a #GMenuModel, or %NULL
677 	 *
678 	 * Since: 3.4
679 	 */
680 	public void setAppMenu(MenuModel appMenu)
681 	{
682 		gtk_application_set_app_menu(gtkApplication, (appMenu is null) ? null : appMenu.getMenuModelStruct());
683 	}
684 
685 	/**
686 	 * Sets or unsets the menubar for windows of @application.
687 	 *
688 	 * This is a menubar in the traditional sense.
689 	 *
690 	 * This can only be done in the primary instance of the application,
691 	 * after it has been registered.  #GApplication::startup is a good place
692 	 * to call this.
693 	 *
694 	 * Depending on the desktop environment, this may appear at the top of
695 	 * each window, or at the top of the screen.  In some environments, if
696 	 * both the application menu and the menubar are set, the application
697 	 * menu will be presented as if it were the first item of the menubar.
698 	 * Other environments treat the two as completely separate — for example,
699 	 * the application menu may be rendered by the desktop shell while the
700 	 * menubar (if set) remains in each individual window.
701 	 *
702 	 * Use the base #GActionMap interface to add actions, to respond to the
703 	 * user selecting these menu items.
704 	 *
705 	 * Params:
706 	 *     menubar = a #GMenuModel, or %NULL
707 	 *
708 	 * Since: 3.4
709 	 */
710 	public void setMenubar(MenuModel menubar)
711 	{
712 		gtk_application_set_menubar(gtkApplication, (menubar is null) ? null : menubar.getMenuModelStruct());
713 	}
714 
715 	/**
716 	 * Removes an inhibitor that has been established with gtk_application_inhibit().
717 	 * Inhibitors are also cleared when the application exits.
718 	 *
719 	 * Params:
720 	 *     cookie = a cookie that was returned by gtk_application_inhibit()
721 	 *
722 	 * Since: 3.4
723 	 */
724 	public void uninhibit(uint cookie)
725 	{
726 		gtk_application_uninhibit(gtkApplication, cookie);
727 	}
728 
729 	protected class OnWindowAddedDelegateWrapper
730 	{
731 		static OnWindowAddedDelegateWrapper[] listeners;
732 		void delegate(Window, Application) dlg;
733 		gulong handlerId;
734 		
735 		this(void delegate(Window, Application) dlg)
736 		{
737 			this.dlg = dlg;
738 			this.listeners ~= this;
739 		}
740 		
741 		void remove(OnWindowAddedDelegateWrapper source)
742 		{
743 			foreach(index, wrapper; listeners)
744 			{
745 				if (wrapper.handlerId == source.handlerId)
746 				{
747 					listeners[index] = null;
748 					listeners = std.algorithm.remove(listeners, index);
749 					break;
750 				}
751 			}
752 		}
753 	}
754 
755 	/**
756 	 * Emitted when a #GtkWindow is added to @application through
757 	 * gtk_application_add_window().
758 	 *
759 	 * Params:
760 	 *     window = the newly-added #GtkWindow
761 	 *
762 	 * Since: 3.2
763 	 */
764 	gulong addOnWindowAdded(void delegate(Window, Application) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
765 	{
766 		auto wrapper = new OnWindowAddedDelegateWrapper(dlg);
767 		wrapper.handlerId = Signals.connectData(
768 			this,
769 			"window-added",
770 			cast(GCallback)&callBackWindowAdded,
771 			cast(void*)wrapper,
772 			cast(GClosureNotify)&callBackWindowAddedDestroy,
773 			connectFlags);
774 		return wrapper.handlerId;
775 	}
776 	
777 	extern(C) static void callBackWindowAdded(GtkApplication* applicationStruct, GtkWindow* window, OnWindowAddedDelegateWrapper wrapper)
778 	{
779 		wrapper.dlg(ObjectG.getDObject!(Window)(window), wrapper.outer);
780 	}
781 	
782 	extern(C) static void callBackWindowAddedDestroy(OnWindowAddedDelegateWrapper wrapper, GClosure* closure)
783 	{
784 		wrapper.remove(wrapper);
785 	}
786 
787 	protected class OnWindowRemovedDelegateWrapper
788 	{
789 		static OnWindowRemovedDelegateWrapper[] listeners;
790 		void delegate(Window, Application) dlg;
791 		gulong handlerId;
792 		
793 		this(void delegate(Window, Application) dlg)
794 		{
795 			this.dlg = dlg;
796 			this.listeners ~= this;
797 		}
798 		
799 		void remove(OnWindowRemovedDelegateWrapper source)
800 		{
801 			foreach(index, wrapper; listeners)
802 			{
803 				if (wrapper.handlerId == source.handlerId)
804 				{
805 					listeners[index] = null;
806 					listeners = std.algorithm.remove(listeners, index);
807 					break;
808 				}
809 			}
810 		}
811 	}
812 
813 	/**
814 	 * Emitted when a #GtkWindow is removed from @application,
815 	 * either as a side-effect of being destroyed or explicitly
816 	 * through gtk_application_remove_window().
817 	 *
818 	 * Params:
819 	 *     window = the #GtkWindow that is being removed
820 	 *
821 	 * Since: 3.2
822 	 */
823 	gulong addOnWindowRemoved(void delegate(Window, Application) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
824 	{
825 		auto wrapper = new OnWindowRemovedDelegateWrapper(dlg);
826 		wrapper.handlerId = Signals.connectData(
827 			this,
828 			"window-removed",
829 			cast(GCallback)&callBackWindowRemoved,
830 			cast(void*)wrapper,
831 			cast(GClosureNotify)&callBackWindowRemovedDestroy,
832 			connectFlags);
833 		return wrapper.handlerId;
834 	}
835 	
836 	extern(C) static void callBackWindowRemoved(GtkApplication* applicationStruct, GtkWindow* window, OnWindowRemovedDelegateWrapper wrapper)
837 	{
838 		wrapper.dlg(ObjectG.getDObject!(Window)(window), wrapper.outer);
839 	}
840 	
841 	extern(C) static void callBackWindowRemovedDestroy(OnWindowRemovedDelegateWrapper wrapper, GClosure* closure)
842 	{
843 		wrapper.remove(wrapper);
844 	}
845 }