1 /*
2  * This file is part of gtkD.
3  *
4  * gtkD is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU Lesser General Public License
6  * as published by the Free Software Foundation; either version 3
7  * of the License, or (at your option) any later version, with
8  * some exceptions, please read the COPYING file.
9  *
10  * gtkD is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public License
16  * along with gtkD; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110, USA
18  */
19  
20 // generated automatically - do not change
21 // find conversion definition on APILookup.txt
22 // implement new conversion functionalities on the wrap.utils pakage
23 
24 /*
25  * Conversion parameters:
26  * inFile  = GtkApplication.html
27  * outPack = gtk
28  * outFile = Application
29  * strct   = GtkApplication
30  * realStrct=
31  * ctorStrct=
32  * clss    = Application
33  * interf  = 
34  * class Code: No
35  * interface Code: No
36  * template for:
37  * extend  = GioApplication
38  * implements:
39  * prefixes:
40  * 	- gtk_application_
41  * omit structs:
42  * omit prefixes:
43  * omit code:
44  * omit signals:
45  * imports:
46  * 	- glib.Str
47  * 	- glib.ListG
48  * 	- glib.Variant
49  * 	- gio.Application : GioApplication = Application
50  * 	- gio.MenuModel
51  * 	- gtk.Window
52  * structWrap:
53  * 	- GList* -> ListG
54  * 	- GMenuModel* -> MenuModel
55  * 	- GVariant* -> Variant
56  * 	- GtkWindow* -> Window
57  * module aliases:
58  * local aliases:
59  * overrides:
60  */
61 
62 module gtk.Application;
63 
64 public  import gtkc.gtktypes;
65 
66 private import gtkc.gtk;
67 private import glib.ConstructionException;
68 private import gobject.ObjectG;
69 
70 private import gobject.Signals;
71 public  import gtkc.gdktypes;
72 
73 private import glib.Str;
74 private import glib.ListG;
75 private import glib.Variant;
76 private import gio.Application : GioApplication = Application;
77 private import gio.MenuModel;
78 private import gtk.Window;
79 
80 
81 
82 
83 /**
84  * GtkApplication is a class that handles many important aspects
85  * of a GTK+ application in a convenient fashion, without enforcing
86  * a one-size-fits-all application model.
87  *
88  * Currently, GtkApplication handles GTK+ initialization, application
89  * uniqueness, session management, provides some basic scriptability and
90  * desktop shell integration by exporting actions and menus and manages a
91  * list of toplevel windows whose life-cycle is automatically tied to the
92  * life-cycle of your application.
93  *
94  * While GtkApplication works fine with plain GtkWindows, it is recommended
95  * to use it together with GtkApplicationWindow.
96  *
97  * When GDK threads are enabled, GtkApplication will acquire the GDK
98  * lock when invoking actions that arrive from other processes. The GDK
99  * lock is not touched for local action invocations. In order to have
100  * actions invoked in a predictable context it is therefore recommended
101  * that the GDK lock be held while invoking actions locally with
102  * g_action_group_activate_action(). The same applies to actions
103  * associated with GtkApplicationWindow and to the 'activate' and
104  * 'open' GApplication methods.
105  *
106  * To set an application menu for a GtkApplication, use
107  * gtk_application_set_app_menu(). The GMenuModel that this function
108  * expects is usually constructed using GtkBuilder, as seen in the
109  * following example. To specify a menubar that will be shown by
110  * GtkApplicationWindows, use gtk_application_set_menubar(). Use the base
111  * GActionMap interface to add actions, to respond to the user
112  * selecting these menu items.
113  *
114  * GTK+ displays these menus as expected, depending on the platform
115  * the application is running on.
116  *
117  * Figure Menu integration in OS X.
118  *
119  * Figure Menu integration in GNOME.
120  *
121  * Figure Menu integration in Xfce.
122  *
123  * $(DDOC_COMMENT example)
124  *
125  * GtkApplication optionally registers with a session manager
126  * of the users session (if you set the "register-session"
127  * property) and offers various functionality related to the session
128  * life-cycle.
129  *
130  * An application can block various ways to end the session with
131  * the gtk_application_inhibit() function. Typical use cases for
132  * this kind of inhibiting are long-running, uninterruptible operations,
133  * such as burning a CD or performing a disk backup. The session
134  * manager may not honor the inhibitor, but it can be expected to
135  * inform the user about the negative consequences of ending the
136  * session while inhibitors are present.
137  */
138 public class Application : GioApplication
139 {
140 	
141 	/** the main Gtk struct */
142 	protected GtkApplication* gtkApplication;
143 	
144 	
145 	public GtkApplication* getGtkApplicationStruct()
146 	{
147 		return gtkApplication;
148 	}
149 	
150 	
151 	/** the main Gtk struct as a void* */
152 	protected override void* getStruct()
153 	{
154 		return cast(void*)gtkApplication;
155 	}
156 	
157 	/**
158 	 * Sets our main struct and passes it to the parent class
159 	 */
160 	public this (GtkApplication* gtkApplication)
161 	{
162 		super(cast(GApplication*)gtkApplication);
163 		this.gtkApplication = gtkApplication;
164 	}
165 	
166 	protected override void setStruct(GObject* obj)
167 	{
168 		super.setStruct(obj);
169 		gtkApplication = cast(GtkApplication*)obj;
170 	}
171 	
172 	/**
173 	 */
174 	int[string] connectedSignals;
175 	
176 	void delegate(Window, Application)[] onWindowAddedListeners;
177 	/**
178 	 * Emitted when a GtkWindow is added to application through
179 	 * gtk_application_add_window().
180 	 * Since 3.2
181 	 */
182 	void addOnWindowAdded(void delegate(Window, Application) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
183 	{
184 		if ( !("window-added" in connectedSignals) )
185 		{
186 			Signals.connectData(
187 			getStruct(),
188 			"window-added",
189 			cast(GCallback)&callBackWindowAdded,
190 			cast(void*)this,
191 			null,
192 			connectFlags);
193 			connectedSignals["window-added"] = 1;
194 		}
195 		onWindowAddedListeners ~= dlg;
196 	}
197 	extern(C) static void callBackWindowAdded(GtkApplication* applicationStruct, GtkWindow* window, Application _application)
198 	{
199 		foreach ( void delegate(Window, Application) dlg ; _application.onWindowAddedListeners )
200 		{
201 			dlg(ObjectG.getDObject!(Window)(window), _application);
202 		}
203 	}
204 	
205 	void delegate(Window, Application)[] onWindowRemovedListeners;
206 	/**
207 	 * Emitted when a GtkWindow is removed from application,
208 	 * either as a side-effect of being destroyed or explicitly
209 	 * through gtk_application_remove_window().
210 	 * Since 3.2
211 	 */
212 	void addOnWindowRemoved(void delegate(Window, Application) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
213 	{
214 		if ( !("window-removed" in connectedSignals) )
215 		{
216 			Signals.connectData(
217 			getStruct(),
218 			"window-removed",
219 			cast(GCallback)&callBackWindowRemoved,
220 			cast(void*)this,
221 			null,
222 			connectFlags);
223 			connectedSignals["window-removed"] = 1;
224 		}
225 		onWindowRemovedListeners ~= dlg;
226 	}
227 	extern(C) static void callBackWindowRemoved(GtkApplication* applicationStruct, GtkWindow* window, Application _application)
228 	{
229 		foreach ( void delegate(Window, Application) dlg ; _application.onWindowRemovedListeners )
230 		{
231 			dlg(ObjectG.getDObject!(Window)(window), _application);
232 		}
233 	}
234 	
235 	
236 	/**
237 	 * Creates a new GtkApplication instance.
238 	 * When using GtkApplication, it is not necessary to call gtk_init()
239 	 * manually. It is called as soon as the application gets registered as
240 	 * the primary instance.
241 	 * Concretely, gtk_init() is called in the default handler for the
242 	 * "startup" signal. Therefore, GtkApplication subclasses should
243 	 * chain up in their "startup" handler before using any GTK+ API.
244 	 * Note that commandline arguments are not passed to gtk_init().
245 	 * All GTK+ functionality that is available via commandline arguments
246 	 * can also be achieved by setting suitable environment variables
247 	 * such as G_DEBUG, so this should not be a big
248 	 * problem. If you absolutely must support GTK+ commandline arguments,
249 	 * you can explicitly call gtk_init() before creating the application
250 	 * instance.
251 	 * If non-NULL, the application ID must be valid. See
252 	 * g_application_id_is_valid().
253 	 * If no application ID is given then some features (most notably application
254 	 * uniqueness) will be disabled. A null application ID is only allowed with
255 	 * GTK+ 3.6 or later.
256 	 * Params:
257 	 * applicationId = The application ID. [allow-none]
258 	 * flags = the application flags
259 	 * Throws: ConstructionException GTK+ fails to create the object.
260 	 */
261 	public this (string applicationId, GApplicationFlags flags)
262 	{
263 		// GtkApplication * gtk_application_new (const gchar *application_id,  GApplicationFlags flags);
264 		auto p = gtk_application_new(Str.toStringz(applicationId), flags);
265 		if(p is null)
266 		{
267 			throw new ConstructionException("null returned by gtk_application_new(Str.toStringz(applicationId), flags)");
268 		}
269 		this(cast(GtkApplication*) p);
270 	}
271 	
272 	/**
273 	 * Adds a window to application.
274 	 * This call is equivalent to setting the "application"
275 	 * property of window to application.
276 	 * Normally, the connection between the application and the window
277 	 * will remain until the window is destroyed, but you can explicitly
278 	 * remove it with gtk_application_remove_window().
279 	 * GTK+ will keep the application running as long as it has
280 	 * any windows.
281 	 * Params:
282 	 * window = a GtkWindow
283 	 * Since 3.0
284 	 */
285 	public void addWindow(Window window)
286 	{
287 		// void gtk_application_add_window (GtkApplication *application,  GtkWindow *window);
288 		gtk_application_add_window(gtkApplication, (window is null) ? null : window.getWindowStruct());
289 	}
290 	
291 	/**
292 	 * Remove a window from application.
293 	 * If window belongs to application then this call is equivalent to
294 	 * setting the "application" property of window to
295 	 * NULL.
296 	 * The application may stop running as a result of a call to this
297 	 * function.
298 	 * Params:
299 	 * window = a GtkWindow
300 	 * Since 3.0
301 	 */
302 	public void removeWindow(Window window)
303 	{
304 		// void gtk_application_remove_window (GtkApplication *application,  GtkWindow *window);
305 		gtk_application_remove_window(gtkApplication, (window is null) ? null : window.getWindowStruct());
306 	}
307 	
308 	/**
309 	 * Gets a list of the GtkWindows associated with application.
310 	 * The list is sorted by most recently focused window, such that the first
311 	 * element is the currently focused window. (Useful for choosing a parent
312 	 * for a transient window.)
313 	 * The list that is returned should not be modified in any way. It will
314 	 * only remain valid until the next focus change or window creation or
315 	 * deletion.
316 	 * Returns: a GList of GtkWindow. [element-type GtkWindow][transfer none] Since 3.0
317 	 */
318 	public ListG getWindows()
319 	{
320 		// GList * gtk_application_get_windows (GtkApplication *application);
321 		auto p = gtk_application_get_windows(gtkApplication);
322 		
323 		if(p is null)
324 		{
325 			return null;
326 		}
327 		
328 		return ObjectG.getDObject!(ListG)(cast(GList*) p);
329 	}
330 	
331 	/**
332 	 * Returns the GtkApplicationWindow with the given ID.
333 	 * Params:
334 	 * id = an identifier number
335 	 * Returns: the window with ID id, or NULL if there is no window with this ID. [transfer none] Since 3.6
336 	 */
337 	public Window getWindowById(uint id)
338 	{
339 		// GtkWindow * gtk_application_get_window_by_id (GtkApplication *application,  guint id);
340 		auto p = gtk_application_get_window_by_id(gtkApplication, id);
341 		
342 		if(p is null)
343 		{
344 			return null;
345 		}
346 		
347 		return ObjectG.getDObject!(Window)(cast(GtkWindow*) p);
348 	}
349 	
350 	/**
351 	 * Gets the "active" window for the application.
352 	 * The active window is the one that was most recently focused (within
353 	 * the application). This window may not have the focus at the moment
354 	 * if another application has it -- this is just the most
355 	 * recently-focused window within this application.
356 	 * Returns: the active window. [transfer none] Since 3.6
357 	 */
358 	public Window getActiveWindow()
359 	{
360 		// GtkWindow * gtk_application_get_active_window (GtkApplication *application);
361 		auto p = gtk_application_get_active_window(gtkApplication);
362 		
363 		if(p is null)
364 		{
365 			return null;
366 		}
367 		
368 		return ObjectG.getDObject!(Window)(cast(GtkWindow*) p);
369 	}
370 	
371 	/**
372 	 * Inform the session manager that certain types of actions should be
373 	 * inhibited. This is not guaranteed to work on all platforms and for
374 	 * all types of actions.
375 	 * Applications should invoke this method when they begin an operation
376 	 * that should not be interrupted, such as creating a CD or DVD. The
377 	 * types of actions that may be blocked are specified by the flags
378 	 * parameter. When the application completes the operation it should
379 	 * call gtk_application_uninhibit() to remove the inhibitor. Note that
380 	 * an application can have multiple inhibitors, and all of the must
381 	 * be individually removed. Inhibitors are also cleared when the
382 	 * application exits.
383 	 * Applications should not expect that they will always be able to block
384 	 * the action. In most cases, users will be given the option to force
385 	 * the action to take place.
386 	 * Reasons should be short and to the point.
387 	 * If window is given, the session manager may point the user to
388 	 * this window to find out more about why the action is inhibited.
389 	 * Params:
390 	 * window = a GtkWindow, or NULL. [allow-none]
391 	 * flags = what types of actions should be inhibited
392 	 * reason = a short, human-readable string that explains
393 	 * why these operations are inhibited. [allow-none]
394 	 * Returns: A non-zero cookie that is used to uniquely identify this request. It should be used as an argument to gtk_application_uninhibit() in order to remove the request. If the platform does not support inhibiting or the request failed for some reason, 0 is returned. Since 3.4
395 	 */
396 	public uint inhibit(Window window, GtkApplicationInhibitFlags flags, string reason)
397 	{
398 		// guint gtk_application_inhibit (GtkApplication *application,  GtkWindow *window,  GtkApplicationInhibitFlags flags,  const gchar *reason);
399 		return gtk_application_inhibit(gtkApplication, (window is null) ? null : window.getWindowStruct(), flags, Str.toStringz(reason));
400 	}
401 	
402 	/**
403 	 * Removes an inhibitor that has been established with gtk_application_inhibit().
404 	 * Inhibitors are also cleared when the application exits.
405 	 * Params:
406 	 * cookie = a cookie that was returned by gtk_application_inhibit()
407 	 * Since 3.4
408 	 */
409 	public void uninhibit(uint cookie)
410 	{
411 		// void gtk_application_uninhibit (GtkApplication *application,  guint cookie);
412 		gtk_application_uninhibit(gtkApplication, cookie);
413 	}
414 	
415 	/**
416 	 * Determines if any of the actions specified in flags are
417 	 * currently inhibited (possibly by another application).
418 	 * Params:
419 	 * flags = what types of actions should be queried
420 	 * Returns: TRUE if any of the actions specified in flags are inhibited Since 3.4
421 	 */
422 	public int isInhibited(GtkApplicationInhibitFlags flags)
423 	{
424 		// gboolean gtk_application_is_inhibited (GtkApplication *application,  GtkApplicationInhibitFlags flags);
425 		return gtk_application_is_inhibited(gtkApplication, flags);
426 	}
427 	
428 	/**
429 	 * Returns the menu model that has been set with
430 	 * gtk_application_set_app_menu().
431 	 * Returns: the application menu of application. [transfer none] Since 3.4
432 	 */
433 	public MenuModel getAppMenu()
434 	{
435 		// GMenuModel * gtk_application_get_app_menu (GtkApplication *application);
436 		auto p = gtk_application_get_app_menu(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 	 * Sets or unsets the application menu for application.
448 	 * This can only be done in the primary instance of the application,
449 	 * after it has been registered. "startup" is a good place
450 	 * to call this.
451 	 * The application menu is a single menu containing items that typically
452 	 * impact the application as a whole, rather than acting on a specific
453 	 * window or document. For example, you would expect to see
454 	 * "Preferences" or "Quit" in an application menu, but not "Save" or
455 	 * "Print".
456 	 * If supported, the application menu will be rendered by the desktop
457 	 * environment.
458 	 * Use the base GActionMap interface to add actions, to respond to the user
459 	 * selecting these menu items.
460 	 * Params:
461 	 * appMenu = a GMenuModel, or NULL. [allow-none]
462 	 * Since 3.4
463 	 */
464 	public void setAppMenu(MenuModel appMenu)
465 	{
466 		// void gtk_application_set_app_menu (GtkApplication *application,  GMenuModel *app_menu);
467 		gtk_application_set_app_menu(gtkApplication, (appMenu is null) ? null : appMenu.getMenuModelStruct());
468 	}
469 	
470 	/**
471 	 * Returns the menu model that has been set with
472 	 * gtk_application_set_menubar().
473 	 * Returns: the menubar for windows of application. [transfer none] Since 3.4
474 	 */
475 	public MenuModel getMenubar()
476 	{
477 		// GMenuModel * gtk_application_get_menubar (GtkApplication *application);
478 		auto p = gtk_application_get_menubar(gtkApplication);
479 		
480 		if(p is null)
481 		{
482 			return null;
483 		}
484 		
485 		return ObjectG.getDObject!(MenuModel)(cast(GMenuModel*) p);
486 	}
487 	
488 	/**
489 	 * Sets or unsets the menubar for windows of application.
490 	 * This is a menubar in the traditional sense.
491 	 * This can only be done in the primary instance of the application,
492 	 * after it has been registered. "startup" is a good place
493 	 * to call this.
494 	 * Depending on the desktop environment, this may appear at the top of
495 	 * each window, or at the top of the screen. In some environments, if
496 	 * both the application menu and the menubar are set, the application
497 	 * menu will be presented as if it were the first item of the menubar.
498 	 * Other environments treat the two as completely separate -- for
499 	 * example, the application menu may be rendered by the desktop shell
500 	 * while the menubar (if set) remains in each individual window.
501 	 * Use the base GActionMap interface to add actions, to respond to the user
502 	 * selecting these menu items.
503 	 * Params:
504 	 * menubar = a GMenuModel, or NULL. [allow-none]
505 	 * Since 3.4
506 	 */
507 	public void setMenubar(MenuModel menubar)
508 	{
509 		// void gtk_application_set_menubar (GtkApplication *application,  GMenuModel *menubar);
510 		gtk_application_set_menubar(gtkApplication, (menubar is null) ? null : menubar.getMenuModelStruct());
511 	}
512 	
513 	/**
514 	 * Installs an accelerator that will cause the named action
515 	 * to be activated when the key combination specificed by accelerator
516 	 * is pressed.
517 	 * accelerator must be a string that can be parsed by
518 	 * gtk_accelerator_parse(), e.g. "<Primary>q" or
519 	 * "<Control><Alt>p".
520 	 * action_name must be the name of an action as it would be used
521 	 * in the app menu, i.e. actions that have been added to the application
522 	 * are referred to with an "app." prefix, and window-specific actions
523 	 * with a "win." prefix.
524 	 * GtkApplication also extracts accelerators out of 'accel' attributes
525 	 * in the GMenuModels passed to gtk_application_set_app_menu() and
526 	 * gtk_application_set_menubar(), which is usually more convenient
527 	 * than calling this function for each accelerator.
528 	 * Params:
529 	 * accelerator = accelerator string
530 	 * actionName = the name of the action to activate
531 	 * parameter = parameter to pass when activating the action,
532 	 * or NULL if the action does not accept an activation parameter. [allow-none]
533 	 * Since 3.4
534 	 */
535 	public void addAccelerator(string accelerator, string actionName, Variant parameter)
536 	{
537 		// void gtk_application_add_accelerator (GtkApplication *application,  const gchar *accelerator,  const gchar *action_name,  GVariant *parameter);
538 		gtk_application_add_accelerator(gtkApplication, Str.toStringz(accelerator), Str.toStringz(actionName), (parameter is null) ? null : parameter.getVariantStruct());
539 	}
540 	
541 	/**
542 	 * Removes an accelerator that has been previously added
543 	 * with gtk_application_add_accelerator().
544 	 * Params:
545 	 * actionName = the name of the action to activate
546 	 * parameter = parameter to pass when activating the action,
547 	 * or NULL if the action does not accept an activation parameter. [allow-none]
548 	 * Since 3.4
549 	 */
550 	public void removeAccelerator(string actionName, Variant parameter)
551 	{
552 		// void gtk_application_remove_accelerator (GtkApplication *application,  const gchar *action_name,  GVariant *parameter);
553 		gtk_application_remove_accelerator(gtkApplication, Str.toStringz(actionName), (parameter is null) ? null : parameter.getVariantStruct());
554 	}
555 }