From ff263164e30661801e684e2c1db5382023135724 Mon Sep 17 00:00:00 2001 From: Mike Kestner Date: Mon, 15 Dec 2003 16:59:25 +0000 Subject: [PATCH] 2003-12-15 Mike Kestner * generator/BoxedGen.cs : s/uint/GLib.GType * generator/ManualGen.cs : add a ctor to pass ToNative handle name * generator/ObjectGen.cs : s/uint/GLib.GType * generator/Signal.cs : use GLib.GType and call OverrideVirtualMethod * generator/SymbolTable.cs : make GType a ManualGen and update a few ManualGens to the new signatures. * glib/DefaultSignalHandler.cs : s/Type/System.Type * glib/ManagedValue.cs : s/uint/GLib.GType * glib/Object.cs : s/uint/GLib.GType, add OverrideVirtualMethod. * glib/Type.cs : s/uint/IntPtr, add static fields for fundamentals. make it a value type and add ==, !=, Equals, and GetHashCode. * glib/TypeConverter.cs : use new GType statics, not fundamentals. * glib/Value.cs : use new GType statics, not fundamentals. * gnome/*.custom : s/uint/GLib.GType * gtk/*Store.custom : use GType statics, not fundamentals. * sample/Subclass.cs : s/uint/GLib.GType. svn path=/trunk/gtk-sharp/; revision=21181 --- ChangeLog | 19 ++++ generator/BoxedGen.cs | 2 +- generator/ManualGen.cs | 15 ++- generator/ObjectGen.cs | 2 +- generator/Signal.cs | 4 +- generator/SymbolTable.cs | 10 +- glib/DefaultSignalHandlerAttribute.cs | 4 +- glib/ManagedValue.cs | 11 ++- glib/Object.cs | 37 ++++--- glib/Type.cs | 64 ++++++++---- glib/TypeConverter.cs | 24 ++--- glib/Value.cs | 137 +++++++++++--------------- gnome/CanvasGroup.custom | 2 +- gnome/CanvasItem.custom | 4 +- gnome/CanvasRE.custom | 2 +- gnome/CanvasShape.custom | 2 +- gtk/ListStore.custom | 12 +-- gtk/NodeStore.cs | 22 ++--- gtk/TreeStore.custom | 12 +-- sample/Subclass.cs | 10 +- 20 files changed, 212 insertions(+), 183 deletions(-) diff --git a/ChangeLog b/ChangeLog index 3530aacf3..38e13bce1 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,22 @@ +2003-12-15 Mike Kestner + + * generator/BoxedGen.cs : s/uint/GLib.GType + * generator/ManualGen.cs : add a ctor to pass ToNative handle name + * generator/ObjectGen.cs : s/uint/GLib.GType + * generator/Signal.cs : use GLib.GType and call OverrideVirtualMethod + * generator/SymbolTable.cs : make GType a ManualGen and update a few + ManualGens to the new signatures. + * glib/DefaultSignalHandler.cs : s/Type/System.Type + * glib/ManagedValue.cs : s/uint/GLib.GType + * glib/Object.cs : s/uint/GLib.GType, add OverrideVirtualMethod. + * glib/Type.cs : s/uint/IntPtr, add static fields for fundamentals. + make it a value type and add ==, !=, Equals, and GetHashCode. + * glib/TypeConverter.cs : use new GType statics, not fundamentals. + * glib/Value.cs : use new GType statics, not fundamentals. + * gnome/*.custom : s/uint/GLib.GType + * gtk/*Store.custom : use GType statics, not fundamentals. + * sample/Subclass.cs : s/uint/GLib.GType. + 2003-12-12 Mike Kestner * generator/CallbackGen.cs : kill some redundant generation diff --git a/generator/BoxedGen.cs b/generator/BoxedGen.cs index 045c1843b..09b912561 100644 --- a/generator/BoxedGen.cs +++ b/generator/BoxedGen.cs @@ -25,7 +25,7 @@ namespace GtkSharp.Generation { StreamWriter sw = gen_info.Writer = gen_info.OpenStream (Name); base.Generate (gen_info); sw.WriteLine ("\t\t[DllImport(\"gtksharpglue\")]"); - sw.WriteLine ("\t\tstatic extern IntPtr gtksharp_value_create (uint gtype);"); + sw.WriteLine ("\t\tstatic extern IntPtr gtksharp_value_create (GLib.GType gtype);"); sw.WriteLine (); sw.WriteLine ("\t\t[DllImport(\"libgobject-2.0-0.dll\")]"); sw.WriteLine ("\t\tstatic extern void g_value_set_boxed (IntPtr handle, ref " + QualifiedName + " boxed);"); diff --git a/generator/ManualGen.cs b/generator/ManualGen.cs index b4d0888bb..4edb5022b 100644 --- a/generator/ManualGen.cs +++ b/generator/ManualGen.cs @@ -10,13 +10,17 @@ namespace GtkSharp.Generation { public class ManualGen : IGeneratable { + string handle; string ctype; string type; string ns = ""; - public ManualGen (string ctype, string type) + public ManualGen (string ctype, string type) : this (ctype, type, "Handle") {} + + public ManualGen (string ctype, string type, string handle) { string[] toks = type.Split('.'); + this.handle = handle; this.ctype = ctype; this.type = toks[toks.Length - 1]; if (toks.Length > 2) @@ -25,13 +29,6 @@ namespace GtkSharp.Generation { this.ns = toks[0]; } - public ManualGen (string ctype, string ns, string type) - { - this.ns = ns; - this.ctype = ctype; - this.type = type; - } - public string CName { get { @@ -68,7 +65,7 @@ namespace GtkSharp.Generation { public string CallByName (string var_name) { - return var_name + ".Handle"; + return var_name + "." + handle; } public string FromNative(string var) diff --git a/generator/ObjectGen.cs b/generator/ObjectGen.cs index 19354eec1..e627781a1 100644 --- a/generator/ObjectGen.cs +++ b/generator/ObjectGen.cs @@ -179,7 +179,7 @@ namespace GtkSharp.Generation { gen_info.Writer.WriteLine("\t\t\tDispose();"); gen_info.Writer.WriteLine("\t\t}"); gen_info.Writer.WriteLine(); - gen_info.Writer.WriteLine("\t\tprotected " + Name + "(GLib.Type gtype) : base(gtype) {}"); + gen_info.Writer.WriteLine("\t\tprotected " + Name + "(GLib.GType gtype) : base(gtype) {}"); gen_info.Writer.WriteLine("\t\tpublic " + Name + "(IntPtr raw) : base(raw) {}"); gen_info.Writer.WriteLine(); diff --git a/generator/Signal.cs b/generator/Signal.cs index 04826c4f9..afb8a7188 100644 --- a/generator/Signal.cs +++ b/generator/Signal.cs @@ -195,11 +195,11 @@ namespace GtkSharp.Generation { sw.WriteLine ("obj.{0} ({1});", "On" + Name, call.ToString ()); sw.WriteLine ("\t\t}\n"); string cname = "\"" + elem.GetAttribute("cname") + "\""; - sw.WriteLine ("\t\tprotected static void Override" + Name + " (uint gtype)"); + sw.WriteLine ("\t\tprotected static void Override" + Name + " (GLib.GType gtype)"); sw.WriteLine ("\t\t{"); sw.WriteLine ("\t\t\tif (" + Name + "Callback == null)"); sw.WriteLine ("\t\t\t\t" + Name + "Callback = new " + Name + "Delegate (" + Name.ToLower() + "_cb);"); - sw.WriteLine ("\t\t\tgtksharp_override_virtual_method (gtype, " + cname + ", " + Name + "Callback);"); + sw.WriteLine ("\t\t\tOverrideVirtualMethod (gtype, " + cname + ", " + Name + "Callback);"); sw.WriteLine ("\t\t}\n"); } diff --git a/generator/SymbolTable.cs b/generator/SymbolTable.cs index aa4ae5528..a03df3ee8 100644 --- a/generator/SymbolTable.cs +++ b/generator/SymbolTable.cs @@ -69,7 +69,7 @@ namespace GtkSharp.Generation { AddType (new SimpleGen ("uint1", "bool")); AddType (new SimpleGen ("GC", "IntPtr")); AddType (new SimpleGen ("GPtrArray", "IntPtr[]")); - AddType (new SimpleGen ("GType", "uint")); + AddType (new ManualGen ("GType", "GLib.GType", "Val")); AddType (new SimpleGen ("GError", "IntPtr")); // gsize is a system-specific typedef in glibconfig.h, // but this should work for now @@ -89,10 +89,10 @@ namespace GtkSharp.Generation { AddType (new SimpleGen ("GParamSpec", "IntPtr")); AddType (new SimpleGen ("gconstpointer", "IntPtr")); - AddType (new ManualGen ("GSList", "GLib", "SList")); - AddType (new ManualGen ("GList", "GLib", "List")); - AddType (new ManualGen ("GValue", "GLib", "Value")); - AddType (new ManualGen ("GObject", "GLib", "Object")); + AddType (new ManualGen ("GSList", "GLib.SList")); + AddType (new ManualGen ("GList", "GLib.List")); + AddType (new ManualGen ("GValue", "GLib.Value")); + AddType (new ManualGen ("GObject", "GLib.Object")); } public void AddType (IGeneratable gen) diff --git a/glib/DefaultSignalHandlerAttribute.cs b/glib/DefaultSignalHandlerAttribute.cs index 98fbc94b2..48e0b093f 100644 --- a/glib/DefaultSignalHandlerAttribute.cs +++ b/glib/DefaultSignalHandlerAttribute.cs @@ -13,7 +13,7 @@ namespace GLib { public sealed class DefaultSignalHandlerAttribute : Attribute { private string method; - private Type type; + private System.Type type; public DefaultSignalHandlerAttribute () {} @@ -27,7 +27,7 @@ namespace GLib { } } - public Type Type + public System.Type Type { get { return type; diff --git a/glib/ManagedValue.cs b/glib/ManagedValue.cs index 1aa82311b..a07d82856 100644 --- a/glib/ManagedValue.cs +++ b/glib/ManagedValue.cs @@ -8,6 +8,7 @@ namespace GLibSharp { using System; using System.Collections; using System.Runtime.InteropServices; + using GLib; /// /// Managed types boxer @@ -37,18 +38,18 @@ namespace GLibSharp { private static IntPtr cur_ptr = IntPtr.Zero; private static CopyFunc copy; private static FreeFunc free; - private static uint boxed_type = 0; + private static GType boxed_type = GType.Invalid; [DllImport("libgobject-2.0-0.dll")] - private static extern uint g_boxed_type_register_static (string typename, CopyFunc copy_func, FreeFunc free_func); + private static extern IntPtr g_boxed_type_register_static (string typename, CopyFunc copy_func, FreeFunc free_func); - public static uint GType { + public static GType GType { get { - if (boxed_type == 0) { + if (boxed_type == GType.Invalid) { copy = new CopyFunc (Copy); free = new FreeFunc (Free); - boxed_type = g_boxed_type_register_static ("GtkSharpValue", copy, free); + boxed_type = new GLib.GType (g_boxed_type_register_static ("GtkSharpValue", copy, free)); } return boxed_type; diff --git a/glib/Object.cs b/glib/Object.cs index 3e451d235..1ad0d236b 100644 --- a/glib/Object.cs +++ b/glib/Object.cs @@ -142,7 +142,7 @@ namespace GLib { } [DllImport("gtksharpglue")] - static extern uint gtksharp_register_type (string name, uint parent_type); + static extern IntPtr gtksharp_register_type (string name, IntPtr parent_type); /// /// RegisterGType Shared Method @@ -154,18 +154,18 @@ namespace GLib { /// of subclasses. /// - public static GLib.Type RegisterGType (System.Type t) + public static GType RegisterGType (System.Type t) { System.Type parent = t.BaseType; PropertyInfo pi = parent.GetProperty ("GType", BindingFlags.DeclaredOnly | BindingFlags.Static | BindingFlags.Public); if (pi == null) { Console.WriteLine ("null PropertyInfo"); - return null; + return GType.Invalid; } - uint parent_gtype = (uint) pi.GetValue (null, null); + GType parent_gtype = (GType) pi.GetValue (null, null); string name = t.Namespace.Replace(".", "_") + t.Name; GtkSharp.ObjectManager.RegisterType (name, t.Namespace + t.Name, t.Assembly.GetName().Name); - return new GLib.Type (gtksharp_register_type (name, parent_gtype)); + return new GLib.GType (gtksharp_register_type (name, parent_gtype.Val)); } /// @@ -192,7 +192,7 @@ namespace GLib { } [DllImport("libgobject-2.0-0.dll")] - static extern IntPtr g_object_new (uint gtype, IntPtr dummy); + static extern IntPtr g_object_new (IntPtr gtype, IntPtr dummy); /// /// Object Constructor @@ -202,9 +202,9 @@ namespace GLib { /// Creates an object from a specified GType. /// - protected Object (GLib.Type gtype) + protected Object (GType gtype) { - Raw = g_object_new (gtype.Value, IntPtr.Zero); + Raw = g_object_new (gtype.Val, IntPtr.Zero); } /// @@ -237,11 +237,11 @@ namespace GLib { /// [DllImport("gtksharpglue")] - private static extern uint gtksharp_get_type_id (IntPtr obj); + private static extern IntPtr gtksharp_get_type_id (IntPtr obj); - public static uint GType { + public static GLib.GType GType { get { - return 0; + return GType.Invalid; } } @@ -262,11 +262,11 @@ namespace GLib { /// Returns the GType of this object. /// - public uint GetGType () { + public GLib.GType GetGType () { if (_obj == IntPtr.Zero) - return (uint) TypeFundamentals.TypeInvalid; - else - return gtksharp_get_type_id (_obj); + return GType.Invalid; + + return new GLib.GType (gtksharp_get_type_id (_obj)); } /// @@ -367,7 +367,12 @@ namespace GLib { } [DllImport("gtksharpglue")] - protected static extern void gtksharp_override_virtual_method (uint gtype, string name, Delegate cb); + static extern void gtksharp_override_virtual_method (IntPtr gtype, string name, Delegate cb); + + protected static void OverrideVirtualMethod (GType gtype, string name, Delegate cb) + { + gtksharp_override_virtual_method (gtype.Val, name, cb); + } [DllImport("libgobject-2.0-0.dll")] protected static extern void g_signal_chain_from_overridden (IntPtr[] args, IntPtr retval); diff --git a/glib/Type.cs b/glib/Type.cs index ed31f23e5..2cba0ccaf 100755 --- a/glib/Type.cs +++ b/glib/Type.cs @@ -1,15 +1,16 @@ -// GLib.Type.cs - GLib Type class implementation +// GLib.Type.cs - GLib GType class implementation // // Author: Mike Kestner // -// (c) 2003 Mike Kestner +// (c) 2003 Mike Kestner, Novell, Inc. namespace GLib { using System; + using System.Runtime.InteropServices; /// - /// Type Class + /// GType Class /// /// /// @@ -17,37 +18,66 @@ namespace GLib { /// to get and set properties on Objects. /// - public class Type { + [StructLayout(LayoutKind.Sequential)] + public struct GType { - uint val; + IntPtr val; /// - /// Type Constructor + /// GType Constructor /// /// /// - /// Constructs a new Type from a native GType value. + /// Constructs a new GType from a native GType value. /// - public Type (uint val) { + public GType (IntPtr val) { this.val = val; } - /// - /// Value Property - /// - /// - /// - /// Gets the native value of a Type object. - /// + public static readonly GType Invalid = new GType ((IntPtr) TypeFundamentals.TypeInvalid); + public static readonly GType None = new GType ((IntPtr) TypeFundamentals.TypeNone); + public static readonly GType String = new GType ((IntPtr) TypeFundamentals.TypeString); + public static readonly GType Boolean = new GType ((IntPtr) TypeFundamentals.TypeBoolean); + public static readonly GType Int = new GType ((IntPtr) TypeFundamentals.TypeInt); + public static readonly GType Double = new GType ((IntPtr) TypeFundamentals.TypeDouble); + public static readonly GType Float = new GType ((IntPtr) TypeFundamentals.TypeFloat); + public static readonly GType Char = new GType ((IntPtr) TypeFundamentals.TypeChar); + public static readonly GType UInt = new GType ((IntPtr) TypeFundamentals.TypeUInt); + public static readonly GType Object = new GType ((IntPtr) TypeFundamentals.TypeObject); + public static readonly GType Pointer = new GType ((IntPtr) TypeFundamentals.TypePointer); + public static readonly GType Boxed = new GType ((IntPtr) TypeFundamentals.TypeBoxed); - public uint Value { + public IntPtr Val { get { return val; } } - public override string ToString() + public override bool Equals (object o) + { + if (!(o is GType)) + return false; + + return ((GType) o) == this; + } + + public static bool operator == (GType a, GType b) + { + return a.Val == b.Val; + } + + public static bool operator != (GType a, GType b) + { + return a.Val != b.Val; + } + + public override int GetHashCode () + { + return val.GetHashCode (); + } + + public override string ToString () { return val.ToString(); } diff --git a/glib/TypeConverter.cs b/glib/TypeConverter.cs index 603baa030..e2c4b316d 100644 --- a/glib/TypeConverter.cs +++ b/glib/TypeConverter.cs @@ -20,34 +20,34 @@ namespace GLibSharp { private TypeConverter () {} - public static TypeFundamentals LookupType (System.Type type) + public static GType LookupType (System.Type type) { if (type.Equals (typeof (string))) - return TypeFundamentals.TypeString; + return GType.String; if (!type.IsValueType) { if (type.IsSubclassOf (typeof (GLib.Object))) - return TypeFundamentals.TypeObject; + return GType.Object; else if (type.IsSubclassOf (typeof (GLib.Boxed))) - return TypeFundamentals.TypeBoxed; + return GType.Boxed; else - return TypeFundamentals.TypeNone; + return GType.None; } if (type.Equals (typeof (bool))) - return TypeFundamentals.TypeBoolean; + return GType.Boolean; if (type.Equals (typeof (int))) - return TypeFundamentals.TypeInt; + return GType.Int; if (type.Equals (typeof (double))) - return TypeFundamentals.TypeDouble; + return GType.Double; if (type.Equals (typeof (float))) - return TypeFundamentals.TypeFloat; + return GType.Float; if (type.Equals (typeof (char))) - return TypeFundamentals.TypeChar; + return GType.Char; if (type.Equals (typeof (uint))) - return TypeFundamentals.TypeUInt; + return GType.UInt; - return TypeFundamentals.TypeInvalid; + return GType.Invalid; } } } diff --git a/glib/Value.cs b/glib/Value.cs index 814e2e64a..c33fe9e14 100755 --- a/glib/Value.cs +++ b/glib/Value.cs @@ -2,7 +2,7 @@ // // Author: Mike Kestner // -// (c) 2001 Mike Kestner +// (c) 2001 Mike Kestner, (c) 2003 Novell, Inc. namespace GLib { @@ -37,8 +37,8 @@ namespace GLib { public void Dispose () { if (_val != IntPtr.Zero) { - uint type = gtksharp_value_get_value_type (_val); - if (type == ManagedValue.GType) { + IntPtr rawtype = gtksharp_value_get_value_type (_val); + if (rawtype == ManagedValue.GType.Val) { ManagedValue.Free (g_value_get_boxed (_val)); } @@ -51,7 +51,7 @@ namespace GLib { // import the glue function to allocate values on heap [DllImport("gtksharpglue")] - static extern IntPtr gtksharp_value_create(uint type); + static extern IntPtr gtksharp_value_create(IntPtr type); [DllImport("gtksharpglue")] static extern IntPtr gtksharp_value_create_from_property(IntPtr obj, string name); @@ -74,7 +74,7 @@ namespace GLib { /// public Value () { - _val = gtksharp_value_create ((uint) TypeFundamentals.TypeInvalid); + _val = gtksharp_value_create (GType.Invalid.Val); } /// @@ -92,8 +92,7 @@ namespace GLib { } [DllImport("libgobject-2.0-0.dll")] - static extern void g_value_set_boolean (IntPtr val, - bool data); + static extern void g_value_set_boolean (IntPtr val, bool data); /// /// Value Constructor @@ -105,13 +104,14 @@ namespace GLib { public Value (bool val) { - _val = gtksharp_value_create((uint) TypeFundamentals.TypeBoolean); + _val = gtksharp_value_create(GType.Boolean.Val); g_value_set_boolean (_val, val); } [DllImport("libgobject-2.0-0.dll")] static extern void g_value_set_boxed (IntPtr val, IntPtr data); +/* /// /// Value Constructor /// @@ -122,7 +122,7 @@ namespace GLib { public Value (GLib.Boxed val) { - _val = gtksharp_value_create((uint) TypeFundamentals.TypeBoxed); + _val = gtksharp_value_create(GType.Boxed); //g_value_set_boxed (_val, val.Handle); } @@ -131,6 +131,7 @@ namespace GLib { _val = gtksharp_value_create_from_property (obj, prop_name); //g_value_set_boxed (_val, val.Handle); } +*/ public Value (IntPtr obj, string prop_name, Opaque val) { @@ -151,7 +152,7 @@ namespace GLib { public Value (double val) { - _val = gtksharp_value_create ((uint) TypeFundamentals.TypeDouble); + _val = gtksharp_value_create (GType.Double.Val); g_value_set_double (_val, val); } @@ -168,7 +169,7 @@ namespace GLib { public Value (float val) { - _val = gtksharp_value_create ((uint) TypeFundamentals.TypeFloat); + _val = gtksharp_value_create (GType.Float.Val); g_value_set_float (_val, val); } @@ -185,7 +186,7 @@ namespace GLib { public Value (int val) { - _val = gtksharp_value_create ((uint) TypeFundamentals.TypeInt); + _val = gtksharp_value_create (GType.Int.Val); g_value_set_int (_val, val); } @@ -202,7 +203,7 @@ namespace GLib { public Value (GLib.Object val) { - _val = gtksharp_value_create (val.GetGType ()); + _val = gtksharp_value_create (val.GetGType ().Val); g_value_set_object (_val, val.Handle); } @@ -219,7 +220,7 @@ namespace GLib { public Value (IntPtr val) { - _val = gtksharp_value_create ((uint) TypeFundamentals.TypePointer); + _val = gtksharp_value_create (GType.Pointer.Val); g_value_set_pointer (_val, val); } @@ -236,7 +237,7 @@ namespace GLib { public Value (string val) { - _val = gtksharp_value_create ((uint) TypeFundamentals.TypeString); + _val = gtksharp_value_create (GType.String.Val); g_value_set_string (_val, val); } @@ -253,7 +254,7 @@ namespace GLib { public Value (uint val) { - _val = gtksharp_value_create ((uint) TypeFundamentals.TypeUInt); + _val = gtksharp_value_create (GType.UInt.Val); g_value_set_uint (_val, val); } @@ -267,7 +268,7 @@ namespace GLib { public Value (ushort val) { - _val = gtksharp_value_create ((uint) TypeFundamentals.TypeUInt); + _val = gtksharp_value_create (GType.UInt.Val); g_value_set_uint (_val, val); } @@ -309,48 +310,37 @@ namespace GLib { public Value (object obj) { - TypeFundamentals type = TypeConverter.LookupType (obj.GetType ()); - if (type == TypeFundamentals.TypeNone) { - _val = gtksharp_value_create (ManagedValue.GType); - } else if (type == TypeFundamentals.TypeObject) { - _val = gtksharp_value_create (((GLib.Object) obj).GetGType ()); - } else if (type == TypeFundamentals.TypeInvalid) { + GType type = TypeConverter.LookupType (obj.GetType ()); + if (type == GType.None) { + _val = gtksharp_value_create (ManagedValue.GType.Val); + } else if (type == GType.Object) { + _val = gtksharp_value_create (((GLib.Object) obj).GetGType ().Val); + } else if (type == GType.Invalid) { throw new Exception ("Unknown type"); } else { - _val = gtksharp_value_create ((uint) type); + _val = gtksharp_value_create (type.Val); } - switch (type) { - case TypeFundamentals.TypeNone: + if (type == GType.None) g_value_set_boxed_take_ownership (_val, ManagedValue.WrapObject (obj)); - break; - case TypeFundamentals.TypeString: + else if (type == GType.String) g_value_set_string (_val, (string) obj); - break; - case TypeFundamentals.TypeBoolean: + else if (type == GType.Boolean) g_value_set_boolean (_val, (bool) obj); - break; - case TypeFundamentals.TypeInt: + else if (type == GType.Int) g_value_set_int (_val, (int) obj); - break; - case TypeFundamentals.TypeDouble: + else if (type == GType.Double) g_value_set_double (_val, (double) obj); - break; - case TypeFundamentals.TypeFloat: + else if (type == GType.Float) g_value_set_float (_val, (float) obj); - break; - case TypeFundamentals.TypeChar: + else if (type == GType.Char) g_value_set_char (_val, (char) obj); - break; - case TypeFundamentals.TypeUInt: + else if (type == GType.UInt) g_value_set_uint (_val, (uint) obj); - break; - case TypeFundamentals.TypeObject: + else if (type == GType.Object) g_value_set_object (_val, ((GLib.Object) obj).Handle); - break; - default: + else throw new Exception ("Unknown type"); - } } @@ -597,70 +587,57 @@ namespace GLib { } [DllImport("gtksharpglue")] - static extern uint gtksharp_value_get_value_type (IntPtr val); + static extern IntPtr gtksharp_value_get_value_type (IntPtr val); public object Val { get { - uint type = gtksharp_value_get_value_type (_val); + GLib.GType type = new GLib.GType (gtksharp_value_get_value_type (_val)); if (type == ManagedValue.GType) { return ManagedValue.ObjectForWrapper (g_value_get_boxed (_val)); } - switch ((TypeFundamentals) type) { - case TypeFundamentals.TypeString: + if (type == GType.String) return (string) this; - case TypeFundamentals.TypeBoolean: + else if (type == GType.Boolean) return (bool) this; - case TypeFundamentals.TypeInt: + else if (type == GType.Int) return (int) this; - case TypeFundamentals.TypeDouble: + else if (type == GType.Double) return (double) this; - case TypeFundamentals.TypeFloat: + else if (type == GType.Float) return (float) this; - case TypeFundamentals.TypeChar: + else if (type == GType.Char) return (char) this; - case TypeFundamentals.TypeUInt: + else if (type == GType.UInt) return (uint) this; - case TypeFundamentals.TypeObject: + else if (type == GType.Object) return (GLib.Object) this; - default: + else throw new Exception ("Unknown type"); - } } set { - GLib.TypeFundamentals type = GLibSharp.TypeConverter.LookupType (value.GetType()); - switch (type) { - case TypeFundamentals.TypeNone: + GType type = GLibSharp.TypeConverter.LookupType (value.GetType()); + if (type == GType.None) g_value_set_boxed_take_ownership (_val, ManagedValue.WrapObject (value)); - break; - case TypeFundamentals.TypeString: + else if (type == GType.String) g_value_set_string (_val, (string) value); - break; - case TypeFundamentals.TypeBoolean: + else if (type == GType.Boolean) g_value_set_boolean (_val, (bool) value); - break; - case TypeFundamentals.TypeInt: + else if (type == GType.Int) g_value_set_int (_val, (int) value); - break; - case TypeFundamentals.TypeDouble: + else if (type == GType.Double) g_value_set_double (_val, (double) value); - break; - case TypeFundamentals.TypeFloat: + else if (type == GType.Float) g_value_set_float (_val, (float) value); - break; - case TypeFundamentals.TypeChar: + else if (type == GType.Char) g_value_set_char (_val, (char) value); - break; - case TypeFundamentals.TypeUInt: + else if (type == GType.UInt) g_value_set_uint (_val, (uint) value); - break; - case TypeFundamentals.TypeObject: + else if (type == GType.Object) g_value_set_object (_val, ((GLib.Object) value).Handle); - break; - default: + else throw new Exception ("Unknown type"); - } } } diff --git a/gnome/CanvasGroup.custom b/gnome/CanvasGroup.custom index b6a8586f9..7b650d8e3 100644 --- a/gnome/CanvasGroup.custom +++ b/gnome/CanvasGroup.custom @@ -8,7 +8,7 @@ // This code is inserted after the automatically generated code. // -protected CanvasGroup (Gnome.CanvasGroup group, uint type) : base (group, type) +protected CanvasGroup (Gnome.CanvasGroup group, GLib.GType type) : base (group, type) { } diff --git a/gnome/CanvasItem.custom b/gnome/CanvasItem.custom index e4432405d..236dcce7a 100644 --- a/gnome/CanvasItem.custom +++ b/gnome/CanvasItem.custom @@ -8,12 +8,12 @@ // This code is inserted after the automatically generated code. // [DllImport("gnomecanvas-2")] - static extern System.IntPtr gnome_canvas_item_new (IntPtr group, uint type, IntPtr null_terminator); + static extern System.IntPtr gnome_canvas_item_new (IntPtr group, GLib.GType type, IntPtr null_terminator); [DllImport("libgobject-2.0-0.dll")] static extern void g_object_ref (IntPtr raw); - public CanvasItem (Gnome.CanvasGroup group, uint type) + public CanvasItem (Gnome.CanvasGroup group, GLib.GType type) : base (gnome_canvas_item_new (group.Handle, type, IntPtr.Zero)) { g_object_ref (Handle); diff --git a/gnome/CanvasRE.custom b/gnome/CanvasRE.custom index 5f679ac6e..c76d05d87 100644 --- a/gnome/CanvasRE.custom +++ b/gnome/CanvasRE.custom @@ -8,7 +8,7 @@ // This code is inserted after the automatically generated code. // -protected CanvasRE (Gnome.CanvasGroup group, uint type) : base (group, type) +protected CanvasRE (Gnome.CanvasGroup group, GLib.GType type) : base (group, type) { } diff --git a/gnome/CanvasShape.custom b/gnome/CanvasShape.custom index ac0f1f2d2..d1922082c 100644 --- a/gnome/CanvasShape.custom +++ b/gnome/CanvasShape.custom @@ -8,7 +8,7 @@ // This code is inserted after the automatically generated code. // -protected CanvasShape (Gnome.CanvasGroup group, uint type) : base (group, type) +protected CanvasShape (Gnome.CanvasGroup group, GLib.GType type) : base (group, type) { } diff --git a/gtk/ListStore.custom b/gtk/ListStore.custom index 40f66c506..98c8cdfe1 100644 --- a/gtk/ListStore.custom +++ b/gtk/ListStore.custom @@ -83,16 +83,16 @@ public ListStore (params Type[] types) { - uint[] ctypes = new uint[types.Length]; + IntPtr[] ctypes = new IntPtr[types.Length]; int i = 0; foreach (Type type in types) { - GLib.TypeFundamentals ctype = GLibSharp.TypeConverter.LookupType (type); - if (ctype == GLib.TypeFundamentals.TypeNone) { - ctypes[i] = GLibSharp.ManagedValue.GType; - } else if (ctype == GLib.TypeFundamentals.TypeInvalid) { + GLib.GType ctype = GLibSharp.TypeConverter.LookupType (type); + if (ctype == GLib.GType.None) { + ctypes[i] = GLibSharp.ManagedValue.GType.Val; + } else if (ctype == GLib.GType.Invalid) { throw new Exception ("Unknown type"); } else { - ctypes[i] = (uint) ctype; + ctypes[i] = ctype.Val; } i++; } diff --git a/gtk/NodeStore.cs b/gtk/NodeStore.cs index c1777c97d..eeb665ff5 100644 --- a/gtk/NodeStore.cs +++ b/gtk/NodeStore.cs @@ -36,7 +36,7 @@ namespace Gtk { delegate int GetFlagsDelegate (); delegate int GetNColumnsDelegate (); - delegate uint GetColumnTypeDelegate (int col); + delegate IntPtr GetColumnTypeDelegate (int col); delegate bool GetNodeDelegate (out int node_idx, IntPtr path); delegate IntPtr GetPathDelegate (int node_idx); delegate void GetValueDelegate (int node_idx, int col, IntPtr val); @@ -65,7 +65,7 @@ namespace Gtk { int stamp; Hashtable node_hash = new IDHashtable (); - uint[] ctypes; + GLib.GType[] ctypes; PropertyInfo[] getters; int n_cols = 1; ArrayList nodes = new ArrayList (); @@ -81,9 +81,9 @@ namespace Gtk { return n_cols; } - uint get_column_type_cb (int col) + IntPtr get_column_type_cb (int col) { - return ctypes [col]; + return ctypes [col].Val; } bool get_node_cb (out int node_idx, IntPtr path) @@ -124,7 +124,7 @@ namespace Gtk { } [DllImport("libgobject-2.0-0.dll")] - static extern void g_value_init (IntPtr handle, uint type); + static extern void g_value_init (IntPtr handle, IntPtr type); void get_value_cb (int node_idx, int col, IntPtr val) { @@ -132,7 +132,7 @@ namespace Gtk { ITreeNode node = node_hash [node_idx] as ITreeNode; if (node == null) return; - g_value_init (gval.Handle, ctypes [col]); + g_value_init (gval.Handle, ctypes [col].Val); object col_val = getters[col].GetValue (node, null); gval.Val = col_val; } @@ -292,7 +292,7 @@ namespace Gtk { } } - ctypes = new uint [n_cols]; + ctypes = new GLib.GType [n_cols]; getters = new PropertyInfo [n_cols]; MemberInfo[] info = type.GetMembers (); @@ -306,13 +306,13 @@ namespace Gtk { int col = tnva.Column; pi = mi as PropertyInfo; getters [col] = pi; - GLib.TypeFundamentals ctype = GLibSharp.TypeConverter.LookupType (pi.PropertyType); - if (ctype == GLib.TypeFundamentals.TypeNone) { + GLib.GType ctype = GLibSharp.TypeConverter.LookupType (pi.PropertyType); + if (ctype == GLib.GType.None) { ctypes[col] = GLibSharp.ManagedValue.GType; - } else if (ctype == GLib.TypeFundamentals.TypeInvalid) { + } else if (ctype == GLib.GType.Invalid) { throw new Exception ("Unknown type"); } else { - ctypes[col] = (uint) ctype; + ctypes[col] = ctype; } break; default: diff --git a/gtk/TreeStore.custom b/gtk/TreeStore.custom index 843115938..1259e5d84 100644 --- a/gtk/TreeStore.custom +++ b/gtk/TreeStore.custom @@ -171,16 +171,16 @@ public TreeStore (params Type[] types) { - uint[] ctypes = new uint[types.Length]; + IntPtr[] ctypes = new IntPtr[types.Length]; int i = 0; foreach (Type type in types) { - GLib.TypeFundamentals ctype = GLibSharp.TypeConverter.LookupType (type); - if (ctype == GLib.TypeFundamentals.TypeNone) { - ctypes[i] = GLibSharp.ManagedValue.GType; - } else if (ctype == GLib.TypeFundamentals.TypeInvalid) { + GLib.GType ctype = GLibSharp.TypeConverter.LookupType (type); + if (ctype == GLib.GType.None) { + ctypes[i] = GLibSharp.ManagedValue.GType.Val; + } else if (ctype == GLib.GType.Invalid) { throw new Exception ("Unknown type"); } else { - ctypes[i] = (uint) ctype; + ctypes[i] = ctype.Val; } i++; } diff --git a/sample/Subclass.cs b/sample/Subclass.cs index 0c173cab7..330a7af4b 100755 --- a/sample/Subclass.cs +++ b/sample/Subclass.cs @@ -43,14 +43,14 @@ namespace GtkSamples { public class MyButton : Gtk.Button { - static uint gtype = 0; + static GLib.GType gtype = GLib.GType.Invalid; - public MyButton () : base (new GLib.Type (GType)) {} + public MyButton () : base (GType) {} - public static new uint GType { + public static new GLib.GType GType { get { - if (gtype == 0) - gtype = RegisterGType (typeof (MyButton)).Value; + if (gtype == GLib.GType.Invalid) + gtype = RegisterGType (typeof (MyButton)); return gtype; } }