2002-08-28 Rachel Hestilow <hestilow@ximian.com>
* generator/CallbackGen.cs: Generate wrappers to map from managed delegates to native ones. * generator/Ctor.cs: Call parms.Initialize for the static case. * generator/Parameters.cs: Add "CType" property. Append [] to CSType if necessary. Add "HideData" property if a container wishes to hide the user_data (used in callbacks). (Initialize): Add case for callback. * generator/SymbolTable.cs: Add size_t. * glue/program.c: string[] marshalling is no longer broken, remove hack. * sources/Gtk.metadata: Disable GtkColorSelection.SetChangePaletteHook and GtkTreeView.GetSearchEqualFunc for now, they return delegates and we don't support native->managed delegate mapping yet. svn path=/trunk/gtk-sharp/; revision=7133
This commit is contained in:
parent
b7e21da53a
commit
38e7bdeec5
8 changed files with 246 additions and 25 deletions
19
ChangeLog
19
ChangeLog
|
@ -1,3 +1,22 @@
|
|||
2002-08-28 Rachel Hestilow <hestilow@ximian.com>
|
||||
|
||||
* generator/CallbackGen.cs: Generate wrappers to map
|
||||
from managed delegates to native ones.
|
||||
* generator/Ctor.cs: Call parms.Initialize for the static case.
|
||||
* generator/Parameters.cs: Add "CType" property. Append []
|
||||
to CSType if necessary. Add "HideData" property if a container
|
||||
wishes to hide the user_data (used in callbacks).
|
||||
(Initialize): Add case for callback.
|
||||
* generator/SymbolTable.cs: Add size_t.
|
||||
|
||||
* glue/program.c: string[] marshalling is no longer broken,
|
||||
remove hack.
|
||||
|
||||
* sources/Gtk.metadata: Disable
|
||||
GtkColorSelection.SetChangePaletteHook and
|
||||
GtkTreeView.GetSearchEqualFunc for now, they return delegates and
|
||||
we don't support native->managed delegate mapping yet.
|
||||
|
||||
2002-08-28 Joe Shaw <joe@assbarn.com>
|
||||
|
||||
* makefile: Add the art directory back in; fixes the build.
|
||||
|
|
|
@ -2196,7 +2196,7 @@
|
|||
<parameter type="gint" name="n_colors"/>
|
||||
</parameters>
|
||||
</method>
|
||||
<method name="SetChangePaletteHook" cname="gtk_color_selection_set_change_palette_hook" shared="true">
|
||||
<method name="SetChangePaletteHook" cname="gtk_color_selection_set_change_palette_hook" shared="true" hidden="1">
|
||||
<return-type type="GtkColorSelectionChangePaletteFunc"/>
|
||||
<parameters>
|
||||
<parameter type="GtkColorSelectionChangePaletteFunc" name="func"/>
|
||||
|
@ -8241,7 +8241,7 @@
|
|||
<method name="GetSearchColumn" cname="gtk_tree_view_get_search_column">
|
||||
<return-type type="gint"/>
|
||||
</method>
|
||||
<method name="GetSearchEqualFunc" cname="gtk_tree_view_get_search_equal_func">
|
||||
<method name="GetSearchEqualFunc" cname="gtk_tree_view_get_search_equal_func" hidden="1">
|
||||
<return-type type="GtkTreeViewSearchEqualFunc"/>
|
||||
</method>
|
||||
<method name="GetSelection" cname="gtk_tree_view_get_selection">
|
||||
|
|
|
@ -23,7 +23,7 @@ namespace GtkSharp.Generation {
|
|||
public String MarshalType {
|
||||
get
|
||||
{
|
||||
return QualifiedName;
|
||||
return "GtkSharp." + NS + Name + "Native";
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -36,7 +36,7 @@ namespace GtkSharp.Generation {
|
|||
|
||||
public String CallByName (String var_name)
|
||||
{
|
||||
return var_name;
|
||||
return var_name + ".NativeDelegate";
|
||||
}
|
||||
|
||||
public String FromNative(String var)
|
||||
|
@ -49,6 +49,116 @@ namespace GtkSharp.Generation {
|
|||
return FromNative (var);
|
||||
}
|
||||
|
||||
private void GenWrapper (string s_ret, string sig)
|
||||
{
|
||||
char sep = Path.DirectorySeparatorChar;
|
||||
string dir = ".." + sep + NS.ToLower() + sep + "generated";
|
||||
|
||||
if (!Directory.Exists (dir))
|
||||
Directory.CreateDirectory (dir);
|
||||
|
||||
string wrapper = NS + Name + "Native";
|
||||
|
||||
string filename = dir + sep + "GtkSharp." + wrapper + ".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;");
|
||||
|
||||
string import_sig;
|
||||
if (parms != null)
|
||||
{
|
||||
parms.CreateSignature (false);
|
||||
import_sig = parms.ImportSig;
|
||||
} else
|
||||
import_sig = "";
|
||||
|
||||
XmlElement ret_elem = Elem["return-type"];
|
||||
string rettype = ret_elem.GetAttribute("type");
|
||||
string m_ret = SymbolTable.GetMarshalReturnType (rettype);
|
||||
|
||||
sw.WriteLine ("\tpublic delegate " + m_ret + " " + wrapper + "(" + import_sig + ");");
|
||||
sw.WriteLine ();
|
||||
|
||||
sw.WriteLine ("\tpublic class " + NS + Name + "Wrapper : GLib.DelegateWrapper {");
|
||||
sw.WriteLine ();
|
||||
|
||||
sw.WriteLine ("\t\tpublic " + m_ret + " NativeCallback (" + import_sig + ")");
|
||||
sw.WriteLine ("\t\t{");
|
||||
int count = (parms != null) ? parms.Count : 0;
|
||||
if (count > 0)
|
||||
sw.WriteLine ("\t\t\tobject[] _args = new object[{0}];", count - 1);
|
||||
int idx = 0;
|
||||
bool need_sep = false;
|
||||
string call_str = "";
|
||||
for (int i = 0; i < count; i++)
|
||||
{
|
||||
string parm_name = parms[i].Name;
|
||||
string ctype = parms[i].CType;
|
||||
if (ctype == "gpointer" && (parm_name.EndsWith ("data") || parm_name.EndsWith ("data_or_owner")))
|
||||
continue;
|
||||
string cstype = parms[i].CSType;
|
||||
// FIXME: Too much code copy/pasted here. Refactor?
|
||||
ClassBase parm_wrapper = SymbolTable.GetClassGen (ctype);
|
||||
if (parm_wrapper != null && (parm_wrapper is StructBase)) {
|
||||
sw.WriteLine("\t\t\t{0}._Initialize ();", parm_name);
|
||||
}
|
||||
sw.WriteLine("\t\t\t_args[" + idx + "] = " + SymbolTable.FromNative (ctype, parm_name) + ";");
|
||||
if ((parm_wrapper != null && ((parm_wrapper is OpaqueGen))) || SymbolTable.IsManuallyWrapped (ctype)) {
|
||||
sw.WriteLine("\t\t\tif (_args[" + idx + "] == null)");
|
||||
sw.WriteLine("\t\t\t\t_args[{0}] = new {1}({2});", idx, cstype, parm_name);
|
||||
}
|
||||
if (need_sep)
|
||||
call_str += ", ";
|
||||
else
|
||||
need_sep = true;
|
||||
call_str += String.Format ("({0}) _args[{1}]", cstype, idx);
|
||||
idx++;
|
||||
}
|
||||
|
||||
sw.Write ("\t\t\t");
|
||||
string invoke = "_managed (" + call_str + ")";
|
||||
if (m_ret != "void") {
|
||||
ClassBase parm_wrapper = SymbolTable.GetClassGen (rettype);
|
||||
if (parm_wrapper != null && (parm_wrapper is ObjectGen || parm_wrapper is OpaqueGen))
|
||||
sw.WriteLine ("return (({0}) {1}).Handle;", s_ret, invoke);
|
||||
else if (SymbolTable.IsStruct (rettype) || SymbolTable.IsBoxed (rettype)) {
|
||||
// Shoot. I have no idea what to do here.
|
||||
sw.WriteLine ("return IntPtr.Zero;");
|
||||
}
|
||||
else if (SymbolTable.IsEnum (rettype))
|
||||
sw.WriteLine ("return (int) {0};", invoke);
|
||||
else
|
||||
sw.WriteLine ("return ({0}) {1};", s_ret, invoke);
|
||||
}
|
||||
else
|
||||
sw.WriteLine (invoke + ";");
|
||||
sw.WriteLine ("\t\t}");
|
||||
sw.WriteLine ();
|
||||
|
||||
sw.WriteLine ("\t\tpublic {0} NativeDelegate;", wrapper);
|
||||
sw.WriteLine ("\t\tprotected {0} _managed;", NS + "." + Name);
|
||||
sw.WriteLine ();
|
||||
|
||||
sw.WriteLine ("\t\tpublic {0} ({1} managed) : base ()", NS + Name + "Wrapper", NS + "." + Name);
|
||||
sw.WriteLine ("\t\t{");
|
||||
|
||||
sw.WriteLine ("\t\t\tNativeDelegate = new {0} (NativeCallback);", wrapper);
|
||||
sw.WriteLine ("\t\t\t_managed = managed;");
|
||||
sw.WriteLine ("\t\t}");
|
||||
|
||||
sw.WriteLine ("\t}");
|
||||
|
||||
CloseWriter (sw);
|
||||
}
|
||||
|
||||
public void Generate ()
|
||||
{
|
||||
if (!DoGenerate)
|
||||
|
@ -62,7 +172,7 @@ namespace GtkSharp.Generation {
|
|||
}
|
||||
|
||||
string rettype = ret_elem.GetAttribute("type");
|
||||
string s_ret = SymbolTable.GetCSType(rettype);
|
||||
string s_ret = SymbolTable.GetCSType (rettype);
|
||||
if (s_ret == "") {
|
||||
Console.WriteLine("rettype: " + rettype + " in callback " + CName);
|
||||
Statistics.ThrottledCount++;
|
||||
|
@ -78,12 +188,18 @@ namespace GtkSharp.Generation {
|
|||
StreamWriter sw = CreateWriter ();
|
||||
|
||||
string sig = "";
|
||||
if (parms != null)
|
||||
if (parms != null) {
|
||||
parms.HideData = true;
|
||||
parms.CreateSignature (false);
|
||||
sig = parms.Signature;
|
||||
}
|
||||
|
||||
sw.WriteLine ("\tpublic delegate " + s_ret + " " + Name + "(" + sig + ");");
|
||||
|
||||
CloseWriter (sw);
|
||||
|
||||
GenWrapper (s_ret, sig);
|
||||
|
||||
Statistics.CBCount++;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -134,7 +134,7 @@ namespace GtkSharp.Generation {
|
|||
sw.WriteLine("\t\t{");
|
||||
|
||||
if (parms != null)
|
||||
parms.HandleException (sw, "");
|
||||
parms.Initialize(sw, false, "");
|
||||
|
||||
sw.Write("\t\t\treturn ");
|
||||
if (container_type is StructBase)
|
||||
|
|
|
@ -19,9 +19,18 @@ namespace GtkSharp.Generation {
|
|||
elem = e;
|
||||
}
|
||||
|
||||
public string CType {
|
||||
get {
|
||||
return elem.GetAttribute("type");
|
||||
}
|
||||
}
|
||||
|
||||
public string CSType {
|
||||
get {
|
||||
return SymbolTable.GetCSType( elem.GetAttribute("type"));
|
||||
string cstype = SymbolTable.GetCSType( elem.GetAttribute("type"));
|
||||
if (elem.HasAttribute("array"))
|
||||
cstype += "[]";
|
||||
return cstype;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -71,6 +80,7 @@ namespace GtkSharp.Generation {
|
|||
private string call_string;
|
||||
private string signature;
|
||||
private string signature_types;
|
||||
private bool hide_data;
|
||||
|
||||
public Parameters (XmlElement elem) {
|
||||
|
||||
|
@ -112,6 +122,11 @@ namespace GtkSharp.Generation {
|
|||
}
|
||||
}
|
||||
|
||||
public bool HideData {
|
||||
get { return hide_data; }
|
||||
set { hide_data = value; }
|
||||
}
|
||||
|
||||
public bool Validate ()
|
||||
{
|
||||
foreach (XmlNode parm in elem.ChildNodes) {
|
||||
|
@ -146,6 +161,10 @@ namespace GtkSharp.Generation {
|
|||
{
|
||||
signature_types = signature = import_sig = call_string = "";
|
||||
bool need_sep = false;
|
||||
bool has_callback = hide_data;
|
||||
bool last_was_user_data = false;
|
||||
bool has_user_data = false;
|
||||
string callback_type = "";
|
||||
|
||||
int len = 0;
|
||||
XmlElement last_param = null;
|
||||
|
@ -153,6 +172,9 @@ namespace GtkSharp.Generation {
|
|||
if (parm.Name != "parameter") {
|
||||
continue;
|
||||
}
|
||||
XmlElement p_elem = (XmlElement) parm;
|
||||
if (p_elem.GetAttribute("type") == "gpointer" && (p_elem.GetAttribute("name").EndsWith ("data") || p_elem.GetAttribute("name").EndsWith ("data_or_owner")))
|
||||
has_user_data = true;
|
||||
len++;
|
||||
last_param = (XmlElement) parm;
|
||||
}
|
||||
|
@ -168,14 +190,23 @@ namespace GtkSharp.Generation {
|
|||
string cs_type = SymbolTable.GetCSType(type);
|
||||
string m_type = SymbolTable.GetMarshalType(type);
|
||||
string name = MangleName(p_elem.GetAttribute("name"));
|
||||
string call_parm, call_parm_name;;
|
||||
string call_parm, call_parm_name;
|
||||
|
||||
if (SymbolTable.IsCallback (type)) {
|
||||
has_callback = true;
|
||||
}
|
||||
|
||||
if (is_set && i == 0)
|
||||
call_parm_name = "value";
|
||||
else
|
||||
call_parm_name = name;
|
||||
|
||||
call_parm = SymbolTable.CallByName(type, call_parm_name);
|
||||
if (SymbolTable.IsCallback (type)) {
|
||||
call_parm = SymbolTable.CallByName (type, call_parm_name + "_wrapper");
|
||||
callback_type = type.Replace (".", "");
|
||||
callback_type = "GtkSharp." + callback_type + "Wrapper";
|
||||
} else
|
||||
call_parm = SymbolTable.CallByName(type, call_parm_name);
|
||||
|
||||
if (p_elem.HasAttribute ("null_ok") && cs_type != "IntPtr" && cs_type != "System.IntPtr" && !SymbolTable.IsStruct (type))
|
||||
call_parm = String.Format ("({0} != null) ? {1} : IntPtr.Zero", call_parm_name, call_parm);
|
||||
|
@ -183,6 +214,9 @@ namespace GtkSharp.Generation {
|
|||
if (p_elem.HasAttribute("array")) {
|
||||
cs_type += "[]";
|
||||
m_type += "[]";
|
||||
cs_type = cs_type.Replace ("ref ", "");
|
||||
m_type = m_type.Replace ("ref ", "");
|
||||
call_parm = call_parm.Replace ("ref ", "");
|
||||
}
|
||||
|
||||
if (IsVarArgs && i == (len - 1) && VAType == "length_param") {
|
||||
|
@ -193,7 +227,7 @@ namespace GtkSharp.Generation {
|
|||
if (need_sep) {
|
||||
call_string += ", ";
|
||||
import_sig += ", ";
|
||||
if (type != "GError**" && !(IsVarArgs && i == (len - 1) && VAType == "length_param"))
|
||||
if (!(type == "GError**" || last_was_user_data) && !(IsVarArgs && i == (len - 1) && VAType == "length_param"))
|
||||
{
|
||||
signature += ", ";
|
||||
signature_types += ":";
|
||||
|
@ -224,27 +258,42 @@ namespace GtkSharp.Generation {
|
|||
if (IsVarArgs && i == (len - 2) && VAType == "length_param")
|
||||
{
|
||||
call_string += MangleName(last_param.GetAttribute("name")) + ".Length";
|
||||
last_was_user_data = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (type != "GError**") {
|
||||
if (!(type == "GError**" || (has_callback && type == "gpointer" && (name.EndsWith ("data") || name.EndsWith ("data_or_owner"))))) {
|
||||
signature += (cs_type + " " + name);
|
||||
signature_types += cs_type;
|
||||
}
|
||||
last_was_user_data = false;
|
||||
} else if (type == "GError**") {
|
||||
call_parm = call_parm.Replace (name, "error");
|
||||
last_was_user_data = false;
|
||||
} else if (type == "gpointer" && (name.EndsWith ("data") || name.EndsWith ("data_or_owner"))) {
|
||||
call_parm = "IntPtr.Zero";
|
||||
last_was_user_data = true;
|
||||
} else
|
||||
last_was_user_data = false;
|
||||
|
||||
call_string += call_parm;
|
||||
}
|
||||
import_sig += (m_type + " " + name);
|
||||
// FIXME: lame
|
||||
call_string = call_string.Replace ("out ref", "out");
|
||||
import_sig = import_sig.Replace ("out ref", "out");
|
||||
|
||||
i++;
|
||||
}
|
||||
|
||||
// FIXME: lame
|
||||
call_string = call_string.Replace ("out ref", "out");
|
||||
import_sig = import_sig.Replace ("out ref", "out");
|
||||
|
||||
// FIXME: this is also lame, I need to fix the need_sep algo
|
||||
if (signature.EndsWith (", "))
|
||||
signature = signature.Remove (signature.Length - 2, 2);
|
||||
}
|
||||
|
||||
public void Initialize (StreamWriter sw, bool is_get, string indent)
|
||||
{
|
||||
string name = "";
|
||||
|
||||
foreach (XmlNode parm in elem.ChildNodes) {
|
||||
if (parm.Name != "parameter") {
|
||||
continue;
|
||||
|
@ -270,6 +319,25 @@ namespace GtkSharp.Generation {
|
|||
|
||||
if (ThrowsException)
|
||||
sw.WriteLine (indent + "\t\t\tIntPtr error = IntPtr.Zero;");
|
||||
|
||||
foreach (XmlNode parm in elem.ChildNodes) {
|
||||
if (parm.Name != "parameter") {
|
||||
continue;
|
||||
}
|
||||
|
||||
XmlElement p_elem = (XmlElement) parm;
|
||||
|
||||
string c_type = p_elem.GetAttribute ("type");
|
||||
string type = SymbolTable.GetCSType(c_type);
|
||||
name = MangleName(p_elem.GetAttribute("name"));
|
||||
|
||||
if (SymbolTable.IsCallback (c_type)) {
|
||||
type = type.Replace (".", "");
|
||||
type = "GtkSharp." + type + "Wrapper";
|
||||
|
||||
sw.WriteLine(indent + "\t\t\t{0} {1}_wrapper = new {0} ({1});", type, name);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void Finish (StreamWriter sw, string indent)
|
||||
|
|
|
@ -57,6 +57,7 @@ namespace GtkSharp.Generation {
|
|||
// but this should work for now
|
||||
simple_types.Add ("gsize", "uint");
|
||||
simple_types.Add ("gssize", "int");
|
||||
simple_types.Add ("size_t", "int");
|
||||
|
||||
// FIXME: These ought to be handled properly.
|
||||
simple_types.Add ("GList", "System.IntPtr");
|
||||
|
|
|
@ -81,10 +81,6 @@ gtksharp_gnome_program_init (const char *app_id, const char *app_version,
|
|||
gnome_datadir = get_default (klass, GNOME_PARAM_GNOME_DATADIR);
|
||||
if (!gnome_sysconfdir)
|
||||
gnome_sysconfdir = get_default (klass, GNOME_PARAM_GNOME_SYSCONFDIR);
|
||||
/* FIXME: string[] marshalling broken */
|
||||
argc = 1;
|
||||
argv = g_new0 (char*, 1);
|
||||
argv[0] = app_id;
|
||||
|
||||
ret = gnome_program_init (app_id, app_version, module_info,
|
||||
argc, argv,
|
||||
|
@ -130,9 +126,6 @@ gtksharp_gnome_program_init (const char *app_id, const char *app_version,
|
|||
|
||||
g_free (unhandled);
|
||||
|
||||
/* Remove this too when marshalling fixed */
|
||||
g_free (argv);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
|
|
@ -1262,6 +1262,30 @@
|
|||
</attribute>
|
||||
</data>
|
||||
</rule>
|
||||
<!-- both temporarily disabled because we do not support
|
||||
Native->Managed delegates (only the other way around) -->
|
||||
<rule>
|
||||
<class name="GtkColorSelection">
|
||||
<method>SetChangePaletteHook</method>
|
||||
</class>
|
||||
<data>
|
||||
<attribute target="method">
|
||||
<name>hidden</name>
|
||||
<value>1</value>
|
||||
</attribute>
|
||||
</data>
|
||||
</rule>
|
||||
<rule>
|
||||
<class name="GtkTreeView">
|
||||
<method>GetSearchEqualFunc</method>
|
||||
</class>
|
||||
<data>
|
||||
<attribute target="method">
|
||||
<name>hidden</name>
|
||||
<value>1</value>
|
||||
</attribute>
|
||||
</data>
|
||||
</rule>
|
||||
|
||||
<!-- overloads -->
|
||||
<rule>
|
||||
|
|
Loading…
Reference in a new issue