mirror of
https://github.com/Ryujinx/GtkSharp.git
synced 2025-01-11 20:15:34 +00:00
967e3e9c5a
* generator/ClassBase.cs: Change hasDefaultConstructor to protected, adjust now that it is an attr and not a subnode. Also add virtual property AssignToName (for ctors). * generator/Ctor.cs: Add property ForceStatic. (Generate): Optimize return code a bit for the static case. * generator/Method.cs: Assign to a "raw_ret" pointer before calling FromNativeReturn. * generator/Parameters.cs: Change "out ref" to "out", not "ref". * generator/Property.cs: Fix to work correctly with all object and struct types (mostly just some if-cases added). * generator/SignalHandler.cs: Remove args_type and argfields (unused). (Generate): Initialize struct if necessary. * generator/StructBase.cs: Massive reworking to support methods, ctors, etc. * generator/SymbolTable.cs: Add GdkAtom and gconstpointer simple types. * glib/Boxed.cs: Accept both IntPtr and object ctors. Add access for both. * glib/Opaque.cs: Fix copy/pasted copyright notice, remove data and event fields. Fix docs. * glib/Value.cs: Work correctly with boxed properties. * gnome/Modules.cs: Use new struct ctors. * gnome/Program.custom: Remove Get, this is being generated now. * parser/Gdk.metadata: Fix the drawable classes to inherit correctly. * parser/Metadata.pm: Change per-class attributes to actually be attributes. * parser/Gtk.metadata: Add a dummy attribute value for disabledefaultctor. * parser/gapi2xml.pl: Add hacks for the (broken) Drawable and Bitmap typedefs. * sample/test/TestColorSelection.cs: Display color string in hex format, update to use IsNull instead of == null, and size dialog to look pretty. * sample/Size.cs: Added. svn path=/trunk/gtk-sharp/; revision=6264
140 lines
4.2 KiB
C#
140 lines
4.2 KiB
C#
// 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;
|
|
private ClassBase container_type;
|
|
|
|
public string Name {
|
|
get {
|
|
return elem.GetAttribute ("name");
|
|
}
|
|
}
|
|
|
|
public Property (XmlElement elem, ClassBase container_type)
|
|
{
|
|
this.elem = elem;
|
|
this.container_type = container_type;
|
|
}
|
|
|
|
public bool Validate ()
|
|
{
|
|
string c_type = elem.GetAttribute("type");
|
|
string cs_type = SymbolTable.GetCSType(c_type);
|
|
|
|
if (cs_type == "") {
|
|
Console.Write("Property has unknown Type {0} ", c_type);
|
|
Statistics.ThrottledCount++;
|
|
return false;
|
|
}
|
|
|
|
if (SymbolTable.IsInterface(c_type)) {
|
|
// FIXME: Handle interface props properly.
|
|
Console.Write("Interface property detected ");
|
|
Statistics.ThrottledCount++;
|
|
return false;
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
public void Generate (StreamWriter sw)
|
|
{
|
|
string c_type = elem.GetAttribute("type");
|
|
string cs_type = SymbolTable.GetCSType(c_type);
|
|
string modifiers = "";
|
|
|
|
if (elem.HasAttribute("new_flag") || (container_type.Parent != null && container_type.Parent.GetPropertyRecursively (Name) != null))
|
|
modifiers = "new ";
|
|
|
|
XmlElement parent = (XmlElement) elem.ParentNode;
|
|
string name = elem.GetAttribute("name");
|
|
if (name == parent.GetAttribute("name")) {
|
|
name += "Prop";
|
|
}
|
|
string cname = "\"" + elem.GetAttribute("cname") + "\"";
|
|
|
|
string v_type = "";
|
|
if (SymbolTable.IsEnum(c_type)) {
|
|
v_type = "(int) (GLib.EnumWrapper)";
|
|
} else if (SymbolTable.IsInterface(c_type)) {
|
|
// FIXME: Handle interface props properly.
|
|
Console.Write("Interface property detected ");
|
|
Statistics.ThrottledCount++;
|
|
return;
|
|
} else if (SymbolTable.IsObject(c_type)) {
|
|
v_type = "(GLib.UnwrappedObject)";
|
|
} else if (SymbolTable.IsBoxed (c_type)) {
|
|
v_type = "(GLib.Boxed)";
|
|
} else if (SymbolTable.IsOpaque (c_type)) {
|
|
v_type = "(GLib.Opaque)";
|
|
}
|
|
|
|
if (elem.HasAttribute("construct-only") && !elem.HasAttribute("readable")) {
|
|
return;
|
|
}
|
|
|
|
sw.WriteLine();
|
|
sw.WriteLine("\t\t/// <summary> " + name + " Property </summary>");
|
|
sw.WriteLine("\t\t/// <remarks>");
|
|
sw.WriteLine("\t\t/// </remarks>");
|
|
|
|
sw.WriteLine("\t\tpublic " + modifiers + cs_type + " " + name + " {");
|
|
if (elem.HasAttribute("readable")) {
|
|
sw.WriteLine("\t\t\tget {");
|
|
sw.WriteLine("\t\t\t\tGLib.Value val = new GLib.Value (Handle, " + cname + ");");
|
|
sw.WriteLine("\t\t\t\tGetProperty(" + cname + ", val);");
|
|
if (SymbolTable.IsObject (c_type) || SymbolTable.IsOpaque (c_type) || SymbolTable.IsBoxed (c_type)) {
|
|
sw.WriteLine("\t\t\t\tSystem.IntPtr raw_ret = (System.IntPtr) {0} val;", v_type);
|
|
sw.WriteLine("\t\t\t\t" + cs_type + " ret = " + SymbolTable.FromNativeReturn(c_type, "raw_ret") + ";");
|
|
if (!SymbolTable.IsBoxed (c_type))
|
|
sw.WriteLine("\t\t\t\tif (ret == null) ret = new " + cs_type + "(raw_ret);");
|
|
} else {
|
|
sw.Write("\t\t\t\t" + cs_type + " ret = ");
|
|
sw.Write ("(" + cs_type + ") ");
|
|
if (v_type != "") {
|
|
sw.Write(v_type + " ");
|
|
}
|
|
sw.WriteLine("val;");
|
|
}
|
|
|
|
sw.WriteLine("\t\t\t\treturn ret;");
|
|
sw.WriteLine("\t\t\t}");
|
|
}
|
|
|
|
if (elem.HasAttribute("writeable") && !elem.HasAttribute("construct-only")) {
|
|
sw.WriteLine("\t\t\tset {");
|
|
sw.Write("\t\t\t\tSetProperty(" + cname + ", new GLib.Value(");
|
|
if (SymbolTable.IsEnum(c_type)) {
|
|
sw.WriteLine("Handle, " + cname + ", new GLib.EnumWrapper ((int) value)));");
|
|
} else if (SymbolTable.IsBoxed (c_type)) {
|
|
sw.WriteLine("Handle, " + cname + ", new GLib.Boxed (value)));");
|
|
} else {
|
|
if (v_type != "" && !(SymbolTable.IsObject (c_type) || SymbolTable.IsOpaque (c_type))) {
|
|
sw.Write(v_type + " ");
|
|
}
|
|
sw.WriteLine("value));");
|
|
}
|
|
sw.WriteLine("\t\t\t}");
|
|
}
|
|
|
|
sw.WriteLine("\t\t}");
|
|
sw.WriteLine();
|
|
|
|
Statistics.PropCount++;
|
|
}
|
|
}
|
|
}
|
|
|