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

« back to all changes in this revision

Viewing changes to libgimpwidgets/gimpresolutionentry.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
/* LIBGIMP - The GIMP Library
 
2
 * Copyright (C) 1995-2005 Peter Mattis and Spencer Kimball
 
3
 *
 
4
 * gimpresolutionentry.c
 
5
 * Copyright (C) 1999-2005 Sven Neumann <sven@gimp.org>
 
6
 *                         Michael Natterer <mitch@gimp.org>
 
7
 *                         Nathan Summers <rock@gimp.org>
 
8
 *
 
9
 * This library is free software; you can redistribute it and/or
 
10
 * modify it under the terms of the GNU Lesser General Public
 
11
 * License as published by the Free Software Foundation; either
 
12
 * version 2 of the License, or (at your option) any later version.
 
13
 *
 
14
 * This library is distributed in the hope that it will be useful,
 
15
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
16
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 
17
 * Library General Public License for more details.
 
18
 *
 
19
 * You should have received a copy of the GNU Lesser General Public
 
20
 * License along with this library; if not, write to the
 
21
 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 
22
 * Boston, MA 02111-1307, USA.
 
23
 */
 
24
 
 
25
#include "config.h"
 
26
 
 
27
#include <gtk/gtk.h>
 
28
 
 
29
#include "libgimpbase/gimpbase.h"
 
30
 
 
31
#include "gimpwidgets.h"
 
32
 
 
33
#include "gimpresolutionentry.h"
 
34
 
 
35
#include "libgimp/libgimp-intl.h"
 
36
 
 
37
 
 
38
#define SIZE_MAX_VALUE 500000.0
 
39
 
 
40
#define GIMP_RESOLUTION_ENTRY_DIGITS(unit) \
 
41
  (MIN (gimp_unit_get_digits (unit), 5) + 1)
 
42
 
 
43
 
 
44
enum
 
45
{
 
46
  WIDTH_CHANGED,
 
47
  HEIGHT_CHANGED,
 
48
  X_CHANGED,
 
49
  Y_CHANGED,
 
50
  UNIT_CHANGED,
 
51
  LAST_SIGNAL
 
52
};
 
53
 
 
54
static void   gimp_resolution_entry_class_init      (GimpResolutionEntryClass *class);
 
55
static void   gimp_resolution_entry_init            (GimpResolutionEntry      *gre);
 
56
 
 
57
static void   gimp_resolution_entry_finalize        (GObject            *object);
 
58
 
 
59
static void   gimp_resolution_entry_update_value    (GimpResolutionEntryField *gref,
 
60
                                                     gdouble              value);
 
61
static void   gimp_resolution_entry_value_callback  (GtkWidget           *widget,
 
62
                                                     gpointer             data);
 
63
static void   gimp_resolution_entry_update_unit     (GimpResolutionEntry *gre,
 
64
                                                     GimpUnit             unit);
 
65
static void   gimp_resolution_entry_unit_callback   (GtkWidget           *widget,
 
66
                                                     GimpResolutionEntry *gre);
 
67
 
 
68
static void   gimp_resolution_entry_field_init (GimpResolutionEntry      *gre,
 
69
                                                GimpResolutionEntryField *gref,
 
70
                                                GimpResolutionEntryField *corresponding,
 
71
                                                guint                     changed_signal,
 
72
                                                gdouble                   initial_val,
 
73
                                                GimpUnit                  initial_unit,
 
74
                                                gboolean                  size,
 
75
                                                gint                      spinbutton_width);
 
76
 
 
77
 
 
78
static void gimp_resolution_entry_field_set_boundaries
 
79
                                           (GimpResolutionEntryField *gref,
 
80
                                            gdouble                   lower,
 
81
                                            gdouble                   upper);
 
82
 
 
83
static void gimp_resolution_entry_field_set_value
 
84
                                           (GimpResolutionEntryField *gref,
 
85
                                            gdouble                   value);
 
86
 
 
87
static void  gimp_resolution_entry_format_label (GimpResolutionEntry *gre,
 
88
                                                 GtkWidget           *label,
 
89
                                                 gdouble              size);
 
90
static guint gimp_resolution_entry_signals[LAST_SIGNAL] = { 0 };
 
91
 
 
92
static GtkTableClass *parent_class = NULL;
 
93
 
 
94
 
 
95
GType
 
96
gimp_resolution_entry_get_type (void)
 
97
{
 
98
  static GType gre_type = 0;
 
99
 
 
100
  if (! gre_type)
 
101
    {
 
102
      const GTypeInfo gre_info =
 
103
      {
 
104
        sizeof (GimpResolutionEntryClass),
 
105
        (GBaseInitFunc) NULL,
 
106
        (GBaseFinalizeFunc) NULL,
 
107
        (GClassInitFunc) gimp_resolution_entry_class_init,
 
108
        NULL,                /* class_finalize */
 
109
        NULL,                /* class_data     */
 
110
        sizeof (GimpResolutionEntry),
 
111
        0,              /* n_preallocs    */
 
112
        (GInstanceInitFunc) gimp_resolution_entry_init,
 
113
      };
 
114
 
 
115
      gre_type = g_type_register_static (GTK_TYPE_TABLE,
 
116
                                         "GimpResolutionEntry",
 
117
                                         &gre_info, 0);
 
118
    }
 
119
 
 
120
  return gre_type;
 
121
}
 
122
 
 
123
static void
 
124
gimp_resolution_entry_class_init (GimpResolutionEntryClass *klass)
 
125
{
 
126
  GObjectClass *object_class;
 
127
 
 
128
  object_class = G_OBJECT_CLASS (klass);
 
129
 
 
130
  parent_class = g_type_class_peek_parent (klass);
 
131
 
 
132
  gimp_resolution_entry_signals[HEIGHT_CHANGED] =
 
133
    g_signal_new ("height-changed",
 
134
                  G_TYPE_FROM_CLASS (klass),
 
135
                  G_SIGNAL_RUN_FIRST,
 
136
                  G_STRUCT_OFFSET (GimpResolutionEntryClass, value_changed),
 
137
                  NULL, NULL,
 
138
                  g_cclosure_marshal_VOID__VOID,
 
139
                  G_TYPE_NONE, 0);
 
140
 
 
141
  gimp_resolution_entry_signals[WIDTH_CHANGED] =
 
142
    g_signal_new ("width-changed",
 
143
                  G_TYPE_FROM_CLASS (klass),
 
144
                  G_SIGNAL_RUN_FIRST,
 
145
                  G_STRUCT_OFFSET (GimpResolutionEntryClass, value_changed),
 
146
                  NULL, NULL,
 
147
                  g_cclosure_marshal_VOID__VOID,
 
148
                  G_TYPE_NONE, 0);
 
149
 
 
150
  gimp_resolution_entry_signals[X_CHANGED] =
 
151
    g_signal_new ("x-changed",
 
152
                  G_TYPE_FROM_CLASS (klass),
 
153
                  G_SIGNAL_RUN_FIRST,
 
154
                  G_STRUCT_OFFSET (GimpResolutionEntryClass, value_changed),
 
155
                  NULL, NULL,
 
156
                  g_cclosure_marshal_VOID__VOID,
 
157
                  G_TYPE_NONE, 0);
 
158
 
 
159
  gimp_resolution_entry_signals[Y_CHANGED] =
 
160
    g_signal_new ("y-changed",
 
161
                  G_TYPE_FROM_CLASS (klass),
 
162
                  G_SIGNAL_RUN_FIRST,
 
163
                  G_STRUCT_OFFSET (GimpResolutionEntryClass, refval_changed),
 
164
                  NULL, NULL,
 
165
                  g_cclosure_marshal_VOID__VOID,
 
166
                  G_TYPE_NONE, 0);
 
167
 
 
168
  gimp_resolution_entry_signals[UNIT_CHANGED] =
 
169
    g_signal_new ("unit-changed",
 
170
                  G_TYPE_FROM_CLASS (klass),
 
171
                  G_SIGNAL_RUN_FIRST,
 
172
                  G_STRUCT_OFFSET (GimpResolutionEntryClass, unit_changed),
 
173
                  NULL, NULL,
 
174
                  g_cclosure_marshal_VOID__VOID,
 
175
                  G_TYPE_NONE, 0);
 
176
 
 
177
  object_class->finalize = gimp_resolution_entry_finalize;
 
178
 
 
179
  klass->value_changed   = NULL;
 
180
  klass->refval_changed  = NULL;
 
181
  klass->unit_changed    = NULL;
 
182
}
 
