Commit bb72b647 authored by Matthias Clasen's avatar Matthias Clasen

i Bug 560228 – Add "action-controller" property to GtkWidgetClass

        Rework the way actions and proxies interact, to make the
        interaction less ad hoc, more extensible, and better suited
        for support in GUI builders like glade.

        To be used as a proxy, a widget must now implement the
        GtkActivatable interface, and GtkActivatable implementations
        are responsible for syncing their appearance with the action
        and for activating the action.

        All the widgets that are commonly used as proxies implement
        GtkActivatable now.

        Patch by Tristan van Berkom.

        * gtk/gtkactivatable.[hc]: The GtkActivatable interface.

        * gtk/gtkbutton.c:
        * gtk/gtktogglebutton.c:
        * gtk/gtktoolitem.c:
        * gtk/gtktoolbutton.c:
        * gtk/gtktoggletoolbutton.c:
        * gtk/gtkmenuitem.c:
        * gtk/gtkcheckmenuitem.c:
        * gtk/gtkimagemenuitem.c:
        * gtk/gtkradiomenuitem.c:
        * gtk/gtkrecentchooserprivate.h:
        * gtk/gtkrecentchooser.c:
        * gtk/gtkrecentchooserdefault.c:
        * gtk/gtkrecentchoosermenu.c: Implement GtkActivatable.
        * gtk/gtkaction.[hc]: Move appearance synchronization to
        GtkActivatable implementations.

        * gtk/gtkradioaction.c:
        * gtk/gtkrecentaction.c:
        * gtk/gtktoggleaction.c:
        * gtk/gtkactiongroup.c: Adapt.

        * gtk/gtk.h: Include gtkactivatable.h
        * gtk/gtk.symbols: Add new functions


