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

« back to all changes in this revision

Viewing changes to app/widgets/gimpviewabledialog.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
 
1
/* GIMP - The GNU Image Manipulation Program
2
2
 * Copyright (C) 1995 Spencer Kimball and Peter Mattis
3
3
 *
4
4
 * gimpviewabledialog.c
27
27
 
28
28
#include "widgets-types.h"
29
29
 
 
30
#include "core/gimpcontext.h"
30
31
#include "core/gimpimage.h"
31
32
#include "core/gimpitem.h"
32
33
 
34
35
 
35
36
#include "gimpview.h"
36
37
#include "gimpviewabledialog.h"
 
38
#include "gimpviewrenderer.h"
37
39
 
38
40
 
39
41
enum
40
42
{
41
43
  PROP_0,
 
44
  PROP_VIEWABLE,
 
45
  PROP_CONTEXT,
42
46
  PROP_STOCK_ID,
43
47
  PROP_DESC,
44
48
  PROP_PARENT
45
49
};
46
50
 
47
51
 
48
 
static void   gimp_viewable_dialog_class_init (GimpViewableDialogClass *klass);
49
 
static void   gimp_viewable_dialog_init       (GimpViewableDialog      *dialog);
50
 
 
51
52
static void   gimp_viewable_dialog_set_property (GObject            *object,
52
53
                                                 guint               property_id,
53
54
                                                 const GValue       *value,
54
55
                                                 GParamSpec         *pspec);
 
56
static void   gimp_viewable_dialog_get_property (GObject            *object,
 
57
                                                 guint               property_id,
 
58
                                                 GValue             *value,
 
59
                                                 GParamSpec         *pspec);
55
60
 
56
61
static void   gimp_viewable_dialog_destroy      (GtkObject          *object);
57
62
 
60
65
static void   gimp_viewable_dialog_close        (GimpViewableDialog *dialog);
61
66
 
62
67
 
63
 
static GimpDialogClass *parent_class = NULL;
64
 
 
65
 
 
66
 
GType
67
 
gimp_viewable_dialog_get_type (void)
68
 
{
69
 
  static GType dialog_type = 0;
70
 
 
71
 
  if (! dialog_type)
72
 
    {
73
 
      static const GTypeInfo dialog_info =
74
 
      {
75
 
        sizeof (GimpViewableDialogClass),
76
 
        (GBaseInitFunc) NULL,
77
 
        (GBaseFinalizeFunc) NULL,
78
 
        (GClassInitFunc) gimp_viewable_dialog_class_init,
79
 
        NULL,           /* class_finalize */
80
 
        NULL,           /* class_data     */
81
 
        sizeof (GimpViewableDialog),
82
 
        0,              /* n_preallocs    */
83
 
        (GInstanceInitFunc) gimp_viewable_dialog_init,
84
 
      };
85
 
 
86
 
      dialog_type = g_type_register_static (GIMP_TYPE_DIALOG,
87
 
                                            "GimpViewableDialog",
88
 
                                            &dialog_info, 0);
89
 
    }
90
 
 
91
 
  return dialog_type;
92
 
}
 
68
G_DEFINE_TYPE (GimpViewableDialog, gimp_viewable_dialog, GIMP_TYPE_DIALOG)
 
69
 
 
70
#define parent_class gimp_viewable_dialog_parent_class
 
71
 
93
72
 
