2002-05-23 23:43:25 +00:00
|
|
|
// GtkSharp.Generation.Property.cs - The Property Generatable.
|
|
|
|
//
|
|
|
|
// Author: Mike Kestner <mkestner@speakeasy.net>
|
|
|
|
//
|
2004-06-25 16:35:15 +00:00
|
|
|
// Copyright (c) 2001-2003 Mike Kestner
|
|
|
|
// Copyright (c) 2004 Novell, Inc.
|
|
|
|
//
|
|
|
|
// This program is free software; you can redistribute it and/or
|
|
|
|
// modify it under the terms of version 2 of the GNU General Public
|
|
|
|
// License as published by the Free Software Foundation.
|
|
|
|
//
|
|
|
|
// This program is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
// General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU General Public
|
|
|
|
// License along with this program; if not, write to the
|
|
|
|
// Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
|
|
// Boston, MA 02111-1307, USA.
|
|
|
|
|
2002-05-23 23:43:25 +00:00
|
|
|
|
|
|
|
namespace GtkSharp.Generation {
|
|
|
|
|
|
|
|
using System;
|
|
|
|
using System.Collections;
|
|
|
|
using System.IO;
|
|
|
|
using System.Xml;
|
|
|
|
|
2005-05-02 18:40:30 +00:00
|
|
|
public class Property : PropertyBase {
|
2002-05-23 23:43:25 +00:00
|
|
|
|
2005-05-02 18:40:30 +00:00
|
|
|
public Property (XmlElement elem, ClassBase container_type) : base (elem, container_type) {}
|
2002-05-23 23:43:25 +00:00
|
|
|
|
|
|
|
public bool Validate ()
|
|
|
|
{
|
2005-05-02 18:40:30 +00:00
|
|
|
if (CSType == "" && !Hidden) {
|
|
|
|
Console.Write("Property has unknown Type {0} ", CType);
|
2002-05-23 23:43:25 +00:00
|
|
|
Statistics.ThrottledCount++;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2005-05-02 18:40:30 +00:00
|
|
|
bool Readable {
|
|
|
|
get {
|
|
|
|
return elem.GetAttribute ("readable") == "true";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Writable {
|
|
|
|
get {
|
|
|
|
return elem.GetAttribute ("writeable") == "true" &&
|
|
|
|
!elem.HasAttribute ("construct-only");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-08-22 16:55:20 +00:00
|
|
|
bool IsDeprecated {
|
|
|
|
get {
|
|
|
|
return !container_type.IsDeprecated &&
|
|
|
|
elem.GetAttribute ("deprecated") == "1";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-11-18 20:31:22 +00:00
|
|
|
protected virtual string PropertyAttribute (string qpname) {
|
|
|
|
return "[GLib.Property (" + qpname + ")]";
|
2004-11-05 16:47:15 +00:00
|
|
|
}
|
|
|
|
|
2004-11-08 17:48:27 +00:00
|
|
|
protected virtual string RawGetter (string qpname) {
|
|
|
|
return "GetProperty (" + qpname + ")";
|
2004-11-05 16:47:15 +00:00
|
|
|
}
|
|
|
|
|
2004-11-08 17:48:27 +00:00
|
|
|
protected virtual string RawSetter (string qpname) {
|
|
|
|
return "SetProperty(" + qpname + ", val)";
|
2004-11-05 16:47:15 +00:00
|
|
|
}
|
|
|
|
|
2005-07-22 18:35:37 +00:00
|
|
|
public void GenerateDecl (StreamWriter sw, string indent)
|
|
|
|
{
|
|
|
|
if (Hidden || (!Readable && !Writable))
|
|
|
|
return;
|
|
|
|
|
|
|
|
string name = Name;
|
|
|
|
if (name == container_type.Name)
|
|
|
|
name += "Prop";
|
|
|
|
|
|
|
|
sw.WriteLine (indent + CSType + " " + name + " {");
|
|
|
|
sw.Write (indent + "\t");
|
|
|
|
if (Readable || Getter != null)
|
|
|
|
sw.Write ("get; ");
|
|
|
|
if (Writable || Setter != null)
|
|
|
|
sw.Write ("set;");
|
|
|
|
sw.WriteLine ();
|
|
|
|
sw.WriteLine (indent + "}");
|
|
|
|
}
|
|
|
|
|
|
|
|
public void Generate (GenerationInfo gen_info, string indent, ClassBase implementor)
|
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
|
|
|
|
2005-05-02 18:40:30 +00:00
|
|
|
if (Hidden || (!Readable && !Writable))
|
|
|
|
return;
|
|
|
|
|
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 = "";
|
|
|
|
|
2005-05-02 18:40:30 +00:00
|
|
|
if (IsNew || (container_type.Parent != null && container_type.Parent.GetPropertyRecursively (Name) != null))
|
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
|
|
|
modifiers = "new ";
|
2008-01-17 14:37:02 +00:00
|
|
|
else if (implementor != null && implementor.Parent != null && implementor.Parent.GetPropertyRecursively (Name) != null)
|
2005-07-22 18:35:37 +00:00
|
|
|
modifiers = "new ";
|
2002-05-23 23:43:25 +00:00
|
|
|
|
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";
|
|
|
|
}
|
2005-05-02 18:40:30 +00:00
|
|
|
string qpname = "\"" + CName + "\"";
|
2002-05-23 23:43:25 +00:00
|
|
|
|
|
|
|
string v_type = "";
|
2005-07-22 18:36:50 +00:00
|
|
|
if (table.IsInterface (CType)) {
|
|
|
|
v_type = "(GLib.Object)";
|
2005-05-02 18:40:30 +00:00
|
|
|
} else if (table.IsOpaque (CType)) {
|
2002-07-26 06:08:52 +00:00
|
|
|
v_type = "(GLib.Opaque)";
|
2005-08-03 14:58:38 +00:00
|
|
|
} else if (table.IsEnum (CType)) {
|
|
|
|
v_type = "(Enum)";
|
2002-05-23 23:43:25 +00:00
|
|
|
}
|
|
|
|
|
2005-05-02 18:40:30 +00:00
|
|
|
GenerateImports (gen_info, indent);
|
2002-08-04 04:23:13 +00:00
|
|
|
|
2005-08-22 16:55:20 +00:00
|
|
|
if (IsDeprecated ||
|
|
|
|
(Getter != null && Getter.IsDeprecated) ||
|
|
|
|
(Setter != null && Setter.IsDeprecated))
|
|
|
|
sw.WriteLine (indent + "[Obsolete]");
|
2004-11-18 20:31:22 +00:00
|
|
|
sw.WriteLine (indent + PropertyAttribute (qpname));
|
2005-05-02 18:40:30 +00:00
|
|
|
sw.WriteLine (indent + "public " + modifiers + CSType + " " + name + " {");
|
2004-11-18 20:31:22 +00:00
|
|
|
indent += "\t";
|
|
|
|
|
2005-05-02 18:40:30 +00:00
|
|
|
if (Getter != null) {
|
2004-11-18 20:31:22 +00:00
|
|
|
sw.Write(indent + "get ");
|
2007-08-13 14:29:06 +00:00
|
|
|
Getter.GenerateBody(gen_info, implementor, "\t");
|
2002-08-04 04:23:13 +00:00
|
|
|
sw.WriteLine();
|
2005-05-02 18:40:30 +00:00
|
|
|
} else if (Readable) {
|
2004-11-18 20:31:22 +00:00
|
|
|
sw.WriteLine(indent + "get {");
|
2004-11-08 17:48:27 +00:00
|
|
|
sw.WriteLine(indent + "\tGLib.Value val = " + RawGetter (qpname) + ";");
|
2005-07-22 18:36:50 +00:00
|
|
|
if (table.IsOpaque (CType) || table.IsBoxed (CType)) {
|
2005-05-02 18:40:30 +00:00
|
|
|
sw.WriteLine(indent + "\t" + CSType + " ret = (" + CSType + ") val;");
|
2002-07-26 06:08:52 +00:00
|
|
|
} else {
|
2005-05-02 18:40:30 +00:00
|
|
|
sw.Write(indent + "\t" + CSType + " ret = ");
|
|
|
|
sw.Write ("(" + CSType + ") ");
|
2002-07-30 23:02:12 +00:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2004-11-05 16:47:15 +00:00
|
|
|
sw.WriteLine(indent + "\tval.Dispose ();");
|
|
|
|
sw.WriteLine(indent + "\treturn ret;");
|
|
|
|
sw.WriteLine(indent + "}");
|
2002-05-23 23:43:25 +00:00
|
|
|
}
|
|
|
|
|
2005-05-02 18:40:30 +00:00
|
|
|
if (Setter != null) {
|
2004-11-18 20:31:22 +00:00
|
|
|
sw.Write(indent + "set ");
|
2007-08-13 14:29:06 +00:00
|
|
|
Setter.GenerateBody(gen_info, implementor, "\t");
|
2002-08-04 04:23:13 +00:00
|
|
|
sw.WriteLine();
|
2005-05-02 18:40:30 +00:00
|
|
|
} else if (Writable) {
|
2004-11-18 20:31:22 +00:00
|
|
|
sw.WriteLine(indent + "set {");
|
2004-11-05 16:47:15 +00:00
|
|
|
sw.Write(indent + "\tGLib.Value val = ");
|
2005-07-22 18:36:50 +00:00
|
|
|
if (table.IsBoxed (CType)) {
|
2004-04-12 15:54:57 +00:00
|
|
|
sw.WriteLine("(GLib.Value) value;");
|
2005-05-02 18:40:30 +00:00
|
|
|
} else if (table.IsOpaque (CType)) {
|
|
|
|
sw.WriteLine("new GLib.Value(value, \"{0}\");", CType);
|
2002-06-24 22:04:10 +00:00
|
|
|
} else {
|
2003-10-28 15:45:35 +00:00
|
|
|
sw.Write("new GLib.Value(");
|
2005-05-02 18:40:30 +00:00
|
|
|
if (v_type != "" && !(table.IsObject (CType) || table.IsInterface (CType) || table.IsOpaque (CType))) {
|
2002-06-24 22:04:10 +00:00
|
|
|
sw.Write(v_type + " ");
|
|
|
|
}
|
2004-04-12 15:54:57 +00:00
|
|
|
sw.WriteLine("value);");
|
2002-05-23 23:43:25 +00:00
|
|
|
}
|
2004-11-08 17:48:27 +00:00
|
|
|
sw.WriteLine(indent + "\t" + RawSetter (qpname) + ";");
|
2004-11-05 16:47:15 +00:00
|
|
|
sw.WriteLine(indent + "\tval.Dispose ();");
|
|
|
|
sw.WriteLine(indent + "}");
|
2002-05-23 23:43:25 +00:00
|
|
|
}
|
|
|
|
|
2004-11-18 20:31:22 +00:00
|
|
|
sw.WriteLine(indent.Substring (1) + "}");
|
2002-05-23 23:43:25 +00:00
|
|
|
sw.WriteLine();
|
|
|
|
|
|
|
|
Statistics.PropCount++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|