]> git.sur5r.net Git - glabels/blob - glabels1/src/prop_fill.c
f9f5151cc73f4b2b83a7408a30928468f46e8f22
[glabels] / glabels1 / src / prop_fill.c
1 /*
2  *  (GLABELS) Label and Business Card Creation program for GNOME
3  *
4  *  prop_fill.c:  fill 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_fill.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 (*glPropFillSignal) (GtkObject * object, gpointer data);
44
45 /*===========================================*/
46 /* Private globals                           */
47 /*===========================================*/
48
49 static GtkContainerClass *parent_class;
50
51 static gint prop_fill_signals[LAST_SIGNAL] = { 0 };
52
53 /*===========================================*/
54 /* Local function prototypes                 */
55 /*===========================================*/
56
57 static void gl_prop_fill_class_init (glPropFillClass * class);
58 static void gl_prop_fill_init (glPropFill * fill);
59 static void gl_prop_fill_destroy (GtkObject * object);
60 static void gl_prop_fill_construct (glPropFill * fill, gchar * label);
61 static void changed_cb (glPropFill * fill);
62 \f
63 /*================================================================*/
64 /* Boilerplate Object stuff.                                      */
65 /*================================================================*/
66 guint
67 gl_prop_fill_get_type (void)
68 {
69         static guint prop_fill_type = 0;
70
71         if (!prop_fill_type) {
72                 GtkTypeInfo prop_fill_info = {
73                         "glPropFill",
74                         sizeof (glPropFill),
75                         sizeof (glPropFillClass),
76                         (GtkClassInitFunc) gl_prop_fill_class_init,
77                         (GtkObjectInitFunc) gl_prop_fill_init,
78                         (GtkArgSetFunc) NULL,
79                         (GtkArgGetFunc) NULL,
80                 };
81
82                 prop_fill_type =
83                     gtk_type_unique (gtk_vbox_get_type (), &prop_fill_info);
84         }
85
86         return prop_fill_type;
87 }
88
89 static void
90 gl_prop_fill_class_init (glPropFillClass * 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_fill_destroy;
101
102         prop_fill_signals[CHANGED] =
103             gtk_signal_new ("changed", GTK_RUN_LAST, object_class->type,
104                             GTK_SIGNAL_OFFSET (glPropFillClass, changed),
105                             gtk_signal_default_marshaller, GTK_TYPE_NONE, 0);
106         gtk_object_class_add_signals (object_class, prop_fill_signals,
107                                       LAST_SIGNAL);
108
109         class->changed = NULL;
110 }
111
112 static void
113 gl_prop_fill_init (glPropFill * fill)
114 {
115         fill->color_picker = NULL;
116 }
117
118 static void
119 gl_prop_fill_destroy (GtkObject * object)
120 {
121         glPropFill *fill;
122         glPropFillClass *class;
123
124         g_return_if_fail (object != NULL);
125         g_return_if_fail (GL_IS_PROP_FILL (object));
126
127         fill = GL_PROP_FILL (object);
128         class = GL_PROP_FILL_CLASS (GTK_OBJECT (fill)->klass);
129
130         GTK_OBJECT_CLASS (parent_class)->destroy (object);
131 }
132
133 GtkWidget *
134 gl_prop_fill_new (gchar * label)
135 {
136         glPropFill *fill;
137
138         fill = gtk_type_new (gl_prop_fill_get_type ());
139
140         gl_prop_fill_construct (fill, label);
141
142         return GTK_WIDGET (fill);
143 }
144 \f
145 /*============================================================*/
146 /* Construct composite widget.                                */
147 /*============================================================*/
148 static void
149 gl_prop_fill_construct (glPropFill * fill,
150                         gchar * label)
151 {
152         GtkWidget *wvbox, *wframe, *wtable, *wlabel;
153
154         wvbox = GTK_WIDGET (fill);
155
156         wframe = gtk_frame_new (label);
157         gtk_box_pack_start (GTK_BOX (wvbox), wframe, FALSE, FALSE, 0);
158
159         wtable = gtk_table_new (1, 3, TRUE);
160         gtk_container_set_border_width (GTK_CONTAINER (wtable), 10);
161         gtk_table_set_row_spacings (GTK_TABLE (wtable), 5);
162         gtk_table_set_col_spacings (GTK_TABLE (wtable), 5);
163         gtk_container_add (GTK_CONTAINER (wframe), wtable);
164
165         /* Fill Color Label */
166         wlabel = gtk_label_new (_("Color:"));
167         gtk_misc_set_alignment (GTK_MISC (wlabel), 0, 0.5);
168         gtk_label_set_justify (GTK_LABEL (wlabel), GTK_JUSTIFY_RIGHT);
169         gtk_table_attach_defaults (GTK_TABLE (wtable), wlabel, 0, 1, 0, 1);
170
171         /* Fill Color picker widget */
172         fill->color_picker = gnome_color_picker_new ();
173         gtk_signal_connect_object (GTK_OBJECT (fill->color_picker), "color_set",
174                                    GTK_SIGNAL_FUNC (changed_cb),
175                                    GTK_OBJECT (fill));
176         gtk_table_attach_defaults (GTK_TABLE (wtable), fill->color_picker, 1, 3,
177                                    0, 1);
178
179 }
180
181 /*--------------------------------------------------------------------------*/
182 /* PRIVATE.  Callback for when any control in the widget has changed.       */
183 /*--------------------------------------------------------------------------*/
184 static void
185 changed_cb (glPropFill * fill)
186 {
187         /* Emit our "changed" signal */
188         gtk_signal_emit (GTK_OBJECT (fill), prop_fill_signals[CHANGED]);
189 }
190 \f
191 /*====================================================================*/
192 /* query values from controls.                                        */
193 /*====================================================================*/
194 void
195 gl_prop_fill_get_params (glPropFill * fill,
196                          guint * color)
197 {
198         guint8 r, g, b, a;
199
200         gnome_color_picker_get_i8 (GNOME_COLOR_PICKER (fill->color_picker),
201                                    &r, &g, &b, &a);
202         *color = GNOME_CANVAS_COLOR_A (r, g, b, a);
203 }
204
205 /*====================================================================*/
206 /* fill in values and ranges for controls.                            */
207 /*====================================================================*/
208 void
209 gl_prop_fill_set_params (glPropFill * fill,
210                          guint color)
211 {
212         gnome_color_picker_set_i8 (GNOME_COLOR_PICKER (fill->color_picker),
213                                    RED (color), GREEN (color), BLUE (color),
214                                    ALPHA (color));
215 }