]> git.sur5r.net Git - glabels/blobdiff - glabels2/src/label-object.c
2009-09-17 Jim Evins <evins@snaught.com>
[glabels] / glabels2 / src / label-object.c
index f4b4395504ddbc24e46a3621136cc9d3f026cae2..89cefc98a9e3568f1c0d51789f831373cb6c0896 100644 (file)
@@ -1,33 +1,28 @@
-/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- */
-
 /*
- *  (GLABELS) Label and Business Card Creation program for GNOME
- *
- *  label_object.c:  GLabels label object base class
+ *  label-object.c
+ *  Copyright (C) 2001-2009  Jim Evins <evins@snaught.com>.
  *
- *  Copyright (C) 2001-2007  Jim Evins <evins@snaught.com>.
+ *  This file is part of gLabels.
  *
- *  This program is free software; you can redistribute it and/or modify
+ *  gLabels is free software: you can redistribute it and/or modify
  *  it under the terms of the GNU General Public License as published by
- *  the Free Software Foundation; either version 2 of the License, or
+ *  the Free Software Foundation, either version 3 of the License, or
  *  (at your option) any later version.
  *
- *  This program is distributed in the hope that it will be useful,
+ *  gLabels is distributed in the hope that it will be useful,
  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  *  GNU General Public License for more details.
  *
  *  You should have received a copy of the GNU General Public License
- *  along with this program; if not, write to the Free Software
- *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
+ *  along with gLabels.  If not, see <http://www.gnu.org/licenses/>.
  */
+
 #include <config.h>
 
 #include "label-object.h"
 
-#include <glib/gmem.h>
-#include <glib/gstrfuncs.h>
-#include <glib/gmessages.h>
+#include <glib.h>
 #include <math.h>
 
 #include "marshal.h"
@@ -43,6 +38,7 @@
 #define DEFAULT_SHADOW_Y_OFFSET (3.6)
 #define DEFAULT_SHADOW_OPACITY  (0.5)
 
+
 /*========================================================*/
 /* Private types.                                         */
 /*========================================================*/
@@ -68,9 +64,11 @@ enum {
        FLIP_ROTATE,
        TOP,
        BOTTOM,
+        REMOVED,
        LAST_SIGNAL
 };
 
+
 /*========================================================*/
 /* Private globals.                                       */
 /*========================================================*/
@@ -79,6 +77,7 @@ static guint signals[LAST_SIGNAL] = {0};
 
 static guint instance = 0;
 
+
 /*========================================================*/
 /* Private function prototypes.                           */
 /*========================================================*/
@@ -93,12 +92,12 @@ static void set_size                      (glLabelObject      *object,
                                           gdouble             h);
 
 
-\f
 /*****************************************************************************/
 /* Boilerplate object stuff.                                                 */
 /*****************************************************************************/
 G_DEFINE_TYPE (glLabelObject, gl_label_object, G_TYPE_OBJECT);
 
+
 static void
 gl_label_object_class_init (glLabelObjectClass *class)
 {
@@ -159,10 +158,20 @@ gl_label_object_class_init (glLabelObjectClass *class)
                              gl_marshal_VOID__VOID,
                              G_TYPE_NONE,
                              0);
+       signals[REMOVED] =
+               g_signal_new ("removed",
+                             G_OBJECT_CLASS_TYPE (object_class),
+                             G_SIGNAL_RUN_LAST,
+                             G_STRUCT_OFFSET (glLabelObjectClass, removed),
+                             NULL, NULL,
+                             gl_marshal_VOID__VOID,
+                             G_TYPE_NONE,
+                             0);
 
        gl_debug (DEBUG_LABEL, "END");
 }
 
+
 static void
 gl_label_object_init (glLabelObject *object)
 {
@@ -183,19 +192,16 @@ gl_label_object_init (glLabelObject *object)
        gl_debug (DEBUG_LABEL, "END");
 }
 
