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

« back to all changes in this revision

Viewing changes to app/dialogs/info-dialog.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
 
/* The GIMP -- an image manipulation program
2
 
 * Copyright (C) 1995 Spencer Kimball and Peter Mattis
3
 
 *
4
 
 * This program is free software; you can redistribute it and/or modify
5
 
 * it under the terms of the GNU General Public License as published by
6
 
 * the Free Software Foundation; either version 2 of the License, or
7
 
 * (at your option) any later version.
8
 
 *
9
 
 * This program is distributed in the hope that it will be useful,
10
 
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11
 
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
 
 * GNU General Public License for more details.
13
 
 *
14
 
 * You should have received a copy of the GNU General Public License
15
 
 * along with this program; if not, write to the Free Software
16
 
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17
 
 */
18
 
 
19
 
#include "config.h"
20
 
 
21
 
#include <string.h>
22
 
 
23
 
#include <gtk/gtk.h>
24
 
 
25
 
#include "libgimpwidgets/gimpwidgets.h"
26
 
 
27
 
#include "dialogs-types.h"
28
 
 
29
 
#include "widgets/gimpviewabledialog.h"
30
 
 
31
 
#include "info-dialog.h"
32
 
 
33
 
#include "gimp-intl.h"
34
 
 
35
 
 
36
 
#define SB_WIDTH 10
37
 
 
38
 
 
39
 
/*  local function prototypes  */
40
 
 
41
 
static InfoDialog * info_dialog_new_extended    (GimpViewable  *viewable,
42
 
                                                 const gchar   *title,
43
 
                                                 const gchar   *role,
44
 
                                                 const gchar   *stock_id,
45
 
                                                 const gchar   *desc,
46
 
                                                 GtkWidget     *parent,
47
 
                                                 GimpHelpFunc   help_func,
48
 
                                                 gpointer       help_data,
49
 
                                                 gboolean       in_notebook);
50
 
static void         info_dialog_field_new       (InfoDialog    *idialog,
51
 
                                                 InfoFieldType  field_type,
52
 
                                                 gchar         *title,
53
 
                                                 GtkWidget     *widget,
54
 
                                                 GtkObject     *object,
55
 
                                                 gpointer       value_ptr,
56
 
                                                 GCallback      callback,
57
 
                                                 gpointer       callback_data);
58
 
static void         info_dialog_update_field    (InfoField     *info_field);
59
 
static void         info_dialog_field_free      (gpointer       data,
60
 
                                                 gpointer       user_data);
61
 
 
62
 
 
63
 
/*  public functions  */
64
 
 
65
 
InfoDialog *
66
 
info_dialog_new (GimpViewable *viewable,
67
 
                 const gchar  *title,
68
 
                 const gchar  *role,
69
 
                 const gchar  *stock_id,
70
 
                 const gchar  *desc,
71
 
                 GtkWidget    *parent,
72
 
                 GimpHelpFunc  help_func,
73
 
                 gpointer      help_data)
74
 
{
75
 
  return info_dialog_new_extended (viewable, title, role,
76
 
                                   stock_id, desc,
77
 
                                   parent,
78
 
                                   help_func, help_data, FALSE);
79
 
}
80
 
 
81
 
InfoDialog *
82
 
info_dialog_notebook_new (GimpViewable *viewable,
83
 
                          const gchar  *title,
84
 
                          const gchar  *role,
85
 
                          const gchar  *stock_id,
86
 
                          const gchar  *desc,
87
 
                          GtkWidget    *parent,
88
 
                          GimpHelpFunc  help_func,
89
 
                          gpointer      help_data)
90
 
{
91
 
  return info_dialog_new_extended (viewable, title, role,
92
 
                                   stock_id, desc,
93
 
                                   parent,
94
 
                                   help_func, help_data, TRUE);
95
 
}
96
 
 
97
 
static void
98
 
info_dialog_field_free (gpointer data,
99
 
                        gpointer user_data)
100
 
