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  * Conversion parameters:
26  * inFile  = 
27  * outPack = gio
28  * outFile = MenuItem
29  * strct   = GMenuItem
30  * realStrct=
31  * ctorStrct=
32  * clss    = MenuItem
33  * interf  = 
34  * class Code: No
35  * interface Code: No
36  * template for:
37  * extend  = 
38  * implements:
39  * prefixes:
40  * 	- g_menu_item_
41  * omit structs:
42  * omit prefixes:
43  * omit code:
44  * 	- g_menu_item_new_section
45  * 	- g_menu_item_new_submenu
46  * omit signals:
47  * imports:
48  * 	- glib.Str
49  * 	- glib.Variant
50  * 	- glib.VariantType
51  * 	- gio.IconIF
52  * 	- gio.MenuModel
53  * structWrap:
54  * 	- GIcon* -> IconIF
55  * 	- GMenuModel* -> MenuModel
56  * 	- GVariant* -> Variant
57  * 	- GVariantType* -> VariantType
58  * module aliases:
59  * local aliases:
60  * overrides:
61  */
62 
63 module gio.MenuItem;
64 
65 public  import gtkc.giotypes;
66 
67 private import gtkc.gio;
68 private import glib.ConstructionException;
69 private import gobject.ObjectG;
70 
71 private import glib.Str;
72 private import glib.Variant;
73 private import glib.VariantType;
74 private import gio.IconIF;
75 private import gio.MenuModel;
76 
77 
78 
79 /**
80  * GMenu is a simple implementation of GMenuModel.
81  * You populate a GMenu by adding GMenuItem instances to it.
82  *
83  * There are some convenience functions to allow you to directly
84  * add items (avoiding GMenuItem) for the common cases. To add
85  * a regular item, use g_menu_insert(). To add a section, use
86  * g_menu_insert_section(). To add a submenu, use
87  * g_menu_insert_submenu().
88  */
89 public class MenuItem
90 {
91 	
92 	/** the main Gtk struct */
93 	protected GMenuItem* gMenuItem;
94 	
95 	
96 	/** Get the main Gtk struct */
97 	public GMenuItem* getMenuItemStruct()
98 	{
99 		return gMenuItem;
100 	}
101 	
102 	
103 	/** the main Gtk struct as a void* */
104 	protected void* getStruct()
105 	{
106 		return cast(void*)gMenuItem;
107 	}
108 	
109 	/**
110 	 * Sets our main struct and passes it to the parent class
111 	 */
112 	public this (GMenuItem* gMenuItem)
113 	{
114 		this.gMenuItem = gMenuItem;
115 	}
116 	
117 	/**
118 	 */
119 	
120 	/**
121 	 * Creates a new GMenuItem.
122 	 * If label is non-NULL it is used to set the "label" attribute of the
123 	 * new item.
124 	 * If detailed_action is non-NULL it is used to set the "action" and
125 	 * possibly the "target" attribute of the new item. See
126 	 * g_menu_item_set_detailed_action() for more information.
127 	 * Since 2.32
128 	 * Params:
129 	 * label = the section label, or NULL. [allow-none]
130 	 * detailedAction = the detailed action string, or NULL. [allow-none]
131 	 * Throws: ConstructionException GTK+ fails to create the object.
132 	 */
133 	public this (string label, string detailedAction)
134 	{
135 		// GMenuItem * g_menu_item_new (const gchar *label,  const gchar *detailed_action);
136 		auto p = g_menu_item_new(Str.toStringz(label), Str.toStringz(detailedAction));
137 		if(p is null)
138 		{
139 			throw new ConstructionException("null returned by g_menu_item_new(Str.toStringz(label), Str.toStringz(detailedAction))");
140 		}
141 		this(cast(GMenuItem*) p);
142 	}
143 	
144 	/**
145 	 * Creates a GMenuItem as an exact copy of an existing menu item in a
146 	 * GMenuModel.
147 	 * item_index must be valid (ie: be sure to call
148 	 * g_menu_model_get_n_items() first).
149 	 * Since 2.34
150 	 * Params:
151 	 * model = a GMenuModel
152 	 * itemIndex = the index of an item in model
153 	 * Throws: ConstructionException GTK+ fails to create the object.
154 	 */
155 	public this (MenuModel model, int itemIndex)
156 	{
157 		// GMenuItem * g_menu_item_new_from_model (GMenuModel *model,  gint item_index);
158 		auto p = g_menu_item_new_from_model((model is null) ? null : model.getMenuModelStruct(), itemIndex);
159 		if(p is null)
160 		{
161 			throw new ConstructionException("null returned by g_menu_item_new_from_model((model is null) ? null : model.getMenuModelStruct(), itemIndex)");
162 		}
163 		this(cast(GMenuItem*) p);
164 	}
165 	
166 	/**
167 	 * Sets or unsets the "label" attribute of menu_item.
168 	 * If label is non-NULL it is used as the label for the menu item. If
169 	 * it is NULL then the label attribute is unset.
170 	 * Since 2.32
171 	 * Params:
172 	 * label = the label to set, or NULL to unset. [allow-none]
173 	 */
174 	public void setLabel(string label)
175 	{
176 		// void g_menu_item_set_label (GMenuItem *menu_item,  const gchar *label);
177 		g_menu_item_set_label(gMenuItem, Str.toStringz(label));
178 	}
179 	
180 	/**
181 	 * Sets (or unsets) the icon on menu_item.
182 	 * This call is the same as calling g_icon_serialize() and using the
183 	 * result as the value to g_menu_item_set_attribute_value() for
184 	 * G_MENU_ATTRIBUTE_ICON.
185 	 * This API is only intended for use with "noun" menu items; things like
186 	 * bookmarks or applications in an "Open With" menu. Don't use it on
187 	 * menu items corresponding to verbs (eg: stock icons for 'Save' or
188 	 * 'Quit').
189 	 * If icon is NULL then the icon is unset.
190 	 * Since 2.38
191 	 * Params:
192 	 * icon = a GIcon, or NULL
193 	 */
194 	public void setIcon(IconIF icon)
195 	{
196 		// void g_menu_item_set_icon (GMenuItem *menu_item,  GIcon *icon);
197 		g_menu_item_set_icon(gMenuItem, (icon is null) ? null : icon.getIconTStruct());
198 	}
199 	
200 	/**
201 	 * Sets or unsets the "action" and "target" attributes of menu_item.
202 	 * If action is NULL then both the "action" and "target" attributes
203 	 * are unset (and target_value is ignored).
204 	 * If action is non-NULL then the "action" attribute is set. The
205 	 * "target" attribute is then set to the value of target_value if it is
206 	 * non-NULL or unset otherwise.
207 	 * Normal menu items (ie: not submenu, section or other custom item
208 	 * types) are expected to have the "action" attribute set to identify
209 	 * the action that they are associated with. The state type of the
210 	 * action help to determine the disposition of the menu item. See
211 	 * GAction and GActionGroup for an overview of actions.
212 	 * In general, clicking on the menu item will result in activation of
213 	 * the named action with the "target" attribute given as the parameter
214 	 * to the action invocation. If the "target" attribute is not set then
215 	 * the action is invoked with no parameter.
216 	 * If the action has no state then the menu item is usually drawn as a
217 	 * plain menu item (ie: with no additional decoration).
218 	 * If the action has a boolean state then the menu item is usually drawn
219 	 * as a toggle menu item (ie: with a checkmark or equivalent
220 	 * indication). The item should be marked as 'toggled' or 'checked'
221 	 * when the boolean state is TRUE.
222 	 * If the action has a string state then the menu item is usually drawn
223 	 * as a radio menu item (ie: with a radio bullet or equivalent
224 	 * indication). The item should be marked as 'selected' when the string
225 	 * state is equal to the value of the target property.
226 	 * See g_menu_item_set_action_and_target() or
227 	 * g_menu_item_set_detailed_action() for two equivalent calls that are
228 	 * probably more convenient for most uses.
229 	 * Since 2.32
230 	 * Params:
231 	 * action = the name of the action for this item. [allow-none]
232 	 * targetValue = a GVariant to use as the action target. [allow-none]
233 	 */
234 	public void setActionAndTargetValue(string action, Variant targetValue)
235 	{
236 		// void g_menu_item_set_action_and_target_value  (GMenuItem *menu_item,  const gchar *action,  GVariant *target_value);
237 		g_menu_item_set_action_and_target_value(gMenuItem, Str.toStringz(action), (targetValue is null) ? null : targetValue.getVariantStruct());
238 	}
239 	
240 	/**
241 	 * Sets the "action" and possibly the "target" attribute of menu_item.
242 	 * The format of detailed_action is the same format parsed by
243 	 * g_action_parse_detailed_name().
244 	 * See g_menu_item_set_action_and_target() or
245 	 * g_menu_item_set_action_and_target_value() for more flexible (but
246 	 * slightly less convenient) alternatives.
247 	 * See also g_menu_item_set_action_and_target_value() for a description of
248 	 * the semantics of the action and target attributes.
249 	 * Since 2.32
250 	 * Params:
251 	 * detailedAction = the "detailed" action string
252 	 */
253 	public void setDetailedAction(string detailedAction)
254 	{
255 		// void g_menu_item_set_detailed_action (GMenuItem *menu_item,  const gchar *detailed_action);
256 		g_menu_item_set_detailed_action(gMenuItem, Str.toStringz(detailedAction));
257 	}
258 	
259 	/**
260 	 * Sets or unsets the "section" link of menu_item to section.
261 	 * The effect of having one menu appear as a section of another is
262 	 * exactly as it sounds: the items from section become a direct part of
263 	 * the menu that menu_item is added to. See g_menu_item_new_section()
264 	 * for more information about what it means for a menu item to be a
265 	 * section.
266 	 * Since 2.32
267 	 * Params:
268 	 * section = a GMenuModel, or NULL. [allow-none]
269 	 */
270 	public void setSection(MenuModel section)
271 	{
272 		// void g_menu_item_set_section (GMenuItem *menu_item,  GMenuModel *section);
273 		g_menu_item_set_section(gMenuItem, (section is null) ? null : section.getMenuModelStruct());
274 	}
275 	
276 	/**
277 	 * Sets or unsets the "submenu" link of menu_item to submenu.
278 	 * If submenu is non-NULL, it is linked to. If it is NULL then the
279 	 * link is unset.
280 	 * The effect of having one menu appear as a submenu of another is
281 	 * exactly as it sounds.
282 	 * Since 2.32
283 	 * Params:
284 	 * submenu = a GMenuModel, or NULL. [allow-none]
285 	 */
286 	public void setSubmenu(MenuModel submenu)
287 	{
288 		// void g_menu_item_set_submenu (GMenuItem *menu_item,  GMenuModel *submenu);
289 		g_menu_item_set_submenu(gMenuItem, (submenu is null) ? null : submenu.getMenuModelStruct());
290 	}
291 	
292 	/**
293 	 * Queries the named attribute on menu_item.
294 	 * If expected_type is specified and the attribute does not have this
295 	 * type, NULL is returned. NULL is also returned if the attribute
296 	 * simply does not exist.
297 	 * Since 2.34
298 	 * Params:
299 	 * attribute = the attribute name to query
300 	 * expectedType = the expected type of the attribute. [allow-none]
301 	 * Returns: the attribute value, or NULL. [transfer full]
302 	 */
303 	public Variant getAttributeValue(string attribute, VariantType expectedType)
304 	{
305 		// GVariant * g_menu_item_get_attribute_value (GMenuItem *menu_item,  const gchar *attribute,  const GVariantType *expected_type);
306 		auto p = g_menu_item_get_attribute_value(gMenuItem, Str.toStringz(attribute), (expectedType is null) ? null : expectedType.getVariantTypeStruct());
307 		
308 		if(p is null)
309 		{
310 			return null;
311 		}
312 		
313 		return ObjectG.getDObject!(Variant)(cast(GVariant*) p);
314 	}
315 	
316 	/**
317 	 * Queries the named link on menu_item.
318 	 * Since 2.34
319 	 * Params:
320 	 * link = the link name to query
321 	 * Returns: the link, or NULL. [transfer full]
322 	 */
323 	public MenuModel getLink(string link)
324 	{
325 		// GMenuModel * g_menu_item_get_link (GMenuItem *menu_item,  const gchar *link);
326 		auto p = g_menu_item_get_link(gMenuItem, Str.toStringz(link));
327 		
328 		if(p is null)
329 		{
330 			return null;
331 		}
332 		
333 		return ObjectG.getDObject!(MenuModel)(cast(GMenuModel*) p);
334 	}
335 	
336 	/**
337 	 * Sets or unsets an attribute on menu_item.
338 	 * The attribute to set or unset is specified by attribute. This
339 	 * can be one of the standard attribute names G_MENU_ATTRIBUTE_LABEL,
340 	 * G_MENU_ATTRIBUTE_ACTION, G_MENU_ATTRIBUTE_TARGET, or a custom
341 	 * attribute name.
342 	 * Attribute names are restricted to lowercase characters, numbers
343 	 * and '-'. Furthermore, the names must begin with a lowercase character,
344 	 * must not end with a '-', and must not contain consecutive dashes.
345 	 * must consist only of lowercase
346 	 * ASCII characters, digits and '-'.
347 	 * If value is non-NULL then it is used as the new value for the
348 	 * attribute. If value is NULL then the attribute is unset. If
349 	 * the value GVariant is floating, it is consumed.
350 	 * See also g_menu_item_set_attribute() for a more convenient way to do
351 	 * the same.
352 	 * Since 2.32
353 	 * Params:
354 	 * attribute = the attribute to set
355 	 * value = a GVariant to use as the value, or NULL. [allow-none]
356 	 */
357 	public void setAttributeValue(string attribute, Variant value)
358 	{
359 		// void g_menu_item_set_attribute_value (GMenuItem *menu_item,  const gchar *attribute,  GVariant *value);
360 		g_menu_item_set_attribute_value(gMenuItem, Str.toStringz(attribute), (value is null) ? null : value.getVariantStruct());
361 	}
362 	
363 	/**
364 	 * Creates a link from menu_item to model if non-NULL, or unsets it.
365 	 * Links are used to establish a relationship between a particular menu
366 	 * item and another menu. For example, G_MENU_LINK_SUBMENU is used to
367 	 * associate a submenu with a particular menu item, and G_MENU_LINK_SECTION
368 	 * is used to create a section. Other types of link can be used, but there
369 	 * is no guarantee that clients will be able to make sense of them.
370 	 * Link types are restricted to lowercase characters, numbers
371 	 * and '-'. Furthermore, the names must begin with a lowercase character,
372 	 * must not end with a '-', and must not contain consecutive dashes.
373 	 * Since 2.32
374 	 * Params:
375 	 * link = type of link to establish or unset
376 	 * model = the GMenuModel to link to (or NULL to unset). [allow-none]
377 	 */
378 	public void setLink(string link, MenuModel model)
379 	{
380 		// void g_menu_item_set_link (GMenuItem *menu_item,  const gchar *link,  GMenuModel *model);
381 		g_menu_item_set_link(gMenuItem, Str.toStringz(link), (model is null) ? null : model.getMenuModelStruct());
382 	}
383 }