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