cursor refcounts




Trivial patch against HEAD, adds a reference count to GdkCursor so you
can use it in nontrivial code without creating a wrapper datatype
(would like to avoid GnomeCursor).


Index: ChangeLog
===================================================================
RCS file: /cvs/gnome/gtk+/ChangeLog,v
retrieving revision 1.1189
diff -u -u -r1.1189 ChangeLog
--- ChangeLog	2000/01/28 12:16:24	1.1189
+++ ChangeLog	2000/01/29 21:23:22
@@ -1,3 +1,20 @@
+2000-01-30  Havoc Pennington  <hp@pobox.com>
+
+	* gdk/Makefile.am (gdk_c_sources): add gdkcursor.c
+
+	* gdk/x11/gdkcursor-x11.c (gdk_cursor_unref): replace
+	gdk_cursor_destroy with unref
+
+	* gdk/win32/gdkcursor-win32.c (gdk_cursor_unref): replace
+	gdk_cursor_destroy with gdk_cursor_unref
+
+	* gdk/gdkcursor.c: new file, implements gdk_cursor_ref in 
+	a cross-platform way.
+
+	* gdk/gdkcursor.h: Refcount GdkCursor
+
+	* gdk/gdkcompat.h (gdk_cursor_destroy): compat
+
 2000-01-29  Tor Lillqvist  <tml@iki.fi>
 
 	* gdk/gdkwindow.h
Index: gdk/Makefile.am
===================================================================
RCS file: /cvs/gnome/gtk+/gdk/Makefile.am,v
retrieving revision 1.38
diff -u -u -r1.38 Makefile.am
--- gdk/Makefile.am	2000/01/15 16:04:53	1.38
+++ gdk/Makefile.am	2000/01/29 21:23:23
@@ -76,6 +76,7 @@
 gdk_c_sources = @STRIP_BEGIN@ \
 	gdk.c		\
 	gdkcolor.c	\
+	gdkcursor.c	\
 	gdkdraw.c	\
 	gdkevents.c     \
 	gdkfont.c	\
Index: gdk/gdkcompat.h
===================================================================
RCS file: /cvs/gnome/gtk+/gdk/gdkcompat.h,v
retrieving revision 1.2
diff -u -u -r1.2 gdkcompat.h
--- gdk/gdkcompat.h	1999/11/08 20:14:55	1.2
+++ gdk/gdkcompat.h	2000/01/29 21:23:23
@@ -34,6 +34,8 @@
 
 #define gdk_gc_destroy                 gdk_gc_unref
 #define gdk_image_destroy              gdk_image_unref
+#define gdk_cursor_destroy             gdk_cursor_unref
+
 
 #define GDK_WINDOW_PIXMAP GDK_DRAWABLE_PIXMAP
              
Index: gdk/gdkcursor.h
===================================================================
RCS file: /cvs/gnome/gtk+/gdk/gdkcursor.h,v
retrieving revision 1.1
diff -u -u -r1.1 gdkcursor.h
--- gdk/gdkcursor.h	1999/10/01 23:18:29	1.1
+++ gdk/gdkcursor.h	2000/01/29 21:23:23
@@ -19,6 +19,7 @@
 struct _GdkCursor
 {
   GdkCursorType type;
+  guint refcount;
 };
 
 /* Cursors
@@ -30,7 +31,8 @@
 					  GdkColor	  *bg,
 					  gint		   x,
 					  gint		   y);
-void	   gdk_cursor_destroy		 (GdkCursor	 *cursor);
+GdkCursor* gdk_cursor_ref                (GdkCursor      *cursor);
+void       gdk_cursor_unref              (GdkCursor      *cursor);
 
 #ifdef __cplusplus
 }
Index: gdk/win32/gdkcursor-win32.c
===================================================================
RCS file: /cvs/gnome/gtk+/gdk/win32/gdkcursor-win32.c,v
retrieving revision 1.10
diff -u -u -r1.10 gdkcursor-win32.c
--- gdk/win32/gdkcursor-win32.c	1999/11/20 01:22:57	1.10
+++ gdk/win32/gdkcursor-win32.c	2000/01/29 21:23:24
@@ -255,19 +255,26 @@
 }
 
 void
-gdk_cursor_destroy (GdkCursor *cursor)
+gdk_cursor_unref (GdkCursor *cursor)
 {
   GdkCursorPrivate *private;
 
   g_return_if_fail (cursor != NULL);
+  g_return_if_fail (cursor->refcount > 0);
   private = (GdkCursorPrivate *) cursor;
 
-  GDK_NOTE (MISC, g_print ("gdk_cursor_destroy: %#x\n",
+  GDK_NOTE (MISC, g_print ("gdk_cursor_unref: %#x\n",
 			   (cursor->type == GDK_CURSOR_IS_PIXMAP) ? private->xcursor : 0));
 
-  if (cursor->type == GDK_CURSOR_IS_PIXMAP)
-    if (!DestroyIcon (private->xcursor))
-      g_warning ("gdk_cursor_destroy: DestroyIcon failed");
+  cursor->refcount -= 1;
 
-  g_free (private);
+
+  if (cursor->refcount == 0)
+    {
+      if (cursor->type == GDK_CURSOR_IS_PIXMAP)
+        if (!DestroyIcon (private->xcursor))
+          g_warning ("gdk_cursor_destroy: DestroyIcon failed");
+
+      g_free (private);
+    }
 }
Index: gdk/x11/gdkcursor-x11.c
===================================================================
RCS file: /cvs/gnome/gtk+/gdk/x11/gdkcursor-x11.c,v
retrieving revision 1.8
diff -u -u -r1.8 gdkcursor-x11.c
--- gdk/x11/gdkcursor-x11.c	1999/11/08 20:14:58	1.8
+++ gdk/x11/gdkcursor-x11.c	2000/01/29 21:23:25
@@ -79,14 +79,22 @@
 }
 
 void
-gdk_cursor_destroy (GdkCursor *cursor)
+gdk_cursor_unref (GdkCursor *cursor)
 {
   GdkCursorPrivate *private;
 
   g_return_if_fail (cursor != NULL);
+  g_return_if_fail (cursor->refcount > 0);
 
-  private = (GdkCursorPrivate *) cursor;
-  XFreeCursor (private->xdisplay, private->xcursor);
+  cursor->refcount -= 1;
 
-  g_free (private);
+  if (cursor->refcount == 0)
+    {
+      private = (GdkCursorPrivate *) cursor;
+      XFreeCursor (private->xdisplay, private->xcursor);
+
+      g_free (private);
+    }
 }
+
+



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]