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 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 template ActivatableT(TStruct)
270 {
271 	/** Get the main Gtk struct */
272 	public GtkActivatable* getActivatableStruct()
273 	{
274 		return cast(GtkActivatable*)getStruct();
275 	}
276 
277 	/**
278 	 */
279 
280 	/**
281 	 * This is a utility function for #GtkActivatable implementors.
282 	 *
283 	 * When implementing #GtkActivatable you must call this when
284 	 * handling changes of the #GtkActivatable:related-action, and
285 	 * you must also use this to break references in #GObject->dispose().
286 	 *
287 	 * This function adds a reference to the currently set related
288 	 * action for you, it also makes sure the #GtkActivatable->update()
289 	 * method is called when the related #GtkAction properties change
290 	 * and registers to the action’s proxy list.
291 	 *
292 	 * > Be careful to call this before setting the local
293 	 * > copy of the #GtkAction property, since this function uses
294 	 * > gtk_activatable_get_related_action() to retrieve the
295 	 * > previous action.
296 	 *
297 	 * Params:
298 	 *     action = the #GtkAction to set
299 	 *
300 	 * Since: 2.16
301 	 */
302 	public void doSetRelatedAction(Action action)
303 	{
304 		gtk_activatable_do_set_related_action(getActivatableStruct(), (action is null) ? null : action.getActionStruct());
305 	}
306 
307 	/**
308 	 * Gets the related #GtkAction for @activatable.
309 	 *
310 	 * Return: the related #GtkAction if one is set.
311 	 *
312 	 * Since: 2.16
313 	 */
314 	public Action getRelatedAction()
315 	{
316 		auto p = gtk_activatable_get_related_action(getActivatableStruct());
317 		
318 		if(p is null)
319 		{
320 			return null;
321 		}
322 		
323 		return ObjectG.getDObject!(Action)(cast(GtkAction*) p);
324 	}
325 
326 	/**
327 	 * Gets whether this activatable should reset its layout
328 	 * and appearance when setting the related action or when
329 	 * the action changes appearance.
330 	 *
331 	 * Return: whether @activatable uses its actions appearance.
332 	 *
333 	 * Since: 2.16
334 	 */
335 	public bool getUseActionAppearance()
336 	{
337 		return gtk_activatable_get_use_action_appearance(getActivatableStruct()) != 0;
338 	}
339 
340 	/**
341 	 * Sets the related action on the @activatable object.
342 	 *
343 	 * > #GtkActivatable implementors need to handle the #GtkActivatable:related-action
344 	 * > property and call gtk_activatable_do_set_related_action() when it changes.
345 	 *
346 	 * Params:
347 	 *     action = the #GtkAction to set
348 	 *
349 	 * Since: 2.16
350 	 */
351 	public void setRelatedAction(Action action)
352 	{
353 		gtk_activatable_set_related_action(getActivatableStruct(), (action is null) ? null : action.getActionStruct());
354 	}
355 
356 	/**
357 	 * Sets whether this activatable should reset its layout and appearance
358 	 * when setting the related action or when the action changes appearance
359 	 *
360 	 * > #GtkActivatable implementors need to handle the
361 	 * > #GtkActivatable:use-action-appearance property and call
362 	 * > gtk_activatable_sync_action_properties() to update @activatable
363 	 * > if needed.
364 	 *
365 	 * Params:
366 	 *     useAppearance = whether to use the actions appearance
367 	 *
368 	 * Since: 2.16
369 	 */
370 	public void setUseActionAppearance(bool useAppearance)
371 	{
372 		gtk_activatable_set_use_action_appearance(getActivatableStruct(), useAppearance);
373 	}
374 
375 	/**
376 	 * This is called to update the activatable completely, this is called
377 	 * internally when the #GtkActivatable:related-action property is set
378 	 * or unset and by the implementing class when
379 	 * #GtkActivatable:use-action-appearance changes.
380 	 *
381 	 * Params:
382 	 *     action = the related #GtkAction or %NULL
383 	 *
384 	 * Since: 2.16
385 	 */
386 	public void syncActionProperties(Action action)
387 	{
388 		gtk_activatable_sync_action_properties(getActivatableStruct(), (action is null) ? null : action.getActionStruct());
389 	}
390 }