From: Jim Evins Date: Sat, 25 Jan 2003 00:43:45 +0000 (+0000) Subject: Barcodes are now resizable interactively on the canvas in both width and height ... X-Git-Tag: glabels-2_3_0~643 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=251323ecb306c6ed40528a6e57e0dbd2a0495f5c;p=glabels Barcodes are now resizable interactively on the canvas in both width and height (no more scale). Added checkbox to turn-off checksum digit on barcodes when it is optional. git-svn-id: https://glabels.svn.sourceforge.net/svnroot/glabels/trunk@245 f5e0f49d-192f-0410-a22d-a8d8700d0965 --- diff --git a/glabels2/src/bc-gnubarcode.c b/glabels2/src/bc-gnubarcode.c index c97f56ff..2bacb0d7 100644 --- a/glabels2/src/bc-gnubarcode.c +++ b/glabels2/src/bc-gnubarcode.c @@ -3,7 +3,7 @@ * * bc-gnubarcode.c: front-end to GNU-barcode-library module * - * Copyright (C) 2001-2002 Jim Evins . + * Copyright (C) 2001-2003 Jim Evins . * * Some of this code is borrowed from the postscript renderer (ps.c) * from the GNU barcode library: @@ -47,8 +47,8 @@ /* Local function prototypes */ /*===========================================*/ static glBarcode *render_pass1 (struct Barcode_Item *bci, - gboolean text_flag, - gdouble scale); + gint flags); + /*****************************************************************************/ /* Generate intermediate representation of barcode. */ @@ -56,7 +56,9 @@ static glBarcode *render_pass1 (struct Barcode_Item *bci, glBarcode * gl_barcode_gnubarcode_new (glBarcodeStyle style, gboolean text_flag, - gdouble scale, + gboolean checksum_flag, + gdouble w, + gdouble h, gchar *digits) { glBarcode *gbc; @@ -105,6 +107,18 @@ gl_barcode_gnubarcode_new (glBarcodeStyle style, flags = BARCODE_ANY; break; } + + if (!text_flag) { + flags |= BARCODE_NO_ASCII; + } + if (!checksum_flag) { + flags |= BARCODE_NO_CHECKSUM; + } + + bci->scalef = 0.0; + bci->width = w; + bci->height = h; + Barcode_Encode (bci, flags); if (!bci->partial || !bci->textinfo) { g_warning ("Barcode Data Invalid"); @@ -114,7 +128,7 @@ gl_barcode_gnubarcode_new (glBarcodeStyle style, /* now render with our custom back-end, to create appropriate intermdediate format */ - gbc = render_pass1 (bci, text_flag, scale); + gbc = render_pass1 (bci, flags); Barcode_Delete (bci); return gbc; @@ -132,12 +146,13 @@ gl_barcode_gnubarcode_new (glBarcodeStyle style, *--------------------------------------------------------------------------*/ static glBarcode * render_pass1 (struct Barcode_Item *bci, - gboolean text_flag, - gdouble scale) + gint flags) { + gint validbits = BARCODE_NO_ASCII; glBarcode *gbc; glBarcodeLine *line; glBarcodeChar *bchar; + gdouble scalef = 1.0; gdouble x; gint i, j, barlen; gdouble f1, f2; @@ -145,6 +160,19 @@ render_pass1 (struct Barcode_Item *bci, gdouble x0, y0, yr; guchar *p, c; + if (bci->width > (2*bci->margin)) { + bci->width -= 2*bci->margin; + } + if (bci->height > (2*bci->margin)) { + bci->height -= 2*bci->margin; + } + + /* If any flag is clear in "flags", inherit it from "bci->flags" */ + if (!(flags & BARCODE_NO_ASCII)) { + flags |= bci->flags & BARCODE_NO_ASCII; + } + flags = bci->flags = (flags & validbits) | (bci->flags & ~validbits); + /* First calculate barlen */ barlen = bci->partial[0] - '0'; for (p = bci->partial + 1; *p != 0; p++) { @@ -157,17 +185,50 @@ render_pass1 (struct Barcode_Item *bci, } } + /* The scale factor depends on bar length */ + if (!bci->scalef) { + if (!bci->width) bci->width = barlen; /* default */ + scalef = bci->scalef = (double)bci->width / (double)barlen; + if (scalef < 0.5) scalef = 0.5; + } + /* The width defaults to "just enough" */ - bci->width = barlen * scale + 1; + bci->width = barlen * scalef + 1; + + /* But it can be too small, in this case enlarge and center the area */ + if (bci->width < barlen * scalef) { + int wid = barlen * scalef + 1; + bci->xoff -= (wid - bci->width)/2 ; + bci->width = wid; + /* Can't extend too far on the left */ + if (bci->xoff < 0) { + bci->width += -bci->xoff; + bci->xoff = 0; + } + } /* The height defaults to 80 points (rescaled) */ if (!bci->height) - bci->height = 80 * scale; + bci->height = 80 * scalef; + + /* If too small (5 + text), reduce the scale factor and center */ + i = 5 + 10 * ((bci->flags & BARCODE_NO_ASCII)==0); + if (bci->height < i * scalef ) { +#if 0 + double scaleg = ((double)bci->height) / i; + int wid = bci->width * scaleg / scalef; + bci->xoff += (bci->width - wid)/2; + bci->width = wid; + scalef = scaleg; +#else + bci->height = i * scalef; +#endif + } gbc = g_new0 (glBarcode, 1); /* Now traverse the code string and create a list of lines */ - x = bci->margin + (bci->partial[0] - '0') * scale; + x = bci->margin + (bci->partial[0] - '0') * scalef; for (p = bci->partial + 1, i = 1; *p != 0; p++, i++) { /* special cases: '+' and '-' */ if (*p == '+' || *p == '-') { @@ -181,34 +242,34 @@ render_pass1 (struct Barcode_Item *bci, else j = *p - 'a' + 1; if (i % 2) { /* bar */ - x0 = x + (j * scale) / 2; + x0 = x + (j * scalef) / 2; y0 = bci->margin; yr = bci->height; - if (text_flag) { /* leave space for text */ + if (!(bci->flags & BARCODE_NO_ASCII)) { /* leave space for text */ if (mode == '-') { /* text below bars: 10 or 5 points */ - yr -= (isdigit (*p) ? 10 : 5) * scale; + yr -= (isdigit (*p) ? 10 : 5) * scalef; } else { /* '+' */ /* above bars: 10 or 0 from bottom, and 10 from top */ - y0 += 10 * scale; - yr -= (isdigit (*p) ? 20 : 10) * scale; + y0 += 10 * scalef; + yr -= (isdigit (*p) ? 20 : 10) * scalef; } } line = g_new0 (glBarcodeLine, 1); line->x = x0; line->y = y0; line->length = yr; - line->width = (j * scale) - SHRINK_AMOUNT; + line->width = (j * scalef) - SHRINK_AMOUNT; gbc->lines = g_list_append (gbc->lines, line); } - x += j * scale; + x += j * scalef; } /* Now the text */ mode = '-'; /* reinstantiate default */ - if (text_flag) { + if (!(bci->flags & BARCODE_NO_ASCII)) { for (p = bci->textinfo; p; p = strchr (p, ' ')) { while (*p == ' ') p++; @@ -223,14 +284,14 @@ render_pass1 (struct Barcode_Item *bci, continue; } bchar = g_new0 (glBarcodeChar, 1); - bchar->x = f1 * scale + bci->margin; + bchar->x = f1 * scalef + bci->margin; if (mode == '-') { bchar->y = - bci->margin + bci->height - 8 * scale; + bci->margin + bci->height - 8 * scalef; } else { bchar->y = bci->margin; } - bchar->fsize = f2 * FONT_SCALE * scale; + bchar->fsize = f2 * FONT_SCALE * scalef; bchar->c = c; gbc->chars = g_list_append (gbc->chars, bchar); } @@ -240,5 +301,9 @@ render_pass1 (struct Barcode_Item *bci, gbc->height = bci->height + 2.0 * bci->margin; gbc->width = bci->width + 2.0 * bci->margin; +#if 0 + g_print ("w=%f, h=%f\n", gbc->width, gbc->height); +#endif + return gbc; } diff --git a/glabels2/src/bc-gnubarcode.h b/glabels2/src/bc-gnubarcode.h index 3dc8cf6c..ab186eed 100644 --- a/glabels2/src/bc-gnubarcode.h +++ b/glabels2/src/bc-gnubarcode.h @@ -3,7 +3,7 @@ * * bc_gnubarcode.h: front-end to GNU-barcode-library module header file * - * Copyright (C) 2001-2002 Jim Evins . + * Copyright (C) 2001-2003 Jim Evins . * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -28,7 +28,9 @@ G_BEGIN_DECLS glBarcode *gl_barcode_gnubarcode_new (glBarcodeStyle style, gboolean text_flag, - gdouble scale, + gboolean checksum_flag, + gdouble w, + gdouble h, gchar *digits); G_END_DECLS diff --git a/glabels2/src/bc-postnet.c b/glabels2/src/bc-postnet.c index 2bea1ae3..c333b2d1 100644 --- a/glabels2/src/bc-postnet.c +++ b/glabels2/src/bc-postnet.c @@ -3,7 +3,7 @@ * * bc_postnet.c: GLabels POSTNET barcode module * - * Copyright (C) 2001-2002 Jim Evins . + * Copyright (C) 2001-2003 Jim Evins . * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -72,7 +72,12 @@ static gchar *postnet_code (gchar *digits); /* Generate list of lines that form the barcode for the given digits. */ /****************************************************************************/ glBarcode * -gl_barcode_postnet_new (gchar *digits) +gl_barcode_postnet_new (glBarcodeStyle style, + gboolean text_flag, + gboolean checksum_flag, + gdouble w, + gdouble h, + gchar *digits) { gchar *code, *p; glBarcode *gbc; diff --git a/glabels2/src/bc-postnet.h b/glabels2/src/bc-postnet.h index 63c17265..717f1043 100644 --- a/glabels2/src/bc-postnet.h +++ b/glabels2/src/bc-postnet.h @@ -3,7 +3,7 @@ * * bc_postnet.h: GLabels POSTNET barcode module header file * - * Copyright (C) 2001 Jim Evins . + * Copyright (C) 2001-2003 Jim Evins . * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -26,7 +26,12 @@ G_BEGIN_DECLS -glBarcode *gl_barcode_postnet_new (gchar *digits); +glBarcode *gl_barcode_postnet_new (glBarcodeStyle style, + gboolean text_flag, + gboolean checksum_flag, + gdouble w, + gdouble h, + gchar *digits); G_END_DECLS diff --git a/glabels2/src/bc.c b/glabels2/src/bc.c index 93215e11..8c431f1b 100644 --- a/glabels2/src/bc.c +++ b/glabels2/src/bc.c @@ -3,7 +3,7 @@ * * bc.c: GLabels barcode module * - * Copyright (C) 2001-2002 Jim Evins . + * Copyright (C) 2001-2003 Jim Evins . * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -26,6 +26,74 @@ #include "bc-gnubarcode.h" #include "debug.h" + +/*========================================================*/ +/* Private macros and constants. */ +/*========================================================*/ + +/*========================================================*/ +/* Private types. */ +/*========================================================*/ + +typedef struct { + gchar *name; + glBarcodeNewFunc new; + gboolean can_text; + gboolean text_optional; + gboolean can_checksum; + gboolean checksum_optional; + gchar *default_digits; +} Backend; + + +/*========================================================*/ +/* Private globals. */ +/*========================================================*/ + +Backend backends[GL_BARCODE_N_STYLES] = { + + { "POSTNET", gl_barcode_postnet_new, + FALSE, FALSE, TRUE, FALSE, "000000000"}, + + { "EAN", gl_barcode_gnubarcode_new, + TRUE, TRUE, TRUE, FALSE, "000000000000 00000"}, + + { "UPC", gl_barcode_gnubarcode_new, + TRUE, TRUE, TRUE, FALSE, "00000000000 00000"}, + + { "ISBN", gl_barcode_gnubarcode_new, + TRUE, TRUE, TRUE, TRUE, "0-00000-000-0 00000"}, + + { "Code39", gl_barcode_gnubarcode_new, + TRUE, TRUE, TRUE, TRUE, "0000000000"}, + + { "Code128", gl_barcode_gnubarcode_new, + TRUE, TRUE, TRUE, TRUE, "0000000000"}, + + { "Code128C", gl_barcode_gnubarcode_new, + TRUE, TRUE, TRUE, TRUE, "0000000000"}, + + { "Code128B", gl_barcode_gnubarcode_new, + TRUE, TRUE, TRUE, TRUE, "0000000000"}, + + { "I25", gl_barcode_gnubarcode_new, + TRUE, TRUE, TRUE, TRUE, "0000000000"}, + + { "CBR", gl_barcode_gnubarcode_new, + TRUE, TRUE, TRUE, TRUE, "0000000000"}, + + { "MSI", gl_barcode_gnubarcode_new, + TRUE, TRUE, TRUE, TRUE, "0000000000"}, + + { "PLS", gl_barcode_gnubarcode_new, + TRUE, TRUE, TRUE, TRUE, "0000000000"}, + +}; + +/*========================================================*/ +/* Private function prototypes. */ +/*========================================================*/ + /*****************************************************************************/ /* Call appropriate barcode backend to create barcode in intermediate format.*/ @@ -33,30 +101,26 @@ glBarcode * gl_barcode_new (glBarcodeStyle style, gboolean text_flag, - gdouble scale, + gboolean checksum_flag, + gdouble w, + gdouble h, gchar *digits) { glBarcode *gbc; - switch (style) { + g_return_val_if_fail ((style>=0) && (stylenext) { + g_free (p->data); + p->data = NULL; + } + + g_list_free (styles_list); +} + + /*****************************************************************************/ /* Return an appropriate set of digits for the given barcode style. */ /*****************************************************************************/ gchar * gl_barcode_default_digits (glBarcodeStyle style) { - switch (style) { - - case GL_BARCODE_STYLE_POSTNET: - return g_strdup ("000000000"); - case GL_BARCODE_STYLE_EAN: - return g_strdup ("000000000000 00000"); - case GL_BARCODE_STYLE_UPC: - return g_strdup ("00000000000 00000"); - case GL_BARCODE_STYLE_ISBN: - return g_strdup ("0-00000-000-0 00000"); - case GL_BARCODE_STYLE_39: - case GL_BARCODE_STYLE_128: - case GL_BARCODE_STYLE_128C: - case GL_BARCODE_STYLE_128B: - case GL_BARCODE_STYLE_I25: - case GL_BARCODE_STYLE_CBR: - case GL_BARCODE_STYLE_MSI: - case GL_BARCODE_STYLE_PLS: - return g_strdup ("0000000000"); - default: - return g_strdup ("0"); - } + g_return_val_if_fail ((style>=0) && (style=0) && (style=0) && (style=0) && (style=0) && (style=0) && (style. + * Copyright (C) 2001-2003 Jim Evins . * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -36,10 +36,11 @@ typedef enum { GL_BARCODE_STYLE_128C, GL_BARCODE_STYLE_128B, GL_BARCODE_STYLE_I25, - GL_BARCODE_STYLE_128RAW, GL_BARCODE_STYLE_CBR, GL_BARCODE_STYLE_MSI, GL_BARCODE_STYLE_PLS, + + GL_BARCODE_N_STYLES } glBarcodeStyle; typedef struct { @@ -57,21 +58,40 @@ typedef struct { GList *chars; /* List of glBarcodeChar */ } glBarcode; +typedef glBarcode *(*glBarcodeNewFunc) (glBarcodeStyle style, + gboolean text_flag, + gboolean checksum_flag, + gdouble w, + gdouble h, + gchar *digits); + + #define GL_BARCODE_FONT_FAMILY "Helvetica" #define GL_BARCODE_FONT_WEIGHT GNOME_FONT_BOOK -glBarcode *gl_barcode_new (glBarcodeStyle style, - gboolean text_flag, - gdouble scale, - gchar *digits); +glBarcode *gl_barcode_new (glBarcodeStyle style, + gboolean text_flag, + gboolean checksum_flag, + gdouble w, + gdouble h, + gchar *digits); + +void gl_barcode_free (glBarcode **bc); + +GList *gl_barcode_get_styles_list (void); +void gl_barcode_free_styles_list (GList *styles_list); + +gchar *gl_barcode_default_digits (glBarcodeStyle style); -void gl_barcode_free (glBarcode **bc); +gboolean gl_barcode_can_text (glBarcodeStyle style); +gboolean gl_barcode_text_optional (glBarcodeStyle style); -gchar *gl_barcode_default_digits (glBarcodeStyle style); +gboolean gl_barcode_can_csum (glBarcodeStyle style); +gboolean gl_barcode_csum_optional (glBarcodeStyle style); -const gchar *gl_barcode_style_to_text (glBarcodeStyle style); -glBarcodeStyle gl_barcode_text_to_style (const gchar *text); +const gchar *gl_barcode_style_to_text (glBarcodeStyle style); +glBarcodeStyle gl_barcode_text_to_style (const gchar *text); G_END_DECLS diff --git a/glabels2/src/label-barcode.c b/glabels2/src/label-barcode.c index c907d193..e0ae915f 100644 --- a/glabels2/src/label-barcode.c +++ b/glabels2/src/label-barcode.c @@ -42,14 +42,14 @@ struct _glLabelBarcodePrivate { glBarcodeStyle style; guint color; gboolean text_flag; - gdouble scale; + gboolean checksum_flag; }; /*========================================================*/ /* Private globals. */ /*========================================================*/ -static GObjectClass *parent_class = NULL; +static glLabelObjectClass *parent_class = NULL; static guint instance = 0; @@ -159,6 +159,7 @@ copy (glLabelObject *dst_object, glTextNode *text_node; glBarcodeStyle style; gboolean text_flag; + gboolean checksum_flag; guint color; gdouble scale; @@ -168,10 +169,10 @@ copy (glLabelObject *dst_object, g_return_if_fail (new_lbc && GL_IS_LABEL_BARCODE (new_lbc)); text_node = gl_label_barcode_get_data (lbc); - gl_label_barcode_get_props (lbc, &style, &text_flag, &color, &scale); + gl_label_barcode_get_props (lbc, &style, &text_flag, &checksum_flag, &color); gl_label_barcode_set_data (new_lbc, text_node); - gl_label_barcode_set_props (new_lbc,style, text_flag, color, scale); + gl_label_barcode_set_props (new_lbc,style, text_flag, checksum_flag, color); gl_text_node_free (&text_node); @@ -202,8 +203,8 @@ void gl_label_barcode_set_props (glLabelBarcode *lbc, glBarcodeStyle style, gboolean text_flag, - guint color, - gdouble scale) + gboolean checksum_flag, + guint color) { gl_debug (DEBUG_LABEL, "START"); @@ -211,8 +212,8 @@ gl_label_barcode_set_props (glLabelBarcode *lbc, lbc->private->style = style; lbc->private->text_flag = text_flag; + lbc->private->checksum_flag = checksum_flag; lbc->private->color = color; - lbc->private->scale = scale; gl_label_object_emit_changed (GL_LABEL_OBJECT(lbc)); @@ -235,15 +236,15 @@ void gl_label_barcode_get_props (glLabelBarcode *lbc, glBarcodeStyle *style, gboolean *text_flag, - guint *color, - gdouble *scale) + gboolean *checksum_flag, + guint *color) { g_return_if_fail (lbc && GL_IS_LABEL_BARCODE (lbc)); *style = lbc->private->style; *text_flag = lbc->private->text_flag; + *checksum_flag = lbc->private->checksum_flag; *color = lbc->private->color; - *scale = lbc->private->scale; } /*---------------------------------------------------------------------------*/ @@ -256,22 +257,45 @@ get_size (glLabelObject *object, { glLabelBarcode *lbc = (glLabelBarcode *)object; gchar *data; + gdouble w_parent, h_parent; glBarcode *gbc; gl_debug (DEBUG_LABEL, "START"); g_return_if_fail (lbc && GL_IS_LABEL_BARCODE (lbc)); - data = gl_barcode_default_digits (lbc->private->style); + (* parent_class->get_size) (object, &w_parent, &h_parent); + + + if (lbc->private->text_node->field_flag) { + data = gl_barcode_default_digits (lbc->private->style); + } else { + data = gl_text_node_expand (lbc->private->text_node, NULL); + } + gbc = gl_barcode_new (lbc->private->style, lbc->private->text_flag, - lbc->private->scale, + lbc->private->checksum_flag, + w_parent, + h_parent, data); + if ( gbc == NULL ) { + /* Try again with default digits. */ + data = gl_barcode_default_digits (lbc->private->style); + gbc = gl_barcode_new (lbc->private->style, + lbc->private->text_flag, + lbc->private->checksum_flag, + w_parent, + h_parent, + data); + } + *w = gbc->width; *h = gbc->height; gl_barcode_free (&gbc); + g_free (data); gl_debug (DEBUG_LABEL, "END"); } diff --git a/glabels2/src/label-barcode.h b/glabels2/src/label-barcode.h index cbe773a5..4fbecea0 100644 --- a/glabels2/src/label-barcode.h +++ b/glabels2/src/label-barcode.h @@ -63,15 +63,15 @@ void gl_label_barcode_set_data (glLabelBarcode *lbc, void gl_label_barcode_set_props (glLabelBarcode *lbc, glBarcodeStyle style, gboolean text_flag, - guint color, - gdouble scale); + gboolean checksum_flag, + guint color); glTextNode *gl_label_barcode_get_data (glLabelBarcode *lbc); void gl_label_barcode_get_props (glLabelBarcode *lbc, glBarcodeStyle *style, gboolean *text_flag, - guint *color, - gdouble *scale); + gboolean *checksum_flag, + guint *color); G_END_DECLS diff --git a/glabels2/src/print.c b/glabels2/src/print.c index 1807d959..0e62f215 100644 --- a/glabels2/src/print.c +++ b/glabels2/src/print.c @@ -875,17 +875,19 @@ draw_barcode_object (PrintInfo *pi, glTextNode *text_node; glBarcodeStyle style; gboolean text_flag; + gboolean checksum_flag; guint color; - gdouble scale; + gdouble w, h; gl_debug (DEBUG_PRINT, "START"); text_node = gl_label_barcode_get_data (object); gl_label_barcode_get_props (object, - &style, &text_flag, &color, &scale); + &style, &text_flag, &checksum_flag, &color); + gl_label_object_get_size (GL_LABEL_OBJECT(object), &w, &h); text = gl_text_node_expand (text_node, record); - gbc = gl_barcode_new (style, text_flag, scale, text); + gbc = gl_barcode_new (style, text_flag, checksum_flag, w, h, text); g_free (text); gl_text_node_free (&text_node); diff --git a/glabels2/src/view-barcode.c b/glabels2/src/view-barcode.c index e22bfc5a..a2312d13 100644 --- a/glabels2/src/view-barcode.c +++ b/glabels2/src/view-barcode.c @@ -199,7 +199,7 @@ gl_view_barcode_new (glLabelBarcode *object, gl_view_object_set_view (GL_VIEW_OBJECT(view_barcode), view); gl_view_object_set_object (GL_VIEW_OBJECT(view_barcode), GL_LABEL_OBJECT(object), - GL_VIEW_HIGHLIGHT_SIMPLE); + GL_VIEW_HIGHLIGHT_BOX_RESIZABLE); /* Create analogous canvas items. */ draw_barcode (view_barcode); @@ -245,8 +245,8 @@ construct_properties_dialog (glViewObject *view_object) glTextNode *text_node; glBarcodeStyle style; gboolean text_flag; + gboolean checksum_flag; guint color; - gdouble scale; glMerge *merge; GtkSizeGroup *label_size_group; GtkWidget *window; @@ -258,7 +258,7 @@ construct_properties_dialog (glViewObject *view_object) gl_label_object_get_position (GL_LABEL_OBJECT(object), &x, &y); text_node = gl_label_barcode_get_data(GL_LABEL_BARCODE(object)); gl_label_barcode_get_props (GL_LABEL_BARCODE(object), - &style, &text_flag, &color, &scale); + &style, &text_flag, &checksum_flag, &color); gl_label_get_size (GL_LABEL(object->parent), &label_width, &label_height); merge = gl_label_get_merge (GL_LABEL(object->parent)); @@ -311,7 +311,7 @@ construct_properties_dialog (glViewObject *view_object) gl_wdgt_bc_style_set_label_size_group (GL_WDGT_BC_STYLE(view_barcode->private->bc_style), label_size_group); gl_wdgt_bc_style_set_params (GL_WDGT_BC_STYLE (view_barcode->private->bc_style), - style, text_flag); + style, text_flag, checksum_flag); gl_hig_category_add_widget (GL_HIG_CATEGORY(wsection), view_barcode->private->bc_style); g_signal_connect (G_OBJECT (view_barcode->private->bc_style), @@ -324,7 +324,7 @@ construct_properties_dialog (glViewObject *view_object) gl_wdgt_bc_props_set_label_size_group (GL_WDGT_BC_PROPS(view_barcode->private->bc_props), label_size_group); gl_wdgt_bc_props_set_params (GL_WDGT_BC_PROPS(view_barcode->private->bc_props), - scale, color); + color); gl_hig_category_add_widget (GL_HIG_CATEGORY(wsection), view_barcode->private->bc_props); g_signal_connect ( G_OBJECT(view_barcode->private->bc_props), @@ -439,22 +439,21 @@ bc_props_changed_cb (glWdgtBCProps *text_props, glLabelObject *object; glBarcodeStyle style; gboolean text_flag; + gboolean checksum_flag; guint color; - gdouble scale; - gl_debug (DEBUG_VIEW, "START"); object = gl_view_object_get_object (GL_VIEW_OBJECT(view_barcode)); gl_label_barcode_get_props (GL_LABEL_BARCODE(object), - &style, &text_flag, &color, &scale); - gl_wdgt_bc_props_get_params (text_props, &scale, &color); + &style, &text_flag, &checksum_flag, &color); + gl_wdgt_bc_props_get_params (text_props, &color); g_signal_handlers_block_by_func (G_OBJECT(object), update_dialog_cb, view_barcode); gl_label_barcode_set_props (GL_LABEL_BARCODE(object), - style, text_flag, color, scale); + style, text_flag, checksum_flag, color); g_signal_handlers_unblock_by_func (G_OBJECT(object), update_dialog_cb, view_barcode); @@ -471,8 +470,8 @@ bc_style_changed_cb (glWdgtBCStyle *bc_style, glLabelObject *object; glBarcodeStyle style; gboolean text_flag; + gboolean checksum_flag; guint color; - gdouble scale; gl_debug (DEBUG_VIEW, "START"); @@ -480,13 +479,13 @@ bc_style_changed_cb (glWdgtBCStyle *bc_style, object = gl_view_object_get_object (GL_VIEW_OBJECT(view_barcode)); gl_label_barcode_get_props (GL_LABEL_BARCODE(object), - &style, &text_flag, &color, &scale); - gl_wdgt_bc_style_get_params (bc_style, &style, &text_flag); + &style, &text_flag, &checksum_flag, &color); + gl_wdgt_bc_style_get_params (bc_style, &style, &text_flag, &checksum_flag); g_signal_handlers_block_by_func (G_OBJECT(object), update_dialog_cb, view_barcode); gl_label_barcode_set_props (GL_LABEL_BARCODE(object), - style, text_flag, color, scale); + style, text_flag, checksum_flag, color); g_signal_handlers_unblock_by_func (G_OBJECT(object), update_dialog_cb, view_barcode); @@ -498,7 +497,7 @@ bc_style_changed_cb (glWdgtBCStyle *bc_style, /*---------------------------------------------------------------------------*/ static void position_changed_cb (glWdgtPosition *position, - glViewBarcode *view_barcode) + glViewBarcode *view_barcode) { glLabelObject *object; gdouble x, y; @@ -529,8 +528,8 @@ update_dialog_cb (glLabelObject *object, glTextNode *text_node; glBarcodeStyle style; gboolean text_flag; + gboolean checksum_flag; guint color; - gdouble scale; glMerge *merge; gl_debug (DEBUG_VIEW, "START"); @@ -538,7 +537,7 @@ update_dialog_cb (glLabelObject *object, /* Query properties of object. */ text_node = gl_label_barcode_get_data(GL_LABEL_BARCODE(object)); gl_label_barcode_get_props (GL_LABEL_BARCODE(object), - &style, &text_flag, &color, &scale); + &style, &text_flag, &checksum_flag, &color); gl_label_object_get_position (GL_LABEL_OBJECT(object), &x, &y); merge = gl_label_get_merge (GL_LABEL(object->parent)); @@ -560,9 +559,9 @@ update_dialog_cb (glLabelObject *object, gl_wdgt_bc_data_set_field_defs (GL_WDGT_BC_DATA(view_barcode->private->bc_data), merge); gl_wdgt_bc_props_set_params (GL_WDGT_BC_PROPS(view_barcode->private->bc_props), - scale, color); + color); gl_wdgt_bc_style_set_params (GL_WDGT_BC_STYLE(view_barcode->private->bc_style), - style, text_flag); + style, text_flag, checksum_flag); gl_wdgt_position_set_position (GL_WDGT_POSITION(view_barcode->private->position), x, y); @@ -753,8 +752,9 @@ draw_barcode (glViewBarcode *view_barcode) glTextNode *text_node; glBarcodeStyle style; gboolean text_flag; + gboolean checksum_flag; guint color; - gdouble scale; + gdouble w, h; glBarcodeLine *line; glBarcodeChar *bchar; glBarcode *gbc; @@ -771,7 +771,8 @@ draw_barcode (glViewBarcode *view_barcode) /* Query label object and properties */ object = gl_view_object_get_object (GL_VIEW_OBJECT(view_barcode)); gl_label_barcode_get_props (GL_LABEL_BARCODE(object), - &style, &text_flag, &color, &scale); + &style, &text_flag, &checksum_flag, &color); + gl_label_object_get_size (object, &w, &h); text_node = gl_label_barcode_get_data(GL_LABEL_BARCODE(object)); if (text_node->field_flag) { digits = gl_barcode_default_digits (style); @@ -795,7 +796,7 @@ draw_barcode (glViewBarcode *view_barcode) FALSE, 10.0); - gbc = gl_barcode_new (style, text_flag, scale, digits); + gbc = gl_barcode_new (style, text_flag, checksum_flag, w, h, digits); if (gbc == NULL) { cstring = _("Invalid barcode"); diff --git a/glabels2/src/view-highlight.c b/glabels2/src/view-highlight.c index d25b10f8..5274656b 100644 --- a/glabels2/src/view-highlight.c +++ b/glabels2/src/view-highlight.c @@ -102,6 +102,14 @@ static void update_resizable_line (glViewHighlight *view_h static void update_simple (glViewHighlight *view_highlight); +static void get_origin_and_corners (glViewHighlight *view_highlight, + gdouble *x0, + gdouble *y0, + gdouble *x1, + gdouble *y1, + gdouble *x2, + gdouble *y2); + static int tl_resize_event_handler (GnomeCanvasItem *handle_item, GdkEvent *event, glViewHighlight *view_highlight); @@ -929,7 +937,36 @@ update_simple (glViewHighlight *view_highlight) } /*---------------------------------------------------------------------------*/ -/* PRIVATE. "Top-left" Resize event handler. */ +/* PRIVATE. Get origin and corners relative to object. */ +/*---------------------------------------------------------------------------*/ +static void +get_origin_and_corners (glViewHighlight *view_highlight, + gdouble *x0, + gdouble *y0, + gdouble *x1, + gdouble *y1, + gdouble *x2, + gdouble *y2) +{ + glLabelObject *object; + + object = view_highlight->private->object;; + + /* origin, relative to item */ + gl_label_object_get_position (object, x0, y0); + gnome_canvas_item_w2i (view_highlight->private->group, x0, y0); + + /* Top left corner, relative to item */ + *x1 = 0.0; + *y1 = 0.0; + + /* Bottom right corner, relative to item */ + gl_label_object_get_size (object, x2, y2); +} + + +/*---------------------------------------------------------------------------*/ +/* PRIVATE. "Top-left" Resize event handler. */ /*---------------------------------------------------------------------------*/ static int tl_resize_event_handler (GnomeCanvasItem *handle_item, @@ -949,18 +986,6 @@ tl_resize_event_handler (GnomeCanvasItem *handle_item, object = view_highlight->private->object;; - /* origin, relative to item */ - gl_label_object_get_position (object, &x0, &y0); - gnome_canvas_item_w2i (view_highlight->private->group, &x0, &y0); - - /* Top left corner, relative to item */ - x1 = 0.0; - y1 = 0.0; - - /* Bottom right corner, relative to item */ - gl_label_object_get_size (object, &x2, &y2); - - switch (event->type) { case GDK_BUTTON_PRESS: @@ -982,6 +1007,8 @@ tl_resize_event_handler (GnomeCanvasItem *handle_item, switch (event->button.button) { case 1: dragging = FALSE; + get_origin_and_corners (view_highlight, + &x0, &y0, &x1, &y1, &x2, &y2); gnome_canvas_item_ungrab (handle_item, event->button.time); gnome_canvas_item_w2i (view_highlight->private->group, @@ -1003,6 +1030,8 @@ tl_resize_event_handler (GnomeCanvasItem *handle_item, case GDK_MOTION_NOTIFY: if (dragging && (event->motion.state & GDK_BUTTON1_MASK)) { + get_origin_and_corners (view_highlight, + &x0, &y0, &x1, &y1, &x2, &y2); gnome_canvas_item_w2i (view_highlight->private->group, &event->button.x, &event->button.y); x1 = MIN (event->motion.x, x2 - MIN_ITEM_SIZE); @@ -1060,18 +1089,6 @@ tr_resize_event_handler (GnomeCanvasItem *handle_item, object = view_highlight->private->object;; - /* origin, relative to item */ - gl_label_object_get_position (object, &x0, &y0); - gnome_canvas_item_w2i (view_highlight->private->group, &x0, &y0); - - /* Top left corner, relative to item */ - x1 = 0.0; - y1 = 0.0; - - /* Bottom right corner, relative to item */ - gl_label_object_get_size (object, &x2, &y2); - - switch (event->type) { case GDK_BUTTON_PRESS: @@ -1093,6 +1110,8 @@ tr_resize_event_handler (GnomeCanvasItem *handle_item, switch (event->button.button) { case 1: dragging = FALSE; + get_origin_and_corners (view_highlight, + &x0, &y0, &x1, &y1, &x2, &y2); gnome_canvas_item_ungrab (handle_item, event->button.time); gnome_canvas_item_w2i (view_highlight->private->group, @@ -1114,6 +1133,8 @@ tr_resize_event_handler (GnomeCanvasItem *handle_item, case GDK_MOTION_NOTIFY: if (dragging && (event->motion.state & GDK_BUTTON1_MASK)) { + get_origin_and_corners (view_highlight, + &x0, &y0, &x1, &y1, &x2, &y2); gnome_canvas_item_w2i (view_highlight->private->group, &event->button.x, &event->button.y); /* x1 unchanged */ @@ -1171,18 +1192,6 @@ bl_resize_event_handler (GnomeCanvasItem *handle_item, object = view_highlight->private->object;; - /* origin, relative to item */ - gl_label_object_get_position (object, &x0, &y0); - gnome_canvas_item_w2i (view_highlight->private->group, &x0, &y0); - - /* Top left corner, relative to item */ - x1 = 0.0; - y1 = 0.0; - - /* Bottom right corner, relative to item */ - gl_label_object_get_size (object, &x2, &y2); - - switch (event->type) { case GDK_BUTTON_PRESS: @@ -1204,6 +1213,8 @@ bl_resize_event_handler (GnomeCanvasItem *handle_item, switch (event->button.button) { case 1: dragging = FALSE; + get_origin_and_corners (view_highlight, + &x0, &y0, &x1, &y1, &x2, &y2); gnome_canvas_item_ungrab (handle_item, event->button.time); gnome_canvas_item_w2i (view_highlight->private->group, @@ -1225,6 +1236,8 @@ bl_resize_event_handler (GnomeCanvasItem *handle_item, case GDK_MOTION_NOTIFY: if (dragging && (event->motion.state & GDK_BUTTON1_MASK)) { + get_origin_and_corners (view_highlight, + &x0, &y0, &x1, &y1, &x2, &y2); gnome_canvas_item_w2i (view_highlight->private->group, &event->button.x, &event->button.y); x1 = MIN (event->button.x, x2 - MIN_ITEM_SIZE); @@ -1282,18 +1295,6 @@ br_resize_event_handler (GnomeCanvasItem *handle_item, object = view_highlight->private->object;; - /* origin, relative to item */ - gl_label_object_get_position (object, &x0, &y0); - gnome_canvas_item_w2i (view_highlight->private->group, &x0, &y0); - - /* Top left corner, relative to item */ - x1 = 0.0; - y1 = 0.0; - - /* Bottom right corner, relative to item */ - gl_label_object_get_size (object, &x2, &y2); - - switch (event->type) { case GDK_BUTTON_PRESS: @@ -1317,6 +1318,8 @@ br_resize_event_handler (GnomeCanvasItem *handle_item, switch (event->button.button) { case 1: dragging = FALSE; + get_origin_and_corners (view_highlight, + &x0, &y0, &x1, &y1, &x2, &y2); gnome_canvas_item_ungrab (handle_item, event->button.time); gnome_canvas_item_w2i (view_highlight->private->group, @@ -1339,6 +1342,8 @@ br_resize_event_handler (GnomeCanvasItem *handle_item, case GDK_MOTION_NOTIFY: gl_debug (DEBUG_VIEW, "MOTION_NOTIFY"); if (dragging && (event->motion.state & GDK_BUTTON1_MASK)) { + get_origin_and_corners (view_highlight, + &x0, &y0, &x1, &y1, &x2, &y2); gnome_canvas_item_w2i (view_highlight->private->group, &event->button.x, &event->button.y); /* x1 unchanged */ @@ -1399,18 +1404,6 @@ sl_resize_event_handler (GnomeCanvasItem *handle_item, object = view_highlight->private->object;; - /* origin, relative to item */ - gl_label_object_get_position (object, &x0, &y0); - gnome_canvas_item_w2i (view_highlight->private->group, &x0, &y0); - - /* Top left corner, relative to item */ - x1 = 0.0; - y1 = 0.0; - - /* Bottom right corner, relative to item */ - gl_label_object_get_size (object, &x2, &y2); - - switch (event->type) { case GDK_BUTTON_PRESS: @@ -1432,6 +1425,8 @@ sl_resize_event_handler (GnomeCanvasItem *handle_item, switch (event->button.button) { case 1: dragging = FALSE; + get_origin_and_corners (view_highlight, + &x0, &y0, &x1, &y1, &x2, &y2); gnome_canvas_item_ungrab (handle_item, event->button.time); gnome_canvas_item_w2i (view_highlight->private->group, @@ -1453,6 +1448,8 @@ sl_resize_event_handler (GnomeCanvasItem *handle_item, case GDK_MOTION_NOTIFY: if (dragging && (event->motion.state & GDK_BUTTON1_MASK)) { + get_origin_and_corners (view_highlight, + &x0, &y0, &x1, &y1, &x2, &y2); gnome_canvas_item_w2i (view_highlight->private->group, &event->button.x, &event->button.y); x1 = MIN (event->button.x, x2 - MIN_ITEM_SIZE); @@ -1510,18 +1507,6 @@ sr_resize_event_handler (GnomeCanvasItem *handle_item, object = view_highlight->private->object;; - /* origin, relative to item */ - gl_label_object_get_position (object, &x0, &y0); - gnome_canvas_item_w2i (view_highlight->private->group, &x0, &y0); - - /* Top left corner, relative to item */ - x1 = 0.0; - y1 = 0.0; - - /* Bottom right corner, relative to item */ - gl_label_object_get_size (object, &x2, &y2); - - switch (event->type) { case GDK_BUTTON_PRESS: @@ -1543,6 +1528,8 @@ sr_resize_event_handler (GnomeCanvasItem *handle_item, switch (event->button.button) { case 1: dragging = FALSE; + get_origin_and_corners (view_highlight, + &x0, &y0, &x1, &y1, &x2, &y2); gnome_canvas_item_ungrab (handle_item, event->button.time); gnome_canvas_item_w2i (view_highlight->private->group, @@ -1564,6 +1551,8 @@ sr_resize_event_handler (GnomeCanvasItem *handle_item, case GDK_MOTION_NOTIFY: if (dragging && (event->motion.state & GDK_BUTTON1_MASK)) { + get_origin_and_corners (view_highlight, + &x0, &y0, &x1, &y1, &x2, &y2); gnome_canvas_item_w2i (view_highlight->private->group, &event->button.x, &event->button.y); /* x1 unchanged */ @@ -1621,18 +1610,6 @@ st_resize_event_handler (GnomeCanvasItem *handle_item, object = view_highlight->private->object;; - /* origin, relative to item */ - gl_label_object_get_position (object, &x0, &y0); - gnome_canvas_item_w2i (view_highlight->private->group, &x0, &y0); - - /* Top left corner, relative to item */ - x1 = 0.0; - y1 = 0.0; - - /* Bottom right corner, relative to item */ - gl_label_object_get_size (object, &x2, &y2); - - switch (event->type) { case GDK_BUTTON_PRESS: @@ -1654,6 +1631,8 @@ st_resize_event_handler (GnomeCanvasItem *handle_item, switch (event->button.button) { case 1: dragging = FALSE; + get_origin_and_corners (view_highlight, + &x0, &y0, &x1, &y1, &x2, &y2); gnome_canvas_item_ungrab (handle_item, event->button.time); gnome_canvas_item_w2i (view_highlight->private->group, @@ -1675,6 +1654,8 @@ st_resize_event_handler (GnomeCanvasItem *handle_item, case GDK_MOTION_NOTIFY: if (dragging && (event->motion.state & GDK_BUTTON1_MASK)) { + get_origin_and_corners (view_highlight, + &x0, &y0, &x1, &y1, &x2, &y2); gnome_canvas_item_w2i (view_highlight->private->group, &event->button.x, &event->button.y); /* x1 unchanged */ @@ -1732,18 +1713,6 @@ sb_resize_event_handler (GnomeCanvasItem *handle_item, object = view_highlight->private->object;; - /* origin, relative to item */ - gl_label_object_get_position (object, &x0, &y0); - gnome_canvas_item_w2i (view_highlight->private->group, &x0, &y0); - - /* Top left corner, relative to item */ - x1 = 0.0; - y1 = 0.0; - - /* Bottom right corner, relative to item */ - gl_label_object_get_size (object, &x2, &y2); - - switch (event->type) { case GDK_BUTTON_PRESS: @@ -1765,6 +1734,8 @@ sb_resize_event_handler (GnomeCanvasItem *handle_item, switch (event->button.button) { case 1: dragging = FALSE; + get_origin_and_corners (view_highlight, + &x0, &y0, &x1, &y1, &x2, &y2); gnome_canvas_item_ungrab (handle_item, event->button.time); gnome_canvas_item_w2i (view_highlight->private->group, @@ -1786,6 +1757,8 @@ sb_resize_event_handler (GnomeCanvasItem *handle_item, case GDK_MOTION_NOTIFY: if (dragging && (event->motion.state & GDK_BUTTON1_MASK)) { + get_origin_and_corners (view_highlight, + &x0, &y0, &x1, &y1, &x2, &y2); gnome_canvas_item_w2i (view_highlight->private->group, &event->button.x, &event->button.y); /* x1 unchanged */ @@ -1843,18 +1816,6 @@ p1_resize_event_handler (GnomeCanvasItem *handle_item, object = view_highlight->private->object;; - /* origin, relative to item */ - gl_label_object_get_position (object, &x0, &y0); - gnome_canvas_item_w2i (view_highlight->private->group, &x0, &y0); - - /* Top left corner, relative to item */ - x1 = 0.0; - y1 = 0.0; - - /* Bottom right corner, relative to item */ - gl_label_object_get_size (object, &x2, &y2); - - switch (event->type) { case GDK_BUTTON_PRESS: @@ -1876,6 +1837,8 @@ p1_resize_event_handler (GnomeCanvasItem *handle_item, switch (event->button.button) { case 1: dragging = FALSE; + get_origin_and_corners (view_highlight, + &x0, &y0, &x1, &y1, &x2, &y2); gnome_canvas_item_ungrab (handle_item, event->button.time); gnome_canvas_item_w2i (view_highlight->private->group, @@ -1897,6 +1860,8 @@ p1_resize_event_handler (GnomeCanvasItem *handle_item, case GDK_MOTION_NOTIFY: if (dragging && (event->motion.state & GDK_BUTTON1_MASK)) { + get_origin_and_corners (view_highlight, + &x0, &y0, &x1, &y1, &x2, &y2); gnome_canvas_item_w2i (view_highlight->private->group, &event->button.x, &event->button.y); x1 = event->button.x; @@ -1954,18 +1919,6 @@ p2_resize_event_handler (GnomeCanvasItem *handle_item, object = view_highlight->private->object;; - /* origin, relative to item */ - gl_label_object_get_position (object, &x0, &y0); - gnome_canvas_item_w2i (view_highlight->private->group, &x0, &y0); - - /* Top left corner, relative to item */ - x1 = 0.0; - y1 = 0.0; - - /* Bottom right corner, relative to item */ - gl_label_object_get_size (object, &x2, &y2); - - switch (event->type) { case GDK_BUTTON_PRESS: @@ -1987,6 +1940,8 @@ p2_resize_event_handler (GnomeCanvasItem *handle_item, switch (event->button.button) { case 1: dragging = FALSE; + get_origin_and_corners (view_highlight, + &x0, &y0, &x1, &y1, &x2, &y2); gnome_canvas_item_ungrab (handle_item, event->button.time); gnome_canvas_item_w2i (view_highlight->private->group, @@ -2008,6 +1963,8 @@ p2_resize_event_handler (GnomeCanvasItem *handle_item, case GDK_MOTION_NOTIFY: if (dragging && (event->motion.state & GDK_BUTTON1_MASK)) { + get_origin_and_corners (view_highlight, + &x0, &y0, &x1, &y1, &x2, &y2); gnome_canvas_item_w2i (view_highlight->private->group, &event->button.x, &event->button.y); /* x1 unchanged */ diff --git a/glabels2/src/wdgt-bc-props.c b/glabels2/src/wdgt-bc-props.c index a81aa8a9..e0169fb0 100644 --- a/glabels2/src/wdgt-bc-props.c +++ b/glabels2/src/wdgt-bc-props.c @@ -113,7 +113,6 @@ gl_wdgt_bc_props_class_init (glWdgtBCPropsClass *class) static void gl_wdgt_bc_props_instance_init (glWdgtBCProps *prop) { - prop->scale_spin = NULL; prop->color_picker = NULL; } @@ -157,29 +156,6 @@ gl_wdgt_bc_props_construct (glWdgtBCProps *prop) wvbox = GTK_WIDGET (prop); - /* ---- Scale line ---- */ - whbox = gl_hig_hbox_new (); - gl_hig_vbox_add_widget (GL_HIG_VBOX(wvbox), whbox); - - /* Scale Label */ - prop->scale_label = gtk_label_new (_("Scale:")); - gtk_misc_set_alignment (GTK_MISC (prop->scale_label), 0, 0.5); - gl_hig_hbox_add_widget (GL_HIG_HBOX(whbox), prop->scale_label); - - /* Scale widget */ - adjust = gtk_adjustment_new (100.0, 50.0, 200.0, 10.0, 10.0, 10.0); - prop->scale_spin = - gtk_spin_button_new (GTK_ADJUSTMENT (adjust), 10.0, 0); - g_signal_connect_swapped (G_OBJECT (prop->scale_spin), "changed", - G_CALLBACK (changed_cb), - G_OBJECT (prop)); - gl_hig_hbox_add_widget (GL_HIG_HBOX(whbox), prop->scale_spin); - - /* scale % Label */ - wlabel = gtk_label_new (_("%")); - gtk_misc_set_alignment (GTK_MISC (wlabel), 0, 0.5); - gl_hig_hbox_add_widget (GL_HIG_HBOX(whbox), wlabel); - /* ---- Color line ---- */ whbox = gl_hig_hbox_new (); gl_hig_vbox_add_widget (GL_HIG_VBOX(wvbox), whbox); @@ -212,16 +188,10 @@ changed_cb (glWdgtBCProps *prop) /***************************************************************************/ void gl_wdgt_bc_props_get_params (glWdgtBCProps *prop, - gdouble *scale, guint *color) { guint8 r, g, b, a; - /* ------- Get updated scale ------ */ - *scale = - gtk_spin_button_get_value (GTK_SPIN_BUTTON(prop->scale_spin)); - *scale /= 100.0; - /* ------- Get updated line color ------ */ gnome_color_picker_get_i8 (GNOME_COLOR_PICKER (prop->color_picker), &r, &g, &b, &a); @@ -234,12 +204,8 @@ gl_wdgt_bc_props_get_params (glWdgtBCProps *prop, /***************************************************************************/ void gl_wdgt_bc_props_set_params (glWdgtBCProps *prop, - gdouble scale, guint color) { - scale *= 100.0; - gtk_spin_button_set_value (GTK_SPIN_BUTTON (prop->scale_spin), scale); - gnome_color_picker_set_i8 (GNOME_COLOR_PICKER (prop->color_picker), GL_COLOR_I_RED (color), GL_COLOR_I_GREEN (color), @@ -254,7 +220,6 @@ void gl_wdgt_bc_props_set_label_size_group (glWdgtBCProps *prop, GtkSizeGroup *label_size_group) { - gtk_size_group_add_widget (label_size_group, prop->scale_label); gtk_size_group_add_widget (label_size_group, prop->color_label); } diff --git a/glabels2/src/wdgt-bc-props.h b/glabels2/src/wdgt-bc-props.h index dfa5b69b..fd588e31 100644 --- a/glabels2/src/wdgt-bc-props.h +++ b/glabels2/src/wdgt-bc-props.h @@ -45,9 +45,6 @@ typedef struct _glWdgtBCPropsClass glWdgtBCPropsClass; struct _glWdgtBCProps { glHigVBox parent_widget; - GtkWidget *scale_label; - GtkWidget *scale_spin; - GtkWidget *color_label; GtkWidget *color_picker; }; @@ -63,11 +60,9 @@ guint gl_wdgt_bc_props_get_type (void); GtkWidget *gl_wdgt_bc_props_new (void); void gl_wdgt_bc_props_get_params (glWdgtBCProps *prop, - gdouble *scale, guint *color); void gl_wdgt_bc_props_set_params (glWdgtBCProps *prop, - gdouble scale, guint color); void gl_wdgt_bc_props_set_label_size_group (glWdgtBCProps *prop, diff --git a/glabels2/src/wdgt-bc-style.c b/glabels2/src/wdgt-bc-style.c index d19cbe04..0f97455a 100644 --- a/glabels2/src/wdgt-bc-style.c +++ b/glabels2/src/wdgt-bc-style.c @@ -55,7 +55,9 @@ static void gl_wdgt_bc_style_instance_init (glWdgtBCStyle *bc_style); static void gl_wdgt_bc_style_finalize (GObject *object); static void gl_wdgt_bc_style_construct (glWdgtBCStyle *bc_style); -static void changed_cb (glWdgtBCStyle *bc_style); +static void style_changed_cb (glWdgtBCStyle *bc_style); +static void checkbox_changed_cb (glWdgtBCStyle *bc_style); + /****************************************************************************/ /* Boilerplate Object stuff. */ @@ -168,57 +170,80 @@ gl_wdgt_bc_style_construct (glWdgtBCStyle *bc_style) /* Style entry widget */ wcombo = gtk_combo_new (); - style_list = NULL; - style_list = g_list_append (style_list, - (gchar *)gl_barcode_style_to_text(GL_BARCODE_STYLE_POSTNET)); - style_list = g_list_append (style_list, - (gchar *)gl_barcode_style_to_text(GL_BARCODE_STYLE_EAN)); - style_list = g_list_append (style_list, - (gchar *)gl_barcode_style_to_text(GL_BARCODE_STYLE_UPC)); - style_list = g_list_append (style_list, - (gchar *)gl_barcode_style_to_text(GL_BARCODE_STYLE_ISBN)); - style_list = g_list_append (style_list, - (gchar *)gl_barcode_style_to_text(GL_BARCODE_STYLE_39)); - style_list = g_list_append (style_list, - (gchar *)gl_barcode_style_to_text(GL_BARCODE_STYLE_128)); - style_list = g_list_append (style_list, - (gchar *)gl_barcode_style_to_text(GL_BARCODE_STYLE_128B)); - style_list = g_list_append (style_list, - (gchar *)gl_barcode_style_to_text(GL_BARCODE_STYLE_128C)); - style_list = g_list_append (style_list, - (gchar *)gl_barcode_style_to_text(GL_BARCODE_STYLE_I25)); - style_list = g_list_append (style_list, - (gchar *)gl_barcode_style_to_text(GL_BARCODE_STYLE_CBR)); - style_list = g_list_append (style_list, - (gchar *)gl_barcode_style_to_text(GL_BARCODE_STYLE_MSI)); - style_list = g_list_append (style_list, - (gchar *)gl_barcode_style_to_text(GL_BARCODE_STYLE_PLS)); + style_list = gl_barcode_get_styles_list ();; gtk_combo_set_popdown_strings (GTK_COMBO (wcombo), style_list); - g_list_free (style_list); + gl_barcode_free_styles_list (style_list); bc_style->style_entry = GTK_COMBO (wcombo)->entry; gtk_entry_set_editable (GTK_ENTRY (bc_style->style_entry), FALSE); gtk_widget_set_size_request (wcombo, 200, -1); - g_signal_connect_swapped (G_OBJECT (bc_style->style_entry), "changed", - G_CALLBACK (changed_cb), - G_OBJECT (bc_style)); gl_hig_hbox_add_widget (GL_HIG_HBOX(whbox), wcombo); /* Text checkbox widget */ bc_style->text_check = - gtk_check_button_new_with_label (_("Show text with barcode")); + gtk_check_button_new_with_label (_("Text")); gl_hig_vbox_add_widget (GL_HIG_VBOX(wvbox), bc_style->text_check); + + + /* Checksum checkbox widget */ + bc_style->checksum_check = + gtk_check_button_new_with_label (_("Checksum")); + gl_hig_vbox_add_widget (GL_HIG_VBOX(wvbox), bc_style->checksum_check); + + + /* Connect signal callbacks */ + g_signal_connect_swapped (G_OBJECT (bc_style->style_entry), "changed", + G_CALLBACK (style_changed_cb), + G_OBJECT (bc_style)); g_signal_connect_swapped (G_OBJECT (bc_style->text_check), "toggled", - G_CALLBACK (changed_cb), + G_CALLBACK (checkbox_changed_cb), + G_OBJECT (bc_style)); + g_signal_connect_swapped (G_OBJECT (bc_style->checksum_check), "toggled", + G_CALLBACK (checkbox_changed_cb), G_OBJECT (bc_style)); +} +/*--------------------------------------------------------------------------*/ +/* PRIVATE. Callback for when style has changed. */ +/*--------------------------------------------------------------------------*/ +static void +style_changed_cb (glWdgtBCStyle *bc_style) +{ + gchar *style_string; + glBarcodeStyle style; + + style_string = + gtk_editable_get_chars (GTK_EDITABLE(bc_style->style_entry), + 0, -1); + + /* Don't emit if entry is empty. */ + if ( *style_string != 0 ) { + style = gl_barcode_text_to_style (style_string); + + gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON(bc_style->text_check), + gl_barcode_can_text (style)); + gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON(bc_style->checksum_check), + gl_barcode_can_csum (style)); + + gtk_widget_set_sensitive (bc_style->text_check, + gl_barcode_text_optional (style)); + gtk_widget_set_sensitive (bc_style->checksum_check, + gl_barcode_csum_optional (style)); + + + /* Emit our "changed" signal */ + g_signal_emit (G_OBJECT (bc_style), + wdgt_bc_style_signals[CHANGED], 0); + } + + g_free (style_string); } /*--------------------------------------------------------------------------*/ -/* PRIVATE. Callback for when any control in the widget has changed. */ +/* PRIVATE. Callback for when either checkbox has changed. */ /*--------------------------------------------------------------------------*/ static void -changed_cb (glWdgtBCStyle *bc_style) +checkbox_changed_cb (glWdgtBCStyle *bc_style) { /* Emit our "changed" signal */ g_signal_emit (G_OBJECT (bc_style), @@ -231,7 +256,8 @@ changed_cb (glWdgtBCStyle *bc_style) void gl_wdgt_bc_style_get_params (glWdgtBCStyle *bc_style, glBarcodeStyle *style, - gboolean *text_flag) + gboolean *text_flag, + gboolean *checksum_flag) { gchar *style_string; @@ -243,6 +269,9 @@ gl_wdgt_bc_style_get_params (glWdgtBCStyle *bc_style, *text_flag = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (bc_style->text_check)); + *checksum_flag = + gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (bc_style->checksum_check)); + g_free (style_string); } @@ -252,7 +281,8 @@ gl_wdgt_bc_style_get_params (glWdgtBCStyle *bc_style, void gl_wdgt_bc_style_set_params (glWdgtBCStyle *bc_style, glBarcodeStyle style, - gboolean text_flag) + gboolean text_flag, + gboolean checksum_flag) { const gchar *style_string; gint pos; @@ -260,12 +290,12 @@ gl_wdgt_bc_style_set_params (glWdgtBCStyle *bc_style, style_string = gl_barcode_style_to_text (style); g_signal_handlers_block_by_func (G_OBJECT(bc_style->style_entry), - G_CALLBACK (changed_cb), + G_CALLBACK (style_changed_cb), bc_style); gtk_editable_delete_text (GTK_EDITABLE (bc_style->style_entry), 0, -1); g_signal_handlers_unblock_by_func (G_OBJECT(bc_style->style_entry), - G_CALLBACK(changed_cb), + G_CALLBACK(style_changed_cb), bc_style); pos = 0; @@ -277,6 +307,9 @@ gl_wdgt_bc_style_set_params (glWdgtBCStyle *bc_style, gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (bc_style->text_check), text_flag); + gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (bc_style->checksum_check), + checksum_flag); + } /****************************************************************************/ diff --git a/glabels2/src/wdgt-bc-style.h b/glabels2/src/wdgt-bc-style.h index 40d28f40..d02f9074 100644 --- a/glabels2/src/wdgt-bc-style.h +++ b/glabels2/src/wdgt-bc-style.h @@ -49,6 +49,7 @@ struct _glWdgtBCStyle { GtkWidget *style_entry; GtkWidget *text_check; + GtkWidget *checksum_check; }; struct _glWdgtBCStyleClass { @@ -63,11 +64,13 @@ GtkWidget *gl_wdgt_bc_style_new (void); void gl_wdgt_bc_style_get_params (glWdgtBCStyle *bc_style, glBarcodeStyle *style, - gboolean *text_flag); + gboolean *text_flag, + gboolean *checksum_flag); void gl_wdgt_bc_style_set_params (glWdgtBCStyle *bc_style, glBarcodeStyle style, - gboolean text_flag); + gboolean text_flag, + gboolean checksum_flag); void gl_wdgt_bc_style_set_label_size_group (glWdgtBCStyle *bc_style, GtkSizeGroup *label_size_group); diff --git a/glabels2/src/xml-label.c b/glabels2/src/xml-label.c index c1f05a7e..c1445d79 100644 --- a/glabels2/src/xml-label.c +++ b/glabels2/src/xml-label.c @@ -664,8 +664,8 @@ xml_parse_barcode_props (xmlNodePtr node, glTextNode *text_node; glBarcodeStyle style; gboolean text_flag; + gboolean checksum_flag; guint color; - gdouble scale; gl_debug (DEBUG_XML, "START"); @@ -678,8 +678,7 @@ xml_parse_barcode_props (xmlNodePtr node, g_free (string); text_flag = gl_xml_get_prop_boolean (node, "text", FALSE); - - scale = gl_xml_get_prop_double (node, "scale", 1.0); + checksum_flag = gl_xml_get_prop_boolean (node, "checksum", TRUE); text_node = g_new0 (glTextNode, 1); for (child = node->xmlChildrenNode; child != NULL; child = child->next) { @@ -696,7 +695,7 @@ xml_parse_barcode_props (xmlNodePtr node, gl_label_barcode_set_data (GL_LABEL_BARCODE(object), text_node); gl_label_barcode_set_props (GL_LABEL_BARCODE(object), - style, text_flag, color, scale); + style, text_flag, checksum_flag, color); gl_text_node_free (&text_node); @@ -1184,8 +1183,8 @@ xml_create_barcode_props (xmlNodePtr object_node, glTextNode *text_node; glBarcodeStyle style; gboolean text_flag; + gboolean checksum_flag; guint color; - gdouble scale; xmlNodePtr child; gl_debug (DEBUG_XML, "START"); @@ -1194,13 +1193,13 @@ xml_create_barcode_props (xmlNodePtr object_node, text_node = gl_label_barcode_get_data (GL_LABEL_BARCODE(object)); gl_label_barcode_get_props (GL_LABEL_BARCODE(object), - &style, &text_flag, &color, &scale); + &style, &text_flag, &checksum_flag, &color); gl_xml_set_prop_uint_hex (object_node, "color", color); xmlSetProp (object_node, "style", gl_barcode_style_to_text (style)); gl_xml_set_prop_boolean (object_node, "text", text_flag); - gl_xml_set_prop_double (object_node, "scale", scale); + gl_xml_set_prop_boolean (object_node, "checksum", checksum_flag); if (text_node->field_flag) { child = xmlNewChild (object_node, ns, "Field", NULL);