]> git.sur5r.net Git - glabels/blob - glabels2/src/object-editor-fill-page.c
6270c9d39baa6ec947006227ea9fad15ea154d52
[glabels] / glabels2 / src / object-editor-fill-page.c
1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- */
2
3 /*
4  *  (GLABELS) Label and Business Card Creation program for GNOME
5  *
6  *  object-editor.c:  object properties editor module
7  *
8  *  Copyright (C) 2003  Jim Evins <evins@snaught.com>.
9  *
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.
14  *
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.
19  *
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
23  */
24 #include <config.h>
25
26 #include "object-editor.h"
27
28 #include <glib/gi18n.h>
29 #include <gtk/gtktogglebutton.h>
30 #include <gtk/gtkcombobox.h>
31 #include <math.h>
32
33 #include "prefs.h"
34 #include "color-combo.h"
35 #include "color.h"
36 #include "util.h"
37
38 #include "object-editor-private.h"
39
40 #include "debug.h"
41
42 /*===========================================*/
43 /* Private macros                            */
44 /*===========================================*/
45
46 /*===========================================*/
47 /* Private data types                        */
48 /*===========================================*/
49
50 /*===========================================*/
51 /* Private globals                           */
52 /*===========================================*/
53
54 /*===========================================*/
55 /* Local function prototypes                 */
56 /*===========================================*/
57
58 static void fill_radio_toggled_cb                (glObjectEditor        *editor);
59
60 \f
61 /*--------------------------------------------------------------------------*/
62 /* PRIVATE.  Prepare fill page.                                             */
63 /*--------------------------------------------------------------------------*/
64 void
65 gl_object_editor_prepare_fill_page (glObjectEditor *editor)
66 {
67         gl_debug (DEBUG_EDITOR, "START");
68
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,
76                                      NULL);
77         
78         editor->priv->fill_color_combo = gl_color_combo_new (NULL,
79                                                              _("No Fill"),
80                                                              GL_COLOR_NO_FILL,
81                                                              gl_prefs->default_fill_color);
82         gtk_container_add (GTK_CONTAINER (editor->priv->fill_color_hbox),
83                            editor->priv->fill_color_combo);
84
85         gl_util_combo_box_add_text_model ( GTK_COMBO_BOX(editor->priv->fill_key_combo));
86
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);
93
94         /* Un-hide */
95         gtk_widget_show_all (editor->priv->fill_page_vbox);
96
97         /* Connect signals */
98         g_signal_connect_swapped (G_OBJECT (editor->priv->fill_color_combo),
99                                   "color_changed",
100                                   G_CALLBACK (gl_object_editor_changed_cb),
101                                   G_OBJECT (editor));
102         g_signal_connect_swapped (G_OBJECT (editor->priv->fill_key_combo),
103                                   "changed",
104                                   G_CALLBACK (gl_object_editor_changed_cb),
105                                   G_OBJECT (editor));
106         g_signal_connect_swapped (G_OBJECT (editor->priv->fill_color_radio),
107                                   "toggled",
108                                   G_CALLBACK (fill_radio_toggled_cb),
109                                   G_OBJECT (editor));                             
110         g_signal_connect_swapped (G_OBJECT (editor->priv->fill_key_radio),
111                                   "toggled",
112                                   G_CALLBACK (fill_radio_toggled_cb),
113                                   G_OBJECT (editor));                             
114         gl_debug (DEBUG_EDITOR, "END");
115 }
116
117 /*****************************************************************************/
118 /* Set fill color.                                                           */
119 /*****************************************************************************/
120 void
121 gl_object_editor_set_fill_color (glObjectEditor      *editor,
122                                  gboolean             merge_flag,
123                                  glColorNode         *color_node)
124 {
125         gl_debug (DEBUG_EDITOR, "START");
126
127         editor->priv->stop_signals = TRUE;
128
129         gtk_widget_set_sensitive (editor->priv->fill_key_radio, merge_flag);
130
131         if ( color_node->color == GL_COLOR_NONE ) {
132
133                 gl_color_combo_set_to_default (GL_COLOR_COMBO(editor->priv->fill_color_combo));
134
135         } else {
136
137                 gl_color_combo_set_color (GL_COLOR_COMBO(editor->priv->fill_color_combo),
138                                            color_node->color);
139
140         }
141         
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);
147                 
148         } else {
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);
153                 
154                 gl_util_combo_box_set_active_text (GTK_COMBO_BOX (editor->priv->fill_key_combo),
155                                                    color_node->key);
156         }
157         
158         editor->priv->stop_signals = FALSE;
159
160         gl_debug (DEBUG_EDITOR, "END");
161 }
162
163 /*****************************************************************************/
164 /* Query fill color.                                                         */
165 /*****************************************************************************/
166 glColorNode*
167 gl_object_editor_get_fill_color (glObjectEditor      *editor)
168 {
169         guint        color;
170         gboolean     is_default;
171         glColorNode *color_node;
172  
173         gl_debug (DEBUG_EDITOR, "START");
174
175         color_node = gl_color_node_new_default ();
176         
177         if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (editor->priv->fill_key_radio))) {
178                 color_node->field_flag = TRUE;
179                 color_node->key = 
180                         gtk_combo_box_get_active_text (GTK_COMBO_BOX (editor->priv->fill_key_combo));
181         } else {
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),
185                                                   &is_default);
186
187                 if (!is_default) {
188                         color_node->color = color;
189                 }
190         }
191
192         gl_debug (DEBUG_EDITOR, "END");
193
194         return color_node;
195 }
196
197 /*--------------------------------------------------------------------------*/
198 /* PRIVATE.  fill radio callback.                                           */
199 /*--------------------------------------------------------------------------*/
200 static void
201 fill_radio_toggled_cb (glObjectEditor *editor)
202 {
203         if (editor->priv->stop_signals) return;
204
205         gl_debug (DEBUG_EDITOR, "START");
206         
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);
210     } else {
211                 gtk_widget_set_sensitive (editor->priv->fill_color_combo, FALSE);
212                 gtk_widget_set_sensitive (editor->priv->fill_key_combo, TRUE);
213                 
214         }
215  
216         /* Emit our "changed" signal */
217         g_signal_emit (G_OBJECT (editor), gl_object_editor_signals[CHANGED], 0);
218  
219         gl_debug (DEBUG_EDITOR, "END");
220 }