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