]> git.sur5r.net Git - glabels/blob - glabels1/src/prop_bc.c
0b0e81757a41249bd5ebd5ed8b9902d00e1a5152
[glabels] / glabels1 / src / prop_bc.c
1 /*
2  *  (GLABELS) Label and Business Card Creation program for GNOME
3  *
4  *  prop_bc.c:  barcode properties widget module
5  *
6  *  Copyright (C) 2001-2002  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
23 #include <config.h>
24
25 #include "prop_bc.h"
26
27 #include "debug.h"
28
29 #define RED(x)   ( ((x)>>24) & 0xff )
30 #define GREEN(x) ( ((x)>>16) & 0xff )
31 #define BLUE(x)  ( ((x)>>8)  & 0xff )
32 #define ALPHA(x) (  (x)      & 0xff )
33
34 /*===========================================*/
35 /* Private types                             */
36 /*===========================================*/
37
38 enum {
39         CHANGED,
40         LAST_SIGNAL
41 };
42
43 typedef void (*glPropBCSignal) (GtkObject * object, gpointer data);
44
45 /*===========================================*/
46 /* Private globals                           */
47 /*===========================================*/
48
49 static GtkContainerClass *parent_class;
50
51 static gint prop_bc_signals[LAST_SIGNAL] = { 0 };
52
53 /*===========================================*/
54 /* Local function prototypes                 */
55 /*===========================================*/
56
57 static void gl_prop_bc_class_init (glPropBCClass * class);
58 static void gl_prop_bc_init (glPropBC * prop);
59 static void gl_prop_bc_destroy (GtkObject * object);
60 static void gl_prop_bc_construct (glPropBC * prop, gchar * label);
61 static void changed_cb (glPropBC * prop);
62 \f
63 /*================================================================*/
64 /* Boilerplate Object stuff.                                      */
65 /*================================================================*/
66 guint
67 gl_prop_bc_get_type (void)
68 {
69         static guint prop_bc_type = 0;
70
71         if (!prop_bc_type) {
72                 GtkTypeInfo prop_bc_info = {
73                         "glPropBC",
74                         sizeof (glPropBC),
75                         sizeof (glPropBCClass),
76                         (GtkClassInitFunc) gl_prop_bc_class_init,
77                         (GtkObjectInitFunc) gl_prop_bc_init,
78                         (GtkArgSetFunc) NULL,
79                         (GtkArgGetFunc) NULL,
80                 };
81
82                 prop_bc_type = gtk_type_unique (gtk_vbox_get_type (),
83                                                 &prop_bc_info);
84         }
85
86         return prop_bc_type;
87 }
88
89 static void
90 gl_prop_bc_class_init (glPropBCClass * class)
91 {
92         GtkObjectClass *object_class;
93         GtkWidgetClass *widget_class;
94
95         object_class = (GtkObjectClass *) class;
96         widget_class = (GtkWidgetClass *) class;
97
98         parent_class = gtk_type_class (gtk_vbox_get_type ());
99
100         object_class->destroy = gl_prop_bc_destroy;
101
102         prop_bc_signals[CHANGED] =
103             gtk_signal_new ("changed", GTK_RUN_LAST, object_class->type,
104                             GTK_SIGNAL_OFFSET (glPropBCClass, changed),
105                             gtk_signal_default_marshaller, GTK_TYPE_NONE, 0);
106         gtk_object_class_add_signals (object_class, prop_bc_signals,
107                                       LAST_SIGNAL);
108
109         class->changed = NULL;
110 }
111
112 static void
113 gl_prop_bc_init (glPropBC * prop)
114 {
115         prop->scale_spin = NULL;
116         prop->color_picker = NULL;
117 }
118
119 static void
120 gl_prop_bc_destroy (GtkObject * object)
121 {
122         glPropBC *prop;
123         glPropBCClass *class;
124
125         g_return_if_fail (object != NULL);
126         g_return_if_fail (GL_IS_PROP_BC (object));
127
128         prop = GL_PROP_BC (object);
129         class = GL_PROP_BC_CLASS (GTK_OBJECT (prop)->klass);
130
131         GTK_OBJECT_CLASS (parent_class)->destroy (object);
132 }
133
134 GtkWidget *
135 gl_prop_bc_new (gchar * label)
136 {
137         glPropBC *prop;
138
139         prop = gtk_type_new (gl_prop_bc_get_type ());
140
141         gl_prop_bc_construct (prop, label);
142
143         return GTK_WIDGET (prop);
144 }
145 \f
146 /*============================================================*/
147 /* Construct composite widget.                                */
148 /*============================================================*/
149 static void
150 gl_prop_bc_construct (glPropBC * prop,
151                       gchar * label)
152 {
153         GtkWidget *wvbox, *wframe, *wtable, *wlabel;
154         GtkObject *adjust;
155
156         wvbox = GTK_WIDGET (prop);
157
158         wframe = gtk_frame_new (label);
159         gtk_box_pack_start (GTK_BOX (wvbox), wframe, FALSE, FALSE, 0);
160
161         wtable = gtk_table_new (2, 3, TRUE);
162         gtk_container_set_border_width (GTK_CONTAINER (wtable), 10);
163         gtk_table_set_row_spacings (GTK_TABLE (wtable), 5);
164         gtk_table_set_col_spacings (GTK_TABLE (wtable), 5);
165         gtk_container_add (GTK_CONTAINER (wframe), wtable);
166
167         /* Scale Label */
168         wlabel = gtk_label_new (_("Scale:"));
169         gtk_misc_set_alignment (GTK_MISC (wlabel), 0, 0.5);
170         gtk_label_set_justify (GTK_LABEL (wlabel), GTK_JUSTIFY_RIGHT);
171         gtk_table_attach_defaults (GTK_TABLE (wtable), wlabel, 0, 1, 0, 1);
172         /* Scale widget */
173         adjust = gtk_adjustment_new (100.0, 50.0, 200.0, 10.0, 10.0, 10.0);
174         prop->scale_spin =
175             gtk_spin_button_new (GTK_ADJUSTMENT (adjust), 10.0, 0);
176         gtk_signal_connect_object (GTK_OBJECT (prop->scale_spin), "changed",
177                                    GTK_SIGNAL_FUNC (changed_cb),
178                                    GTK_OBJECT (prop));
179         gtk_table_attach_defaults (GTK_TABLE (wtable), prop->scale_spin, 1, 2,
180                                    0, 1);
181         /* % Label */
182         wlabel = gtk_label_new (_("%"));
183         gtk_misc_set_alignment (GTK_MISC (wlabel), 0, 0.5);
184         gtk_label_set_justify (GTK_LABEL (wlabel), GTK_JUSTIFY_RIGHT);
185         gtk_table_attach_defaults (GTK_TABLE (wtable), wlabel, 2, 3, 0, 1);
186
187         /* Line Color Label */
188         wlabel = gtk_label_new (_("Color:"));
189         gtk_misc_set_alignment (GTK_MISC (wlabel), 0, 0.5);
190         gtk_label_set_justify (GTK_LABEL (wlabel), GTK_JUSTIFY_RIGHT);
191         gtk_table_attach_defaults (GTK_TABLE (wtable), wlabel, 0, 1, 1, 2);
192         /* Line Color picker widget */
193         prop->color_picker = gnome_color_picker_new ();
194         gtk_signal_connect_object (GTK_OBJECT (prop->color_picker), "color_set",
195                                    GTK_SIGNAL_FUNC (changed_cb),
196                                    GTK_OBJECT (prop));
197         gtk_table_attach_defaults (GTK_TABLE (wtable), prop->color_picker, 1, 3,
198                                    1, 2);
199 }
200
201 /*--------------------------------------------------------------------------*/
202 /* PRIVATE.  Callback for when any control in the widget has changed.       */
203 /*--------------------------------------------------------------------------*/
204 static void
205 changed_cb (glPropBC * prop)
206 {
207         /* Emit our "changed" signal */
208         gtk_signal_emit (GTK_OBJECT (prop), prop_bc_signals[CHANGED]);
209 }
210 \f
211 /*====================================================================*/
212 /* query values from controls.                                        */
213 /*====================================================================*/
214 void
215 gl_prop_bc_get_params (glPropBC * prop,
216                        gdouble * scale,
217                        guint * color)
218 {
219         guint8 r, g, b, a;
220
221         /* ------- Get updated scale ------ */
222         *scale =
223             gtk_spin_button_get_value_as_float (GTK_SPIN_BUTTON
224                                                 (prop->scale_spin));
225         *scale /= 100.0;
226
227         /* ------- Get updated line color ------ */
228         gnome_color_picker_get_i8 (GNOME_COLOR_PICKER (prop->color_picker),
229                                    &r, &g, &b, &a);
230         *color = GNOME_CANVAS_COLOR_A (r, g, b, a);
231
232 }
233
234 /*====================================================================*/
235 /* fill in values and ranges for controls.                            */
236 /*====================================================================*/
237 void
238 gl_prop_bc_set_params (glPropBC * prop,
239                        gdouble scale,
240                        guint color)
241 {
242         scale *= 100.0;
243         gtk_spin_button_set_value (GTK_SPIN_BUTTON (prop->scale_spin), scale);
244
245         gnome_color_picker_set_i8 (GNOME_COLOR_PICKER (prop->color_picker),
246                                    RED (color), GREEN (color), BLUE (color),
247                                    ALPHA (color));
248
249 }