]> git.sur5r.net Git - glabels/blob - glabels2/src/wdgt-fill.c
Initial revision
[glabels] / glabels2 / src / wdgt-fill.c
1 /*
2  *  (GLABELS) Label and Business Card Creation program for GNOME
3  *
4  *  wdgt_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 "wdgt-fill.h"
26 #include "marshal.h"
27
28 #include "debug.h"
29
30 #define RED(x)   ( ((x)>>24) & 0xff )
31 #define GREEN(x) ( ((x)>>16) & 0xff )
32 #define BLUE(x)  ( ((x)>>8)  & 0xff )
33 #define ALPHA(x) (  (x)      & 0xff )
34
35 /*===========================================*/
36 /* Private types                             */
37 /*===========================================*/
38
39 enum {
40         CHANGED,
41         LAST_SIGNAL
42 };
43
44 typedef void (*glWdgtFillSignal) (GObject * object, gpointer data);
45
46 /*===========================================*/
47 /* Private globals                           */
48 /*===========================================*/
49
50 static GtkContainerClass *parent_class;
51
52 static gint wdgt_fill_signals[LAST_SIGNAL] = { 0 };
53
54 /*===========================================*/
55 /* Local function prototypes                 */
56 /*===========================================*/
57
58 static void gl_wdgt_fill_class_init (glWdgtFillClass * class);
59 static void gl_wdgt_fill_instance_init (glWdgtFill * fill);
60 static void gl_wdgt_fill_finalize (GObject * object);
61 static void gl_wdgt_fill_construct (glWdgtFill * fill, gchar * label);
62 static void changed_cb (glWdgtFill * fill);
63 \f
64 /*================================================================*/
65 /* Boilerplate Object stuff.                                      */
66 /*================================================================*/
67 guint
68 gl_wdgt_fill_get_type (void)
69 {
70         static guint wdgt_fill_type = 0;
71
72         if (!wdgt_fill_type) {
73                 GTypeInfo wdgt_fill_info = {
74                         sizeof (glWdgtFillClass),
75                         NULL,
76                         NULL,
77                         (GClassInitFunc) gl_wdgt_fill_class_init,
78                         NULL,
79                         NULL,
80                         sizeof (glWdgtFill),
81                         0,
82                         (GInstanceInitFunc) gl_wdgt_fill_instance_init,
83                 };
84
85                 wdgt_fill_type =
86                     g_type_register_static (gtk_vbox_get_type (),
87                                             "glWdgtFill",
88                                             &wdgt_fill_info, 0);
89         }
90
91         return wdgt_fill_type;
92 }
93
94 static void
95 gl_wdgt_fill_class_init (glWdgtFillClass * class)
96 {
97         GObjectClass *object_class;
98
99         object_class = (GObjectClass *) class;
100
101         parent_class = gtk_type_class (gtk_vbox_get_type ());
102
103         object_class->finalize = gl_wdgt_fill_finalize;
104
105         wdgt_fill_signals[CHANGED] =
106             g_signal_new ("changed",
107                           G_OBJECT_CLASS_TYPE(object_class),
108                           G_SIGNAL_RUN_LAST,
109                           G_STRUCT_OFFSET (glWdgtFillClass, changed),
110                           NULL, NULL,
111                           gl_marshal_VOID__VOID,
112                           G_TYPE_NONE, 0);
113
114 }
115
116 static void
117 gl_wdgt_fill_instance_init (glWdgtFill * fill)
118 {
119         fill->color_picker = NULL;
120 }
121
122 static void
123 gl_wdgt_fill_finalize (GObject * object)
124 {
125         glWdgtFill *fill;
126         glWdgtFillClass *class;
127
128         g_return_if_fail (object != NULL);
129         g_return_if_fail (GL_IS_WDGT_FILL (object));
130
131         fill = GL_WDGT_FILL (object);
132
133         G_OBJECT_CLASS (parent_class)->finalize (object);
134 }
135
136 GtkWidget *
137 gl_wdgt_fill_new (gchar * label)
138 {
139         glWdgtFill *fill;
140
141         fill = g_object_new (gl_wdgt_fill_get_type (), NULL);
142
143         gl_wdgt_fill_construct (fill, label);
144
145         return GTK_WIDGET (fill);
146 }
147 \f
148 /*============================================================*/
149 /* Construct composite widget.                                */
150 /*============================================================*/
151 static void
152 gl_wdgt_fill_construct (glWdgtFill * fill,
153                         gchar * label)
154 {
155         GtkWidget *wvbox, *wframe, *wtable, *wlabel;
156
157         wvbox = GTK_WIDGET (fill);
158
159         wframe = gtk_frame_new (label);
160         gtk_box_pack_start (GTK_BOX (wvbox), wframe, FALSE, FALSE, 0);
161
162         wtable = gtk_table_new (1, 3, TRUE);
163         gtk_container_set_border_width (GTK_CONTAINER (wtable), 10);
164         gtk_table_set_row_spacings (GTK_TABLE (wtable), 5);
165         gtk_table_set_col_spacings (GTK_TABLE (wtable), 5);
166         gtk_container_add (GTK_CONTAINER (wframe), wtable);
167
168         /* Fill Color Label */
169         wlabel = gtk_label_new (_("Color:"));
170         gtk_misc_set_alignment (GTK_MISC (wlabel), 0, 0.5);
171         gtk_label_set_justify (GTK_LABEL (wlabel), GTK_JUSTIFY_RIGHT);
172         gtk_table_attach_defaults (GTK_TABLE (wtable), wlabel, 0, 1, 0, 1);
173
174         /* Fill Color picker widget */
175         fill->color_picker = gnome_color_picker_new ();
176         g_signal_connect_swapped (G_OBJECT (fill->color_picker), "color_set",
177                                   G_CALLBACK (changed_cb),
178                                   G_OBJECT (fill));
179         gtk_table_attach_defaults (GTK_TABLE (wtable), fill->color_picker, 1, 3,
180                                    0, 1);
181
182 }
183
184 /*--------------------------------------------------------------------------*/
185 /* PRIVATE.  Callback for when any control in the widget has changed.       */
186 /*--------------------------------------------------------------------------*/
187 static void
188 changed_cb (glWdgtFill * fill)
189 {
190         /* Emit our "changed" signal */
191         g_signal_emit (G_OBJECT (fill), wdgt_fill_signals[CHANGED], 0);
192 }
193 \f
194 /*====================================================================*/
195 /* query values from controls.                                        */
196 /*====================================================================*/
197 void
198 gl_wdgt_fill_get_params (glWdgtFill * fill,
199                          guint * color)
200 {
201         guint8 r, g, b, a;
202
203         gnome_color_picker_get_i8 (GNOME_COLOR_PICKER (fill->color_picker),
204                                    &r, &g, &b, &a);
205         *color = GNOME_CANVAS_COLOR_A (r, g, b, a);
206 }
207
208 /*====================================================================*/
209 /* fill in values and ranges for controls.                            */
210 /*====================================================================*/
211 void
212 gl_wdgt_fill_set_params (glWdgtFill * fill,
213                          guint color)
214 {
215         gnome_color_picker_set_i8 (GNOME_COLOR_PICKER (fill->color_picker),
216                                    RED (color), GREEN (color), BLUE (color),
217                                    ALPHA (color));
218 }