2002-02-15 01:10:14 +00:00
|
|
|
// GtkSharp.Generation.SignalHandler.cs - The SignalHandler marshaling Class.
|
|
|
|
//
|
|
|
|
// Author: Mike Kestner <mkestner@speakeasy.net>
|
|
|
|
//
|
|
|
|
// (c) 2002 Mike Kestner
|
|
|
|
|
|
|
|
namespace GtkSharp.Generation {
|
|
|
|
|
|
|
|
using System;
|
|
|
|
using System.Collections;
|
|
|
|
using System.IO;
|
|
|
|
using System.Xml;
|
|
|
|
|
|
|
|
public class SignalHandler {
|
|
|
|
|
|
|
|
private static Hashtable handlers = new Hashtable ();
|
2002-07-16 23:14:35 +00:00
|
|
|
private string args_type;
|
2002-02-15 01:10:14 +00:00
|
|
|
|
2002-05-23 23:43:25 +00:00
|
|
|
public static String GetName(XmlElement sig)
|
2002-02-15 01:10:14 +00:00
|
|
|
{
|
|
|
|
XmlElement ret_elem = sig["return-type"];
|
|
|
|
if (ret_elem == null) {
|
|
|
|
Console.Write("Missing return-type ");
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
|
2002-07-16 23:14:35 +00:00
|
|
|
string retval = ret_elem.GetAttribute("type");
|
2002-02-15 01:10:14 +00:00
|
|
|
if (retval == "") {
|
|
|
|
Console.Write("Invalid return-type ");
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
|
2002-07-16 23:14:35 +00:00
|
|
|
string s_ret = SymbolTable.GetCSType(retval);
|
2002-07-26 06:08:52 +00:00
|
|
|
string p_ret = SymbolTable.GetMarshalReturnType(retval);
|
2002-02-15 01:10:14 +00:00
|
|
|
if ((s_ret == "") || (p_ret == "")) {
|
|
|
|
Console.Write("Funky type: " + retval);
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
|
2002-07-16 23:14:35 +00:00
|
|
|
string key = retval;
|
|
|
|
string pinv = "";
|
|
|
|
string name = SymbolTable.GetName(retval);
|
|
|
|
string argfields = "";
|
2002-02-15 01:10:14 +00:00
|
|
|
int pcnt = 0;
|
|
|
|
|
|
|
|
ArrayList parms = new ArrayList();
|
|
|
|
|
|
|
|
XmlElement params_elem = sig["parameters"];
|
|
|
|
if (params_elem == null) {
|
|
|
|
Console.Write("Missing parameters ");
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
|
|
|
|
foreach (XmlNode parm in params_elem.ChildNodes) {
|
2002-06-26 13:10:48 +00:00
|
|
|
if (!(parm is XmlElement) || parm.Name != "parameter") continue;
|
2002-02-15 01:10:14 +00:00
|
|
|
|
|
|
|
XmlElement elem = (XmlElement) parm;
|
2002-07-16 23:14:35 +00:00
|
|
|
string type = elem.GetAttribute("type");
|
|
|
|
string ptype = SymbolTable.GetMarshalType(type);
|
2002-02-15 01:10:14 +00:00
|
|
|
if (ptype == "") {
|
|
|
|
Console.Write("Funky type: " + type);
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
|
|
|
|
if (pcnt > 0) {
|
|
|
|
pinv += ", ";
|
|
|
|
}
|
2002-07-24 14:11:40 +00:00
|
|
|
|
2002-02-15 01:10:14 +00:00
|
|
|
pinv += (ptype + " arg" + pcnt);
|
|
|
|
parms.Add(type);
|
2002-05-23 23:43:25 +00:00
|
|
|
if (SymbolTable.IsObject(type)) {
|
2002-02-15 01:10:14 +00:00
|
|
|
name += "Object";
|
|
|
|
key += "Object";
|
|
|
|
} else {
|
2002-05-23 23:43:25 +00:00
|
|
|
name += SymbolTable.GetName(type);
|
2002-02-15 01:10:14 +00:00
|
|
|
key += type;
|
|
|
|
}
|
|
|
|
pcnt++;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (handlers.ContainsKey(name)) {
|
|
|
|
return (String) handlers[name];
|
|
|
|
}
|
|
|
|
|
|
|
|
String dir;
|
2002-03-27 01:24:56 +00:00
|
|
|
char sep = Path.DirectorySeparatorChar;
|
2002-02-15 01:10:14 +00:00
|
|
|
|
|
|
|
if (key.IndexOf("Gtk") >= 0) {
|
2002-03-27 01:24:56 +00:00
|
|
|
dir = ".." + sep + "gtk" + sep + "generated";
|
2002-02-15 01:10:14 +00:00
|
|
|
} else if (key.IndexOf("Gdk") >= 0) {
|
2002-03-27 01:24:56 +00:00
|
|
|
dir = ".." + sep + "gdk" + sep + "generated";
|
2002-02-15 01:10:14 +00:00
|
|
|
} else if (key.IndexOf("Atk") >= 0) {
|
2002-03-27 01:24:56 +00:00
|
|
|
dir = ".." + sep + "atk" + sep + "generated";
|
2002-02-15 01:10:14 +00:00
|
|
|
} else if (key.IndexOf("Pango") >= 0) {
|
2002-03-27 01:24:56 +00:00
|
|
|
dir = ".." + sep + "pango" + sep + "generated";
|
2002-06-26 Rachel Hestilow <hestilow@ximian.com>
* configure.in, makefile, makefile.win32: add gnome.
* doc/index.html, netdoc.xsl: Add gnome.
* gdk/Event.cs: New manual wrap for GdkEvent.
* generator/ClassBase.cs: Add methods GetProperty,
GetPropertyRecursively, GetMethodRecursively.
Move Parent property here from ObjectGen.cs. Pass this pointer
into Property.
* generator/Ctor.cs: Generate docs.
* generator/Method.cs, Property.cs: Tag method as "new" if a
Method/Property with the same name is found in the class hierarchy.
* generator/SignalHandler.cs: Correctly wrap complex signal argument
types. Add gnome directory.
* generator/SymbolTable.cs: Add manually wrapped types hash
(contains GLib.GSList and Gdk.Event). Add method IsManuallyWrapped.
* glib/SList.cs: Add constructor from IntPtr.
* glue/slist.c, glue/event.c: Added (field accessor glue).
* glue/Makefile.am: Update.
* parser/Gtk.metadata: Add new signal renames for new signals
exposed by GdkEvent changes.
* parser/README, parser/build.pl: Add libgnome, libgnomecanvas,
libgnomeui.
* parser/gapi2xml.pl: Handle literal-length array parameters,
and NULL property doc strings.
* sample/: Add new test GnomeHelloWorld.cs.
* gnome/: Added.
* parser/Gnome.metadata: Added.
svn path=/trunk/gtk-sharp/; revision=5461
2002-06-26 08:36:05 +00:00
|
|
|
} else if (key.IndexOf("Gnome") >= 0) {
|
|
|
|
dir = ".." + sep + "gnome" + sep + "generated";
|
2002-02-15 01:10:14 +00:00
|
|
|
} else {
|
2002-03-27 01:24:56 +00:00
|
|
|
dir = ".." + sep + "glib" + sep + "generated";
|
2002-02-15 01:10:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
String sname = name + "Signal";
|
|
|
|
String dname = name + "Delegate";
|
|
|
|
String cbname = name + "Callback";
|
|
|
|
|
|
|
|
handlers[name] = sname;
|
|
|
|
|
|
|
|
if (!Directory.Exists(dir)) {
|
|
|
|
Directory.CreateDirectory(dir);
|
|
|
|
}
|
|
|
|
|
2002-03-27 01:24:56 +00:00
|
|
|
String filename = dir + sep + sname + ".cs";
|
2002-02-15 01:10:14 +00:00
|
|
|
|
|
|
|
FileStream stream = new FileStream (filename, FileMode.Create, FileAccess.Write);
|
|
|
|
StreamWriter sw = new StreamWriter (stream);
|
|
|
|
|
|
|
|
sw.WriteLine ("// Generated File. Do not modify.");
|
|
|
|
sw.WriteLine ("// <c> 2001-2002 Mike Kestner");
|
|
|
|
sw.WriteLine ();
|
|
|
|
sw.WriteLine("namespace GtkSharp {");
|
|
|
|
sw.WriteLine();
|
|
|
|
sw.WriteLine("\tusing System;");
|
|
|
|
sw.WriteLine("\tusing System.Runtime.InteropServices;");
|
|
|
|
sw.WriteLine();
|
|
|
|
sw.Write("\tpublic delegate " + p_ret + " ");
|
|
|
|
sw.WriteLine(dname + "(" + pinv + ", int key);");
|
|
|
|
sw.WriteLine();
|
|
|
|
sw.WriteLine("\tpublic class " + sname + " : SignalCallback {");
|
|
|
|
sw.WriteLine();
|
|
|
|
sw.WriteLine("\t\tprivate static " + dname + " _Delegate;");
|
|
|
|
sw.WriteLine();
|
|
|
|
sw.Write("\t\tprivate static " + s_ret + " ");
|
|
|
|
sw.WriteLine(cbname + "(" + pinv + ", int key)");
|
|
|
|
sw.WriteLine("\t\t{");
|
|
|
|
sw.WriteLine("\t\t\tif (!_Instances.Contains(key))");
|
2002-07-20 15:00:10 +00:00
|
|
|
sw.WriteLine("\t\t\t\tthrow new Exception(\"Unexpected signal key \" + key);");
|
2002-02-15 01:10:14 +00:00
|
|
|
sw.WriteLine();
|
|
|
|
sw.WriteLine("\t\t\t" + sname + " inst = (" + sname + ") _Instances[key];");
|
2002-07-16 23:14:35 +00:00
|
|
|
if ((s_ret == "void") && (parms.Count == 1)) {
|
|
|
|
sw.WriteLine("\t\t\tEventHandler h = (EventHandler) inst._handler;");
|
|
|
|
sw.WriteLine("\t\t\th (inst._obj, new EventArgs ());");
|
|
|
|
sw.WriteLine("\t\t}");
|
|
|
|
sw.WriteLine();
|
|
|
|
} else {
|
|
|
|
sw.WriteLine("\t\t\tSignalArgs args = (SignalArgs) Activator.CreateInstance (inst._argstype);");
|
|
|
|
if (parms.Count > 1) {
|
|
|
|
sw.WriteLine("\t\t\targs.Args = new object[" + (parms.Count-1) + "];");
|
|
|
|
}
|
|
|
|
for (int idx=1; idx < parms.Count; idx++) {
|
|
|
|
if (SymbolTable.IsObject((String)parms[idx])) {
|
|
|
|
sw.Write("\t\t\targs.Args[" + (idx-1) + "] ");
|
|
|
|
sw.WriteLine("= GLib.Object.GetObject(arg" + idx + ");");
|
|
|
|
} else {
|
|
|
|
string ctype = (string) parms[idx];
|
|
|
|
sw.WriteLine("\t\t\targs.Args[" + (idx-1) + "] = " + SymbolTable.FromNative (ctype, "arg" + idx) + ";");
|
|
|
|
ClassBase wrapper = SymbolTable.GetClassGen (ctype);
|
2002-07-26 06:08:52 +00:00
|
|
|
if ((wrapper != null && ((wrapper is ObjectGen) || (wrapper is OpaqueGen))) || SymbolTable.IsManuallyWrapped (ctype)) {
|
2002-07-16 23:14:35 +00:00
|
|
|
sw.WriteLine("\t\t\tif (args.Args[" + (idx-1) + "] == null)");
|
|
|
|
sw.WriteLine("\t\t\t\targs.Args[{0}] = new {1}(arg{2});", idx-1, SymbolTable.GetCSType (ctype), idx);
|
|
|
|
}
|
2002-06-26 Rachel Hestilow <hestilow@ximian.com>
* configure.in, makefile, makefile.win32: add gnome.
* doc/index.html, netdoc.xsl: Add gnome.
* gdk/Event.cs: New manual wrap for GdkEvent.
* generator/ClassBase.cs: Add methods GetProperty,
GetPropertyRecursively, GetMethodRecursively.
Move Parent property here from ObjectGen.cs. Pass this pointer
into Property.
* generator/Ctor.cs: Generate docs.
* generator/Method.cs, Property.cs: Tag method as "new" if a
Method/Property with the same name is found in the class hierarchy.
* generator/SignalHandler.cs: Correctly wrap complex signal argument
types. Add gnome directory.
* generator/SymbolTable.cs: Add manually wrapped types hash
(contains GLib.GSList and Gdk.Event). Add method IsManuallyWrapped.
* glib/SList.cs: Add constructor from IntPtr.
* glue/slist.c, glue/event.c: Added (field accessor glue).
* glue/Makefile.am: Update.
* parser/Gtk.metadata: Add new signal renames for new signals
exposed by GdkEvent changes.
* parser/README, parser/build.pl: Add libgnome, libgnomecanvas,
libgnomeui.
* parser/gapi2xml.pl: Handle literal-length array parameters,
and NULL property doc strings.
* sample/: Add new test GnomeHelloWorld.cs.
* gnome/: Added.
* parser/Gnome.metadata: Added.
svn path=/trunk/gtk-sharp/; revision=5461
2002-06-26 08:36:05 +00:00
|
|
|
}
|
2002-02-15 01:10:14 +00:00
|
|
|
}
|
2002-07-16 23:14:35 +00:00
|
|
|
sw.WriteLine("\t\t\tobject[] argv = new object[2];");
|
|
|
|
sw.WriteLine("\t\t\targv[0] = inst._obj;");
|
|
|
|
sw.WriteLine("\t\t\targv[1] = args;");
|
|
|
|
sw.WriteLine("\t\t\tinst._handler.DynamicInvoke(argv);");
|
|
|
|
if (retval != "void") {
|
|
|
|
sw.WriteLine("\t\t\treturn (" + s_ret + ") args.RetVal;");
|
|
|
|
}
|
|
|
|
sw.WriteLine("\t\t}");
|
|
|
|
sw.WriteLine();
|
2002-02-15 01:10:14 +00:00
|
|
|
}
|
2002-06-22 22:12:51 +00:00
|
|
|
sw.Write("\t\t[DllImport(\"gobject-2.0\")]");
|
2002-02-15 01:10:14 +00:00
|
|
|
sw.Write("\t\tstatic extern void g_signal_connect_data(");
|
|
|
|
sw.Write("IntPtr obj, String name, " + dname + " cb, int key, IntPtr p,");
|
|
|
|
sw.WriteLine(" int flags);");
|
|
|
|
sw.WriteLine();
|
|
|
|
sw.Write("\t\tpublic " + sname + "(GLib.Object obj, IntPtr raw, ");
|
2002-07-16 23:14:35 +00:00
|
|
|
sw.WriteLine("String name, MulticastDelegate eh, Type argstype) : base(obj, eh, argstype)");
|
2002-02-15 01:10:14 +00:00
|
|
|
sw.WriteLine("\t\t{");
|
|
|
|
sw.WriteLine("\t\t\tif (_Delegate == null) {");
|
|
|
|
sw.WriteLine("\t\t\t\t_Delegate = new " + dname + "(" + cbname + ");");
|
|
|
|
sw.WriteLine("\t\t\t}");
|
|
|
|
sw.Write("\t\t\tg_signal_connect_data(raw, name, ");
|
|
|
|
sw.WriteLine("_Delegate, _key, new IntPtr(0), 0);");
|
|
|
|
sw.WriteLine("\t\t}");
|
|
|
|
sw.WriteLine();
|
|
|
|
sw.WriteLine("\t\t~" + sname + "()");
|
|
|
|
sw.WriteLine("\t\t{");
|
|
|
|
sw.WriteLine("\t\t\t_Instances.Remove(_key);");
|
|
|
|
sw.WriteLine("\t\t\tif(_Instances.Count == 0) {");
|
|
|
|
sw.WriteLine("\t\t\t\t_Delegate = null;");
|
|
|
|
sw.WriteLine("\t\t\t}");
|
|
|
|
sw.WriteLine("\t\t}");
|
|
|
|
sw.WriteLine("\t}");
|
|
|
|
sw.WriteLine("}");
|
|
|
|
sw.Close();
|
|
|
|
|
|
|
|
return sname;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|