183
 
 
184
static void
 
185
gimp_resolution_entry_init (GimpResolutionEntry *gre)
 
186
{
 
187
  gre->unitmenu     = NULL;
 
188
  gre->unit         = GIMP_UNIT_INCH;
 
189
  gre->independent  = FALSE;
 
190
 
 
191
  gtk_table_set_col_spacings (GTK_TABLE (gre), 4);
 
192
  gtk_table_set_row_spacings (GTK_TABLE (gre), 2);
 
193
}
 
194
 
 
195
static void
 
196
gimp_resolution_entry_finalize (GObject *object)
 
197
{
 
198
  GimpResolutionEntry *gre;
 
199
 
 
200
  g_return_if_fail (GIMP_IS_RESOLUTION_ENTRY (object));
 
201
 
 
202
  gre = GIMP_RESOLUTION_ENTRY (object);
 
203
 
 
204
  G_OBJECT_CLASS (parent_class)->finalize (object);
 
205
}
 
206
 
 
207
static void
 
208
gimp_resolution_entry_field_init (GimpResolutionEntry      *gre,
 
209
                                  GimpResolutionEntryField *gref,
 
210
                                  GimpResolutionEntryField *corresponding,
 
211
                                  guint                     changed_signal,
 
212
                                  gdouble                   initial_val,
 
213
                                  GimpUnit                  initial_unit,
 
214
                                  gboolean                  size,
 
215
                                  gint                      spinbutton_width)
 
216
{
 
217
  gint digits;
 
218
 
 
219
  g_return_if_fail (GIMP_IS_RESOLUTION_ENTRY (gre));
 
220
 
 
221
  gref->gre               = gre;
 
222
  gref->corresponding     = corresponding;
 
223
  gref->changed_signal    = gimp_resolution_entry_signals[changed_signal];
 
224
 
 
225
  if (size)
 
226
    {
 
227
      gref->value         = initial_val /
 
228
                            gimp_unit_get_factor (initial_unit) *
 
229
                            corresponding->value *
 
230
                            gimp_unit_get_factor (gre->unit);
 
231
 
 
232
      gref->phy_size      = initial_val /
 
233
                            gimp_unit_get_factor (initial_unit);
 
234
    }
 
235
  else
 
236
    gref->value           = initial_val;
 
237
 
 
238
  gref->min_value         = GIMP_MIN_RESOLUTION;
 
239
  gref->max_value         = GIMP_MAX_RESOLUTION;
 
240
  gref->adjustment        = NULL;
 
241
 
 
242
  gref->stop_recursion    = 0;
 
243
 
 
244
  gref->size              = size;
 
245
 
 
246
  if (size)
 
247
    {
 
248
      gref->label = g_object_new (GTK_TYPE_LABEL,
 
249
                                  "xalign", 0.0,
 
250
                                  "yalign", 0.5,
 
251
                                  NULL);
 
252
      gimp_label_set_attributes (GTK_LABEL (gref->label),
 
253
                                 PANGO_ATTR_STYLE, PANGO_STYLE_ITALIC,
 
254
                                 -1);
 
255
 
 
256
      gimp_resolution_entry_format_label (gre, gref->label, gref->phy_size);
 
257
    }
 
258
 
 
259
  digits = size ? 0 : GIMP_RESOLUTION_ENTRY_DIGITS (initial_unit);
 
260
 
 
261
  gref->spinbutton = gimp_spin_button_new (&gref->adjustment,
 
262
                                            gref->value,
 
263
                                            gref->min_value,
 
264
                                            gref->max_value,
 
265
                                            1.0, 10.0, 0.0,
 
266
                                            1.0,
 
267
                                            digits);
 
268
 
 
269
 
 
270
  if (spinbutton_width > 0)
 
271
    {
 
272
      if (spinbutton_width < 17)
 
273
        gtk_entry_set_width_chars (GTK_ENTRY (gref->spinbutton),
 
274
                                   spinbutton_width);
 
275
      else
 
276
        gtk_widget_set_size_request (gref->spinbutton,
 
277
                                     spinbutton_width, -1);
 
278
    }
 
279
}
 
280
 
 
281
/**
 
282
 * gimp_resolution_entry_new:
 
283
 * @width_label:       Optional label for the width control.
 
284
 * @width:             Width of the item, specified in terms of @size_unit.
 
285
 * @height_label:      Optional label for the height control.
 
286
 * @height:            Height of the item, specified in terms of @size_unit.
 
287
 * @size_unit:         Unit used to specify the width and height.
 
288
 * @x_label:           Optional label for the X resolution entry.
 
289
 * @initial_x:         The initial X resolution.
 
290
 * @y_label:           Optional label for the Y resolution entry.  Ignored if
 
291
 *                     @independent is %FALSE.
 
292
 * @initial_y:         The initial Y resolution.  Ignored if @independent is
 
293
 *                     %FALSE.
 
294
 * @initial_unit:      The initial unit.
 
295
 * @independent:       Whether the X and Y resolutions can be different values.
 
296
 * @spinbutton_width:  The minimal horizontal size of the #GtkSpinButton s.
 
297
 *
 
298
 * Creates a new #GimpResolutionEntry widget.
 
299
 *
 
300
 * The #GimpResolutionEntry is derived from #GtkTable and will have
 
301
 * an empty border of one cell width on each side plus an empty column left
 
302
 * of the #GimpUnitMenu to allow the caller to add labels or other widgets.
 
303
 *
 
304
 * A #GimpChainButton is displayed if independent is set to %TRUE.
 
305
 *
 
306
 * Returns: A pointer to the new #GimpResolutionEntry widget.
 
307
 *
 
308
 * Since: GIMP 2.4
 
309
 **/
 
310
GtkWidget *
 
311
gimp_resolution_entry_new (const gchar *width_label,
 
312
                           gdouble      width,
 
313
                           const gchar *height_label,
 
314
                           gdouble      height,
 
315
                           GimpUnit     size_unit,
 
316
                           const gchar *x_label,
 
317
                           gdouble      initial_x,
 
318
                           const gchar *y_label,
 
319
                           gdouble      initial_y,
 
320
                           GimpUnit     initial_unit,
 
321
                           gboolean     independent,
 
322
                           gint         spinbutton_width)
 
