From 9ad6d1b6a48f588a23fe8d1a68b8b5565638fc13 Mon Sep 17 00:00:00 2001 From: Vladimir Vukicevic Date: Sun, 10 Nov 2002 10:03:51 +0000 Subject: [PATCH] * generator/StructBase.cs: create a Zero static member for use when the IntPtr is NULL. * generator/SignalHandler.cs, generator/CallbackGen.cs: removed call to Initialize for structs * gtk/Clipboard.custom, gtk/ClipboardClearFunc.cs, gtk/ClipboardGetFunc.cs, gtk/GtkSharp.GtkClipboardClearFuncNative.cs, gtk/GtkSharp.ClipboardGetFuncNative.cs, SelectionData.custom: Hand-wrapped selection handling stuff, along with relevant signals and the like. * gnome/voidObjectAffineSVPintSignal.cs: removed Initialize for hand-wrapped signal * sample/GnomeHelloWorld.cs, sample/Size.cs: compare against .Zero instead of using IsNull * api/gtk-api.xml, sources/Gtk.metadata: metadata updates for hiding some manually-wrapped stuff svn path=/trunk/gtk-sharp/; revision=8912 --- ChangeLog | 24 + api/gtk-api.xml | 55 -- generator/CallbackGen.cs | 411 ++++++++------- generator/SignalHandler.cs | 392 +++++++------- generator/StructBase.cs | 534 ++++++++++---------- glue/Makefile.am | 1 + glue/clipboard.c | 56 ++ gnome/voidObjectAffineSVPintSignal.cs | 2 +- gtk/Clipboard.custom | 54 ++ gtk/ClipboardClearFunc.cs | 8 + gtk/ClipboardGetFunc.cs | 8 + gtk/GtkSharp.GtkClipboardClearFuncNative.cs | 31 ++ gtk/GtkSharp.GtkClipboardGetFuncNative.cs | 33 ++ gtk/Object.custom | 30 +- gtk/SelectionData.custom | 29 ++ sample/GnomeHelloWorld.cs | 2 +- sample/Size.cs | 2 +- sources/Gtk.metadata | 16 +- 18 files changed, 942 insertions(+), 746 deletions(-) create mode 100644 glue/clipboard.c create mode 100644 gtk/Clipboard.custom create mode 100644 gtk/ClipboardClearFunc.cs create mode 100644 gtk/ClipboardGetFunc.cs create mode 100644 gtk/GtkSharp.GtkClipboardClearFuncNative.cs create mode 100644 gtk/GtkSharp.GtkClipboardGetFuncNative.cs create mode 100644 gtk/SelectionData.custom diff --git a/ChangeLog b/ChangeLog index 6aae8c184..c214fb1e9 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,27 @@ +2002-11-10 Vladimir Vukicevic + + * generator/StructBase.cs: create a Zero static member for + use when the IntPtr is NULL. + + * generator/SignalHandler.cs, generator/CallbackGen.cs: removed + call to Initialize for structs + + * gtk/Clipboard.custom, gtk/ClipboardClearFunc.cs, + gtk/ClipboardGetFunc.cs, + gtk/GtkSharp.GtkClipboardClearFuncNative.cs, + gtk/GtkSharp.ClipboardGetFuncNative.cs, SelectionData.custom: + Hand-wrapped selection handling stuff, along with relevant + signals and the like. + + * gnome/voidObjectAffineSVPintSignal.cs: removed Initialize + for hand-wrapped signal + + * sample/GnomeHelloWorld.cs, sample/Size.cs: compare against + .Zero instead of using IsNull + + * api/gtk-api.xml, sources/Gtk.metadata: metadata updates for + hiding some manually-wrapped stuff + 2002-11-10 Alejandro Sánchez Acosta * sample/tutorial: added some examples for the gtk# tutorial diff --git a/api/gtk-api.xml b/api/gtk-api.xml index c68375edb..b8b7204b8 100644 --- a/api/gtk-api.xml +++ b/api/gtk-api.xml @@ -506,22 +506,6 @@ - - - - - - - - - - - - - - - - @@ -10487,26 +10471,6 @@ - - - - - - - - - - - - - - - - - - - - @@ -10809,28 +10773,9 @@ - - - - - - - - - - - - - - - - - - - diff --git a/generator/CallbackGen.cs b/generator/CallbackGen.cs index 28b3b8da5..2a80bd901 100644 --- a/generator/CallbackGen.cs +++ b/generator/CallbackGen.cs @@ -1,207 +1,204 @@ -// GtkSharp.Generation.CallbackGen.cs - The Callback Generatable. -// -// Author: Mike Kestner -// -// (c) 2002 Mike Kestner - -namespace GtkSharp.Generation { - - using System; - using System.IO; - using System.Xml; - - public class CallbackGen : GenBase, IGeneratable { - - private Parameters parms; - - public CallbackGen (XmlElement ns, XmlElement elem) : base (ns, elem) - { - if (elem ["parameters"] != null) - parms = new Parameters (elem ["parameters"]); - } - - public String MarshalType { - get - { - return NS + "Sharp." + Name + "Native"; - } - } - - public String MarshalReturnType { - get - { - return MarshalType; - } - } - - public String CallByName (String var_name) - { - return var_name + ".NativeDelegate"; - } - - public String FromNative(String var) - { - return var; - } - - public String FromNativeReturn(String var) - { - 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 = Name + "Native"; - - string filename = dir + sep + NS + "Sharp." + 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 ("// 2001-2002 Mike Kestner"); - sw.WriteLine (); - sw.WriteLine ("namespace " + NS + "Sharp {"); - sw.WriteLine (); - sw.WriteLine ("\tusing System;"); - sw.WriteLine (); - - 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 " + 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); - 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 ((i == count - 1) && 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 ()", 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) - return; - - XmlElement ret_elem = Elem["return-type"]; - if (ret_elem == null) { - Console.WriteLine("No return type in callback " + CName); - Statistics.ThrottledCount++; - return; - } - - string rettype = ret_elem.GetAttribute("type"); - string s_ret = SymbolTable.GetCSType (rettype); - if (s_ret == "") { - Console.WriteLine("rettype: " + rettype + " in callback " + CName); - Statistics.ThrottledCount++; - return; - } - - if ((parms != null) && !parms.Validate ()) { - Console.WriteLine(" in callback " + CName + " **** Stubbing it out ****"); - Statistics.ThrottledCount++; - parms = null; - } - - StreamWriter sw = CreateWriter (); - - string sig = ""; - 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++; - } - } -} - +// GtkSharp.Generation.CallbackGen.cs - The Callback Generatable. +// +// Author: Mike Kestner +// +// (c) 2002 Mike Kestner + +namespace GtkSharp.Generation { + + using System; + using System.IO; + using System.Xml; + + public class CallbackGen : GenBase, IGeneratable { + + private Parameters parms; + + public CallbackGen (XmlElement ns, XmlElement elem) : base (ns, elem) + { + if (elem ["parameters"] != null) + parms = new Parameters (elem ["parameters"]); + } + + public String MarshalType { + get + { + return NS + "Sharp." + Name + "Native"; + } + } + + public String MarshalReturnType { + get + { + return MarshalType; + } + } + + public String CallByName (String var_name) + { + return var_name + ".NativeDelegate"; + } + + public String FromNative(String var) + { + return var; + } + + public String FromNativeReturn(String var) + { + 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 = Name + "Native"; + + string filename = dir + sep + NS + "Sharp." + 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 ("// 2001-2002 Mike Kestner"); + sw.WriteLine (); + sw.WriteLine ("namespace " + NS + "Sharp {"); + sw.WriteLine (); + sw.WriteLine ("\tusing System;"); + sw.WriteLine (); + + 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 " + 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); + 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 ((i == count - 1) && 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); + 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 ()", 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) + return; + + XmlElement ret_elem = Elem["return-type"]; + if (ret_elem == null) { + Console.WriteLine("No return type in callback " + CName); + Statistics.ThrottledCount++; + return; + } + + string rettype = ret_elem.GetAttribute("type"); + string s_ret = SymbolTable.GetCSType (rettype); + if (s_ret == "") { + Console.WriteLine("rettype: " + rettype + " in callback " + CName); + Statistics.ThrottledCount++; + return; + } + + if ((parms != null) && !parms.Validate ()) { + Console.WriteLine(" in callback " + CName + " **** Stubbing it out ****"); + Statistics.ThrottledCount++; + parms = null; + } + + StreamWriter sw = CreateWriter (); + + string sig = ""; + 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++; + } + } +} + diff --git a/generator/SignalHandler.cs b/generator/SignalHandler.cs index 1b17e811f..47efd9ee0 100644 --- a/generator/SignalHandler.cs +++ b/generator/SignalHandler.cs @@ -1,197 +1,195 @@ -// GtkSharp.Generation.SignalHandler.cs - The SignalHandler marshaling Class. -// -// Author: Mike Kestner -// -// (c) 2002 Mike Kestner - -namespace GtkSharp.Generation { - - using System; - using System.Collections; - using System.IO; - using System.Xml; - - public class SignalHandler { - - public static String GetName(XmlElement sig, string ns, bool generate) - { - XmlElement ret_elem = sig["return-type"]; - if (ret_elem == null) { - Console.Write("Missing return-type "); - return ""; - } - - string retval = ret_elem.GetAttribute("type"); - if (retval == "") { - Console.Write("Invalid return-type "); - return ""; - } - - string s_ret = SymbolTable.GetCSType(retval); - string p_ret = SymbolTable.GetMarshalReturnType(retval); - if ((s_ret == "") || (p_ret == "")) { - Console.Write("Funky type: " + retval); - return ""; - } - - string key = retval; - string pinv = ""; - string name = SymbolTable.GetName(retval); - int pcnt = 0; - - ArrayList parms = new ArrayList(); - - XmlElement params_elem = sig["parameters"]; - if (params_elem == null) { - Console.Write("Missing parameters "); - return ""; - } - - foreach (XmlNode parm in params_elem.ChildNodes) { - if (!(parm is XmlElement) || parm.Name != "parameter") continue; - - XmlElement elem = (XmlElement) parm; - string type = elem.GetAttribute("type"); - string ptype = SymbolTable.GetMarshalType(type); - if (ptype == "") { - Console.Write("Funky type: " + type); - return ""; - } - - if (pcnt > 0) { - pinv += ", "; - } - - pinv += (ptype + " arg" + pcnt); - parms.Add(type); - if (SymbolTable.IsObject(type) || SymbolTable.IsInterface(type)) { - name += "Object"; - key += "Object"; - } else { - name += SymbolTable.GetName(type); - key += type; - } - pcnt++; - } - - String sname = name + "Signal"; - String dname = name + "Delegate"; - String cbname = name + "Callback"; - - if (!generate) - return ns + "." + sname; - - char sep = Path.DirectorySeparatorChar; - String dir = ".." + sep + ns.ToLower() + sep + "generated"; - - if (!Directory.Exists(dir)) { - Directory.CreateDirectory(dir); - } - - String filename = dir + sep + ns + "Sharp." + sname + ".cs"; - - FileStream stream = new FileStream (filename, FileMode.Create, FileAccess.Write); - StreamWriter sw = new StreamWriter (stream); - - sw.WriteLine ("// Generated File. Do not modify."); - sw.WriteLine ("// 2001-2002 Mike Kestner"); - sw.WriteLine (); - sw.WriteLine("namespace " + ns + "Sharp {"); - sw.WriteLine(); - sw.WriteLine("\tusing System;"); - sw.WriteLine("\tusing System.Runtime.InteropServices;"); - sw.WriteLine("\tusing GtkSharp;"); - sw.WriteLine(); - sw.Write("\tpublic delegate " + p_ret + " "); - sw.WriteLine(dname + "(" + pinv + ", int key);"); - sw.WriteLine(); - sw.WriteLine("\tpublic class " + sname + " : SignalCallback {"); - sw.WriteLine(); - sw.WriteLine("\t\tprivate static " + dname + " _Delegate;"); - sw.WriteLine(); - sw.Write("\t\tprivate static " + s_ret + " "); - sw.WriteLine(cbname + "(" + pinv + ", int key)"); - sw.WriteLine("\t\t{"); - sw.WriteLine("\t\t\tif (!_Instances.Contains(key))"); - sw.WriteLine("\t\t\t\tthrow new Exception(\"Unexpected signal key \" + key);"); - sw.WriteLine(); - sw.WriteLine("\t\t\t" + sname + " inst = (" + sname + ") _Instances[key];"); - if ((s_ret == "void") && (parms.Count == 1)) { - sw.WriteLine("\t\t\tEventHandler h = (EventHandler) inst._handler;"); - sw.WriteLine("\t\t\th (inst._obj, new EventArgs ());"); - sw.WriteLine("\t\t}"); - sw.WriteLine(); - } else { - sw.WriteLine("\t\t\tSignalArgs args = (SignalArgs) Activator.CreateInstance (inst._argstype);"); - if (parms.Count > 1) { - sw.WriteLine("\t\t\targs.Args = new object[" + (parms.Count-1) + "];"); - } - for (int idx=1; idx < parms.Count; idx++) { - string ctype = (string) parms[idx]; - ClassBase wrapper = SymbolTable.GetClassGen (ctype); - if ((wrapper != null && !(wrapper is StructBase)) || SymbolTable.IsManuallyWrapped (ctype)) { - sw.WriteLine("\t\t\tif (arg{0} == IntPtr.Zero)", idx); - sw.WriteLine("\t\t\t\targs.Args[{0}] = null;", idx - 1); - sw.WriteLine("\t\t\telse {"); - if (wrapper != null && wrapper is ObjectGen) - sw.WriteLine("\t\t\t\targs.Args[" + (idx-1) + "] = GLib.Object.GetObject(arg" + idx + ");"); - else - sw.WriteLine("\t\t\t\targs.Args[" + (idx-1) + "] = " + SymbolTable.FromNative (ctype, "arg" + idx) + ";"); - if ((wrapper != null && (wrapper is OpaqueGen)) || SymbolTable.IsManuallyWrapped (ctype)) { - sw.WriteLine("\t\t\t\tif (args.Args[" + (idx-1) + "] == null)"); - sw.WriteLine("\t\t\t\t\targs.Args[{0}] = new {1}(arg{2});", idx-1, SymbolTable.GetCSType (ctype), idx); - } - sw.WriteLine("\t\t\t}"); - } else { - if (wrapper != null && (wrapper is StructBase)) - sw.WriteLine("\t\t\targ{0}._Initialize ();", idx); - sw.WriteLine("\t\t\targs.Args[" + (idx-1) + "] = " + SymbolTable.FromNative (ctype, "arg" + idx) + ";"); - } - } - sw.WriteLine("\t\t\tobject[] argv = new object[2];"); - sw.WriteLine("\t\t\targv[0] = inst._obj;"); - sw.WriteLine("\t\t\targv[1] = args;"); - sw.WriteLine("\t\t\tinst._handler.DynamicInvoke(argv);"); - if (retval != "void") { - sw.WriteLine ("\t\t\tif (args.RetVal == null)"); - if (s_ret == "bool") - sw.WriteLine ("\t\t\t\treturn false;"); - else - sw.WriteLine ("\t\t\t\tthrow new Exception(\"args.RetVal unset in callback\");"); - - sw.WriteLine("\t\t\treturn (" + s_ret + ") args.RetVal;"); - } - sw.WriteLine("\t\t}"); - sw.WriteLine(); - } - sw.Write("\t\t[DllImport(\"gobject-2.0\")]"); - sw.Write("\t\tstatic extern void g_signal_connect_data("); - sw.Write("IntPtr obj, String name, " + dname + " cb, int key, IntPtr p,"); - sw.WriteLine(" int flags);"); - sw.WriteLine(); - sw.Write("\t\tpublic " + sname + "(GLib.Object obj, IntPtr raw, "); - sw.WriteLine("String name, MulticastDelegate eh, Type argstype) : base(obj, eh, argstype)"); - sw.WriteLine("\t\t{"); - sw.WriteLine("\t\t\tif (_Delegate == null) {"); - sw.WriteLine("\t\t\t\t_Delegate = new " + dname + "(" + cbname + ");"); - sw.WriteLine("\t\t\t}"); - sw.Write("\t\t\tg_signal_connect_data(raw, name, "); - sw.WriteLine("_Delegate, _key, new IntPtr(0), 0);"); - sw.WriteLine("\t\t}"); - sw.WriteLine(); - sw.WriteLine("\t\t~" + sname + "()"); - sw.WriteLine("\t\t{"); - sw.WriteLine("\t\t\t_Instances.Remove(_key);"); - sw.WriteLine("\t\t\tif(_Instances.Count == 0) {"); - sw.WriteLine("\t\t\t\t_Delegate = null;"); - sw.WriteLine("\t\t\t}"); - sw.WriteLine("\t\t}"); - sw.WriteLine("\t}"); - sw.WriteLine("}"); - sw.Close(); - - return ns + "Sharp." + sname; - } - } -} - +// GtkSharp.Generation.SignalHandler.cs - The SignalHandler marshaling Class. +// +// Author: Mike Kestner +// +// (c) 2002 Mike Kestner + +namespace GtkSharp.Generation { + + using System; + using System.Collections; + using System.IO; + using System.Xml; + + public class SignalHandler { + + public static String GetName(XmlElement sig, string ns, bool generate) + { + XmlElement ret_elem = sig["return-type"]; + if (ret_elem == null) { + Console.Write("Missing return-type "); + return ""; + } + + string retval = ret_elem.GetAttribute("type"); + if (retval == "") { + Console.Write("Invalid return-type "); + return ""; + } + + string s_ret = SymbolTable.GetCSType(retval); + string p_ret = SymbolTable.GetMarshalReturnType(retval); + if ((s_ret == "") || (p_ret == "")) { + Console.Write("Funky type: " + retval); + return ""; + } + + string key = retval; + string pinv = ""; + string name = SymbolTable.GetName(retval); + int pcnt = 0; + + ArrayList parms = new ArrayList(); + + XmlElement params_elem = sig["parameters"]; + if (params_elem == null) { + Console.Write("Missing parameters "); + return ""; + } + + foreach (XmlNode parm in params_elem.ChildNodes) { + if (!(parm is XmlElement) || parm.Name != "parameter") continue; + + XmlElement elem = (XmlElement) parm; + string type = elem.GetAttribute("type"); + string ptype = SymbolTable.GetMarshalType(type); + if (ptype == "") { + Console.Write("Funky type: " + type); + return ""; + } + + if (pcnt > 0) { + pinv += ", "; + } + + pinv += (ptype + " arg" + pcnt); + parms.Add(type); + if (SymbolTable.IsObject(type) || SymbolTable.IsInterface(type)) { + name += "Object"; + key += "Object"; + } else { + name += SymbolTable.GetName(type); + key += type; + } + pcnt++; + } + + String sname = name + "Signal"; + String dname = name + "Delegate"; + String cbname = name + "Callback"; + + if (!generate) + return ns + "." + sname; + + char sep = Path.DirectorySeparatorChar; + String dir = ".." + sep + ns.ToLower() + sep + "generated"; + + if (!Directory.Exists(dir)) { + Directory.CreateDirectory(dir); + } + + String filename = dir + sep + ns + "Sharp." + sname + ".cs"; + + FileStream stream = new FileStream (filename, FileMode.Create, FileAccess.Write); + StreamWriter sw = new StreamWriter (stream); + + sw.WriteLine ("// Generated File. Do not modify."); + sw.WriteLine ("// 2001-2002 Mike Kestner"); + sw.WriteLine (); + sw.WriteLine("namespace " + ns + "Sharp {"); + sw.WriteLine(); + sw.WriteLine("\tusing System;"); + sw.WriteLine("\tusing System.Runtime.InteropServices;"); + sw.WriteLine("\tusing GtkSharp;"); + sw.WriteLine(); + sw.Write("\tpublic delegate " + p_ret + " "); + sw.WriteLine(dname + "(" + pinv + ", int key);"); + sw.WriteLine(); + sw.WriteLine("\tpublic class " + sname + " : SignalCallback {"); + sw.WriteLine(); + sw.WriteLine("\t\tprivate static " + dname + " _Delegate;"); + sw.WriteLine(); + sw.Write("\t\tprivate static " + s_ret + " "); + sw.WriteLine(cbname + "(" + pinv + ", int key)"); + sw.WriteLine("\t\t{"); + sw.WriteLine("\t\t\tif (!_Instances.Contains(key))"); + sw.WriteLine("\t\t\t\tthrow new Exception(\"Unexpected signal key \" + key);"); + sw.WriteLine(); + sw.WriteLine("\t\t\t" + sname + " inst = (" + sname + ") _Instances[key];"); + if ((s_ret == "void") && (parms.Count == 1)) { + sw.WriteLine("\t\t\tEventHandler h = (EventHandler) inst._handler;"); + sw.WriteLine("\t\t\th (inst._obj, new EventArgs ());"); + sw.WriteLine("\t\t}"); + sw.WriteLine(); + } else { + sw.WriteLine("\t\t\tSignalArgs args = (SignalArgs) Activator.CreateInstance (inst._argstype);"); + if (parms.Count > 1) { + sw.WriteLine("\t\t\targs.Args = new object[" + (parms.Count-1) + "];"); + } + for (int idx=1; idx < parms.Count; idx++) { + string ctype = (string) parms[idx]; + ClassBase wrapper = SymbolTable.GetClassGen (ctype); + if ((wrapper != null && !(wrapper is StructBase)) || SymbolTable.IsManuallyWrapped (ctype)) { + sw.WriteLine("\t\t\tif (arg{0} == IntPtr.Zero)", idx); + sw.WriteLine("\t\t\t\targs.Args[{0}] = null;", idx - 1); + sw.WriteLine("\t\t\telse {"); + if (wrapper != null && wrapper is ObjectGen) + sw.WriteLine("\t\t\t\targs.Args[" + (idx-1) + "] = GLib.Object.GetObject(arg" + idx + ");"); + else + sw.WriteLine("\t\t\t\targs.Args[" + (idx-1) + "] = " + SymbolTable.FromNative (ctype, "arg" + idx) + ";"); + if ((wrapper != null && (wrapper is OpaqueGen)) || SymbolTable.IsManuallyWrapped (ctype)) { + sw.WriteLine("\t\t\t\tif (args.Args[" + (idx-1) + "] == null)"); + sw.WriteLine("\t\t\t\t\targs.Args[{0}] = new {1}(arg{2});", idx-1, SymbolTable.GetCSType (ctype), idx); + } + sw.WriteLine("\t\t\t}"); + } else { + sw.WriteLine("\t\t\targs.Args[" + (idx-1) + "] = " + SymbolTable.FromNative (ctype, "arg" + idx) + ";"); + } + } + sw.WriteLine("\t\t\tobject[] argv = new object[2];"); + sw.WriteLine("\t\t\targv[0] = inst._obj;"); + sw.WriteLine("\t\t\targv[1] = args;"); + sw.WriteLine("\t\t\tinst._handler.DynamicInvoke(argv);"); + if (retval != "void") { + sw.WriteLine ("\t\t\tif (args.RetVal == null)"); + if (s_ret == "bool") + sw.WriteLine ("\t\t\t\treturn false;"); + else + sw.WriteLine ("\t\t\t\tthrow new Exception(\"args.RetVal unset in callback\");"); + + sw.WriteLine("\t\t\treturn (" + s_ret + ") args.RetVal;"); + } + sw.WriteLine("\t\t}"); + sw.WriteLine(); + } + sw.Write("\t\t[DllImport(\"gobject-2.0\")]"); + sw.Write("\t\tstatic extern void g_signal_connect_data("); + sw.Write("IntPtr obj, String name, " + dname + " cb, int key, IntPtr p,"); + sw.WriteLine(" int flags);"); + sw.WriteLine(); + sw.Write("\t\tpublic " + sname + "(GLib.Object obj, IntPtr raw, "); + sw.WriteLine("String name, MulticastDelegate eh, Type argstype) : base(obj, eh, argstype)"); + sw.WriteLine("\t\t{"); + sw.WriteLine("\t\t\tif (_Delegate == null) {"); + sw.WriteLine("\t\t\t\t_Delegate = new " + dname + "(" + cbname + ");"); + sw.WriteLine("\t\t\t}"); + sw.Write("\t\t\tg_signal_connect_data(raw, name, "); + sw.WriteLine("_Delegate, _key, new IntPtr(0), 0);"); + sw.WriteLine("\t\t}"); + sw.WriteLine(); + sw.WriteLine("\t\t~" + sname + "()"); + sw.WriteLine("\t\t{"); + sw.WriteLine("\t\t\t_Instances.Remove(_key);"); + sw.WriteLine("\t\t\tif(_Instances.Count == 0) {"); + sw.WriteLine("\t\t\t\t_Delegate = null;"); + sw.WriteLine("\t\t\t}"); + sw.WriteLine("\t\t}"); + sw.WriteLine("\t}"); + sw.WriteLine("}"); + sw.Close(); + + return ns + "Sharp." + sname; + } + } +} + diff --git a/generator/StructBase.cs b/generator/StructBase.cs index 4ca64c213..67317370b 100644 --- a/generator/StructBase.cs +++ b/generator/StructBase.cs @@ -1,266 +1,268 @@ -// GtkSharp.Generation.StructBase.cs - The Structure/Object Base Class. -// -// Author: Mike Kestner -// -// (c) 2001 Mike Kestner - -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 (); - uint bitfields; - - public StructBase (XmlElement ns, XmlElement elem) : base (ns, elem) - { - hasDefaultConstructor = false; - - 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; - } - } - } - - public override String MarshalType { - get - { - return "ref " + QualifiedName; - } - } - - public override String MarshalReturnType { - get - { - return "IntPtr"; - } - } - - public override String CallByName (String var_name) - { - return "ref " + var_name; - } - - public override String CallByName () - { - return "ref this"; - } - - public override String AssignToName { - get { return "raw"; } - } - - public override String FromNative(String var) - { - return var; - } - - public override String FromNativeReturn(String var) - { - return QualifiedName + ".New (" + var + ")"; - } - - bool IsBit (XmlElement field) - { - return (field.HasAttribute("bits") && (field.GetAttribute("bits") == "1")); - } - - bool IsPointer (XmlElement field) - { - string c_type = field.GetAttribute("type"); - return (c_type[c_type.Length - 1] == '*'); - } - - protected void GenFields (StreamWriter sw) - { - bitfields = 0; - bool need_field = true; - foreach (XmlElement field in fields) { - if (IsBit (field)) { - if (need_field) - need_field = false; - else - continue; - } else - need_field = true; - GenField (field, sw); - } - } - - protected bool GetFieldInfo (XmlElement field, out string c_type, out string type, out string name) - { - name = ""; - c_type = field.GetAttribute ("type"); - type = SymbolTable.GetCSType (c_type); - if (IsBit (field)) { - type = "uint"; - } else if ((IsPointer (field) || SymbolTable.IsOpaque (c_type)) && type != "string") { - type = "IntPtr"; - name = "_"; - } else if (SymbolTable.IsCallback (c_type)) { - type = "IntPtr"; - } else { - if (type == "") { - Console.WriteLine ("Field has unknown Type {0}", c_type); - Statistics.ThrottledCount++; - return false; - } - } - - // FIXME: marshalling not implemented here in mono - if (field.HasAttribute("array_len")) - type = "IntPtr"; - - if (IsBit (field)) - name = String.Format ("_bitfield{0}", bitfields++); - else - name += MangleName (field.GetAttribute ("cname")); - - return true; - } - - protected bool GenField (XmlElement field, StreamWriter sw) - { - string c_type, type, name; - if (!GetFieldInfo (field, out c_type, out type, out name)) - return false; - sw.WriteLine ("\t\tpublic {0} {1};", type, name); - - if (field.HasAttribute("array_len")) - Console.WriteLine ("warning: array field {0}.{1} probably incorrectly generated", QualifiedName, name); - - string wrapped = SymbolTable.GetCSType (c_type); - string wrapped_name = MangleName (field.GetAttribute ("cname")); - if (SymbolTable.IsObject (c_type)) { - sw.WriteLine (); - sw.WriteLine ("\t\tpublic " + wrapped + " " + wrapped_name + " {"); - sw.WriteLine ("\t\t\tget { "); - sw.WriteLine ("\t\t\t\t" + wrapped + " ret = " + SymbolTable.FromNativeReturn(c_type, name) + ";"); - sw.WriteLine ("\t\t\t\tret.Ref ();"); - sw.WriteLine ("\t\t\t\treturn ret;"); - sw.WriteLine ("\t\t\t}"); - sw.WriteLine ("\t\t\tset { " + name + " = " + SymbolTable.CallByName (c_type, "value") + "; }"); - sw.WriteLine ("\t\t}"); - } else if (SymbolTable.IsOpaque (c_type)) { - sw.WriteLine (); - sw.WriteLine ("\t\tpublic " + wrapped + " " + wrapped_name + " {"); - sw.WriteLine ("\t\t\tget { "); - sw.WriteLine ("\t\t\t\t" + wrapped + " ret = " + SymbolTable.FromNativeReturn(c_type, name) + ";"); - sw.WriteLine ("\t\t\t\tif (ret == null) ret = new " + wrapped + "(" + name + ");"); - sw.WriteLine ("\t\t\t\treturn ret;"); - sw.WriteLine ("\t\t\t}"); - - sw.WriteLine ("\t\t\tset { " + name + " = " + SymbolTable.CallByName (c_type, "value") + "; }"); - sw.WriteLine ("\t\t}"); - } else if (IsPointer (field) && (SymbolTable.IsStruct (c_type) || SymbolTable.IsBoxed (c_type))) { - sw.WriteLine (); - sw.WriteLine ("\t\tpublic " + wrapped + " " + wrapped_name + " {"); - sw.WriteLine ("\t\t\tget { return " + SymbolTable.FromNativeReturn (c_type, name) + "; }"); - sw.WriteLine ("\t\t}"); - } - - return true; - } - - private String MangleName(String name) - { - if (name == "string") { - return "str1ng"; - } else if (name == "event") { - return "evnt"; - } else if (name == "null") { - return "is_null"; - } else if (name == "object") { - return "objekt"; - } else if (name == "ref") { - return "reference"; - } else if (name == "params") { - return "parms"; - } else if (name == "fixed") { - return "mfixed"; - } else if (name == "in") { - return "inn"; - } else { - return name; - } - } - - public virtual void Generate () - { - StreamWriter sw = CreateWriter (); - - sw.WriteLine ("\tusing System;"); - sw.WriteLine ("\tusing System.Collections;"); - sw.WriteLine ("\tusing System.Runtime.InteropServices;"); - sw.WriteLine (); - - sw.WriteLine("\t\t/// " + Name + " Struct "); - sw.WriteLine("\t\t/// "); - sw.WriteLine("\t\t/// "); - - sw.WriteLine ("\t[StructLayout(LayoutKind.Sequential)]"); - sw.WriteLine ("\tpublic struct " + Name + " {"); - sw.WriteLine (); - - GenFields (sw); - sw.WriteLine (); - GenCtors (sw); - GenMethods (sw, null, null, true); - AppendCustom(sw); - - sw.WriteLine ("\t}"); - CloseWriter (sw); - } - - protected override void GenCtors (StreamWriter sw) - { - sw.WriteLine ("\t\tbool _is_null;"); - sw.WriteLine ("\t\tpublic bool IsNull {"); - sw.WriteLine ("\t\t\tget { return _is_null; }"); - sw.WriteLine ("\t\t}"); - sw.WriteLine ("\t\tpublic void _Initialize () {"); - sw.WriteLine ("\t\t\t_is_null = false;"); - sw.WriteLine ("\t\t}"); - sw.WriteLine(); - sw.WriteLine ("\t\tpublic static " + QualifiedName + " New(IntPtr raw) {"); - sw.WriteLine ("\t\t\t{0} self = new {0}();", QualifiedName); - sw.WriteLine ("\t\t\tif (raw == IntPtr.Zero) {"); - sw.WriteLine ("\t\t\t\tself._is_null = true;"); - sw.WriteLine ("\t\t\t} else {"); - sw.WriteLine ("\t\t\t\tself = ({0}) Marshal.PtrToStructure (raw, self.GetType ());", QualifiedName); - sw.WriteLine ("\t\t\t\tself._is_null = false;"); - sw.WriteLine ("\t\t\t}"); - sw.WriteLine ("\t\t\treturn self;"); - sw.WriteLine ("\t\t}"); - sw.WriteLine(); - - foreach (Ctor ctor in Ctors) { - ctor.ForceStatic = true; - } - base.GenCtors (sw); - } - - } -} - +// GtkSharp.Generation.StructBase.cs - The Structure/Object Base Class. +// +// Author: Mike Kestner +// +// (c) 2001 Mike Kestner + +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 (); + uint bitfields; + + public StructBase (XmlElement ns, XmlElement elem) : base (ns, elem) + { + hasDefaultConstructor = false; + + 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; + } + } + } + + public override String MarshalType { + get + { + return "ref " + QualifiedName; + } + } + + public override String MarshalReturnType { + get + { + return "IntPtr"; + } + } + + public override String CallByName (String var_name) + { + return "ref " + var_name; + } + + public override String CallByName () + { + return "ref this"; + } + + public override String AssignToName { + get { return "raw"; } + } + + public override String FromNative(String var) + { + return var; + } + + public override String FromNativeReturn(String var) + { + return QualifiedName + ".New (" + var + ")"; + } + + bool IsBit (XmlElement field) + { + return (field.HasAttribute("bits") && (field.GetAttribute("bits") == "1")); + } + + bool IsPointer (XmlElement field) + { + string c_type = field.GetAttribute("type"); + return (c_type[c_type.Length - 1] == '*'); + } + + protected void GenFields (StreamWriter sw) + { + bitfields = 0; + bool need_field = true; + foreach (XmlElement field in fields) { + if (IsBit (field)) { + if (need_field) + need_field = false; + else + continue; + } else + need_field = true; + GenField (field, sw); + } + } + + protected bool GetFieldInfo (XmlElement field, out string c_type, out string type, out string name) + { + name = ""; + c_type = field.GetAttribute ("type"); + type = SymbolTable.GetCSType (c_type); + if (IsBit (field)) { + type = "uint"; + } else if ((IsPointer (field) || SymbolTable.IsOpaque (c_type)) && type != "string") { + type = "IntPtr"; + name = "_"; + } else if (SymbolTable.IsCallback (c_type)) { + type = "IntPtr"; + } else { + if (type == "") { + Console.WriteLine ("Field has unknown Type {0}", c_type); + Statistics.ThrottledCount++; + return false; + } + } + + // FIXME: marshalling not implemented here in mono + if (field.HasAttribute("array_len")) + type = "IntPtr"; + + if (IsBit (field)) + name = String.Format ("_bitfield{0}", bitfields++); + else + name += MangleName (field.GetAttribute ("cname")); + + return true; + } + + protected bool GenField (XmlElement field, StreamWriter sw) + { + string c_type, type, name; + if (!GetFieldInfo (field, out c_type, out type, out name)) + return false; + sw.WriteLine ("\t\tpublic {0} {1};", type, name); + + if (field.HasAttribute("array_len")) + Console.WriteLine ("warning: array field {0}.{1} probably incorrectly generated", QualifiedName, name); + + string wrapped = SymbolTable.GetCSType (c_type); + string wrapped_name = MangleName (field.GetAttribute ("cname")); + if (SymbolTable.IsObject (c_type)) { + sw.WriteLine (); + sw.WriteLine ("\t\tpublic " + wrapped + " " + wrapped_name + " {"); + sw.WriteLine ("\t\t\tget { "); + sw.WriteLine ("\t\t\t\t" + wrapped + " ret = " + SymbolTable.FromNativeReturn(c_type, name) + ";"); + sw.WriteLine ("\t\t\t\tret.Ref ();"); + sw.WriteLine ("\t\t\t\treturn ret;"); + sw.WriteLine ("\t\t\t}"); + sw.WriteLine ("\t\t\tset { " + name + " = " + SymbolTable.CallByName (c_type, "value") + "; }"); + sw.WriteLine ("\t\t}"); + } else if (SymbolTable.IsOpaque (c_type)) { + sw.WriteLine (); + sw.WriteLine ("\t\tpublic " + wrapped + " " + wrapped_name + " {"); + sw.WriteLine ("\t\t\tget { "); + sw.WriteLine ("\t\t\t\t" + wrapped + " ret = " + SymbolTable.FromNativeReturn(c_type, name) + ";"); + sw.WriteLine ("\t\t\t\tif (ret == null) ret = new " + wrapped + "(" + name + ");"); + sw.WriteLine ("\t\t\t\treturn ret;"); + sw.WriteLine ("\t\t\t}"); + + sw.WriteLine ("\t\t\tset { " + name + " = " + SymbolTable.CallByName (c_type, "value") + "; }"); + sw.WriteLine ("\t\t}"); + } else if (IsPointer (field) && (SymbolTable.IsStruct (c_type) || SymbolTable.IsBoxed (c_type))) { + sw.WriteLine (); + sw.WriteLine ("\t\tpublic " + wrapped + " " + wrapped_name + " {"); + sw.WriteLine ("\t\t\tget { return " + SymbolTable.FromNativeReturn (c_type, name) + "; }"); + sw.WriteLine ("\t\t}"); + } + + return true; + } + + private String MangleName(String name) + { + if (name == "string") { + return "str1ng"; + } else if (name == "event") { + return "evnt"; + } else if (name == "null") { + return "is_null"; + } else if (name == "object") { + return "objekt"; + } else if (name == "ref") { + return "reference"; + } else if (name == "params") { + return "parms"; + } else if (name == "fixed") { + return "mfixed"; + } else if (name == "in") { + return "inn"; + } else { + return name; + } + } + + public virtual void Generate () + { + StreamWriter sw = CreateWriter (); + + sw.WriteLine ("\tusing System;"); + sw.WriteLine ("\tusing System.Collections;"); + sw.WriteLine ("\tusing System.Runtime.InteropServices;"); + sw.WriteLine (); + + sw.WriteLine("\t\t/// " + Name + " Struct "); + sw.WriteLine("\t\t/// "); + sw.WriteLine("\t\t/// "); + + sw.WriteLine ("\t[StructLayout(LayoutKind.Sequential)]"); + sw.WriteLine ("\tpublic struct " + Name + " {"); + sw.WriteLine (); + + GenFields (sw); + sw.WriteLine (); + GenCtors (sw); + GenMethods (sw, null, null, true); + AppendCustom(sw); + + sw.WriteLine ("\t}"); + CloseWriter (sw); + } + + protected override void GenCtors (StreamWriter sw) + { + sw.WriteLine ("\t\tpublic static {0} Zero = new {0} ();", QualifiedName); + sw.WriteLine(); + 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 (); + sw.WriteLine ("\t\tpublic static bool operator == ({0} a, {0} b)", QualifiedName); + sw.WriteLine ("\t\t{"); + sw.WriteLine ("\t\t\treturn a.Equals (b);"); + sw.WriteLine ("\t\t}"); + sw.WriteLine (); + sw.WriteLine ("\t\tpublic static bool operator != ({0} a, {0} b)", QualifiedName); + sw.WriteLine ("\t\t{"); + sw.WriteLine ("\t\t\treturn ! a.Equals (b);"); + sw.WriteLine ("\t\t}"); + sw.WriteLine(); + + foreach (Ctor ctor in Ctors) { + ctor.ForceStatic = true; + } + base.GenCtors (sw); + } + + } +} + diff --git a/glue/Makefile.am b/glue/Makefile.am index 941a3a2a7..190be94e7 100644 --- a/glue/Makefile.am +++ b/glue/Makefile.am @@ -16,6 +16,7 @@ BASESOURCES = \ type.c \ widget.c \ list.c \ + clipboard.c \ # GNOMESOURCES = \ diff --git a/glue/clipboard.c b/glue/clipboard.c new file mode 100644 index 000000000..9fb8c69e5 --- /dev/null +++ b/glue/clipboard.c @@ -0,0 +1,56 @@ +/* + * clipboard.c + */ + +#include + +GSList * +gtksharp_clipboard_target_list_add (GSList *list, char *target, guint flags, guint info) +{ + GtkTargetEntry *entry = g_new0 (GtkTargetEntry, 1); + + entry->target = g_strdup (target); + entry->flags = flags; + entry->info = info; + + return g_slist_prepend (list, entry); +} + +GtkTargetEntry * +gtksharp_clipboard_target_list_to_array (GSList *list) +{ + GtkTargetEntry *targets; + GSList *iter; + int i; + + targets = g_new0 (GtkTargetEntry, g_slist_length (list)); + for (iter = list, i = 0; iter; iter = iter->next, i++) { + GtkTargetEntry *t = (GtkTargetEntry *) iter->data; + targets[i].target = t->target; /* NOT COPIED */ + targets[i].flags = t->flags; + targets[i].info = t->info; + } + + return targets; +} + +void +gtksharp_clipboard_target_array_free (GtkTargetEntry *targets) +{ + g_free (targets); +} + +void +gtksharp_clipboard_target_list_free (GSList *list) +{ + GSList *iter; + + for (iter = list; iter; iter = iter->next) { + GtkTargetEntry *t = (GtkTargetEntry *) iter->data; + g_free (t->target); + g_free (t); + } + + g_slist_free (list); +} + diff --git a/gnome/voidObjectAffineSVPintSignal.cs b/gnome/voidObjectAffineSVPintSignal.cs index e49211a57..a860f4eae 100644 --- a/gnome/voidObjectAffineSVPintSignal.cs +++ b/gnome/voidObjectAffineSVPintSignal.cs @@ -27,7 +27,7 @@ namespace Gnome { } else { args.Args[0] = null; } - arg2._Initialize (); + args.Args[1] = arg2; args.Args[2] = arg3; diff --git a/gtk/Clipboard.custom b/gtk/Clipboard.custom new file mode 100644 index 000000000..0904f6e0c --- /dev/null +++ b/gtk/Clipboard.custom @@ -0,0 +1,54 @@ + + public static Hashtable clipboard_objects = new Hashtable (); + private static uint clipboard_object_next_id = 0; + + [DllImport("gtk-x11-2.0")] + static extern bool gtk_clipboard_set_with_data(IntPtr raw, IntPtr targets, int n_targets, GtkSharp.GtkClipboardGetFuncNative get_func, GtkSharp.GtkClipboardClearFuncNative clear_func, uint id); + + [DllImport("gtksharpglue")] + static extern IntPtr gtksharp_clipboard_target_list_add (IntPtr list, string name, uint flags, uint info); + + [DllImport("gtksharpglue")] + static extern IntPtr gtksharp_clipboard_target_list_to_array (IntPtr list); + + [DllImport("gtksharpglue")] + static extern void gtksharp_clipboard_target_array_free (IntPtr targets); + + [DllImport("gtksharpglue")] + static extern void gtksharp_clipboard_target_list_free (IntPtr list); + + GtkSharp.GtkClipboardGetFuncWrapper get_func_wrapper; + GtkSharp.GtkClipboardClearFuncWrapper clear_func_wrapper; + + public bool Set (Gtk.TargetEntry[] targets, + Gtk.ClipboardGetFunc get_func, + Gtk.ClipboardClearFunc clear_func, + object data) + { + uint this_id; + + lock (clipboard_objects) { + this_id = clipboard_object_next_id++; + clipboard_objects[this_id] = data; + } + + get_func_wrapper = new GtkSharp.GtkClipboardGetFuncWrapper (get_func); + clear_func_wrapper = new GtkSharp.GtkClipboardClearFuncWrapper (clear_func); + + IntPtr list = IntPtr.Zero; + + foreach (Gtk.TargetEntry t in targets) { + list = gtksharp_clipboard_target_list_add (list, t.target, t.flags, t.info); + } + + IntPtr array = gtksharp_clipboard_target_list_to_array (list); + + bool ret = gtk_clipboard_set_with_data (Handle, array, targets.Length, get_func_wrapper.NativeDelegate, clear_func_wrapper.NativeDelegate, this_id); + + gtksharp_clipboard_target_array_free (array); + gtksharp_clipboard_target_list_free (list); + + return ret; + } + + diff --git a/gtk/ClipboardClearFunc.cs b/gtk/ClipboardClearFunc.cs new file mode 100644 index 000000000..e09bc497a --- /dev/null +++ b/gtk/ClipboardClearFunc.cs @@ -0,0 +1,8 @@ +// Generated File. Do not modify. +// 2001-2002 Mike Kestner + +namespace Gtk { + + public delegate void ClipboardClearFunc(Gtk.Clipboard clipboard, object o); + +} diff --git a/gtk/ClipboardGetFunc.cs b/gtk/ClipboardGetFunc.cs new file mode 100644 index 000000000..a6118598c --- /dev/null +++ b/gtk/ClipboardGetFunc.cs @@ -0,0 +1,8 @@ +// Generated File. Do not modify. +// 2001-2002 Mike Kestner + +namespace Gtk { + + public delegate void ClipboardGetFunc(Gtk.Clipboard clipboard, ref Gtk.SelectionData selection_data, uint info, object o); + +} diff --git a/gtk/GtkSharp.GtkClipboardClearFuncNative.cs b/gtk/GtkSharp.GtkClipboardClearFuncNative.cs new file mode 100644 index 000000000..58f7450fc --- /dev/null +++ b/gtk/GtkSharp.GtkClipboardClearFuncNative.cs @@ -0,0 +1,31 @@ + +namespace GtkSharp { + + using System; + using System.Collections; + public delegate void GtkClipboardClearFuncNative(IntPtr clipboard, uint objid); + + public class GtkClipboardClearFuncWrapper : GLib.DelegateWrapper { + + public void NativeCallback (IntPtr clipboard, uint objid) + { + object[] _args = new object[2]; + _args[0] = (Gtk.Clipboard) GLib.Opaque.GetOpaque(clipboard); + if (_args[0] == null) + _args[0] = new Gtk.Clipboard(clipboard); + _args[1] = Gtk.Clipboard.clipboard_objects[objid]; + _managed ((Gtk.Clipboard) _args[0], _args[1]); + Gtk.Clipboard.clipboard_objects.Remove (objid); + } + + public GtkClipboardClearFuncNative NativeDelegate; + protected Gtk.ClipboardClearFunc _managed; + + public GtkClipboardClearFuncWrapper (Gtk.ClipboardClearFunc managed) : base () + { + NativeDelegate = new GtkClipboardClearFuncNative (NativeCallback); + _managed = managed; + } + } + +} diff --git a/gtk/GtkSharp.GtkClipboardGetFuncNative.cs b/gtk/GtkSharp.GtkClipboardGetFuncNative.cs new file mode 100644 index 000000000..df5633091 --- /dev/null +++ b/gtk/GtkSharp.GtkClipboardGetFuncNative.cs @@ -0,0 +1,33 @@ + +namespace GtkSharp { + + using System; + using System.Collections; + public delegate void GtkClipboardGetFuncNative(IntPtr clipboard, ref Gtk.SelectionData selection_data, uint info, uint obj_id); + + public class GtkClipboardGetFuncWrapper : GLib.DelegateWrapper { + + public void NativeCallback (IntPtr clipboard, ref Gtk.SelectionData selection_data, uint info, uint obj_id) + { + object[] _args = new object[4]; + _args[0] = (Gtk.Clipboard) GLib.Opaque.GetOpaque(clipboard); + if (_args[0] == null) + _args[0] = new Gtk.Clipboard(clipboard); + _args[1] = selection_data; + _args[2] = info; + _args[3] = Gtk.Clipboard.clipboard_objects[obj_id]; + + _managed ((Gtk.Clipboard) _args[0], ref selection_data, (uint) _args[2], _args[3]); + } + + public GtkClipboardGetFuncNative NativeDelegate; + protected Gtk.ClipboardGetFunc _managed; + + public GtkClipboardGetFuncWrapper (Gtk.ClipboardGetFunc managed) : base () + { + NativeDelegate = new GtkClipboardGetFuncNative (NativeCallback); + _managed = managed; + } + } + +} diff --git a/gtk/Object.custom b/gtk/Object.custom index c121d571d..c98808c47 100755 --- a/gtk/Object.custom +++ b/gtk/Object.custom @@ -6,23 +6,19 @@ // // This code is inserted after the automatically generated code. - [DllImport("gtksharpglue")] - static extern void gtksharp_object_unref_if_floating (IntPtr raw); + private static extern bool gtksharp_object_is_floating (IntPtr raw); - protected override void DisposeNative () - { - if (_needs_unref) - base.DisposeNative (); - else - gtksharp_object_unref_if_floating (Handle); + protected override IntPtr Raw { + get { + return base.Raw; + } + set { + base.Raw = value; + if (!needs_ref && gtksharp_object_is_floating (value)) { + Ref (); + Sink (); + } +// System.Diagnostics.Debug.WriteLine ("Gtk.Object:set_Raw: object type is: " + (this as GLib.Object).GType.Name + " refcount now: " + RefCount + " needs_ref: " + needs_ref); + } } - - private bool _needs_unref = false; - - public override void Ref () - { - _needs_unref = true; - base.Ref (); - } - diff --git a/gtk/SelectionData.custom b/gtk/SelectionData.custom new file mode 100644 index 000000000..86fa69574 --- /dev/null +++ b/gtk/SelectionData.custom @@ -0,0 +1,29 @@ + + [DllImport("gtk-x11-2.0")] + private static extern string gtk_selection_data_get_text (ref Gtk.SelectionData selection_data); + + [DllImport("gtk-x11-2.0")] + private static extern void gtk_selection_data_set_text (ref Gtk.SelectionData selection_data, string str, int len); + + public string Text { + get { + return gtk_selection_data_get_text (ref this); + } + set { + gtk_selection_data_set_text (ref this, value, value.Length); + } + } + + [DllImport("gtk-x11-2.0")] + static extern void gtk_selection_data_set (ref Gtk.SelectionData raw, IntPtr type, int format, byte[] data, int length); + + public byte[] Data { + get { + byte[] ret = new byte[length]; + Marshal.Copy (_data, ret, 0, length); + return ret; + } + set { + gtk_selection_data_set (ref this, _type, format, value, value.Length); + } + } diff --git a/sample/GnomeHelloWorld.cs b/sample/GnomeHelloWorld.cs index 039ddadc8..65f771e04 100644 --- a/sample/GnomeHelloWorld.cs +++ b/sample/GnomeHelloWorld.cs @@ -161,7 +161,7 @@ namespace GtkSamples { if (type != Gdk.WindowType.Child) Console.WriteLine ("Struct field accessors appear to be broken."); - if (!ev.IsNull && ev.type == EventType.TwoButtonPress && ev.button == 1) { + if ((ev != Gdk.EventButton.Zero) && ev.type == EventType.TwoButtonPress && ev.button == 1) { g_spawn_command_line_async ("mono " + entries[idx].program, IntPtr.Zero); } } diff --git a/sample/Size.cs b/sample/Size.cs index b135dc4c1..f3f218bf0 100644 --- a/sample/Size.cs +++ b/sample/Size.cs @@ -34,7 +34,7 @@ namespace GtkSamples { static void Size_Allocated (object obj, SizeAllocatedArgs args) { Gdk.Rectangle rect = args.Allocation; - if (rect.IsNull) + if (rect == Gdk.Rectangle.Zero) Console.WriteLine ("ERROR: Allocation is null!"); Console.WriteLine ("Size: ({0}, {1})", rect.width, rect.height); } diff --git a/sources/Gtk.metadata b/sources/Gtk.metadata index 44431284d..e32aac04c 100644 --- a/sources/Gtk.metadata +++ b/sources/Gtk.metadata @@ -1286,6 +1286,19 @@ + + + GetText + SetText + Set + + + + hidden + 1 + + + @@ -1854,7 +1867,7 @@ - +