2 * (GLABELS) Label and Business Card Creation program for GNOME
4 * wdgt_fill.c: fill properties widget module
6 * Copyright (C) 2001-2002 Jim Evins <evins@snaught.com>.
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.
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.
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
25 #include "wdgt-fill.h"
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 )
35 /*===========================================*/
37 /*===========================================*/
44 typedef void (*glWdgtFillSignal) (GObject * object, gpointer data);
46 /*===========================================*/
48 /*===========================================*/
50 static GtkContainerClass *parent_class;
52 static gint wdgt_fill_signals[LAST_SIGNAL] = { 0 };
54 /*===========================================*/
55 /* Local function prototypes */
56 /*===========================================*/
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);
64 /*================================================================*/
65 /* Boilerplate Object stuff. */
66 /*================================================================*/
68 gl_wdgt_fill_get_type (void)
70 static guint wdgt_fill_type = 0;
72 if (!wdgt_fill_type) {
73 GTypeInfo wdgt_fill_info = {
74 sizeof (glWdgtFillClass),
77 (GClassInitFunc) gl_wdgt_fill_class_init,
82 (GInstanceInitFunc) gl_wdgt_fill_instance_init,
86 g_type_register_static (gtk_vbox_get_type (),
91 return wdgt_fill_type;
95 gl_wdgt_fill_class_init (glWdgtFillClass * class)
97 GObjectClass *object_class;
99 object_class = (GObjectClass *) class;
101 parent_class = gtk_type_class (gtk_vbox_get_type ());
103 object_class->finalize = gl_wdgt_fill_finalize;
105 wdgt_fill_signals[CHANGED] =
106 g_signal_new ("changed",
107 G_OBJECT_CLASS_TYPE(object_class),
109 G_STRUCT_OFFSET (glWdgtFillClass, changed),
111 gl_marshal_VOID__VOID,
117 gl_wdgt_fill_instance_init (glWdgtFill * fill)
119 fill->color_picker = NULL;
123 gl_wdgt_fill_finalize (GObject * object)
126 glWdgtFillClass *class;
128 g_return_if_fail (object != NULL);
129 g_return_if_fail (GL_IS_WDGT_FILL (object));
131 fill = GL_WDGT_FILL (object);
133 G_OBJECT_CLASS (parent_class)->finalize (object);
137 gl_wdgt_fill_new (gchar * label)
141 fill = g_object_new (gl_wdgt_fill_get_type (), NULL);
143 gl_wdgt_fill_construct (fill, label);
145 return GTK_WIDGET (fill);
148 /*============================================================*/
149 /* Construct composite widget. */
150 /*============================================================*/
152 gl_wdgt_fill_construct (glWdgtFill * fill,
155 GtkWidget *wvbox, *wframe, *wtable, *wlabel;
157 wvbox = GTK_WIDGET (fill);
159 wframe = gtk_frame_new (label);
160 gtk_box_pack_start (GTK_BOX (wvbox), wframe, FALSE, FALSE, 0);
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);
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);
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),
179 gtk_table_attach_defaults (GTK_TABLE (wtable), fill->color_picker, 1, 3,
184 /*--------------------------------------------------------------------------*/
185 /* PRIVATE. Callback for when any control in the widget has changed. */
186 /*--------------------------------------------------------------------------*/
188 changed_cb (glWdgtFill * fill)
190 /* Emit our "changed" signal */
191 g_signal_emit (G_OBJECT (fill), wdgt_fill_signals[CHANGED], 0);
194 /*====================================================================*/
195 /* query values from controls. */
196 /*====================================================================*/
198 gl_wdgt_fill_get_params (glWdgtFill * fill,
203 gnome_color_picker_get_i8 (GNOME_COLOR_PICKER (fill->color_picker),
205 *color = GNOME_CANVAS_COLOR_A (r, g, b, a);
208 /*====================================================================*/
209 /* fill in values and ranges for controls. */
210 /*====================================================================*/
212 gl_wdgt_fill_set_params (glWdgtFill * fill,
215 gnome_color_picker_set_i8 (GNOME_COLOR_PICKER (fill->color_picker),
216 RED (color), GREEN (color), BLUE (color),