]> git.sur5r.net Git - glabels/blob - glabels2/src/object-editor-fill-page.c
b1143d2c4fe97c3a351d3c099aa528ea572712e9
[glabels] / glabels2 / src / object-editor-fill-page.c
1 /*
2  *  object-editor-fill-page.c
3  *  Copyright (C) 2003-2009  Jim Evins <evins@snaught.com>.
4  *
5  *  This file is part of gLabels.
6  *
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.
11  *
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.
16  *
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/>.
19  */
20
21 #include <config.h>
22
23 #include "object-editor.h"
24
25 #include <glib/gi18n.h>
26 #include <gtk/gtk.h>
27 #include <math.h>
28
29 #include "prefs.h"
30 #include "color-combo.h"
31 #include "color.h"
32 #include "combo-util.h"
33 #include "builder-util.h"
34
35 #include "object-editor-private.h"
36
37 #include "debug.h"
38
39
40 /*===========================================*/
41 /* Private macros                            */
42 /*===========================================*/
43
44
45 /*===========================================*/
46 /* Private data types                        */
47 /*===========================================*/
48
49
50 /*===========================================*/
51 /* Private globals                           */
52 /*===========================================*/
53
54
55 /*===========================================*/
56 /* Local function prototypes                 */
57 /*===========================================*/
58
59 static void fill_radio_toggled_cb                (glObjectEditor        *editor);
60
61
62 /*--------------------------------------------------------------------------*/
63 /* PRIVATE.  Prepare fill page.                                             */
64 /*--------------------------------------------------------------------------*/
65 void
66 gl_object_editor_prepare_fill_page (glObjectEditor *editor)
67 {
68         gl_debug (DEBUG_EDITOR, "START");
69
70         /* Extract widgets from XML tree. */
71         gl_builder_util_get_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,
77                                      NULL);
78         
79         editor->priv->fill_color_combo = gl_color_combo_new (_("No Fill"),
80                                                              GL_COLOR_NO_FILL,
81                                                              gl_prefs->default_fill_color);
82         gtk_box_pack_start (GTK_BOX (editor->priv->fill_color_hbox),
83                             editor->priv->fill_color_combo,
84                             FALSE, FALSE, 0);
85
86         gl_combo_util_add_text_model ( GTK_COMBO_BOX(editor->priv->fill_key_combo));
87
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);
94
95         /* Un-hide */
96         gtk_widget_show_all (editor->priv->fill_page_vbox);
97
98         /* Connect signals */
99         g_signal_connect_swapped (G_OBJECT (editor->priv->fill_color_combo),
100                                   "color_changed",
101                                   G_CALLBACK (gl_object_editor_changed_cb),
102                                   G_OBJECT (editor));
103         g_signal_connect_swapped (G_OBJECT (editor->priv->fill_key_combo),
104                                   "changed",
105                                   G_CALLBACK (gl_object_editor_changed_cb),
106                                   G_OBJECT (editor));
107         g_signal_connect_swapped (G_OBJECT (editor->priv->fill_color_radio),
108                                   "toggled",
109                                   G_CALLBACK (fill_radio_toggled_cb),
110                                   G_OBJECT (editor));                             
111         g_signal_connect_swapped (G_OBJECT (editor->priv->fill_key_radio),
112                                   "toggled",
113                                   G_CALLBACK (fill_radio_toggled_cb),
114                                   G_OBJECT (editor));                             
115         gl_debug (DEBUG_EDITOR, "END");
116 }
117
118
119 /*****************************************************************************/
120 /* Set fill color.                                                           */
121 /*****************************************************************************/
122 void
123 gl_object_editor_set_fill_color (glObjectEditor      *editor,
124                                  gboolean             merge_flag,
125                                  glColorNode         *color_node)
126 {
127         gl_debug (DEBUG_EDITOR, "START");
128
129         editor->priv->stop_signals = TRUE;
130
131         gtk_widget_set_sensitive (editor->priv->fill_key_radio, merge_flag);
132
133         if ( color_node->color == GL_COLOR_NONE ) {
134
135                 gl_color_combo_set_to_default (GL_COLOR_COMBO(editor->priv->fill_color_combo));
136
137         } else {
138
139                 gl_color_combo_set_color (GL_COLOR_COMBO(editor->priv->fill_color_combo),
140                                            color_node->color);
141
142         }
143         
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);
149                 
150         } else {
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);
155                 
156                 gl_combo_util_set_active_text (GTK_COMBO_BOX (editor->priv->fill_key_combo),
157                                                color_node->key);
158         }
159         
160         editor->priv->stop_signals = FALSE;
161
162         gl_debug (DEBUG_EDITOR, "END");
163 }
164
165
166 /*****************************************************************************/
167 /* Query fill color.                                                         */
168 /*****************************************************************************/
169 glColorNode*
170 gl_object_editor_get_fill_color (glObjectEditor      *editor)
171 {
172         guint        color;
173         gboolean     is_default;
174         glColorNode *color_node;
175  
176         gl_debug (DEBUG_EDITOR, "START");
177
178         color_node = gl_color_node_new_default ();
179         
180         if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (editor->priv->fill_key_radio))) {
181                 color_node->field_flag = TRUE;
182                 color_node->key = 
183                         gtk_combo_box_get_active_text (GTK_COMBO_BOX (editor->priv->fill_key_combo));
184         } else {
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),
188                                                   &is_default);
189
190                 if (!is_default) {
191                         color_node->color = color;
192                 }
193         }
194
195         gl_debug (DEBUG_EDITOR, "END");
196
197         return color_node;
198 }
199
200
201 /*--------------------------------------------------------------------------*/
202 /* PRIVATE.  fill radio callback.                                           */
203 /*--------------------------------------------------------------------------*/
204 static void
205 fill_radio_toggled_cb (glObjectEditor *editor)
206 {
207         if (editor->priv->stop_signals) return;
208
209         gl_debug (DEBUG_EDITOR, "START");
210         
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);
214     } else {
215                 gtk_widget_set_sensitive (editor->priv->fill_color_combo, FALSE);
216                 gtk_widget_set_sensitive (editor->priv->fill_key_combo, TRUE);
217                 
218         }
219  
220         /* Emit our "changed" signal */
221         g_signal_emit (G_OBJECT (editor), gl_object_editor_signals[CHANGED], 0);
222  
223         gl_debug (DEBUG_EDITOR, "END");
224 }
225
226
227
228 /*
229  * Local Variables:       -- emacs
230  * mode: C                -- emacs
231  * c-basic-offset: 8      -- emacs
232  * tab-width: 8           -- emacs
233  * indent-tabs-mode: nil  -- emacs
234  * End:                   -- emacs
235  */