Author: danw
Date: 2005-03-11 16:35:50 -0500 (Fri, 11 Mar 2005)
New Revision: 41726
Modified:
trunk/stetic/ChangeLog
trunk/stetic/libstetic/ObjectWrapper.cs
trunk/stetic/libstetic/wrapper/Alignment.cs
trunk/stetic/libstetic/wrapper/Arrow.cs
trunk/stetic/libstetic/wrapper/HBox.cs
trunk/stetic/libstetic/wrapper/RadioButton.cs
trunk/stetic/libstetic/wrapper/VBox.cs
trunk/stetic/libstetic/wrapper/Window.cs
Log:
* libstetic/ObjectWrapper.cs (Register, Create): if the wrapper
type doesn't have a CreateInstance method and the wrapped type
doesn't have a no-arg constructor, use g_object_new and the IntPtr
constructor.
* libstetic/wrapper/Alignment.cs:
* libstetic/wrapper/Arrow.cs:
* libstetic/wrapper/HBox.cs:
* libstetic/wrapper/RadioButton.cs:
* libstetic/wrapper/VBox.cs:
* libstetic/wrapper/Window.cs: remove no-longer-necessary
CreateInstance methods
Modified: trunk/stetic/ChangeLog
===================================================================
--- trunk/stetic/ChangeLog 2005-03-11 21:25:39 UTC (rev 41725)
+++ trunk/stetic/ChangeLog 2005-03-11 21:35:50 UTC (rev 41726)
@@ -1,3 +1,18 @@
+2005-03-11 Dan Winship <[EMAIL PROTECTED]>
+
+ * libstetic/ObjectWrapper.cs (Register, Create): if the wrapper
+ type doesn't have a CreateInstance method and the wrapped type
+ doesn't have a no-arg constructor, use g_object_new and the IntPtr
+ constructor.
+
+ * libstetic/wrapper/Alignment.cs:
+ * libstetic/wrapper/Arrow.cs:
+ * libstetic/wrapper/HBox.cs:
+ * libstetic/wrapper/RadioButton.cs:
+ * libstetic/wrapper/VBox.cs:
+ * libstetic/wrapper/Window.cs: remove no-longer-necessary
+ CreateInstance methods
+
2005-03-08 Dan Winship <[EMAIL PROTECTED]>
* libstetic/GladePropertyAttribute.cs: new attribute to mark
Modified: trunk/stetic/libstetic/ObjectWrapper.cs
===================================================================
--- trunk/stetic/libstetic/ObjectWrapper.cs 2005-03-11 21:25:39 UTC (rev
41725)
+++ trunk/stetic/libstetic/ObjectWrapper.cs 2005-03-11 21:35:50 UTC (rev
41726)
@@ -22,7 +22,7 @@
static Hashtable wrappers = new Hashtable ();
static Hashtable wrapperTypes = new Hashtable ();
- static Hashtable instanceCtors = new Hashtable ();
+ static Hashtable factories = new Hashtable ();
static Type WrappedType (Type type)
{
@@ -35,17 +35,59 @@
}
}
+ static IntPtr LookupGType (Type gtkSharpType)
+ {
+ PropertyInfo pinfo = gtkSharpType.GetProperty ("GType",
BindingFlags.Static | BindingFlags.Public);
+ if (pinfo == null)
+ return IntPtr.Zero;
+
+ return ((GLib.GType)pinfo.GetValue (null, null)).Val;
+ }
+
[DllImport("libgobject-2.0-0.dll")]
static extern IntPtr g_type_name (IntPtr gtype);
static string NativeTypeName (Type gtkSharpType)
{
- PropertyInfo pinfo = gtkSharpType.GetProperty ("GType",
BindingFlags.Static | BindingFlags.Public);
- if (pinfo == null)
- return null;
+ IntPtr gtype = LookupGType (gtkSharpType);
+ return gtype == IntPtr.Zero ? null :
Marshal.PtrToStringAnsi (g_type_name (gtype));
+ }
- GLib.GType gtype = (GLib.GType)pinfo.GetValue (null,
null);
- return Marshal.PtrToStringAnsi (g_type_name
(gtype.Val));
+ class ObjectFactory {
+ MethodInfo minfo;
+ ConstructorInfo cinfo;
+ IntPtr gtype;
+
+ public ObjectFactory (Type wrapperType, Type
wrappedType)
+ {
+ minfo = wrapperType.GetMethod ("CreateInstance",
+
BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic |
BindingFlags.DeclaredOnly,
+ null, new
Type[0], null);
+ if (minfo != null)
+ return;
+
+ cinfo = wrappedType.GetConstructor (new
Type[0]);
+ if (cinfo != null)
+ return;
+
+ cinfo = wrappedType.GetConstructor (new Type[]
{ typeof (IntPtr) });
+ gtype = LookupGType (wrappedType);
+ }
+
+ [DllImport("libgobject-2.0-0.dll")]
+ static extern IntPtr g_object_new (IntPtr gtype, IntPtr
dummy);
+
+ public object New ()
+ {
+ if (minfo != null)
+ return minfo.Invoke (null, new
object[0]);
+ else if (gtype == IntPtr.Zero)
+ return cinfo.Invoke (null, new
object[0]);
+ else {
+ IntPtr raw = g_object_new (gtype,
IntPtr.Zero);
+ return cinfo.Invoke (new object[] { raw
});
+ }
+ }
}
public static void Register (Type type)
@@ -55,12 +97,7 @@
if (className != null)
wrapperTypes[className] = type;
- MethodBase instanceCtor = type.GetMethod
("CreateInstance",
-
BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic |
BindingFlags.DeclaredOnly,
- null, new
Type[0], null);
- if (instanceCtor == null)
- instanceCtor = wrappedType.GetConstructor (new
Type[0]);
- instanceCtors[type] = instanceCtor;
+ factories[type] = new ObjectFactory (type, wrappedType);
// Run wrapper registration methods
Type regType = type;
@@ -81,8 +118,8 @@
return null;
wrapper.stetic = stetic;
- MethodBase instanceCtor = instanceCtors[type] as
MethodBase;
- wrapper.Wrap (instanceCtor.Invoke (null, new
object[0]), false);
+ ObjectFactory factory = factories[type] as
ObjectFactory;
+ wrapper.Wrap (factory.New (), false);
return wrapper;
}
Modified: trunk/stetic/libstetic/wrapper/Alignment.cs
===================================================================
--- trunk/stetic/libstetic/wrapper/Alignment.cs 2005-03-11 21:25:39 UTC (rev
41725)
+++ trunk/stetic/libstetic/wrapper/Alignment.cs 2005-03-11 21:35:50 UTC (rev
41726)
@@ -21,10 +21,5 @@
"BottomPadding",
"BorderWidth");
}
-
- public static new Gtk.Alignment CreateInstance ()
- {
- return new Gtk.Alignment (0.5f, 0.5f, 1.0f, 1.0f);
- }
}
}
Modified: trunk/stetic/libstetic/wrapper/Arrow.cs
===================================================================
--- trunk/stetic/libstetic/wrapper/Arrow.cs 2005-03-11 21:25:39 UTC (rev
41725)
+++ trunk/stetic/libstetic/wrapper/Arrow.cs 2005-03-11 21:35:50 UTC (rev
41726)
@@ -13,10 +13,5 @@
"ArrowType",
"ShadowType");
}
-
- public static new Gtk.Arrow CreateInstance ()
- {
- return new Gtk.Arrow (Gtk.ArrowType.Left,
Gtk.ShadowType.None);
- }
}
}
Modified: trunk/stetic/libstetic/wrapper/HBox.cs
===================================================================
--- trunk/stetic/libstetic/wrapper/HBox.cs 2005-03-11 21:25:39 UTC (rev
41725)
+++ trunk/stetic/libstetic/wrapper/HBox.cs 2005-03-11 21:35:50 UTC (rev
41726)
@@ -7,11 +7,6 @@
public static new Type WrappedType = typeof (Gtk.HBox);
- public static new Gtk.HBox CreateInstance ()
- {
- return new Gtk.HBox (false, 0);
- }
-
public override bool HExpandable {
get {
foreach (WidgetSite site in Sites) {
Modified: trunk/stetic/libstetic/wrapper/RadioButton.cs
===================================================================
--- trunk/stetic/libstetic/wrapper/RadioButton.cs 2005-03-11 21:25:39 UTC
(rev 41725)
+++ trunk/stetic/libstetic/wrapper/RadioButton.cs 2005-03-11 21:35:50 UTC
(rev 41726)
@@ -22,11 +22,6 @@
"DrawIndicator");
}
- public static new Gtk.RadioButton CreateInstance ()
- {
- return new Gtk.RadioButton ("");
- }
-
public override void Wrap (object obj, bool initialized)
{
base.Wrap (obj, initialized);
Modified: trunk/stetic/libstetic/wrapper/VBox.cs
===================================================================
--- trunk/stetic/libstetic/wrapper/VBox.cs 2005-03-11 21:25:39 UTC (rev
41725)
+++ trunk/stetic/libstetic/wrapper/VBox.cs 2005-03-11 21:35:50 UTC (rev
41726)
@@ -7,11 +7,6 @@
public static new Type WrappedType = typeof (Gtk.VBox);
- public static new Gtk.VBox CreateInstance ()
- {
- return new Gtk.VBox (false, 0);
- }
-
public override bool HExpandable {
get {
foreach (WidgetSite site in Sites) {
Modified: trunk/stetic/libstetic/wrapper/Window.cs
===================================================================
--- trunk/stetic/libstetic/wrapper/Window.cs 2005-03-11 21:25:39 UTC (rev
41725)
+++ trunk/stetic/libstetic/wrapper/Window.cs 2005-03-11 21:35:50 UTC (rev
41726)
@@ -37,11 +37,6 @@
"SkipTaskbarHint");
}
- public static new Gtk.Window CreateInstance ()
- {
- return new Gtk.Window (Gtk.WindowType.Toplevel);
- }
-
public override void Wrap (object obj, bool initialized)
{
Gtk.Window window = (Gtk.Window)obj;
_______________________________________________
Mono-patches maillist - [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches