Re: Make GdkDevice, GdkVisual objects



On Sat, 30 Jun 2001, Tim Janik wrote:

> On Fri, 29 Jun 2001, Alex Larsson wrote:
>
> > Here is a patch:
> >
> > Index: gdk/gdkcolor.c
>
> looks good to me, except that you're missing the standard macros
> (_GET_CLASS() etc..) for gdk_visual_private_get_type().
> please commit once fixed.

After talking with owen I redid it slightly. This version hides the
classes in the device-specific portions of Gdk so that the user cannot
derive from it himself. It also avoids an extra type.

Index: gdk/gdkcolor.c
===================================================================
RCS file: /cvs/gnome/gtk+/gdk/gdkcolor.c,v
retrieving revision 1.25
diff -u -p -r1.25 gdkcolor.c
--- gdk/gdkcolor.c	2001/04/02 23:33:46	1.25
+++ gdk/gdkcolor.c	2001/06/30 02:13:14
@@ -230,21 +230,3 @@ gdk_color_get_type (void)
 					     FALSE);
   return our_type;
 }
-
-/* We define this here to avoid having to create a new .C file just for this
- * function. The rest of GdkVisual is platform-specific
- */
-GType
-gdk_visual_get_type (void)
-{
-  static GType our_type = 0;
-
-  if (our_type == 0)
-    our_type = g_boxed_type_register_static ("GdkVisual",
-					     NULL,
-					     (GBoxedCopyFunc)gdk_visual_ref,
-					     (GBoxedFreeFunc)gdk_visual_unref,
-					     TRUE);
-  return our_type;
-}
-
Index: gdk/gdkevents.c
===================================================================
RCS file: /cvs/gnome/gtk+/gdk/gdkevents.c,v
retrieving revision 1.38
diff -u -p -r1.38 gdkevents.c
--- gdk/gdkevents.c	2001/06/28 22:49:19	1.38
+++ gdk/gdkevents.c	2001/06/30 02:13:14
@@ -1016,32 +1016,3 @@ gdk_event_get_type (void)
 					     FALSE);
   return our_type;
 }
