2009-08-05 Christian Hoff <christian_hoff@gmx.net>

* generator/InterfaceGen: Override CallByName to handle interface
	adaptors properly.	[Fixes #527478]

svn path=/trunk/gtk-sharp/; revision=139390
This commit is contained in:
Christian Hoff 2009-08-05 06:24:27 +00:00
parent b3f341768f
commit 6002d77051
4 changed files with 35 additions and 15 deletions

View file

@ -1,3 +1,8 @@
2009-08-05 Christian Hoff <christian_hoff@gmx.net>
* generator/InterfaceGen: Override CallByName to handle interface
adaptors properly. [Fixes #527478]
2009-08-01 Mike Kestner <mkestner@novell.com>
* glib/GType.cs: lock the types hash to support threaded access and

View file

@ -58,6 +58,11 @@ namespace GtkSharp.Generation {
}
}
public override string CallByName (string var, bool owned)
{
return String.Format ("{0} == null ? IntPtr.Zero : (({0} is GLib.Object) ? ({0} as GLib.Object).{1} : ({0} as {2}Adapter).{1})", var, owned ? "OwnedHandle" : "Handle", QualifiedName);
}
public override string FromNative (string var, bool owned)
{
return QualifiedName + "Adapter.GetObject (" + var + ", " + (owned ? "true" : "false") + ")";
@ -121,19 +126,23 @@ namespace GtkSharp.Generation {
void GenerateCtors (StreamWriter sw)
{
// Native GObjects do not implement the *Implementor interfaces
sw.WriteLine ("\t\tGLib.Object implementor;", Name);
sw.WriteLine ();
if (!IsConsumeOnly) {
sw.WriteLine ("\t\tpublic " + Name + "Adapter ()");
sw.WriteLine ("\t\t{");
sw.WriteLine ("\t\t\tInitHandler = new GLib.GInterfaceInitHandler (Initialize);");
sw.WriteLine ("\t\t}");
sw.WriteLine ();
sw.WriteLine ("\t\t{0}Implementor implementor;", Name);
sw.WriteLine ();
sw.WriteLine ("\t\tpublic {0}Adapter ({0}Implementor implementor)", Name);
sw.WriteLine ("\t\t{");
sw.WriteLine ("\t\t\tif (implementor == null)");
sw.WriteLine ("\t\t\t\tthrow new ArgumentNullException (\"implementor\");");
sw.WriteLine ("\t\t\tthis.implementor = implementor;");
sw.WriteLine ("\t\t\telse if (!(implementor is GLib.Object))");
sw.WriteLine ("\t\t\t\tthrow new ArgumentException (\"implementor must be a subclass of GLib.Object\");");
sw.WriteLine ("\t\t\tthis.implementor = implementor as GLib.Object;");
sw.WriteLine ("\t\t}");
sw.WriteLine ();
}
@ -142,7 +151,7 @@ namespace GtkSharp.Generation {
sw.WriteLine ("\t\t{");
sw.WriteLine ("\t\t\tif (!_gtype.IsInstance (handle))");
sw.WriteLine ("\t\t\t\tthrow new ArgumentException (\"The gobject doesn't implement the GInterface of this adapter\", \"handle\");");
sw.WriteLine ("\t\t\tthis.handle = handle;");
sw.WriteLine ("\t\t\timplementor = GLib.Object.GetObject (handle);");
sw.WriteLine ("\t\t}");
sw.WriteLine ();
}
@ -163,16 +172,15 @@ namespace GtkSharp.Generation {
void GenerateHandleProp (StreamWriter sw)
{
sw.WriteLine ("\t\tIntPtr handle;");
sw.WriteLine ("\t\tpublic override IntPtr Handle {");
sw.WriteLine ("\t\t\tget {");
if (IsConsumeOnly) {
sw.WriteLine ("\t\t\t\treturn handle;");
} else {
sw.WriteLine ("\t\t\t\tif (handle != IntPtr.Zero)");
sw.WriteLine ("\t\t\t\t\treturn handle;");
sw.WriteLine ("\t\t\t\treturn implementor == null ? IntPtr.Zero : implementor.Handle;");
}
sw.WriteLine ("\t\t\t\treturn implementor.Handle;");
sw.WriteLine ("\t\t\t}");
sw.WriteLine ("\t\t}");
sw.WriteLine ();
sw.WriteLine ("\t\tpublic IntPtr OwnedHandle {");
sw.WriteLine ("\t\t\tget {");
sw.WriteLine ("\t\t\t\treturn implementor.OwnedHandle;");
sw.WriteLine ("\t\t\t}");
sw.WriteLine ("\t\t}");
sw.WriteLine ();
@ -206,7 +214,7 @@ namespace GtkSharp.Generation {
{
sw.WriteLine ("\t\tpublic " + Name + "Implementor Implementor {");
sw.WriteLine ("\t\t\tget {");
sw.WriteLine ("\t\t\t\treturn implementor;");
sw.WriteLine ("\t\t\t\treturn implementor as {0}Implementor;", Name);
sw.WriteLine ("\t\t\t}");
sw.WriteLine ("\t\t}");
sw.WriteLine ();

View file

@ -155,11 +155,13 @@ namespace GtkSharp.Generation {
}
}
public virtual string CallByName (string var, bool owned)
public override string CallByName (string var)
{
return String.Format ("{0} == null ? IntPtr.Zero : ({0} as GLib.Object).{1}", var, owned ? "OwnedHandle" : "Handle");
return CallByName (var, false);
}
public abstract string CallByName (string var, bool owned);
public override string FromNative (string var, bool owned)
{
return "GLib.Object.GetObject(" + var + (owned ? ", true" : "") + ") as " + QualifiedName;

View file

@ -70,6 +70,11 @@ namespace GtkSharp.Generation {
}
}
public override string CallByName (string var, bool owned)
{
return String.Format ("{0} == null ? IntPtr.Zero : {0}.{1}", var, owned ? "OwnedHandle" : "Handle");
}
public override bool Validate ()
{
ArrayList invalids = new ArrayList ();