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

« back to all changes in this revision

Viewing changes to app/widgets/gimpsizebox.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
 * gimpsizebox.c
20
20
 */
21
21
 
22
22
#include "config.h"
 
23
 
23
24
#include <stdio.h>
 
25
 
24
26
#include <gtk/gtk.h>
25
27
 
26
28
#include "libgimpbase/gimpbase.h"
 
29
#include "libgimpmath/gimpmath.h"
 
30
#include "libgimpconfig/gimpconfig.h"
27
31
#include "libgimpwidgets/gimpwidgets.h"
28
32
 
29
33
#include "widgets-types.h"
30
34
 
31
 
#include "config/gimpconfig-params.h"
32
 
 
33
 
#include "gimppropwidgets.h"
34
35
#include "gimpsizebox.h"
35
36
 
36
37
#include "gimp-intl.h"
52
53
};
53
54
 
54
55
 
55
 
#define GIMP_SIZE_BOX_GET_PRIVATE(obj) \
56
 
  (G_TYPE_INSTANCE_GET_PRIVATE ((obj), GIMP_TYPE_SIZE_BOX, GimpSizeBoxPrivate))
 
56
#define GIMP_SIZE_BOX_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), \
 
57
                                        GIMP_TYPE_SIZE_BOX, GimpSizeBoxPrivate))
57
58
 
58
59
typedef struct _GimpSizeBoxPrivate GimpSizeBoxPrivate;
59
60
 
67
68
};
68
69
 
69
70
 
70
 
static void      gimp_size_box_class_init    (GimpSizeBoxClass      *klass);
71
 
 
72
71
static GObject * gimp_size_box_constructor   (GType                  type,
73
72
                                              guint                  n_params,
74
73
                                              GObjectConstructParam *params);
75
74
 
76
 
static void      gimp_size_box_init           (GimpSizeBox     *box);
77
 
 
78
 
static void      gimp_size_box_set_property   (GObject         *object,
79
 
                                               guint            property_id,
80
 
                                               const GValue    *value,
81
 
                                               GParamSpec      *pspec);
82
 
static void      gimp_size_box_get_property   (GObject         *object,
83
 
                                               guint            property_id,
84
 
                                               GValue          *value,
85
 
                                               GParamSpec      *pspec);
86
 
 
87
 
static void      gimp_size_box_update_size       (GimpSizeBox *box);
88
 
static void      gimp_size_box_update_resolution (GimpSizeBox *box);
89
 
 
90
 
 
91
 
static GtkVBoxClass *parent_class = NULL;
92
 
 
93
 
 
94
 
GType
95
 
gimp_size_box_get_type (void)
96
 
{
97
 
  static GType box_type = 0;
98
 
 
99
 
  if (! box_type)
100
 
    {
101
 
      static const GTypeInfo box_info =
102
 
      {
103
 
        sizeof (GimpSizeBoxClass),
104
 
        (GBaseInitFunc) NULL,
105
 
        (GBaseFinalizeFunc) NULL,
106
 
        (GClassInitFunc) gimp_size_box_class_init,
107
 
        NULL,           /* class_finalize */
108
 
        NULL,           /* class_data     */
109
 
        sizeof (GimpSizeBox),
110
 
        0,              /* n_preallocs    */
111
 
        (GInstanceInitFunc) gimp_size_box_init
112
 
      };
113
 
 
114
 
      box_type = g_type_register_static (GTK_TYPE_VBOX,
115
 
                                         "GimpSizeBox",
116
 
                                         &box_info, 0);
117
 
    }
118
 
 
119
 
  return box_type;
120
 
}
 
75
static void      gimp_size_box_set_property      (GObject         *object,
 
76
                                                  guint            property_id,
 
77
                                                  const GValue    *value,
 
78
                                                  GParamSpec      *pspec);
 
79
static void      gimp_size_box_get_property      (GObject         *object,
 
80
                                                  guint            property_id,
 
81
                                                  GValue          *value,
 
82
                                                  GParamSpec      *pspec);
 
83
 
 
84
static void      gimp_size_box_destroy           (GtkObject       *object);
 
85
 
 
86
static void      gimp_size_box_update_size       (GimpSizeBox     *box);
 
87
static void      gimp_size_box_update_resolution (GimpSizeBox     *box);
 
88
static void      gimp_size_box_chain_toggled     (GimpChainButton *button,
 
89
                                                  GimpSizeBox     *box);
 
90
 
 
91
 
 
92
G_DEFINE_TYPE (GimpSizeBox, gimp_size_box, GTK_TYPE_VBOX)
 
93
 
 
94
#define parent_class gimp_size_box_parent_class
 
95
 
121
96
 
