1 /* GIMP - The GNU Image Manipulation Program
2 * Copyright (C) 1995 Spencer Kimball and Peter Mattis
3 *
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 3 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <https://www.gnu.org/licenses/>.
16 */
17
18 #include "config.h"
19
20 #include <gegl.h>
21 #include <gtk/gtk.h>
22
23 #include "libgimpconfig/gimpconfig.h"
24 #include "libgimpwidgets/gimpwidgets.h"
25
26 #include "tools-types.h"
27
28 #include "config/gimpdisplayconfig.h"
29
30 #include "core/gimp.h"
31 #include "core/gimptoolinfo.h"
32
33 #include "widgets/gimpwidgets-utils.h"
34
35 #include "gimpmagnifyoptions.h"
36 #include "gimptooloptions-gui.h"
37
38 #include "gimp-intl.h"
39
40
41 enum
42 {
43 PROP_0,
44 PROP_AUTO_RESIZE,
45 PROP_ZOOM_TYPE
46 };
47
48
49 static void gimp_magnify_options_config_iface_init (GimpConfigInterface *config_iface);
50
51 static void gimp_magnify_options_set_property (GObject *object,
52 guint property_id,
53 const GValue *value,
54 GParamSpec *pspec);
55 static void gimp_magnify_options_get_property (GObject *object,
56 guint property_id,
57 GValue *value,
58 GParamSpec *pspec);
59
60 static void gimp_magnify_options_reset (GimpConfig *config);
61
62
63 G_DEFINE_TYPE_WITH_CODE (GimpMagnifyOptions, gimp_magnify_options,
64 GIMP_TYPE_TOOL_OPTIONS,
65 G_IMPLEMENT_INTERFACE (GIMP_TYPE_CONFIG,
66 gimp_magnify_options_config_iface_init))
67
68 #define parent_class gimp_magnify_options_parent_class
69
70 static GimpConfigInterface *parent_config_iface = NULL;
71
72
73 static void
gimp_magnify_options_class_init(GimpMagnifyOptionsClass * klass)74 gimp_magnify_options_class_init (GimpMagnifyOptionsClass *klass)
75 {
76 GObjectClass *object_class = G_OBJECT_CLASS (klass);
77
78 object_class->set_property = gimp_magnify_options_set_property;
79 object_class->get_property = gimp_magnify_options_get_property;
80
81 GIMP_CONFIG_PROP_BOOLEAN (object_class, PROP_AUTO_RESIZE,
82 "auto-resize",
83 _("Auto-resize window"),
84 _("Resize image window to accommodate "
85 "new zoom level"),
86 FALSE,
87 GIMP_PARAM_STATIC_STRINGS);
88
89 GIMP_CONFIG_PROP_ENUM (object_class, PROP_ZOOM_TYPE,
90 "zoom-type",
91 _("Direction"),
92 _("Direction of magnification"),
93 GIMP_TYPE_ZOOM_TYPE,
94 GIMP_ZOOM_IN,
95 GIMP_PARAM_STATIC_STRINGS);
96 }
97
98 static void
gimp_magnify_options_config_iface_init(GimpConfigInterface * config_iface)99 gimp_magnify_options_config_iface_init (GimpConfigInterface *config_iface)
100 {
101 parent_config_iface = g_type_interface_peek_parent (config_iface);
102
103 config_iface->reset = gimp_magnify_options_reset;
104 }
105
106 static void
gimp_magnify_options_init(GimpMagnifyOptions * options)107 gimp_magnify_options_init (GimpMagnifyOptions *options)
108 {
109 }
110
111 static void
gimp_magnify_options_set_property(GObject * object,guint property_id,const GValue * value,GParamSpec * pspec)112 gimp_magnify_options_set_property (GObject *object,
113 guint property_id,
114 const GValue *value,
115 GParamSpec *pspec)
116 {
117 GimpMagnifyOptions *options = GIMP_MAGNIFY_OPTIONS (object);
118
119 switch (property_id)
120 {
121 case PROP_AUTO_RESIZE:
122 options->auto_resize = g_value_get_boolean (value);
123 break;
124 case PROP_ZOOM_TYPE:
125 options->zoom_type = g_value_get_enum (value);
126 break;
127
128 default:
129 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
130 break;
131 }
132 }
133
134 static void
gimp_magnify_options_get_property(GObject * object,guint property_id,GValue * value,GParamSpec * pspec)135 gimp_magnify_options_get_property (GObject *object,
136 guint property_id,
137 GValue *value,
138 GParamSpec *pspec)
139 {
140 GimpMagnifyOptions *options = GIMP_MAGNIFY_OPTIONS (object);
141
142 switch (property_id)
143 {
144 case PROP_AUTO_RESIZE:
145 g_value_set_boolean (value, options->auto_resize);
146 break;
147 case PROP_ZOOM_TYPE:
148 g_value_set_enum (value, options->zoom_type);
149 break;
150
151 default:
152 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
153 break;
154 }
155 }
156
157 static void
gimp_magnify_options_reset(GimpConfig * config)158 gimp_magnify_options_reset (GimpConfig *config)
159 {
160 GimpToolOptions *tool_options = GIMP_TOOL_OPTIONS (config);
161 GParamSpec *pspec;
162
163 pspec = g_object_class_find_property (G_OBJECT_GET_CLASS (config),
164 "auto-resize");
165
166 if (pspec)
167 G_PARAM_SPEC_BOOLEAN (pspec)->default_value =
168 GIMP_DISPLAY_CONFIG (tool_options->tool_info->gimp->config)->resize_windows_on_zoom;
169
170 parent_config_iface->reset (config);
171 }
172
173 GtkWidget *
gimp_magnify_options_gui(GimpToolOptions * tool_options)174 gimp_magnify_options_gui (GimpToolOptions *tool_options)
175 {
176 GObject *config = G_OBJECT (tool_options);
177 GtkWidget *vbox = gimp_tool_options_gui (tool_options);
178 GtkWidget *frame;
179 GtkWidget *button;
180 gchar *str;
181 GdkModifierType toggle_mask;
182
183 toggle_mask = gimp_get_toggle_behavior_mask ();
184
185 /* the auto_resize toggle button */
186 button = gimp_prop_check_button_new (config, "auto-resize", NULL);
187 gtk_box_pack_start (GTK_BOX (vbox), button, FALSE, FALSE, 0);
188 gtk_widget_show (button);
189
190 /* tool toggle */
191 str = g_strdup_printf (_("Direction (%s)"),
192 gimp_get_mod_string (toggle_mask));
193
194 frame = gimp_prop_enum_radio_frame_new (config, "zoom-type",
195 str, 0, 0);
196 gtk_box_pack_start (GTK_BOX (vbox), frame, FALSE, FALSE, 0);
197 gtk_widget_show (frame);
198
199 g_free (str);
200
201 return vbox;
202 }
203