summaryrefslogtreecommitdiff
path: root/gdk-pixbuf/gdk-pixbuf.c
diff options
context:
space:
mode:
authorHavoc Pennington <hp@pobox.com>2000-06-22 15:36:12 +0000
committerHavoc Pennington <hp@src.gnome.org>2000-06-22 15:36:12 +0000
commit3a422541e314126987c24fc1752f94962fad78d5 (patch)
tree9692c443f5df4063c64c4b72cc9482cb1b342a4b /gdk-pixbuf/gdk-pixbuf.c
parent7b6c38f544dd6d55123b1a21d6a45da957ee6396 (diff)
downloadgtk+-3a422541e314126987c24fc1752f94962fad78d5.tar.gz
Convert GdkPixbuf to GObject, leaving it opaque (i.e. derivation is not
2000-06-21 Havoc Pennington <hp@pobox.com> * gdk-pixbuf.c: Convert GdkPixbuf to GObject, leaving it opaque (i.e. derivation is not allowed, and there are no virtual methods anyway). (gdk_pixbuf_preinit): Call g_type_init() here. (gdk_pixbuf_init): Add a user-friendly init function, for users of standalone gdk-pixbuf * gdk-pixbuf-animation.c: Convert to GObject, in the same way GdkPixbufAnimation was done. * gdk-pixbuf.h: Remove gdk_pixbuf_set_unref_handler() and gdk_pixbuf_finalize() from API, since these are broken and don't make sense with new GObject stuff. 2000-06-21 Havoc Pennington <hp@pobox.com> * gdk/gdkwindow.c (_gdk_window_destroy_hierarchy): Fix bug where we didn't check window->bg_pixmap != GDK_NO_BG. * gtk/gdk-pixbuf-loader.c: Change to reflect GObject-ification of gdk-pixbuf
Diffstat (limited to 'gdk-pixbuf/gdk-pixbuf.c')
-rw-r--r--gdk-pixbuf/gdk-pixbuf.c131
1 files changed, 64 insertions, 67 deletions
diff --git a/gdk-pixbuf/gdk-pixbuf.c b/gdk-pixbuf/gdk-pixbuf.c
index d42cfd159d..50947ba8ea 100644
--- a/gdk-pixbuf/gdk-pixbuf.c
+++ b/gdk-pixbuf/gdk-pixbuf.c
@@ -28,97 +28,86 @@
#include "gdk-pixbuf.h"
#include "gdk-pixbuf-private.h"
+static void gdk_pixbuf_class_init (GdkPixbufClass *klass);
+static void gdk_pixbuf_finalize (GObject *object);
+
-/* Reference counting */
+static gpointer parent_class;
+
+GType
+gdk_pixbuf_get_type (void)
+{
+ static GType object_type = 0;
+
+ if (!object_type) {
+ static const GTypeInfo object_info = {
+ sizeof (GdkPixbufClass),
+ (GBaseInitFunc) NULL,
+ (GBaseFinalizeFunc) NULL,
+ (GClassInitFunc) gdk_pixbuf_class_init,
+ NULL, /* class_finalize */
+ NULL, /* class_data */
+ sizeof (GdkPixbuf),
+ 0, /* n_preallocs */
+ (GInstanceInitFunc) NULL,
+ };
+
+ object_type = g_type_register_static (G_TYPE_OBJECT,
+ "GdkPixbuf",
+ &object_info);
+ }
+
+ return object_type;
+}
+
+static void
+gdk_pixbuf_class_init (GdkPixbufClass *klass)
+{
+ GObjectClass *object_class = G_OBJECT_CLASS (klass);
+
+ parent_class = g_type_class_peek_parent (klass);
+
+ object_class->finalize = gdk_pixbuf_finalize;
+}
+
+static void
+gdk_pixbuf_finalize (GObject *object)
+{
+ GdkPixbuf *pixbuf = GDK_PIXBUF (object);
+
+ if (pixbuf->destroy_fn)
+ (* pixbuf->destroy_fn) (pixbuf->pixels, pixbuf->destroy_fn_data);
+
+ G_OBJECT_CLASS (parent_class)->finalize (object);
+}
/**
* gdk_pixbuf_ref:
* @pixbuf: A pixbuf.
*
- * Adds a reference to a pixbuf. It must be released afterwards using
- * gdk_pixbuf_unref().
+ * Adds a reference to a pixbuf. Deprecated; use g_object_ref().
*
* Return value: The same as the @pixbuf argument.
**/
GdkPixbuf *
gdk_pixbuf_ref (GdkPixbuf *pixbuf)
{
- g_return_val_if_fail (pixbuf != NULL, NULL);
- g_return_val_if_fail (pixbuf->ref_count > 0, NULL);
-
- pixbuf->ref_count++;
- return pixbuf;
+ return (GdkPixbuf *) g_object_ref (G_OBJECT(pixbuf));
}
/**
* gdk_pixbuf_unref:
* @pixbuf: A pixbuf.
*
- * Removes a reference from a pixbuf. If this is the last reference for the
- * @pixbuf, then its last unref handler function will be called; if no handler
- * has been defined, then the pixbuf will be finalized.
+ * Removes a reference from a pixbuf. Deprecated; use
+ * g_object_unref().
*
- * See also: gdk_pixbuf_set_last_unref_handler().
**/
void
gdk_pixbuf_unref (GdkPixbuf *pixbuf)
{
- g_return_if_fail (pixbuf != NULL);
- g_return_if_fail (pixbuf->ref_count > 0);
-
- if (pixbuf->ref_count > 1)
- pixbuf->ref_count--;
- else if (pixbuf->last_unref_fn)
- (* pixbuf->last_unref_fn) (pixbuf, pixbuf->last_unref_fn_data);
- else
- gdk_pixbuf_finalize (pixbuf);
-}
-
-/**
- * gdk_pixbuf_set_last_unref_handler:
- * @pixbuf: A pixbuf.
- * @last_unref_fn: Handler function for the last unref.
- * @last_unref_fn_data: Closure data to pass to the last unref handler function.
- *
- * Sets the handler function for the @pixbuf's last unref handler. When
- * gdk_pixbuf_unref() is called on this pixbuf and it has a reference count of
- * 1, i.e. its last reference, then the last unref handler will be called. This
- * function should determine whether to finalize the pixbuf or just continue.
- * If it wishes to finalize the pixbuf, it should do so by calling
- * gdk_pixbuf_finalize().
- *
- * See also: gdk_pixbuf_finalize().
- **/
-void
-gdk_pixbuf_set_last_unref_handler (GdkPixbuf *pixbuf, GdkPixbufLastUnref last_unref_fn,
- gpointer last_unref_fn_data)
-{
- g_return_if_fail (pixbuf != NULL);
-
- pixbuf->last_unref_fn = last_unref_fn;
- pixbuf->last_unref_fn_data = last_unref_fn_data;
-}
-
-/**
- * gdk_pixbuf_finalize:
- * @pixbuf: A pixbuf with a reference count of 1.
- *
- * Finalizes a pixbuf by calling its destroy notification function to free the
- * pixel data and freeing the pixbuf itself. This function is meant to be
- * called only from within a #GdkPixbufLastUnref handler function, and the
- * specified @pixbuf must have a reference count of 1, i.e. its last reference.
- **/
-void
-gdk_pixbuf_finalize (GdkPixbuf *pixbuf)
-{
- g_return_if_fail (pixbuf != NULL);
- g_return_if_fail (pixbuf->ref_count == 1);
-
- if (pixbuf->destroy_fn)
- (* pixbuf->destroy_fn) (pixbuf->pixels, pixbuf->destroy_fn_data);
-
- g_free (pixbuf);
+ g_object_unref (G_OBJECT (pixbuf));
}
@@ -357,9 +346,17 @@ const char *gdk_pixbuf_version = GDK_PIXBUF_VERSION;
void
gdk_pixbuf_preinit (gpointer app, gpointer modinfo)
{
+ g_type_init ();
}
void
gdk_pixbuf_postinit (gpointer app, gpointer modinfo)
{
}
+
+void
+gdk_pixbuf_init (void)
+{
+ gdk_pixbuf_preinit (NULL, NULL);
+ gdk_pixbuf_postinit (NULL, NULL);
+}