ActivatableProtocol
public protocol ActivatableProtocol
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
(C Language Example):
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));
...
}
The ActivatableProtocol
protocol exposes the methods and properties of an underlying GtkActivatable
instance.
The default implementation of these can be found in the protocol extension below.
For a concrete class that implements these methods and properties, see Activatable
.
Alternatively, use ActivatableRef
as a lighweight, unowned
reference if you already have an instance you just want to use.
-
Untyped pointer to the underlying
GtkActivatable
instance.Declaration
Swift
var ptr: UnsafeMutableRawPointer! { get }
-
activatable_ptr
Default implementationTyped pointer to the underlying
GtkActivatable
instance.Default Implementation
Return the stored, untyped pointer as a typed pointer to the
GtkActivatable
instance.Declaration
Swift
var activatable_ptr: UnsafeMutablePointer<GtkActivatable>! { get }
-
Required Initialiser for types conforming to
ActivatableProtocol
Declaration
Swift
init(raw: UnsafeMutableRawPointer)
-
bind(property:
Extension methodto: _: flags: transformFrom: transformTo: ) Bind a
ActivatablePropertyName
source property to a given target object.Declaration
Swift
@discardableResult @inlinable func bind<Q, T>(property source_property: ActivatablePropertyName, to target: T, _ target_property: Q, flags f: BindingFlags = .default, transformFrom transform_from: @escaping GLibObject.ValueTransformer = { $0.transform(destValue: $1) }, transformTo transform_to: @escaping GLibObject.ValueTransformer = { $0.transform(destValue: $1) }) -> BindingRef! where Q : PropertyNameProtocol, T : ObjectProtocol
Parameters
source_property
the source property to bind
target
the target object to bind to
target_property
the target property to bind to
flags
the flags to pass to the
Binding
transform_from
ValueTransformer
to use for forward transformationtransform_to
ValueTransformer
to use for backwards transformationReturn Value
binding reference or
nil
in case of an error -
get(property:
Extension method) Get the value of a Activatable property
Declaration
Swift
@inlinable func get(property: ActivatablePropertyName) -> GLibObject.Value
Parameters
property
the property to get the value for
Return Value
the value of the named property
-
set(property:
Extension methodvalue: ) Set the value of a Activatable property. Note that this will only have an effect on properties that are writable and not construct-only!
Declaration
Swift
@inlinable func set(property: ActivatablePropertyName, value v: GLibObject.Value)
Parameters
property
the property to get the value for
Return Value
the value of the named property
-
doSetRelated(action:
Extension method) This is a utility function for
GtkActivatable
implementors.When implementing
GtkActivatable
you must call this when handling changes of theGtkActivatable:related-action
, and you must also use this to break references inGObject-
>dispose()
.This function adds a reference to the currently set related action for you, it also makes sure the
GtkActivatable-
>update()
method is called when the relatedGtkAction
properties change and registers to the action’s proxy list.> Be careful to call this before setting the local > copy of the
GtkAction
property, since this function uses >gtk_activatable_get_related_action()
to retrieve the > previous action.do_set_related_action is deprecated: This method is deprecated.
Declaration
Swift
@available(*, deprecated) @inlinable func doSetRelated<ActionT>(action: ActionT) where ActionT : ActionProtocol
-
getRelatedAction()
Extension methodGets the related
GtkAction
foractivatable
.get_related_action is deprecated: This method is deprecated.
Declaration
Swift
@available(*, deprecated) @inlinable func getRelatedAction() -> ActionRef!
-
getUseActionAppearance()
Extension methodGets whether this activatable should reset its layout and appearance when setting the related action or when the action changes appearance.
get_use_action_appearance is deprecated: This method is deprecated.
Declaration
Swift
@available(*, deprecated) @inlinable func getUseActionAppearance() -> Bool
-
setRelated(action:
Extension method) Sets the related action on the
activatable
object.>
GtkActivatable
implementors need to handle theGtkActivatable:related-action
> property and callgtk_activatable_do_set_related_action()
when it changes.set_related_action is deprecated: This method is deprecated.
Declaration
Swift
@available(*, deprecated) @inlinable func setRelated<ActionT>(action: ActionT) where ActionT : ActionProtocol
-
setUseActionAppearance(useAppearance:
Extension method) Sets whether this activatable should reset its layout and appearance when setting the related action or when the action changes appearance
>
GtkActivatable
implementors need to handle the >GtkActivatable:use-action-appearance
property and call >gtk_activatable_sync_action_properties()
to updateactivatable
> if needed.set_use_action_appearance is deprecated: This method is deprecated.
Declaration
Swift
@available(*, deprecated) @inlinable func setUseActionAppearance(useAppearance: Bool)
-
syncActionProperties(action:
Extension method) 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 whenGtkActivatable:use-action-appearance
changes.sync_action_properties is deprecated: This method is deprecated.
Declaration
Swift
@available(*, deprecated) @inlinable func syncActionProperties(action: ActionRef? = nil)
-
syncActionProperties(action:
Extension method) 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 whenGtkActivatable:use-action-appearance
changes.sync_action_properties is deprecated: This method is deprecated.
Declaration
Swift
@available(*, deprecated) @inlinable func syncActionProperties<ActionT>(action: ActionT?) where ActionT : ActionProtocol
-
relatedAction
Extension methodGets the related
GtkAction
foractivatable
.get_related_action is deprecated: This method is deprecated.
Declaration
Swift
@inlinable var relatedAction: ActionRef! { get nonmutating set }
-
useActionAppearance
Extension methodGets whether this activatable should reset its layout and appearance when setting the related action or when the action changes appearance.
get_use_action_appearance is deprecated: This method is deprecated.
Declaration
Swift
@inlinable var useActionAppearance: Bool { get nonmutating set }