2003-10-06 Mike Kestner <mkestner@ximian.com>

* generator/InterfaceGen.cs (Generate): gen the EventHandlers for sigs
	* generator/Signal.cs (GetHandlerName): kill this and split it into
	EventHandlerName and EventHandlerArgsName props instead of the ugly
	out param hack.
	(GenEventHandler): make public void and add gen_info param. open
	stream with gen_info. use new *Name props.
	(Generate): only gen the EventHandler if we're genning the container,
	not for implementors.

svn path=/trunk/gtk-sharp/; revision=18684
This commit is contained in:
Mike Kestner 2003-10-06 20:12:09 +00:00
parent 06a02e97b4
commit 9877690874
3 changed files with 62 additions and 45 deletions

View file

@ -1,3 +1,14 @@
2003-10-06 Mike Kestner <mkestner@ximian.com>
* generator/InterfaceGen.cs (Generate): gen the EventHandlers for sigs
* generator/Signal.cs (GetHandlerName): kill this and split it into
EventHandlerName and EventHandlerArgsName props instead of the ugly
out param hack.
(GenEventHandler): make public void and add gen_info param. open
stream with gen_info. use new *Name props.
(Generate): only gen the EventHandler if we're genning the container,
not for implementors.
2003-10-06 Mike Kestner <mkestner@ximian.com>
* generator/CodeGenerator.cs (Main): use new ObjectGen.GenerateMappers.

View file

@ -33,8 +33,10 @@ namespace GtkSharp.Generation {
sw.WriteLine ();
foreach (Signal sig in sigs.Values) {
if (sig.Validate ())
if (sig.Validate ()) {
sig.GenerateDecl (sw);
sig.GenEventHandler (gen_info);
}
}
foreach (Method method in methods.Values) {

View file

@ -54,57 +54,65 @@ namespace GtkSharp.Generation {
public void GenerateDecl (StreamWriter sw)
{
string argsname;
string handler = GetHandlerName (out argsname);
if (handler != "EventHandler")
handler = container_type.NS + "Sharp." + handler;
if (elem.HasAttribute("new_flag") || (container_type != null && container_type.GetSignalRecursively (Name) != null))
sw.Write("new ");
sw.WriteLine ("\t\tevent " + handler + " " + Name + ";");
sw.WriteLine ("\t\tevent " + EventHandlerQualifiedName + " " + Name + ";");
}
private string GetHandlerName (out string argsname)
{
if (sig_handler.Name == "voidObjectSignal") {
argsname = "System.EventArgs";
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
return container_type.NS + "Sharp." + Name + "Args";
}
}
private string EventHandlerName {
get {
if (sig_handler.Name == "voidObjectSignal")
return "EventHandler";
}
argsname = Name + "Args";
else
return Name + "Handler";
}
}
private string GenHandler (out string argsname)
private string EventHandlerQualifiedName {
get {
if (sig_handler.Name == "voidObjectSignal")
return "System.EventHandler";
else
return container_type.NS + "Sharp." + Name + "Handler";
}
}
public void GenEventHandler (GenerationInfo gen_info)
{
string handler = GetHandlerName (out argsname);
if (handler == "EventHandler")
return handler;
if (EventHandlerName == "EventHandler")
return;
string ns = container_type.NS;
char sep = Path.DirectorySeparatorChar;
string dir = ".." + sep + ns.ToLower() + sep + "generated";
if (!Directory.Exists (dir))
Directory.CreateDirectory (dir);
StreamWriter sw = gen_info.OpenStream (ns + "Sharp." + EventHandlerName);
string filename = dir + sep + ns + "Sharp." + handler + ".cs";
FileStream stream = new FileStream (filename, FileMode.Create, FileAccess.Write);
StreamWriter sw = new StreamWriter (stream);
sw.WriteLine ("// This file was generated by the Gtk# Code generator.");
sw.WriteLine ("// Any changes made will be lost if regenerated.");
sw.WriteLine ();
sw.WriteLine ("namespace " + ns + "Sharp {");
sw.WriteLine ();
sw.WriteLine ("\tusing System;");
sw.WriteLine ();
sw.WriteLine ("\tpublic delegate void " + handler + "(object o, " + argsname + " args);");
sw.WriteLine ("\tpublic delegate void " + EventHandlerName + "(object o, " + EventArgsName + " args);");
sw.WriteLine ();
sw.WriteLine ("\tpublic class " + argsname + " : GtkSharp.SignalArgs {");
sw.WriteLine ("\tpublic class " + EventArgsName + " : GtkSharp.SignalArgs {");
if (parms != null) {
for (int i = 1; i < parms.Count; i++) {
sw.WriteLine ("\t\tpublic " + parms[i].CSType + " " + parms[i].StudlyName + "{");
@ -118,8 +126,6 @@ namespace GtkSharp.Generation {
sw.WriteLine ("\t}");
sw.WriteLine ("}");
sw.Close ();
argsname = ns + "Sharp." + argsname;
return ns + "Sharp." + handler;
}
public void Generate (GenerationInfo gen_info, ClassBase implementor)
@ -127,27 +133,25 @@ namespace GtkSharp.Generation {
StreamWriter sw = gen_info.Writer;
string cname = "\"" + elem.GetAttribute("cname") + "\"";
string ns;
if (implementor == null)
if (implementor == null) {
ns = container_type.NS;
else
GenEventHandler (gen_info);
} else
ns = implementor.NS;
sig_handler.Generate (ns, gen_info);
string qual_marsh = ns + "Sharp." + sig_handler.Name;
string argsname;
string handler = GenHandler (out argsname);
sw.WriteLine("\t\t[GLib.Signal("+ cname + ")]");
sw.Write("\t\tpublic ");
if (elem.HasAttribute("new_flag") || (container_type != null && container_type.GetSignalRecursively (Name) != null) || (implementor != null && implementor.GetSignalRecursively (Name) != null))
sw.Write("new ");
sw.WriteLine("event " + handler + " " + Name + " {");
sw.WriteLine("event " + EventHandlerQualifiedName + " " + Name + " {");
sw.WriteLine("\t\t\tadd {");
sw.WriteLine("\t\t\t\tif (EventList[" + cname + "] == null)");
sw.Write("\t\t\t\t\tSignals[" + cname + "] = new " + qual_marsh);
sw.Write("(this, Handle, " + cname + ", value, System.Type.GetType(\"" + argsname);
if (argsname != "System.EventArgs")
sw.Write("(this, Handle, " + cname + ", value, System.Type.GetType(\"" + EventArgsQualifiedName);
if (EventArgsQualifiedName != "System.EventArgs")
sw.Write("," + gen_info.AssemblyName);
sw.WriteLine("\"));\n\t\t\t\telse");
sw.WriteLine("\t\t\t\t\t((GtkSharp.SignalCallback) Signals [{0}]).AddDelegate (value);", cname);