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  = GMenuModel.html
27  * outPack = gio
28  * outFile = MenuModel
29  * strct   = GMenuModel
30  * realStrct=
31  * ctorStrct=
32  * clss    = MenuModel
33  * interf  = 
34  * class Code: No
35  * interface Code: No
36  * template for:
37  * extend  = 
38  * implements:
39  * prefixes:
40  * 	- g_menu_model_
41  * omit structs:
42  * omit prefixes:
43  * 	- g_menu_attribute_iter_
44  * 	- g_menu_link_iter_
45  * omit code:
46  * omit signals:
47  * imports:
48  * 	- glib.Str
49  * 	- glib.Variant
50  * 	- glib.VariantType
51  * 	- gio.MenuAttributeIter
52  * 	- gio.MenuLinkIter
53  * structWrap:
54  * 	- GMenuAttributeIter* -> MenuAttributeIter
55  * 	- GMenuLinkIter* -> MenuLinkIter
56  * 	- GMenuModel* -> MenuModel
57  * 	- GVariant* -> Variant
58  * 	- GVariantType* -> VariantType
59  * module aliases:
60  * local aliases:
61  * overrides:
62  */
63 
64 module gio.MenuModel;
65 
66 public  import gtkc.giotypes;
67 
68 private import gtkc.gio;
69 private import glib.ConstructionException;
70 private import gobject.ObjectG;
71 
72 private import gobject.Signals;
73 public  import gtkc.gdktypes;
74 
75 private import glib.Str;
76 private import glib.Variant;
77 private import glib.VariantType;
78 private import gio.MenuAttributeIter;
79 private import gio.MenuLinkIter;
80 
81 
82 
83 private import gobject.ObjectG;
84 
85 /**
86  * GMenuModel represents the contents of a menu -- an ordered list of
87  * menu items. The items are associated with actions, which can be
88  * activated through them. Items can be grouped in sections, and may
89  * have submenus associated with them. Both items and sections usually
90  * have some representation data, such as labels or icons. The type of
91  * the associated action (ie whether it is stateful, and what kind of
92  * state it has) can influence the representation of the item.
93  *
94  * The conceptual model of menus in GMenuModel is hierarchical:
95  * sections and submenus are again represented by GMenuModels.
96  * Menus themselves do not define their own roles. Rather, the role
97  * of a particular GMenuModel is defined by the item that references
98  * it (or, in the case of the 'root' menu, is defined by the context
99  * in which it is used).
100  *
101  * As an example, consider the visible portions of the menu in
102  *  Figure 2, “An example menu”.
103  *
104  * Figure 2. An example menu
105  *
106  * There are 8 "menus" visible in the screenshot: one menubar, two
107  * submenus and 5 sections:
108  *
109  * the toplevel menubar (containing 4 items)
110  * the View submenu (containing 3 sections)
111  * the first section of the View submenu (containing 2 items)
112  * the second section of the View submenu (containing 1 item)
113  * the final section of the View submenu (containing 1 item)
114  * the Highlight Mode submenu (containing 2 sections)
115  * the Sources section (containing 2 items)
116  * the Markup section (containing 2 items)
117  *
118  *  Figure 3, “A menu model” illustrates the conceptual connection between
119  * these 8 menus. Each large block in the figure represents a menu and the
120  * smaller blocks within the large block represent items in that menu. Some
121  * items contain references to other menus.
122  *
123  * Figure 3. A menu model
124  *
125  * Notice that the separators visible in Figure 2, “An example menu”
126  * appear nowhere in Figure 3, “A menu model”. This is because
127  * separators are not explicitly represented in the menu model. Instead,
128  * a separator is inserted between any two non-empty sections of a menu.
129  * Section items can have labels just like any other item. In that case,
130  * a display system may show a section header instead of a separator.
131  *
132  * The motivation for this abstract model of application controls is
133  * that modern user interfaces tend to make these controls available
134  * outside the application. Examples include global menus, jumplists,
135  * dash boards, etc. To support such uses, it is necessary to 'export'
136  * information about actions and their representation in menus, which
137  * is exactly what the
138  * GActionGroup exporter
139  * and the
140  * GMenuModel exporter
141  * do for GActionGroup and GMenuModel. The client-side counterparts
142  * to make use of the exported information are GDBusActionGroup and
143  * GDBusMenuModel.
144  *
145  * The API of GMenuModel is very generic, with iterators for the
146  * attributes and links of an item, see g_menu_model_iterate_item_attributes()
147  * and g_menu_model_iterate_item_links(). The 'standard' attributes and
148  * link types have predefined names: G_MENU_ATTRIBUTE_LABEL,
149  * G_MENU_ATTRIBUTE_ACTION, G_MENU_ATTRIBUTE_TARGET, G_MENU_LINK_SECTION
150  * and G_MENU_LINK_SUBMENU.
151  *
152  * Items in a GMenuModel represent active controls if they refer to
153  * an action that can get activated when the user interacts with the
154  * menu item. The reference to the action is encoded by the string id
155  * in the G_MENU_ATTRIBUTE_ACTION attribute. An action id uniquely
156  * identifies an action in an action group. Which action group(s) provide
157  * actions depends on the context in which the menu model is used.
158  * E.g. when the model is exported as the application menu of a
159  * GtkApplication, actions can be application-wide or window-specific
160  * (and thus come from two different action groups). By convention, the
161  * application-wide actions have names that start with "app.", while the
162  * names of window-specific actions start with "win.".
163  *
164  * While a wide variety of stateful actions is possible, the following
165  * is the minimum that is expected to be supported by all users of exported
166  * menu information:
167  *
168  * an action with no parameter type and no state
169  * an action with no parameter type and boolean state
170  * an action with string parameter type and string state
171  *
172  * Stateless.
173  * A stateless action typically corresponds to an ordinary menu item.
174  *
175  * Selecting such a menu item will activate the action (with no parameter).
176  *
177  * Boolean State.
178  * An action with a boolean state will most typically be used with a "toggle"
179  * or "switch" menu item. The state can be set directly, but activating the
180  * action (with no parameter) results in the state being toggled.
181  *
182  * Selecting a toggle menu item will activate the action. The menu item should
183  * be rendered as "checked" when the state is true.
184  *
185  * String Parameter and State.
186  * Actions with string parameters and state will most typically be used to
187  * represent an enumerated choice over the items available for a group of
188  * radio menu items. Activating the action with a string parameter is
189  * equivalent to setting that parameter as the state.
190  *
191  * Radio menu items, in addition to being associated with the action, will
192  * have a target value. Selecting that menu item will result in activation
193  * of the action with the target value as the parameter. The menu item should
194  * be rendered as "selected" when the state of the action is equal to the
195  * target value of the menu item.
196  */
197 public class MenuModel : ObjectG
198 {
199 	
200 	/** the main Gtk struct */
201 	protected GMenuModel* gMenuModel;
202 	
203 	
204 	public GMenuModel* getMenuModelStruct()
205 	{
206 		return gMenuModel;
207 	}
208 	
209 	
210 	/** the main Gtk struct as a void* */
211 	protected override void* getStruct()
212 	{
213 		return cast(void*)gMenuModel;
214 	}
215 	
216 	/**
217 	 * Sets our main struct and passes it to the parent class
218 	 */
219 	public this (GMenuModel* gMenuModel)
220 	{
221 		super(cast(GObject*)gMenuModel);
222 		this.gMenuModel = gMenuModel;
223 	}
224 	
225 	protected override void setStruct(GObject* obj)
226 	{
227 		super.setStruct(obj);
228 		gMenuModel = cast(GMenuModel*)obj;
229 	}
230 	
231 	/**
232 	 */
233 	int[string] connectedSignals;
234 	
235 	void delegate(gint, gint, gint, MenuModel)[] onItemsChangedListeners;
236 	/**
237 	 * Emitted when a change has occured to the menu.
238 	 * The only changes that can occur to a menu is that items are removed
239 	 * or added. Items may not change (except by being removed and added
240 	 * back in the same location). This signal is capable of describing
241 	 * both of those changes (at the same time).
242 	 * The signal means that starting at the index position, removed
243 	 * items were removed and added items were added in their place. If
244 	 * removed is zero then only items were added. If added is zero
245 	 * then only items were removed.
246 	 * As an example, if the menu contains items a, b, c, d (in that
247 	 * order) and the signal (2, 1, 3) occurs then the new composition of
248 	 * the menu will be a, b, _, _, _, d (with each _ representing some
249 	 * new item).
250 	 * Signal handlers may query the model (particularly the added items)
251 	 * and expect to see the results of the modification that is being
252 	 * reported. The signal is emitted after the modification.
253 	 * See Also
254 	 * GActionGroup
255 	 */
256 	void addOnItemsChanged(void delegate(gint, gint, gint, MenuModel) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
257 	{
258 		if ( !("items-changed" in connectedSignals) )
259 		{
260 			Signals.connectData(
261 			getStruct(),
262 			"items-changed",
263 			cast(GCallback)&callBackItemsChanged,
264 			cast(void*)this,
265 			null,
266 			connectFlags);
267 			connectedSignals["items-changed"] = 1;
268 		}
269 		onItemsChangedListeners ~= dlg;
270 	}
271 	extern(C) static void callBackItemsChanged(GMenuModel* modelStruct, gint position, gint removed, gint added, MenuModel _menuModel)
272 	{
273 		foreach ( void delegate(gint, gint, gint, MenuModel) dlg ; _menuModel.onItemsChangedListeners )
274 		{
275 			dlg(position, removed, added, _menuModel);
276 		}
277 	}
278 	
279 	
280 	/**
281 	 * Queries if model is mutable.
282 	 * An immutable GMenuModel will never emit the "items-changed"
283 	 * signal. Consumers of the model may make optimisations accordingly.
284 	 * Since 2.32
285 	 * Returns: TRUE if the model is mutable (ie: "items-changed" may be emitted).
286 	 */
287 	public int isMutable()
288 	{
289 		// gboolean g_menu_model_is_mutable (GMenuModel *model);
290 		return g_menu_model_is_mutable(gMenuModel);
291 	}
292 	
293 	/**
294 	 * Query the number of items in model.
295 	 * Since 2.32
296 	 * Returns: the number of items
297 	 */
298 	public int getNItems()
299 	{
300 		// gint g_menu_model_get_n_items (GMenuModel *model);
301 		return g_menu_model_get_n_items(gMenuModel);
302 	}
303 	
304 	/**
305 	 * Queries the item at position item_index in model for the attribute
306 	 * specified by attribute.
307 	 * If expected_type is non-NULL then it specifies the expected type of
308 	 * the attribute. If it is NULL then any type will be accepted.
309 	 * If the attribute exists and matches expected_type (or if the
310 	 * expected type is unspecified) then the value is returned.
311 	 * If the attribute does not exist, or does not match the expected type
312 	 * then NULL is returned.
313 	 * Since 2.32
314 	 * Params:
315 	 * itemIndex = the index of the item
316 	 * attribute = the attribute to query
317 	 * expectedType = the expected type of the attribute, or
318 	 * NULL. [allow-none]
319 	 * Returns: the value of the attribute. [transfer full]
320 	 */
321 	public Variant getItemAttributeValue(int itemIndex, string attribute, VariantType expectedType)
322 	{
323 		// GVariant * g_menu_model_get_item_attribute_value  (GMenuModel *model,  gint item_index,  const gchar *attribute,  const GVariantType *expected_type);
324 		auto p = g_menu_model_get_item_attribute_value(gMenuModel, itemIndex, Str.toStringz(attribute), (expectedType is null) ? null : expectedType.getVariantTypeStruct());
325 		
326 		if(p is null)
327 		{
328 			return null;
329 		}
330 		
331 		return ObjectG.getDObject!(Variant)(cast(GVariant*) p);
332 	}
333 	
334 	/**
335 	 * Queries the item at position item_index in model for the link
336 	 * specified by link.
337 	 * If the link exists, the linked GMenuModel is returned. If the link
338 	 * does not exist, NULL is returned.
339 	 * Since 2.32
340 	 * Params:
341 	 * itemIndex = the index of the item
342 	 * link = the link to query
343 	 * Returns: the linked GMenuModel, or NULL. [transfer full]
344 	 */
345 	public MenuModel getItemLink(int itemIndex, string link)
346 	{
347 		// GMenuModel * g_menu_model_get_item_link (GMenuModel *model,  gint item_index,  const gchar *link);
348 		auto p = g_menu_model_get_item_link(gMenuModel, itemIndex, Str.toStringz(link));
349 		
350 		if(p is null)
351 		{
352 			return null;
353 		}
354 		
355 		return ObjectG.getDObject!(MenuModel)(cast(GMenuModel*) p);
356 	}
357 	
358 	/**
359 	 * Creates a GMenuAttributeIter to iterate over the attributes of
360 	 * the item at position item_index in model.
361 	 * You must free the iterator with g_object_unref() when you are done.
362 	 * Since 2.32
363 	 * Params:
364 	 * itemIndex = the index of the item
365 	 * Returns: a new GMenuAttributeIter. [transfer full]
366 	 */
367 	public MenuAttributeIter iterateItemAttributes(int itemIndex)
368 	{
369 		// GMenuAttributeIter * g_menu_model_iterate_item_attributes  (GMenuModel *model,  gint item_index);
370 		auto p = g_menu_model_iterate_item_attributes(gMenuModel, itemIndex);
371 		
372 		if(p is null)
373 		{
374 			return null;
375 		}
376 		
377 		return ObjectG.getDObject!(MenuAttributeIter)(cast(GMenuAttributeIter*) p);
378 	}
379 	
380 	/**
381 	 * Creates a GMenuLinkIter to iterate over the links of the item at
382 	 * position item_index in model.
383 	 * You must free the iterator with g_object_unref() when you are done.
384 	 * Since 2.32
385 	 * Params:
386 	 * itemIndex = the index of the item
387 	 * Returns: a new GMenuLinkIter. [transfer full]
388 	 */
389 	public MenuLinkIter iterateItemLinks(int itemIndex)
390 	{
391 		// GMenuLinkIter * g_menu_model_iterate_item_links (GMenuModel *model,  gint item_index);
392 		auto p = g_menu_model_iterate_item_links(gMenuModel, itemIndex);
393 		
394 		if(p is null)
395 		{
396 			return null;
397 		}
398 		
399 		return ObjectG.getDObject!(MenuLinkIter)(cast(GMenuLinkIter*) p);
400 	}
401 	
402 	/**
403 	 * Requests emission of the "items-changed" signal on model.
404 	 * This function should never be called except by GMenuModel
405 	 * subclasses. Any other calls to this function will very likely lead
406 	 * to a violation of the interface of the model.
407 	 * The implementation should update its internal representation of the
408 	 * menu before emitting the signal. The implementation should further
409 	 * expect to receive queries about the new state of the menu (and
410 	 * particularly added menu items) while signal handlers are running.
411 	 * The implementation must dispatch this call directly from a mainloop
412 	 * entry and not in response to calls -- particularly those from the
413 	 * GMenuModel API. Said another way: the menu must not change while
414 	 * user code is running without returning to the mainloop.
415 	 * Since 2.32
416 	 * Params:
417 	 * position = the position of the change
418 	 * removed = the number of items removed
419 	 * added = the number of items added
420 	 */
421 	public void itemsChanged(int position, int removed, int added)
422 	{
423 		// void g_menu_model_items_changed (GMenuModel *model,  gint position,  gint removed,  gint added);
424 		g_menu_model_items_changed(gMenuModel, position, removed, added);
425 	}
426 }