22
22
#include "config.h"
24
26
#include <gtk/gtk.h>
26
28
#include "libgimpbase/gimpbase.h"
29
#include "libgimpmath/gimpmath.h"
30
#include "libgimpconfig/gimpconfig.h"
27
31
#include "libgimpwidgets/gimpwidgets.h"
29
33
#include "widgets-types.h"
31
#include "config/gimpconfig-params.h"
33
#include "gimppropwidgets.h"
34
35
#include "gimpsizebox.h"
36
37
#include "gimp-intl.h"
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))
58
59
typedef struct _GimpSizeBoxPrivate GimpSizeBoxPrivate;
70
static void gimp_size_box_class_init (GimpSizeBoxClass *klass);
72
71
static GObject * gimp_size_box_constructor (GType type,
74
73
GObjectConstructParam *params);
76
static void gimp_size_box_init (GimpSizeBox *box);
78
static void gimp_size_box_set_property (GObject *object,
82
static void gimp_size_box_get_property (GObject *object,
87
static void gimp_size_box_update_size (GimpSizeBox *box);
88
static void gimp_size_box_update_resolution (GimpSizeBox *box);
91
static GtkVBoxClass *parent_class = NULL;
95
gimp_size_box_get_type (void)
97
static GType box_type = 0;
101
static const GTypeInfo box_info =
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),
111
(GInstanceInitFunc) gimp_size_box_init
114
box_type = g_type_register_static (GTK_TYPE_VBOX,
75
static void gimp_size_box_set_property (GObject *object,
79
static void gimp_size_box_get_property (GObject *object,
84
static void gimp_size_box_destroy (GtkObject *object);
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,
92
G_DEFINE_TYPE (GimpSizeBox, gimp_size_box, GTK_TYPE_VBOX)
94
#define parent_class gimp_size_box_parent_class
123
98
gimp_size_box_class_init (GimpSizeBoxClass *klass)
125
GObjectClass *object_class = G_OBJECT_CLASS (klass);
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);
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;
107
gtk_object_class->destroy = gimp_size_box_destroy;
133
109
g_type_class_add_private (object_class, sizeof (GimpSizeBoxPrivate));
135
111
g_object_class_install_property (object_class, PROP_WIDTH,
137
113
GIMP_MIN_IMAGE_SIZE,
138
114
GIMP_MAX_IMAGE_SIZE,
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,
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,
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",
166
142
GIMP_MIN_RESOLUTION,
167
143
GIMP_MAX_RESOLUTION,
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",
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",
158
GIMP_PARAM_READWRITE));
183
159
g_object_class_install_property (object_class, PROP_EDIT_RESOLUTION,
184
160
g_param_spec_boolean ("edit-resolution",
163
GIMP_PARAM_READWRITE |
188
164
G_PARAM_CONSTRUCT_ONLY));
246
226
box->xresolution,
247
227
box->yresolution);
229
g_signal_connect (priv->size_chain, "toggled",
230
G_CALLBACK (gimp_size_box_chain_toggled),
249
233
gtk_box_pack_start (GTK_BOX (hbox), entry, FALSE, FALSE, 0);
250
234
gtk_widget_show (entry);
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);
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);
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);
287
283
gimp_prop_coordinates_connect (G_OBJECT (box),
288
284
"xresolution", "yresolution",
289
285
"resolution-unit",
295
291
label = gtk_label_new (NULL);
420
gimp_size_box_destroy (GtkObject *object)
422
GimpSizeBox *box = GIMP_SIZE_BOX (object);
426
g_object_unref (box->size_group);
427
box->size_group = NULL;
430
GTK_OBJECT_CLASS (parent_class)->destroy (object);
424
434
gimp_size_box_update_size (GimpSizeBox *box)
426
436
GimpSizeBoxPrivate *priv = GIMP_SIZE_BOX_GET_PRIVATE (box);
428
438
if (priv->pixel_label)
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);
453
463
gint yres = ROUND (box->yresolution);
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);
458
text = g_strdup_printf (_("%d dpi"), yres);
468
text = g_strdup_printf (_("%d ppi"), yres);
460
470
gtk_label_set_text (GTK_LABEL (priv->res_label), text);
476
gimp_size_box_chain_toggled (GimpChainButton *button,
480
"keep-aspect", gimp_chain_button_get_active (button),