Copyright | Will Thompson, Iñaki García Etxebarria and Jonas Platte |
---|---|
License | LGPL-2.1 |
Maintainer | Iñaki García Etxebarria (garetxe@gmail.com) |
Safe Haskell | None |
Language | Haskell2010 |
Activatable widgets can be connected to a Action
and reflects
the state of its action. A Activatable
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 Activatable
; it is only
necessary to implement the Activatable
->sync_action_properties()
and Activatable
->update()
methods and chain up to the parent
implementation, however when introducing
a new Activatable
class; the Activatable
:related-action
and
Activatable
: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
activatableDoSetRelatedAction
and
activatableSyncActionProperties
at the appropriate times.
## A class fragment implementing Activatable
C code
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_sync_action_properties (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->sync_action_properties = foo_bar_activatable_sync_action_properties; } ... 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_sync_action_properties (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_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)); 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)); ... }
- newtype Activatable = Activatable (ManagedPtr Activatable)
- noActivatable :: Maybe Activatable
- class GObject o => IsActivatable o
- toActivatable :: IsActivatable o => o -> IO Activatable
- data ActivatableDoSetRelatedActionMethodInfo
- activatableDoSetRelatedAction :: (HasCallStack, MonadIO m, IsActivatable a, IsAction b) => a -> b -> m ()
- data ActivatableGetRelatedActionMethodInfo
- activatableGetRelatedAction :: (HasCallStack, MonadIO m, IsActivatable a) => a -> m Action
- data ActivatableGetUseActionAppearanceMethodInfo
- activatableGetUseActionAppearance :: (HasCallStack, MonadIO m, IsActivatable a) => a -> m Bool
- data ActivatableSetRelatedActionMethodInfo
- activatableSetRelatedAction :: (HasCallStack, MonadIO m, IsActivatable a, IsAction b) => a -> b -> m ()
- data ActivatableSetUseActionAppearanceMethodInfo
- activatableSetUseActionAppearance :: (HasCallStack, MonadIO m, IsActivatable a) => a -> Bool -> m ()
- data ActivatableSyncActionPropertiesMethodInfo
- activatableSyncActionProperties :: (HasCallStack, MonadIO m, IsActivatable a, IsAction b) => a -> Maybe b -> m ()
- data ActivatableRelatedActionPropertyInfo
- activatableRelatedAction :: AttrLabelProxy "relatedAction"
- constructActivatableRelatedAction :: (IsActivatable o, IsAction a) => a -> IO (GValueConstruct o)
- getActivatableRelatedAction :: (MonadIO m, IsActivatable o) => o -> m Action
- setActivatableRelatedAction :: (MonadIO m, IsActivatable o, IsAction a) => o -> a -> m ()
- data ActivatableUseActionAppearancePropertyInfo
- activatableUseActionAppearance :: AttrLabelProxy "useActionAppearance"
- constructActivatableUseActionAppearance :: IsActivatable o => Bool -> IO (GValueConstruct o)
- getActivatableUseActionAppearance :: (MonadIO m, IsActivatable o) => o -> m Bool
- setActivatableUseActionAppearance :: (MonadIO m, IsActivatable o) => o -> Bool -> m ()
Exported types
newtype Activatable Source #
GObject Activatable Source # | |
IsObject Activatable Source # | |
IsActivatable Activatable Source # | |
((~) * info (ResolveActivatableMethod t Activatable), MethodInfo * info Activatable p) => IsLabel t (Activatable -> p) Source # | |
((~) * info (ResolveActivatableMethod t Activatable), MethodInfo * info Activatable p) => IsLabelProxy t (Activatable -> p) Source # | |
HasAttributeList * Activatable Source # | |
type AttributeList Activatable Source # | |
type SignalList Activatable Source # | |
class GObject o => IsActivatable o Source #
toActivatable :: IsActivatable o => o -> IO Activatable Source #
Methods
doSetRelatedAction
data ActivatableDoSetRelatedActionMethodInfo Source #
((~) * signature (b -> m ()), MonadIO m, IsActivatable a, IsAction b) => MethodInfo * ActivatableDoSetRelatedActionMethodInfo a signature Source # | |
activatableDoSetRelatedAction Source #
:: (HasCallStack, MonadIO m, IsActivatable a, IsAction b) | |
=> a |
|
-> b |
|
-> m () |
Deprecated: (Since version 3.10)
This is a utility function for Activatable
implementors.
When implementing Activatable
you must call this when
handling changes of the Activatable
:related-action
, and
you must also use this to break references in Object
->dispose()
.
This function adds a reference to the currently set related
action for you, it also makes sure the Activatable
->update()
method is called when the related Action
properties change
and registers to the action’s proxy list.
Be careful to call this before setting the local copy of the 'GI.Gtk.Objects.Action.Action' property, since this function uses 'GI.Gtk.Interfaces.Activatable.activatableGetRelatedAction' to retrieve the previous action.
Since: 2.16
getRelatedAction
data ActivatableGetRelatedActionMethodInfo Source #
((~) * signature (m Action), MonadIO m, IsActivatable a) => MethodInfo * ActivatableGetRelatedActionMethodInfo a signature Source # | |
activatableGetRelatedAction Source #
:: (HasCallStack, MonadIO m, IsActivatable a) | |
=> a |
|
-> m Action | Returns: the related |
getUseActionAppearance
data ActivatableGetUseActionAppearanceMethodInfo Source #
((~) * signature (m Bool), MonadIO m, IsActivatable a) => MethodInfo * ActivatableGetUseActionAppearanceMethodInfo a signature Source # | |
activatableGetUseActionAppearance Source #
:: (HasCallStack, MonadIO m, IsActivatable a) | |
=> a |
|
-> m Bool | Returns: whether |
Deprecated: (Since version 3.10)
Gets whether this activatable should reset its layout and appearance when setting the related action or when the action changes appearance.
Since: 2.16
setRelatedAction
data ActivatableSetRelatedActionMethodInfo Source #
((~) * signature (b -> m ()), MonadIO m, IsActivatable a, IsAction b) => MethodInfo * ActivatableSetRelatedActionMethodInfo a signature Source # | |
activatableSetRelatedAction Source #
:: (HasCallStack, MonadIO m, IsActivatable a, IsAction b) | |
=> a |
|
-> b |
|
-> m () |
Deprecated: (Since version 3.10)
Sets the related action on the activatable
object.
'GI.Gtk.Interfaces.Activatable.Activatable' implementors need to handle the 'GI.Gtk.Interfaces.Activatable.Activatable':@/related-action/@ property and call 'GI.Gtk.Interfaces.Activatable.activatableDoSetRelatedAction' when it changes.
Since: 2.16
setUseActionAppearance
data ActivatableSetUseActionAppearanceMethodInfo Source #
((~) * signature (Bool -> m ()), MonadIO m, IsActivatable a) => MethodInfo * ActivatableSetUseActionAppearanceMethodInfo a signature Source # | |
activatableSetUseActionAppearance Source #
:: (HasCallStack, MonadIO m, IsActivatable a) | |
=> a |
|
-> Bool |
|
-> m () |
Deprecated: (Since version 3.10)
Sets whether this activatable should reset its layout and appearance when setting the related action or when the action changes appearance
'GI.Gtk.Interfaces.Activatable.Activatable' implementors need to handle the 'GI.Gtk.Interfaces.Activatable.Activatable':@/use-action-appearance/@ property and call 'GI.Gtk.Interfaces.Activatable.activatableSyncActionProperties' to update /@activatable@/ if needed.
Since: 2.16
syncActionProperties
data ActivatableSyncActionPropertiesMethodInfo Source #
((~) * signature (Maybe b -> m ()), MonadIO m, IsActivatable a, IsAction b) => MethodInfo * ActivatableSyncActionPropertiesMethodInfo a signature Source # | |
activatableSyncActionProperties Source #
:: (HasCallStack, MonadIO m, IsActivatable a, IsAction b) | |
=> a |
|
-> Maybe b | |
-> m () |
Deprecated: (Since version 3.10)
This is called to update the activatable completely, this is called
internally when the Activatable
:related-action
property is set
or unset and by the implementing class when
Activatable
:use-action-appearance
changes.
Since: 2.16
Properties
relatedAction
data ActivatableRelatedActionPropertyInfo Source #
activatableRelatedAction :: AttrLabelProxy "relatedAction" Source #
constructActivatableRelatedAction :: (IsActivatable o, IsAction a) => a -> IO (GValueConstruct o) Source #
getActivatableRelatedAction :: (MonadIO m, IsActivatable o) => o -> m Action Source #
setActivatableRelatedAction :: (MonadIO m, IsActivatable o, IsAction a) => o -> a -> m () Source #
useActionAppearance
data ActivatableUseActionAppearancePropertyInfo Source #
activatableUseActionAppearance :: AttrLabelProxy "useActionAppearance" Source #
constructActivatableUseActionAppearance :: IsActivatable o => Bool -> IO (GValueConstruct o) Source #
getActivatableUseActionAppearance :: (MonadIO m, IsActivatable o) => o -> m Bool Source #
setActivatableUseActionAppearance :: (MonadIO m, IsActivatable o) => o -> Bool -> m () Source #