]> git.sur5r.net Git - glabels/commitdiff
2007-09-14 Jim Evins <evins@snaught.com>
authorJim Evins <evins@snaught.com>
Sat, 15 Sep 2007 02:02:57 +0000 (02:02 +0000)
committerJim Evins <evins@snaught.com>
Sat, 15 Sep 2007 02:02:57 +0000 (02:02 +0000)
* src/marshal.list:
* src/label.c:
* src/label.h:
* src/label-object.c:
* src/label-object.h:
* src/label-barcode.c:
* src/label-ellipse.c:
* src/view.c:
* src/view-object.c:
* src/view-barcode.c:
* src/view-box.c:
* src/view-ellipse.c:
* src/view-image.c:
* src/view-line.c:
* src/view-text.c:
Better separation of model from view.

git-svn-id: https://glabels.svn.sourceforge.net/svnroot/glabels/trunk@673 f5e0f49d-192f-0410-a22d-a8d8700d0965

16 files changed:
glabels2/ChangeLog
glabels2/src/label-barcode.c
glabels2/src/label-ellipse.c
glabels2/src/label-object.c
glabels2/src/label-object.h
glabels2/src/label.c
glabels2/src/label.h
glabels2/src/marshal.list
glabels2/src/view-barcode.c
glabels2/src/view-box.c
glabels2/src/view-ellipse.c
glabels2/src/view-image.c
glabels2/src/view-line.c
glabels2/src/view-object.c
glabels2/src/view-text.c
glabels2/src/view.c

index 3266fd8722bb98dd82cdf899eba31e306afe4793..129791cf2b1bfab1d8b07236cfb5a77cf212f838 100644 (file)
@@ -1,3 +1,22 @@
+2007-09-14  Jim Evins  <evins@snaught.com>
+
+       * src/marshal.list:
+       * src/label.c:
+       * src/label.h:
+       * src/label-object.c:
+       * src/label-object.h:
+       * src/label-barcode.c:
+       * src/label-ellipse.c:
+       * src/view.c:
+       * src/view-object.c:
+       * src/view-barcode.c:
+       * src/view-box.c:
+       * src/view-ellipse.c:
+       * src/view-image.c:
+       * src/view-line.c:
+       * src/view-text.c:
+               Better separation of model from view.
+
 2007-08-21  Jim Evins  <evins@snaught.com>
 
        * src/print-op.c: (create_custom_widget_cb):
index 9f93d0114eb09160b63a065531f632eab458ddcb..9cb08043e8cb2ad679cc5ef9435f56df9cc28bbd 100644 (file)
@@ -109,6 +109,7 @@ gl_label_barcode_init (glLabelBarcode *lbc)
 {
        lbc->priv = g_new0 (glLabelBarcodePrivate, 1);
        lbc->priv->color_node = gl_color_node_new_default ();
+       lbc->priv->text_node  = gl_text_node_new_from_text ("");
 }
 
 static void
@@ -127,7 +128,7 @@ gl_label_barcode_finalize (GObject *object)
 }
 
 /*****************************************************************************/
-/* NEW label "text" object.                                               */
+/* NEW label "barcode" object.                                               */
 /*****************************************************************************/
 GObject *
 gl_label_barcode_new (glLabel *label)
index efc8dd88b7e42faba5a581eae7717079cdc0ad89..fb21cbf2cafedfb4fca286045ec03e6dc9ab41ac 100644 (file)
@@ -118,7 +118,7 @@ static void
 gl_label_ellipse_init (glLabelEllipse *lellipse)
 {
        lellipse->priv = g_new0 (glLabelEllipsePrivate, 1);
-       lellipse->priv->fill_color_node = gl_color_node_new_default ();
+       lellipse->priv->line_color_node = gl_color_node_new_default ();
        lellipse->priv->fill_color_node = gl_color_node_new_default ();
 }
 
index 467cd2c51fbe072aaaad097e18b4a0fdafccf514..24cfdb20e7ea9cf0a9828fae67fc12ab6fb888d1 100644 (file)
@@ -68,6 +68,7 @@ enum {
        FLIP_ROTATE,
        TOP,
        BOTTOM,
+        REMOVED,
        LAST_SIGNAL
 };
 
@@ -159,6 +160,15 @@ 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");
 }
@@ -193,9 +203,6 @@ gl_label_object_finalize (GObject *object)
 
        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);
 
@@ -337,6 +344,34 @@ 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.                                                       */
 /*****************************************************************************/
