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