]> git.sur5r.net Git - glabels/blob - src/object-editor-line-page.c
Imported Upstream version 2.2.8
[glabels] / src / object-editor-line-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/gtklabel.h>
30 #include <gtk/gtkspinbutton.h>
31 #include <gtk/gtkcombobox.h>
32 #include <gtk/gtktogglebutton.h>
33 #include <math.h>
34
35 #include "prefs.h"
36 #include "mygal/widget-color-combo.h"
37 #include "color.h"
38 #include "util.h"
39
40 #include "object-editor-private.h"
41
42 #include "debug.h"
43
44 /*===========================================*/
45 /* Private macros                            */
46 /*===========================================*/
47
48 /*===========================================*/
49 /* Private data types                        */
50 /*===========================================*/
51
52 /*===========================================*/
53 /* Private globals                           */
54 /*===========================================*/
55
56 /*===========================================*/
57 /* Local function prototypes                 */
58 /*===========================================*/
59 static void line_radio_toggled_cb               (glObjectEditor        *editor);
60
61 \f
62 /*--------------------------------------------------------------------------*/
63 /* PRIVATE.  Prepare line page.                                             */
64 /*--------------------------------------------------------------------------*/
65 void
66 gl_object_editor_prepare_line_page (glObjectEditor *editor)
67 {
68         GdkColor     *gdk_color;
69
70         gl_debug (DEBUG_EDITOR, "START");
71
72         /* Extract widgets from XML tree. */
73         editor->priv->line_page_vbox   = glade_xml_get_widget (editor->priv->gui,
74                                                                "line_page_vbox");
75         editor->priv->line_width_spin  = glade_xml_get_widget (editor->priv->gui,
76                                                                "line_width_spin");
77         editor->priv->line_color_combo = glade_xml_get_widget (editor->priv->gui,
78                                                                "line_color_combo");
79         editor->priv->line_key_combo = glade_xml_get_widget (editor->priv->gui,
80                                                                 "line_key_combo");      
81         editor->priv->line_key_radio = glade_xml_get_widget (editor->priv->gui,
82                                                                 "line_key_radio");      
83         editor->priv->line_color_radio = glade_xml_get_widget (editor->priv->gui,
84                                                                 "line_color_radio");    
85
86         gl_util_combo_box_add_text_model ( GTK_COMBO_BOX(editor->priv->line_key_combo));
87
88         /* Modify widgets based on configuration */
89         gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (editor->priv->line_color_radio), TRUE);
90         gtk_widget_set_sensitive (editor->priv->line_color_combo, TRUE);
91     gtk_widget_set_sensitive (editor->priv->line_key_combo, FALSE);     
92         gtk_spin_button_set_value (GTK_SPIN_BUTTON (editor->priv->line_width_spin),
93                                    gl_prefs->default_line_width);
94         gdk_color = gl_color_to_gdk_color (gl_prefs->default_line_color);
95         color_combo_set_color (COLOR_COMBO(editor->priv->line_color_combo), gdk_color);
96         g_free (gdk_color);
97
98         /* Un-hide */
99         gtk_widget_show_all (editor->priv->line_page_vbox);
100
101         /* Connect signals */
102         g_signal_connect_swapped (G_OBJECT (editor->priv->line_width_spin),
103                                   "changed",
104                                   G_CALLBACK (gl_object_editor_changed_cb),
105                                   G_OBJECT (editor));
106         g_signal_connect_swapped (G_OBJECT (editor->priv->line_color_combo),
107                                   "color_changed",
108                                   G_CALLBACK (gl_object_editor_changed_cb),
109                                   G_OBJECT (editor));
110         g_signal_connect_swapped (G_OBJECT (editor->priv->line_key_combo),
111                                   "changed",
112                                   G_CALLBACK (gl_object_editor_changed_cb),
113                                   G_OBJECT (editor));
114         g_signal_connect_swapped (G_OBJECT (editor->priv->line_color_radio),
115                                   "toggled",
116                                   G_CALLBACK (line_radio_toggled_cb),
117                                   G_OBJECT (editor));                             
118         g_signal_connect_swapped (G_OBJECT (editor->priv->line_key_radio),
119                                   "toggled",
120                                   G_CALLBACK (line_radio_toggled_cb),
121                                   G_OBJECT (editor));
122
123         gl_debug (DEBUG_EDITOR, "END");
124 }
125
126 /*****************************************************************************/
127 /* Set line width.                                                           */
128 /*****************************************************************************/
129 void
130 gl_object_editor_set_line_width (glObjectEditor      *editor,
131                                  gdouble              width)
132 {
133         gl_debug (DEBUG_EDITOR, "START");
134
135         editor->priv->stop_signals = TRUE;
136
137         /* Set widget values */
138         gtk_spin_button_set_value (GTK_SPIN_BUTTON (editor->priv->line_width_spin),
139                                    width);
140
141         editor->priv->stop_signals = FALSE;
142
143         gl_debug (DEBUG_EDITOR, "END");
144 }
145
146 /*****************************************************************************/
147 /* Query line width.                                                         */
148 /*****************************************************************************/
149 gdouble
150 gl_object_editor_get_line_width (glObjectEditor      *editor)
151 {
152         gdouble w;
153  
154         gl_debug (DEBUG_EDITOR, "START");
155
156         w = gtk_spin_button_get_value (GTK_SPIN_BUTTON(editor->priv->line_width_spin));
157
158         gl_debug (DEBUG_EDITOR, "END");
159
160         return w;
161 }
162
163 /*****************************************************************************/
164 /* Set line color.                                                           */
165 /*****************************************************************************/
166 void
167 gl_object_editor_set_line_color (glObjectEditor      *editor,
168                                  gboolean             merge_flag,
169                                  glColorNode         *color_node)
170 {
171         GdkColor *gdk_color;
172
173         gl_debug (DEBUG_EDITOR, "START");
174
175         editor->priv->stop_signals = TRUE;
176
177         gl_debug (DEBUG_EDITOR, "color field %s(%d) / %X", color_node->key, color_node->field_flag, color_node->color);
178         gtk_widget_set_sensitive (editor->priv->line_key_radio, merge_flag);
179
180         if ( color_node->color == GL_COLOR_NONE ) {
181
182                 color_combo_set_color_to_default (COLOR_COMBO(editor->priv->line_color_combo));
183
184         } else {
185
186                 gdk_color = gl_color_to_gdk_color (color_node->color);
187                 color_combo_set_color (COLOR_COMBO(editor->priv->line_color_combo),
188                                            gdk_color);
189                 g_free (gdk_color);
190
191         }       
192         
193         if (!color_node->field_flag || !merge_flag) {
194                 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON
195                                                   (editor->priv->line_color_radio), TRUE); 
196                 gtk_widget_set_sensitive (editor->priv->line_color_combo, TRUE);
197                 gtk_widget_set_sensitive (editor->priv->line_key_combo, FALSE);
198                 
199         } else {
200                 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON
201                                                   (editor->priv->line_key_radio), TRUE); 
202                 gtk_widget_set_sensitive (editor->priv->line_color_combo, FALSE);
203                 gtk_widget_set_sensitive (editor->priv->line_key_combo, TRUE);
204                 
205                 gl_util_combo_box_set_active_text (GTK_COMBO_BOX (editor->priv->line_key_combo),
206                                                    color_node->key);
207         }
208
209         editor->priv->stop_signals = FALSE;
210
211         gl_debug (DEBUG_EDITOR, "END");
212 }
213
214 /*****************************************************************************/
215 /* Query line color.                                                         */
216 /*****************************************************************************/
217 glColorNode*
218 gl_object_editor_get_line_color (glObjectEditor      *editor)
219 {
220         GdkColor    *gdk_color;
221         gboolean     is_default;
222         glColorNode *color_node;
223  
224         gl_debug (DEBUG_EDITOR, "START");
225
226         color_node = gl_color_node_new_default ();
227         
228         if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (editor->priv->line_key_radio))) {
229                 color_node->field_flag = TRUE;
230                 color_node->key = 
231                         gtk_combo_box_get_active_text (GTK_COMBO_BOX (editor->priv->line_key_combo));
232     } else {
233                 color_node->field_flag = FALSE;
234                 color_node->key = NULL;
235                 gdk_color = color_combo_get_color (COLOR_COMBO(editor->priv->line_color_combo),
236                                            &is_default);
237
238                 if (!is_default) {
239                 color_node->color = gl_color_from_gdk_color (gdk_color);
240         }
241         }
242         
243         gl_debug (DEBUG_EDITOR, "END");
244
245         return color_node;
246 }
247
248 /*--------------------------------------------------------------------------*/
249 /* PRIVATE.  line color radio callback.                                     */
250 /*--------------------------------------------------------------------------*/
251 static void
252 line_radio_toggled_cb (glObjectEditor *editor)
253 {
254         if (editor->priv->stop_signals) return;
255
256         gl_debug (DEBUG_EDITOR, "START");
257         
258         if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (editor->priv->line_color_radio))) {
259                 gtk_widget_set_sensitive (editor->priv->line_color_combo, TRUE);
260                 gtk_widget_set_sensitive (editor->priv->line_key_combo, FALSE);
261         } else {
262                 gtk_widget_set_sensitive (editor->priv->line_color_combo, FALSE);
263                 gtk_widget_set_sensitive (editor->priv->line_key_combo, TRUE);
264                 
265         }
266  
267         /* Emit our "changed" signal */
268         g_signal_emit (G_OBJECT (editor), gl_object_editor_signals[CHANGED], 0);
269  
270         gl_debug (DEBUG_EDITOR, "END");
271 }