2001-09-27 17:17:33 +00:00
|
|
|
// GLib.Value.cs - GLib Value class implementation
|
2001-09-19 11:37:15 +00:00
|
|
|
//
|
|
|
|
// Author: Mike Kestner <mkestner@speakeasy.net>
|
|
|
|
//
|
2003-12-15 16:59:25 +00:00
|
|
|
// (c) 2001 Mike Kestner, (c) 2003 Novell, Inc.
|
2001-09-19 11:37:15 +00:00
|
|
|
|
|
|
|
namespace GLib {
|
|
|
|
|
|
|
|
using System;
|
2004-02-02 18:21:02 +00:00
|
|
|
using System.Collections;
|
2001-09-19 11:37:15 +00:00
|
|
|
using System.Runtime.InteropServices;
|
2003-05-19 07:18:52 +00:00
|
|
|
using GLibSharp;
|
2001-09-19 11:37:15 +00:00
|
|
|
|
2001-09-27 17:17:33 +00:00
|
|
|
/// <summary>
|
|
|
|
/// Value Class
|
|
|
|
/// </summary>
|
|
|
|
///
|
|
|
|
/// <remarks>
|
|
|
|
/// An arbitrary data type similar to a CORBA Any which is used
|
|
|
|
/// to get and set properties on Objects.
|
|
|
|
/// </remarks>
|
|
|
|
|
2003-05-19 07:18:52 +00:00
|
|
|
public class Value : IDisposable {
|
2001-09-19 11:37:15 +00:00
|
|
|
|
2001-09-27 17:17:33 +00:00
|
|
|
IntPtr _val;
|
2004-01-28 03:59:14 +00:00
|
|
|
bool needs_dispose = true;
|
2001-09-19 11:37:15 +00:00
|
|
|
|
2001-09-28 00:28:30 +00:00
|
|
|
|
2002-05-02 21:57:41 +00:00
|
|
|
// Destructor is required since we are allocating unmanaged
|
2001-09-28 00:28:30 +00:00
|
|
|
// heap resources.
|
|
|
|
|
2003-02-22 04:34:56 +00:00
|
|
|
[DllImport("libglib-2.0-0.dll")]
|
2001-09-27 17:17:33 +00:00
|
|
|
static extern void g_free (IntPtr mem);
|
2001-09-19 11:37:15 +00:00
|
|
|
|
2004-02-02 18:21:02 +00:00
|
|
|
[DllImport("libgobject-2.0-0.dll")]
|
|
|
|
static extern void g_value_unset (IntPtr mem);
|
|
|
|
|
2001-09-28 00:28:30 +00:00
|
|
|
~Value ()
|
|
|
|
{
|
2003-05-19 07:18:52 +00:00
|
|
|
Dispose ();
|
|
|
|
}
|
|
|
|
|
2004-02-02 18:21:02 +00:00
|
|
|
static bool idle_queued;
|
|
|
|
static Queue idle_queue = new Queue ();
|
|
|
|
|
|
|
|
static bool DoDispose ()
|
|
|
|
{
|
|
|
|
IntPtr [] vals;
|
|
|
|
|
|
|
|
lock (idle_queue){
|
|
|
|
vals = new IntPtr [idle_queue.Count];
|
|
|
|
idle_queue.CopyTo (vals, 0);
|
|
|
|
idle_queue.Clear ();
|
|
|
|
}
|
|
|
|
lock (typeof (Value))
|
|
|
|
idle_queued = false;
|
|
|
|
|
|
|
|
foreach (IntPtr v in vals) {
|
|
|
|
if (v == IntPtr.Zero)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
g_value_unset (v);
|
|
|
|
g_free (v);
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2003-05-19 07:18:52 +00:00
|
|
|
public void Dispose () {
|
|
|
|
if (_val != IntPtr.Zero) {
|
2003-12-15 16:59:25 +00:00
|
|
|
IntPtr rawtype = gtksharp_value_get_value_type (_val);
|
|
|
|
if (rawtype == ManagedValue.GType.Val) {
|
2003-05-19 07:18:52 +00:00
|
|
|
ManagedValue.Free (g_value_get_boxed (_val));
|
|
|
|
}
|
|
|
|
|
2004-01-28 03:59:14 +00:00
|
|
|
if (needs_dispose)
|
2004-02-02 18:21:02 +00:00
|
|
|
lock (idle_queue) {
|
|
|
|
idle_queue.Enqueue (_val);
|
|
|
|
lock (typeof (Value)){
|
|
|
|
if (!idle_queued){
|
|
|
|
Idle.Add (new IdleHandler (DoDispose));
|
|
|
|
idle_queued = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2003-05-19 07:18:52 +00:00
|
|
|
_val = IntPtr.Zero;
|
|
|
|
}
|
2004-01-14 18:05:50 +00:00
|
|
|
|
|
|
|
if (buf != IntPtr.Zero) {
|
|
|
|
Marshal.FreeHGlobal (buf);
|
|
|
|
buf = IntPtr.Zero;
|
|
|
|
}
|
2001-09-28 00:28:30 +00:00
|
|
|
}
|
|
|
|
|
2002-05-02 21:57:41 +00:00
|
|
|
// import the glue function to allocate values on heap
|
|
|
|
|
|
|
|
[DllImport("gtksharpglue")]
|
2003-12-15 16:59:25 +00:00
|
|
|
static extern IntPtr gtksharp_value_create(IntPtr type);
|
2002-05-02 21:57:41 +00:00
|
|
|
|
2002-06-05 21:59:10 +00:00
|
|
|
[DllImport("gtksharpglue")]
|
|
|
|
static extern IntPtr gtksharp_value_create_from_property(IntPtr obj, string name);
|
|
|
|
|
2002-05-02 21:57:41 +00:00
|
|
|
// Constructor to wrap a raw GValue ref. We need the dummy param
|
|
|
|
// to distinguish this ctor from the TypePointer ctor.
|
|
|
|
|
|
|
|
public Value (IntPtr val, IntPtr dummy)
|
|
|
|
{
|
|
|
|
_val = val;
|
2004-01-28 03:59:14 +00:00
|
|
|
needs_dispose = false;
|
2002-05-02 21:57:41 +00:00
|
|
|
}
|
|
|
|
|
2002-10-05 05:12:00 +00:00
|
|
|
/// <summary>
|
|
|
|
/// Value Constructor
|
|
|
|
/// </summary>
|
|
|
|
///
|
|
|
|
/// <remarks>
|
|
|
|
/// Constructs a new empty value that can be used
|
|
|
|
/// to receive "out" GValue parameters.
|
|
|
|
/// </remarks>
|
|
|
|
|
|
|
|
public Value () {
|
2003-12-15 16:59:25 +00:00
|
|
|
_val = gtksharp_value_create (GType.Invalid.Val);
|
2002-10-05 05:12:00 +00:00
|
|
|
}
|
|
|
|
|
2004-01-14 18:05:50 +00:00
|
|
|
/// <summary>
|
|
|
|
/// Value Constructor
|
|
|
|
/// </summary>
|
|
|
|
///
|
|
|
|
/// <remarks>
|
|
|
|
/// Constructs a new empty initialized value that can be used
|
|
|
|
/// to receive "out" GValue parameters.
|
|
|
|
/// </remarks>
|
|
|
|
|
|
|
|
public Value (GLib.GType gtype) {
|
|
|
|
_val = gtksharp_value_create (gtype.Val);
|
|
|
|
}
|
|
|
|
|
2002-06-05 21:59:10 +00:00
|
|
|
/// <summary>
|
|
|
|
/// Value Constructor
|
|
|
|
/// </summary>
|
|
|
|
///
|
|
|
|
/// <remarks>
|
|
|
|
/// Constructs a Value corresponding to the type of the
|
|
|
|
/// specified property.
|
|
|
|
/// </remarks>
|
|
|
|
|
|
|
|
public Value (IntPtr obj, string prop_name)
|
|
|
|
{
|
|
|
|
_val = gtksharp_value_create_from_property (obj, prop_name);
|
|
|
|
}
|
|
|
|
|
2003-02-22 04:34:56 +00:00
|
|
|
[DllImport("libgobject-2.0-0.dll")]
|
2003-12-15 16:59:25 +00:00
|
|
|
static extern void g_value_set_boolean (IntPtr val, bool data);
|
2002-06-23 18:49:33 +00:00
|
|
|
|
2001-09-19 11:37:15 +00:00
|
|
|
/// <summary>
|
2001-09-27 17:17:33 +00:00
|
|
|
/// Value Constructor
|
2001-09-19 11:37:15 +00:00
|
|
|
/// </summary>
|
|
|
|
///
|
|
|
|
/// <remarks>
|
2002-05-02 21:57:41 +00:00
|
|
|
/// Constructs a Value from a specified boolean.
|
2001-09-28 00:28:30 +00:00
|
|
|
/// </remarks>
|
|
|
|
|
2002-05-02 21:57:41 +00:00
|
|
|
public Value (bool val)
|
|
|
|
{
|
2003-12-15 16:59:25 +00:00
|
|
|
_val = gtksharp_value_create(GType.Boolean.Val);
|
2002-05-02 21:57:41 +00:00
|
|
|
g_value_set_boolean (_val, val);
|
|
|
|
}
|
|
|
|
|
2003-02-22 04:34:56 +00:00
|
|
|
[DllImport("libgobject-2.0-0.dll")]
|
2002-06-23 18:49:33 +00:00
|
|
|
static extern void g_value_set_boxed (IntPtr val, IntPtr data);
|
|
|
|
|
2003-12-15 16:59:25 +00:00
|
|
|
/*
|
2002-05-02 21:57:41 +00:00
|
|
|
/// <summary>
|
|
|
|
/// Value Constructor
|
|
|
|
/// </summary>
|
|
|
|
///
|
|
|
|
/// <remarks>
|
|
|
|
/// Constructs a Value from a specified boxed type.
|
|
|
|
/// </remarks>
|
2001-09-28 00:28:30 +00:00
|
|
|
|
2002-05-02 21:57:41 +00:00
|
|
|
public Value (GLib.Boxed val)
|
2002-07-26 06:08:52 +00:00
|
|
|
{
|
2003-12-15 16:59:25 +00:00
|
|
|
_val = gtksharp_value_create(GType.Boxed);
|
2002-07-26 06:08:52 +00:00
|
|
|
//g_value_set_boxed (_val, val.Handle);
|
|
|
|
}
|
|
|
|
|
|
|
|
public Value (IntPtr obj, string prop_name, Boxed val)
|
|
|
|
{
|
|
|
|
_val = gtksharp_value_create_from_property (obj, prop_name);
|
|
|
|
//g_value_set_boxed (_val, val.Handle);
|
|
|
|
}
|
2003-12-15 16:59:25 +00:00
|
|
|
*/
|
2002-07-26 06:08:52 +00:00
|
|
|
|
2003-10-15 20:13:50 +00:00
|
|
|
public Value (IntPtr obj, string prop_name, Opaque val)
|
2001-09-28 00:28:30 +00:00
|
|
|
{
|
2003-10-15 20:13:50 +00:00
|
|
|
_val = gtksharp_value_create_from_property (obj, prop_name);
|
2002-05-02 21:57:41 +00:00
|
|
|
g_value_set_boxed (_val, val.Handle);
|
2001-09-28 00:28:30 +00:00
|
|
|
}
|
|
|
|
|
2003-02-22 04:34:56 +00:00
|
|
|
[DllImport("libgobject-2.0-0.dll")]
|
2002-06-23 18:49:33 +00:00
|
|
|
static extern void g_value_set_double (IntPtr val, double data);
|
|
|
|
|
2001-09-28 18:23:14 +00:00
|
|
|
/// <summary>
|
|
|
|
/// Value Constructor
|
|
|
|
/// </summary>
|
|
|
|
///
|
|
|
|
/// <remarks>
|
2002-05-02 21:57:41 +00:00
|
|
|
/// Constructs a Value from a specified double.
|
2001-09-28 18:23:14 +00:00
|
|
|
/// </remarks>
|
|
|
|
|
2002-05-02 21:57:41 +00:00
|
|
|
public Value (double val)
|
2001-09-28 18:23:14 +00:00
|
|
|
{
|
2003-12-15 16:59:25 +00:00
|
|
|
_val = gtksharp_value_create (GType.Double.Val);
|
2002-05-02 21:57:41 +00:00
|
|
|
g_value_set_double (_val, val);
|
2001-09-28 18:23:14 +00:00
|
|
|
}
|
|
|
|
|
2003-02-22 04:34:56 +00:00
|
|
|
[DllImport("libgobject-2.0-0.dll")]
|
2002-06-23 18:49:33 +00:00
|
|
|
static extern void g_value_set_float (IntPtr val, float data);
|
|
|
|
|
2001-09-28 00:28:30 +00:00
|
|
|
/// <summary>
|
|
|
|
/// Value Constructor
|
|
|
|
/// </summary>
|
|
|
|
///
|
|
|
|
/// <remarks>
|
2002-05-02 21:57:41 +00:00
|
|
|
/// Constructs a Value from a specified float.
|
2001-09-19 11:37:15 +00:00
|
|
|
/// </remarks>
|
|
|
|
|
2002-05-02 21:57:41 +00:00
|
|
|
public Value (float val)
|
2001-09-27 17:17:33 +00:00
|
|
|
{
|
2003-12-15 16:59:25 +00:00
|
|
|
_val = gtksharp_value_create (GType.Float.Val);
|
2002-05-02 21:57:41 +00:00
|
|
|
g_value_set_float (_val, val);
|
2001-09-27 17:17:33 +00:00
|
|
|
}
|
2001-09-19 11:37:15 +00:00
|
|
|
|
2003-02-22 04:34:56 +00:00
|
|
|
[DllImport("libgobject-2.0-0.dll")]
|
2002-06-23 18:49:33 +00:00
|
|
|
static extern void g_value_set_int (IntPtr val, int data);
|
|
|
|
|
2001-09-29 20:08:30 +00:00
|
|
|
/// <summary>
|
|
|
|
/// Value Constructor
|
|
|
|
/// </summary>
|
|
|
|
///
|
|
|
|
/// <remarks>
|
|
|
|
/// Constructs a Value from a specified integer.
|
|
|
|
/// </remarks>
|
|
|
|
|
2002-05-02 21:57:41 +00:00
|
|
|
public Value (int val)
|
2001-09-29 20:08:30 +00:00
|
|
|
{
|
2003-12-15 16:59:25 +00:00
|
|
|
_val = gtksharp_value_create (GType.Int.Val);
|
2001-09-29 20:08:30 +00:00
|
|
|
g_value_set_int (_val, val);
|
|
|
|
}
|
|
|
|
|
2003-02-22 04:34:56 +00:00
|
|
|
[DllImport("libgobject-2.0-0.dll")]
|
2002-06-23 18:49:33 +00:00
|
|
|
static extern void g_value_set_object (IntPtr val, IntPtr data);
|
|
|
|
|
2002-05-02 21:57:41 +00:00
|
|
|
/// <summary>
|
|
|
|
/// Value Constructor
|
|
|
|
/// </summary>
|
|
|
|
///
|
|
|
|
/// <remarks>
|
|
|
|
/// Constructs a Value from a specified object.
|
|
|
|
/// </remarks>
|
|
|
|
|
|
|
|
public Value (GLib.Object val)
|
|
|
|
{
|
2003-12-15 16:59:25 +00:00
|
|
|
_val = gtksharp_value_create (val.GetGType ().Val);
|
2002-05-02 21:57:41 +00:00
|
|
|
g_value_set_object (_val, val.Handle);
|
|
|
|
}
|
|
|
|
|
2003-02-22 04:34:56 +00:00
|
|
|
[DllImport("libgobject-2.0-0.dll")]
|
2002-06-23 18:49:33 +00:00
|
|
|
static extern void g_value_set_pointer (IntPtr val, IntPtr data);
|
|
|
|
|
2002-05-02 21:57:41 +00:00
|
|
|
/// <summary>
|
|
|
|
/// Value Constructor
|
|
|
|
/// </summary>
|
|
|
|
///
|
|
|
|
/// <remarks>
|
|
|
|
/// Constructs a Value from a specified pointer.
|
|
|
|
/// </remarks>
|
|
|
|
|
|
|
|
public Value (IntPtr val)
|
|
|
|
{
|
2003-12-15 16:59:25 +00:00
|
|
|
_val = gtksharp_value_create (GType.Pointer.Val);
|
2002-05-02 21:57:41 +00:00
|
|
|
g_value_set_pointer (_val, val);
|
|
|
|
}
|
|
|
|
|
2003-02-22 04:34:56 +00:00
|
|
|
[DllImport("libgobject-2.0-0.dll")]
|
2002-06-23 18:49:33 +00:00
|
|
|
static extern void g_value_set_string (IntPtr val, string data);
|
|
|
|
|
2001-09-28 00:28:30 +00:00
|
|
|
/// <summary>
|
|
|
|
/// Value Constructor
|
|
|
|
/// </summary>
|
|
|
|
///
|
|
|
|
/// <remarks>
|
|
|
|
/// Constructs a Value from a specified string.
|
|
|
|
/// </remarks>
|
|
|
|
|
2002-05-02 21:57:41 +00:00
|
|
|
public Value (string val)
|
2001-09-19 11:37:15 +00:00
|
|
|
{
|
2003-12-15 16:59:25 +00:00
|
|
|
_val = gtksharp_value_create (GType.String.Val);
|
2002-04-19 16:17:47 +00:00
|
|
|
g_value_set_string (_val, val);
|
2001-09-28 00:28:30 +00:00
|
|
|
}
|
|
|
|
|
2003-02-22 04:34:56 +00:00
|
|
|
[DllImport("libgobject-2.0-0.dll")]
|
2002-06-23 18:49:33 +00:00
|
|
|
static extern void g_value_set_uint (IntPtr val, uint data);
|
|
|
|
|
2001-09-28 00:28:30 +00:00
|
|
|
/// <summary>
|
2002-05-02 21:57:41 +00:00
|
|
|
/// Value Constructor
|
2001-09-28 00:28:30 +00:00
|
|
|
/// </summary>
|
|
|
|
///
|
|
|
|
/// <remarks>
|
2002-05-02 21:57:41 +00:00
|
|
|
/// Constructs a Value from a specified uint.
|
2001-09-28 00:28:30 +00:00
|
|
|
/// </remarks>
|
|
|
|
|
2002-05-02 21:57:41 +00:00
|
|
|
public Value (uint val)
|
2001-09-28 00:28:30 +00:00
|
|
|
{
|
2003-12-15 16:59:25 +00:00
|
|
|
_val = gtksharp_value_create (GType.UInt.Val);
|
2002-05-02 21:57:41 +00:00
|
|
|
g_value_set_uint (_val, val);
|
2001-09-28 00:28:30 +00:00
|
|
|
}
|
|
|
|
|
2002-10-27 02:30:51 +00:00
|
|
|
/// <summary>
|
|
|
|
/// Value Constructor
|
|
|
|
/// </summary>
|
|
|
|
///
|
|
|
|
/// <remarks>
|
|
|
|
/// Constructs a Value from a specified ushort.
|
|
|
|
/// </remarks>
|
|
|
|
|
|
|
|
public Value (ushort val)
|
|
|
|
{
|
2003-12-15 16:59:25 +00:00
|
|
|
_val = gtksharp_value_create (GType.UInt.Val);
|
2002-10-27 02:30:51 +00:00
|
|
|
g_value_set_uint (_val, val);
|
|
|
|
}
|
|
|
|
|
2003-02-22 04:34:56 +00:00
|
|
|
[DllImport("libgobject-2.0-0.dll")]
|
2002-06-24 22:04:10 +00:00
|
|
|
static extern void g_value_set_enum (IntPtr val, int data);
|
2003-02-22 04:34:56 +00:00
|
|
|
[DllImport("libgobject-2.0-0.dll")]
|
2002-08-03 22:24:37 +00:00
|
|
|
static extern void g_value_set_flags (IntPtr val, uint data);
|
2003-05-22 23:39:04 +00:00
|
|
|
[DllImport("libgobject-2.0-0.dll")]
|
2003-05-19 07:18:52 +00:00
|
|
|
static extern void g_value_set_char (IntPtr val, char data);
|
2002-06-24 22:04:10 +00:00
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Value Constructor
|
|
|
|
/// </summary>
|
|
|
|
///
|
|
|
|
/// <remarks>
|
|
|
|
/// Constructs a Value from a specified enum wrapper.
|
|
|
|
/// </remarks>
|
|
|
|
|
|
|
|
public Value (IntPtr obj, string prop_name, EnumWrapper wrap)
|
|
|
|
{
|
|
|
|
_val = gtksharp_value_create_from_property (obj, prop_name);
|
2002-08-03 22:24:37 +00:00
|
|
|
if (wrap.flags)
|
|
|
|
g_value_set_flags (_val, (uint) (int) wrap);
|
|
|
|
else
|
|
|
|
g_value_set_enum (_val, (int) wrap);
|
2002-06-24 22:04:10 +00:00
|
|
|
}
|
|
|
|
|
2004-01-14 18:05:50 +00:00
|
|
|
[DllImport("libgobject-2.0-0.dll")]
|
|
|
|
static extern void g_value_set_boxed_take_ownership (IntPtr val, IntPtr data);
|
|
|
|
|
2004-01-27 23:55:13 +00:00
|
|
|
[DllImport("libgobject-2.0-0.dll")]
|
|
|
|
static extern bool g_type_is_a (IntPtr type, IntPtr is_a_type);
|
|
|
|
|
2004-01-14 18:05:50 +00:00
|
|
|
IntPtr buf = IntPtr.Zero;
|
|
|
|
|
2003-05-19 07:18:52 +00:00
|
|
|
/// <summary>
|
|
|
|
/// Value Constructor
|
|
|
|
/// </summary>
|
|
|
|
///
|
|
|
|
/// <remarks>
|
|
|
|
/// Constructs a Value from any object, including a managed
|
|
|
|
/// type.
|
|
|
|
/// </remarks>
|
|
|
|
|
|
|
|
public Value (object obj)
|
|
|
|
{
|
2003-12-15 16:59:25 +00:00
|
|
|
GType type = TypeConverter.LookupType (obj.GetType ());
|
|
|
|
if (type == GType.None) {
|
|
|
|
_val = gtksharp_value_create (ManagedValue.GType.Val);
|
|
|
|
} else if (type == GType.Object) {
|
|
|
|
_val = gtksharp_value_create (((GLib.Object) obj).GetGType ().Val);
|
2003-05-19 07:18:52 +00:00
|
|
|
} else {
|
2003-12-15 16:59:25 +00:00
|
|
|
_val = gtksharp_value_create (type.Val);
|
2003-05-19 07:18:52 +00:00
|
|
|
}
|
|
|
|
|
2003-12-15 16:59:25 +00:00
|
|
|
if (type == GType.None)
|
2003-05-19 07:18:52 +00:00
|
|
|
g_value_set_boxed_take_ownership (_val, ManagedValue.WrapObject (obj));
|
2003-12-15 16:59:25 +00:00
|
|
|
else if (type == GType.String)
|
2003-05-19 07:18:52 +00:00
|
|
|
g_value_set_string (_val, (string) obj);
|
2003-12-15 16:59:25 +00:00
|
|
|
else if (type == GType.Boolean)
|
2003-05-19 07:18:52 +00:00
|
|
|
g_value_set_boolean (_val, (bool) obj);
|
2003-12-15 16:59:25 +00:00
|
|
|
else if (type == GType.Int)
|
2003-05-19 07:18:52 +00:00
|
|
|
g_value_set_int (_val, (int) obj);
|
2003-12-15 16:59:25 +00:00
|
|
|
else if (type == GType.Double)
|
2003-05-19 07:18:52 +00:00
|
|
|
g_value_set_double (_val, (double) obj);
|
2003-12-15 16:59:25 +00:00
|
|
|
else if (type == GType.Float)
|
2003-05-19 07:18:52 +00:00
|
|
|
g_value_set_float (_val, (float) obj);
|
2003-12-15 16:59:25 +00:00
|
|
|
else if (type == GType.Char)
|
2003-05-19 07:18:52 +00:00
|
|
|
g_value_set_char (_val, (char) obj);
|
2003-12-15 16:59:25 +00:00
|
|
|
else if (type == GType.UInt)
|
2003-05-19 07:18:52 +00:00
|
|
|
g_value_set_uint (_val, (uint) obj);
|
2003-12-15 16:59:25 +00:00
|
|
|
else if (type == GType.Object)
|
2003-05-19 07:18:52 +00:00
|
|
|
g_value_set_object (_val, ((GLib.Object) obj).Handle);
|
2004-01-14 18:05:50 +00:00
|
|
|
else if (type == GType.Pointer) {
|
|
|
|
buf = Marshal.AllocHGlobal (Marshal.SizeOf (obj.GetType()));
|
|
|
|
Marshal.StructureToPtr (obj, buf, false);
|
|
|
|
g_value_set_pointer (_val, buf);
|
2004-01-27 23:55:13 +00:00
|
|
|
} else if (g_type_is_a (type.Val, GLib.GType.Boxed.Val)) {
|
|
|
|
buf = Marshal.AllocHGlobal (Marshal.SizeOf (obj.GetType()));
|
|
|
|
Marshal.StructureToPtr (obj, buf, false);
|
|
|
|
g_value_set_boxed (_val, buf);
|
2004-01-14 18:05:50 +00:00
|
|
|
} else
|
2003-05-19 07:18:52 +00:00
|
|
|
throw new Exception ("Unknown type");
|
|
|
|
}
|
|
|
|
|
2003-02-22 04:34:56 +00:00
|
|
|
[DllImport("libgobject-2.0-0.dll")]
|
2002-06-23 18:49:33 +00:00
|
|
|
static extern bool g_value_get_boolean (IntPtr val);
|
|
|
|
|
2001-09-28 00:28:30 +00:00
|
|
|
/// <summary>
|
|
|
|
/// Value to Boolean Conversion
|
|
|
|
/// </summary>
|
|
|
|
///
|
|
|
|
/// <remarks>
|
|
|
|
/// Extracts a bool from a Value. Note, this method
|
|
|
|
/// will produce an exception if the Value does not hold a
|
|
|
|
/// boolean value.
|
|
|
|
/// </remarks>
|
|
|
|
|
|
|
|
public static explicit operator bool (Value val)
|
|
|
|
{
|
|
|
|
// FIXME: Insert an appropriate exception here if
|
|
|
|
// _val.type indicates an error.
|
|
|
|
return g_value_get_boolean (val._val);
|
2001-09-19 11:37:15 +00:00
|
|
|
}
|
|
|
|
|
2003-02-22 04:34:56 +00:00
|
|
|
[DllImport("libgobject-2.0-0.dll")]
|
2002-06-23 18:49:33 +00:00
|
|
|
static extern IntPtr g_value_get_boxed (IntPtr val);
|
|
|
|
|
2002-07-26 06:08:52 +00:00
|
|
|
public static explicit operator GLib.Opaque (Value val)
|
|
|
|
{
|
|
|
|
return GLib.Opaque.GetOpaque (g_value_get_boxed (val._val));
|
|
|
|
}
|
|
|
|
|
2002-05-02 21:57:41 +00:00
|
|
|
/// <summary>
|
|
|
|
/// Value to Boxed Conversion
|
|
|
|
/// </summary>
|
|
|
|
///
|
|
|
|
/// <remarks>
|
|
|
|
/// Extracts a boxed type from a Value. Note, this method
|
|
|
|
/// will produce an exception if the Value does not hold a
|
|
|
|
/// boxed type value.
|
|
|
|
/// </remarks>
|
|
|
|
|
|
|
|
public static explicit operator GLib.Boxed (Value val)
|
|
|
|
{
|
2002-07-30 23:02:12 +00:00
|
|
|
return new GLib.Boxed (g_value_get_boxed (val._val));
|
2002-05-02 21:57:41 +00:00
|
|
|
}
|
|
|
|
|
2003-02-22 04:34:56 +00:00
|
|
|
[DllImport("libgobject-2.0-0.dll")]
|
2002-06-23 18:49:33 +00:00
|
|
|
static extern double g_value_get_double (IntPtr val);
|
|
|
|
|
2002-05-02 21:57:41 +00:00
|
|
|
/// <summary>
|
|
|
|
/// Value to Double Conversion
|
|
|
|
/// </summary>
|
|
|
|
///
|
|
|
|
/// <remarks>
|
|
|
|
/// Extracts a double from a Value. Note, this method
|
|
|
|
/// will produce an exception if the Value does not hold a
|
|
|
|
/// double value.
|
|
|
|
/// </remarks>
|
|
|
|
|
|
|
|
public static explicit operator double (Value val)
|
|
|
|
{
|
|
|
|
// FIXME: Insert an appropriate exception here if
|
|
|
|
// _val.type indicates an error.
|
|
|
|
return g_value_get_double (val._val);
|
|
|
|
}
|
|
|
|
|
2003-02-22 04:34:56 +00:00
|
|
|
[DllImport("libgobject-2.0-0.dll")]
|
2002-06-23 18:49:33 +00:00
|
|
|
static extern float g_value_get_float (IntPtr val);
|
|
|
|
|
2002-05-02 21:57:41 +00:00
|
|
|
/// <summary>
|
|
|
|
/// Value to Float Conversion
|
|
|
|
/// </summary>
|
|
|
|
///
|
|
|
|
/// <remarks>
|
|
|
|
/// Extracts a float from a Value. Note, this method
|
|
|
|
/// will produce an exception if the Value does not hold a
|
|
|
|
/// float value.
|
|
|
|
/// </remarks>
|
|
|
|
|
|
|
|
public static explicit operator float (Value val)
|
|
|
|
{
|
|
|
|
// FIXME: Insert an appropriate exception here if
|
|
|
|
// _val.type indicates an error.
|
|
|
|
return g_value_get_float (val._val);
|
|
|
|
}
|
|
|
|
|
2003-02-22 04:34:56 +00:00
|
|
|
[DllImport("libgobject-2.0-0.dll")]
|
2002-06-23 18:49:33 +00:00
|
|
|
static extern int g_value_get_int (IntPtr val);
|
|
|
|
|
2001-09-29 20:08:30 +00:00
|
|
|
/// <summary>
|
|
|
|
/// Value to Integer Conversion
|
|
|
|
/// </summary>
|
|
|
|
///
|
|
|
|
/// <remarks>
|
|
|
|
/// Extracts an int from a Value. Note, this method
|
|
|
|
/// will produce an exception if the Value does not hold a
|
|
|
|
/// integer value.
|
|
|
|
/// </remarks>
|
|
|
|
|
|
|
|
public static explicit operator int (Value val)
|
|
|
|
{
|
|
|
|
// FIXME: Insert an appropriate exception here if
|
|
|
|
// _val.type indicates an error.
|
|
|
|
return g_value_get_int (val._val);
|
|
|
|
}
|
|
|
|
|
2003-02-22 04:34:56 +00:00
|
|
|
[DllImport("libgobject-2.0-0.dll")]
|
2002-06-23 18:49:33 +00:00
|
|
|
static extern IntPtr g_value_get_object (IntPtr val);
|
|
|
|
|
2002-05-02 21:57:41 +00:00
|
|
|
/// <summary>
|
|
|
|
/// Value to Object Conversion
|
|
|
|
/// </summary>
|
|
|
|
///
|
|
|
|
/// <remarks>
|
|
|
|
/// Extracts an object from a Value. Note, this method
|
|
|
|
/// will produce an exception if the Value does not hold a
|
|
|
|
/// object value.
|
|
|
|
/// </remarks>
|
|
|
|
|
|
|
|
public static explicit operator GLib.Object (Value val)
|
|
|
|
{
|
|
|
|
// FIXME: Insert an appropriate exception here if
|
|
|
|
// _val.type indicates an error.
|
2003-07-23 17:19:21 +00:00
|
|
|
return GLib.Object.GetObject(g_value_get_object (val._val), true);
|
2002-05-02 21:57:41 +00:00
|
|
|
}
|
|
|
|
|
2002-06-24 23:38:51 +00:00
|
|
|
/// <summary>
|
|
|
|
/// Value to Unresolved Object Conversion
|
|
|
|
/// </summary>
|
|
|
|
///
|
|
|
|
/// <remarks>
|
|
|
|
/// Extracts an object from a Value without looking up its wrapping
|
|
|
|
/// class.
|
|
|
|
/// Note, this method will produce an exception if the Value does
|
|
|
|
/// not hold a object value.
|
|
|
|
/// </remarks>
|
|
|
|
|
|
|
|
public static explicit operator GLib.UnwrappedObject (Value val)
|
|
|
|
{
|
|
|
|
// FIXME: Insert an appropriate exception here if
|
|
|
|
// _val.type indicates an error.
|
|
|
|
return new UnwrappedObject(g_value_get_object (val._val));
|
|
|
|
}
|
|
|
|
|
2003-02-22 04:34:56 +00:00
|
|
|
[DllImport("libgobject-2.0-0.dll")]
|
2002-06-23 18:49:33 +00:00
|
|
|
static extern IntPtr g_value_get_pointer (IntPtr val);
|
|
|
|
|
2002-05-02 21:57:41 +00:00
|
|
|
/// <summary>
|
|
|
|
/// Value to Pointer Conversion
|
|
|
|
/// </summary>
|
|
|
|
///
|
|
|
|
/// <remarks>
|
|
|
|
/// Extracts a pointer from a Value. Note, this method
|
|
|
|
/// will produce an exception if the Value does not hold a
|
|
|
|
/// pointer value.
|
|
|
|
/// </remarks>
|
|
|
|
|
|
|
|
public static explicit operator IntPtr (Value val)
|
|
|
|
{
|
|
|
|
// FIXME: Insert an appropriate exception here if
|
|
|
|
// _val.type indicates an error.
|
|
|
|
return g_value_get_pointer (val._val);
|
|
|
|
}
|
|
|
|
|
2003-02-22 04:34:56 +00:00
|
|
|
[DllImport("libgobject-2.0-0.dll")]
|
2003-05-29 Rachel Hestilow <rachel@nullenvoid.com>
* gconf/Value.cs: Update to use new string marshalling.
* generator/StringGen.cs, ConstStringGen.cs: Added.
* generator/IGeneratable.cs: Add new method ToNativeReturn.
* generator/CallbackGen.cs: Implement ToNativeReturn. Call
ToNativeReturn for the return statement. Fix a couple of
places where s_ret was being used incorrectly for m_ret.
* generator/ClassGen.cs, EnumGen.cs, ManualGen.cs,
SimpleGen.cs, StructBase.cs: Implement ToNativeReturn.
* generator/SignalHandler.cs: Call ToNativeReturn for the
return statement, instead of CallByName.
* generator/SymbolTable.cs: Use StringGen for gchar, char,
and gunichar, and ConstStringGen for their const variants.
Add a new method wrapper for ToNativeReturn.
(Trim): Add a special-case for const strings so that the
const is not stripped. Otherwise there is no way of
resolving the const case.
* glade/XML.custom: Update to use new string marshalling.
* glib/Marshaller.cs: Added.
* glib/GException.cs, Markup.cs, ObjectManager.cs,
Value.cs: Update to use new string marshalling.
* glib/Object.cs: Remove old g_type_name DllImport
as it is no longer used.
* glue/fileselection.c (gtksharp_file_selection_get_fileop_entry):
Mark this as const return.
* gtk/ColorSelection.custom, FileSelection.custom,
SelectionData.custom: Update to use new string marshalling.
svn path=/trunk/gtk-sharp/; revision=15286
2003-06-10 18:09:47 +00:00
|
|
|
static extern IntPtr g_value_get_string (IntPtr val);
|
2002-06-23 18:49:33 +00:00
|
|
|
|
2001-09-19 11:37:15 +00:00
|
|
|
/// <summary>
|
2001-09-28 00:28:30 +00:00
|
|
|
/// Value to String Conversion
|
2001-09-19 11:37:15 +00:00
|
|
|
/// </summary>
|
|
|
|
///
|
|
|
|
/// <remarks>
|
2001-09-27 17:17:33 +00:00
|
|
|
/// Extracts a string from a Value. Note, this method
|
|
|
|
/// will produce an exception if the Value does not hold a
|
2001-09-19 11:37:15 +00:00
|
|
|
/// string value.
|
|
|
|
/// </remarks>
|
|
|
|
|
2001-09-28 00:28:30 +00:00
|
|
|
public static explicit operator String (Value val)
|
2001-09-19 11:37:15 +00:00
|
|
|
{
|
|
|
|
// FIXME: Insert an appropriate exception here if
|
|
|
|
// _val.type indicates an error.
|
2003-05-29 Rachel Hestilow <rachel@nullenvoid.com>
* gconf/Value.cs: Update to use new string marshalling.
* generator/StringGen.cs, ConstStringGen.cs: Added.
* generator/IGeneratable.cs: Add new method ToNativeReturn.
* generator/CallbackGen.cs: Implement ToNativeReturn. Call
ToNativeReturn for the return statement. Fix a couple of
places where s_ret was being used incorrectly for m_ret.
* generator/ClassGen.cs, EnumGen.cs, ManualGen.cs,
SimpleGen.cs, StructBase.cs: Implement ToNativeReturn.
* generator/SignalHandler.cs: Call ToNativeReturn for the
return statement, instead of CallByName.
* generator/SymbolTable.cs: Use StringGen for gchar, char,
and gunichar, and ConstStringGen for their const variants.
Add a new method wrapper for ToNativeReturn.
(Trim): Add a special-case for const strings so that the
const is not stripped. Otherwise there is no way of
resolving the const case.
* glade/XML.custom: Update to use new string marshalling.
* glib/Marshaller.cs: Added.
* glib/GException.cs, Markup.cs, ObjectManager.cs,
Value.cs: Update to use new string marshalling.
* glib/Object.cs: Remove old g_type_name DllImport
as it is no longer used.
* glue/fileselection.c (gtksharp_file_selection_get_fileop_entry):
Mark this as const return.
* gtk/ColorSelection.custom, FileSelection.custom,
SelectionData.custom: Update to use new string marshalling.
svn path=/trunk/gtk-sharp/; revision=15286
2003-06-10 18:09:47 +00:00
|
|
|
return Marshal.PtrToStringAnsi (g_value_get_string (val._val));
|
2001-09-19 11:37:15 +00:00
|
|
|
}
|
|
|
|
|
2003-02-22 04:34:56 +00:00
|
|
|
[DllImport("libgobject-2.0-0.dll")]
|
2002-06-23 18:49:33 +00:00
|
|
|
static extern uint g_value_get_uint (IntPtr val);
|
|
|
|
|
2001-09-19 11:37:15 +00:00
|
|
|
/// <summary>
|
2002-05-02 21:57:41 +00:00
|
|
|
/// Value to Unsigned Integer Conversion
|
|
|
|
/// </summary>
|
|
|
|
///
|
|
|
|
/// <remarks>
|
|
|
|
/// Extracts an uint from a Value. Note, this method
|
|
|
|
/// will produce an exception if the Value does not hold a
|
|
|
|
/// unsigned integer value.
|
|
|
|
/// </remarks>
|
|
|
|
|
|
|
|
public static explicit operator uint (Value val)
|
|
|
|
{
|
|
|
|
// FIXME: Insert an appropriate exception here if
|
|
|
|
// _val.type indicates an error.
|
|
|
|
return g_value_get_uint (val._val);
|
|
|
|
}
|
|
|
|
|
2002-10-27 02:30:51 +00:00
|
|
|
/// <summary>
|
|
|
|
/// Value to Unsigned Short Conversion
|
|
|
|
/// </summary>
|
|
|
|
///
|
|
|
|
/// <remarks>
|
|
|
|
/// Extracts a ushort from a Value. Note, this method
|
|
|
|
/// will produce an exception if the Value does not hold a
|
|
|
|
/// unsigned integer value.
|
|
|
|
/// </remarks>
|
|
|
|
|
|
|
|
public static explicit operator ushort (Value val)
|
|
|
|
{
|
|
|
|
// FIXME: Insert an appropriate exception here if
|
|
|
|
// _val.type indicates an error.
|
|
|
|
return (ushort) g_value_get_uint (val._val);
|
|
|
|
}
|
|
|
|
|
2003-02-22 04:34:56 +00:00
|
|
|
[DllImport("libgobject-2.0-0.dll")]
|
2002-06-24 22:04:10 +00:00
|
|
|
static extern int g_value_get_enum (IntPtr val);
|
2003-02-22 04:34:56 +00:00
|
|
|
[DllImport("libgobject-2.0-0.dll")]
|
2002-08-03 22:24:37 +00:00
|
|
|
static extern uint g_value_get_flags (IntPtr val);
|
2002-06-24 22:04:10 +00:00
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Value to Enum Conversion
|
|
|
|
/// </summary>
|
|
|
|
///
|
|
|
|
/// <remarks>
|
|
|
|
/// Extracts an enum from a Value. Note, this method
|
|
|
|
/// will produce an exception if the Value does not hold an
|
|
|
|
/// enum value.
|
|
|
|
/// </remarks>
|
|
|
|
|
|
|
|
public static explicit operator EnumWrapper (Value val)
|
|
|
|
{
|
|
|
|
// FIXME: Insert an appropriate exception here if
|
|
|
|
// _val.type indicates an error.
|
2002-08-03 22:24:37 +00:00
|
|
|
// FIXME: handle flags
|
|
|
|
return new EnumWrapper (g_value_get_enum (val._val), false);
|
2002-06-24 22:04:10 +00:00
|
|
|
}
|
|
|
|
|
2003-05-19 07:18:52 +00:00
|
|
|
[DllImport("gtksharpglue")]
|
2003-12-15 16:59:25 +00:00
|
|
|
static extern IntPtr gtksharp_value_get_value_type (IntPtr val);
|
2003-05-19 07:18:52 +00:00
|
|
|
|
|
|
|
public object Val
|
|
|
|
{
|
|
|
|
get {
|
2003-12-15 16:59:25 +00:00
|
|
|
GLib.GType type = new GLib.GType (gtksharp_value_get_value_type (_val));
|
2003-05-19 07:18:52 +00:00
|
|
|
if (type == ManagedValue.GType) {
|
|
|
|
return ManagedValue.ObjectForWrapper (g_value_get_boxed (_val));
|
|
|
|
}
|
|
|
|
|
2003-12-15 16:59:25 +00:00
|
|
|
if (type == GType.String)
|
2003-05-19 07:18:52 +00:00
|
|
|
return (string) this;
|
2003-12-15 16:59:25 +00:00
|
|
|
else if (type == GType.Boolean)
|
2003-05-19 07:18:52 +00:00
|
|
|
return (bool) this;
|
2003-12-15 16:59:25 +00:00
|
|
|
else if (type == GType.Int)
|
2003-05-19 07:18:52 +00:00
|
|
|
return (int) this;
|
2003-12-15 16:59:25 +00:00
|
|
|
else if (type == GType.Double)
|
2003-05-19 07:18:52 +00:00
|
|
|
return (double) this;
|
2003-12-15 16:59:25 +00:00
|
|
|
else if (type == GType.Float)
|
2003-05-19 07:18:52 +00:00
|
|
|
return (float) this;
|
2003-12-15 16:59:25 +00:00
|
|
|
else if (type == GType.Char)
|
2003-05-19 07:18:52 +00:00
|
|
|
return (char) this;
|
2003-12-15 16:59:25 +00:00
|
|
|
else if (type == GType.UInt)
|
2003-05-19 07:18:52 +00:00
|
|
|
return (uint) this;
|
2003-12-15 16:59:25 +00:00
|
|
|
else if (type == GType.Object)
|
2003-05-19 07:18:52 +00:00
|
|
|
return (GLib.Object) this;
|
2003-12-15 16:59:25 +00:00
|
|
|
else
|
2003-05-19 07:18:52 +00:00
|
|
|
throw new Exception ("Unknown type");
|
|
|
|
}
|
2003-11-04 23:20:15 +00:00
|
|
|
set {
|
2003-12-15 16:59:25 +00:00
|
|
|
GType type = GLibSharp.TypeConverter.LookupType (value.GetType());
|
|
|
|
if (type == GType.None)
|
2003-11-04 23:20:15 +00:00
|
|
|
g_value_set_boxed_take_ownership (_val, ManagedValue.WrapObject (value));
|
2003-12-15 16:59:25 +00:00
|
|
|
else if (type == GType.String)
|
2003-11-04 23:20:15 +00:00
|
|
|
g_value_set_string (_val, (string) value);
|
2003-12-15 16:59:25 +00:00
|
|
|
else if (type == GType.Boolean)
|
2003-11-04 23:20:15 +00:00
|
|
|
g_value_set_boolean (_val, (bool) value);
|
2003-12-15 16:59:25 +00:00
|
|
|
else if (type == GType.Int)
|
2003-11-04 23:20:15 +00:00
|
|
|
g_value_set_int (_val, (int) value);
|
2003-12-15 16:59:25 +00:00
|
|
|
else if (type == GType.Double)
|
2003-11-04 23:20:15 +00:00
|
|
|
g_value_set_double (_val, (double) value);
|
2003-12-15 16:59:25 +00:00
|
|
|
else if (type == GType.Float)
|
2003-11-04 23:20:15 +00:00
|
|
|
g_value_set_float (_val, (float) value);
|
2003-12-15 16:59:25 +00:00
|
|
|
else if (type == GType.Char)
|
2003-11-04 23:20:15 +00:00
|
|
|
g_value_set_char (_val, (char) value);
|
2003-12-15 16:59:25 +00:00
|
|
|
else if (type == GType.UInt)
|
2003-11-04 23:20:15 +00:00
|
|
|
g_value_set_uint (_val, (uint) value);
|
2003-12-15 16:59:25 +00:00
|
|
|
else if (type == GType.Object)
|
2003-11-04 23:20:15 +00:00
|
|
|
g_value_set_object (_val, ((GLib.Object) value).Handle);
|
2003-12-15 16:59:25 +00:00
|
|
|
else
|
2003-11-04 23:20:15 +00:00
|
|
|
throw new Exception ("Unknown type");
|
|
|
|
}
|
2003-05-19 07:18:52 +00:00
|
|
|
}
|
|
|
|
|
2002-05-02 21:57:41 +00:00
|
|
|
/// <summary>
|
|
|
|
/// Handle Property
|
2001-09-19 11:37:15 +00:00
|
|
|
/// </summary>
|
|
|
|
///
|
|
|
|
/// <remarks>
|
2001-09-28 00:28:30 +00:00
|
|
|
/// Read only. Accesses a pointer to the raw GValue.
|
2001-09-19 11:37:15 +00:00
|
|
|
/// </remarks>
|
|
|
|
|
2002-05-02 21:57:41 +00:00
|
|
|
public IntPtr Handle {
|
2001-09-19 11:37:15 +00:00
|
|
|
get {
|
|
|
|
return _val;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|