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");
138 editor->priv->stop_signals = TRUE;
140 /* Set widget values */
141 gtk_spin_button_set_value (GTK_SPIN_BUTTON (editor->priv->line_width_spin),
144 editor->priv->stop_signals = FALSE;
146 gl_debug (DEBUG_EDITOR, "END");
150 /*****************************************************************************/
151 /* Query line width. */
152 /*****************************************************************************/
154 gl_object_editor_get_line_width (glObjectEditor *editor)
158 gl_debug (DEBUG_EDITOR, "START");
160 w = gtk_spin_button_get_value (GTK_SPIN_BUTTON(editor->priv->line_width_spin));
162 gl_debug (DEBUG_EDITOR, "END");
168 /*****************************************************************************/
169 /* Set line color. */
170 /*****************************************************************************/
172 gl_object_editor_set_line_color (glObjectEditor *editor,
174 glColorNode *color_node)
176 gl_debug (DEBUG_EDITOR, "START");
178 if (color_node == NULL)
183 editor->priv->stop_signals = TRUE;
185 gl_debug (DEBUG_EDITOR, "color field %s(%d) / %X", color_node->key, color_node->field_flag, color_node->color);
186 gtk_widget_set_sensitive (editor->priv->line_key_radio, merge_flag);
188 if ( color_node->color == GL_COLOR_NONE ) {
190 gl_color_combo_set_to_default (GL_COLOR_COMBO(editor->priv->line_color_combo));
194 gl_color_combo_set_color (GL_COLOR_COMBO(editor->priv->line_color_combo),
199 if (!color_node->field_flag || !merge_flag) {
200 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON
201 (editor->priv->line_color_radio), TRUE);
202 gtk_widget_set_sensitive (editor->priv->line_color_combo, TRUE);
203 gtk_widget_set_sensitive (editor->priv->line_key_combo, FALSE);
206 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON
207 (editor->priv->line_key_radio), TRUE);
208 gtk_widget_set_sensitive (editor->priv->line_color_combo, FALSE);
209 gtk_widget_set_sensitive (editor->priv->line_key_combo, TRUE);
211 gl_field_button_set_key (GL_FIELD_BUTTON (editor->priv->line_key_combo),
215 editor->priv->stop_signals = FALSE;
217 gl_debug (DEBUG_EDITOR, "END");
221 /*****************************************************************************/
222 /* Query line color. */
223 /*****************************************************************************/
225 gl_object_editor_get_line_color (glObjectEditor *editor)
229 glColorNode *color_node;
231 gl_debug (DEBUG_EDITOR, "START");
233 color_node = gl_color_node_new_default ();
235 if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (editor->priv->line_key_radio))) {
236 color_node->field_flag = TRUE;
238 gl_field_button_get_key (GL_FIELD_BUTTON (editor->priv->line_key_combo));
240 color_node->field_flag = FALSE;
241 color_node->key = NULL;
242 color = gl_color_combo_get_color (GL_COLOR_COMBO(editor->priv->line_color_combo),
246 color_node->color = color;
250 gl_debug (DEBUG_EDITOR, "END");
256 /*--------------------------------------------------------------------------*/
257 /* PRIVATE. line color radio callback. */
258 /*--------------------------------------------------------------------------*/
260 line_radio_toggled_cb (glObjectEditor *editor)
262 if (editor->priv->stop_signals) return;
264 gl_debug (DEBUG_EDITOR, "START");
266 if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (editor->priv->line_color_radio))) {
267 gtk_widget_set_sensitive (editor->priv->line_color_combo, TRUE);
268 gtk_widget_set_sensitive (editor->priv->line_key_combo, FALSE);
270 gtk_widget_set_sensitive (editor->priv->line_color_combo, FALSE);
271 gtk_widget_set_sensitive (editor->priv->line_key_combo, TRUE);
275 gl_object_editor_changed_cb (editor);
277 gl_debug (DEBUG_EDITOR, "END");
283 * Local Variables: -- emacs
285 * c-basic-offset: 8 -- emacs
286 * tab-width: 8 -- emacs
287 * indent-tabs-mode: nil -- emacs