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