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