]> 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 467cd2c51fbe072aaaad097e18b4a0fdafccf514..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,6 +612,7 @@ gl_label_object_get_size (glLabelObject *object,
        gl_debug (DEBUG_LABEL, "END");
 }
 
+
 /*****************************************************************************/
 /* Get extent of object.                                                     */
 /*****************************************************************************/
@@ -607,6 +658,7 @@ gl_label_object_get_extent (glLabelObject *object,
        gl_debug (DEBUG_LABEL, "END");
 }
 
+
 /*****************************************************************************/
 /* Can text properties be set for this object?                               */
 /*****************************************************************************/
@@ -629,6 +681,7 @@ gl_label_object_can_text (glLabelObject     *object)
 
 }
 
+
 /*****************************************************************************/
 /* Set font family for all text contained in object.                         */
 /*****************************************************************************/
@@ -650,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.                          */
 /****************************************************************************/
@@ -671,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.                        */
 /****************************************************************************/
@@ -692,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.                   */
 /****************************************************************************/
@@ -714,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.                     */
 /****************************************************************************/
@@ -736,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.                  */
 /****************************************************************************/
@@ -757,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.                         */
 /****************************************************************************/
@@ -778,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.                         */
 /*****************************************************************************/
@@ -802,6 +862,7 @@ gl_label_object_get_font_family (glLabelObject     *object)
        return ret;
 }
 
+
 /****************************************************************************/
 /* Get font size for all text contained in object.                          */
 /****************************************************************************/
@@ -826,6 +887,7 @@ gl_label_object_get_font_size (glLabelObject     *object)
        return ret;
 }
 
+
 /****************************************************************************/
 /* Get font weight for all text contained in object.                        */
 /****************************************************************************/
@@ -850,6 +912,7 @@ gl_label_object_get_font_weight (glLabelObject     *object)
        return ret;
 }
 
+
 /****************************************************************************/
 /* Get font italic flag for all text contained in object.                   */
 /****************************************************************************/
@@ -874,6 +937,7 @@ gl_label_object_get_font_italic_flag (glLabelObject     *object)
        return ret;
 }
 
+
 /****************************************************************************/
 /* Get text alignment for all text contained in object.                     */
 /****************************************************************************/
@@ -898,6 +962,7 @@ gl_label_object_get_text_alignment (glLabelObject     *object)
        return ret;
 }
 
+
 /****************************************************************************/
 /* Get text line spacing for all text contained in object.                  */
 /****************************************************************************/
@@ -922,6 +987,7 @@ gl_label_object_get_text_line_spacing (glLabelObject     *object)
        return ret;
 }
 
+
 /****************************************************************************/
 /* Get text color for all text contained in object.                         */
 /****************************************************************************/
@@ -946,6 +1012,7 @@ gl_label_object_get_text_color (glLabelObject     *object)
        return ret;
 }
 
+
 /*****************************************************************************/
 /* Can fill properties be set for this object?                               */
 /*****************************************************************************/
@@ -968,6 +1035,7 @@ gl_label_object_can_fill (glLabelObject     *object)
 
 }
 
+
 /****************************************************************************/
 /* Set fill color for object.                                               */
 /****************************************************************************/
@@ -989,6 +1057,7 @@ gl_label_object_set_fill_color (glLabelObject     *object,
        gl_debug (DEBUG_LABEL, "END");
 }
 
+
 /****************************************************************************/
 /* Get fill color for object.                                               */
 /****************************************************************************/
@@ -1013,6 +1082,7 @@ gl_label_object_get_fill_color (glLabelObject     *object)
        return ret;
 }
 
+
 /*****************************************************************************/
 /* Can line color property be set for this object?                           */
 /*****************************************************************************/
@@ -1035,6 +1105,7 @@ gl_label_object_can_line_color (glLabelObject     *object)
 
 }
 
+
 /****************************************************************************/
 /* Set line color for object.                                               */
 /****************************************************************************/
@@ -1056,6 +1127,7 @@ gl_label_object_set_line_color (glLabelObject     *object,
        gl_debug (DEBUG_LABEL, "END");
 }
 
+
 /****************************************************************************/
 /* Get line color for object.                                               */
 /****************************************************************************/
@@ -1080,6 +1152,7 @@ gl_label_object_get_line_color (glLabelObject     *object)
        return ret;
 }
 
+
 /*****************************************************************************/
 /* Can line width property be set for this object?                           */
 /*****************************************************************************/
@@ -1102,6 +1175,7 @@ gl_label_object_can_line_width (glLabelObject     *object)
 
 }
 
+
 /****************************************************************************/
 /* Set line width for object.                                               */
 /****************************************************************************/
