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