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 gtk.ActivatableT; 26 27 public import gobject.ObjectG; 28 public import gtk.Action; 29 public import gtk.c.functions; 30 public import gtk.c.types; 31 public import gtkc.gtktypes; 32 33 34 /** 35 * Activatable widgets can be connected to a #GtkAction and reflects 36 * the state of its action. A #GtkActivatable can also provide feedback 37 * through its action, as they are responsible for activating their 38 * related actions. 39 * 40 * # Implementing GtkActivatable 41 * 42 * When extending a class that is already #GtkActivatable; it is only 43 * necessary to implement the #GtkActivatable->sync_action_properties() 44 * and #GtkActivatable->update() methods and chain up to the parent 45 * implementation, however when introducing 46 * a new #GtkActivatable class; the #GtkActivatable:related-action and 47 * #GtkActivatable:use-action-appearance properties need to be handled by 48 * the implementor. Handling these properties is mostly a matter of installing 49 * the action pointer and boolean flag on your instance, and calling 50 * gtk_activatable_do_set_related_action() and 51 * gtk_activatable_sync_action_properties() at the appropriate times. 52 * 53 * ## A class fragment implementing #GtkActivatable 54 * 55 * |[<!-- language="C" --> 56 * 57 * enum { 58 * ... 59 * 60 * PROP_ACTIVATABLE_RELATED_ACTION, 61 * PROP_ACTIVATABLE_USE_ACTION_APPEARANCE 62 * } 63 * 64 * struct _FooBarPrivate 65 * { 66 * 67 * ... 68 * 69 * GtkAction *action; 70 * gboolean use_action_appearance; 71 * }; 72 * 73 * ... 74 * 75 * static void foo_bar_activatable_interface_init (GtkActivatableIface *iface); 76 * static void foo_bar_activatable_update (GtkActivatable *activatable, 77 * GtkAction *action, 78 * const gchar *property_name); 79 * static void foo_bar_activatable_sync_action_properties (GtkActivatable *activatable, 80 * GtkAction *action); 81 * ... 82 * 83 * 84 * static void 85 * foo_bar_class_init (FooBarClass *klass) 86 * { 87 * 88 * ... 89 * 90 * g_object_class_override_property (gobject_class, PROP_ACTIVATABLE_RELATED_ACTION, "related-action"); 91 * g_object_class_override_property (gobject_class, PROP_ACTIVATABLE_USE_ACTION_APPEARANCE, "use-action-appearance"); 92 * 93 * ... 94 * } 95 * 96 * 97 * static void 98 * foo_bar_activatable_interface_init (GtkActivatableIface *iface) 99 * { 100 * iface->update = foo_bar_activatable_update; 101 * iface->sync_action_properties = foo_bar_activatable_sync_action_properties; 102 * } 103 * 104 * ... Break the reference using gtk_activatable_do_set_related_action()... 105 * 106 * static void 107 * foo_bar_dispose (GObject *object) 108 * { 109 * FooBar *bar = FOO_BAR (object); 110 * FooBarPrivate *priv = FOO_BAR_GET_PRIVATE (bar); 111 * 112 * ... 113 * 114 * if (priv->action) 115 * { 116 * gtk_activatable_do_set_related_action (GTK_ACTIVATABLE (bar), NULL); 117 * priv->action = NULL; 118 * } 119 * G_OBJECT_CLASS (foo_bar_parent_class)->dispose (object); 120 * } 121 * 122 * ... Handle the “related-action” and “use-action-appearance” properties ... 123 * 124 * static void 125 * foo_bar_set_property (GObject *object, 126 * guint prop_id, 127 * const GValue *value, 128 * GParamSpec *pspec) 129 * { 130 * FooBar *bar = FOO_BAR (object); 131 * FooBarPrivate *priv = FOO_BAR_GET_PRIVATE (bar); 132 * 133 * switch (prop_id) 134 * { 135 * 136 * ... 137 * 138 * case PROP_ACTIVATABLE_RELATED_ACTION: 139 * foo_bar_set_related_action (bar, g_value_get_object (value)); 140 * break; 141 * case PROP_ACTIVATABLE_USE_ACTION_APPEARANCE: 142 * foo_bar_set_use_action_appearance (bar, g_value_get_boolean (value)); 143 * break; 144 * default: 145 * G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); 146 * break; 147 * } 148 * } 149 * 150 * static void 151 * foo_bar_get_property (GObject *object, 152 * guint prop_id, 153 * GValue *value, 154 * GParamSpec *pspec) 155 * { 156 * FooBar *bar = FOO_BAR (object); 157 * FooBarPrivate *priv = FOO_BAR_GET_PRIVATE (bar); 158 * 159 * switch (prop_id) 160 * { 161 * 162 * ... 163 * 164 * case PROP_ACTIVATABLE_RELATED_ACTION: 165 * g_value_set_object (value, priv->action); 166 * break; 167 * case PROP_ACTIVATABLE_USE_ACTION_APPEARANCE: 168 * g_value_set_boolean (value, priv->use_action_appearance); 169 * break; 170 * default: 171 * G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); 172 * break; 173 * } 174 * } 175 * 176 * 177 * static void 178 * foo_bar_set_use_action_appearance (FooBar *bar, 179 * gboolean use_appearance) 180 * { 181 * FooBarPrivate *priv = FOO_BAR_GET_PRIVATE (bar); 182 * 183 * if (priv->use_action_appearance != use_appearance) 184 * { 185 * priv->use_action_appearance = use_appearance; 186 * 187 * gtk_activatable_sync_action_properties (GTK_ACTIVATABLE (bar), priv->action); 188 * } 189 * } 190 * 191 * ... call gtk_activatable_do_set_related_action() and then assign the action pointer, 192 * no need to reference the action here since gtk_activatable_do_set_related_action() already 193 * holds a reference here for you... 194 * static void 195 * foo_bar_set_related_action (FooBar *bar, 196 * GtkAction *action) 197 * { 198 * FooBarPrivate *priv = FOO_BAR_GET_PRIVATE (bar); 199 * 200 * if (priv->action == action) 201 * return; 202 * 203 * gtk_activatable_do_set_related_action (GTK_ACTIVATABLE (bar), action); 204 * 205 * priv->action = action; 206 * } 207 * 208 * ... Selectively reset and update activatable depending on the use-action-appearance property ... 209 * static void 210 * gtk_button_activatable_sync_action_properties (GtkActivatable *activatable, 211 * GtkAction *action) 212 * { 213 * GtkButtonPrivate *priv = GTK_BUTTON_GET_PRIVATE (activatable); 214 * 215 * if (!action) 216 * return; 217 * 218 * if (gtk_action_is_visible (action)) 219 * gtk_widget_show (GTK_WIDGET (activatable)); 220 * else 221 * gtk_widget_hide (GTK_WIDGET (activatable)); 222 * 223 * gtk_widget_set_sensitive (GTK_WIDGET (activatable), gtk_action_is_sensitive (action)); 224 * 225 * ... 226 * 227 * if (priv->use_action_appearance) 228 * { 229 * if (gtk_action_get_stock_id (action)) 230 * foo_bar_set_stock (button, gtk_action_get_stock_id (action)); 231 * else if (gtk_action_get_label (action)) 232 * foo_bar_set_label (button, gtk_action_get_label (action)); 233 * 234 * ... 235 * 236 * } 237 * } 238 * 239 * static void 240 * foo_bar_activatable_update (GtkActivatable *activatable, 241 * GtkAction *action, 242 * const gchar *property_name) 243 * { 244 * FooBarPrivate *priv = FOO_BAR_GET_PRIVATE (activatable); 245 * 246 * if (strcmp (property_name, "visible") == 0) 247 * { 248 * if (gtk_action_is_visible (action)) 249 * gtk_widget_show (GTK_WIDGET (activatable)); 250 * else 251 * gtk_widget_hide (GTK_WIDGET (activatable)); 252 * } 253 * else if (strcmp (property_name, "sensitive") == 0) 254 * gtk_widget_set_sensitive (GTK_WIDGET (activatable), gtk_action_is_sensitive (action)); 255 * 256 * ... 257 * 258 * if (!priv->use_action_appearance) 259 * return; 260 * 261 * if (strcmp (property_name, "stock-id") == 0) 262 * foo_bar_set_stock (button, gtk_action_get_stock_id (action)); 263 * else if (strcmp (property_name, "label") == 0) 264 * foo_bar_set_label (button, gtk_action_get_label (action)); 265 * 266 * ... 267 * } 268 * ]| 269 */ 270 public template ActivatableT(TStruct) 271 { 272 /** Get the main Gtk struct */ 273 public GtkActivatable* getActivatableStruct(bool transferOwnership = false) 274 { 275 if (transferOwnership) 276 ownedRef = false; 277 return cast(GtkActivatable*)getStruct(); 278 } 279 280 281 /** 282 * This is a utility function for #GtkActivatable implementors. 283 * 284 * When implementing #GtkActivatable you must call this when 285 * handling changes of the #GtkActivatable:related-action, and 286 * you must also use this to break references in #GObject->dispose(). 287 * 288 * This function adds a reference to the currently set related 289 * action for you, it also makes sure the #GtkActivatable->update() 290 * method is called when the related #GtkAction properties change 291 * and registers to the action’s proxy list. 292 * 293 * > Be careful to call this before setting the local 294 * > copy of the #GtkAction property, since this function uses 295 * > gtk_activatable_get_related_action() to retrieve the 296 * > previous action. 297 * 298 * Params: 299 * action = the #GtkAction to set 300 * 301 * Since: 2.16 302 */ 303 public void doSetRelatedAction(Action action) 304 { 305 gtk_activatable_do_set_related_action(getActivatableStruct(), (action is null) ? null : action.getActionStruct()); 306 } 307 308 /** 309 * Gets the related #GtkAction for @activatable. 310 * 311 * Returns: the related #GtkAction if one is set. 312 * 313 * Since: 2.16 314 */ 315 public Action getRelatedAction() 316 { 317 auto p = gtk_activatable_get_related_action(getActivatableStruct()); 318 319 if(p is null) 320 { 321 return null; 322 } 323 324 return ObjectG.getDObject!(Action)(cast(GtkAction*) p); 325 } 326 327 /** 328 * Gets whether this activatable should reset its layout 329 * and appearance when setting the related action or when 330 * the action changes appearance. 331 * 332 * Returns: whether @activatable uses its actions appearance. 333 * 334 * Since: 2.16 335 */ 336 public bool getUseActionAppearance() 337 { 338 return gtk_activatable_get_use_action_appearance(getActivatableStruct()) != 0; 339 } 340 341 /** 342 * Sets the related action on the @activatable object. 343 * 344 * > #GtkActivatable implementors need to handle the #GtkActivatable:related-action 345 * > property and call gtk_activatable_do_set_related_action() when it changes. 346 * 347 * Params: 348 * action = the #GtkAction to set 349 * 350 * Since: 2.16 351 */ 352 public void setRelatedAction(Action action) 353 { 354 gtk_activatable_set_related_action(getActivatableStruct(), (action is null) ? null : action.getActionStruct()); 355 } 356 357 /** 358 * Sets whether this activatable should reset its layout and appearance 359 * when setting the related action or when the action changes appearance 360 * 361 * > #GtkActivatable implementors need to handle the 362 * > #GtkActivatable:use-action-appearance property and call 363 * > gtk_activatable_sync_action_properties() to update @activatable 364 * > if needed. 365 * 366 * Params: 367 * useAppearance = whether to use the actions appearance 368 * 369 * Since: 2.16 370 */ 371 public void setUseActionAppearance(bool useAppearance) 372 { 373 gtk_activatable_set_use_action_appearance(getActivatableStruct(), useAppearance); 374 } 375 376 /** 377 * This is called to update the activatable completely, this is called 378 * internally when the #GtkActivatable:related-action property is set 379 * or unset and by the implementing class when 380 * #GtkActivatable:use-action-appearance changes. 381 * 382 * Params: 383 * action = the related #GtkAction or %NULL 384 * 385 * Since: 2.16 386 */ 387 public void syncActionProperties(Action action) 388 { 389 gtk_activatable_sync_action_properties(getActivatableStruct(), (action is null) ? null : action.getActionStruct()); 390 } 391 }