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