2 * object-editor-line-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 "color-combo.h"
32 #include "field-button.h"
33 #include "builder-util.h"
35 #include "object-editor-private.h"
40 /*===========================================*/
42 /*===========================================*/
45 /*===========================================*/
46 /* Private data types */
47 /*===========================================*/
50 /*===========================================*/
52 /*===========================================*/
55 /*===========================================*/
56 /* Local function prototypes */
57 /*===========================================*/
58 static void line_radio_toggled_cb (glObjectEditor *editor);
61 /*--------------------------------------------------------------------------*/
62 /* PRIVATE. Prepare line page. */
63 /*--------------------------------------------------------------------------*/
65 gl_object_editor_prepare_line_page (glObjectEditor *editor)
67 gl_debug (DEBUG_EDITOR, "START");
69 /* Extract widgets from XML tree. */
70 gl_builder_util_get_widgets (editor->priv->builder,
71 "line_page_vbox", &editor->priv->line_page_vbox,
72 "line_width_spin", &editor->priv->line_width_spin,
73 "line_color_hbox", &editor->priv->line_color_hbox,
74 "line_key_hbox", &editor->priv->line_key_hbox,
75 "line_key_radio", &editor->priv->line_key_radio,
76 "line_color_radio", &editor->priv->line_color_radio,
79 editor->priv->line_color_combo = gl_color_combo_new (_("No Line"),
81 gl_prefs_model_get_default_line_color (gl_prefs));
82 gtk_box_pack_start (GTK_BOX (editor->priv->line_color_hbox),
83 editor->priv->line_color_combo,
86 editor->priv->line_key_combo = gl_field_button_new (NULL);
87 gtk_box_pack_start (GTK_BOX (editor->priv->line_key_hbox),
88 editor->priv->line_key_combo,
91 /* Modify widgets based on configuration */
92 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (editor->priv->line_color_radio), TRUE);
93 gtk_widget_set_sensitive (editor->priv->line_color_combo, TRUE);
94 gtk_widget_set_sensitive (editor->priv->line_key_combo, FALSE);
95 gtk_spin_button_set_value (GTK_SPIN_BUTTON (editor->priv->line_width_spin),
96 gl_prefs_model_get_default_line_width (gl_prefs));
97 gl_color_combo_set_color (GL_COLOR_COMBO(editor->priv->line_color_combo),
98 gl_prefs_model_get_default_line_color (gl_prefs));
101 gtk_widget_show_all (editor->priv->line_page_vbox);
103 /* Connect signals */
104 g_signal_connect_swapped (G_OBJECT (editor->priv->line_width_spin),
106 G_CALLBACK (gl_object_editor_changed_cb),
108 g_signal_connect_swapped (G_OBJECT (editor->priv->line_color_combo),
110 G_CALLBACK (gl_object_editor_changed_cb),
112 g_signal_connect_swapped (G_OBJECT (editor->priv->line_key_combo),
114 G_CALLBACK (gl_object_editor_changed_cb),
116 g_signal_connect_swapped (G_OBJECT (editor->priv->line_color_radio),
118 G_CALLBACK (line_radio_toggled_cb),
120 g_signal_connect_swapped (G_OBJECT (editor->priv->line_key_radio),
122 G_CALLBACK (line_radio_toggled_cb),
125 gl_debug (DEBUG_EDITOR, "END");
129 /*****************************************************************************/
130 /* Set line width. */
131 /*****************************************************************************/
133 gl_object_editor_set_line_width (glObjectEditor *editor,
136 gl_debug (DEBUG_EDITOR, "START");
139 g_signal_handlers_block_by_func (G_OBJECT (editor->priv->line_width_spin),
140 gl_object_editor_changed_cb, editor);
143 /* Set widget values */
144 gtk_spin_button_set_value (GTK_SPIN_BUTTON (editor->priv->line_width_spin),
148 g_signal_handlers_unblock_by_func (G_OBJECT (editor->priv->line_width_spin),
149 gl_object_editor_changed_cb, editor);
152 gl_debug (DEBUG_EDITOR, "END");
156 /*****************************************************************************/
157 /* Query line width. */
158 /*****************************************************************************/
160 gl_object_editor_get_line_width (glObjectEditor *editor)
164 gl_debug (DEBUG_EDITOR, "START");
166 w = gtk_spin_button_get_value (GTK_SPIN_BUTTON(editor->priv->line_width_spin));
168 gl_debug (DEBUG_EDITOR, "END");
174 /*****************************************************************************/
175 /* Set line color. */
176 /*****************************************************************************/
178 gl_object_editor_set_line_color (glObjectEditor *editor,
180 glColorNode *color_node)
182 gl_debug (DEBUG_EDITOR, "START");
184 if (color_node == NULL)
190 g_signal_handlers_block_by_func (G_OBJECT (editor->priv->line_color_combo),
191 gl_object_editor_changed_cb, editor);
192 g_signal_handlers_block_by_func (G_OBJECT (editor->priv->line_color_radio),
193 line_radio_toggled_cb, editor);
194 g_signal_handlers_block_by_func (G_OBJECT (editor->priv->line_key_radio),
195 line_radio_toggled_cb, editor);
196 g_signal_handlers_block_by_func (G_OBJECT (editor->priv->line_key_combo),
197 gl_object_editor_changed_cb, editor);
200 gl_debug (DEBUG_EDITOR, "color field %s(%d) / %X", color_node->key, color_node->field_flag, color_node->color);
201 gtk_widget_set_sensitive (editor->priv->line_key_radio, merge_flag);
203 if ( color_node->color == GL_COLOR_NONE ) {
205 gl_color_combo_set_to_default (GL_COLOR_COMBO(editor->priv->line_color_combo));
209 gl_color_combo_set_color (GL_COLOR_COMBO(editor->priv->line_color_combo),
214 if (!color_node->field_flag || !merge_flag) {
215 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON
216 (editor->priv->line_color_radio), TRUE);
217 gtk_widget_set_sensitive (editor->priv->line_color_combo, TRUE);
218 gtk_widget_set_sensitive (editor->priv->line_key_combo, FALSE);
221 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON
222 (editor->priv->line_key_radio), TRUE);
223 gtk_widget_set_sensitive (editor->priv->line_color_combo, FALSE);
224 gtk_widget_set_sensitive (editor->priv->line_key_combo, TRUE);
226 gl_field_button_set_key (GL_FIELD_BUTTON (editor->priv->line_key_combo),
231 g_signal_handlers_unblock_by_func (G_OBJECT (editor->priv->line_color_combo),
232 gl_object_editor_changed_cb, editor);
233 g_signal_handlers_unblock_by_func (G_OBJECT (editor->priv->line_color_radio),
234 line_radio_toggled_cb, editor);
235 g_signal_handlers_unblock_by_func (G_OBJECT (editor->priv->line_key_radio),
236 line_radio_toggled_cb, editor);
237 g_signal_handlers_unblock_by_func (G_OBJECT (editor->priv->line_key_combo),
238 gl_object_editor_changed_cb, editor);
241 gl_debug (DEBUG_EDITOR, "END");
245 /*****************************************************************************/
246 /* Query line color. */
247 /*****************************************************************************/
249 gl_object_editor_get_line_color (glObjectEditor *editor)
253 glColorNode *color_node;
255 gl_debug (DEBUG_EDITOR, "START");
257 color_node = gl_color_node_new_default ();
259 if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (editor->priv->line_key_radio))) {
260 color_node->field_flag = TRUE;
262 gl_field_button_get_key (GL_FIELD_BUTTON (editor->priv->line_key_combo));
264 color_node->field_flag = FALSE;
265 color_node->key = NULL;
266 color = gl_color_combo_get_color (GL_COLOR_COMBO(editor->priv->line_color_combo),
270 color_node->color = color;
274 gl_debug (DEBUG_EDITOR, "END");
280 /*--------------------------------------------------------------------------*/
281 /* PRIVATE. line color radio callback. */
282 /*--------------------------------------------------------------------------*/
284 line_radio_toggled_cb (glObjectEditor *editor)
286 gl_debug (DEBUG_EDITOR, "START");
288 if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (editor->priv->line_color_radio))) {
289 gtk_widget_set_sensitive (editor->priv->line_color_combo, TRUE);
290 gtk_widget_set_sensitive (editor->priv->line_key_combo, FALSE);
292 gtk_widget_set_sensitive (editor->priv->line_color_combo, FALSE);
293 gtk_widget_set_sensitive (editor->priv->line_key_combo, TRUE);
297 gl_object_editor_changed_cb (editor);
299 gl_debug (DEBUG_EDITOR, "END");
305 * Local Variables: -- emacs
307 * c-basic-offset: 8 -- emacs
308 * tab-width: 8 -- emacs
309 * indent-tabs-mode: nil -- emacs