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:
Mike Kestner 2002-02-08 23:56:27 +00:00
parent e99a131e6a
commit 4966896f1e
16 changed files with 162 additions and 30 deletions

View File

@ -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>
* generator/BoxedGen.cs : Marshal as IntPtr using Raw prop.

27
README
View File

@ -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.
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
there and adjust accordingly.
The "Hello World" application in the sample directory has been executed
on Win32, but a recent version of Gtk is required. The binaries from the Gimp
Win32 porting project were not compatible at last check.
Building Gtk#:
--------------
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.

View File

@ -1,4 +1,3 @@
*.dll
*.exe
generated

View File

@ -25,7 +25,12 @@ namespace GtkSharp.Generation {
{
return var_name + ".Raw";
}
public String FromNative(String var)
{
return "GLib.Boxed.GetBoxed(" + var + ")";
}
public void Generate (SymbolTable table)
{
if (!Directory.Exists("..\\" + ns.ToLower() + "\\generated")) {

View File

@ -54,6 +54,11 @@ namespace GtkSharp.Generation {
return "";
}
public String FromNative(String var)
{
return "";
}
public void Generate (SymbolTable table)
{
if (!Directory.Exists("..\\" + ns.ToLower() + "\\generated")) {

View File

@ -54,6 +54,11 @@ namespace GtkSharp.Generation {
return "(int) " + var_name;
}
public String FromNative(String var)
{
return "(" + QualifiedName + ")" + var;
}
public void Generate (SymbolTable table)
{
if (!Directory.Exists("..\\" + ns.ToLower() + "\\generated")) {

View File

@ -19,6 +19,8 @@ namespace GtkSharp.Generation {
String QualifiedName {get;}
String CallByName (String var_name);
String FromNative (String var);
void Generate (SymbolTable table);
}

View File

@ -53,7 +53,12 @@ namespace GtkSharp.Generation {
{
return "";
}
public String FromNative(String var)
{
return "";
}
public void Generate (SymbolTable table)
{
if (!Directory.Exists("..\\" + ns.ToLower() + "\\generated")) {

View File

@ -27,6 +27,11 @@ namespace GtkSharp.Generation {
return var_name + ".Handle";
}
public String FromNative(String var)
{
return "GLib.Object.GetObject(" + var + ")";
}
public void Generate (SymbolTable table)
{
if (!Directory.Exists("..\\" + ns.ToLower() + "\\generated")) {
@ -86,6 +91,9 @@ namespace GtkSharp.Generation {
break;
case "method":
if (!GenMethod(member, table, sw)) {
Console.WriteLine("in object " + CName);
}
break;
case "property":

View File

@ -51,12 +51,16 @@ namespace GtkSharp.Generation {
XmlElement parms = ctor["parameters"];
if (parms == null) {
sig = "()";
isig = call = "();";
call = sig = "()";
isig = "();";
sigtypes = "";
} else if (!GetSignature(parms, table, out sig, out sigtypes) ||
!GetImportSig(parms, table, out isig) ||
!GetCallString(parms, table, out call)) {
} else if (GetSignature(parms, table, out sig, out sigtypes) &&
GetImportSig(parms, table, out isig) &&
GetCallString(parms, table, out call)) {
sig = "(" + sig + ")";
isig = "(" + isig + ");";
call = "(" + call + ")";
} else {
Console.Write("ctor ");
return false;
}
@ -119,9 +123,64 @@ namespace GtkSharp.Generation {
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)
{
call = "(";
call = "";
bool need_comma = false;
@ -149,13 +208,12 @@ namespace GtkSharp.Generation {
call += call_parm;
}
call += ")";
return true;
}
private bool GetImportSig(XmlElement parms, SymbolTable table, out String isig)
{
isig = "(";
isig = "";
bool need_comma = false;
@ -187,16 +245,13 @@ namespace GtkSharp.Generation {
isig += (m_type + " " + name);
}
isig += ");";
return true;
}
private bool GetSignature(XmlElement parms, SymbolTable table, out String sig, out String sigtypes)
{
sig = "(";
sigtypes = sig = "";
bool need_comma = false;
sigtypes = "";
foreach (XmlNode parm in parms.ChildNodes) {
if (parm.Name != "parameter") {
@ -228,7 +283,6 @@ namespace GtkSharp.Generation {
sigtypes += cs_type;
}
sig += ")";
return true;
}

View File

@ -26,6 +26,11 @@ namespace GtkSharp.Generation {
return var_name;
}
public String FromNative(String var)
{
return var;
}
public void Generate (SymbolTable table)
{
if (!Directory.Exists("..\\" + ns.ToLower() + "\\generated")) {

View File

@ -18,6 +18,7 @@ namespace GtkSharp.Generation {
public SymbolTable ()
{
simple_types = new Hashtable ();
simple_types.Add ("void", "void");
simple_types.Add ("gboolean", "bool");
simple_types.Add ("gint", "int");
simple_types.Add ("guint", "uint");
@ -95,6 +96,19 @@ namespace GtkSharp.Generation {
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)
{
c_type = Trim(c_type);

File diff suppressed because one or more lines are too long

View File

@ -4,7 +4,7 @@ all:
windows:
$(CSC) /unsafe /out:codegen.exe /recurse:*.cs
./codegen api.xml
./codegen gtkapi.xml
unix:
@echo "'make unix' is broken for now."

View File

@ -368,14 +368,14 @@ sub addFuncElems
foreach $mname (keys(%fdefs)) {
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);
$fdefs{$mname} =~ /(.*?)\w+\s*\(/;
addReturnElem($el, $1);
$drop_1st = 1;
} elsif ($mname =~ /$prefix(new)/) {
$el = addNameElem($obj_el, 'constructor', $mname);
$drop_1st = 0;
} else {
next;
}
@ -401,7 +401,7 @@ sub addNameElem
$node->appendChild($elem);
if ($prefix) {
$cname =~ /$prefix(\w+)/;
$elem->setAttribute('name', $1);
$elem->setAttribute('name', StudlyCaps($1));
}
if ($cname) {
$elem->setAttribute('cname', $cname);

View File

@ -22,7 +22,7 @@ namespace GtkSamples {
Console.WriteLine("Setting Title");
win.Title = "Gtk# Hello World";
// win.Deleted += new EventHandler (Window_Delete);
// win.Show ();
win.Show ();
Console.WriteLine("Entering event loop");
Application.Run ();
return 0;