94
73
static void
95
74
gimp_viewable_dialog_class_init (GimpViewableDialogClass *klass)
96
75
{
97
 
  GtkObjectClass *gtk_object_class;
98
 
  GObjectClass   *object_class;
99
 
 
100
 
  gtk_object_class = GTK_OBJECT_CLASS (klass);
101
 
  object_class     = G_OBJECT_CLASS (klass);
102
 
 
103
 
  parent_class = g_type_class_peek_parent (klass);
104
 
 
105
 
  gtk_object_class->destroy = gimp_viewable_dialog_destroy;
106
 
 
 
76
  GtkObjectClass *gtk_object_class = GTK_OBJECT_CLASS (klass);
 
77
  GObjectClass   *object_class     = G_OBJECT_CLASS (klass);
 
78
 
 
79
  gtk_object_class->destroy  = gimp_viewable_dialog_destroy;
 
80
 
 
81
  object_class->get_property = gimp_viewable_dialog_get_property;
107
82
  object_class->set_property = gimp_viewable_dialog_set_property;
108
83
 
 
84
  g_object_class_install_property (object_class, PROP_VIEWABLE,
 
85
                                   g_param_spec_object ("viewable", NULL, NULL,
 
86
                                                        GIMP_TYPE_VIEWABLE,
 
87
                                                        GIMP_PARAM_READWRITE));
 
88
  g_object_class_install_property (object_class, PROP_CONTEXT,
 
89
                                   g_param_spec_object ("context", NULL, NULL,
 
90
                                                        GIMP_TYPE_CONTEXT,
 
91
                                                        GIMP_PARAM_READWRITE));
109
92
  g_object_class_install_property (object_class, PROP_STOCK_ID,
110
93
                                   g_param_spec_string ("stock-id", NULL, NULL,
111
94
                                                        NULL,
112
 
                                                        G_PARAM_WRITABLE |
 
95
                                                        GIMP_PARAM_WRITABLE |
113
96
                                                        G_PARAM_CONSTRUCT_ONLY));
114
97
  g_object_class_install_property (object_class, PROP_DESC,
115
98
                                   g_param_spec_string ("description", NULL, NULL,
116
99
                                                        NULL,
117
 
                                                        G_PARAM_WRITABLE |
 
100
                                                        GIMP_PARAM_WRITABLE |
118
101
                                                        G_PARAM_CONSTRUCT));
119
102
  g_object_class_install_property (object_class, PROP_PARENT,
120
103
                                   g_param_spec_object ("parent", NULL, NULL,
121
104
                                                        GTK_TYPE_WIDGET,
122
 
                                                        G_PARAM_WRITABLE |
 
105
                                                        GIMP_PARAM_WRITABLE |
123
106
                                                        G_PARAM_CONSTRUCT_ONLY));
124
107
}
125
108
 
159
142
  gtk_box_pack_start (GTK_BOX (vbox), dialog->desc_label, FALSE, FALSE, 0);
160
143
  gtk_widget_show (dialog->desc_label);
161
144
 
162
 
  dialog->viewable_label = gtk_label_new (NULL);
163
 
  gtk_misc_set_alignment (GTK_MISC (dialog->viewable_label), 0.0, 0.5);
 
145
  dialog->viewable_label = g_object_new (GTK_TYPE_LABEL,
 
146
                                         "xalign",    0.0,
 
147
                                         "yalign",    0.5,
 
148
                                         "ellipsize", PANGO_ELLIPSIZE_END,
 
149
                                         NULL);
164
150
  gimp_label_set_attributes (GTK_LABEL (dialog->viewable_label),
165
151
                             PANGO_ATTR_SCALE,  PANGO_SCALE_SMALL,
166
152
                             -1);
178
164
 
179
165
  switch (property_id)
