2 * (GLABELS) Label and Business Card Creation program for GNOME
4 * label_barcode.c: GLabels label text object
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
24 #include <libgnomeprint/gnome-glyphlist.h>
26 #include "label-barcode.h"
28 #include "pixmaps/checkerboard.xpm"
32 /*========================================================*/
33 /* Private macros and constants. */
34 /*========================================================*/
36 /*========================================================*/
38 /*========================================================*/
40 struct _glLabelBarcodePrivate {
41 glTextNode *text_node;
48 /*========================================================*/
49 /* Private globals. */
50 /*========================================================*/
52 static GObjectClass *parent_class = NULL;
54 static guint instance = 0;
56 /*========================================================*/
57 /* Private function prototypes. */
58 /*========================================================*/
60 static void gl_label_barcode_class_init (glLabelBarcodeClass *klass);
61 static void gl_label_barcode_instance_init (glLabelBarcode *lbc);
62 static void gl_label_barcode_finalize (GObject *object);
64 static void update_size (glLabelBarcode *lbc);
67 /*****************************************************************************/
68 /* Boilerplate object stuff. */
69 /*****************************************************************************/
71 gl_label_barcode_get_type (void)
73 static GType type = 0;
77 sizeof (glLabelBarcodeClass),
80 (GClassInitFunc) gl_label_barcode_class_init,
83 sizeof (glLabelBarcode),
85 (GInstanceInitFunc) gl_label_barcode_instance_init,
88 type = g_type_register_static (GL_TYPE_LABEL_OBJECT,
89 "glLabelBarcode", &info, 0);
96 gl_label_barcode_class_init (glLabelBarcodeClass *klass)
98 GObjectClass *object_class = (GObjectClass *) klass;
100 parent_class = g_type_class_peek_parent (klass);
102 object_class->finalize = gl_label_barcode_finalize;
106 gl_label_barcode_instance_init (glLabelBarcode *lbc)
108 lbc->private = g_new0 (glLabelBarcodePrivate, 1);
112 gl_label_barcode_finalize (GObject *object)
116 g_return_if_fail (object && GL_IS_LABEL_BARCODE (object));
118 lbc = GL_LABEL_BARCODE (object);
120 gl_text_node_free (&lbc->private->text_node);
121 g_free (lbc->private);
123 G_OBJECT_CLASS (parent_class)->finalize (object);
126 /*****************************************************************************/
127 /* NEW label "text" object. */
128 /*****************************************************************************/
130 gl_label_barcode_new (glLabel *label)
134 lbc = g_object_new (gl_label_barcode_get_type(), NULL);
136 gl_label_object_set_parent (GL_LABEL_OBJECT(lbc), label);
138 return G_OBJECT (lbc);
141 /*****************************************************************************/
142 /* Duplicate object. */
143 /*****************************************************************************/
145 gl_label_barcode_dup (glLabelBarcode *lbc,
148 glLabelBarcode *new_lbc;
149 glTextNode *text_node;
151 glBarcodeStyle style;
156 gl_debug (DEBUG_LABEL, "START");
158 g_return_if_fail (lbc && GL_IS_LABEL_BARCODE (lbc));
159 g_return_if_fail (label && GL_IS_LABEL (label));
161 new_lbc = GL_LABEL_BARCODE(gl_label_barcode_new (label));
163 gl_label_object_get_position (GL_LABEL_OBJECT(lbc), &x, &y);
164 gl_label_object_get_size (GL_LABEL_OBJECT(lbc), &w, &h);
166 gl_label_object_set_position (GL_LABEL_OBJECT(new_lbc), x, y);
167 gl_label_object_set_size (GL_LABEL_OBJECT(new_lbc), w, h);
169 text_node = gl_label_barcode_get_data (lbc);
170 gl_label_barcode_get_props (lbc, &style, &text_flag, &color, &scale);
172 gl_label_barcode_set_data (new_lbc, text_node);
173 gl_label_barcode_set_props (new_lbc,style, text_flag, color, scale);
175 gl_text_node_free (&text_node);
177 gl_debug (DEBUG_LABEL, "END");
183 /*****************************************************************************/
184 /* Set object params. */
185 /*****************************************************************************/
187 gl_label_barcode_set_data (glLabelBarcode *lbc,
188 glTextNode *text_node)
190 gl_debug (DEBUG_LABEL, "START");
192 g_return_if_fail (lbc && GL_IS_LABEL_BARCODE (lbc));
194 gl_text_node_free (&lbc->private->text_node);
195 lbc->private->text_node = gl_text_node_dup (text_node);
199 gl_label_object_emit_changed (GL_LABEL_OBJECT(lbc));
201 gl_debug (DEBUG_LABEL, "END");
205 gl_label_barcode_set_props (glLabelBarcode *lbc,
206 glBarcodeStyle style,
213 gl_debug (DEBUG_LABEL, "START");
215 g_return_if_fail (lbc && GL_IS_LABEL_BARCODE (lbc));
217 lbc->private->style = style;
218 lbc->private->text_flag = text_flag;
219 lbc->private->color = color;
220 lbc->private->scale = scale;
224 gl_label_object_emit_changed (GL_LABEL_OBJECT(lbc));
226 gl_debug (DEBUG_LABEL, "END");
230 /*****************************************************************************/
231 /* Get object params. */
232 /*****************************************************************************/
234 gl_label_barcode_get_data (glLabelBarcode *lbc)
236 g_return_val_if_fail (lbc && GL_IS_LABEL_BARCODE (lbc), NULL);
238 return gl_text_node_dup (lbc->private->text_node);
242 gl_label_barcode_get_props (glLabelBarcode *lbc,
243 glBarcodeStyle *style,
248 g_return_if_fail (lbc && GL_IS_LABEL_BARCODE (lbc));
250 *style = lbc->private->style;
251 *text_flag = lbc->private->text_flag;
252 *color = lbc->private->color;
253 *scale = lbc->private->scale;
256 /*---------------------------------------------------------------------------*/
257 /* PRIVATE. Update object size. */
258 /*---------------------------------------------------------------------------*/
260 update_size (glLabelBarcode *lbc)
265 gl_debug (DEBUG_LABEL, "START");
267 data = gl_barcode_default_digits (lbc->private->style);
268 gbc = gl_barcode_new (lbc->private->style,
269 lbc->private->text_flag,
273 gl_label_object_set_size (GL_LABEL_OBJECT(lbc),
274 gbc->width, gbc->height);
276 gl_barcode_free (&gbc);
278 gl_debug (DEBUG_LABEL, "END");