2002-11-10 10:03:51 +00:00
|
|
|
// GtkSharp.Generation.StructBase.cs - The Structure/Object Base Class.
|
|
|
|
//
|
|
|
|
// Author: Mike Kestner <mkestner@speakeasy.net>
|
|
|
|
//
|
2004-06-25 16:35:15 +00:00
|
|
|
// Copyright (c) 2001-2003 Mike Kestner
|
|
|
|
//
|
|
|
|
// 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-11-10 10:03:51 +00:00
|
|
|
|
|
|
|
namespace GtkSharp.Generation {
|
|
|
|
|
|
|
|
using System;
|
|
|
|
using System.Collections;
|
|
|
|
using System.IO;
|
|
|
|
using System.Text.RegularExpressions;
|
|
|
|
using System.Xml;
|
|
|
|
|
|
|
|
public class StructBase : ClassBase {
|
|
|
|
|
|
|
|
ArrayList fields = new ArrayList ();
|
|
|
|
|
|
|
|
public StructBase (XmlElement ns, XmlElement elem) : base (ns, elem)
|
|
|
|
{
|
|
|
|
foreach (XmlNode node in elem.ChildNodes) {
|
|
|
|
|
|
|
|
if (!(node is XmlElement)) continue;
|
|
|
|
XmlElement member = (XmlElement) node;
|
|
|
|
|
|
|
|
switch (node.Name) {
|
|
|
|
case "field":
|
|
|
|
fields.Add (member);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case "callback":
|
|
|
|
Statistics.IgnoreCount++;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
if (!IsNodeNameHandled (node.Name))
|
|
|
|
Console.WriteLine ("Unexpected node " + node.Name + " in " + CName);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-01-19 05:30:05 +00:00
|
|
|
public override string MarshalType {
|
2002-11-10 10:03:51 +00:00
|
|
|
get
|
|
|
|
{
|
|
|
|
return "ref " + QualifiedName;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-01-19 05:30:05 +00:00
|
|
|
public override string MarshalReturnType {
|
2002-11-10 10:03:51 +00:00
|
|
|
get
|
|
|
|
{
|
|
|
|
return "IntPtr";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-11-18 22:19:31 +00:00
|
|
|
public override string ToNativeReturnType {
|
|
|
|
get
|
|
|
|
{
|
|
|
|
return QualifiedName;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-01-19 05:30:05 +00:00
|
|
|
public override string CallByName (string var_name)
|
2002-11-10 10:03:51 +00:00
|
|
|
{
|
|
|
|
return "ref " + var_name;
|
|
|
|
}
|
|
|
|
|
2004-01-19 05:30:05 +00:00
|
|
|
public override string CallByName ()
|
2002-11-10 10:03:51 +00:00
|
|
|
{
|
|
|
|
return "ref this";
|
|
|
|
}
|
|
|
|
|
2004-01-19 05:30:05 +00:00
|
|
|
public override string AssignToName {
|
2002-11-10 10:03:51 +00:00
|
|
|
get { return "raw"; }
|
|
|
|
}
|
|
|
|
|
2004-01-19 05:30:05 +00:00
|
|
|
public override string FromNative(string var)
|
2002-11-10 10:03:51 +00:00
|
|
|
{
|
|
|
|
return var;
|
|
|
|
}
|
|
|
|
|
2004-01-19 05:30:05 +00:00
|
|
|
public override string FromNativeReturn(string var)
|
2002-11-10 10:03:51 +00:00
|
|
|
{
|
|
|
|
return QualifiedName + ".New (" + var + ")";
|
|
|
|
}
|
|
|
|
|
2004-01-19 05:30:05 +00:00
|
|
|
public override string ToNativeReturn(string var)
|
2003-05-29 Rachel Hestilow <rachel@nullenvoid.com>
* gconf/Value.cs: Update to use new string marshalling.
* generator/StringGen.cs, ConstStringGen.cs: Added.
* generator/IGeneratable.cs: Add new method ToNativeReturn.
* generator/CallbackGen.cs: Implement ToNativeReturn. Call
ToNativeReturn for the return statement. Fix a couple of
places where s_ret was being used incorrectly for m_ret.
* generator/ClassGen.cs, EnumGen.cs, ManualGen.cs,
SimpleGen.cs, StructBase.cs: Implement ToNativeReturn.
* generator/SignalHandler.cs: Call ToNativeReturn for the
return statement, instead of CallByName.
* generator/SymbolTable.cs: Use StringGen for gchar, char,
and gunichar, and ConstStringGen for their const variants.
Add a new method wrapper for ToNativeReturn.
(Trim): Add a special-case for const strings so that the
const is not stripped. Otherwise there is no way of
resolving the const case.
* glade/XML.custom: Update to use new string marshalling.
* glib/Marshaller.cs: Added.
* glib/GException.cs, Markup.cs, ObjectManager.cs,
Value.cs: Update to use new string marshalling.
* glib/Object.cs: Remove old g_type_name DllImport
as it is no longer used.
* glue/fileselection.c (gtksharp_file_selection_get_fileop_entry):
Mark this as const return.
* gtk/ColorSelection.custom, FileSelection.custom,
SelectionData.custom: Update to use new string marshalling.
svn path=/trunk/gtk-sharp/; revision=15286
2003-06-10 18:09:47 +00:00
|
|
|
{
|
|
|
|
// FIXME
|
|
|
|
return var;
|
|
|
|
}
|
|
|
|
|
2004-06-02 20:28:42 +00:00
|
|
|
private bool DisableNew {
|
|
|
|
get {
|
|
|
|
return Elem.HasAttribute ("disable_new");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-11-10 10:03:51 +00:00
|
|
|
protected void GenFields (StreamWriter sw)
|
|
|
|
{
|
2004-01-19 05:30:05 +00:00
|
|
|
Field.bitfields = 0;
|
2002-11-10 10:03:51 +00:00
|
|
|
bool need_field = true;
|
2004-01-19 05:30:05 +00:00
|
|
|
foreach (XmlElement field_elem in fields) {
|
|
|
|
Field field = new Field (field_elem);
|
|
|
|
if (field.IsBit) {
|
2002-11-10 10:03:51 +00:00
|
|
|
if (need_field)
|
|
|
|
need_field = false;
|
|
|
|
else
|
|
|
|
continue;
|
|
|
|
} else
|
|
|
|
need_field = true;
|
2004-01-19 05:30:05 +00:00
|
|
|
field.Generate (sw);
|
2002-11-10 10:03:51 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-10-05 00:20:17 +00:00
|
|
|
public virtual void Generate (GenerationInfo gen_info)
|
2002-11-10 10:03:51 +00:00
|
|
|
{
|
2003-10-28 15:45:35 +00:00
|
|
|
bool need_close = false;
|
|
|
|
if (gen_info.Writer == null) {
|
|
|
|
gen_info.Writer = gen_info.OpenStream (Name);
|
|
|
|
need_close = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
StreamWriter sw = gen_info.Writer;
|
2002-11-10 10:03:51 +00:00
|
|
|
|
2003-10-05 00:20:17 +00:00
|
|
|
sw.WriteLine ("namespace " + NS + " {");
|
|
|
|
sw.WriteLine ();
|
|
|
|
sw.WriteLine ("\tusing System;");
|
2002-11-10 10:03:51 +00:00
|
|
|
sw.WriteLine ("\tusing System.Collections;");
|
|
|
|
sw.WriteLine ("\tusing System.Runtime.InteropServices;");
|
|
|
|
sw.WriteLine ();
|
|
|
|
|
2003-01-05 23:51:37 +00:00
|
|
|
sw.WriteLine ("#region Autogenerated code");
|
2002-11-10 10:03:51 +00:00
|
|
|
sw.WriteLine ("\t[StructLayout(LayoutKind.Sequential)]");
|
|
|
|
sw.WriteLine ("\tpublic struct " + Name + " {");
|
|
|
|
sw.WriteLine ();
|
|
|
|
|
|
|
|
GenFields (sw);
|
|
|
|
sw.WriteLine ();
|
2003-10-05 00:20:17 +00:00
|
|
|
GenCtors (gen_info);
|
|
|
|
GenMethods (gen_info, null, null);
|
2003-01-05 23:51:37 +00:00
|
|
|
|
2003-10-28 15:45:35 +00:00
|
|
|
if (!need_close)
|
|
|
|
return;
|
|
|
|
|
2003-01-05 23:51:37 +00:00
|
|
|
sw.WriteLine ("#endregion");
|
2003-10-05 00:20:17 +00:00
|
|
|
AppendCustom(sw, gen_info.CustomDir);
|
2002-11-10 10:03:51 +00:00
|
|
|
|
|
|
|
sw.WriteLine ("\t}");
|
2003-10-05 00:20:17 +00:00
|
|
|
sw.WriteLine ("}");
|
|
|
|
sw.Close ();
|
|
|
|
gen_info.Writer = null;
|
2002-11-10 10:03:51 +00:00
|
|
|
}
|
|
|
|
|
2003-10-05 00:20:17 +00:00
|
|
|
protected override void GenCtors (GenerationInfo gen_info)
|
2002-11-10 10:03:51 +00:00
|
|
|
{
|
2003-10-05 00:20:17 +00:00
|
|
|
StreamWriter sw = gen_info.Writer;
|
|
|
|
|
2002-11-10 10:03:51 +00:00
|
|
|
sw.WriteLine ("\t\tpublic static {0} Zero = new {0} ();", QualifiedName);
|
|
|
|
sw.WriteLine();
|
2004-06-02 20:28:42 +00:00
|
|
|
if (!DisableNew) {
|
|
|
|
sw.WriteLine ("\t\tpublic static " + QualifiedName + " New(IntPtr raw) {");
|
|
|
|
sw.WriteLine ("\t\t\tif (raw == IntPtr.Zero) {");
|
|
|
|
sw.WriteLine ("\t\t\t\treturn {0}.Zero;", QualifiedName);
|
|
|
|
sw.WriteLine ("\t\t\t}");
|
|
|
|
sw.WriteLine ("\t\t\t{0} self = new {0}();", QualifiedName);
|
|
|
|
sw.WriteLine ("\t\t\tself = ({0}) Marshal.PtrToStructure (raw, self.GetType ());", QualifiedName);
|
|
|
|
sw.WriteLine ("\t\t\treturn self;");
|
|
|
|
sw.WriteLine ("\t\t}");
|
|
|
|
sw.WriteLine ();
|
|
|
|
}
|
2002-11-10 10:03:51 +00:00
|
|
|
|
|
|
|
foreach (Ctor ctor in Ctors) {
|
|
|
|
ctor.ForceStatic = true;
|
2003-04-06 09:21:15 +00:00
|
|
|
if (ctor.Params != null)
|
|
|
|
ctor.Params.Static = true;
|
2002-11-10 10:03:51 +00:00
|
|
|
}
|
2003-04-06 09:21:15 +00:00
|
|
|
|
2003-10-05 00:20:17 +00:00
|
|
|
base.GenCtors (gen_info);
|
2002-11-10 10:03:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|