@@ -1123,6 +1197,7 @@ gl_label_object_set_line_width (glLabelObject     *object,
        gl_debug (DEBUG_LABEL, "END");
 }
 
+
 /****************************************************************************/
 /* Get line width for object.                                               */
 /****************************************************************************/
@@ -1147,6 +1222,7 @@ gl_label_object_get_line_width (glLabelObject     *object)
        return ret;
 }
 
+
 /****************************************************************************/
 /* Set shadow state of object.                                              */
 /****************************************************************************/
@@ -1167,6 +1243,7 @@ gl_label_object_set_shadow_state (glLabelObject     *object,
        gl_debug (DEBUG_LABEL, "END");
 }
 
+
 /****************************************************************************/
 /* Get shadow state of object.                                              */
 /****************************************************************************/
@@ -1180,6 +1257,7 @@ gl_label_object_get_shadow_state (glLabelObject     *object)
        return object->priv->shadow_state;
 }
 
+
 /****************************************************************************/
 /* Set offset of object's shadow.                                           */
 /****************************************************************************/
@@ -1203,6 +1281,7 @@ gl_label_object_set_shadow_offset (glLabelObject     *object,
        gl_debug (DEBUG_LABEL, "END");
 }
 
+
 /****************************************************************************/
 /* Get offset of object's shadow.                                           */
 /****************************************************************************/
@@ -1221,6 +1300,7 @@ gl_label_object_get_shadow_offset (glLabelObject     *object,
        gl_debug (DEBUG_LABEL, "END");
 }
 
+
 /****************************************************************************/
 /* Set color of object's shadow.                                            */
 /****************************************************************************/
@@ -1242,6 +1322,7 @@ gl_label_object_set_shadow_color (glLabelObject     *object,
        gl_debug (DEBUG_LABEL, "END");
 }
 
+
 /****************************************************************************/
 /* Get color of object's shadow.                                            */
 /****************************************************************************/
@@ -1255,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.                                          */
 /****************************************************************************/
@@ -1275,6 +1357,7 @@ gl_label_object_set_shadow_opacity (glLabelObject     *object,
        gl_debug (DEBUG_LABEL, "END");
 }
 
+
 /****************************************************************************/
 /* Get opacity of object's shadow.                                          */
 /****************************************************************************/
@@ -1288,6 +1371,7 @@ gl_label_object_get_shadow_opacity (glLabelObject     *object)
        return object->priv->shadow_opacity;
 }
 
+
 /****************************************************************************/
 /* Flip object horizontally.                                                */
 /****************************************************************************/
@@ -1308,6 +1392,7 @@ gl_label_object_flip_horiz (glLabelObject *object)
        gl_debug (DEBUG_LABEL, "END");
 }
 
+
 /****************************************************************************/
 /* Flip object vertically.                                                  */
 /****************************************************************************/
@@ -1328,6 +1413,7 @@ gl_label_object_flip_vert (glLabelObject *object)
        gl_debug (DEBUG_LABEL, "END");
 }
 
+
 /****************************************************************************/
 /* Rotate object.                                                           */
 /****************************************************************************/
@@ -1349,6 +1435,7 @@ gl_label_object_rotate (glLabelObject *object,
        gl_debug (DEBUG_LABEL, "END");
 }
 
+
 /****************************************************************************/
 /* Set raw affine                                                           */
 /****************************************************************************/
@@ -1363,6 +1450,7 @@ gl_label_object_set_matrix (glLabelObject  *object,
         object->priv->matrix = *matrix;
 }
 
+
 /****************************************************************************/
 /* Get raw affine                                                           */
 /****************************************************************************/
@@ -1377,6 +1465,7 @@ gl_label_object_get_matrix (glLabelObject  *object,
         *matrix = object->priv->matrix;
 }
 
+
 /****************************************************************************/
 /* Bring label object to front/top.                                         */
 /****************************************************************************/
@@ -1396,6 +1485,7 @@ gl_label_object_raise_to_top (glLabelObject *object)
        gl_debug (DEBUG_LABEL, "END");
 }
 
+
 /****************************************************************************/
 /* Send label object to rear/bottom.                                        */
 /****************************************************************************/
@@ -1415,6 +1505,7 @@ gl_label_object_lower_to_bottom (glLabelObject *object)
        gl_debug (DEBUG_LABEL, "END");
 }
 
+
 /*--------------------------------------------------------------------------*/
 /* PRIVATE.  Label's merge data changed callback.                           */
 /*--------------------------------------------------------------------------*/
@@ -1425,6 +1516,7 @@ merge_changed_cb (glLabel       *label,
        gl_label_object_emit_changed (object);
 }
 
+
 /*****************************************************************************/
 /* Draw object                                                               */
 /*****************************************************************************/
@@ -1489,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
+ */