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