122
97
static void
123
98
gimp_size_box_class_init (GimpSizeBoxClass *klass)
124
99
{
125
 
  GObjectClass *object_class = G_OBJECT_CLASS (klass);
126
 
 
127
 
  parent_class = g_type_class_peek_parent (klass);
 
100
  GObjectClass   *object_class     = G_OBJECT_CLASS (klass);
 
101
  GtkObjectClass *gtk_object_class = GTK_OBJECT_CLASS (klass);
128
102
 
129
103
  object_class->constructor  = gimp_size_box_constructor;
130
104
  object_class->set_property = gimp_size_box_set_property;
131
105
  object_class->get_property = gimp_size_box_get_property;
132
106
 
 
107
  gtk_object_class->destroy  = gimp_size_box_destroy;
 
108
 
133
109
  g_type_class_add_private (object_class, sizeof (GimpSizeBoxPrivate));
134
110
 
135
111
  g_object_class_install_property (object_class, PROP_WIDTH,
137
113
                                                     GIMP_MIN_IMAGE_SIZE,
138
114
                                                     GIMP_MAX_IMAGE_SIZE,
139
115
                                                     256,
140
 
                                                     G_PARAM_READWRITE |
 
116
                                                     GIMP_PARAM_READWRITE |
141
117
                                                     G_PARAM_CONSTRUCT));
142
118
  g_object_class_install_property (object_class, PROP_HEIGHT,
143
119
                                   g_param_spec_int ("height", NULL, NULL,
144
120
                                                     GIMP_MIN_IMAGE_SIZE,
145
121
                                                     GIMP_MAX_IMAGE_SIZE,
146
122
                                                     256,
147
 
                                                     G_PARAM_READWRITE |
 
123
                                                     GIMP_PARAM_READWRITE |
148
124
                                                     G_PARAM_CONSTRUCT));
149
125
  g_object_class_install_property (object_class, PROP_UNIT,
150
126
                                   gimp_param_spec_unit ("unit", NULL, NULL,
151
127
                                                         TRUE, TRUE,
152
128
                                                         GIMP_UNIT_PIXEL,
153
 
                                                         G_PARAM_READWRITE |
 
129
                                                         GIMP_PARAM_READWRITE |
154
130
                                                         G_PARAM_CONSTRUCT));
155
131
  g_object_class_install_property (object_class, PROP_XRESOLUTION,
156
132
                                   g_param_spec_double ("xresolution",
158
134
                                                        GIMP_MIN_RESOLUTION,
159
135
                                                        GIMP_MAX_RESOLUTION,
160
136
                                                        72.0,
161
 
                                                        G_PARAM_READWRITE |
 
137
                                                        GIMP_PARAM_READWRITE |
162
138
                                                        G_PARAM_CONSTRUCT));
163
139
  g_object_class_install_property (object_class, PROP_YRESOLUTION,
164
140
                                   g_param_spec_double ("yresolution",
166
142
                                                        GIMP_MIN_RESOLUTION,
167
143
                                                        GIMP_MAX_RESOLUTION,
168
144
                                                        72.0,
169
 
                                                        G_PARAM_READWRITE |
 
145
                                                        GIMP_PARAM_READWRITE |
170
146
                                                        G_PARAM_CONSTRUCT));
171
147
  g_object_class_install_property (object_class, PROP_RESOLUTION_UNIT,
172
148
                                   gimp_param_spec_unit ("resolution-unit",
173
149
                                                         NULL, NULL,
174
150
                                                         FALSE, FALSE,
175
151
                                                         GIMP_UNIT_INCH,
176
 
                                                         G_PARAM_READWRITE |
 
152
                                                         GIMP_PARAM_READWRITE |
177
153
                                                         G_PARAM_CONSTRUCT));
178
154
  g_object_class_install_property (object_class, PROP_KEEP_ASPECT,
179
155
                                   g_param_spec_boolean ("keep-aspect",
180
156
                                                         NULL, NULL,
181
157
                                                         TRUE,
182
 
                                                         G_PARAM_READWRITE));
 
158
                                                         GIMP_PARAM_READWRITE));
183
159
  g_object_class_install_property (object_class, PROP_EDIT_RESOLUTION,
184
160
                                   g_param_spec_boolean ("edit-resolution",
185
161
                                                         NULL, NULL,
186
162
                                                         FALSE,
187
 
                                                         G_PARAM_READWRITE |
 
163
                                                         GIMP_PARAM_READWRITE |
188
164
                                                         G_PARAM_CONSTRUCT_ONLY));
189
165
}
190
166
 
192
168
gimp_size_box_init (GimpSizeBox *box)
193
169
{
194
170
  gtk_box_set_spacing (GTK_BOX (box), 6);
 
171
 
 
172
  box->size_group = gtk_size_group_new (GTK_SIZE_GROUP_HORIZONTAL);
195
173
}
196
174
 
