2002-01-06 13:33:25 +00:00
|
|
|
// GtkSharp.Generation.ObjectGen.cs - The Object Generatable.
|
|
|
|
//
|
|
|
|
// Author: Mike Kestner <mkestner@speakeasy.net>
|
|
|
|
//
|
|
|
|
// (c) 2001 Mike Kestner
|
|
|
|
|
|
|
|
namespace GtkSharp.Generation {
|
|
|
|
|
|
|
|
using System;
|
2002-02-03 03:44:10 +00:00
|
|
|
using System.Collections;
|
2002-01-06 13:33:25 +00:00
|
|
|
using System.IO;
|
|
|
|
using System.Xml;
|
|
|
|
|
|
|
|
public class ObjectGen : StructBase, IGeneratable {
|
|
|
|
|
|
|
|
public ObjectGen (String ns, XmlElement elem) : base (ns, elem) {}
|
|
|
|
|
|
|
|
public String MarshalType {
|
|
|
|
get
|
|
|
|
{
|
|
|
|
return "IntPtr";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public String CallByName (String var_name)
|
|
|
|
{
|
2002-02-06 20:09:14 +00:00
|
|
|
return var_name + ".Handle";
|
2002-01-06 13:33:25 +00:00
|
|
|
}
|
|
|
|
|
2002-02-08 23:56:27 +00:00
|
|
|
public String FromNative(String var)
|
|
|
|
{
|
2002-02-10 23:11:25 +00:00
|
|
|
return "(" + QualifiedName + ") GLib.Object.GetObject(" + var + ")";
|
2002-02-08 23:56:27 +00:00
|
|
|
}
|
|
|
|
|
2002-01-06 13:33:25 +00:00
|
|
|
public void Generate (SymbolTable table)
|
|
|
|
{
|
2002-01-07 00:25:51 +00:00
|
|
|
if (!Directory.Exists("..\\" + ns.ToLower() + "\\generated")) {
|
|
|
|
Directory.CreateDirectory("..\\"+ns.ToLower()+"\\generated");
|
|
|
|
}
|
2002-01-06 13:33:25 +00:00
|
|
|
String filename = "..\\" + ns.ToLower() + "\\generated\\" + Name + ".cs";
|
|
|
|
|
|
|
|
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 Mike Kestner");
|
|
|
|
sw.WriteLine ();
|
|
|
|
|
|
|
|
sw.WriteLine ("namespace " + ns + " {");
|
|
|
|
sw.WriteLine ();
|
|
|
|
|
|
|
|
sw.WriteLine ("\tusing System;");
|
|
|
|
sw.WriteLine ("\tusing System.Collections;");
|
|
|
|
sw.WriteLine ("\tusing System.Runtime.InteropServices;");
|
|
|
|
sw.WriteLine ();
|
|
|
|
|
|
|
|
String parent = elem.GetAttribute("parent");
|
|
|
|
String cs_parent = table.GetCSType(parent);
|
|
|
|
sw.Write ("\tpublic class " + Name);
|
|
|
|
if (cs_parent == "") {
|
|
|
|
sw.WriteLine (" {");
|
2002-01-07 23:30:01 +00:00
|
|
|
Console.WriteLine ("Object " + Name + " Unknown parent " + parent);
|
2002-01-06 13:33:25 +00:00
|
|
|
} else {
|
|
|
|
sw.WriteLine (" : " + cs_parent + " {");
|
|
|
|
}
|
|
|
|
sw.WriteLine ();
|
|
|
|
|
2002-02-03 03:44:10 +00:00
|
|
|
sw.WriteLine("\t\tpublic " + Name + "(IntPtr raw) : base(raw) {}");
|
|
|
|
sw.WriteLine();
|
|
|
|
|
|
|
|
Hashtable clash_map = new Hashtable();
|
|
|
|
|
2002-01-06 13:33:25 +00:00
|
|
|
foreach (XmlNode node in elem.ChildNodes) {
|
|
|
|
|
|
|
|
XmlElement member = (XmlElement) node;
|
|
|
|
|
|
|
|
switch (node.Name) {
|
|
|
|
case "field":
|
2002-01-10 15:01:31 +00:00
|
|
|
//if (!GenField(member, table, sw)) {
|
|
|
|
// Console.WriteLine("in object " + CName);
|
|
|
|
//}
|
2002-01-06 13:33:25 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case "callback":
|
|
|
|
break;
|
|
|
|
|
|
|
|
case "constructor":
|
2002-02-03 03:44:10 +00:00
|
|
|
if (!GenCtor(member, table, sw, clash_map)) {
|
2002-01-17 Mike Kestner <mkestner@speakeasy.net>
* generator/BoxedGen.cs : Removed Name, CName, and QualifiedName.
* generator/ObjectGen.cs : Removed Name, CName, and QualifiedName.
* generator/StructBase.cs : Add Name, CName, and QualifiedName. Add
GenCtor method. Stub GetCallString, GetImportSig, and GetSignature
methods.
* generator/StructGen.cs : Removed Name, CName, and QualifiedName.
* generator/SymbolTable.cs : Add GetDllName method.
* parser/gapi2xml.pl : Fix a couple <parameters> bugs.
svn path=/trunk/gtk-sharp/; revision=2030
2002-01-17 23:44:56 +00:00
|
|
|
Console.WriteLine("in object " + CName);
|
|
|
|
}
|
2002-01-06 13:33:25 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case "method":
|
2002-02-08 23:56:27 +00:00
|
|
|
if (!GenMethod(member, table, sw)) {
|
|
|
|
Console.WriteLine("in object " + CName);
|
|
|
|
}
|
2002-01-06 13:33:25 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case "property":
|
2002-01-12 02:08:16 +00:00
|
|
|
if (!GenProperty(member, table, sw)) {
|
|
|
|
Console.WriteLine("in object " + CName);
|
|
|
|
}
|
2002-01-06 13:33:25 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case "signal":
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
Console.WriteLine ("Unexpected node");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2002-02-03 03:44:10 +00:00
|
|
|
|
|
|
|
if (!clash_map.ContainsKey("")) {
|
|
|
|
sw.WriteLine("\t\tpublic " + Name + "() : base(){}");
|
|
|
|
sw.WriteLine();
|
|
|
|
}
|
2002-01-06 13:33:25 +00:00
|
|
|
|
|
|
|
sw.WriteLine ("\t}");
|
|
|
|
sw.WriteLine ();
|
|
|
|
sw.WriteLine ("}");
|
|
|
|
|
|
|
|
sw.Flush();
|
|
|
|
sw.Close();
|
2002-01-12 02:08:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public bool GenProperty (XmlElement prop, SymbolTable table, StreamWriter sw)
|
|
|
|
{
|
|
|
|
String c_type = prop.GetAttribute("type");
|
|
|
|
|
|
|
|
char[] ast = {'*'};
|
|
|
|
c_type = c_type.TrimEnd(ast);
|
|
|
|
String cs_type = table.GetCSType(c_type);
|
|
|
|
String m_type;
|
|
|
|
|
|
|
|
if (table.IsObject(c_type)) {
|
|
|
|
m_type = "GLib.Object";
|
2002-01-17 00:26:46 +00:00
|
|
|
} else if (table.IsBoxed(c_type)) {
|
|
|
|
m_type = "GtkSharp.Boxed";
|
|
|
|
} else if (table.IsInterface(c_type)) {
|
|
|
|
// FIXME: Handle interface props properly.
|
|
|
|
Console.Write("Interface property detected ");
|
|
|
|
return true;
|
2002-01-12 02:08:16 +00:00
|
|
|
} else {
|
|
|
|
m_type = table.GetMarshalType(c_type);
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((cs_type == "") || (m_type == "")) {
|
|
|
|
Console.Write("Property has unknown Type {0} ", c_type);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (prop.HasAttribute("construct-only") && !prop.HasAttribute("readable")) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
XmlElement parent = (XmlElement) prop.ParentNode;
|
|
|
|
String name = prop.GetAttribute("name");
|
|
|
|
if (name == parent.GetAttribute("name")) {
|
|
|
|
name += "Prop";
|
|
|
|
}
|
|
|
|
|
|
|
|
sw.WriteLine("\t\tpublic " + cs_type + " " + name + " {");
|
|
|
|
if (prop.HasAttribute("readable")) {
|
|
|
|
sw.WriteLine("\t\t\tget {");
|
|
|
|
sw.WriteLine("\t\t\t\t" + m_type + " val;");
|
|
|
|
sw.WriteLine("\t\t\t\tGetProperty(\"" + prop.GetAttribute("cname") + "\", out val);");
|
|
|
|
sw.Write("\t\t\t\treturn ");
|
|
|
|
if (cs_type != m_type) {
|
|
|
|
sw.Write("(" + cs_type + ") ");
|
|
|
|
}
|
|
|
|
sw.WriteLine("val;");
|
|
|
|
sw.WriteLine("\t\t\t}");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (prop.HasAttribute("writeable") && !prop.HasAttribute("construct-only")) {
|
|
|
|
sw.WriteLine("\t\t\tset {");
|
|
|
|
sw.WriteLine("\t\t\t\tSetProperty(\"" + prop.GetAttribute("cname") + "\", (" + m_type + ") value);");
|
|
|
|
sw.WriteLine("\t\t\t}");
|
|
|
|
}
|
|
|
|
|
|
|
|
sw.WriteLine("\t\t}");
|
|
|
|
sw.WriteLine();
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
2002-02-10 23:11:25 +00:00
|
|
|
|
|
|
|
public bool GenSignal (XmlElement sig, SymbolTable table, StreamWriter sw)
|
|
|
|
{
|
|
|
|
String cname = "\"" + sig.GetAttribute("cname") + "\"";
|
|
|
|
|
|
|
|
String marsh = "blah"; // SignalHandler.GetName(sig);
|
|
|
|
if (marsh == "") {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
sw.WriteLine("\t\t/// <summary> " + cname + " Event </summary>");
|
|
|
|
sw.WriteLine("\t\t/// <remarks>");
|
|
|
|
// FIXME: Generate some signal docs
|
|
|
|
sw.WriteLine("\t\t/// </remarks>");
|
|
|
|
sw.WriteLine();
|
|
|
|
sw.WriteLine("\t\tpublic event EventHandler " + cname + " {");
|
|
|
|
sw.WriteLine("\t\t\tadd {");
|
|
|
|
sw.WriteLine("\t\t\t\tif (Events [" + cname + "] == null)");
|
|
|
|
sw.Write("\t\t\t\t\tSignals[" + cname + "] = new " + marsh);
|
|
|
|
sw.WriteLine("(this, Handle, " + cname + ", value);");
|
|
|
|
sw.WriteLine("\t\t\t\tEvents.AddHandler(" + cname + ", value);");
|
|
|
|
sw.WriteLine("\t\t\t}");
|
|
|
|
sw.WriteLine("\t\t\tremove {");
|
|
|
|
sw.WriteLine("\t\t\t\tEvents.RemoveHandler(" + cname + ", value);");
|
|
|
|
sw.WriteLine("\t\t\t\tif (Events[" + cname + "] == null)");
|
|
|
|
sw.WriteLine("\t\t\t\t\tSignals.Remove(" + cname + ");");
|
|
|
|
sw.WriteLine("\t\t\t}");
|
|
|
|
sw.WriteLine("\t\t}");
|
|
|
|
sw.WriteLine();
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
2002-01-06 13:33:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|