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.SimpleAction; 26 27 private import gio.ActionIF; 28 private import gio.ActionT; 29 private import glib.ConstructionException; 30 private import glib.Str; 31 private import glib.Variant; 32 private import glib.VariantType; 33 private import gobject.ObjectG; 34 private import gobject.Signals; 35 public import gtkc.gdktypes; 36 private import gtkc.gio; 37 public import gtkc.giotypes; 38 39 40 /** 41 * A #GSimpleAction is the obvious simple implementation of the #GAction 42 * interface. This is the easiest way to create an action for purposes of 43 * adding it to a #GSimpleActionGroup. 44 * 45 * See also #GtkAction. 46 */ 47 public class SimpleAction : ObjectG, ActionIF 48 { 49 /** the main Gtk struct */ 50 protected GSimpleAction* gSimpleAction; 51 52 /** Get the main Gtk struct */ 53 public GSimpleAction* getSimpleActionStruct() 54 { 55 return gSimpleAction; 56 } 57 58 /** the main Gtk struct as a void* */ 59 protected override void* getStruct() 60 { 61 return cast(void*)gSimpleAction; 62 } 63 64 protected override void setStruct(GObject* obj) 65 { 66 gSimpleAction = cast(GSimpleAction*)obj; 67 super.setStruct(obj); 68 } 69 70 /** 71 * Sets our main struct and passes it to the parent class. 72 */ 73 public this (GSimpleAction* gSimpleAction, bool ownedRef = false) 74 { 75 this.gSimpleAction = gSimpleAction; 76 super(cast(GObject*)gSimpleAction, ownedRef); 77 } 78 79 // add the Action capabilities 80 mixin ActionT!(GSimpleAction); 81 82 /** 83 */ 84 85 public static GType getType() 86 { 87 return g_simple_action_get_type(); 88 } 89 90 /** 91 * Creates a new action. 92 * 93 * The created action is stateless. See g_simple_action_new_stateful(). 94 * 95 * Params: 96 * name = the name of the action 97 * parameterType = the type of parameter to the activate function 98 * 99 * Return: a new #GSimpleAction 100 * 101 * Since: 2.28 102 * 103 * Throws: ConstructionException GTK+ fails to create the object. 104 */ 105 public this(string name, VariantType parameterType) 106 { 107 auto p = g_simple_action_new(Str.toStringz(name), (parameterType is null) ? null : parameterType.getVariantTypeStruct()); 108 109 if(p is null) 110 { 111 throw new ConstructionException("null returned by new"); 112 } 113 114 this(cast(GSimpleAction*) p, true); 115 } 116 117 /** 118 * Creates a new stateful action. 119 * 120 * @state is the initial state of the action. All future state values 121 * must have the same #GVariantType as the initial state. 122 * 123 * If the @state GVariant is floating, it is consumed. 124 * 125 * Params: 126 * name = the name of the action 127 * parameterType = the type of the parameter to the activate function 128 * state = the initial state of the action 129 * 130 * Return: a new #GSimpleAction 131 * 132 * Since: 2.28 133 * 134 * Throws: ConstructionException GTK+ fails to create the object. 135 */ 136 public this(string name, VariantType parameterType, Variant state) 137 { 138 auto p = g_simple_action_new_stateful(Str.toStringz(name), (parameterType is null) ? null : parameterType.getVariantTypeStruct(), (state is null) ? null : state.getVariantStruct()); 139 140 if(p is null) 141 { 142 throw new ConstructionException("null returned by new_stateful"); 143 } 144 145 this(cast(GSimpleAction*) p, true); 146 } 147 148 /** 149 * Sets the action as enabled or not. 150 * 151 * An action must be enabled in order to be activated or in order to 152 * have its state changed from outside callers. 153 * 154 * This should only be called by the implementor of the action. Users 155 * of the action should not attempt to modify its enabled flag. 156 * 157 * Params: 158 * enabled = whether the action is enabled 159 * 160 * Since: 2.28 161 */ 162 public void setEnabled(bool enabled) 163 { 164 g_simple_action_set_enabled(gSimpleAction, enabled); 165 } 166 167 /** 168 * Sets the state of the action. 169 * 170 * This directly updates the 'state' property to the given value. 171 * 172 * This should only be called by the implementor of the action. Users 173 * of the action should not attempt to directly modify the 'state' 174 * property. Instead, they should call g_action_change_state() to 175 * request the change. 176 * 177 * If the @value GVariant is floating, it is consumed. 178 * 179 * Params: 180 * value = the new #GVariant for the state 181 * 182 * Since: 2.30 183 */ 184 public void setState(Variant value) 185 { 186 g_simple_action_set_state(gSimpleAction, (value is null) ? null : value.getVariantStruct()); 187 } 188 189 /** 190 * Sets the state hint for the action. 191 * 192 * See g_action_get_state_hint() for more information about 193 * action state hints. 194 * 195 * Params: 196 * stateHint = a #GVariant representing the state hint 197 * 198 * Since: 2.44 199 */ 200 public void setStateHint(Variant stateHint) 201 { 202 g_simple_action_set_state_hint(gSimpleAction, (stateHint is null) ? null : stateHint.getVariantStruct()); 203 } 204 205 int[string] connectedSignals; 206 207 void delegate(Variant, SimpleAction)[] onActivateListeners; 208 /** 209 * Indicates that the action was just activated. 210 * 211 * @parameter will always be of the expected type. In the event that 212 * an incorrect type was given, no signal will be emitted. 213 * 214 * Since GLib 2.40, if no handler is connected to this signal then the 215 * default behaviour for boolean-stated actions with a %NULL parameter 216 * type is to toggle them via the #GSimpleAction::change-state signal. 217 * For stateful actions where the state type is equal to the parameter 218 * type, the default is to forward them directly to 219 * #GSimpleAction::change-state. This should allow almost all users 220 * of #GSimpleAction to connect only one handler or the other. 221 * 222 * Params: 223 * parameter = the parameter to the activation 224 * 225 * Since: 2.28 226 */ 227 void addOnActivate(void delegate(Variant, SimpleAction) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 228 { 229 if ( "activate" !in connectedSignals ) 230 { 231 Signals.connectData( 232 this, 233 "activate", 234 cast(GCallback)&callBackActivate, 235 cast(void*)this, 236 null, 237 connectFlags); 238 connectedSignals["activate"] = 1; 239 } 240 onActivateListeners ~= dlg; 241 } 242 extern(C) static void callBackActivate(GSimpleAction* simpleactionStruct, GVariant* parameter, SimpleAction _simpleaction) 243 { 244 foreach ( void delegate(Variant, SimpleAction) dlg; _simpleaction.onActivateListeners ) 245 { 246 dlg(new Variant(parameter), _simpleaction); 247 } 248 } 249 250 void delegate(Variant, SimpleAction)[] onChangeStateListeners; 251 /** 252 * Indicates that the action just received a request to change its 253 * state. 254 * 255 * @value will always be of the correct state type. In the event that 256 * an incorrect type was given, no signal will be emitted. 257 * 258 * If no handler is connected to this signal then the default 259 * behaviour is to call g_simple_action_set_state() to set the state 260 * to the requested value. If you connect a signal handler then no 261 * default action is taken. If the state should change then you must 262 * call g_simple_action_set_state() from the handler. 263 * 264 * An example of a 'change-state' handler: 265 * |[<!-- language="C" --> 266 * static void 267 * change_volume_state (GSimpleAction *action, 268 * GVariant *value, 269 * gpointer user_data) 270 * { 271 * gint requested; 272 * 273 * requested = g_variant_get_int32 (value); 274 * 275 * // Volume only goes from 0 to 10 276 * if (0 <= requested && requested <= 10) 277 * g_simple_action_set_state (action, value); 278 * } 279 * ]| 280 * 281 * The handler need not set the state to the requested value. 282 * It could set it to any value at all, or take some other action. 283 * 284 * Params: 285 * value = the requested value for the state 286 * 287 * Since: 2.30 288 */ 289 void addOnChangeState(void delegate(Variant, SimpleAction) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 290 { 291 if ( "change-state" !in connectedSignals ) 292 { 293 Signals.connectData( 294 this, 295 "change-state", 296 cast(GCallback)&callBackChangeState, 297 cast(void*)this, 298 null, 299 connectFlags); 300 connectedSignals["change-state"] = 1; 301 } 302 onChangeStateListeners ~= dlg; 303 } 304 extern(C) static void callBackChangeState(GSimpleAction* simpleactionStruct, GVariant* value, SimpleAction _simpleaction) 305 { 306 foreach ( void delegate(Variant, SimpleAction) dlg; _simpleaction.onChangeStateListeners ) 307 { 308 dlg(new Variant(value), _simpleaction); 309 } 310 } 311 }