index d7a62764d98133f9bc5eab3be337ab780b8fffe3..5ee0f9bac6e49a227d472a7f747b424fc9496264 100644 (file)
@@ -167,6 +167,10 @@ struct _glLabelObjectClass {
 
         void (*bottom)      (glLabelObject     *object,
                              gpointer           user_data);
+
+        void (*removed)     (glLabelObject     *object,
+                             gpointer            user_data);
+
 };
 
 GType          gl_label_object_get_type              (void) G_GNUC_CONST;
@@ -186,6 +190,8 @@ void           gl_label_object_set_parent            (glLabelObject     *object,
 glLabel       *gl_label_object_get_parent            (glLabelObject     *object);
 
 
+void           gl_label_object_remove                (glLabelObject     *object);
+
 void           gl_label_object_set_name              (glLabelObject     *object,
                                                       gchar             *name);
 
index fc4122d77ad49410d0727ee060764ba2876305a8..d335a7bd1d31c1acaa6a75653908395c1849d59d 100644 (file)
@@ -59,6 +59,7 @@ enum {
        MODIFIED_CHANGED,
        MERGE_CHANGED,
        SIZE_CHANGED,
+        OBJECT_ADDED,
        LAST_SIGNAL
 };
 
@@ -146,6 +147,15 @@ gl_label_class_init (glLabelClass *class)
                              gl_marshal_VOID__VOID,
                              G_TYPE_NONE,
                              0);
+       signals[OBJECT_ADDED] =
+               g_signal_new ("object_added",
+                             G_OBJECT_CLASS_TYPE (object_class),
+                             G_SIGNAL_RUN_LAST,
+                             G_STRUCT_OFFSET (glLabelClass, object_added),
+                             NULL, NULL,
+                             gl_marshal_VOID__OBJECT,
+                             G_TYPE_NONE,
+                             1, G_TYPE_OBJECT);
 
        gl_debug (DEBUG_LABEL, "END");
 }
