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 "mygal/widget-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)
69 gl_debug (DEBUG_EDITOR, "START");
71 /* Extract widgets from XML tree. */
72 editor->priv->fill_page_vbox = glade_xml_get_widget (editor->priv->gui,
74 editor->priv->fill_color_combo = glade_xml_get_widget (editor->priv->gui,
76 editor->priv->fill_key_combo = glade_xml_get_widget (editor->priv->gui,
78 editor->priv->fill_key_radio = glade_xml_get_widget (editor->priv->gui,
80 editor->priv->fill_color_radio = glade_xml_get_widget (editor->priv->gui,
84 gl_util_combo_box_add_text_model ( GTK_COMBO_BOX(editor->priv->fill_key_combo));
86 /* Modify widgets based on configuration */
87 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (editor->priv->fill_color_radio), TRUE);
88 gtk_widget_set_sensitive (editor->priv->fill_color_combo, TRUE);
89 gtk_widget_set_sensitive (editor->priv->fill_key_combo, FALSE);
90 gdk_color = gl_color_to_gdk_color (gl_prefs->default_fill_color);
91 color_combo_set_color (COLOR_COMBO(editor->priv->fill_color_combo), gdk_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)
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 color_combo_set_color_to_default (COLOR_COMBO(editor->priv->fill_color_combo));
139 gdk_color = gl_color_to_gdk_color (color_node->color);
140 color_combo_set_color (COLOR_COMBO(editor->priv->fill_color_combo),
146 if (!color_node->field_flag) {
147 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON
148 (editor->priv->fill_color_radio), TRUE);
149 gtk_widget_set_sensitive (editor->priv->fill_color_combo, TRUE);
150 gtk_widget_set_sensitive (editor->priv->fill_key_combo, FALSE);
153 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON
154 (editor->priv->fill_key_radio), TRUE);
155 gtk_widget_set_sensitive (editor->priv->fill_color_combo, FALSE);
156 gtk_widget_set_sensitive (editor->priv->fill_key_combo, TRUE);
158 gl_util_combo_box_set_active_text (GTK_COMBO_BOX (editor->priv->fill_key_combo),
162 editor->priv->stop_signals = FALSE;
164 gl_debug (DEBUG_EDITOR, "END");
167 /*****************************************************************************/
168 /* Query fill color. */
169 /*****************************************************************************/
171 gl_object_editor_get_fill_color (glObjectEditor *editor)
175 glColorNode *color_node;
177 gl_debug (DEBUG_EDITOR, "START");
179 color_node = gl_color_node_new_default ();
181 if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (editor->priv->fill_key_radio))) {
182 color_node->field_flag = TRUE;
184 gtk_combo_box_get_active_text (GTK_COMBO_BOX (editor->priv->fill_key_combo));
186 color_node->field_flag = FALSE;
187 color_node->key = NULL;
188 gdk_color = color_combo_get_color (COLOR_COMBO(editor->priv->fill_color_combo),
192 color_node->color = gl_color_from_gdk_color (gdk_color);
196 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");