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.ApplicationWindow;
26 
27 private import gio.ActionGroupIF;
28 private import gio.ActionGroupT;
29 private import gio.ActionMapIF;
30 private import gio.ActionMapT;
31 private import glib.ConstructionException;
32 private import gobject.ObjectG;
33 private import gtk.Application;
34 private import gtk.ShortcutsWindow;
35 private import gtk.Widget;
36 private import gtk.Window;
37 private import gtk.c.functions;
38 public  import gtk.c.types;
39 public  import gtkc.gtktypes;
40 
41 
42 /**
43  * #GtkApplicationWindow is a #GtkWindow subclass that offers some
44  * extra functionality for better integration with #GtkApplication
45  * features.  Notably, it can handle both the application menu as well
46  * as the menubar. See gtk_application_set_app_menu() and
47  * gtk_application_set_menubar().
48  * 
49  * This class implements the #GActionGroup and #GActionMap interfaces,
50  * to let you add window-specific actions that will be exported by the
51  * associated #GtkApplication, together with its application-wide
52  * actions.  Window-specific actions are prefixed with the “win.”
53  * prefix and application-wide actions are prefixed with the “app.”
54  * prefix.  Actions must be addressed with the prefixed name when
55  * referring to them from a #GMenuModel.
56  * 
57  * Note that widgets that are placed inside a #GtkApplicationWindow
58  * can also activate these actions, if they implement the
59  * #GtkActionable interface.
60  * 
61  * As with #GtkApplication, the GDK lock will be acquired when
62  * processing actions arriving from other processes and should therefore
63  * be held when activating actions locally (if GDK threads are enabled).
64  * 
65  * The settings #GtkSettings:gtk-shell-shows-app-menu and
66  * #GtkSettings:gtk-shell-shows-menubar tell GTK+ whether the
67  * desktop environment is showing the application menu and menubar
68  * models outside the application as part of the desktop shell.
69  * For instance, on OS X, both menus will be displayed remotely;
70  * on Windows neither will be. gnome-shell (starting with version 3.4)
71  * will display the application menu, but not the menubar.
72  * 
73  * If the desktop environment does not display the menubar, then
74  * #GtkApplicationWindow will automatically show a #GtkMenuBar for it.
75  * This behaviour can be overridden with the #GtkApplicationWindow:show-menubar
76  * property. If the desktop environment does not display the application
77  * menu, then it will automatically be included in the menubar or in the
78  * windows client-side decorations.
79  * 
80  * ## A GtkApplicationWindow with a menubar
81  * 
82  * |[<!-- language="C" -->
83  * GtkApplication *app = gtk_application_new ("org.gtk.test", 0);
84  * 
85  * GtkBuilder *builder = gtk_builder_new_from_string (
86  * "<interface>"
87  * "  <menu id='menubar'>"
88  * "    <submenu label='_Edit'>"
89  * "      <item label='_Copy' action='win.copy'/>"
90  * "      <item label='_Paste' action='win.paste'/>"
91  * "    </submenu>"
92  * "  </menu>"
93  * "</interface>",
94  * -1);
95  * 
96  * GMenuModel *menubar = G_MENU_MODEL (gtk_builder_get_object (builder,
97  * "menubar"));
98  * gtk_application_set_menubar (GTK_APPLICATION (app), menubar);
99  * g_object_unref (builder);
100  * 
101  * // ...
102  * 
103  * GtkWidget *window = gtk_application_window_new (app);
104  * ]|
105  * 
106  * ## Handling fallback yourself
107  * 
108  * [A simple example](https://git.gnome.org/browse/gtk+/tree/examples/sunny.c)
109  * 
110  * The XML format understood by #GtkBuilder for #GMenuModel consists
111  * of a toplevel `<menu>` element, which contains one or more `<item>`
112  * elements. Each `<item>` element contains `<attribute>` and `<link>`
113  * elements with a mandatory name attribute. `<link>` elements have the
114  * same content model as `<menu>`. Instead of `<link name="submenu>` or
115  * `<link name="section">`, you can use `<submenu>` or `<section>`
116  * elements.
117  * 
118  * Attribute values can be translated using gettext, like other #GtkBuilder
119  * content. `<attribute>` elements can be marked for translation with a
120  * `translatable="yes"` attribute. It is also possible to specify message
121  * context and translator comments, using the context and comments attributes.
122  * To make use of this, the #GtkBuilder must have been given the gettext
123  * domain to use.
124  * 
125  * The following attributes are used when constructing menu items:
126  * - "label": a user-visible string to display
127  * - "action": the prefixed name of the action to trigger
128  * - "target": the parameter to use when activating the action
129  * - "icon" and "verb-icon": names of icons that may be displayed
130  * - "submenu-action": name of an action that may be used to determine
131  * if a submenu can be opened
132  * - "hidden-when": a string used to determine when the item will be hidden.
133  * Possible values include "action-disabled", "action-missing", "macos-menubar".
134  * 
135  * The following attributes are used when constructing sections:
136  * - "label": a user-visible string to use as section heading
137  * - "display-hint": a string used to determine special formatting for the section.
138  * Possible values include "horizontal-buttons".
139  * - "text-direction": a string used to determine the #GtkTextDirection to use
140  * when "display-hint" is set to "horizontal-buttons". Possible values
141  * include "rtl", "ltr", and "none".
142  * 
143  * The following attributes are used when constructing submenus:
144  * - "label": a user-visible string to display
145  * - "icon": icon name to display
146  */
147 public class ApplicationWindow : Window, ActionGroupIF, ActionMapIF
148 {
149 	/** the main Gtk struct */
150 	protected GtkApplicationWindow* gtkApplicationWindow;
151 
152 	/** Get the main Gtk struct */
153 	public GtkApplicationWindow* getApplicationWindowStruct(bool transferOwnership = false)
154 	{
155 		if (transferOwnership)
156 			ownedRef = false;
157 		return gtkApplicationWindow;
158 	}
159 
160 	/** the main Gtk struct as a void* */
161 	protected override void* getStruct()
162 	{
163 		return cast(void*)gtkApplicationWindow;
164 	}
165 
166 	/**
167 	 * Sets our main struct and passes it to the parent class.
168 	 */
169 	public this (GtkApplicationWindow* gtkApplicationWindow, bool ownedRef = false)
170 	{
171 		this.gtkApplicationWindow = gtkApplicationWindow;
172 		super(cast(GtkWindow*)gtkApplicationWindow, ownedRef);
173 	}
174 
175 	// add the ActionGroup capabilities
176 	mixin ActionGroupT!(GtkApplicationWindow);
177 
178 	// add the ActionMap capabilities
179 	mixin ActionMapT!(GtkApplicationWindow);
180 
181 
182 	/** */
183 	public static GType getType()
184 	{
185 		return gtk_application_window_get_type();
186 	}
187 
188 	/**
189 	 * Creates a new #GtkApplicationWindow.
190 	 *
191 	 * Params:
192 	 *     application = a #GtkApplication
193 	 *
194 	 * Returns: a newly created #GtkApplicationWindow
195 	 *
196 	 * Since: 3.4
197 	 *
198 	 * Throws: ConstructionException GTK+ fails to create the object.
199 	 */
200 	public this(Application application)
201 	{
202 		auto p = gtk_application_window_new((application is null) ? null : application.getGtkApplicationStruct());
203 
204 		if(p is null)
205 		{
206 			throw new ConstructionException("null returned by new");
207 		}
208 
209 		this(cast(GtkApplicationWindow*) p);
210 	}
211 
212 	/**
213 	 * Gets the #GtkShortcutsWindow that has been set up with
214 	 * a prior call to gtk_application_window_set_help_overlay().
215 	 *
216 	 * Returns: the help overlay associated with @window, or %NULL
217 	 *
218 	 * Since: 3.20
219 	 */
220 	public ShortcutsWindow getHelpOverlay()
221 	{
222 		auto p = gtk_application_window_get_help_overlay(gtkApplicationWindow);
223 
224 		if(p is null)
225 		{
226 			return null;
227 		}
228 
229 		return ObjectG.getDObject!(ShortcutsWindow)(cast(GtkShortcutsWindow*) p);
230 	}
231 
232 	/**
233 	 * Returns the unique ID of the window. If the window has not yet been added to
234 	 * a #GtkApplication, returns `0`.
235 	 *
236 	 * Returns: the unique ID for @window, or `0` if the window
237 	 *     has not yet been added to a #GtkApplication
238 	 *
239 	 * Since: 3.6
240 	 */
241 	public uint getId()
242 	{
243 		return gtk_application_window_get_id(gtkApplicationWindow);
244 	}
245 
246 	/**
247 	 * Returns whether the window will display a menubar for the app menu
248 	 * and menubar as needed.
249 	 *
250 	 * Returns: %TRUE if @window will display a menubar when needed
251 	 *
252 	 * Since: 3.4
253 	 */
254 	public bool getShowMenubar()
255 	{
256 		return gtk_application_window_get_show_menubar(gtkApplicationWindow) != 0;
257 	}
258 
259 	/**
260 	 * Associates a shortcuts window with the application window, and
261 	 * sets up an action with the name win.show-help-overlay to present
262 	 * it.
263 	 *
264 	 * @window takes resposibility for destroying @help_overlay.
265 	 *
266 	 * Params:
267 	 *     helpOverlay = a #GtkShortcutsWindow
268 	 *
269 	 * Since: 3.20
270 	 */
271 	public void setHelpOverlay(ShortcutsWindow helpOverlay)
272 	{
273 		gtk_application_window_set_help_overlay(gtkApplicationWindow, (helpOverlay is null) ? null : helpOverlay.getShortcutsWindowStruct());
274 	}
275 
276 	/**
277 	 * Sets whether the window will display a menubar for the app menu
278 	 * and menubar as needed.
279 	 *
280 	 * Params:
281 	 *     showMenubar = whether to show a menubar when needed
282 	 *
283 	 * Since: 3.4
284 	 */
285 	public void setShowMenubar(bool showMenubar)
286 	{
287 		gtk_application_window_set_show_menubar(gtkApplicationWindow, showMenubar);
288 	}
289 }