2 * object-editor-fill-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>
26 #include <gtk/gtktogglebutton.h>
27 #include <gtk/gtkcombobox.h>
31 #include "color-combo.h"
35 #include "object-editor-private.h"
40 /*===========================================*/
42 /*===========================================*/
45 /*===========================================*/
46 /* Private data types */
47 /*===========================================*/
50 /*===========================================*/
52 /*===========================================*/
55 /*===========================================*/
56 /* Local function prototypes */
57 /*===========================================*/
59 static void fill_radio_toggled_cb (glObjectEditor *editor);
62 /*--------------------------------------------------------------------------*/
63 /* PRIVATE. Prepare fill page. */
64 /*--------------------------------------------------------------------------*/
66 gl_object_editor_prepare_fill_page (glObjectEditor *editor)
68 gl_debug (DEBUG_EDITOR, "START");
70 /* Extract widgets from XML tree. */
71 gl_util_get_builder_widgets (editor->priv->builder,
72 "fill_page_vbox", &editor->priv->fill_page_vbox,
73 "fill_color_hbox", &editor->priv->fill_color_hbox,
74 "fill_key_combo", &editor->priv->fill_key_combo,
75 "fill_key_radio", &editor->priv->fill_key_radio,
76 "fill_color_radio", &editor->priv->fill_color_radio,
79 editor->priv->fill_color_combo = gl_color_combo_new (NULL,
82 gl_prefs->default_fill_color);
83 gtk_container_add (GTK_CONTAINER (editor->priv->fill_color_hbox),
84 editor->priv->fill_color_combo);
86 gl_util_combo_box_add_text_model ( GTK_COMBO_BOX(editor->priv->fill_key_combo));
88 /* Modify widgets based on configuration */
89 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (editor->priv->fill_color_radio), TRUE);
90 gtk_widget_set_sensitive (editor->priv->fill_color_combo, TRUE);
91 gtk_widget_set_sensitive (editor->priv->fill_key_combo, FALSE);
92 gl_color_combo_set_color (GL_COLOR_COMBO(editor->priv->fill_color_combo),
93 gl_prefs->default_fill_color);
96 gtk_widget_show_all (editor->priv->fill_page_vbox);
99 g_signal_connect_swapped (G_OBJECT (editor->priv->fill_color_combo),
101 G_CALLBACK (gl_object_editor_changed_cb),
103 g_signal_connect_swapped (G_OBJECT (editor->priv->fill_key_combo),
105 G_CALLBACK (gl_object_editor_changed_cb),
107 g_signal_connect_swapped (G_OBJECT (editor->priv->fill_color_radio),
109 G_CALLBACK (fill_radio_toggled_cb),
111 g_signal_connect_swapped (G_OBJECT (editor->priv->fill_key_radio),
113 G_CALLBACK (fill_radio_toggled_cb),
115 gl_debug (DEBUG_EDITOR, "END");
119 /*****************************************************************************/
120 /* Set fill color. */
121 /*****************************************************************************/
123 gl_object_editor_set_fill_color (glObjectEditor *editor,
125 glColorNode *color_node)
127 gl_debug (DEBUG_EDITOR, "START");
129 editor->priv->stop_signals = TRUE;
131 gtk_widget_set_sensitive (editor->priv->fill_key_radio, merge_flag);
133 if ( color_node->color == GL_COLOR_NONE ) {
135 gl_color_combo_set_to_default (GL_COLOR_COMBO(editor->priv->fill_color_combo));
139 gl_color_combo_set_color (GL_COLOR_COMBO(editor->priv->fill_color_combo),
144 if (!color_node->field_flag) {
145 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON
146 (editor->priv->fill_color_radio), TRUE);
147 gtk_widget_set_sensitive (editor->priv->fill_color_combo, TRUE);
148 gtk_widget_set_sensitive (editor->priv->fill_key_combo, FALSE);
151 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON
152 (editor->priv->fill_key_radio), TRUE);
153 gtk_widget_set_sensitive (editor->priv->fill_color_combo, FALSE);
154 gtk_widget_set_sensitive (editor->priv->fill_key_combo, TRUE);
156 gl_util_combo_box_set_active_text (GTK_COMBO_BOX (editor->priv->fill_key_combo),
160 editor->priv->stop_signals = FALSE;
162 gl_debug (DEBUG_EDITOR, "END");
166 /*****************************************************************************/
167 /* Query fill color. */
168 /*****************************************************************************/
170 gl_object_editor_get_fill_color (glObjectEditor *editor)
174 glColorNode *color_node;
176 gl_debug (DEBUG_EDITOR, "START");
178 color_node = gl_color_node_new_default ();
180 if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (editor->priv->fill_key_radio))) {
181 color_node->field_flag = TRUE;
183 gtk_combo_box_get_active_text (GTK_COMBO_BOX (editor->priv->fill_key_combo));
185 color_node->field_flag = FALSE;
186 color_node->key = NULL;
187 color = gl_color_combo_get_color (GL_COLOR_COMBO(editor->priv->fill_color_combo),
191 color_node->color = color;
195 gl_debug (DEBUG_EDITOR, "END");
201 /*--------------------------------------------------------------------------*/
202 /* PRIVATE. fill radio callback. */
203 /*--------------------------------------------------------------------------*/
205 fill_radio_toggled_cb (glObjectEditor *editor)
207 if (editor->priv->stop_signals) return;
209 gl_debug (DEBUG_EDITOR, "START");
211 if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (editor->priv->fill_color_radio))) {
212 gtk_widget_set_sensitive (editor->priv->fill_color_combo, TRUE);
213 gtk_widget_set_sensitive (editor->priv->fill_key_combo, FALSE);
215 gtk_widget_set_sensitive (editor->priv->fill_color_combo, FALSE);
216 gtk_widget_set_sensitive (editor->priv->fill_key_combo, TRUE);
220 /* Emit our "changed" signal */
221 g_signal_emit (G_OBJECT (editor), gl_object_editor_signals[CHANGED], 0);
223 gl_debug (DEBUG_EDITOR, "END");
229 * Local Variables: -- emacs
231 * c-basic-offset: 8 -- emacs
232 * tab-width: 8 -- emacs
233 * indent-tabs-mode: nil -- emacs