2002-05-23 23:43:25 +00:00
|
|
|
// GtkSharp.Generation.Signal.cs - The Signal Generatable.
|
|
|
|
//
|
|
|
|
// Author: Mike Kestner <mkestner@speakeasy.net>
|
|
|
|
//
|
2004-03-16 19:43:04 +00:00
|
|
|
// (c) 2001-2003 Mike Kestner
|
|
|
|
// (c) 2003-2004 Novell, Inc.
|
2002-05-23 23:43:25 +00:00
|
|
|
|
|
|
|
namespace GtkSharp.Generation {
|
|
|
|
|
|
|
|
using System;
|
|
|
|
using System.Collections;
|
|
|
|
using System.IO;
|
|
|
|
using System.Xml;
|
|
|
|
|
|
|
|
public class Signal {
|
|
|
|
|
2002-06-21 Rachel Hestilow <hestilow@ximian.com>
* generator/ClassBase.cs: New base class for classes and interfaces.
* generator/InterfaceGen.cs: Inherit from ClassBase, generate declarations.
* generator/ObjectGen.cs: Move half of this into ClassBase.
* generator/Method.cs: Turn all applicable Get/Set functions into .NET
accessors. Remove redundant == overload and move into Equals, as
it was confusing "!= null".
* generator/Parameters.cs: Alter signature creation to accept "is_set"
option, add support for variable arguments. Add properties "Count",
"IsVarArgs", "VAType".
* generator/Ctor.cs: Fixup for changes in Parameters (indenting,
signature creation).
* generator/Signal.cs: Support generating declarations.
* generator/SymbolTable: Change GetObjectGen to GetClassGen.
* glib/IWrapper.cs: Move "Handle" declaration to here, so
both classes and interfaces can benefit from it.
* glib/Object.cs: Inherit from IWrapper.cs
* parser/Metadata.pm: Support attribute changes on constructors,
methods, signals, and paramater lists.
* parser/gapi2xml.pl: Parse init funcs for interfaces. Ignore "_"
functions here.
* parser/gapi_pp.pl: Remove boxed_type_register check, as it will
be caught in the init funcs.
* parser/Atk.metadata: Added.
* parser/Gtk.metadata: Add all needed signal/method collision
renames. Rename GtkEditable.Editable accessors to IsEditable,
as .NET does not like accessors with the same name as their
declaring type. Tag TreeStore constructor as varargs.
* samples/ButtonApp.cs: s/EmitAdd/Add.
* samples/Menu.cs: s/EmitAdd/Add, s/Activate/Activated.
svn path=/trunk/gtk-sharp/; revision=5394
2002-06-21 17:15:19 +00:00
|
|
|
private string name;
|
2002-05-23 23:43:25 +00:00
|
|
|
private XmlElement elem;
|
2002-07-16 23:14:35 +00:00
|
|
|
private Parameters parms;
|
2002-07-13 Rachel Hestilow <hestilow@ximian.com>
* parser/Gnome.metadata, Gtk.metadata: More conflict
fixes.
* parser/build.pl: Fully qualify all lib names. (Gtk+ packages
are now LFS-compliant in Debian...)
* parser/gapi2xml.pl: Fix for whitespace in fields, defines,
and docs.
* generator/BoxedGen.cs: Remove extraneous CallByName definition,
add "override" keyword to FromNative.
(Generate): Generate methods after fields.
* generator/ClassBase.cs: Change CallByName, FromNative to virtual.
(.ctor): Ignore "hidden" nodes. Set container on signal.
(GenSignals, GenMethods): Add "implementor" argument for interface
use.
(Get(Method|Signal|Property)Recursively): Rework to correctly
recurse interfaces.
(Implements): Added.
* generator/Ctor.cs (Initialize): Move clash initialization completely
out of Generate, so we can check for collisions.
* generator/Method.cs (GenerateDeclCommon): Check for duplicates,
for "new" keyword.
(Generate): Add "implementor" argument.
* generator/ObjectGen.cs (Generate): Initialize ctor clashes on
this and all parents, before generating.
(Ctors, InitializeCtors): Added.
* generator/Signal.cs: Store the container_type, check for
collisions.
* generator/StructGen.cs: Add "override" keyword to overriden methods.
* gtk/FileSelection.custom (ActionArea): Add "new" keyword.
svn path=/trunk/gtk-sharp/; revision=5782
2002-07-13 20:31:23 +00:00
|
|
|
private ClassBase container_type;
|
2003-09-15 04:20:33 +00:00
|
|
|
SignalHandler sig_handler;
|
2002-05-23 23:43:25 +00:00
|
|
|
|
2002-07-13 Rachel Hestilow <hestilow@ximian.com>
* parser/Gnome.metadata, Gtk.metadata: More conflict
fixes.
* parser/build.pl: Fully qualify all lib names. (Gtk+ packages
are now LFS-compliant in Debian...)
* parser/gapi2xml.pl: Fix for whitespace in fields, defines,
and docs.
* generator/BoxedGen.cs: Remove extraneous CallByName definition,
add "override" keyword to FromNative.
(Generate): Generate methods after fields.
* generator/ClassBase.cs: Change CallByName, FromNative to virtual.
(.ctor): Ignore "hidden" nodes. Set container on signal.
(GenSignals, GenMethods): Add "implementor" argument for interface
use.
(Get(Method|Signal|Property)Recursively): Rework to correctly
recurse interfaces.
(Implements): Added.
* generator/Ctor.cs (Initialize): Move clash initialization completely
out of Generate, so we can check for collisions.
* generator/Method.cs (GenerateDeclCommon): Check for duplicates,
for "new" keyword.
(Generate): Add "implementor" argument.
* generator/ObjectGen.cs (Generate): Initialize ctor clashes on
this and all parents, before generating.
(Ctors, InitializeCtors): Added.
* generator/Signal.cs: Store the container_type, check for
collisions.
* generator/StructGen.cs: Add "override" keyword to overriden methods.
* gtk/FileSelection.custom (ActionArea): Add "new" keyword.
svn path=/trunk/gtk-sharp/; revision=5782
2002-07-13 20:31:23 +00:00
|
|
|
public Signal (XmlElement elem, ClassBase container_type)
|
2002-05-23 23:43:25 +00:00
|
|
|
{
|
|
|
|
this.elem = elem;
|
2002-06-21 Rachel Hestilow <hestilow@ximian.com>
* generator/ClassBase.cs: New base class for classes and interfaces.
* generator/InterfaceGen.cs: Inherit from ClassBase, generate declarations.
* generator/ObjectGen.cs: Move half of this into ClassBase.
* generator/Method.cs: Turn all applicable Get/Set functions into .NET
accessors. Remove redundant == overload and move into Equals, as
it was confusing "!= null".
* generator/Parameters.cs: Alter signature creation to accept "is_set"
option, add support for variable arguments. Add properties "Count",
"IsVarArgs", "VAType".
* generator/Ctor.cs: Fixup for changes in Parameters (indenting,
signature creation).
* generator/Signal.cs: Support generating declarations.
* generator/SymbolTable: Change GetObjectGen to GetClassGen.
* glib/IWrapper.cs: Move "Handle" declaration to here, so
both classes and interfaces can benefit from it.
* glib/Object.cs: Inherit from IWrapper.cs
* parser/Metadata.pm: Support attribute changes on constructors,
methods, signals, and paramater lists.
* parser/gapi2xml.pl: Parse init funcs for interfaces. Ignore "_"
functions here.
* parser/gapi_pp.pl: Remove boxed_type_register check, as it will
be caught in the init funcs.
* parser/Atk.metadata: Added.
* parser/Gtk.metadata: Add all needed signal/method collision
renames. Rename GtkEditable.Editable accessors to IsEditable,
as .NET does not like accessors with the same name as their
declaring type. Tag TreeStore constructor as varargs.
* samples/ButtonApp.cs: s/EmitAdd/Add.
* samples/Menu.cs: s/EmitAdd/Add, s/Activate/Activated.
svn path=/trunk/gtk-sharp/; revision=5394
2002-06-21 17:15:19 +00:00
|
|
|
this.name = elem.GetAttribute ("name");
|
2002-07-16 23:14:35 +00:00
|
|
|
if (elem["parameters"] != null)
|
2003-06-14 17:30:32 +00:00
|
|
|
parms = new Parameters (elem["parameters"], container_type.NS);
|
2002-07-13 Rachel Hestilow <hestilow@ximian.com>
* parser/Gnome.metadata, Gtk.metadata: More conflict
fixes.
* parser/build.pl: Fully qualify all lib names. (Gtk+ packages
are now LFS-compliant in Debian...)
* parser/gapi2xml.pl: Fix for whitespace in fields, defines,
and docs.
* generator/BoxedGen.cs: Remove extraneous CallByName definition,
add "override" keyword to FromNative.
(Generate): Generate methods after fields.
* generator/ClassBase.cs: Change CallByName, FromNative to virtual.
(.ctor): Ignore "hidden" nodes. Set container on signal.
(GenSignals, GenMethods): Add "implementor" argument for interface
use.
(Get(Method|Signal|Property)Recursively): Rework to correctly
recurse interfaces.
(Implements): Added.
* generator/Ctor.cs (Initialize): Move clash initialization completely
out of Generate, so we can check for collisions.
* generator/Method.cs (GenerateDeclCommon): Check for duplicates,
for "new" keyword.
(Generate): Add "implementor" argument.
* generator/ObjectGen.cs (Generate): Initialize ctor clashes on
this and all parents, before generating.
(Ctors, InitializeCtors): Added.
* generator/Signal.cs: Store the container_type, check for
collisions.
* generator/StructGen.cs: Add "override" keyword to overriden methods.
* gtk/FileSelection.custom (ActionArea): Add "new" keyword.
svn path=/trunk/gtk-sharp/; revision=5782
2002-07-13 20:31:23 +00:00
|
|
|
this.container_type = container_type;
|
2003-09-15 04:20:33 +00:00
|
|
|
sig_handler = new SignalHandler (elem, container_type.NS);
|
2002-05-23 23:43:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public string Name {
|
|
|
|
get {
|
2002-06-21 Rachel Hestilow <hestilow@ximian.com>
* generator/ClassBase.cs: New base class for classes and interfaces.
* generator/InterfaceGen.cs: Inherit from ClassBase, generate declarations.
* generator/ObjectGen.cs: Move half of this into ClassBase.
* generator/Method.cs: Turn all applicable Get/Set functions into .NET
accessors. Remove redundant == overload and move into Equals, as
it was confusing "!= null".
* generator/Parameters.cs: Alter signature creation to accept "is_set"
option, add support for variable arguments. Add properties "Count",
"IsVarArgs", "VAType".
* generator/Ctor.cs: Fixup for changes in Parameters (indenting,
signature creation).
* generator/Signal.cs: Support generating declarations.
* generator/SymbolTable: Change GetObjectGen to GetClassGen.
* glib/IWrapper.cs: Move "Handle" declaration to here, so
both classes and interfaces can benefit from it.
* glib/Object.cs: Inherit from IWrapper.cs
* parser/Metadata.pm: Support attribute changes on constructors,
methods, signals, and paramater lists.
* parser/gapi2xml.pl: Parse init funcs for interfaces. Ignore "_"
functions here.
* parser/gapi_pp.pl: Remove boxed_type_register check, as it will
be caught in the init funcs.
* parser/Atk.metadata: Added.
* parser/Gtk.metadata: Add all needed signal/method collision
renames. Rename GtkEditable.Editable accessors to IsEditable,
as .NET does not like accessors with the same name as their
declaring type. Tag TreeStore constructor as varargs.
* samples/ButtonApp.cs: s/EmitAdd/Add.
* samples/Menu.cs: s/EmitAdd/Add, s/Activate/Activated.
svn path=/trunk/gtk-sharp/; revision=5394
2002-06-21 17:15:19 +00:00
|
|
|
return name;
|
|
|
|
}
|
|
|
|
set {
|
|
|
|
name = value;
|
2002-05-23 23:43:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public bool Validate ()
|
|
|
|
{
|
2003-09-15 04:20:33 +00:00
|
|
|
if (Name == "" || !sig_handler.Validate ()) {
|
2002-05-23 23:43:25 +00:00
|
|
|
Console.Write ("bad signal " + Name);
|
|
|
|
Statistics.ThrottledCount++;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2002-07-16 23:14:35 +00:00
|
|
|
if (parms != null && !parms.Validate ())
|
|
|
|
return false;
|
|
|
|
|
2002-05-23 23:43:25 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2002-07-16 23:14:35 +00:00
|
|
|
public void GenerateDecl (StreamWriter sw)
|
|
|
|
{
|
2002-07-13 Rachel Hestilow <hestilow@ximian.com>
* parser/Gnome.metadata, Gtk.metadata: More conflict
fixes.
* parser/build.pl: Fully qualify all lib names. (Gtk+ packages
are now LFS-compliant in Debian...)
* parser/gapi2xml.pl: Fix for whitespace in fields, defines,
and docs.
* generator/BoxedGen.cs: Remove extraneous CallByName definition,
add "override" keyword to FromNative.
(Generate): Generate methods after fields.
* generator/ClassBase.cs: Change CallByName, FromNative to virtual.
(.ctor): Ignore "hidden" nodes. Set container on signal.
(GenSignals, GenMethods): Add "implementor" argument for interface
use.
(Get(Method|Signal|Property)Recursively): Rework to correctly
recurse interfaces.
(Implements): Added.
* generator/Ctor.cs (Initialize): Move clash initialization completely
out of Generate, so we can check for collisions.
* generator/Method.cs (GenerateDeclCommon): Check for duplicates,
for "new" keyword.
(Generate): Add "implementor" argument.
* generator/ObjectGen.cs (Generate): Initialize ctor clashes on
this and all parents, before generating.
(Ctors, InitializeCtors): Added.
* generator/Signal.cs: Store the container_type, check for
collisions.
* generator/StructGen.cs: Add "override" keyword to overriden methods.
* gtk/FileSelection.custom (ActionArea): Add "new" keyword.
svn path=/trunk/gtk-sharp/; revision=5782
2002-07-13 20:31:23 +00:00
|
|
|
if (elem.HasAttribute("new_flag") || (container_type != null && container_type.GetSignalRecursively (Name) != null))
|
2002-06-21 Rachel Hestilow <hestilow@ximian.com>
* generator/ClassBase.cs: New base class for classes and interfaces.
* generator/InterfaceGen.cs: Inherit from ClassBase, generate declarations.
* generator/ObjectGen.cs: Move half of this into ClassBase.
* generator/Method.cs: Turn all applicable Get/Set functions into .NET
accessors. Remove redundant == overload and move into Equals, as
it was confusing "!= null".
* generator/Parameters.cs: Alter signature creation to accept "is_set"
option, add support for variable arguments. Add properties "Count",
"IsVarArgs", "VAType".
* generator/Ctor.cs: Fixup for changes in Parameters (indenting,
signature creation).
* generator/Signal.cs: Support generating declarations.
* generator/SymbolTable: Change GetObjectGen to GetClassGen.
* glib/IWrapper.cs: Move "Handle" declaration to here, so
both classes and interfaces can benefit from it.
* glib/Object.cs: Inherit from IWrapper.cs
* parser/Metadata.pm: Support attribute changes on constructors,
methods, signals, and paramater lists.
* parser/gapi2xml.pl: Parse init funcs for interfaces. Ignore "_"
functions here.
* parser/gapi_pp.pl: Remove boxed_type_register check, as it will
be caught in the init funcs.
* parser/Atk.metadata: Added.
* parser/Gtk.metadata: Add all needed signal/method collision
renames. Rename GtkEditable.Editable accessors to IsEditable,
as .NET does not like accessors with the same name as their
declaring type. Tag TreeStore constructor as varargs.
* samples/ButtonApp.cs: s/EmitAdd/Add.
* samples/Menu.cs: s/EmitAdd/Add, s/Activate/Activated.
svn path=/trunk/gtk-sharp/; revision=5394
2002-06-21 17:15:19 +00:00
|
|
|
sw.Write("new ");
|
2002-07-13 Rachel Hestilow <hestilow@ximian.com>
* parser/Gnome.metadata, Gtk.metadata: More conflict
fixes.
* parser/build.pl: Fully qualify all lib names. (Gtk+ packages
are now LFS-compliant in Debian...)
* parser/gapi2xml.pl: Fix for whitespace in fields, defines,
and docs.
* generator/BoxedGen.cs: Remove extraneous CallByName definition,
add "override" keyword to FromNative.
(Generate): Generate methods after fields.
* generator/ClassBase.cs: Change CallByName, FromNative to virtual.
(.ctor): Ignore "hidden" nodes. Set container on signal.
(GenSignals, GenMethods): Add "implementor" argument for interface
use.
(Get(Method|Signal|Property)Recursively): Rework to correctly
recurse interfaces.
(Implements): Added.
* generator/Ctor.cs (Initialize): Move clash initialization completely
out of Generate, so we can check for collisions.
* generator/Method.cs (GenerateDeclCommon): Check for duplicates,
for "new" keyword.
(Generate): Add "implementor" argument.
* generator/ObjectGen.cs (Generate): Initialize ctor clashes on
this and all parents, before generating.
(Ctors, InitializeCtors): Added.
* generator/Signal.cs: Store the container_type, check for
collisions.
* generator/StructGen.cs: Add "override" keyword to overriden methods.
* gtk/FileSelection.custom (ActionArea): Add "new" keyword.
svn path=/trunk/gtk-sharp/; revision=5782
2002-07-13 20:31:23 +00:00
|
|
|
|
2003-10-06 20:12:09 +00:00
|
|
|
sw.WriteLine ("\t\tevent " + EventHandlerQualifiedName + " " + Name + ";");
|
2002-07-16 23:14:35 +00:00
|
|
|
}
|
|
|
|
|
2003-10-06 20:12:09 +00:00
|
|
|
private string EventArgsName {
|
|
|
|
get {
|
|
|
|
if (sig_handler.Name == "voidObjectSignal")
|
|
|
|
return "EventArgs";
|
|
|
|
else
|
|
|
|
return Name + "Args";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private string EventArgsQualifiedName {
|
|
|
|
get {
|
|
|
|
if (sig_handler.Name == "voidObjectSignal")
|
|
|
|
return "System.EventArgs";
|
|
|
|
else
|
2004-02-10 20:35:40 +00:00
|
|
|
return container_type.NS + "." + Name + "Args";
|
2003-10-06 20:12:09 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private string EventHandlerName {
|
|
|
|
get {
|
|
|
|
if (sig_handler.Name == "voidObjectSignal")
|
|
|
|
return "EventHandler";
|
2004-02-10 20:35:40 +00:00
|
|
|
else if (SymbolTable.Table [container_type.NS + Name + "Handler"] != null)
|
|
|
|
return Name + "EventHandler";
|
|
|
|
else
|
2003-10-06 20:12:09 +00:00
|
|
|
return Name + "Handler";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private string EventHandlerQualifiedName {
|
|
|
|
get {
|
|
|
|
if (sig_handler.Name == "voidObjectSignal")
|
|
|
|
return "System.EventHandler";
|
|
|
|
else
|
2004-02-10 20:35:40 +00:00
|
|
|
return container_type.NS + "." + EventHandlerName;
|
2003-10-06 20:12:09 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-12-09 05:01:22 +00:00
|
|
|
private bool IsVoid {
|
|
|
|
get {
|
|
|
|
return ReturnType == "void";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private string MarshalReturnType {
|
|
|
|
get {
|
|
|
|
string ctype = elem ["return-type"].GetAttribute("type");
|
|
|
|
return SymbolTable.Table.GetMarshalType (ctype);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-01-14 18:05:50 +00:00
|
|
|
private string ReturnGType {
|
|
|
|
get {
|
|
|
|
ClassBase igen = SymbolTable.Table.GetClassGen (elem ["return-type"].GetAttribute("type"));
|
|
|
|
|
|
|
|
if (igen is ObjectGen)
|
|
|
|
return "GLib.GType.Object";
|
|
|
|
|
|
|
|
switch (ReturnType) {
|
|
|
|
case "bool":
|
|
|
|
return "GLib.GType.Boolean";
|
|
|
|
case "string":
|
|
|
|
return "GLib.GType.String";
|
|
|
|
case "int":
|
|
|
|
return "GLib.GType.Int";
|
|
|
|
default:
|
|
|
|
throw new Exception (ReturnType);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-12-09 05:01:22 +00:00
|
|
|
private string ReturnType {
|
|
|
|
get {
|
|
|
|
string ctype = elem ["return-type"].GetAttribute("type");
|
|
|
|
return SymbolTable.Table.GetCSType (ctype);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-10-06 20:12:09 +00:00
|
|
|
public void GenEventHandler (GenerationInfo gen_info)
|
2002-07-16 23:14:35 +00:00
|
|
|
{
|
2003-10-06 20:12:09 +00:00
|
|
|
if (EventHandlerName == "EventHandler")
|
|
|
|
return;
|
2002-07-16 23:14:35 +00:00
|
|
|
|
2003-05-08 04:44:13 +00:00
|
|
|
string ns = container_type.NS;
|
2002-07-16 23:14:35 +00:00
|
|
|
|
2004-02-10 20:35:40 +00:00
|
|
|
StreamWriter sw = gen_info.OpenStream (EventHandlerName);
|
2002-07-16 23:14:35 +00:00
|
|
|
|
2004-02-10 20:35:40 +00:00
|
|
|
sw.WriteLine ("namespace " + ns + " {");
|
2002-07-16 23:14:35 +00:00
|
|
|
sw.WriteLine ();
|
|
|
|
sw.WriteLine ("\tusing System;");
|
|
|
|
|
|
|
|
sw.WriteLine ();
|
2003-10-06 20:12:09 +00:00
|
|
|
sw.WriteLine ("\tpublic delegate void " + EventHandlerName + "(object o, " + EventArgsName + " args);");
|
2002-07-16 23:14:35 +00:00
|
|
|
sw.WriteLine ();
|
2004-05-05 18:24:04 +00:00
|
|
|
sw.WriteLine ("\tpublic class " + EventArgsName + " : GLib.SignalArgs {");
|
2002-07-16 23:14:35 +00:00
|
|
|
if (parms != null) {
|
|
|
|
for (int i = 1; i < parms.Count; i++) {
|
|
|
|
sw.WriteLine ("\t\tpublic " + parms[i].CSType + " " + parms[i].StudlyName + "{");
|
|
|
|
sw.WriteLine ("\t\t\tget {");
|
|
|
|
sw.WriteLine ("\t\t\t\treturn (" + parms[i].CSType + ") Args[" + (i - 1) + "];");
|
|
|
|
sw.WriteLine ("\t\t\t}");
|
|
|
|
sw.WriteLine ("\t\t}");
|
|
|
|
sw.WriteLine ();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
sw.WriteLine ("\t}");
|
|
|
|
sw.WriteLine ("}");
|
|
|
|
sw.Close ();
|
|
|
|
}
|
|
|
|
|
2003-12-10 22:56:49 +00:00
|
|
|
private void GenVirtualMethod (StreamWriter sw, ClassBase implementor)
|
2003-12-09 05:01:22 +00:00
|
|
|
{
|
|
|
|
VMSignature vmsig = new VMSignature (parms);
|
2003-12-10 22:56:49 +00:00
|
|
|
sw.WriteLine ("\t\t[GLib.DefaultSignalHandler(Type=typeof(" + (implementor != null ? implementor.QualifiedName : container_type.QualifiedName) + "), ConnectionMethod=\"Override" + Name +"\")]");
|
2003-12-09 05:01:22 +00:00
|
|
|
sw.WriteLine ("\t\tprotected virtual {0} {1} ({2})", ReturnType, "On" + Name, vmsig.ToString ());
|
|
|
|
sw.WriteLine ("\t\t{");
|
2004-04-12 15:54:57 +00:00
|
|
|
if (IsVoid)
|
|
|
|
sw.WriteLine ("\t\t\tGLib.Value ret = GLib.Value.Empty;");
|
|
|
|
else
|
2004-01-14 18:05:50 +00:00
|
|
|
sw.WriteLine ("\t\t\tGLib.Value ret = new GLib.Value (" + ReturnGType + ");");
|
2003-12-09 05:01:22 +00:00
|
|
|
|
2004-01-14 18:05:50 +00:00
|
|
|
sw.WriteLine ("\t\t\tGLib.ValueArray inst_and_params = new GLib.ValueArray (" + parms.Count + ");");
|
2003-12-10 22:56:49 +00:00
|
|
|
sw.WriteLine ("\t\t\tGLib.Value[] vals = new GLib.Value [" + parms.Count + "];");
|
|
|
|
sw.WriteLine ("\t\t\tvals [0] = new GLib.Value (this);");
|
2004-01-14 18:05:50 +00:00
|
|
|
sw.WriteLine ("\t\t\tinst_and_params.Append (vals [0]);");
|
2003-12-09 05:01:22 +00:00
|
|
|
string cleanup = "";
|
|
|
|
for (int i = 1; i < parms.Count; i++) {
|
|
|
|
if (parms [i].PassAs == "out") {
|
2004-04-12 15:54:57 +00:00
|
|
|
sw.WriteLine ("\t\t\tvals [" + i + "] = GLib.Value.Empty;");
|
2003-12-10 22:56:49 +00:00
|
|
|
cleanup += "\t\t\t" + parms [i].Name + " = (" + parms [i].CSType + ") vals [" + i + "];\n";
|
2003-12-09 05:01:22 +00:00
|
|
|
} else if (parms [i].IsLength && parms [i - 1].IsString)
|
2003-12-10 22:56:49 +00:00
|
|
|
sw.WriteLine ("\t\t\tvals [" + i + "] = new GLib.Value (" + parms [i-1].Name + ".Length);");
|
2003-12-09 05:01:22 +00:00
|
|
|
else
|
2003-12-10 22:56:49 +00:00
|
|
|
sw.WriteLine ("\t\t\tvals [" + i + "] = new GLib.Value (" + parms [i].Name + ");");
|
2003-12-09 05:01:22 +00:00
|
|
|
|
2004-01-14 18:05:50 +00:00
|
|
|
sw.WriteLine ("\t\t\tinst_and_params.Append (vals [" + i + "]);");
|
2003-12-09 05:01:22 +00:00
|
|
|
}
|
|
|
|
|
2004-04-12 15:54:57 +00:00
|
|
|
sw.WriteLine ("\t\t\tg_signal_chain_from_overridden (inst_and_params.ArrayPtr, ref ret);");
|
2003-12-09 05:01:22 +00:00
|
|
|
if (cleanup != "")
|
|
|
|
sw.WriteLine (cleanup);
|
|
|
|
if (!IsVoid)
|
|
|
|
sw.WriteLine ("\t\t\treturn (" + ReturnType + ") ret;");
|
|
|
|
sw.WriteLine ("\t\t}\n");
|
|
|
|
}
|
|
|
|
|
2003-12-10 22:56:49 +00:00
|
|
|
private void GenDefaultHandlerDelegate (StreamWriter sw, ClassBase implementor)
|
|
|
|
{
|
|
|
|
ImportSignature isig = new ImportSignature (parms, container_type.NS);
|
|
|
|
ManagedCallString call = new ManagedCallString (parms);
|
|
|
|
sw.WriteLine ("\t\tdelegate " + MarshalReturnType + " " + Name + "Delegate (" + isig.ToString () + ");\n");
|
|
|
|
sw.WriteLine ("\t\tstatic {0} {1};\n", Name + "Delegate", Name + "Callback");
|
|
|
|
sw.WriteLine ("\t\tstatic " + MarshalReturnType + " " + Name.ToLower() + "_cb (" + isig.ToString () + ")");
|
|
|
|
sw.WriteLine ("\t\t{");
|
|
|
|
sw.WriteLine ("\t\t\t{0} obj = GLib.Object.GetObject ({1}, false) as {0};", implementor != null ? implementor.Name : container_type.Name, parms[0].Name);
|
|
|
|
sw.Write ("\t\t\t{0}", IsVoid ? "" : "return ");
|
|
|
|
sw.WriteLine ("obj.{0} ({1});", "On" + Name, call.ToString ());
|
|
|
|
sw.WriteLine ("\t\t}\n");
|
|
|
|
string cname = "\"" + elem.GetAttribute("cname") + "\"";
|
2003-12-15 16:59:25 +00:00
|
|
|
sw.WriteLine ("\t\tprotected static void Override" + Name + " (GLib.GType gtype)");
|
2003-12-10 22:56:49 +00:00
|
|
|
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);");
|
2003-12-15 16:59:25 +00:00
|
|
|
sw.WriteLine ("\t\t\tOverrideVirtualMethod (gtype, " + cname + ", " + Name + "Callback);");
|
2003-12-10 22:56:49 +00:00
|
|
|
sw.WriteLine ("\t\t}\n");
|
|
|
|
}
|
|
|
|
|
2003-10-05 00:20:17 +00:00
|
|
|
public void Generate (GenerationInfo gen_info, ClassBase implementor)
|
2002-06-24 22:04:10 +00:00
|
|
|
{
|
2003-10-05 00:20:17 +00:00
|
|
|
StreamWriter sw = gen_info.Writer;
|
2002-06-24 22:04:10 +00:00
|
|
|
string cname = "\"" + elem.GetAttribute("cname") + "\"";
|
2003-05-08 04:44:13 +00:00
|
|
|
string ns;
|
2003-10-06 20:12:09 +00:00
|
|
|
if (implementor == null) {
|
2003-05-08 04:44:13 +00:00
|
|
|
ns = container_type.NS;
|
2003-10-06 20:12:09 +00:00
|
|
|
GenEventHandler (gen_info);
|
|
|
|
} else
|
2003-05-08 04:44:13 +00:00
|
|
|
ns = implementor.NS;
|
2002-06-24 22:04:10 +00:00
|
|
|
|
2003-10-06 16:15:05 +00:00
|
|
|
sig_handler.Generate (ns, gen_info);
|
2003-12-10 22:56:49 +00:00
|
|
|
GenDefaultHandlerDelegate (sw, implementor);
|
|
|
|
GenVirtualMethod (sw, implementor);
|
2003-09-15 04:20:33 +00:00
|
|
|
string qual_marsh = ns + "Sharp." + sig_handler.Name;
|
2002-07-16 23:14:35 +00:00
|
|
|
|
2002-09-13 11:38:36 +00:00
|
|
|
sw.WriteLine("\t\t[GLib.Signal("+ cname + ")]");
|
2002-05-23 23:43:25 +00:00
|
|
|
sw.Write("\t\tpublic ");
|
2002-07-13 Rachel Hestilow <hestilow@ximian.com>
* parser/Gnome.metadata, Gtk.metadata: More conflict
fixes.
* parser/build.pl: Fully qualify all lib names. (Gtk+ packages
are now LFS-compliant in Debian...)
* parser/gapi2xml.pl: Fix for whitespace in fields, defines,
and docs.
* generator/BoxedGen.cs: Remove extraneous CallByName definition,
add "override" keyword to FromNative.
(Generate): Generate methods after fields.
* generator/ClassBase.cs: Change CallByName, FromNative to virtual.
(.ctor): Ignore "hidden" nodes. Set container on signal.
(GenSignals, GenMethods): Add "implementor" argument for interface
use.
(Get(Method|Signal|Property)Recursively): Rework to correctly
recurse interfaces.
(Implements): Added.
* generator/Ctor.cs (Initialize): Move clash initialization completely
out of Generate, so we can check for collisions.
* generator/Method.cs (GenerateDeclCommon): Check for duplicates,
for "new" keyword.
(Generate): Add "implementor" argument.
* generator/ObjectGen.cs (Generate): Initialize ctor clashes on
this and all parents, before generating.
(Ctors, InitializeCtors): Added.
* generator/Signal.cs: Store the container_type, check for
collisions.
* generator/StructGen.cs: Add "override" keyword to overriden methods.
* gtk/FileSelection.custom (ActionArea): Add "new" keyword.
svn path=/trunk/gtk-sharp/; revision=5782
2002-07-13 20:31:23 +00:00
|
|
|
if (elem.HasAttribute("new_flag") || (container_type != null && container_type.GetSignalRecursively (Name) != null) || (implementor != null && implementor.GetSignalRecursively (Name) != null))
|
2002-05-23 23:43:25 +00:00
|
|
|
sw.Write("new ");
|
2003-10-06 20:12:09 +00:00
|
|
|
sw.WriteLine("event " + EventHandlerQualifiedName + " " + Name + " {");
|
2002-05-23 23:43:25 +00:00
|
|
|
sw.WriteLine("\t\t\tadd {");
|
2004-03-16 19:43:04 +00:00
|
|
|
sw.WriteLine("\t\t\t\tif (value.Method.GetCustomAttributes(typeof(GLib.ConnectBeforeAttribute), false).Length > 0) {");
|
|
|
|
sw.WriteLine("\t\t\t\t\tif (BeforeHandlers[" + cname + "] == null)");
|
|
|
|
sw.Write("\t\t\t\t\t\tBeforeSignals[" + cname + "] = new " + qual_marsh);
|
2004-05-05 18:24:04 +00:00
|
|
|
sw.Write("(this, " + cname + ", value, System.Type.GetType(\"" + EventArgsQualifiedName);
|
2003-10-06 20:12:09 +00:00
|
|
|
if (EventArgsQualifiedName != "System.EventArgs")
|
2003-10-06 16:15:05 +00:00
|
|
|
sw.Write("," + gen_info.AssemblyName);
|
2004-03-16 19:43:04 +00:00
|
|
|
sw.WriteLine("\"), 0);");
|
|
|
|
sw.WriteLine("\t\t\t\t\telse");
|
2004-05-05 18:24:04 +00:00
|
|
|
sw.WriteLine("\t\t\t\t\t\t((GLib.SignalCallback) BeforeSignals [{0}]).AddDelegate (value);", cname);
|
2004-03-16 19:43:04 +00:00
|
|
|
sw.WriteLine("\t\t\t\t\tBeforeHandlers.AddHandler(" + cname + ", value);");
|
|
|
|
sw.WriteLine("\t\t\t\t} else {");
|
|
|
|
sw.WriteLine("\t\t\t\t\tif (AfterHandlers[" + cname + "] == null)");
|
|
|
|
sw.Write("\t\t\t\t\t\tAfterSignals[" + cname + "] = new " + qual_marsh);
|
2004-05-05 18:24:04 +00:00
|
|
|
sw.Write("(this, " + cname + ", value, System.Type.GetType(\"" + EventArgsQualifiedName);
|
2004-03-16 19:43:04 +00:00
|
|
|
if (EventArgsQualifiedName != "System.EventArgs")
|
|
|
|
sw.Write("," + gen_info.AssemblyName);
|
|
|
|
sw.WriteLine("\"), 1);");
|
|
|
|
sw.WriteLine("\t\t\t\t\telse");
|
2004-05-05 18:24:04 +00:00
|
|
|
sw.WriteLine("\t\t\t\t\t\t((GLib.SignalCallback) AfterSignals [{0}]).AddDelegate (value);", cname);
|
2004-03-16 19:43:04 +00:00
|
|
|
sw.WriteLine("\t\t\t\t\tAfterHandlers.AddHandler(" + cname + ", value);");
|
|
|
|
sw.WriteLine("\t\t\t\t}");
|
2002-05-23 23:43:25 +00:00
|
|
|
sw.WriteLine("\t\t\t}");
|
|
|
|
sw.WriteLine("\t\t\tremove {");
|
2004-03-16 21:21:11 +00:00
|
|
|
sw.WriteLine("\t\t\t\tSystem.ComponentModel.EventHandlerList event_list = AfterHandlers;");
|
|
|
|
sw.WriteLine("\t\t\t\tHashtable signals = AfterSignals;");
|
2004-03-16 19:43:04 +00:00
|
|
|
sw.WriteLine("\t\t\t\tif (value.Method.GetCustomAttributes(typeof(GLib.ConnectBeforeAttribute), false).Length > 0) {");
|
|
|
|
sw.WriteLine("\t\t\t\t\tevent_list = BeforeHandlers;");
|
|
|
|
sw.WriteLine("\t\t\t\t\tsignals = BeforeSignals;");
|
|
|
|
sw.WriteLine("\t\t\t\t}");
|
2004-05-05 18:24:04 +00:00
|
|
|
sw.WriteLine("\t\t\t\tGLib.SignalCallback cb = signals [{0}] as GLib.SignalCallback;", cname);
|
2004-03-16 19:43:04 +00:00
|
|
|
sw.WriteLine("\t\t\t\tevent_list.RemoveHandler(" + cname + ", value);");
|
2003-02-26 02:16:38 +00:00
|
|
|
sw.WriteLine("\t\t\t\tif (cb == null)");
|
|
|
|
sw.WriteLine("\t\t\t\t\treturn;");
|
|
|
|
sw.WriteLine();
|
|
|
|
sw.WriteLine("\t\t\t\tcb.RemoveDelegate (value);");
|
|
|
|
sw.WriteLine();
|
2004-03-16 19:43:04 +00:00
|
|
|
sw.WriteLine("\t\t\t\tif (event_list[" + cname + "] == null) {");
|
|
|
|
sw.WriteLine("\t\t\t\t\tsignals.Remove(" + cname + ");");
|
2003-02-26 02:16:38 +00:00
|
|
|
sw.WriteLine("\t\t\t\t\tcb.Dispose ();");
|
|
|
|
sw.WriteLine("\t\t\t\t}");
|
2002-05-23 23:43:25 +00:00
|
|
|
sw.WriteLine("\t\t\t}");
|
|
|
|
sw.WriteLine("\t\t}");
|
|
|
|
sw.WriteLine();
|
|
|
|
|
|
|
|
Statistics.SignalCount++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|