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