summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2012-04-28 17:11:16 +0000
committerDavid Robillard <d@drobilla.net>2012-04-28 17:11:16 +0000
commit64e8c26cef155ec5422e700827bbc337c95e97a3 (patch)
treeb6b8910ec4c2ec1ccb17898a1c387488abd5d41d
parent6601a7e2c274fa1ed0a53680b068e864c67c89ec (diff)
downloadganv-64e8c26cef155ec5422e700827bbc337c95e97a3.tar.gz
ganv-64e8c26cef155ec5422e700827bbc337c95e97a3.tar.bz2
ganv-64e8c26cef155ec5422e700827bbc337c95e97a3.zip
Fix warnings about non-parent items.
git-svn-id: http://svn.drobilla.net/lad/trunk/ganv@4304 a436a847-0d15-0410-975c-d299462d15a1
-rw-r--r--ganv/canvas-base.h3
-rw-r--r--src/canvas-base.c38
-rw-r--r--src/node.c1
-rw-r--r--src/port.c1
4 files changed, 33 insertions, 10 deletions
diff --git a/ganv/canvas-base.h b/ganv/canvas-base.h
index 5254e5d..816fb28 100644
--- a/ganv/canvas-base.h
+++ b/ganv/canvas-base.h
@@ -88,6 +88,9 @@ struct _GanvItem {
/* Bounding box for this item (in canvas coordinates) */
double x1, y1, x2, y2;
+
+ /* True if parent manages this item (don't call add/remove) */
+ gboolean managed;
};
struct _GanvItemClass {
diff --git a/src/canvas-base.c b/src/canvas-base.c
index a521ad6..7e5099b 100644
--- a/src/canvas-base.c
+++ b/src/canvas-base.c
@@ -52,7 +52,8 @@ enum {
ITEM_PROP_0,
ITEM_PROP_PARENT,
ITEM_PROP_X,
- ITEM_PROP_Y
+ ITEM_PROP_Y,
+ ITEM_PROP_MANAGED
};
enum {
@@ -75,6 +76,7 @@ static void
ganv_item_init(GanvItem* item)
{
item->object.flags |= GANV_ITEM_VISIBLE;
+ item->managed = FALSE;
}
/**
@@ -120,15 +122,17 @@ static void
item_post_create_setup(GanvItem* item)
{
GanvItemClass* parent_class = GANV_ITEM_GET_CLASS(item->parent);
- if (parent_class->add) {
- parent_class->add(item->parent, item);
- ganv_canvas_base_request_redraw(item->canvas,
- item->x1, item->y1,
- item->x2 + 1, item->y2 + 1);
- item->canvas->need_repick = TRUE;
- } else {
- g_warning("item added to non-parent item\n");
+ if (!item->managed) {
+ if (parent_class->add) {
+ parent_class->add(item->parent, item);
+ } else {
+ g_warning("item added to non-parent item\n");
+ }
}
+ ganv_canvas_base_request_redraw(item->canvas,
+ item->x1, item->y1,
+ item->x2 + 1, item->y2 + 1);
+ item->canvas->need_repick = TRUE;
}
/* Set_property handler for canvas items */
@@ -159,6 +163,9 @@ ganv_item_set_property(GObject* gobject, guint param_id,
item->y = g_value_get_double(value);
ganv_item_request_update(item);
break;
+ case ITEM_PROP_MANAGED:
+ item->managed = g_value_get_boolean(value);
+ break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID(gobject, param_id, pspec);
break;
@@ -184,6 +191,9 @@ ganv_item_get_property(GObject* gobject, guint param_id,
case ITEM_PROP_Y:
g_value_set_double(value, item->y);
break;
+ case ITEM_PROP_MANAGED:
+ g_value_set_boolean(value, item->managed);
+ break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID(gobject, param_id, pspec);
break;
@@ -268,7 +278,7 @@ ganv_item_dispose(GObject* object)
(*GANV_ITEM_GET_CLASS(item)->unrealize)(item);
}
- if (item->parent) {
+ if (!item->managed && item->parent) {
if (GANV_ITEM_GET_CLASS(item->parent)->remove) {
GANV_ITEM_GET_CLASS(item->parent)->remove(item->parent, item);
} else {
@@ -2619,6 +2629,14 @@ ganv_item_class_init(GanvItemClass* class)
-G_MAXDOUBLE, G_MAXDOUBLE, 0.0,
(G_PARAM_READABLE | G_PARAM_WRITABLE)));
+ g_object_class_install_property
+ (gobject_class, ITEM_PROP_MANAGED,
+ g_param_spec_boolean("managed",
+ _("Managed"),
+ _("Whether the item is managed by its parent"),
+ 0,
+ (G_PARAM_READABLE | G_PARAM_WRITABLE)));
+
item_signals[ITEM_EVENT]
= g_signal_new("event",
G_TYPE_FROM_CLASS(class),
diff --git a/src/node.c b/src/node.c
index feba244..0a885c3 100644
--- a/src/node.c
+++ b/src/node.c
@@ -299,6 +299,7 @@ ganv_node_set_label(GanvNode* node, const char* str)
ganv_text_get_type(),
"text", str,
"color", 0xFFFFFFFF,
+ "managed", TRUE,
NULL));
}
diff --git a/src/port.c b/src/port.c
index 2aa153b..c33e925 100644
--- a/src/port.c
+++ b/src/port.c
@@ -400,6 +400,7 @@ ganv_port_show_control(GanvPort* port)
"fill-color", control_col,
"border-color", control_col,
"border-width", 0.0,
+ "managed", TRUE,
NULL));
ganv_item_show(GANV_ITEM(control->rect));
}