~ubuntu-branches/ubuntu/maverick/gimp/maverick-updates

« back to all changes in this revision

Viewing changes to app/widgets/gimptemplateeditor.c

  • Committer: Bazaar Package Importer
  • Author(s): Daniel Holbach
  • Date: 2005-12-09 19:44:52 UTC
  • Revision ID: james.westby@ubuntu.com-20051209194452-yggpemjlofpjqyf4
Tags: upstream-2.2.9
ImportĀ upstreamĀ versionĀ 2.2.9

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* The GIMP -- an image manipulation program
 
2
 * Copyright (C) 1995-1999 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 "libgimpmath/gimpmath.h"
 
26
#include "libgimpbase/gimpbase.h"
 
27
#include "libgimpwidgets/gimpwidgets.h"
 
28
 
 
29
#include "widgets-types.h"
 
30
 
 
31
#include "config/gimpconfig-utils.h"
 
32
#include "config/gimpconfig.h"
 
33
 
 
34
#include "core/gimp.h"
 
35
#include "core/gimplist.h"
 
36
#include "core/gimpcontext.h"
 
37
#include "core/gimptemplate.h"
 
38
 
 
39
#include "gimptemplateeditor.h"
 
40
#include "gimpenumwidgets.h"
 
41
#include "gimppropwidgets.h"
 
42
#include "gimpviewablebutton.h"
 
43
 
 
44
#include "gimp-intl.h"
 
45
 
 
46
 
 
47
#define SB_WIDTH            8
 
48
#define MAX_COMMENT_LENGTH  512  /* arbitrary */
 
49
 
 
50
enum
 
51
{
 
52
  PROP_0,
 
53
  PROP_TEMPLATE
 
54
};
 
55
 
 
56
 
 
57
static void gimp_template_editor_class_init (GimpTemplateEditorClass *klass);
 
58
static GObject * gimp_template_editor_constructor  (GType                 type,
 
59
                                                    guint                 n_params,
 
60
                                                   GObjectConstructParam *params);
 
61
static void      gimp_template_editor_set_property (GObject          *object,
 
62
                                                    guint             property_id,
 
63
                                                    const GValue     *value,
 
64
                                                    GParamSpec       *pspec);
 
65
static void      gimp_template_editor_get_property (GObject          *object,
 
66
                                                    guint             property_id,
 
67
                                                    GValue           *value,
 
68
                                                    GParamSpec       *pspec);
 
69
 
 
70
static void gimp_template_editor_finalize        (GObject            *object);
 
71
static void gimp_template_editor_init            (GimpTemplateEditor *editor);
 
72
 
 
73
static void gimp_template_editor_aspect_callback (GtkWidget          *widget,
 
74
                                                  GimpTemplateEditor *editor);
 
75
static void gimp_template_editor_template_notify (GimpTemplate       *template,
 
76
                                                  GParamSpec         *param_spec,
 
77
                                                  GimpTemplateEditor *editor);
 
78
static void gimp_template_editor_icon_changed    (GimpContext        *context,
 
79
                                                  GimpTemplate       *template,
 
80
                                                  GimpTemplateEditor *editor);
 
81
 
 
82
 
 
83
static GtkVBoxClass *parent_class = NULL;
 
84
 
 
85
 
 
86
GType
 
87
gimp_template_editor_get_type (void)
 
88
{
 
89
  static GType view_type = 0;
 
90
 
 
91
  if (! view_type)
 
92
    {
 
93
      static const GTypeInfo view_info =
 
94
      {
 
95
        sizeof (GimpTemplateEditorClass),
 
96
        NULL,           /* base_init      */
 
97
        NULL,           /* base_finalize  */
 
98
        (GClassInitFunc) gimp_template_editor_class_init,
 
99
        NULL,           /* class_finalize */
 
100
        NULL,           /* class_data     */
 
101
        sizeof (GimpTemplateEditor),
 
102
        0,              /* n_preallocs    */
 
103
        (GInstanceInitFunc) gimp_template_editor_init
 
104
      };
 
105
 
 
106
      view_type = g_type_register_static (GTK_TYPE_VBOX,
 
107
                                          "GimpTemplateEditor",
 
108
                                          &view_info, 0);
 
109
    }
 
110
 
 
111
  return view_type;
 
112
}
 
113
 
 
114
static void
 
115
gimp_template_editor_class_init (GimpTemplateEditorClass *klass)
 
