1
/* The GIMP -- an image manipulation program
2
* Copyright (C) 1995-1997 Spencer Kimball and Peter Mattis
5
* Copyright (C) 2002-2004 Michael Natterer <mitch@gimp.org>
6
* Sven Neumann <sven@gimp.org>
8
* This program is free software; you can redistribute it and/or modify
9
* it under the terms of the GNU General Public License as published by
10
* the Free Software Foundation; either version 2 of the License, or
11
* (at your option) any later version.
13
* This program is distributed in the hope that it will be useful,
14
* but WITHOUT ANY WARRANTY; without even the implied warranty of
15
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
* GNU General Public License for more details.
18
* You should have received a copy of the GNU General Public License
19
* along with this program; if not, write to the Free Software
20
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
29
#include "libgimpcolor/gimpcolor.h"
30
#include "libgimpmath/gimpmath.h"
31
#include "libgimpbase/gimpbase.h"
32
#include "libgimpwidgets/gimpwidgets.h"
34
#include "widgets-types.h"
36
#include "config/gimpconfig-params.h"
37
#include "config/gimpconfig-path.h"
39
#include "core/gimpviewable.h"
41
#include "gimpcolorpanel.h"
43
#include "gimpenumcombobox.h"
44
#include "gimpenumstore.h"
45
#include "gimpenumwidgets.h"
47
#include "gimppropwidgets.h"
48
#include "gimpwidgets-constructors.h"
50
#include "gimp-intl.h"
53
/* utility function prototypes */
55
static void set_param_spec (GObject *object,
57
GParamSpec *param_spec);
58
static void set_radio_spec (GObject *object,
59
GParamSpec *param_spec);
60
static GParamSpec * get_param_spec (GObject *object);
62
static GParamSpec * find_param_spec (GObject *object,
63
const gchar *property_name,
65
static GParamSpec * check_param_spec (GObject *object,
66
const gchar *property_name,
70
static gboolean get_numeric_values (GObject *object,
71
GParamSpec *param_spec,
77
static void connect_notify (GObject *config,
78
const gchar *property_name,
80
gpointer callback_data);
87
static void gimp_prop_check_button_callback (GtkWidget *widget,
89
static void gimp_prop_check_button_notify (GObject *config,
90
GParamSpec *param_spec,
94
gimp_prop_check_button_new (GObject *config,
95
const gchar *property_name,
98
GParamSpec *param_spec;
102
param_spec = check_param_spec (config, property_name,
103
G_TYPE_PARAM_BOOLEAN, G_STRFUNC);
107
g_object_get (config,
108
property_name, &value,
111
button = gtk_check_button_new_with_mnemonic (label);
112
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (button), value);
114
set_param_spec (G_OBJECT (button), button, param_spec);
116
g_signal_connect (button, "toggled",
117
G_CALLBACK (gimp_prop_check_button_callback),
120
connect_notify (config, property_name,
121
G_CALLBACK (gimp_prop_check_button_notify),
128
gimp_prop_check_button_callback (GtkWidget *widget,
131
GParamSpec *param_spec;
133
param_spec = get_param_spec (G_OBJECT (widget));
137
g_object_set (config,
138
param_spec->name, GTK_TOGGLE_BUTTON (widget)->active,
141
gimp_toggle_button_sensitive_update (GTK_TOGGLE_BUTTON (widget));
145
gimp_prop_check_button_notify (GObject *config,
146
GParamSpec *param_spec,
151
g_object_get (config,
152
param_spec->name, &value,
155
if (GTK_TOGGLE_BUTTON (button)->active != value)
157
g_signal_handlers_block_by_func (button,
158
gimp_prop_check_button_callback,
161
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (button), value);
162
gimp_toggle_button_sensitive_update (GTK_TOGGLE_BUTTON (button));
164
g_signal_handlers_unblock_by_func (button,
165
gimp_prop_check_button_callback,
171
static void gimp_prop_enum_check_button_callback (GtkWidget *widget,
173
static void gimp_prop_enum_check_button_notify (GObject *config,
174
GParamSpec *param_spec,
178
gimp_prop_enum_check_button_new (GObject *config,
179
const gchar *property_name,
184
GParamSpec *param_spec;
188
param_spec = check_param_spec (config, property_name,
189
G_TYPE_PARAM_ENUM, G_STRFUNC);
193
g_object_get (config,
194
property_name, &value,
197
button = gtk_check_button_new_with_mnemonic (label);
198
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (button), value == true_value);
200
if (value != false_value && value != true_value)
201
gtk_toggle_button_set_inconsistent (GTK_TOGGLE_BUTTON (button), TRUE);
203
set_param_spec (G_OBJECT (button), button, param_spec);
205
g_object_set_data (G_OBJECT (button), "false-value",
206
GINT_TO_POINTER (false_value));
207
g_object_set_data (G_OBJECT (button), "true-value",
208
GINT_TO_POINTER (true_value));
210
g_signal_connect (button, "toggled",
211
G_CALLBACK (gimp_prop_enum_check_button_callback),
214
connect_notify (config, property_name,
215
G_CALLBACK (gimp_prop_enum_check_button_notify),
222
gimp_prop_enum_check_button_callback (GtkWidget *widget,
225
GParamSpec *param_spec;
229
param_spec = get_param_spec (G_OBJECT (widget));
233
false_value = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (widget),
235
true_value = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (widget),
238
g_object_set (config,
240
GTK_TOGGLE_BUTTON (widget)->active ? true_value : false_value,
243
gtk_toggle_button_set_inconsistent (GTK_TOGGLE_BUTTON (widget), FALSE);
245
gimp_toggle_button_sensitive_update (GTK_TOGGLE_BUTTON (widget));
249
gimp_prop_enum_check_button_notify (GObject *config,
250
GParamSpec *param_spec,
256
gboolean active = FALSE;
257
gboolean inconsistent = FALSE;
259
g_object_get (config,
260
param_spec->name, &value,
263
false_value = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (button),
265
true_value = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (button),
268
if (value == true_value)
270
else if (value != false_value)
273
gtk_toggle_button_set_inconsistent (GTK_TOGGLE_BUTTON (button),
276
if (GTK_TOGGLE_BUTTON (button)->active != active)
278
g_signal_handlers_block_by_func (button,
279
gimp_prop_enum_check_button_callback,
282
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (button), active);
283
gimp_toggle_button_sensitive_update (GTK_TOGGLE_BUTTON (button));
285
g_signal_handlers_unblock_by_func (button,
286
gimp_prop_enum_check_button_callback,
292
/*************************/
293
/* int/enum combo box */
294
/*************************/
296
static void gimp_prop_int_combo_box_callback (GtkWidget *widget,
298
static void gimp_prop_int_combo_box_notify (GObject *config,
299
GParamSpec *param_spec,
303
gimp_prop_int_combo_box_new (GObject *config,
304
const gchar *property_name,
307
GParamSpec *param_spec;
308
GtkWidget *combo_box;
312
param_spec = check_param_spec (config, property_name,
313
G_TYPE_PARAM_INT, G_STRFUNC);
317
g_object_get (config,
318
property_name, &value,
321
combo_box = g_object_new (GIMP_TYPE_INT_COMBO_BOX,
325
gimp_int_combo_box_set_active (GIMP_INT_COMBO_BOX (combo_box), value);
327
g_signal_connect (combo_box, "changed",
328
G_CALLBACK (gimp_prop_int_combo_box_callback),
331
/* can't set a tooltip on a combo_box */
332
if (g_param_spec_get_blurb (param_spec))
334
widget = gtk_event_box_new ();
335
gtk_container_add (GTK_CONTAINER (widget), combo_box);
336
gtk_widget_show (combo_box);
343
set_param_spec (G_OBJECT (combo_box), widget, param_spec);
345
connect_notify (config, property_name,
346
G_CALLBACK (gimp_prop_int_combo_box_notify),
353
gimp_prop_enum_combo_box_new (GObject *config,
354
const gchar *property_name,
358
GParamSpec *param_spec;
359
GtkWidget *combo_box;
363
param_spec = check_param_spec (config, property_name,
364
G_TYPE_PARAM_ENUM, G_STRFUNC);
368
g_object_get (config,
369
property_name, &value,
372
if (minimum != maximum)
376
store = gimp_enum_store_new_with_range (param_spec->value_type,
379
combo_box = g_object_new (GIMP_TYPE_ENUM_COMBO_BOX,
383
g_object_unref (store);
387
combo_box = gimp_enum_combo_box_new (param_spec->value_type);
390
gimp_int_combo_box_set_active (GIMP_INT_COMBO_BOX (combo_box), value);
392
g_signal_connect (combo_box, "changed",
393
G_CALLBACK (gimp_prop_int_combo_box_callback),
396
/* can't set a tooltip on a combo_box */
397
if (g_param_spec_get_blurb (param_spec))
399
widget = gtk_event_box_new ();
400
gtk_container_add (GTK_CONTAINER (widget), combo_box);
401
gtk_widget_show (combo_box);
408
set_param_spec (G_OBJECT (combo_box), widget, param_spec);
410
connect_notify (config, property_name,
411
G_CALLBACK (gimp_prop_int_combo_box_notify),
418
gimp_prop_int_combo_box_callback (GtkWidget *widget,
421
GParamSpec *param_spec;
424
param_spec = get_param_spec (G_OBJECT (widget));
428
if (gimp_int_combo_box_get_active (GIMP_INT_COMBO_BOX (widget), &value))
430
g_object_set (config,
431
param_spec->name, value,
437
gimp_prop_int_combo_box_notify (GObject *config,
438
GParamSpec *param_spec,
439
GtkWidget *combo_box)
443
g_object_get (config,
444
param_spec->name, &value,
447
g_signal_handlers_block_by_func (combo_box,
448
gimp_prop_int_combo_box_callback,
451
gimp_int_combo_box_set_active (GIMP_INT_COMBO_BOX (combo_box), value);
453
g_signal_handlers_unblock_by_func (combo_box,
454
gimp_prop_int_combo_box_callback,
459
/************************/
460
/* boolean combo box */
461
/************************/
463
static void gimp_prop_boolean_combo_box_callback (GtkWidget *widget,
465
static void gimp_prop_boolean_combo_box_notify (GObject *config,
466
GParamSpec *param_spec,
471
gimp_prop_boolean_combo_box_new (GObject *config,
472
const gchar *property_name,
473
const gchar *true_text,
474
const gchar *false_text)
476
GParamSpec *param_spec;
477
GtkWidget *combo_box;
481
param_spec = check_param_spec (config, property_name,
482
G_TYPE_PARAM_BOOLEAN, G_STRFUNC);
486
g_object_get (config,
487
property_name, &value,
490
combo_box = gtk_combo_box_new_text ();
492
gtk_combo_box_append_text (GTK_COMBO_BOX (combo_box), true_text);
493
gtk_combo_box_append_text (GTK_COMBO_BOX (combo_box), false_text);
495
gtk_combo_box_set_active (GTK_COMBO_BOX (combo_box), value ? 0 : 1);
497
g_signal_connect (combo_box, "changed",
498
G_CALLBACK (gimp_prop_boolean_combo_box_callback),
501
/* can't set a tooltip on a combo_box */
502
if (g_param_spec_get_blurb (param_spec))
504
widget = gtk_event_box_new ();
505
gtk_container_add (GTK_CONTAINER (widget), combo_box);
506
gtk_widget_show (combo_box);
513
set_param_spec (G_OBJECT (combo_box), widget, param_spec);
515
connect_notify (config, property_name,
516
G_CALLBACK (gimp_prop_boolean_combo_box_notify),
523
gimp_prop_boolean_combo_box_callback (GtkWidget *widget,
526
GParamSpec *param_spec;
529
param_spec = get_param_spec (G_OBJECT (widget));
533
value = gtk_combo_box_get_active (GTK_COMBO_BOX (widget));
535
g_object_set (config,
536
param_spec->name, value ? FALSE : TRUE,
541
gimp_prop_boolean_combo_box_notify (GObject *config,
542
GParamSpec *param_spec,
543
GtkWidget *combo_box)
547
g_object_get (config,
548
param_spec->name, &value,
551
g_signal_handlers_block_by_func (combo_box,
552
gimp_prop_boolean_combo_box_callback,
555
gtk_combo_box_set_active (GTK_COMBO_BOX (combo_box), value ? 0 : 1);
557
g_signal_handlers_unblock_by_func (combo_box,
558
gimp_prop_boolean_combo_box_callback,
567
static void gimp_prop_paint_menu_callback (GtkWidget *widget,
569
static void gimp_prop_paint_menu_notify (GObject *config,
570
GParamSpec *param_spec,
574
gimp_prop_paint_mode_menu_new (GObject *config,
575
const gchar *property_name,
576
gboolean with_behind_mode)
578
GParamSpec *param_spec;
582
param_spec = check_param_spec (config, property_name,
583
G_TYPE_PARAM_ENUM, G_STRFUNC);
587
g_object_get (config,
588
property_name, &value,
591
menu = gimp_paint_mode_menu_new (G_CALLBACK (gimp_prop_paint_menu_callback),
596
set_param_spec (G_OBJECT (menu), menu, param_spec);
598
connect_notify (config, property_name,
599
G_CALLBACK (gimp_prop_paint_menu_notify),
606
gimp_prop_paint_menu_callback (GtkWidget *widget,
609
if (GTK_IS_MENU (widget->parent))
613
menu = gtk_menu_get_attach_widget (GTK_MENU (widget->parent));
617
GParamSpec *param_spec;
620
param_spec = get_param_spec (G_OBJECT (menu));
624
value = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (widget),
627
g_object_set (config,
628
param_spec->name, value,
635
gimp_prop_paint_menu_notify (GObject *config,
636
GParamSpec *param_spec,
641
g_object_get (config,
642
param_spec->name, &value,
645
gimp_paint_mode_menu_set_history (GTK_OPTION_MENU (menu), value);
653
static void gimp_prop_radio_button_callback (GtkWidget *widget,
655
static void gimp_prop_radio_button_notify (GObject *config,
656
GParamSpec *param_spec,
661
gimp_prop_enum_radio_frame_new (GObject *config,
662
const gchar *property_name,
667
GParamSpec *param_spec;
672
param_spec = check_param_spec (config, property_name,
673
G_TYPE_PARAM_ENUM, G_STRFUNC);
677
g_object_get (config,
678
property_name, &value,
681
if (minimum != maximum)
683
frame = gimp_enum_radio_frame_new_with_range (param_spec->value_type,
685
gtk_label_new (label),
686
G_CALLBACK (gimp_prop_radio_button_callback),
692
frame = gimp_enum_radio_frame_new (param_spec->value_type,
693
gtk_label_new (label),
694
G_CALLBACK (gimp_prop_radio_button_callback),
699
gimp_int_radio_group_set_active (GTK_RADIO_BUTTON (button), value);
701
set_radio_spec (G_OBJECT (button), param_spec);
703
connect_notify (config, property_name,
704
G_CALLBACK (gimp_prop_radio_button_notify),
707
g_object_set_data (G_OBJECT (frame), "radio-button", button);
713
gimp_prop_enum_radio_box_new (GObject *config,
714
const gchar *property_name,
718
GParamSpec *param_spec;
723
param_spec = check_param_spec (config, property_name,
724
G_TYPE_PARAM_ENUM, G_STRFUNC);
728
g_object_get (config,
729
property_name, &value,
732
if (minimum != maximum)
734
vbox = gimp_enum_radio_box_new_with_range (param_spec->value_type,
736
G_CALLBACK (gimp_prop_radio_button_callback),
742
vbox = gimp_enum_radio_box_new (param_spec->value_type,
743
G_CALLBACK (gimp_prop_radio_button_callback),
748
gimp_int_radio_group_set_active (GTK_RADIO_BUTTON (button), value);
750
set_radio_spec (G_OBJECT (button), param_spec);
752
connect_notify (config, property_name,
753
G_CALLBACK (gimp_prop_radio_button_notify),
756
g_object_set_data (G_OBJECT (vbox), "radio-button", button);
762
gimp_prop_boolean_radio_frame_new (GObject *config,
763
const gchar *property_name,
765
const gchar *true_text,
766
const gchar *false_text)
768
GParamSpec *param_spec;
773
param_spec = check_param_spec (config, property_name,
774
G_TYPE_PARAM_BOOLEAN, G_STRFUNC);
778
g_object_get (config,
779
property_name, &value,
783
gimp_int_radio_group_new (TRUE, title,
784
G_CALLBACK (gimp_prop_radio_button_callback),
787
false_text, FALSE, &button,
788
true_text, TRUE, NULL,
792
set_radio_spec (G_OBJECT (button), param_spec);
794
connect_notify (config, property_name,
795
G_CALLBACK (gimp_prop_radio_button_notify),
798
g_object_set_data (G_OBJECT (frame), "radio-button", button);
804
gimp_prop_enum_stock_box_new (GObject *config,
805
const gchar *property_name,
806
const gchar *stock_prefix,
810
GParamSpec *param_spec;
815
param_spec = check_param_spec (config, property_name,
816
G_TYPE_PARAM_ENUM, G_STRFUNC);
820
g_object_get (config,
821
property_name, &value,
824
if (minimum != maximum)
826
box = gimp_enum_stock_box_new_with_range (param_spec->value_type,
830
G_CALLBACK (gimp_prop_radio_button_callback),
836
box = gimp_enum_stock_box_new (param_spec->value_type,
839
G_CALLBACK (gimp_prop_radio_button_callback),
844
gimp_int_radio_group_set_active (GTK_RADIO_BUTTON (button), value);
846
set_radio_spec (G_OBJECT (button), param_spec);
848
connect_notify (config, property_name,
849
G_CALLBACK (gimp_prop_radio_button_notify),
856
gimp_prop_radio_button_callback (GtkWidget *widget,
859
if (GTK_TOGGLE_BUTTON (widget)->active)
861
GParamSpec *param_spec;
864
param_spec = get_param_spec (G_OBJECT (widget));
868
value = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (widget),
871
g_object_set (config,
872
param_spec->name, value,
878
gimp_prop_radio_button_notify (GObject *config,
879
GParamSpec *param_spec,
884
g_object_get (config,
885
param_spec->name, &value,
888
gimp_int_radio_group_set_active (GTK_RADIO_BUTTON (button), value);
896
static void gimp_prop_adjustment_callback (GtkAdjustment *adjustment,
898
static void gimp_prop_adjustment_notify (GObject *config,
899
GParamSpec *param_spec,
900
GtkAdjustment *adjustment);
903
gimp_prop_spin_button_new (GObject *config,
904
const gchar *property_name,
905
gdouble step_increment,
906
gdouble page_increment,
909
GParamSpec *param_spec;
910
GtkWidget *spinbutton;
911
GtkObject *adjustment;
916
param_spec = find_param_spec (config, property_name, G_STRFUNC);
920
if (! get_numeric_values (config,
921
param_spec, &value, &lower, &upper, G_STRFUNC))
924
if (! G_IS_PARAM_SPEC_DOUBLE (param_spec))
927
spinbutton = gimp_spin_button_new (&adjustment,
929
step_increment, page_increment,
932
set_param_spec (G_OBJECT (adjustment), spinbutton, param_spec);
934
g_signal_connect (adjustment, "value_changed",
935
G_CALLBACK (gimp_prop_adjustment_callback),
938
connect_notify (config, property_name,
939
G_CALLBACK (gimp_prop_adjustment_notify),
946
gimp_prop_scale_entry_new (GObject *config,
947
const gchar *property_name,
952
gdouble step_increment,
953
gdouble page_increment,
955
gboolean restrict_scale,
956
gdouble restricted_lower,
957
gdouble restricted_upper)
959
GParamSpec *param_spec;
960
GtkObject *adjustment;
961
const gchar *tooltip;
966
param_spec = find_param_spec (config, property_name, G_STRFUNC);
970
if (! get_numeric_values (config,
971
param_spec, &value, &lower, &upper, G_STRFUNC))
974
tooltip = gettext (g_param_spec_get_blurb (param_spec));
976
if (! restrict_scale)
978
adjustment = gimp_scale_entry_new (table, column, row,
981
step_increment, page_increment, digits,
988
adjustment = gimp_scale_entry_new (table, column, row,
993
step_increment, page_increment, digits,
999
set_param_spec (G_OBJECT (adjustment), NULL, param_spec);
1001
g_signal_connect (adjustment, "value_changed",
1002
G_CALLBACK (gimp_prop_adjustment_callback),
1005
connect_notify (config, property_name,
1006
G_CALLBACK (gimp_prop_adjustment_notify),
1013
gimp_prop_opacity_entry_new (GObject *config,
1014
const gchar *property_name,
1020
GParamSpec *param_spec;
1021
GtkObject *adjustment;
1022
const gchar *tooltip;
1027
param_spec = check_param_spec (config, property_name,
1028
G_TYPE_PARAM_DOUBLE, G_STRFUNC);
1032
g_object_get (config, property_name, &value, NULL);
1034
tooltip = gettext (g_param_spec_get_blurb (param_spec));
1037
lower = G_PARAM_SPEC_DOUBLE (param_spec)->minimum * 100.0;
1038
upper = G_PARAM_SPEC_DOUBLE (param_spec)->maximum * 100.0;
1040
adjustment = gimp_scale_entry_new (table, column, row,
1042
value, lower, upper,
1048
set_param_spec (G_OBJECT (adjustment), NULL, param_spec);
1049
g_object_set_data (G_OBJECT (adjustment),
1050
"opacity-scale", GINT_TO_POINTER (TRUE));
1052
g_signal_connect (adjustment, "value_changed",
1053
G_CALLBACK (gimp_prop_adjustment_callback),
1056
connect_notify (config, property_name,
1057
G_CALLBACK (gimp_prop_adjustment_notify),
1065
gimp_prop_adjustment_callback (GtkAdjustment *adjustment,
1068
GParamSpec *param_spec;
1070
param_spec = get_param_spec (G_OBJECT (adjustment));
1074
if (G_IS_PARAM_SPEC_INT (param_spec))
1076
g_object_set (config,
1077
param_spec->name, (gint) adjustment->value,
1080
else if (G_IS_PARAM_SPEC_UINT (param_spec))
1082
g_object_set (config,
1083
param_spec->name, (guint) adjustment->value,
1086
else if (G_IS_PARAM_SPEC_LONG (param_spec))
1088
g_object_set (config,
1089
param_spec->name, (glong) adjustment->value,
1092
else if (G_IS_PARAM_SPEC_ULONG (param_spec))
1094
g_object_set (config,
1095
param_spec->name, (gulong) adjustment->value,
1098
else if (G_IS_PARAM_SPEC_INT64 (param_spec))
1100
g_object_set (config,
1101
param_spec->name, (gint64) adjustment->value,
1104
else if (G_IS_PARAM_SPEC_UINT64 (param_spec))
1106
g_object_set (config,
1107
param_spec->name, (guint64) adjustment->value,
1110
else if (G_IS_PARAM_SPEC_DOUBLE (param_spec))
1114
if (GPOINTER_TO_INT (g_object_get_data (G_OBJECT (adjustment),
1116
value = adjustment->value / 100.0;
1118
value = adjustment->value;
1120
g_object_set (config, param_spec->name, value, NULL);
1125
gimp_prop_adjustment_notify (GObject *config,
1126
GParamSpec *param_spec,
1127
GtkAdjustment *adjustment)
1131
if (G_IS_PARAM_SPEC_INT (param_spec))
1135
g_object_get (config, param_spec->name, &int_value, NULL);
1139
else if (G_IS_PARAM_SPEC_UINT (param_spec))
1143
g_object_get (config, param_spec->name, &uint_value, NULL);
1147
else if (G_IS_PARAM_SPEC_LONG (param_spec))
1151
g_object_get (config, param_spec->name, &long_value, NULL);
1155
else if (G_IS_PARAM_SPEC_ULONG (param_spec))
1159
g_object_get (config, param_spec->name, &ulong_value, NULL);
1161
value = ulong_value;
1163
else if (G_IS_PARAM_SPEC_INT64 (param_spec))
1167
g_object_get (config, param_spec->name, &int64_value, NULL);
1169
value = int64_value;
1171
else if (G_IS_PARAM_SPEC_UINT64 (param_spec))
1173
guint64 uint64_value;
1175
g_object_get (config, param_spec->name, &uint64_value, NULL);
1177
#if defined _MSC_VER && (_MSC_VER < 1300)
1178
value = (gint64) uint64_value;
1180
value = uint64_value;
1183
else if (G_IS_PARAM_SPEC_DOUBLE (param_spec))
1185
g_object_get (config, param_spec->name, &value, NULL);
1187
if (GPOINTER_TO_INT (g_object_get_data (G_OBJECT (adjustment),
1193
g_warning ("%s: unhandled param spec of type %s",
1194
G_STRFUNC, G_PARAM_SPEC_TYPE_NAME (param_spec));
1198
if (adjustment->value != value)
1200
g_signal_handlers_block_by_func (adjustment,
1201
gimp_prop_adjustment_callback,
1204
gtk_adjustment_set_value (adjustment, value);
1206
g_signal_handlers_unblock_by_func (adjustment,
1207
gimp_prop_adjustment_callback,
1217
static void gimp_prop_memsize_callback (GimpMemsizeEntry *entry,
1219
static void gimp_prop_memsize_notify (GObject *config,
1220
GParamSpec *param_spec,
1221
GimpMemsizeEntry *entry);
1224
gimp_prop_memsize_entry_new (GObject *config,
1225
const gchar *property_name)
1227
GParamSpec *param_spec;
1228
GParamSpecUInt64 *uint64_spec;
1232
param_spec = check_param_spec (config, property_name,
1233
GIMP_TYPE_PARAM_MEMSIZE, G_STRFUNC);
1237
g_object_get (config,
1238
property_name, &value,
1241
uint64_spec = G_PARAM_SPEC_UINT64 (param_spec);
1243
g_return_val_if_fail (uint64_spec->minimum <= GIMP_MAX_MEMSIZE, NULL);
1244
g_return_val_if_fail (uint64_spec->maximum <= GIMP_MAX_MEMSIZE, NULL);
1246
entry = gimp_memsize_entry_new (value,
1247
uint64_spec->minimum,
1248
uint64_spec->maximum);
1250
set_param_spec (G_OBJECT (entry),
1251
GIMP_MEMSIZE_ENTRY (entry)->spinbutton,
1254
g_signal_connect (entry, "value_changed",
1255
G_CALLBACK (gimp_prop_memsize_callback),
1258
connect_notify (config, property_name,
1259
G_CALLBACK (gimp_prop_memsize_notify),
1267
gimp_prop_memsize_callback (GimpMemsizeEntry *entry,
1270
GParamSpec *param_spec;
1272
param_spec = get_param_spec (G_OBJECT (entry));
1276
g_return_if_fail (G_IS_PARAM_SPEC_UINT64 (param_spec));
1278
g_object_set (config,
1279
param_spec->name, gimp_memsize_entry_get_value (entry),
1284
gimp_prop_memsize_notify (GObject *config,
1285
GParamSpec *param_spec,
1286
GimpMemsizeEntry *entry)
1290
g_return_if_fail (G_IS_PARAM_SPEC_UINT64 (param_spec));
1292
g_object_get (config,
1293
param_spec->name, &value,
1296
if (entry->value != value)
1298
g_signal_handlers_block_by_func (entry,
1299
gimp_prop_memsize_callback,
1302
gimp_memsize_entry_set_value (entry, value);
1304
g_signal_handlers_unblock_by_func (entry,
1305
gimp_prop_memsize_callback,
1315
static void gimp_prop_label_notify (GObject *config,
1316
GParamSpec *param_spec,
1320
gimp_prop_label_new (GObject *config,
1321
const gchar *property_name)
1323
GParamSpec *param_spec;
1327
param_spec = check_param_spec (config, property_name,
1328
G_TYPE_PARAM_STRING, G_STRFUNC);
1332
g_object_get (config,
1333
property_name, &value,
1336
label = gtk_label_new (value ? value : "");
1339
set_param_spec (G_OBJECT (label), label, param_spec);
1341
connect_notify (config, property_name,
1342
G_CALLBACK (gimp_prop_label_notify),
1349
gimp_prop_label_notify (GObject *config,
1350
GParamSpec *param_spec,
1355
g_object_get (config,
1356
param_spec->name, &value,
1359
gtk_label_set_text (GTK_LABEL (label), value ? value : "");
1369
static void gimp_prop_entry_callback (GtkWidget *entry,
1371
static void gimp_prop_entry_notify (GObject *config,
1372
GParamSpec *param_spec,
1376
gimp_prop_entry_new (GObject *config,
1377
const gchar *property_name,
1380
GParamSpec *param_spec;
1384
param_spec = check_param_spec (config, property_name,
1385
G_TYPE_PARAM_STRING, G_STRFUNC);
1389
g_object_get (config,
1390
property_name, &value,
1393
entry = gtk_entry_new ();
1394
gtk_entry_set_text (GTK_ENTRY (entry), value);
1399
gtk_entry_set_max_length (GTK_ENTRY (entry), max_len);
1401
set_param_spec (G_OBJECT (entry), entry, param_spec);
1403
g_signal_connect (entry, "changed",
1404
G_CALLBACK (gimp_prop_entry_callback),
1407
connect_notify (config, property_name,
1408
G_CALLBACK (gimp_prop_entry_notify),
1415
gimp_prop_entry_callback (GtkWidget *entry,
1418
GParamSpec *param_spec;
1421
param_spec = get_param_spec (G_OBJECT (entry));
1425
text = gtk_entry_get_text (GTK_ENTRY (entry));
1427
g_signal_handlers_block_by_func (config,
1428
gimp_prop_entry_notify,
1431
g_object_set (config,
1432
param_spec->name, text,
1435
g_signal_handlers_unblock_by_func (config,
1436
gimp_prop_entry_notify,
1441
gimp_prop_entry_notify (GObject *config,
1442
GParamSpec *param_spec,
1447
g_object_get (config,
1448
param_spec->name, &value,
1451
g_signal_handlers_block_by_func (entry,
1452
gimp_prop_entry_callback,
1455
gtk_entry_set_text (GTK_ENTRY (entry), value);
1457
g_signal_handlers_unblock_by_func (entry,
1458
gimp_prop_entry_callback,
1469
static void gimp_prop_text_buffer_callback (GtkTextBuffer *text_buffer,
1471
static void gimp_prop_text_buffer_notify (GObject *config,
1472
GParamSpec *param_spec,
1473
GtkTextBuffer *text_buffer);
1476
gimp_prop_text_buffer_new (GObject *config,
1477
const gchar *property_name,
1480
GParamSpec *param_spec;
1481
GtkTextBuffer *text_buffer;
1484
param_spec = check_param_spec (config, property_name,
1485
G_TYPE_PARAM_STRING, G_STRFUNC);
1489
g_object_get (config,
1490
property_name, &value,
1493
text_buffer = gtk_text_buffer_new (NULL);
1494
gtk_text_buffer_set_text (text_buffer, value ? value : "", -1);
1499
g_object_set_data (G_OBJECT (text_buffer), "max-len",
1500
GINT_TO_POINTER (max_len));
1502
set_param_spec (G_OBJECT (text_buffer), NULL, param_spec);
1504
g_signal_connect (text_buffer, "changed",
1505
G_CALLBACK (gimp_prop_text_buffer_callback),
1508
connect_notify (config, property_name,
1509
G_CALLBACK (gimp_prop_text_buffer_notify),
1516
gimp_prop_text_buffer_callback (GtkTextBuffer *text_buffer,
1519
GParamSpec *param_spec;
1520
GtkTextIter start_iter;
1521
GtkTextIter end_iter;
1525
param_spec = get_param_spec (G_OBJECT (text_buffer));
1529
gtk_text_buffer_get_bounds (text_buffer, &start_iter, &end_iter);
1530
text = gtk_text_buffer_get_text (text_buffer, &start_iter, &end_iter, FALSE);
1532
max_len = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (text_buffer),
1535
if (max_len > 0 && strlen (text) > max_len)
1537
g_message (_("This text input field is limited to %d characters."),
1540
gtk_text_buffer_get_iter_at_offset (text_buffer, &start_iter,
1542
gtk_text_buffer_get_end_iter (text_buffer, &end_iter);
1544
/* this calls us recursivaly, but in the else branch */
1545
gtk_text_buffer_delete (text_buffer, &start_iter, &end_iter);
1549
g_signal_handlers_block_by_func (config,
1550
gimp_prop_text_buffer_notify,
1553
g_object_set (config,
1554
param_spec->name, text,
1557
g_signal_handlers_unblock_by_func (config,
1558
gimp_prop_text_buffer_notify,
1566
gimp_prop_text_buffer_notify (GObject *config,
1567
GParamSpec *param_spec,
1568
GtkTextBuffer *text_buffer)
1572
g_object_get (config,
1573
param_spec->name, &value,
1576
g_signal_handlers_block_by_func (text_buffer,
1577
gimp_prop_text_buffer_callback,
1580
gtk_text_buffer_set_text (text_buffer, value ? value : "", -1);
1582
g_signal_handlers_unblock_by_func (text_buffer,
1583
gimp_prop_text_buffer_callback,
1595
static void gimp_prop_file_entry_callback (GimpFileEntry *entry,
1597
static void gimp_prop_file_entry_notify (GObject *config,
1598
GParamSpec *param_spec,
1599
GimpFileEntry *entry);
1602
gimp_prop_file_entry_new (GObject *config,
1603
const gchar *property_name,
1604
const gchar *filesel_title,
1606
gboolean check_valid)
1608
GParamSpec *param_spec;
1613
param_spec = check_param_spec (config, property_name,
1614
GIMP_TYPE_PARAM_PATH, G_STRFUNC);
1618
g_object_get (config,
1619
property_name, &value,
1622
filename = value ? gimp_config_path_expand (value, TRUE, NULL) : NULL;
1625
entry = gimp_file_entry_new (filesel_title, filename, dir_only, check_valid);
1628
set_param_spec (G_OBJECT (entry),
1629
GIMP_FILE_ENTRY (entry)->entry,
1632
g_signal_connect (entry, "filename_changed",
1633
G_CALLBACK (gimp_prop_file_entry_callback),
1636
connect_notify (config, property_name,
1637
G_CALLBACK (gimp_prop_file_entry_notify),
1644
gimp_prop_file_entry_callback (GimpFileEntry *entry,
1647
GParamSpec *param_spec;
1651
param_spec = get_param_spec (G_OBJECT (entry));
1655
value = gimp_file_entry_get_filename (entry);
1656
utf8 = g_filename_to_utf8 (value, -1, NULL, NULL, NULL);
1659
g_signal_handlers_block_by_func (config,
1660
gimp_prop_file_entry_notify,
1663
g_object_set (config,
1664
param_spec->name, utf8,
1667
g_signal_handlers_block_by_func (config,
1668
gimp_prop_file_entry_notify,
1675
gimp_prop_file_entry_notify (GObject *config,
1676
GParamSpec *param_spec,
1677
GimpFileEntry *entry)
1682
g_object_get (config,
1683
param_spec->name, &value,
1686
filename = value ? gimp_config_path_expand (value, TRUE, NULL) : NULL;
1689
g_signal_handlers_block_by_func (entry,
1690
gimp_prop_file_entry_callback,
1693
gimp_file_entry_set_filename (entry, filename);
1695
g_signal_handlers_unblock_by_func (entry,
1696
gimp_prop_file_entry_callback,
1707
static void gimp_prop_path_editor_path_callback (GimpPathEditor *editor,
1709
static void gimp_prop_path_editor_writable_callback (GimpPathEditor *editor,
1711
static void gimp_prop_path_editor_path_notify (GObject *config,
1712
GParamSpec *param_spec,
1713
GimpPathEditor *editor);
1714
static void gimp_prop_path_editor_writable_notify (GObject *config,
1715
GParamSpec *param_spec,
1716
GimpPathEditor *editor);
1719
gimp_prop_path_editor_new (GObject *config,
1720
const gchar *path_property_name,
1721
const gchar *writable_property_name,
1722
const gchar *filesel_title)
1724
GParamSpec *path_param_spec;
1725
GParamSpec *writable_param_spec = NULL;
1730
path_param_spec = check_param_spec (config, path_property_name,
1731
GIMP_TYPE_PARAM_PATH, G_STRFUNC);
1732
if (! path_param_spec)
1735
if (writable_property_name)
1737
writable_param_spec = check_param_spec (config, writable_property_name,
1738
GIMP_TYPE_PARAM_PATH, G_STRFUNC);
1739
if (! writable_param_spec)
1743
g_object_get (config,
1744
path_property_name, &value,
1747
filename = value ? gimp_config_path_expand (value, TRUE, NULL) : NULL;
1750
editor = gimp_path_editor_new (filesel_title, filename);
1753
if (writable_property_name)
1755
g_object_get (config,
1756
writable_property_name, &value,
1759
filename = value ? gimp_config_path_expand (value, TRUE, NULL) : NULL;
1762
gimp_path_editor_set_writable_path (GIMP_PATH_EDITOR (editor), filename);
1766
g_object_set_data (G_OBJECT (editor), "gimp-config-param-spec-path",
1769
g_signal_connect (editor, "path_changed",
1770
G_CALLBACK (gimp_prop_path_editor_path_callback),
1773
connect_notify (config, path_property_name,
1774
G_CALLBACK (gimp_prop_path_editor_path_notify),
1777
if (writable_property_name)
1779
g_object_set_data (G_OBJECT (editor), "gimp-config-param-spec-writable",
1780
writable_param_spec);
1782
g_signal_connect (editor, "writable_changed",
1783
G_CALLBACK (gimp_prop_path_editor_writable_callback),
1786
connect_notify (config, writable_property_name,
1787
G_CALLBACK (gimp_prop_path_editor_writable_notify),
1795
gimp_prop_path_editor_path_callback (GimpPathEditor *editor,
1798
GParamSpec *path_param_spec;
1799
GParamSpec *writable_param_spec;
1803
path_param_spec = g_object_get_data (G_OBJECT (editor),
1804
"gimp-config-param-spec-path");
1805
writable_param_spec = g_object_get_data (G_OBJECT (editor),
1806
"gimp-config-param-spec-writable");
1807
if (! path_param_spec)
1810
value = gimp_path_editor_get_path (editor);
1811
utf8 = g_filename_to_utf8 (value, -1, NULL, NULL, NULL);
1814
g_signal_handlers_block_by_func (config,
1815
gimp_prop_path_editor_path_notify,
1818
g_object_set (config,
1819
path_param_spec->name, utf8,
1822
g_signal_handlers_unblock_by_func (config,
1823
gimp_prop_path_editor_path_notify,
1828
if (writable_param_spec)
1830
value = gimp_path_editor_get_writable_path (editor);
1831
utf8 = g_filename_to_utf8 (value, -1, NULL, NULL, NULL);
1834
g_signal_handlers_block_by_func (config,
1835
gimp_prop_path_editor_writable_notify,
1838
g_object_set (config,
1839
writable_param_spec->name, utf8,
1842
g_signal_handlers_unblock_by_func (config,
1843
gimp_prop_path_editor_writable_notify,
1851
gimp_prop_path_editor_writable_callback (GimpPathEditor *editor,
1854
GParamSpec *param_spec;
1858
param_spec = g_object_get_data (G_OBJECT (editor),
1859
"gimp-config-param-spec-writable");
1863
value = gimp_path_editor_get_writable_path (editor);
1864
utf8 = g_filename_to_utf8 (value, -1, NULL, NULL, NULL);
1867
g_signal_handlers_block_by_func (config,
1868
gimp_prop_path_editor_writable_notify,
1871
g_object_set (config,
1872
param_spec->name, utf8,
1875
g_signal_handlers_unblock_by_func (config,
1876
gimp_prop_path_editor_writable_notify,
1883
gimp_prop_path_editor_path_notify (GObject *config,
1884
GParamSpec *param_spec,
1885
GimpPathEditor *editor)
1890
g_object_get (config,
1891
param_spec->name, &value,
1894
filename = value ? gimp_config_path_expand (value, TRUE, NULL) : NULL;
1897
g_signal_handlers_block_by_func (editor,
1898
gimp_prop_path_editor_path_callback,
1901
gimp_path_editor_set_path (editor, filename);
1903
g_signal_handlers_unblock_by_func (editor,
1904
gimp_prop_path_editor_path_callback,
1911
gimp_prop_path_editor_writable_notify (GObject *config,
1912
GParamSpec *param_spec,
1913
GimpPathEditor *editor)
1918
g_object_get (config,
1919
param_spec->name, &value,
1922
filename = value ? gimp_config_path_expand (value, TRUE, NULL) : NULL;
1925
g_signal_handlers_block_by_func (editor,
1926
gimp_prop_path_editor_writable_callback,
1929
gimp_path_editor_set_writable_path (editor, filename);
1931
g_signal_handlers_unblock_by_func (editor,
1932
gimp_prop_path_editor_writable_callback,
1943
static void gimp_prop_size_entry_callback (GimpSizeEntry *sizeentry,
1945
static void gimp_prop_size_entry_notify (GObject *config,
1946
GParamSpec *param_spec,
1947
GimpSizeEntry *sizeentry);
1948
static void gimp_prop_size_entry_notify_unit (GObject *config,
1949
GParamSpec *param_spec,
1950
GimpSizeEntry *sizeentry);
1954
gimp_prop_size_entry_new (GObject *config,
1955
const gchar *property_name,
1956
const gchar *unit_property_name,
1957
const gchar *unit_format,
1958
GimpSizeEntryUpdatePolicy update_policy,
1961
GtkWidget *sizeentry;
1962
GParamSpec *param_spec;
1963
GParamSpec *unit_param_spec;
1964
gboolean show_pixels;
1968
GimpUnit unit_value;
1970
param_spec = find_param_spec (config, property_name, G_STRFUNC);
1974
if (! get_numeric_values (config,
1975
param_spec, &value, &lower, &upper, G_STRFUNC))
1978
if (unit_property_name)
1980
GValue value = { 0 };
1982
unit_param_spec = check_param_spec (config, unit_property_name,
1983
GIMP_TYPE_PARAM_UNIT, G_STRFUNC);
1984
if (! unit_param_spec)
1987
g_value_init (&value, unit_param_spec->value_type);
1988
g_value_set_int (&value, GIMP_UNIT_PIXEL);
1990
(g_param_value_validate (unit_param_spec, &value) == FALSE);
1991
g_value_unset (&value);
1993
g_object_get (config,
1994
unit_property_name, &unit_value,
1999
unit_param_spec = NULL;
2000
unit_value = GIMP_UNIT_INCH;
2001
show_pixels = FALSE;
2004
sizeentry = gimp_size_entry_new (1, unit_value, unit_format,
2006
ceil (log (upper) / log (10) + 2),
2008
gtk_table_set_col_spacing (GTK_TABLE (sizeentry), 1, 4);
2010
set_param_spec (NULL,
2011
gimp_size_entry_get_help_widget (GIMP_SIZE_ENTRY (sizeentry),
2015
if (unit_param_spec)
2016
set_param_spec (NULL,
2017
GIMP_SIZE_ENTRY (sizeentry)->unitmenu, unit_param_spec);
2019
gimp_size_entry_set_unit (GIMP_SIZE_ENTRY (sizeentry), unit_value);
2021
if (update_policy == GIMP_SIZE_ENTRY_UPDATE_SIZE)
2022
gimp_size_entry_set_resolution (GIMP_SIZE_ENTRY (sizeentry), 0,
2025
gimp_size_entry_set_value_boundaries (GIMP_SIZE_ENTRY (sizeentry), 0,
2028
gimp_size_entry_set_value (GIMP_SIZE_ENTRY (sizeentry), 0, value);
2030
g_object_set_data (G_OBJECT (sizeentry), "gimp-config-param-spec",
2033
g_signal_connect (sizeentry, "value_changed",
2034
G_CALLBACK (gimp_prop_size_entry_callback),
2037
connect_notify (config, property_name,
2038
G_CALLBACK (gimp_prop_size_entry_notify),
2041
if (unit_property_name)
2043
g_object_set_data (G_OBJECT (sizeentry), "gimp-config-param-spec-unit",
2046
g_signal_connect (sizeentry, "unit_changed",
2047
G_CALLBACK (gimp_prop_size_entry_callback),
2050
connect_notify (config, unit_property_name,
2051
G_CALLBACK (gimp_prop_size_entry_notify_unit),
2059
gimp_prop_size_entry_callback (GimpSizeEntry *sizeentry,
2062
GParamSpec *param_spec;
2063
GParamSpec *unit_param_spec;
2065
GimpUnit unit_value;
2067
param_spec = g_object_get_data (G_OBJECT (sizeentry),
2068
"gimp-config-param-spec");
2072
unit_param_spec = g_object_get_data (G_OBJECT (sizeentry),
2073
"gimp-config-param-spec-unit");
2075
value = gimp_size_entry_get_value (sizeentry, 0);
2076
unit_value = gimp_size_entry_get_unit (sizeentry);
2078
if (unit_param_spec)
2082
g_object_get (config,
2083
unit_param_spec->name, &old_unit,
2086
if (unit_value == old_unit)
2087
unit_param_spec = NULL;
2090
if (G_IS_PARAM_SPEC_INT (param_spec))
2092
g_object_set (config,
2093
param_spec->name, ROUND (value),
2096
unit_param_spec->name : NULL, unit_value,
2100
else if (G_IS_PARAM_SPEC_DOUBLE (param_spec))
2102
g_object_set (config,
2103
param_spec->name, value,
2106
unit_param_spec->name : NULL, unit_value,
2113
gimp_prop_size_entry_notify (GObject *config,
2114
GParamSpec *param_spec,
2115
GimpSizeEntry *sizeentry)
2119
if (G_IS_PARAM_SPEC_INT (param_spec))
2123
g_object_get (config,
2124
param_spec->name, &int_value,
2131
g_object_get (config,
2132
param_spec->name, &value,
2136
if (value != gimp_size_entry_get_value (sizeentry, 0))
2138
g_signal_handlers_block_by_func (sizeentry,
2139
gimp_prop_size_entry_callback,
2142
gimp_size_entry_set_value (sizeentry, 0, value);
2144
g_signal_handlers_unblock_by_func (sizeentry,
2145
gimp_prop_size_entry_callback,
2151
gimp_prop_size_entry_notify_unit (GObject *config,
2152
GParamSpec *param_spec,
2153
GimpSizeEntry *sizeentry)
2157
g_object_get (config,
2158
param_spec->name, &value,
2161
if (value != gimp_size_entry_get_unit (sizeentry))
2163
g_signal_handlers_block_by_func (sizeentry,
2164
gimp_prop_size_entry_callback,
2167
gimp_size_entry_set_unit (sizeentry, value);
2169
g_signal_handlers_unblock_by_func (sizeentry,
2170
gimp_prop_size_entry_callback,
2180
static void gimp_prop_coordinates_callback (GimpSizeEntry *sizeentry,
2182
static void gimp_prop_coordinates_notify_x (GObject *config,
2183
GParamSpec *param_spec,
2184
GimpSizeEntry *sizeentry);
2185
static void gimp_prop_coordinates_notify_y (GObject *config,
2186
GParamSpec *param_spec,
2187
GimpSizeEntry *sizeentry);
2188
static void gimp_prop_coordinates_notify_unit (GObject *config,
2189
GParamSpec *param_spec,
2190
GimpSizeEntry *sizeentry);
2194
gimp_prop_coordinates_new (GObject *config,
2195
const gchar *x_property_name,
2196
const gchar *y_property_name,
2197
const gchar *unit_property_name,
2198
const gchar *unit_format,
2199
GimpSizeEntryUpdatePolicy update_policy,
2200
gdouble xresolution,
2201
gdouble yresolution,
2202
gboolean has_chainbutton)
2204
GtkWidget *sizeentry;
2205
GtkWidget *chainbutton = NULL;
2207
sizeentry = gimp_size_entry_new (2, GIMP_UNIT_INCH, unit_format,
2208
FALSE, FALSE, TRUE, 10,
2211
if (has_chainbutton)
2213
chainbutton = gimp_chain_button_new (GIMP_CHAIN_BOTTOM);
2214
gtk_table_attach_defaults (GTK_TABLE (sizeentry), chainbutton,
2216
gtk_widget_show (chainbutton);
2219
if (! gimp_prop_coordinates_connect (config,
2228
gtk_widget_destroy (sizeentry);
2236
gimp_prop_coordinates_connect (GObject *config,
2237
const gchar *x_property_name,
2238
const gchar *y_property_name,
2239
const gchar *unit_property_name,
2240
GtkWidget *sizeentry,
2241
GtkWidget *chainbutton,
2242
gdouble xresolution,
2243
gdouble yresolution)
2245
GParamSpec *x_param_spec;
2246
GParamSpec *y_param_spec;
2247
GParamSpec *unit_param_spec;
2248
gdouble x_value, x_lower, x_upper;
2249
gdouble y_value, y_lower, y_upper;
2250
GimpUnit unit_value;
2251
gdouble *old_x_value;
2252
gdouble *old_y_value;
2253
GimpUnit *old_unit_value;
2254
gboolean chain_checked;
2256
g_return_val_if_fail (GIMP_IS_SIZE_ENTRY (sizeentry), FALSE);
2257
g_return_val_if_fail (GIMP_SIZE_ENTRY (sizeentry)->number_of_fields == 2,
2259
g_return_val_if_fail (chainbutton == NULL ||
2260
GIMP_IS_CHAIN_BUTTON (chainbutton), FALSE);
2262
x_param_spec = find_param_spec (config, x_property_name, G_STRFUNC);
2266
y_param_spec = find_param_spec (config, y_property_name, G_STRFUNC);
2270
if (! get_numeric_values (config, x_param_spec,
2271
&x_value, &x_lower, &x_upper, G_STRFUNC) ||
2272
! get_numeric_values (config, y_param_spec,
2273
&y_value, &y_lower, &y_upper, G_STRFUNC))
2276
if (unit_property_name)
2278
unit_param_spec = check_param_spec (config, unit_property_name,
2279
GIMP_TYPE_PARAM_UNIT, G_STRFUNC);
2280
if (! unit_param_spec)
2283
g_object_get (config,
2284
unit_property_name, &unit_value,
2289
unit_param_spec = NULL;
2290
unit_value = GIMP_UNIT_INCH;
2293
set_param_spec (NULL,
2294
gimp_size_entry_get_help_widget (GIMP_SIZE_ENTRY (sizeentry),
2297
set_param_spec (NULL,
2298
gimp_size_entry_get_help_widget (GIMP_SIZE_ENTRY (sizeentry),
2302
if (unit_param_spec)
2303
set_param_spec (NULL,
2304
GIMP_SIZE_ENTRY (sizeentry)->unitmenu, unit_param_spec);
2306
gimp_size_entry_set_unit (GIMP_SIZE_ENTRY (sizeentry), unit_value);
2308
switch (GIMP_SIZE_ENTRY (sizeentry)->update_policy)
2310
case GIMP_SIZE_ENTRY_UPDATE_SIZE:
2311
gimp_size_entry_set_resolution (GIMP_SIZE_ENTRY (sizeentry), 0,
2312
xresolution, FALSE);
2313
gimp_size_entry_set_resolution (GIMP_SIZE_ENTRY (sizeentry), 1,
2314
yresolution, FALSE);
2315
chain_checked = (ABS (x_value - y_value) < 1);
2318
case GIMP_SIZE_ENTRY_UPDATE_RESOLUTION:
2319
chain_checked = (ABS (x_value - y_value) < GIMP_MIN_RESOLUTION);
2323
chain_checked = (x_value == y_value);
2327
gimp_size_entry_set_refval_boundaries (GIMP_SIZE_ENTRY (sizeentry), 0,
2329
gimp_size_entry_set_refval_boundaries (GIMP_SIZE_ENTRY (sizeentry), 1,
2332
gimp_size_entry_set_refval (GIMP_SIZE_ENTRY (sizeentry), 0, x_value);
2333
gimp_size_entry_set_refval (GIMP_SIZE_ENTRY (sizeentry), 1, y_value);
2335
g_object_set_data (G_OBJECT (sizeentry), "gimp-config-param-spec-x",
2337
g_object_set_data (G_OBJECT (sizeentry), "gimp-config-param-spec-y",
2340
old_x_value = g_new0 (gdouble, 1);
2341
*old_x_value = x_value;
2342
g_object_set_data_full (G_OBJECT (sizeentry), "old-x-value",
2344
(GDestroyNotify) g_free);
2346
old_y_value = g_new0 (gdouble, 1);
2347
*old_y_value = y_value;
2348
g_object_set_data_full (G_OBJECT (sizeentry), "old-y-value",
2350
(GDestroyNotify) g_free);
2355
gimp_chain_button_set_active (GIMP_CHAIN_BUTTON (chainbutton), TRUE);
2357
g_object_set_data (G_OBJECT (sizeentry), "chainbutton", chainbutton);
2360
g_signal_connect (sizeentry, "value_changed",
2361
G_CALLBACK (gimp_prop_coordinates_callback),
2363
g_signal_connect (sizeentry, "refval_changed",
2364
G_CALLBACK (gimp_prop_coordinates_callback),
2367
connect_notify (config, x_property_name,
2368
G_CALLBACK (gimp_prop_coordinates_notify_x),
2370
connect_notify (config, y_property_name,
2371
G_CALLBACK (gimp_prop_coordinates_notify_y),
2374
if (unit_property_name)
2376
g_object_set_data (G_OBJECT (sizeentry), "gimp-config-param-spec-unit",
2379
old_unit_value = g_new0 (GimpUnit, 1);
2380
*old_unit_value = unit_value;
2381
g_object_set_data_full (G_OBJECT (sizeentry), "old-unit-value",
2383
(GDestroyNotify) g_free);
2385
g_signal_connect (sizeentry, "unit_changed",
2386
G_CALLBACK (gimp_prop_coordinates_callback),
2389
connect_notify (config, unit_property_name,
2390
G_CALLBACK (gimp_prop_coordinates_notify_unit),
2398
gimp_prop_coordinates_callback (GimpSizeEntry *sizeentry,
2401
GParamSpec *x_param_spec;
2402
GParamSpec *y_param_spec;
2403
GParamSpec *unit_param_spec;
2406
GimpUnit unit_value;
2407
gdouble *old_x_value;
2408
gdouble *old_y_value;
2409
GimpUnit *old_unit_value;
2412
x_param_spec = g_object_get_data (G_OBJECT (sizeentry),
2413
"gimp-config-param-spec-x");
2414
y_param_spec = g_object_get_data (G_OBJECT (sizeentry),
2415
"gimp-config-param-spec-y");
2417
if (! x_param_spec || ! y_param_spec)
2420
unit_param_spec = g_object_get_data (G_OBJECT (sizeentry),
2421
"gimp-config-param-spec-unit");
2423
x_value = gimp_size_entry_get_refval (sizeentry, 0);
2424
y_value = gimp_size_entry_get_refval (sizeentry, 1);
2425
unit_value = gimp_size_entry_get_unit (sizeentry);
2427
old_x_value = g_object_get_data (G_OBJECT (sizeentry), "old-x-value");
2428
old_y_value = g_object_get_data (G_OBJECT (sizeentry), "old-y-value");
2429
old_unit_value = g_object_get_data (G_OBJECT (sizeentry), "old-unit-value");
2431
if (! old_x_value || ! old_y_value || (unit_param_spec && ! old_unit_value))
2435
* FIXME: if the entry was created using gimp_coordinates_new, then
2436
* the chain button is handled automatically and the following block
2437
* of code is unnecessary (and, in fact, redundant).
2439
if (x_value != y_value)
2441
GtkWidget *chainbutton;
2443
chainbutton = g_object_get_data (G_OBJECT (sizeentry), "chainbutton");
2446
gimp_chain_button_get_active (GIMP_CHAIN_BUTTON (chainbutton)) &&
2447
! g_object_get_data (G_OBJECT (chainbutton), "constrains-ratio"))
2449
if (x_value != *old_x_value)
2451
else if (y_value != *old_y_value)
2456
backwards = (*old_x_value == x_value);
2458
if (*old_x_value == x_value &&
2459
*old_y_value == y_value &&
2460
(old_unit_value == NULL || *old_unit_value == unit_value))
2463
*old_x_value = x_value;
2464
*old_y_value = y_value;
2467
*old_unit_value = unit_value;
2469
if (unit_param_spec)
2470
g_object_set (config,
2471
unit_param_spec->name, unit_value,
2474
if (G_IS_PARAM_SPEC_INT (x_param_spec) &&
2475
G_IS_PARAM_SPEC_INT (y_param_spec))
2478
g_object_set (config,
2479
y_param_spec->name, ROUND (y_value),
2480
x_param_spec->name, ROUND (x_value),
2483
g_object_set (config,
2484
x_param_spec->name, ROUND (x_value),
2485
y_param_spec->name, ROUND (y_value),
2489
else if (G_IS_PARAM_SPEC_DOUBLE (x_param_spec) &&
2490
G_IS_PARAM_SPEC_DOUBLE (y_param_spec))
2493
g_object_set (config,
2494
y_param_spec->name, y_value,
2495
x_param_spec->name, x_value,
2498
g_object_set (config,
2499
x_param_spec->name, x_value,
2500
y_param_spec->name, y_value,
2506
gimp_prop_coordinates_notify_x (GObject *config,
2507
GParamSpec *param_spec,
2508
GimpSizeEntry *sizeentry)
2512
if (G_IS_PARAM_SPEC_INT (param_spec))
2516
g_object_get (config,
2517
param_spec->name, &int_value,
2524
g_object_get (config,
2525
param_spec->name, &value,
2529
if (value != gimp_size_entry_get_refval (sizeentry, 0))
2531
g_signal_handlers_block_by_func (sizeentry,
2532
gimp_prop_coordinates_callback,
2535
gimp_size_entry_set_refval (sizeentry, 0, value);
2537
g_signal_handlers_unblock_by_func (sizeentry,
2538
gimp_prop_coordinates_callback,
2544
gimp_prop_coordinates_notify_y (GObject *config,
2545
GParamSpec *param_spec,
2546
GimpSizeEntry *sizeentry)
2550
if (G_IS_PARAM_SPEC_INT (param_spec))
2554
g_object_get (config,
2555
param_spec->name, &int_value,
2562
g_object_get (config,
2563
param_spec->name, &value,
2567
if (value != gimp_size_entry_get_refval (sizeentry, 1))
2569
g_signal_handlers_block_by_func (sizeentry,
2570
gimp_prop_coordinates_callback,
2573
gimp_size_entry_set_refval (sizeentry, 1, value);
2575
g_signal_handlers_unblock_by_func (sizeentry,
2576
gimp_prop_coordinates_callback,
2582
gimp_prop_coordinates_notify_unit (GObject *config,
2583
GParamSpec *param_spec,
2584
GimpSizeEntry *sizeentry)
2588
g_object_get (config,
2589
param_spec->name, &value,
2592
if (value != gimp_size_entry_get_unit (sizeentry))
2594
g_signal_handlers_block_by_func (sizeentry,
2595
gimp_prop_coordinates_callback,
2598
gimp_size_entry_set_unit (sizeentry, value);
2600
g_signal_handlers_unblock_by_func (sizeentry,
2601
gimp_prop_coordinates_callback,
2611
static void gimp_prop_color_area_callback (GtkWidget *widget,
2613
static void gimp_prop_color_area_notify (GObject *config,
2614
GParamSpec *param_spec,
2618
gimp_prop_color_area_new (GObject *config,
2619
const gchar *property_name,
2622
GimpColorAreaType type)
2624
GParamSpec *param_spec;
2628
param_spec = check_param_spec (config, property_name,
2629
GIMP_TYPE_PARAM_RGB, G_STRFUNC);
2633
g_object_get (config,
2634
property_name, &value,
2637
area = gimp_color_area_new (value, type,
2638
GDK_BUTTON1_MASK | GDK_BUTTON2_MASK);
2639
gtk_widget_set_size_request (area, width, height);
2643
set_param_spec (G_OBJECT (area), area, param_spec);
2645
g_signal_connect (area, "color_changed",
2646
G_CALLBACK (gimp_prop_color_area_callback),
2649
connect_notify (config, property_name,
2650
G_CALLBACK (gimp_prop_color_area_notify),
2657
gimp_prop_color_area_callback (GtkWidget *area,
2660
GParamSpec *param_spec;
2663
param_spec = get_param_spec (G_OBJECT (area));
2667
gimp_color_area_get_color (GIMP_COLOR_AREA (area), &value);
2669
g_signal_handlers_block_by_func (config,
2670
gimp_prop_color_area_notify,
2673
g_object_set (config,
2674
param_spec->name, &value,
2677
g_signal_handlers_unblock_by_func (config,
2678
gimp_prop_color_area_notify,
2683
gimp_prop_color_area_notify (GObject *config,
2684
GParamSpec *param_spec,
2689
g_object_get (config,
2690
param_spec->name, &value,
2693
g_signal_handlers_block_by_func (area,
2694
gimp_prop_color_area_callback,
2697
gimp_color_area_set_color (GIMP_COLOR_AREA (area), value);
2701
g_signal_handlers_unblock_by_func (area,
2702
gimp_prop_color_area_callback,
2707
/******************/
2709
/******************/
2711
static void gimp_prop_color_button_callback (GtkWidget *widget,
2713
static void gimp_prop_color_button_notify (GObject *config,
2714
GParamSpec *param_spec,
2718
gimp_prop_color_button_new (GObject *config,
2719
const gchar *property_name,
2723
GimpColorAreaType type)
2725
GParamSpec *param_spec;
2729
param_spec = check_param_spec (config, property_name,
2730
GIMP_TYPE_PARAM_RGB, G_STRFUNC);
2734
g_object_get (config,
2735
property_name, &value,
2738
button = gimp_color_panel_new (title, value, type, width, height);
2742
set_param_spec (G_OBJECT (button), button, param_spec);
2744
g_signal_connect (button, "color_changed",
2745
G_CALLBACK (gimp_prop_color_button_callback),
2748
connect_notify (config, property_name,
2749
G_CALLBACK (gimp_prop_color_button_notify),
2756
gimp_prop_color_button_callback (GtkWidget *button,
2759
GParamSpec *param_spec;
2762
param_spec = get_param_spec (G_OBJECT (button));
2766
gimp_color_button_get_color (GIMP_COLOR_BUTTON (button), &value);
2768
g_signal_handlers_block_by_func (config,
2769
gimp_prop_color_button_notify,
2772
g_object_set (config,
2773
param_spec->name, &value,
2776
g_signal_handlers_unblock_by_func (config,
2777
gimp_prop_color_button_notify,
2782
gimp_prop_color_button_notify (GObject *config,
2783
GParamSpec *param_spec,
2788
g_object_get (config,
2789
param_spec->name, &value,
2792
g_signal_handlers_block_by_func (button,
2793
gimp_prop_color_button_callback,
2796
gimp_color_button_set_color (GIMP_COLOR_BUTTON (button), value);
2800
g_signal_handlers_unblock_by_func (button,
2801
gimp_prop_color_button_callback,
2810
static void gimp_prop_unit_menu_callback (GtkWidget *menu,
2812
static void gimp_prop_unit_menu_notify (GObject *config,
2813
GParamSpec *param_spec,
2817
gimp_prop_unit_menu_new (GObject *config,
2818
const gchar *property_name,
2819
const gchar *unit_format)
2821
GParamSpec *param_spec;
2824
GValue value = { 0, };
2825
gboolean show_pixels;
2826
gboolean show_percent;
2828
param_spec = check_param_spec (config, property_name,
2829
GIMP_TYPE_PARAM_UNIT, G_STRFUNC);
2833
g_value_init (&value, param_spec->value_type);
2835
g_value_set_int (&value, GIMP_UNIT_PIXEL);
2836
show_pixels = (g_param_value_validate (param_spec, &value) == FALSE);
2838
g_value_set_int (&value, GIMP_UNIT_PERCENT);
2839
show_percent = (g_param_value_validate (param_spec, &value) == FALSE);
2841
g_value_unset (&value);
2843
g_object_get (config,
2844
property_name, &unit,
2847
menu = gimp_unit_menu_new (unit_format, unit, show_pixels, show_percent, TRUE);
2849
set_param_spec (G_OBJECT (menu), menu, param_spec);
2851
g_signal_connect (menu, "unit_changed",
2852
G_CALLBACK (gimp_prop_unit_menu_callback),
2855
connect_notify (config, property_name,
2856
G_CALLBACK (gimp_prop_unit_menu_notify),
2863
gimp_prop_unit_menu_callback (GtkWidget *menu,
2866
GParamSpec *param_spec;
2869
param_spec = get_param_spec (G_OBJECT (menu));
2873
gimp_unit_menu_update (menu, &unit);
2875
g_signal_handlers_block_by_func (config,
2876
gimp_prop_unit_menu_notify,
2879
g_object_set (config,
2880
param_spec->name, unit,
2883
g_signal_handlers_unblock_by_func (config,
2884
gimp_prop_unit_menu_notify,
2889
gimp_prop_unit_menu_notify (GObject *config,
2890
GParamSpec *param_spec,
2895
g_object_get (config,
2896
param_spec->name, &unit,
2899
g_signal_handlers_block_by_func (menu,
2900
gimp_prop_unit_menu_callback,
2903
gimp_unit_menu_set_unit (GIMP_UNIT_MENU (menu), unit);
2904
gimp_unit_menu_update (menu, &unit);
2906
g_signal_handlers_unblock_by_func (menu,
2907
gimp_prop_unit_menu_callback,
2916
static void gimp_prop_preview_drop (GtkWidget *menu,
2917
GimpViewable *viewable,
2919
static void gimp_prop_preview_notify (GObject *config,
2920
GParamSpec *param_spec,
2921
GtkWidget *preview);
2924
gimp_prop_preview_new (GObject *config,
2925
const gchar *property_name,
2928
GParamSpec *param_spec;
2930
GimpViewable *viewable;
2932
param_spec = check_param_spec (config, property_name,
2933
G_TYPE_PARAM_OBJECT, G_STRFUNC);
2937
if (! g_type_is_a (param_spec->value_type, GIMP_TYPE_VIEWABLE))
2939
g_warning ("%s: property '%s' of %s is not a GimpViewable",
2940
G_STRFUNC, property_name,
2941
g_type_name (G_TYPE_FROM_INSTANCE (config)));
2945
preview = gimp_view_new_by_types (GIMP_TYPE_VIEW,
2946
param_spec->value_type,
2951
g_warning ("%s: cannot create preview for type '%s'",
2952
G_STRFUNC, g_type_name (param_spec->value_type));
2956
g_object_get (config,
2957
property_name, &viewable,
2962
gimp_view_set_viewable (GIMP_VIEW (preview), viewable);
2963
g_object_unref (viewable);
2966
set_param_spec (G_OBJECT (preview), preview, param_spec);
2968
gimp_dnd_viewable_dest_add (preview, param_spec->value_type,
2969
gimp_prop_preview_drop,
2972
connect_notify (config, property_name,
2973
G_CALLBACK (gimp_prop_preview_notify),
2980
gimp_prop_preview_drop (GtkWidget *preview,
2981
GimpViewable *viewable,
2985
GParamSpec *param_spec;
2987
param_spec = get_param_spec (G_OBJECT (preview));
2991
config = G_OBJECT (data);
2993
g_object_set (config,
2994
param_spec->name, viewable,
2999
gimp_prop_preview_notify (GObject *config,
3000
GParamSpec *param_spec,
3003
GimpViewable *viewable;
3005
g_object_get (config,
3006
param_spec->name, &viewable,
3009
gimp_view_set_viewable (GIMP_VIEW (preview), viewable);
3012
g_object_unref (viewable);
3020
static void gimp_prop_stock_image_notify (GObject *config,
3021
GParamSpec *param_spec,
3025
gimp_prop_stock_image_new (GObject *config,
3026
const gchar *property_name,
3027
GtkIconSize icon_size)
3029
GParamSpec *param_spec;
3033
param_spec = check_param_spec (config, property_name,
3034
G_TYPE_PARAM_STRING, G_STRFUNC);
3038
g_object_get (config,
3039
property_name, &stock_id,
3042
image = gtk_image_new_from_stock (stock_id, icon_size);
3047
set_param_spec (G_OBJECT (image), image, param_spec);
3049
connect_notify (config, property_name,
3050
G_CALLBACK (gimp_prop_stock_image_notify),
3057
gimp_prop_stock_image_notify (GObject *config,
3058
GParamSpec *param_spec,
3063
g_object_get (config,
3064
param_spec->name, &stock_id,
3067
gtk_image_set_from_stock (GTK_IMAGE (image), stock_id,
3068
GTK_IMAGE (image)->icon_size);
3075
/*******************************/
3076
/* private utility functions */
3077
/*******************************/
3079
static GQuark param_spec_quark = 0;
3082
set_param_spec (GObject *object,
3084
GParamSpec *param_spec)
3088
if (! param_spec_quark)
3089
param_spec_quark = g_quark_from_static_string ("gimp-config-param-spec");
3091
g_object_set_qdata (object, param_spec_quark, param_spec);
3096
const gchar *blurb = g_param_spec_get_blurb (param_spec);
3099
gimp_help_set_help_data (widget, gettext (blurb), NULL);
3104
set_radio_spec (GObject *object,
3105
GParamSpec *param_spec)
3109
for (list = gtk_radio_button_get_group (GTK_RADIO_BUTTON (object));
3111
list = g_slist_next (list))
3113
set_param_spec (list->data, NULL, param_spec);
3118
get_param_spec (GObject *object)
3120
if (! param_spec_quark)
3121
param_spec_quark = g_quark_from_static_string ("gimp-config-param-spec");
3123
return g_object_get_qdata (object, param_spec_quark);
3127
find_param_spec (GObject *object,
3128
const gchar *property_name,
3129
const gchar *strloc)
3131
GParamSpec *param_spec;
3133
param_spec = g_object_class_find_property (G_OBJECT_GET_CLASS (object),
3137
g_warning ("%s: %s has no property named '%s'",
3139
g_type_name (G_TYPE_FROM_INSTANCE (object)),
3146
check_param_spec (GObject *object,
3147
const gchar *property_name,
3149
const gchar *strloc)
3151
GParamSpec *param_spec;
3153
param_spec = find_param_spec (object, property_name, strloc);
3155
if (param_spec && ! g_type_is_a (G_TYPE_FROM_INSTANCE (param_spec), type))
3157
g_warning ("%s: property '%s' of %s is not a %s",
3160
g_type_name (param_spec->owner_type),
3161
g_type_name (type));
3169
get_numeric_values (GObject *object,
3170
GParamSpec *param_spec,
3174
const gchar *strloc)
3176
if (G_IS_PARAM_SPEC_INT (param_spec))
3178
GParamSpecInt *int_spec = G_PARAM_SPEC_INT (param_spec);
3181
g_object_get (object, param_spec->name, &int_value, NULL);
3184
*lower = int_spec->minimum;
3185
*upper = int_spec->maximum;
3187
else if (G_IS_PARAM_SPEC_UINT (param_spec))
3189
GParamSpecUInt *uint_spec = G_PARAM_SPEC_UINT (param_spec);
3192
g_object_get (object, param_spec->name, &uint_value, NULL);
3194
*value = uint_value;
3195
*lower = uint_spec->minimum;
3196
*upper = uint_spec->maximum;
3198
else if (G_IS_PARAM_SPEC_DOUBLE (param_spec))
3200
GParamSpecDouble *double_spec = G_PARAM_SPEC_DOUBLE (param_spec);
3202
g_object_get (object, param_spec->name, value, NULL);
3204
*lower = double_spec->minimum;
3205
*upper = double_spec->maximum;
3209
g_warning ("%s: property '%s' of %s is not numeric",
3212
g_type_name (G_TYPE_FROM_INSTANCE (object)));
3220
connect_notify (GObject *config,
3221
const gchar *property_name,
3223
gpointer callback_data)
3227
notify_name = g_strconcat ("notify::", property_name, NULL);
3229
g_signal_connect_object (config, notify_name, callback, callback_data, 0);
3231
g_free (notify_name);