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

« back to all changes in this revision

Viewing changes to libgimpwidgets/gimpenumwidgets.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
/* LIBGIMP - The GIMP Library
 
2
 * Copyright (C) 1995-1997 Peter Mattis and Spencer Kimball
 
3
 *
 
4
 * gimpenumwidgets.c
 
5
 * Copyright (C) 2002-2004  Sven Neumann <sven@gimp.org>
 
6
 *
 
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.
 
11
 *
 
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.
 
16
 *
 
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.
 
21
 */
 
22
 
 
23
#include "config.h"
 
24
 
 
25
#include <gtk/gtk.h>
 
26
 
 
27
#include "libgimpbase/gimpbase.h"
 
28
 
 
29
#include "gimpwidgetstypes.h"
 
30
 
 
31
#include "gimpenumwidgets.h"
 
32
#include "gimpframe.h"
 
33
#include "gimphelpui.h"
 
34
 
 
35
 
 
36
/**
 
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.
 
43
 *
 
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.
 
48
 *
 
49
 * Return value: a new #GtkVBox holding a group of #GtkRadioButtons.
 
50
 *
 
51
 * Since: GIMP 2.4
 
52
 **/
 
53
GtkWidget *
 
54
gimp_enum_radio_box_new (GType       enum_type,
 
55
                         GCallback   callback,
 
56
                         gpointer    callback_data,
 
57
                         GtkWidget **first_button)
 
58
{
 
59
  GEnumClass *enum_class;
 
60
  GtkWidget  *vbox;
 
61
 
 
62
  g_return_val_if_fail (G_TYPE_IS_ENUM (enum_type), NULL);
 
63
 
 
64
  enum_class = g_type_class_ref (enum_type);
 
65
 
 
66
  vbox = gimp_enum_radio_box_new_with_range (enum_type,
 
67
                                             enum_class->minimum,
 
68
                                             enum_class->maximum,
 
69
                                             callback, callback_data,
 
70
                                             first_button);
 
71
 
 
72
  g_type_class_unref (enum_class);
 
73
 
 
74
  return vbox;
 
75
}
 
76
 
 
77
/**
 
78
 * gimp_enum_radio_box_new_with_range:
 
79
 * @minimum:
 
80
 * @maximum:
 
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.
 
86
 *
 
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
 
89
 * enum values.
 
90
 *
 
91
 * Return value: a new #GtkVBox holding a group of #GtkRadioButtons.
 
92
 *
 
93
 * Since: GIMP 2.4
 
94
 **/
 
95
GtkWidget *
 
96
gimp_enum_radio_box_new_with_range (GType       enum_type,
 
97
                                    gint        minimum,
 
98
                                    gint        maximum,
 
99
                                    GCallback   callback,
 
100
                                    gpointer    callback_data,
 
101
                                    GtkWidget **first_button)
 
102
{
 
103
  GtkWidget  *vbox;
 
104
  GtkWidget  *button;
 
105
  GEnumClass *enum_class;
 
106
  GEnumValue *value;
 
107
  GSList     *group = NULL;
 
108
 
 
109
  g_return_val_if_fail (G_TYPE_IS_ENUM (enum_type), NULL);
 
110
 
 
111
  enum_class = g_type_class_ref (enum_type);
 
112
 
 
113
  vbox = gtk_vbox_new (FALSE, 1);
 
114
  g_object_weak_ref (G_OBJECT (vbox),
 
115
                     (GWeakNotify) g_type_class_unref, enum_class);
 
116
 
 
117
  if (first_button)
 
118
    *first_button = NULL;
 
119
 
 
120
  for (value = enum_class->values; value->value_name; value++)
 
121
    {
 
122
      const gchar *desc;
 
123
 
 
124
      if (value->value < minimum || value->value > maximum)
 
125
        continue;
 
126
 
 
127
      desc = gimp_enum_value_get_desc (enum_class, value);
 
128
 
 
129
      button = gtk_radio_button_new_with_mnemonic (group, desc);
 
130
 
 
131
      if (first_button && *first_button == NULL)
 
132
        *first_button = button;
 
133
 
 
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);
 
137
 
 
138
      g_object_set_data (G_OBJECT (button), "gimp-item-data",
 
139
                         GINT_TO_POINTER (value->value));
 
140
 
 
141
      if (callback)
 
142
        g_signal_connect (button, "toggled",
 
143
                          callback,
 
144
                          callback_data);
 
145
    }
 
146
 
 
147
  return vbox;
 
148
}
 
149
 
 
150
/**
 
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.
 
159
 *
 
160
 * Calls gimp_enum_radio_box_new() and puts the resulting vbox into a
 
161
 * #GtkFrame.
 
162
 *
 
163
 * Return value: a new #GtkFrame holding a group of #GtkRadioButtons.
 
164
 *
 
165
 * Since: GIMP 2.4
 
166
 **/
 