116
{
 
117
  GObjectClass *object_class;
 
118
 
 
119
  object_class = G_OBJECT_CLASS (klass);
 
120
 
 
121
  parent_class = g_type_class_peek_parent (klass);
 
122
 
 
123
  object_class->constructor  = gimp_template_editor_constructor;
 
124
  object_class->set_property = gimp_template_editor_set_property;
 
125
  object_class->get_property = gimp_template_editor_get_property;
 
126
  object_class->finalize     = gimp_template_editor_finalize;
 
127
 
 
128
  g_object_class_install_property (object_class, PROP_TEMPLATE,
 
129
                                   g_param_spec_object ("template", NULL, NULL,
 
130
                                                        GIMP_TYPE_TEMPLATE,
 
131
                                                        G_PARAM_READWRITE |
 
132
                                                        G_PARAM_CONSTRUCT_ONLY));
 
133
}
 
134
 
 
135
static void
 
136
gimp_template_editor_init (GimpTemplateEditor *editor)
 
137
{
 
138
  editor->template = NULL;
 
139
}
 
140
 
 
141
static void
 
142
gimp_template_editor_set_property (GObject      *object,
 
143
                                   guint         property_id,
 
144
                                   const GValue *value,
 
145
                                   GParamSpec   *pspec)
 
146
{
 
147
  GimpTemplateEditor *editor = GIMP_TEMPLATE_EDITOR (object);
 
148
 
 
149
  switch (property_id)
 
150
    {
 
151
    case PROP_TEMPLATE:
 
152
      editor->template = GIMP_TEMPLATE (g_value_dup_object (value));
 
153
      break;
 
154
    default:
 
155
      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
 
156
      break;
 
157
    }
 
158
}
 
159
 
 
160
static void
 
161
gimp_template_editor_get_property (GObject      *object,
 
162
                                   guint         property_id,
 
163
                                   GValue       *value,
 
164
                                   GParamSpec   *pspec)
 
165
{
 
166
  GimpTemplateEditor *editor = GIMP_TEMPLATE_EDITOR (object);
 
167
 
 
168
  switch (property_id)
 
169
    {
 
170
    case PROP_TEMPLATE:
 
171
      g_value_set_object (value, editor->template);
 
172
      break;
 
173
    default:
 
174
      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
 
175
      break;
 
176
    }
 
177
}
 
178
 
 
179
static GObject *
 
180
gimp_template_editor_constructor (GType                  type,
 
181
                                  guint                  n_params,
 
182
                                  GObjectConstructParam *params)
 
