[nautilus/gtk3-happyness: 2/19] canvas: don't use GtkObject
- From: Cosimo Cecchi <cosimoc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [nautilus/gtk3-happyness: 2/19] canvas: don't use GtkObject
- Date: Wed, 29 Sep 2010 12:32:35 +0000 (UTC)
commit ef90c58b7c03b1b19a466fdce7143b3f8c8df5d2
Author: Cosimo Cecchi <cosimoc gnome org>
Date: Wed Sep 29 12:58:15 2010 +0200
canvas: don't use GtkObject
This implies adding a 'destroy' signal to EelCanvasItem, with similar
semantics to gtk_object_destroy()
eel/eel-canvas-rect-ellipse.c | 21 ------------
eel/eel-canvas.c | 71 +++++++++++++++++++++++-----------------
eel/eel-canvas.h | 8 +++-
3 files changed, 47 insertions(+), 53 deletions(-)
---
diff --git a/eel/eel-canvas-rect-ellipse.c b/eel/eel-canvas-rect-ellipse.c
index 688e289..10df7d5 100644
--- a/eel/eel-canvas-rect-ellipse.c
+++ b/eel/eel-canvas-rect-ellipse.c
@@ -67,7 +67,6 @@ enum {
static void eel_canvas_re_class_init (EelCanvasREClass *klass);
static void eel_canvas_re_init (EelCanvasRE *re);
-static void eel_canvas_re_destroy (GtkObject *object);
static void eel_canvas_re_set_property (GObject *object,
guint param_id,
const GValue *value,
@@ -129,11 +128,9 @@ static void
eel_canvas_re_class_init (EelCanvasREClass *klass)
{
GObjectClass *gobject_class;
- GtkObjectClass *object_class;
EelCanvasItemClass *item_class;
gobject_class = (GObjectClass *) klass;
- object_class = (GtkObjectClass *) klass;
item_class = (EelCanvasItemClass *) klass;
re_parent_class = g_type_class_peek_parent (klass);
@@ -219,8 +216,6 @@ eel_canvas_re_class_init (EelCanvasREClass *klass)
0.0, G_MAXDOUBLE, 0.0,
G_PARAM_READWRITE));
- object_class->destroy = eel_canvas_re_destroy;
-
item_class->realize = eel_canvas_re_realize;
item_class->unrealize = eel_canvas_re_unrealize;
item_class->translate = eel_canvas_re_translate;
@@ -237,22 +232,6 @@ eel_canvas_re_init (EelCanvasRE *re)
re->width = 0.0;
}
-static void
-eel_canvas_re_destroy (GtkObject *object)
-{
- EelCanvasRE *re;
-
- g_return_if_fail (object != NULL);
- g_return_if_fail (EEL_IS_CANVAS_RE (object));
-
- re = EEL_CANVAS_RE (object);
-
- /* remember, destroy can be run multiple times! */
-
- if (GTK_OBJECT_CLASS (re_parent_class)->destroy)
- (* GTK_OBJECT_CLASS (re_parent_class)->destroy) (object);
-}
-
static void get_bounds (EelCanvasRE *re, double *px1, double *py1, double *px2, double *py2)
{
EelCanvasItem *item;
diff --git a/eel/eel-canvas.c b/eel/eel-canvas.c
index 87def99..d90d909 100644
--- a/eel/eel-canvas.c
+++ b/eel/eel-canvas.c
@@ -93,6 +93,7 @@ enum {
};
enum {
+ ITEM_DESTROY,
ITEM_EVENT,
ITEM_LAST_SIGNAL
};
@@ -103,7 +104,7 @@ static int emit_event (EelCanvas *canvas, GdkEvent *event
static guint item_signals[ITEM_LAST_SIGNAL];
-static GtkObjectClass *item_parent_class;
+static GObjectClass *item_parent_class;
static gpointer accessible_item_parent_class;
static gpointer accessible_parent_class;
@@ -135,7 +136,7 @@ eel_canvas_item_get_type (void)
(GInstanceInitFunc) eel_canvas_item_init
};
- canvas_item_type = g_type_register_static (gtk_object_get_type (),
+ canvas_item_type = g_type_register_static (G_TYPE_INITIALLY_UNOWNED,
"EelCanvasItem",
&canvas_item_info,
0);
@@ -336,9 +337,21 @@ eel_canvas_item_dispose (GObject *object)
item->canvas = NULL;
}
+ g_object_set_data (object, "in-destruction", GINT_TO_POINTER (1));
+ g_signal_emit (object, item_signals[ITEM_DESTROY], 0);
+
+ g_object_set_data (object, "in-destruction", NULL);
+
G_OBJECT_CLASS (item_parent_class)->dispose (object);
}
+void
+eel_canvas_item_destroy (EelCanvasItem *item)
+{
+ if (g_object_get_data (G_OBJECT (item), "in-destruction") == NULL) {
+ g_object_run_dispose (G_OBJECT (item));
+ }
+}
/* Realize handler for canvas items */
static void
@@ -1146,7 +1159,7 @@ static void eel_canvas_group_get_property(GObject *object,
GValue *value,
GParamSpec *pspec);
-static void eel_canvas_group_destroy (GtkObject *object);
+static void eel_canvas_group_destroy (EelCanvasItem *object);
static void eel_canvas_group_update (EelCanvasItem *item,
double i2w_dx,
@@ -1210,11 +1223,9 @@ static void
eel_canvas_group_class_init (EelCanvasGroupClass *klass)
{
GObjectClass *gobject_class;
- GtkObjectClass *object_class;
EelCanvasItemClass *item_class;
gobject_class = (GObjectClass *) klass;
- object_class = (GtkObjectClass *) klass;
item_class = (EelCanvasItemClass *) klass;
group_parent_class = g_type_class_peek_parent (klass);
@@ -1237,8 +1248,7 @@ eel_canvas_group_class_init (EelCanvasGroupClass *klass)
-G_MAXDOUBLE, G_MAXDOUBLE, 0.0,
G_PARAM_READWRITE));
- object_class->destroy = eel_canvas_group_destroy;
-
+ item_class->destroy = eel_canvas_group_destroy;
item_class->update = eel_canvas_group_update;
item_class->unrealize = eel_canvas_group_unrealize;
item_class->map = eel_canvas_group_map;
@@ -1332,7 +1342,7 @@ eel_canvas_group_get_property (GObject *gobject, guint param_id,
/* Destroy handler for canvas groups */
static void
-eel_canvas_group_destroy (GtkObject *object)
+eel_canvas_group_destroy (EelCanvasItem *object)
{
EelCanvasGroup *group;
EelCanvasItem *child;
@@ -1347,11 +1357,11 @@ eel_canvas_group_destroy (GtkObject *object)
child = list->data;
list = list->next;
- gtk_object_destroy (GTK_OBJECT (child));
+ eel_canvas_item_destroy (child);
}
- if (GTK_OBJECT_CLASS (group_parent_class)->destroy)
- (* GTK_OBJECT_CLASS (group_parent_class)->destroy) (object);
+ if (EEL_CANVAS_ITEM_CLASS (group_parent_class)->destroy)
+ (* EEL_CANVAS_ITEM_CLASS (group_parent_class)->destroy) (object);
}
/* Update handler for canvas groups */
@@ -1709,7 +1719,7 @@ enum {
static void eel_canvas_class_init (EelCanvasClass *klass);
static void eel_canvas_init (EelCanvas *canvas);
-static void eel_canvas_destroy (GtkObject *object);
+static void eel_canvas_destroy (GtkWidget *object);
static void eel_canvas_map (GtkWidget *widget);
static void eel_canvas_unmap (GtkWidget *widget);
static void eel_canvas_realize (GtkWidget *widget);
@@ -2011,11 +2021,9 @@ static void
eel_canvas_class_init (EelCanvasClass *klass)
{
GObjectClass *gobject_class;
- GtkObjectClass *object_class;
GtkWidgetClass *widget_class;
gobject_class = (GObjectClass *)klass;
- object_class = (GtkObjectClass *) klass;
widget_class = (GtkWidgetClass *) klass;
canvas_parent_class = g_type_class_peek_parent (klass);
@@ -2023,8 +2031,7 @@ eel_canvas_class_init (EelCanvasClass *klass)
gobject_class->set_property = eel_canvas_set_property;
gobject_class->get_property = eel_canvas_get_property;
- object_class->destroy = eel_canvas_destroy;
-
+ widget_class->destroy = eel_canvas_destroy;
widget_class->map = eel_canvas_map;
widget_class->unmap = eel_canvas_unmap;
widget_class->realize = eel_canvas_realize;
@@ -2046,7 +2053,7 @@ eel_canvas_class_init (EelCanvasClass *klass)
canvas_signals[DRAW_BACKGROUND] =
g_signal_new ("draw_background",
- G_TYPE_FROM_CLASS (object_class),
+ G_TYPE_FROM_CLASS (klass),
G_SIGNAL_RUN_LAST,
G_STRUCT_OFFSET (EelCanvasClass, draw_background),
NULL, NULL,
@@ -2063,7 +2070,7 @@ eel_canvas_class_init (EelCanvasClass *klass)
* never ever do this, so we panic if this happens.
*/
static void
-panic_root_destroyed (GtkObject *object, gpointer data)
+panic_root_destroyed (GtkWidget *object, gpointer data)
{
g_error ("Eeeek, root item %p of canvas %p was destroyed!", object, data);
}
@@ -2098,12 +2105,7 @@ eel_canvas_init (EelCanvas *canvas)
canvas->root = EEL_CANVAS_ITEM (g_object_new (eel_canvas_group_get_type (), NULL));
canvas->root->canvas = canvas;
-#if GLIB_CHECK_VERSION(2,10,0) && GTK_CHECK_VERSION(2,8,14)
g_object_ref_sink (canvas->root);
-#else
- g_object_ref (canvas->root);
- gtk_object_sink (GTK_OBJECT (canvas->root));
-#endif
canvas->root_destroy_id = g_signal_connect (G_OBJECT (canvas->root),
"destroy", G_CALLBACK (panic_root_destroyed), canvas);
@@ -2147,7 +2149,7 @@ shutdown_transients (EelCanvas *canvas)
/* Destroy handler for EelCanvas */
static void
-eel_canvas_destroy (GtkObject *object)
+eel_canvas_destroy (GtkWidget *object)
{
EelCanvas *canvas;
@@ -2164,14 +2166,14 @@ eel_canvas_destroy (GtkObject *object)
if (canvas->root) {
EelCanvasItem *root = canvas->root;
canvas->root = NULL;
- gtk_object_destroy (GTK_OBJECT (root));
+ eel_canvas_item_destroy (root);
g_object_unref (root);
}
shutdown_transients (canvas);
- if (GTK_OBJECT_CLASS (canvas_parent_class)->destroy)
- (* GTK_OBJECT_CLASS (canvas_parent_class)->destroy) (object);
+ if (GTK_WIDGET_CLASS (canvas_parent_class)->destroy)
+ (* GTK_WIDGET_CLASS (canvas_parent_class)->destroy) (object);
}
/**
@@ -2544,14 +2546,14 @@ emit_event (EelCanvas *canvas, GdkEvent *event)
finished = FALSE;
while (item && !finished) {
- g_object_ref (GTK_OBJECT (item));
+ g_object_ref (item);
g_signal_emit (
G_OBJECT (item), item_signals[ITEM_EVENT], 0,
&ev, &finished);
parent = item->parent;
- g_object_unref (GTK_OBJECT (item));
+ g_object_unref (item);
item = parent;
}
@@ -3833,7 +3835,7 @@ eel_canvas_item_accessible_get_type (void)
GTypeInfo tinfo = { 0 };
factory = atk_registry_get_factory (atk_get_default_registry(),
- GTK_TYPE_OBJECT);
+ G_TYPE_INITIALLY_UNOWNED);
if (!factory) {
return G_TYPE_INVALID;
}
@@ -3961,6 +3963,15 @@ eel_canvas_item_class_init (EelCanvasItemClass *klass)
G_TYPE_BOOLEAN, 1,
GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
+ item_signals[ITEM_DESTROY] =
+ g_signal_new ("destroy",
+ G_TYPE_FROM_CLASS (klass),
+ G_SIGNAL_RUN_CLEANUP | G_SIGNAL_NO_RECURSE | G_SIGNAL_NO_HOOKS,
+ G_STRUCT_OFFSET (EelCanvasItemClass, destroy),
+ NULL, NULL,
+ g_cclosure_marshal_VOID__VOID,
+ G_TYPE_NONE, 0);
+
klass->realize = eel_canvas_item_realize;
klass->unrealize = eel_canvas_item_unrealize;
klass->map = eel_canvas_item_map;
diff --git a/eel/eel-canvas.h b/eel/eel-canvas.h
index e66e440..2a7d66e 100644
--- a/eel/eel-canvas.h
+++ b/eel/eel-canvas.h
@@ -110,7 +110,7 @@ enum {
struct _EelCanvasItem {
- GtkObject object;
+ GInitiallyUnowned object;
/* Parent canvas for this item */
EelCanvas *canvas;
@@ -126,7 +126,9 @@ struct _EelCanvasItem {
};
struct _EelCanvasItemClass {
- GtkObjectClass parent_class;
+ GInitiallyUnownedClass parent_class;
+
+ void (* destroy) (EelCanvasItem *item);
/* Tell the item to update itself. The flags are from the update flags
* defined above. The item should update its internal state from its
@@ -189,6 +191,8 @@ GType eel_canvas_item_get_type (void) G_GNUC_CONST;
EelCanvasItem *eel_canvas_item_new (EelCanvasGroup *parent, GType type,
const gchar *first_arg_name, ...);
+void eel_canvas_item_destroy (EelCanvasItem *item);
+
/* Constructors for use in derived classes and language wrappers */
void eel_canvas_item_construct (EelCanvasItem *item, EelCanvasGroup *parent,
const gchar *first_arg_name, va_list args);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]