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