183
{
 
184
  GimpTemplateEditor *editor;
 
185
  GObject            *object;
 
186
  GtkWidget          *aspect_box;
 
187
  GtkWidget          *frame;
 
188
  GtkWidget          *hbox;
 
189
  GtkWidget          *vbox;
 
190
  GtkWidget          *table;
 
191
  GtkWidget          *label;
 
192
  GtkObject          *adjustment;
 
193
  GtkWidget          *width;
 
194
  GtkWidget          *height;
 
195
  GtkWidget          *xres;
 
196
  GtkWidget          *yres;
 
197
  GtkWidget          *chainbutton;
 
198
  GtkWidget          *combo;
 
199
  GtkWidget          *scrolled_window;
 
200
  GtkWidget          *text_view;
 
201
  GtkTextBuffer      *text_buffer;
 
202
  GList              *focus_chain = NULL;
 
203
  gchar              *text;
 
204
 
 
205
  object = G_OBJECT_CLASS (parent_class)->constructor (type, n_params, params);
 
206
 
 
207
  editor = GIMP_TEMPLATE_EDITOR (object);
 
208
 
 
209
  g_assert (editor->template != NULL);
 
210
 
 
211
  gtk_box_set_spacing (GTK_BOX (editor), 12);
 
212
 
 
213
  /*  Image size frame  */
 
214
  frame = gimp_frame_new (_("Image Size"));
 
215
  gtk_box_pack_start (GTK_BOX (editor), frame, FALSE, FALSE, 0);
 
216
  gtk_widget_show (frame);
 
217
 
 
218
  table = gtk_table_new (3, 2, FALSE);
 
219
  gtk_table_set_col_spacing (GTK_TABLE (table), 0, 6);
 
220
  gtk_table_set_row_spacings (GTK_TABLE (table), 6);
 
221
  gtk_table_set_row_spacing (GTK_TABLE (table), 0, 2);
 
222
  gtk_container_add (GTK_CONTAINER (frame), table);
 
223
  gtk_widget_show (table);
 
224
 
 
225
  width = gimp_spin_button_new (&adjustment,
 
226
                                1, 1, 1, 1, 10, 0,
 
227
                                1, 2);
 
228
  gtk_entry_set_width_chars (GTK_ENTRY (width), SB_WIDTH);
 
229
 
 
230
  height = gimp_spin_button_new (&adjustment,
 
231
                                 1, 1, 1, 1, 10, 0,
 
232
                                 1, 2);
 
233
  gtk_entry_set_width_chars (GTK_ENTRY (height), SB_WIDTH);
 
234
 
 
235
  /*  the image size labels  */
 
236
  label = gtk_label_new_with_mnemonic (_("_Width:"));
 
237
  gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
 
238
  gtk_label_set_mnemonic_widget (GTK_LABEL (label), width);
 
239
  gtk_table_attach (GTK_TABLE (table), label, 0, 1, 0, 1,
 
240
                    GTK_SHRINK | GTK_FILL, GTK_SHRINK | GTK_FILL, 0, 0);
 
241
  gtk_widget_show (label);
 
242
 
 
243
  label = gtk_label_new_with_mnemonic (_("H_eight:"));
 
244
  gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
 
245
  gtk_label_set_mnemonic_widget (GTK_LABEL (label), height);
 
246
  gtk_table_attach (GTK_TABLE (table), label, 0, 1, 1, 2,
 
247
                    GTK_SHRINK | GTK_FILL, GTK_SHRINK | GTK_FILL, 0, 0);
 
248
  gtk_widget_show (label);
 
249
 
 
250
  /*  create the sizeentry which keeps it all together  */
 
251
  hbox = gtk_hbox_new (FALSE, 0);
 
252
  gtk_table_attach_defaults (GTK_TABLE (table), hbox, 1, 2, 0, 2);
 
253
  gtk_widget_show (hbox);
 
254
 
 
255
  editor->size_se = gimp_size_entry_new (0, editor->template->unit,_("%p"),
 
256
                                         TRUE, FALSE, FALSE, SB_WIDTH,
 
257
                                         GIMP_SIZE_ENTRY_UPDATE_SIZE);
 
258
 
 
259
  gtk_table_set_row_spacing (GTK_TABLE (editor->size_se), 0, 2);
 
260
  gtk_table_set_col_spacing (GTK_TABLE (editor->size_se), 1, 6);
 
261
 
 
262
  gtk_box_pack_start (GTK_BOX (hbox), editor->size_se, FALSE, FALSE, 0);
 
263
  gtk_widget_show (editor->size_se);
 
264
 
 
265
  gimp_size_entry_add_field (GIMP_SIZE_ENTRY (editor->size_se),
 
266
                             GTK_SPIN_BUTTON (height), NULL);
 
267
  gtk_table_attach_defaults (GTK_TABLE (editor->size_se), height, 0, 1, 1, 2);
 
268
  gtk_widget_show (height);
 
269
 
 
270
  gimp_size_entry_add_field (GIMP_SIZE_ENTRY (editor->size_se),
 
271
                             GTK_SPIN_BUTTON (width), NULL);
 
272
  gtk_table_attach_defaults (GTK_TABLE (editor->size_se), width, 0, 1, 0, 1);
 
273
  gtk_widget_show (width);
 
274
 
 
275
  gimp_prop_coordinates_connect (G_OBJECT (editor->template),
 
276
                                 "width", "height", "unit",
 
277
                                 editor->size_se, NULL,
 
278
                                 editor->template->xresolution,
 
279
                                 editor->template->yresolution);
 
280
 
 
281
  hbox = gtk_hbox_new (FALSE, 12);
 
282
  gtk_table_attach_defaults (GTK_TABLE (table), hbox, 1, 3, 2, 3);
 
283
  gtk_widget_show (hbox);
 
284
 
 
285
  vbox = gtk_vbox_new (0, FALSE);
 
286
  gtk_box_pack_start (GTK_BOX (hbox), vbox, FALSE, FALSE, 0);
 
287
  gtk_widget_show (vbox);
 
288
 
 
289
  aspect_box = gimp_enum_stock_box_new (GIMP_TYPE_ASPECT_TYPE,
 
290
                                        "gimp", GTK_ICON_SIZE_MENU,
 
291
                                        G_CALLBACK (gimp_template_editor_aspect_callback),
 
292
                                        editor,
 
293
                                        &editor->aspect_button);
 
294
  gtk_widget_hide (editor->aspect_button); /* hide "square" */
 
295
 
 
296
  gtk_box_pack_start (GTK_BOX (vbox), aspect_box, FALSE, FALSE, 0);
 
297
  gtk_widget_show (aspect_box);
 
298
 
 
299
  vbox = gtk_vbox_new (2, FALSE);
 
300
  gtk_box_pack_start (GTK_BOX (hbox), vbox, TRUE, TRUE, 0);
 
301
  gtk_widget_show (vbox);
 
302
 
 
303
  editor->pixel_label = gtk_label_new (NULL);
 
304
  gimp_label_set_attributes (GTK_LABEL (editor->pixel_label),
 
305
                             PANGO_ATTR_SCALE,  PANGO_SCALE_SMALL,
 
306
                             -1);
 
307
  gtk_misc_set_alignment (GTK_MISC (editor->pixel_label), 0.0, 0.0);
 
308
  gtk_box_pack_start (GTK_BOX (vbox), editor->pixel_label, FALSE, FALSE, 0);
 
309
  gtk_widget_show (editor->pixel_label);
 
310
 
 
311
  editor->more_label = gtk_label_new (NULL);
 
312
  gimp_label_set_attributes (GTK_LABEL (editor->more_label),
 
313
                             PANGO_ATTR_SCALE,  PANGO_SCALE_SMALL,
 
314
                             -1);
 
315
  gtk_misc_set_alignment (GTK_MISC (editor->more_label), 0.0, 0.0);
 
316
  gtk_box_pack_start (GTK_BOX (vbox), editor->more_label, FALSE, FALSE, 0);
 
317
  gtk_widget_show (editor->more_label);
 
318
 
 
319
#ifdef ENABLE_MEMSIZE_LABEL
 
320
  editor->memsize_label = gtk_label_new (NULL);
 
321
  gimp_label_set_attributes (GTK_LABEL (editor->memsize_label),
 
322
                             PANGO_ATTR_SCALE,  PANGO_SCALE_SMALL,
 
323
                             PANGO_ATTR_WEIGHT, PANGO_WEIGHT_BOLD,
 
324
                             -1);
 
325
  gtk_misc_set_alignment (GTK_MISC (editor->memsize_label), 0.0, 0.0);
 
326
  gtk_box_pack_start (GTK_BOX (vbox), editor->memsize_label, FALSE, FALSE, 0);
 
327
  gtk_widget_show (editor->memsize_label);
 
328
#endif
 
329
 
 
330
  text = g_strdup_printf ("<b>%s</b>", _("_Advanced Options"));
 
331
  editor->expander = g_object_new (GTK_TYPE_EXPANDER,
 
332
                                   "label",         text,
 
333
                                   "use_markup",    TRUE,
 
334
                                   "use_underline", TRUE,
 
335
                                   NULL);
 
336
  g_free (text);
 
337
 
 
338
  gtk_box_pack_start (GTK_BOX (editor), editor->expander, TRUE, TRUE, 0);
 
339
  gtk_widget_show (editor->expander);
 
340
 
 
341
  frame = gimp_frame_new ("<expander>");
 
342
  gtk_container_add (GTK_CONTAINER (editor->expander), frame);
 
343
  gtk_widget_show (frame);
 
344
 
 
345
  table = gtk_table_new (5, 2, FALSE);
 
346
  gtk_table_set_col_spacing (GTK_TABLE (table), 0, 6);
 
347
  gtk_table_set_row_spacings (GTK_TABLE (table), 6);
 
348
  gtk_table_set_row_spacing (GTK_TABLE (table), 0, 2);
 
349
  gtk_container_add (GTK_CONTAINER (frame), table);
 
350
  gtk_widget_show (table);
 
351
 
 
352
  xres = gimp_spin_button_new (&adjustment,
 
353
                               1, 1, 1, 1, 10, 0,
 
354
                               1, 2);
 
355
  gtk_entry_set_width_chars (GTK_ENTRY (xres), SB_WIDTH);
 
356
 
 
357
  yres = gimp_spin_button_new (&adjustment,
 
358
                               1, 1, 1, 1, 10, 0,
 
359
                               1, 2);
 
360
  gtk_entry_set_width_chars (GTK_ENTRY (yres), SB_WIDTH);
 
361
 
 
362
  /*  the resolution labels  */
 
363
  label = gtk_label_new_with_mnemonic (_("_X resolution:"));
 
364
  gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
 
365
  gtk_label_set_mnemonic_widget (GTK_LABEL (label), xres);
 
366
  gtk_table_attach (GTK_TABLE (table), label, 0, 1, 0, 1,
 
367
                    GTK_SHRINK | GTK_FILL, GTK_SHRINK | GTK_FILL, 0, 0);
 
368
  gtk_widget_show (label);
 
369
 
 
370
  label = gtk_label_new_with_mnemonic (_("_Y resolution:"));
 
371
  gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
 
372
  gtk_label_set_mnemonic_widget (GTK_LABEL (label), yres);
 
373
  gtk_table_attach (GTK_TABLE (table), label, 0, 1, 1, 2,
 
374
                    GTK_SHRINK | GTK_FILL, GTK_SHRINK | GTK_FILL, 0, 0);
 
375
  gtk_widget_show (label);
 
376
 
 
377
  /*  the resolution sizeentry  */
 
378
  hbox = gtk_hbox_new (FALSE, 0);
 
379
  gtk_table_attach_defaults (GTK_TABLE (table), hbox, 1, 2, 0, 2);
 
380
  gtk_widget_show (hbox);
 
381
 
 
382
  editor->resolution_se =
 
383
    gimp_size_entry_new (0, editor->template->resolution_unit, _("pixels/%a"),
 
384
                         FALSE, FALSE, FALSE, SB_WIDTH,
 
385
                         GIMP_SIZE_ENTRY_UPDATE_RESOLUTION);
 
386
 
 
387
  gtk_table_set_row_spacing (GTK_TABLE (editor->resolution_se), 0, 2);
 
388
  gtk_table_set_col_spacing (GTK_TABLE (editor->resolution_se), 1, 2);
 
389
  gtk_table_set_col_spacing (GTK_TABLE (editor->resolution_se), 2, 2);
 
390
 
 
391
  gtk_box_pack_start (GTK_BOX (hbox), editor->resolution_se, FALSE, FALSE, 0);
 
392
  gtk_widget_show (editor->resolution_se);
 
393
 
 
394
  gimp_size_entry_add_field (GIMP_SIZE_ENTRY (editor->resolution_se),
 
395
                             GTK_SPIN_BUTTON (yres), NULL);
 
396
  gtk_table_attach_defaults (GTK_TABLE (editor->resolution_se), yres,
 
397
                             0, 1, 1, 2);
 
398
  gtk_widget_show (yres);
 
399
 
 
400
  gimp_size_entry_add_field (GIMP_SIZE_ENTRY (editor->resolution_se),
 
401
                             GTK_SPIN_BUTTON (xres), NULL);
 
402
  gtk_table_attach_defaults (GTK_TABLE (editor->resolution_se), xres,
 
403
                             0, 1, 0, 1);
 
404
  gtk_widget_show (xres);
 
405
 
 
406
  gimp_size_entry_set_resolution (GIMP_SIZE_ENTRY (editor->size_se), 0,
 
407
                                  editor->template->xresolution, FALSE);
 
408
  gimp_size_entry_set_resolution (GIMP_SIZE_ENTRY (editor->size_se), 1,
 
409
                                  editor->template->yresolution, FALSE);
 
410
 
 
411
  /*  the resolution chainbutton  */
 
412
  chainbutton = gimp_chain_button_new (GIMP_CHAIN_RIGHT);
 
413
  gtk_table_attach_defaults (GTK_TABLE (editor->resolution_se), chainbutton,
 
414
                             1, 2, 0, 2);
 
415
  gtk_widget_show (chainbutton);
 
416
 
 
417
  gimp_prop_coordinates_connect (G_OBJECT (editor->template),
 
418
                                 "xresolution", "yresolution",
 
419
                                 "resolution-unit",
 
420
                                 editor->resolution_se, chainbutton,
 
421
                                 1.0, 1.0);
 
422
 
 
423
  focus_chain = g_list_prepend (focus_chain,
 
424
                                GIMP_SIZE_ENTRY (editor->resolution_se)->unitmenu);
 
425
  focus_chain = g_list_prepend (focus_chain, chainbutton);
 
426
  focus_chain = g_list_prepend (focus_chain, yres);
 
427
  focus_chain = g_list_prepend (focus_chain, xres);
 
428
 
 
429
  gtk_container_set_focus_chain (GTK_CONTAINER (editor->resolution_se),
 
430
                                 focus_chain);
 
431
  g_list_free (focus_chain);
 
432
 
 
433
  combo = gimp_prop_enum_combo_box_new (G_OBJECT (editor->template),
 
434
                                        "image-type",
 
435
                                        GIMP_RGB, GIMP_GRAY);
 
436
  gimp_table_attach_aligned (GTK_TABLE (table), 0, 2,
 
437
                             _("Color_space:"), 0.0, 0.5,
 
438
                             combo, 1, FALSE);
 
439
 
 
440
  combo = gimp_prop_enum_combo_box_new (G_OBJECT (editor->template),
 
441
                                        "fill-type",
 
442
                                        GIMP_FOREGROUND_FILL,
 
443
                                        GIMP_TRANSPARENT_FILL);
 
444
  gimp_table_attach_aligned (GTK_TABLE (table), 0, 3,
 
445
                             _("_Fill with:"), 0.0, 0.5,
 
446
                             combo, 1, FALSE);
 
447
 
 
448
  scrolled_window = gtk_scrolled_window_new (NULL, NULL);
 
449
  gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (scrolled_window),
 
450
                                       GTK_SHADOW_IN);
 
