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.ActionT; 26 27 public import gio.c.functions; 28 public import gio.c.types; 29 public import glib.ErrorG; 30 public import glib.GException; 31 public import glib.Str; 32 public import glib.Variant; 33 public import glib.VariantType; 34 public import gtkc.giotypes; 35 36 37 /** 38 * #GAction represents a single named action. 39 * 40 * The main interface to an action is that it can be activated with 41 * g_action_activate(). This results in the 'activate' signal being 42 * emitted. An activation has a #GVariant parameter (which may be 43 * %NULL). The correct type for the parameter is determined by a static 44 * parameter type (which is given at construction time). 45 * 46 * An action may optionally have a state, in which case the state may be 47 * set with g_action_change_state(). This call takes a #GVariant. The 48 * correct type for the state is determined by a static state type 49 * (which is given at construction time). 50 * 51 * The state may have a hint associated with it, specifying its valid 52 * range. 53 * 54 * #GAction is merely the interface to the concept of an action, as 55 * described above. Various implementations of actions exist, including 56 * #GSimpleAction. 57 * 58 * In all cases, the implementing class is responsible for storing the 59 * name of the action, the parameter type, the enabled state, the 60 * optional state type and the state and emitting the appropriate 61 * signals when these change. The implementor is responsible for filtering 62 * calls to g_action_activate() and g_action_change_state() for type 63 * safety and for the state being enabled. 64 * 65 * Probably the only useful thing to do with a #GAction is to put it 66 * inside of a #GSimpleActionGroup. 67 */ 68 public template ActionT(TStruct) 69 { 70 /** Get the main Gtk struct */ 71 public GAction* getActionStruct(bool transferOwnership = false) 72 { 73 if (transferOwnership) 74 ownedRef = false; 75 return cast(GAction*)getStruct(); 76 } 77 78 79 /** 80 * Activates the action. 81 * 82 * @parameter must be the correct type of parameter for the action (ie: 83 * the parameter type given at construction time). If the parameter 84 * type was %NULL then @parameter must also be %NULL. 85 * 86 * If the @parameter GVariant is floating, it is consumed. 87 * 88 * Params: 89 * parameter = the parameter to the activation 90 * 91 * Since: 2.28 92 */ 93 public void activate(Variant parameter) 94 { 95 g_action_activate(getActionStruct(), (parameter is null) ? null : parameter.getVariantStruct()); 96 } 97 98 /** 99 * Request for the state of @action to be changed to @value. 100 * 101 * The action must be stateful and @value must be of the correct type. 102 * See g_action_get_state_type(). 103 * 104 * This call merely requests a change. The action may refuse to change 105 * its state or may change its state to something other than @value. 106 * See g_action_get_state_hint(). 107 * 108 * If the @value GVariant is floating, it is consumed. 109 * 110 * Params: 111 * value = the new state 112 * 113 * Since: 2.30 114 */ 115 public void changeState(Variant value) 116 { 117 g_action_change_state(getActionStruct(), (value is null) ? null : value.getVariantStruct()); 118 } 119 120 /** 121 * Checks if @action is currently enabled. 122 * 123 * An action must be enabled in order to be activated or in order to 124 * have its state changed from outside callers. 125 * 126 * Returns: whether the action is enabled 127 * 128 * Since: 2.28 129 */ 130 public bool getEnabled() 131 { 132 return g_action_get_enabled(getActionStruct()) != 0; 133 } 134 135 /** 136 * Queries the name of @action. 137 * 138 * Returns: the name of the action 139 * 140 * Since: 2.28 141 */ 142 public string getName() 143 { 144 return Str.toString(g_action_get_name(getActionStruct())); 145 } 146 147 /** 148 * Queries the type of the parameter that must be given when activating 149 * @action. 150 * 151 * When activating the action using g_action_activate(), the #GVariant 152 * given to that function must be of the type returned by this function. 153 * 154 * In the case that this function returns %NULL, you must not give any 155 * #GVariant, but %NULL instead. 156 * 157 * Returns: the parameter type 158 * 159 * Since: 2.28 160 */ 161 public VariantType getParameterType() 162 { 163 auto __p = g_action_get_parameter_type(getActionStruct()); 164 165 if(__p is null) 166 { 167 return null; 168 } 169 170 return new VariantType(cast(GVariantType*) __p); 171 } 172 173 /** 174 * Queries the current state of @action. 175 * 176 * If the action is not stateful then %NULL will be returned. If the 177 * action is stateful then the type of the return value is the type 178 * given by g_action_get_state_type(). 179 * 180 * The return value (if non-%NULL) should be freed with 181 * g_variant_unref() when it is no longer required. 182 * 183 * Returns: the current state of the action 184 * 185 * Since: 2.28 186 */ 187 public Variant getState() 188 { 189 auto __p = g_action_get_state(getActionStruct()); 190 191 if(__p is null) 192 { 193 return null; 194 } 195 196 return new Variant(cast(GVariant*) __p, true); 197 } 198 199 /** 200 * Requests a hint about the valid range of values for the state of 201 * @action. 202 * 203 * If %NULL is returned it either means that the action is not stateful 204 * or that there is no hint about the valid range of values for the 205 * state of the action. 206 * 207 * If a #GVariant array is returned then each item in the array is a 208 * possible value for the state. If a #GVariant pair (ie: two-tuple) is 209 * returned then the tuple specifies the inclusive lower and upper bound 210 * of valid values for the state. 211 * 212 * In any case, the information is merely a hint. It may be possible to 213 * have a state value outside of the hinted range and setting a value 214 * within the range may fail. 215 * 216 * The return value (if non-%NULL) should be freed with 217 * g_variant_unref() when it is no longer required. 218 * 219 * Returns: the state range hint 220 * 221 * Since: 2.28 222 */ 223 public Variant getStateHint() 224 { 225 auto __p = g_action_get_state_hint(getActionStruct()); 226 227 if(__p is null) 228 { 229 return null; 230 } 231 232 return new Variant(cast(GVariant*) __p, true); 233 } 234 235 /** 236 * Queries the type of the state of @action. 237 * 238 * If the action is stateful (e.g. created with 239 * g_simple_action_new_stateful()) then this function returns the 240 * #GVariantType of the state. This is the type of the initial value 241 * given as the state. All calls to g_action_change_state() must give a 242 * #GVariant of this type and g_action_get_state() will return a 243 * #GVariant of the same type. 244 * 245 * If the action is not stateful (e.g. created with g_simple_action_new()) 246 * then this function will return %NULL. In that case, g_action_get_state() 247 * will return %NULL and you must not call g_action_change_state(). 248 * 249 * Returns: the state type, if the action is stateful 250 * 251 * Since: 2.28 252 */ 253 public VariantType getStateType() 254 { 255 auto __p = g_action_get_state_type(getActionStruct()); 256 257 if(__p is null) 258 { 259 return null; 260 } 261 262 return new VariantType(cast(GVariantType*) __p); 263 } 264 }