From 5de50e936f70f27c27b0ae219f4a5f4e1dd7a16a Mon Sep 17 00:00:00 2001 From: Mike Kestner Date: Thu, 24 Sep 2009 17:21:16 +0000 Subject: [PATCH] 2009-09-23 Mike Kestner * glib/Value.cs: support long and ulong gtypes. still can't construct generically, but can cast to long/ulong and access via Val prop. [Fixes #539812] svn path=/trunk/gtk-sharp/; revision=142588 --- ChangeLog | 6 ++++ glib/Value.cs | 98 +++++++++++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 102 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index af82c3970..1314e9d5a 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2009-09-23 Mike Kestner + + * glib/Value.cs: support long and ulong gtypes. still can't construct + generically, but can cast to long/ulong and access via Val prop. + [Fixes #539812] + 2009-09-23 Mike Kestner * generator/ReturnValue.cs: support metadata override of default return diff --git a/glib/Value.cs b/glib/Value.cs index 406253331..81e67ad38 100755 --- a/glib/Value.cs +++ b/glib/Value.cs @@ -261,12 +261,18 @@ namespace GLib { public static explicit operator long (Value val) { - return g_value_get_int64 (ref val); + if (val.type == GType.Long.Val) + return val.GetLongForPlatform (); + else + return g_value_get_int64 (ref val); } public static explicit operator ulong (Value val) { - return g_value_get_uint64 (ref val); + if (val.type == GType.ULong.Val) + return val.GetULongForPlatform (); + else + return g_value_get_uint64 (ref val); } [Obsolete ("Replaced by Enum cast")] @@ -393,6 +399,62 @@ namespace GLib { this = (GLib.Value) parameters[0]; } + long GetLongForPlatform () + { + switch (Environment.OSVersion.Platform) { + case PlatformID.Win32NT: + case PlatformID.Win32S: + case PlatformID.Win32Windows: + case PlatformID.WinCE: + return (long) g_value_get_long_as_int (ref this); + default: + return g_value_get_long (ref this).ToInt64 (); + } + } + + ulong GetULongForPlatform () + { + switch (Environment.OSVersion.Platform) { + case PlatformID.Win32NT: + case PlatformID.Win32S: + case PlatformID.Win32Windows: + case PlatformID.WinCE: + return (ulong) g_value_get_ulong_as_uint (ref this); + default: + return g_value_get_ulong (ref this).ToUInt64 (); + } + } + + void SetLongForPlatform (long val) + { + switch (Environment.OSVersion.Platform) { + case PlatformID.Win32NT: + case PlatformID.Win32S: + case PlatformID.Win32Windows: + case PlatformID.WinCE: + g_value_set_long (ref this, (int) val); + break; + default: + g_value_set_long (ref this, new IntPtr (val)); + break; + } + } + + void SetULongForPlatform (ulong val) + { + switch (Environment.OSVersion.Platform) { + case PlatformID.Win32NT: + case PlatformID.Win32S: + case PlatformID.Win32Windows: + case PlatformID.WinCE: + g_value_set_ulong (ref this, (uint) val); + break; + default: + g_value_set_ulong (ref this, new UIntPtr (val)); + break; + } + } + object ToEnum () { Type t = GType.LookupType (type); @@ -438,8 +500,12 @@ namespace GLib { return (uint) this; else if (type == GType.Int64.Val) return (long) this; + else if (type == GType.Long.Val) + return GetLongForPlatform (); else if (type == GType.UInt64.Val) return (ulong) this; + else if (type == GType.ULong.Val) + return GetULongForPlatform (); else if (GType.Is (type, GType.Enum) || GType.Is (type, GType.Flags)) return ToEnum (); @@ -481,8 +547,12 @@ namespace GLib { g_value_set_uint (ref this, (uint) value); else if (type == GType.Int64.Val) g_value_set_int64 (ref this, (long) value); + else if (type == GType.Long.Val) + SetLongForPlatform ((long) value); else if (type == GType.UInt64.Val) g_value_set_uint64 (ref this, (ulong) value); + else if (type == GType.ULong.Val) + SetULongForPlatform ((ulong) value); else if (GType.Is (type, GType.Enum)) g_value_set_enum (ref this, (int)value); else if (GType.Is (type, GType.Flags)) @@ -599,6 +669,12 @@ namespace GLib { [DllImport ("libgobject-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)] static extern void g_value_set_int64 (ref Value val, long data); + [DllImport ("libgobject-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)] + static extern void g_value_set_long (ref Value val, IntPtr data); + + [DllImport ("libgobject-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)] + static extern void g_value_set_long (ref Value val, int data); + [DllImport ("libgobject-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)] static extern void g_value_set_uint64 (ref Value val, ulong data); @@ -617,6 +693,12 @@ namespace GLib { [DllImport ("libgobject-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)] static extern void g_value_set_uint (ref Value val, uint data); + [DllImport ("libgobject-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)] + static extern void g_value_set_ulong (ref Value val, UIntPtr data); + + [DllImport ("libgobject-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)] + static extern void g_value_set_ulong (ref Value val, uint data); + [DllImport ("libgobject-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)] static extern void g_value_set_enum (ref Value val, int data); [DllImport ("libgobject-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)] @@ -646,9 +728,21 @@ namespace GLib { [DllImport ("libgobject-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)] static extern long g_value_get_int64 (ref Value val); + [DllImport ("libgobject-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)] + static extern IntPtr g_value_get_long (ref Value val); + + [DllImport ("libgobject-2.0-0.dll", EntryPoint = "g_value_get_long", CallingConvention = CallingConvention.Cdecl)] + static extern int g_value_get_long_as_int (ref Value val); + [DllImport ("libgobject-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)] static extern ulong g_value_get_uint64 (ref Value val); + [DllImport ("libgobject-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)] + static extern UIntPtr g_value_get_ulong (ref Value val); + + [DllImport ("libgobject-2.0-0.dll", EntryPoint = "g_value_get_ulong", CallingConvention = CallingConvention.Cdecl)] + static extern int g_value_get_ulong_as_uint (ref Value val); + [DllImport ("libgobject-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)] static extern IntPtr g_value_get_object (ref Value val);