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