323
{
 
324
  GimpResolutionEntry *gre;
 
325
 
 
326
  gre = g_object_new (GIMP_TYPE_RESOLUTION_ENTRY, NULL);
 
327
 
 
328
  gre->unit        = initial_unit;
 
329
  gre->independent = independent;
 
330
 
 
331
  gtk_table_resize (GTK_TABLE (gre),
 
332
                    independent ? 5 : 4,
 
333
                    4);
 
334
 
 
335
  gimp_resolution_entry_field_init (gre, &gre->x,
 
336
                                    &gre->width,
 
337
                                    X_CHANGED,
 
338
                                    initial_x, initial_unit,
 
339
                                    FALSE,
 
340
                                    spinbutton_width);
 
341
 
 
342
  gtk_table_attach_defaults (GTK_TABLE (gre), gre->x.spinbutton,
 
343
                             1, 2,
 
344
                             3, 4);
 
345
 
 
346
  g_signal_connect (gre->x.adjustment, "value-changed",
 
347
                    G_CALLBACK (gimp_resolution_entry_value_callback),
 
348
                    &gre->x);
 
349
 
 
350
  gtk_widget_show (gre->x.spinbutton);
 
351
 
 
352
  if (independent)
 
353
    {
 
354
      gre->chainbutton = gimp_chain_button_new (GIMP_CHAIN_RIGHT);
 
355
 
 
356
      gtk_table_attach (GTK_TABLE (gre), gre->chainbutton,
 
357
                        2, 3,
 
358
                        3, 5,
 
359
                        GTK_SHRINK, GTK_SHRINK | GTK_FILL,
 
360
                        0, 0);
 
361
 
 
362
      gtk_widget_show (gre->chainbutton);
 
363
 
 
364
      gimp_resolution_entry_field_init (gre, &gre->y,
 
365
                                        &gre->height,
 
366
                                        Y_CHANGED,
 
367
                                        initial_y, initial_unit,
 
368
                                        FALSE,
 
369
                                        spinbutton_width);
 
370
 
 
371
      gtk_table_attach_defaults (GTK_TABLE (gre), gre->y.spinbutton,
 
372
                                 1, 2,
 
373
                                 4, 5);
 
374
 
 
375
      g_signal_connect (gre->y.adjustment, "value-changed",
 
376
                        G_CALLBACK (gimp_resolution_entry_value_callback),
 
377
                        &gre->y);
 
378
 
 
379
      gtk_widget_show (gre->y.spinbutton);
 
380
    }
 
381
 
 
382
  gre->unitmenu = gimp_unit_menu_new (_("pixels/%s"), initial_unit,
 
383
                                      FALSE, FALSE,
 
384
                                      TRUE);
 
385
  gtk_table_attach (GTK_TABLE (gre), gre->unitmenu,
 
386
                    3, 4,
 
387
                    independent ? 4 : 3, independent ? 5 : 4,
 
388
                    GTK_SHRINK | GTK_FILL, GTK_SHRINK | GTK_FILL, 0, 0);
 
389
  g_signal_connect (gre->unitmenu, "unit-changed",
 
390
                    G_CALLBACK (gimp_resolution_entry_unit_callback),
 
391
                    gre);
 
392
  gtk_widget_show (gre->unitmenu);
 
393
 
 
394
  gimp_resolution_entry_field_init (gre, &gre->width,
 
395
                                    &gre->x,
 
396
                                    WIDTH_CHANGED,
 
397
                                    width, size_unit,
 
398
                                    TRUE,
 
399
                                    spinbutton_width);
 
400
 
 
401
  gtk_table_attach_defaults (GTK_TABLE (gre), gre->width.spinbutton,
 
402
                             1, 2,
 
403
                             1, 2);
 
404
 
 
405
  gtk_table_attach_defaults (GTK_TABLE (gre), gre->width.label,
 
406
                             3, 4,
 
407
                             1, 2);
 
408
 
 
409
  g_signal_connect (gre->width.adjustment, "value-changed",
 
410
                    G_CALLBACK (gimp_resolution_entry_value_callback),
 
411
                    &gre->width);
 
412
 
 
413
  gtk_widget_show (gre->width.spinbutton);
 
414
  gtk_widget_show (gre->width.label);
 
415
 
 
416
  gimp_resolution_entry_field_init (gre, &gre->height,
 
417
                                    independent ? &gre->y : &gre->x,
 
418
                                    HEIGHT_CHANGED,
 
419
                                    height, size_unit,
 
420
                                    TRUE,
 
421
                                    spinbutton_width);
 
422
 
 
423
  gtk_table_attach_defaults (GTK_TABLE (gre), gre->height.spinbutton,
 
424
                             1, 2,
 
425
                             2, 3);
 
426
 
 
427
  gtk_table_attach_defaults (GTK_TABLE (gre), gre->height.label,
 
428
                             3, 4,
 
429
                             2, 3);
 
430
 
 
431
  g_signal_connect (gre->height.adjustment, "value-changed",
 
432
                    G_CALLBACK (gimp_resolution_entry_value_callback),
 
433
                    &gre->height);
 
434
 
 
435
  gtk_widget_show (gre->height.spinbutton);
 
436
  gtk_widget_show (gre->height.label);
 
437
 
 
438
  if (width_label)
 
439
    gimp_resolution_entry_attach_label (gre, width_label,  1, 0, 0.0);
 
440
 
 
441
  if (height_label)
 
442
    gimp_resolution_entry_attach_label (gre, height_label, 2, 0, 0.0);
 
443
 
 
444
  if (x_label)
 
445
    gimp_resolution_entry_attach_label (gre, x_label,      3, 0, 0.0);
 
446
 
 
447
  if (independent && y_label)
 
448
    gimp_resolution_entry_attach_label (gre, y_label,      4, 0, 0.0);
 
449
 
 
450
  return GTK_WIDGET (gre);
 
451
}
 
452
 
 
453
/**
 
454
 * gimp_resolution_entry_attach_label:
 
455
 * @gre:       The #GimpResolutionEntry you want to add a label to.
 
456
 * @text:      The text of the label.
 
457
 * @row:       The row where the label will be attached.
 
458
 * @column:    The column where the label will be attached.
 
459
 * @alignment: The horizontal alignment of the label.
 
460
 *
 
461
 * Attaches a #GtkLabel to the #GimpResolutionEntry (which is a #GtkTable).
 
462
 *
 
463
 * Returns: A pointer to the new #GtkLabel widget.
 
464
 *
 
465
 * Since: GIMP 2.4
 
466
 **/
 
467
GtkWidget *
 
468
gimp_resolution_entry_attach_label (GimpResolutionEntry *gre,
 
469
                                    const gchar         *text,
 
470
                                    gint                 row,
 
471
                                    gint                 column,
 
472
                                    gfloat               alignment)
 