{
101
 
  InfoField *field = data;
102
 
 
103
 
  g_signal_handlers_disconnect_by_func (field->obj,
104
 
                                        field->callback,
105
 
                                        field->callback_data);
106
 
  g_free (field);
107
 
}
108
 
 
109
 
void
110
 
info_dialog_free (InfoDialog *idialog)
111
 
{
112
 
  g_return_if_fail (idialog != NULL);
113
 
 
114
 
  g_slist_foreach (idialog->field_list, (GFunc) info_dialog_field_free, NULL);
115
 
  g_slist_free (idialog->field_list);
116
 
 
117
 
  gtk_widget_destroy (idialog->shell);
118
 
 
119
 
  g_free (idialog);
120
 
}
121
 
 
122
 
void
123
 
info_dialog_show (InfoDialog *idialog)
124
 
{
125
 
  g_return_if_fail (idialog != NULL);
126
 
 
127
 
  gtk_widget_show (idialog->shell);
128
 
}
129
 
 
130
 
void
131
 
info_dialog_present (InfoDialog *idialog)
132
 
{
133
 
  g_return_if_fail (idialog != NULL);
134
 
 
135
 
  gtk_window_present (GTK_WINDOW (idialog->shell));
136
 
}
137
 
 
138
 
void
139
 
info_dialog_hide (InfoDialog *idialog)
140
 
{
141
 
  g_return_if_fail (idialog != NULL);
142
 
 
143
 
  gtk_widget_hide (idialog->shell);
144
 
}
145
 
 
146
 
void
147
 
info_dialog_update (InfoDialog *idialog)
148
 
{
149
 
  GSList *list;
150
 
 
151
 
  g_return_if_fail (idialog != NULL);
152
 
 
153
 
  for (list = idialog->field_list; list; list = g_slist_next (list))
154
 
    info_dialog_update_field ((InfoField *) list->data);
155
 
}
156
 
 
157
 
GtkWidget *
158
 
info_dialog_add_label (InfoDialog *idialog,
159
 
                       gchar      *title,
160
 
                       gchar      *text_ptr)
161
 
{
162
 
  GtkWidget *label;
163
 
 
164
 
  g_return_val_if_fail (idialog != NULL, NULL);
165
 
 
166
 
  label = gtk_label_new (text_ptr);
167
 
  gtk_label_set_selectable (GTK_LABEL (label), TRUE);
168
 
  gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
169
 
 
170
 
  info_dialog_field_new (idialog, INFO_LABEL, title, label, NULL,
171
 
                         text_ptr,
172
 
                         NULL, NULL);
173
 
 
174
 
  return label;
175
 
}
176
 
 
177
 
GtkWidget *
178
 
info_dialog_add_entry (InfoDialog    *idialog,
179
 
                       gchar         *title,
180
 
                       gchar         *text_ptr,
181
 
                       GCallback      callback,
182
 
                       gpointer       callback_data)
183
 
{
184
 
  GtkWidget *entry;
185
 
 
186
 
  g_return_val_if_fail (idialog != NULL, NULL);
187
 
 
188
 
  entry = gtk_entry_new ();
189
 
  gtk_widget_set_size_request (entry, 50, -1);
190
 
  gtk_entry_set_text (GTK_ENTRY (entry), text_ptr ? text_ptr : "");
191
 
 
192
 
  if (callback)
193
 
    g_signal_connect (entry, "changed",
194
 
                      callback,
195
 
                      callback_data);
196
 
 
197
 
  info_dialog_field_new (idialog, INFO_ENTRY, title, entry, NULL,
198
 
                         text_ptr,
199
 
                         callback, callback_data);
200
 
 
201
 
  return entry;
202
 
}
203
 
 
204
 
GtkWidget *
205
 
info_dialog_add_scale   (InfoDialog    *idialog,
206
 
                         gchar         *title,
207
 
                         gdouble       *value_ptr,
208
 
                         gfloat         lower,
209
 
                         gfloat         upper,
210
 
                         gfloat         step_increment,
211
 
                         gfloat         page_increment,
212
 
                         gfloat         page_size,
213
 
                         gint           digits,
214
 
                         GCallback      callback,
215
 
                         gpointer       callback_data)
