2004-05-19 Mike Kestner <mkestner@ximian.com>

* gtk/Container.custom : add CallbackInvoke and use it in OnForall.

2004-05-19  Mike Kestner  <mkestner@ximian.com>

	* 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

svn path=/trunk/gtk-sharp/; revision=27704
This commit is contained in:
Mike Kestner 2004-05-19 18:57:28 +00:00
parent fed2de1fe7
commit 9f54a63375
19 changed files with 167 additions and 131 deletions

View file

@ -1,3 +1,25 @@
2004-05-19 Mike Kestner <mkestner@ximian.com>
* gtk/Container.custom : add CallbackInvoke and use it in OnForall.
2004-05-19 Mike Kestner <mkestner@ximian.com>
* 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 <vargaz@freemail.hu>
* glib/time_t_CustomMarshaler.cs: Fix custom marshalling after runtime

View file

@ -43,6 +43,7 @@ sources = \
StructBase.cs \
StructGen.cs \
SymbolTable.cs \
TimeTGen.cs \
VMSignature.cs
build_sources = $(addprefix $(srcdir)/, $(sources))

View file

@ -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 + ")";
}
}
}

View file

@ -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"));

80
generator/TimeTGen.cs Normal file
View file

@ -0,0 +1,80 @@
// GtkSharp.Generation.TimeTGen.cs - The time_t Generatable.
//
// Author: Mike Kestner <mkestner@speakeasy.net>
//
// (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)
{
}
}
}

View file

@ -37,7 +37,6 @@ sources = \
Source.cs \
Thread.cs \
Timeout.cs \
time_t_CustomMarshaler.cs \
TypeConverter.cs \
Type.cs \
TypeFundamentals.cs \

View file

@ -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));
}
}
}

View file

@ -1,26 +1,17 @@
// GLibSharp.Marshaller.cs : Marshalling utils
//
// Author: Rachel Hestilow <rachel@nullenvoid.com>
// Mike Kestner <mkestner@ximian.com>
//
// (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;
/// <summary>
/// Marshalling utilities
/// </summary>
///
/// <remarks>
/// Utility class for internal wrapper use
/// </remarks>
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);
}
}
}

View file

@ -7,7 +7,6 @@ libglibsharpglue_la_SOURCES = \
list.c \
object.c \
slist.c \
time_t.c \
type.c \
unichar.c \
value.c \

View file

@ -8,7 +8,6 @@ GLUE_OBJS = \
list.o \
object.o \
slist.o \
time_t.o \
type.o \
unichar.o \
value.o \

View file

@ -1,20 +0,0 @@
/* time_t.c : Glue to allocate time_t.
*
* Author: Mike Kestner <mkestner@ximian.com>
*
* Copyright <c> 2004 Novell, Inc.
*/
#include <glib.h>
#include <time.h>
#include <stdio.h>
/* Forward declarations */
gint gtksharp_time_t_sizeof (void);
gint
gtksharp_time_t_sizeof ()
{
return sizeof (time_t);
}

View file

@ -1,76 +0,0 @@
// time_t_CustomMarshaler.cs - Custom marshaling between time_t and DateTime
//
// Author: Mike Kestner <mkestner@ximian.com>
//
// 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 ();
}
}
}

View file

@ -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);
}

View file

@ -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);
}

View file

@ -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);
}

View file

@ -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;
}

View file

@ -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);
}

View file

@ -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);

View file

@ -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;
}
}