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