216
 
{
217
 
  GtkObject *adjustment;
218
 
  GtkWidget *scale;
219
 
 
220
 
  g_return_val_if_fail (idialog != NULL, NULL);
221
 
 
222
 
  adjustment = gtk_adjustment_new (value_ptr ? *value_ptr : 0, lower, upper,
223
 
                                   step_increment, page_increment, page_size);
224
 
  scale = gtk_hscale_new (GTK_ADJUSTMENT (adjustment));
225
 
 
226
 
  if (digits >= 0)
227
 
    gtk_scale_set_digits (GTK_SCALE (scale), MAX (digits, 6));
228
 
  else
229
 
    gtk_scale_set_draw_value (GTK_SCALE (scale), FALSE);
230
 
 
231
 
  if (callback)
232
 
    g_signal_connect (adjustment, "value_changed",
233
 
                      callback,
234
 
                      callback_data);
235
 
 
236
 
  info_dialog_field_new (idialog, INFO_SCALE, title, scale, adjustment,
237
 
                         value_ptr,
238
 
                         callback, callback_data);
239
 
 
240
 
  return scale;
241
 
}
242
 
 
243
 
GtkWidget *
244
 
info_dialog_add_spinbutton (InfoDialog    *idialog,
245
 
                            gchar         *title,
246
 
                            gdouble       *value_ptr,
247
 
                            gfloat         lower,
248
 
                            gfloat         upper,
249
 
                            gfloat         step_increment,
250
 
                            gfloat         page_increment,
251
 
                            gfloat         page_size,
252
 
                            gfloat         climb_rate,
253
 
                            gint           digits,
254
 
                            GCallback      callback,
255
 
                            gpointer       callback_data)
256
 
{
257
 
  GtkWidget *alignment;
258
 
  GtkObject *adjustment;
259
 
  GtkWidget *spinbutton;
260
 
 
261
 
  g_return_val_if_fail (idialog != NULL, NULL);
262
 
 
263
 
  alignment = gtk_alignment_new (0.0, 0.5, 0.0, 1.0);
264
 
 
265
 
  spinbutton = gimp_spin_button_new (&adjustment,
266
 
                                     value_ptr ? *value_ptr : 0,
267
 
                                     lower, upper,
268
 
                                     step_increment, page_increment, page_size,
269
 
                                     climb_rate, MAX (MIN (digits, 6), 0));
270
 
  gtk_entry_set_width_chars (GTK_ENTRY (spinbutton), SB_WIDTH);
271
 
 
272
 
  if (callback)
273
 
    g_signal_connect (adjustment, "value_changed",
274
 
                      callback,
275
 
                      callback_data);
276
 
 
277
 
  gtk_container_add (GTK_CONTAINER (alignment), spinbutton);
278
 
  gtk_widget_show (spinbutton);
279
 
 
280
 
  info_dialog_field_new (idialog, INFO_SPINBUTTON, title, alignment,
281
 
                         adjustment,
282
 
                         value_ptr,
283
 
                         callback, callback_data);
284
 
 
285
 
  return spinbutton;
286
 
}
287
 
 
288
 
GtkWidget *
289
 
info_dialog_add_sizeentry (InfoDialog                *idialog,
290
 
                           gchar                     *title,
291
 
                           gdouble                   *value_ptr,
292
 
                           gint                       nfields,
293
 
                           GimpUnit                   unit,
294
 
                           gchar                     *unit_format,
295
 
                           gboolean                   menu_show_pixels,
296
 
                           gboolean                   menu_show_percent,
297
 
                           gboolean                   show_refval,
298
 
                           GimpSizeEntryUpdatePolicy  update_policy,
299
 
                           GCallback                  callback,
300
 
                           gpointer                   callback_data)
301
 