180
166
    {
 
167
    case PROP_VIEWABLE:
 
168
      gimp_viewable_dialog_set_viewable (dialog,
 
169
                                         g_value_get_object (value),
 
170
                                         dialog->context);
 
171
      break;
 
172
    case PROP_CONTEXT:
 
173
      gimp_viewable_dialog_set_viewable (dialog,
 
174
                                         dialog->view ?
 
175
                                         GIMP_VIEW (dialog->view)->viewable :
 
176
                                         NULL,
 
177
                                         g_value_get_object (value));
 
178
      break;
181
179
    case PROP_STOCK_ID:
182
180
      gtk_image_set_from_stock (GTK_IMAGE (dialog->icon),
183
181
                                g_value_get_string (value),
209
207
}
210
208
 
211
209
static void
 
210
gimp_viewable_dialog_get_property (GObject    *object,
 
211
                                   guint       property_id,
 
212
                                   GValue     *value,
 
213
                                   GParamSpec *pspec)
 
214
{
 
215
  GimpViewableDialog *dialog = GIMP_VIEWABLE_DIALOG (object);
 
216
 
 
217
  switch (property_id)
 
218
    {
 
219
    case PROP_VIEWABLE:
 
220
      g_value_set_object (value,
 
221
                          dialog->view ?
 
222
                          GIMP_VIEW (dialog->view)->viewable : NULL);
 
223
      break;
 
224
    case PROP_CONTEXT:
 
225
      g_value_set_object (value, dialog->context);
 
226
      break;
 
227
    default:
 
228
      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
 
229
      break;
 
230
    }
 
231
}
 
232
 
 
233
static void
212
234
gimp_viewable_dialog_destroy (GtkObject *object)
213
235
{
214
236
  GimpViewableDialog *dialog = GIMP_VIEWABLE_DIALOG (object);
215
237
 
216
 
  if (dialog->preview)
217
 
    gimp_viewable_dialog_set_viewable (dialog, NULL);
 
238
  if (dialog->view)
 
239
    gimp_viewable_dialog_set_viewable (dialog, NULL, NULL);
218
240
 
219
241
  GTK_OBJECT_CLASS (parent_class)->destroy (object);
220
242
}
221
243
 
222
244
GtkWidget *
223
245
gimp_viewable_dialog_new (GimpViewable *viewable,
 
246
                          GimpContext  *context,
224
247
                          const gchar  *title,
225
248
                          const gchar  *role,
226
249
                          const gchar  *stock_id,
233
256
  GimpViewableDialog *dialog;
234
257
  va_list             args;
235
258
 
236
 
  g_return_val_if_fail (! viewable || GIMP_IS_VIEWABLE (viewable), NULL);
 
259
  g_return_val_if_fail (viewable == NULL || GIMP_IS_VIEWABLE (viewable), NULL);
 
260
  g_return_val_if_fail (context == NULL || GIMP_IS_CONTEXT (context), NULL);
237
261
  g_return_val_if_fail (title != NULL, NULL);
238
262
  g_return_val_if_fail (role != NULL, NULL);
239
263
  g_return_val_if_fail (parent == NULL || GTK_IS_WIDGET (parent), NULL);
240
264
 
 
265
  if (! viewable)
 
266
    g_warning ("Use of GimpViewableDialog with a NULL viewable is depecrated!");
 
267
 
241
268
  dialog = g_object_new (GIMP_TYPE_VIEWABLE_DIALOG,
 
269
                         "viewable",    viewable,
 
270
                         "context",     context,
242
271
                         "title",       title,
243
272
                         "role",        role,
244
273
                         "help-func",   help_func,
252
281
  gimp_dialog_add_buttons_valist (GIMP_DIALOG (dialog), args);
253
282
  va_end (args);
254
283
 
255
 
  if (viewable)
256
 
    gimp_viewable_dialog_set_viewable (dialog, viewable);
257
 
 
258
284
  return GTK_WIDGET (dialog);
259
285
}
260
286
 
261
287
void
262
288
gimp_viewable_dialog_set_viewable (GimpViewableDialog *dialog,
263
 
                                   GimpViewable       *viewable)
 
289
                                   GimpViewable       *viewable,
 
290
                                   GimpContext        *context)
264
291
{
265
292
  g_return_if_fail (GIMP_IS_VIEWABLE_DIALOG (dialog));
266
 
  g_return_if_fail (! viewable || GIMP_IS_VIEWABLE (viewable));
267
 
 
268
 
  if (dialog->preview)
 
293
  g_return_if_fail (viewable == NULL || GIMP_IS_VIEWABLE (viewable));
 
294
  g_return_if_fail (context == NULL || GIMP_IS_CONTEXT (context));
 
295
 
 
296
  dialog->context = context;
 
297
 
 
298
  if (dialog->view)
269
299
    {
270
 
      GimpViewable *old_viewable;
271
 
 
272
 
      old_viewable = GIMP_VIEW (dialog->preview)->viewable;
 
300
      GimpViewable *old_viewable = GIMP_VIEW (dialog->view)->viewable;
273
301
 
274
302
      if (viewable == old_viewable)
275
 
        return;
 
303
        {
 
304
          gimp_view_renderer_set_context (GIMP_VIEW (dialog->view)->renderer,
 
305
                                          context);
 
306
          return;
 
307
        }
276
308
 
277
 
      gtk_widget_destroy (dialog->preview);
 
309
      gtk_widget_destroy (dialog->view);
278
310
 
279
311
      if (old_viewable)
280
312
        {
296
328
                               dialog,
297
329
                               0);
298
330
 
299
 
      dialog->preview = gimp_view_new (viewable, 32, 1, TRUE);
300
 
      gtk_box_pack_end (GTK_BOX (dialog->icon->parent), dialog->preview,
 
331
      dialog->view = gimp_view_new (context, viewable, 32, 1, TRUE);
 
332
      gtk_box_pack_end (GTK_BOX (dialog->icon->parent), dialog->view,
301
333
                        FALSE, FALSE, 2);
302
 
      gtk_widget_show (dialog->preview);
 
334
      gtk_widget_show (dialog->view);
303
335
 
304
 
      g_object_add_weak_pointer (G_OBJECT (dialog->preview),
305
 
                                 (gpointer *) &dialog->preview);
 
336
      g_object_add_weak_pointer (G_OBJECT (dialog->view),
 
337
                                 (gpointer) &dialog->view);
306
338
 
307
339
      gimp_viewable_dialog_name_changed (GIMP_OBJECT (viewable), dialog);
308
340
 
343
375
      uri = gimp_image_get_uri (gimp_item_get_image (GIMP_ITEM (object)));
344
376
      tmp = name;
345
377
 
346
 
      basename = file_utils_uri_to_utf8_basename (uri);
 
378
      basename = file_utils_uri_display_basename (uri);
347
379
      name = g_strdup_printf ("%s-%d (%s)",
348
380
                              tmp,
349
381
                              gimp_item_get_ID (GIMP_ITEM (object)),