[sapwood] use a GObject-derived type for the images
- From: Sven Herzberg <herzi src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [sapwood] use a GObject-derived type for the images
- Date: Wed, 4 Aug 2010 11:10:32 +0000 (UTC)
commit 042e930f599021a64c2a1ba13a68c0264a0c58d8
Author: Sven Herzberg <herzi gnome-de org>
Date: Fri Jul 30 23:43:29 2010 +0200
use a GObject-derived type for the images
* engine/sapwood-rc-style.c,
* engine/theme-image.c,
* engine/theme-image.h: turn ThemeImage into a type deriving from
GObject and update the internal API
engine/sapwood-rc-style.c | 3 +-
engine/theme-image.c | 65 ++++++++++++++++++++++++++++++++------------
engine/theme-image.h | 31 ++++++++++++++++-----
3 files changed, 72 insertions(+), 27 deletions(-)
---
diff --git a/engine/sapwood-rc-style.c b/engine/sapwood-rc-style.c
index c4660a7..d34e682 100644
--- a/engine/sapwood-rc-style.c
+++ b/engine/sapwood-rc-style.c
@@ -608,8 +608,7 @@ theme_parse_image (GtkSettings *settings,
if (token != G_TOKEN_LEFT_CURLY)
return G_TOKEN_LEFT_CURLY;
- data = g_new0 (ThemeImage, 1);
- data->refcount = 1;
+ data = theme_image_new ();
token = g_scanner_peek_next_token (scanner);
while (token != G_TOKEN_RIGHT_CURLY)
diff --git a/engine/theme-image.c b/engine/theme-image.c
index 5c7e621..500f429 100644
--- a/engine/theme-image.c
+++ b/engine/theme-image.c
@@ -25,6 +25,40 @@
#include <string.h>
#include "sapwood-rc-style.h"
+G_DEFINE_TYPE (ThemeImage, theme_image, G_TYPE_OBJECT);
+
+static void
+theme_image_init (ThemeImage* self)
+{}
+
+static void
+finalize (GObject* object)
+{
+ ThemeImage* data = THEME_IMAGE (object);
+
+ g_free (data->match_data.detail);
+ if (data->background)
+ theme_pixbuf_unref (data->background);
+ if (data->overlay)
+ theme_pixbuf_unref (data->overlay);
+ if (data->gap_start)
+ theme_pixbuf_unref (data->gap_start);
+ if (data->gap)
+ theme_pixbuf_unref (data->gap);
+ if (data->gap_end)
+ theme_pixbuf_unref (data->gap_end);
+
+ G_OBJECT_CLASS (theme_image_parent_class)->finalize (object);
+}
+
+static void
+theme_image_class_init (ThemeImageClass* self_class)
+{
+ GObjectClass* object_class = G_OBJECT_CLASS (self_class);
+
+ object_class->finalize = finalize;
+}
+
ThemeImage *
match_theme_image (GtkStyle *style,
ThemeMatchData *match_data)
@@ -94,32 +128,27 @@ match_theme_image (GtkStyle *style,
return NULL;
}
+ThemeImage*
+theme_image_new (void)
+{
+ return g_object_new (THEME_TYPE_IMAGE,
+ NULL);
+}
+
void
theme_image_ref (ThemeImage *data)
{
- data->refcount++;
+ g_warning ("use g_object_ref(ThemeImage)");
+
+ g_object_ref (data);
}
void
theme_image_unref (ThemeImage *data)
{
- data->refcount--;
- if (data->refcount == 0)
- {
- if (data->match_data.detail)
- g_free (data->match_data.detail);
- if (data->background)
- theme_pixbuf_unref (data->background);
- if (data->overlay)
- theme_pixbuf_unref (data->overlay);
- if (data->gap_start)
- theme_pixbuf_unref (data->gap_start);
- if (data->gap)
- theme_pixbuf_unref (data->gap);
- if (data->gap_end)
- theme_pixbuf_unref (data->gap_end);
- g_free (data);
- }
+ g_warning ("the g_object_unref(ThemeImage)");
+
+ g_object_unref (data);
}
/* vim:set et sw=2 cino=t0,f0,(0,{s,>2s,n-1s,^-1s,e2s: */
diff --git a/engine/theme-image.h b/engine/theme-image.h
index d46576e..dadfe5f 100644
--- a/engine/theme-image.h
+++ b/engine/theme-image.h
@@ -27,13 +27,25 @@
G_BEGIN_DECLS
-typedef struct _ThemeImage ThemeImage;
-typedef struct _ThemeMatchData ThemeMatchData;
+typedef struct _ThemeImage ThemeImage;
+typedef struct _ThemeImageClass ThemeImageClass;
+typedef struct _ThemeMatchData ThemeMatchData;
-ThemeImage* match_theme_image (GtkStyle * style,
- ThemeMatchData* match_data) G_GNUC_INTERNAL;
-void theme_image_ref (ThemeImage * self) G_GNUC_INTERNAL;
-void theme_image_unref (ThemeImage * self) G_GNUC_INTERNAL;
+#define THEME_TYPE_IMAGE (theme_image_get_type ())
+#define THEME_IMAGE(i) (G_TYPE_CHECK_INSTANCE_CAST ((i), THEME_TYPE_IMAGE, ThemeImage))
+#define THEME_IMAGE_CLASS(c) (G_TYPE_CHECK_CLASS_CAST ((c), THEME_TYPE_IMAGE, ThemeImageClass))
+#define THEME_IS_IMAGE(i) (G_TYPE_CHECK_INSTANCE_TYPE ((i), THEME_TYPE_IMAGE))
+#define THEME_IS_IMAGE_CLASS(c) (G_TYPE_CHECK_CLASS_TYPE ((c), THEME_TYPE_IMAGE))
+#define THEME_IMAGE_GET_CLASS(i) (G_TYPE_INSTANCE_GET_CLASS ((i), THEME_TYPE_IMAGE, ThemeImageClass))
+
+GType theme_image_get_type (void);
+
+ThemeImage* match_theme_image (GtkStyle * style,
+ ThemeMatchData* match_data) G_GNUC_INTERNAL;
+
+ThemeImage* theme_image_new (void) G_GNUC_INTERNAL;
+void theme_image_ref (ThemeImage * self) G_GNUC_INTERNAL;
+void theme_image_unref (ThemeImage * self) G_GNUC_INTERNAL;
typedef enum {
@@ -68,6 +80,7 @@ struct _ThemeMatchData
struct _ThemeImage
{
+ GObject base_instance;
ThemePixbuf *background;
ThemePixbuf *overlay;
ThemePixbuf *gap_start;
@@ -76,10 +89,14 @@ struct _ThemeImage
ThemeMatchData match_data;
- guint refcount : 31;
guint background_shaped : 1;
};
+struct _ThemeImageClass
+{
+ GObjectClass base_class;
+};
+
G_END_DECLS
#endif /* !THEME_IMAGE_H */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]