451
  gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled_window),
 
452
                                  GTK_POLICY_AUTOMATIC,
 
453
                                  GTK_POLICY_AUTOMATIC);
 
454
  gimp_table_attach_aligned (GTK_TABLE (table), 0, 4,
 
455
                             _("Comme_nt:"), 0.0, 0.0,
 
456
                             scrolled_window, 1, FALSE);
 
457
 
 
458
  text_buffer = gimp_prop_text_buffer_new (G_OBJECT (editor->template),
 
459
                                           "comment", MAX_COMMENT_LENGTH);
 
460
 
 
461
  text_view = gtk_text_view_new_with_buffer (text_buffer);
 
462
  g_object_unref (text_buffer);
 
463
 
 
464
  gtk_text_view_set_wrap_mode (GTK_TEXT_VIEW (text_view), GTK_WRAP_WORD);
 
465
  gtk_container_add (GTK_CONTAINER (scrolled_window), text_view);
 
466
  gtk_widget_show (text_view);
 
467
 
 
468
  g_signal_connect_object (editor->template, "notify",
 
469
                           G_CALLBACK (gimp_template_editor_template_notify),
 
470
                           editor, 0);
 
471
 
 
472
  /*  call the notify callback once to get the labels set initially  */
 
473
  gimp_template_editor_template_notify (editor->template, NULL, editor);
 
