From 5ddb04aa4cf50122ae8d65409a00f6999c5cf169 Mon Sep 17 00:00:00 2001 From: Jim Evins Date: Wed, 11 Dec 2002 05:09:28 +0000 Subject: [PATCH] Initial support for supplying images from merge data. git-svn-id: https://glabels.svn.sourceforge.net/svnroot/glabels/trunk@213 f5e0f49d-192f-0410-a22d-a8d8700d0965 --- glabels2/src/label-image.c | 53 +++++++++++++++++++++++++++---------- glabels2/src/label-image.h | 13 +++++---- glabels2/src/print.c | 15 ++++++----- glabels2/src/text-node.c | 2 ++ glabels2/src/view-image.c | 53 ++++++++++++++----------------------- glabels2/src/xml-label-04.c | 8 +++--- glabels2/src/xml-label.c | 47 +++++++++++++++++++++----------- 7 files changed, 114 insertions(+), 77 deletions(-) diff --git a/glabels2/src/label-image.c b/glabels2/src/label-image.c index 6440a678..3976f882 100644 --- a/glabels2/src/label-image.c +++ b/glabels2/src/label-image.c @@ -33,7 +33,7 @@ /*========================================================*/ struct _glLabelImagePrivate { - gchar *filename; + glTextNode *filename; GdkPixbuf *pixbuf; }; @@ -146,7 +146,7 @@ copy (glLabelObject *dst_object, { glLabelImage *limage = (glLabelImage *)src_object; glLabelImage *new_limage = (glLabelImage *)dst_object; - gchar *filename; + glTextNode *filename; gl_debug (DEBUG_LABEL, "START"); @@ -155,7 +155,7 @@ copy (glLabelObject *dst_object, filename = gl_label_image_get_filename (limage); gl_label_image_set_filename (new_limage, filename); - g_free (filename); + gl_text_node_free (&filename); gl_debug (DEBUG_LABEL, "END"); } @@ -166,7 +166,7 @@ copy (glLabelObject *dst_object, /*****************************************************************************/ void gl_label_image_set_filename (glLabelImage *limage, - const gchar *filename) + glTextNode *filename) { GdkPixbuf *pixbuf; @@ -174,10 +174,10 @@ gl_label_image_set_filename (glLabelImage *limage, g_return_if_fail (limage && GL_IS_LABEL_IMAGE (limage)); - if ( filename == NULL ) { + if ( (filename == NULL) || filename->field_flag ) { - g_free (limage->private->filename); - limage->private->filename = NULL; + gl_text_node_free (&limage->private->filename); + limage->private->filename = gl_text_node_dup(filename); g_object_unref (limage->private->pixbuf); limage->private->pixbuf = @@ -188,12 +188,12 @@ gl_label_image_set_filename (glLabelImage *limage, } else { if ( (limage->private->filename == NULL) || - (strcmp (limage->private->filename, filename) != 0) ) { + (strcmp (limage->private->filename->data, filename->data) != 0) ) { - g_free (limage->private->filename); - limage->private->filename = g_strdup (filename); + gl_text_node_free (&limage->private->filename); + limage->private->filename = gl_text_node_dup (filename); - pixbuf = gdk_pixbuf_new_from_file (filename, NULL); + pixbuf = gdk_pixbuf_new_from_file (filename->data, NULL); g_object_unref (limage->private->pixbuf); if ( pixbuf != NULL ) { limage->private->pixbuf = pixbuf; @@ -215,19 +215,44 @@ gl_label_image_set_filename (glLabelImage *limage, /*****************************************************************************/ /* Get object params. */ /*****************************************************************************/ -gchar * +glTextNode * gl_label_image_get_filename (glLabelImage *limage) { g_return_val_if_fail (limage && GL_IS_LABEL_IMAGE (limage), NULL); - return g_strdup (limage->private->filename); + return gl_text_node_dup (limage->private->filename); } const GdkPixbuf * -gl_label_image_get_pixbuf (glLabelImage *limage) +gl_label_image_get_pixbuf (glLabelImage *limage, + glMergeRecord *record) { + GdkPixbuf *pixbuf = NULL; + gchar *real_filename; + g_return_val_if_fail (limage && GL_IS_LABEL_IMAGE (limage), NULL); + if ((record != NULL) && limage->private->filename->field_flag) { + + /* Indirect filename, re-evaluate for given record. */ + + real_filename = gl_merge_eval_key (record, + limage->private->filename->data); + + if (real_filename != NULL) { + pixbuf = gdk_pixbuf_new_from_file (real_filename, NULL); + } + g_object_unref (limage->private->pixbuf); + if ( pixbuf != NULL ) { + limage->private->pixbuf = pixbuf; + } else { + limage->private->pixbuf = + gdk_pixbuf_new_from_xpm_data ((const char **) + checkerboard_xpm); + } + + } + return limage->private->pixbuf; } diff --git a/glabels2/src/label-image.h b/glabels2/src/label-image.h index 9dbf731e..0b6b98ba 100644 --- a/glabels2/src/label-image.h +++ b/glabels2/src/label-image.h @@ -24,6 +24,8 @@ #define __LABEL_IMAGE_H__ #include "label-object.h" +#include "text-node.h" +#include "merge.h" #include "gdk-pixbuf/gdk-pixbuf.h" G_BEGIN_DECLS @@ -52,14 +54,15 @@ struct _glLabelImageClass { GType gl_label_image_get_type (void); -GObject *gl_label_image_new (glLabel *label); +GObject *gl_label_image_new (glLabel *label); -void gl_label_image_set_filename (glLabelImage *limage, - const gchar *filename); +void gl_label_image_set_filename (glLabelImage *limage, + glTextNode *filename); -gchar *gl_label_image_get_filename (glLabelImage *limage); +glTextNode *gl_label_image_get_filename (glLabelImage *limage); -const GdkPixbuf *gl_label_image_get_pixbuf (glLabelImage *limage); +const GdkPixbuf *gl_label_image_get_pixbuf (glLabelImage *limage, + glMergeRecord *record); G_END_DECLS diff --git a/glabels2/src/print.c b/glabels2/src/print.c index 31767312..618782e5 100644 --- a/glabels2/src/print.c +++ b/glabels2/src/print.c @@ -113,7 +113,8 @@ static void draw_ellipse_object (PrintInfo *pi, glLabelEllipse *object); static void draw_image_object (PrintInfo *pi, - glLabelImage *object); + glLabelImage *object, + glMergeRecord *record); static void draw_barcode_object (PrintInfo *pi, glLabelBarcode *object, @@ -585,10 +586,9 @@ draw_object (PrintInfo *pi, } else if (GL_IS_LABEL_ELLIPSE(object)) { draw_ellipse_object (pi, GL_LABEL_ELLIPSE(object)); } else if (GL_IS_LABEL_IMAGE(object)) { - draw_image_object (pi, GL_LABEL_IMAGE(object)); + draw_image_object (pi, GL_LABEL_IMAGE(object), record); } else if (GL_IS_LABEL_BARCODE(object)) { - draw_barcode_object (pi, GL_LABEL_BARCODE(object), - record); + draw_barcode_object (pi, GL_LABEL_BARCODE(object), record); } gnome_print_grestore (pi->pc); @@ -811,8 +811,9 @@ draw_ellipse_object (PrintInfo *pi, /* PRIVATE. Draw image object. */ /*---------------------------------------------------------------------------*/ static void -draw_image_object (PrintInfo *pi, - glLabelImage *object) +draw_image_object (PrintInfo *pi, + glLabelImage *object, + glMergeRecord *record) { gdouble w, h; const GdkPixbuf *pixbuf; @@ -825,7 +826,7 @@ draw_image_object (PrintInfo *pi, gl_label_object_get_size (GL_LABEL_OBJECT(object), &w, &h); - pixbuf = gl_label_image_get_pixbuf (object); + pixbuf = gl_label_image_get_pixbuf (object, record); image_data = gdk_pixbuf_get_pixels (pixbuf); image_w = gdk_pixbuf_get_width (pixbuf); image_h = gdk_pixbuf_get_height (pixbuf); diff --git a/glabels2/src/text-node.c b/glabels2/src/text-node.c index 2cad667e..cdf874bd 100644 --- a/glabels2/src/text-node.c +++ b/glabels2/src/text-node.c @@ -144,6 +144,8 @@ gl_text_node_dup (glTextNode *src) { glTextNode *dst; + if ( src == NULL ) return NULL; + dst = g_new0 (glTextNode, 1); dst->field_flag = src->field_flag; diff --git a/glabels2/src/view-image.c b/glabels2/src/view-image.c index e4f17c70..533e4ac8 100644 --- a/glabels2/src/view-image.c +++ b/glabels2/src/view-image.c @@ -26,6 +26,7 @@ #include "view-highlight.h" +#include "wdgt-image-select.h" #include "wdgt-line.h" #include "wdgt-fill.h" #include "wdgt-size.h" @@ -199,7 +200,7 @@ gl_view_image_new (glLabelImage *object, /* Query properties of object. */ gl_label_object_get_size (GL_LABEL_OBJECT(object), &w, &h); - pixbuf = gl_label_image_get_pixbuf(object); + pixbuf = gl_label_image_get_pixbuf(object, NULL); /* Create analogous canvas item. */ view_image->private->item = @@ -236,7 +237,7 @@ update_view_image_cb (glLabelObject *object, /* Query properties of object. */ gl_label_object_get_size (GL_LABEL_OBJECT(object), &w, &h); - pixbuf = gl_label_image_get_pixbuf (GL_LABEL_IMAGE(object)); + pixbuf = gl_label_image_get_pixbuf (GL_LABEL_IMAGE(object), NULL); /* Adjust appearance of analogous canvas item. */ gnome_canvas_item_set (view_image->private->item, @@ -260,7 +261,8 @@ construct_properties_dialog (glViewObject *view_object) GtkWidget *dialog, *wsection, *wbutton; glLabelObject *object; gdouble x, y, w, h, label_width, label_height; - gchar *filename; + glTextNode *filename; + glMerge *merge; GtkSizeGroup *label_size_group; GtkWidget *window; @@ -273,6 +275,7 @@ construct_properties_dialog (glViewObject *view_object) filename = gl_label_image_get_filename (GL_LABEL_IMAGE(object)); gl_label_get_size (GL_LABEL(object->parent), &label_width, &label_height); + merge = gl_label_get_merge (GL_LABEL(object->parent)); /*-----------------------------------------------------------------*/ /* Build dialog. */ @@ -296,32 +299,13 @@ construct_properties_dialog (glViewObject *view_object) /*---------------------------*/ wsection = gl_hig_category_new (_("Image")); gl_hig_dialog_add_widget (GL_HIG_DIALOG(dialog), wsection); - view_image->private->pixmap_entry = - gnome_pixmap_entry_new ("image", "Load image", TRUE); - gnome_pixmap_entry_set_preview_size (GNOME_PIXMAP_ENTRY - (view_image->private->pixmap_entry), - 128, 128); - - /* Set default path for image entry */ - if (filename != NULL) { - /* Set default path to the directory containing image. */ - if (image_path != NULL) - g_free (image_path); - image_path = g_path_get_dirname (filename); - if (image_path != NULL) { - image_path = g_strconcat (image_path, "/", NULL); - } - } else if (image_path == NULL) { - /* First time, set it to our CWD. */ - image_path = g_get_current_dir (); - } + view_image->private->pixmap_entry = + gl_wdgt_image_select_new (merge, filename); gl_hig_category_add_widget (GL_HIG_CATEGORY(wsection), view_image->private->pixmap_entry); - g_signal_connect ( G_OBJECT(gnome_file_entry_gtk_entry - (GNOME_FILE_ENTRY (view_image->private->pixmap_entry))), - "changed", G_CALLBACK (file_changed_cb), - view_image); + g_signal_connect ( G_OBJECT(view_image->private->pixmap_entry), "changed", + G_CALLBACK (file_changed_cb), view_image); /*----------------------------*/ @@ -420,14 +404,14 @@ file_changed_cb (GtkEntry *pixmap_entry, glViewImage *view_image) { glLabelObject *object; - gchar *filename; + glTextNode *filename; gl_debug (DEBUG_VIEW, "START"); object = gl_view_object_get_object (GL_VIEW_OBJECT(view_image)); - filename = gnome_pixmap_entry_get_filename (GNOME_PIXMAP_ENTRY(view_image->private->pixmap_entry)); - gl_debug (DEBUG_VIEW, "filename = %s", filename); + filename = gl_wdgt_image_select_get_data (GL_WDGT_IMAGE_SELECT(view_image->private->pixmap_entry)); + gl_debug (DEBUG_VIEW, "filename = %s", filename->data); g_signal_handlers_block_by_func (G_OBJECT(object), update_dialog_cb, view_image); @@ -435,7 +419,7 @@ file_changed_cb (GtkEntry *pixmap_entry, g_signal_handlers_unblock_by_func (G_OBJECT(object), update_dialog_cb, view_image); - g_free (filename); + gl_text_node_free (&filename); gl_debug (DEBUG_VIEW, "END"); } @@ -506,7 +490,7 @@ size_reset_cb (GtkButton *button, gl_debug (DEBUG_VIEW, "START"); object = gl_view_object_get_object (GL_VIEW_OBJECT(view_image)); - pixbuf = gl_label_image_get_pixbuf (GL_LABEL_IMAGE(object)); + pixbuf = gl_label_image_get_pixbuf (GL_LABEL_IMAGE(object), NULL); image_w = gdk_pixbuf_get_width (pixbuf); image_h = gdk_pixbuf_get_height (pixbuf); @@ -523,8 +507,9 @@ static void update_dialog_cb (glLabelObject *object, glViewImage *view_image) { - gchar *filename; + glTextNode *filename; gdouble x, y, w, h; + glMerge *merge; gl_debug (DEBUG_VIEW, "START"); @@ -532,6 +517,7 @@ update_dialog_cb (glLabelObject *object, gl_label_object_get_position (GL_LABEL_OBJECT(object), &x, &y); gl_label_object_get_size (GL_LABEL_OBJECT(object), &w, &h); filename = gl_label_image_get_filename (GL_LABEL_IMAGE(object)); + merge = gl_label_get_merge (GL_LABEL(object->parent)); /* Block widget handlers to prevent recursion */ g_signal_handlers_block_by_func (G_OBJECT(view_image->private->pixmap_entry), @@ -544,7 +530,8 @@ update_dialog_cb (glLabelObject *object, /* Update widgets in property dialog */ if ( filename != NULL ) { - gnome_file_entry_set_filename (GNOME_FILE_ENTRY (view_image->private->pixmap_entry), + gl_wdgt_image_select_set_data (GL_WDGT_IMAGE_SELECT(view_image->private->pixmap_entry), + (merge != NULL), filename); } gl_wdgt_position_set_position (GL_WDGT_POSITION(view_image->private->position), diff --git a/glabels2/src/xml-label-04.c b/glabels2/src/xml-label-04.c index 62625bf0..845a6b94 100644 --- a/glabels2/src/xml-label-04.c +++ b/glabels2/src/xml-label-04.c @@ -381,7 +381,7 @@ xml04_parse_image_props (xmlNodePtr node, glLabelImage *object) { gdouble w, h; - gchar *filename; + glTextNode *filename; gl_debug (DEBUG_XML, "START"); @@ -389,9 +389,11 @@ xml04_parse_image_props (xmlNodePtr node, h = g_strtod (xmlGetProp (node, "h"), NULL); gl_label_object_set_size (GL_LABEL_OBJECT(object), w, h); - filename = xmlGetProp (node, "filename"); + filename = g_new0 (glTextNode, 1); + filename->field_flag = FALSE; + filename->data = xmlGetProp (node, "filename"); gl_label_image_set_filename (object, filename); - g_free (filename); + gl_text_node_free (&filename); gl_debug (DEBUG_XML, "END"); } diff --git a/glabels2/src/xml-label.c b/glabels2/src/xml-label.c index 25c4e802..c18f3e72 100644 --- a/glabels2/src/xml-label.c +++ b/glabels2/src/xml-label.c @@ -532,9 +532,10 @@ static glLabelObject * xml_parse_image_props (xmlNodePtr node, glLabel *label) { - GObject *object; - gdouble w, h; - gchar *filename; + GObject *object; + xmlNodePtr child; + gdouble w, h; + glTextNode *filename; gl_debug (DEBUG_XML, "START"); @@ -543,12 +544,22 @@ xml_parse_image_props (xmlNodePtr node, w = g_strtod (xmlGetProp (node, "w"), NULL); h = g_strtod (xmlGetProp (node, "h"), NULL); - filename = xmlNodeGetContent (node); + child = node->xmlChildrenNode; + filename = g_new0 (glTextNode, 1); + if (g_strcasecmp (child->name, "Field") == 0) { + filename->field_flag = TRUE; + filename->data = xmlGetProp (child, "name"); + } else if (xmlNodeIsText (child)) { + filename->field_flag = FALSE; + filename->data = xmlNodeGetContent (child); + } else { + g_warning ("Unexpected Image child: \"%s\"", child->name); + } gl_label_object_set_size (GL_LABEL_OBJECT(object), w, h); gl_label_image_set_filename (GL_LABEL_IMAGE(object), filename); - g_free (filename); + gl_text_node_free (&filename); gl_debug (DEBUG_XML, "END"); @@ -562,9 +573,9 @@ static glLabelObject * xml_parse_barcode_props (xmlNodePtr node, glLabel *label) { - GObject *object; - xmlNodePtr child; - glTextNode *text_node; + GObject *object; + xmlNodePtr child; + glTextNode *text_node; glBarcodeStyle style; gboolean text_flag; guint color; @@ -1023,9 +1034,10 @@ xml_create_image_props (xmlNodePtr object_node, xmlNsPtr ns, glLabelObject * object) { - gchar *string; - gdouble w, h; - gchar *filename; + gchar *string; + gdouble w, h; + glTextNode *filename; + xmlNodePtr child; gl_debug (DEBUG_XML, "START"); @@ -1041,9 +1053,14 @@ xml_create_image_props (xmlNodePtr object_node, xmlSetProp (object_node, "h", string); g_free (string); - xmlNodeSetContent (object_node, filename); + if (filename->field_flag) { + child = xmlNewChild (object_node, ns, "Field", NULL); + xmlSetProp (child, "name", filename->data); + } else { + xmlNodeSetContent (object_node, filename->data); + } - g_free (filename); + gl_text_node_free (&filename); gl_debug (DEBUG_XML, "END"); } @@ -1061,8 +1078,8 @@ xml_create_barcode_props (xmlNodePtr object_node, gboolean text_flag; guint color; gdouble scale; - xmlNodePtr child; - gchar *string; + xmlNodePtr child; + gchar *string; gl_debug (DEBUG_XML, "START"); -- 2.39.5