2002-05-23 23:43:25 +00:00
|
|
|
// GtkSharp.Generation.Property.cs - The Property Generatable.
|
|
|
|
//
|
|
|
|
// Author: Mike Kestner <mkestner@speakeasy.net>
|
|
|
|
//
|
|
|
|
// (c) 2001-2002 Mike Kestner
|
|
|
|
|
|
|
|
namespace GtkSharp.Generation {
|
|
|
|
|
|
|
|
using System;
|
|
|
|
using System.Collections;
|
|
|
|
using System.IO;
|
|
|
|
using System.Xml;
|
|
|
|
|
|
|
|
public class Property {
|
|
|
|
|
|
|
|
private XmlElement elem;
|
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
|
|
|
private ClassBase container_type;
|
2002-05-23 23:43:25 +00:00
|
|
|
|
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
|
|
|
public string Name {
|
|
|
|
get {
|
|
|
|
return elem.GetAttribute ("name");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public Property (XmlElement elem, ClassBase container_type)
|
2002-05-23 23:43:25 +00:00
|
|
|
{
|
|
|
|
this.elem = elem;
|
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
|
|
|
this.container_type = container_type;
|
2002-05-23 23:43:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public bool Validate ()
|
|
|
|
{
|
|
|
|
string c_type = elem.GetAttribute("type");
|
2003-05-19 02:45:17 +00:00
|
|
|
SymbolTable table = SymbolTable.Table;
|
|
|
|
string cs_type = table.GetCSType(c_type);
|
2002-05-23 23:43:25 +00:00
|
|
|
|
|
|
|
if (cs_type == "") {
|
|
|
|
Console.Write("Property has unknown Type {0} ", c_type);
|
|
|
|
Statistics.ThrottledCount++;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2003-05-19 02:45:17 +00:00
|
|
|
if (table.IsInterface(c_type)) {
|
2002-05-23 23:43:25 +00:00
|
|
|
// FIXME: Handle interface props properly.
|
|
|
|
Console.Write("Interface property detected ");
|
|
|
|
Statistics.ThrottledCount++;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2003-10-05 00:20:17 +00:00
|
|
|
public void Generate (GenerationInfo gen_info)
|
2002-05-23 23:43:25 +00:00
|
|
|
{
|
2003-05-19 02:45:17 +00:00
|
|
|
SymbolTable table = SymbolTable.Table;
|
2003-10-05 00:20:17 +00:00
|
|
|
StreamWriter sw = gen_info.Writer;
|
2003-05-19 02:45:17 +00:00
|
|
|
|
2002-05-23 23:43:25 +00:00
|
|
|
string c_type = elem.GetAttribute("type");
|
2003-05-19 02:45:17 +00:00
|
|
|
string cs_type = table.GetCSType(c_type);
|
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
|
|
|
string modifiers = "";
|
|
|
|
|
|
|
|
if (elem.HasAttribute("new_flag") || (container_type.Parent != null && container_type.Parent.GetPropertyRecursively (Name) != null))
|
|
|
|
modifiers = "new ";
|
2002-05-23 23:43:25 +00:00
|
|
|
|
|
|
|
XmlElement parent = (XmlElement) elem.ParentNode;
|
2002-08-04 04:23:13 +00:00
|
|
|
string name = Name;
|
|
|
|
if (name == container_type.Name) {
|
2002-05-23 23:43:25 +00:00
|
|
|
name += "Prop";
|
|
|
|
}
|
2002-06-05 21:59:10 +00:00
|
|
|
string cname = "\"" + elem.GetAttribute("cname") + "\"";
|
2002-05-23 23:43:25 +00:00
|
|
|
|
|
|
|
string v_type = "";
|
2003-05-19 02:45:17 +00:00
|
|
|
if (table.IsEnum(c_type)) {
|
2002-06-24 22:04:10 +00:00
|
|
|
v_type = "(int) (GLib.EnumWrapper)";
|
2003-05-19 02:45:17 +00:00
|
|
|
} else if (table.IsInterface(c_type)) {
|
2002-05-23 23:43:25 +00:00
|
|
|
// FIXME: Handle interface props properly.
|
|
|
|
Console.Write("Interface property detected ");
|
|
|
|
Statistics.ThrottledCount++;
|
|
|
|
return;
|
2003-05-19 02:45:17 +00:00
|
|
|
} else if (table.IsObject(c_type)) {
|
2002-07-30 23:02:12 +00:00
|
|
|
v_type = "(GLib.UnwrappedObject)";
|
2003-05-19 02:45:17 +00:00
|
|
|
} else if (table.IsBoxed (c_type)) {
|
2002-06-24 22:04:10 +00:00
|
|
|
v_type = "(GLib.Boxed)";
|
2003-05-19 02:45:17 +00:00
|
|
|
} else if (table.IsOpaque (c_type)) {
|
2002-07-26 06:08:52 +00:00
|
|
|
v_type = "(GLib.Opaque)";
|
2002-05-23 23:43:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (elem.HasAttribute("construct-only") && !elem.HasAttribute("readable")) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2002-08-04 04:23:13 +00:00
|
|
|
bool has_getter = false;
|
|
|
|
bool has_setter = false;
|
|
|
|
Method getter = container_type.GetMethod("Get" + Name);
|
|
|
|
Method setter = container_type.GetMethod("Set" + Name);
|
|
|
|
|
2002-08-09 04:27:15 +00:00
|
|
|
if (getter != null && getter.Validate() && getter.IsGetter && getter.ReturnType == cs_type) {
|
2002-08-04 04:23:13 +00:00
|
|
|
has_getter = true;
|
|
|
|
getter.GenerateImport(sw);
|
|
|
|
}
|
|
|
|
if (setter != null && setter.Validate() && setter.IsSetter) {
|
|
|
|
has_setter = true;
|
|
|
|
setter.GenerateImport(sw);
|
|
|
|
}
|
|
|
|
|
2003-12-03 23:08:14 +00:00
|
|
|
if (has_setter && setter.Signature.Types != cs_type)
|
|
|
|
cs_type = setter.Signature.Types;
|
2002-08-04 04:23:13 +00:00
|
|
|
else if (has_getter && getter.ReturnType != cs_type)
|
|
|
|
cs_type = getter.ReturnType;
|
|
|
|
|
2002-06-24 22:04:10 +00:00
|
|
|
sw.WriteLine();
|
|
|
|
|
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
|
|
|
sw.WriteLine("\t\tpublic " + modifiers + cs_type + " " + name + " {");
|
2002-08-04 04:23:13 +00:00
|
|
|
if (has_getter) {
|
|
|
|
sw.Write("\t\t\tget ");
|
2003-10-05 00:20:17 +00:00
|
|
|
getter.GenerateBody(gen_info, "\t");
|
2002-08-04 04:23:13 +00:00
|
|
|
sw.WriteLine();
|
|
|
|
} else if (elem.HasAttribute("readable")) {
|
2002-05-23 23:43:25 +00:00
|
|
|
sw.WriteLine("\t\t\tget {");
|
2002-06-05 21:59:10 +00:00
|
|
|
sw.WriteLine("\t\t\t\tGLib.Value val = new GLib.Value (Handle, " + cname + ");");
|
|
|
|
sw.WriteLine("\t\t\t\tGetProperty(" + cname + ", val);");
|
2003-10-15 20:13:50 +00:00
|
|
|
if (table.IsObject (c_type)) {
|
2002-07-30 23:02:12 +00:00
|
|
|
sw.WriteLine("\t\t\t\tSystem.IntPtr raw_ret = (System.IntPtr) {0} val;", v_type);
|
2003-05-19 02:45:17 +00:00
|
|
|
sw.WriteLine("\t\t\t\t" + cs_type + " ret = " + table.FromNativeReturn(c_type, "raw_ret") + ";");
|
2003-10-09 05:16:37 +00:00
|
|
|
if (!table.IsBoxed (c_type) && !table.IsObject (c_type))
|
2002-07-30 23:02:12 +00:00
|
|
|
sw.WriteLine("\t\t\t\tif (ret == null) ret = new " + cs_type + "(raw_ret);");
|
2003-10-15 20:13:50 +00:00
|
|
|
} else if (table.IsOpaque (c_type) || table.IsBoxed (c_type)) {
|
|
|
|
sw.WriteLine("\t\t\t\tSystem.IntPtr raw_ret = val.Handle;");
|
|
|
|
sw.WriteLine("\t\t\t\t" + cs_type + " ret = " + table.FromNativeReturn(c_type, "raw_ret") + ";");
|
2002-07-26 06:08:52 +00:00
|
|
|
} else {
|
2002-06-24 23:38:51 +00:00
|
|
|
sw.Write("\t\t\t\t" + cs_type + " ret = ");
|
2002-07-30 23:02:12 +00:00
|
|
|
sw.Write ("(" + cs_type + ") ");
|
|
|
|
if (v_type != "") {
|
|
|
|
sw.Write(v_type + " ");
|
2002-06-24 23:38:51 +00:00
|
|
|
}
|
2002-07-30 23:02:12 +00:00
|
|
|
sw.WriteLine("val;");
|
2002-06-24 23:38:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
sw.WriteLine("\t\t\t\treturn ret;");
|
2002-05-23 23:43:25 +00:00
|
|
|
sw.WriteLine("\t\t\t}");
|
|
|
|
}
|
|
|
|
|
2002-08-04 04:23:13 +00:00
|
|
|
if (has_setter) {
|
|
|
|
sw.Write("\t\t\tset ");
|
2003-10-05 00:20:17 +00:00
|
|
|
setter.GenerateBody(gen_info, "\t");
|
2002-08-04 04:23:13 +00:00
|
|
|
sw.WriteLine();
|
|
|
|
} else if (elem.HasAttribute("writeable") && !elem.HasAttribute("construct-only")) {
|
2002-05-23 23:43:25 +00:00
|
|
|
sw.WriteLine("\t\t\tset {");
|
2003-10-28 15:45:35 +00:00
|
|
|
sw.Write("\t\t\t\tSetProperty(" + cname + ", ");
|
2003-05-19 02:45:17 +00:00
|
|
|
if (table.IsEnum(c_type)) {
|
2003-10-28 15:45:35 +00:00
|
|
|
sw.WriteLine("new GLib.Value(Handle, " + cname + ", new GLib.EnumWrapper ((int) value, {0})));", table.IsEnumFlags (c_type) ? "true" : "false");
|
2003-05-19 02:45:17 +00:00
|
|
|
} else if (table.IsBoxed (c_type)) {
|
2003-10-28 15:45:35 +00:00
|
|
|
sw.WriteLine("(GLib.Value) (value));");
|
2003-10-15 20:13:50 +00:00
|
|
|
} else if (table.IsOpaque (c_type)) {
|
2003-10-28 15:45:35 +00:00
|
|
|
sw.WriteLine("new GLib.Value(Handle, " + cname + ", value));");
|
2002-06-24 22:04:10 +00:00
|
|
|
} else {
|
2003-10-28 15:45:35 +00:00
|
|
|
sw.Write("new GLib.Value(");
|
2003-05-19 02:45:17 +00:00
|
|
|
if (v_type != "" && !(table.IsObject (c_type) || table.IsOpaque (c_type))) {
|
2002-06-24 22:04:10 +00:00
|
|
|
sw.Write(v_type + " ");
|
|
|
|
}
|
|
|
|
sw.WriteLine("value));");
|
2002-05-23 23:43:25 +00:00
|
|
|
}
|
|
|
|
sw.WriteLine("\t\t\t}");
|
|
|
|
}
|
|
|
|
|
|
|
|
sw.WriteLine("\t\t}");
|
|
|
|
sw.WriteLine();
|
|
|
|
|
|
|
|
Statistics.PropCount++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|