474
 
 
475
  return object;
 
476
}
 
477
 
 
478
static void
 
479
gimp_template_editor_finalize (GObject *object)
 
480
{
 
481
  GimpTemplateEditor *editor = GIMP_TEMPLATE_EDITOR (object);
 
482
 
 
483
  if (editor->template)
 
484
    {
 
485
      g_object_unref (editor->template);
 
486
      editor->template = NULL;
 
487
    }
 
488
 
 
489
  if (editor->stock_id_container)
 
490
    {
 
491
      g_object_unref (editor->stock_id_container);
 
492
      editor->stock_id_container = NULL;
 
493
    }
 
494
 
 
495
  if (editor->stock_id_context)
 
496
    {
 
497
      g_object_unref (editor->stock_id_context);
 
498
      editor->stock_id_context = NULL;
 
499
    }
 
500
 
 
501
  G_OBJECT_CLASS (parent_class)->finalize (object);
 
502
}
 
503
 
 
504
GtkWidget *
 
505
gimp_template_editor_new (GimpTemplate *template,
 
506
                          Gimp         *gimp,
 
507
                          gboolean      edit_template)
 
508
{
 
509
  GimpTemplateEditor *editor;
 
510
 
 
511
  g_return_val_if_fail (!edit_template || GIMP_IS_GIMP (gimp), NULL);
 
512
 
 
513
  editor = g_object_new (GIMP_TYPE_TEMPLATE_EDITOR,
 
514
                         "template", template,
 
515
                         NULL);
 
516
 
 
517
  if (edit_template)
 
518
    {
 
519
      GtkWidget   *table;
 
520
      GtkWidget   *entry;
 
521
      GtkWidget   *button;
 
522
      GSList      *stock_list;
 
523
      GSList      *list;
 
524
      const gchar *stock_id;
 
525
 
 
526
      stock_id = gimp_viewable_get_stock_id (GIMP_VIEWABLE (editor->template));
 
527
 
 
528
      editor->stock_id_container = gimp_list_new (GIMP_TYPE_TEMPLATE, FALSE);
 
529
      editor->stock_id_context = gimp_context_new (gimp, "foo", NULL);
 
530
 
 
531
      g_signal_connect (editor->stock_id_context, "template_changed",
 
532
                        G_CALLBACK (gimp_template_editor_icon_changed),
 
533
                        editor);
 
534
 
 
535
      stock_list = gtk_stock_list_ids ();
 
536
 
 
537
      for (list = stock_list; list; list = g_slist_next (list))
 
538
        {
 
539
          GimpObject *object = g_object_new (GIMP_TYPE_TEMPLATE,
 
540
                                             "name",     list->data,
 
541
                                             "stock-id", list->data,
 
542
                                             NULL);
 
543
 
 
544
          gimp_container_add (editor->stock_id_container, object);
 
545
          g_object_unref (object);
 
546
 
 
547
          if (strcmp (list->data, stock_id) == 0)
 
548
            gimp_context_set_template (editor->stock_id_context,
 
549
                                       GIMP_TEMPLATE (object));
 
550
        }
 
551
 
 
552
      g_slist_foreach (stock_list, (GFunc) g_free, NULL);
 
553
      g_slist_free (stock_list);
 
554
 
 
555
      table = gtk_table_new (2, 2, FALSE);
 
556
      gtk_table_set_col_spacings (GTK_TABLE (table), 6);
 
557
      gtk_table_set_row_spacings (GTK_TABLE (table), 6);
 
558
      gtk_box_pack_start (GTK_BOX (editor), table, FALSE, FALSE, 0);
 
559
      gtk_box_reorder_child (GTK_BOX (editor), table, 0);
 
560
      gtk_widget_show (table);
 
561
 
 
562
      entry = gimp_prop_entry_new (G_OBJECT (editor->template), "name", 128);
 
563
 
 
564
      gimp_table_attach_aligned (GTK_TABLE (table), 0, 0,
 
565
                                 _("_Name:"), 1.0, 0.5,
 
566
                                 entry, 1, FALSE);
 
567
 
 
568
      button = gimp_viewable_button_new (editor->stock_id_container,
 
569
                                         editor->stock_id_context,
 
570
                                         GIMP_VIEW_SIZE_SMALL, 0,
 
571
                                         NULL, NULL, NULL, NULL);
 
572
      gimp_viewable_button_set_view_type (GIMP_VIEWABLE_BUTTON (button),
 
573
                                          GIMP_VIEW_TYPE_GRID);
 
574
 
 
575
      gimp_table_attach_aligned (GTK_TABLE (table), 0, 1,
 
576
                                 _("_Icon:"), 1.0, 0.5,
 
577
                                 button, 1, TRUE);
 
578
    }
 
579
 
 
580
  return GTK_WIDGET (editor);
 
581
}
 