@@ -226,15 +236,16 @@ gl_label_add_object (glLabel       *label,
        gl_debug (DEBUG_LABEL, "START");
 
        g_return_if_fail (label && GL_IS_LABEL (label));
-       g_return_if_fail (GL_IS_LABEL_OBJECT (object));
+       g_return_if_fail (object && GL_IS_LABEL_OBJECT (object));
 
        object->parent = label;
-       label->objects = g_list_append (label->objects, object);
+       label->objects = g_list_append (label->objects, g_object_ref (object));
 
        label->priv->modified_flag = TRUE;
 
-       g_signal_emit (G_OBJECT(label), signals[MODIFIED_CHANGED], 0);
+       g_signal_emit (G_OBJECT(label), signals[OBJECT_ADDED], 0, object);
        g_signal_emit (G_OBJECT(label), signals[CHANGED], 0);
+       g_signal_emit (G_OBJECT(label), signals[MODIFIED_CHANGED], 0);
 
        g_signal_connect (G_OBJECT(object), "changed",
                          G_CALLBACK(object_changed_cb), label);
@@ -271,8 +282,8 @@ gl_label_remove_object (glLabel       *label,
 
                label->priv->modified_flag = TRUE;
 
-               g_signal_emit (G_OBJECT(label), signals[MODIFIED_CHANGED], 0);
                g_signal_emit (G_OBJECT(label), signals[CHANGED], 0);
+               g_signal_emit (G_OBJECT(label), signals[MODIFIED_CHANGED], 0);
 
        }
 
index a3a9e5f40d43def77c696480f0405fe6b08ea7f7..d03cb8243caa5faa86c04a13b4d27b7095a03691 100644 (file)
@@ -76,6 +76,10 @@ struct _glLabelClass {
 
        void (*size_changed)     (glLabel *label, gpointer user_data);
 
+       void (*object_added)     (glLabel       *label,
+                                  glLabelObject *object,
+                                  gpointer       user_data);
+
 };
 
 
index 019f5a6eaff521dc295dbb9cd94d280215a14a73..ea17eaf346794b5eb9eedadc5deb1eb0efbb0385 100644 (file)
@@ -1,10 +1,7 @@
 VOID:VOID
-VOID:BOOLEAN
 VOID:INT
 VOID:INT,INT
 VOID:INT,UINT
-VOID:INT,DOUBLE
 VOID:DOUBLE
 VOID:DOUBLE,DOUBLE
-VOID:STRING
-BOOLEAN:OBJECT
+VOID:OBJECT
index 11b2384a11ca31b58517e6aac856ebc1496d1f38..309287ae8ded2bc8605204cdc5e6584f26ff0338 100644 (file)
@@ -406,6 +406,8 @@ gl_view_barcode_create_button_press_event   (glView *view,
        glColorNode         *line_color_node;
         glViewObject        *view_barcode;
 
+        gl_view_unselect_all (view);
+
         line_color_node = gl_color_node_new_default ();
                
         object = gl_label_barcode_new (view->label);
@@ -418,10 +420,6 @@ gl_view_barcode_create_button_press_event   (glView *view,
 
         gl_color_node_free (&line_color_node);
 
-        gl_view_unselect_all (view);
-        view_barcode = gl_view_barcode_new (GL_LABEL_BARCODE(object), view);
-        gl_view_object_select (GL_VIEW_OBJECT(view_barcode));
-                       
         view->create_object = GL_LABEL_OBJECT (object);
         view->create_x0 = x;
         view->create_y0 = y;
index ec3e8a260215d85f3e72a9e96de1be83fd5c8bc2..bd72252f6e114022431d3e6ec242ec92ccb7c73b 100644 (file)
@@ -444,6 +444,8 @@ gl_view_box_create_button_press_event   (glView *view,
        glColorNode         *line_color_node;
         glViewObject        *view_box;
 
+        gl_view_unselect_all (view);
+
         fill_color_node = gl_color_node_new_default ();
         line_color_node = gl_color_node_new_default ();
                
@@ -461,10 +463,6 @@ gl_view_box_create_button_press_event   (glView *view,
 
         gl_color_node_free (&fill_color_node);
         gl_color_node_free (&line_color_node);
-
-        gl_view_unselect_all (view);
-        view_box = gl_view_box_new (GL_LABEL_BOX(object), view);
-        gl_view_object_select (GL_VIEW_OBJECT(view_box));
                        
         view->create_object = GL_LABEL_OBJECT (object);
         view->create_x0 = x;
index 4bfa66916cbd44496aa55380853b42f7ec3f9933..cebbc863603bb248d9cb86089de04c0c9abc6560 100644 (file)
@@ -139,7 +139,7 @@ gl_view_ellipse_finalize (GObject *object)
 /*****************************************************************************/
 glViewObject *
 gl_view_ellipse_new (glLabelEllipse *object,
-                     glView     *view)
+                     glView         *view)
 {
        glViewEllipse         *view_ellipse;
 
@@ -444,6 +444,8 @@ gl_view_ellipse_create_button_press_event   (glView *view,
        glColorNode         *line_color_node;
         glViewObject        *view_ellipse;
 
+        gl_view_unselect_all (view);
+
         fill_color_node = gl_color_node_new_default ();
         line_color_node = gl_color_node_new_default ();
                
@@ -462,10 +464,6 @@ gl_view_ellipse_create_button_press_event   (glView *view,
         gl_color_node_free (&fill_color_node);
         gl_color_node_free (&line_color_node);
 
-        gl_view_unselect_all (view);
-        view_ellipse = gl_view_ellipse_new (GL_LABEL_ELLIPSE(object), view);
-        gl_view_object_select (GL_VIEW_OBJECT(view_ellipse));
-                       
         view->create_object = GL_LABEL_OBJECT (object);
         view->create_x0 = x;
         view->create_y0 = y;
index c145ab6661fe608f944dde2c446b8e8146b61083..0d2aa5268b69517a3d6d09b546b16f66c833564a 100644 (file)
@@ -397,14 +397,12 @@ gl_view_image_create_button_press_event   (glView *view,
        GObject             *object;
         glViewObject        *view_image;
 
+        gl_view_unselect_all (view);
+
         object = gl_label_image_new (view->label);
         gl_label_object_set_position (GL_LABEL_OBJECT(object), x, y);
         gl_label_object_set_size (GL_LABEL_OBJECT(object), 0.0, 0.0);
 
-        gl_view_unselect_all (view);
-        view_image = gl_view_image_new (GL_LABEL_IMAGE(object), view);
-        gl_view_object_select (GL_VIEW_OBJECT(view_image));
-                       
         view->create_object = GL_LABEL_OBJECT (object);
         view->create_x0 = x;
         view->create_y0 = y;
index 5ee579e61bc5972f655ac6f1bff6a6e5a3f53bb5..23a8c92f61b415007ecb06faf3e1495d00e20a5f 100644 (file)
@@ -427,6 +427,8 @@ gl_view_line_create_button_press_event   (glView *view,
        glColorNode         *line_color_node;
         glViewObject        *view_line;
 
+        gl_view_unselect_all (view);
+
         line_color_node = gl_color_node_new_default ();
                
         object = gl_label_line_new (view->label);
@@ -440,10 +442,6 @@ gl_view_line_create_button_press_event   (glView *view,
 
         gl_color_node_free (&line_color_node);
 
-        gl_view_unselect_all (view);
-        view_line = gl_view_line_new (GL_LABEL_LINE(object), view);
-        gl_view_object_select (GL_VIEW_OBJECT(view_line));
-                       
         view->create_object = GL_LABEL_OBJECT (object);
         view->create_x0 = x;
         view->create_y0 = y;
index cfbe92b1151976be6c17047a7a25ad56e33742d5..ccbf153f70bda0541a9364855ca1dba38bda554e 100644 (file)
@@ -64,6 +64,15 @@ struct _glViewObjectPrivate {
 
 static void     gl_view_object_finalize      (GObject             *object);
 
+static void     object_removed_cb            (glViewObject        *view_object,
+                                              glLabelObject       *object);
+
+static void     object_top_cb                (glViewObject        *view_object,
+                                              glLabelObject       *object);
+
+static void     object_bottom_cb             (glViewObject        *view_object,
+                                              glLabelObject       *object);
+
 
 
 
@@ -178,9 +187,80 @@ gl_view_object_set_object     (glViewObject            *view_object,
        g_return_if_fail (view_object && GL_IS_VIEW_OBJECT (view_object));
        g_return_if_fail (object && GL_IS_LABEL_OBJECT (object));
        
-       view_object->priv->object = object;
+       view_object->priv->object = g_object_ref (G_OBJECT (object));
        view_object->priv->handles_style = style;
 
+       g_signal_connect_swapped (G_OBJECT (object), "removed",
+                                 G_CALLBACK (object_removed_cb), view_object);
+       g_signal_connect_swapped (G_OBJECT (object), "top",
+                                 G_CALLBACK (object_top_cb), view_object);
+       g_signal_connect_swapped (G_OBJECT (object), "bottom",
+                                 G_CALLBACK (object_bottom_cb), view_object);
+
+       gl_debug (DEBUG_VIEW, "END");
+}
+
+/*---------------------------------------------------------------------------*/
+/* PRIVATE.  Handle object "removed" signal.                                 */
+/*---------------------------------------------------------------------------*/
+static void
+object_removed_cb (glViewObject  *view_object,
+                   glLabelObject *object)
+{
+        glView *view;
+       gl_debug (DEBUG_VIEW, "START");
+
+       g_return_if_fail (view_object && GL_IS_VIEW_OBJECT (view_object));
+       g_return_if_fail (object && GL_IS_LABEL_OBJECT (object));
+
+        view = gl_view_object_get_view (view_object);
+        view->object_list = g_list_remove (view->object_list, view_object);
+        g_object_unref (G_OBJECT (view_object));
+
+       gl_debug (DEBUG_VIEW, "END");
+}
+
+/*---------------------------------------------------------------------------*/
+/* PRIVATE. Handle object "top" signal.                                      */
+/*---------------------------------------------------------------------------*/
+static void
+object_top_cb (glViewObject  *view_object,
+               glLabelObject *object)
+{
+        glView *view;
+       gl_debug (DEBUG_VIEW, "START");
+
+       g_return_if_fail (view_object && GL_IS_VIEW_OBJECT (view_object));
+       g_return_if_fail (object && GL_IS_LABEL_OBJECT (object));
+
+        view = gl_view_object_get_view (view_object);
+
+       /* Move to end of list, representing front most object */
+        view->object_list = g_list_remove (view->object_list, view_object);
+        view->object_list = g_list_append (view->object_list, view_object);
+
+       gl_debug (DEBUG_VIEW, "END");
+}
+
+/*---------------------------------------------------------------------------*/
+/* PRIVATE. Handle object "removed" signal.                                  */
+/*---------------------------------------------------------------------------*/
+static void
+object_bottom_cb (glViewObject  *view_object,
+                  glLabelObject *object)
+{
+        glView *view;
+       gl_debug (DEBUG_VIEW, "START");
+
+       g_return_if_fail (view_object && GL_IS_VIEW_OBJECT (view_object));
+       g_return_if_fail (object && GL_IS_LABEL_OBJECT (object));
+
+        view = gl_view_object_get_view (view_object);
+
+       /* Move to front of list, representing rear most object */
+        view->object_list = g_list_remove (view->object_list, view_object);
+        view->object_list = g_list_prepend (view->object_list, view_object);
+
        gl_debug (DEBUG_VIEW, "END");
 }
 
index aed5eafaabad901aacad8aa9e5eb7146b20a0266..55d9ac9cd65927758950c6fcafdb435e15d9656f 100644 (file)
@@ -502,6 +502,8 @@ gl_view_text_create_button_press_event   (glView *view,
        gchar               *family;
        glColorNode         *color_node;
 
+        gl_view_unselect_all (view);
+
         object = gl_label_text_new (view->label);
         color_node = gl_color_node_new_default ();
         gl_label_object_set_position (GL_LABEL_OBJECT(object), x, y);
@@ -527,10 +529,6 @@ gl_view_text_create_button_press_event   (glView *view,
         view_text = gl_view_text_new (GL_LABEL_TEXT(object), view);
         gl_color_node_free (&color_node);
 
-        gl_view_unselect_all (view);
-        view_text = gl_view_text_new (GL_LABEL_TEXT(object), view);
-        gl_view_object_select (GL_VIEW_OBJECT(view_text));
-                       
         view->create_object = GL_LABEL_OBJECT (object);
         view->create_x0 = x;
         view->create_y0 = y;
index 7429e4197f8ea283ed5b275255608301a4dab7df..2ed875989a70f8eb100df088c163a2ff4768222d 100644 (file)
@@ -143,6 +143,9 @@ static void       label_changed_cb                (glView         *view);
 
 static void       label_resized_cb                (glView         *view);
 
+static void       label_object_added_cb           (glView         *view,
+                                                   glLabelObject  *object);
+
 static void       draw_layers                     (glView         *view,
                                                    cairo_t        *cr);
 
@@ -483,6 +486,8 @@ gl_view_construct (glView  *view,
                                   G_CALLBACK (label_changed_cb), view);
        g_signal_connect_swapped (G_OBJECT (view->label), "size_changed",
                                   G_CALLBACK (label_resized_cb), view);
+       g_signal_connect_swapped (G_OBJECT (view->label), "object_added",
+                                  G_CALLBACK (label_object_added_cb), view);
 
        gl_debug (DEBUG_VIEW, "END");
 }
@@ -729,6 +734,39 @@ label_resized_cb (glView  *view)
 }
 
 
+/*---------------------------------------------------------------------------*/
+/* PRIVATE.  Handle new label object.                                        */
+/*---------------------------------------------------------------------------*/
+static void
+label_object_added_cb (glView         *view,
+                       glLabelObject  *object)
+{
+        glViewObject *view_object;
+
+       g_return_if_fail (view && GL_IS_VIEW (view));
+       g_return_if_fail (object && GL_IS_LABEL_OBJECT (object));
+
+        if (GL_IS_LABEL_BOX (object)) {
+                view_object = gl_view_box_new (GL_LABEL_BOX(object), view);
+        } else if (GL_IS_LABEL_ELLIPSE (object)) {
+                view_object = gl_view_ellipse_new (GL_LABEL_ELLIPSE(object), view);
+        } else if (GL_IS_LABEL_LINE (object)) {
+                view_object = gl_view_line_new (GL_LABEL_LINE(object), view);
+        } else if (GL_IS_LABEL_IMAGE (object)) {
+                view_object = gl_view_image_new (GL_LABEL_IMAGE(object), view);
+        } else if (GL_IS_LABEL_TEXT (object)) {
+                view_object = gl_view_text_new (GL_LABEL_TEXT(object), view);
+        } else if (GL_IS_LABEL_BARCODE (object)) {
+                view_object = gl_view_barcode_new (GL_LABEL_BARCODE(object), view);
+        } else {
+                /* Should not happen! */
+                view_object = NULL;
+                g_message ("Invalid label object type.");
+        }
+
+        gl_view_select_object (view, view_object);
+}
+
 /*---------------------------------------------------------------------------*/
 /* PRIVATE.  Create, draw and order layers.                                  */
 /*---------------------------------------------------------------------------*/
@@ -1411,9 +1449,11 @@ gl_view_is_selection_atomic (glView *view)
 void
 gl_view_delete_selection (glView *view)
 {
-       GList *object_list;
-       GList *p;
-       GList *p_next;
+       GList         *object_list;
+       GList         *p;
+       GList         *p_next;
+       glViewObject  *view_object;
+       glLabelObject *object;
 
        gl_debug (DEBUG_VIEW, "START");
 
@@ -1425,10 +1465,13 @@ gl_view_delete_selection (glView *view)
 
        for (p = object_list; p != NULL; p = p_next) {
                p_next = p->next;
-               g_object_unref (G_OBJECT (p->data));
-               object_list = g_list_delete_link (object_list, p);
+               view_object = GL_VIEW_OBJECT (p->data);
+               object = gl_view_object_get_object (view_object);
+                gl_label_object_remove (object);
        }
 
+        g_list_free (object_list);
+
        gl_debug (DEBUG_VIEW, "END");
 }