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