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.ActivatableIF; 26 27 private import gobject.ObjectG; 28 private import gtk.Action; 29 private 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 interface ActivatableIF{ 271 /** Get the main Gtk struct */ 272 public GtkActivatable* getActivatableStruct(bool transferOwnership = false); 273 274 /** the main Gtk struct as a void* */ 275 protected void* getStruct(); 276 277 278 /** */ 279 public static GType getType() 280 { 281 return gtk_activatable_get_type(); 282 } 283 284 /** 285 * This is a utility function for #GtkActivatable implementors. 286 * 287 * When implementing #GtkActivatable you must call this when 288 * handling changes of the #GtkActivatable:related-action, and 289 * you must also use this to break references in #GObject->dispose(). 290 * 291 * This function adds a reference to the currently set related 292 * action for you, it also makes sure the #GtkActivatable->update() 293 * method is called when the related #GtkAction properties change 294 * and registers to the action’s proxy list. 295 * 296 * > Be careful to call this before setting the local 297 * > copy of the #GtkAction property, since this function uses 298 * > gtk_activatable_get_related_action() to retrieve the 299 * > previous action. 300 * 301 * Params: 302 * action = the #GtkAction to set 303 * 304 * Since: 2.16 305 */ 306 public void doSetRelatedAction(Action action); 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 /** 318 * Gets whether this activatable should reset its layout 319 * and appearance when setting the related action or when 320 * the action changes appearance. 321 * 322 * Returns: whether @activatable uses its actions appearance. 323 * 324 * Since: 2.16 325 */ 326 public bool getUseActionAppearance(); 327 328 /** 329 * Sets the related action on the @activatable object. 330 * 331 * > #GtkActivatable implementors need to handle the #GtkActivatable:related-action 332 * > property and call gtk_activatable_do_set_related_action() when it changes. 333 * 334 * Params: 335 * action = the #GtkAction to set 336 * 337 * Since: 2.16 338 */ 339 public void setRelatedAction(Action action); 340 341 /** 342 * Sets whether this activatable should reset its layout and appearance 343 * when setting the related action or when the action changes appearance 344 * 345 * > #GtkActivatable implementors need to handle the 346 * > #GtkActivatable:use-action-appearance property and call 347 * > gtk_activatable_sync_action_properties() to update @activatable 348 * > if needed. 349 * 350 * Params: 351 * useAppearance = whether to use the actions appearance 352 * 353 * Since: 2.16 354 */ 355 public void setUseActionAppearance(bool useAppearance); 356 357 /** 358 * This is called to update the activatable completely, this is called 359 * internally when the #GtkActivatable:related-action property is set 360 * or unset and by the implementing class when 361 * #GtkActivatable:use-action-appearance changes. 362 * 363 * Params: 364 * action = the related #GtkAction or %NULL 365 * 366 * Since: 2.16 367 */ 368 public void syncActionProperties(Action action); 369 }