1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- */
4 * (GLABELS) Label and Business Card Creation program for GNOME
6 * object-editor.c: object properties editor module
8 * Copyright (C) 2003 Jim Evins <evins@snaught.com>.
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
26 #include "object-editor.h"
28 #include <glib/gi18n.h>
29 #include <gtk/gtklabel.h>
30 #include <gtk/gtkspinbutton.h>
35 #include "object-editor-private.h"
39 /*===========================================*/
41 /*===========================================*/
43 /*===========================================*/
44 /* Private data types */
45 /*===========================================*/
47 /*===========================================*/
49 /*===========================================*/
51 /*===========================================*/
52 /* Local function prototypes */
53 /*===========================================*/
56 /*--------------------------------------------------------------------------*/
57 /* PRIVATE. Prepare position page. */
58 /*--------------------------------------------------------------------------*/
60 gl_object_editor_prepare_position_page (glObjectEditor *editor)
62 const gchar *units_string;
66 gl_debug (DEBUG_EDITOR, "START");
68 /* Extract widgets from XML tree. */
69 editor->priv->pos_page_vbox = glade_xml_get_widget (editor->priv->gui,
71 editor->priv->pos_x_spin = glade_xml_get_widget (editor->priv->gui,
73 editor->priv->pos_y_spin = glade_xml_get_widget (editor->priv->gui,
75 editor->priv->pos_x_units_label = glade_xml_get_widget (editor->priv->gui,
77 editor->priv->pos_y_units_label = glade_xml_get_widget (editor->priv->gui,
80 /* Get configuration information */
81 units_string = gl_prefs_get_units_string ();
82 editor->priv->units_per_point = gl_prefs_get_units_per_point ();
83 climb_rate = gl_prefs_get_units_step_size ();
84 digits = gl_prefs_get_units_precision ();
86 /* Modify widgets based on configuration */
87 gtk_spin_button_set_digits (GTK_SPIN_BUTTON(editor->priv->pos_x_spin), digits);
88 gtk_spin_button_set_increments (GTK_SPIN_BUTTON(editor->priv->pos_x_spin),
89 climb_rate, 10.0*climb_rate);
90 gtk_label_set_text (GTK_LABEL(editor->priv->pos_x_units_label), units_string);
91 gtk_spin_button_set_digits (GTK_SPIN_BUTTON(editor->priv->pos_y_spin), digits);
92 gtk_spin_button_set_increments (GTK_SPIN_BUTTON(editor->priv->pos_y_spin),
93 climb_rate, 10.0*climb_rate);
94 gtk_label_set_text (GTK_LABEL(editor->priv->pos_y_units_label), units_string);
97 gtk_widget_show_all (editor->priv->pos_page_vbox);
100 g_signal_connect_swapped (G_OBJECT (editor->priv->pos_x_spin),
102 G_CALLBACK (gl_object_editor_changed_cb),
104 g_signal_connect_swapped (G_OBJECT (editor->priv->pos_y_spin),
106 G_CALLBACK (gl_object_editor_changed_cb),
109 gl_debug (DEBUG_EDITOR, "END");
112 /*****************************************************************************/
114 /*****************************************************************************/
116 gl_object_editor_set_position (glObjectEditor *editor,
120 gl_debug (DEBUG_EDITOR, "START");
122 editor->priv->stop_signals = TRUE;
124 /* save a copy in internal units */
128 /* convert internal units to displayed units */
129 gl_debug (DEBUG_EDITOR, "internal x,y = %g, %g", x, y);
130 x *= editor->priv->units_per_point;
131 y *= editor->priv->units_per_point;
132 gl_debug (DEBUG_EDITOR, "display x,y = %g, %g", x, y);
134 /* Set widget values */
135 gtk_spin_button_set_value (GTK_SPIN_BUTTON (editor->priv->pos_x_spin), x);
136 gtk_spin_button_set_value (GTK_SPIN_BUTTON (editor->priv->pos_y_spin), y);
138 editor->priv->stop_signals = FALSE;
140 gl_debug (DEBUG_EDITOR, "END");
143 /*****************************************************************************/
144 /* Set maximum position. */
145 /*****************************************************************************/
147 gl_object_editor_set_max_position (glObjectEditor *editor,
153 gl_debug (DEBUG_EDITOR, "START");
155 editor->priv->stop_signals = TRUE;
157 /* save a copy in internal units */
158 editor->priv->x_max = x_max;
159 editor->priv->y_max = y_max;
161 /* convert internal units to displayed units */
162 gl_debug (DEBUG_EDITOR, "internal x_max,y_max = %g, %g", x_max, y_max);
163 x_max *= editor->priv->units_per_point;
164 y_max *= editor->priv->units_per_point;
165 gl_debug (DEBUG_EDITOR, "display x_max,y_max = %g, %g", x_max, y_max);
167 /* Set widget values */
168 tmp = gtk_spin_button_get_value (GTK_SPIN_BUTTON (editor->priv->pos_x_spin));
169 gtk_spin_button_set_range (GTK_SPIN_BUTTON (editor->priv->pos_x_spin),
171 gtk_spin_button_set_value (GTK_SPIN_BUTTON (editor->priv->pos_x_spin), tmp);
172 tmp = gtk_spin_button_get_value (GTK_SPIN_BUTTON (editor->priv->pos_y_spin));
173 gtk_spin_button_set_range (GTK_SPIN_BUTTON (editor->priv->pos_y_spin),
175 gtk_spin_button_set_value (GTK_SPIN_BUTTON (editor->priv->pos_y_spin), tmp);
177 editor->priv->stop_signals = FALSE;
179 gl_debug (DEBUG_EDITOR, "END");
182 /*****************************************************************************/
183 /* Query position. */
184 /*****************************************************************************/
186 gl_object_editor_get_position (glObjectEditor *editor,
190 gl_debug (DEBUG_EDITOR, "START");
192 /* Get values from widgets */
193 *x = gtk_spin_button_get_value (GTK_SPIN_BUTTON (editor->priv->pos_x_spin));
194 *y = gtk_spin_button_get_value (GTK_SPIN_BUTTON (editor->priv->pos_y_spin));
196 /* convert everything back to our internal units (points) */
197 *x /= editor->priv->units_per_point;
198 *y /= editor->priv->units_per_point;
200 /* save a copy in internal units */
201 editor->priv->x = *x;
202 editor->priv->y = *y;
204 gl_debug (DEBUG_EDITOR, "END");
207 /*****************************************************************************/
208 /* PRIVATE. Prefs changed callback. Update units related items. */
209 /*****************************************************************************/
211 position_prefs_changed_cb (glObjectEditor *editor)
213 const gchar *units_string;
217 gl_debug (DEBUG_EDITOR, "START");
219 /* Get new configuration information */
220 units_string = gl_prefs_get_units_string ();
221 editor->priv->units_per_point = gl_prefs_get_units_per_point ();
222 climb_rate = gl_prefs_get_units_step_size ();
223 digits = gl_prefs_get_units_precision ();
225 /* Update characteristics of x_spin/y_spin */
226 editor->priv->stop_signals = TRUE;
227 gtk_spin_button_set_digits (GTK_SPIN_BUTTON(editor->priv->pos_x_spin),
229 gtk_spin_button_set_digits (GTK_SPIN_BUTTON(editor->priv->pos_y_spin),
231 gtk_spin_button_set_increments (GTK_SPIN_BUTTON(editor->priv->pos_x_spin),
232 climb_rate, 10.0*climb_rate);
233 gtk_spin_button_set_increments (GTK_SPIN_BUTTON(editor->priv->pos_y_spin),
234 climb_rate, 10.0*climb_rate);
235 editor->priv->stop_signals = FALSE;
237 /* Update units_labels */
238 gtk_label_set_text (GTK_LABEL(editor->priv->pos_x_units_label),
240 gtk_label_set_text (GTK_LABEL(editor->priv->pos_y_units_label),
243 /* Update values of x_spin/y_spin */
244 gl_object_editor_set_position (editor,
247 gl_object_editor_set_max_position (editor,
249 editor->priv->y_max);
251 gl_debug (DEBUG_EDITOR, "END");