582
 
 
583
void
 
584
gimp_template_editor_show_advanced (GimpTemplateEditor *editor,
 
585
                                    gboolean            expanded)
 
586
{
 
587
  g_return_if_fail (GIMP_IS_TEMPLATE_EDITOR (editor));
 
588
 
 
589
  gtk_expander_set_expanded (GTK_EXPANDER (editor->expander), expanded);
 
590
}
 
591
 
 
592
 
 
593
/*  private functions  */
 
594
 
 
595
static void
 
596
gimp_template_editor_aspect_callback (GtkWidget          *widget,
 
597
                                      GimpTemplateEditor *editor)
 
598
{
 
599
  if (! editor->block_aspect && GTK_TOGGLE_BUTTON (widget)->active)
 
600
    {
 
601
      GimpTemplate *template    = editor->template;
 
602
      gint          width       = template->width;
 
603
      gint          height      = template->height;
 
604
      gdouble       xresolution = template->xresolution;
 
605
      gdouble       yresolution = template->yresolution;
 
606
      gchar        *text;
 
607
 
 
608
      if (template->width == template->height)
 
609
        {
 
610
          editor->block_aspect = TRUE;
 
611
          gimp_int_radio_group_set_active (GTK_RADIO_BUTTON (editor->aspect_button),
 
612
                                           GIMP_ASPECT_SQUARE);
 
613
          editor->block_aspect = FALSE;
 
614
          return;
 
615
       }
 
616
 
 
617
      g_signal_handlers_block_by_func (template,
 
618
                                       gimp_template_editor_template_notify,
 
619
                                       editor);
 
620
 
 
621
      gimp_size_entry_set_resolution (GIMP_SIZE_ENTRY (editor->size_se), 0,
 
622
                                      yresolution, FALSE);
 
623
      gimp_size_entry_set_resolution (GIMP_SIZE_ENTRY (editor->size_se), 1,
 
624
                                      xresolution, FALSE);
 
625
 
 
626
      g_object_set (template,
 
627
                    "width",       height,
 
628
                    "height",      width,
 
629
                    "xresolution", yresolution,
 
630
                    "yresolution", xresolution,
 
631
                    NULL);
 
632
 
 
633
      g_signal_handlers_unblock_by_func (template,
 
634
                                         gimp_template_editor_template_notify,
 
635
                                         editor);
 
636
 
 
637
      text = g_strdup_printf (_("%d x %d pixels"),
 
638
                              template->width, template->height);
 
639
      gtk_label_set_text (GTK_LABEL (editor->pixel_label), text);
 
640
      g_free (text);
 
641
    }
 
642
}
 
