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