+
 static void
 gl_label_object_finalize (GObject *object)
 {
         glLabelObject *label_object = GL_LABEL_OBJECT (object);
-       glLabel       *parent;
 
        gl_debug (DEBUG_LABEL, "START");
 
        g_return_if_fail (object && GL_IS_LABEL_OBJECT (object));
 
-       parent = label_object->parent;
-       gl_label_remove_object (parent, label_object);
-
        g_free (label_object->priv->name);
        g_free (label_object->priv);
 
@@ -204,6 +210,7 @@ gl_label_object_finalize (GObject *object)
        gl_debug (DEBUG_LABEL, "END");
 }
 
+
 /*****************************************************************************/
 /* New label object.                                                         */
 /*****************************************************************************/
@@ -223,6 +230,7 @@ gl_label_object_new (glLabel *label)
        return G_OBJECT (object);
 }
 
+
 /*****************************************************************************/
 /* Duplicate object.                                                         */
 /*****************************************************************************/
@@ -276,6 +284,7 @@ gl_label_object_dup (glLabelObject *src_object,
        return dst_object;
 }
 
+
 /*****************************************************************************/
 /* Emit "changed" signal (for derived objects).                              */
 /*****************************************************************************/
@@ -291,6 +300,7 @@ gl_label_object_emit_changed (glLabelObject *object)
        gl_debug (DEBUG_LABEL, "END");
 }
 
+
 /*****************************************************************************/
 /* Set parent label of object.                                               */
 /*****************************************************************************/
@@ -322,6 +332,7 @@ gl_label_object_set_parent (glLabelObject *object,
        gl_debug (DEBUG_LABEL, "END");
 }
 
+
 /*****************************************************************************/
 /* Get parent label of object.                                               */
 /*****************************************************************************/
@@ -337,6 +348,36 @@ gl_label_object_get_parent (glLabelObject *object)
        return object->parent;
 }
 
+
+/*****************************************************************************/
+/* Set remove object from parent.                                            */
+/*****************************************************************************/
+void
+gl_label_object_remove (glLabelObject *object)
+{
+       glLabel *parent;
+
+       gl_debug (DEBUG_LABEL, "START");
+
+       g_return_if_fail (object && GL_IS_LABEL_OBJECT (object));
+
+       parent = object->parent;
+       if ( parent != NULL ) {
+               g_signal_handlers_disconnect_by_func (parent,
+                                                     G_CALLBACK(merge_changed_cb),
+                                                     object);
+               gl_label_remove_object (parent, object);
+
+                g_signal_emit (G_OBJECT(object), signals[REMOVED], 0);
+
+                g_object_unref (G_OBJECT(object));
+       }
+
+
+       gl_debug (DEBUG_LABEL, "END");
+}
+
+
 /*****************************************************************************/
 /* Set name of object.                                                       */
 /*****************************************************************************/
@@ -356,6 +397,7 @@ gl_label_object_set_name (glLabelObject *object,
        gl_debug (DEBUG_LABEL, "END");
 }
 
+
 /*****************************************************************************/
 /* Get name of object.                                                       */
 /*****************************************************************************/
@@ -371,6 +413,7 @@ gl_label_object_get_name (glLabelObject *object)
        return g_strdup(object->priv->name);
 }
 
+
 /*****************************************************************************/
 /* Set position of object.                                                   */
 /*****************************************************************************/
@@ -400,6 +443,7 @@ gl_label_object_set_position (glLabelObject *object,
        gl_debug (DEBUG_LABEL, "END");
 }
 
+
 /*****************************************************************************/
 /* Set position of object relative to old position.                          */
 /*****************************************************************************/
@@ -428,6 +472,7 @@ gl_label_object_set_position_relative (glLabelObject *object,
        gl_debug (DEBUG_LABEL, "END");
 }
 
+
 /*****************************************************************************/
 /* Get position of object.                                                   */
 /*****************************************************************************/
