diff --git a/ChangeLog b/ChangeLog index a2c05f3dd..7bb87b602 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,25 @@ +2004-05-19 Mike Kestner + + * gtk/Container.custom : add CallbackInvoke and use it in OnForall. + +2004-05-19 Mike Kestner + + * generator/Makefile.am : add TimeTGen.cs + * generator/SymbolTable.cs : use new TimeTGen. + * generator/StringGen.cs : s/GLibSharp/GLib + * generator/TimeTGen.cs : generatable to marshal time_t. + * glib/time_t_CustomMarshaler.cs : kill + * glib/Makefile.am : remove time_t_CustomMarshaler.cs + * glib/Markup.cs : s/GLibSharp/GLib + * glib/Marshaller.cs : move to GLib namespace. Add methods to + marshal time_t to and from DateTime. + * glib/glue/time_t.c : kill + * glib/glue/Makefile.am : remove time_t.c + * glib/glue/makefile.win32 : remove time_t.o + * gnome/*.custom : use GLib.Marshaller instead of the time_t custom + marshaler. + * gtk/*.custom : s/GLibSharp/GLib + 2004-05-18 Zoltan Varga * glib/time_t_CustomMarshaler.cs: Fix custom marshalling after runtime diff --git a/generator/Makefile.am b/generator/Makefile.am index 75d6d3fcd..20596fecd 100644 --- a/generator/Makefile.am +++ b/generator/Makefile.am @@ -43,6 +43,7 @@ sources = \ StructBase.cs \ StructGen.cs \ SymbolTable.cs \ + TimeTGen.cs \ VMSignature.cs build_sources = $(addprefix $(srcdir)/, $(sources)) diff --git a/generator/StringGen.cs b/generator/StringGen.cs index 4dbfd5ad6..48f3eb783 100644 --- a/generator/StringGen.cs +++ b/generator/StringGen.cs @@ -16,12 +16,12 @@ namespace GtkSharp.Generation { public override string FromNativeReturn(String var) { - return "GLibSharp.Marshaller.PtrToStringGFree(" + var + ")"; + return "GLib.Marshaller.PtrToStringGFree(" + var + ")"; } public override string ToNativeReturn(String var) { - return "GLibSharp.Marshaller.StringToPtrGStrdup(" + var + ")"; + return "GLib.Marshaller.StringToPtrGStrdup(" + var + ")"; } } } diff --git a/generator/SymbolTable.cs b/generator/SymbolTable.cs index 05bbc15eb..090fb1f04 100644 --- a/generator/SymbolTable.cs +++ b/generator/SymbolTable.cs @@ -90,7 +90,7 @@ namespace GtkSharp.Generation { AddType (new SimpleGen ("GParamSpec", "IntPtr")); AddType (new SimpleGen ("gconstpointer", "IntPtr")); - AddType (new CustomMarshalerGen ("time_t", "System.DateTime", "GLib.time_t_CustomMarshaler")); + AddType (new TimeTGen ()); AddType (new ManualGen ("GSList", "GLib.SList")); AddType (new ManualGen ("GList", "GLib.List")); AddType (new ByRefGen ("GValue", "GLib.Value")); diff --git a/generator/TimeTGen.cs b/generator/TimeTGen.cs new file mode 100644 index 000000000..0997efca7 --- /dev/null +++ b/generator/TimeTGen.cs @@ -0,0 +1,80 @@ +// GtkSharp.Generation.TimeTGen.cs - The time_t Generatable. +// +// Author: Mike Kestner +// +// (c) 2003 Mike Kestner + +namespace GtkSharp.Generation { + + using System; + + public class TimeTGen : IGeneratable { + + string ctype; + string type; + string ns = ""; + + public string CName { + get + { + return "time_t"; + } + } + + public string Name { + get + { + return "DateTime"; + } + } + + public string QualifiedName { + get + { + return "System.DateTime"; + } + } + + public string MarshalType { + get + { + return "IntPtr"; + } + } + public string MarshalReturnType { + get + { + return "IntPtr"; + } + } + + public string CallByName (string var_name) + { + return "GLib.Marshaller.DateTimeTotime_t (" + var_name + ")"; + } + + public virtual string FromNative(string var) + { + return "GLib.Marshaller.time_tToDateTime (" + var + ")"; + } + + public virtual string FromNativeReturn(string var) + { + return FromNative (var); + } + + public virtual string ToNativeReturn(string var) + { + return CallByName (var); + } + + public void Generate () + { + } + + public void Generate (GenerationInfo gen_info) + { + } + } +} + diff --git a/glib/Makefile.am b/glib/Makefile.am index 6d70fef7f..5f8ac2127 100644 --- a/glib/Makefile.am +++ b/glib/Makefile.am @@ -37,7 +37,6 @@ sources = \ Source.cs \ Thread.cs \ Timeout.cs \ - time_t_CustomMarshaler.cs \ TypeConverter.cs \ Type.cs \ TypeFundamentals.cs \ diff --git a/glib/Markup.cs b/glib/Markup.cs index 4bdd43aa0..112b67252 100644 --- a/glib/Markup.cs +++ b/glib/Markup.cs @@ -23,7 +23,7 @@ namespace GLib { if (s == null) return ""; - return GLibSharp.Marshaller.PtrToStringGFree (g_markup_escape_text (s, s.Length)); + return Marshaller.PtrToStringGFree (g_markup_escape_text (s, s.Length)); } } } diff --git a/glib/Marshaller.cs b/glib/Marshaller.cs index 706d84269..a42c06575 100644 --- a/glib/Marshaller.cs +++ b/glib/Marshaller.cs @@ -1,26 +1,17 @@ // GLibSharp.Marshaller.cs : Marshalling utils // // Author: Rachel Hestilow +// Mike Kestner // -// (c) 2002, 2003 Rachel Hestilow +// Copyright (c) 2002, 2003 Rachel Hestilow +// Copyright (c) 2004 Novell, Inc. -namespace GLibSharp { +namespace GLib { using System; using System.Runtime.InteropServices; - /// - /// Marshalling utilities - /// - /// - /// - /// Utility class for internal wrapper use - /// - public class Marshaller { - // - // Do not allow instances of this - // private Marshaller () {} [DllImport("libglib-2.0-0.dll")] @@ -153,6 +144,18 @@ namespace GLibSharp { return unmarshal_32 (array, argc); } + + static DateTime local_epoch = new DateTime (1970, 1, 1, 0, 0, 0); + + public static IntPtr DateTimeTotime_t (DateTime time) + { + return new IntPtr (((int)time.Subtract (local_epoch).TotalSeconds)); + } + + public static DateTime time_tToDateTime (IntPtr time_t) + { + return local_epoch.AddSeconds ((int)time_t); + } } } diff --git a/glib/glue/Makefile.am b/glib/glue/Makefile.am index ee7966363..bbb685cc8 100644 --- a/glib/glue/Makefile.am +++ b/glib/glue/Makefile.am @@ -7,7 +7,6 @@ libglibsharpglue_la_SOURCES = \ list.c \ object.c \ slist.c \ - time_t.c \ type.c \ unichar.c \ value.c \ diff --git a/glib/glue/makefile.win32 b/glib/glue/makefile.win32 index 877b8e880..120617de1 100755 --- a/glib/glue/makefile.win32 +++ b/glib/glue/makefile.win32 @@ -8,7 +8,6 @@ GLUE_OBJS = \ list.o \ object.o \ slist.o \ - time_t.o \ type.o \ unichar.o \ value.o \ diff --git a/glib/glue/time_t.c b/glib/glue/time_t.c deleted file mode 100644 index 6ac4474c3..000000000 --- a/glib/glue/time_t.c +++ /dev/null @@ -1,20 +0,0 @@ -/* time_t.c : Glue to allocate time_t. - * - * Author: Mike Kestner - * - * Copyright 2004 Novell, Inc. - */ - -#include -#include -#include - -/* Forward declarations */ -gint gtksharp_time_t_sizeof (void); - -gint -gtksharp_time_t_sizeof () -{ - return sizeof (time_t); -} - diff --git a/glib/time_t_CustomMarshaler.cs b/glib/time_t_CustomMarshaler.cs deleted file mode 100644 index 16d1fbe01..000000000 --- a/glib/time_t_CustomMarshaler.cs +++ /dev/null @@ -1,76 +0,0 @@ -// time_t_CustomMarshaler.cs - Custom marshaling between time_t and DateTime -// -// Author: Mike Kestner -// -// Copyright (c) 2004 Novell, Inc. - -namespace GLib { - - using System; - using System.Runtime.InteropServices; - - public class time_t_CustomMarshaler : ICustomMarshaler { - - static time_t_CustomMarshaler marshaler; - int utc_offset; - DateTime local_epoch; - - private time_t_CustomMarshaler () - { - utc_offset = (int) DateTime.Now.Subtract (DateTime.UtcNow).TotalSeconds; - local_epoch = new DateTime (1970, 1, 1, 0, 0, 0); - } - - public static ICustomMarshaler GetInstance (string cookie) - { - if (marshaler == null) - marshaler = new time_t_CustomMarshaler (); - - return marshaler; - } - - public IntPtr MarshalManagedToNative (object obj) - { - DateTime dt = (DateTime) obj; - int size = GetNativeDataSize (); - IntPtr ptr = Marshal.AllocCoTaskMem (size); - int secs = ((int)dt.Subtract (local_epoch).TotalSeconds) + utc_offset; - if (GetNativeDataSize () == 4) - Marshal.WriteInt32 (ptr, secs); - else if (GetNativeDataSize () == 8) - Marshal.WriteInt64 (ptr, secs); - else - throw new Exception ("Unexpected native size for time_t."); - return ptr; - } - - public void CleanUpNativeData (IntPtr data) - { - Marshal.FreeCoTaskMem (data); - } - - public object MarshalNativeToManaged (IntPtr data) - { - long secs; - if (GetNativeDataSize () == 4) - secs = (int)data; - else if (GetNativeDataSize () == 8) - secs = (long)data; - else - throw new Exception ("Unexpected native size for time_t."); - - TimeSpan span = new TimeSpan ((int)secs - utc_offset); - return local_epoch.Add (span); - } - - public void CleanUpManagedData (object obj) {} - - [DllImport ("glibsharpglue")] - static extern int gtksharp_time_t_sizeof (); - - public int GetNativeDataSize () - { - return gtksharp_time_t_sizeof (); - } - } -} diff --git a/gnome/DateEdit.custom b/gnome/DateEdit.custom index 7ddbccf3c..d0d0b4abc 100644 --- a/gnome/DateEdit.custom +++ b/gnome/DateEdit.custom @@ -1,5 +1,5 @@ [DllImport("gnomeui-2")] - static extern IntPtr gnome_date_edit_new([MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(GLib.time_t_CustomMarshaler))] System.DateTime the_time, bool show_time, bool use_24_format); + static extern IntPtr gnome_date_edit_new(IntPtr the_time, bool show_time, bool use_24_format); public DateEdit () : this (System.DateTime.Now, true, false) { @@ -20,5 +20,5 @@ Construct (the_time, ((show_time) ? DateEditFlags.ShowTime : 0) | ((use_24_format) ? DateEditFlags.Two4Hr : 0)); return; } - Raw = gnome_date_edit_new(the_time, show_time, use_24_format); + Raw = gnome_date_edit_new(GLib.Marshaller.DateTimeTotime_t (the_time), show_time, use_24_format); } diff --git a/gnome/Scores.custom b/gnome/Scores.custom index 8622d673e..e25ad4eca 100644 --- a/gnome/Scores.custom +++ b/gnome/Scores.custom @@ -1,5 +1,5 @@ [DllImport("gnomeui-2")] - static extern IntPtr gnome_scores_new(uint n_scores, string names, out float scores, [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(GLib.time_t_CustomMarshaler))] System.DateTime times, bool clear); + static extern IntPtr gnome_scores_new(uint n_scores, string names, out float scores, IntPtr times, bool clear); public Scores (uint n_scores, string names, out float scores, System.DateTime times, bool clear) : base (IntPtr.Zero) { @@ -8,5 +8,5 @@ scores = Construct (n_scores, names, times, clear); return; } - Raw = gnome_scores_new(n_scores, names, out scores, times, clear); + Raw = gnome_scores_new(n_scores, names, out scores, GLib.Marshaller.DateTimeTotime_t (times), clear); } diff --git a/gtk/Application.cs b/gtk/Application.cs index 6a26193db..13f9195e9 100755 --- a/gtk/Application.cs +++ b/gtk/Application.cs @@ -41,7 +41,7 @@ namespace Gtk { progargs[0] = progname; args.CopyTo (progargs, 1); - IntPtr buf = GLibSharp.Marshaller.ArgvToArrayPtr (progargs); + IntPtr buf = GLib.Marshaller.ArgvToArrayPtr (progargs); int argc = progargs.Length; if (check) @@ -55,7 +55,7 @@ namespace Gtk { if (argc == 0) args = new string[0]; else { - progargs = GLibSharp.Marshaller.ArrayPtrToArgv (buf, argc); + progargs = GLib.Marshaller.ArrayPtrToArgv (buf, argc); args = new string[argc - 1]; Array.Copy (progargs, 1, args, 0, argc - 1); } diff --git a/gtk/ColorSelection.custom b/gtk/ColorSelection.custom index 3c64b00b3..6dbfc2067 100644 --- a/gtk/ColorSelection.custom +++ b/gtk/ColorSelection.custom @@ -9,7 +9,7 @@ public static string PaletteToString(Gdk.Color[] colors) { int n_colors = colors.Length; IntPtr raw_ret = gtk_color_selection_palette_to_string(colors, n_colors); - string ret = GLibSharp.Marshaller.PtrToStringGFree (raw_ret); + string ret = GLib.Marshaller.PtrToStringGFree (raw_ret); return ret; } diff --git a/gtk/Container.custom b/gtk/Container.custom index 9002db024..017814647 100644 --- a/gtk/Container.custom +++ b/gtk/Container.custom @@ -50,19 +50,48 @@ public Widget[] FocusChain { } [DllImport("gtksharpglue")] -static extern void gtksharp_container_base_forall (IntPtr handle, bool include_internals, Gtk.Callback cb, IntPtr data); +static extern void gtksharp_container_base_forall (IntPtr handle, bool include_internals, GtkSharp.CallbackNative cb, IntPtr data); [DllImport("gtksharpglue")] static extern void gtksharp_container_override_forall (GLib.GType gtype, ForallDelegate cb); -delegate void ForallDelegate (IntPtr container, bool include_internals, Gtk.Callback cb, IntPtr data); +delegate void ForallDelegate (IntPtr container, bool include_internals, GtkSharp.CallbackNative cb, IntPtr data); static ForallDelegate ForallCallback; -static void Forall_cb (IntPtr container, bool include_internals, Gtk.Callback cb, IntPtr data) +public struct CallbackInvoker { + GtkSharp.CallbackNative cb; + IntPtr data; + + internal CallbackInvoker (GtkSharp.CallbackNative cb, IntPtr data) + { + this.cb = cb; + this.data = data; + } + + internal IntPtr Data { + get { + return data; + } + } + + internal GtkSharp.CallbackNative Delegate { + get { + return cb; + } + } + + public void Invoke (Widget w) + { + cb (w.Handle, data); + } +} + +static void Forall_cb (IntPtr container, bool include_internals, GtkSharp.CallbackNative cb, IntPtr data) { Container obj = GLib.Object.GetObject (container, false) as Container; - obj.OnForall (include_internals, cb, data); + CallbackInvoker invoker = new CallbackInvoker (cb, data); + obj.OnForall (include_internals, invoker); } protected static void OverrideForall (GLib.GType gtype) @@ -72,8 +101,8 @@ protected static void OverrideForall (GLib.GType gtype) gtksharp_container_override_forall (gtype, ForallCallback); } -protected virtual void OnForall (bool include_internals, Gtk.Callback cb, IntPtr data) +protected virtual void OnForall (bool include_internals, CallbackInvoker invoker) { - gtksharp_container_base_forall (Handle, include_internals, cb, data); + gtksharp_container_base_forall (Handle, include_internals, invoker.Delegate, invoker.Data); } diff --git a/gtk/SelectionData.custom b/gtk/SelectionData.custom index 114c3e4d4..b42d95ccb 100644 --- a/gtk/SelectionData.custom +++ b/gtk/SelectionData.custom @@ -27,7 +27,7 @@ IntPtr text = gtk_selection_data_get_text (Handle); if (text == IntPtr.Zero) return null; - return GLibSharp.Marshaller.PtrToStringGFree (text); + return GLib.Marshaller.PtrToStringGFree (text); } set { gtk_selection_data_set_text (Handle, value, value.Length); diff --git a/gtk/TextIter.custom b/gtk/TextIter.custom index 30c46d1b3..775bb5a58 100755 --- a/gtk/TextIter.custom +++ b/gtk/TextIter.custom @@ -13,7 +13,7 @@ public string Char { get { IntPtr raw_ret = gtksharp_unichar_to_utf8_string (gtk_text_iter_get_char (ref this)); - string ret = GLibSharp.Marshaller.PtrToStringGFree(raw_ret); + string ret = GLib.Marshaller.PtrToStringGFree(raw_ret); return ret; } }