1. ------------------------------------------------------------------------------ 
  2. --                                                                          -- 
  3. --      Copyright (C) 1998-2000 E. Briot, J. Brobecker and A. Charlet       -- 
  4. --                     Copyright (C) 2000-2014, AdaCore                     -- 
  5. --                                                                          -- 
  6. -- This library is free software;  you can redistribute it and/or modify it -- 
  7. -- under terms of the  GNU General Public License  as published by the Free -- 
  8. -- Software  Foundation;  either version 3,  or (at your  option) any later -- 
  9. -- version. This library is distributed in the hope that it will be useful, -- 
  10. -- but WITHOUT ANY WARRANTY;  without even the implied warranty of MERCHAN- -- 
  11. -- TABILITY or FITNESS FOR A PARTICULAR PURPOSE.                            -- 
  12. --                                                                          -- 
  13. -- As a special exception under Section 7 of GPL version 3, you are granted -- 
  14. -- additional permissions described in the GCC Runtime Library Exception,   -- 
  15. -- version 3.1, as published by the Free Software Foundation.               -- 
  16. --                                                                          -- 
  17. -- You should have received a copy of the GNU General Public License and    -- 
  18. -- a copy of the GCC Runtime Library Exception along with this program;     -- 
  19. -- see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see    -- 
  20. -- <http://www.gnu.org/licenses/>.                                          -- 
  21. --                                                                          -- 
  22. ------------------------------------------------------------------------------ 
  23.  
  24. --  <description> 
  25. --  GtkApplicationWindow is a Gtk.Window.Gtk_Window subclass that offers some 
  26. --  extra functionality for better integration with 
  27. --  Gtk.Application.Gtk_Application features. Notably, it can handle both the 
  28. --  application menu as well as the menubar. See Gtk.Application.Set_App_Menu 
  29. --  and Gtk.Application.Set_Menubar. 
  30. -- 
  31. --  This class implements the Glib.Action_Group.Gaction_Group and 
  32. --  Glib.Action_Map.Gaction_Map interfaces, to let you add window-specific 
  33. --  actions that will be exported by the associated 
  34. --  Gtk.Application.Gtk_Application, together with its application-wide 
  35. --  actions. Window-specific actions are prefixed with the "win." prefix and 
  36. --  application-wide actions are prefixed with the "app." prefix. Actions must 
  37. --  be addressed with the prefixed name when referring to them from a 
  38. --  Glib.Menu_Model.Gmenu_Model. 
  39. -- 
  40. --  Note that widgets that are placed inside a GtkApplicationWindow can also 
  41. --  activate these actions, if they implement the GtkActionable interface. 
  42. -- 
  43. --  As with Gtk.Application.Gtk_Application, the GDK lock will be acquired 
  44. --  when processing actions arriving from other processes and should therefore 
  45. --  be held when activating actions locally (if GDK threads are enabled). 
  46. -- 
  47. --  The settings Gtk.Settings.Gtk_Settings:gtk-shell-shows-app-menu and 
  48. --  Gtk.Settings.Gtk_Settings:gtk-shell-shows-menubar tell GTK+ whether the 
  49. --  desktop environment is showing the application menu and menubar models 
  50. --  outside the application as part of the desktop shell. For instance, on OS 
  51. --  X, both menus will be displayed remotely; on Windows neither will be. 
  52. --  gnome-shell (starting with version 3.4) will display the application menu, 
  53. --  but not the menubar. 
  54. -- 
  55. --  If the desktop environment does not display the menubar, then 
  56. --  Gtk.Application_Window.Gtk_Application_Window will automatically show a 
  57. --  Gtk.Menu_Bar.Gtk_Menu_Bar for it. (see the Gtk.Application.Gtk_Application 
  58. --  docs for some screenshots of how this looks on different platforms). This 
  59. --  behaviour can be overridden with the 
  60. --  Gtk.Application_Window.Gtk_Application_Window:show-menubar property. If the 
  61. --  desktop environment does not display the application menu, then it will 
  62. --  automatically be included in the menubar. 
  63. -- 
  64. --  == A GtkApplicationWindow with a menubar == 
  65. -- 
  66. --    app = gtk_application_new (); 
  67. --    builder = gtk_builder_new (); 
  68. --    gtk_builder_add_from_string (builder, 
  69. --       "<interface>" 
  70. --       "  <menu id='menubar'>" 
  71. --       "    <submenu label='_Edit'>" 
  72. --       "      <item label='_Copy' action='win.copy'/>" 
  73. --       "      <item label='_Paste' action='win.paste'/>" 
  74. --       "    </submenu>" 
  75. --       "  </menu>" 
  76. --       "</interface>"); 
  77. --    gtk_application_set_menubar (G_APPLICATION (app), 
  78. --       G_MENU_MODEL (gtk_builder_get_object (builder, "menubar"))); 
  79. --    g_object_unref (builder); 
  80. --    ... 
  81. --    window = gtk_application_window_new (app); 
  82. -- 
  83. --  == Handling fallback yourself == 
  84. -- 
  85. --    <xi:include xmlns:xi="http://www.w3.org/2001/XInclude" parse="text" href="../../../../examples/sunny.c"> 
  86. --    <xi:fallback>FIXME: MISSING XINCLUDE CONTENT</xi:fallback> 
  87. --    </xi:include> 
  88. --  The XML format understood by Gtk.Builder.Gtk_Builder for 
  89. --  Glib.Menu_Model.Gmenu_Model consists of a toplevel <tag 
  90. --  class="starttag">menu</tag> element, which contains one or more <tag 
  91. --  class="starttag">item</tag> elements. Each <tag class="starttag">item</tag> 
  92. --  element contains <tag class="starttag">attribute</tag> and <tag 
  93. --  class="starttag">link</tag> elements with a mandatory name attribute. <tag 
  94. --  class="starttag">link</tag> elements have the same content model as <tag 
  95. --  class="starttag">menu</tag>. 
  96. -- 
  97. --  Attribute values can be translated using gettext, like other 
  98. --  Gtk.Builder.Gtk_Builder content. <tag class="starttag">attribute</tag> 
  99. --  elements can be marked for translation with a 'translatable="yes"' 
  100. --  attribute. It is also possible to specify message context and translator 
  101. --  comments, using the context and comments attributes. To make use of this, 
  102. --  the Gtk.Builder.Gtk_Builder must have been given the gettext domain to use. 
  103. -- 
  104. --  </description> 
  105. pragma Ada_2005; 
  106.  
  107. pragma Warnings (Off, "*is already use-visible*"); 
  108. with GNAT.Strings;      use GNAT.Strings; 
  109. with Glib;              use Glib; 
  110. with Glib.Action;       use Glib.Action; 
  111. with Glib.Action_Group; use Glib.Action_Group; 
  112. with Glib.Action_Map;   use Glib.Action_Map; 
  113. with Glib.Properties;   use Glib.Properties; 
  114. with Glib.Types;        use Glib.Types; 
  115. with Glib.Variant;      use Glib.Variant; 
  116. with Gtk.Application;   use Gtk.Application; 
  117. with Gtk.Buildable;     use Gtk.Buildable; 
  118. with Gtk.Window;        use Gtk.Window; 
  119.  
  120. package Gtk.Application_Window is 
  121.  
  122.    type Gtk_Application_Window_Record is new Gtk_Window_Record with null record; 
  123.    type Gtk_Application_Window is access all Gtk_Application_Window_Record'Class; 
  124.  
  125.    ------------------ 
  126.    -- Constructors -- 
  127.    ------------------ 
  128.  
  129.    procedure Gtk_New 
  130.       (Self        : out Gtk_Application_Window; 
  131.        Application : not null access Gtk.Application.Gtk_Application_Record'Class); 
  132.    procedure Initialize 
  133.       (Self        : not null access Gtk_Application_Window_Record'Class; 
  134.        Application : not null access Gtk.Application.Gtk_Application_Record'Class); 
  135.    --  Creates a new Gtk.Application_Window.Gtk_Application_Window. 
  136.    --  Since: gtk+ 3.4 
  137.    --  "application": a Gtk.Application.Gtk_Application 
  138.  
  139.    function Gtk_Application_Window_New 
  140.       (Application : not null access Gtk.Application.Gtk_Application_Record'Class) 
  141.        return Gtk_Application_Window; 
  142.    --  Creates a new Gtk.Application_Window.Gtk_Application_Window. 
  143.    --  Since: gtk+ 3.4 
  144.    --  "application": a Gtk.Application.Gtk_Application 
  145.  
  146.    function Get_Type return Glib.GType; 
  147.    pragma Import (C, Get_Type, "gtk_application_window_get_type"); 
  148.  
  149.    ------------- 
  150.    -- Methods -- 
  151.    ------------- 
  152.  
  153.    function Get_Id 
  154.       (Self : not null access Gtk_Application_Window_Record) return Guint; 
  155.    --  Returns the unique ID of the window. If the window has not yet been 
  156.    --  added to a Gtk.Application.Gtk_Application, returns '0'. 
  157.    --  Since: gtk+ 3.6 
  158.  
  159.    function Get_Show_Menubar 
  160.       (Self : not null access Gtk_Application_Window_Record) return Boolean; 
  161.    --  Returns whether the window will display a menubar for the app menu and 
  162.    --  menubar as needed. 
  163.    --  Since: gtk+ 3.4 
  164.  
  165.    procedure Set_Show_Menubar 
  166.       (Self         : not null access Gtk_Application_Window_Record; 
  167.        Show_Menubar : Boolean); 
  168.    --  Sets whether the window will display a menubar for the app menu and 
  169.    --  menubar as needed. 
  170.    --  Since: gtk+ 3.4 
  171.    --  "show_menubar": whether to show a menubar when needed 
  172.  
  173.    --------------------------------------------- 
  174.    -- Inherited subprograms (from interfaces) -- 
  175.    --------------------------------------------- 
  176.    --  Methods inherited from the Buildable interface are not duplicated here 
  177.    --  since they are meant to be used by tools, mostly. If you need to call 
  178.    --  them, use an explicit cast through the "-" operator below. 
  179.  
  180.    procedure Action_Added 
  181.       (Self        : not null access Gtk_Application_Window_Record; 
  182.        Action_Name : UTF8_String); 
  183.  
  184.    procedure Action_Enabled_Changed 
  185.       (Self        : not null access Gtk_Application_Window_Record; 
  186.        Action_Name : UTF8_String; 
  187.        Enabled     : Boolean); 
  188.  
  189.    procedure Action_Removed 
  190.       (Self        : not null access Gtk_Application_Window_Record; 
  191.        Action_Name : UTF8_String); 
  192.  
  193.    procedure Action_State_Changed 
  194.       (Self        : not null access Gtk_Application_Window_Record; 
  195.        Action_Name : UTF8_String; 
  196.        State       : Glib.Variant.Gvariant); 
  197.  
  198.    procedure Activate_Action 
  199.       (Self        : not null access Gtk_Application_Window_Record; 
  200.        Action_Name : UTF8_String; 
  201.        Parameter   : Glib.Variant.Gvariant); 
  202.  
  203.    procedure Change_Action_State 
  204.       (Self        : not null access Gtk_Application_Window_Record; 
  205.        Action_Name : UTF8_String; 
  206.        Value       : Glib.Variant.Gvariant); 
  207.  
  208.    function Get_Action_Enabled 
  209.       (Self        : not null access Gtk_Application_Window_Record; 
  210.        Action_Name : UTF8_String) return Boolean; 
  211.  
  212.    function Get_Action_Parameter_Type 
  213.       (Self        : not null access Gtk_Application_Window_Record; 
  214.        Action_Name : UTF8_String) return Glib.Variant.Gvariant_Type; 
  215.  
  216.    function Get_Action_State 
  217.       (Self        : not null access Gtk_Application_Window_Record; 
  218.        Action_Name : UTF8_String) return Glib.Variant.Gvariant; 
  219.  
  220.    function Get_Action_State_Hint 
  221.       (Self        : not null access Gtk_Application_Window_Record; 
  222.        Action_Name : UTF8_String) return Glib.Variant.Gvariant; 
  223.  
  224.    function Get_Action_State_Type 
  225.       (Self        : not null access Gtk_Application_Window_Record; 
  226.        Action_Name : UTF8_String) return Glib.Variant.Gvariant_Type; 
  227.  
  228.    function Has_Action 
  229.       (Self        : not null access Gtk_Application_Window_Record; 
  230.        Action_Name : UTF8_String) return Boolean; 
  231.  
  232.    function List_Actions 
  233.       (Self : not null access Gtk_Application_Window_Record) 
  234.        return GNAT.Strings.String_List; 
  235.  
  236.    function Query_Action 
  237.       (Self           : not null access Gtk_Application_Window_Record; 
  238.        Action_Name    : UTF8_String; 
  239.        Enabled        : access Boolean; 
  240.        Parameter_Type : access Glib.Variant.Gvariant_Type; 
  241.        State_Type     : access Glib.Variant.Gvariant_Type; 
  242.        State_Hint     : access Glib.Variant.Gvariant; 
  243.        State          : access Glib.Variant.Gvariant) return Boolean; 
  244.  
  245.    procedure Add_Action 
  246.       (Self   : not null access Gtk_Application_Window_Record; 
  247.        Action : Glib.Action.Gaction); 
  248.  
  249.    procedure Add_Action_Entries 
  250.       (Self      : not null access Gtk_Application_Window_Record; 
  251.        Entries   : GAction_Entry_Array; 
  252.        User_Data : System.Address := System.Null_Address); 
  253.  
  254.    function Lookup_Action 
  255.       (Self        : not null access Gtk_Application_Window_Record; 
  256.        Action_Name : UTF8_String) return Glib.Action.Gaction; 
  257.  
  258.    procedure Remove_Action 
  259.       (Self        : not null access Gtk_Application_Window_Record; 
  260.        Action_Name : UTF8_String); 
  261.  
  262.    ---------------- 
  263.    -- Properties -- 
  264.    ---------------- 
  265.    --  The following properties are defined for this widget. See 
  266.    --  Glib.Properties for more information on properties) 
  267.  
  268.    Show_Menubar_Property : constant Glib.Properties.Property_Boolean; 
  269.    --  If this property is True, the window will display a menubar that 
  270.    --  includes the app menu and menubar, unless these are shown by the desktop 
  271.    --  shell. See Gtk.Application.Set_App_Menu and Gtk.Application.Set_Menubar. 
  272.    -- 
  273.    --  If False, the window will not display a menubar, regardless of whether 
  274.    --  the desktop shell is showing the menus or not. 
  275.  
  276.    ---------------- 
  277.    -- Interfaces -- 
  278.    ---------------- 
  279.    --  This class implements several interfaces. See Glib.Types 
  280.    -- 
  281.    --  - "Buildable" 
  282.    -- 
  283.    --  - "Gio.ActionGroup" 
  284.    -- 
  285.    --  - "Gio.ActionMap" 
  286.  
  287.    package Implements_Gtk_Buildable is new Glib.Types.Implements 
  288.      (Gtk.Buildable.Gtk_Buildable, Gtk_Application_Window_Record, Gtk_Application_Window); 
  289.    function "+" 
  290.      (Widget : access Gtk_Application_Window_Record'Class) 
  291.    return Gtk.Buildable.Gtk_Buildable 
  292.    renames Implements_Gtk_Buildable.To_Interface; 
  293.    function "-" 
  294.      (Interf : Gtk.Buildable.Gtk_Buildable) 
  295.    return Gtk_Application_Window 
  296.    renames Implements_Gtk_Buildable.To_Object; 
  297.  
  298.    package Implements_Gaction_Group is new Glib.Types.Implements 
  299.      (Glib.Action_Group.Gaction_Group, Gtk_Application_Window_Record, Gtk_Application_Window); 
  300.    function "+" 
  301.      (Widget : access Gtk_Application_Window_Record'Class) 
  302.    return Glib.Action_Group.Gaction_Group 
  303.    renames Implements_Gaction_Group.To_Interface; 
  304.    function "-" 
  305.      (Interf : Glib.Action_Group.Gaction_Group) 
  306.    return Gtk_Application_Window 
  307.    renames Implements_Gaction_Group.To_Object; 
  308.  
  309.    package Implements_Gaction_Map is new Glib.Types.Implements 
  310.      (Glib.Action_Map.Gaction_Map, Gtk_Application_Window_Record, Gtk_Application_Window); 
  311.    function "+" 
  312.      (Widget : access Gtk_Application_Window_Record'Class) 
  313.    return Glib.Action_Map.Gaction_Map 
  314.    renames Implements_Gaction_Map.To_Interface; 
  315.    function "-" 
  316.      (Interf : Glib.Action_Map.Gaction_Map) 
  317.    return Gtk_Application_Window 
  318.    renames Implements_Gaction_Map.To_Object; 
  319.  
  320. private 
  321.    Show_Menubar_Property : constant Glib.Properties.Property_Boolean := 
  322.      Glib.Properties.Build ("show-menubar"); 
  323. end Gtk.Application_Window;