473
{
 
474
  GtkWidget *label;
 
475
 
 
476
  g_return_val_if_fail (GIMP_IS_RESOLUTION_ENTRY (gre), NULL);
 
477
  g_return_val_if_fail (text != NULL, NULL);
 
478
 
 
479
  label = gtk_label_new_with_mnemonic (text);
 
480
 
 
481
  if (column == 0)
 
482
    {
 
483
      GtkTableChild *child;
 
484
      GList         *list;
 
485
 
 
486
      for (list = GTK_TABLE (gre)->children; list; list = g_list_next (list))
 
487
        {
 
488
          child = list->data;
 
489
 
 
490
          if (child->left_attach == 1 && child->top_attach == row)
 
491
            {
 
492
              gtk_label_set_mnemonic_widget (GTK_LABEL (label),
 
493
                                             child->widget);
 
494
              break;
 
495
            }
 
496
        }
 
497
    }
 
498
 
 
499
  gtk_misc_set_alignment (GTK_MISC (label), alignment, 0.5);
 
500
 
 
501
  gtk_table_attach (GTK_TABLE (gre), label, column, column+1, row, row+1,
 
502
                    GTK_SHRINK | GTK_FILL, GTK_SHRINK | GTK_FILL, 0, 0);
 
503
  gtk_widget_show (label);
 
504
 
 
505
  return label;
 
506
}
 
507
 
 
508
/**
 
509
 * gimp_resolution_entry_set_width_boundaries:
 
510
 * @gre:   The #GimpResolutionEntry you want to set value boundaries for.
 
511
 * @lower: The new lower boundary of the value of the field in pixels.
 
512
 * @upper: The new upper boundary of the value of the field in pixels.
 
513
 *
 
514
 * Limits the range of possible values which can be entered in the width field
 
515
 * of the #GimpResolutionEntry.
 
516
 *
 
517
 * The current value of the field will be clamped to fit in its
 
518
 * new boundaries.
 
519
 *
 
520
 * Since: GIMP 2.4
 
521
 **/
 
522
void
 
523
gimp_resolution_entry_set_width_boundaries (GimpResolutionEntry *gre,
 
524
                                            gdouble              lower,
 
525
                                            gdouble              upper)
 
526
{
 
527
  g_return_if_fail (GIMP_IS_RESOLUTION_ENTRY (gre));
 
528
 
 
529
  gimp_resolution_entry_field_set_boundaries (&gre->width,
 
530
                                              lower,
 
531
                                              upper);
 
532
}
 
533
 
 
534
/**
 
535
 * gimp_resolution_entry_set_height_boundaries:
 
536
 * @gre:   The #GimpResolutionEntry you want to set value boundaries for.
 
537
 * @lower: The new lower boundary of the value of the field in pixels.
 
538
 * @upper: The new upper boundary of the value of the field in pixels.
 
539
 *
 
540
 * Limits the range of possible values which can be entered in the height field
 
541
 * of the #GimpResolutionEntry.
 
542
 *
 
543
 * The current value of the field will be clamped to fit in its
 
544
 * new boundaries.
 
545
 *
 
546
 * Since: GIMP 2.4
 
547
 **/
 
548
void
 
549
gimp_resolution_entry_set_height_boundaries (GimpResolutionEntry *gre,
 
550
                                             gdouble              lower,
 
551
                                             gdouble              upper)
 
552
{
 
553
  g_return_if_fail (GIMP_IS_RESOLUTION_ENTRY (gre));
 
554
 
 
555
  gimp_resolution_entry_field_set_boundaries (&gre->height,
 
556
                                              lower,
 
557
                                              upper);
 
558
}
 
559
 
 
560
/**
 
561
 * gimp_resolution_entry_set_x_boundaries:
 
562
 * @gre:   The #GimpResolutionEntry you want to set value boundaries for.
 
563
 * @lower: The new lower boundary of the value of the field, in the current unit.
 
564
 * @upper: The new upper boundary of the value of the field, in the current unit.
 
565
 *
 
566
 * Limits the range of possible values which can be entered in the x field
 
567
 * of the #GimpResolutionEntry.
 
568
 *
 
569
 * The current value of the field will be clamped to fit in its
 
570
 * new boundaries.
 
571
 *
 
572
 * Since: GIMP 2.4
 
573
 **/
 
574
void
 
575
gimp_resolution_entry_set_x_boundaries (GimpResolutionEntry *gre,
 
576
                                        gdouble              lower,
 
577
                                        gdouble              upper)
 
578
{
 
579
  g_return_if_fail (GIMP_IS_RESOLUTION_ENTRY (gre));
 
580
 
 
581
  gimp_resolution_entry_field_set_boundaries (&gre->x,
 
582
                                              lower,
 
583
                                              upper);
 
584
}
 
585
 
 
586
/**
 
587
 * gimp_resolution_entry_set_y_boundaries:
 
588
 * @gre:   The #GimpResolutionEntry you want to set value boundaries for.
 
589
 * @lower: The new lower boundary of the value of the field, in the current unit.
 
590
 * @upper: The new upper boundary of the value of the field, in the current unit.
 
591
 *
 
592
 * Limits the range of possible values which can be entered in the y field
 
593
 * of the #GimpResolutionEntry.
 
594
 *
 
595
 * The current value of the field will be clamped to fit in its
 
596
 * new boundaries.
 
597
 *
 
598
 *
 
599
 * Since: GIMP 2.4
 
600
 **/
 
601
void
 
602
gimp_resolution_entry_set_y_boundaries (GimpResolutionEntry *gre,
 
603
                                        gdouble              lower,
 
604
                                        gdouble              upper)
 
605
{
 
606
  g_return_if_fail (GIMP_IS_RESOLUTION_ENTRY (gre));
 
607
  g_return_if_fail (gre->independent);
 
608
 
 
609
  gimp_resolution_entry_field_set_boundaries (&gre->y,
 
610
                                              lower,
 
611
                                              upper);
 
612
}
 
613
 
 
614
static void
 
615
gimp_resolution_entry_field_set_boundaries (GimpResolutionEntryField *gref,
 
616
                                            gdouble                   lower,
 
617
                                            gdouble                   upper)
 
618
{
 
619
  g_return_if_fail (lower <= upper);
 
620
 
 
621
  gref->min_value        = lower;
 
622
  gref->max_value        = upper;
 
623
 
 
624
  GTK_ADJUSTMENT (gref->adjustment)->lower = gref->min_value;
 
625
  GTK_ADJUSTMENT (gref->adjustment)->upper = gref->max_value;
 
626
 
 
627
  if (gref->value > upper || gref->value < lower)
 
628
    gimp_resolution_entry_field_set_value (gref, gref->value);
 
629
}
 
630
 
 
631
/**
 
632
 * gimp_resolution_entry_get_width;
 
633
 * @gre:   The #GimpResolutionEntry you want to know the width of.
 
634
 *
 
635
 * Returns the width of the #GimpResolutionEntry in pixels.
 
636
 *
 
637
 * SeeAlso: gimp_resolution_get_x
 
638
 *
 
639
 * Since: GIMP 2.4
 
640
 **/
 
641
 
 
642
gdouble
 
643
gimp_resolution_entry_get_width (GimpResolutionEntry *gre)
 
644
{
 
645
  g_return_val_if_fail (GIMP_IS_RESOLUTION_ENTRY (gre), 0);
 
646
 
 
647
  return gre->width.value;
 
648
}
 
649
 
 
650
/**
 
651
 * gimp_resolution_entry_get_height;
 
652
 * @gre:   The #GimpResolutionEntry you want to know the height of.
 
653
 *
 
654
 * Returns the height of the #GimpResolutionEntry in pixels.
 
655
 *
 
656
 * SeeAlso: gimp_resolution_get_y
 
657
 *
 
658
 * Since: GIMP 2.4
 
659
 **/
 
660
 
 
661
gdouble
 
