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;
45 gboolean checksum_flag;
48 /*========================================================*/
49 /* Private globals. */
50 /*========================================================*/
52 static glLabelObjectClass *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 copy (glLabelObject *dst_object,
65 glLabelObject *src_object);
67 static void get_size (glLabelObject *object,
71 static void set_line_color (glLabelObject *object,
74 static guint get_line_color (glLabelObject *object);
78 /*****************************************************************************/
79 /* Boilerplate object stuff. */
80 /*****************************************************************************/
82 gl_label_barcode_get_type (void)
84 static GType type = 0;
88 sizeof (glLabelBarcodeClass),
91 (GClassInitFunc) gl_label_barcode_class_init,
94 sizeof (glLabelBarcode),
96 (GInstanceInitFunc) gl_label_barcode_instance_init,
99 type = g_type_register_static (GL_TYPE_LABEL_OBJECT,
100 "glLabelBarcode", &info, 0);
107 gl_label_barcode_class_init (glLabelBarcodeClass *klass)
109 GObjectClass *object_class = (GObjectClass *) klass;
110 glLabelObjectClass *label_object_class = (glLabelObjectClass *) klass;
112 parent_class = g_type_class_peek_parent (klass);
114 label_object_class->copy = copy;
115 label_object_class->get_size = get_size;
116 label_object_class->set_line_color = set_line_color;
117 label_object_class->get_line_color = get_line_color;
119 object_class->finalize = gl_label_barcode_finalize;
123 gl_label_barcode_instance_init (glLabelBarcode *lbc)
125 lbc->private = g_new0 (glLabelBarcodePrivate, 1);
129 gl_label_barcode_finalize (GObject *object)
133 g_return_if_fail (object && GL_IS_LABEL_BARCODE (object));
135 lbc = GL_LABEL_BARCODE (object);
137 gl_text_node_free (&lbc->private->text_node);
138 g_free (lbc->private);
140 G_OBJECT_CLASS (parent_class)->finalize (object);
143 /*****************************************************************************/
144 /* NEW label "text" object. */
145 /*****************************************************************************/
147 gl_label_barcode_new (glLabel *label)
151 lbc = g_object_new (gl_label_barcode_get_type(), NULL);
153 gl_label_object_set_parent (GL_LABEL_OBJECT(lbc), label);
155 return G_OBJECT (lbc);
158 /*****************************************************************************/
159 /* Copy object contents. */
160 /*****************************************************************************/
162 copy (glLabelObject *dst_object,
163 glLabelObject *src_object)
165 glLabelBarcode *lbc = (glLabelBarcode *)src_object;
166 glLabelBarcode *new_lbc = (glLabelBarcode *)dst_object;
167 glTextNode *text_node;
170 gboolean checksum_flag;
173 gl_debug (DEBUG_LABEL, "START");
175 g_return_if_fail (lbc && GL_IS_LABEL_BARCODE (lbc));
176 g_return_if_fail (new_lbc && GL_IS_LABEL_BARCODE (new_lbc));
178 text_node = gl_label_barcode_get_data (lbc);
179 gl_label_barcode_get_props (lbc, &id, &text_flag, &checksum_flag);
180 color = get_line_color (src_object);
182 gl_label_barcode_set_data (new_lbc, text_node);
183 gl_label_barcode_set_props (new_lbc, id, text_flag, checksum_flag);
184 set_line_color (dst_object, color);
186 gl_text_node_free (&text_node);
189 gl_debug (DEBUG_LABEL, "END");
193 /*****************************************************************************/
194 /* Set object params. */
195 /*****************************************************************************/
197 gl_label_barcode_set_data (glLabelBarcode *lbc,
198 glTextNode *text_node)
200 gl_debug (DEBUG_LABEL, "START");
202 g_return_if_fail (lbc && GL_IS_LABEL_BARCODE (lbc));
204 gl_text_node_free (&lbc->private->text_node);
205 lbc->private->text_node = gl_text_node_dup (text_node);
207 gl_label_object_emit_changed (GL_LABEL_OBJECT(lbc));
209 gl_debug (DEBUG_LABEL, "END");
213 gl_label_barcode_set_props (glLabelBarcode *lbc,
216 gboolean checksum_flag)
218 gl_debug (DEBUG_LABEL, "START");
220 g_return_if_fail (lbc && GL_IS_LABEL_BARCODE (lbc));
222 lbc->private->id = g_strdup (id);
223 lbc->private->text_flag = text_flag;
224 lbc->private->checksum_flag = checksum_flag;
226 gl_label_object_emit_changed (GL_LABEL_OBJECT(lbc));
228 gl_debug (DEBUG_LABEL, "END");
232 /*****************************************************************************/
233 /* Get object params. */
234 /*****************************************************************************/
236 gl_label_barcode_get_data (glLabelBarcode *lbc)
238 g_return_val_if_fail (lbc && GL_IS_LABEL_BARCODE (lbc), NULL);
240 return gl_text_node_dup (lbc->private->text_node);
244 gl_label_barcode_get_props (glLabelBarcode *lbc,
247 gboolean *checksum_flag)
249 g_return_if_fail (lbc && GL_IS_LABEL_BARCODE (lbc));
251 *id = g_strdup (lbc->private->id);
252 *text_flag = lbc->private->text_flag;
253 *checksum_flag = lbc->private->checksum_flag;
256 /*---------------------------------------------------------------------------*/
257 /* PRIVATE. Get object size method. */
258 /*---------------------------------------------------------------------------*/
260 get_size (glLabelObject *object,
264 glLabelBarcode *lbc = (glLabelBarcode *)object;
266 gdouble w_parent, h_parent;
269 gl_debug (DEBUG_LABEL, "START");
271 g_return_if_fail (lbc && GL_IS_LABEL_BARCODE (lbc));
273 (* parent_class->get_size) (object, &w_parent, &h_parent);
276 if (lbc->private->text_node->field_flag) {
277 data = gl_barcode_default_digits (lbc->private->id);
279 data = gl_text_node_expand (lbc->private->text_node, NULL);
282 gbc = gl_barcode_new (lbc->private->id,
283 lbc->private->text_flag,
284 lbc->private->checksum_flag,
290 /* Try again with default digits. */
291 data = gl_barcode_default_digits (lbc->private->id);
292 gbc = gl_barcode_new (lbc->private->id,
293 lbc->private->text_flag,
294 lbc->private->checksum_flag,
303 gl_barcode_free (&gbc);
306 gl_debug (DEBUG_LABEL, "END");
309 /*---------------------------------------------------------------------------*/
310 /* PRIVATE. Set line color method. */
311 /*---------------------------------------------------------------------------*/
313 set_line_color (glLabelObject *object,
316 glLabelBarcode *lbarcode = (glLabelBarcode *)object;
318 g_return_if_fail (lbarcode && GL_IS_LABEL_BARCODE (lbarcode));
320 if ( lbarcode->private->color != line_color ) {
321 lbarcode->private->color = line_color;
322 gl_label_object_emit_changed (GL_LABEL_OBJECT(lbarcode));
326 /*---------------------------------------------------------------------------*/
327 /* PRIVATE. Get line color method. */
328 /*---------------------------------------------------------------------------*/
330 get_line_color (glLabelObject *object)
332 glLabelBarcode *lbarcode = (glLabelBarcode *)object;
334 g_return_if_fail (lbarcode && GL_IS_LABEL_BARCODE (lbarcode));
336 return lbarcode->private->color;