]> git.sur5r.net Git - glabels/blob - glabels2/src/view-barcode.c
Additional dialogs and widgets migrated to use HIG module.
[glabels] / glabels2 / src / view-barcode.c
1 /*
2  *  (GLABELS) Label and Business Card Creation program for GNOME
3  *
4  *  view_barcode.c:  GLabels label barcode object widget
5  *
6  *  Copyright (C) 2001-2002  Jim Evins <evins@snaught.com>.
7  *
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.
12  *
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.
17  *
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
21  */
22
23 #include <glib.h>
24
25 #include <libgnomeprint/gnome-glyphlist.h>
26
27 #include "view-barcode.h"
28 #include "canvas-hacktext.h"
29
30 #include "view-highlight.h"
31
32 #include "glabels.h"
33 #include "wdgt-bc-data.h"
34 #include "wdgt-bc-props.h"
35 #include "wdgt-bc-style.h"
36 #include "wdgt-position.h"
37 #include "color.h"
38 #include "prefs.h"
39
40 #include "pixmaps/cursor_barcode.xbm"
41 #include "pixmaps/cursor_barcode_mask.xbm"
42
43 #include "debug.h"
44
45 /*========================================================*/
46 /* Private macros and constants.                          */
47 /*========================================================*/
48
49 /*========================================================*/
50 /* Private types.                                         */
51 /*========================================================*/
52
53 struct _glViewBarcodePrivate {
54
55         GList     *item_list;
56
57         /* Page 0 widgets */
58         GtkWidget *bc_data;
59
60         /* Page 1 widgets */
61         GtkWidget *bc_props;
62         GtkWidget *bc_style;
63
64         /* Page 2 widgets */
65         GtkWidget *position;
66 };
67
68 /*========================================================*/
69 /* Private globals.                                       */
70 /*========================================================*/
71
72 static glViewObjectClass *parent_class = NULL;
73
74
75 /*========================================================*/
76 /* Private function prototypes.                           */
77 /*========================================================*/
78
79 static void      gl_view_barcode_class_init       (glViewBarcodeClass *klass);
80 static void      gl_view_barcode_instance_init    (glViewBarcode *view_barcode);
81 static void      gl_view_barcode_finalize         (GObject *object);
82
83 static void      update_view_barcode_cb           (glLabelObject *object,
84                                                 glViewBarcode *view_barcode);
85
86 static GtkWidget *construct_properties_dialog  (glViewBarcode *view_barcode);
87
88 static void      response_cb                   (GtkDialog *dialog,
89                                                 gint response,
90                                                 glViewBarcode *view_barcode);
91
92 static void      bc_data_changed_cb            (glWdgtBCData *bc_data,
93                                                 glViewBarcode *view_barcode);
94
95 static void      bc_props_changed_cb           (glWdgtBCProps *bc_props,
96                                                 glViewBarcode *view_barcode);
97
98 static void      bc_style_changed_cb           (glWdgtBCStyle *bc_style,
99                                                 glViewBarcode *view_barcode);
100
101 static void      position_changed_cb           (glWdgtPosition *position,
102                                                 glViewBarcode *view_barcode);
103
104 static void      update_dialog_cb              (glLabelObject *object,
105                                                 glViewBarcode *view_barcode);
106
107 static void      draw_barcode                  (glViewBarcode *view_barcode);
108
109 \f
110 /*****************************************************************************/
111 /* Boilerplate object stuff.                                                 */
112 /*****************************************************************************/
113 GType
114 gl_view_barcode_get_type (void)
115 {
116         static GType type = 0;
117
118         if (!type) {
119                 GTypeInfo info = {
120                         sizeof (glViewBarcodeClass),
121                         NULL,
122                         NULL,
123                         (GClassInitFunc) gl_view_barcode_class_init,
124                         NULL,
125                         NULL,
126                         sizeof (glViewBarcode),
127                         0,
128                         (GInstanceInitFunc) gl_view_barcode_instance_init,
129                 };
130
131                 type = g_type_register_static (GL_TYPE_VIEW_OBJECT,
132                                                "glViewBarcode", &info, 0);
133         }
134
135         return type;
136 }
137
138 static void
139 gl_view_barcode_class_init (glViewBarcodeClass *klass)
140 {
141         GObjectClass *object_class = (GObjectClass *) klass;
142
143         gl_debug (DEBUG_VIEW, "START");
144
145         parent_class = g_type_class_peek_parent (klass);
146
147         object_class->finalize = gl_view_barcode_finalize;
148
149         gl_debug (DEBUG_VIEW, "END");
150 }
151
152 static void
153 gl_view_barcode_instance_init (glViewBarcode *view_barcode)
154 {
155         gl_debug (DEBUG_VIEW, "START");
156
157         view_barcode->private = g_new0 (glViewBarcodePrivate, 1);
158
159         gl_debug (DEBUG_VIEW, "END");
160 }
161
162 static void
163 gl_view_barcode_finalize (GObject *object)
164 {
165         glLabel       *parent;
166
167         gl_debug (DEBUG_VIEW, "START");
168
169         g_return_if_fail (object && GL_IS_VIEW_BARCODE (object));
170
171         G_OBJECT_CLASS (parent_class)->finalize (object);
172
173         gl_debug (DEBUG_VIEW, "END");
174 }
175
176 /*****************************************************************************/
177 /* NEW barcode object view.                                                  */
178 /*****************************************************************************/
179 glViewObject *
180 gl_view_barcode_new (glLabelBarcode *object,
181                      glView         *view)
182 {
183         glViewBarcode      *view_barcode;
184         GtkMenu            *menu;
185         GtkWidget          *dialog;
186
187         gl_debug (DEBUG_VIEW, "START");
188         g_return_if_fail (object && GL_IS_LABEL_BARCODE (object));
189         g_return_if_fail (view && GL_IS_VIEW (view));
190         
191         view_barcode = g_object_new (gl_view_barcode_get_type(), NULL);
192
193         gl_view_object_set_view (GL_VIEW_OBJECT(view_barcode), view);
194         gl_view_object_set_object (GL_VIEW_OBJECT(view_barcode),
195                                    GL_LABEL_OBJECT(object),
196                                    GL_VIEW_HIGHLIGHT_SIMPLE);
197
198         /* Create analogous canvas items. */
199         draw_barcode (view_barcode);
200
201         g_signal_connect (G_OBJECT (object), "changed",
202                           G_CALLBACK (update_view_barcode_cb), view_barcode);
203
204         /* Create a dialog for controlling/viewing object properties. */
205         dialog = construct_properties_dialog (view_barcode);
206         gl_view_object_set_dialog     (GL_VIEW_OBJECT(view_barcode), dialog);
207
208         gl_debug (DEBUG_VIEW, "END");
209
210         return GL_VIEW_OBJECT (view_barcode);
211 }
212
213 /*---------------------------------------------------------------------------*/
214 /* PRIVATE. label object "changed" callback.                                 */
215 /*---------------------------------------------------------------------------*/
216 static void
217 update_view_barcode_cb (glLabelObject *object,
218                         glViewBarcode *view_barcode)
219 {
220         glView             *view;
221         GnomeCanvasItem    *group;
222
223         gl_debug (DEBUG_VIEW, "START");
224
225         view = gl_view_object_get_view (GL_VIEW_OBJECT(view_barcode));
226
227         /* Adjust appearance of analogous canvas items. */
228         draw_barcode (view_barcode);
229
230         /* Adjust highlight */
231         gl_view_object_update_highlight (GL_VIEW_OBJECT(view_barcode));
232
233         gl_debug (DEBUG_VIEW, "END");
234 }
235
236 /*****************************************************************************/
237 /* Create a properties dialog for a barcode object.                          */
238 /*****************************************************************************/
239 static GtkWidget *
240 construct_properties_dialog (glViewBarcode *view_barcode)
241 {
242         GtkWidget          *dialog, *wsection;
243         BonoboWindow       *win = glabels_get_active_window ();
244         glLabelObject      *object;
245         gdouble            x, y, w, h, label_width, label_height;
246         glTextNode         *text_node;
247         glBarcodeStyle     style;
248         gboolean           text_flag;
249         guint              color;
250         gdouble            scale;
251         glMerge            *merge;
252         GtkSizeGroup       *label_size_group;
253
254         gl_debug (DEBUG_VIEW, "START");
255
256         /* retrieve object and query parameters */
257         object = gl_view_object_get_object (GL_VIEW_OBJECT(view_barcode));
258         gl_label_object_get_position (GL_LABEL_OBJECT(object), &x, &y);
259         text_node = gl_label_barcode_get_data(GL_LABEL_BARCODE(object));
260         gl_label_barcode_get_props (GL_LABEL_BARCODE(object),
261                                     &style, &text_flag, &color, &scale);
262         gl_label_get_size (GL_LABEL(object->parent),
263                            &label_width, &label_height);
264         merge = gl_label_get_merge (GL_LABEL(object->parent));
265
266         /*-----------------------------------------------------------------*/
267         /* Build dialog.                                                   */
268         /*-----------------------------------------------------------------*/
269         dialog = gl_hig_dialog_new_with_buttons ( _("Edit barcode object properties"),
270                                                   GTK_WINDOW (win),
271                                                   GTK_DIALOG_DESTROY_WITH_PARENT,
272                                                   GTK_STOCK_CLOSE,
273                                                            GTK_RESPONSE_CLOSE,
274                                                   NULL );
275         gtk_window_set_resizable (GTK_WINDOW (dialog), FALSE);
276         g_signal_connect (G_OBJECT (dialog), "response",
277                           G_CALLBACK (response_cb), view_barcode);
278
279         label_size_group = gtk_size_group_new (GTK_SIZE_GROUP_HORIZONTAL);
280
281         /*---------------------------*/
282         /* Data section              */
283         /*---------------------------*/
284         wsection = gl_hig_category_new (_("Data"));
285         gl_hig_dialog_add_widget (GL_HIG_DIALOG(dialog), wsection);
286
287         /* barcode data */
288         view_barcode->private->bc_data =
289                 gl_wdgt_bc_data_new (merge->field_defs);
290         gl_wdgt_bc_data_set_label_size_group (GL_WDGT_BC_DATA(view_barcode->private->bc_data),
291                                               label_size_group);
292         gl_wdgt_bc_data_set_data (GL_WDGT_BC_DATA(view_barcode->private->bc_data),
293                                   (merge->type != GL_MERGE_NONE),
294                                   text_node);
295         gl_hig_category_add_widget (GL_HIG_CATEGORY(wsection),
296                                     view_barcode->private->bc_data);
297         g_signal_connect ( G_OBJECT(view_barcode->private->bc_data),
298                            "changed", G_CALLBACK (bc_data_changed_cb),
299                            view_barcode);
300
301
302         /*---------------------------*/
303         /* Appearance section        */
304         /*---------------------------*/
305         wsection = gl_hig_category_new (_("Properties"));
306         gl_hig_dialog_add_widget (GL_HIG_DIALOG(dialog), wsection);
307
308         /* barcode props entry */
309         gl_debug (DEBUG_VIEW, "Creating props entry...");
310         view_barcode->private->bc_props = gl_wdgt_bc_props_new ();
311         gl_wdgt_bc_props_set_label_size_group (GL_WDGT_BC_PROPS(view_barcode->private->bc_props),
312                                                label_size_group);
313         gl_wdgt_bc_props_set_params (GL_WDGT_BC_PROPS(view_barcode->private->bc_props),
314                                      scale, color);
315         gl_hig_category_add_widget (GL_HIG_CATEGORY(wsection),
316                                     view_barcode->private->bc_props);
317         g_signal_connect ( G_OBJECT(view_barcode->private->bc_props),
318                            "changed", G_CALLBACK (bc_props_changed_cb),
319                            view_barcode);
320
321         /* Barcode style widget */
322         view_barcode->private->bc_style = gl_wdgt_bc_style_new ();
323         gl_wdgt_bc_style_set_label_size_group (GL_WDGT_BC_STYLE(view_barcode->private->bc_style),
324                                                label_size_group);
325         gl_wdgt_bc_style_set_params (GL_WDGT_BC_STYLE (view_barcode->private->bc_style),
326                                      style, text_flag);
327         gl_hig_category_add_widget (GL_HIG_CATEGORY(wsection),
328                                     view_barcode->private->bc_style);
329         g_signal_connect (G_OBJECT (view_barcode->private->bc_style),
330                           "changed", G_CALLBACK (bc_style_changed_cb),
331                           view_barcode);
332
333
334         /*----------------------------*/
335         /* Position section           */
336         /*----------------------------*/
337         wsection = gl_hig_category_new (_("Position"));
338         gl_hig_dialog_add_widget (GL_HIG_DIALOG(dialog), wsection);
339
340         /* ------ Position Frame ------ */
341         view_barcode->private->position = gl_wdgt_position_new ();
342         gl_wdgt_position_set_label_size_group (GL_WDGT_POSITION(view_barcode->private->position),
343                                                label_size_group);
344         gl_wdgt_position_set_params (GL_WDGT_POSITION (view_barcode->private->position),
345                                      x, y,
346                                      label_width, label_height);
347         gl_hig_category_add_widget (GL_HIG_CATEGORY(wsection),
348                                     view_barcode->private->position);
349         g_signal_connect (G_OBJECT (view_barcode->private->position),
350                           "changed",
351                           G_CALLBACK(position_changed_cb), view_barcode);
352
353
354         /*----------------------------*/
355         /* Track object changes.      */
356         /*----------------------------*/
357         g_signal_connect (G_OBJECT (object), "changed",
358                           G_CALLBACK (update_dialog_cb), view_barcode);
359
360         gl_debug (DEBUG_VIEW, "END");
361
362         return dialog;
363 }
364
365 /*---------------------------------------------------------------------------*/
366 /* PRIVATE.  "Response" callback.                                            */
367 /*---------------------------------------------------------------------------*/
368 static void
369 response_cb (GtkDialog     *dialog,
370              gint          response,
371              glViewBarcode   *view_barcode)
372 {
373         gl_debug (DEBUG_VIEW, "START");
374
375         g_return_if_fail(dialog != NULL);
376         g_return_if_fail(GTK_IS_DIALOG(dialog));
377
378         switch(response) {
379         case GTK_RESPONSE_CLOSE:
380                 gtk_widget_hide (GTK_WIDGET(dialog));
381                 break;
382         default:
383                 g_assert_not_reached();
384         }
385
386         gl_debug (DEBUG_VIEW, "END");
387 }
388
389 /*---------------------------------------------------------------------------*/
390 /* PRIVATE.  barcode data "changed" callback.                                */
391 /*---------------------------------------------------------------------------*/
392 static void
393 bc_data_changed_cb (glWdgtBCData        *bc_data,
394                     glViewBarcode       *view_barcode)
395 {
396         glLabelObject    *object;
397         glTextNode       *text_node;
398
399         gl_debug (DEBUG_VIEW, "START");
400
401         object = gl_view_object_get_object (GL_VIEW_OBJECT(view_barcode));
402
403         text_node = gl_wdgt_bc_data_get_data (bc_data);
404
405         g_signal_handlers_block_by_func (G_OBJECT(object),
406                                          update_dialog_cb, view_barcode);
407         gl_label_barcode_set_data (GL_LABEL_BARCODE(object), text_node);
408         g_signal_handlers_unblock_by_func (G_OBJECT(object),
409                                            update_dialog_cb, view_barcode);
410
411         gl_text_node_free (&text_node);
412
413         gl_debug (DEBUG_VIEW, "END");
414 }
415
416 /*---------------------------------------------------------------------------*/
417 /* PRIVATE.  barcode props "changed" callback.                               */
418 /*---------------------------------------------------------------------------*/
419 static void
420 bc_props_changed_cb (glWdgtBCProps  *text_props,
421                      glViewBarcode  *view_barcode)
422 {
423         glLabelObject      *object;
424         glBarcodeStyle     style;
425         gboolean           text_flag;
426         guint              color;
427         gdouble            scale;
428
429
430         gl_debug (DEBUG_VIEW, "START");
431
432         object = gl_view_object_get_object (GL_VIEW_OBJECT(view_barcode));
433
434         gl_label_barcode_get_props (GL_LABEL_BARCODE(object),
435                                     &style, &text_flag, &color, &scale);
436         gl_wdgt_bc_props_get_params (text_props, &scale, &color);
437
438         g_signal_handlers_block_by_func (G_OBJECT(object),
439                                          update_dialog_cb, view_barcode);
440         gl_label_barcode_set_props (GL_LABEL_BARCODE(object),
441                                     style, text_flag, color, scale);
442         g_signal_handlers_unblock_by_func (G_OBJECT(object),
443                                            update_dialog_cb, view_barcode);
444
445         gl_debug (DEBUG_VIEW, "END");
446 }
447
448 /*---------------------------------------------------------------------------*/
449 /* PRIVATE.  barcode style "changed" callback.                               */
450 /*---------------------------------------------------------------------------*/
451 static void
452 bc_style_changed_cb (glWdgtBCStyle  *bc_style,
453                      glViewBarcode  *view_barcode)
454 {
455         glLabelObject      *object;
456         glBarcodeStyle     style;
457         gboolean           text_flag;
458         guint              color;
459         gdouble            scale;
460
461
462         gl_debug (DEBUG_VIEW, "START");
463
464         object = gl_view_object_get_object (GL_VIEW_OBJECT(view_barcode));
465
466         gl_label_barcode_get_props (GL_LABEL_BARCODE(object),
467                                     &style, &text_flag, &color, &scale);
468         gl_wdgt_bc_style_get_params (bc_style, &style, &text_flag);
469
470         g_signal_handlers_block_by_func (G_OBJECT(object),
471                                          update_dialog_cb, view_barcode);
472         gl_label_barcode_set_props (GL_LABEL_BARCODE(object),
473                                     style, text_flag, color, scale);
474         g_signal_handlers_unblock_by_func (G_OBJECT(object),
475                                            update_dialog_cb, view_barcode);
476
477         gl_debug (DEBUG_VIEW, "END");
478 }
479
480 /*---------------------------------------------------------------------------*/
481 /* PRIVATE.  position "changed" callback.                                    */
482 /*---------------------------------------------------------------------------*/
483 static void
484 position_changed_cb (glWdgtPosition     *position,
485                      glViewBarcode         *view_barcode)
486 {
487         glLabelObject      *object;
488         gdouble            x, y;
489
490         gl_debug (DEBUG_VIEW, "START");
491
492         gl_wdgt_position_get_position (GL_WDGT_POSITION (position), &x, &y);
493
494         object = gl_view_object_get_object (GL_VIEW_OBJECT(view_barcode));
495
496         g_signal_handlers_block_by_func (G_OBJECT(object),
497                                          update_dialog_cb, view_barcode);
498         gl_label_object_set_position (GL_LABEL_OBJECT(object), x, y);
499         g_signal_handlers_unblock_by_func (G_OBJECT(object),
500                                            update_dialog_cb, view_barcode);
501
502         gl_debug (DEBUG_VIEW, "END");
503 }
504
505 /*---------------------------------------------------------------------------*/
506 /* PRIVATE. label object "changed" callback.                                 */
507 /*---------------------------------------------------------------------------*/
508 static void
509 update_dialog_cb (glLabelObject  *object,
510                   glViewBarcode     *view_barcode)
511 {
512         gdouble            x, y;
513         glTextNode         *text_node;
514         glBarcodeStyle     style;
515         gboolean           text_flag;
516         guint              color;
517         gdouble            scale;
518         glMerge            *merge;
519
520         gl_debug (DEBUG_VIEW, "START");
521
522         /* Query properties of object. */
523         text_node = gl_label_barcode_get_data(GL_LABEL_BARCODE(object));
524         gl_label_barcode_get_props (GL_LABEL_BARCODE(object),
525                                     &style, &text_flag, &color, &scale);
526         gl_label_object_get_position (GL_LABEL_OBJECT(object), &x, &y);
527         merge = gl_label_get_merge (GL_LABEL(object->parent));
528
529         /* Block widget handlers to prevent recursion */
530         g_signal_handlers_block_by_func (G_OBJECT(view_barcode->private->bc_data),
531                                          bc_data_changed_cb, view_barcode);
532         g_signal_handlers_block_by_func (G_OBJECT(view_barcode->private->bc_props),
533                                          bc_props_changed_cb, view_barcode);
534         g_signal_handlers_block_by_func (G_OBJECT(view_barcode->private->bc_style),
535                                          bc_style_changed_cb, view_barcode);
536         g_signal_handlers_block_by_func (G_OBJECT(view_barcode->private->position),
537                                          position_changed_cb, view_barcode);
538
539         /* Update widgets in property dialog */
540
541         gl_wdgt_bc_data_set_data (GL_WDGT_BC_DATA(view_barcode->private->bc_data),
542                                   (merge->type != GL_MERGE_NONE),
543                                   text_node);
544         gl_wdgt_bc_props_set_params (GL_WDGT_BC_PROPS(view_barcode->private->bc_props),
545                                      scale, color);
546         gl_wdgt_bc_style_set_params (GL_WDGT_BC_STYLE(view_barcode->private->bc_style),
547                                      style, text_flag);
548         gl_wdgt_position_set_position (GL_WDGT_POSITION(view_barcode->private->position),
549                                        x, y);
550
551         /* Unblock widget handlers */
552         g_signal_handlers_unblock_by_func (G_OBJECT(view_barcode->private->bc_data),
553                                            bc_data_changed_cb, view_barcode);
554         g_signal_handlers_unblock_by_func (G_OBJECT(view_barcode->private->bc_props),
555                                            bc_props_changed_cb, view_barcode);
556         g_signal_handlers_unblock_by_func (G_OBJECT(view_barcode->private->bc_style),
557                                            bc_style_changed_cb, view_barcode);
558         g_signal_handlers_unblock_by_func (G_OBJECT(view_barcode->private->position),
559                                            position_changed_cb, view_barcode);
560
561         gl_text_node_free (&text_node);
562
563         gl_debug (DEBUG_VIEW, "END");
564 }
565
566 /*****************************************************************************/
567 /* Return apropos cursor for create object mode.                             */
568 /*****************************************************************************/
569 GdkCursor *
570 gl_view_barcode_get_create_cursor (void)
571 {
572         static GdkCursor *cursor = NULL;
573         GdkPixmap        *pixmap_data, *pixmap_mask;
574         GdkColor         fg = { 0, 0, 0, 0 };
575         GdkColor         bg = { 0, 65535, 65535, 65535 };
576
577         gl_debug (DEBUG_VIEW, "START");
578
579         if (!cursor) {
580                 pixmap_data = gdk_bitmap_create_from_data (NULL,
581                                                            cursor_barcode_bits,
582                                                            cursor_barcode_width,
583                                                            cursor_barcode_height);
584                 pixmap_mask = gdk_bitmap_create_from_data (NULL,
585                                                            cursor_barcode_mask_bits,
586                                                            cursor_barcode_mask_width,
587                                                            cursor_barcode_mask_height);
588                 cursor =
589                     gdk_cursor_new_from_pixmap (pixmap_data, pixmap_mask, &fg,
590                                                 &bg, cursor_barcode_x_hot,
591                                                 cursor_barcode_y_hot);
592         }
593
594         gl_debug (DEBUG_VIEW, "END");
595
596         return cursor;
597 }
598
599 /*****************************************************************************/
600 /* Canvas event handler for creating barcode objects.                            */
601 /*****************************************************************************/
602 int
603 gl_view_barcode_create_event_handler (GnomeCanvas *canvas,
604                                       GdkEvent    *event,
605                                       glView      *view)
606 {
607         static gdouble      x0, y0;
608         static gboolean     dragging = FALSE;
609         static glViewObject *view_barcode;
610         static GObject      *object;
611         gdouble             x, y;
612         glTextNode          *text_node;
613
614         gl_debug (DEBUG_VIEW, "");
615
616         switch (event->type) {
617
618         case GDK_BUTTON_PRESS:
619                 gl_debug (DEBUG_VIEW, "BUTTON_PRESS");
620                 switch (event->button.button) {
621                 case 1:
622                         dragging = TRUE;
623                         gdk_pointer_grab (GTK_WIDGET (view->canvas)->window,
624                                           FALSE,
625                                           GDK_POINTER_MOTION_MASK |
626                                           GDK_BUTTON_RELEASE_MASK |
627                                           GDK_BUTTON_PRESS_MASK,
628                                           NULL, NULL, event->button.time);
629                         gnome_canvas_window_to_world (canvas,
630                                                       event->button.x,
631                                                       event->button.y, &x, &y);
632                         object = gl_label_barcode_new (view->label);
633                         gl_label_object_set_position (GL_LABEL_OBJECT(object),
634                                                      x, y);
635                         text_node = gl_text_node_new_from_text ("123456789");
636                         gl_label_barcode_set_data (GL_LABEL_BARCODE(object),
637                                                    text_node);
638                         gl_label_barcode_set_props (GL_LABEL_BARCODE(object),
639                                                     GL_BARCODE_STYLE_POSTNET,
640                                                     FALSE,
641                                                     gl_color_set_opacity (gl_prefs->default_line_color, 0.5),
642                                                     1.0);
643                         view_barcode = gl_view_barcode_new (GL_LABEL_BARCODE(object),
644                                                             view);
645                         x0 = x;
646                         y0 = y;
647                         return TRUE;
648
649                 default:
650                         return FALSE;
651                 }
652
653         case GDK_BUTTON_RELEASE:
654                 gl_debug (DEBUG_VIEW, "BUTTON_RELEASE");
655                 switch (event->button.button) {
656                 case 1:
657                         dragging = FALSE;
658                         gdk_pointer_ungrab (event->button.time);
659                         gnome_canvas_window_to_world (canvas,
660                                                       event->button.x,
661                                                       event->button.y, &x, &y);
662                         gl_label_object_set_position (GL_LABEL_OBJECT(object),
663                                                       x, y);
664                         gl_label_barcode_set_props (GL_LABEL_BARCODE(object),
665                                                     GL_BARCODE_STYLE_POSTNET,
666                                                     FALSE,
667                                                     gl_prefs->default_line_color,
668                                                     1.0);
669                         gl_view_unselect_all (view);
670                         gl_view_object_select (GL_VIEW_OBJECT(view_barcode));
671                         gl_view_arrow_mode (view);
672                         return TRUE;
673
674                 default:
675                         return FALSE;
676                 }
677
678         case GDK_MOTION_NOTIFY:
679                 gl_debug (DEBUG_VIEW, "MOTION_NOTIFY");
680                 if (dragging && (event->motion.state & GDK_BUTTON1_MASK)) {
681                         gnome_canvas_window_to_world (canvas,
682                                                       event->motion.x,
683                                                       event->motion.y, &x, &y);
684                         gl_label_object_set_position (GL_LABEL_OBJECT(object),
685                                                       x, y);
686                         return TRUE;
687                 } else {
688                         return FALSE;
689                 }
690
691         default:
692                 return FALSE;
693         }
694
695 }
696
697 /*--------------------------------------------------------------------------*/
698 /* PRIVATE.  Draw barcode to item (group).                                  */
699 /*--------------------------------------------------------------------------*/
700 static void
701 draw_barcode (glViewBarcode *view_barcode)
702 {
703         glLabelObject    *object;
704         GnomeCanvasItem  *group, *item;
705         glTextNode *text_node;
706         glBarcodeStyle style;
707         gboolean text_flag;
708         guint color;
709         gdouble scale;
710         glBarcodeLine *line;
711         glBarcodeChar *bchar;
712         glBarcode *gbc;
713         GList *li;
714         GList *item_list = NULL;
715         GnomeCanvasPoints *points;
716         gchar *digits, *cstring;
717         GnomeFont *font;
718         GnomeGlyphList *glyphlist;
719         gdouble y_offset;
720
721         gl_debug (DEBUG_VIEW, "START");
722
723         /* Query label object and properties */
724         object = gl_view_object_get_object (GL_VIEW_OBJECT(view_barcode));
725         gl_label_barcode_get_props (GL_LABEL_BARCODE(object),
726                                     &style, &text_flag, &color, &scale);
727         text_node = gl_label_barcode_get_data(GL_LABEL_BARCODE(object));
728         if (text_node->field_flag) {
729                 digits = gl_barcode_default_digits (style);
730         } else {
731                 digits = gl_text_node_expand (text_node, NULL);
732         }
733
734         /* get parent item/group to render to. */
735         group = gl_view_object_get_group (GL_VIEW_OBJECT(view_barcode));
736
737         /* remove previous items from group. */
738         for (li = view_barcode->private->item_list; li!=NULL; li = li->next) {
739                 gl_debug (DEBUG_VIEW, "in loop");
740                 gtk_object_destroy (GTK_OBJECT (li->data));
741         }
742         gl_debug (DEBUG_VIEW, "1");
743         g_list_free (view_barcode->private->item_list);
744         view_barcode->private->item_list = NULL;
745         gl_debug (DEBUG_VIEW, "2");
746
747         /* get Gnome Font */
748         font = gnome_font_find_closest_from_weight_slant (GL_BARCODE_FONT_FAMILY,
749                                                           GL_BARCODE_FONT_WEIGHT,
750                                                           FALSE,
751                                                           10.0);
752
753         gbc = gl_barcode_new (style, text_flag, scale, digits);
754         if (gbc == NULL) {
755
756                 cstring = _("Invalid barcode");
757                 glyphlist = gnome_glyphlist_from_text_sized_dumb (font,
758                                                                   color,
759                                                                   0.0, 0.0,
760                                                                   cstring,
761                                                                   strlen
762                                                                   (cstring));
763                 y_offset = 10.0 - gnome_font_get_descender (font);
764                 item = gnome_canvas_item_new (GNOME_CANVAS_GROUP (group),
765                                               gl_canvas_hacktext_get_type (),
766                                               "x", 0.0,
767                                               "y", y_offset,
768                                               "glyphlist", glyphlist, NULL);
769
770                 view_barcode->private->item_list =
771                         g_list_prepend (view_barcode->private->item_list, item);
772         } else {
773
774                 points = gnome_canvas_points_new (2);
775                 for (li = gbc->lines; li != NULL; li = li->next) {
776                         line = (glBarcodeLine *) li->data;
777
778                         points->coords[0] = line->x;
779                         points->coords[1] = line->y;
780                         points->coords[2] = line->x;
781                         points->coords[3] = line->y + line->length;
782
783                         item =
784                             gnome_canvas_item_new (GNOME_CANVAS_GROUP (group),
785                                                    gnome_canvas_line_get_type
786                                                    (), "points", points,
787                                                    "width_units", line->width,
788                                                    "fill_color_rgba", color,
789                                                    NULL);
790                         view_barcode->private->item_list =
791                                 g_list_prepend (view_barcode->private->item_list, item);
792                 }
793                 gnome_canvas_points_free (points);
794
795                 for (li = gbc->chars; li != NULL; li = li->next) {
796                         bchar = (glBarcodeChar *) li->data;
797
798                         font = gnome_font_find_closest_from_weight_slant (
799                                                        GL_BARCODE_FONT_FAMILY,
800                                                        GL_BARCODE_FONT_WEIGHT,
801                                                        FALSE, bchar->fsize);
802                         glyphlist = gnome_glyphlist_from_text_sized_dumb (font,
803                                                                           color,
804                                                                           0.0,
805                                                                           0.0,
806                                                                           &
807                                                                           (bchar->
808                                                                            c),
809                                                                           1);
810                         y_offset =
811                             bchar->fsize - gnome_font_get_descender (font);
812                         item =
813                             gnome_canvas_item_new (GNOME_CANVAS_GROUP (group),
814                                                    gnome_canvas_hacktext_get_type
815                                                    (), "x", bchar->x, "y",
816                                                    bchar->y + y_offset,
817                                                    "glyphlist", glyphlist,
818                                                    NULL);
819
820                         view_barcode->private->item_list =
821                                 g_list_prepend (view_barcode->private->item_list, item);
822
823                 }
824
825         }
826
827         /* clean up */
828         gl_barcode_free (&gbc);
829         g_free (digits);
830
831         gl_debug (DEBUG_VIEW, "END");
832 }
833