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