{
302
 
  GtkWidget *alignment;
303
 
  GtkWidget *sizeentry;
304
 
  gint       i;
305
 
 
306
 
  g_return_val_if_fail (idialog != NULL, NULL);
307
 
 
308
 
  alignment = gtk_alignment_new (0.0, 0.5, 0.0, 1.0);
309
 
 
310
 
  sizeentry = gimp_size_entry_new (nfields, unit, unit_format,
311
 
                                   menu_show_pixels, menu_show_percent,
312
 
                                   show_refval, SB_WIDTH,
313
 
                                   update_policy);
314
 
  if (value_ptr)
315
 
    for (i = 0; i < nfields; i++)
316
 
      gimp_size_entry_set_refval (GIMP_SIZE_ENTRY (sizeentry), i, value_ptr[i]);
317
 
 
318
 
  if (callback)
319
 
    g_signal_connect (sizeentry, "value_changed",
320
 
                      callback,
321
 
                      callback_data);
322
 
 
323
 
  gtk_container_add (GTK_CONTAINER (alignment), sizeentry);
324
 
  gtk_widget_show (sizeentry);
325
 
 
326
 
  info_dialog_field_new (idialog, INFO_SIZEENTRY, title, alignment,
327
 
                         GTK_OBJECT (sizeentry),
328
 
                         value_ptr,
329
 
                         callback, callback_data);
330
 
 
331
 
  return sizeentry;
332
 
}
333
 
 
334
 
 
335
 
/*  private functions  */
336
 
 
337
 
static InfoDialog *
338
 
info_dialog_new_extended (GimpViewable *viewable,
339
 
                          const gchar  *title,
340
 
                          const gchar  *role,
341
 
                          const gchar  *stock_id,
342
 
                          const gchar  *desc,
343
 
                          GtkWidget    *parent,
344
 
                          GimpHelpFunc  help_func,
345
 
                          gpointer      help_data,
346
 
                          gboolean      in_notebook)
347
 
{
348
 
  InfoDialog *idialog;
349
 
  GtkWidget  *shell;
350
 
  GtkWidget  *vbox;
351
 
  GtkWidget  *info_table;
352
 
  GtkWidget  *info_notebook;
353
 
 
354
 
  idialog = g_new (InfoDialog, 1);
355
 
  idialog->field_list = NULL;
356
 
  idialog->nfields    = 0;
357
 
 
358
 
  shell = gimp_viewable_dialog_new (viewable,
359
 
                                    title, role,
360
 
                                    stock_id, desc,
361
 
                                    parent,
362
 
                                    help_func, help_data,
363
 
                                    NULL);
364
 
 
365
 
  vbox = gtk_vbox_new (FALSE, 6);
366
 
  gtk_container_set_border_width (GTK_CONTAINER (vbox), 12);
367
 
  gtk_container_add (GTK_CONTAINER (GTK_DIALOG (shell)->vbox), vbox);
368
 
 
369
 
  info_table = gtk_table_new (2, 0, FALSE);
370
 
 
371
 
  if (in_notebook)
372
 
    {
373
 
      info_notebook = gtk_notebook_new ();
374
 
      gtk_container_set_border_width (GTK_CONTAINER (info_table), 6);
375
 
      gtk_notebook_append_page (GTK_NOTEBOOK (info_notebook),
376
 
                                info_table,
377
 
                                gtk_label_new (_("General")));
378
 
      gtk_box_pack_start (GTK_BOX (vbox), info_notebook, FALSE, FALSE, 0);
379
 
    }
380
 
  else
381
 
    {
382
 
      info_notebook = NULL;
383
 
      gtk_box_pack_start (GTK_BOX (vbox), info_table, FALSE, FALSE, 0);
384
 
    }
385
 
 
386
 
  idialog->shell         = shell;
387
 
  idialog->vbox          = vbox;
388
 
  idialog->info_table    = info_table;
389
 
  idialog->info_notebook = info_notebook;
390
 
 
391
 
  if (in_notebook)
392
 
    gtk_widget_show (idialog->info_notebook);
393
 
 
394
 
  gtk_widget_show (idialog->info_table);
395
 
  gtk_widget_show (idialog->vbox);
396
 
 
397
 
  return idialog;
398
 
}
399
 
 
400
 
static void
401
 
