A sample patch that illustrates how to do virtual methods
- From: Philip Van Hoof <spam pvanhoof be>
- To: tinymail-devel-list gnome org
- Subject: A sample patch that illustrates how to do virtual methods
- Date: Mon, 06 Nov 2006 20:08:56 +0100
On Mon, 2006-11-06 at 15:49 +0100, Philip Van Hoof wrote:
> For example making most methods virtual (which isn't easy in GObject,
> but I can teach you --it's not as easy as putting "virtual" in front of
> the method name, no. You need to store the function pointer
> somewhere--).
This patch illustrates how to transform normal methods into virtual
ones.
I would be very very interested in patches like this coming from people
on this mailing list ;-).
As far as I'm concerned, all implementation-methods of the tinymail
framework can be virtual ones (that's a lot, indeed).
--
Philip Van Hoof, software developer at x-tend
home: me at pvanhoof dot be
gnome: pvanhoof at gnome dot org
work: vanhoof at x-tend dot be
http://www.pvanhoof.be - http://www.x-tend.be
Index: tny-gtk-header-view.c
===================================================================
--- tny-gtk-header-view.c (revision 1096)
+++ tny-gtk-header-view.c (working copy)
@@ -57,10 +57,16 @@
return g_strdup (readable_date);
}
-
static void
tny_gtk_header_view_set_header (TnyHeaderView *self, TnyHeader *header)
{
+ TNY_GTK_HEADER_VIEW_GET_CLASS (self)->set_header_func (self, header);
+ return;
+}
+
+static void
+tny_gtk_header_view_set_header_default (TnyHeaderView *self, TnyHeader *header)
+{
TnyGtkHeaderViewPriv *priv = TNY_GTK_HEADER_VIEW_GET_PRIVATE (self);
if (G_LIKELY (priv->header))
@@ -69,7 +75,7 @@
if (header && G_IS_OBJECT (header))
{
- gchar *str;
+ gchar *str;
g_object_ref (G_OBJECT (header));
priv->header = header;
@@ -81,29 +87,36 @@
gtk_label_set_text (GTK_LABEL (priv->date_label), (const gchar*)str);
g_free (str);
}
-
+
return;
}
-
static void
tny_gtk_header_view_clear (TnyHeaderView *self)
{
+ TNY_GTK_HEADER_VIEW_GET_CLASS (self)->clear_func (self);
+ return;
+}
+
+static void
+tny_gtk_header_view_clear_default (TnyHeaderView *self)
+{
TnyGtkHeaderViewPriv *priv = TNY_GTK_HEADER_VIEW_GET_PRIVATE (self);
if (G_LIKELY (priv->header))
g_object_unref (G_OBJECT (priv->header));
priv->header = NULL;
-
+
gtk_label_set_text (GTK_LABEL (priv->to_label), "");
gtk_label_set_text (GTK_LABEL (priv->from_label), "");
gtk_label_set_text (GTK_LABEL (priv->subject_label), "");
gtk_label_set_text (GTK_LABEL (priv->date_label), "");
-
+
return;
}
+
/**
* tny_gtk_header_view_new:
*
@@ -203,7 +216,7 @@
if (G_LIKELY (priv->header))
g_object_unref (G_OBJECT (priv->header));
priv->header = NULL;
-
+
(*parent_class->finalize) (object);
return;
@@ -216,7 +229,7 @@
klass->set_header_func = tny_gtk_header_view_set_header;
klass->clear_func = tny_gtk_header_view_clear;
-
+
return;
}
@@ -228,6 +241,9 @@
parent_class = g_type_class_peek_parent (class);
object_class = (GObjectClass*) class;
+ class->set_header_func = tny_gtk_header_view_set_header_default;
+ class->clear_func = tny_gtk_header_view_clear_default;
+
object_class->finalize = tny_gtk_header_view_finalize;
g_type_class_add_private (object_class, sizeof (TnyGtkHeaderViewPriv));
Index: tny-gtk-header-view.h
===================================================================
--- tny-gtk-header-view.h (revision 1096)
+++ tny-gtk-header-view.h (working copy)
@@ -46,6 +46,10 @@
struct _TnyGtkHeaderViewClass
{
GtkTableClass parent_class;
+
+ /* virtual methods */
+ void (*set_header_func) (TnyHeaderView *self, TnyHeader *header);
+ void (*clear_func) (TnyHeaderView *self);
};
GType tny_gtk_header_view_get_type (void);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]