167
GtkWidget *
 
168
gimp_enum_radio_frame_new (GType       enum_type,
 
169
                           GtkWidget  *label_widget,
 
170
                           GCallback   callback,
 
171
                           gpointer    callback_data,
 
172
                           GtkWidget **first_button)
 
173
{
 
174
  GtkWidget *frame;
 
175
  GtkWidget *radio_box;
 
176
 
 
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),
 
179
                        NULL);
 
180
 
 
181
  frame = gimp_frame_new (NULL);
 
182
 
 
183
  if (label_widget)
 
184
    {
 
185
      gtk_frame_set_label_widget (GTK_FRAME (frame), label_widget);
 
186
      gtk_widget_show (label_widget);
 
187
    }
 
188
 
 
189
  radio_box = gimp_enum_radio_box_new (enum_type,
 
190
                                       callback, callback_data,
 
191
                                       first_button);
 
192
  gtk_container_add (GTK_CONTAINER (frame), radio_box);
 
193
  gtk_widget_show (radio_box);
 
194
 
 
195
  return frame;
 
196
}
 
197
 
 
198
/**
 
199
 * gimp_enum_radio_frame_new_with_range:
 
200
 * @enum_type: the #GType of an enum.
 
201
 * @minimum:
 
202
 * @maximum:
 
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.
 
208
 *
 
209
 * Calls gimp_enum_radio_box_new_with_range() and puts the resulting
 
210
 * vbox into a #GtkFrame.
 
211
 *
 
212
 * Return value: a new #GtkFrame holding a group of #GtkRadioButtons.
 
213
 *
 
214
 * Since: GIMP 2.4
 
215
 **/
 
216
GtkWidget *
 
217
gimp_enum_radio_frame_new_with_range (GType       enum_type,
 
218
                                      gint        minimum,
 
219
                                      gint        maximum,
 
220
                                      GtkWidget  *label_widget,
 
221
                                      GCallback   callback,
 
222
                                      gpointer    callback_data,
 
223
                                      GtkWidget **first_button)
 
224
{
 
225
  GtkWidget *frame;
 
226
  GtkWidget *radio_box;
 
227
 
 
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),
 
230
                        NULL);
 
231
 
 
232
  frame = gimp_frame_new (NULL);
 
233
 
 
234
  if (label_widget)
 
235
    {
 
236
      gtk_frame_set_label_widget (GTK_FRAME (frame), label_widget);
 
237
      gtk_widget_show (label_widget);
 
238
    }
 
239
 
 
240
  radio_box = gimp_enum_radio_box_new_with_range (enum_type,
 
241
                                                  minimum,
 
242
                                                  maximum,
 
243
                                                  callback, callback_data,
 
244
                                                  first_button);
 
245
  gtk_container_add (GTK_CONTAINER (frame), radio_box);
 
246
  gtk_widget_show (radio_box);
 
247
 
 
248
  return frame;
 
249
}
 
250
 
 
251
 
 
252
/**
 
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.
 
256
 * @icon_size:
 
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.
 
261
 *
 
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.
 
265
 *
 
266
 * Return value: a new #GtkHbox holding a group of #GtkRadioButtons.
 
267
 *
 
268
 * Since: GIMP 2.4
 
269
 **/
 
270
GtkWidget *
 
271
gimp_enum_stock_box_new (GType         enum_type,
 
272
                         const gchar  *stock_prefix,
 
273
                         GtkIconSize   icon_size,
 
274
                         GCallback     callback,
 
275
                         gpointer      callback_data,
 
276
                         GtkWidget   **first_button)
 
277
{
 
278
  GEnumClass *enum_class;
 
279
  GtkWidget  *box;
 
280
 
 
281
  g_return_val_if_fail (G_TYPE_IS_ENUM (enum_type), NULL);
 
282
 
 
283
  enum_class = g_type_class_ref (enum_type);
 
284
 
 
285
  box = gimp_enum_stock_box_new_with_range (enum_type,
 
286
                                            enum_class->minimum,
 
287
                                            enum_class->maximum,
 
288
                                            stock_prefix, icon_size,
 
289
                                            callback, callback_data,
 
290
                                            first_button);
 
291
 
 
292
  g_type_class_unref (enum_class);
 
293
 
 
294
  return box;
 
295
}
 
296
 
 
297
/**
 
298
 * gimp_enum_stock_box_new_with_range:
 
299
 * @enum_type: the #GType of an enum.
 
300
 * @minimum:
 
301
 * @maximum:
 
302
 * @stock_prefix: the prefix of the group of stock ids to use.
 
303
 * @icon_size:
 
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.
 
308
 *
 
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
 
311
 * enum values.
 
312
 *
 
313
 * Return value: a new #GtkHbox holding a group of #GtkRadioButtons.
 
314
 *
 
315
 * Since: GIMP 2.4
 
316
 **/
 