info_dialog_field_new (InfoDialog    *idialog,
402
 
                       InfoFieldType  field_type,
403
 
                       gchar         *title,
404
 
                       GtkWidget     *widget,
405
 
                       GtkObject     *obj,
406
 
                       gpointer       value_ptr,
407
 
                       GCallback      callback,
408
 
                       gpointer       callback_data)
409
 
{
410
 
  GtkWidget *label;
411
 
  InfoField *field;
412
 
  gint       row;
413
 
 
414
 
  field = g_new (InfoField, 1);
415
 
 
416
 
  row = idialog->nfields + 1;
417
 
  gtk_table_resize (GTK_TABLE (idialog->info_table), 2, row);
418
 
 
419
 
  label = gtk_label_new (title);
420
 
  gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
421
 
  gtk_table_attach (GTK_TABLE (idialog->info_table), label,
422
 
                    0, 1, row - 1, row,
423
 
                    GTK_SHRINK | GTK_FILL, GTK_SHRINK | GTK_FILL, 0, 0);
424
 
  gtk_widget_show (label);
425
 
 
426
 
  gtk_table_attach_defaults (GTK_TABLE (idialog->info_table), widget,
427
 
                             1, 2, row - 1, row);
428
 
  gtk_widget_show (widget);
429
 
 
430
 
  gtk_table_set_col_spacing (GTK_TABLE (idialog->info_table), 0, 6);
431
 
  gtk_table_set_row_spacings (GTK_TABLE (idialog->info_table), 2);
432
 
 
433
 
  field->field_type = field_type;
434
 
 
435
 
  if (obj == NULL)
436
 
    field->obj = GTK_OBJECT (widget);
437
 
  else
438
 
    field->obj = obj;
439
 
 
440
 
  field->value_ptr     = value_ptr;
441
 
  field->callback      = callback;
442
 
  field->callback_data = callback_data;
443
 
 
444
 
  idialog->field_list = g_slist_prepend (idialog->field_list, field);
445
 
  idialog->nfields++;
446
 
}
447
 
 
448
 
static void
449
 
info_dialog_update_field (InfoField *field)
450
 
{
451
 
  const gchar *old_text;
452
 
  gint         num;
453
 
  gint         i;
454
 
 
455
 
  if (field->value_ptr == NULL)
456
 
    return;
457
 
 
458
 
  if (field->field_type != INFO_LABEL)
459
 
    g_signal_handlers_block_by_func (field->obj,
460
 
                                     field->callback,
461
 
                                     field->callback_data);
462
 
 
463
 
  switch (field->field_type)
464
 
    {
465
 
    case INFO_LABEL:
466
 
      gtk_label_set_text (GTK_LABEL (field->obj), (gchar *) field->value_ptr);
467
 
      break;
468
 
 
469
 
    case INFO_ENTRY:
470
 
      old_text = gtk_entry_get_text (GTK_ENTRY (field->obj));
471
 
      if (strcmp (old_text, (gchar *) field->value_ptr))
472
 
        gtk_entry_set_text (GTK_ENTRY (field->obj), (gchar *) field->value_ptr);
473
 
      break;
474
 
 
475
 
    case INFO_SCALE:
476
 
    case INFO_SPINBUTTON:
477
 
      gtk_adjustment_set_value (GTK_ADJUSTMENT (field->obj),
478
 
                                *((gdouble *) field->value_ptr));
479
 
      break;
480
 
 
481
 
    case INFO_SIZEENTRY:
482
 
      num = GIMP_SIZE_ENTRY (field->obj)->number_of_fields;
483
 
      for (i = 0; i < num; i++)
484
 
        gimp_size_entry_set_refval (GIMP_SIZE_ENTRY (field->obj), i,
485
 
                                    ((gdouble *) field->value_ptr)[i]);
486
 
      break;
487
 
 
488
 
    default:
489
 
      g_warning ("%s: Unknown info_dialog field type.", G_STRFUNC);
490
 
      break;
491
 
    }
492
 
 
493
 
  if (field->field_type != INFO_LABEL)
494
 
    g_signal_handlers_unblock_by_func (field->obj,
495
 
                                       field->callback,
496
 
                                       field->callback_data);
497
 
}