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 gio.Menu;
26 
27 private import gio.MenuItem;
28 private import gio.MenuModel;
29 private import gio.c.functions;
30 public  import gio.c.types;
31 private import glib.ConstructionException;
32 private import glib.Str;
33 private import gobject.ObjectG;
34 public  import gtkc.giotypes;
35 
36 
37 /**
38  * #GMenu is a simple implementation of #GMenuModel.
39  * You populate a #GMenu by adding #GMenuItem instances to it.
40  * 
41  * There are some convenience functions to allow you to directly
42  * add items (avoiding #GMenuItem) for the common cases. To add
43  * a regular item, use g_menu_insert(). To add a section, use
44  * g_menu_insert_section(). To add a submenu, use
45  * g_menu_insert_submenu().
46  *
47  * Since: 2.32
48  */
49 public class Menu : MenuModel
50 {
51 	/** the main Gtk struct */
52 	protected GMenu* gMenu;
53 
54 	/** Get the main Gtk struct */
55 	public GMenu* getMenuStruct(bool transferOwnership = false)
56 	{
57 		if (transferOwnership)
58 			ownedRef = false;
59 		return gMenu;
60 	}
61 
62 	/** the main Gtk struct as a void* */
63 	protected override void* getStruct()
64 	{
65 		return cast(void*)gMenu;
66 	}
67 
68 	protected override void setStruct(GObject* obj)
69 	{
70 		gMenu = cast(GMenu*)obj;
71 		super.setStruct(obj);
72 	}
73 
74 	/**
75 	 * Sets our main struct and passes it to the parent class.
76 	 */
77 	public this (GMenu* gMenu, bool ownedRef = false)
78 	{
79 		this.gMenu = gMenu;
80 		super(cast(GMenuModel*)gMenu, ownedRef);
81 	}
82 
83 
84 	/** */
85 	public static GType getType()
86 	{
87 		return g_menu_get_type();
88 	}
89 
90 	/**
91 	 * Creates a new #GMenu.
92 	 *
93 	 * The new menu has no items.
94 	 *
95 	 * Returns: a new #GMenu
96 	 *
97 	 * Since: 2.32
98 	 *
99 	 * Throws: ConstructionException GTK+ fails to create the object.
100 	 */
101 	public this()
102 	{
103 		auto p = g_menu_new();
104 
105 		if(p is null)
106 		{
107 			throw new ConstructionException("null returned by new");
108 		}
109 
110 		this(cast(GMenu*) p, true);
111 	}
112 
113 	/**
114 	 * Convenience function for appending a normal menu item to the end of
115 	 * @menu.  Combine g_menu_item_new() and g_menu_insert_item() for a more
116 	 * flexible alternative.
117 	 *
118 	 * Params:
119 	 *     label = the section label, or %NULL
120 	 *     detailedAction = the detailed action string, or %NULL
121 	 *
122 	 * Since: 2.32
123 	 */
124 	public void append(string label, string detailedAction)
125 	{
126 		g_menu_append(gMenu, Str.toStringz(label), Str.toStringz(detailedAction));
127 	}
128 
129 	/**
130 	 * Appends @item to the end of @menu.
131 	 *
132 	 * See g_menu_insert_item() for more information.
133 	 *
134 	 * Params:
135 	 *     item = a #GMenuItem to append
136 	 *
137 	 * Since: 2.32
138 	 */
139 	public void appendItem(MenuItem item)
140 	{
141 		g_menu_append_item(gMenu, (item is null) ? null : item.getMenuItemStruct());
142 	}
143 
144 	/**
145 	 * Convenience function for appending a section menu item to the end of
146 	 * @menu.  Combine g_menu_item_new_section() and g_menu_insert_item() for a
147 	 * more flexible alternative.
148 	 *
149 	 * Params:
150 	 *     label = the section label, or %NULL
151 	 *     section = a #GMenuModel with the items of the section
152 	 *
153 	 * Since: 2.32
154 	 */
155 	public void appendSection(string label, MenuModel section)
156 	{
157 		g_menu_append_section(gMenu, Str.toStringz(label), (section is null) ? null : section.getMenuModelStruct());
158 	}
159 
160 	/**
161 	 * Convenience function for appending a submenu menu item to the end of
162 	 * @menu.  Combine g_menu_item_new_submenu() and g_menu_insert_item() for a
163 	 * more flexible alternative.
164 	 *
165 	 * Params:
166 	 *     label = the section label, or %NULL
167 	 *     submenu = a #GMenuModel with the items of the submenu
168 	 *
169 	 * Since: 2.32
170 	 */
171 	public void appendSubmenu(string label, MenuModel submenu)
172 	{
173 		g_menu_append_submenu(gMenu, Str.toStringz(label), (submenu is null) ? null : submenu.getMenuModelStruct());
174 	}
175 
176 	/**
177 	 * Marks @menu as frozen.
178 	 *
179 	 * After the menu is frozen, it is an error to attempt to make any
180 	 * changes to it.  In effect this means that the #GMenu API must no
181 	 * longer be used.
182 	 *
183 	 * This function causes g_menu_model_is_mutable() to begin returning
184 	 * %FALSE, which has some positive performance implications.
185 	 *
186 	 * Since: 2.32
187 	 */
188 	public void freeze()
189 	{
190 		g_menu_freeze(gMenu);
191 	}
192 
193 	/**
194 	 * Convenience function for inserting a normal menu item into @menu.
195 	 * Combine g_menu_item_new() and g_menu_insert_item() for a more flexible
196 	 * alternative.
197 	 *
198 	 * Params:
199 	 *     position = the position at which to insert the item
200 	 *     label = the section label, or %NULL
201 	 *     detailedAction = the detailed action string, or %NULL
202 	 *
203 	 * Since: 2.32
204 	 */
205 	public void insert(int position, string label, string detailedAction)
206 	{
207 		g_menu_insert(gMenu, position, Str.toStringz(label), Str.toStringz(detailedAction));
208 	}
209 
210 	/**
211 	 * Inserts @item into @menu.
212 	 *
213 	 * The "insertion" is actually done by copying all of the attribute and
214 	 * link values of @item and using them to form a new item within @menu.
215 	 * As such, @item itself is not really inserted, but rather, a menu item
216 	 * that is exactly the same as the one presently described by @item.
217 	 *
218 	 * This means that @item is essentially useless after the insertion
219 	 * occurs.  Any changes you make to it are ignored unless it is inserted
220 	 * again (at which point its updated values will be copied).
221 	 *
222 	 * You should probably just free @item once you're done.
223 	 *
224 	 * There are many convenience functions to take care of common cases.
225 	 * See g_menu_insert(), g_menu_insert_section() and
226 	 * g_menu_insert_submenu() as well as "prepend" and "append" variants of
227 	 * each of these functions.
228 	 *
229 	 * Params:
230 	 *     position = the position at which to insert the item
231 	 *     item = the #GMenuItem to insert
232 	 *
233 	 * Since: 2.32
234 	 */
235 	public void insertItem(int position, MenuItem item)
236 	{
237 		g_menu_insert_item(gMenu, position, (item is null) ? null : item.getMenuItemStruct());
238 	}
239 
240 	/**
241 	 * Convenience function for inserting a section menu item into @menu.
242 	 * Combine g_menu_item_new_section() and g_menu_insert_item() for a more
243 	 * flexible alternative.
244 	 *
245 	 * Params:
246 	 *     position = the position at which to insert the item
247 	 *     label = the section label, or %NULL
248 	 *     section = a #GMenuModel with the items of the section
249 	 *
250 	 * Since: 2.32
251 	 */
252 	public void insertSection(int position, string label, MenuModel section)
253 	{
254 		g_menu_insert_section(gMenu, position, Str.toStringz(label), (section is null) ? null : section.getMenuModelStruct());
255 	}
256 
257 	/**
258 	 * Convenience function for inserting a submenu menu item into @menu.
259 	 * Combine g_menu_item_new_submenu() and g_menu_insert_item() for a more
260 	 * flexible alternative.
261 	 *
262 	 * Params:
263 	 *     position = the position at which to insert the item
264 	 *     label = the section label, or %NULL
265 	 *     submenu = a #GMenuModel with the items of the submenu
266 	 *
267 	 * Since: 2.32
268 	 */
269 	public void insertSubmenu(int position, string label, MenuModel submenu)
270 	{
271 		g_menu_insert_submenu(gMenu, position, Str.toStringz(label), (submenu is null) ? null : submenu.getMenuModelStruct());
272 	}
273 
274 	/**
275 	 * Convenience function for prepending a normal menu item to the start
276 	 * of @menu.  Combine g_menu_item_new() and g_menu_insert_item() for a more
277 	 * flexible alternative.
278 	 *
279 	 * Params:
280 	 *     label = the section label, or %NULL
281 	 *     detailedAction = the detailed action string, or %NULL
282 	 *
283 	 * Since: 2.32
284 	 */
285 	public void prepend(string label, string detailedAction)
286 	{
287 		g_menu_prepend(gMenu, Str.toStringz(label), Str.toStringz(detailedAction));
288 	}
289 
290 	/**
291 	 * Prepends @item to the start of @menu.
292 	 *
293 	 * See g_menu_insert_item() for more information.
294 	 *
295 	 * Params:
296 	 *     item = a #GMenuItem to prepend
297 	 *
298 	 * Since: 2.32
299 	 */
300 	public void prependItem(MenuItem item)
301 	{
302 		g_menu_prepend_item(gMenu, (item is null) ? null : item.getMenuItemStruct());
303 	}
304 
305 	/**
306 	 * Convenience function for prepending a section menu item to the start
307 	 * of @menu.  Combine g_menu_item_new_section() and g_menu_insert_item() for
308 	 * a more flexible alternative.
309 	 *
310 	 * Params:
311 	 *     label = the section label, or %NULL
312 	 *     section = a #GMenuModel with the items of the section
313 	 *
314 	 * Since: 2.32
315 	 */
316 	public void prependSection(string label, MenuModel section)
317 	{
318 		g_menu_prepend_section(gMenu, Str.toStringz(label), (section is null) ? null : section.getMenuModelStruct());
319 	}
320 
321 	/**
322 	 * Convenience function for prepending a submenu menu item to the start
323 	 * of @menu.  Combine g_menu_item_new_submenu() and g_menu_insert_item() for
324 	 * a more flexible alternative.
325 	 *
326 	 * Params:
327 	 *     label = the section label, or %NULL
328 	 *     submenu = a #GMenuModel with the items of the submenu
329 	 *
330 	 * Since: 2.32
331 	 */
332 	public void prependSubmenu(string label, MenuModel submenu)
333 	{
334 		g_menu_prepend_submenu(gMenu, Str.toStringz(label), (submenu is null) ? null : submenu.getMenuModelStruct());
335 	}
336 
337 	/**
338 	 * Removes an item from the menu.
339 	 *
340 	 * @position gives the index of the item to remove.
341 	 *
342 	 * It is an error if position is not in range the range from 0 to one
343 	 * less than the number of items in the menu.
344 	 *
345 	 * It is not possible to remove items by identity since items are added
346 	 * to the menu simply by copying their links and attributes (ie:
347 	 * identity of the item itself is not preserved).
348 	 *
349 	 * Params:
350 	 *     position = the position of the item to remove
351 	 *
352 	 * Since: 2.32
353 	 */
354 	public void remove(int position)
355 	{
356 		g_menu_remove(gMenu, position);
357 	}
358 
359 	/**
360 	 * Removes all items in the menu.
361 	 *
362 	 * Since: 2.38
363 	 */
364 	public void removeAll()
365 	{
366 		g_menu_remove_all(gMenu);
367 	}
368 }