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/gtktogglebutton.h>
30 #include <gtk/gtkcombobox.h>
34 #include "color-combo.h"
38 #include "object-editor-private.h"
42 /*===========================================*/
44 /*===========================================*/
46 /*===========================================*/
47 /* Private data types */
48 /*===========================================*/
50 /*===========================================*/
52 /*===========================================*/
54 /*===========================================*/
55 /* Local function prototypes */
56 /*===========================================*/
58 static void fill_radio_toggled_cb (glObjectEditor *editor);
61 /*--------------------------------------------------------------------------*/
62 /* PRIVATE. Prepare fill page. */
63 /*--------------------------------------------------------------------------*/
65 gl_object_editor_prepare_fill_page (glObjectEditor *editor)
67 gl_debug (DEBUG_EDITOR, "START");
69 /* Extract widgets from XML tree. */
70 gl_util_get_builder_widgets (editor->priv->gui,
71 "fill_page_vbox", &editor->priv->fill_page_vbox,
72 "fill_color_hbox", &editor->priv->fill_color_hbox,
73 "fill_key_combo", &editor->priv->fill_key_combo,
74 "fill_key_radio", &editor->priv->fill_key_radio,
75 "fill_color_radio", &editor->priv->fill_color_radio,
78 editor->priv->fill_color_combo = gl_color_combo_new (NULL,
81 gl_prefs->default_fill_color);
82 gtk_container_add (GTK_CONTAINER (editor->priv->fill_color_hbox),
83 editor->priv->fill_color_combo);
85 gl_util_combo_box_add_text_model ( GTK_COMBO_BOX(editor->priv->fill_key_combo));
87 /* Modify widgets based on configuration */
88 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (editor->priv->fill_color_radio), TRUE);
89 gtk_widget_set_sensitive (editor->priv->fill_color_combo, TRUE);
90 gtk_widget_set_sensitive (editor->priv->fill_key_combo, FALSE);
91 gl_color_combo_set_color (GL_COLOR_COMBO(editor->priv->fill_color_combo),
92 gl_prefs->default_fill_color);
95 gtk_widget_show_all (editor->priv->fill_page_vbox);
98 g_signal_connect_swapped (G_OBJECT (editor->priv->fill_color_combo),
100 G_CALLBACK (gl_object_editor_changed_cb),
102 g_signal_connect_swapped (G_OBJECT (editor->priv->fill_key_combo),
104 G_CALLBACK (gl_object_editor_changed_cb),
106 g_signal_connect_swapped (G_OBJECT (editor->priv->fill_color_radio),
108 G_CALLBACK (fill_radio_toggled_cb),
110 g_signal_connect_swapped (G_OBJECT (editor->priv->fill_key_radio),
112 G_CALLBACK (fill_radio_toggled_cb),
114 gl_debug (DEBUG_EDITOR, "END");
117 /*****************************************************************************/
118 /* Set fill color. */
119 /*****************************************************************************/
121 gl_object_editor_set_fill_color (glObjectEditor *editor,
123 glColorNode *color_node)
125 gl_debug (DEBUG_EDITOR, "START");
127 editor->priv->stop_signals = TRUE;
129 gtk_widget_set_sensitive (editor->priv->fill_key_radio, merge_flag);
131 if ( color_node->color == GL_COLOR_NONE ) {
133 gl_color_combo_set_to_default (GL_COLOR_COMBO(editor->priv->fill_color_combo));
137 gl_color_combo_set_color (GL_COLOR_COMBO(editor->priv->fill_color_combo),
142 if (!color_node->field_flag) {
143 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON
144 (editor->priv->fill_color_radio), TRUE);
145 gtk_widget_set_sensitive (editor->priv->fill_color_combo, TRUE);
146 gtk_widget_set_sensitive (editor->priv->fill_key_combo, FALSE);
149 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON
150 (editor->priv->fill_key_radio), TRUE);
151 gtk_widget_set_sensitive (editor->priv->fill_color_combo, FALSE);
152 gtk_widget_set_sensitive (editor->priv->fill_key_combo, TRUE);
154 gl_util_combo_box_set_active_text (GTK_COMBO_BOX (editor->priv->fill_key_combo),
158 editor->priv->stop_signals = FALSE;
160 gl_debug (DEBUG_EDITOR, "END");
163 /*****************************************************************************/
164 /* Query fill color. */
165 /*****************************************************************************/
167 gl_object_editor_get_fill_color (glObjectEditor *editor)
171 glColorNode *color_node;
173 gl_debug (DEBUG_EDITOR, "START");
175 color_node = gl_color_node_new_default ();
177 if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (editor->priv->fill_key_radio))) {
178 color_node->field_flag = TRUE;
180 gtk_combo_box_get_active_text (GTK_COMBO_BOX (editor->priv->fill_key_combo));
182 color_node->field_flag = FALSE;
183 color_node->key = NULL;
184 color = gl_color_combo_get_color (GL_COLOR_COMBO(editor->priv->fill_color_combo),
188 color_node->color = color;
192 gl_debug (DEBUG_EDITOR, "END");
197 /*--------------------------------------------------------------------------*/
198 /* PRIVATE. fill radio callback. */
199 /*--------------------------------------------------------------------------*/
201 fill_radio_toggled_cb (glObjectEditor *editor)
203 if (editor->priv->stop_signals) return;
205 gl_debug (DEBUG_EDITOR, "START");
207 if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (editor->priv->fill_color_radio))) {
208 gtk_widget_set_sensitive (editor->priv->fill_color_combo, TRUE);
209 gtk_widget_set_sensitive (editor->priv->fill_key_combo, FALSE);
211 gtk_widget_set_sensitive (editor->priv->fill_color_combo, FALSE);
212 gtk_widget_set_sensitive (editor->priv->fill_key_combo, TRUE);
216 /* Emit our "changed" signal */
217 g_signal_emit (G_OBJECT (editor), gl_object_editor_signals[CHANGED], 0);
219 gl_debug (DEBUG_EDITOR, "END");