317
GtkWidget *
 
318
gimp_enum_stock_box_new_with_range (GType         enum_type,
 
319
                                    gint          minimum,
 
320
                                    gint          maximum,
 
321
                                    const gchar  *stock_prefix,
 
322
                                    GtkIconSize   icon_size,
 
323
                                    GCallback     callback,
 
324
                                    gpointer      callback_data,
 
325
                                    GtkWidget   **first_button)
 
326
{
 
327
  GtkWidget  *hbox;
 
328
  GtkWidget  *button;
 
329
  GtkWidget  *image;
 
330
  GEnumClass *enum_class;
 
331
  GEnumValue *value;
 
332
  gchar      *stock_id;
 
333
  GSList     *group = NULL;
 
334
 
 
335
  g_return_val_if_fail (G_TYPE_IS_ENUM (enum_type), NULL);
 
336
  g_return_val_if_fail (stock_prefix != NULL, NULL);
 
337
 
 
338
  enum_class = g_type_class_ref (enum_type);
 
339
 
 
340
  hbox = gtk_hbox_new (FALSE, 0);
 
341
  g_object_weak_ref (G_OBJECT (hbox),
 
342
                     (GWeakNotify) g_type_class_unref, enum_class);
 
343
 
 
344
  if (first_button)
 
345
    *first_button = NULL;
 
346
 
 
347
  for (value = enum_class->values; value->value_name; value++)
 
348
    {
 
349
      if (value->value < minimum || value->value > maximum)
 
350
        continue;
 
351
 
 
352
      button = gtk_radio_button_new (group);
 
353
 
 
354
      gtk_button_set_relief (GTK_BUTTON (button), GTK_RELIEF_NONE);
 
355
      gtk_toggle_button_set_mode (GTK_TOGGLE_BUTTON (button), FALSE);
 
356
 
 
357
      if (first_button && *first_button == NULL)
 
358
        *first_button = button;
 
359
 
 
360
      stock_id = g_strconcat (stock_prefix, "-", value->value_nick, NULL);
 
361
 
 
362
      image = gtk_image_new_from_stock (stock_id, icon_size);
 
363
 
 
364
      g_free (stock_id);
 
365
 
 
366
      if (image)
 
367
        {
 
368
          gtk_container_add (GTK_CONTAINER (button), image);
 
369
          gtk_widget_show (image);
 
370
        }
 
371
 
 
372
      gimp_help_set_help_data (button,
 
373
                               gimp_enum_value_get_desc (enum_class, value),
 
374
                               NULL);
 
375
 
 
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);
 
379
 
 
380
      g_object_set_data (G_OBJECT (button), "gimp-item-data",
 
381
                         GINT_TO_POINTER (value->value));
 
382
 
 
383
      if (callback)
 
384
        g_signal_connect (button, "toggled",
 
385
                          callback,
 
386
                          callback_data);
 
387
    }
 
388
 
 
389
  return hbox;
 
390
}
 
391
 
 
392
/**
 
393
 * gimp_enum_stock_box_set_child_padding:
 
394
 * @stock_box: a stock box widget
 
395
 * @xpad: horizontal padding
 
396
 * @ypad: vertical padding
 
397
 *
 
398
 * Sets the padding of all buttons in a box created by
 
399
 * gimp_enum_stock_box_new().
 
400
 *
 
401
 * Since: GIMP 2.4
 
402
 **/
 
403
void
 
404
gimp_enum_stock_box_set_child_padding (GtkWidget *stock_box,
 
405
                                       gint       xpad,
 
406
                                       gint       ypad)
 
407
{
 
408
  GList *children;
 
409
  GList *list;
 
410
 
 
411
  g_return_if_fail (GTK_IS_CONTAINER (stock_box));
 
412
 
 
413
  children = gtk_container_get_children (GTK_CONTAINER (stock_box));
 
414
 
 
415
  for (list = children; list; list = g_list_next (list))
 
416
    {
 
417
      GtkBin *bin = list->data;
 
418
 
 
419
      if (GTK_IS_MISC (bin->child))
 
420
        {
 
421
          GtkMisc *misc = GTK_MISC (bin->child);
 
422
 
 
423
          gtk_misc_set_padding (misc,
 
424
                                xpad < 0 ? misc->xpad : xpad,
 
425
                                ypad < 0 ? misc->ypad : ypad);
 
426
        }
 
427
    }
 
428
 
 
429
  g_list_free (children);
 
430
}