From c31a43a3500a82401710abef158614e6c24e8a4a Mon Sep 17 00:00:00 2001 From: Jim Evins Date: Tue, 26 Nov 2002 03:12:05 +0000 Subject: [PATCH] Cleaned up label object duplication code. Added get_size methods for text and barcode objects. git-svn-id: https://glabels.svn.sourceforge.net/svnroot/glabels/trunk@185 f5e0f49d-192f-0410-a22d-a8d8700d0965 --- glabels2/src/label-barcode.c | 49 +++++++++++--------- glabels2/src/label-barcode.h | 3 -- glabels2/src/label-box.c | 28 ++++++------ glabels2/src/label-box.h | 5 +- glabels2/src/label-ellipse.c | 28 ++++++------ glabels2/src/label-ellipse.h | 5 +- glabels2/src/label-image.c | 27 +++++------ glabels2/src/label-image.h | 5 +- glabels2/src/label-line.c | 27 +++++------ glabels2/src/label-line.h | 3 -- glabels2/src/label-object.c | 27 +++++++++-- glabels2/src/label-object.h | 89 +++++++++++++++++++----------------- glabels2/src/label-text.c | 56 ++++++++++++----------- glabels2/src/label-text.h | 3 -- glabels2/src/view.c | 26 +---------- 15 files changed, 184 insertions(+), 197 deletions(-) diff --git a/glabels2/src/label-barcode.c b/glabels2/src/label-barcode.c index 6f738bb7..c907d193 100644 --- a/glabels2/src/label-barcode.c +++ b/glabels2/src/label-barcode.c @@ -61,7 +61,12 @@ static void gl_label_barcode_class_init (glLabelBarcodeClass *klass); static void gl_label_barcode_instance_init (glLabelBarcode *lbc); static void gl_label_barcode_finalize (GObject *object); -static void update_size (glLabelBarcode *lbc); +static void copy (glLabelObject *dst_object, + glLabelObject *src_object); + +static void get_size (glLabelObject *object, + gdouble *w, + gdouble *h); /*****************************************************************************/ @@ -95,10 +100,14 @@ gl_label_barcode_get_type (void) static void gl_label_barcode_class_init (glLabelBarcodeClass *klass) { - GObjectClass *object_class = (GObjectClass *) klass; + GObjectClass *object_class = (GObjectClass *) klass; + glLabelObjectClass *label_object_class = (glLabelObjectClass *) klass; parent_class = g_type_class_peek_parent (klass); + label_object_class->copy = copy; + label_object_class->get_size = get_size; + object_class->finalize = gl_label_barcode_finalize; } @@ -139,13 +148,14 @@ gl_label_barcode_new (glLabel *label) } /*****************************************************************************/ -/* Duplicate object. */ +/* Copy object contents. */ /*****************************************************************************/ -glLabelBarcode * -gl_label_barcode_dup (glLabelBarcode *lbc, - glLabel *label) +static void +copy (glLabelObject *dst_object, + glLabelObject *src_object) { - glLabelBarcode *new_lbc; + glLabelBarcode *lbc = (glLabelBarcode *)src_object; + glLabelBarcode *new_lbc = (glLabelBarcode *)dst_object; glTextNode *text_node; glBarcodeStyle style; gboolean text_flag; @@ -155,11 +165,7 @@ gl_label_barcode_dup (glLabelBarcode *lbc, gl_debug (DEBUG_LABEL, "START"); g_return_if_fail (lbc && GL_IS_LABEL_BARCODE (lbc)); - g_return_if_fail (label && GL_IS_LABEL (label)); - - new_lbc = GL_LABEL_BARCODE(gl_label_barcode_new (label)); - - gl_label_object_copy_props (GL_LABEL_OBJECT(new_lbc), GL_LABEL_OBJECT(lbc)); + 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); @@ -170,8 +176,6 @@ gl_label_barcode_dup (glLabelBarcode *lbc, gl_text_node_free (&text_node); gl_debug (DEBUG_LABEL, "END"); - - return new_lbc; } @@ -189,8 +193,6 @@ gl_label_barcode_set_data (glLabelBarcode *lbc, gl_text_node_free (&lbc->private->text_node); lbc->private->text_node = gl_text_node_dup (text_node); - update_size (lbc); - gl_label_object_emit_changed (GL_LABEL_OBJECT(lbc)); gl_debug (DEBUG_LABEL, "END"); @@ -212,8 +214,6 @@ gl_label_barcode_set_props (glLabelBarcode *lbc, lbc->private->color = color; lbc->private->scale = scale; - update_size (lbc); - gl_label_object_emit_changed (GL_LABEL_OBJECT(lbc)); gl_debug (DEBUG_LABEL, "END"); @@ -247,24 +247,29 @@ gl_label_barcode_get_props (glLabelBarcode *lbc, } /*---------------------------------------------------------------------------*/ -/* PRIVATE. Update object size. */ +/* PRIVATE. Get object size method. */ /*---------------------------------------------------------------------------*/ static void -update_size (glLabelBarcode *lbc) +get_size (glLabelObject *object, + gdouble *w, + gdouble *h) { + glLabelBarcode *lbc = (glLabelBarcode *)object; gchar *data; 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); gbc = gl_barcode_new (lbc->private->style, lbc->private->text_flag, lbc->private->scale, data); - gl_label_object_set_size (GL_LABEL_OBJECT(lbc), - gbc->width, gbc->height); + *w = gbc->width; + *h = gbc->height; gl_barcode_free (&gbc); diff --git a/glabels2/src/label-barcode.h b/glabels2/src/label-barcode.h index a0b87830..cbe773a5 100644 --- a/glabels2/src/label-barcode.h +++ b/glabels2/src/label-barcode.h @@ -58,9 +58,6 @@ GType gl_label_barcode_get_type (void); GObject *gl_label_barcode_new (glLabel *label); -glLabelBarcode *gl_label_barcode_dup (glLabelBarcode *lbc, - glLabel *label); - void gl_label_barcode_set_data (glLabelBarcode *lbc, glTextNode *text_node); void gl_label_barcode_set_props (glLabelBarcode *lbc, diff --git a/glabels2/src/label-box.c b/glabels2/src/label-box.c index 9797cd97..56e46be6 100644 --- a/glabels2/src/label-box.c +++ b/glabels2/src/label-box.c @@ -52,6 +52,9 @@ static void gl_label_box_class_init (glLabelBoxClass *klass); static void gl_label_box_instance_init (glLabelBox *lbox); static void gl_label_box_finalize (GObject *object); +static void copy (glLabelObject *dst_object, + glLabelObject *src_object); + /*****************************************************************************/ /* Boilerplate object stuff. */ @@ -84,10 +87,13 @@ gl_label_box_get_type (void) static void gl_label_box_class_init (glLabelBoxClass *klass) { - GObjectClass *object_class = (GObjectClass *) klass; + GObjectClass *object_class = (GObjectClass *) klass; + glLabelObjectClass *label_object_class = (glLabelObjectClass *) klass; parent_class = g_type_class_peek_parent (klass); + label_object_class->copy = copy; + object_class->finalize = gl_label_box_finalize; } @@ -127,24 +133,21 @@ gl_label_box_new (glLabel *label) } /*****************************************************************************/ -/* Duplicate object. */ +/* Copy object contents. */ /*****************************************************************************/ -glLabelBox * -gl_label_box_dup (glLabelBox *lbox, - glLabel *label) +static void +copy (glLabelObject *dst_object, + glLabelObject *src_object) { - glLabelBox *new_lbox; + glLabelBox *lbox = (glLabelBox *)src_object; + glLabelBox *new_lbox = (glLabelBox *)dst_object; gdouble line_width; guint line_color, fill_color; gl_debug (DEBUG_LABEL, "START"); g_return_if_fail (lbox && GL_IS_LABEL_BOX (lbox)); - g_return_if_fail (label && GL_IS_LABEL (label)); - - new_lbox = GL_LABEL_BOX(gl_label_box_new (label)); - - gl_label_object_copy_props (GL_LABEL_OBJECT(new_lbox), GL_LABEL_OBJECT(lbox)); + g_return_if_fail (new_lbox && GL_IS_LABEL_BOX (new_lbox)); line_width = gl_label_box_get_line_width (lbox); line_color = gl_label_box_get_line_color (lbox); @@ -154,10 +157,7 @@ gl_label_box_dup (glLabelBox *lbox, gl_label_box_set_line_color (new_lbox, line_color); gl_label_box_set_fill_color (new_lbox, fill_color); - gl_debug (DEBUG_LABEL, "END"); - - return new_lbox; } diff --git a/glabels2/src/label-box.h b/glabels2/src/label-box.h index cfd93df6..d257ab56 100644 --- a/glabels2/src/label-box.h +++ b/glabels2/src/label-box.h @@ -52,10 +52,7 @@ struct _glLabelBoxClass { GType gl_label_box_get_type (void); -GObject *gl_label_box_new (glLabel *label); - -glLabelBox *gl_label_box_dup (glLabelBox *lbox, - glLabel *label); +GObject *gl_label_box_new (glLabel *label); void gl_label_box_set_line_width (glLabelBox *lbox, gdouble line_width); diff --git a/glabels2/src/label-ellipse.c b/glabels2/src/label-ellipse.c index 25d06c75..5033afc2 100644 --- a/glabels2/src/label-ellipse.c +++ b/glabels2/src/label-ellipse.c @@ -52,6 +52,9 @@ static void gl_label_ellipse_class_init (glLabelEllipseClass *klass); static void gl_label_ellipse_instance_init (glLabelEllipse *lellipse); static void gl_label_ellipse_finalize (GObject *object); +static void copy (glLabelObject *dst_object, + glLabelObject *src_object); + /*****************************************************************************/ /* Boilerplate object stuff. */ @@ -84,10 +87,13 @@ gl_label_ellipse_get_type (void) static void gl_label_ellipse_class_init (glLabelEllipseClass *klass) { - GObjectClass *object_class = (GObjectClass *) klass; + GObjectClass *object_class = (GObjectClass *) klass; + glLabelObjectClass *label_object_class = (glLabelObjectClass *) klass; parent_class = g_type_class_peek_parent (klass); + label_object_class->copy = copy; + object_class->finalize = gl_label_ellipse_finalize; } @@ -127,25 +133,21 @@ gl_label_ellipse_new (glLabel *label) } /*****************************************************************************/ -/* Duplicate object. */ +/* Copy object contents. */ /*****************************************************************************/ -glLabelEllipse * -gl_label_ellipse_dup (glLabelEllipse *lellipse, - glLabel *label) +static void +copy (glLabelObject *dst_object, + glLabelObject *src_object) { - glLabelEllipse *new_lellipse; + glLabelEllipse *lellipse = (glLabelEllipse *)src_object; + glLabelEllipse *new_lellipse = (glLabelEllipse *)dst_object; gdouble line_width; guint line_color, fill_color; gl_debug (DEBUG_LABEL, "START"); g_return_if_fail (lellipse && GL_IS_LABEL_ELLIPSE (lellipse)); - g_return_if_fail (label && GL_IS_LABEL (label)); - - new_lellipse = GL_LABEL_ELLIPSE(gl_label_ellipse_new (label)); - - gl_label_object_copy_props (GL_LABEL_OBJECT(new_lellipse), - GL_LABEL_OBJECT(lellipse)); + g_return_if_fail (new_lellipse && GL_IS_LABEL_ELLIPSE (new_lellipse)); line_width = gl_label_ellipse_get_line_width (lellipse); line_color = gl_label_ellipse_get_line_color (lellipse); @@ -156,8 +158,6 @@ gl_label_ellipse_dup (glLabelEllipse *lellipse, gl_label_ellipse_set_fill_color (new_lellipse, fill_color); gl_debug (DEBUG_LABEL, "END"); - - return new_lellipse; } diff --git a/glabels2/src/label-ellipse.h b/glabels2/src/label-ellipse.h index b7b0cf72..faf35f3f 100644 --- a/glabels2/src/label-ellipse.h +++ b/glabels2/src/label-ellipse.h @@ -52,10 +52,7 @@ struct _glLabelEllipseClass { GType gl_label_ellipse_get_type (void); -GObject *gl_label_ellipse_new (glLabel *label); - -glLabelEllipse *gl_label_ellipse_dup (glLabelEllipse *lellipse, - glLabel *label); +GObject *gl_label_ellipse_new (glLabel *label); void gl_label_ellipse_set_line_width (glLabelEllipse *lellipse, gdouble line_width); diff --git a/glabels2/src/label-image.c b/glabels2/src/label-image.c index 15b7a92e..6440a678 100644 --- a/glabels2/src/label-image.c +++ b/glabels2/src/label-image.c @@ -53,6 +53,9 @@ static void gl_label_image_class_init (glLabelImageClass *klass); static void gl_label_image_instance_init (glLabelImage *limage); static void gl_label_image_finalize (GObject *object); +static void copy (glLabelObject *dst_object, + glLabelObject *src_object); + /*****************************************************************************/ /* Boilerplate object stuff. */ @@ -85,10 +88,13 @@ gl_label_image_get_type (void) static void gl_label_image_class_init (glLabelImageClass *klass) { - GObjectClass *object_class = (GObjectClass *) klass; + GObjectClass *object_class = (GObjectClass *) klass; + glLabelObjectClass *label_object_class = (glLabelObjectClass *) klass; parent_class = g_type_class_peek_parent (klass); + label_object_class->copy = copy; + object_class->finalize = gl_label_image_finalize; } @@ -132,31 +138,26 @@ gl_label_image_new (glLabel *label) } /*****************************************************************************/ -/* Duplicate object. */ +/* Copy object contents. */ /*****************************************************************************/ -glLabelImage * -gl_label_image_dup (glLabelImage *limage, - glLabel *label) +static void +copy (glLabelObject *dst_object, + glLabelObject *src_object) { - glLabelImage *new_limage; + glLabelImage *limage = (glLabelImage *)src_object; + glLabelImage *new_limage = (glLabelImage *)dst_object; gchar *filename; gl_debug (DEBUG_LABEL, "START"); g_return_if_fail (limage && GL_IS_LABEL_IMAGE (limage)); - g_return_if_fail (label && GL_IS_LABEL (label)); - - new_limage = GL_LABEL_IMAGE(gl_label_image_new (label)); - - gl_label_object_copy_props (GL_LABEL_OBJECT(new_limage), GL_LABEL_OBJECT(limage)); + g_return_if_fail (new_limage && GL_IS_LABEL_IMAGE (new_limage)); filename = gl_label_image_get_filename (limage); gl_label_image_set_filename (new_limage, filename); g_free (filename); gl_debug (DEBUG_LABEL, "END"); - - return new_limage; } diff --git a/glabels2/src/label-image.h b/glabels2/src/label-image.h index 143f0d19..9dbf731e 100644 --- a/glabels2/src/label-image.h +++ b/glabels2/src/label-image.h @@ -52,10 +52,7 @@ struct _glLabelImageClass { GType gl_label_image_get_type (void); -GObject *gl_label_image_new (glLabel *label); - -glLabelImage *gl_label_image_dup (glLabelImage *limage, - glLabel *label); +GObject *gl_label_image_new (glLabel *label); void gl_label_image_set_filename (glLabelImage *limage, const gchar *filename); diff --git a/glabels2/src/label-line.c b/glabels2/src/label-line.c index 61b18ea5..47620e3f 100644 --- a/glabels2/src/label-line.c +++ b/glabels2/src/label-line.c @@ -51,6 +51,9 @@ static void gl_label_line_class_init (glLabelLineClass *klass); static void gl_label_line_instance_init (glLabelLine *lline); static void gl_label_line_finalize (GObject *object); +static void copy (glLabelObject *dst_object, + glLabelObject *src_object); + /*****************************************************************************/ /* Boilerplate object stuff. */ @@ -83,10 +86,13 @@ gl_label_line_get_type (void) static void gl_label_line_class_init (glLabelLineClass *klass) { - GObjectClass *object_class = (GObjectClass *) klass; + GObjectClass *object_class = (GObjectClass *) klass; + glLabelObjectClass *label_object_class = (glLabelObjectClass *) klass; parent_class = g_type_class_peek_parent (klass); + label_object_class->copy = copy; + object_class->finalize = gl_label_line_finalize; } @@ -126,24 +132,21 @@ gl_label_line_new (glLabel *label) } /*****************************************************************************/ -/* Duplicate object. */ +/* Copy object contents. */ /*****************************************************************************/ -glLabelLine * -gl_label_line_dup (glLabelLine *lline, - glLabel *label) +static void +copy (glLabelObject *dst_object, + glLabelObject *src_object) { - glLabelLine *new_lline; + glLabelLine *lline = (glLabelLine *)src_object; + glLabelLine *new_lline = (glLabelLine *)dst_object; gdouble line_width; guint line_color; gl_debug (DEBUG_LABEL, "START"); g_return_if_fail (lline && GL_IS_LABEL_LINE (lline)); - g_return_if_fail (label && GL_IS_LABEL (label)); - - new_lline = GL_LABEL_LINE(gl_label_line_new (label)); - - gl_label_object_copy_props (GL_LABEL_OBJECT(new_lline), GL_LABEL_OBJECT(lline)); + g_return_if_fail (new_lline && GL_IS_LABEL_LINE (new_lline)); line_width = gl_label_line_get_line_width (lline); line_color = gl_label_line_get_line_color (lline); @@ -152,8 +155,6 @@ gl_label_line_dup (glLabelLine *lline, gl_label_line_set_line_color (new_lline, line_color); gl_debug (DEBUG_LABEL, "END"); - - return new_lline; } diff --git a/glabels2/src/label-line.h b/glabels2/src/label-line.h index 5b1f175d..84fda6da 100644 --- a/glabels2/src/label-line.h +++ b/glabels2/src/label-line.h @@ -54,9 +54,6 @@ GType gl_label_line_get_type (void); GObject *gl_label_line_new (glLabel *label); -glLabelLine *gl_label_line_dup (glLabelLine *lline, - glLabel *label); - void gl_label_line_set_line_width (glLabelLine *lline, gdouble line_width); diff --git a/glabels2/src/label-object.c b/glabels2/src/label-object.c index 346aa87a..03cc4714 100644 --- a/glabels2/src/label-object.c +++ b/glabels2/src/label-object.c @@ -214,17 +214,23 @@ gl_label_object_new (glLabel *label) } /*****************************************************************************/ -/* Copy properties of one label object to another. */ +/* Duplicate object. */ /*****************************************************************************/ -void -gl_label_object_copy_props (glLabelObject *dst_object, - glLabelObject *src_object) +glLabelObject * +gl_label_object_dup (glLabelObject *src_object, + glLabel *label) { + glLabelObject *dst_object; gdouble x, y, w, h; gdouble affine[6]; + gl_debug (DEBUG_LABEL, "START"); + g_return_if_fail (src_object && GL_IS_LABEL_OBJECT (src_object)); - g_return_if_fail (dst_object && GL_IS_LABEL_OBJECT (dst_object)); + + dst_object = g_object_new (G_OBJECT_TYPE(src_object), NULL); + + gl_label_object_set_parent (dst_object, label); gl_label_object_get_position (src_object, &x, &y); gl_label_object_get_size (src_object, &w, &h); @@ -233,6 +239,17 @@ gl_label_object_copy_props (glLabelObject *dst_object, gl_label_object_set_position (dst_object, x, y); gl_label_object_set_size (dst_object, w, h); gl_label_object_set_affine (dst_object, affine); + + if ( GL_LABEL_OBJECT_GET_CLASS(src_object)->copy != NULL ) { + + /* We have an object specific method, use it */ + GL_LABEL_OBJECT_GET_CLASS(src_object)->copy (dst_object, src_object); + + } + + gl_debug (DEBUG_LABEL, "END"); + + return dst_object; } /*****************************************************************************/ diff --git a/glabels2/src/label-object.h b/glabels2/src/label-object.h index 7d46b71e..a7703b94 100644 --- a/glabels2/src/label-object.h +++ b/glabels2/src/label-object.h @@ -77,6 +77,9 @@ struct _glLabelObjectClass { gdouble *w, gdouble *h); + void (*copy) (glLabelObject *dst_object, + glLabelObject *src_object); + /* * Signals */ @@ -98,76 +101,76 @@ struct _glLabelObjectClass { gpointer user_data); }; -GType gl_label_object_get_type (void); +GType gl_label_object_get_type (void); -GObject *gl_label_object_new (glLabel *label); +GObject *gl_label_object_new (glLabel *label); -void gl_label_object_copy_props (glLabelObject *dst_object, - glLabelObject *src_object); +glLabelObject *gl_label_object_dup (glLabelObject *src_object, + glLabel *label); -void gl_label_object_emit_changed (glLabelObject *object); +void gl_label_object_emit_changed (glLabelObject *object); -void gl_label_object_set_parent (glLabelObject *object, - glLabel *label); +void gl_label_object_set_parent (glLabelObject *object, + glLabel *label); -glLabel *gl_label_object_get_parent (glLabelObject *object); +glLabel *gl_label_object_get_parent (glLabelObject *object); -void gl_label_object_set_name (glLabelObject *object, - gchar *name); +void gl_label_object_set_name (glLabelObject *object, + gchar *name); -gchar *gl_label_object_get_name (glLabelObject *object); +gchar *gl_label_object_get_name (glLabelObject *object); -void gl_label_object_set_position (glLabelObject *object, - gdouble x, - gdouble y); +void gl_label_object_set_position (glLabelObject *object, + gdouble x, + gdouble y); -void gl_label_object_set_position_relative (glLabelObject *object, - gdouble dx, - gdouble dy); +void gl_label_object_set_position_relative (glLabelObject *object, + gdouble dx, + gdouble dy); -void gl_label_object_get_position (glLabelObject *object, - gdouble *x, - gdouble *y); +void gl_label_object_get_position (glLabelObject *object, + gdouble *x, + gdouble *y); -void gl_label_object_set_size (glLabelObject *object, - gdouble w, - gdouble h); +void gl_label_object_set_size (glLabelObject *object, + gdouble w, + gdouble h); -void gl_label_object_get_size (glLabelObject *object, - gdouble *w, - gdouble *h); +void gl_label_object_get_size (glLabelObject *object, + gdouble *w, + gdouble *h); -void gl_label_object_get_extent (glLabelObject *object, - gdouble *x1, - gdouble *y1, - gdouble *x2, - gdouble *y2); +void gl_label_object_get_extent (glLabelObject *object, + gdouble *x1, + gdouble *y1, + gdouble *x2, + gdouble *y2); -void gl_label_object_raise_to_top (glLabelObject *object); +void gl_label_object_raise_to_top (glLabelObject *object); -void gl_label_object_lower_to_bottom (glLabelObject *object); +void gl_label_object_lower_to_bottom (glLabelObject *object); -void gl_label_object_flip_horiz (glLabelObject *object); +void gl_label_object_flip_horiz (glLabelObject *object); -void gl_label_object_flip_vert (glLabelObject *object); +void gl_label_object_flip_vert (glLabelObject *object); -void gl_label_object_rotate (glLabelObject *object, - gdouble theta_degs); +void gl_label_object_rotate (glLabelObject *object, + gdouble theta_degs); -void gl_label_object_set_affine (glLabelObject *object, - gdouble affine[6]); +void gl_label_object_set_affine (glLabelObject *object, + gdouble affine[6]); -void gl_label_object_get_affine (glLabelObject *object, - gdouble affine[6]); +void gl_label_object_get_affine (glLabelObject *object, + gdouble affine[6]); -void gl_label_object_get_applied_affine (glLabelObject *object, - gdouble affine[6]); +void gl_label_object_get_applied_affine (glLabelObject *object, + gdouble affine[6]); G_END_DECLS diff --git a/glabels2/src/label-text.c b/glabels2/src/label-text.c index 72dfb655..37d010ed 100644 --- a/glabels2/src/label-text.c +++ b/glabels2/src/label-text.c @@ -70,7 +70,12 @@ static void gl_label_text_class_init (glLabelTextClass *klass); static void gl_label_text_instance_init (glLabelText *ltext); static void gl_label_text_finalize (GObject *object); -static void update_size (glLabelText *ltext); +static void copy (glLabelObject *dst_object, + glLabelObject *src_object); + +static void get_size (glLabelObject *object, + gdouble *w, + gdouble *h); /*****************************************************************************/ @@ -104,10 +109,14 @@ gl_label_text_get_type (void) static void gl_label_text_class_init (glLabelTextClass *klass) { - GObjectClass *object_class = (GObjectClass *) klass; + GObjectClass *object_class = (GObjectClass *) klass; + glLabelObjectClass *label_object_class = (glLabelObjectClass *) klass; parent_class = g_type_class_peek_parent (klass); + label_object_class->copy = copy; + label_object_class->get_size = get_size; + object_class->finalize = gl_label_text_finalize; } @@ -154,13 +163,14 @@ gl_label_text_new (glLabel *label) } /*****************************************************************************/ -/* Duplicate object. */ +/* Copy object contents. */ /*****************************************************************************/ -glLabelText * -gl_label_text_dup (glLabelText *ltext, - glLabel *label) +static void +copy (glLabelObject *dst_object, + glLabelObject *src_object) { - glLabelText *new_ltext; + glLabelText *ltext = (glLabelText *)src_object; + glLabelText *new_ltext = (glLabelText *)dst_object; GList *lines; gchar *font_family; gdouble font_size; @@ -172,11 +182,7 @@ gl_label_text_dup (glLabelText *ltext, gl_debug (DEBUG_LABEL, "START"); g_return_if_fail (ltext && GL_IS_LABEL_TEXT (ltext)); - g_return_if_fail (label && GL_IS_LABEL (label)); - - new_ltext = GL_LABEL_TEXT(gl_label_text_new (label)); - - gl_label_object_copy_props (GL_LABEL_OBJECT(new_ltext), GL_LABEL_OBJECT(ltext)); + g_return_if_fail (new_ltext && GL_IS_LABEL_TEXT (new_ltext)); lines = gl_label_text_get_lines (ltext); gl_label_text_get_props (ltext, @@ -194,8 +200,6 @@ gl_label_text_dup (glLabelText *ltext, g_free (font_family); gl_debug (DEBUG_LABEL, "END"); - - return new_ltext; } @@ -213,8 +217,6 @@ gl_label_text_set_lines (glLabelText *ltext, gl_text_node_lines_free (<ext->private->lines); ltext->private->lines = gl_text_node_lines_dup (lines); - update_size (ltext); - gl_label_object_emit_changed (GL_LABEL_OBJECT(ltext)); gl_debug (DEBUG_LABEL, "END"); @@ -246,8 +248,6 @@ gl_label_text_set_props (glLabelText *ltext, gl_debug (DEBUG_LABEL, "just = %d", ltext->private->just); - update_size (ltext); - gl_label_object_emit_changed (GL_LABEL_OBJECT(ltext)); gl_debug (DEBUG_LABEL, "END"); @@ -287,12 +287,14 @@ gl_label_text_get_props (glLabelText *ltext, } /*---------------------------------------------------------------------------*/ -/* PRIVATE. Update object size. */ +/* PRIVATE. get object size method. */ /*---------------------------------------------------------------------------*/ static void -update_size (glLabelText *ltext) +get_size (glLabelObject *object, + gdouble *w, + gdouble *h) { - gdouble w, h; + glLabelText *ltext = (glLabelText *)object; GnomeFont *font; gchar *text; gchar **line; @@ -303,6 +305,8 @@ update_size (glLabelText *ltext) gl_debug (DEBUG_LABEL, "START"); + g_return_if_fail (ltext && GL_IS_LABEL_TEXT (ltext)); + font = gnome_font_find_closest_from_weight_slant ( ltext->private->font_family, ltext->private->font_weight, @@ -315,8 +319,8 @@ update_size (glLabelText *ltext) art_affine_identity (affine); - w = 0.0; - h = 0.0; + *w = 0.0; + *h = 0.0; for (i = 0; line[i] != NULL; i++) { glyphlist = gnome_glyphlist_from_text_dumb (font, 0, @@ -325,16 +329,14 @@ update_size (glLabelText *ltext) gnome_glyphlist_bbox (glyphlist, affine, 0, &bbox); - if ( bbox.x1 > w ) w = bbox.x1; + if ( bbox.x1 > *w ) *w = bbox.x1; - h += ltext->private->font_size; + *h += ltext->private->font_size; } g_strfreev (line); - gl_label_object_set_size (GL_LABEL_OBJECT(ltext), w, h); - gl_debug (DEBUG_LABEL, "END"); } diff --git a/glabels2/src/label-text.h b/glabels2/src/label-text.h index 83c64982..f315dd0b 100644 --- a/glabels2/src/label-text.h +++ b/glabels2/src/label-text.h @@ -56,9 +56,6 @@ GType gl_label_text_get_type (void); GObject *gl_label_text_new (glLabel *label); -glLabelText *gl_label_text_dup (glLabelText *ltext, - glLabel *label); - void gl_label_text_set_lines (glLabelText *ltext, GList *lines); void gl_label_text_set_props (glLabelText *ltext, diff --git a/glabels2/src/view.c b/glabels2/src/view.c index 194c97fb..410842e2 100644 --- a/glabels2/src/view.c +++ b/glabels2/src/view.c @@ -2080,31 +2080,7 @@ gl_view_copy (glView *view) view_object = GL_VIEW_OBJECT (p->data); object = gl_view_object_get_object (view_object); - gl_debug (DEBUG_VIEW, "Object copied"); - - if (GL_IS_LABEL_BOX (object)) { - gl_label_box_dup (GL_LABEL_BOX(object), - view->selection_data); - } else if (GL_IS_LABEL_ELLIPSE (object)) { - gl_label_ellipse_dup (GL_LABEL_ELLIPSE(object), - view->selection_data); - } else if (GL_IS_LABEL_LINE (object)) { - gl_label_line_dup (GL_LABEL_LINE(object), - view->selection_data); - } else if (GL_IS_LABEL_IMAGE (object)) { - gl_label_image_dup (GL_LABEL_IMAGE(object), - view->selection_data); - } else if (GL_IS_LABEL_TEXT (object)) { - gl_label_text_dup (GL_LABEL_TEXT(object), - view->selection_data); - } else if (GL_IS_LABEL_BARCODE (object)) { - gl_label_barcode_dup (GL_LABEL_BARCODE(object), - view->selection_data); - } else { - /* Should not happen! */ - g_warning ("Invalid label object type."); - } - + gl_label_object_dup (object, view->selection_data); } -- 2.39.5