diff --git a/ChangeLog b/ChangeLog index 9b70e03c1..101f772da 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,60 @@ +2005-05-04 Dan Winship + + * parser/gapi2xml.pl: make note of _get_type methods for enums + + * */*-api.xml: Regen, adding gtype="..." to many enum types + + * generator/EnumGen.cs (Generate): if the enum has the + "gtype" property, add a GTypeAttribute pointing to an internal + FooGType class whose GType property can be used to get the enum's + GType. + + * generator/ObjectGen.cs: + s/ObjectManager.RegisterType/GType.Register/ + + * glib/GTypeAttribute.cs: attribute for indicating a property that + will return the GType of a type (particularly for enums, which + can't have GType properties added to them). + + * glib/GType.cs: renamed from Type.cs to match the type name + (public static readonly GType ...): add a few missing types. + (Register): moved from ObjectManager.RegisterType + (LookupGType): moved from TypeConverter.LookupType and extended to + handle GTypeAttribute. Also, fix mappings for sbyte/byte/char, and + return specific GTypes for Object subclasses rather than always + returning GType.Object. [Fixes #74699] + (LookupType): moved from ObjectWrapper.LookupType + (ToString): return the type name + + * glib/Object.cs (RegisterGType): + s/ObjectManager.Register/GType.Register/ + (LookupGType): Make this protected internal so GType can access + it. + + * glib/ObjectManager.cs (RegisterType): deprecate in favor of + GType.Register. + (LookupType): moved to GType + + * glib/TypeConverter.cs (LookupType): now a deprecated wrapper + around GType.LookupGType. + + * glib/Value.cs: Use GType casts rather than TypeConverter + + * gtk/NodeStore.cs (ScanType): + * gtk/ListStore.custom (ListStore): + * gtk/TreeStore.custom (TreeStore): Use (GType) cast rather than + TypeConverter. Remove the error check and exception, since the + cast never returns GType.Invalid. (The check probably predates + GLib.ManagedValue.) + + * gnome/PanelAppletFactory.cs (Register): Use a GType cast rather + than GLib.Object.LookupGType (which is no longer accessible after + an mcs bugfix) + + * sample/GtkDemo/DemoIconView.cs (CreateStore): use the Type[] + constructor rather than the GType[] constructor, since it + translates typeof(Gdk.Pixbuf) correctly now. + 2005-05-04 Dan Winship * generator/Parameters.cs (Parameters.Validate): If the parameters diff --git a/atk/atk-api.raw b/atk/atk-api.raw index a0cecd69e..e8751ece3 100644 --- a/atk/atk-api.raw +++ b/atk/atk-api.raw @@ -7,19 +7,19 @@ --> - + - + - + - + @@ -29,7 +29,7 @@ - + @@ -46,7 +46,7 @@ - + @@ -126,7 +126,7 @@ - + @@ -161,7 +161,7 @@ - + @@ -192,7 +192,7 @@ - + @@ -201,7 +201,7 @@ - + diff --git a/doc/ChangeLog b/doc/ChangeLog index ab57970d4..311f619e4 100644 --- a/doc/ChangeLog +++ b/doc/ChangeLog @@ -1,3 +1,10 @@ +2005-05-04 Dan Winship + + * en/GLib/GType.xml: update, and remove a bunch of examples of how + not to derive types any more... + + * en/GLib/GTypeAttribute.xml: add + 2005-05-04 Dan Winship * updater/updater.cs (GetFieldVisibility, GetMethodVisibility): diff --git a/doc/en/GLib/GType.xml b/doc/en/GLib/GType.xml index 96629fd45..304256a05 100644 --- a/doc/en/GLib/GType.xml +++ b/doc/en/GLib/GType.xml @@ -10,42 +10,8 @@ - The GLib Runtime type identification and management system. The GType API is the foundation of the GObject system. It provides the facilities for registering and managing all fundamental data types, user-defined object and interface types. - - - -using System; -using Gtk; - -public class MagrittesWindow : Window { - static GLib.GType gtype; - Button button; - - public static new GLib.GType GType - { - get - { - if (gtype == GLib.GType.Invalid) - gtype = RegisterGType (typeof (MagrittesWindow)); - return gtype; - } - } - - public MagrittesWindow() : base (GType) - { - button = new Button("This is not a button"); - button.Clicked += new EventHandler(button_Clicked); - - this.Title = "This is not a Window"; - this.SetDefaultSize (400, 300); - this.DeleteEvent += new DeleteEventHandler (MagrittesWindow_Delete); - this.Add(button); - this.ShowAll (); - } - /* elided for brevity */ - - - + The GLib Runtime type identification and management system. The GType API is the foundation of the GObject system. It provides the facilities for registering and managing all fundamental data types, user-defined object and interface types. + System.ValueType @@ -62,28 +28,8 @@ public class MagrittesWindow : Window { - A field of type GType.Invalid - - - - - public class MyWindow : Window { - static GLib.GType gtype; - Button button; - - public static new GLib.GType GType - { - get - { - if (gtype == GLib.GType.Invalid) - gtype = RegisterGType (typeof (MyWindow)); - return gtype; - } - } -/* Rest elided for clarity */ - - - + An invalid . + @@ -95,8 +41,8 @@ public class MagrittesWindow : Window { - A field of type GType.None - Sample see: GLib.GType.Invalid. + A corresponding to . + @@ -108,8 +54,8 @@ public class MagrittesWindow : Window { - A field of type GType.String - Sample see: GLib.GType.Invalid. + The for values. + @@ -121,8 +67,8 @@ public class MagrittesWindow : Window { - A field of type GType.Boolean. - Sample see: GLib.GType.Invalid. + The for values. + @@ -134,8 +80,8 @@ public class MagrittesWindow : Window { - A field of type GType.Int - Sample see: GLib.GType.Invalid. + The for values. + @@ -147,8 +93,8 @@ public class MagrittesWindow : Window { - A field of type GType.Double - Sample see: GLib.GType.Invalid. + The for values. + @@ -160,8 +106,8 @@ public class MagrittesWindow : Window { - A field of type GType.Float - Sample see: GLib.GType.Invalid. + The for values. + @@ -173,8 +119,8 @@ public class MagrittesWindow : Window { - A field of type GType.Char - Sample see: GLib.GType.Invalid. + The for values. + @@ -186,8 +132,8 @@ public class MagrittesWindow : Window { - A field of type GType.UInt - Sample see: GLib.GType.Invalid. + The for values. + @@ -199,8 +145,8 @@ public class MagrittesWindow : Window { - A field of type GType.Object - Sample see: GLib.GType.Invalid. + The for values. + @@ -212,8 +158,8 @@ public class MagrittesWindow : Window { - A field of type GType.Pointer - Sample see: GLib.GType.Invalid. + The for pointer values. + @@ -225,8 +171,86 @@ public class MagrittesWindow : Window { - A field of type GType.Boxed - Sample see: GLib.GType.Invalid. + The for "boxed" struct values. + + + + + + Field + + GLib.GType + + + + + The for values. + + + + + + Field + + GLib.GType + + + + + The for values. + + + + + + Field + + GLib.GType + + + + + The for unmanaged interface values. + + + + + + Field + + GLib.GType + + + + + The for values. + + + + + + Field + + GLib.GType + + + + + The for GType-registered enum values. + + + + + + Field + + GLib.GType + + + + + The for GType-registered flag values. + @@ -317,31 +341,38 @@ public class MagrittesWindow : Window { - - - Field + + + Method - GLib.GType + System.Void + + - 64 bit integer type. + Registers a to mapping. + a + a - - - Field + + + Method - GLib.GType + System.Type + - 64 bit unsigned integer type. + Looks up the corresponding to an unmanaged GType + a + a - + \ No newline at end of file diff --git a/doc/en/GLib/GTypeAttribute.xml b/doc/en/GLib/GTypeAttribute.xml new file mode 100644 index 000000000..7eb5f2b64 --- /dev/null +++ b/doc/en/GLib/GTypeAttribute.xml @@ -0,0 +1,53 @@ + + + + glib-sharp + [00 24 00 00 04 80 00 00 94 00 00 00 06 02 00 00 00 24 00 00 52 53 41 31 00 04 00 00 01 00 01 00 71 EB 6C 55 75 52 9C BF 72 44 F7 A6 EA 05 62 84 F9 EA E0 3B CF F2 CC 13 2C 9C 49 0A B3 09 EA B0 B5 6B CE 44 9D F5 03 D9 C0 A8 1E 52 05 85 CD BE 70 E2 FB 90 43 4B AC 04 FA 62 22 A8 00 98 B7 A1 A7 B3 AF 99 1A 41 23 24 BB 43 25 F6 B8 65 BB 64 EB F6 D1 C2 06 D5 73 2D DF BC 70 A7 38 9E E5 3E 0C 24 6E 32 79 74 1A D0 05 03 E4 98 42 E1 9B F3 7B 19 8B 40 21 26 CB 36 89 C2 EA 64 96 A4 7C B4] + 2.0.0.0 + neutral + + + Gtk# is thread aware, but not thread safe; See the Gtk# Thread Programming for details. + + Identifies a property that can be read to find the GType of a managed type + + + + System.Attribute + + + + + System.AttributeUsageAttribute + + + + + + Constructor + + + + + + Creates an attribute. + the containing the GType property + a + + + + + + Property + + System.Type + + + + The class containing the GType property + a + + + + + \ No newline at end of file diff --git a/doc/en/GLib/ObjectManager.xml b/doc/en/GLib/ObjectManager.xml index 1e2bd77e3..c548f5ea1 100644 --- a/doc/en/GLib/ObjectManager.xml +++ b/doc/en/GLib/ObjectManager.xml @@ -93,7 +93,7 @@ - Registers a GType to System.Type mapping. + Obsolete. Replaced by . a a diff --git a/doc/en/GLib/TypeConverter.xml b/doc/en/GLib/TypeConverter.xml index 9e13db6bb..30c25c01a 100644 --- a/doc/en/GLib/TypeConverter.xml +++ b/doc/en/GLib/TypeConverter.xml @@ -29,10 +29,10 @@ - To be added + Obsolete: Replaced by cast. a a - To be added + diff --git a/gdk/gdk-api.raw b/gdk/gdk-api.raw index 03bb22935..328ada1bb 100644 --- a/gdk/gdk-api.raw +++ b/gdk/gdk-api.raw @@ -7,7 +7,7 @@ --> - + @@ -17,22 +17,22 @@ - + - + - + - + @@ -113,7 +113,7 @@ - + @@ -121,7 +121,7 @@ - + @@ -130,7 +130,7 @@ - + @@ -154,7 +154,7 @@ - + @@ -192,31 +192,31 @@ - + - + - + - + - + - + @@ -254,14 +254,14 @@ - + - + @@ -273,38 +273,38 @@ - + - + - + - + - + - + - + @@ -321,7 +321,7 @@ - + @@ -329,58 +329,58 @@ - + - + - + - + - + - + - + - + - + - + - + @@ -405,7 +405,7 @@ - + @@ -415,11 +415,11 @@ - + - + @@ -429,7 +429,7 @@ - + @@ -440,7 +440,7 @@ - + @@ -449,7 +449,7 @@ - + @@ -457,7 +457,7 @@ - + @@ -4593,20 +4593,20 @@ - + - + - + - + @@ -4619,7 +4619,7 @@ - + diff --git a/generator/EnumGen.cs b/generator/EnumGen.cs index b075f36f8..0151cbd9d 100644 --- a/generator/EnumGen.cs +++ b/generator/EnumGen.cs @@ -74,15 +74,16 @@ namespace GtkSharp.Generation { sw.WriteLine ("namespace " + NS + " {"); sw.WriteLine (); sw.WriteLine ("\tusing System;"); + sw.WriteLine ("\tusing System.Runtime.InteropServices;"); sw.WriteLine (); - if (Elem.GetAttribute("type") == "flags") { - sw.WriteLine (); - sw.WriteLine ("\t[Flags]"); - } - sw.WriteLine ("#region Autogenerated code"); + if (Elem.GetAttribute("type") == "flags") + sw.WriteLine ("\t[Flags]"); + if (Elem.HasAttribute("gtype")) + sw.WriteLine ("\t[GLib.GType (typeof (" + NS + "." + Name + "GType))]"); + sw.WriteLine ("\tpublic enum " + Name + enum_type + " {"); sw.WriteLine (); @@ -90,12 +91,26 @@ namespace GtkSharp.Generation { sw.WriteLine (member); sw.WriteLine ("\t}"); + + if (Elem.HasAttribute ("gtype")) { + sw.WriteLine (); + sw.WriteLine ("\tinternal class " + Name + "GType {"); + sw.WriteLine ("\t\t[DllImport (\"" + LibraryName + "\")]"); + sw.WriteLine ("\t\tstatic extern IntPtr " + Elem.GetAttribute ("gtype") + " ();"); + sw.WriteLine (); + sw.WriteLine ("\t\tpublic static GLib.GType GType {"); + sw.WriteLine ("\t\t\tget {"); + sw.WriteLine ("\t\t\t\treturn new GLib.GType (" + Elem.GetAttribute ("gtype") + " ());"); + sw.WriteLine ("\t\t\t}"); + sw.WriteLine ("\t\t}"); + sw.WriteLine ("\t}"); + } + sw.WriteLine ("#endregion"); sw.WriteLine ("}"); sw.Close (); Statistics.EnumCount++; } - } } diff --git a/generator/ObjectGen.cs b/generator/ObjectGen.cs index 55ccb68d9..b8c1e83ea 100644 --- a/generator/ObjectGen.cs +++ b/generator/ObjectGen.cs @@ -324,7 +324,7 @@ namespace GtkSharp.Generation { } } - /* Keep this in sync with the one in glib/ObjectManager.cs */ + /* Keep this in sync with the one in glib/GType.cs */ private static string GetExpected (string cname) { for (int i = 1; i < cname.Length; i++) { @@ -393,7 +393,7 @@ namespace GtkSharp.Generation { foreach (string key in dir_info.objects.Keys) { if (GetExpected(key) != ((string) dir_info.objects[key])) - sw.WriteLine ("\t\t\tGLib.ObjectManager.RegisterType({0}.GType, typeof ({0}));", dir_info.objects [key]); + sw.WriteLine ("\t\t\tGLib.GType.Register ({0}.GType, typeof ({0}));", dir_info.objects [key]); } sw.WriteLine ("\t\t}"); diff --git a/glib/GType.cs b/glib/GType.cs new file mode 100755 index 000000000..5f598d5ee --- /dev/null +++ b/glib/GType.cs @@ -0,0 +1,191 @@ +// GLib.Type.cs - GLib GType class implementation +// +// Author: Mike Kestner +// +// Copyright (c) 2003 Mike Kestner +// Copyright (c) 2003 Novell, Inc. +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of version 2 of the Lesser GNU General +// Public License as published by the Free Software Foundation. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the +// Free Software Foundation, Inc., 59 Temple Place - Suite 330, +// Boston, MA 02111-1307, USA. + + +namespace GLib { + + using System; + using System.Collections; + using System.Reflection; + using System.Runtime.InteropServices; + + [StructLayout(LayoutKind.Sequential)] + public struct GType { + + IntPtr val; + + public GType (IntPtr val) + { + this.val = val; + } + + public static readonly GType Invalid = new GType ((IntPtr) TypeFundamentals.TypeInvalid); + public static readonly GType None = new GType ((IntPtr) TypeFundamentals.TypeNone); + public static readonly GType Interface = new GType ((IntPtr) TypeFundamentals.TypeInterface); + public static readonly GType Char = new GType ((IntPtr) TypeFundamentals.TypeChar); + public static readonly GType UChar = new GType ((IntPtr) TypeFundamentals.TypeUChar); + public static readonly GType Boolean = new GType ((IntPtr) TypeFundamentals.TypeBoolean); + public static readonly GType Int = new GType ((IntPtr) TypeFundamentals.TypeInt); + public static readonly GType UInt = new GType ((IntPtr) TypeFundamentals.TypeUInt); + public static readonly GType Int64 = new GType ((IntPtr) TypeFundamentals.TypeInt64); + public static readonly GType UInt64 = new GType ((IntPtr) TypeFundamentals.TypeUInt64); + public static readonly GType Enum = new GType ((IntPtr) TypeFundamentals.TypeEnum); + public static readonly GType Flags = new GType ((IntPtr) TypeFundamentals.TypeFlags); + public static readonly GType Float = new GType ((IntPtr) TypeFundamentals.TypeFloat); + public static readonly GType Double = new GType ((IntPtr) TypeFundamentals.TypeDouble); + public static readonly GType String = new GType ((IntPtr) TypeFundamentals.TypeString); + public static readonly GType Pointer = new GType ((IntPtr) TypeFundamentals.TypePointer); + public static readonly GType Boxed = new GType ((IntPtr) TypeFundamentals.TypeBoxed); + public static readonly GType Object = new GType ((IntPtr) TypeFundamentals.TypeObject); + + static Hashtable types = new Hashtable (); + static Hashtable gtypes = new Hashtable (); + + public static void Register (GType native_type, System.Type type) + { + if (native_type != GType.Pointer && native_type != GType.Boxed && native_type != ManagedValue.GType) + types[native_type.Val] = type; + if (type != null) + gtypes[type] = native_type; + } + + static GType () + { + Register (GType.Char, typeof (sbyte)); + Register (GType.UChar, typeof (byte)); + Register (GType.Boolean, typeof (bool)); + Register (GType.Int, typeof (int)); + Register (GType.UInt, typeof (uint)); + Register (GType.Int64, typeof (long)); + Register (GType.UInt64, typeof (ulong)); + Register (GType.Float, typeof (float)); + Register (GType.Double, typeof (double)); + Register (GType.String, typeof (string)); + Register (GType.Object, typeof (GLib.Object)); + + // One-way mapping + gtypes[typeof (char)] = GType.UInt; + } + + public static explicit operator GType (System.Type type) + { + GType gtype; + + if (gtypes.Contains (type)) + return (GType)gtypes[type]; + + if (type.IsSubclassOf (typeof (GLib.Object))) { + gtype = GLib.Object.LookupGType (type); + Register (gtype, type); + return gtype; + } + + PropertyInfo pi = type.GetProperty ("GType", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.FlattenHierarchy); + if (pi != null) + gtype = (GType) pi.GetValue (null, null); + else if (type.IsDefined (typeof (GTypeAttribute), false)) { + GTypeAttribute gattr = (GTypeAttribute)Attribute.GetCustomAttribute (type, typeof (GTypeAttribute), false); + pi = gattr.WrapperType.GetProperty ("GType", BindingFlags.Public | BindingFlags.Static); + gtype = (GType) pi.GetValue (null, null); + } else if (type.IsSubclassOf (typeof (GLib.Opaque))) + gtype = GType.Pointer; + else + gtype = ManagedValue.GType; + + Register (gtype, type); + return gtype; + } + + static string GetQualifiedName (string cname) + { + for (int i = 1; i < cname.Length; i++) { + if (System.Char.IsUpper (cname[i])) { + if (i == 1 && cname [0] == 'G') + return "GLib." + cname.Substring (1); + else + return cname.Substring (0, i) + "." + cname.Substring (i); + } + } + + throw new ArgumentException ("cname is not in NamespaceType format. GType.Register should be called directly for " + cname); + } + + public static explicit operator Type (GType gtype) + { + return LookupType (gtype.Val); + } + + public static Type LookupType (IntPtr typeid) + { + if (types.Contains (typeid)) + return (Type)types[typeid]; + + string native_name = Marshaller.Utf8PtrToString (g_type_name (typeid)); + string type_name = GetQualifiedName (native_name); + Type result = null; + foreach (Assembly asm in AppDomain.CurrentDomain.GetAssemblies ()) { + result = asm.GetType (type_name); + if (result != null) + break; + } + + Register (new GType (typeid), result); + return result; + } + + public IntPtr Val { + get { + return val; + } + } + + 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 (); + } + + [DllImport("libgobject-2.0-0.dll")] + static extern IntPtr g_type_name (IntPtr raw); + + public override string ToString () + { + return Marshaller.Utf8PtrToString (g_type_name (val)); + } + } +} diff --git a/glib/GTypeAttribute.cs b/glib/GTypeAttribute.cs new file mode 100644 index 000000000..7a2e14f00 --- /dev/null +++ b/glib/GTypeAttribute.cs @@ -0,0 +1,42 @@ +// GTypeAttribute.cs +// +// Copyright (c) 2005 Novell, Inc. +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of version 2 of the Lesser GNU General +// Public License as published by the Free Software Foundation. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the +// Free Software Foundation, Inc., 59 Temple Place - Suite 330, +// Boston, MA 02111-1307, USA. + + +namespace GLib { + + using System; + + [AttributeUsage (AttributeTargets.Enum)] + public sealed class GTypeAttribute : Attribute { + Type wrapper_type; + + public GTypeAttribute (Type wrapper_type) + { + this.wrapper_type = wrapper_type; + } + + public Type WrapperType { + get { + return wrapper_type; + } + set { + wrapper_type = value; + } + } + } +} diff --git a/glib/Makefile.am b/glib/Makefile.am index 74c768f1e..fe5e6db3e 100644 --- a/glib/Makefile.am +++ b/glib/Makefile.am @@ -22,6 +22,8 @@ sources = \ FileUtils.cs \ GException.cs \ GString.cs \ + GType.cs \ + GTypeAttribute.cs \ Idle.cs \ IWrapper.cs \ ListBase.cs \ @@ -47,7 +49,6 @@ sources = \ Thread.cs \ Timeout.cs \ TypeConverter.cs \ - Type.cs \ TypeFundamentals.cs \ UnwrappedObject.cs \ ValueArray.cs \ diff --git a/glib/Object.cs b/glib/Object.cs index 02d793485..e9152c8a7 100644 --- a/glib/Object.cs +++ b/glib/Object.cs @@ -156,7 +156,7 @@ namespace GLib { IntPtr native_name = GLib.Marshaller.StringToPtrGStrdup (name); GType gtype = new GType (gtksharp_register_type (native_name, parent_gtype.Val)); GLib.Marshaller.Free (native_name); - GLib.ObjectManager.RegisterType (gtype, t); + GLib.GType.Register (gtype, t); ConnectDefaultHandlers (gtype, t); InvokeClassInitializers (gtype, t); g_types[t] = gtype; @@ -171,7 +171,7 @@ namespace GLib { return LookupGType (GetType ()); } - protected static GType LookupGType (System.Type t) + protected internal static GType LookupGType (System.Type t) { if (g_types.Contains (t)) return (GType) g_types [t]; diff --git a/glib/ObjectManager.cs b/glib/ObjectManager.cs index 673b65a89..8cb91582f 100644 --- a/glib/ObjectManager.cs +++ b/glib/ObjectManager.cs @@ -23,15 +23,11 @@ namespace GLib { using System; - using System.Collections; using System.Runtime.InteropServices; using System.Reflection; - using System.Text; public class ObjectManager { - private static Hashtable types = new Hashtable (); - static BindingFlags flags = BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance | BindingFlags.CreateInstance; public static GLib.Object CreateObject (IntPtr raw) @@ -53,76 +49,45 @@ namespace GLib { return obj; } - [Obsolete ("Use the (GType, Type) overload instead")] + [Obsolete ("Replaced by GType.Register (GType, Type)")] public static void RegisterType (string native_name, string managed_name, string assembly) { RegisterType (native_name, managed_name + "," + assembly); } - [Obsolete ("Use the (GType, Type) overload instead")] + [Obsolete ("Replaced by GType.Register (GType, Type)")] public static void RegisterType (string native_name, string mangled) { - types [native_name] = mangled; + RegisterType (new GType (g_type_from_name (native_name)), Type.GetType (mangled)); } + [Obsolete ("Replaced by GType.Register (GType, Type)")] public static void RegisterType (GType native_type, System.Type type) { - types [native_type.Val] = type; - } - - static string GetQualifiedName (string cname) - { - for (int i = 1; i < cname.Length; i++) { - if (Char.IsUpper (cname[i])) { - if (i == 1 && cname [0] == 'G') - return "GLib." + cname.Substring (1); - else - return cname.Substring (0, i) + "." + cname.Substring (i); - } - } - - throw new ArgumentException ("cname is not in NamespaceType format. RegisterType should be called directly for " + cname); + GType.Register (native_type, type); } static Type GetTypeOrParent (IntPtr obj) { IntPtr typeid = gtksharp_get_type_id (obj); - Type result = LookupType (typeid); + Type result = GType.LookupType (typeid); while (result == null) { - typeid = gtksharp_get_parent_type (typeid); + typeid = g_type_parent (typeid); if (typeid == IntPtr.Zero) return null; - result = LookupType (typeid); + result = GType.LookupType (typeid); } return result; } - static Type LookupType (IntPtr typeid) - { - if (types.Contains (typeid)) - return types [typeid] as Type; - - string native_name = Marshaller.Utf8PtrToString (gtksharp_get_type_name_for_id (typeid)); - string type_name = GetQualifiedName (native_name); - Type result = null; - foreach (Assembly asm in AppDomain.CurrentDomain.GetAssemblies ()) { - result = asm.GetType (type_name); - if (result != null) - break; - } - - types [typeid] = result; - return result; - } - [DllImport("glibsharpglue-2")] static extern IntPtr gtksharp_get_type_id (IntPtr raw); - [DllImport("glibsharpglue-2")] - static extern IntPtr gtksharp_get_parent_type (IntPtr typ); + [DllImport("libgobject-2.0-0.dll")] + static extern IntPtr g_type_parent (IntPtr typ); - [DllImport("glibsharpglue-2")] - static extern IntPtr gtksharp_get_type_name_for_id (IntPtr typ); + [DllImport("libgobject-2.0-0.dll")] + static extern IntPtr g_type_from_name (string name); } } diff --git a/glib/Type.cs b/glib/Type.cs deleted file mode 100755 index 9c12d3a00..000000000 --- a/glib/Type.cs +++ /dev/null @@ -1,86 +0,0 @@ -// GLib.Type.cs - GLib GType class implementation -// -// Author: Mike Kestner -// -// Copyright (c) 2003 Mike Kestner -// Copyright (c) 2003 Novell, Inc. -// -// This program is free software; you can redistribute it and/or -// modify it under the terms of version 2 of the Lesser GNU General -// Public License as published by the Free Software Foundation. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -// Lesser General Public License for more details. -// -// You should have received a copy of the GNU Lesser General Public -// License along with this program; if not, write to the -// Free Software Foundation, Inc., 59 Temple Place - Suite 330, -// Boston, MA 02111-1307, USA. - - -namespace GLib { - - using System; - using System.Runtime.InteropServices; - - [StructLayout(LayoutKind.Sequential)] - public struct GType { - - IntPtr val; - - public GType (IntPtr val) { - this.val = val; - } - - public static readonly GType Invalid = new GType ((IntPtr) TypeFundamentals.TypeInvalid); - public static readonly GType None = new GType ((IntPtr) TypeFundamentals.TypeNone); - public static readonly GType Char = new GType ((IntPtr) TypeFundamentals.TypeChar); - public static readonly GType Boolean = new GType ((IntPtr) TypeFundamentals.TypeBoolean); - public static readonly GType Int = new GType ((IntPtr) TypeFundamentals.TypeInt); - public static readonly GType UInt = new GType ((IntPtr) TypeFundamentals.TypeUInt); - public static readonly GType Int64 = new GType ((IntPtr) TypeFundamentals.TypeInt64); - public static readonly GType UInt64 = new GType ((IntPtr) TypeFundamentals.TypeUInt64); - public static readonly GType Float = new GType ((IntPtr) TypeFundamentals.TypeFloat); - public static readonly GType Double = new GType ((IntPtr) TypeFundamentals.TypeDouble); - public static readonly GType String = new GType ((IntPtr) TypeFundamentals.TypeString); - public static readonly GType Pointer = new GType ((IntPtr) TypeFundamentals.TypePointer); - public static readonly GType Boxed = new GType ((IntPtr) TypeFundamentals.TypeBoxed); - public static readonly GType Object = new GType ((IntPtr) TypeFundamentals.TypeObject); - - public IntPtr Val { - get { - return val; - } - } - - 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 dc65b3486..0115d9d1e 100644 --- a/glib/TypeConverter.cs +++ b/glib/TypeConverter.cs @@ -21,42 +21,15 @@ namespace GLib { using System; - using System.Collections; - using System.Reflection; public class TypeConverter { private TypeConverter () {} + [Obsolete ("Replaced by explicit (GType) cast")] public static GType LookupType (System.Type type) { - if (type.Equals (typeof (char))) - return GType.Char; - if (type.Equals (typeof (bool))) - return GType.Boolean; - if (type.Equals (typeof (int))) - return GType.Int; - if (type.Equals (typeof (uint))) - return GType.UInt; - if (type.Equals (typeof (long))) - return GType.Int64; - if (type.Equals (typeof (ulong))) - return GType.UInt64; - if (type.Equals (typeof (float))) - return GType.Float; - if (type.Equals (typeof (double))) - return GType.Double; - if (type.Equals (typeof (string))) - return GType.String; - if (type.IsSubclassOf (typeof (GLib.Object))) - return GType.Object; - PropertyInfo pi = type.GetProperty ("GType", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.FlattenHierarchy); - if (pi != null) - return (GType) pi.GetValue (null, null); - if (type.IsSubclassOf (typeof (GLib.Opaque))) - return GType.Pointer; - - return ManagedValue.GType; + return (GType) type; } } } diff --git a/glib/Value.cs b/glib/Value.cs index 3984063b0..2380e081a 100755 --- a/glib/Value.cs +++ b/glib/Value.cs @@ -47,13 +47,8 @@ namespace GLib { type = IntPtr.Zero; pad_1 = pad_2 = 0; - GType gtype = TypeConverter.LookupType (obj.GetType ()); - if (gtype == GType.Object) { - g_value_init (ref this, ((GLib.Object) obj).NativeType.Val); - } else { - g_value_init (ref this, gtype.Val); - } - + GType gtype = (GType) obj.GetType (); + g_value_init (ref this, gtype.Val); Val = obj; } @@ -295,7 +290,7 @@ namespace GLib { } set { IntPtr buf; - GType type = TypeConverter.LookupType (value.GetType()); + GType type = (GType) value.GetType(); if (type == GType.Char) g_value_set_char (ref this, (char) value); else if (type == GType.Boolean) @@ -335,7 +330,7 @@ namespace GLib { Marshal.StructureToPtr (value, buf, false); g_value_set_boxed (ref this, buf); Marshal.FreeHGlobal (buf); - } else if (type == GType.Object) + } else if (g_type_is_a (type.Val, GType.Object.Val)) g_value_set_object (ref this, ((GLib.Object) value).Handle); else throw new Exception ("Unknown type"); diff --git a/gnome/PanelAppletFactory.cs b/gnome/PanelAppletFactory.cs index 395c9eb42..af0dcb41b 100644 --- a/gnome/PanelAppletFactory.cs +++ b/gnome/PanelAppletFactory.cs @@ -42,7 +42,7 @@ namespace Gnome _IID = applet.IID; _factoryIID = applet.FactoryIID; IntPtr native_iid = GLib.Marshaller.StringToPtrGStrdup (_factoryIID); - panel_applet_factory_main (native_iid, GLib.Object.LookupGType (applet_type).Val, cb_wrapper.NativeDelegate, IntPtr.Zero); + panel_applet_factory_main (native_iid, ((GLib.GType) applet_type).Val, cb_wrapper.NativeDelegate, IntPtr.Zero); GLib.Marshaller.Free (native_iid); } diff --git a/gnome/gnome-api.raw b/gnome/gnome-api.raw index d1b16f039..d84bfc1cf 100644 --- a/gnome/gnome-api.raw +++ b/gnome/gnome-api.raw @@ -7,7 +7,7 @@ --> - + @@ -22,11 +22,11 @@ - + - + @@ -1757,12 +1757,12 @@ - + - + @@ -1771,64 +1771,64 @@ - + - + - + - + - + - + - + - + - + - + - + - + @@ -1838,7 +1838,7 @@ - + diff --git a/gtk/ListStore.custom b/gtk/ListStore.custom index 6c5cc6eff..4c8f2d1ed 100644 --- a/gtk/ListStore.custom +++ b/gtk/ListStore.custom @@ -130,10 +130,7 @@ GLib.GType[] gtypes = new GLib.GType[types.Length]; int i = 0; foreach (Type type in types) { - GLib.GType ctype = GLib.TypeConverter.LookupType (type); - if (ctype == GLib.GType.Invalid) - throw new Exception ("Unknown type"); - gtypes[i] = ctype; + gtypes[i] = (GLib.GType) type; i++; } diff --git a/gtk/NodeStore.cs b/gtk/NodeStore.cs index ead8f91f3..8e0c52cf8 100644 --- a/gtk/NodeStore.cs +++ b/gtk/NodeStore.cs @@ -305,10 +305,7 @@ namespace Gtk { foreach (TreeNodeValueAttribute attr in pi.GetCustomAttributes (typeof (TreeNodeValueAttribute), false)) { int col = attr.Column; getters [col] = pi; - GLib.GType ctype = GLib.TypeConverter.LookupType (pi.PropertyType); - if (ctype == GLib.GType.Invalid) - throw new Exception ("Unknown type"); - ctypes[col] = ctype; + ctypes[col] = (GLib.GType) pi.PropertyType; } } } diff --git a/gtk/TreeStore.custom b/gtk/TreeStore.custom index 5b439a993..50062ddfc 100644 --- a/gtk/TreeStore.custom +++ b/gtk/TreeStore.custom @@ -306,10 +306,7 @@ GLib.GType[] gtypes = new GLib.GType[types.Length]; int i = 0; foreach (Type type in types) { - GLib.GType ctype = GLib.TypeConverter.LookupType (type); - if (ctype == GLib.GType.Invalid) - throw new Exception ("Unknown type"); - gtypes[i] = ctype; + gtypes[i] = (GLib.GType) type; i++; } diff --git a/gtk/gtk-api.raw b/gtk/gtk-api.raw index 006e2677e..677161309 100644 --- a/gtk/gtk-api.raw +++ b/gtk/gtk-api.raw @@ -7,12 +7,12 @@ --> - + - + @@ -31,32 +31,32 @@ - + - + - + - + - + @@ -64,37 +64,37 @@ - + - + - + - + - + - + @@ -104,18 +104,18 @@ - + - + - + @@ -123,23 +123,23 @@ - + - + - + - + @@ -155,12 +155,12 @@ - + - + @@ -169,11 +169,11 @@ - + - + @@ -183,13 +183,13 @@ - + - + @@ -197,24 +197,24 @@ - + - + - + - + @@ -226,25 +226,25 @@ - + - + - + - + - + @@ -252,43 +252,43 @@ - + - + - + - + - + - + - + - + @@ -328,17 +328,17 @@ - + - + - + @@ -351,7 +351,7 @@ - + @@ -359,7 +359,7 @@ - + @@ -377,27 +377,27 @@ - + - + - + - + @@ -405,21 +405,21 @@ - + - + - + - + @@ -428,35 +428,35 @@ - + - + - + - + - + - + - + @@ -465,33 +465,33 @@ - + - + - + - + - + - + @@ -509,17 +509,17 @@ - + - + - + @@ -540,22 +540,22 @@ - + - + - + - + diff --git a/pango/pango-api.raw b/pango/pango-api.raw index b4fe4537f..aaa0dce95 100644 --- a/pango/pango-api.raw +++ b/pango/pango-api.raw @@ -7,12 +7,12 @@ --> - + - + @@ -34,13 +34,13 @@ - + - + @@ -49,13 +49,13 @@ - + - + @@ -63,13 +63,13 @@ - + - + @@ -126,7 +126,7 @@ - + @@ -137,26 +137,26 @@ - + - + - + - + - + @@ -165,7 +165,7 @@ - + diff --git a/parser/gapi2xml.pl b/parser/gapi2xml.pl index c08495d1d..0b50f570d 100755 --- a/parser/gapi2xml.pl +++ b/parser/gapi2xml.pl @@ -145,6 +145,9 @@ while ($line = ) { my $boxtype = $1; $boxtype =~ s/($ns)Type(\w+)/$ns$2/; $boxdefs{$boxtype} = $boxdef; + } elsif ($line =~ /g_(enum|flags)_register_static/) { + $pedef =~ /^(\w+_get_type)/; + $enum_gtype{$class} = $1; } last if ($line =~ /^}/); } @@ -222,6 +225,9 @@ foreach $cname (sort(keys(%edefs))) { $enum_elem->setAttribute("deprecated", "1"); $def =~ s/deprecated//g; } + if ($enum_gtype{$cname}) { + $enum_elem->setAttribute("gtype", $enum_gtype{$cname}); + } if ($def =~ /=\s*1\s*<<\s*\d+/) { $enum_elem->setAttribute('type', "flags"); } else { diff --git a/sample/GtkDemo/DemoIconView.cs b/sample/GtkDemo/DemoIconView.cs index 457e17380..cc0717893 100644 --- a/sample/GtkDemo/DemoIconView.cs +++ b/sample/GtkDemo/DemoIconView.cs @@ -73,7 +73,7 @@ namespace GtkDemo ListStore CreateStore () { // path, name, pixbuf, is_dir - ListStore store = new ListStore (GLib.GType.String, GLib.GType.String, Gdk.Pixbuf.GType, GLib.GType.Boolean); + ListStore store = new ListStore (typeof (string), typeof (string), typeof (Gdk.Pixbuf), typeof (bool)); // Set sort column and function store.DefaultSortFunc = SortFunc; diff --git a/vte/vte-api.raw b/vte/vte-api.raw index 528974417..499d7df54 100644 --- a/vte/vte-api.raw +++ b/vte/vte-api.raw @@ -28,7 +28,7 @@ - +