svn path=/trunk/; revision=22195
parent acd40c45
2009-01-23 Matthias Clasen <mclasen@redhat.com>
Bug 560228 – Add "action-controller" property to GtkWidgetClass
Rework the way actions and proxies interact, to make the
interaction less ad hoc, more extensible, and better suited
for support in GUI builders like glade.
To be used as a proxy, a widget must now implement the
GtkActivatable interface, and GtkActivatable implementations
are responsible for syncing their appearance with the action
and for activating the action.
All the widgets that are commonly used as proxies implement
GtkActivatable now.
Patch by Tristan van Berkom.
* gtk/gtkactivatable.[hc]: The GtkActivatable interface.
* gtk/gtkbutton.c:
* gtk/gtktogglebutton.c:
* gtk/gtktoolitem.c:
* gtk/gtktoolbutton.c:
* gtk/gtktoggletoolbutton.c:
* gtk/gtkmenuitem.c:
* gtk/gtkcheckmenuitem.c:
* gtk/gtkimagemenuitem.c:
* gtk/gtkradiomenuitem.c:
* gtk/gtkrecentchooserprivate.h:
* gtk/gtkrecentchooser.c:
* gtk/gtkrecentchooserdefault.c:
* gtk/gtkrecentchoosermenu.c: Implement GtkActivatable.
* gtk/gtkaction.[hc]: Move appearance synchronization to
GtkActivatable implementations.
* gtk/gtkradioaction.c:
* gtk/gtkrecentaction.c:
* gtk/gtktoggleaction.c:
* gtk/gtkactiongroup.c: Adapt.
* gtk/gtk.h: Include gtkactivatable.h
* gtk/gtk.symbols: Add new functions
2009-01-23 Matthias Clasen <mclasen@redhat.com> 2009-01-23 Matthias Clasen <mclasen@redhat.com>
Bug 567124 – proposal to delay doing something related to Bug 567124 – proposal to delay doing something related to
......
2009-01-23 Matthias Clasen <mclasen@redhat.com>
* gtk/gtk-sections.txt: Add new GtkActivatable API
* gtk/gtk-docs.sgml: Include GtkActivatable section
* gtk.types: Add gtk_activatable_get_type
2009-01-23 Matthias Clasen <mclasen@redhat.com> 2009-01-23 Matthias Clasen <mclasen@redhat.com>
* gtk/gtk-sections.txt: Additions * gtk/gtk-sections.txt: Additions
......
...@@ -247,6 +247,7 @@ that is, GUI components such as #GtkButton or #GtkTextView. ...@@ -247,6 +247,7 @@ that is, GUI components such as #GtkButton or #GtkTextView.
<xi:include href="xml/gtktoggleaction.xml" /> <xi:include href="xml/gtktoggleaction.xml" />
<xi:include href="xml/gtkradioaction.xml" /> <xi:include href="xml/gtkradioaction.xml" />
<xi:include href="xml/gtkrecentaction.xml" /> <xi:include href="xml/gtkrecentaction.xml" />
<xi:include href="xml/gtkactivatable.xml" />
</chapter> </chapter>
<chapter id="SelectorWidgets"> <chapter id="SelectorWidgets">
......
...@@ -188,6 +188,8 @@ gtk_action_disconnect_proxy ...@@ -188,6 +188,8 @@ gtk_action_disconnect_proxy
gtk_action_get_proxies gtk_action_get_proxies
gtk_action_connect_accelerator gtk_action_connect_accelerator
gtk_action_disconnect_accelerator gtk_action_disconnect_accelerator
gtk_action_block_activate
gtk_action_unblock_activate
gtk_action_block_activate_from gtk_action_block_activate_from
gtk_action_unblock_activate_from gtk_action_unblock_activate_from
gtk_action_get_accel_path gtk_action_get_accel_path
...@@ -226,6 +228,19 @@ gtk_action_get_type ...@@ -226,6 +228,19 @@ gtk_action_get_type
GtkActionPrivate GtkActionPrivate
</SECTION> </SECTION>
<SECTION>
<FILE>gtkactivatable</FILE>
<TITLE>GtkActivatable</TITLE>
gtk_activatable_do_set_related_action
gtk_activatable_get_related_action
gtk_activatable_get_use_action_appearance
gtk_activatable_reset
gtk_activatable_set_related_action
gtk_activatable_set_use_action_appearance
<SUBSECTION Private>
gtk_activatable_get_type
</SECTION>
<SECTION> <SECTION>
<FILE>gtkactiongroup</FILE> <FILE>gtkactiongroup</FILE>
<TITLE>GtkActionGroup</TITLE> <TITLE>GtkActionGroup</TITLE>
......
...@@ -8,6 +8,7 @@ gtk_accel_map_get_type ...@@ -8,6 +8,7 @@ gtk_accel_map_get_type
gtk_accessible_get_type gtk_accessible_get_type
gtk_action_get_type gtk_action_get_type
gtk_action_group_get_type gtk_action_group_get_type
gtk_activatable_get_type
gtk_adjustment_get_type gtk_adjustment_get_type
gtk_alignment_get_type gtk_alignment_get_type
gtk_arrow_get_type gtk_arrow_get_type
......
...@@ -148,6 +148,7 @@ gtk_public_h_sources = \ ...@@ -148,6 +148,7 @@ gtk_public_h_sources = \
gtkaccessible.h \ gtkaccessible.h \
gtkaction.h \ gtkaction.h \
gtkactiongroup.h \ gtkactiongroup.h \
gtkactivatable.h \
gtkadjustment.h \ gtkadjustment.h \
gtkalignment.h \ gtkalignment.h \
gtkarrow.h \ gtkarrow.h \
...@@ -397,6 +398,7 @@ gtk_base_c_sources = \ ...@@ -397,6 +398,7 @@ gtk_base_c_sources = \
gtkaccessible.c \ gtkaccessible.c \
gtkaction.c \ gtkaction.c \
gtkactiongroup.c \ gtkactiongroup.c \
gtkactivatable.c \
gtkadjustment.c \ gtkadjustment.c \
gtkalignment.c \ gtkalignment.c \
gtkarrow.c \ gtkarrow.c \
......
...@@ -37,6 +37,7 @@ ...@@ -37,6 +37,7 @@
#include <gtk/gtkaccessible.h> #include <gtk/gtkaccessible.h>
#include <gtk/gtkaction.h> #include <gtk/gtkaction.h>
#include <gtk/gtkactiongroup.h> #include <gtk/gtkactiongroup.h>
#include <gtk/gtkactivatable.h>
#include <gtk/gtkadjustment.h> #include <gtk/gtkadjustment.h>
#include <gtk/gtkalignment.h> #include <gtk/gtkalignment.h>
#include <gtk/gtkarrow.h> #include <gtk/gtkarrow.h>
......
...@@ -144,49 +144,61 @@ gtk_accessible_get_type G_GNUC_CONST ...@@ -144,49 +144,61 @@ gtk_accessible_get_type G_GNUC_CONST
#if IN_HEADER(__GTK_ACTION_H__) #if IN_HEADER(__GTK_ACTION_H__)
#if IN_FILE(__GTK_ACTION_C__) #if IN_FILE(__GTK_ACTION_C__)
gtk_action_activate gtk_action_activate
gtk_action_block_activate
#ifndef GTK_DISABLE_DEPRECATED
gtk_action_block_activate_from gtk_action_block_activate_from
#endif
gtk_action_connect_accelerator gtk_action_connect_accelerator
#ifndef GTK_DISABLE_DEPRECATED
gtk_action_connect_proxy gtk_action_connect_proxy
#endif
gtk_action_create_icon gtk_action_create_icon
gtk_action_create_menu_item gtk_action_create_menu_item
gtk_action_create_tool_item gtk_action_create_tool_item
gtk_action_create_menu gtk_action_create_menu
gtk_action_disconnect_accelerator gtk_action_disconnect_accelerator
#ifndef GTK_DISABLE_DEPRECATED
gtk_action_disconnect_proxy gtk_action_disconnect_proxy
#endif
gtk_action_get_accel_closure gtk_action_get_accel_closure
gtk_action_get_accel_path gtk_action_get_accel_path
gtk_action_get_gicon
gtk_action_get_label
gtk_action_get_name gtk_action_get_name
gtk_action_get_proxies gtk_action_get_proxies
#ifndef GTK_DISABLE_DEPRECATED
gtk_widget_get_action gtk_widget_get_action
#endif
gtk_action_get_icon_name
gtk_action_get_is_important
gtk_action_get_sensitive gtk_action_get_sensitive
gtk_action_get_short_label
gtk_action_get_stock_id
gtk_action_get_tooltip
gtk_action_get_type G_GNUC_CONST gtk_action_get_type G_GNUC_CONST
gtk_action_get_visible gtk_action_get_visible
gtk_action_get_visible_horizontal
gtk_action_get_visible_vertical
gtk_action_is_sensitive gtk_action_is_sensitive
gtk_action_is_visible gtk_action_is_visible
gtk_action_new gtk_action_new
gtk_action_set_accel_group gtk_action_set_accel_group
gtk_action_set_accel_path gtk_action_set_accel_path
gtk_action_set_sensitive gtk_action_set_gicon
gtk_action_set_visible gtk_action_set_icon_name
gtk_action_unblock_activate_from gtk_action_set_is_important
gtk_action_set_label gtk_action_set_label
gtk_action_get_label gtk_action_set_sensitive
gtk_action_set_short_label gtk_action_set_short_label
gtk_action_get_short_label
gtk_action_set_tooltip
gtk_action_get_tooltip
gtk_action_set_stock_id gtk_action_set_stock_id
gtk_action_get_stock_id gtk_action_set_tooltip
gtk_action_set_gicon gtk_action_set_visible
gtk_action_get_gicon
gtk_action_set_icon_name
gtk_action_get_icon_name
gtk_action_set_visible_horizontal gtk_action_set_visible_horizontal
gtk_action_get_visible_horizontal
gtk_action_set_visible_vertical gtk_action_set_visible_vertical
gtk_action_get_visible_vertical gtk_action_unblock_activate
gtk_action_set_is_important #ifndef GTK_DISABLE_DEPRECATED
gtk_action_get_is_important gtk_action_unblock_activate_from
#endif
#endif #endif
#endif #endif
...@@ -216,6 +228,18 @@ gtk_action_group_translate_string ...@@ -216,6 +228,18 @@ gtk_action_group_translate_string
#endif #endif
#endif #endif
#if IN_HEADER(__GTK_ACTIVATABLE_H__)
#if IN_FILE(__GTK_ACTIVATABLE_C__)
gtk_activatable_do_set_related_action
gtk_activatable_get_related_action
gtk_activatable_get_type G_GNUC_CONST
gtk_activatable_get_use_action_appearance
gtk_activatable_reset
gtk_activatable_set_related_action
gtk_activatable_set_use_action_appearance
#endif
#endif
#if IN_HEADER(__GTK_ADJUSTMENT_H__) #if IN_HEADER(__GTK_ADJUSTMENT_H__)
#if IN_FILE(__GTK_ADJUSTMENT_C__) #if IN_FILE(__GTK_ADJUSTMENT_C__)
gtk_adjustment_changed gtk_adjustment_changed
......
This diff is collapsed.
...@@ -105,22 +105,33 @@ GtkWidget * gtk_action_create_icon (GtkAction *action, ...@@ -105,22 +105,33 @@ GtkWidget * gtk_action_create_icon (GtkAction *action,
GtkWidget * gtk_action_create_menu_item (GtkAction *action); GtkWidget * gtk_action_create_menu_item (GtkAction *action);
GtkWidget * gtk_action_create_tool_item (GtkAction *action); GtkWidget * gtk_action_create_tool_item (GtkAction *action);
GtkWidget * gtk_action_create_menu (GtkAction *action); GtkWidget * gtk_action_create_menu (GtkAction *action);
void gtk_action_connect_proxy (GtkAction *action,
GtkWidget *proxy);
void gtk_action_disconnect_proxy (GtkAction *action,
GtkWidget *proxy);
GSList * gtk_action_get_proxies (GtkAction *action); GSList * gtk_action_get_proxies (GtkAction *action);
GtkAction * gtk_widget_get_action (GtkWidget *widget);
void gtk_action_connect_accelerator (GtkAction *action); void gtk_action_connect_accelerator (GtkAction *action);
void gtk_action_disconnect_accelerator (GtkAction *action); void gtk_action_disconnect_accelerator (GtkAction *action);
G_CONST_RETURN gchar *gtk_action_get_accel_path (GtkAction *action); G_CONST_RETURN gchar *gtk_action_get_accel_path (GtkAction *action);
GClosure *gtk_action_get_accel_closure (GtkAction *action); GClosure *gtk_action_get_accel_closure (GtkAction *action);
/* protected ... for use by child actions */ #ifndef GTK_DISABLE_DEPRECATED
GtkAction *gtk_widget_get_action (GtkWidget *widget);
void gtk_action_connect_proxy (GtkAction *action,
GtkWidget *proxy);
void gtk_action_disconnect_proxy (GtkAction *action,
GtkWidget *proxy);
void gtk_action_block_activate_from (GtkAction *action, void gtk_action_block_activate_from (GtkAction *action,
GtkWidget *proxy); GtkWidget *proxy);
void gtk_action_unblock_activate_from (GtkAction *action, void gtk_action_unblock_activate_from (GtkAction *action,
GtkWidget *proxy); GtkWidget *proxy);
#endif /* GTK_DISABLE_DEPRECATED */
void gtk_action_block_activate (GtkAction *action);
void gtk_action_unblock_activate (GtkAction *action);
void _gtk_action_add_to_proxy_list (GtkAction *action,
GtkWidget *proxy);
void _gtk_action_remove_from_proxy_list(GtkAction *action,
GtkWidget *proxy);
/* protected ... for use by child actions */
void _gtk_action_emit_activate (GtkAction *action); void _gtk_action_emit_activate (GtkAction *action);
/* protected ... for use by action groups */ /* protected ... for use by action groups */
...@@ -128,8 +139,6 @@ void gtk_action_set_accel_path (GtkAction *action, ...@@ -128,8 +139,6 @@ void gtk_action_set_accel_path (GtkAction *action,
const gchar *accel_path); const gchar *accel_path);
void gtk_action_set_accel_group (GtkAction *action, void gtk_action_set_accel_group (GtkAction *action,
GtkAccelGroup *accel_group); GtkAccelGroup *accel_group);
void _gtk_action_sync_sensitive (GtkAction *action);
void _gtk_action_sync_visible (GtkAction *action);
void _gtk_action_sync_menu_visible (GtkAction *action, void _gtk_action_sync_menu_visible (GtkAction *action,
GtkWidget *proxy, GtkWidget *proxy,
gboolean empty); gboolean empty);
......
...@@ -626,8 +626,8 @@ cb_set_action_sensitivity (const gchar *name, ...@@ -626,8 +626,8 @@ cb_set_action_sensitivity (const gchar *name,
{ {
/* Minor optimization, the action_groups state only affects actions /* Minor optimization, the action_groups state only affects actions
* that are themselves sensitive */ * that are themselves sensitive */
if (gtk_action_get_sensitive (action)) g_object_notify (G_OBJECT (action), "sensitive");
_gtk_action_sync_sensitive (action);
} }
/** /**
...@@ -691,8 +691,7 @@ cb_set_action_visiblity (const gchar *name, ...@@ -691,8 +691,7 @@ cb_set_action_visiblity (const gchar *name,
{ {
/* Minor optimization, the action_groups state only affects actions /* Minor optimization, the action_groups state only affects actions
* that are themselves visible */ * that are themselves visible */
if (gtk_action_get_visible (action)) g_object_notify (G_OBJECT (action), "visible");
_gtk_action_sync_visible (action);
} }
/** /**
......
/* gtkactivatable.c
* Copyright (C) 2008 Tristan Van Berkom <tristan.van.berkom@gmail.com>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/
/**
* SECTION:gtk-activatable
* @Short_Description: An interface for activatable widgets.
*
* Activatable widgets can be connected to a #GtkAction and reflects
* the state of its action - a #GtkActivatable can also provide feedback
* through its action, as they are responsible for activating their
* related actions.
*
* <refsect2>
* <title>Implementing GtkActivatable</title>
* <para>
* When extending a class that is already #GtkActivatable; it is only
* necessary to implement the #GtkActivatable->reset() and #GtkActivatable->update()
* methods and chain up to the parent implementation, however when introducing
* a new #GtkActivatable class; the #GtkActivatable:related-action and
* #GtkActivatable:use-action-appearance properties need to be handled by
* the implementor. Handling these properties is mostly a matter of installing
* the action pointer and boolean flag on your instance, and calling
* gtk_activatable_do_set_related_action() and gtk_activatable_reset() at the
* appropriate times.
* </para>
* <example>
* <title>A class fragment implementing #GtkActivatable</title>
* <programlisting><![CDATA[
*
* enum {
* ...
*
* PROP_ACTIVATABLE_RELATED_ACTION,
* PROP_ACTIVATABLE_USE_ACTION_APPEARANCE
* }
*
* struct _FooBarPrivate
* {
*
* ...
*
* GtkAction *action;
* gboolean use_action_appearance;
* };
*
* ...
*
* static void foo_bar_activatable_interface_init (GtkActivatableIface *iface);
* static void foo_bar_activatable_update (GtkActivatable *activatable,
* GtkAction *action,
* const gchar *property_name);
* static void foo_bar_activatable_reset (GtkActivatable *activatable,
* GtkAction *action);
* ...
*
*
* static void
* foo_bar_class_init (FooBarClass *klass)
* {
*
* ...
*
* g_object_class_override_property (gobject_class, PROP_ACTIVATABLE_RELATED_ACTION, "related-action");
* g_object_class_override_property (gobject_class, PROP_ACTIVATABLE_USE_ACTION_APPEARANCE, "use-action-appearance");
*
* ...
* }
*
*
* static void
* foo_bar_activatable_interface_init (GtkActivatableIface *iface)
* {
* iface->update = foo_bar_activatable_update;
* iface->reset = foo_bar_activatable_reset;
* }
*
* ... Break the reference using gtk_activatable_do_set_related_action()...
*
* static void
* foo_bar_dispose (GObject *object)
* {
* FooBar *bar = FOO_BAR (object);
* FooBarPrivate *priv = FOO_BAR_GET_PRIVATE (bar);
*
* ...
*
* if (priv->action)
* {
* gtk_activatable_do_set_related_action (GTK_ACTIVATABLE (bar), NULL);
* priv->action = NULL;
* }
* G_OBJECT_CLASS (foo_bar_parent_class)->dispose (object);
* }
*
* ... Handle the "related-action" and "use-action-appearance" properties ...
*
* static void
* foo_bar_set_property (GObject *object,
* guint prop_id,
* const GValue *value,
* GParamSpec *pspec)
* {
* FooBar *bar = FOO_BAR (object);
* FooBarPrivate *priv = FOO_BAR_GET_PRIVATE (bar);
*
* switch (prop_id)
* {
*
* ...
*
* case PROP_ACTIVATABLE_RELATED_ACTION:
* foo_bar_set_related_action (bar, g_value_get_object (value));
* break;
* case PROP_ACTIVATABLE_USE_ACTION_APPEARANCE:
* foo_bar_set_use_action_appearance (bar, g_value_get_boolean (value));
* break;
* default:
* G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
* break;
* }
* }
*
* static void
* foo_bar_get_property (GObject *object,
* guint prop_id,
* GValue *value,
* GParamSpec *pspec)
* {
* FooBar *bar = FOO_BAR (object);
* FooBarPrivate *priv = FOO_BAR_GET_PRIVATE (bar);
*
* switch (prop_id)
* {
*
* ...
*
* case PROP_ACTIVATABLE_RELATED_ACTION:
* g_value_set_object (value, priv->action);
* break;
* case PROP_ACTIVATABLE_USE_ACTION_APPEARANCE:
* g_value_set_boolean (value, priv->use_action_appearance);
* break;
* default:
* G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
* break;
* }
* }
*
*
* static void
* foo_bar_set_use_action_appearance (FooBar *bar,
* gboolean use_appearance)
* {
* FooBarPrivate *priv = FOO_BAR_GET_PRIVATE (bar);
*
* if (priv->use_action_appearance != use_appearance)
* {
* priv->use_action_appearance = use_appearance;
*
* gtk_activatable_reset (GTK_ACTIVATABLE (bar), priv->action);
* }
* }
*
* ... call gtk_activatable_do_set_related_action() and then assign the action pointer,
* no need to reference the action here since gtk_activatable_do_set_related_action() already
* holds a reference here for you...
* static void
* foo_bar_set_related_action (FooBar *bar,
* GtkAction *action)
* {
* FooBarPrivate *priv = FOO_BAR_GET_PRIVATE (bar);
*
* if (priv->action == action)
* return;
*
* gtk_activatable_do_set_related_action (GTK_ACTIVATABLE (bar), action);
*
* priv->action = action;
* }
*
* ... Selectively reset and update activatable depending on the use-action-appearance property ...
* static void
* gtk_button_activatable_reset (GtkActivatable *activatable,
* GtkAction *action)
* {
* GtkButtonPrivate *priv = GTK_BUTTON_GET_PRIVATE (activatable);
*
* if (!action)
* return;
*
* if (gtk_action_is_visible (action))
* gtk_widget_show (GTK_WIDGET (activatable));
* else
* gtk_widget_hide (GTK_WIDGET (activatable));
*
* gtk_widget_set_sensitive (GTK_WIDGET (activatable), gtk_action_is_sensitive (action));
*
* ...
*
* if (priv->use_action_appearance)
* {
* if (gtk_action_get_stock_id (action))
* foo_bar_set_stock (button, gtk_action_get_stock_id (action));
* else if (gtk_action_get_label (action))
* foo_bar_set_label (button, gtk_action_get_label (action));
*
* ...
*
* }
* }
*
* static void
* foo_bar_activatable_update (GtkActivatable *activatable,
* GtkAction *action,
* const gchar *property_name)
* {
* FooBarPrivate *priv = FOO_BAR_GET_PRIVATE (activatable);
*
* if (strcmp (property_name, "visible") == 0)
* {
* if (gtk_action_is_visible (action))
* gtk_widget_show (GTK_WIDGET (activatable));
* else
* gtk_widget_hide (GTK_WIDGET (activatable));
* }
* else if (strcmp (property_name, "sensitive") == 0)
* gtk_widget_set_sensitive (GTK_WIDGET (activatable), gtk_action_is_sensitive (action));
*
* ...
*
* if (!priv->use_action_appearance)
* return;
*
* if (strcmp (property_name, "stock-id") == 0)
* foo_bar_set_stock (button, gtk_action_get_stock_id (action));
* else if (strcmp (property_name, "label") == 0)
* foo_bar_set_label (button, gtk_action_get_label (action));
*
* ...
* }]]></programlisting>
* </example>
*
*/
#include "config.h"
#include "gtkactivatable.h"
#include "gtkactiongroup.h"
#include "gtktypeutils.h"
#include "gtkprivate.h"
#include "gtkintl.h"
#include "gtkalias.h"
static void gtk_activatable_class_init (gpointer g_iface);
GType
gtk_activatable_get_type (void)
{
static GType activatable_type = 0;
if (!activatable_type)
activatable_type =
g_type_register_static_simple (G_TYPE_INTERFACE, I_("GtkActivatable"),
sizeof (GtkActivatableIface),
(GClassInitFunc) gtk_activatable_class_init,
0, NULL, 0);
return activatable_type;
}
static void
gtk_activatable_class_init (gpointer g_iface)
{
/**
* GtkActivatable:related-action:
*
* The action that this activatable will activate and receive
* updates from for various states and possibly appearance.
*
* <note><para>#GtkActivatable implementors need to handle the this property and
* call gtk_activatable_do_set_related_action() when it changes.</para></note>
*
* Since: 2.16
*/
g_object_interface_install_property (g_iface,
g_param_spec_object ("related-action",
P_("Related Action"),
P_("The action this activatable will activate and receive updates from"),
GTK_TYPE_ACTION,
GTK_PARAM_READWRITE));
/**
* GtkActivatable:use-action-appearance:
*
* Whether this activatable should reset its layout
* and appearance when setting the related action or when
* the action changes appearance.
*
* See the #GtkAction documentation directly to find which properties
* should be ignored by the #GtkActivatable when this property is %FALSE.
*
* <note><para>#GtkActivatable implementors need to handle this property
* and call gtk_activatable_reset() on the activatable widget when it changes.</para></note>
*
* Since: 2.16
*/
g_object_interface_install_property (g_iface,
g_param_spec_boolean ("use-action-appearance",
P_("Use Action Appearance"),
P_("Whether to use the related actions appearance properties"),
TRUE,
GTK_PARAM_READWRITE));
}
static void
gtk_activatable_update (GtkActivatable *activatable,
GtkAction *action,
const gchar *property_name)
{
GtkActivatableIface *iface;
g_return_if_fail (GTK_IS_ACTIVATABLE (activatable));
iface = GTK_ACTIVATABLE_GET_IFACE (activatable);
if (iface->update)
iface->update (activatable, action, property_name);
else
g_critical ("GtkActivatable->update() unimplemented for type %s",
g_type_name (G_OBJECT_TYPE (activatable)));
}
/**
* gtk_activatable_reset:
* @activatable: a #GtkActivatable
* @action: the related #GtkAction or %NULL
*
* This is called to update the activatable completely, this is called internally when
* the #GtkActivatable::related-action property is set or unset and by the implementing
* class when #GtkActivatable::use-action-appearance changes.
*
* Since: 2.16
**/
void
gtk_activatable_reset (GtkActivatable *activatable,
GtkAction *action)
{
GtkActivatableIface *iface;
g_return_if_fail (GTK_IS_ACTIVATABLE (activatable));
iface = GTK_ACTIVATABLE_GET_IFACE (activatable);
if (iface->reset)
iface->reset (activatable, action);
else
g_critical ("GtkActivatable->reset() unimplemented for type %s",
g_type_name (G_OBJECT_TYPE (activatable)));
}
/**
* gtk_activatable_set_related_action: