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 "mygal/widget-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)
215 gl_debug (DEBUG_EDITOR, "START");
217 editor->priv->stop_signals = TRUE;
219 gtk_widget_set_sensitive (editor->priv->shadow_key_radio, merge_flag);
221 if ( color_node->color == GL_COLOR_NONE ) {
223 color_combo_set_color_to_default (COLOR_COMBO(editor->priv->shadow_color_combo));
227 gdk_color = gl_color_to_gdk_color (color_node->color);
228 color_combo_set_color (COLOR_COMBO(editor->priv->shadow_color_combo),
234 if (!color_node->field_flag || !merge_flag) {
235 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON
236 (editor->priv->shadow_color_radio), TRUE);
237 gtk_widget_set_sensitive (editor->priv->shadow_color_combo, TRUE);
238 gtk_widget_set_sensitive (editor->priv->shadow_key_combo, FALSE);
241 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON
242 (editor->priv->shadow_key_radio), TRUE);
243 gtk_widget_set_sensitive (editor->priv->shadow_color_combo, FALSE);
244 gtk_widget_set_sensitive (editor->priv->shadow_key_combo, TRUE);
246 gl_util_combo_box_set_active_text (GTK_COMBO_BOX (editor->priv->shadow_key_combo),
250 editor->priv->stop_signals = FALSE;
252 gl_debug (DEBUG_EDITOR, "END");
256 gl_object_editor_set_shadow_opacity (glObjectEditor *editor,
259 gl_debug (DEBUG_EDITOR, "START");
261 editor->priv->stop_signals = TRUE;
263 gtk_spin_button_set_value (GTK_SPIN_BUTTON (editor->priv->shadow_opacity_spin),
266 editor->priv->stop_signals = FALSE;
268 gl_debug (DEBUG_EDITOR, "END");
272 /*****************************************************************************/
273 /* Set maximum shadow offset. */
274 /*****************************************************************************/
276 gl_object_editor_set_max_shadow_offset (glObjectEditor *editor,
282 gl_debug (DEBUG_EDITOR, "START");
284 if (editor->priv->shadow_page_vbox)
287 editor->priv->stop_signals = TRUE;
289 /* save a copy in internal units */
290 editor->priv->shadow_x_max = x_max;
291 editor->priv->shadow_y_max = y_max;
293 /* convert internal units to displayed units */
294 gl_debug (DEBUG_EDITOR, "internal x_max,y_max = %g, %g", x_max, y_max);
295 x_max *= editor->priv->units_per_point;
296 y_max *= editor->priv->units_per_point;
297 gl_debug (DEBUG_EDITOR, "display x_max,y_max = %g, %g", x_max, y_max);
299 /* Set widget values */
300 tmp = gtk_spin_button_get_value (GTK_SPIN_BUTTON (editor->priv->shadow_x_spin));
301 gtk_spin_button_set_range (GTK_SPIN_BUTTON (editor->priv->shadow_x_spin),
303 gtk_spin_button_set_value (GTK_SPIN_BUTTON (editor->priv->shadow_x_spin), tmp);
304 tmp = gtk_spin_button_get_value (GTK_SPIN_BUTTON (editor->priv->shadow_y_spin));
305 gtk_spin_button_set_range (GTK_SPIN_BUTTON (editor->priv->shadow_y_spin),
307 gtk_spin_button_set_value (GTK_SPIN_BUTTON (editor->priv->shadow_y_spin), tmp);
309 editor->priv->stop_signals = FALSE;
313 gl_debug (DEBUG_EDITOR, "END");
316 /*****************************************************************************/
317 /* Query shadow parameters. */
318 /*****************************************************************************/
320 gl_object_editor_get_shadow_state (glObjectEditor *editor)
324 gl_debug (DEBUG_EDITOR, "START");
326 state = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (editor->priv->shadow_enable_check));
328 gl_debug (DEBUG_EDITOR, "END");
334 gl_object_editor_get_shadow_offset (glObjectEditor *editor,
338 gl_debug (DEBUG_EDITOR, "START");
340 /* Get values from widgets */
341 *x = gtk_spin_button_get_value (GTK_SPIN_BUTTON (editor->priv->shadow_x_spin));
342 *y = gtk_spin_button_get_value (GTK_SPIN_BUTTON (editor->priv->shadow_y_spin));
344 /* convert everything back to our internal units (points) */
345 *x /= editor->priv->units_per_point;
346 *y /= editor->priv->units_per_point;
348 /* save a copy in internal units */
349 editor->priv->shadow_x = *x;
350 editor->priv->shadow_y = *y;
352 gl_debug (DEBUG_EDITOR, "END");
356 gl_object_editor_get_shadow_color (glObjectEditor *editor)
360 glColorNode *color_node;
362 gl_debug (DEBUG_EDITOR, "START");
364 color_node = gl_color_node_new_default ();
366 if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (editor->priv->shadow_key_radio))) {
367 color_node->field_flag = TRUE;
369 gtk_combo_box_get_active_text (GTK_COMBO_BOX (editor->priv->shadow_key_combo));
371 color_node->field_flag = FALSE;
372 color_node->key = NULL;
373 gdk_color = color_combo_get_color (COLOR_COMBO(editor->priv->shadow_color_combo),
377 color_node->color = gl_color_from_gdk_color (gdk_color);
381 gl_debug (DEBUG_EDITOR, "END");
387 gl_object_editor_get_shadow_opacity (glObjectEditor *editor)
391 gl_debug (DEBUG_EDITOR, "START");
393 alpha = gtk_spin_button_get_value (GTK_SPIN_BUTTON (editor->priv->shadow_opacity_spin));
395 gl_debug (DEBUG_EDITOR, "END");
397 return alpha / 100.0;
401 /*****************************************************************************/
402 /* PRIVATE. Prefs changed callback. Update units related items. */
403 /*****************************************************************************/
405 shadow_prefs_changed_cb (glObjectEditor *editor)
407 const gchar *units_string;
411 gl_debug (DEBUG_EDITOR, "START");
413 /* Get new configuration information */
414 units_string = gl_prefs_get_units_string ();
415 editor->priv->units_per_point = gl_prefs_get_units_per_point ();
416 climb_rate = gl_prefs_get_units_step_size ();
417 digits = gl_prefs_get_units_precision ();
419 /* Update characteristics of x_spin/y_spin */
420 editor->priv->stop_signals = TRUE;
421 gtk_spin_button_set_digits (GTK_SPIN_BUTTON(editor->priv->shadow_x_spin),
423 gtk_spin_button_set_digits (GTK_SPIN_BUTTON(editor->priv->shadow_y_spin),
425 gtk_spin_button_set_increments (GTK_SPIN_BUTTON(editor->priv->shadow_x_spin),
426 climb_rate, 10.0*climb_rate);
427 gtk_spin_button_set_increments (GTK_SPIN_BUTTON(editor->priv->shadow_y_spin),
428 climb_rate, 10.0*climb_rate);
429 editor->priv->stop_signals = FALSE;
431 /* Update units_labels */
432 gtk_label_set_text (GTK_LABEL(editor->priv->shadow_x_units_label),
434 gtk_label_set_text (GTK_LABEL(editor->priv->shadow_y_units_label),
437 /* Update values of x_spin/y_spin */
438 gl_object_editor_set_shadow_offset (editor,
439 editor->priv->shadow_x,
440 editor->priv->shadow_y);
441 gl_object_editor_set_max_shadow_offset (editor,
442 editor->priv->shadow_x_max,
443 editor->priv->shadow_y_max);
445 gl_debug (DEBUG_EDITOR, "END");
448 /*--------------------------------------------------------------------------*/
449 /* PRIVATE. shadow enable check callback. */
450 /*--------------------------------------------------------------------------*/
452 shadow_enable_check_toggled_cb (glObjectEditor *editor)
456 if (editor->priv->stop_signals) return;
458 gl_debug (DEBUG_EDITOR, "START");
460 state = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (editor->priv->shadow_enable_check));
462 gtk_widget_set_sensitive (editor->priv->shadow_controls_table, state);
464 /* Emit our "changed" signal */
465 g_signal_emit (G_OBJECT (editor), gl_object_editor_signals[CHANGED], 0);
467 gl_debug (DEBUG_EDITOR, "END");
471 /*--------------------------------------------------------------------------*/
472 /* PRIVATE. shadow color radio callback. */
473 /*--------------------------------------------------------------------------*/
475 shadow_color_radio_toggled_cb (glObjectEditor *editor)
477 if (editor->priv->stop_signals) return;
479 gl_debug (DEBUG_EDITOR, "START");
481 if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (editor->priv->shadow_color_radio))) {
482 gtk_widget_set_sensitive (editor->priv->shadow_color_combo, TRUE);
483 gtk_widget_set_sensitive (editor->priv->shadow_key_combo, FALSE);
485 gtk_widget_set_sensitive (editor->priv->shadow_color_combo, FALSE);
486 gtk_widget_set_sensitive (editor->priv->shadow_key_combo, TRUE);
490 /* Emit our "changed" signal */
491 g_signal_emit (G_OBJECT (editor), gl_object_editor_signals[CHANGED], 0);
493 gl_debug (DEBUG_EDITOR, "END");