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 	protected override void setStruct(GObject* obj)
167 	{
168 		gtkApplicationWindow = cast(GtkApplicationWindow*)obj;
169 		super.setStruct(obj);
170 	}
171 
172 	/**
173 	 * Sets our main struct and passes it to the parent class.
174 	 */
175 	public this (GtkApplicationWindow* gtkApplicationWindow, bool ownedRef = false)
176 	{
177 		this.gtkApplicationWindow = gtkApplicationWindow;
178 		super(cast(GtkWindow*)gtkApplicationWindow, ownedRef);
179 	}
180 
181 	// add the ActionGroup capabilities
182 	mixin ActionGroupT!(GtkApplicationWindow);
183 
184 	// add the ActionMap capabilities
185 	mixin ActionMapT!(GtkApplicationWindow);
186 
187 
188 	/** */
189 	public static GType getType()
190 	{
191 		return gtk_application_window_get_type();
192 	}
193 
194 	/**
195 	 * Creates a new #GtkApplicationWindow.
196 	 *
197 	 * Params:
198 	 *     application = a #GtkApplication
199 	 *
200 	 * Returns: a newly created #GtkApplicationWindow
201 	 *
202 	 * Since: 3.4
203 	 *
204 	 * Throws: ConstructionException GTK+ fails to create the object.
205 	 */
206 	public this(Application application)
207 	{
208 		auto p = gtk_application_window_new((application is null) ? null : application.getGtkApplicationStruct());
209 
210 		if(p is null)
211 		{
212 			throw new ConstructionException("null returned by new");
213 		}
214 
215 		this(cast(GtkApplicationWindow*) p);
216 	}
217 
218 	/**
219 	 * Gets the #GtkShortcutsWindow that has been set up with
220 	 * a prior call to gtk_application_window_set_help_overlay().
221 	 *
222 	 * Returns: the help overlay associated with @window, or %NULL
223 	 *
224 	 * Since: 3.20
225 	 */
226 	public ShortcutsWindow getHelpOverlay()
227 	{
228 		auto p = gtk_application_window_get_help_overlay(gtkApplicationWindow);
229 
230 		if(p is null)
231 		{
232 			return null;
233 		}
234 
235 		return ObjectG.getDObject!(ShortcutsWindow)(cast(GtkShortcutsWindow*) p);
236 	}
237 
238 	/**
239 	 * Returns the unique ID of the window. If the window has not yet been added to
240 	 * a #GtkApplication, returns `0`.
241 	 *
242 	 * Returns: the unique ID for @window, or `0` if the window
243 	 *     has not yet been added to a #GtkApplication
244 	 *
245 	 * Since: 3.6
246 	 */
247 	public uint getId()
248 	{
249 		return gtk_application_window_get_id(gtkApplicationWindow);
250 	}
251 
252 	/**
253 	 * Returns whether the window will display a menubar for the app menu
254 	 * and menubar as needed.
255 	 *
256 	 * Returns: %TRUE if @window will display a menubar when needed
257 	 *
258 	 * Since: 3.4
259 	 */
260 	public bool getShowMenubar()
261 	{
262 		return gtk_application_window_get_show_menubar(gtkApplicationWindow) != 0;
263 	}
264 
265 	/**
266 	 * Associates a shortcuts window with the application window, and
267 	 * sets up an action with the name win.show-help-overlay to present
268 	 * it.
269 	 *
270 	 * @window takes resposibility for destroying @help_overlay.
271 	 *
272 	 * Params:
273 	 *     helpOverlay = a #GtkShortcutsWindow
274 	 *
275 	 * Since: 3.20
276 	 */
277 	public void setHelpOverlay(ShortcutsWindow helpOverlay)
278 	{
279 		gtk_application_window_set_help_overlay(gtkApplicationWindow, (helpOverlay is null) ? null : helpOverlay.getShortcutsWindowStruct());
280 	}
281 
282 	/**
283 	 * Sets whether the window will display a menubar for the app menu
284 	 * and menubar as needed.
285 	 *
286 	 * Params:
287 	 *     showMenubar = whether to show a menubar when needed
288 	 *
289 	 * Since: 3.4
290 	 */
291 	public void setShowMenubar(bool showMenubar)
292 	{
293 		gtk_application_window_set_show_menubar(gtkApplicationWindow, showMenubar);
294 	}
295 }