662
gimp_resolution_entry_get_height (GimpResolutionEntry *gre)
 
663
{
 
664
  g_return_val_if_fail (GIMP_IS_RESOLUTION_ENTRY (gre), 0);
 
665
 
 
666
  return gre->height.value;
 
667
}
 
668
 
 
669
/**
 
670
 * gimp_resolution_entry_get_x;
 
671
 * @gre:   The #GimpResolutionEntry you want to know the resolution of.
 
672
 *
 
673
 * Returns the X resolution of the #GimpResolutionEntry in the current unit.
 
674
 *
 
675
 * SeeAlso: gimp_resolution_get_x_in_dpi
 
676
 *
 
677
 * Since: GIMP 2.4
 
678
 **/
 
679
 
 
680
gdouble
 
681
gimp_resolution_entry_get_x (GimpResolutionEntry *gre)
 
682
{
 
683
  g_return_val_if_fail (GIMP_IS_RESOLUTION_ENTRY (gre), 0);
 
684
 
 
685
  return gre->x.value;
 
686
}
 
687
 
 
688
/**
 
689
 * gimp_resolution_entry_get_x_in_dpi;
 
690
 * @gre:   The #GimpResolutionEntry you want to know the resolution of.
 
691
 *
 
692
 * Returns the X resolution of the #GimpResolutionEntry in pixels per inch.
 
693
 *
 
694
 * SeeAlso: gimp_resolution_get_x
 
695
 *
 
696
 * Since: GIMP 2.4
 
697
 **/
 
698
 
 
699
gdouble
 
700
gimp_resolution_entry_get_x_in_dpi (GimpResolutionEntry *gre)
 
701
{
 
702
  g_return_val_if_fail (GIMP_IS_RESOLUTION_ENTRY (gre), 0);
 
703
 
 
704
  return gre->x.value / gimp_unit_get_factor (gre->unit);
 
705
}
 
706
 
 
707
/**
 
708
 * gimp_resolution_entry_get_y;
 
709
 * @gre:   The #GimpResolutionEntry you want to know the resolution of.
 
710
 *
 
711
 * Returns the Y resolution of the #GimpResolutionEntry in the current unit.
 
712
 *
 
713
 * SeeAlso: gimp_resolution_get_y_in_dpi
 
714
 *
 
715
 * Since: GIMP 2.4
 
716
 **/
 
717
 
 
718
gdouble
 
719
gimp_resolution_entry_get_y (GimpResolutionEntry *gre)
 
720
{
 
721
  g_return_val_if_fail (GIMP_IS_RESOLUTION_ENTRY (gre), 0);
 
722
 
 
723
  return gre->y.value;
 
724
}
 
725
 
 
726
/**
 
727
 * gimp_resolution_entry_get_y_in_dpi;
 
728
 * @gre:   The #GimpResolutionEntry you want to know the resolution of.
 
729
 *
 
730
 * Returns the Y resolution of the #GimpResolutionEntry in pixels per inch.
 
731
 *
 
732
 * SeeAlso: gimp_resolution_get_y
 
733
 *
 
734
 * Since: GIMP 2.4
 
735
 **/
 
736
 
 
737
gdouble
 
738
gimp_resolution_entry_get_y_in_dpi (GimpResolutionEntry *gre)
 
739
{
 
740
  g_return_val_if_fail (GIMP_IS_RESOLUTION_ENTRY (gre), 0);
 
741
 
 
742
  return gre->y.value / gimp_unit_get_factor (gre->unit);
 
743
}
 
744
 
 
745
 
 
746
static void
 
747
gimp_resolution_entry_update_value (GimpResolutionEntryField *gref,
 
748
                                    gdouble                   value)
 
749
{
 
750
  if (gref->stop_recursion > 0)
 
751
    return;
 
752
 
 
753
  gref->value = value;
 
754
 
 
755
  gref->stop_recursion++;
 
756
 
 
757
  if (gref->gre->independent &&
 
758
      !gref->size &&
 
759
      gimp_chain_button_get_active (GIMP_CHAIN_BUTTON (gref->gre->chainbutton)))
 
760
    {
 
761
      gimp_resolution_entry_update_value (&gref->gre->x, value);
 
762
      gimp_resolution_entry_update_value (&gref->gre->y, value);
 
763
    }
 
764
 
 
765
  if (gref->size)
 
766
    gimp_resolution_entry_update_value (gref->corresponding,
 
767
                                        gref->value /
 
768
                                          gref->phy_size /
 
769
                                          gimp_unit_get_factor (gref->gre->unit));
 
770
  else
 
771
    {
 
772
      gdouble factor = gimp_unit_get_factor (gref->gre->unit);
 
773
 
 
774
      if (gref->gre->independent)
 
775
        gimp_resolution_entry_update_value (gref->corresponding,
 
776
                                            gref->value *
 
777
                                              gref->corresponding->phy_size *
 
778
                                              factor);
 
779
      else
 
780
        {
 
781
          gimp_resolution_entry_update_value (&gref->gre->width,
 
782
                                              gref->value *
 
783
                                                gref->gre->width.phy_size *
 
784
                                                factor);
 
785
 
 
786
          gimp_resolution_entry_update_value (&gref->gre->height,
 
787
                                                gref->value *
 
788
                                                gref->gre->height.phy_size *
 
789
                                                factor);
 
790
        }
 
791
    }
 
792
 
 
793
  gtk_adjustment_set_value (GTK_ADJUSTMENT (gref->adjustment), value);
 
794
 
 
795
  gref->stop_recursion--;
 
796
 
 
797
  g_signal_emit (gref->gre, gref->changed_signal, 0);
 
798
}
 
799
 
 
800
/**
 
801
 * gimp_resolution_entry_set_width:
 
802
 * @gre:   The #GimpResolutionEntry you want to set a value for.
 
803
 * @value: The new value for the width entry.
 
804
 *
 
805
 * Sets the value for the width control of the #GimpResolutionEntry.
 
806
 *
 
807
 * Since: GIMP 2.4
 
808
 **/
 
809
void
 
810
gimp_resolution_entry_set_width (GimpResolutionEntry *gre,
 
811
                                 gdouble              value)
 
812
{
 
813
  g_return_if_fail (GIMP_IS_RESOLUTION_ENTRY (gre));
 
814
 
 
815
  gimp_resolution_entry_field_set_value (&gre->width,
 
816
                                         value);
 
817
}
 
818
 
 
819
/**
 
820
 * gimp_resolution_entry_set_height:
 
821
 * @gre:   The #GimpResolutionEntry you want to set a value for.
 
822
 * @value: The new value for the height entry.
 
823
 *
 
824
 * Sets the value for the height control of the #GimpResolutionEntry.
 
825
 *
 
826
 * Since: GIMP 2.4
 
827
 **/
 
828
void
 
829
gimp_resolution_entry_set_height (GimpResolutionEntry *gre,
 
830
                                  gdouble              value)
 
831
{
 
832
  g_return_if_fail (GIMP_IS_RESOLUTION_ENTRY (gre));
 
833
 
 
834
  gimp_resolution_entry_field_set_value (&gre->height,
 
835
                                         value);
 
836
}
 
837
 
 
838
/**
 
839
 * gimp_resolution_entry_set_x:
 
840
 * @gre:   The #GimpResolutionEntry you want to set a value for.
 
841
 * @value: The new value for the X resolution in the current unit.
 
842
 *
 
843
 * Sets the value for the x resolution of the #GimpResolutionEntry.
 
844
 *
 
845
 * Since: GIMP 2.4
 
846
 **/
 