@@ -446,6 +491,7 @@ gl_label_object_get_position (glLabelObject *object,
        gl_debug (DEBUG_LABEL, "END");
 }
 
+
 /*---------------------------------------------------------------------------*/
 /* PRIVATE.  Default set size method.                                        */
 /*---------------------------------------------------------------------------*/
@@ -465,6 +511,7 @@ set_size (glLabelObject *object,
        }
 }
 
+
 /*****************************************************************************/
 /* Set size of object.                                                       */
 /*****************************************************************************/
@@ -490,6 +537,7 @@ gl_label_object_set_size (glLabelObject *object,
        gl_debug (DEBUG_LABEL, "END");
 }
 
+
 /*****************************************************************************/
 /* Set size of object honoring current aspect ratio.                         */
 /*****************************************************************************/
@@ -522,6 +570,7 @@ gl_label_object_set_size_honor_aspect (glLabelObject *object,
        gl_debug (DEBUG_LABEL, "END");
 }
 
+
 /*****************************************************************************/
 /* Get raw size method (don't let object content adjust size).               */
 /*****************************************************************************/
@@ -536,6 +585,7 @@ gl_label_object_get_raw_size (glLabelObject *object,
        *h = object->priv->h;
 }
 
+
 /*****************************************************************************/
 /* Get size of object.                                                       */
 /*****************************************************************************/
@@ -562,18 +612,17 @@ gl_label_object_get_size (glLabelObject *object,
        gl_debug (DEBUG_LABEL, "END");
 }
 