643
 
 
644
static void
 
645
gimp_template_editor_template_notify (GimpTemplate       *template,
 
646
                                      GParamSpec         *param_spec,
 
647
                                      GimpTemplateEditor *editor)
 
648
{
 
649
  GimpAspectType  aspect;
 
650
  const gchar    *desc;
 
651
  gchar          *text;
 
652
  gint            xres;
 
653
  gint            yres;
 
654
 
 
655
  if (param_spec)
 
656
    {
 
657
      if (! strcmp (param_spec->name, "xresolution"))
 
658
        {
 
659
          gimp_size_entry_set_resolution (GIMP_SIZE_ENTRY (editor->size_se), 0,
 
660
                                          template->xresolution, FALSE);
 
661
        }
 
662
      else if (! strcmp (param_spec->name, "yresolution"))
 
663
        {
 
664
          gimp_size_entry_set_resolution (GIMP_SIZE_ENTRY (editor->size_se), 1,
 
665
                                          template->yresolution, FALSE);
 
666
        }
 
667
    }
 
668
 
 
669
#ifdef ENABLE_MEMSIZE_LABEL
 
670
  text = gimp_memsize_to_string (template->initial_size);
 
671
  gtk_label_set_text (GTK_LABEL (editor->memsize_label), text);
 
672
  g_free (text);
 
673
#endif
 
674
 
 
675
  text = g_strdup_printf (_("%d x %d pixels"),
 
676
                          template->width, template->height);
 
677
  gtk_label_set_text (GTK_LABEL (editor->pixel_label), text);
 
678
  g_free (text);
 
679
 
 
680
  if (template->width > template->height)
 
681
    aspect = GIMP_ASPECT_LANDSCAPE;
 
682
  else if (template->height > template->width)
 
683
    aspect = GIMP_ASPECT_PORTRAIT;
 
684
  else
 
685
    aspect = GIMP_ASPECT_SQUARE;
 
686
 
 
687
  editor->block_aspect = TRUE;
 
688
  gimp_int_radio_group_set_active (GTK_RADIO_BUTTON (editor->aspect_button),
 
689
                                   aspect);
 
690
  editor->block_aspect = FALSE;
 
691
 
 
692
  gimp_enum_get_value (GIMP_TYPE_IMAGE_BASE_TYPE, template->image_type,
 
693
                       NULL, NULL, &desc, NULL);
 
694
 
 
695
  xres = ROUND (template->xresolution);
 
696
  yres = ROUND (template->yresolution);
 
697
 
 
698
  if (xres != yres)
 
699
    text = g_strdup_printf (_("%d x %d dpi, %s"), xres, yres, desc);
 
700
  else
 
701
    text = g_strdup_printf (_("%d dpi, %s"), yres, desc);
 
702
 
 
703
  gtk_label_set_text (GTK_LABEL (editor->more_label), text);
 
704
  g_free (text);
 
705
 
 
706
  if (editor->stock_id_container)
 
707
    {
 
708
      GimpObject  *object;
 
709
      const gchar *stock_id;
 
710
 
 
711
      stock_id = gimp_viewable_get_stock_id (GIMP_VIEWABLE (template));
 
712
 
 
713
      object = gimp_container_get_child_by_name (editor->stock_id_container,
 
714
                                                 stock_id);
 
715
 
 
716
      gimp_context_set_template (editor->stock_id_context,
 
717
                                 (GimpTemplate *) object);
 
718
    }
 
719
}
 
720
 
 
721
static void
 
722
gimp_template_editor_icon_changed (GimpContext        *context,
 
723
                                   GimpTemplate       *template,
 
724
                                   GimpTemplateEditor *editor)
 
725
{
 
726
  g_object_set (editor->template,
 
727
                "stock-id", GIMP_OBJECT (template)->name,
 
728
                NULL);
 
729
}