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