+
 /*****************************************************************************/
 /* Get extent of object.                                                     */
 /*****************************************************************************/
 void
 gl_label_object_get_extent (glLabelObject *object,
-                           gdouble       *x1,
-                           gdouble       *y1,
-                           gdouble       *x2,
-                           gdouble       *y2)
+                            glLabelRegion *region)
 {
-       gdouble  w, h;
-       gdouble xa1, ya1, xa2, ya2, xa3, ya3, xa4, ya4;
+       gdouble        w, h;
+        gdouble        line_w;
+       gdouble        xa1, ya1, xa2, ya2, xa3, ya3, xa4, ya4;
         cairo_matrix_t matrix;
 
        gl_debug (DEBUG_LABEL, "START");
@@ -581,16 +630,17 @@ gl_label_object_get_extent (glLabelObject *object,
        g_return_if_fail (object && GL_IS_LABEL_OBJECT (object));
 
        gl_label_object_get_size (object, &w, &h);
-
-       /* setup untransformed corners of bounding box */
-       xa1 = 0.0;
-       ya1 = 0.0;
-       xa2 = w;
-       ya2 = 0.0;
-       xa3 = w;
-       ya3 = h;
-       xa4 = 0.0;
-       ya4 = h;
+        line_w = gl_label_object_get_line_width (object);
+
+       /* setup untransformed corners of bounding box, account for line width */
+       xa1 =   - line_w/2;
+       ya1 =   - line_w/2;
+       xa2 = w + line_w/2;
+       ya2 =   - line_w/2;
+       xa3 = w + line_w/2;
+       ya3 = h + line_w/2;
+       xa4 =   - line_w/2;
+       ya4 = h + line_w/2;
 
        /* transform these points */
        gl_label_object_get_matrix (object, &matrix);
@@ -600,14 +650,15 @@ gl_label_object_get_extent (glLabelObject *object,
         cairo_matrix_transform_point (&matrix, &xa4, &ya4);
 
        /* now find the maximum extent of these points in x and y */
-       *x1 = MIN (xa1, MIN (xa2, MIN (xa3, xa4))) + object->priv->x;
-       *y1 = MIN (ya1, MIN (ya2, MIN (ya3, ya4))) + object->priv->y;
-       *x2 = MAX (xa1, MAX (xa2, MAX (xa3, xa4))) + object->priv->x;
-       *y2 = MAX (ya1, MAX (ya2, MAX (ya3, ya4))) + object->priv->y;
+       region->x1 = MIN (xa1, MIN (xa2, MIN (xa3, xa4))) + object->priv->x;
+       region->y1 = MIN (ya1, MIN (ya2, MIN (ya3, ya4))) + object->priv->y;
+       region->x2 = MAX (xa1, MAX (xa2, MAX (xa3, xa4))) + object->priv->x;
+       region->y2 = MAX (ya1, MAX (ya2, MAX (ya3, ya4))) + object->priv->y;
 
        gl_debug (DEBUG_LABEL, "END");
 }
 
+
 /*****************************************************************************/
 /* Can text properties be set for this object?                               */
 /*****************************************************************************/
@@ -630,6 +681,7 @@ gl_label_object_can_text (glLabelObject     *object)
 
 }
 
+
 /*****************************************************************************/
 /* Set font family for all text contained in object.                         */
 /*****************************************************************************/
@@ -651,6 +703,7 @@ gl_label_object_set_font_family (glLabelObject     *object,
        gl_debug (DEBUG_LABEL, "END");
 }
 
+
 /****************************************************************************/
 /* Set font size for all text contained in object.                          */
 /****************************************************************************/
@@ -672,6 +725,7 @@ gl_label_object_set_font_size (glLabelObject     *object,
        gl_debug (DEBUG_LABEL, "END");
 }
 
+
 /****************************************************************************/
 /* Set font weight for all text contained in object.                        */
 /****************************************************************************/
@@ -693,6 +747,7 @@ gl_label_object_set_font_weight (glLabelObject     *object,
        gl_debug (DEBUG_LABEL, "END");
 }
 
+
 /****************************************************************************/
 /* Set font italic flag for all text contained in object.                   */
 /****************************************************************************/
@@ -715,6 +770,7 @@ gl_label_object_set_font_italic_flag (glLabelObject     *object,
        gl_debug (DEBUG_LABEL, "END");
 }
 
+
 /****************************************************************************/
 /* Set text alignment for all text contained in object.                     */
 /****************************************************************************/
@@ -737,6 +793,7 @@ gl_label_object_set_text_alignment (glLabelObject     *object,
        gl_debug (DEBUG_LABEL, "END");
 }
 
+
 /****************************************************************************/
 /* Set text line spacing for all text contained in object.                  */
 /****************************************************************************/
@@ -758,6 +815,7 @@ gl_label_object_set_text_line_spacing (glLabelObject     *object,
        gl_debug (DEBUG_LABEL, "END");
 }
 
+
 /****************************************************************************/
 /* Set text color for all text contained in object.                         */
 /****************************************************************************/
@@ -779,6 +837,7 @@ gl_label_object_set_text_color (glLabelObject     *object,
        gl_debug (DEBUG_LABEL, "END");
 }
 
+
 /*****************************************************************************/
 /* Get font family for all text contained in object.                         */
 /*****************************************************************************/
@@ -803,6 +862,7 @@ gl_label_object_get_font_family (glLabelObject     *object)
        return ret;
 }
 
+
 /****************************************************************************/
 /* Get font size for all text contained in object.                          */
 /****************************************************************************/
@@ -827,6 +887,7 @@ gl_label_object_get_font_size (glLabelObject     *object)
        return ret;
 }
 
+
 /****************************************************************************/
 /* Get font weight for all text contained in object.                        */
 /****************************************************************************/
@@ -851,6 +912,7 @@ gl_label_object_get_font_weight (glLabelObject     *object)
        return ret;
 }
 
+
 /****************************************************************************/
 /* Get font italic flag for all text contained in object.                   */
 /****************************************************************************/
@@ -875,6 +937,7 @@ gl_label_object_get_font_italic_flag (glLabelObject     *object)
        return ret;
 }
 
+
 /****************************************************************************/
 /* Get text alignment for all text contained in object.                     */
 /****************************************************************************/
