]> git.sur5r.net Git - glabels/commitdiff
Cleaned up label object duplication code.
authorJim Evins <evins@snaught.com>
Tue, 26 Nov 2002 03:12:05 +0000 (03:12 +0000)
committerJim Evins <evins@snaught.com>
Tue, 26 Nov 2002 03:12:05 +0000 (03:12 +0000)
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

15 files changed:
glabels2/src/label-barcode.c
glabels2/src/label-barcode.h
glabels2/src/label-box.c
glabels2/src/label-box.h
glabels2/src/label-ellipse.c
glabels2/src/label-ellipse.h
glabels2/src/label-image.c
glabels2/src/label-image.h
glabels2/src/label-line.c
glabels2/src/label-line.h
glabels2/src/label-object.c
glabels2/src/label-object.h
glabels2/src/label-text.c
glabels2/src/label-text.h
glabels2/src/view.c

index 6f738bb731cbff8e58d05e7a03e398797d42c58e..c907d1938ccd9c4389469ca5f72d5c4125d527fc 100644 (file)
@@ -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);
 
 \f
 /*****************************************************************************/
@@ -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);
 
index a0b878303187c2407b86fa7f221565e368974f48..cbe773a5a0c5780d9fb1c208f4e419c15c95ece9 100644 (file)
@@ -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,
index 9797cd97aef4c32fd9e071e8372db225256e7980..56e46be6675affbef3d5cb661eee9603d736f6d3 100644 (file)
@@ -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);
+
 \f
 /*****************************************************************************/
 /* 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;
 }
 
 
index cfd93df62352b73b9b406a560b24021651fd06fe..d257ab56e3a0d956dcca880cfbb6fd702d559e70 100644 (file)
@@ -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);
index 25d06c75bf3d377388942e98e7b317cb39014570..5033afc26dc688c6311bf9bd72c9f556e1921d33 100644 (file)
@@ -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);
+
 \f
 /*****************************************************************************/
 /* 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;
 }
 
 
index b7b0cf724daa1bdd1df2e133f96e26a6acc3660b..faf35f3f580b72041add5a4ec60ddc893cd9c9aa 100644 (file)
@@ -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);
index 15b7a92edc78f30adca5b3d321ff41fd3e52a2cb..6440a678767c08fa67646b99567c8268a96b8187 100644 (file)
@@ -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);
+
 \f
 /*****************************************************************************/
 /* 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;
 }
 
 
index 143f0d198232a823c8883333f2733bbd381f2c79..9dbf731e31febf74b9c8787ff8e796bc8b408e5b 100644 (file)
@@ -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);
index 61b18ea503ab5818299dc3d100f744a7e0aa0068..47620e3f10725546b0994f00d3bc084e1c2df37a 100644 (file)
@@ -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);
+
 \f
 /*****************************************************************************/
 /* 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;
 }
 
 
index 5b1f175d90b37482303a3f44f3f5cc5757b89568..84fda6da74d4a2a686cdbef77d4ce895a7d94717 100644 (file)
@@ -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);
 
index 346aa87a2058fa7da007595b019eda2296f0a151..03cc4714014536f4f00cac1a6517e1544db94892 100644 (file)
@@ -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;
 }
 
 /*****************************************************************************/
index 7d46b71e86853c5023fe7e2460daa95c4c820f08..a7703b94b9860d680a3f4d999c54bd90ff131346 100644 (file)
@@ -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
 
index 72dfb655a1b86053d139df4927f5fbd561744ac6..37d010ed3367af1dbca9000b1baa8a82401cddcd 100644 (file)
@@ -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);
 
 \f
 /*****************************************************************************/
@@ -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 (&ltext->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");
 }
 
index 83c6498223ff9da0623ab0c42117d75f81e57bbb..f315dd0b2544db4fb3a184ec90effe2ef752132d 100644 (file)
@@ -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,
index 194c97fba4adedba392d198cce29c78d656feb37..410842e237e23994ba18e1f574eb0acbc928d5a9 100644 (file)
@@ -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);
 
                }