847
void
 
848
gimp_resolution_entry_set_x (GimpResolutionEntry *gre,
 
849
                             gdouble              value)
 
850
{
 
851
  g_return_if_fail (GIMP_IS_RESOLUTION_ENTRY (gre));
 
852
 
 
853
  gimp_resolution_entry_field_set_value (&gre->x,
 
854
                                         value);
 
855
}
 
856
/**
 
857
 * gimp_resolution_entry_set_y:
 
858
 * @gre:   The #GimpResolutionEntry you want to set a value for.
 
859
 * @value: The new value for the Y resolution in the current unit.
 
860
 *
 
861
 * Sets the value for the y resolution of the #GimpResolutionEntry.
 
862
 *
 
863
 * Since: GIMP 2.4
 
864
 **/
 
865
void
 
866
gimp_resolution_entry_set_y (GimpResolutionEntry *gre,
 
867
                             gdouble              value)
 
868
{
 
869
  g_return_if_fail (GIMP_IS_RESOLUTION_ENTRY (gre));
 
870
 
 
871
  gimp_resolution_entry_field_set_value (&gre->y,
 
872
                                         value);
 
873
}
 
874
 
 
875
static void
 
876
gimp_resolution_entry_field_set_value (GimpResolutionEntryField *gref,
 
877
                                       gdouble                   value)
 
878
{
 
879
  value = CLAMP (value, gref->min_value, gref->max_value);
 
880
 
 
881
  gtk_adjustment_set_value (GTK_ADJUSTMENT (gref->adjustment), value);
 
882
  gimp_resolution_entry_update_value (gref, value);
 
883
}
 
884
 
 
885
static void
 
886
gimp_resolution_entry_value_callback (GtkWidget *widget,
 
887
                                  gpointer   data)
 
888
{
 
889
  GimpResolutionEntryField *gref;
 
890
  gdouble             new_value;
 
891
 
 
892
  gref = (GimpResolutionEntryField *) data;
 
893
 
 
894
  new_value = GTK_ADJUSTMENT (widget)->value;
 
895
 
 
896
  if (gref->value != new_value)
 
897
    gimp_resolution_entry_update_value (gref, new_value);
 
898
}
 
899
 
 
900
/**
 
901
 * gimp_resolution_entry_get_unit:
 
902
 * @gre: The #GimpResolutionEntry you want to know the unit of.
 
903
 *
 
904
 * Returns the #GimpUnit the user has selected in the #GimpResolutionEntry's
 
905
 * #GimpUnitMenu.
 
906
 *
 
907
 * Returns: The #GimpResolutionEntry's unit.
 
908
 *
 
909
 * Since: GIMP 2.4
 
910
 **/
 
911
GimpUnit
 
912
gimp_resolution_entry_get_unit (GimpResolutionEntry *gre)
 
913
{
 
914
  g_return_val_if_fail (GIMP_IS_RESOLUTION_ENTRY (gre), GIMP_UNIT_INCH);
 
915
 
 
916
  return gre->unit;
 
917
}
 
918
 
 
919
static void
 
920
gimp_resolution_entry_update_unit (GimpResolutionEntry *gre,
 
921
                                   GimpUnit             unit)
 
922
{
 
923
  GimpUnit  old_unit;
 
924
  gint      digits;
 
925
  gdouble   factor;
 
926
 
 
927
  old_unit  = gre->unit;
 
928
  gre->unit = unit;
 
929
 
 
930
  digits = (gimp_unit_get_digits (GIMP_UNIT_INCH) -
 
931
            gimp_unit_get_digits (unit));
 
932
 
 
933
  gtk_spin_button_set_digits (GTK_SPIN_BUTTON (gre->x.spinbutton),
 
934
                              MAX (3 + digits, 3));
 
935
 
 
936
 
 
937
  factor = gimp_unit_get_factor (old_unit) / gimp_unit_get_factor (unit);
 
938
 
 
939
  gre->x.min_value *= factor;
 
940
  gre->x.max_value *= factor;
 
941
  gre->x.value     *= factor;
 
942
 
 
943
  gtk_adjustment_set_value (GTK_ADJUSTMENT (gre->x.adjustment),
 
944
                            gre->x.value);
 
945
 
 
946
 
 
947
  if (gre->independent)
 
948
    {
 
949
      gtk_spin_button_set_digits (GTK_SPIN_BUTTON (gre->y.spinbutton),
 
950
                                  MAX (3 + digits, 3));
 
951
 
 
952
      gre->y.min_value *= factor;
 
953
      gre->y.max_value *= factor;
 
954
      gre->y.value     *= factor;
 
955
 
 
956
      gtk_adjustment_set_value (GTK_ADJUSTMENT (gre->y.adjustment),
 
957
                                gre->y.value);
 
958
    }
 
959
 
 
960
 
 
961
  gimp_resolution_entry_format_label (gre,
 
962
                                      gre->width.label, gre->width.phy_size);
 
963
  gimp_resolution_entry_format_label (gre,
 
964
                                      gre->height.label, gre->height.phy_size);
 
965
 
 
966
  g_signal_emit (gre, gimp_resolution_entry_signals[UNIT_CHANGED], 0);
 
967
}
 
968
 
 
969
/**
 
970
 * gimp_resolution_entry_set_unit:
 
971
 * @gre:  The #GimpResolutionEntry you want to change the unit for.
 
972
 * @unit: The new unit.
 
973
 *
 
974
 * Sets the #GimpResolutionEntry's unit. The resolution will
 
975
 * stay the same but the value in pixels per unit will change
 
976
 * accordingly.
 
977
 *
 
978
 * Since: Gimp 2.4
 
979
 **/
 
980
void
 
981
gimp_resolution_entry_set_unit (GimpResolutionEntry *gre,
 
982
                                GimpUnit             unit)
 
983
{
 
984
  g_return_if_fail (GIMP_IS_RESOLUTION_ENTRY (gre));
 
985
  g_return_if_fail (unit != GIMP_UNIT_PIXEL);
 
986
  g_return_if_fail (unit != GIMP_UNIT_PERCENT);
 
987
 
 
988
  gimp_unit_menu_set_unit (GIMP_UNIT_MENU (gre->unitmenu), unit);
 
989
  gimp_resolution_entry_update_unit (gre, unit);
 
990
}
 
991
 
 
992
static void
 
993
gimp_resolution_entry_unit_callback (GtkWidget           *widget,
 
994
                                     GimpResolutionEntry *gre)
 
995
{
 
996
  GimpUnit new_unit;
 
997
 
 
998
  new_unit = gimp_unit_menu_get_unit (GIMP_UNIT_MENU (widget));
 
999
 
 
1000
  if (gre->unit != new_unit)
 
1001
    gimp_resolution_entry_update_unit (gre, new_unit);
 
1002
}
 
1003
 
 
1004
/**
 
1005
 * gimp_resolution_entry_show_unit_menu:
 
1006
 * @gre: a #GimpResolutionEntry
 
1007
 * @show: Boolean
 
1008
 *
 
1009
 * Controls whether a unit menu is shown in the size entry.  If
 
1010
 * @show is #TRUE, the menu is shown; otherwise it is hidden.
 
1011
 *
 
1012
 * Since: GIMP 2.4
 
1013
 **/
 
