1
/* LIBGIMP - The GIMP Library
2
* Copyright (C) 1995-2005 Peter Mattis and Spencer Kimball
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>
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.
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.
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.
29
#include "libgimpbase/gimpbase.h"
31
#include "gimpwidgets.h"
33
#include "gimpresolutionentry.h"
35
#include "libgimp/libgimp-intl.h"
38
#define SIZE_MAX_VALUE 500000.0
40
#define GIMP_RESOLUTION_ENTRY_DIGITS(unit) \
41
(MIN (gimp_unit_get_digits (unit), 5) + 1)
54
static void gimp_resolution_entry_class_init (GimpResolutionEntryClass *class);
55
static void gimp_resolution_entry_init (GimpResolutionEntry *gre);
57
static void gimp_resolution_entry_finalize (GObject *object);
59
static void gimp_resolution_entry_update_value (GimpResolutionEntryField *gref,
61
static void gimp_resolution_entry_value_callback (GtkWidget *widget,
63
static void gimp_resolution_entry_update_unit (GimpResolutionEntry *gre,
65
static void gimp_resolution_entry_unit_callback (GtkWidget *widget,
66
GimpResolutionEntry *gre);
68
static void gimp_resolution_entry_field_init (GimpResolutionEntry *gre,
69
GimpResolutionEntryField *gref,
70
GimpResolutionEntryField *corresponding,
73
GimpUnit initial_unit,
75
gint spinbutton_width);
78
static void gimp_resolution_entry_field_set_boundaries
79
(GimpResolutionEntryField *gref,
83
static void gimp_resolution_entry_field_set_value
84
(GimpResolutionEntryField *gref,
87
static void gimp_resolution_entry_format_label (GimpResolutionEntry *gre,
90
static guint gimp_resolution_entry_signals[LAST_SIGNAL] = { 0 };
92
static GtkTableClass *parent_class = NULL;
96
gimp_resolution_entry_get_type (void)
98
static GType gre_type = 0;
102
const GTypeInfo gre_info =
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),
112
(GInstanceInitFunc) gimp_resolution_entry_init,
115
gre_type = g_type_register_static (GTK_TYPE_TABLE,
116
"GimpResolutionEntry",
124
gimp_resolution_entry_class_init (GimpResolutionEntryClass *klass)
126
GObjectClass *object_class;
128
object_class = G_OBJECT_CLASS (klass);
130
parent_class = g_type_class_peek_parent (klass);
132
gimp_resolution_entry_signals[HEIGHT_CHANGED] =
133
g_signal_new ("height-changed",
134
G_TYPE_FROM_CLASS (klass),
136
G_STRUCT_OFFSET (GimpResolutionEntryClass, value_changed),
138
g_cclosure_marshal_VOID__VOID,
141
gimp_resolution_entry_signals[WIDTH_CHANGED] =
142
g_signal_new ("width-changed",
143
G_TYPE_FROM_CLASS (klass),
145
G_STRUCT_OFFSET (GimpResolutionEntryClass, value_changed),
147
g_cclosure_marshal_VOID__VOID,
150
gimp_resolution_entry_signals[X_CHANGED] =
151
g_signal_new ("x-changed",
152
G_TYPE_FROM_CLASS (klass),
154
G_STRUCT_OFFSET (GimpResolutionEntryClass, value_changed),
156
g_cclosure_marshal_VOID__VOID,
159
gimp_resolution_entry_signals[Y_CHANGED] =
160
g_signal_new ("y-changed",
161
G_TYPE_FROM_CLASS (klass),
163
G_STRUCT_OFFSET (GimpResolutionEntryClass, refval_changed),
165
g_cclosure_marshal_VOID__VOID,
168
gimp_resolution_entry_signals[UNIT_CHANGED] =
169
g_signal_new ("unit-changed",
170
G_TYPE_FROM_CLASS (klass),
172
G_STRUCT_OFFSET (GimpResolutionEntryClass, unit_changed),
174
g_cclosure_marshal_VOID__VOID,
177
object_class->finalize = gimp_resolution_entry_finalize;
179
klass->value_changed = NULL;
180
klass->refval_changed = NULL;
181
klass->unit_changed = NULL;
185
gimp_resolution_entry_init (GimpResolutionEntry *gre)
187
gre->unitmenu = NULL;
188
gre->unit = GIMP_UNIT_INCH;
189
gre->independent = FALSE;
191
gtk_table_set_col_spacings (GTK_TABLE (gre), 4);
192
gtk_table_set_row_spacings (GTK_TABLE (gre), 2);
196
gimp_resolution_entry_finalize (GObject *object)
198
GimpResolutionEntry *gre;
200
g_return_if_fail (GIMP_IS_RESOLUTION_ENTRY (object));
202
gre = GIMP_RESOLUTION_ENTRY (object);
204
G_OBJECT_CLASS (parent_class)->finalize (object);
208
gimp_resolution_entry_field_init (GimpResolutionEntry *gre,
209
GimpResolutionEntryField *gref,
210
GimpResolutionEntryField *corresponding,
211
guint changed_signal,
213
GimpUnit initial_unit,
215
gint spinbutton_width)
219
g_return_if_fail (GIMP_IS_RESOLUTION_ENTRY (gre));
222
gref->corresponding = corresponding;
223
gref->changed_signal = gimp_resolution_entry_signals[changed_signal];
227
gref->value = initial_val /
228
gimp_unit_get_factor (initial_unit) *
229
corresponding->value *
230
gimp_unit_get_factor (gre->unit);
232
gref->phy_size = initial_val /
233
gimp_unit_get_factor (initial_unit);
236
gref->value = initial_val;
238
gref->min_value = GIMP_MIN_RESOLUTION;
239
gref->max_value = GIMP_MAX_RESOLUTION;
240
gref->adjustment = NULL;
242
gref->stop_recursion = 0;
248
gref->label = g_object_new (GTK_TYPE_LABEL,
252
gimp_label_set_attributes (GTK_LABEL (gref->label),
253
PANGO_ATTR_STYLE, PANGO_STYLE_ITALIC,
256
gimp_resolution_entry_format_label (gre, gref->label, gref->phy_size);
259
digits = size ? 0 : GIMP_RESOLUTION_ENTRY_DIGITS (initial_unit);
261
gref->spinbutton = gimp_spin_button_new (&gref->adjustment,
270
if (spinbutton_width > 0)
272
if (spinbutton_width < 17)
273
gtk_entry_set_width_chars (GTK_ENTRY (gref->spinbutton),
276
gtk_widget_set_size_request (gref->spinbutton,
277
spinbutton_width, -1);
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
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.
298
* Creates a new #GimpResolutionEntry widget.
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.
304
* A #GimpChainButton is displayed if independent is set to %TRUE.
306
* Returns: A pointer to the new #GimpResolutionEntry widget.
311
gimp_resolution_entry_new (const gchar *width_label,
313
const gchar *height_label,
316
const gchar *x_label,
318
const gchar *y_label,
320
GimpUnit initial_unit,
321
gboolean independent,
322
gint spinbutton_width)
324
GimpResolutionEntry *gre;
326
gre = g_object_new (GIMP_TYPE_RESOLUTION_ENTRY, NULL);
328
gre->unit = initial_unit;
329
gre->independent = independent;
331
gtk_table_resize (GTK_TABLE (gre),
335
gimp_resolution_entry_field_init (gre, &gre->x,
338
initial_x, initial_unit,
342
gtk_table_attach_defaults (GTK_TABLE (gre), gre->x.spinbutton,
346
g_signal_connect (gre->x.adjustment, "value-changed",
347
G_CALLBACK (gimp_resolution_entry_value_callback),
350
gtk_widget_show (gre->x.spinbutton);
354
gre->chainbutton = gimp_chain_button_new (GIMP_CHAIN_RIGHT);
356
gtk_table_attach (GTK_TABLE (gre), gre->chainbutton,
359
GTK_SHRINK, GTK_SHRINK | GTK_FILL,
362
gtk_widget_show (gre->chainbutton);
364
gimp_resolution_entry_field_init (gre, &gre->y,
367
initial_y, initial_unit,
371
gtk_table_attach_defaults (GTK_TABLE (gre), gre->y.spinbutton,
375
g_signal_connect (gre->y.adjustment, "value-changed",
376
G_CALLBACK (gimp_resolution_entry_value_callback),
379
gtk_widget_show (gre->y.spinbutton);
382
gre->unitmenu = gimp_unit_menu_new (_("pixels/%s"), initial_unit,
385
gtk_table_attach (GTK_TABLE (gre), gre->unitmenu,
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),
392
gtk_widget_show (gre->unitmenu);
394
gimp_resolution_entry_field_init (gre, &gre->width,
401
gtk_table_attach_defaults (GTK_TABLE (gre), gre->width.spinbutton,
405
gtk_table_attach_defaults (GTK_TABLE (gre), gre->width.label,
409
g_signal_connect (gre->width.adjustment, "value-changed",
410
G_CALLBACK (gimp_resolution_entry_value_callback),
413
gtk_widget_show (gre->width.spinbutton);
414
gtk_widget_show (gre->width.label);
416
gimp_resolution_entry_field_init (gre, &gre->height,
417
independent ? &gre->y : &gre->x,
423
gtk_table_attach_defaults (GTK_TABLE (gre), gre->height.spinbutton,
427
gtk_table_attach_defaults (GTK_TABLE (gre), gre->height.label,
431
g_signal_connect (gre->height.adjustment, "value-changed",
432
G_CALLBACK (gimp_resolution_entry_value_callback),
435
gtk_widget_show (gre->height.spinbutton);
436
gtk_widget_show (gre->height.label);
439
gimp_resolution_entry_attach_label (gre, width_label, 1, 0, 0.0);
442
gimp_resolution_entry_attach_label (gre, height_label, 2, 0, 0.0);
445
gimp_resolution_entry_attach_label (gre, x_label, 3, 0, 0.0);
447
if (independent && y_label)
448
gimp_resolution_entry_attach_label (gre, y_label, 4, 0, 0.0);
450
return GTK_WIDGET (gre);
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.
461
* Attaches a #GtkLabel to the #GimpResolutionEntry (which is a #GtkTable).
463
* Returns: A pointer to the new #GtkLabel widget.
468
gimp_resolution_entry_attach_label (GimpResolutionEntry *gre,
476
g_return_val_if_fail (GIMP_IS_RESOLUTION_ENTRY (gre), NULL);
477
g_return_val_if_fail (text != NULL, NULL);
479
label = gtk_label_new_with_mnemonic (text);
483
GtkTableChild *child;
486
for (list = GTK_TABLE (gre)->children; list; list = g_list_next (list))
490
if (child->left_attach == 1 && child->top_attach == row)
492
gtk_label_set_mnemonic_widget (GTK_LABEL (label),
499
gtk_misc_set_alignment (GTK_MISC (label), alignment, 0.5);
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);
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.
514
* Limits the range of possible values which can be entered in the width field
515
* of the #GimpResolutionEntry.
517
* The current value of the field will be clamped to fit in its
523
gimp_resolution_entry_set_width_boundaries (GimpResolutionEntry *gre,
527
g_return_if_fail (GIMP_IS_RESOLUTION_ENTRY (gre));
529
gimp_resolution_entry_field_set_boundaries (&gre->width,
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.
540
* Limits the range of possible values which can be entered in the height field
541
* of the #GimpResolutionEntry.
543
* The current value of the field will be clamped to fit in its
549
gimp_resolution_entry_set_height_boundaries (GimpResolutionEntry *gre,
553
g_return_if_fail (GIMP_IS_RESOLUTION_ENTRY (gre));
555
gimp_resolution_entry_field_set_boundaries (&gre->height,
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.
566
* Limits the range of possible values which can be entered in the x field
567
* of the #GimpResolutionEntry.
569
* The current value of the field will be clamped to fit in its
575
gimp_resolution_entry_set_x_boundaries (GimpResolutionEntry *gre,
579
g_return_if_fail (GIMP_IS_RESOLUTION_ENTRY (gre));
581
gimp_resolution_entry_field_set_boundaries (&gre->x,
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.
592
* Limits the range of possible values which can be entered in the y field
593
* of the #GimpResolutionEntry.
595
* The current value of the field will be clamped to fit in its
602
gimp_resolution_entry_set_y_boundaries (GimpResolutionEntry *gre,
606
g_return_if_fail (GIMP_IS_RESOLUTION_ENTRY (gre));
607
g_return_if_fail (gre->independent);
609
gimp_resolution_entry_field_set_boundaries (&gre->y,
615
gimp_resolution_entry_field_set_boundaries (GimpResolutionEntryField *gref,
619
g_return_if_fail (lower <= upper);
621
gref->min_value = lower;
622
gref->max_value = upper;
624
GTK_ADJUSTMENT (gref->adjustment)->lower = gref->min_value;
625
GTK_ADJUSTMENT (gref->adjustment)->upper = gref->max_value;
627
if (gref->value > upper || gref->value < lower)
628
gimp_resolution_entry_field_set_value (gref, gref->value);
632
* gimp_resolution_entry_get_width;
633
* @gre: The #GimpResolutionEntry you want to know the width of.
635
* Returns the width of the #GimpResolutionEntry in pixels.
637
* SeeAlso: gimp_resolution_get_x
643
gimp_resolution_entry_get_width (GimpResolutionEntry *gre)
645
g_return_val_if_fail (GIMP_IS_RESOLUTION_ENTRY (gre), 0);
647
return gre->width.value;
651
* gimp_resolution_entry_get_height;
652
* @gre: The #GimpResolutionEntry you want to know the height of.
654
* Returns the height of the #GimpResolutionEntry in pixels.
656
* SeeAlso: gimp_resolution_get_y
662
gimp_resolution_entry_get_height (GimpResolutionEntry *gre)
664
g_return_val_if_fail (GIMP_IS_RESOLUTION_ENTRY (gre), 0);
666
return gre->height.value;
670
* gimp_resolution_entry_get_x;
671
* @gre: The #GimpResolutionEntry you want to know the resolution of.
673
* Returns the X resolution of the #GimpResolutionEntry in the current unit.
675
* SeeAlso: gimp_resolution_get_x_in_dpi
681
gimp_resolution_entry_get_x (GimpResolutionEntry *gre)
683
g_return_val_if_fail (GIMP_IS_RESOLUTION_ENTRY (gre), 0);
689
* gimp_resolution_entry_get_x_in_dpi;
690
* @gre: The #GimpResolutionEntry you want to know the resolution of.
692
* Returns the X resolution of the #GimpResolutionEntry in pixels per inch.
694
* SeeAlso: gimp_resolution_get_x
700
gimp_resolution_entry_get_x_in_dpi (GimpResolutionEntry *gre)
702
g_return_val_if_fail (GIMP_IS_RESOLUTION_ENTRY (gre), 0);
704
return gre->x.value / gimp_unit_get_factor (gre->unit);
708
* gimp_resolution_entry_get_y;
709
* @gre: The #GimpResolutionEntry you want to know the resolution of.
711
* Returns the Y resolution of the #GimpResolutionEntry in the current unit.
713
* SeeAlso: gimp_resolution_get_y_in_dpi
719
gimp_resolution_entry_get_y (GimpResolutionEntry *gre)
721
g_return_val_if_fail (GIMP_IS_RESOLUTION_ENTRY (gre), 0);
727
* gimp_resolution_entry_get_y_in_dpi;
728
* @gre: The #GimpResolutionEntry you want to know the resolution of.
730
* Returns the Y resolution of the #GimpResolutionEntry in pixels per inch.
732
* SeeAlso: gimp_resolution_get_y
738
gimp_resolution_entry_get_y_in_dpi (GimpResolutionEntry *gre)
740
g_return_val_if_fail (GIMP_IS_RESOLUTION_ENTRY (gre), 0);
742
return gre->y.value / gimp_unit_get_factor (gre->unit);
747
gimp_resolution_entry_update_value (GimpResolutionEntryField *gref,
750
if (gref->stop_recursion > 0)
755
gref->stop_recursion++;
757
if (gref->gre->independent &&
759
gimp_chain_button_get_active (GIMP_CHAIN_BUTTON (gref->gre->chainbutton)))
761
gimp_resolution_entry_update_value (&gref->gre->x, value);
762
gimp_resolution_entry_update_value (&gref->gre->y, value);
766
gimp_resolution_entry_update_value (gref->corresponding,
769
gimp_unit_get_factor (gref->gre->unit));
772
gdouble factor = gimp_unit_get_factor (gref->gre->unit);
774
if (gref->gre->independent)
775
gimp_resolution_entry_update_value (gref->corresponding,
777
gref->corresponding->phy_size *
781
gimp_resolution_entry_update_value (&gref->gre->width,
783
gref->gre->width.phy_size *
786
gimp_resolution_entry_update_value (&gref->gre->height,
788
gref->gre->height.phy_size *
793
gtk_adjustment_set_value (GTK_ADJUSTMENT (gref->adjustment), value);
795
gref->stop_recursion--;
797
g_signal_emit (gref->gre, gref->changed_signal, 0);
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.
805
* Sets the value for the width control of the #GimpResolutionEntry.
810
gimp_resolution_entry_set_width (GimpResolutionEntry *gre,
813
g_return_if_fail (GIMP_IS_RESOLUTION_ENTRY (gre));
815
gimp_resolution_entry_field_set_value (&gre->width,
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.
824
* Sets the value for the height control of the #GimpResolutionEntry.
829
gimp_resolution_entry_set_height (GimpResolutionEntry *gre,
832
g_return_if_fail (GIMP_IS_RESOLUTION_ENTRY (gre));
834
gimp_resolution_entry_field_set_value (&gre->height,
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.
843
* Sets the value for the x resolution of the #GimpResolutionEntry.
848
gimp_resolution_entry_set_x (GimpResolutionEntry *gre,
851
g_return_if_fail (GIMP_IS_RESOLUTION_ENTRY (gre));
853
gimp_resolution_entry_field_set_value (&gre->x,
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.
861
* Sets the value for the y resolution of the #GimpResolutionEntry.
866
gimp_resolution_entry_set_y (GimpResolutionEntry *gre,
869
g_return_if_fail (GIMP_IS_RESOLUTION_ENTRY (gre));
871
gimp_resolution_entry_field_set_value (&gre->y,
876
gimp_resolution_entry_field_set_value (GimpResolutionEntryField *gref,
879
value = CLAMP (value, gref->min_value, gref->max_value);
881
gtk_adjustment_set_value (GTK_ADJUSTMENT (gref->adjustment), value);
882
gimp_resolution_entry_update_value (gref, value);
886
gimp_resolution_entry_value_callback (GtkWidget *widget,
889
GimpResolutionEntryField *gref;
892
gref = (GimpResolutionEntryField *) data;
894
new_value = GTK_ADJUSTMENT (widget)->value;
896
if (gref->value != new_value)
897
gimp_resolution_entry_update_value (gref, new_value);
901
* gimp_resolution_entry_get_unit:
902
* @gre: The #GimpResolutionEntry you want to know the unit of.
904
* Returns the #GimpUnit the user has selected in the #GimpResolutionEntry's
907
* Returns: The #GimpResolutionEntry's unit.
912
gimp_resolution_entry_get_unit (GimpResolutionEntry *gre)
914
g_return_val_if_fail (GIMP_IS_RESOLUTION_ENTRY (gre), GIMP_UNIT_INCH);
920
gimp_resolution_entry_update_unit (GimpResolutionEntry *gre,
927
old_unit = gre->unit;
930
digits = (gimp_unit_get_digits (GIMP_UNIT_INCH) -
931
gimp_unit_get_digits (unit));
933
gtk_spin_button_set_digits (GTK_SPIN_BUTTON (gre->x.spinbutton),
934
MAX (3 + digits, 3));
937
factor = gimp_unit_get_factor (old_unit) / gimp_unit_get_factor (unit);
939
gre->x.min_value *= factor;
940
gre->x.max_value *= factor;
941
gre->x.value *= factor;
943
gtk_adjustment_set_value (GTK_ADJUSTMENT (gre->x.adjustment),
947
if (gre->independent)
949
gtk_spin_button_set_digits (GTK_SPIN_BUTTON (gre->y.spinbutton),
950
MAX (3 + digits, 3));
952
gre->y.min_value *= factor;
953
gre->y.max_value *= factor;
954
gre->y.value *= factor;
956
gtk_adjustment_set_value (GTK_ADJUSTMENT (gre->y.adjustment),
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);
966
g_signal_emit (gre, gimp_resolution_entry_signals[UNIT_CHANGED], 0);
970
* gimp_resolution_entry_set_unit:
971
* @gre: The #GimpResolutionEntry you want to change the unit for.
972
* @unit: The new unit.
974
* Sets the #GimpResolutionEntry's unit. The resolution will
975
* stay the same but the value in pixels per unit will change
981
gimp_resolution_entry_set_unit (GimpResolutionEntry *gre,
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);
988
gimp_unit_menu_set_unit (GIMP_UNIT_MENU (gre->unitmenu), unit);
989
gimp_resolution_entry_update_unit (gre, unit);
993
gimp_resolution_entry_unit_callback (GtkWidget *widget,
994
GimpResolutionEntry *gre)
998
new_unit = gimp_unit_menu_get_unit (GIMP_UNIT_MENU (widget));
1000
if (gre->unit != new_unit)
1001
gimp_resolution_entry_update_unit (gre, new_unit);
1005
* gimp_resolution_entry_show_unit_menu:
1006
* @gre: a #GimpResolutionEntry
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.
1015
gimp_resolution_entry_show_unit_menu (GimpResolutionEntry *gre,
1018
g_return_if_fail (GIMP_IS_RESOLUTION_ENTRY (gre));
1021
gtk_widget_show (gre->unitmenu);
1023
gtk_widget_hide (gre->unitmenu);
1028
* gimp_resolution_entry_set_pixel_digits:
1029
* @gre: a #GimpResolutionEntry
1030
* @digits: the number of digits to display for a pixel size
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.
1038
gimp_resolution_entry_set_pixel_digits (GimpResolutionEntry *gre,
1043
g_return_if_fail (GIMP_IS_RESOLUTION_ENTRY (gre));
1045
menu = GIMP_UNIT_MENU (gre->unitmenu);
1047
gimp_unit_menu_set_pixel_digits (menu, digits);
1048
gimp_resolution_entry_update_unit (gre, gimp_unit_menu_get_unit (menu));
1053
* gimp_resolution_entry_grab_focus:
1054
* @gre: The #GimpResolutionEntry you want to grab the keyboard focus.
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.
1062
gimp_resolution_entry_grab_focus (GimpResolutionEntry *gre)
1064
g_return_if_fail (GIMP_IS_RESOLUTION_ENTRY (gre));
1066
gtk_widget_grab_focus (gre->x.spinbutton);
1070
* gimp_resolution_entry_set_activates_default:
1071
* @gre: A #GimpResolutionEntry
1072
* @setting: %TRUE to activate window's default widget on Enter keypress
1074
* Iterates over all entries in the #GimpResolutionEntry and calls
1075
* gtk_entry_set_activates_default() on them.
1080
gimp_resolution_entry_set_activates_default (GimpResolutionEntry *gre,
1083
g_return_if_fail (GIMP_IS_RESOLUTION_ENTRY (gre));
1085
gtk_entry_set_activates_default (GTK_ENTRY (gre->width.spinbutton),
1087
gtk_entry_set_activates_default (GTK_ENTRY (gre->height.spinbutton),
1089
gtk_entry_set_activates_default (GTK_ENTRY (gre->x.spinbutton),
1092
if (gre->independent)
1093
gtk_entry_set_activates_default (GTK_ENTRY (gre->y.spinbutton),
1099
* gimp_resolution_entry_get_width_help_widget:
1100
* @gre: a #GimpResolutionEntry
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.
1106
* Return value: a #GtkWidget pointer that you can attach a tooltip to.
1109
gimp_resolution_entry_get_width_help_widget (GimpResolutionEntry *gre)
1111
g_return_val_if_fail (GIMP_IS_RESOLUTION_ENTRY (gre), NULL);
1113
return gre->width.spinbutton;
1117
* gimp_resolution_entry_get_height_help_widget:
1118
* @gre: a #GimpResolutionEntry
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.
1124
* Return value: a #GtkWidget pointer that you can attach a tooltip to.
1127
gimp_resolution_entry_get_height_help_widget (GimpResolutionEntry *gre)
1129
g_return_val_if_fail (GIMP_IS_RESOLUTION_ENTRY (gre), NULL);
1131
return gre->height.spinbutton;
1135
* gimp_resolution_entry_get_x_help_widget:
1136
* @gre: a #GimpResolutionEntry
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.
1142
* Return value: a #GtkWidget pointer that you can attach a tooltip to.
1145
gimp_resolution_entry_get_x_help_widget (GimpResolutionEntry *gre)
1147
g_return_val_if_fail (GIMP_IS_RESOLUTION_ENTRY (gre), NULL);
1149
return gre->x.spinbutton;
1153
* gimp_resolution_entry_get_x_help_widget:
1154
* @gre: a #GimpResolutionEntry
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.
1160
* Return value: a #GtkWidget pointer that you can attach a tooltip to.
1163
gimp_resolution_entry_get_y_help_widget (GimpResolutionEntry *gre)
1165
g_return_val_if_fail (GIMP_IS_RESOLUTION_ENTRY (gre), NULL);
1166
g_return_val_if_fail (gre->independent, NULL);
1168
return gre->x.spinbutton;
1172
* gimp_resolution_entry_update_width:
1173
* @gre: the #GimpResolutionEntry
1174
* @data: a pointer to a gdouble
1176
* Convenience function to set a double to the width, suitable
1177
* for use as a signal callback.
1183
gimp_resolution_entry_update_width (GimpResolutionEntry *gre,
1188
g_return_if_fail (gre != NULL);
1189
g_return_if_fail (data != NULL);
1190
g_return_if_fail (GIMP_IS_RESOLUTION_ENTRY (gre));
1192
val = (gdouble *) data;
1194
*val = gimp_resolution_entry_get_width (gre);
1199
* gimp_resolution_entry_update_height:
1200
* @gre: the #GimpResolutionEntry
1201
* @data: a pointer to a gdouble
1203
* Convenience function to set a double to the height, suitable
1204
* for use as a signal callback.
1210
gimp_resolution_entry_update_height (GimpResolutionEntry *gre,
1215
g_return_if_fail (gre != NULL);
1216
g_return_if_fail (data != NULL);
1217
g_return_if_fail (GIMP_IS_RESOLUTION_ENTRY (gre));
1219
val = (gdouble *) data;
1221
*val = gimp_resolution_entry_get_height (gre);
1226
* gimp_resolution_entry_update_x:
1227
* @gre: the #GimpResolutionEntry
1228
* @data: a pointer to a gdouble
1230
* Convenience function to set a double to the X resolution, suitable
1231
* for use as a signal callback.
1237
gimp_resolution_entry_update_x (GimpResolutionEntry *gre,
1242
g_return_if_fail (gre != NULL);
1243
g_return_if_fail (data != NULL);
1244
g_return_if_fail (GIMP_IS_RESOLUTION_ENTRY (gre));
1246
val = (gdouble *) data;
1248
*val = gimp_resolution_entry_get_x (gre);
1252
* gimp_resolution_entry_update_x_in_dpi:
1253
* @gre: the #GimpResolutionEntry
1254
* @data: a pointer to a gdouble
1256
* Convenience function to set a double to the X resolution, suitable
1257
* for use as a signal callback.
1263
gimp_resolution_entry_update_x_in_dpi (GimpResolutionEntry *gre,
1268
g_return_if_fail (gre != NULL);
1269
g_return_if_fail (data != NULL);
1270
g_return_if_fail (GIMP_IS_RESOLUTION_ENTRY (gre));
1272
val = (gdouble *) data;
1274
*val = gimp_resolution_entry_get_x_in_dpi (gre);
1278
* gimp_resolution_entry_update_y:
1279
* @gre: the #GimpResolutionEntry
1280
* @data: a pointer to a gdouble
1282
* Convenience function to set a double to the Y resolution, suitable
1283
* for use as a signal callback.
1289
gimp_resolution_entry_update_y (GimpResolutionEntry *gre,
1294
g_return_if_fail (gre != NULL);
1295
g_return_if_fail (data != NULL);
1296
g_return_if_fail (GIMP_IS_RESOLUTION_ENTRY (gre));
1298
val = (gdouble *) data;
1300
*val = gimp_resolution_entry_get_y (gre);
1304
* gimp_resolution_entry_update_y_in_dpi:
1305
* @gre: the #GimpResolutionEntry
1306
* @data: a pointer to a gdouble
1308
* Convenience function to set a double to the Y resolution, suitable
1309
* for use as a signal callback.
1315
gimp_resolution_entry_update_y_in_dpi (GimpResolutionEntry *gre,
1320
g_return_if_fail (gre != NULL);
1321
g_return_if_fail (data != NULL);
1322
g_return_if_fail (GIMP_IS_RESOLUTION_ENTRY (gre));
1324
val = (gdouble *) data;
1326
*val = gimp_resolution_entry_get_y_in_dpi (gre);
1330
gimp_resolution_entry_format_label (GimpResolutionEntry *gre,
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));
1341
gtk_label_set_text (GTK_LABEL (label), text);