From 414a14d93ef4fb721fe65cd8f6b28af63d981b76 Mon Sep 17 00:00:00 2001 From: Rachel Hestilow Date: Mon, 24 Jun 2002 23:38:51 +0000 Subject: [PATCH] 2002-06-24 Rachel Hestilow * glib/UnwrappedObject.cs: New class which holds an IntPtr. This is used in Value so that we can retrieve the IntPtr itself for an object property. * glib/Value.cs: Add UnwrappedObject cast operator. * glib/Property.cs: If the retrieved value is an object, and there is no wrapper object, create a new one. svn path=/trunk/gtk-sharp/; revision=5440 --- ChangeLog | 11 +++++++++++ configure.in | 1 + generator/Property.cs | 19 +++++++++++++++---- glib/UnwrappedObject.cs | 26 ++++++++++++++++++++++++++ glib/Value.cs | 18 ++++++++++++++++++ makefile | 2 +- makefile.win32 | 2 +- 7 files changed, 73 insertions(+), 6 deletions(-) create mode 100644 glib/UnwrappedObject.cs diff --git a/ChangeLog b/ChangeLog index d3a84c760..3bacd3c79 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,14 @@ +2002-06-24 Rachel Hestilow + + * glib/UnwrappedObject.cs: New class which holds an IntPtr. + This is used in Value so that we can retrieve the IntPtr itself + for an object property. + + * glib/Value.cs: Add UnwrappedObject cast operator. + + * glib/Property.cs: If the retrieved value is an object, + and there is no wrapper object, create a new one. + 2002-06-24 Rachel Hestilow * gtk/FileSelection.custom: Remove random cruft that was diff --git a/configure.in b/configure.in index 3c5fdbd24..3f98b9d6e 100644 --- a/configure.in +++ b/configure.in @@ -81,6 +81,7 @@ pango/Makefile atk/Makefile gdk/Makefile gtk/Makefile +gnome/Makefile sample/Makefile ]) diff --git a/generator/Property.cs b/generator/Property.cs index 604999881..b39bcffd1 100644 --- a/generator/Property.cs +++ b/generator/Property.cs @@ -81,11 +81,22 @@ namespace GtkSharp.Generation { sw.WriteLine("\t\t\tget {"); sw.WriteLine("\t\t\t\tGLib.Value val = new GLib.Value (Handle, " + cname + ");"); sw.WriteLine("\t\t\t\tGetProperty(" + cname + ", val);"); - sw.Write("\t\t\t\treturn (" + cs_type + ") "); - if (v_type != "") { - sw.Write(v_type + " "); + if (SymbolTable.IsObject (c_type)) + { + sw.WriteLine("\t\t\t\tSystem.IntPtr raw_ret = (System.IntPtr) (GLib.UnwrappedObject) val;"); + sw.WriteLine("\t\t\t\t" + cs_type + " ret = " + SymbolTable.FromNative(c_type, "raw_ret") + ";"); + sw.WriteLine("\t\t\t\tif (ret == null) ret = new " + cs_type + "(raw_ret);"); } - sw.WriteLine("val;"); + else { + sw.Write("\t\t\t\t" + cs_type + " ret = "); + sw.Write ("(" + cs_type + ") "); + if (v_type != "") { + sw.Write(v_type + " "); + } + sw.WriteLine("val;"); + } + + sw.WriteLine("\t\t\t\treturn ret;"); sw.WriteLine("\t\t\t}"); } diff --git a/glib/UnwrappedObject.cs b/glib/UnwrappedObject.cs new file mode 100644 index 000000000..cf333445a --- /dev/null +++ b/glib/UnwrappedObject.cs @@ -0,0 +1,26 @@ +// UnwrappedObject.cs - Class which holds an IntPtr without resolving it: +// +// Author: Rachel Hestilow +// +// (c) 2002 Rachel Hestilow + +namespace GLib { + + using System; + using System.Runtime.InteropServices; + + // Unwrapped object class + // + public class UnwrappedObject { + IntPtr obj; + + public UnwrappedObject (IntPtr obj) { + this.obj = obj; + } + + public static explicit operator System.IntPtr (UnwrappedObject obj) { + return obj.obj; + } + } +} + diff --git a/glib/Value.cs b/glib/Value.cs index a93e5ecda..7559cdd90 100755 --- a/glib/Value.cs +++ b/glib/Value.cs @@ -357,6 +357,24 @@ namespace GLib { return GLib.Object.GetObject(g_value_get_object (val._val)); } + /// + /// Value to Unresolved Object Conversion + /// + /// + /// + /// Extracts an object from a Value without looking up its wrapping + /// class. + /// Note, this method will produce an exception if the Value does + /// not hold a object value. + /// + + public static explicit operator GLib.UnwrappedObject (Value val) + { + // FIXME: Insert an appropriate exception here if + // _val.type indicates an error. + return new UnwrappedObject(g_value_get_object (val._val)); + } + [DllImport("gobject-2.0")] static extern IntPtr g_value_get_pointer (IntPtr val); diff --git a/makefile b/makefile index d9586f63c..dba0107a7 100644 --- a/makefile +++ b/makefile @@ -1,4 +1,4 @@ -DIRS=generator glib pango atk gdk gtk sample +DIRS=generator glib pango atk gdk gtk gnome sample ROOT=/cygdrive/$(subst \,/,$(subst :\,/,$(SYSTEMROOT))) CSC=$(ROOT)/microsoft.net/framework/v1.0.3705/csc.exe MCS=mcs diff --git a/makefile.win32 b/makefile.win32 index 555d84790..92e4e217a 100755 --- a/makefile.win32 +++ b/makefile.win32 @@ -1,4 +1,4 @@ -DIRS=generator glib pango atk gdk gtk sample +DIRS=generator glib pango atk gdk gtk gnome sample ROOT=/cygdrive/$(subst \,/,$(subst :\,/,$(SYSTEMROOT))) CSC=$(ROOT)/microsoft.net/framework/v1.0.3705/csc.exe