mirror of
https://github.com/Ryujinx/GtkSharp.git
synced 2025-01-11 08:35:29 +00:00
2002-08-07 Mike Kestner <mkestner@speakeasy.net>
* generator/CodeGenerator.cs : call ObjectGen.GenerateMapper * generator/Method.cs : Remove the if null workaround * generator/ObjectGen.cs : build a hash of object types. (GenerateMapper): generate the GtkSharp.ObjectManager class. * glib/Object.cs : use ObjectManager.CreateObject. * glue/type.c : helper for typename lookup. svn path=/trunk/gtk-sharp/; revision=6526
This commit is contained in:
parent
29e6647bee
commit
66c0ec1d43
|
@ -1,3 +1,12 @@
|
|||
2002-08-07 Mike Kestner <mkestner@speakeasy.net>
|
||||
|
||||
* generator/CodeGenerator.cs : call ObjectGen.GenerateMapper
|
||||
* generator/Method.cs : Remove the if null workaround
|
||||
* generator/ObjectGen.cs : build a hash of object types.
|
||||
(GenerateMapper): generate the GtkSharp.ObjectManager class.
|
||||
* glib/Object.cs : use ObjectManager.CreateObject.
|
||||
* glue/type.c : helper for typename lookup.
|
||||
|
||||
2002-08-07 Duncan Mak <duncan@ximian.com>
|
||||
|
||||
* sample/Fifteen.cs: Fixed scramble. The whole thing works now.
|
||||
|
|
|
@ -27,6 +27,8 @@ namespace GtkSharp.Generation {
|
|||
gen.Generate ();
|
||||
}
|
||||
|
||||
ObjectGen.GenerateMapper ();
|
||||
|
||||
Statistics.Report();
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -374,7 +374,7 @@ namespace GtkSharp.Generation {
|
|||
{
|
||||
sw.WriteLine(m_ret + " raw_ret = " + cname + call + ";");
|
||||
sw.WriteLine(indent +"\t\t\t" + s_ret + " ret = " + SymbolTable.FromNativeReturn(rettype, "raw_ret") + ";");
|
||||
sw.WriteLine(indent + "\t\t\tif (ret == null) ret = new " + s_ret + "(raw_ret);");
|
||||
// sw.WriteLine(indent + "\t\t\tif (ret == null) ret = new " + s_ret + "(raw_ret);");
|
||||
}
|
||||
else {
|
||||
sw.WriteLine(m_ret + " raw_ret = " + cname + call + ";");
|
||||
|
|
|
@ -14,9 +14,12 @@ namespace GtkSharp.Generation {
|
|||
public class ObjectGen : ClassBase, IGeneratable {
|
||||
|
||||
private ArrayList strings = new ArrayList();
|
||||
private static Hashtable objs = new Hashtable();
|
||||
|
||||
public ObjectGen (XmlElement ns, XmlElement elem) : base (ns, elem)
|
||||
{
|
||||
objs.Add (CName, QualifiedName + "," + NS.ToLower() + "-sharp");
|
||||
|
||||
foreach (XmlNode node in elem.ChildNodes) {
|
||||
|
||||
if (!(node is XmlElement)) continue;
|
||||
|
@ -176,6 +179,65 @@ namespace GtkSharp.Generation {
|
|||
|
||||
base.GenCtors (sw);
|
||||
}
|
||||
|
||||
public static void GenerateMapper ()
|
||||
{
|
||||
char sep = Path.DirectorySeparatorChar;
|
||||
string dir = ".." + sep + "glib" + sep + "generated";
|
||||
if (!Directory.Exists(dir)) {
|
||||
Console.WriteLine ("creating " + dir);
|
||||
Directory.CreateDirectory(dir);
|
||||
}
|
||||
String filename = dir + sep + "ObjectManager.cs";
|
||||
|
||||
FileStream stream = new FileStream (filename, FileMode.Create, FileAccess.Write);
|
||||
StreamWriter sw = new StreamWriter (stream);
|
||||
|
||||
sw.WriteLine ("// Generated File. Do not modify.");
|
||||
sw.WriteLine ("// <c> 2001-2002 Mike Kestner");
|
||||
sw.WriteLine ();
|
||||
|
||||
sw.WriteLine ("namespace GtkSharp {");
|
||||
sw.WriteLine ();
|
||||
sw.WriteLine ("\tusing System;");
|
||||
sw.WriteLine ("\tusing System.Collections;");
|
||||
sw.WriteLine ("\tusing System.Runtime.InteropServices;");
|
||||
sw.WriteLine ();
|
||||
sw.WriteLine ("\tpublic class ObjectManager {");
|
||||
sw.WriteLine ();
|
||||
sw.WriteLine ("\t\tprivate static Hashtable types = new Hashtable ();");
|
||||
sw.WriteLine ();
|
||||
sw.WriteLine ("\t\tstatic ObjectManager ()");
|
||||
sw.WriteLine ("\t\t{");
|
||||
|
||||
foreach (string key in objs.Keys) {
|
||||
sw.WriteLine ("\t\t\t\ttypes.Add(\"" + key + "\", \"" + objs[key] + "\");");
|
||||
}
|
||||
|
||||
sw.WriteLine ("\t\t}");
|
||||
sw.WriteLine ();
|
||||
sw.WriteLine ("\t\t[DllImport(\"gtksharpglue\")]");
|
||||
sw.WriteLine ("\t\tstatic extern string gtksharp_get_type_name (IntPtr raw);");
|
||||
sw.WriteLine ();
|
||||
sw.WriteLine ("\t\tpublic static GLib.Object CreateObject (IntPtr raw)");
|
||||
sw.WriteLine ("\t\t{");
|
||||
sw.WriteLine ("\t\t\tstring typename = gtksharp_get_type_name (raw);");
|
||||
sw.WriteLine ("\t\t\tif (!types.ContainsKey(typename))");
|
||||
sw.WriteLine ("\t\t\t\treturn null;");
|
||||
sw.WriteLine ();
|
||||
sw.WriteLine ("\t\t\tType t = Type.GetType ((string)types[typename]);");
|
||||
sw.WriteLine ("\t\t\treturn (GLib.Object) Activator.CreateInstance (t, new object[] {raw});");
|
||||
sw.WriteLine ("\t\t}");
|
||||
sw.WriteLine ();
|
||||
sw.WriteLine ("\t\tpublic static void RegisterType (string native_name, string managed_name, string assembly)");
|
||||
sw.WriteLine ("\t\t{");
|
||||
sw.WriteLine ("\t\t\ttypes.Add(native_name, managed_name + \",\" + assembly);");
|
||||
sw.WriteLine ("\t\t}");
|
||||
sw.WriteLine ("\t}");
|
||||
sw.WriteLine ("}");
|
||||
sw.Flush ();
|
||||
sw.Close ();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -48,7 +48,7 @@ namespace GLib {
|
|||
{
|
||||
Object obj = (Object)Objects[(int)o];
|
||||
if (obj != null) return obj;
|
||||
return null; //FIXME: Call TypeParser here eventually.
|
||||
return GtkSharp.ObjectManager.CreateObject(o);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
|
|
@ -10,6 +10,7 @@ BASESOURCES = \
|
|||
slist.c \
|
||||
paned.c \
|
||||
style.c \
|
||||
type.c \
|
||||
widget.c \
|
||||
canvasitem.c
|
||||
|
||||
|
|
16
glue/type.c
Normal file
16
glue/type.c
Normal file
|
@ -0,0 +1,16 @@
|
|||
/* value.c : Glue to allocate GValues on the heap.
|
||||
*
|
||||
* Author: Mike Kestner <mkestner@speakeasy.net>
|
||||
*
|
||||
* <c> 2002 Mike Kestner
|
||||
*/
|
||||
|
||||
#include <glib-object.h>
|
||||
|
||||
gchar *
|
||||
gtksharp_get_type_name (GObject *obj)
|
||||
{
|
||||
return G_OBJECT_TYPE_NAME (obj);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in a new issue