source: appstream-generator/build/girepo/gio/SimpleAction.d @ 4841

Last change on this file since 4841 was 4841, checked in by Juanma, 2 years ago

Initial release

File size: 9.6 KB
RevLine 
[4841]1/*
2 * Licensed under the GNU Lesser General Public License Version 3
3 *
4 * This library is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU Lesser General Public License as published by
6 * the Free Software Foundation, either version 3 of the license, or
7 * (at your option) any later version.
8 *
9 * This software is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 * GNU Lesser General Public License for more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public License
15 * along with this library.  If not, see <http://www.gnu.org/licenses/>.
16 */
17
18// generated automatically - do not change
19
20
21module gio.SimpleAction;
22
23private import gi.gio;
24public  import gi.giotypes;
25private import gio.ActionIF;
26private import gio.ActionT;
27private import glib.ConstructionException;
28private import glib.Str;
29private import glib.Variant;
30private import glib.VariantType;
31private import gobject.ObjectG;
32private import gobject.Signals;
33private import std.algorithm;
34
35
36/**
37 * A #GSimpleAction is the obvious simple implementation of the #GAction
38 * interface. This is the easiest way to create an action for purposes of
39 * adding it to a #GSimpleActionGroup.
40 *
41 * See also #GtkAction.
42 */
43public class SimpleAction : ObjectG, ActionIF
44{
45        /** the main Gtk struct */
46        protected GSimpleAction* gSimpleAction;
47
48        /** Get the main Gtk struct */
49        public GSimpleAction* getSimpleActionStruct()
50        {
51                return gSimpleAction;
52        }
53
54        /** the main Gtk struct as a void* */
55        protected override void* getStruct()
56        {
57                return cast(void*)gSimpleAction;
58        }
59
60        protected override void setStruct(GObject* obj)
61        {
62                gSimpleAction = cast(GSimpleAction*)obj;
63                super.setStruct(obj);
64        }
65
66        /**
67         * Sets our main struct and passes it to the parent class.
68         */
69        public this (GSimpleAction* gSimpleAction, bool ownedRef = false)
70        {
71                this.gSimpleAction = gSimpleAction;
72                super(cast(GObject*)gSimpleAction, ownedRef);
73        }
74
75        // add the Action capabilities
76        mixin ActionT!(GSimpleAction);
77
78
79        /** */
80        public static GType getType()
81        {
82                return g_simple_action_get_type();
83        }
84
85        /**
86         * Creates a new action.
87         *
88         * The created action is stateless.  See g_simple_action_new_stateful().
89         *
90         * Params:
91         *     name = the name of the action
92         *     parameterType = the type of parameter to the activate function
93         *
94         * Returns: a new #GSimpleAction
95         *
96         * Since: 2.28
97         *
98         * Throws: ConstructionException GTK+ fails to create the object.
99         */
100        public this(string name, VariantType parameterType)
101        {
102                auto p = g_simple_action_new(Str.toStringz(name), (parameterType is null) ? null : parameterType.getVariantTypeStruct());
103               
104                if(p is null)
105                {
106                        throw new ConstructionException("null returned by new");
107                }
108               
109                this(cast(GSimpleAction*) p, true);
110        }
111
112        /**
113         * Creates a new stateful action.
114         *
115         * @state is the initial state of the action.  All future state values
116         * must have the same #GVariantType as the initial state.
117         *
118         * If the @state GVariant is floating, it is consumed.
119         *
120         * Params:
121         *     name = the name of the action
122         *     parameterType = the type of the parameter to the activate function
123         *     state = the initial state of the action
124         *
125         * Returns: a new #GSimpleAction
126         *
127         * Since: 2.28
128         *
129         * Throws: ConstructionException GTK+ fails to create the object.
130         */
131        public this(string name, VariantType parameterType, Variant state)
132        {
133                auto p = g_simple_action_new_stateful(Str.toStringz(name), (parameterType is null) ? null : parameterType.getVariantTypeStruct(), (state is null) ? null : state.getVariantStruct());
134               
135                if(p is null)
136                {
137                        throw new ConstructionException("null returned by new_stateful");
138                }
139               
140                this(cast(GSimpleAction*) p, true);
141        }
142
143        /**
144         * Sets the action as enabled or not.
145         *
146         * An action must be enabled in order to be activated or in order to
147         * have its state changed from outside callers.
148         *
149         * This should only be called by the implementor of the action.  Users
150         * of the action should not attempt to modify its enabled flag.
151         *
152         * Params:
153         *     enabled = whether the action is enabled
154         *
155         * Since: 2.28
156         */
157        public void setEnabled(bool enabled)
158        {
159                g_simple_action_set_enabled(gSimpleAction, enabled);
160        }
161
162        /**
163         * Sets the state of the action.
164         *
165         * This directly updates the 'state' property to the given value.
166         *
167         * This should only be called by the implementor of the action.  Users
168         * of the action should not attempt to directly modify the 'state'
169         * property.  Instead, they should call g_action_change_state() to
170         * request the change.
171         *
172         * If the @value GVariant is floating, it is consumed.
173         *
174         * Params:
175         *     value = the new #GVariant for the state
176         *
177         * Since: 2.30
178         */
179        public void setState(Variant value)
180        {
181                g_simple_action_set_state(gSimpleAction, (value is null) ? null : value.getVariantStruct());
182        }
183
184        /**
185         * Sets the state hint for the action.
186         *
187         * See g_action_get_state_hint() for more information about
188         * action state hints.
189         *
190         * Params:
191         *     stateHint = a #GVariant representing the state hint
192         *
193         * Since: 2.44
194         */
195        public void setStateHint(Variant stateHint)
196        {
197                g_simple_action_set_state_hint(gSimpleAction, (stateHint is null) ? null : stateHint.getVariantStruct());
198        }
199
200        protected class OnActivateDelegateWrapper
201        {
202                static OnActivateDelegateWrapper[] listeners;
203                void delegate(Variant, SimpleAction) dlg;
204                gulong handlerId;
205               
206                this(void delegate(Variant, SimpleAction) dlg)
207                {
208                        this.dlg = dlg;
209                        this.listeners ~= this;
210                }
211               
212                void remove(OnActivateDelegateWrapper source)
213                {
214                        foreach(index, wrapper; listeners)
215                        {
216                                if (wrapper.handlerId == source.handlerId)
217                                {
218                                        listeners[index] = null;
219                                        listeners = std.algorithm.remove(listeners, index);
220                                        break;
221                                }
222                        }
223                }
224        }
225
226        /**
227         * Indicates that the action was just activated.
228         *
229         * @parameter will always be of the expected type.  In the event that
230         * an incorrect type was given, no signal will be emitted.
231         *
232         * Since GLib 2.40, if no handler is connected to this signal then the
233         * default behaviour for boolean-stated actions with a %NULL parameter
234         * type is to toggle them via the #GSimpleAction::change-state signal.
235         * For stateful actions where the state type is equal to the parameter
236         * type, the default is to forward them directly to
237         * #GSimpleAction::change-state.  This should allow almost all users
238         * of #GSimpleAction to connect only one handler or the other.
239         *
240         * Params:
241         *     parameter = the parameter to the activation
242         *
243         * Since: 2.28
244         */
245        gulong addOnActivate(void delegate(Variant, SimpleAction) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
246        {
247                auto wrapper = new OnActivateDelegateWrapper(dlg);
248                wrapper.handlerId = Signals.connectData(
249                        this,
250                        "activate",
251                        cast(GCallback)&callBackActivate,
252                        cast(void*)wrapper,
253                        cast(GClosureNotify)&callBackActivateDestroy,
254                        connectFlags);
255                return wrapper.handlerId;
256        }
257       
258        extern(C) static void callBackActivate(GSimpleAction* simpleactionStruct, GVariant* parameter, OnActivateDelegateWrapper wrapper)
259        {
260                wrapper.dlg(new Variant(parameter), wrapper.outer);
261        }
262       
263        extern(C) static void callBackActivateDestroy(OnActivateDelegateWrapper wrapper, GClosure* closure)
264        {
265                wrapper.remove(wrapper);
266        }
267
268        protected class OnChangeStateDelegateWrapper
269        {
270                static OnChangeStateDelegateWrapper[] listeners;
271                void delegate(Variant, SimpleAction) dlg;
272                gulong handlerId;
273               
274                this(void delegate(Variant, SimpleAction) dlg)
275                {
276                        this.dlg = dlg;
277                        this.listeners ~= this;
278                }
279               
280                void remove(OnChangeStateDelegateWrapper source)
281                {
282                        foreach(index, wrapper; listeners)
283                        {
284                                if (wrapper.handlerId == source.handlerId)
285                                {
286                                        listeners[index] = null;
287                                        listeners = std.algorithm.remove(listeners, index);
288                                        break;
289                                }
290                        }
291                }
292        }
293
294        /**
295         * Indicates that the action just received a request to change its
296         * state.
297         *
298         * @value will always be of the correct state type.  In the event that
299         * an incorrect type was given, no signal will be emitted.
300         *
301         * If no handler is connected to this signal then the default
302         * behaviour is to call g_simple_action_set_state() to set the state
303         * to the requested value. If you connect a signal handler then no
304         * default action is taken. If the state should change then you must
305         * call g_simple_action_set_state() from the handler.
306         *
307         * An example of a 'change-state' handler:
308         * |[<!-- language="C" -->
309         * static void
310         * change_volume_state (GSimpleAction *action,
311         * GVariant      *value,
312         * gpointer       user_data)
313         * {
314         * gint requested;
315         *
316         * requested = g_variant_get_int32 (value);
317         *
318         * // Volume only goes from 0 to 10
319         * if (0 <= requested && requested <= 10)
320         * g_simple_action_set_state (action, value);
321         * }
322         * ]|
323         *
324         * The handler need not set the state to the requested value.
325         * It could set it to any value at all, or take some other action.
326         *
327         * Params:
328         *     value = the requested value for the state
329         *
330         * Since: 2.30
331         */
332        gulong addOnChangeState(void delegate(Variant, SimpleAction) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
333        {
334                auto wrapper = new OnChangeStateDelegateWrapper(dlg);
335                wrapper.handlerId = Signals.connectData(
336                        this,
337                        "change-state",
338                        cast(GCallback)&callBackChangeState,
339                        cast(void*)wrapper,
340                        cast(GClosureNotify)&callBackChangeStateDestroy,
341                        connectFlags);
342                return wrapper.handlerId;
343        }
344       
345        extern(C) static void callBackChangeState(GSimpleAction* simpleactionStruct, GVariant* value, OnChangeStateDelegateWrapper wrapper)
346        {
347                wrapper.dlg(new Variant(value), wrapper.outer);
348        }
349       
350        extern(C) static void callBackChangeStateDestroy(OnChangeStateDelegateWrapper wrapper, GClosure* closure)
351        {
352                wrapper.remove(wrapper);
353        }
354}
Note: See TracBrowser for help on using the repository browser.