-
-/* These functions are defined here to avoid a new C file, as GdkDevice is
- * platform specific. (similar to how gdk_visual_get_type() is in gdkcolor.c)
- */
-GdkDevice *
-gdk_device_ref (GdkDevice *device)
-{
-  return device;
-}
-
-void
-gdk_device_unref (GdkDevice *device)
-{
-  return;
-}
-
-GType
-gdk_device_get_type (void)
-{
-  static GType our_type = 0;
-
-  if (our_type == 0)
-    our_type = g_boxed_type_register_static ("GdkDevice",
-					     NULL,
-					     (GBoxedCopyFunc)gdk_device_ref,
-					     (GBoxedFreeFunc)gdk_device_unref,
-					     TRUE);
-  return our_type;
-}
Index: gdk/gdkinput.h
===================================================================
RCS file: /cvs/gnome/gtk+/gdk/gdkinput.h,v
retrieving revision 1.12
diff -u -p -r1.12 gdkinput.h
--- gdk/gdkinput.h	2001/06/28 16:35:38	1.12
+++ gdk/gdkinput.h	2001/06/30 02:13:14
@@ -7,11 +7,17 @@
 extern "C" {
 #endif /* __cplusplus */

-#define GDK_TYPE_DEVICE (gdk_device_get_type ())
+#define GDK_TYPE_DEVICE              (gdk_device_get_type ())
+#define GDK_DEVICE(object)           (G_TYPE_CHECK_INSTANCE_CAST ((object), GDK_TYPE_DEVICE, GdkDevice))
+#define GDK_DEVICE_CLASS(klass)      (G_TYPE_CHECK_CLASS_CAST ((klass), GDK_TYPE_DEVICE, GdkDeviceClass))
+#define GDK_IS_DEVICE(object)        (G_TYPE_CHECK_INSTANCE_TYPE ((object), GDK_TYPE_DEVICE))
+#define GDK_IS_DEVICE_CLASS(klass)   (G_TYPE_CHECK_CLASS_TYPE ((klass), GDK_TYPE_DEVICE))
+#define GDK_DEVICE_GET_CLASS(obj)    (G_TYPE_INSTANCE_GET_CLASS ((obj), GDK_TYPE_DEVICE, GdkDeviceClass))

 typedef struct _GdkDeviceKey	    GdkDeviceKey;
 typedef struct _GdkDeviceAxis	    GdkDeviceAxis;
 typedef struct _GdkDevice	    GdkDevice;
+typedef struct _GdkDeviceClass	    GdkDeviceClass;
 typedef struct _GdkTimeCoord	    GdkTimeCoord;

 typedef enum
@@ -63,6 +69,7 @@ struct _GdkDeviceAxis

 struct _GdkDevice
 {
+  GObject parent_instance;
   /* All fields are read-only */

   gchar *name;
@@ -89,11 +96,6 @@ struct _GdkTimeCoord
 };

 GType          gdk_device_get_type      (void);
-/* these two are no ops provided for the boxed type code */
-/* XXXX do they need to be exposed as public APIs at all? */
-GdkDevice     *gdk_device_ref           (GdkDevice *device);
-void           gdk_device_unref         (GdkDevice *device);
-

 /* Returns a list of GdkDevice * */
 GList *        gdk_devices_list         (void);
Index: gdk/gdkvisual.h
===================================================================
RCS file: /cvs/gnome/gtk+/gdk/gdkvisual.h,v
retrieving revision 1.3
diff -u -p -r1.3 gdkvisual.h
--- gdk/gdkvisual.h	2001/04/16 12:46:00	1.3
+++ gdk/gdkvisual.h	2001/06/30 02:13:14
@@ -7,8 +7,15 @@
 extern "C" {
 #endif /* __cplusplus */

-#define GDK_TYPE_VISUAL gdk_visual_get_type ()
+#define GDK_TYPE_VISUAL              (gdk_visual_get_type ())
+#define GDK_VISUAL(object)           (G_TYPE_CHECK_INSTANCE_CAST ((object), GDK_TYPE_VISUAL, GdkVisual))
+#define GDK_VISUAL_CLASS(klass)      (G_TYPE_CHECK_CLASS_CAST ((klass), GDK_TYPE_VISUAL, GdkVisualClass))
+#define GDK_IS_VISUAL(object)        (G_TYPE_CHECK_INSTANCE_TYPE ((object), GDK_TYPE_VISUAL))
+#define GDK_IS_VISUAL_CLASS(klass)   (G_TYPE_CHECK_CLASS_TYPE ((klass), GDK_TYPE_VISUAL))
+#define GDK_VISUAL_GET_CLASS(obj)    (G_TYPE_INSTANCE_GET_CLASS ((obj), GDK_TYPE_VISUAL, GdkVisualClass))

+typedef struct _GdkVisualClass    GdkVisualClass;
+
 /* Types of visuals.
  *   StaticGray:
  *   Grayscale:
@@ -41,6 +48,8 @@ typedef enum
  */
 struct _GdkVisual
 {
+  GObject parent_instance;
+
   GdkVisualType type;
   gint depth;
   GdkByteOrder byte_order;
@@ -70,10 +79,6 @@ GdkVisual*    gdk_visual_get_best_with_d
 GdkVisual*    gdk_visual_get_best_with_type  (GdkVisualType  visual_type);
 GdkVisual*    gdk_visual_get_best_with_both  (gint	     depth,
 					      GdkVisualType  visual_type);
-
-/* Actually, these are no-ops... */
-GdkVisual* gdk_visual_ref (GdkVisual *visual);
-void	   gdk_visual_unref (GdkVisual *visual);

 void gdk_query_depths	    (gint	    **depths,
 			     gint	     *count);
Index: gdk/x11/gdkinput-gxi.c
===================================================================
RCS file: /cvs/gnome/gtk+/gdk/x11/gdkinput-gxi.c,v
retrieving revision 1.10
diff -u -p -r1.10 gdkinput-gxi.c
--- gdk/x11/gdkinput-gxi.c	2000/07/26 11:32:30	1.10
+++ gdk/x11/gdkinput-gxi.c	2001/06/30 02:13:14
@@ -53,6 +53,7 @@ gdk_input_init(void)
 {
   GList *tmp_list;

+  _gdk_init_input_core ();
   gdk_input_ignore_core = FALSE;
   gdk_input_core_pointer = NULL;

Index: gdk/x11/gdkinput-none.c
===================================================================
RCS file: /cvs/gnome/gtk+/gdk/x11/gdkinput-none.c,v
retrieving revision 1.10
diff -u -p -r1.10 gdkinput-none.c
--- gdk/x11/gdkinput-none.c	2000/07/26 11:32:30	1.10
+++ gdk/x11/gdkinput-none.c	2001/06/30 02:13:14
@@ -29,6 +29,7 @@
 void
 gdk_input_init (void)
 {
+  _gdk_init_input_core ();
   gdk_input_devices = g_list_append (NULL, gdk_core_pointer);

   gdk_input_ignore_core = FALSE;
Index: gdk/x11/gdkinput-x11.c
===================================================================
RCS file: /cvs/gnome/gtk+/gdk/x11/gdkinput-x11.c,v
retrieving revision 1.18
diff -u -p -r1.18 gdkinput-x11.c
--- gdk/x11/gdkinput-x11.c	2000/07/26 11:32:30	1.18
+++ gdk/x11/gdkinput-x11.c	2001/06/30 02:13:14
@@ -96,7 +96,7 @@ gdk_input_device_new (XDeviceInfo *devic
   XAnyClassPtr class;
   gint i,j;

-  gdkdev = g_new(GdkDevicePrivate,1);
+  gdkdev = g_object_new (GDK_TYPE_DEVICE_PRIVATE, 1);

   gdkdev->deviceid = device->id;
   if (device->name[0])
@@ -245,7 +245,7 @@ gdk_input_device_new (XDeviceInfo *devic
     g_free (gdkdev->info.keys);
   if (gdkdev->info.axes)
     g_free (gdkdev->info.axes);
-  g_free (gdkdev);
+  g_object_unref (gdkdev);

   return NULL;
 }
Index: gdk/x11/gdkinput-xfree.c
===================================================================
RCS file: /cvs/gnome/gtk+/gdk/x11/gdkinput-xfree.c,v
retrieving revision 1.13
diff -u -p -r1.13 gdkinput-xfree.c
--- gdk/x11/gdkinput-xfree.c	2000/07/26 11:32:30	1.13
+++ gdk/x11/gdkinput-xfree.c	2001/06/30 02:13:15
@@ -33,6 +33,7 @@ static void gdk_input_check_proximity (v
 void
 gdk_input_init(void)
 {
+  _gdk_init_input_core ();
   gdk_input_ignore_core = FALSE;
   gdk_input_common_init(FALSE);
 }
Index: gdk/x11/gdkinput.c
===================================================================
RCS file: /cvs/gnome/gtk+/gdk/x11/gdkinput.c,v
retrieving revision 1.19
diff -u -p -r1.19 gdkinput.c
--- gdk/x11/gdkinput.c	2001/03/04 00:12:55	1.19
+++ gdk/x11/gdkinput.c	2001/06/30 02:13:15
@@ -39,21 +39,7 @@ static GdkDeviceAxis gdk_input_core_axes
   { GDK_AXIS_Y, 0, 0 }
 };

-static const GdkDevice gdk_input_core_info =
-{
-  "Core Pointer",
-  GDK_SOURCE_MOUSE,
-  GDK_MODE_SCREEN,
-  TRUE,
-
-  2,
-  gdk_input_core_axes,
-
-  0,
-  NULL
-};
-
-GdkDevice *gdk_core_pointer = (GdkDevice *)&gdk_input_core_info;
+GdkDevice *gdk_core_pointer = NULL;

 /* Global variables  */

@@ -64,6 +50,61 @@ gint              gdk_input_ignore_core;

 GList            *gdk_input_devices;
 GList            *gdk_input_windows;
+
+void
+_gdk_init_input_core (void)
+{
+  gdk_core_pointer = g_object_new (GDK_TYPE_DEVICE, NULL);
+
+  gdk_core_pointer->name = "Core Pointer";
+  gdk_core_pointer->source = GDK_SOURCE_MOUSE;
+  gdk_core_pointer->mode = GDK_MODE_SCREEN;
+  gdk_core_pointer->has_cursor = TRUE;
+  gdk_core_pointer->num_axes = 2;
+  gdk_core_pointer->axes = gdk_input_core_axes;
+  gdk_core_pointer->num_keys = 0;
+  gdk_core_pointer->keys = NULL;
+}
+
+static void
+gdk_device_finalize (GObject *object)
+{
+  g_error ("A GdkDevice object was finalized. This should not happen");
+}
+
+static void
+gdk_device_class_init (GObjectClass *class)
+{
+  class->finalize = gdk_device_finalize;
+}
+
+GType
+gdk_device_get_type (void)
+{
+  static GType object_type = 0;
+
+  if (!object_type)
+    {
+      static const GTypeInfo object_info =
+      {
+        sizeof (GdkDeviceClass),
+        (GBaseInitFunc) NULL,
+        (GBaseFinalizeFunc) NULL,
+        (GClassInitFunc) gdk_device_class_init,
+        NULL,           /* class_finalize */
+        NULL,           /* class_data */
+        sizeof (GdkDevicePrivate),
+        0,              /* n_preallocs */
+        (GInstanceInitFunc) NULL,
+      };
+
+      object_type = g_type_register_static (G_TYPE_OBJECT,
+                                            "GdkDevice",
+                                            &object_info, 0);
+    }
+
+  return object_type;
+}

 GList *
 gdk_devices_list (void)
Index: gdk/x11/gdkinputprivate.h
===================================================================
RCS file: /cvs/gnome/gtk+/gdk/x11/gdkinputprivate.h,v
retrieving revision 1.6
diff -u -p -r1.6 gdkinputprivate.h
--- gdk/x11/gdkinputprivate.h	2000/07/26 11:32:30	1.6
+++ gdk/x11/gdkinputprivate.h	2001/06/30 02:13:15
@@ -38,6 +38,7 @@
 #include <X11/extensions/XInput.h>
 #endif

+
 typedef struct _GdkAxisInfo    GdkAxisInfo;
 typedef struct _GdkDevicePrivate GdkDevicePrivate;
 typedef struct _GdkInputWindow GdkInputWindow;
@@ -94,6 +95,11 @@ struct _GdkDevicePrivate
 #endif /* !XINPUT_NONE */
 };

+struct _GdkDeviceClass
+{
+  GObjectClass parent_class;
+};
+
 struct _GdkInputWindow
 {
   /* gdk window */
@@ -114,6 +120,8 @@ struct _GdkInputWindow
   gint grabbed;
 };

+
+
 /* Global data */

 #define GDK_IS_CORE(d) (((GdkDevice *)(d)) == gdk_core_pointer)
@@ -132,6 +140,7 @@ GdkInputWindow *gdk_input_window_find
 void            gdk_input_window_destroy     (GdkWindow *window);
 GdkTimeCoord ** _gdk_device_allocate_history (GdkDevice *device,
 					      gint       n_events);
+void            _gdk_init_input_core         (void);

 /* The following functions are provided by each implementation
  * (xfree, gxi, and none)
Index: gdk/x11/gdkvisual-x11.c
===================================================================
RCS file: /cvs/gnome/gtk+/gdk/x11/gdkvisual-x11.c,v
retrieving revision 1.21
diff -u -p -r1.21 gdkvisual-x11.c
--- gdk/x11/gdkvisual-x11.c	2000/11/13 13:15:40	1.21
+++ gdk/x11/gdkvisual-x11.c	2001/06/30 02:13:15
@@ -41,7 +41,7 @@ static gboolean gdk_visual_equal


 static GdkVisualPrivate *system_visual;
-static GdkVisualPrivate *visuals;
+static GdkVisualPrivate **visuals;
 static gint nvisuals;

 static gint available_depths[7];
@@ -66,6 +66,48 @@ static const gchar* visual_names[] =

 static GHashTable *visual_hash = NULL;

+static void
+gdk_visual_finalize (GObject *object)
+{
+  g_error ("A GdkVisual object was finalized. This should not happen");
+}
+
+static void
+gdk_visual_class_init (GObjectClass *class)
+{
+  class->finalize = gdk_visual_finalize;
+}
+
+
+GType
+gdk_visual_get_type (void)
+{
+  static GType object_type = 0;
+
+  if (!object_type)
+    {
+      static const GTypeInfo object_info =
+      {
+        sizeof (GdkVisualClass),
+        (GBaseInitFunc) NULL,
+        (GBaseFinalizeFunc) NULL,
+        (GClassInitFunc) gdk_visual_class_init,
+        NULL,           /* class_finalize */
+        NULL,           /* class_data */
+        sizeof (GdkVisualPrivate),
+        0,              /* n_preallocs */
+        (GInstanceInitFunc) NULL,
+      };
+
+      object_type = g_type_register_static (G_TYPE_OBJECT,
+                                            "GdkVisual",
+                                            &object_info, 0);
+    }
+
+  return object_type;
+}
+
+
 void
 gdk_visual_init (void)
 {
@@ -85,14 +127,17 @@ gdk_visual_init (void)

   XVisualInfo *visual_list;
   XVisualInfo visual_template;
-  GdkVisualPrivate temp_visual;
+  GdkVisualPrivate *temp_visual;
   Visual *default_xvisual;
   int nxvisuals;
   int i, j;

   visual_template.screen = gdk_screen;
   visual_list = XGetVisualInfo (gdk_display, VisualScreenMask, &visual_template, &nxvisuals);
-  visuals = g_new (GdkVisualPrivate, nxvisuals);
+
+  visuals = g_new (GdkVisualPrivate *, nxvisuals);
+  for (i = 0; i < nxvisuals; i++)
+    visuals[i] = g_object_new (GDK_TYPE_VISUAL, NULL);

   default_xvisual = DefaultVisual (gdk_display, gdk_screen);

@@ -108,64 +153,64 @@ gdk_visual_init (void)
 #endif /* __cplusplus */
 	    {
 	    case StaticGray:
-	      visuals[nvisuals].visual.type = GDK_VISUAL_STATIC_GRAY;
+	      visuals[nvisuals]->visual.type = GDK_VISUAL_STATIC_GRAY;
 	      break;
 	    case GrayScale:
-	      visuals[nvisuals].visual.type = GDK_VISUAL_GRAYSCALE;
+	      visuals[nvisuals]->visual.type = GDK_VISUAL_GRAYSCALE;
 	      break;
 	    case StaticColor:
-	      visuals[nvisuals].visual.type = GDK_VISUAL_STATIC_COLOR;
+	      visuals[nvisuals]->visual.type = GDK_VISUAL_STATIC_COLOR;
 	      break;
 	    case PseudoColor:
-	      visuals[nvisuals].visual.type = GDK_VISUAL_PSEUDO_COLOR;
+	      visuals[nvisuals]->visual.type = GDK_VISUAL_PSEUDO_COLOR;
 	      break;
 	    case TrueColor:
-	      visuals[nvisuals].visual.type = GDK_VISUAL_TRUE_COLOR;
+	      visuals[nvisuals]->visual.type = GDK_VISUAL_TRUE_COLOR;
 	      break;
 	    case DirectColor:
-	      visuals[nvisuals].visual.type = GDK_VISUAL_DIRECT_COLOR;
+	      visuals[nvisuals]->visual.type = GDK_VISUAL_DIRECT_COLOR;
 	      break;
 	    }

-	  visuals[nvisuals].visual.depth = visual_list[i].depth;
-	  visuals[nvisuals].visual.byte_order =
+	  visuals[nvisuals]->visual.depth = visual_list[i].depth;
+	  visuals[nvisuals]->visual.byte_order =
 	    (ImageByteOrder(gdk_display) == LSBFirst) ?
 	    GDK_LSB_FIRST : GDK_MSB_FIRST;
-	  visuals[nvisuals].visual.red_mask = visual_list[i].red_mask;
-	  visuals[nvisuals].visual.green_mask = visual_list[i].green_mask;
-	  visuals[nvisuals].visual.blue_mask = visual_list[i].blue_mask;
-	  visuals[nvisuals].visual.colormap_size = visual_list[i].colormap_size;
-	  visuals[nvisuals].visual.bits_per_rgb = visual_list[i].bits_per_rgb;
-	  visuals[nvisuals].xvisual = visual_list[i].visual;
+	  visuals[nvisuals]->visual.red_mask = visual_list[i].red_mask;
+	  visuals[nvisuals]->visual.green_mask = visual_list[i].green_mask;
+	  visuals[nvisuals]->visual.blue_mask = visual_list[i].blue_mask;
+	  visuals[nvisuals]->visual.colormap_size = visual_list[i].colormap_size;
+	  visuals[nvisuals]->visual.bits_per_rgb = visual_list[i].bits_per_rgb;
+	  visuals[nvisuals]->xvisual = visual_list[i].visual;

-	  if ((visuals[nvisuals].visual.type == GDK_VISUAL_TRUE_COLOR) ||
-	      (visuals[nvisuals].visual.type == GDK_VISUAL_DIRECT_COLOR))
+	  if ((visuals[nvisuals]->visual.type == GDK_VISUAL_TRUE_COLOR) ||
+	      (visuals[nvisuals]->visual.type == GDK_VISUAL_DIRECT_COLOR))
 	    {
-	      gdk_visual_decompose_mask (visuals[nvisuals].visual.red_mask,
-					 &visuals[nvisuals].visual.red_shift,
-					 &visuals[nvisuals].visual.red_prec);
-
-	      gdk_visual_decompose_mask (visuals[nvisuals].visual.green_mask,
-					 &visuals[nvisuals].visual.green_shift,
-					 &visuals[nvisuals].visual.green_prec);
-
-	      gdk_visual_decompose_mask (visuals[nvisuals].visual.blue_mask,
-					 &visuals[nvisuals].visual.blue_shift,
-					 &visuals[nvisuals].visual.blue_prec);
+	      gdk_visual_decompose_mask (visuals[nvisuals]->visual.red_mask,
+					 &visuals[nvisuals]->visual.red_shift,
+					 &visuals[nvisuals]->visual.red_prec);
+
+	      gdk_visual_decompose_mask (visuals[nvisuals]->visual.green_mask,
+					 &visuals[nvisuals]->visual.green_shift,
+					 &visuals[nvisuals]->visual.green_prec);
+
+	      gdk_visual_decompose_mask (visuals[nvisuals]->visual.blue_mask,
+					 &visuals[nvisuals]->visual.blue_shift,
+					 &visuals[nvisuals]->visual.blue_prec);
 	    }
 	  else
 	    {
-	      visuals[nvisuals].visual.red_mask = 0;
-	      visuals[nvisuals].visual.red_shift = 0;
-	      visuals[nvisuals].visual.red_prec = 0;
-
-	      visuals[nvisuals].visual.green_mask = 0;
-	      visuals[nvisuals].visual.green_shift = 0;
-	      visuals[nvisuals].visual.green_prec = 0;
-
-	      visuals[nvisuals].visual.blue_mask = 0;
-	      visuals[nvisuals].visual.blue_shift = 0;
-	      visuals[nvisuals].visual.blue_prec = 0;
+	      visuals[nvisuals]->visual.red_mask = 0;
+	      visuals[nvisuals]->visual.red_shift = 0;
+	      visuals[nvisuals]->visual.red_prec = 0;
+
+	      visuals[nvisuals]->visual.green_mask = 0;
+	      visuals[nvisuals]->visual.green_shift = 0;
+	      visuals[nvisuals]->visual.green_prec = 0;
+
+	      visuals[nvisuals]->visual.blue_mask = 0;
+	      visuals[nvisuals]->visual.blue_shift = 0;
+	      visuals[nvisuals]->visual.blue_prec = 0;
 	    }

 	  nvisuals += 1;
@@ -179,27 +224,27 @@ gdk_visual_init (void)
     {
       for (j = i+1; j < nvisuals; j++)
 	{
-	  if (visuals[j].visual.depth >= visuals[i].visual.depth)
+	  if (visuals[j]->visual.depth >= visuals[i]->visual.depth)
 	    {
-	      if ((visuals[j].visual.depth == 8) && (visuals[i].visual.depth == 8))
+	      if ((visuals[j]->visual.depth == 8) && (visuals[i]->visual.depth == 8))
 		{
-		  if (visuals[j].visual.type == GDK_VISUAL_PSEUDO_COLOR)
+		  if (visuals[j]->visual.type == GDK_VISUAL_PSEUDO_COLOR)
 		    {
 		      temp_visual = visuals[j];
 		      visuals[j] = visuals[i];
 		      visuals[i] = temp_visual;
 		    }
-		  else if ((visuals[i].visual.type != GDK_VISUAL_PSEUDO_COLOR) &&
-			   visuals[j].visual.type > visuals[i].visual.type)
+		  else if ((visuals[i]->visual.type != GDK_VISUAL_PSEUDO_COLOR) &&
+			   visuals[j]->visual.type > visuals[i]->visual.type)
 		    {
 		      temp_visual = visuals[j];
 		      visuals[j] = visuals[i];
 		      visuals[i] = temp_visual;
 		    }
 		}
-	      else if ((visuals[j].visual.depth > visuals[i].visual.depth) ||
-		       ((visuals[j].visual.depth == visuals[i].visual.depth) &&
-			(visuals[j].visual.type > visuals[i].visual.type)))
+	      else if ((visuals[j]->visual.depth > visuals[i]->visual.depth) ||
+		       ((visuals[j]->visual.depth == visuals[i]->visual.depth) &&
+			(visuals[j]->visual.type > visuals[i]->visual.type)))
 		{
 		  temp_visual = visuals[j];
 		  visuals[j] = visuals[i];
@@ -210,9 +255,9 @@ gdk_visual_init (void)
     }

   for (i = 0; i < nvisuals; i++)
-    if (default_xvisual->visualid == visuals[i].xvisual->visualid)
+    if (default_xvisual->visualid == visuals[i]->xvisual->visualid)
       {
-	system_visual = &visuals[i];
+	system_visual = visuals[i];
 	break;
       }

@@ -220,8 +265,8 @@ gdk_visual_init (void)
   if (gdk_debug_flags & GDK_DEBUG_MISC)
     for (i = 0; i < nvisuals; i++)
       g_message ("visual: %s: %d",
-		 visual_names[visuals[i].visual.type],
-		 visuals[i].visual.depth);
+		 visual_names[visuals[i]->visual.type],
+		 visuals[i]->visual.depth);
 #endif /* G_ENABLE_DEBUG */

   navailable_depths = 0;
@@ -229,9 +274,9 @@ gdk_visual_init (void)
     {
       for (j = 0; j < nvisuals; j++)
 	{
-	  if (visuals[j].visual.depth == possible_depths[i])
+	  if (visuals[j]->visual.depth == possible_depths[i])
 	    {
-	      available_depths[navailable_depths++] = visuals[j].visual.depth;
+	      available_depths[navailable_depths++] = visuals[j]->visual.depth;
 	      break;
 	    }
 	}
@@ -245,33 +290,21 @@ gdk_visual_init (void)
     {
       for (j = 0; j < nvisuals; j++)
 	{
-	  if (visuals[j].visual.type == possible_types[i])
+	  if (visuals[j]->visual.type == possible_types[i])
 	    {
-	      available_types[navailable_types++] = visuals[j].visual.type;
+	      available_types[navailable_types++] = visuals[j]->visual.type;
 	      break;
 	    }
 	}
     }

   for (i = 0; i < nvisuals; i++)
-    gdk_visual_add ((GdkVisual*) &visuals[i]);
+    gdk_visual_add ((GdkVisual*) visuals[i]);

   if (npossible_types == 0)
     g_error ("unable to find a usable visual type");
 }

-GdkVisual*
-gdk_visual_ref (GdkVisual *visual)
-{
-  return visual;
-}
-
-void
-gdk_visual_unref (GdkVisual *visual)
-{
-  return;
-}
-
 gint
 gdk_visual_get_best_depth (void)
 {
@@ -293,7 +326,7 @@ gdk_visual_get_system (void)
 GdkVisual*
 gdk_visual_get_best (void)
 {
-  return ((GdkVisual*) &(visuals[0]));
+  return ((GdkVisual*) visuals[0]);
 }

 GdkVisual*
@@ -304,9 +337,9 @@ gdk_visual_get_best_with_depth (gint dep

   return_val = NULL;
   for (i = 0; i < nvisuals; i++)
-    if (depth == visuals[i].visual.depth)
+    if (depth == visuals[i]->visual.depth)
       {
-	return_val = (GdkVisual*) &(visuals[i]);
+	return_val = (GdkVisual*) visuals[i];
 	break;
       }

@@ -321,9 +354,9 @@ gdk_visual_get_best_with_type (GdkVisual

   return_val = NULL;
   for (i = 0; i < nvisuals; i++)
-    if (visual_type == visuals[i].visual.type)
+    if (visual_type == visuals[i]->visual.type)
       {
-	return_val = (GdkVisual*) &(visuals[i]);
+	return_val = (GdkVisual*) visuals[i];
 	break;
       }

@@ -339,10 +372,10 @@ gdk_visual_get_best_with_both (gint

   return_val = NULL;
   for (i = 0; i < nvisuals; i++)
-    if ((depth == visuals[i].visual.depth) &&
-	(visual_type == visuals[i].visual.type))
+    if ((depth == visuals[i]->visual.depth) &&
+	(visual_type == visuals[i]->visual.type))
       {
-	return_val = (GdkVisual*) &(visuals[i]);
+	return_val = (GdkVisual*) visuals[i];
 	break;
       }

@@ -373,7 +406,7 @@ gdk_list_visuals (void)

   list = NULL;
   for (i = 0; i < nvisuals; ++i)
-    list = g_list_append (list, (gpointer) &visuals[i]);
+    list = g_list_append (list, (gpointer) visuals[i]);

   return list;
 }
@@ -397,8 +430,8 @@ gdkx_visual_get (VisualID xvisualid)
   int i;

   for (i = 0; i < nvisuals; i++)
-    if (xvisualid == visuals[i].xvisual->visualid)
-      return (GdkVisual*) &visuals[i];
+    if (xvisualid == visuals[i]->xvisual->visualid)
+      return (GdkVisual*) visuals[i];

   return NULL;
 }
Index: gdk/x11/gdkx.h
===================================================================
RCS file: /cvs/gnome/gtk+/gdk/x11/gdkx.h,v
retrieving revision 1.19
diff -u -p -r1.19 gdkx.h
--- gdk/x11/gdkx.h	2001/06/29 01:59:00	1.19
+++ gdk/x11/gdkx.h	2001/06/30 02:13:15
@@ -36,10 +36,10 @@
 #include <gdk/x11/gdkwindow-x11.h>
 #include <gdk/x11/gdkpixmap-x11.h>

-typedef struct _GdkColormapPrivateX11 GdkColormapPrivateX11;
+typedef struct _GdkColormapPrivateX11  GdkColormapPrivateX11;
 typedef struct _GdkCursorPrivate       GdkCursorPrivate;
 typedef struct _GdkFontPrivateX        GdkFontPrivateX;
-typedef struct _GdkImagePrivateX11    GdkImagePrivateX11;
+typedef struct _GdkImagePrivateX11     GdkImagePrivateX11;
 typedef struct _GdkVisualPrivate       GdkVisualPrivate;

 struct _GdkCursorPrivate
@@ -64,6 +64,11 @@ struct _GdkVisualPrivate
 {
   GdkVisual visual;
   Visual *xvisual;
+};
+
+struct _GdkVisualClass
+{
+  GObjectClass parent_class;
 };

 struct _GdkColormapPrivateX11





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