2001-09-27 19:17:33 +02:00
|
|
|
// GLib.Value.cs - GLib Value class implementation
|
2001-09-19 13:37:15 +02:00
|
|
|
//
|
|
|
|
// Author: Mike Kestner <mkestner@speakeasy.net>
|
|
|
|
//
|
2004-04-12 17:54:57 +02:00
|
|
|
// Copyright (c) 2001 Mike Kestner
|
|
|
|
// Copyright (c) 2003-2004 Novell, Inc.
|
2004-06-25 20:42:19 +02:00
|
|
|
//
|
|
|
|
// 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.
|
|
|
|
|
2001-09-19 13:37:15 +02:00
|
|
|
|
|
|
|
namespace GLib {
|
|
|
|
|
|
|
|
using System;
|
2004-02-02 19:21:02 +01:00
|
|
|
using System.Collections;
|
2001-09-19 13:37:15 +02:00
|
|
|
using System.Runtime.InteropServices;
|
|
|
|
|
2004-04-07 05:41:13 +02:00
|
|
|
[StructLayout (LayoutKind.Sequential)]
|
2004-04-12 17:54:57 +02:00
|
|
|
public struct Value : IDisposable {
|
2001-09-28 02:28:30 +02:00
|
|
|
|
2004-05-07 15:42:59 +02:00
|
|
|
IntPtr type;
|
2004-04-12 17:54:57 +02:00
|
|
|
long pad_1;
|
|
|
|
long pad_2;
|
2001-09-28 02:28:30 +02:00
|
|
|
|
2004-04-12 17:54:57 +02:00
|
|
|
public static Value Empty;
|
2001-09-19 13:37:15 +02:00
|
|
|
|
2004-02-02 19:21:02 +01:00
|
|
|
[DllImport("libgobject-2.0-0.dll")]
|
2004-04-12 17:54:57 +02:00
|
|
|
static extern void g_value_init (ref GLib.Value val, IntPtr gtype);
|
2001-09-28 02:28:30 +02:00
|
|
|
|
2004-04-12 17:54:57 +02:00
|
|
|
[DllImport("libgobject-2.0-0.dll")]
|
|
|
|
static extern void g_value_unset (ref GLib.Value val);
|
2002-05-02 23:57:41 +02:00
|
|
|
|
2004-12-07 20:03:55 +01:00
|
|
|
[DllImport("glibsharpglue-2")]
|
2004-04-12 17:54:57 +02:00
|
|
|
static extern IntPtr gtksharp_value_create_from_property(ref GLib.Value val, IntPtr obj, string name);
|
2002-05-02 23:57:41 +02:00
|
|
|
|
2004-12-07 20:03:55 +01:00
|
|
|
[DllImport("glibsharpglue-2")]
|
2004-05-07 15:42:59 +02:00
|
|
|
static extern IntPtr gtksharp_value_create_from_type_and_property(ref GLib.Value val, IntPtr gtype, string name);
|
|
|
|
|
2004-12-07 20:03:55 +01:00
|
|
|
[DllImport("glibsharpglue-2")]
|
2004-11-16 19:03:58 +01:00
|
|
|
static extern IntPtr gtksharp_value_create_from_type_name(ref GLib.Value val, string type_name);
|
|
|
|
|
2004-04-12 17:54:57 +02:00
|
|
|
public void Dispose ()
|
2002-05-02 23:57:41 +02:00
|
|
|
{
|
2004-04-12 17:54:57 +02:00
|
|
|
g_value_unset (ref this);
|
2002-05-02 23:57:41 +02:00
|
|
|
}
|
|
|
|
|
2004-05-05 22:14:14 +02:00
|
|
|
public void Init (GLib.GType gtype)
|
|
|
|
{
|
|
|
|
g_value_init (ref this, gtype.Val);
|
|
|
|
}
|
|
|
|
|
2004-04-12 17:54:57 +02:00
|
|
|
public Value (GLib.GType gtype)
|
|
|
|
{
|
2004-05-07 15:42:59 +02:00
|
|
|
type = IntPtr.Zero;
|
2004-04-12 17:54:57 +02:00
|
|
|
pad_1 = pad_2 = 0;
|
|
|
|
g_value_init (ref this, gtype.Val);
|
2004-01-14 19:05:50 +01:00
|
|
|
}
|
|
|
|
|
2004-04-12 17:54:57 +02:00
|
|
|
public Value (GLib.Object obj, string prop_name)
|
2002-06-05 23:59:10 +02:00
|
|
|
{
|
2004-05-07 15:42:59 +02:00
|
|
|
type = IntPtr.Zero;
|
2004-04-12 17:54:57 +02:00
|
|
|
pad_1 = pad_2 = 0;
|
|
|
|
gtksharp_value_create_from_property (ref this, obj.Handle, prop_name);
|
2002-06-05 23:59:10 +02:00
|
|
|
}
|
|
|
|
|
2003-02-22 05:34:56 +01:00
|
|
|
[DllImport("libgobject-2.0-0.dll")]
|
2004-04-12 17:54:57 +02:00
|
|
|
static extern void g_value_set_boolean (ref Value val, bool data);
|
2001-09-28 02:28:30 +02:00
|
|
|
|
2004-04-12 17:54:57 +02:00
|
|
|
public Value (bool val) : this (GType.Boolean)
|
2002-05-02 23:57:41 +02:00
|
|
|
{
|
2004-04-12 17:54:57 +02:00
|
|
|
g_value_set_boolean (ref this, val);
|
2002-05-02 23:57:41 +02:00
|
|
|
}
|
|
|
|
|
2003-02-22 05:34:56 +01:00
|
|
|
[DllImport("libgobject-2.0-0.dll")]
|
2004-04-12 17:54:57 +02:00
|
|
|
static extern void g_value_set_boxed (ref Value val, IntPtr data);
|
2002-06-23 20:49:33 +02:00
|
|
|
|
2004-11-16 19:03:58 +01:00
|
|
|
public Value (Opaque val, string type_name)
|
2002-07-26 08:08:52 +02:00
|
|
|
{
|
2004-11-16 19:03:58 +01:00
|
|
|
type = IntPtr.Zero;
|
|
|
|
pad_1 = pad_2 = 0;
|
|
|
|
gtksharp_value_create_from_type_name (ref this, type_name);
|
|
|
|
g_value_set_boxed (ref this, val.Handle);
|
2002-07-26 08:08:52 +02:00
|
|
|
}
|
|
|
|
|
2004-11-16 19:03:58 +01:00
|
|
|
[Obsolete]
|
2003-10-15 22:13:50 +02:00
|
|
|
public Value (IntPtr obj, string prop_name, Opaque val)
|
2001-09-28 02:28:30 +02:00
|
|
|
{
|
2004-05-07 15:42:59 +02:00
|
|
|
type = IntPtr.Zero;
|
2004-04-12 17:54:57 +02:00
|
|
|
pad_1 = pad_2 = 0;
|
|
|
|
gtksharp_value_create_from_property (ref this, obj, prop_name);
|
|
|
|
g_value_set_boxed (ref this, val.Handle);
|
2001-09-28 02:28:30 +02:00
|
|
|
}
|
|
|
|
|
2003-02-22 05:34:56 +01:00
|
|
|
[DllImport("libgobject-2.0-0.dll")]
|
2004-04-12 17:54:57 +02:00
|
|
|
static extern void g_value_set_double (ref Value val, double data);
|
2002-06-23 20:49:33 +02:00
|
|
|
|
2004-04-12 17:54:57 +02:00
|
|
|
public Value (double val) : this (GType.Double)
|
2001-09-28 20:23:14 +02:00
|
|
|
{
|
2004-04-12 17:54:57 +02:00
|
|
|
g_value_set_double (ref this, val);
|
2001-09-28 20:23:14 +02:00
|
|
|
}
|
|
|
|
|
2003-02-22 05:34:56 +01:00
|
|
|
[DllImport("libgobject-2.0-0.dll")]
|
2004-04-12 17:54:57 +02:00
|
|
|
static extern void g_value_set_float (ref Value val, float data);
|
2001-09-19 13:37:15 +02:00
|
|
|
|
2004-04-12 17:54:57 +02:00
|
|
|
public Value (float val) : this (GType.Float)
|
2001-09-27 19:17:33 +02:00
|
|
|
{
|
2004-04-12 17:54:57 +02:00
|
|
|
g_value_set_float (ref this, val);
|
2001-09-27 19:17:33 +02:00
|
|
|
}
|
2001-09-19 13:37:15 +02:00
|
|
|
|
2003-02-22 05:34:56 +01:00
|
|
|
[DllImport("libgobject-2.0-0.dll")]
|
2004-04-12 17:54:57 +02:00
|
|
|
static extern void g_value_set_int (ref Value val, int data);
|
2001-09-29 22:08:30 +02:00
|
|
|
|
2004-04-12 17:54:57 +02:00
|
|
|
public Value (int val) : this (GType.Int)
|
2001-09-29 22:08:30 +02:00
|
|
|
{
|
2004-04-12 17:54:57 +02:00
|
|
|
g_value_set_int (ref this, val);
|
2001-09-29 22:08:30 +02:00
|
|
|
}
|
|
|
|
|
2004-12-03 21:04:18 +01:00
|
|
|
[DllImport("libgobject-2.0-0.dll")]
|
|
|
|
static extern void g_value_set_int64 (ref Value val, long data);
|
|
|
|
|
|
|
|
public Value (long val) : this (GType.Int64)
|
|
|
|
{
|
|
|
|
g_value_set_int64 (ref this, val);
|
|
|
|
}
|
|
|
|
|
|
|
|
[DllImport("libgobject-2.0-0.dll")]
|
|
|
|
static extern void g_value_set_uint64 (ref Value val, ulong data);
|
|
|
|
|
|
|
|
public Value (ulong val) : this (GType.UInt64)
|
|
|
|
{
|
|
|
|
g_value_set_uint64 (ref this, val);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-01-27 01:50:46 +01:00
|
|
|
[DllImport("glibsharpglue")]
|
|
|
|
static extern int gtksharp_object_get_ref_count (IntPtr obj);
|
|
|
|
|
2003-02-22 05:34:56 +01:00
|
|
|
[DllImport("libgobject-2.0-0.dll")]
|
2004-04-12 17:54:57 +02:00
|
|
|
static extern void g_value_set_object (ref Value val, IntPtr data);
|
2002-06-23 20:49:33 +02:00
|
|
|
|
2004-07-23 16:54:48 +02:00
|
|
|
public Value (GLib.Object val) : this (val == null ? GType.Object : val.NativeType)
|
2002-05-02 23:57:41 +02:00
|
|
|
{
|
2004-07-23 16:54:48 +02:00
|
|
|
g_value_set_object (ref this, val == null ? IntPtr.Zero : val.Handle);
|
2002-05-02 23:57:41 +02:00
|
|
|
}
|
|
|
|
|
2003-02-22 05:34:56 +01:00
|
|
|
[DllImport("libgobject-2.0-0.dll")]
|
2004-04-12 17:54:57 +02:00
|
|
|
static extern void g_value_set_pointer (ref Value val, IntPtr data);
|
2002-05-02 23:57:41 +02:00
|
|
|
|
2004-04-12 17:54:57 +02:00
|
|
|
public Value (IntPtr val) : this (GType.Pointer)
|
2002-05-02 23:57:41 +02:00
|
|
|
{
|
2004-04-12 17:54:57 +02:00
|
|
|
g_value_set_pointer (ref this, val);
|
2002-05-02 23:57:41 +02:00
|
|
|
}
|
|
|
|
|
2003-02-22 05:34:56 +01:00
|
|
|
[DllImport("libgobject-2.0-0.dll")]
|
2004-04-12 17:54:57 +02:00
|
|
|
static extern void g_value_set_string (ref Value val, string data);
|
2002-06-23 20:49:33 +02:00
|
|
|
|
2004-04-12 17:54:57 +02:00
|
|
|
public Value (string val) : this (GType.String)
|
2001-09-19 13:37:15 +02:00
|
|
|
{
|
2004-04-12 17:54:57 +02:00
|
|
|
g_value_set_string (ref this, val);
|
2001-09-28 02:28:30 +02:00
|
|
|
}
|
|
|
|
|
2003-02-22 05:34:56 +01:00
|
|
|
[DllImport("libgobject-2.0-0.dll")]
|
2004-04-12 17:54:57 +02:00
|
|
|
static extern void g_value_set_uint (ref Value val, uint data);
|
2001-09-28 02:28:30 +02:00
|
|
|
|
2004-04-12 17:54:57 +02:00
|
|
|
public Value (uint val) : this (GType.UInt)
|
2001-09-28 02:28:30 +02:00
|
|
|
{
|
2004-04-12 17:54:57 +02:00
|
|
|
g_value_set_uint (ref this, val);
|
2001-09-28 02:28:30 +02:00
|
|
|
}
|
|
|
|
|
2004-04-12 17:54:57 +02:00
|
|
|
public Value (ushort val) : this (GType.UInt)
|
2002-10-27 03:30:51 +01:00
|
|
|
{
|
2004-04-12 17:54:57 +02:00
|
|
|
g_value_set_uint (ref this, val);
|
2002-10-27 03:30:51 +01:00
|
|
|
}
|
|
|
|
|
2003-02-22 05:34:56 +01:00
|
|
|
[DllImport("libgobject-2.0-0.dll")]
|
2004-04-12 17:54:57 +02:00
|
|
|
static extern void g_value_set_enum (ref Value val, int data);
|
2003-02-22 05:34:56 +01:00
|
|
|
[DllImport("libgobject-2.0-0.dll")]
|
2004-04-12 17:54:57 +02:00
|
|
|
static extern void g_value_set_flags (ref Value val, uint data);
|
2003-05-23 01:39:04 +02:00
|
|
|
[DllImport("libgobject-2.0-0.dll")]
|
2004-04-12 17:54:57 +02:00
|
|
|
static extern void g_value_set_char (ref Value val, char data);
|
2002-06-25 00:04:10 +02:00
|
|
|
|
2004-11-16 19:03:58 +01:00
|
|
|
public Value (EnumWrapper wrap, string type_name)
|
|
|
|
{
|
|
|
|
type = IntPtr.Zero;
|
|
|
|
pad_1 = pad_2 = 0;
|
|
|
|
gtksharp_value_create_from_type_name (ref this, type_name);
|
|
|
|
if (wrap.flags)
|
|
|
|
g_value_set_flags (ref this, (uint) (int) wrap);
|
|
|
|
else
|
|
|
|
g_value_set_enum (ref this, (int) wrap);
|
|
|
|
}
|
|
|
|
|
|
|
|
[Obsolete]
|
2004-05-07 15:42:59 +02:00
|
|
|
public Value (GLib.Object obj, string prop_name, EnumWrapper wrap)
|
2002-06-25 00:04:10 +02:00
|
|
|
{
|
2004-05-07 15:42:59 +02:00
|
|
|
type = IntPtr.Zero;
|
2004-04-12 17:54:57 +02:00
|
|
|
pad_1 = pad_2 = 0;
|
2004-05-17 19:52:00 +02:00
|
|
|
gtksharp_value_create_from_type_and_property (ref this, obj.NativeType.Val, prop_name);
|
2002-08-04 00:24:37 +02:00
|
|
|
if (wrap.flags)
|
2004-04-12 17:54:57 +02:00
|
|
|
g_value_set_flags (ref this, (uint) (int) wrap);
|
2002-08-04 00:24:37 +02:00
|
|
|
else
|
2004-04-12 17:54:57 +02:00
|
|
|
g_value_set_enum (ref this, (int) wrap);
|
2002-06-25 00:04:10 +02:00
|
|
|
}
|
|
|
|
|
2003-05-19 09:18:52 +02:00
|
|
|
public Value (object obj)
|
|
|
|
{
|
2004-05-07 15:42:59 +02:00
|
|
|
type = IntPtr.Zero;
|
2004-04-12 17:54:57 +02:00
|
|
|
pad_1 = pad_2 = 0;
|
|
|
|
|
2004-04-13 22:54:49 +02:00
|
|
|
GType gtype = TypeConverter.LookupType (obj.GetType ());
|
2004-05-28 18:59:21 +02:00
|
|
|
if (gtype == GType.Object) {
|
2004-04-12 17:54:57 +02:00
|
|
|
g_value_init (ref this, ((GLib.Object) obj).NativeType.Val);
|
2003-05-19 09:18:52 +02:00
|
|
|
} else {
|
2004-04-13 22:54:49 +02:00
|
|
|
g_value_init (ref this, gtype.Val);
|
2003-05-19 09:18:52 +02:00
|
|
|
}
|
2004-02-17 06:09:13 +01:00
|
|
|
|
2004-04-12 17:54:57 +02:00
|
|
|
Val = obj;
|
2003-05-19 09:18:52 +02:00
|
|
|
}
|
|
|
|
|
2003-02-22 05:34:56 +01:00
|
|
|
[DllImport("libgobject-2.0-0.dll")]
|
2004-04-12 17:54:57 +02:00
|
|
|
static extern bool g_value_get_boolean (ref Value val);
|
2001-09-28 02:28:30 +02:00
|
|
|
|
|
|
|
public static explicit operator bool (Value val)
|
|
|
|
{
|
2004-04-12 17:54:57 +02:00
|
|
|
return g_value_get_boolean (ref val);
|
2001-09-19 13:37:15 +02:00
|
|
|
}
|
|
|
|
|
2003-02-22 05:34:56 +01:00
|
|
|
[DllImport("libgobject-2.0-0.dll")]
|
2004-04-12 17:54:57 +02:00
|
|
|
static extern IntPtr g_value_get_boxed (ref Value val);
|
2002-06-23 20:49:33 +02:00
|
|
|
|
2002-07-26 08:08:52 +02:00
|
|
|
public static explicit operator GLib.Opaque (Value val)
|
|
|
|
{
|
2004-04-12 17:54:57 +02:00
|
|
|
return GLib.Opaque.GetOpaque (g_value_get_boxed (ref val));
|
2002-07-26 08:08:52 +02:00
|
|
|
}
|
|
|
|
|
2002-05-02 23:57:41 +02:00
|
|
|
public static explicit operator GLib.Boxed (Value val)
|
|
|
|
{
|
2004-04-12 17:54:57 +02:00
|
|
|
return new GLib.Boxed (g_value_get_boxed (ref val));
|
2002-05-02 23:57:41 +02:00
|
|
|
}
|
|
|
|
|
2003-02-22 05:34:56 +01:00
|
|
|
[DllImport("libgobject-2.0-0.dll")]
|
2004-04-12 17:54:57 +02:00
|
|
|
static extern double g_value_get_double (ref Value val);
|
2002-05-02 23:57:41 +02:00
|
|
|
|
|
|
|
public static explicit operator double (Value val)
|
|
|
|
{
|
2004-04-12 17:54:57 +02:00
|
|
|
return g_value_get_double (ref val);
|
2002-05-02 23:57:41 +02:00
|
|
|
}
|
|
|
|
|
2003-02-22 05:34:56 +01:00
|
|
|
[DllImport("libgobject-2.0-0.dll")]
|
2004-04-12 17:54:57 +02:00
|
|
|
static extern float g_value_get_float (ref Value val);
|
2002-05-02 23:57:41 +02:00
|
|
|
|
|
|
|
public static explicit operator float (Value val)
|
|
|
|
{
|
2004-04-12 17:54:57 +02:00
|
|
|
return g_value_get_float (ref val);
|
2002-05-02 23:57:41 +02:00
|
|
|
}
|
|
|
|
|
2003-02-22 05:34:56 +01:00
|
|
|
[DllImport("libgobject-2.0-0.dll")]
|
2004-04-12 17:54:57 +02:00
|
|
|
static extern int g_value_get_int (ref Value val);
|
2001-09-29 22:08:30 +02:00
|
|
|
|
|
|
|
public static explicit operator int (Value val)
|
|
|
|
{
|
2004-04-12 17:54:57 +02:00
|
|
|
return g_value_get_int (ref val);
|
2001-09-29 22:08:30 +02:00
|
|
|
}
|
|
|
|
|
2004-12-03 21:04:18 +01:00
|
|
|
[DllImport("libgobject-2.0-0.dll")]
|
|
|
|
static extern long g_value_get_int64 (ref Value val);
|
|
|
|
|
|
|
|
public static explicit operator long (Value val)
|
|
|
|
{
|
|
|
|
return g_value_get_int64 (ref val);
|
|
|
|
}
|
|
|
|
|
|
|
|
[DllImport("libgobject-2.0-0.dll")]
|
|
|
|
static extern ulong g_value_get_uint64 (ref Value val);
|
|
|
|
|
|
|
|
public static explicit operator ulong (Value val)
|
|
|
|
{
|
|
|
|
return g_value_get_uint64 (ref val);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-02-22 05:34:56 +01:00
|
|
|
[DllImport("libgobject-2.0-0.dll")]
|
2004-04-12 17:54:57 +02:00
|
|
|
static extern IntPtr g_value_get_object (ref Value val);
|
2002-05-02 23:57:41 +02:00
|
|
|
|
|
|
|
public static explicit operator GLib.Object (Value val)
|
|
|
|
{
|
2005-01-27 01:50:46 +01:00
|
|
|
return GLib.Object.GetObject(g_value_get_object (ref val), false);
|
2002-05-02 23:57:41 +02:00
|
|
|
}
|
|
|
|
|
2002-06-25 01:38:51 +02:00
|
|
|
public static explicit operator GLib.UnwrappedObject (Value val)
|
|
|
|
{
|
2004-04-12 17:54:57 +02:00
|
|
|
return new UnwrappedObject(g_value_get_object (ref val));
|
2002-06-25 01:38:51 +02:00
|
|
|
}
|
|
|
|
|
2003-02-22 05:34:56 +01:00
|
|
|
[DllImport("libgobject-2.0-0.dll")]
|
2004-04-12 17:54:57 +02:00
|
|
|
static extern IntPtr g_value_get_pointer (ref Value val);
|
2002-05-02 23:57:41 +02:00
|
|
|
|
|
|
|
public static explicit operator IntPtr (Value val)
|
|
|
|
{
|
2004-04-12 17:54:57 +02:00
|
|
|
return g_value_get_pointer (ref val);
|
2002-05-02 23:57:41 +02:00
|
|
|
}
|
|
|
|
|
2003-02-22 05:34:56 +01:00
|
|
|
[DllImport("libgobject-2.0-0.dll")]
|
2004-04-12 17:54:57 +02:00
|
|
|
static extern IntPtr g_value_get_string (ref Value val);
|
2001-09-19 13:37:15 +02:00
|
|
|
|
2001-09-28 02:28:30 +02:00
|
|
|
public static explicit operator String (Value val)
|
2001-09-19 13:37:15 +02:00
|
|
|
{
|
2004-04-12 17:54:57 +02:00
|
|
|
IntPtr str = g_value_get_string (ref val);
|
2004-04-01 19:10:27 +02:00
|
|
|
return str == IntPtr.Zero ? null : Marshal.PtrToStringAnsi (str);
|
2001-09-19 13:37:15 +02:00
|
|
|
}
|
|
|
|
|
2003-02-22 05:34:56 +01:00
|
|
|
[DllImport("libgobject-2.0-0.dll")]
|
2004-04-12 17:54:57 +02:00
|
|
|
static extern uint g_value_get_uint (ref Value val);
|
2002-05-02 23:57:41 +02:00
|
|
|
|
|
|
|
public static explicit operator uint (Value val)
|
|
|
|
{
|
2004-04-12 17:54:57 +02:00
|
|
|
return g_value_get_uint (ref val);
|
2002-05-02 23:57:41 +02:00
|
|
|
}
|
|
|
|
|
2002-10-27 03:30:51 +01:00
|
|
|
public static explicit operator ushort (Value val)
|
|
|
|
{
|
2004-04-12 17:54:57 +02:00
|
|
|
return (ushort) g_value_get_uint (ref val);
|
2002-10-27 03:30:51 +01:00
|
|
|
}
|
|
|
|
|
2003-02-22 05:34:56 +01:00
|
|
|
[DllImport("libgobject-2.0-0.dll")]
|
2004-04-12 17:54:57 +02:00
|
|
|
static extern int g_value_get_enum (ref Value val);
|
2003-02-22 05:34:56 +01:00
|
|
|
[DllImport("libgobject-2.0-0.dll")]
|
2004-04-12 17:54:57 +02:00
|
|
|
static extern uint g_value_get_flags (ref Value val);
|
2004-12-07 20:03:55 +01:00
|
|
|
[DllImport("glibsharpglue-2")]
|
2004-11-05 17:47:15 +01:00
|
|
|
static extern bool glibsharp_value_holds_flags (ref Value val);
|
2002-06-25 00:04:10 +02:00
|
|
|
|
|
|
|
public static explicit operator EnumWrapper (Value val)
|
|
|
|
{
|
2004-11-05 17:47:15 +01:00
|
|
|
if (glibsharp_value_holds_flags (ref val))
|
|
|
|
return new EnumWrapper ((int)g_value_get_flags (ref val), true);
|
|
|
|
else
|
|
|
|
return new EnumWrapper (g_value_get_enum (ref val), false);
|
2002-06-25 00:04:10 +02:00
|
|
|
}
|
|
|
|
|
2004-12-07 20:03:55 +01:00
|
|
|
[DllImport("glibsharpglue-2")]
|
2004-04-12 17:54:57 +02:00
|
|
|
static extern IntPtr gtksharp_value_get_value_type (ref Value val);
|
|
|
|
|
|
|
|
[DllImport("libgobject-2.0-0.dll")]
|
|
|
|
static extern bool g_type_is_a (IntPtr type, IntPtr is_a_type);
|
2003-05-19 09:18:52 +02:00
|
|
|
|
2004-10-29 22:33:07 +02:00
|
|
|
[DllImport("libgobject-2.0-0.dll")]
|
|
|
|
static extern void g_value_take_boxed (ref Value val, IntPtr data);
|
|
|
|
|
2003-05-19 09:18:52 +02:00
|
|
|
public object Val
|
|
|
|
{
|
|
|
|
get {
|
2004-04-12 17:54:57 +02:00
|
|
|
GLib.GType type = new GLib.GType (gtksharp_value_get_value_type (ref this));
|
2003-05-19 09:18:52 +02:00
|
|
|
if (type == ManagedValue.GType) {
|
2004-04-12 17:54:57 +02:00
|
|
|
return ManagedValue.ObjectForWrapper (g_value_get_boxed (ref this));
|
2003-05-19 09:18:52 +02:00
|
|
|
}
|
|
|
|
|
2003-12-15 17:59:25 +01:00
|
|
|
if (type == GType.String)
|
2003-05-19 09:18:52 +02:00
|
|
|
return (string) this;
|
2003-12-15 17:59:25 +01:00
|
|
|
else if (type == GType.Boolean)
|
2003-05-19 09:18:52 +02:00
|
|
|
return (bool) this;
|
2003-12-15 17:59:25 +01:00
|
|
|
else if (type == GType.Int)
|
2003-05-19 09:18:52 +02:00
|
|
|
return (int) this;
|
2004-12-03 21:04:18 +01:00
|
|
|
else if (type == GType.Int64)
|
|
|
|
return (long) this;
|
|
|
|
else if (type == GType.UInt64)
|
|
|
|
return (ulong) this;
|
2003-12-15 17:59:25 +01:00
|
|
|
else if (type == GType.Double)
|
2003-05-19 09:18:52 +02:00
|
|
|
return (double) this;
|
2003-12-15 17:59:25 +01:00
|
|
|
else if (type == GType.Float)
|
2003-05-19 09:18:52 +02:00
|
|
|
return (float) this;
|
2003-12-15 17:59:25 +01:00
|
|
|
else if (type == GType.Char)
|
2003-05-19 09:18:52 +02:00
|
|
|
return (char) this;
|
2003-12-15 17:59:25 +01:00
|
|
|
else if (type == GType.UInt)
|
2003-05-19 09:18:52 +02:00
|
|
|
return (uint) this;
|
2005-01-27 01:50:46 +01:00
|
|
|
else if (g_type_is_a (type.Val, GType.Object.Val))
|
2003-05-19 09:18:52 +02:00
|
|
|
return (GLib.Object) this;
|
2003-12-15 17:59:25 +01:00
|
|
|
else
|
2003-05-19 09:18:52 +02:00
|
|
|
throw new Exception ("Unknown type");
|
|
|
|
}
|
2003-11-05 00:20:15 +01:00
|
|
|
set {
|
2004-04-12 17:54:57 +02:00
|
|
|
IntPtr buf;
|
2004-05-28 18:59:21 +02:00
|
|
|
GType type = TypeConverter.LookupType (value.GetType());
|
|
|
|
if (type == ManagedValue.GType)
|
2004-04-12 17:54:57 +02:00
|
|
|
g_value_set_boxed (ref this, ManagedValue.WrapObject (value));
|
2003-12-15 17:59:25 +01:00
|
|
|
else if (type == GType.String)
|
2004-04-12 17:54:57 +02:00
|
|
|
g_value_set_string (ref this, (string) value);
|
2003-12-15 17:59:25 +01:00
|
|
|
else if (type == GType.Boolean)
|
2004-04-12 17:54:57 +02:00
|
|
|
g_value_set_boolean (ref this, (bool) value);
|
2003-12-15 17:59:25 +01:00
|
|
|
else if (type == GType.Int)
|
2004-04-12 17:54:57 +02:00
|
|
|
g_value_set_int (ref this, (int) value);
|
2004-12-03 21:04:18 +01:00
|
|
|
else if (type == GType.Int64)
|
|
|
|
g_value_set_int64 (ref this, (long) value);
|
|
|
|
else if (type == GType.UInt64)
|
|
|
|
g_value_set_uint64 (ref this, (ulong) value);
|
2003-12-15 17:59:25 +01:00
|
|
|
else if (type == GType.Double)
|
2004-04-12 17:54:57 +02:00
|
|
|
g_value_set_double (ref this, (double) value);
|
2003-12-15 17:59:25 +01:00
|
|
|
else if (type == GType.Float)
|
2004-04-12 17:54:57 +02:00
|
|
|
g_value_set_float (ref this, (float) value);
|
2003-12-15 17:59:25 +01:00
|
|
|
else if (type == GType.Char)
|
2004-04-12 17:54:57 +02:00
|
|
|
g_value_set_char (ref this, (char) value);
|
2003-12-15 17:59:25 +01:00
|
|
|
else if (type == GType.UInt)
|
2004-04-12 17:54:57 +02:00
|
|
|
g_value_set_uint (ref this, (uint) value);
|
2003-12-15 17:59:25 +01:00
|
|
|
else if (type == GType.Object)
|
2004-04-12 17:54:57 +02:00
|
|
|
g_value_set_object (ref this, ((GLib.Object) value).Handle);
|
|
|
|
else if (type == GType.Pointer) {
|
|
|
|
if (value is IWrapper) {
|
|
|
|
g_value_set_pointer (ref this, ((IWrapper)value).Handle);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
buf = Marshal.AllocHGlobal (Marshal.SizeOf (value.GetType()));
|
|
|
|
Marshal.StructureToPtr (value, buf, false);
|
|
|
|
g_value_set_pointer (ref this, buf);
|
|
|
|
} else if (g_type_is_a (type.Val, GLib.GType.Boxed.Val)) {
|
|
|
|
if (value is IWrapper) {
|
|
|
|
g_value_set_boxed (ref this, ((IWrapper)value).Handle);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
buf = Marshal.AllocHGlobal (Marshal.SizeOf (value.GetType()));
|
|
|
|
Marshal.StructureToPtr (value, buf, false);
|
2004-05-10 20:54:14 +02:00
|
|
|
g_value_set_boxed (ref this, buf);
|
|
|
|
Marshal.FreeHGlobal (buf);
|
2004-04-12 17:54:57 +02:00
|
|
|
} else
|
2003-11-05 00:20:15 +01:00
|
|
|
throw new Exception ("Unknown type");
|
|
|
|
}
|
2003-05-19 09:18:52 +02:00
|
|
|
}
|
2001-09-19 13:37:15 +02:00
|
|
|
}
|
|
|
|
}
|