197
175
static GObject *
201
179
{
202
180
  GObject            *object;
203
181
  GimpSizeBox        *box;
 
182
  GimpSizeBoxPrivate *priv;
204
183
  GtkWidget          *vbox;
205
184
  GtkWidget          *entry;
206
185
  GtkWidget          *hbox;
207
186
  GtkWidget          *label;
208
 
  GimpSizeBoxPrivate *priv;
 
187
  GList              *children;
 
188
  GList              *list;
209
189
 
210
190
  object = G_OBJECT_CLASS (parent_class)->constructor (type, n_params, params);
211
191
 
246
226
                                 box->xresolution,
247
227
                                 box->yresolution);
248
228
 
 
229
  g_signal_connect (priv->size_chain, "toggled",
 
230
                    G_CALLBACK (gimp_size_box_chain_toggled),
 
231
                    box);
 
232
 
249
233
  gtk_box_pack_start (GTK_BOX (hbox), entry, FALSE, FALSE, 0);
250
234
  gtk_widget_show (entry);
251
235
 
 
236
  children = gtk_container_get_children (GTK_CONTAINER (entry));
 
237
  for (list = children; list; list = g_list_next (list))
 
238
    if (GTK_IS_LABEL (list->data))
 
239
      gtk_size_group_add_widget (box->size_group, list->data);
 
240
  g_list_free (children);
 
241
 
252
242
  vbox = gtk_vbox_new (2, FALSE);
253
243
  gtk_table_attach_defaults (GTK_TABLE (entry), vbox, 1, 3, 2, 3);
254
244
  gtk_widget_show (vbox);
284
274
      gtk_box_pack_start (GTK_BOX (hbox), entry, FALSE, FALSE, 0);
285
275
      gtk_widget_show (entry);
286
276
 
 
277
      children = gtk_container_get_children (GTK_CONTAINER (entry));
 
278
      for (list = children; list; list = g_list_next (list))
 
279
        if (GTK_IS_LABEL (list->data))
 
280
          gtk_size_group_add_widget (box->size_group, list->data);
 
281
      g_list_free (children);
 
282
 
287
283
      gimp_prop_coordinates_connect (G_OBJECT (box),
288
284
                                     "xresolution", "yresolution",
289
285
                                     "resolution-unit",
290
286
                                     entry, NULL,
291
287
                                     1.0, 1.0);
292
 
     }
 
288
    }
293
289
  else
294
290
    {
295
291
      label = gtk_label_new (NULL);
421
417
}
422
418
 
423
419
static void
 
420
gimp_size_box_destroy (GtkObject *object)
 
421
{
 
422
  GimpSizeBox *box = GIMP_SIZE_BOX (object);
 
423
 
 
424
  if (box->size_group)
 
425
    {
 
426
      g_object_unref (box->size_group);
 
427
      box->size_group = NULL;
 
428
    }
 
429
 
 
430
  GTK_OBJECT_CLASS (parent_class)->destroy (object);
 
431
}
 
432
 
 
433
static void
424
434
gimp_size_box_update_size (GimpSizeBox *box)
425
435
{
426
436
  GimpSizeBoxPrivate *priv = GIMP_SIZE_BOX_GET_PRIVATE (box);
427
437
 
428
438
  if (priv->pixel_label)
429
439
    {
430
 
      gchar *text;
431
 
 
432
 
      text = g_strdup_printf (_("%d x %d pixels"), box->width, box->height);
 
440
      gchar *text = g_strdup_printf (ngettext ("%d × %d pixel",
 
441
                                               "%d × %d pixels", box->height),
 
442
                                     box->width, box->height);
433
443
      gtk_label_set_text (GTK_LABEL (priv->pixel_label), text);
434
444
      g_free (text);
435
445
    }
453
463
      gint   yres = ROUND (box->yresolution);
454
464
 
455
465
      if (xres != yres)
456
 
        text = g_strdup_printf (_("%d x %d dpi"), xres, yres);
 
466
        text = g_strdup_printf (_("%d × %d ppi"), xres, yres);
457
467
      else
458
 
        text = g_strdup_printf (_("%d dpi"), yres);
 
468
        text = g_strdup_printf (_("%d ppi"), yres);
459
469
 
460
470
      gtk_label_set_text (GTK_LABEL (priv->res_label), text);
461
471
      g_free (text);
462
472
    }
463
473
}
 
474
 
 
475
static void
 
476
gimp_size_box_chain_toggled (GimpChainButton *button,
 
477
                             GimpSizeBox     *box)
 
478
{
 
479
  g_object_set (box,
 
480
                "keep-aspect", gimp_chain_button_get_active (button),
 
481
                NULL);
 
482
}