Ryujinx-GtkSharp/generator/ClassBase.cs
Rachel Hestilow 7fb558bea0 2002-06-23 Rachel Hestilow <hestilow@ximian.com>
* generator/ClassBase.cs: Add accessors for methods and signals.
	Change GenSignals and GenMethods to public, as csc has a different
	idea of protected than mcs. Handle interface collisions in
	GenMethods.

	* generator/Method.cs: Add accessor Protection - "public" by default.

	* generator/ObjectGen.cs: Make sure wrapper's Signals hashtable only
	gets generated once. Generate a list of collisions for GenMethods.
	Remove dead foreach loop from Validate.

	* generator/Paramaters.cs (CreateSignature): Initialize last_param.

	* parser/Gtk.metadata: Add property & event collision renames
	for TextBuffer and OldEditable.

	* sample/makefile.win32: Reference atk-sharp.dll.

	* makefile.win32: Do not build gdk.imaging.

svn path=/trunk/gtk-sharp/; revision=5420
2002-06-23 03:38:02 +00:00

175 lines
3.6 KiB
C#

// GtkSharp.Generation.ClassBase.cs - Common code between object
// and interface wrappers
//
// Authors: Rachel Hestilow <hestilow@ximian.com>
// Mike Kestner <mkestner@speakeasy.net>
//
// (c) 2002 Rachel Hestilow, 2001-2002 Mike Kestner
namespace GtkSharp.Generation {
using System;
using System.Collections;
using System.IO;
using System.Xml;
public class ClassBase : GenBase {
protected Hashtable props = new Hashtable();
protected Hashtable sigs = new Hashtable();
protected Hashtable methods = new Hashtable();
protected ArrayList interfaces = null;
public Hashtable Methods {
get {
return methods;
}
}
public Hashtable Signals {
get {
return sigs;
}
}
protected ClassBase (XmlElement ns, XmlElement elem) : base (ns, elem) {
foreach (XmlNode node in elem.ChildNodes) {
XmlElement member = (XmlElement) node;
switch (node.Name) {
case "method":
methods.Add (member.GetAttribute ("name"), new Method (LibraryName, member, this));
break;
case "property":
props.Add (member.GetAttribute ("name"), new Property (member));
break;
case "signal":
sigs.Add (member.GetAttribute ("name"), new Signal (member));
break;
case "implements":
interfaces = ParseImplements (member);
break;
default:
break;
}
}
}
protected bool IsNodeNameHandled (string name)
{
switch (name) {
case "method":
case "property":
case "signal":
case "implements":
return true;
default:
return false;
}
}
public String MarshalType {
get
{
return "IntPtr";
}
}
public String CallByName (String var_name)
{
return var_name + ".Handle";
}
public String FromNative(String var)
{
return "(" + QualifiedName + ") GLib.Object.GetObject(" + var + ")";
}
protected void GenProperties (StreamWriter sw)
{
if (props == null)
return;
foreach (Property prop in props.Values) {
if (prop.Validate ())
prop.Generate (sw);
else
Console.WriteLine(" in Object " + Name);
}
}
public void GenSignals (StreamWriter sw)
{
if (sigs == null)
return;
foreach (Signal sig in sigs.Values) {
if (sig.Validate ())
sig.Generate (sw);
else
Console.WriteLine(" in Object " + Name);
}
}
private ArrayList ParseImplements (XmlElement member)
{
ArrayList ifaces = new ArrayList ();
foreach (XmlNode node in member.ChildNodes) {
if (node.Name != "interface")
continue;
XmlElement element = (XmlElement) node;
ifaces.Add (element.GetAttribute ("cname"));
}
return ifaces;
}
protected bool IgnoreMethod (Method method)
{
string mname = method.Name;
return ((mname.StartsWith("Set") || mname.StartsWith("Get")) &&
(props != null) && props.ContainsKey(mname.Substring(3)));
}
public void GenMethods (StreamWriter sw, Hashtable collisions)
{
if (methods == null)
return;
foreach (Method method in methods.Values) {
if (IgnoreMethod (method))
continue;
if (method.Validate ())
{
String oname = null, oprotection = null;
if (collisions != null && collisions.Contains (method.Name))
{
oname = method.Name;
oprotection = method.Protection;
method.Name = Name + "." + method.Name;
method.Protection = "";
}
method.Generate (sw);
if (oname != null)
{
method.Name = oname;
method.Protection = oprotection;
}
}
else
Console.WriteLine(" in Object " + Name);
}
}
public Method GetMethod (string name)
{
return (Method) methods[name];
}
}
}