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>
31 #include <gtk/gtkcombobox.h>
32 #include <gtk/gtktogglebutton.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 /*===========================================*/
59 static void line_radio_toggled_cb (glObjectEditor *editor);
62 /*--------------------------------------------------------------------------*/
63 /* PRIVATE. Prepare line page. */
64 /*--------------------------------------------------------------------------*/
66 gl_object_editor_prepare_line_page (glObjectEditor *editor)
70 gl_debug (DEBUG_EDITOR, "START");
72 /* Extract widgets from XML tree. */
73 editor->priv->line_page_vbox = glade_xml_get_widget (editor->priv->gui,
75 editor->priv->line_width_spin = glade_xml_get_widget (editor->priv->gui,
77 editor->priv->line_color_combo = glade_xml_get_widget (editor->priv->gui,
79 editor->priv->line_key_combo = glade_xml_get_widget (editor->priv->gui,
81 editor->priv->line_key_radio = glade_xml_get_widget (editor->priv->gui,
83 editor->priv->line_color_radio = glade_xml_get_widget (editor->priv->gui,
86 gl_util_combo_box_add_text_model ( GTK_COMBO_BOX(editor->priv->line_key_combo));
88 /* Modify widgets based on configuration */
89 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (editor->priv->line_color_radio), TRUE);
90 gtk_widget_set_sensitive (editor->priv->line_color_combo, TRUE);
91 gtk_widget_set_sensitive (editor->priv->line_key_combo, FALSE);
92 gtk_spin_button_set_value (GTK_SPIN_BUTTON (editor->priv->line_width_spin),
93 gl_prefs->default_line_width);
94 gdk_color = gl_color_to_gdk_color (gl_prefs->default_line_color);
95 color_combo_set_color (COLOR_COMBO(editor->priv->line_color_combo), gdk_color);
99 gtk_widget_show_all (editor->priv->line_page_vbox);
101 /* Connect signals */
102 g_signal_connect_swapped (G_OBJECT (editor->priv->line_width_spin),
104 G_CALLBACK (gl_object_editor_changed_cb),
106 g_signal_connect_swapped (G_OBJECT (editor->priv->line_color_combo),
108 G_CALLBACK (gl_object_editor_changed_cb),
110 g_signal_connect_swapped (G_OBJECT (editor->priv->line_key_combo),
112 G_CALLBACK (gl_object_editor_changed_cb),
114 g_signal_connect_swapped (G_OBJECT (editor->priv->line_color_radio),
116 G_CALLBACK (line_radio_toggled_cb),
118 g_signal_connect_swapped (G_OBJECT (editor->priv->line_key_radio),
120 G_CALLBACK (line_radio_toggled_cb),
123 gl_debug (DEBUG_EDITOR, "END");
126 /*****************************************************************************/
127 /* Set line width. */
128 /*****************************************************************************/
130 gl_object_editor_set_line_width (glObjectEditor *editor,
133 gl_debug (DEBUG_EDITOR, "START");
135 editor->priv->stop_signals = TRUE;
137 /* Set widget values */
138 gtk_spin_button_set_value (GTK_SPIN_BUTTON (editor->priv->line_width_spin),
141 editor->priv->stop_signals = FALSE;
143 gl_debug (DEBUG_EDITOR, "END");
146 /*****************************************************************************/
147 /* Query line width. */
148 /*****************************************************************************/
150 gl_object_editor_get_line_width (glObjectEditor *editor)
154 gl_debug (DEBUG_EDITOR, "START");
156 w = gtk_spin_button_get_value (GTK_SPIN_BUTTON(editor->priv->line_width_spin));
158 gl_debug (DEBUG_EDITOR, "END");
163 /*****************************************************************************/
164 /* Set line color. */
165 /*****************************************************************************/
167 gl_object_editor_set_line_color (glObjectEditor *editor,
169 glColorNode *color_node)
173 gl_debug (DEBUG_EDITOR, "START");
175 editor->priv->stop_signals = TRUE;
177 gl_debug (DEBUG_EDITOR, "color field %s(%d) / %X", color_node->key, color_node->field_flag, color_node->color);
178 gtk_widget_set_sensitive (editor->priv->line_key_radio, merge_flag);
180 if ( color_node->color == GL_COLOR_NONE ) {
182 color_combo_set_color_to_default (COLOR_COMBO(editor->priv->line_color_combo));
186 gdk_color = gl_color_to_gdk_color (color_node->color);
187 color_combo_set_color (COLOR_COMBO(editor->priv->line_color_combo),
193 if (!color_node->field_flag || !merge_flag) {
194 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON
195 (editor->priv->line_color_radio), TRUE);
196 gtk_widget_set_sensitive (editor->priv->line_color_combo, TRUE);
197 gtk_widget_set_sensitive (editor->priv->line_key_combo, FALSE);
200 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON
201 (editor->priv->line_key_radio), TRUE);
202 gtk_widget_set_sensitive (editor->priv->line_color_combo, FALSE);
203 gtk_widget_set_sensitive (editor->priv->line_key_combo, TRUE);
205 gl_util_combo_box_set_active_text (GTK_COMBO_BOX (editor->priv->line_key_combo),
209 editor->priv->stop_signals = FALSE;
211 gl_debug (DEBUG_EDITOR, "END");
214 /*****************************************************************************/
215 /* Query line color. */
216 /*****************************************************************************/
218 gl_object_editor_get_line_color (glObjectEditor *editor)
222 glColorNode *color_node;
224 gl_debug (DEBUG_EDITOR, "START");
226 color_node = gl_color_node_new_default ();
228 if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (editor->priv->line_key_radio))) {
229 color_node->field_flag = TRUE;
231 gtk_combo_box_get_active_text (GTK_COMBO_BOX (editor->priv->line_key_combo));
233 color_node->field_flag = FALSE;
234 color_node->key = NULL;
235 gdk_color = color_combo_get_color (COLOR_COMBO(editor->priv->line_color_combo),
239 color_node->color = gl_color_from_gdk_color (gdk_color);
243 gl_debug (DEBUG_EDITOR, "END");
248 /*--------------------------------------------------------------------------*/
249 /* PRIVATE. line color radio callback. */
250 /*--------------------------------------------------------------------------*/
252 line_radio_toggled_cb (glObjectEditor *editor)
254 if (editor->priv->stop_signals) return;
256 gl_debug (DEBUG_EDITOR, "START");
258 if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (editor->priv->line_color_radio))) {
259 gtk_widget_set_sensitive (editor->priv->line_color_combo, TRUE);
260 gtk_widget_set_sensitive (editor->priv->line_key_combo, FALSE);
262 gtk_widget_set_sensitive (editor->priv->line_color_combo, FALSE);
263 gtk_widget_set_sensitive (editor->priv->line_key_combo, TRUE);
267 /* Emit our "changed" signal */
268 g_signal_emit (G_OBJECT (editor), gl_object_editor_signals[CHANGED], 0);
270 gl_debug (DEBUG_EDITOR, "END");