From be11ca532e497806c00fa59c084b0710668226f8 Mon Sep 17 00:00:00 2001 From: Jim Evins Date: Sat, 15 Sep 2007 02:02:57 +0000 Subject: [PATCH] 2007-09-14 Jim Evins * 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 --- glabels2/ChangeLog | 19 +++++++++ glabels2/src/label-barcode.c | 3 +- glabels2/src/label-ellipse.c | 2 +- glabels2/src/label-object.c | 41 ++++++++++++++++-- glabels2/src/label-object.h | 6 +++ glabels2/src/label.c | 19 +++++++-- glabels2/src/label.h | 4 ++ glabels2/src/marshal.list | 5 +-- glabels2/src/view-barcode.c | 6 +-- glabels2/src/view-box.c | 6 +-- glabels2/src/view-ellipse.c | 8 ++-- glabels2/src/view-image.c | 6 +-- glabels2/src/view-line.c | 6 +-- glabels2/src/view-object.c | 82 +++++++++++++++++++++++++++++++++++- glabels2/src/view-text.c | 6 +-- glabels2/src/view.c | 53 ++++++++++++++++++++--- 16 files changed, 228 insertions(+), 44 deletions(-) diff --git a/glabels2/ChangeLog b/glabels2/ChangeLog index 3266fd87..129791cf 100644 --- a/glabels2/ChangeLog +++ b/glabels2/ChangeLog @@ -1,3 +1,22 @@ +2007-09-14 Jim Evins + + * 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 * src/print-op.c: (create_custom_widget_cb): diff --git a/glabels2/src/label-barcode.c b/glabels2/src/label-barcode.c index 9f93d011..9cb08043 100644 --- a/glabels2/src/label-barcode.c +++ b/glabels2/src/label-barcode.c @@ -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) diff --git a/glabels2/src/label-ellipse.c b/glabels2/src/label-ellipse.c index efc8dd88..fb21cbf2 100644 --- a/glabels2/src/label-ellipse.c +++ b/glabels2/src/label-ellipse.c @@ -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 (); } diff --git a/glabels2/src/label-object.c b/glabels2/src/label-object.c index 467cd2c5..24cfdb20 100644 --- a/glabels2/src/label-object.c +++ b/glabels2/src/label-object.c @@ -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. */ /*****************************************************************************/ diff --git a/glabels2/src/label-object.h b/glabels2/src/label-object.h index d7a62764..5ee0f9ba 100644 --- a/glabels2/src/label-object.h +++ b/glabels2/src/label-object.h @@ -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); diff --git a/glabels2/src/label.c b/glabels2/src/label.c index fc4122d7..d335a7bd 100644 --- a/glabels2/src/label.c +++ b/glabels2/src/label.c @@ -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); } diff --git a/glabels2/src/label.h b/glabels2/src/label.h index a3a9e5f4..d03cb824 100644 --- a/glabels2/src/label.h +++ b/glabels2/src/label.h @@ -76,6 +76,10 @@ struct _glLabelClass { void (*size_changed) (glLabel *label, gpointer user_data); + void (*object_added) (glLabel *label, + glLabelObject *object, + gpointer user_data); + }; diff --git a/glabels2/src/marshal.list b/glabels2/src/marshal.list index 019f5a6e..ea17eaf3 100644 --- a/glabels2/src/marshal.list +++ b/glabels2/src/marshal.list @@ -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 diff --git a/glabels2/src/view-barcode.c b/glabels2/src/view-barcode.c index 11b2384a..309287ae 100644 --- a/glabels2/src/view-barcode.c +++ b/glabels2/src/view-barcode.c @@ -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; diff --git a/glabels2/src/view-box.c b/glabels2/src/view-box.c index ec3e8a26..bd72252f 100644 --- a/glabels2/src/view-box.c +++ b/glabels2/src/view-box.c @@ -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; diff --git a/glabels2/src/view-ellipse.c b/glabels2/src/view-ellipse.c index 4bfa6691..cebbc863 100644 --- a/glabels2/src/view-ellipse.c +++ b/glabels2/src/view-ellipse.c @@ -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; diff --git a/glabels2/src/view-image.c b/glabels2/src/view-image.c index c145ab66..0d2aa526 100644 --- a/glabels2/src/view-image.c +++ b/glabels2/src/view-image.c @@ -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; diff --git a/glabels2/src/view-line.c b/glabels2/src/view-line.c index 5ee579e6..23a8c92f 100644 --- a/glabels2/src/view-line.c +++ b/glabels2/src/view-line.c @@ -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; diff --git a/glabels2/src/view-object.c b/glabels2/src/view-object.c index cfbe92b1..ccbf153f 100644 --- a/glabels2/src/view-object.c +++ b/glabels2/src/view-object.c @@ -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"); } diff --git a/glabels2/src/view-text.c b/glabels2/src/view-text.c index aed5eafa..55d9ac9c 100644 --- a/glabels2/src/view-text.c +++ b/glabels2/src/view-text.c @@ -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; diff --git a/glabels2/src/view.c b/glabels2/src/view.c index 7429e419..2ed87598 100644 --- a/glabels2/src/view.c +++ b/glabels2/src/view.c @@ -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"); } -- 2.39.5