~ubuntu-branches/ubuntu/trusty/rgtk2/trusty

« back to all changes in this revision

Viewing changes to man/GtkActivatable.Rd

  • Committer: Bazaar Package Importer
  • Author(s): Dirk Eddelbuettel
  • Date: 2010-11-03 11:35:46 UTC
  • mfrom: (1.3.7 upstream)
  • Revision ID: james.westby@ubuntu.com-20101103113546-a7fi7jdxdebp0tw1
Tags: 2.20.1-1
* New upstream release

* debian/control: Set (Build-)Depends: to current R version
* debian/control: Set Standards-Version: to current version 

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
\alias{GtkActivatable}
 
2
\name{GtkActivatable}
 
3
\title{GtkActivatable}
 
4
\description{An interface for activatable widgets}
 
5
\section{Methods and Functions}{
 
6
\code{\link{gtkActivatableDoSetRelatedAction}(object, action)}\cr
 
7
\code{\link{gtkActivatableGetRelatedAction}(object)}\cr
 
8
\code{\link{gtkActivatableGetUseActionAppearance}(object)}\cr
 
9
\code{\link{gtkActivatableSyncActionProperties}(object, action = NULL)}\cr
 
10
\code{\link{gtkActivatableSetRelatedAction}(object, action)}\cr
 
11
\code{\link{gtkActivatableSetUseActionAppearance}(object, use.appearance)}\cr
 
12
}
 
13
\section{Hierarchy}{\preformatted{GInterface
 
14
   +----GtkActivatable}}
 
15
\section{Implementations}{GtkActivatable is implemented by
 
16
 \code{\link{GtkButton}},  \code{\link{GtkCheckButton}},  \code{\link{GtkCheckMenuItem}},  \code{\link{GtkColorButton}},  \code{\link{GtkFontButton}},  \code{\link{GtkImageMenuItem}},  \code{\link{GtkLinkButton}},  \code{\link{GtkMenuItem}},  \code{\link{GtkMenuToolButton}},  \code{\link{GtkOptionMenu}},  \code{\link{GtkRadioButton}},  \code{\link{GtkRadioMenuItem}},  \code{\link{GtkRadioToolButton}},  \code{\link{GtkRecentChooserMenu}},  \code{\link{GtkScaleButton}},  \code{\link{GtkSeparatorMenuItem}},  \code{\link{GtkSeparatorToolItem}},  \code{\link{GtkTearoffMenuItem}},  \code{\link{GtkToggleButton}},  \code{\link{GtkToggleToolButton}},  \code{\link{GtkToolButton}},  \code{\link{GtkToolItem}} and  \code{\link{GtkVolumeButton}}.}
 
17
\section{Detailed Description}{Activatable widgets can be connected to a \code{\link{GtkAction}} and reflects
 
18
the state of its action. A \code{\link{GtkActivatable}} can also provide feedback
 
19
through its action, as they are responsible for activating their
 
20
related actions.}
 
