2 * (GLABELS) Label and Business Card Creation program for GNOME
4 * wdgt_line.c: line 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-line.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 (*glWdgtLineSignal) (GObject * object, gpointer data);
46 /*===========================================*/
48 /*===========================================*/
50 static GObjectClass *parent_class;
52 static gint wdgt_line_signals[LAST_SIGNAL] = { 0 };
54 /*===========================================*/
55 /* Local function prototypes */
56 /*===========================================*/
58 static void gl_wdgt_line_class_init (glWdgtLineClass * class);
59 static void gl_wdgt_line_instance_init (glWdgtLine * line);
60 static void gl_wdgt_line_finalize (GObject * object);
61 static void gl_wdgt_line_construct (glWdgtLine * line, gchar * label);
62 static void changed_cb (glWdgtLine * line);
64 /*================================================================*/
65 /* Boilerplate Object stuff. */
66 /*================================================================*/
68 gl_wdgt_line_get_type (void)
70 static guint wdgt_line_type = 0;
72 if (!wdgt_line_type) {
73 GTypeInfo wdgt_line_info = {
74 sizeof (glWdgtLineClass),
77 (GClassInitFunc) gl_wdgt_line_class_init,
82 (GInstanceInitFunc) gl_wdgt_line_instance_init,
86 g_type_register_static (gtk_vbox_get_type (),
91 return wdgt_line_type;
95 gl_wdgt_line_class_init (glWdgtLineClass * 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_line_finalize;
105 wdgt_line_signals[CHANGED] =
106 g_signal_new ("changed",
107 G_OBJECT_CLASS_TYPE(object_class),
109 G_STRUCT_OFFSET (glWdgtLineClass, changed),
111 gl_marshal_VOID__VOID,
117 gl_wdgt_line_instance_init (glWdgtLine * line)
119 line->width_spin = NULL;
120 line->color_picker = NULL;
121 line->units_label = NULL;
125 gl_wdgt_line_finalize (GObject * object)
128 glWdgtLineClass *class;
130 g_return_if_fail (object != NULL);
131 g_return_if_fail (GL_IS_WDGT_LINE (object));
133 line = GL_WDGT_LINE (object);
135 G_OBJECT_CLASS (parent_class)->finalize (object);
139 gl_wdgt_line_new (gchar * label)
143 line = g_object_new (gl_wdgt_line_get_type (), NULL);
145 gl_wdgt_line_construct (line, label);
147 return GTK_WIDGET (line);
150 /*============================================================*/
151 /* Construct composite widget. */
152 /*============================================================*/
154 gl_wdgt_line_construct (glWdgtLine * line,
157 GtkWidget *wvbox, *wframe, *wtable, *wlabel;
160 wvbox = GTK_WIDGET (line);
162 wframe = gtk_frame_new (label);
163 gtk_box_pack_start (GTK_BOX (wvbox), wframe, FALSE, FALSE, 0);
165 wtable = gtk_table_new (2, 3, TRUE);
166 gtk_container_set_border_width (GTK_CONTAINER (wtable), 10);
167 gtk_table_set_row_spacings (GTK_TABLE (wtable), 5);
168 gtk_table_set_col_spacings (GTK_TABLE (wtable), 5);
169 gtk_container_add (GTK_CONTAINER (wframe), wtable);
171 /* Line Width Label */
172 wlabel = gtk_label_new (_("Width:"));
173 gtk_misc_set_alignment (GTK_MISC (wlabel), 0, 0.5);
174 gtk_label_set_justify (GTK_LABEL (wlabel), GTK_JUSTIFY_RIGHT);
175 gtk_table_attach_defaults (GTK_TABLE (wtable), wlabel, 0, 1, 0, 1);
176 /* Line Width widget */
177 adjust = gtk_adjustment_new (1.0, 0.25, 4.0, 0.25, 1.0, 1.0);
179 gtk_spin_button_new (GTK_ADJUSTMENT (adjust), 0.25, 2);
180 g_signal_connect_swapped (G_OBJECT (line->width_spin), "changed",
181 G_CALLBACK (changed_cb),
183 gtk_table_attach_defaults (GTK_TABLE (wtable), line->width_spin, 1, 2,
185 /* Line Width units */
186 line->units_label = gtk_label_new (_("points"));
187 gtk_misc_set_alignment (GTK_MISC (line->units_label), 0, 0.5);
188 gtk_table_attach_defaults (GTK_TABLE (wtable), line->units_label,
191 /* Line Color Label */
192 wlabel = gtk_label_new (_("Color:"));
193 gtk_misc_set_alignment (GTK_MISC (wlabel), 0, 0.5);
194 gtk_table_attach_defaults (GTK_TABLE (wtable), wlabel, 0, 1, 1, 2);
195 /* Line Color picker widget */
196 line->color_picker = gnome_color_picker_new ();
197 g_signal_connect_swapped (G_OBJECT (line->color_picker), "color_set",
198 G_CALLBACK (changed_cb),
200 gtk_table_attach_defaults (GTK_TABLE (wtable), line->color_picker, 1, 3,
205 /*--------------------------------------------------------------------------*/
206 /* PRIVATE. Callback for when any control in the widget has changed. */
207 /*--------------------------------------------------------------------------*/
209 changed_cb (glWdgtLine * line)
211 /* Emit our "changed" signal */
212 g_signal_emit (G_OBJECT (line), wdgt_line_signals[CHANGED], 0);
215 /*====================================================================*/
216 /* query values from controls. */
217 /*====================================================================*/
219 gl_wdgt_line_get_params (glWdgtLine * line,
226 gtk_spin_button_get_value_as_int (GTK_SPIN_BUTTON
229 gnome_color_picker_get_i8 (GNOME_COLOR_PICKER (line->color_picker),
231 *color = GNOME_CANVAS_COLOR_A (r, g, b, a);
234 /*====================================================================*/
235 /* fill in values and ranges for controls. */
236 /*====================================================================*/
238 gl_wdgt_line_set_params (glWdgtLine * line,
242 gtk_spin_button_set_value (GTK_SPIN_BUTTON (line->width_spin), width);
244 gnome_color_picker_set_i8 (GNOME_COLOR_PICKER (line->color_picker),
245 RED (color), GREEN (color), BLUE (color),