1
/* LIBGIMP - The GIMP Library
2
* Copyright (C) 1995-1997 Peter Mattis and Spencer Kimball
5
* Copyright (C) 2002-2004 Sven Neumann <sven@gimp.org>
7
* This library is free software; you can redistribute it and/or
8
* modify it under the terms of the GNU Lesser General Public
9
* License as published by the Free Software Foundation; either
10
* version 2 of the License, or (at your option) any later version.
12
* This library 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 GNU
15
* Lesser General Public License for more details.
17
* You should have received a copy of the GNU Lesser General Public
18
* License along with this library; if not, write to the
19
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20
* Boston, MA 02111-1307, USA.
27
#include "libgimpbase/gimpbase.h"
29
#include "gimpwidgetstypes.h"
31
#include "gimpenumwidgets.h"
32
#include "gimpframe.h"
33
#include "gimphelpui.h"
37
* gimp_enum_radio_box_new:
38
* @enum_type: the #GType of an enum.
39
* @callback: a callback to connect to the "toggled" signal of each
40
* #GtkRadioButton that is created.
41
* @callback_data: data to pass to the @callback.
42
* @first_button: returns the first button in the created group.
44
* Creates a new group of #GtkRadioButtons representing the enum
45
* values. A group of radiobuttons is a good way to represent enums
46
* with up to three or four values. Often it is better to use a
47
* #GimpEnumComboBox instead.
49
* Return value: a new #GtkVBox holding a group of #GtkRadioButtons.
54
gimp_enum_radio_box_new (GType enum_type,
56
gpointer callback_data,
57
GtkWidget **first_button)
59
GEnumClass *enum_class;
62
g_return_val_if_fail (G_TYPE_IS_ENUM (enum_type), NULL);
64
enum_class = g_type_class_ref (enum_type);
66
vbox = gimp_enum_radio_box_new_with_range (enum_type,
69
callback, callback_data,
72
g_type_class_unref (enum_class);
78
* gimp_enum_radio_box_new_with_range:
81
* @enum_type: the #GType of an enum.
82
* @callback: a callback to connect to the "toggled" signal of each
83
* #GtkRadioButton that is created.
84
* @callback_data: data to pass to the @callback.
85
* @first_button: returns the first button in the created group.
87
* Just like gimp_enum_radio_box_new(), this function creates a group
88
* of radio buttons, but it allows to limit the range of available
91
* Return value: a new #GtkVBox holding a group of #GtkRadioButtons.
96
gimp_enum_radio_box_new_with_range (GType enum_type,
100
gpointer callback_data,
101
GtkWidget **first_button)
105
GEnumClass *enum_class;
107
GSList *group = NULL;
109
g_return_val_if_fail (G_TYPE_IS_ENUM (enum_type), NULL);
111
enum_class = g_type_class_ref (enum_type);
113
vbox = gtk_vbox_new (FALSE, 1);
114
g_object_weak_ref (G_OBJECT (vbox),
115
(GWeakNotify) g_type_class_unref, enum_class);
118
*first_button = NULL;
120
for (value = enum_class->values; value->value_name; value++)
124
if (value->value < minimum || value->value > maximum)
127
desc = gimp_enum_value_get_desc (enum_class, value);
129
button = gtk_radio_button_new_with_mnemonic (group, desc);
131
if (first_button && *first_button == NULL)
132
*first_button = button;
134
group = gtk_radio_button_get_group (GTK_RADIO_BUTTON (button));
135
gtk_box_pack_start (GTK_BOX (vbox), button, FALSE, FALSE, 0);
136
gtk_widget_show (button);
138
g_object_set_data (G_OBJECT (button), "gimp-item-data",
139
GINT_TO_POINTER (value->value));
142
g_signal_connect (button, "toggled",
151
* gimp_enum_radio_frame_new:
152
* @enum_type: the #GType of an enum.
153
* @label_widget: a widget to use as label for the frame that will
154
* hold the radio box.
155
* @callback: a callback to connect to the "toggled" signal of each
156
* #GtkRadioButton that is created.
157
* @callback_data: data to pass to the @callback.
158
* @first_button: returns the first button in the created group.
160
* Calls gimp_enum_radio_box_new() and puts the resulting vbox into a
163
* Return value: a new #GtkFrame holding a group of #GtkRadioButtons.
168
gimp_enum_radio_frame_new (GType enum_type,
169
GtkWidget *label_widget,
171
gpointer callback_data,
172
GtkWidget **first_button)
175
GtkWidget *radio_box;
177
g_return_val_if_fail (G_TYPE_IS_ENUM (enum_type), NULL);
178
g_return_val_if_fail (label_widget == NULL || GTK_IS_WIDGET (label_widget),
181
frame = gimp_frame_new (NULL);
185
gtk_frame_set_label_widget (GTK_FRAME (frame), label_widget);
186
gtk_widget_show (label_widget);
189
radio_box = gimp_enum_radio_box_new (enum_type,
190
callback, callback_data,
192
gtk_container_add (GTK_CONTAINER (frame), radio_box);
193
gtk_widget_show (radio_box);
199
* gimp_enum_radio_frame_new_with_range:
200
* @enum_type: the #GType of an enum.
203
* @label_widget: a widget to put into the frame that will hold the radio box.
204
* @callback: a callback to connect to the "toggled" signal of each
205
* #GtkRadioButton that is created.
206
* @callback_data: data to pass to the @callback.
207
* @first_button: returns the first button in the created group.
209
* Calls gimp_enum_radio_box_new_with_range() and puts the resulting
210
* vbox into a #GtkFrame.
212
* Return value: a new #GtkFrame holding a group of #GtkRadioButtons.
217
gimp_enum_radio_frame_new_with_range (GType enum_type,
220
GtkWidget *label_widget,
222
gpointer callback_data,
223
GtkWidget **first_button)
226
GtkWidget *radio_box;
228
g_return_val_if_fail (G_TYPE_IS_ENUM (enum_type), NULL);
229
g_return_val_if_fail (label_widget == NULL || GTK_IS_WIDGET (label_widget),
232
frame = gimp_frame_new (NULL);
236
gtk_frame_set_label_widget (GTK_FRAME (frame), label_widget);
237
gtk_widget_show (label_widget);
240
radio_box = gimp_enum_radio_box_new_with_range (enum_type,
243
callback, callback_data,
245
gtk_container_add (GTK_CONTAINER (frame), radio_box);
246
gtk_widget_show (radio_box);
253
* gimp_enum_stock_box_new:
254
* @enum_type: the #GType of an enum.
255
* @stock_prefix: the prefix of the group of stock ids to use.
257
* @callback: a callback to connect to the "toggled" signal of each
258
* #GtkRadioButton that is created.
259
* @callback_data: data to pass to the @callback.
260
* @first_button: returns the first button in the created group.
262
* Creates a horizontal box of radio buttons with stock icons. The
263
* stock_id for each icon is created by appending the enum_value's
264
* nick to the given @stock_prefix.
266
* Return value: a new #GtkHbox holding a group of #GtkRadioButtons.
271
gimp_enum_stock_box_new (GType enum_type,
272
const gchar *stock_prefix,
273
GtkIconSize icon_size,
275
gpointer callback_data,
276
GtkWidget **first_button)
278
GEnumClass *enum_class;
281
g_return_val_if_fail (G_TYPE_IS_ENUM (enum_type), NULL);
283
enum_class = g_type_class_ref (enum_type);
285
box = gimp_enum_stock_box_new_with_range (enum_type,
288
stock_prefix, icon_size,
289
callback, callback_data,
292
g_type_class_unref (enum_class);
298
* gimp_enum_stock_box_new_with_range:
299
* @enum_type: the #GType of an enum.
302
* @stock_prefix: the prefix of the group of stock ids to use.
304
* @callback: a callback to connect to the "toggled" signal of each
305
* #GtkRadioButton that is created.
306
* @callback_data: data to pass to the @callback.
307
* @first_button: returns the first button in the created group.
309
* Just like gimp_enum_stock_box_new(), this function creates a group
310
* of radio buttons, but it allows to limit the range of available
313
* Return value: a new #GtkHbox holding a group of #GtkRadioButtons.
318
gimp_enum_stock_box_new_with_range (GType enum_type,
321
const gchar *stock_prefix,
322
GtkIconSize icon_size,
324
gpointer callback_data,
325
GtkWidget **first_button)
330
GEnumClass *enum_class;
333
GSList *group = NULL;
335
g_return_val_if_fail (G_TYPE_IS_ENUM (enum_type), NULL);
336
g_return_val_if_fail (stock_prefix != NULL, NULL);
338
enum_class = g_type_class_ref (enum_type);
340
hbox = gtk_hbox_new (FALSE, 0);
341
g_object_weak_ref (G_OBJECT (hbox),
342
(GWeakNotify) g_type_class_unref, enum_class);
345
*first_button = NULL;
347
for (value = enum_class->values; value->value_name; value++)
349
if (value->value < minimum || value->value > maximum)
352
button = gtk_radio_button_new (group);
354
gtk_button_set_relief (GTK_BUTTON (button), GTK_RELIEF_NONE);
355
gtk_toggle_button_set_mode (GTK_TOGGLE_BUTTON (button), FALSE);
357
if (first_button && *first_button == NULL)
358
*first_button = button;
360
stock_id = g_strconcat (stock_prefix, "-", value->value_nick, NULL);
362
image = gtk_image_new_from_stock (stock_id, icon_size);
368
gtk_container_add (GTK_CONTAINER (button), image);
369
gtk_widget_show (image);
372
gimp_help_set_help_data (button,
373
gimp_enum_value_get_desc (enum_class, value),
376
group = gtk_radio_button_get_group (GTK_RADIO_BUTTON (button));
377
gtk_box_pack_start (GTK_BOX (hbox), button, FALSE, FALSE, 0);
378
gtk_widget_show (button);
380
g_object_set_data (G_OBJECT (button), "gimp-item-data",
381
GINT_TO_POINTER (value->value));
384
g_signal_connect (button, "toggled",
393
* gimp_enum_stock_box_set_child_padding:
394
* @stock_box: a stock box widget
395
* @xpad: horizontal padding
396
* @ypad: vertical padding
398
* Sets the padding of all buttons in a box created by
399
* gimp_enum_stock_box_new().
404
gimp_enum_stock_box_set_child_padding (GtkWidget *stock_box,
411
g_return_if_fail (GTK_IS_CONTAINER (stock_box));
413
children = gtk_container_get_children (GTK_CONTAINER (stock_box));
415
for (list = children; list; list = g_list_next (list))
417
GtkBin *bin = list->data;
419
if (GTK_IS_MISC (bin->child))
421
GtkMisc *misc = GTK_MISC (bin->child);
423
gtk_misc_set_padding (misc,
424
xpad < 0 ? misc->xpad : xpad,
425
ypad < 0 ? misc->ypad : ypad);
429
g_list_free (children);