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