~ubuntu-branches/ubuntu/jaunty/gimp/jaunty-security

« back to all changes in this revision

Viewing changes to plug-ins/helpbrowser/gimpthrobber.c

  • Committer: Bazaar Package Importer
  • Author(s): Daniel Holbach
  • Date: 2007-05-02 16:33:03 UTC
  • mfrom: (1.1.4 upstream)
  • Revision ID: james.westby@ubuntu.com-20070502163303-bvzhjzbpw8qglc4y
Tags: 2.3.16-1ubuntu1
* Resynchronized with Debian, remaining Ubuntu changes:
  - debian/rules: i18n magic.
* debian/control.in:
  - Maintainer: Ubuntu Core Developers <ubuntu-devel@lists.ubuntu.com>
* debian/patches/02_help-message.patch,
  debian/patches/03_gimp.desktop.in.in.patch,
  debian/patches/10_dont_show_wizard.patch: updated.
* debian/patches/04_composite-signedness.patch,
  debian/patches/05_add-letter-spacing.patch: dropped, used upstream.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* GIMP - The GNU Image Manipulation Program
 
2
 * Copyright (C) 1995 Spencer Kimball and Peter Mattis
 
3
 *
 
4
 * GimpThrobber
 
5
 * Copyright (C) 2005  Sven Neumann <sven@gimp.org>
 
6
 *
 
7
 * This program is free software; you can redistribute it and/or modify
 
8
 * it under the terms of the GNU General Public License as published by
 
9
 * the Free Software Foundation; either version 2 of the License, or
 
10
 * (at your option) any later version.
 
11
 *
 
12
 * This program is distributed in the hope that it will be useful,
 
13
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
14
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
15
 * GNU General Public License for more details.
 
16
 *
 
17
 * You should have received a copy of the GNU General Public License
 
18
 * along with this program; if not, write to the Free Software
 
19
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 
20
 */
 
21
 
 
22
#include "config.h"
 
23
 
 
24
#include <gtk/gtk.h>
 
25
 
 
26
#include "gimpthrobber.h"
 
27
 
 
28
 
 
29
enum
 
30
{
 
31
  CLICKED,
 
32
  LAST_SIGNAL
 
33
};
 
34
 
 
35
enum
 
36
{
 
37
  PROP_0,
 
38
  PROP_STOCK_ID,
 
39
  PROP_IMAGE
 
40
};
 
41
 
 
42
 
 
43
static void      gimp_throbber_class_init      (GimpThrobberClass *klass);
 
44
 
 
45
static void      gimp_throbber_init                 (GimpThrobber *button);
 
46
 
 
47
static void      gimp_throbber_set_property         (GObject      *object,
 
48
                                                     guint         prop_id,
 
49
                                                     const GValue *value,
 
50
                                                     GParamSpec   *pspec);
 
51
static void      gimp_throbber_get_property         (GObject      *object,
 
52
                                                     guint         prop_id,
 
53
                                                     GValue       *value,
 
54
                                                     GParamSpec   *pspec);
 
55
static void      gimp_throbber_finalize             (GObject      *object);
 
56
 
 
57
static gboolean  gimp_throbber_create_menu_proxy    (GtkToolItem  *tool_item);
 
58
static void      gimp_throbber_toolbar_reconfigured (GtkToolItem  *tool_item);
 
59
static void      gimp_throbber_button_clicked       (GtkWidget    *widget,
 
60
                                                     GimpThrobber *button);
 
61
 
 
62
static void      gimp_throbber_construct_contents   (GtkToolItem  *tool_item);
 
63
 
 
64
 
 
65
static GObjectClass *parent_class                    = NULL;
 
66
static guint         toolbutton_signals[LAST_SIGNAL] = { 0 };
 
67
 
 
68
 
 
69
#define GIMP_THROBBER_GET_PRIVATE(obj)(G_TYPE_INSTANCE_GET_PRIVATE ((obj), GIMP_TYPE_THROBBER, GimpThrobberPrivate))
 
70
 
 
71
 
 
72
struct _GimpThrobberPrivate
 
73
{
 
74
  GtkWidget *button;
 
75
  GtkWidget *image;
 
76
  gchar     *stock_id;
 
77
};
 
78
 
 
79
 
 
80
GType
 
81
gimp_throbber_get_type (void)
 
82
{
 
83
  static GtkType type = 0;
 
84
 
 
85
  if (!type)
 
86
    {
 
87
      static const GTypeInfo type_info =
 
88
        {
 
89
          sizeof (GimpThrobberClass),
 
90
          (GBaseInitFunc) NULL,
 
91
          (GBaseFinalizeFunc) NULL,
 
92
          (GClassInitFunc) gimp_throbber_class_init,
 
93
          (GClassFinalizeFunc) NULL,
 
94
          NULL,
 
95
          sizeof (GimpThrobber),
 
96
          0, /* n_preallocs */
 
97
          (GInstanceInitFunc) gimp_throbber_init,
 
98
        };
 
99
 
 
100
      type = g_type_register_static (GTK_TYPE_TOOL_ITEM,
 
101
                                     "GimpThrobber",
 
102
                                     &type_info, 0);
 
103
    }
 
104
  return type;
 
105
}
 
