]> git.sur5r.net Git - glabels/blob - glabels2/src/object-editor-fill-page.c
2005-04-19 Jim Evins <evins@snaught.com>
[glabels] / glabels2 / src / object-editor-fill-page.c
1 /*
2  *  (GLABELS) Label and Business Card Creation program for GNOME
3  *
4  *  object-editor.c:  object properties editor module
5  *
6  *  Copyright (C) 2003  Jim Evins <evins@snaught.com>.
7  *
8  *  This program is free software; you can redistribute it and/or modify
9  *  it under the terms of the GNU General Public License as published by
10  *  the Free Software Foundation; either version 2 of the License, or
11  *  (at your option) any later version.
12  *
13  *  This program is distributed in the hope that it will be useful,
14  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
15  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  *  GNU General Public License for more details.
17  *
18  *  You should have received a copy of the GNU General Public License
19  *  along with this program; if not, write to the Free Software
20  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
21  */
22 #include <config.h>
23
24 #include "object-editor.h"
25
26 #include <glib/gi18n.h>
27 #include <gtk/gtktogglebutton.h>
28 #include <gtk/gtkcombobox.h>
29 #include <math.h>
30
31 #include "prefs.h"
32 #include "mygal/widget-color-combo.h"
33 #include "color.h"
34
35 #include "object-editor-private.h"
36
37 #include "debug.h"
38
39 /*===========================================*/
40 /* Private macros                            */
41 /*===========================================*/
42
43 /*===========================================*/
44 /* Private data types                        */
45 /*===========================================*/
46
47 /*===========================================*/
48 /* Private globals                           */
49 /*===========================================*/
50
51 /*===========================================*/
52 /* Local function prototypes                 */
53 /*===========================================*/
54
55 static void fill_radio_toggled_cb                (glObjectEditor        *editor);
56
57 \f
58 /*--------------------------------------------------------------------------*/
59 /* PRIVATE.  Prepare fill page.                                             */
60 /*--------------------------------------------------------------------------*/
61 void
62 gl_object_editor_prepare_fill_page (glObjectEditor *editor)
63 {
64         GdkColor *gdk_color;
65
66         gl_debug (DEBUG_EDITOR, "START");
67
68         /* Extract widgets from XML tree. */
69         editor->priv->fill_page_vbox   = glade_xml_get_widget (editor->priv->gui,
70                                                                "fill_page_vbox");
71         editor->priv->fill_color_combo = glade_xml_get_widget (editor->priv->gui,
72                                                                "fill_color_combo");
73         editor->priv->fill_key_combo = glade_xml_get_widget (editor->priv->gui,
74                                                                 "fill_key_combo");      
75         editor->priv->fill_key_radio = glade_xml_get_widget (editor->priv->gui,
76                                                                 "fill_key_radio");      
77         editor->priv->fill_color_radio = glade_xml_get_widget (editor->priv->gui,
78                                                                 "fill_color_radio");    
79
80         
81         gl_util_combo_box_add_text_model ( GTK_COMBO_BOX(editor->priv->fill_key_combo));
82
83         /* Modify widgets based on configuration */
84         gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (editor->priv->fill_color_radio), TRUE);
85         gtk_widget_set_sensitive (editor->priv->fill_color_combo, TRUE);
86     gtk_widget_set_sensitive (editor->priv->fill_key_combo, FALSE);
87         gdk_color = gl_color_to_gdk_color (gl_prefs->default_fill_color);
88         color_combo_set_color (COLOR_COMBO(editor->priv->fill_color_combo), gdk_color);
89         g_free (gdk_color);
90
91         /* Un-hide */
92         gtk_widget_show_all (editor->priv->fill_page_vbox);
93
94         /* Connect signals */
95         g_signal_connect_swapped (G_OBJECT (editor->priv->fill_color_combo),
96                                   "color_changed",
97                                   G_CALLBACK (gl_object_editor_changed_cb),
98                                   G_OBJECT (editor));
99         g_signal_connect_swapped (G_OBJECT (editor->priv->fill_key_combo),
100                                   "changed",
101                                   G_CALLBACK (gl_object_editor_changed_cb),
102                                   G_OBJECT (editor));
103         g_signal_connect_swapped (G_OBJECT (editor->priv->fill_color_radio),
104                                   "toggled",
105                                   G_CALLBACK (fill_radio_toggled_cb),
106                                   G_OBJECT (editor));                             
107         g_signal_connect_swapped (G_OBJECT (editor->priv->fill_key_radio),
108                                   "toggled",
109                                   G_CALLBACK (fill_radio_toggled_cb),
110                                   G_OBJECT (editor));                             
111         gl_debug (DEBUG_EDITOR, "END");
112 }
113
114 /*****************************************************************************/
115 /* Set fill color.                                                           */
116 /*****************************************************************************/
117 void
118 gl_object_editor_set_fill_color (glObjectEditor      *editor,
119                                  gboolean             merge_flag,
120                                  glColorNode         *color_node)
121 {
122         GdkColor *gdk_color;
123
124         gl_debug (DEBUG_EDITOR, "START");
125
126         g_signal_handlers_block_by_func (G_OBJECT(editor->priv->fill_color_combo),
127                                          G_CALLBACK (gl_object_editor_changed_cb),
128                                          editor);
129         g_signal_handlers_block_by_func (G_OBJECT(editor->priv->fill_key_combo),
130                                          G_CALLBACK (gl_object_editor_changed_cb),
131                                          editor);
132
133         gtk_widget_set_sensitive (editor->priv->fill_key_radio, merge_flag);
134
135         if ( color_node->color == GL_COLOR_NONE ) {
136
137                 color_combo_set_color_to_default (COLOR_COMBO(editor->priv->fill_color_combo));
138
139         } else {
140
141                 gdk_color = gl_color_to_gdk_color (color_node->color);
142                 color_combo_set_color (COLOR_COMBO(editor->priv->fill_color_combo),
143                                            gdk_color);
144                 g_free (gdk_color);
145
146         }
147         
148         if (!color_node->field_flag) {
149                 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON
150                                                   (editor->priv->fill_color_radio), TRUE); 
151                 gtk_widget_set_sensitive (editor->priv->fill_color_combo, TRUE);
152                 gtk_widget_set_sensitive (editor->priv->fill_key_combo, FALSE);
153                 
154         } else {
155                 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON
156                                                   (editor->priv->fill_key_radio), TRUE); 
157                 gtk_widget_set_sensitive (editor->priv->fill_color_combo, FALSE);
158                 gtk_widget_set_sensitive (editor->priv->fill_key_combo, TRUE);
159                 
160                 gl_util_combo_box_set_active_text (GTK_COMBO_BOX (editor->priv->fill_key_combo),
161                                                    color_node->key);
162         }
163         
164         g_signal_handlers_unblock_by_func (G_OBJECT(editor->priv->fill_color_combo),
165                                            G_CALLBACK (gl_object_editor_changed_cb),
166                                            editor);
167         g_signal_handlers_unblock_by_func (G_OBJECT(editor->priv->fill_key_combo),
168                                            G_CALLBACK (gl_object_editor_changed_cb),
169                                            editor);
170
171         gl_debug (DEBUG_EDITOR, "END");
172 }
173
174 /*****************************************************************************/
175 /* Query fill color.                                                         */
176 /*****************************************************************************/
177 glColorNode*
178 gl_object_editor_get_fill_color (glObjectEditor      *editor)
179 {
180         GdkColor    *gdk_color;
181         gboolean     is_default;
182         glColorNode *color_node;
183  
184         gl_debug (DEBUG_EDITOR, "START");
185
186         color_node = gl_color_node_new_default ();
187         
188         if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (editor->priv->fill_key_radio))) {
189                 color_node->field_flag = TRUE;
190                 color_node->key = 
191                         gtk_combo_box_get_active_text (GTK_COMBO_BOX (editor->priv->fill_key_combo));
192     } else {
193                 color_node->field_flag = FALSE;
194                 color_node->key = NULL;
195                 gdk_color = color_combo_get_color (COLOR_COMBO(editor->priv->fill_color_combo),
196                                            &is_default);
197
198                 if (!is_default) {
199                 color_node->color = gl_color_from_gdk_color (gdk_color);
200         }
201         }
202
203         gl_debug (DEBUG_EDITOR, "END");
204
205         return color_node;
206 }
207
208 /*--------------------------------------------------------------------------*/
209 /* PRIVATE.  fill radio callback.                                           */
210 /*--------------------------------------------------------------------------*/
211 static void
212 fill_radio_toggled_cb (glObjectEditor *editor)
213 {
214     gl_debug (DEBUG_EDITOR, "START");
215         
216         if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (editor->priv->fill_color_radio))) {
217                 gtk_widget_set_sensitive (editor->priv->fill_color_combo, TRUE);
218                 gtk_widget_set_sensitive (editor->priv->fill_key_combo, FALSE);
219     } else {
220                 gtk_widget_set_sensitive (editor->priv->fill_color_combo, FALSE);
221                 gtk_widget_set_sensitive (editor->priv->fill_key_combo, TRUE);
222                 
223         }
224  
225         /* Emit our "changed" signal */
226         g_signal_emit (G_OBJECT (editor), gl_object_editor_signals[CHANGED], 0);
227  
228         gl_debug (DEBUG_EDITOR, "END");
229 }