21
\section{Implementing GtkActivatable}{When extending a class that is already \code{\link{GtkActivatable}}; it is only
 
22
necessary to implement the \code{\link{GtkActivatable}}->\code{syncActionProperties()}
 
23
and \code{\link{GtkActivatable}}->\code{update()} methods and chain up to the parent
 
24
implementation, however when introducing
 
25
a new \code{\link{GtkActivatable}} class; the \verb{"related-action"} and
 
26
\verb{"use-action-appearance"} properties need to be handled by
 
27
the implementor. Handling these properties is mostly a matter of installing
 
28
the action pointer and boolean flag on your instance, and calling
 
29
\code{\link{gtkActivatableDoSetRelatedAction}} and
 
30
\code{\link{gtkActivatableSyncActionProperties}} at the appropriate times.
 
31
  
 
32
 \emph{A class fragment implementing   \code{\link{GtkActivatable}}}\preformatted{enum {
 
33
...
 
34
 
 
35
PROP_ACTIVATABLE_RELATED_ACTION,
 
36
PROP_ACTIVATABLE_USE_ACTION_APPEARANCE
 
37
}
 
38
 
 
39
struct _FooBarPrivate
 
40
{
 
41
 
 
42
  ...
 
43
 
 
44
  GtkAction      *action;
 
45
  gboolean        use_action_appearance;
 
46
};
 
47
 
 
48
...
 
49
 
 
50
static void foo_bar_activatable_interface_init         (GtkActivatableIface  *iface);
 
51
static void foo_bar_activatable_update                 (GtkActivatable       *activatable,
 
52
                                                           GtkAction            *action,
 
53
                                                           const gchar          *property_name);
 
54
static void foo_bar_activatable_sync_action_properties (GtkActivatable       *activatable,
 
55
                                                           GtkAction            *action);
 
56
...
 
57
 
 
58
 
 
59
static void
 
60
foo_bar_class_init (FooBarClass *klass)
 
61
{
 
62
 
 
63
  ...
 
64
 
 
65
  g_object_class_override_property (gobject_class, PROP_ACTIVATABLE_RELATED_ACTION, "related-action");
 
66
  g_object_class_override_property (gobject_class, PROP_ACTIVATABLE_USE_ACTION_APPEARANCE, "use-action-appearance");
 
67
 
 
68
  ...
 
69
}
 
70
 
 
71
 
 
72
static void
 
73
foo_bar_activatable_interface_init (GtkActivatableIface  *iface)
 
74
{
 
75
  iface->update = foo_bar_activatable_update;
 
76
  iface->sync_action_properties = foo_bar_activatable_sync_action_properties;
 
77
}
 
78
 
 
79
... Break the reference using gtk_activatable_do_set_related_action()...
 
80
 
 
81
static void 
 
82
foo_bar_dispose (GObject *object)
 
83
{
 
84
  FooBar *bar = FOO_BAR (object);
 
85
  FooBarPrivate *priv = FOO_BAR_GET_PRIVATE (bar);
 
86
 
 
87
  ...
 
88
 
 
89
  if (priv->action)
 
90
    {
 
91
      gtk_activatable_do_set_related_action (GTK_ACTIVATABLE (bar), NULL);
 
92
      priv->action = NULL;
 
93
    }
 
94
  G_OBJECT_CLASS (foo_bar_parent_class)->dispose (object);
 
95
}
 
96
 
 
97
... Handle the "related-action" and "use-action-appearance" properties ...
 
98
 
 
99
static void
 
100
foo_bar_set_property (GObject         *object,
 
101
                      guint            prop_id,
 
102
                      const GValue    *value,
 
103
                      GParamSpec      *pspec)
 
104
{
 
105
  FooBar *bar = FOO_BAR (object);
 
106
  FooBarPrivate *priv = FOO_BAR_GET_PRIVATE (bar);
 
107
 
 
108
  switch (prop_id)
 
109
    {
 
110
 
 
111
      ...
 
112
 
 
113
    case PROP_ACTIVATABLE_RELATED_ACTION:
 
114
      foo_bar_set_related_action (bar, g_value_get_object (value));
 
115
      break;
 
116
    case PROP_ACTIVATABLE_USE_ACTION_APPEARANCE:
 
117
      foo_bar_set_use_action_appearance (bar, g_value_get_boolean (value));
 
118
      break;
 
119
    default:
 
120
      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
 
121
      break;
 
122
    }
 
123
}
 
124
 
 
125
static void
 
126
foo_bar_get_property (GObject         *object,
 
127
                         guint            prop_id,
 
128
                         GValue          *value,
 
129
                         GParamSpec      *pspec)
 
130
{
 
131
  FooBar *bar = FOO_BAR (object);
 
132
  FooBarPrivate *priv = FOO_BAR_GET_PRIVATE (bar);
 
133
 
 
134
  switch (prop_id)
 
135
    { 
 
136
 
 
137
      ...
 
138
 
 
139
    case PROP_ACTIVATABLE_RELATED_ACTION:
 
140
      g_value_set_object (value, priv->action);
 
141
      break;
 
142
    case PROP_ACTIVATABLE_USE_ACTION_APPEARANCE:
 
143
      g_value_set_boolean (value, priv->use_action_appearance);
 
144
      break;
 
145
    default:
 
146
      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
 
147
      break;
 
148
    }
 
149
}
 
150
 
 
151
 
 
152
static void
 
153
foo_bar_set_use_action_appearance (FooBar   *bar, 
 
154
                                   gboolean  use_appearance)
 
155
{
 
156
  FooBarPrivate *priv = FOO_BAR_GET_PRIVATE (bar);
 
157
 
 
158
  if (priv->use_action_appearance != use_appearance)
 
159
    {
 
160
      priv->use_action_appearance = use_appearance;
 
161
      
 
162
      gtk_activatable_sync_action_properties (GTK_ACTIVATABLE (bar), priv->action);
 
163
    }
 
164
}
 
165
 
 
166
... call gtk_activatable_do_set_related_action() and then assign the action pointer, 
 
167
no need to reference the action here since gtk_activatable_do_set_related_action() already 
 
168
holds a reference here for you...
 
169
static void
 
170
foo_bar_set_related_action (FooBar    *bar, 
 
171
                            GtkAction *action)
 
172
{
 
173
  FooBarPrivate *priv = FOO_BAR_GET_PRIVATE (bar);
 
174
 
 
175
  if (priv->action == action)
 
176
    return;
 
177
 
 
178
  gtk_activatable_do_set_related_action (GTK_ACTIVATABLE (bar), action);
 
179
 
 
180
  priv->action = action;
 
181
}
 
182
 
 
183
... Selectively reset and update activatable depending on the use-action-appearance property ...
 
184
static void
 
185
gtk_button_activatable_sync_action_properties (GtkActivatable       *activatable,
 
186
                                                  GtkAction            *action)
 
187
{
 
188
  GtkButtonPrivate *priv = GTK_BUTTON_GET_PRIVATE (activatable);
 
189
 
 
190
  if (!action)
 
191
    return;
 
192
 
 
193
  if (gtk_action_is_visible (action))
 
194
    gtk_widget_show (GTK_WIDGET (activatable));
 
195
  else
 
196
    gtk_widget_hide (GTK_WIDGET (activatable));
 
197
  
 
198
  gtk_widget_set_sensitive (GTK_WIDGET (activatable), gtk_action_is_sensitive (action));
 
199
 
 
200
  ...
 
201
  
 
202
  if (priv->use_action_appearance)
 
203
    {
 
204
      if (gtk_action_get_stock_id (action))
 
205
        foo_bar_set_stock (button, gtk_action_get_stock_id (action));
 
206
      else if (gtk_action_get_label (action))
 
207
        foo_bar_set_label (button, gtk_action_get_label (action));
 
208
 
 
209
      ...
 
210
 
 
211
    }
 
212
}
 
213
 
 
214
static void 
 
215
foo_bar_activatable_update (GtkActivatable       *activatable,
 
216
                               GtkAction            *action,
 
217
                               const gchar          *property_name)
 
218
{
 
219
  FooBarPrivate *priv = FOO_BAR_GET_PRIVATE (activatable);
 
220
 
 
221
  if (strcmp (property_name, "visible") == 0)
 
222
    {
 
223
      if (gtk_action_is_visible (action))
 
224
        gtk_widget_show (GTK_WIDGET (activatable));
 
225
      else
 
226
        gtk_widget_hide (GTK_WIDGET (activatable));
 
227
    }
 
228
  else if (strcmp (property_name, "sensitive") == 0)
 
229
    gtk_widget_set_sensitive (GTK_WIDGET (activatable), gtk_action_is_sensitive (action));
 
230
 
 
231
  ...
 
232
 
 
233
  if (!priv->use_action_appearance)
 
234
    return;
 
235
 
 
236
  if (strcmp (property_name, "stock-id") == 0)
 
237
    foo_bar_set_stock (button, gtk_action_get_stock_id (action));
 
238
  else if (strcmp (property_name, "label") == 0)
 
239
    foo_bar_set_label (button, gtk_action_get_label (action));
 
240
 
 
241
  ...
 
242
}
 
243
}}
 
