1
/* The GIMP -- an image manipulation program
2
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
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.
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.
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.
25
#include "libgimpwidgets/gimpwidgets.h"
27
#include "dialogs-types.h"
29
#include "widgets/gimpviewabledialog.h"
31
#include "info-dialog.h"
33
#include "gimp-intl.h"
39
/* local function prototypes */
41
static InfoDialog * info_dialog_new_extended (GimpViewable *viewable,
44
const gchar *stock_id,
47
GimpHelpFunc help_func,
49
gboolean in_notebook);
50
static void info_dialog_field_new (InfoDialog *idialog,
51
InfoFieldType field_type,
57
gpointer callback_data);
58
static void info_dialog_update_field (InfoField *info_field);
59
static void info_dialog_field_free (gpointer data,
63
/* public functions */
66
info_dialog_new (GimpViewable *viewable,
69
const gchar *stock_id,
72
GimpHelpFunc help_func,
75
return info_dialog_new_extended (viewable, title, role,
78
help_func, help_data, FALSE);
82
info_dialog_notebook_new (GimpViewable *viewable,
85
const gchar *stock_id,
88
GimpHelpFunc help_func,
91
return info_dialog_new_extended (viewable, title, role,
94
help_func, help_data, TRUE);
98
info_dialog_field_free (gpointer data,
101
InfoField *field = data;
103
g_signal_handlers_disconnect_by_func (field->obj,
105
field->callback_data);
110
info_dialog_free (InfoDialog *idialog)
112
g_return_if_fail (idialog != NULL);
114
g_slist_foreach (idialog->field_list, (GFunc) info_dialog_field_free, NULL);
115
g_slist_free (idialog->field_list);
117
gtk_widget_destroy (idialog->shell);
123
info_dialog_show (InfoDialog *idialog)
125
g_return_if_fail (idialog != NULL);
127
gtk_widget_show (idialog->shell);
131
info_dialog_present (InfoDialog *idialog)
133
g_return_if_fail (idialog != NULL);
135
gtk_window_present (GTK_WINDOW (idialog->shell));
139
info_dialog_hide (InfoDialog *idialog)
141
g_return_if_fail (idialog != NULL);
143
gtk_widget_hide (idialog->shell);
147
info_dialog_update (InfoDialog *idialog)
151
g_return_if_fail (idialog != NULL);
153
for (list = idialog->field_list; list; list = g_slist_next (list))
154
info_dialog_update_field ((InfoField *) list->data);
158
info_dialog_add_label (InfoDialog *idialog,
164
g_return_val_if_fail (idialog != NULL, NULL);
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);
170
info_dialog_field_new (idialog, INFO_LABEL, title, label, NULL,
178
info_dialog_add_entry (InfoDialog *idialog,
182
gpointer callback_data)
186
g_return_val_if_fail (idialog != NULL, NULL);
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 : "");
193
g_signal_connect (entry, "changed",
197
info_dialog_field_new (idialog, INFO_ENTRY, title, entry, NULL,
199
callback, callback_data);
205
info_dialog_add_scale (InfoDialog *idialog,
210
gfloat step_increment,
211
gfloat page_increment,
215
gpointer callback_data)
217
GtkObject *adjustment;
220
g_return_val_if_fail (idialog != NULL, NULL);
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));
227
gtk_scale_set_digits (GTK_SCALE (scale), MAX (digits, 6));
229
gtk_scale_set_draw_value (GTK_SCALE (scale), FALSE);
232
g_signal_connect (adjustment, "value_changed",
236
info_dialog_field_new (idialog, INFO_SCALE, title, scale, adjustment,
238
callback, callback_data);
244
info_dialog_add_spinbutton (InfoDialog *idialog,
249
gfloat step_increment,
250
gfloat page_increment,
255
gpointer callback_data)
257
GtkWidget *alignment;
258
GtkObject *adjustment;
259
GtkWidget *spinbutton;
261
g_return_val_if_fail (idialog != NULL, NULL);
263
alignment = gtk_alignment_new (0.0, 0.5, 0.0, 1.0);
265
spinbutton = gimp_spin_button_new (&adjustment,
266
value_ptr ? *value_ptr : 0,
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);
273
g_signal_connect (adjustment, "value_changed",
277
gtk_container_add (GTK_CONTAINER (alignment), spinbutton);
278
gtk_widget_show (spinbutton);
280
info_dialog_field_new (idialog, INFO_SPINBUTTON, title, alignment,
283
callback, callback_data);
289
info_dialog_add_sizeentry (InfoDialog *idialog,
295
gboolean menu_show_pixels,
296
gboolean menu_show_percent,
297
gboolean show_refval,
298
GimpSizeEntryUpdatePolicy update_policy,
300
gpointer callback_data)
302
GtkWidget *alignment;
303
GtkWidget *sizeentry;
306
g_return_val_if_fail (idialog != NULL, NULL);
308
alignment = gtk_alignment_new (0.0, 0.5, 0.0, 1.0);
310
sizeentry = gimp_size_entry_new (nfields, unit, unit_format,
311
menu_show_pixels, menu_show_percent,
312
show_refval, SB_WIDTH,
315
for (i = 0; i < nfields; i++)
316
gimp_size_entry_set_refval (GIMP_SIZE_ENTRY (sizeentry), i, value_ptr[i]);
319
g_signal_connect (sizeentry, "value_changed",
323
gtk_container_add (GTK_CONTAINER (alignment), sizeentry);
324
gtk_widget_show (sizeentry);
326
info_dialog_field_new (idialog, INFO_SIZEENTRY, title, alignment,
327
GTK_OBJECT (sizeentry),
329
callback, callback_data);
335
/* private functions */
338
info_dialog_new_extended (GimpViewable *viewable,
341
const gchar *stock_id,
344
GimpHelpFunc help_func,
346
gboolean in_notebook)
351
GtkWidget *info_table;
352
GtkWidget *info_notebook;
354
idialog = g_new (InfoDialog, 1);
355
idialog->field_list = NULL;
356
idialog->nfields = 0;
358
shell = gimp_viewable_dialog_new (viewable,
362
help_func, help_data,
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);
369
info_table = gtk_table_new (2, 0, FALSE);
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),
377
gtk_label_new (_("General")));
378
gtk_box_pack_start (GTK_BOX (vbox), info_notebook, FALSE, FALSE, 0);
382
info_notebook = NULL;
383
gtk_box_pack_start (GTK_BOX (vbox), info_table, FALSE, FALSE, 0);
386
idialog->shell = shell;
387
idialog->vbox = vbox;
388
idialog->info_table = info_table;
389
idialog->info_notebook = info_notebook;
392
gtk_widget_show (idialog->info_notebook);
394
gtk_widget_show (idialog->info_table);
395
gtk_widget_show (idialog->vbox);
401
info_dialog_field_new (InfoDialog *idialog,
402
InfoFieldType field_type,
408
gpointer callback_data)
414
field = g_new (InfoField, 1);
416
row = idialog->nfields + 1;
417
gtk_table_resize (GTK_TABLE (idialog->info_table), 2, row);
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,
423
GTK_SHRINK | GTK_FILL, GTK_SHRINK | GTK_FILL, 0, 0);
424
gtk_widget_show (label);
426
gtk_table_attach_defaults (GTK_TABLE (idialog->info_table), widget,
428
gtk_widget_show (widget);
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);
433
field->field_type = field_type;
436
field->obj = GTK_OBJECT (widget);
440
field->value_ptr = value_ptr;
441
field->callback = callback;
442
field->callback_data = callback_data;
444
idialog->field_list = g_slist_prepend (idialog->field_list, field);
449
info_dialog_update_field (InfoField *field)
451
const gchar *old_text;
455
if (field->value_ptr == NULL)
458
if (field->field_type != INFO_LABEL)
459
g_signal_handlers_block_by_func (field->obj,
461
field->callback_data);
463
switch (field->field_type)
466
gtk_label_set_text (GTK_LABEL (field->obj), (gchar *) field->value_ptr);
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);
476
case INFO_SPINBUTTON:
477
gtk_adjustment_set_value (GTK_ADJUSTMENT (field->obj),
478
*((gdouble *) field->value_ptr));
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]);
489
g_warning ("%s: Unknown info_dialog field type.", G_STRFUNC);
493
if (field->field_type != INFO_LABEL)
494
g_signal_handlers_unblock_by_func (field->obj,
496
field->callback_data);