1014
void
 
1015
gimp_resolution_entry_show_unit_menu (GimpResolutionEntry *gre,
 
1016
                                      gboolean             show)
 
1017
{
 
1018
  g_return_if_fail (GIMP_IS_RESOLUTION_ENTRY (gre));
 
1019
 
 
1020
  if (show)
 
1021
    gtk_widget_show (gre->unitmenu);
 
1022
  else
 
1023
    gtk_widget_hide (gre->unitmenu);
 
1024
}
 
1025
 
 
1026
 
 
1027
/**
 
1028
 * gimp_resolution_entry_set_pixel_digits:
 
1029
 * @gre: a #GimpResolutionEntry
 
1030
 * @digits: the number of digits to display for a pixel size
 
1031
 *
 
1032
 * Similar to gimp_unit_menu_set_pixel_digits(), this function allows
 
1033
 * you set up a #GimpResolutionEntry so that sub-pixel sizes can be entered.
 
1034
 *
 
1035
 * Since: GIMP 2.4
 
1036
 **/
 
1037
void
 
1038
gimp_resolution_entry_set_pixel_digits (GimpResolutionEntry *gre,
 
1039
                                        gint                 digits)
 
1040
{
 
1041
  GimpUnitMenu *menu;
 
1042
 
 
1043
  g_return_if_fail (GIMP_IS_RESOLUTION_ENTRY (gre));
 
1044
 
 
1045
  menu = GIMP_UNIT_MENU (gre->unitmenu);
 
1046
 
 
1047
  gimp_unit_menu_set_pixel_digits (menu, digits);
 
1048
  gimp_resolution_entry_update_unit (gre, gimp_unit_menu_get_unit (menu));
 
1049
}
 
1050
 
 
1051
 
 
1052
/**
 
1053
 * gimp_resolution_entry_grab_focus:
 
1054
 * @gre: The #GimpResolutionEntry you want to grab the keyboard focus.
 
1055
 *
 
1056
 * This function is rather ugly and just a workaround for the fact that
 
1057
 * it's impossible to implement gtk_widget_grab_focus() for a #GtkTable.
 
1058
 *
 
1059
 * Since: GIMP 2.4
 
1060
 **/
 
1061
void
 
1062
gimp_resolution_entry_grab_focus (GimpResolutionEntry *gre)
 
1063
{
 
1064
  g_return_if_fail (GIMP_IS_RESOLUTION_ENTRY (gre));
 
1065
 
 
1066
  gtk_widget_grab_focus (gre->x.spinbutton);
 
1067
}
 
1068
 
 
1069
/**
 
1070
 * gimp_resolution_entry_set_activates_default:
 
1071
 * @gre: A #GimpResolutionEntry
 
1072
 * @setting: %TRUE to activate window's default widget on Enter keypress
 
1073
 *
 
1074
 * Iterates over all entries in the #GimpResolutionEntry and calls
 
1075
 * gtk_entry_set_activates_default() on them.
 
1076
 *
 
1077
 * Since: GIMP 2.4
 
1078
 **/
 
1079
void
 
1080
gimp_resolution_entry_set_activates_default (GimpResolutionEntry *gre,
 
1081
                                             gboolean             setting)
 
1082
{
 
1083
  g_return_if_fail (GIMP_IS_RESOLUTION_ENTRY (gre));
 
1084
 
 
1085
  gtk_entry_set_activates_default (GTK_ENTRY (gre->width.spinbutton),
 
1086
                                   setting);
 
1087
  gtk_entry_set_activates_default (GTK_ENTRY (gre->height.spinbutton),
 
1088
                                   setting);
 
1089
  gtk_entry_set_activates_default (GTK_ENTRY (gre->x.spinbutton),
 
1090
                                   setting);
 
1091
 
 
1092
  if (gre->independent)
 
1093
    gtk_entry_set_activates_default (GTK_ENTRY (gre->y.spinbutton),
 
1094
                                     setting);
 
1095
 
 
1096
}
 
1097
 
 
1098
/**
 
1099
 * gimp_resolution_entry_get_width_help_widget:
 
1100
 * @gre: a #GimpResolutionEntry
 
1101
 *
 
1102
 * You shouldn't fiddle with the internals of a #GimpResolutionEntry but
 
1103
 * if you want to set tooltips using gimp_help_set_help_data() you
 
1104
 * can use this function to get a pointer to the spinbuttons.
 
1105
 *
 
1106
 * Return value: a #GtkWidget pointer that you can attach a tooltip to.
 
1107
 **/
 
1108
GtkWidget *
 
1109
gimp_resolution_entry_get_width_help_widget (GimpResolutionEntry *gre)
 
1110
{
 
1111
  g_return_val_if_fail (GIMP_IS_RESOLUTION_ENTRY (gre), NULL);
 
1112
 
 
1113
  return gre->width.spinbutton;
 
1114
}
 
1115
 
 
1116
/**
 
1117
 * gimp_resolution_entry_get_height_help_widget:
 
1118
 * @gre: a #GimpResolutionEntry
 
1119
 *
 
1120
 * You shouldn't fiddle with the internals of a #GimpResolutionEntry but
 
1121
 * if you want to set tooltips using gimp_help_set_help_data() you
 
1122
 * can use this function to get a pointer to the spinbuttons.
 
1123
 *
 
1124
 * Return value: a #GtkWidget pointer that you can attach a tooltip to.
 
1125
 **/
 
1126
GtkWidget *
 
1127
gimp_resolution_entry_get_height_help_widget (GimpResolutionEntry *gre)
 
1128
{
 
1129
  g_return_val_if_fail (GIMP_IS_RESOLUTION_ENTRY (gre), NULL);
 
1130
 
 
1131
  return gre->height.spinbutton;
 
1132
}
 
1133
 
 
1134
/**
 
1135
 * gimp_resolution_entry_get_x_help_widget:
 
1136
 * @gre: a #GimpResolutionEntry
 
1137
 *
 
1138
 * You shouldn't fiddle with the internals of a #GimpResolutionEntry but
 
1139
 * if you want to set tooltips using gimp_help_set_help_data() you
 
1140
 * can use this function to get a pointer to the spinbuttons.
 
1141
 *
 
1142
 * Return value: a #GtkWidget pointer that you can attach a tooltip to.
 
1143
 **/
 
1144
GtkWidget *
 
1145
gimp_resolution_entry_get_x_help_widget (GimpResolutionEntry *gre)
 
1146
{
 
1147
  g_return_val_if_fail (GIMP_IS_RESOLUTION_ENTRY (gre), NULL);
 
1148
 
 
1149
  return gre->x.spinbutton;
 
1150
}
 
1151
 
 
1152
/**
 
1153
 * gimp_resolution_entry_get_x_help_widget:
 
1154
 * @gre: a #GimpResolutionEntry
 
1155
 *
 
1156
 * You shouldn't fiddle with the internals of a #GimpResolutionEntry but
 
1157
 * if you want to set tooltips using gimp_help_set_help_data() you
 
1158
 * can use this function to get a pointer to the spinbuttons.
 
1159
 *
 
1160
 * Return value: a #GtkWidget pointer that you can attach a tooltip to.
 
1161
 **/
 
1162
GtkWidget *
 
1163
gimp_resolution_entry_get_y_help_widget (GimpResolutionEntry *gre)
 
