1
/* GIMP - The GNU Image Manipulation Program
2
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
5
* Copyright (C) 2005 Sven Neumann <sven@gimp.org>
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.
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.
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.
26
#include "gimpthrobber.h"
43
static void gimp_throbber_class_init (GimpThrobberClass *klass);
45
static void gimp_throbber_init (GimpThrobber *button);
47
static void gimp_throbber_set_property (GObject *object,
51
static void gimp_throbber_get_property (GObject *object,
55
static void gimp_throbber_finalize (GObject *object);
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);
62
static void gimp_throbber_construct_contents (GtkToolItem *tool_item);
65
static GObjectClass *parent_class = NULL;
66
static guint toolbutton_signals[LAST_SIGNAL] = { 0 };
69
#define GIMP_THROBBER_GET_PRIVATE(obj)(G_TYPE_INSTANCE_GET_PRIVATE ((obj), GIMP_TYPE_THROBBER, GimpThrobberPrivate))
72
struct _GimpThrobberPrivate
81
gimp_throbber_get_type (void)
83
static GtkType type = 0;
87
static const GTypeInfo type_info =
89
sizeof (GimpThrobberClass),
91
(GBaseFinalizeFunc) NULL,
92
(GClassInitFunc) gimp_throbber_class_init,
93
(GClassFinalizeFunc) NULL,
95
sizeof (GimpThrobber),
97
(GInstanceInitFunc) gimp_throbber_init,
100
type = g_type_register_static (GTK_TYPE_TOOL_ITEM,
108
gimp_throbber_class_init (GimpThrobberClass *klass)
110
GObjectClass *object_class = G_OBJECT_CLASS (klass);
111
GtkToolItemClass *tool_item_class = GTK_TOOL_ITEM_CLASS (klass);
113
parent_class = g_type_class_peek_parent (klass);
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;
119
tool_item_class->create_menu_proxy = gimp_throbber_create_menu_proxy;
120
tool_item_class->toolbar_reconfigured = gimp_throbber_toolbar_reconfigured;
122
g_object_class_install_property (object_class,
124
g_param_spec_string ("stock-id", NULL, NULL,
129
g_object_class_install_property (object_class,
131
g_param_spec_object ("image", NULL, NULL,
135
toolbutton_signals[CLICKED] =
136
g_signal_new ("clicked",
137
G_OBJECT_CLASS_TYPE (klass),
139
G_STRUCT_OFFSET (GimpThrobberClass, clicked),
141
g_cclosure_marshal_VOID__VOID,
144
g_type_class_add_private (object_class, sizeof (GimpThrobberPrivate));
148
gimp_throbber_init (GimpThrobber *button)
150
GtkToolItem *toolitem = GTK_TOOL_ITEM (button);
152
button->priv = GIMP_THROBBER_GET_PRIVATE (button);
154
gtk_tool_item_set_homogeneous (toolitem, TRUE);
156
button->priv->button = g_object_new (GTK_TYPE_BUTTON,
158
"focus-on-click", FALSE,
161
g_signal_connect_object (button->priv->button, "clicked",
162
G_CALLBACK (gimp_throbber_button_clicked),
165
gtk_container_add (GTK_CONTAINER (button), button->priv->button);
166
gtk_widget_show (button->priv->button);
170
gimp_throbber_construct_contents (GtkToolItem *tool_item)
172
GimpThrobber *button = GIMP_THROBBER (tool_item);
175
if (button->priv->image && button->priv->image->parent)
176
gtk_container_remove (GTK_CONTAINER (button->priv->image->parent),
177
button->priv->image);
179
if (GTK_BIN (button->priv->button)->child)
180
gtk_widget_destroy (GTK_BIN (button->priv->button)->child);
182
if (gtk_tool_item_get_toolbar_style (tool_item) == GTK_TOOLBAR_TEXT)
184
image = gtk_image_new_from_stock (button->priv->stock_id,
187
else if (button->priv->image)
189
image = button->priv->image;
193
image = gtk_image_new_from_stock (button->priv->stock_id,
194
GTK_ICON_SIZE_BUTTON);
197
gtk_container_add (GTK_CONTAINER (button->priv->button), image);
198
gtk_widget_show (image);
200
gtk_button_set_relief (GTK_BUTTON (button->priv->button),
201
gtk_tool_item_get_relief_style (tool_item));
203
gtk_widget_queue_resize (GTK_WIDGET (button));
207
gimp_throbber_set_property (GObject *object,
212
GimpThrobber *button = GIMP_THROBBER (object);
217
gimp_throbber_set_stock_id (button, g_value_get_string (value));
221
gimp_throbber_set_image (button, g_value_get_object (value));
225
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
231
gimp_throbber_get_property (GObject *object,
236
GimpThrobber *button = GIMP_THROBBER (object);
241
g_value_set_string (value, button->priv->stock_id);
245
g_value_set_object (value, button->priv->image);
249
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
255
gimp_throbber_finalize (GObject *object)
257
GimpThrobber *button = GIMP_THROBBER (object);
259
if (button->priv->stock_id)
260
g_free (button->priv->stock_id);
262
if (button->priv->image)
263
g_object_unref (button->priv->image);
265
parent_class->finalize (object);
269
gimp_throbber_button_clicked (GtkWidget *widget,
270
GimpThrobber *button)
272
g_signal_emit_by_name (button, "clicked");
276
gimp_throbber_create_menu_proxy (GtkToolItem *tool_item)
278
gtk_tool_item_set_proxy_menu_item (tool_item, "gimp-throbber-menu-id", NULL);
284
gimp_throbber_toolbar_reconfigured (GtkToolItem *tool_item)
286
gimp_throbber_construct_contents (tool_item);
290
gimp_throbber_new (const gchar *stock_id)
292
return g_object_new (GIMP_TYPE_THROBBER,
293
"stock-id", stock_id,
298
gimp_throbber_set_stock_id (GimpThrobber *button,
299
const gchar *stock_id)
303
g_return_if_fail (GIMP_IS_THROBBER (button));
305
old_stock_id = button->priv->stock_id;
307
button->priv->stock_id = g_strdup (stock_id);
308
gimp_throbber_construct_contents (GTK_TOOL_ITEM (button));
310
g_object_notify (G_OBJECT (button), "stock-id");
312
g_free (old_stock_id);
316
gimp_throbber_get_stock_id (GimpThrobber *button)
318
g_return_val_if_fail (GIMP_IS_THROBBER (button), NULL);
320
return button->priv->stock_id;
324
gimp_throbber_set_image (GimpThrobber *button,
327
g_return_if_fail (GIMP_IS_THROBBER (button));
328
g_return_if_fail (image == NULL || GTK_IS_IMAGE (image));
330
if (image != button->priv->image)
332
if (button->priv->image)
334
if (button->priv->image->parent)
335
gtk_container_remove (GTK_CONTAINER (button->priv->image->parent),
336
button->priv->image);
338
g_object_unref (button->priv->image);
342
g_object_ref_sink (image);
344
button->priv->image = image;
346
gimp_throbber_construct_contents (GTK_TOOL_ITEM (button));
348
g_object_notify (G_OBJECT (button), "image");
353
gimp_throbber_get_image (GimpThrobber *button)
355
g_return_val_if_fail (GIMP_IS_THROBBER (button), NULL);
357
return button->priv->image;