@@ -899,6 +962,7 @@ gl_label_object_get_text_alignment (glLabelObject     *object)
        return ret;
 }
 
+
 /****************************************************************************/
 /* Get text line spacing for all text contained in object.                  */
 /****************************************************************************/
@@ -923,6 +987,7 @@ gl_label_object_get_text_line_spacing (glLabelObject     *object)
        return ret;
 }
 
+
 /****************************************************************************/
 /* Get text color for all text contained in object.                         */
 /****************************************************************************/
@@ -947,6 +1012,7 @@ gl_label_object_get_text_color (glLabelObject     *object)
        return ret;
 }
 
+
 /*****************************************************************************/
 /* Can fill properties be set for this object?                               */
 /*****************************************************************************/
@@ -969,6 +1035,7 @@ gl_label_object_can_fill (glLabelObject     *object)
 
 }
 
+
 /****************************************************************************/
 /* Set fill color for object.                                               */
 /****************************************************************************/
@@ -990,6 +1057,7 @@ gl_label_object_set_fill_color (glLabelObject     *object,
        gl_debug (DEBUG_LABEL, "END");
 }
 
+
 /****************************************************************************/
 /* Get fill color for object.                                               */
 /****************************************************************************/
@@ -1014,6 +1082,7 @@ gl_label_object_get_fill_color (glLabelObject     *object)
        return ret;
 }
 
+
 /*****************************************************************************/
 /* Can line color property be set for this object?                           */
 /*****************************************************************************/
@@ -1036,6 +1105,7 @@ gl_label_object_can_line_color (glLabelObject     *object)
 
 }
 
+
 /****************************************************************************/
 /* Set line color for object.                                               */
 /****************************************************************************/
@@ -1057,6 +1127,7 @@ gl_label_object_set_line_color (glLabelObject     *object,
        gl_debug (DEBUG_LABEL, "END");
 }
 
+
 /****************************************************************************/
 /* Get line color for object.                                               */
 /****************************************************************************/
@@ -1081,6 +1152,7 @@ gl_label_object_get_line_color (glLabelObject     *object)
        return ret;
 }
 
+
 /*****************************************************************************/
 /* Can line width property be set for this object?                           */
 /*****************************************************************************/
@@ -1103,6 +1175,7 @@ gl_label_object_can_line_width (glLabelObject     *object)
 
 }
 
+
 /****************************************************************************/
 /* Set line width for object.                                               */
 /****************************************************************************/
@@ -1124,6 +1197,7 @@ gl_label_object_set_line_width (glLabelObject     *object,
        gl_debug (DEBUG_LABEL, "END");
 }
 
+
 /****************************************************************************/
 /* Get line width for object.                                               */
 /****************************************************************************/
@@ -1148,6 +1222,7 @@ gl_label_object_get_line_width (glLabelObject     *object)
        return ret;
 }
 
+
 /****************************************************************************/
 /* Set shadow state of object.                                              */
 /****************************************************************************/
@@ -1168,6 +1243,7 @@ gl_label_object_set_shadow_state (glLabelObject     *object,
        gl_debug (DEBUG_LABEL, "END");
 }
 
+
 /****************************************************************************/
 /* Get shadow state of object.                                              */
 /****************************************************************************/
@@ -1181,6 +1257,7 @@ gl_label_object_get_shadow_state (glLabelObject     *object)
        return object->priv->shadow_state;
 }
 
+
 /****************************************************************************/
 /* Set offset of object's shadow.                                           */
 /****************************************************************************/
@@ -1204,6 +1281,7 @@ gl_label_object_set_shadow_offset (glLabelObject     *object,
        gl_debug (DEBUG_LABEL, "END");
 }
 
+
 /****************************************************************************/
 /* Get offset of object's shadow.                                           */
 /****************************************************************************/
@@ -1222,6 +1300,7 @@ gl_label_object_get_shadow_offset (glLabelObject     *object,
        gl_debug (DEBUG_LABEL, "END");
 }
 