106
 
 
107
static void
 
108
gimp_throbber_class_init (GimpThrobberClass *klass)
 
109
{
 
110
  GObjectClass     *object_class    = G_OBJECT_CLASS (klass);
 
111
  GtkToolItemClass *tool_item_class = GTK_TOOL_ITEM_CLASS (klass);
 
112
 
 
113
  parent_class = g_type_class_peek_parent (klass);
 
114
 
 
115
  object_class->set_property = gimp_throbber_set_property;
 
116
  object_class->get_property = gimp_throbber_get_property;
 
117
  object_class->finalize     = gimp_throbber_finalize;
 
118
 
 
119
  tool_item_class->create_menu_proxy    = gimp_throbber_create_menu_proxy;
 
120
  tool_item_class->toolbar_reconfigured = gimp_throbber_toolbar_reconfigured;
 
121
 
 
122
  g_object_class_install_property (object_class,
 
123
                                   PROP_STOCK_ID,
 
124
                                   g_param_spec_string ("stock-id", NULL, NULL,
 
125
                                                        NULL,
 
126
                                                        G_PARAM_READWRITE |
 
127
                                                        G_PARAM_CONSTRUCT));
 
128
 
 
129
  g_object_class_install_property (object_class,
 
130
                                   PROP_IMAGE,
 
131
                                   g_param_spec_object ("image", NULL, NULL,
 
132
                                                        GTK_TYPE_IMAGE,
 
133
                                                        G_PARAM_READWRITE));
 
134
 
 
135
  toolbutton_signals[CLICKED] =
 
136
    g_signal_new ("clicked",
 
137
                  G_OBJECT_CLASS_TYPE (klass),
 
138
                  G_SIGNAL_RUN_FIRST,
 
139
                  G_STRUCT_OFFSET (GimpThrobberClass, clicked),
 
140
                  NULL, NULL,
 
141
                  g_cclosure_marshal_VOID__VOID,
 
142
                  G_TYPE_NONE, 0);
 
143
 
 
144
  g_type_class_add_private (object_class, sizeof (GimpThrobberPrivate));
 
145
}
 
146
 
 
147
static void
 
148
gimp_throbber_init (GimpThrobber *button)
 
149
{
 
150
  GtkToolItem *toolitem = GTK_TOOL_ITEM (button);
 
151
 
 
152
  button->priv = GIMP_THROBBER_GET_PRIVATE (button);
 
153
 
 
154
  gtk_tool_item_set_homogeneous (toolitem, TRUE);
 
155
 
 
156
  button->priv->button = g_object_new (GTK_TYPE_BUTTON,
 
157
                                       "yalign",         0.0,
 
158
                                       "focus-on-click", FALSE,
 
159
                                       NULL);
 
160
 
 
161
  g_signal_connect_object (button->priv->button, "clicked",
 
162
                           G_CALLBACK (gimp_throbber_button_clicked),
 
163
                           button, 0);
 
164
 
 
165
  gtk_container_add (GTK_CONTAINER (button), button->priv->button);
 
166
  gtk_widget_show (button->priv->button);
 
167
}
 
168
 
 
169
static void
 
170
gimp_throbber_construct_contents (GtkToolItem *tool_item)
 
171
{
 
172
  GimpThrobber *button = GIMP_THROBBER (tool_item);
 
173
  GtkWidget    *image;
 
174
 
 
175
  if (button->priv->image && button->priv->image->parent)
 
176
    gtk_container_remove (GTK_CONTAINER (button->priv->image->parent),
 
177
                          button->priv->image);
 
178
 
 
179
  if (GTK_BIN (button->priv->button)->child)
 
180
    gtk_widget_destroy (GTK_BIN (button->priv->button)->child);
 
181
 
 
182
  if (gtk_tool_item_get_toolbar_style (tool_item) == GTK_TOOLBAR_TEXT)
 
183
    {
 
184
      image = gtk_image_new_from_stock (button->priv->stock_id,
 
185
                                        GTK_ICON_SIZE_MENU);
 
186
    }
 
187
  else if (button->priv->image)
 
188
    {
 
189
      image = button->priv->image;
 
190
    }
 
191
  else
 
192
    {
 
193
      image = gtk_image_new_from_stock (button->priv->stock_id,
 
194
                                        GTK_ICON_SIZE_BUTTON);
 
195
    }
 
196
 
 
197
  gtk_container_add (GTK_CONTAINER (button->priv->button), image);
 
198
  gtk_widget_show (image);
 
199
 
 
200
  gtk_button_set_relief (GTK_BUTTON (button->priv->button),
 
201
                         gtk_tool_item_get_relief_style (tool_item));
 
202
 
 
203
  gtk_widget_queue_resize (GTK_WIDGET (button));
 
204
}
 
205
 
 
206
static void
 
207
gimp_throbber_set_property (GObject      *object,
 
208
                            guint         prop_id,
 
209
                            const GValue *value,
 
210
                            GParamSpec   *pspec)
 