244
\section{Structures}{\describe{\item{\verb{GtkActivatable}}{
 
245
\emph{undocumented
 
246
}
 
247
 
 
248
}}}
 
249
\section{Properties}{\describe{
 
250
\item{\verb{related-action} [\code{\link{GtkAction}} : *            : Read / Write]}{
 
251
 
 
252
The action that this activatable will activate and receive
 
253
updates from for various states and possibly appearance.
 
254
  \strong{PLEASE NOTE:} \code{\link{GtkActivatable}} implementors need to handle the this property and
 
255
call \code{\link{gtkActivatableDoSetRelatedAction}} when it changes.  Since 2.16
 
256
 
 
257
}
 
258
\item{\verb{use-action-appearance} [logical : Read / Write]}{
 
259
 
 
260
Whether this activatable should reset its layout
 
261
and appearance when setting the related action or when
 
262
the action changes appearance.
 
263
  
 
264
See the \code{\link{GtkAction}} documentation directly to find which properties
 
265
should be ignored by the \code{\link{GtkActivatable}} when this property is \code{FALSE}.
 
266
  \strong{PLEASE NOTE:} \code{\link{GtkActivatable}} implementors need to handle this property
 
267
and call \code{\link{gtkActivatableSyncActionProperties}} on the activatable
 
268
widget when it changes.  Default value: TRUE  Since 2.16
 
269
 
 
270
}
 
271
}}
 
272
\references{\url{http://library.gnome.org/devel//gtk/GtkActivatable.html}}
 
273
\author{Derived by RGtkGen from GTK+ documentation}
 
274
\keyword{internal}