2 * (GLABELS) Label and Business Card Creation program for GNOME
4 * prop_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 "prop_line.h"
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 )
34 /*===========================================*/
36 /*===========================================*/
43 typedef void (*glPropLineSignal) (GtkObject * object, gpointer data);
45 /*===========================================*/
47 /*===========================================*/
49 static GtkContainerClass *parent_class;
51 static gint prop_line_signals[LAST_SIGNAL] = { 0 };
53 /*===========================================*/
54 /* Local function prototypes */
55 /*===========================================*/
57 static void gl_prop_line_class_init (glPropLineClass * class);
58 static void gl_prop_line_init (glPropLine * line);
59 static void gl_prop_line_destroy (GtkObject * object);
60 static void gl_prop_line_construct (glPropLine * line, gchar * label);
61 static void changed_cb (glPropLine * line);
63 /*================================================================*/
64 /* Boilerplate Object stuff. */
65 /*================================================================*/
67 gl_prop_line_get_type (void)
69 static guint prop_line_type = 0;
71 if (!prop_line_type) {
72 GtkTypeInfo prop_line_info = {
75 sizeof (glPropLineClass),
76 (GtkClassInitFunc) gl_prop_line_class_init,
77 (GtkObjectInitFunc) gl_prop_line_init,
83 gtk_type_unique (gtk_vbox_get_type (), &prop_line_info);
86 return prop_line_type;
90 gl_prop_line_class_init (glPropLineClass * class)
92 GtkObjectClass *object_class;
93 GtkWidgetClass *widget_class;
95 object_class = (GtkObjectClass *) class;
96 widget_class = (GtkWidgetClass *) class;
98 parent_class = gtk_type_class (gtk_vbox_get_type ());
100 object_class->destroy = gl_prop_line_destroy;
102 prop_line_signals[CHANGED] =
103 gtk_signal_new ("changed", GTK_RUN_LAST, object_class->type,
104 GTK_SIGNAL_OFFSET (glPropLineClass, changed),
105 gtk_signal_default_marshaller, GTK_TYPE_NONE, 0);
106 gtk_object_class_add_signals (object_class, prop_line_signals,
109 class->changed = NULL;
113 gl_prop_line_init (glPropLine * line)
115 line->width_spin = NULL;
116 line->color_picker = NULL;
117 line->units_label = NULL;
121 gl_prop_line_destroy (GtkObject * object)
124 glPropLineClass *class;
126 g_return_if_fail (object != NULL);
127 g_return_if_fail (GL_IS_PROP_LINE (object));
129 line = GL_PROP_LINE (object);
130 class = GL_PROP_LINE_CLASS (GTK_OBJECT (line)->klass);
132 GTK_OBJECT_CLASS (parent_class)->destroy (object);
136 gl_prop_line_new (gchar * label)
140 line = gtk_type_new (gl_prop_line_get_type ());
142 gl_prop_line_construct (line, label);
144 return GTK_WIDGET (line);
147 /*============================================================*/
148 /* Construct composite widget. */
149 /*============================================================*/
151 gl_prop_line_construct (glPropLine * line,
154 GtkWidget *wvbox, *wframe, *wtable, *wlabel;
157 wvbox = GTK_WIDGET (line);
159 wframe = gtk_frame_new (label);
160 gtk_box_pack_start (GTK_BOX (wvbox), wframe, FALSE, FALSE, 0);
162 wtable = gtk_table_new (2, 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 /* Line Width Label */
169 wlabel = gtk_label_new (_("Width:"));
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 /* Line Width widget */
174 adjust = gtk_adjustment_new (1.0, 0.25, 4.0, 0.25, 1.0, 1.0);
176 gtk_spin_button_new (GTK_ADJUSTMENT (adjust), 0.25, 2);
177 gtk_signal_connect_object (GTK_OBJECT (line->width_spin), "changed",
178 GTK_SIGNAL_FUNC (changed_cb),
180 gtk_table_attach_defaults (GTK_TABLE (wtable), line->width_spin, 1, 2,
182 /* Line Width units */
183 line->units_label = gtk_label_new (_("points"));
184 gtk_misc_set_alignment (GTK_MISC (line->units_label), 0, 0.5);
185 gtk_table_attach_defaults (GTK_TABLE (wtable), line->units_label,
188 /* Line Color Label */
189 wlabel = gtk_label_new (_("Color:"));
190 gtk_misc_set_alignment (GTK_MISC (wlabel), 0, 0.5);
191 gtk_table_attach_defaults (GTK_TABLE (wtable), wlabel, 0, 1, 1, 2);
192 /* Line Color picker widget */
193 line->color_picker = gnome_color_picker_new ();
194 gtk_signal_connect_object (GTK_OBJECT (line->color_picker), "color_set",
195 GTK_SIGNAL_FUNC (changed_cb),
197 gtk_table_attach_defaults (GTK_TABLE (wtable), line->color_picker, 1, 3,
202 /*--------------------------------------------------------------------------*/
203 /* PRIVATE. Callback for when any control in the widget has changed. */
204 /*--------------------------------------------------------------------------*/
206 changed_cb (glPropLine * line)
208 /* Emit our "changed" signal */
209 gtk_signal_emit (GTK_OBJECT (line), prop_line_signals[CHANGED]);
212 /*====================================================================*/
213 /* query values from controls. */
214 /*====================================================================*/
216 gl_prop_line_get_params (glPropLine * line,
223 gtk_spin_button_get_value_as_int (GTK_SPIN_BUTTON
226 gnome_color_picker_get_i8 (GNOME_COLOR_PICKER (line->color_picker),
228 *color = GNOME_CANVAS_COLOR_A (r, g, b, a);
231 /*====================================================================*/
232 /* fill in values and ranges for controls. */
233 /*====================================================================*/
235 gl_prop_line_set_params (glPropLine * line,
239 gtk_spin_button_set_value (GTK_SPIN_BUTTON (line->width_spin), width);
241 gnome_color_picker_set_i8 (GNOME_COLOR_PICKER (line->color_picker),
242 RED (color), GREEN (color), BLUE (color),