]> git.sur5r.net Git - glabels/blob - src/object-editor-fill-page.c
Imported Upstream version 2.2.8
[glabels] / 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 "mygal/widget-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         GdkColor *gdk_color;
68
69         gl_debug (DEBUG_EDITOR, "START");
70
71         /* Extract widgets from XML tree. */
72         editor->priv->fill_page_vbox   = glade_xml_get_widget (editor->priv->gui,
73                                                                "fill_page_vbox");
74         editor->priv->fill_color_combo = glade_xml_get_widget (editor->priv->gui,
75                                                                "fill_color_combo");
76         editor->priv->fill_key_combo = glade_xml_get_widget (editor->priv->gui,
77                                                                 "fill_key_combo");      
78         editor->priv->fill_key_radio = glade_xml_get_widget (editor->priv->gui,
79                                                                 "fill_key_radio");      
80         editor->priv->fill_color_radio = glade_xml_get_widget (editor->priv->gui,
81                                                                 "fill_color_radio");    
82
83         
84         gl_util_combo_box_add_text_model ( GTK_COMBO_BOX(editor->priv->fill_key_combo));
85
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);
92         g_free (gdk_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         GdkColor *gdk_color;
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                 color_combo_set_color_to_default (COLOR_COMBO(editor->priv->fill_color_combo));
136
137         } else {
138
139                 gdk_color = gl_color_to_gdk_color (color_node->color);
140                 color_combo_set_color (COLOR_COMBO(editor->priv->fill_color_combo),
141                                            gdk_color);
142                 g_free (gdk_color);
143
144         }
145         
146         if (!color_node->field_flag || !merge_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);
151                 
152         } else {
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);
157                 
158                 gl_util_combo_box_set_active_text (GTK_COMBO_BOX (editor->priv->fill_key_combo),
159                                                    color_node->key);
160         }
161         
162         editor->priv->stop_signals = FALSE;
163
164         gl_debug (DEBUG_EDITOR, "END");
165 }
166
167 /*****************************************************************************/
168 /* Query fill color.                                                         */
169 /*****************************************************************************/
170 glColorNode*
171 gl_object_editor_get_fill_color (glObjectEditor      *editor)
172 {
173         GdkColor    *gdk_color;
174         gboolean     is_default;
175         glColorNode *color_node;
176  
177         gl_debug (DEBUG_EDITOR, "START");
178
179         color_node = gl_color_node_new_default ();
180         
181         if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (editor->priv->fill_key_radio))) {
182                 color_node->field_flag = TRUE;
183                 color_node->key = 
184                         gtk_combo_box_get_active_text (GTK_COMBO_BOX (editor->priv->fill_key_combo));
185     } else {
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),
189                                            &is_default);
190
191                 if (!is_default) {
192                 color_node->color = gl_color_from_gdk_color (gdk_color);
193         }
194         }
195
196         gl_debug (DEBUG_EDITOR, "END");
197
198         return color_node;
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 }