+
 /****************************************************************************/
 /* Set color of object's shadow.                                            */
 /****************************************************************************/
@@ -1243,6 +1322,7 @@ gl_label_object_set_shadow_color (glLabelObject     *object,
        gl_debug (DEBUG_LABEL, "END");
 }
 
+
 /****************************************************************************/
 /* Get color of object's shadow.                                            */
 /****************************************************************************/
@@ -1256,6 +1336,7 @@ gl_label_object_get_shadow_color (glLabelObject     *object)
        return gl_color_node_dup (object->priv->shadow_color_node);
 }
 
+
 /****************************************************************************/
 /* Set opacity of object's shadow.                                          */
 /****************************************************************************/
@@ -1276,6 +1357,7 @@ gl_label_object_set_shadow_opacity (glLabelObject     *object,
        gl_debug (DEBUG_LABEL, "END");
 }
 
+
 /****************************************************************************/
 /* Get opacity of object's shadow.                                          */
 /****************************************************************************/
@@ -1289,6 +1371,7 @@ gl_label_object_get_shadow_opacity (glLabelObject     *object)
        return object->priv->shadow_opacity;
 }
 
+
 /****************************************************************************/
 /* Flip object horizontally.                                                */
 /****************************************************************************/
@@ -1309,6 +1392,7 @@ gl_label_object_flip_horiz (glLabelObject *object)
        gl_debug (DEBUG_LABEL, "END");
 }
 
+
 /****************************************************************************/
 /* Flip object vertically.                                                  */
 /****************************************************************************/
@@ -1329,6 +1413,7 @@ gl_label_object_flip_vert (glLabelObject *object)
        gl_debug (DEBUG_LABEL, "END");
 }
 
+
 /****************************************************************************/
 /* Rotate object.                                                           */
 /****************************************************************************/
@@ -1350,6 +1435,7 @@ gl_label_object_rotate (glLabelObject *object,
        gl_debug (DEBUG_LABEL, "END");
 }
 
+
 /****************************************************************************/
 /* Set raw affine                                                           */
 /****************************************************************************/
@@ -1364,6 +1450,7 @@ gl_label_object_set_matrix (glLabelObject  *object,
         object->priv->matrix = *matrix;
 }
 
+
 /****************************************************************************/
 /* Get raw affine                                                           */
 /****************************************************************************/
@@ -1378,6 +1465,7 @@ gl_label_object_get_matrix (glLabelObject  *object,
         *matrix = object->priv->matrix;
 }
 
+
 /****************************************************************************/
 /* Bring label object to front/top.                                         */
 /****************************************************************************/
@@ -1397,6 +1485,7 @@ gl_label_object_raise_to_top (glLabelObject *object)
        gl_debug (DEBUG_LABEL, "END");
 }
 
+
 /****************************************************************************/
 /* Send label object to rear/bottom.                                        */
 /****************************************************************************/
@@ -1416,6 +1505,7 @@ gl_label_object_lower_to_bottom (glLabelObject *object)
        gl_debug (DEBUG_LABEL, "END");
 }
 
+
 /*--------------------------------------------------------------------------*/
 /* PRIVATE.  Label's merge data changed callback.                           */
 /*--------------------------------------------------------------------------*/
@@ -1426,6 +1516,7 @@ merge_changed_cb (glLabel       *label,
        gl_label_object_emit_changed (object);
 }
 
+
 /*****************************************************************************/
 /* Draw object                                                               */
 /*****************************************************************************/
@@ -1490,3 +1581,14 @@ gl_label_object_draw (glLabelObject *object,
        gl_debug (DEBUG_LABEL, "END");
 }
 
+
+
+
+/*
+ * Local Variables:       -- emacs
+ * mode: C                -- emacs
+ * c-basic-offset: 8      -- emacs
+ * tab-width: 8           -- emacs
+ * indent-tabs-mode: nil  -- emacs
+ * End:                   -- emacs
+ */