diff --git a/ChangeLog b/ChangeLog index deaae30b7..18e91e4b9 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,23 @@ +2005-04-04 Mike Kestner + + * gdk/Gdk.metadata : hide some manually implemented callback methods. + * gdk/*.custom : implement several methods containing persistent + callback parameters. + * generator/BoxedGen.cs : set gen_info.CurrentType in Generate. + * generator/ClassGen.cs : set gen_info.CurrentType in Generate. + * generator/Ctor.cs : set gen_info.CurrentMember in Generate. + * generator/GenerationInfo.cs : add CurrentMember and CurrentType. + * generator/Method.cs : set gen_info.CurrentMember in Generate. + * generator/MethodBody.cs : always generate null guarding for array + parameters, and add a nag for callback parameters without a scope attr. + * generator/ObjectGen.cs : set gen_info.CurrentType in Generate. + * generator/OpaqueGen.cs : set gen_info.CurrentType in Generate. + * generator/Parameters.cs : kill NullOk. add Scope property. + * generator/StructGen.cs : set gen_info.CurrentType in Generate. + * gtk/Gtk.metadata : kill a few null_ok attrs. + * pango/Pango.metadata : mark the callback params as call scope. kill + a couple null_ok attrs. + 2005-04-01 Dan Winship * samples/GtkDemo/*.cs: General fixup and cleanup; Remove some diff --git a/doc/en/Gdk/DestroyNotify.xml b/doc/en/Gdk/DestroyNotify.xml index da999a2e7..57fb1d32b 100644 --- a/doc/en/Gdk/DestroyNotify.xml +++ b/doc/en/Gdk/DestroyNotify.xml @@ -1,5 +1,5 @@ - + gdk-sharp 0.0.0.0 diff --git a/gdk/Display.custom b/gdk/Display.custom index 919ce5b64..0870bb6e5 100644 --- a/gdk/Display.custom +++ b/gdk/Display.custom @@ -73,3 +73,16 @@ return result; } + [DllImport("libgdk-win32-2.0-0.dll")] + static extern void gdk_display_add_client_message_filter (IntPtr raw, IntPtr message_type, GdkSharp.FilterFuncNative func, IntPtr data); + + public void AddClientMessageFilter (Gdk.Atom message_type, Gdk.FilterFunc func) + { + GdkSharp.FilterFuncWrapper func_wrapper = new GdkSharp.FilterFuncWrapper (func); + if (!PersistentData.Contains ("client_message_filter_func_list")) + PersistentData ["client_message_filter_func_list"] = new ArrayList (); + ArrayList func_list = PersistentData ["client_message_filter_func_list"] as ArrayList; + func_list.Add (func_wrapper); + gdk_display_add_client_message_filter (Handle, message_type == null ? IntPtr.Zero : message_type.Handle, func_wrapper.NativeDelegate, IntPtr.Zero); + } + diff --git a/gdk/Gdk.metadata b/gdk/Gdk.metadata index 364afc800..679a303f0 100644 --- a/gdk/Gdk.metadata +++ b/gdk/Gdk.metadata @@ -15,12 +15,15 @@ out 1 EventHelper + 1 + 1 const-gchar* 1 1 1 1 1 + 1 1 1 PangoHelper @@ -47,6 +50,7 @@ 1 1 1 + 1 1 1 1 @@ -61,7 +65,7 @@ out 1 1 - 1 + 1 1 1 1 @@ -104,9 +108,10 @@ 1 1 1 + GdkDrawable + 1 1 1 - GdkDrawable out out out @@ -115,6 +120,7 @@ out 1 1 + 1 1 1 1 @@ -146,6 +152,7 @@ 1 1 n_points + call 128 1 diff --git a/gdk/Global.custom b/gdk/Global.custom index b3ea067d8..135aefd37 100644 --- a/gdk/Global.custom +++ b/gdk/Global.custom @@ -191,3 +191,8 @@ return result; } + public static void AddClientMessageFilter (Gdk.Atom message_type, Gdk.FilterFunc func) + { + Gdk.Display.Default.AddClientMessageFilter (message_type, func); + } + diff --git a/gdk/Input.custom b/gdk/Input.custom new file mode 100644 index 000000000..d6a40ba11 --- /dev/null +++ b/gdk/Input.custom @@ -0,0 +1,58 @@ +// Gdk.Input.custom - Gdk Input class customizations +// +// Author: Mike Kestner +// +// Copyright (C) 2005 Novell, Inc. +// +// This code is inserted after the automatically generated code. +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of version 2 of the Lesser GNU General +// Public License as published by the Free Software Foundation. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the +// Free Software Foundation, Inc., 59 Temple Place - Suite 330, +// Boston, MA 02111-1307, USA. + + [GLib.CDeclCallback] + delegate void DestroyNotify (IntPtr data); + + static void ReleaseGCHandle (IntPtr data) + { + if (data == IntPtr.Zero) + return; + + GCHandle gch = (GCHandle) data; + gch.Free (); + } + + static DestroyNotify release_gchandle; + + [DllImport("libgdk-win32-2.0-0.dll")] + static extern int gdk_input_add_full (int source, int condition, GdkSharp.InputFunctionNative function, IntPtr data, DestroyNotify destroy); + + [Obsolete] + public static int AddFull (int source, Gdk.InputCondition condition, Gdk.InputFunction function, IntPtr data, Gdk.DestroyNotify destroy) + { + if (release_gchandle == null) + release_gchandle = new DestroyNotify (ReleaseGCHandle); + GdkSharp.InputFunctionWrapper function_wrapper = new GdkSharp.InputFunctionWrapper (function); + GCHandle gch = GCHandle.Alloc (function_wrapper); + return gdk_input_add_full (source, (int) condition, function_wrapper.NativeDelegate, (IntPtr) gch, release_gchandle); + } + + [Obsolete] + public static int Add (int source, Gdk.InputCondition condition, Gdk.InputFunction function) + { + if (release_gchandle == null) + release_gchandle = new DestroyNotify (ReleaseGCHandle); + GdkSharp.InputFunctionWrapper function_wrapper = new GdkSharp.InputFunctionWrapper (function); + GCHandle gch = GCHandle.Alloc (function_wrapper); + return gdk_input_add_full (source, (int) condition, function_wrapper.NativeDelegate, (IntPtr) gch, release_gchandle); + } diff --git a/gdk/Makefile.am b/gdk/Makefile.am index bd40b6a06..1363c2125 100644 --- a/gdk/Makefile.am +++ b/gdk/Makefile.am @@ -38,6 +38,7 @@ customs = \ DragContext.custom \ Drawable.custom \ Global.custom \ + Input.custom \ Keymap.custom \ Pixmap.custom \ Pixbuf.custom \ diff --git a/gdk/Pixbuf.custom b/gdk/Pixbuf.custom index d1c867b3e..ac7e68ee9 100644 --- a/gdk/Pixbuf.custom +++ b/gdk/Pixbuf.custom @@ -133,14 +133,22 @@ return ret; } - // overload to default the colorspace - public Pixbuf(byte [] data, bool has_alpha, int bits_per_sample, int width, int height, int rowstride, Gdk.PixbufDestroyNotify destroy_fn) : base (IntPtr.Zero) + [DllImport("libgdk_pixbuf-2.0-0.dll")] + static extern IntPtr gdk_pixbuf_new_from_data(byte[] data, int colorspace, bool has_alpha, int bits_per_sample, int width, int height, int rowstride, GdkSharp.PixbufDestroyNotifyNative destroy_fn, IntPtr destroy_fn_data); + + public Pixbuf (byte[] data, Gdk.Colorspace colorspace, bool has_alpha, int bits_per_sample, int width, int height, int rowstride, Gdk.PixbufDestroyNotify destroy_fn) : base (IntPtr.Zero) { - GdkSharp.PixbufDestroyNotifyWrapper destroy_fn_wrapper = null; - destroy_fn_wrapper = new GdkSharp.PixbufDestroyNotifyWrapper (destroy_fn); - Raw = gdk_pixbuf_new_from_data(data, (int) Gdk.Colorspace.Rgb, has_alpha, bits_per_sample, width, height, rowstride, destroy_fn_wrapper.NativeDelegate, IntPtr.Zero); + if (GetType () != typeof (Pixbuf)) { + throw new InvalidOperationException ("Can't override this constructor."); + } + GdkSharp.PixbufDestroyNotifyWrapper destroy_fn_wrapper = new GdkSharp.PixbufDestroyNotifyWrapper (destroy_fn); + Raw = gdk_pixbuf_new_from_data(data, (int) colorspace, has_alpha, bits_per_sample, width, height, rowstride, destroy_fn_wrapper.NativeDelegate, IntPtr.Zero); + PersistentData ["new_from_data_destroy_fn_wrapper"] = destroy_fn_wrapper; } + // overload to default the colorspace + public Pixbuf(byte [] data, bool has_alpha, int bits_per_sample, int width, int height, int rowstride, Gdk.PixbufDestroyNotify destroy_fn) : this (data, Gdk.Colorspace.Rgb, has_alpha, bits_per_sample, width, height, rowstride, destroy_fn) {} + public unsafe Pixbuf(byte[] data, bool copy_pixels) : base (IntPtr.Zero) { IntPtr error = IntPtr.Zero; @@ -289,8 +297,7 @@ public unsafe void SaveToCallback (PixbufSaveFunc save_func, string type, string[] option_keys, string[] option_values) { - GdkSharp.PixbufSaveFuncWrapper save_func_wrapper = null; - save_func_wrapper = new GdkSharp.PixbufSaveFuncWrapper (save_func); + GdkSharp.PixbufSaveFuncWrapper save_func_wrapper = new GdkSharp.PixbufSaveFuncWrapper (save_func); IntPtr error = IntPtr.Zero; IntPtr ntype = GLib.Marshaller.StringToPtrGStrdup (type); IntPtr[] nkeys = NullTerm (option_keys); diff --git a/gdk/Window.custom b/gdk/Window.custom index 8281a471f..702eaddae 100644 --- a/gdk/Window.custom +++ b/gdk/Window.custom @@ -24,7 +24,6 @@ public Window (Gdk.Window parent, Gdk.WindowAttr attributes, Gdk.WindowAttributesType attributes_mask) : this (parent, attributes, (int)attributes_mask) {} - [DllImport("libgdk-win32-2.0-0.dll")] static extern IntPtr gdk_window_get_children(IntPtr raw); @@ -104,6 +103,12 @@ } } + [DllImport("libgdk-win32-2.0-0.dll")] + static extern void gdk_window_add_filter (IntPtr handle, GdkSharp.FilterFuncNative wrapper, IntPtr data); + + [DllImport("libgdk-win32-2.0-0.dll")] + static extern void gdk_window_remove_filter (IntPtr handle, GdkSharp.FilterFuncNative wrapper, IntPtr data); + static Hashtable filter_all_hash; static Hashtable FilterAllHash { get { @@ -129,6 +134,26 @@ gdk_window_remove_filter (IntPtr.Zero, wrapper.NativeDelegate, IntPtr.Zero); } + public void AddFilter (FilterFunc function) + { + if (!PersistentData.Contains ("filter_func_hash")) + PersistentData ["filter_func_hash"] = new Hashtable (); + Hashtable hash = PersistentData ["filter_func_hash"] as Hashtable; + GdkSharp.FilterFuncWrapper wrapper = new GdkSharp.FilterFuncWrapper (function); + hash [function] = wrapper; + gdk_window_add_filter (Handle, wrapper.NativeDelegate, IntPtr.Zero); + } + + public void RemoveFilter (FilterFunc function) + { + Hashtable hash = PersistentData ["filter_func_hash"] as Hashtable; + GdkSharp.FilterFuncWrapper wrapper = hash [function] as GdkSharp.FilterFuncWrapper; + if (wrapper == null) + return; + hash.Remove (function); + gdk_window_remove_filter (Handle, wrapper.NativeDelegate, IntPtr.Zero); + } + #if MANLY_ENOUGH_TO_INCLUDE public Cairo.Graphics CairoGraphics (out int offset_x, out int offset_y) { diff --git a/generator/BoxedGen.cs b/generator/BoxedGen.cs index 0e9194cf0..94e28e2e4 100644 --- a/generator/BoxedGen.cs +++ b/generator/BoxedGen.cs @@ -31,6 +31,8 @@ namespace GtkSharp.Generation { public override void Generate (GenerationInfo gen_info) { + gen_info.CurrentType = Name; + if (!Validate ()) return; diff --git a/generator/CallbackGen.cs b/generator/CallbackGen.cs index 7d134082d..0daaa77be 100644 --- a/generator/CallbackGen.cs +++ b/generator/CallbackGen.cs @@ -160,6 +160,7 @@ namespace GtkSharp.Generation { public override void Generate (GenerationInfo gen_info) { + gen_info.CurrentType = Name; if (!retval.Validate ()) { Console.WriteLine("rettype: " + retval.CType + " in callback " + CName); Statistics.ThrottledCount++; diff --git a/generator/ClassGen.cs b/generator/ClassGen.cs index 641475ebc..507ccc088 100644 --- a/generator/ClassGen.cs +++ b/generator/ClassGen.cs @@ -36,6 +36,8 @@ namespace GtkSharp.Generation { public override void Generate (GenerationInfo gen_info) { + gen_info.CurrentType = Name; + StreamWriter sw = gen_info.Writer = gen_info.OpenStream(Name); sw.WriteLine ("namespace " + NS + " {"); diff --git a/generator/Ctor.cs b/generator/Ctor.cs index 20ed27996..0f8e55c50 100644 --- a/generator/Ctor.cs +++ b/generator/Ctor.cs @@ -87,6 +87,7 @@ namespace GtkSharp.Generation { public void Generate (GenerationInfo gen_info) { StreamWriter sw = gen_info.Writer; + gen_info.CurrentMember = CName; SymbolTable table = SymbolTable.Table; diff --git a/generator/GenerationInfo.cs b/generator/GenerationInfo.cs index 37c0573c6..626c722ff 100644 --- a/generator/GenerationInfo.cs +++ b/generator/GenerationInfo.cs @@ -2,7 +2,7 @@ // // Author: Mike Kestner // -// Copyright (c) 2003 Ximian Inc. +// Copyright (c) 2003-2005 Novell Inc. // // This program is free software; you can redistribute it and/or // modify it under the terms of version 2 of the GNU General Public @@ -127,6 +127,26 @@ namespace GtkSharp.Generation { glue_sw.Close (); } + string member; + public string CurrentMember { + get { + return typename + "." + member; + } + set { + member = value; + } + } + + string typename; + public string CurrentType { + get { + return typename; + } + set { + typename = value; + } + } + public StreamWriter OpenStream (string name) { char sep = Path.DirectorySeparatorChar; diff --git a/generator/Method.cs b/generator/Method.cs index 24905653d..6a1d84e24 100644 --- a/generator/Method.cs +++ b/generator/Method.cs @@ -252,6 +252,7 @@ namespace GtkSharp.Generation { if (!Initialize ()) return; + gen_info.CurrentMember = Name; if (implementor != null && IsStatic) return; diff --git a/generator/MethodBody.cs b/generator/MethodBody.cs index eb8fdcf92..ec6d0e927 100644 --- a/generator/MethodBody.cs +++ b/generator/MethodBody.cs @@ -49,9 +49,9 @@ namespace GtkSharp.Generation { private string CallArrayLength (Parameter array, Parameter length) { - string result = array.NullOk ? array.Name + " != null ? " : ""; + string result = array.Name + " != null ? "; result += CastFromInt (length.CSType) + array.Name + ".Length"; - result += array.NullOk ? ": 0" : ""; + result += ": 0"; return length.Generatable.CallByName (result); } @@ -126,8 +126,9 @@ namespace GtkSharp.Generation { if ((is_get || p.PassAs == "out") && p.CSType != p.MarshalType && !(gen is StructBase || gen is ByRefGen)) sw.WriteLine(indent + "\t\t\t" + gen.MarshalType + " " + name + "_as_native;"); else if (p.IsArray && p.MarshalType != p.CSType) { - sw.WriteLine(indent + "\t\t\t{0}[] native_" + p.Name + " = new {0} [{1}.Length];", p.MarshalType.TrimEnd('[', ']'), name); - sw.WriteLine(indent + "\t\t\tfor (int i = 0; i < {0}.Length; i++)", name); + sw.WriteLine(indent + "\t\t\tint cnt_" + p.Name + " = {0} == null ? 0 : {0}.Length;", name); + sw.WriteLine(indent + "\t\t\t{0}[] native_" + p.Name + " = new {0} [cnt_{1}];", p.MarshalType.TrimEnd('[', ']'), name); + sw.WriteLine(indent + "\t\t\tfor (int i = 0; i < cnt_{0}; i++)", name); if (gen is IManualMarshaler) sw.WriteLine(indent + "\t\t\t\tnative_{0} [i] = {1};", p.Name, (gen as IManualMarshaler).AllocNative (name + "[i]")); else @@ -137,14 +138,17 @@ namespace GtkSharp.Generation { if (gen is CallbackGen) { - //Console.WriteLine ("***Callback parameter " + gen.Name + " generated in method***" ); CallbackGen cbgen = gen as CallbackGen; string wrapper = cbgen.GenWrapper(impl_ns, gen_info); - sw.WriteLine (indent + "\t\t\t{0} {1}_wrapper = null;", wrapper, name); - sw.Write (indent + "\t\t\t"); - if (p.NullOk) - sw.Write ("if ({0} != null) ", name); - sw.WriteLine ("{1}_wrapper = new {0} ({1});", wrapper, p.Name); + switch (p.Scope) { + case "call": + default: + if (p.Scope == String.Empty) + Console.WriteLine ("Defaulting " + gen.Name + " param to 'call' scope in method " + gen_info.CurrentMember); + sw.WriteLine (indent + "\t\t\t{0} {1}_wrapper = new {0} ({2});", wrapper, name, p.Name); + break; + } + } } diff --git a/generator/ObjectGen.cs b/generator/ObjectGen.cs index bfd6e7a8d..0271122d3 100644 --- a/generator/ObjectGen.cs +++ b/generator/ObjectGen.cs @@ -116,6 +116,8 @@ namespace GtkSharp.Generation { public override void Generate (GenerationInfo gen_info) { + gen_info.CurrentType = Name; + DirectoryInfo di = GetDirectoryInfo (gen_info.Dir, gen_info.AssemblyName); StreamWriter sw = gen_info.Writer = gen_info.OpenStream (Name); diff --git a/generator/OpaqueGen.cs b/generator/OpaqueGen.cs index f6a871436..07cb63712 100644 --- a/generator/OpaqueGen.cs +++ b/generator/OpaqueGen.cs @@ -43,6 +43,8 @@ namespace GtkSharp.Generation { public override void Generate (GenerationInfo gen_info) { + gen_info.CurrentType = Name; + StreamWriter sw = gen_info.Writer = gen_info.OpenStream (Name); sw.WriteLine ("namespace " + NS + " {"); diff --git a/generator/Parameters.cs b/generator/Parameters.cs index 6fe2f701f..26661bdb8 100644 --- a/generator/Parameters.cs +++ b/generator/Parameters.cs @@ -155,12 +155,6 @@ namespace GtkSharp.Generation { } } - public bool NullOk { - get { - return elem.HasAttribute ("null_ok"); - } - } - public string PropertyName { get { return elem.GetAttribute("property_name"); @@ -182,6 +176,12 @@ namespace GtkSharp.Generation { } } + public string Scope { + get { + return elem.GetAttribute ("scope"); + } + } + public string CallByName (string call_parm_name) { string call_parm; @@ -190,9 +190,6 @@ namespace GtkSharp.Generation { else call_parm = SymbolTable.Table.CallByName(CType, call_parm_name); - if (NullOk && !CSType.EndsWith ("IntPtr") && !(Generatable is StructBase)) - call_parm = String.Format ("({0} != null) ? {1} : {2}", call_parm_name, call_parm, Generatable is CallbackGen ? "null" : "IntPtr.Zero"); - if (IsArray) call_parm = call_parm.Replace ("ref ", ""); diff --git a/generator/StructGen.cs b/generator/StructGen.cs index b44cdd43b..a1eb66f0b 100644 --- a/generator/StructGen.cs +++ b/generator/StructGen.cs @@ -31,6 +31,8 @@ namespace GtkSharp.Generation { public override void Generate (GenerationInfo gen_info) { + gen_info.CurrentType = Name; + if (!Validate ()) return; diff --git a/gtk/Gtk.metadata b/gtk/Gtk.metadata index 7d3d6f99f..2997a0ef1 100644 --- a/gtk/Gtk.metadata +++ b/gtk/Gtk.metadata @@ -30,9 +30,7 @@ BindingsActivate 1 1 - 1 1 - 1 1 gboolean GetEventsPending @@ -247,7 +245,6 @@ SizeRequested ToggleSizeAllocated ToggleSizeRequested - 1 1 Canceled Deactivated diff --git a/pango/Pango.metadata b/pango/Pango.metadata index cf6fcffd8..b56856f41 100644 --- a/pango/Pango.metadata +++ b/pango/Pango.metadata @@ -1,5 +1,6 @@ + call 1 1 1 @@ -15,6 +16,7 @@ 1 1 1 + call 1 out out @@ -33,9 +35,7 @@ 1 1 ref - 1 ref - 1 1 1