2 * object-editor-position-page.c
3 * Copyright (C) 2003-2009 Jim Evins <evins@snaught.com>.
5 * This file is part of gLabels.
7 * gLabels is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
12 * gLabels is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with gLabels. If not, see <http://www.gnu.org/licenses/>.
23 #include "object-editor.h"
25 #include <glib/gi18n.h>
30 #include "builder-util.h"
31 #include "units-util.h"
33 #include "object-editor-private.h"
38 /*===========================================*/
40 /*===========================================*/
43 /*===========================================*/
44 /* Private data types */
45 /*===========================================*/
48 /*===========================================*/
50 /*===========================================*/
53 /*===========================================*/
54 /* Local function prototypes */
55 /*===========================================*/
58 /*--------------------------------------------------------------------------*/
59 /* PRIVATE. Prepare position page. */
60 /*--------------------------------------------------------------------------*/
62 gl_object_editor_prepare_position_page (glObjectEditor *editor)
65 const gchar *units_string;
69 gl_debug (DEBUG_EDITOR, "START");
71 /* Extract widgets from XML tree. */
72 gl_builder_util_get_widgets (editor->priv->builder,
73 "pos_page_vbox", &editor->priv->pos_page_vbox,
74 "pos_x_spin", &editor->priv->pos_x_spin,
75 "pos_y_spin", &editor->priv->pos_y_spin,
76 "pos_x_units_label", &editor->priv->pos_x_units_label,
77 "pos_y_units_label", &editor->priv->pos_y_units_label,
80 /* Get configuration information */
81 units = gl_prefs_model_get_units (gl_prefs);
82 units_string = lgl_units_get_name (units);
83 editor->priv->units_per_point = lgl_units_get_units_per_point (units);
84 climb_rate = gl_units_util_get_step_size (units);
85 digits = gl_units_util_get_precision (units);
87 /* Modify widgets based on configuration */
88 gtk_spin_button_set_digits (GTK_SPIN_BUTTON(editor->priv->pos_x_spin), digits);
89 gtk_spin_button_set_increments (GTK_SPIN_BUTTON(editor->priv->pos_x_spin),
90 climb_rate, 10.0*climb_rate);
91 gtk_label_set_text (GTK_LABEL(editor->priv->pos_x_units_label), units_string);
92 gtk_spin_button_set_digits (GTK_SPIN_BUTTON(editor->priv->pos_y_spin), digits);
93 gtk_spin_button_set_increments (GTK_SPIN_BUTTON(editor->priv->pos_y_spin),
94 climb_rate, 10.0*climb_rate);
95 gtk_label_set_text (GTK_LABEL(editor->priv->pos_y_units_label), units_string);
98 gtk_widget_show_all (editor->priv->pos_page_vbox);
100 /* Connect signals */
101 g_signal_connect_swapped (G_OBJECT (editor->priv->pos_x_spin),
103 G_CALLBACK (gl_object_editor_changed_cb),
105 g_signal_connect_swapped (G_OBJECT (editor->priv->pos_y_spin),
107 G_CALLBACK (gl_object_editor_changed_cb),
110 gl_debug (DEBUG_EDITOR, "END");
114 /*****************************************************************************/
116 /*****************************************************************************/
118 gl_object_editor_set_position (glObjectEditor *editor,
122 gl_debug (DEBUG_EDITOR, "START");
125 g_signal_handlers_block_by_func (G_OBJECT (editor->priv->pos_x_spin),
126 gl_object_editor_changed_cb, editor);
127 g_signal_handlers_block_by_func (G_OBJECT (editor->priv->pos_y_spin),
128 gl_object_editor_changed_cb, editor);
131 /* save a copy in internal units */
135 /* convert internal units to displayed units */
136 gl_debug (DEBUG_EDITOR, "internal x,y = %g, %g", x, y);
137 x *= editor->priv->units_per_point;
138 y *= editor->priv->units_per_point;
139 gl_debug (DEBUG_EDITOR, "display x,y = %g, %g", x, y);
141 /* Set widget values */
142 gtk_spin_button_set_value (GTK_SPIN_BUTTON (editor->priv->pos_x_spin), x);
143 gtk_spin_button_set_value (GTK_SPIN_BUTTON (editor->priv->pos_y_spin), y);
146 g_signal_handlers_unblock_by_func (G_OBJECT (editor->priv->pos_x_spin),
147 gl_object_editor_changed_cb, editor);
148 g_signal_handlers_unblock_by_func (G_OBJECT (editor->priv->pos_y_spin),
149 gl_object_editor_changed_cb, editor);
152 gl_debug (DEBUG_EDITOR, "END");
156 /*****************************************************************************/
157 /* Set maximum position. */
158 /*****************************************************************************/
160 gl_object_editor_set_max_position (glObjectEditor *editor,
166 gl_debug (DEBUG_EDITOR, "START");
169 g_signal_handlers_block_by_func (G_OBJECT (editor->priv->pos_x_spin),
170 gl_object_editor_changed_cb, editor);
171 g_signal_handlers_block_by_func (G_OBJECT (editor->priv->pos_y_spin),
172 gl_object_editor_changed_cb, editor);
175 /* save a copy in internal units */
176 editor->priv->x_max = x_max;
177 editor->priv->y_max = y_max;
179 /* convert internal units to displayed units */
180 gl_debug (DEBUG_EDITOR, "internal x_max,y_max = %g, %g", x_max, y_max);
181 x_max *= editor->priv->units_per_point;
182 y_max *= editor->priv->units_per_point;
183 gl_debug (DEBUG_EDITOR, "display x_max,y_max = %g, %g", x_max, y_max);
185 /* Set widget values */
186 tmp = gtk_spin_button_get_value (GTK_SPIN_BUTTON (editor->priv->pos_x_spin));
187 gtk_spin_button_set_range (GTK_SPIN_BUTTON (editor->priv->pos_x_spin), -x_max, 2.0*x_max);
188 gtk_spin_button_set_value (GTK_SPIN_BUTTON (editor->priv->pos_x_spin), tmp);
189 tmp = gtk_spin_button_get_value (GTK_SPIN_BUTTON (editor->priv->pos_y_spin));
190 gtk_spin_button_set_range (GTK_SPIN_BUTTON (editor->priv->pos_y_spin), -y_max, 2.0*y_max);
191 gtk_spin_button_set_value (GTK_SPIN_BUTTON (editor->priv->pos_y_spin), tmp);
194 g_signal_handlers_unblock_by_func (G_OBJECT (editor->priv->pos_x_spin),
195 gl_object_editor_changed_cb, editor);
196 g_signal_handlers_unblock_by_func (G_OBJECT (editor->priv->pos_y_spin),
197 gl_object_editor_changed_cb, editor);
200 gl_debug (DEBUG_EDITOR, "END");
204 /*****************************************************************************/
205 /* Query position. */
206 /*****************************************************************************/
208 gl_object_editor_get_position (glObjectEditor *editor,
212 gl_debug (DEBUG_EDITOR, "START");
214 /* Get values from widgets */
215 *x = gtk_spin_button_get_value (GTK_SPIN_BUTTON (editor->priv->pos_x_spin));
216 *y = gtk_spin_button_get_value (GTK_SPIN_BUTTON (editor->priv->pos_y_spin));
218 /* convert everything back to our internal units (points) */
219 *x /= editor->priv->units_per_point;
220 *y /= editor->priv->units_per_point;
222 /* save a copy in internal units */
223 editor->priv->x = *x;
224 editor->priv->y = *y;
226 gl_debug (DEBUG_EDITOR, "END");
230 /*****************************************************************************/
231 /* PRIVATE. Prefs changed callback. Update units related items. */
232 /*****************************************************************************/
234 position_prefs_changed_cb (glObjectEditor *editor)
237 const gchar *units_string;
241 gl_debug (DEBUG_EDITOR, "START");
244 g_signal_handlers_block_by_func (G_OBJECT (editor->priv->pos_x_spin),
245 gl_object_editor_changed_cb, editor);
246 g_signal_handlers_block_by_func (G_OBJECT (editor->priv->pos_y_spin),
247 gl_object_editor_changed_cb, editor);
250 /* Get new configuration information */
251 units = gl_prefs_model_get_units (gl_prefs);
252 units_string = lgl_units_get_name (units);
253 editor->priv->units_per_point = lgl_units_get_units_per_point (units);
254 climb_rate = gl_units_util_get_step_size (units);
255 digits = gl_units_util_get_precision (units);
257 /* Update characteristics of x_spin/y_spin */
258 gtk_spin_button_set_digits (GTK_SPIN_BUTTON(editor->priv->pos_x_spin), digits);
259 gtk_spin_button_set_digits (GTK_SPIN_BUTTON(editor->priv->pos_y_spin), digits);
260 gtk_spin_button_set_increments (GTK_SPIN_BUTTON(editor->priv->pos_x_spin),
261 climb_rate, 10.0*climb_rate);
262 gtk_spin_button_set_increments (GTK_SPIN_BUTTON(editor->priv->pos_y_spin),
263 climb_rate, 10.0*climb_rate);
266 /* Update units_labels */
267 gtk_label_set_text (GTK_LABEL(editor->priv->pos_x_units_label),
269 gtk_label_set_text (GTK_LABEL(editor->priv->pos_y_units_label),
272 /* Update values of x_spin/y_spin */
273 gl_object_editor_set_position (editor, editor->priv->x, editor->priv->y);
274 gl_object_editor_set_max_position (editor, editor->priv->x_max, editor->priv->y_max);
277 g_signal_handlers_unblock_by_func (G_OBJECT (editor->priv->pos_x_spin),
278 gl_object_editor_changed_cb, editor);
279 g_signal_handlers_unblock_by_func (G_OBJECT (editor->priv->pos_y_spin),
280 gl_object_editor_changed_cb, editor);
283 gl_debug (DEBUG_EDITOR, "END");
289 * Local Variables: -- emacs
291 * c-basic-offset: 8 -- emacs
292 * tab-width: 8 -- emacs
293 * indent-tabs-mode: nil -- emacs