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) 2006 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/gtktogglebutton.h>
30 #include <gtk/gtklabel.h>
31 #include <gtk/gtkspinbutton.h>
32 #include <gtk/gtkcombobox.h>
36 #include "color-combo.h"
40 #include "object-editor-private.h"
44 /*===========================================*/
46 /*===========================================*/
48 /*===========================================*/
49 /* Private data types */
50 /*===========================================*/
52 /*===========================================*/
54 /*===========================================*/
56 /*===========================================*/
57 /* Local function prototypes */
58 /*===========================================*/
60 static void shadow_enable_check_toggled_cb (glObjectEditor *editor);
61 static void shadow_color_radio_toggled_cb (glObjectEditor *editor);
64 /*--------------------------------------------------------------------------*/
65 /* PRIVATE. Prepare shadow page. */
66 /*--------------------------------------------------------------------------*/
68 gl_object_editor_prepare_shadow_page (glObjectEditor *editor)
70 const gchar *units_string;
74 gl_debug (DEBUG_EDITOR, "START");
76 /* Extract widgets from XML tree. */
77 editor->priv->shadow_page_vbox
78 = glade_xml_get_widget (editor->priv->gui, "shadow_page_vbox");
79 editor->priv->shadow_enable_check
80 = glade_xml_get_widget (editor->priv->gui, "shadow_enable_check");
81 editor->priv->shadow_controls_table
82 = glade_xml_get_widget (editor->priv->gui, "shadow_controls_table");
83 editor->priv->shadow_x_spin
84 = glade_xml_get_widget (editor->priv->gui, "shadow_x_spin");
85 editor->priv->shadow_y_spin
86 = glade_xml_get_widget (editor->priv->gui, "shadow_y_spin");
87 editor->priv->shadow_x_units_label
88 = glade_xml_get_widget (editor->priv->gui, "shadow_x_units_label");
89 editor->priv->shadow_y_units_label
90 = glade_xml_get_widget (editor->priv->gui, "shadow_y_units_label");
91 editor->priv->shadow_color_radio
92 = glade_xml_get_widget (editor->priv->gui, "shadow_color_radio");
93 editor->priv->shadow_key_radio
94 = glade_xml_get_widget (editor->priv->gui, "shadow_key_radio");
95 editor->priv->shadow_color_combo
96 = glade_xml_get_widget (editor->priv->gui, "shadow_color_combo");
97 editor->priv->shadow_key_combo
98 = glade_xml_get_widget (editor->priv->gui, "shadow_key_combo");
99 editor->priv->shadow_opacity_spin
100 = glade_xml_get_widget (editor->priv->gui, "shadow_opacity_spin");
102 gl_util_combo_box_add_text_model ( GTK_COMBO_BOX(editor->priv->shadow_key_combo));
104 /* Get configuration information */
105 units_string = gl_prefs_get_units_string ();
106 editor->priv->units_per_point = gl_prefs_get_units_per_point ();
107 climb_rate = gl_prefs_get_units_step_size ();
108 digits = gl_prefs_get_units_precision ();
110 /* Modify widgets based on configuration */
111 gtk_spin_button_set_digits (GTK_SPIN_BUTTON(editor->priv->shadow_x_spin), digits);
112 gtk_spin_button_set_increments (GTK_SPIN_BUTTON(editor->priv->shadow_x_spin),
113 climb_rate, 10.0*climb_rate);
114 gtk_label_set_text (GTK_LABEL(editor->priv->shadow_x_units_label), units_string);
115 gtk_spin_button_set_digits (GTK_SPIN_BUTTON(editor->priv->shadow_y_spin), digits);
116 gtk_spin_button_set_increments (GTK_SPIN_BUTTON(editor->priv->shadow_y_spin),
117 climb_rate, 10.0*climb_rate);
118 gtk_label_set_text (GTK_LABEL(editor->priv->shadow_y_units_label), units_string);
121 gtk_widget_show_all (editor->priv->shadow_page_vbox);
123 /* Connect signals */
124 g_signal_connect_swapped (G_OBJECT (editor->priv->shadow_enable_check),
126 G_CALLBACK (shadow_enable_check_toggled_cb),
128 g_signal_connect_swapped (G_OBJECT (editor->priv->shadow_x_spin),
130 G_CALLBACK (gl_object_editor_changed_cb),
132 g_signal_connect_swapped (G_OBJECT (editor->priv->shadow_y_spin),
134 G_CALLBACK (gl_object_editor_changed_cb),
136 g_signal_connect_swapped (G_OBJECT (editor->priv->shadow_color_combo),
138 G_CALLBACK (gl_object_editor_changed_cb),
140 g_signal_connect_swapped (G_OBJECT (editor->priv->shadow_key_combo),
142 G_CALLBACK (gl_object_editor_changed_cb),
144 g_signal_connect_swapped (G_OBJECT (editor->priv->shadow_color_radio),
146 G_CALLBACK (shadow_color_radio_toggled_cb),
148 g_signal_connect_swapped (G_OBJECT (editor->priv->shadow_key_radio),
150 G_CALLBACK (shadow_color_radio_toggled_cb),
152 g_signal_connect_swapped (G_OBJECT (editor->priv->shadow_opacity_spin),
154 G_CALLBACK (gl_object_editor_changed_cb),
157 gl_debug (DEBUG_EDITOR, "END");
160 /*****************************************************************************/
161 /* Set shadow parameters. */
162 /*****************************************************************************/
164 gl_object_editor_set_shadow_state (glObjectEditor *editor,
167 gl_debug (DEBUG_EDITOR, "START");
169 editor->priv->stop_signals = TRUE;
171 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (editor->priv->shadow_enable_check),
173 gtk_widget_set_sensitive (editor->priv->shadow_controls_table, state);
175 editor->priv->stop_signals = FALSE;
177 gl_debug (DEBUG_EDITOR, "END");
181 gl_object_editor_set_shadow_offset (glObjectEditor *editor,
185 gl_debug (DEBUG_EDITOR, "START");
187 editor->priv->stop_signals = TRUE;
189 /* save a copy in internal units */
190 editor->priv->shadow_x = x;
191 editor->priv->shadow_y = y;
193 /* convert internal units to displayed units */
194 gl_debug (DEBUG_EDITOR, "internal x,y = %g, %g", x, y);
195 x *= editor->priv->units_per_point;
196 y *= editor->priv->units_per_point;
197 gl_debug (DEBUG_EDITOR, "display x,y = %g, %g", x, y);
199 /* Set widget values */
200 gtk_spin_button_set_value (GTK_SPIN_BUTTON (editor->priv->shadow_x_spin), x);
201 gtk_spin_button_set_value (GTK_SPIN_BUTTON (editor->priv->shadow_y_spin), y);
203 editor->priv->stop_signals = FALSE;
205 gl_debug (DEBUG_EDITOR, "END");
209 gl_object_editor_set_shadow_color (glObjectEditor *editor,
211 glColorNode *color_node)
213 gl_debug (DEBUG_EDITOR, "START");
215 editor->priv->stop_signals = TRUE;
217 gtk_widget_set_sensitive (editor->priv->shadow_key_radio, merge_flag);
219 if ( color_node->color == GL_COLOR_NONE ) {
221 gl_color_combo_set_to_default (GL_COLOR_COMBO(editor->priv->shadow_color_combo));
225 gl_color_combo_set_color (GL_COLOR_COMBO(editor->priv->shadow_color_combo),
230 if (!color_node->field_flag) {
231 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON
232 (editor->priv->shadow_color_radio), TRUE);
233 gtk_widget_set_sensitive (editor->priv->shadow_color_combo, TRUE);
234 gtk_widget_set_sensitive (editor->priv->shadow_key_combo, FALSE);
237 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON
238 (editor->priv->shadow_key_radio), TRUE);
239 gtk_widget_set_sensitive (editor->priv->shadow_color_combo, FALSE);
240 gtk_widget_set_sensitive (editor->priv->shadow_key_combo, TRUE);
242 gl_util_combo_box_set_active_text (GTK_COMBO_BOX (editor->priv->shadow_key_combo),
246 editor->priv->stop_signals = FALSE;
248 gl_debug (DEBUG_EDITOR, "END");
252 gl_object_editor_set_shadow_opacity (glObjectEditor *editor,
255 gl_debug (DEBUG_EDITOR, "START");
257 editor->priv->stop_signals = TRUE;
259 gtk_spin_button_set_value (GTK_SPIN_BUTTON (editor->priv->shadow_opacity_spin),
262 editor->priv->stop_signals = FALSE;
264 gl_debug (DEBUG_EDITOR, "END");
268 /*****************************************************************************/
269 /* Set maximum shadow offset. */
270 /*****************************************************************************/
272 gl_object_editor_set_max_shadow_offset (glObjectEditor *editor,
278 gl_debug (DEBUG_EDITOR, "START");
280 if (editor->priv->shadow_page_vbox)
283 editor->priv->stop_signals = TRUE;
285 /* save a copy in internal units */
286 editor->priv->shadow_x_max = x_max;
287 editor->priv->shadow_y_max = y_max;
289 /* convert internal units to displayed units */
290 gl_debug (DEBUG_EDITOR, "internal x_max,y_max = %g, %g", x_max, y_max);
291 x_max *= editor->priv->units_per_point;
292 y_max *= editor->priv->units_per_point;
293 gl_debug (DEBUG_EDITOR, "display x_max,y_max = %g, %g", x_max, y_max);
295 /* Set widget values */
296 tmp = gtk_spin_button_get_value (GTK_SPIN_BUTTON (editor->priv->shadow_x_spin));
297 gtk_spin_button_set_range (GTK_SPIN_BUTTON (editor->priv->shadow_x_spin),
299 gtk_spin_button_set_value (GTK_SPIN_BUTTON (editor->priv->shadow_x_spin), tmp);
300 tmp = gtk_spin_button_get_value (GTK_SPIN_BUTTON (editor->priv->shadow_y_spin));
301 gtk_spin_button_set_range (GTK_SPIN_BUTTON (editor->priv->shadow_y_spin),
303 gtk_spin_button_set_value (GTK_SPIN_BUTTON (editor->priv->shadow_y_spin), tmp);
305 editor->priv->stop_signals = FALSE;
309 gl_debug (DEBUG_EDITOR, "END");
312 /*****************************************************************************/
313 /* Query shadow parameters. */
314 /*****************************************************************************/
316 gl_object_editor_get_shadow_state (glObjectEditor *editor)
320 gl_debug (DEBUG_EDITOR, "START");
322 state = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (editor->priv->shadow_enable_check));
324 gl_debug (DEBUG_EDITOR, "END");
330 gl_object_editor_get_shadow_offset (glObjectEditor *editor,
334 gl_debug (DEBUG_EDITOR, "START");
336 /* Get values from widgets */
337 *x = gtk_spin_button_get_value (GTK_SPIN_BUTTON (editor->priv->shadow_x_spin));
338 *y = gtk_spin_button_get_value (GTK_SPIN_BUTTON (editor->priv->shadow_y_spin));
340 /* convert everything back to our internal units (points) */
341 *x /= editor->priv->units_per_point;
342 *y /= editor->priv->units_per_point;
344 /* save a copy in internal units */
345 editor->priv->shadow_x = *x;
346 editor->priv->shadow_y = *y;
348 gl_debug (DEBUG_EDITOR, "END");
352 gl_object_editor_get_shadow_color (glObjectEditor *editor)
356 glColorNode *color_node;
358 gl_debug (DEBUG_EDITOR, "START");
360 color_node = gl_color_node_new_default ();
362 if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (editor->priv->shadow_key_radio))) {
363 color_node->field_flag = TRUE;
365 gtk_combo_box_get_active_text (GTK_COMBO_BOX (editor->priv->shadow_key_combo));
367 color_node->field_flag = FALSE;
368 color_node->key = NULL;
369 color = gl_color_combo_get_color (GL_COLOR_COMBO(editor->priv->shadow_color_combo),
373 color_node->color = color;
377 gl_debug (DEBUG_EDITOR, "END");
383 gl_object_editor_get_shadow_opacity (glObjectEditor *editor)
387 gl_debug (DEBUG_EDITOR, "START");
389 alpha = gtk_spin_button_get_value (GTK_SPIN_BUTTON (editor->priv->shadow_opacity_spin));
391 gl_debug (DEBUG_EDITOR, "END");
393 return alpha / 100.0;
397 /*****************************************************************************/
398 /* PRIVATE. Prefs changed callback. Update units related items. */
399 /*****************************************************************************/
401 shadow_prefs_changed_cb (glObjectEditor *editor)
403 const gchar *units_string;
407 gl_debug (DEBUG_EDITOR, "START");
409 /* Get new configuration information */
410 units_string = gl_prefs_get_units_string ();
411 editor->priv->units_per_point = gl_prefs_get_units_per_point ();
412 climb_rate = gl_prefs_get_units_step_size ();
413 digits = gl_prefs_get_units_precision ();
415 /* Update characteristics of x_spin/y_spin */
416 editor->priv->stop_signals = TRUE;
417 gtk_spin_button_set_digits (GTK_SPIN_BUTTON(editor->priv->shadow_x_spin),
419 gtk_spin_button_set_digits (GTK_SPIN_BUTTON(editor->priv->shadow_y_spin),
421 gtk_spin_button_set_increments (GTK_SPIN_BUTTON(editor->priv->shadow_x_spin),
422 climb_rate, 10.0*climb_rate);
423 gtk_spin_button_set_increments (GTK_SPIN_BUTTON(editor->priv->shadow_y_spin),
424 climb_rate, 10.0*climb_rate);
425 editor->priv->stop_signals = FALSE;
427 /* Update units_labels */
428 gtk_label_set_text (GTK_LABEL(editor->priv->shadow_x_units_label),
430 gtk_label_set_text (GTK_LABEL(editor->priv->shadow_y_units_label),
433 /* Update values of x_spin/y_spin */
434 gl_object_editor_set_shadow_offset (editor,
435 editor->priv->shadow_x,
436 editor->priv->shadow_y);
437 gl_object_editor_set_max_shadow_offset (editor,
438 editor->priv->shadow_x_max,
439 editor->priv->shadow_y_max);
441 gl_debug (DEBUG_EDITOR, "END");
444 /*--------------------------------------------------------------------------*/
445 /* PRIVATE. shadow enable check callback. */
446 /*--------------------------------------------------------------------------*/
448 shadow_enable_check_toggled_cb (glObjectEditor *editor)
452 if (editor->priv->stop_signals) return;
454 gl_debug (DEBUG_EDITOR, "START");
456 state = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (editor->priv->shadow_enable_check));
458 gtk_widget_set_sensitive (editor->priv->shadow_controls_table, state);
460 /* Emit our "changed" signal */
461 g_signal_emit (G_OBJECT (editor), gl_object_editor_signals[CHANGED], 0);
463 gl_debug (DEBUG_EDITOR, "END");
467 /*--------------------------------------------------------------------------*/
468 /* PRIVATE. shadow color radio callback. */
469 /*--------------------------------------------------------------------------*/
471 shadow_color_radio_toggled_cb (glObjectEditor *editor)
473 if (editor->priv->stop_signals) return;
475 gl_debug (DEBUG_EDITOR, "START");
477 if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (editor->priv->shadow_color_radio))) {
478 gtk_widget_set_sensitive (editor->priv->shadow_color_combo, TRUE);
479 gtk_widget_set_sensitive (editor->priv->shadow_key_combo, FALSE);
481 gtk_widget_set_sensitive (editor->priv->shadow_color_combo, FALSE);
482 gtk_widget_set_sensitive (editor->priv->shadow_key_combo, TRUE);
486 /* Emit our "changed" signal */
487 g_signal_emit (G_OBJECT (editor), gl_object_editor_signals[CHANGED], 0);
489 gl_debug (DEBUG_EDITOR, "END");