1164
{
 
1165
  g_return_val_if_fail (GIMP_IS_RESOLUTION_ENTRY (gre), NULL);
 
1166
  g_return_val_if_fail (gre->independent, NULL);
 
1167
 
 
1168
  return gre->x.spinbutton;
 
1169
}
 
1170
 
 
1171
/**
 
1172
 * gimp_resolution_entry_update_width:
 
1173
 * @gre: the #GimpResolutionEntry
 
1174
 * @data: a pointer to a gdouble
 
1175
 *
 
1176
 * Convenience function to set a double to the width, suitable
 
1177
 * for use as a signal callback.
 
1178
 *
 
1179
 * Since: GIMP 2.4
 
1180
 */
 
1181
 
 
1182
void
 
1183
gimp_resolution_entry_update_width (GimpResolutionEntry *gre,
 
1184
                                    gpointer             data)
 
1185
{
 
1186
  gdouble *val;
 
1187
 
 
1188
  g_return_if_fail (gre  != NULL);
 
1189
  g_return_if_fail (data != NULL);
 
1190
  g_return_if_fail (GIMP_IS_RESOLUTION_ENTRY (gre));
 
1191
 
 
1192
  val = (gdouble *) data;
 
1193
 
 
1194
  *val = gimp_resolution_entry_get_width (gre);
 
1195
}
 
1196
 
 
1197
 
 
1198
/**
 
1199
 * gimp_resolution_entry_update_height:
 
1200
 * @gre: the #GimpResolutionEntry
 
1201
 * @data: a pointer to a gdouble
 
1202
 *
 
1203
 * Convenience function to set a double to the height, suitable
 
1204
 * for use as a signal callback.
 
1205
 *
 
1206
 * Since: GIMP 2.4
 
1207
 */
 
1208
 
 
1209
void
 
1210
gimp_resolution_entry_update_height (GimpResolutionEntry *gre,
 
1211
                                     gpointer             data)
 
1212
{
 
1213
  gdouble *val;
 
1214
 
 
1215
  g_return_if_fail (gre  != NULL);
 
1216
  g_return_if_fail (data != NULL);
 
1217
  g_return_if_fail (GIMP_IS_RESOLUTION_ENTRY (gre));
 
1218
 
 
1219
  val = (gdouble *) data;
 
1220
 
 
1221
  *val = gimp_resolution_entry_get_height (gre);
 
1222
}
 
1223
 
 
1224
 
 
1225
/**
 
1226
 * gimp_resolution_entry_update_x:
 
1227
 * @gre: the #GimpResolutionEntry
 
1228
 * @data: a pointer to a gdouble
 
1229
 *
 
1230
 * Convenience function to set a double to the X resolution, suitable
 
1231
 * for use as a signal callback.
 
1232
 *
 
1233
 * Since: GIMP 2.4
 
1234
 */
 
1235
 
 
1236
void
 
1237
gimp_resolution_entry_update_x (GimpResolutionEntry *gre,
 
1238
                                gpointer             data)
 
1239
{
 
1240
  gdouble *val;
 
1241
 
 
1242
  g_return_if_fail (gre  != NULL);
 
1243
  g_return_if_fail (data != NULL);
 
1244
  g_return_if_fail (GIMP_IS_RESOLUTION_ENTRY (gre));
 
1245
 
 
1246
  val = (gdouble *) data;
 
1247
 
 
1248
  *val = gimp_resolution_entry_get_x (gre);
 
1249
}
 
1250
 
 
1251
/**
 
1252
 * gimp_resolution_entry_update_x_in_dpi:
 
1253
 * @gre: the #GimpResolutionEntry
 
1254
 * @data: a pointer to a gdouble
 
1255
 *
 
1256
 * Convenience function to set a double to the X resolution, suitable
 
1257
 * for use as a signal callback.
 
1258
 *
 
1259
 * Since: GIMP 2.4
 
1260
 */
 
1261
 
 
1262
void
 
1263
gimp_resolution_entry_update_x_in_dpi (GimpResolutionEntry *gre,
 
1264
                                       gpointer             data)
 
1265
{
 
1266
  gdouble *val;
 
1267
 
 
1268
  g_return_if_fail (gre  != NULL);
 
1269
  g_return_if_fail (data != NULL);
 
1270
  g_return_if_fail (GIMP_IS_RESOLUTION_ENTRY (gre));
 
1271
 
 
1272
  val = (gdouble *) data;
 
1273
 
 
1274
  *val = gimp_resolution_entry_get_x_in_dpi (gre);
 
1275
}
 
1276
 
 
1277
/**
 
1278
 * gimp_resolution_entry_update_y:
 
1279
 * @gre: the #GimpResolutionEntry
 
1280
 * @data: a pointer to a gdouble
 
1281
 *
 
1282
 * Convenience function to set a double to the Y resolution, suitable
 
1283
 * for use as a signal callback.
 
1284
 *
 
1285
 * Since: GIMP 2.4
 
1286
 */
 
1287
 
 
1288
void
 
1289
gimp_resolution_entry_update_y (GimpResolutionEntry *gre,
 
1290
                                gpointer             data)
 
1291
{
 
1292
  gdouble *val;
 
1293
 
 
1294
  g_return_if_fail (gre  != NULL);
 
1295
  g_return_if_fail (data != NULL);
 
1296
  g_return_if_fail (GIMP_IS_RESOLUTION_ENTRY (gre));
 
1297
 
 
1298
  val = (gdouble *) data;
 
1299
 
 
1300
  *val = gimp_resolution_entry_get_y (gre);
 
1301
}
 
1302
 
 
1303
/**
 
1304
 * gimp_resolution_entry_update_y_in_dpi:
 
1305
 * @gre: the #GimpResolutionEntry
 
1306
 * @data: a pointer to a gdouble
 
1307
 *
 
1308
 * Convenience function to set a double to the Y resolution, suitable
 
1309
 * for use as a signal callback.
 
1310
 *
 
1311
 * Since: GIMP 2.4
 
1312
 */
 
1313
 
 
1314
void
 
1315
gimp_resolution_entry_update_y_in_dpi (GimpResolutionEntry *gre,
 
1316
                                       gpointer             data)
 
1317
{
 
1318
  gdouble *val;
 
1319
 
 
1320
  g_return_if_fail (gre  != NULL);
 
1321
  g_return_if_fail (data != NULL);
 
1322
  g_return_if_fail (GIMP_IS_RESOLUTION_ENTRY (gre));
 
1323
 
 
1324
  val = (gdouble *) data;
 
1325
 
 
1326
  *val = gimp_resolution_entry_get_y_in_dpi (gre);
 
1327
}
 
1328
 
 
1329
static void
 
1330
gimp_resolution_entry_format_label (GimpResolutionEntry *gre,
 
1331
                                    GtkWidget           *label,
 
1332
                                    gdouble              size)
 
1333
{
 
1334
  gchar *format = g_strdup_printf ("%%.%df %%s",
 
1335
                                   gimp_unit_get_digits (gre->unit));
 
1336
  gchar *text = g_strdup_printf (format,
 
1337
                                 size * gimp_unit_get_factor (gre->unit),
 
1338
                                 gimp_unit_get_plural (gre->unit));
 
1339
  g_free (format);
 
1340
 
 
1341
  gtk_label_set_text (GTK_LABEL (label), text);
 
1342
  g_free (text);
 
1343
}