This should be the last enormo-diff on mono-patches. I have removed the
api.xml file from CVS with this commit. It can be downloaded from http://sf.net/projects/gtk-sharp. I will be uploading new versions of the file, now named gtkapi.xml, to the project download area from now on. 2002-02-08 Mike Kestner <mkestner@speakeasy.net> * README : Some updates. * generator/BoxedGen.cs : Add FromNative method. * generator/CallbackGen.cs : Add FromNative method. * generator/EnumGen.cs : Add FromNative method. * generator/IGeneratable.cs : Add FromNative method. * generator/InterfaceGen.cs : Add FromNative method. * generator/ObjectGen.cs : Add FromNative method. Hook in GenMethod. * generator/StructBase.cs : Revamp param handling. Add GenMethod. * generator/StructGen.cs : Add FromNative method. * generator/SymbolTable.cs : Add FromNative method. * parser/gapi2xml.pl : Detect ctors before methods. Fix method names. * sample/HelloWorld.cs : uncomment the Show call. svn path=/trunk/gtk-sharp/; revision=2277
This commit is contained in:
parent
e99a131e6a
commit
4966896f1e
16 changed files with 162 additions and 30 deletions
15
ChangeLog
15
ChangeLog
|
@ -1,3 +1,18 @@
|
||||||
|
2002-02-08 Mike Kestner <mkestner@speakeasy.net>
|
||||||
|
|
||||||
|
* README : Some updates.
|
||||||
|
* generator/BoxedGen.cs : Add FromNative method.
|
||||||
|
* generator/CallbackGen.cs : Add FromNative method.
|
||||||
|
* generator/EnumGen.cs : Add FromNative method.
|
||||||
|
* generator/IGeneratable.cs : Add FromNative method.
|
||||||
|
* generator/InterfaceGen.cs : Add FromNative method.
|
||||||
|
* generator/ObjectGen.cs : Add FromNative method. Hook in GenMethod.
|
||||||
|
* generator/StructBase.cs : Revamp param handling. Add GenMethod.
|
||||||
|
* generator/StructGen.cs : Add FromNative method.
|
||||||
|
* generator/SymbolTable.cs : Add FromNative method.
|
||||||
|
* parser/gapi2xml.pl : Detect ctors before methods. Fix method names.
|
||||||
|
* sample/HelloWorld.cs : uncomment the Show call.
|
||||||
|
|
||||||
2002-02-06 Mike Kestner <mkestner@speakeasy.net>
|
2002-02-06 Mike Kestner <mkestner@speakeasy.net>
|
||||||
|
|
||||||
* generator/BoxedGen.cs : Marshal as IntPtr using Raw prop.
|
* generator/BoxedGen.cs : Marshal as IntPtr using Raw prop.
|
||||||
|
|
27
README
27
README
|
@ -1,13 +1,30 @@
|
||||||
The Gtk# hompage can be found at gtk-sharp.sourceforge.net.
|
The Gtk# homepage can be found at gtk-sharp.sourceforge.net.
|
||||||
|
|
||||||
Gtk# is a C# binding for the Gtk toolkit (www.gtk.org). The target is the
|
Gtk# is a C# binding for the Gtk+ toolkit (www.gtk.org). The target is the
|
||||||
2.0 platform, and no plans are currently in place to backport to 1.2.
|
2.0 platform, and no plans are currently in place to backport to 1.2.
|
||||||
|
|
||||||
The effort essentially boils down to an exercise in PInvoke against the C
|
The effort essentially boils down to an exercise in PInvoke against the C
|
||||||
dynamic libraries. It may end up being slow as hell, but we'll see when we get
|
dynamic libraries. It may end up being slow as hell, but we'll see when we get
|
||||||
there and adjust accordingly.
|
there and adjust accordingly.
|
||||||
|
|
||||||
The "Hello World" application in the sample directory has been executed
|
Building Gtk#:
|
||||||
on Win32, but a recent version of Gtk is required. The binaries from the Gimp
|
--------------
|
||||||
Win32 porting project were not compatible at last check.
|
Currently, it is only possible to compile Gtk# on Win32 using the .Net
|
||||||
|
framework compiler and libraries. Miguel and company will be changing that
|
||||||
|
shortly. The win32 compilation utilizes the cygwin environment for a GNU
|
||||||
|
build environment.
|
||||||
|
|
||||||
|
You will also need a a recent copy of the gtkapi.xml file. Tarballs containing
|
||||||
|
this file can be downloaded from the Sourceforge gtk-sharp project page. Extract
|
||||||
|
the tar.gz file into the generator directory and then type:
|
||||||
|
|
||||||
|
make windows
|
||||||
|
|
||||||
|
in the top level directory.
|
||||||
|
|
||||||
|
Discussion:
|
||||||
|
-----------
|
||||||
|
A mailing list for Gtk# discussion (gtk-sharp-list@ximian.com) is available.
|
||||||
|
Subscription and archives are available at lists.ximian.com. The list
|
||||||
|
requires subscription in order to post.
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,3 @@
|
||||||
*.dll
|
*.dll
|
||||||
*.exe
|
*.exe
|
||||||
generated
|
|
||||||
|
|
||||||
|
|
|
@ -25,7 +25,12 @@ namespace GtkSharp.Generation {
|
||||||
{
|
{
|
||||||
return var_name + ".Raw";
|
return var_name + ".Raw";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String FromNative(String var)
|
||||||
|
{
|
||||||
|
return "GLib.Boxed.GetBoxed(" + var + ")";
|
||||||
|
}
|
||||||
|
|
||||||
public void Generate (SymbolTable table)
|
public void Generate (SymbolTable table)
|
||||||
{
|
{
|
||||||
if (!Directory.Exists("..\\" + ns.ToLower() + "\\generated")) {
|
if (!Directory.Exists("..\\" + ns.ToLower() + "\\generated")) {
|
||||||
|
|
|
@ -54,6 +54,11 @@ namespace GtkSharp.Generation {
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String FromNative(String var)
|
||||||
|
{
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
public void Generate (SymbolTable table)
|
public void Generate (SymbolTable table)
|
||||||
{
|
{
|
||||||
if (!Directory.Exists("..\\" + ns.ToLower() + "\\generated")) {
|
if (!Directory.Exists("..\\" + ns.ToLower() + "\\generated")) {
|
||||||
|
|
|
@ -54,6 +54,11 @@ namespace GtkSharp.Generation {
|
||||||
return "(int) " + var_name;
|
return "(int) " + var_name;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String FromNative(String var)
|
||||||
|
{
|
||||||
|
return "(" + QualifiedName + ")" + var;
|
||||||
|
}
|
||||||
|
|
||||||
public void Generate (SymbolTable table)
|
public void Generate (SymbolTable table)
|
||||||
{
|
{
|
||||||
if (!Directory.Exists("..\\" + ns.ToLower() + "\\generated")) {
|
if (!Directory.Exists("..\\" + ns.ToLower() + "\\generated")) {
|
||||||
|
|
|
@ -19,6 +19,8 @@ namespace GtkSharp.Generation {
|
||||||
String QualifiedName {get;}
|
String QualifiedName {get;}
|
||||||
|
|
||||||
String CallByName (String var_name);
|
String CallByName (String var_name);
|
||||||
|
|
||||||
|
String FromNative (String var);
|
||||||
|
|
||||||
void Generate (SymbolTable table);
|
void Generate (SymbolTable table);
|
||||||
}
|
}
|
||||||
|
|
|
@ -53,7 +53,12 @@ namespace GtkSharp.Generation {
|
||||||
{
|
{
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String FromNative(String var)
|
||||||
|
{
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
public void Generate (SymbolTable table)
|
public void Generate (SymbolTable table)
|
||||||
{
|
{
|
||||||
if (!Directory.Exists("..\\" + ns.ToLower() + "\\generated")) {
|
if (!Directory.Exists("..\\" + ns.ToLower() + "\\generated")) {
|
||||||
|
|
|
@ -27,6 +27,11 @@ namespace GtkSharp.Generation {
|
||||||
return var_name + ".Handle";
|
return var_name + ".Handle";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String FromNative(String var)
|
||||||
|
{
|
||||||
|
return "GLib.Object.GetObject(" + var + ")";
|
||||||
|
}
|
||||||
|
|
||||||
public void Generate (SymbolTable table)
|
public void Generate (SymbolTable table)
|
||||||
{
|
{
|
||||||
if (!Directory.Exists("..\\" + ns.ToLower() + "\\generated")) {
|
if (!Directory.Exists("..\\" + ns.ToLower() + "\\generated")) {
|
||||||
|
@ -86,6 +91,9 @@ namespace GtkSharp.Generation {
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case "method":
|
case "method":
|
||||||
|
if (!GenMethod(member, table, sw)) {
|
||||||
|
Console.WriteLine("in object " + CName);
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case "property":
|
case "property":
|
||||||
|
|
|
@ -51,12 +51,16 @@ namespace GtkSharp.Generation {
|
||||||
XmlElement parms = ctor["parameters"];
|
XmlElement parms = ctor["parameters"];
|
||||||
|
|
||||||
if (parms == null) {
|
if (parms == null) {
|
||||||
sig = "()";
|
call = sig = "()";
|
||||||
isig = call = "();";
|
isig = "();";
|
||||||
sigtypes = "";
|
sigtypes = "";
|
||||||
} else if (!GetSignature(parms, table, out sig, out sigtypes) ||
|
} else if (GetSignature(parms, table, out sig, out sigtypes) &&
|
||||||
!GetImportSig(parms, table, out isig) ||
|
GetImportSig(parms, table, out isig) &&
|
||||||
!GetCallString(parms, table, out call)) {
|
GetCallString(parms, table, out call)) {
|
||||||
|
sig = "(" + sig + ")";
|
||||||
|
isig = "(" + isig + ");";
|
||||||
|
call = "(" + call + ")";
|
||||||
|
} else {
|
||||||
Console.Write("ctor ");
|
Console.Write("ctor ");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -119,9 +123,64 @@ namespace GtkSharp.Generation {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected bool GenMethod(XmlElement method, SymbolTable table, StreamWriter sw)
|
||||||
|
{
|
||||||
|
String sig, isig, call, sigtypes;
|
||||||
|
XmlElement parms = method["parameters"];
|
||||||
|
|
||||||
|
if (parms == null) {
|
||||||
|
call = sig = "()";
|
||||||
|
isig = "();";
|
||||||
|
sigtypes = "";
|
||||||
|
} else if (GetSignature(parms, table, out sig, out sigtypes) &&
|
||||||
|
GetImportSig(parms, table, out isig) &&
|
||||||
|
GetCallString(parms, table, out call)) {
|
||||||
|
sig = "(" + sig + ")";
|
||||||
|
isig = "(IntPtr raw, " + isig + ");";
|
||||||
|
call = "(Handle, " + call + ")";
|
||||||
|
} else {
|
||||||
|
Console.Write("method ");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
String rettype = "void";
|
||||||
|
if (method.HasAttribute("return-type")) {
|
||||||
|
rettype = method.GetAttribute("return-type");
|
||||||
|
}
|
||||||
|
|
||||||
|
String m_ret = table.GetMarshalType(rettype);
|
||||||
|
String s_ret = table.GetCSType(rettype);
|
||||||
|
if (m_ret == "" || s_ret == "") {
|
||||||
|
Console.Write("rettype: " + rettype + " method ");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
String cname = method.GetAttribute("cname");
|
||||||
|
String name = method.GetAttribute("name");
|
||||||
|
|
||||||
|
sw.WriteLine("\t\t[DllImport(\"" + table.GetDllName(ns) +
|
||||||
|
"\", CallingConvention=CallingConvention.Cdecl)]");
|
||||||
|
sw.Write("\t\tstatic extern " + m_ret + " " + cname + isig);
|
||||||
|
sw.WriteLine();
|
||||||
|
|
||||||
|
sw.WriteLine("\t\tpublic " + s_ret + " " + name + sig);
|
||||||
|
sw.WriteLine("\t\t{");
|
||||||
|
sw.Write("\t\t\t");
|
||||||
|
if (m_ret == "void") {
|
||||||
|
sw.WriteLine(cname + call + ";");
|
||||||
|
} else {
|
||||||
|
sw.WriteLine("return " + table.FromNative(rettype, cname + call) + ";");
|
||||||
|
}
|
||||||
|
|
||||||
|
sw.WriteLine("\t\t}");
|
||||||
|
sw.WriteLine();
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
private bool GetCallString(XmlElement parms, SymbolTable table, out String call)
|
private bool GetCallString(XmlElement parms, SymbolTable table, out String call)
|
||||||
{
|
{
|
||||||
call = "(";
|
call = "";
|
||||||
|
|
||||||
bool need_comma = false;
|
bool need_comma = false;
|
||||||
|
|
||||||
|
@ -149,13 +208,12 @@ namespace GtkSharp.Generation {
|
||||||
call += call_parm;
|
call += call_parm;
|
||||||
}
|
}
|
||||||
|
|
||||||
call += ")";
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private bool GetImportSig(XmlElement parms, SymbolTable table, out String isig)
|
private bool GetImportSig(XmlElement parms, SymbolTable table, out String isig)
|
||||||
{
|
{
|
||||||
isig = "(";
|
isig = "";
|
||||||
|
|
||||||
bool need_comma = false;
|
bool need_comma = false;
|
||||||
|
|
||||||
|
@ -187,16 +245,13 @@ namespace GtkSharp.Generation {
|
||||||
isig += (m_type + " " + name);
|
isig += (m_type + " " + name);
|
||||||
}
|
}
|
||||||
|
|
||||||
isig += ");";
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private bool GetSignature(XmlElement parms, SymbolTable table, out String sig, out String sigtypes)
|
private bool GetSignature(XmlElement parms, SymbolTable table, out String sig, out String sigtypes)
|
||||||
{
|
{
|
||||||
sig = "(";
|
sigtypes = sig = "";
|
||||||
|
|
||||||
bool need_comma = false;
|
bool need_comma = false;
|
||||||
sigtypes = "";
|
|
||||||
|
|
||||||
foreach (XmlNode parm in parms.ChildNodes) {
|
foreach (XmlNode parm in parms.ChildNodes) {
|
||||||
if (parm.Name != "parameter") {
|
if (parm.Name != "parameter") {
|
||||||
|
@ -228,7 +283,6 @@ namespace GtkSharp.Generation {
|
||||||
sigtypes += cs_type;
|
sigtypes += cs_type;
|
||||||
}
|
}
|
||||||
|
|
||||||
sig += ")";
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -26,6 +26,11 @@ namespace GtkSharp.Generation {
|
||||||
return var_name;
|
return var_name;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String FromNative(String var)
|
||||||
|
{
|
||||||
|
return var;
|
||||||
|
}
|
||||||
|
|
||||||
public void Generate (SymbolTable table)
|
public void Generate (SymbolTable table)
|
||||||
{
|
{
|
||||||
if (!Directory.Exists("..\\" + ns.ToLower() + "\\generated")) {
|
if (!Directory.Exists("..\\" + ns.ToLower() + "\\generated")) {
|
||||||
|
|
|
@ -18,6 +18,7 @@ namespace GtkSharp.Generation {
|
||||||
public SymbolTable ()
|
public SymbolTable ()
|
||||||
{
|
{
|
||||||
simple_types = new Hashtable ();
|
simple_types = new Hashtable ();
|
||||||
|
simple_types.Add ("void", "void");
|
||||||
simple_types.Add ("gboolean", "bool");
|
simple_types.Add ("gboolean", "bool");
|
||||||
simple_types.Add ("gint", "int");
|
simple_types.Add ("gint", "int");
|
||||||
simple_types.Add ("guint", "uint");
|
simple_types.Add ("guint", "uint");
|
||||||
|
@ -95,6 +96,19 @@ namespace GtkSharp.Generation {
|
||||||
return trim_type;
|
return trim_type;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String FromNative(String c_type, String val)
|
||||||
|
{
|
||||||
|
c_type = Trim(c_type);
|
||||||
|
if (simple_types.ContainsKey(c_type)) {
|
||||||
|
return val;
|
||||||
|
} else if (complex_types.ContainsKey(c_type)) {
|
||||||
|
IGeneratable gen = (IGeneratable) complex_types[c_type];
|
||||||
|
return gen.FromNative(val);
|
||||||
|
} else {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public String GetCSType(String c_type)
|
public String GetCSType(String c_type)
|
||||||
{
|
{
|
||||||
c_type = Trim(c_type);
|
c_type = Trim(c_type);
|
||||||
|
|
File diff suppressed because one or more lines are too long
|
@ -4,7 +4,7 @@ all:
|
||||||
|
|
||||||
windows:
|
windows:
|
||||||
$(CSC) /unsafe /out:codegen.exe /recurse:*.cs
|
$(CSC) /unsafe /out:codegen.exe /recurse:*.cs
|
||||||
./codegen api.xml
|
./codegen gtkapi.xml
|
||||||
|
|
||||||
unix:
|
unix:
|
||||||
@echo "'make unix' is broken for now."
|
@echo "'make unix' is broken for now."
|
||||||
|
|
|
@ -368,14 +368,14 @@ sub addFuncElems
|
||||||
foreach $mname (keys(%fdefs)) {
|
foreach $mname (keys(%fdefs)) {
|
||||||
next if ($mname !~ /$prefix/);
|
next if ($mname !~ /$prefix/);
|
||||||
|
|
||||||
if ($fdefs{$mname} =~ /\(\s*$inst\b/) {
|
if ($mname =~ /$prefix(new)/) {
|
||||||
|
$el = addNameElem($obj_el, 'constructor', $mname);
|
||||||
|
$drop_1st = 0;
|
||||||
|
} elsif ($fdefs{$mname} =~ /\(\s*$inst\b/) {
|
||||||
$el = addNameElem($obj_el, 'method', $mname, $prefix);
|
$el = addNameElem($obj_el, 'method', $mname, $prefix);
|
||||||
$fdefs{$mname} =~ /(.*?)\w+\s*\(/;
|
$fdefs{$mname} =~ /(.*?)\w+\s*\(/;
|
||||||
addReturnElem($el, $1);
|
addReturnElem($el, $1);
|
||||||
$drop_1st = 1;
|
$drop_1st = 1;
|
||||||
} elsif ($mname =~ /$prefix(new)/) {
|
|
||||||
$el = addNameElem($obj_el, 'constructor', $mname);
|
|
||||||
$drop_1st = 0;
|
|
||||||
} else {
|
} else {
|
||||||
next;
|
next;
|
||||||
}
|
}
|
||||||
|
@ -401,7 +401,7 @@ sub addNameElem
|
||||||
$node->appendChild($elem);
|
$node->appendChild($elem);
|
||||||
if ($prefix) {
|
if ($prefix) {
|
||||||
$cname =~ /$prefix(\w+)/;
|
$cname =~ /$prefix(\w+)/;
|
||||||
$elem->setAttribute('name', $1);
|
$elem->setAttribute('name', StudlyCaps($1));
|
||||||
}
|
}
|
||||||
if ($cname) {
|
if ($cname) {
|
||||||
$elem->setAttribute('cname', $cname);
|
$elem->setAttribute('cname', $cname);
|
||||||
|
|
|
@ -22,7 +22,7 @@ namespace GtkSamples {
|
||||||
Console.WriteLine("Setting Title");
|
Console.WriteLine("Setting Title");
|
||||||
win.Title = "Gtk# Hello World";
|
win.Title = "Gtk# Hello World";
|
||||||
// win.Deleted += new EventHandler (Window_Delete);
|
// win.Deleted += new EventHandler (Window_Delete);
|
||||||
// win.Show ();
|
win.Show ();
|
||||||
Console.WriteLine("Entering event loop");
|
Console.WriteLine("Entering event loop");
|
||||||
Application.Run ();
|
Application.Run ();
|
||||||
return 0;
|
return 0;
|
||||||
|
|
Loading…
Reference in a new issue