211
{
 
212
  GimpThrobber *button = GIMP_THROBBER (object);
 
213
 
 
214
  switch (prop_id)
 
215
    {
 
216
    case PROP_STOCK_ID:
 
217
      gimp_throbber_set_stock_id (button, g_value_get_string (value));
 
218
      break;
 
219
 
 
220
    case PROP_IMAGE:
 
221
      gimp_throbber_set_image (button, g_value_get_object (value));
 
222
      break;
 
223
 
 
224
    default:
 
225
      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
 
226
      break;
 
227
    }
 
228
}
 
229
 
 
230
static void
 
231
gimp_throbber_get_property (GObject         *object,
 
232
                              guint            prop_id,
 
233
                              GValue          *value,
 
234
                              GParamSpec      *pspec)
 
235
{
 
236
  GimpThrobber *button = GIMP_THROBBER (object);
 
237
 
 
238
  switch (prop_id)
 
239
    {
 
240
    case PROP_STOCK_ID:
 
241
      g_value_set_string (value, button->priv->stock_id);
 
242
      break;
 
243
 
 
244
    case PROP_IMAGE:
 
245
      g_value_set_object (value, button->priv->image);
 
246
      break;
 
247
 
 
248
    default:
 
249
      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
 
250
      break;
 
251
    }
 
252
}
 
253
 
 
254
static void
 
255
gimp_throbber_finalize (GObject *object)
 
256
{
 
257
  GimpThrobber *button = GIMP_THROBBER (object);
 
258
 
 
259
  if (button->priv->stock_id)
 
260
    g_free (button->priv->stock_id);
 
261
 
 
262
  if (button->priv->image)
 
263
    g_object_unref (button->priv->image);
 
264
 
 
265
  parent_class->finalize (object);
 
266
}
 
267
 
 
268
static void
 
269
gimp_throbber_button_clicked (GtkWidget    *widget,
 
270
                              GimpThrobber *button)
 
271
{
 
272
  g_signal_emit_by_name (button, "clicked");
 
273
}
 
274
 
 
275
static gboolean
 
276
gimp_throbber_create_menu_proxy (GtkToolItem *tool_item)
 
277
{
 
278
  gtk_tool_item_set_proxy_menu_item (tool_item, "gimp-throbber-menu-id", NULL);
 
279
 
 
280
  return FALSE;
 
281
}
 
282
 
 
283
static void
 
284
gimp_throbber_toolbar_reconfigured (GtkToolItem *tool_item)
 
285
{
 
286
  gimp_throbber_construct_contents (tool_item);
 
287
}
 
288
 
 
289
GtkToolItem *
 
290
gimp_throbber_new (const gchar *stock_id)
 
291
{
 
292
  return g_object_new (GIMP_TYPE_THROBBER,
 
293
                       "stock-id", stock_id,
 
294
                       NULL);
 
295
}
 
296
 
 
297
void
 
298
gimp_throbber_set_stock_id (GimpThrobber *button,
 
299
                            const gchar  *stock_id)
 
300
{
 
301
  gchar *old_stock_id;
 
302
 
 
303
  g_return_if_fail (GIMP_IS_THROBBER (button));
 
304
 
 
305
  old_stock_id = button->priv->stock_id;
 
306
 
 
307
  button->priv->stock_id = g_strdup (stock_id);
 
308
  gimp_throbber_construct_contents (GTK_TOOL_ITEM (button));
 
309
 
 
310
  g_object_notify (G_OBJECT (button), "stock-id");
 
311
 
 
312
  g_free (old_stock_id);
 
313
}
 
314
 
 
315
const gchar *
 
316
gimp_throbber_get_stock_id (GimpThrobber *button)
 
317
{
 
318
  g_return_val_if_fail (GIMP_IS_THROBBER (button), NULL);
 
319
 
 
320
  return button->priv->stock_id;
 
321
}
 
322
 
 
323
void
 
324
gimp_throbber_set_image (GimpThrobber *button,
 
325
                         GtkWidget    *image)
 
326
{
 
327
  g_return_if_fail (GIMP_IS_THROBBER (button));
 
328
  g_return_if_fail (image == NULL || GTK_IS_IMAGE (image));
 
329
 
 
330
  if (image != button->priv->image)
 
331
    {
 
332
      if (button->priv->image)
 
333
        {
 
334
          if (button->priv->image->parent)
 
335
            gtk_container_remove (GTK_CONTAINER (button->priv->image->parent),
 
336
                                  button->priv->image);
 
337
 
 
338
          g_object_unref (button->priv->image);
 
339
        }
 
340
 
 
341
      if (image)
 
342
        g_object_ref_sink (image);
 
343
 
 
344
      button->priv->image = image;
 
345
 
 
346
      gimp_throbber_construct_contents (GTK_TOOL_ITEM (button));
 
347
 
 
348
      g_object_notify (G_OBJECT (button), "image");
 
349
    }
 
350
}
 
351
 
 
352
GtkWidget *
 
353
gimp_throbber_get_image (GimpThrobber *button)
 
354
{
 
355
  g_return_val_if_fail (GIMP_IS_THROBBER (button), NULL);
 
356
 
 
357
  return button->priv->image;
 
358
}