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  = GActionGroup.html
27  * outPack = gio
28  * outFile = ActionGroupT
29  * strct   = GActionGroup
30  * realStrct=
31  * ctorStrct=
32  * clss    = ActionGroupT
33  * interf  = ActionGroupIF
34  * class Code: No
35  * interface Code: No
36  * template for:
37  * 	- TStruct
38  * extend  = 
39  * implements:
40  * prefixes:
41  * 	- g_action_group_
42  * omit structs:
43  * omit prefixes:
44  * omit code:
45  * omit signals:
46  * imports:
47  * 	- glib.Str
48  * 	- glib.Variant
49  * 	- glib.VariantType
50  * structWrap:
51  * 	- GVariant* -> Variant
52  * 	- GVariantType* -> VariantType
53  * module aliases:
54  * local aliases:
55  * overrides:
56  */
57 
58 module gio.ActionGroupT;
59 
60 public  import gtkc.giotypes;
61 
62 public import gtkc.gio;
63 public import glib.ConstructionException;
64 public import gobject.ObjectG;
65 
66 public import gobject.Signals;
67 public  import gtkc.gdktypes;
68 public import glib.Str;
69 public import glib.Variant;
70 public import glib.VariantType;
71 
72 
73 
74 /**
75  * GActionGroup represents a group of actions. Actions can be used to
76  * expose functionality in a structured way, either from one part of a
77  * program to another, or to the outside world. Action groups are often
78  * used together with a GMenuModel that provides additional
79  * representation data for displaying the actions to the user, e.g. in
80  * a menu.
81  *
82  * The main way to interact with the actions in a GActionGroup is to
83  * activate them with g_action_group_activate_action(). Activating an
84  * action may require a GVariant parameter. The required type of the
85  * parameter can be inquired with g_action_group_get_action_parameter_type().
86  * Actions may be disabled, see g_action_group_get_action_enabled().
87  * Activating a disabled action has no effect.
88  *
89  * Actions may optionally have a state in the form of a GVariant. The
90  * current state of an action can be inquired with
91  * g_action_group_get_action_state(). Activating a stateful action may
92  * change its state, but it is also possible to set the state by calling
93  * g_action_group_change_action_state().
94  *
95  * As typical example, consider a text editing application which has an
96  * option to change the current font to 'bold'. A good way to represent
97  * this would be a stateful action, with a boolean state. Activating the
98  * action would toggle the state.
99  *
100  * Each action in the group has a unique name (which is a string). All
101  * method calls, except g_action_group_list_actions() take the name of
102  * an action as an argument.
103  *
104  * The GActionGroup API is meant to be the 'public' API to the action
105  * group. The calls here are exactly the interaction that 'external
106  * forces' (eg: UI, incoming D-Bus messages, etc.) are supposed to have
107  * with actions. 'Internal' APIs (ie: ones meant only to be accessed by
108  * the action group implementation) are found on subclasses. This is
109  * why you will find - for example - g_action_group_get_action_enabled()
110  * but not an equivalent set() call.
111  *
112  * Signals are emitted on the action group in response to state changes
113  * on individual actions.
114  *
115  * Implementations of GActionGroup should provide implementations for
116  * the virtual functions g_action_group_list_actions() and
117  * g_action_group_query_action(). The other virtual functions should
118  * not be implemented - their "wrappers" are actually implemented with
119  * calls to g_action_group_query_action().
120  */
121 public template ActionGroupT(TStruct)
122 {
123 	
124 	/** the main Gtk struct */
125 	protected GActionGroup* gActionGroup;
126 	
127 	
128 	/** Get the main Gtk struct */
129 	public GActionGroup* getActionGroupTStruct()
130 	{
131 		return cast(GActionGroup*)getStruct();
132 	}
133 	
134 	
135 	/**
136 	 */
137 	int[string] connectedSignals;
138 	
139 	void delegate(string, ActionGroupIF)[] _onActionAddedListeners;
140 	@property void delegate(string, ActionGroupIF)[] onActionAddedListeners()
141 	{
142 		return  _onActionAddedListeners;
143 	}
144 	/**
145 	 * Signals that a new action was just added to the group.
146 	 * This signal is emitted after the action has been added
147 	 * and is now visible.
148 	 * Since 2.28
149 	 */
150 	void addOnActionAdded(void delegate(string, ActionGroupIF) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
151 	{
152 		if ( !("action-added" in connectedSignals) )
153 		{
154 			Signals.connectData(
155 			getStruct(),
156 			"action-added",
157 			cast(GCallback)&callBackActionAdded,
158 			cast(void*)cast(ActionGroupIF)this,
159 			null,
160 			connectFlags);
161 			connectedSignals["action-added"] = 1;
162 		}
163 		_onActionAddedListeners ~= dlg;
164 	}
165 	extern(C) static void callBackActionAdded(GActionGroup* actionGroupStruct, gchar* actionName, ActionGroupIF _actionGroupIF)
166 	{
167 		foreach ( void delegate(string, ActionGroupIF) dlg ; _actionGroupIF.onActionAddedListeners )
168 		{
169 			dlg(Str.toString(actionName), _actionGroupIF);
170 		}
171 	}
172 	
173 	void delegate(string, gboolean, ActionGroupIF)[] _onActionEnabledChangedListeners;
174 	@property void delegate(string, gboolean, ActionGroupIF)[] onActionEnabledChangedListeners()
175 	{
176 		return  _onActionEnabledChangedListeners;
177 	}
178 	/**
179 	 * Signals that the enabled status of the named action has changed.
180 	 * Since 2.28
181 	 */
182 	void addOnActionEnabledChanged(void delegate(string, gboolean, ActionGroupIF) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
183 	{
184 		if ( !("action-enabled-changed" in connectedSignals) )
185 		{
186 			Signals.connectData(
187 			getStruct(),
188 			"action-enabled-changed",
189 			cast(GCallback)&callBackActionEnabledChanged,
190 			cast(void*)cast(ActionGroupIF)this,
191 			null,
192 			connectFlags);
193 			connectedSignals["action-enabled-changed"] = 1;
194 		}
195 		_onActionEnabledChangedListeners ~= dlg;
196 	}
197 	extern(C) static void callBackActionEnabledChanged(GActionGroup* actionGroupStruct, gchar* actionName, gboolean enabled, ActionGroupIF _actionGroupIF)
198 	{
199 		foreach ( void delegate(string, gboolean, ActionGroupIF) dlg ; _actionGroupIF.onActionEnabledChangedListeners )
200 		{
201 			dlg(Str.toString(actionName), enabled, _actionGroupIF);
202 		}
203 	}
204 	
205 	void delegate(string, ActionGroupIF)[] _onActionRemovedListeners;
206 	@property void delegate(string, ActionGroupIF)[] onActionRemovedListeners()
207 	{
208 		return  _onActionRemovedListeners;
209 	}
210 	/**
211 	 * Signals that an action is just about to be removed from the group.
212 	 * This signal is emitted before the action is removed, so the action
213 	 * is still visible and can be queried from the signal handler.
214 	 * Since 2.28
215 	 */
216 	void addOnActionRemoved(void delegate(string, ActionGroupIF) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
217 	{
218 		if ( !("action-removed" in connectedSignals) )
219 		{
220 			Signals.connectData(
221 			getStruct(),
222 			"action-removed",
223 			cast(GCallback)&callBackActionRemoved,
224 			cast(void*)cast(ActionGroupIF)this,
225 			null,
226 			connectFlags);
227 			connectedSignals["action-removed"] = 1;
228 		}
229 		_onActionRemovedListeners ~= dlg;
230 	}
231 	extern(C) static void callBackActionRemoved(GActionGroup* actionGroupStruct, gchar* actionName, ActionGroupIF _actionGroupIF)
232 	{
233 		foreach ( void delegate(string, ActionGroupIF) dlg ; _actionGroupIF.onActionRemovedListeners )
234 		{
235 			dlg(Str.toString(actionName), _actionGroupIF);
236 		}
237 	}
238 	
239 	void delegate(string, Variant, ActionGroupIF)[] _onActionStateChangedListeners;
240 	@property void delegate(string, Variant, ActionGroupIF)[] onActionStateChangedListeners()
241 	{
242 		return  _onActionStateChangedListeners;
243 	}
244 	/**
245 	 * Signals that the state of the named action has changed.
246 	 * Since 2.28
247 	 * See Also
248 	 * GAction
249 	 */
250 	void addOnActionStateChanged(void delegate(string, Variant, ActionGroupIF) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
251 	{
252 		if ( !("action-state-changed" in connectedSignals) )
253 		{
254 			Signals.connectData(
255 			getStruct(),
256 			"action-state-changed",
257 			cast(GCallback)&callBackActionStateChanged,
258 			cast(void*)cast(ActionGroupIF)this,
259 			null,
260 			connectFlags);
261 			connectedSignals["action-state-changed"] = 1;
262 		}
263 		_onActionStateChangedListeners ~= dlg;
264 	}
265 	extern(C) static void callBackActionStateChanged(GActionGroup* actionGroupStruct, gchar* actionName, GVariant* value, ActionGroupIF _actionGroupIF)
266 	{
267 		foreach ( void delegate(string, Variant, ActionGroupIF) dlg ; _actionGroupIF.onActionStateChangedListeners )
268 		{
269 			dlg(Str.toString(actionName), ObjectG.getDObject!(Variant)(value), _actionGroupIF);
270 		}
271 	}
272 	
273 	
274 	/**
275 	 * Lists the actions contained within action_group.
276 	 * The caller is responsible for freeing the list with g_strfreev() when
277 	 * it is no longer required.
278 	 * Since 2.28
279 	 * Returns: a NULL-terminated array of the names of the actions in the groupb. [transfer full]
280 	 */
281 	public string[] listActions()
282 	{
283 		// gchar ** g_action_group_list_actions (GActionGroup *action_group);
284 		return Str.toStringArray(g_action_group_list_actions(getActionGroupTStruct()));
285 	}
286 	
287 	/**
288 	 * Queries all aspects of the named action within an action_group.
289 	 * This function acquires the information available from
290 	 * g_action_group_has_action(), g_action_group_get_action_enabled(),
291 	 * g_action_group_get_action_parameter_type(),
292 	 * g_action_group_get_action_state_type(),
293 	 * g_action_group_get_action_state_hint() and
294 	 * g_action_group_get_action_state() with a single function call.
295 	 * This provides two main benefits.
296 	 * The first is the improvement in efficiency that comes with not having
297 	 * to perform repeated lookups of the action in order to discover
298 	 * different things about it. The second is that implementing
299 	 * GActionGroup can now be done by only overriding this one virtual
300 	 * function.
301 	 * The interface provides a default implementation of this function that
302 	 * calls the individual functions, as required, to fetch the
303 	 * information. The interface also provides default implementations of
304 	 * those functions that call this function. All implementations,
305 	 * therefore, must override either this function or all of the others.
306 	 * If the action exists, TRUE is returned and any of the requested
307 	 * fields (as indicated by having a non-NULL reference passed in) are
308 	 * filled. If the action doesn't exist, FALSE is returned and the
309 	 * fields may or may not have been modified.
310 	 * Since 2.32
311 	 * Params:
312 	 * actionName = the name of an action in the group
313 	 * enabled = if the action is presently enabled. [out]
314 	 * parameterType = the parameter type, or NULL if none needed. [out][allow-none]
315 	 * stateType = the state type, or NULL if stateless. [out][allow-none]
316 	 * stateHint = the state hint, or NULL if none. [out][allow-none]
317 	 * state = the current state, or NULL if stateless. [out][allow-none]
318 	 * Returns: TRUE if the action exists, else FALSE
319 	 */
320 	public int queryAction(string actionName, out int enabled, out VariantType parameterType, out VariantType stateType, out Variant stateHint, out Variant state)
321 	{
322 		// gboolean g_action_group_query_action (GActionGroup *action_group,  const gchar *action_name,  gboolean *enabled,  const GVariantType **parameter_type,  const GVariantType **state_type,  GVariant **state_hint,  GVariant **state);
323 		GVariantType* outparameterType = null;
324 		GVariantType* outstateType = null;
325 		GVariant* outstateHint = null;
326 		GVariant* outstate = null;
327 		
328 		auto p = g_action_group_query_action(getActionGroupTStruct(), Str.toStringz(actionName), &enabled, &outparameterType, &outstateType, &outstateHint, &outstate);
329 		
330 		parameterType = ObjectG.getDObject!(VariantType)(outparameterType);
331 		stateType = ObjectG.getDObject!(VariantType)(outstateType);
332 		stateHint = ObjectG.getDObject!(Variant)(outstateHint);
333 		state = ObjectG.getDObject!(Variant)(outstate);
334 		return p;
335 	}
336 	
337 	/**
338 	 * Checks if the named action exists within action_group.
339 	 * Since 2.28
340 	 * Params:
341 	 * actionName = the name of the action to check for
342 	 * Returns: whether the named action exists
343 	 */
344 	public int hasAction(string actionName)
345 	{
346 		// gboolean g_action_group_has_action (GActionGroup *action_group,  const gchar *action_name);
347 		return g_action_group_has_action(getActionGroupTStruct(), Str.toStringz(actionName));
348 	}
349 	
350 	/**
351 	 * Checks if the named action within action_group is currently enabled.
352 	 * An action must be enabled in order to be activated or in order to
353 	 * have its state changed from outside callers.
354 	 * Since 2.28
355 	 * Params:
356 	 * actionName = the name of the action to query
357 	 * Returns: whether or not the action is currently enabled
358 	 */
359 	public int getActionEnabled(string actionName)
360 	{
361 		// gboolean g_action_group_get_action_enabled (GActionGroup *action_group,  const gchar *action_name);
362 		return g_action_group_get_action_enabled(getActionGroupTStruct(), Str.toStringz(actionName));
363 	}
364 	
365 	/**
366 	 * Queries the type of the parameter that must be given when activating
367 	 * the named action within action_group.
368 	 * When activating the action using g_action_group_activate_action(),
369 	 * the GVariant given to that function must be of the type returned
370 	 * by this function.
371 	 * In the case that this function returns NULL, you must not give any
372 	 * GVariant, but NULL instead.
373 	 * The parameter type of a particular action will never change but it is
374 	 * possible for an action to be removed and for a new action to be added
375 	 * with the same name but a different parameter type.
376 	 * Since 2.28
377 	 * Params:
378 	 * actionName = the name of the action to query
379 	 * Returns: the parameter type
380 	 */
381 	public VariantType getActionParameterType(string actionName)
382 	{
383 		// const GVariantType * g_action_group_get_action_parameter_type  (GActionGroup *action_group,  const gchar *action_name);
384 		auto p = g_action_group_get_action_parameter_type(getActionGroupTStruct(), Str.toStringz(actionName));
385 		
386 		if(p is null)
387 		{
388 			return null;
389 		}
390 		
391 		return ObjectG.getDObject!(VariantType)(cast(GVariantType*) p);
392 	}
393 	
394 	/**
395 	 * Queries the type of the state of the named action within
396 	 * action_group.
397 	 * If the action is stateful then this function returns the
398 	 * GVariantType of the state. All calls to
399 	 * g_action_group_change_action_state() must give a GVariant of this
400 	 * type and g_action_group_get_action_state() will return a GVariant
401 	 * of the same type.
402 	 * If the action is not stateful then this function will return NULL.
403 	 * In that case, g_action_group_get_action_state() will return NULL
404 	 * and you must not call g_action_group_change_action_state().
405 	 * The state type of a particular action will never change but it is
406 	 * possible for an action to be removed and for a new action to be added
407 	 * with the same name but a different state type.
408 	 * Since 2.28
409 	 * Params:
410 	 * actionName = the name of the action to query
411 	 * Returns: the state type, if the action is stateful. [transfer full]
412 	 */
413 	public VariantType getActionStateType(string actionName)
414 	{
415 		// const GVariantType * g_action_group_get_action_state_type  (GActionGroup *action_group,  const gchar *action_name);
416 		auto p = g_action_group_get_action_state_type(getActionGroupTStruct(), Str.toStringz(actionName));
417 		
418 		if(p is null)
419 		{
420 			return null;
421 		}
422 		
423 		return ObjectG.getDObject!(VariantType)(cast(GVariantType*) p);
424 	}
425 	
426 	/**
427 	 * Requests a hint about the valid range of values for the state of the
428 	 * named action within action_group.
429 	 * If NULL is returned it either means that the action is not stateful
430 	 * or that there is no hint about the valid range of values for the
431 	 * state of the action.
432 	 * If a GVariant array is returned then each item in the array is a
433 	 * possible value for the state. If a GVariant pair (ie: two-tuple) is
434 	 * returned then the tuple specifies the inclusive lower and upper bound
435 	 * of valid values for the state.
436 	 * In any case, the information is merely a hint. It may be possible to
437 	 * have a state value outside of the hinted range and setting a value
438 	 * within the range may fail.
439 	 * The return value (if non-NULL) should be freed with
440 	 * g_variant_unref() when it is no longer required.
441 	 * Since 2.28
442 	 * Params:
443 	 * actionName = the name of the action to query
444 	 * Returns: the state range hint. [transfer full]
445 	 */
446 	public Variant getActionStateHint(string actionName)
447 	{
448 		// GVariant * g_action_group_get_action_state_hint  (GActionGroup *action_group,  const gchar *action_name);
449 		auto p = g_action_group_get_action_state_hint(getActionGroupTStruct(), Str.toStringz(actionName));
450 		
451 		if(p is null)
452 		{
453 			return null;
454 		}
455 		
456 		return ObjectG.getDObject!(Variant)(cast(GVariant*) p);
457 	}
458 	
459 	/**
460 	 * Queries the current state of the named action within action_group.
461 	 * If the action is not stateful then NULL will be returned. If the
462 	 * action is stateful then the type of the return value is the type
463 	 * given by g_action_group_get_action_state_type().
464 	 * The return value (if non-NULL) should be freed with
465 	 * g_variant_unref() when it is no longer required.
466 	 * Since 2.28
467 	 * Params:
468 	 * actionName = the name of the action to query
469 	 * Returns: the current state of the action. [allow-none]
470 	 */
471 	public Variant getActionState(string actionName)
472 	{
473 		// GVariant * g_action_group_get_action_state (GActionGroup *action_group,  const gchar *action_name);
474 		auto p = g_action_group_get_action_state(getActionGroupTStruct(), Str.toStringz(actionName));
475 		
476 		if(p is null)
477 		{
478 			return null;
479 		}
480 		
481 		return ObjectG.getDObject!(Variant)(cast(GVariant*) p);
482 	}
483 	
484 	/**
485 	 * Request for the state of the named action within action_group to be
486 	 * changed to value.
487 	 * The action must be stateful and value must be of the correct type.
488 	 * See g_action_group_get_action_state_type().
489 	 * This call merely requests a change. The action may refuse to change
490 	 * its state or may change its state to something other than value.
491 	 * See g_action_group_get_action_state_hint().
492 	 * If the value GVariant is floating, it is consumed.
493 	 * Since 2.28
494 	 * Params:
495 	 * actionName = the name of the action to request the change on
496 	 * value = the new state
497 	 */
498 	public void changeActionState(string actionName, Variant value)
499 	{
500 		// void g_action_group_change_action_state (GActionGroup *action_group,  const gchar *action_name,  GVariant *value);
501 		g_action_group_change_action_state(getActionGroupTStruct(), Str.toStringz(actionName), (value is null) ? null : value.getVariantStruct());
502 	}
503 	
504 	/**
505 	 * Activate the named action within action_group.
506 	 * If the action is expecting a parameter, then the correct type of
507 	 * parameter must be given as parameter. If the action is expecting no
508 	 * parameters then parameter must be NULL. See
509 	 * g_action_group_get_action_parameter_type().
510 	 * Since 2.28
511 	 * Params:
512 	 * actionName = the name of the action to activate
513 	 * parameter = parameters to the activation. [allow-none]
514 	 */
515 	public void activateAction(string actionName, Variant parameter)
516 	{
517 		// void g_action_group_activate_action (GActionGroup *action_group,  const gchar *action_name,  GVariant *parameter);
518 		g_action_group_activate_action(getActionGroupTStruct(), Str.toStringz(actionName), (parameter is null) ? null : parameter.getVariantStruct());
519 	}
520 	
521 	/**
522 	 * Emits the "action-added" signal on action_group.
523 	 * This function should only be called by GActionGroup implementations.
524 	 * Since 2.28
525 	 * Params:
526 	 * actionName = the name of an action in the group
527 	 */
528 	public void actionAdded(string actionName)
529 	{
530 		// void g_action_group_action_added (GActionGroup *action_group,  const gchar *action_name);
531 		g_action_group_action_added(getActionGroupTStruct(), Str.toStringz(actionName));
532 	}
533 	
534 	/**
535 	 * Emits the "action-removed" signal on action_group.
536 	 * This function should only be called by GActionGroup implementations.
537 	 * Since 2.28
538 	 * Params:
539 	 * actionName = the name of an action in the group
540 	 */
541 	public void actionRemoved(string actionName)
542 	{
543 		// void g_action_group_action_removed (GActionGroup *action_group,  const gchar *action_name);
544 		g_action_group_action_removed(getActionGroupTStruct(), Str.toStringz(actionName));
545 	}
546 	
547 	/**
548 	 * Emits the "action-enabled-changed" signal on action_group.
549 	 * This function should only be called by GActionGroup implementations.
550 	 * Since 2.28
551 	 * Params:
552 	 * actionName = the name of an action in the group
553 	 * enabled = whether or not the action is now enabled
554 	 */
555 	public void actionEnabledChanged(string actionName, int enabled)
556 	{
557 		// void g_action_group_action_enabled_changed  (GActionGroup *action_group,  const gchar *action_name,  gboolean enabled);
558 		g_action_group_action_enabled_changed(getActionGroupTStruct(), Str.toStringz(actionName), enabled);
559 	}
560 	
561 	/**
562 	 * Emits the "action-state-changed" signal on action_group.
563 	 * This function should only be called by GActionGroup implementations.
564 	 * Since 2.28
565 	 * Signal Details
566 	 * The "action-added" signal
567 	 * void user_function (GActionGroup *action_group,
568 	 *  gchar *action_name,
569 	 *  gpointer user_data) : Has Details
570 	 * Signals that a new action was just added to the group.
571 	 * This signal is emitted after the action has been added
572 	 * and is now visible.
573 	 * Since 2.28
574 	 * Params:
575 	 * actionName = the name of an action in the group
576 	 * state = the new state of the named action
577 	 * actionName = the name of the action in action_group
578 	 */
579 	public void actionStateChanged(string actionName, Variant state)
580 	{
581 		// void g_action_group_action_state_changed (GActionGroup *action_group,  const gchar *action_name,  GVariant *state);
582 		g_action_group_action_state_changed(getActionGroupTStruct(), Str.toStringz(actionName), (state is null) ? null : state.getVariantStruct());
583 	}
584 }