Interface
GtkActivatable
Description [src]
interface Gtk.Activatable : GObject.Object
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.
Implementing GtkActivatable
When extending a class that is already GtkActivatable; it is only
necessary to implement the GtkActivatable->sync_action_properties()
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_sync_action_properties() at the appropriate times.
A class fragment implementing GtkActivatable
enum{ ... PROP_ACTIVATABLE_RELATED_ACTION, PROP_ACTIVATABLE_USE_ACTION_APPEARANCE } struct_FooBarPrivate { ... GtkAction*action; gbooleanuse_action_appearance; }; ... staticvoidfoo_bar_activatable_interface_init(GtkActivatableIface*iface); staticvoidfoo_bar_activatable_update(GtkActivatable*activatable, GtkAction*action, constgchar*property_name); staticvoidfoo_bar_activatable_sync_action_properties(GtkActivatable*activatable, GtkAction*action); ... staticvoid 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"); ... } staticvoid foo_bar_activatable_interface_init(GtkActivatableIface*iface) { iface->update=foo_bar_activatable_update; iface->sync_action_properties=foo_bar_activatable_sync_action_properties; } ...Breakthereferenceusinggtk_activatable_do_set_related_action()... staticvoid 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); } ...Handlethe"related-action"and"use-action-appearance"properties... staticvoid foo_bar_set_property(GObject*object, guintprop_id, constGValue*value, GParamSpec*pspec) { FooBar*bar=FOO_BAR(object); FooBarPrivate*priv=FOO_BAR_GET_PRIVATE(bar); switch(prop_id) { ... casePROP_ACTIVATABLE_RELATED_ACTION: foo_bar_set_related_action(bar,g_value_get_object(value)); break; casePROP_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; } } staticvoid foo_bar_get_property(GObject*object, guintprop_id, GValue*value, GParamSpec*pspec) { FooBar*bar=FOO_BAR(object); FooBarPrivate*priv=FOO_BAR_GET_PRIVATE(bar); switch(prop_id) { ... casePROP_ACTIVATABLE_RELATED_ACTION: g_value_set_object(value,priv->action); break; casePROP_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; } } staticvoid foo_bar_set_use_action_appearance(FooBar*bar, gbooleanuse_appearance) { FooBarPrivate*priv=FOO_BAR_GET_PRIVATE(bar); if(priv->use_action_appearance!=use_appearance) { priv->use_action_appearance=use_appearance; gtk_activatable_sync_action_properties(GTK_ACTIVATABLE(bar),priv->action); } } ...callgtk_activatable_do_set_related_action()andthenassigntheactionpointer, noneedtoreferencetheactionheresincegtk_activatable_do_set_related_action()already holdsareferencehereforyou... staticvoid 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; } ...Selectivelyresetandupdateactivatabledependingontheuse-action-appearanceproperty... staticvoid gtk_button_activatable_sync_action_properties(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)); elseif(gtk_action_get_label(action)) foo_bar_set_label(button,gtk_action_get_label(action)); ... } } staticvoid foo_bar_activatable_update(GtkActivatable*activatable, GtkAction*action, constgchar*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)); } elseif(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)); elseif(strcmp(property_name,"label")==0) foo_bar_set_label(button,gtk_action_get_label(action)); ... }
Prerequisite
In order to implement Activatable, your type must inherit from.
Implementations
- GtkButton
- GtkCheckButton
- GtkCheckMenuItem
- GtkColorButton
- GtkFontButton
- GtkImageMenuItem
- GtkLinkButton
- GtkLockButton
- GtkMenuButton
- GtkMenuItem
- GtkMenuToolButton
- GtkModelButton
- GtkRadioButton
- GtkRadioMenuItem
- GtkRadioToolButton
- GtkRecentChooserMenu
- GtkScaleButton
- GtkSeparatorMenuItem
- GtkSeparatorToolItem
- GtkSwitch
- GtkTearoffMenuItem
- GtkToggleButton
- GtkToggleToolButton
- GtkToolButton
- GtkToolItem
- GtkVolumeButton
Instance methods
gtk_activatable_do_set_related_action
This is a utility function for GtkActivatable implementors.
deprecated: 3.10 since: 2.16
gtk_activatable_get_related_action
Gets the related GtkAction for activatable.
deprecated: 3.10 since: 2.16
gtk_activatable_get_use_action_appearance
Gets whether this activatable should reset its layout and appearance when setting the related action or when the action changes appearance.
deprecated: 3.10 since: 2.16
gtk_activatable_set_related_action
Sets the related action on the activatable object.
deprecated: 3.10 since: 2.16
gtk_activatable_set_use_action_appearance
Sets whether this activatable should reset its layout and appearance when setting the related action or when the action changes appearance.
deprecated: 3.10 since: 2.16
gtk_activatable_sync_action_properties
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.
deprecated: 3.10 since: 2.16
Properties
Gtk.Activatable:related-action
The action that this activatable will activate and receive updates from for various states and possibly appearance.
deprecated: 3.10 since: 2.16
Gtk.Activatable:use-action-appearance
Whether this activatable should reset its layout and appearance when setting the related action or when the action changes appearance.
deprecated: 3.10 since: 2.16
Interface structure
struct GtkActivatableIface {
void (* update) (
GtkActivatable* activatable,
GtkAction* action,
const gchar* property_name
);
void (* sync_action_properties) (
GtkActivatable* activatable,
GtkAction* action
);
}
This method can be called with a
NULLaction at times.
Interface members
update
void (* update) (
GtkActivatable* activatable,
GtkAction* action,
const gchar* property_name
)
Called to update the activatable when its related action’s properties change.
You must check the GtkActivatable:use-action-appearance property only apply action
properties that are meant to effect the appearance accordingly.
sync_action_properties
void (* sync_action_properties) (
GtkActivatable* activatable,
GtkAction* action
)
Called to update the activatable completely, this is called internally when
GtkActivatable:related-action property is set or unset and by the implementor when
GtkActivatable:use-action-appearance changes.
Virtual methods
Gtk.Activatable.sync_action_properties
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.
deprecated: 3.10 since: 2.16
Gtk.Activatable.update
Called to update the activatable when its related action’s properties change.
You must check the GtkActivatable:use-action-appearance property only apply action
properties that are meant to effect the appearance accordingly.