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