2003-05-19 07:18:52 +00:00
|
|
|
// GLib.ManagedValue.cs : Managed types boxer
|
|
|
|
//
|
|
|
|
// Author: Rachel Hestilow <hestilow@ximian.com>
|
|
|
|
//
|
2004-06-25 18:42:19 +00:00
|
|
|
// Copyright (c) 2002 Rachel Hestilow
|
|
|
|
//
|
|
|
|
// 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.
|
|
|
|
|
2003-05-19 07:18:52 +00:00
|
|
|
|
2004-05-28 16:59:21 +00:00
|
|
|
namespace GLib {
|
2003-05-19 07:18:52 +00:00
|
|
|
using System;
|
|
|
|
using System.Collections;
|
|
|
|
using System.Runtime.InteropServices;
|
2003-12-15 16:59:25 +00:00
|
|
|
using GLib;
|
2003-05-19 07:18:52 +00:00
|
|
|
|
2004-05-28 16:59:21 +00:00
|
|
|
internal class ManagedValue {
|
2003-05-19 07:18:52 +00:00
|
|
|
|
2005-03-23 20:35:15 +00:00
|
|
|
[CDeclCallback]
|
|
|
|
delegate IntPtr CopyFunc (IntPtr gch);
|
|
|
|
[CDeclCallback]
|
|
|
|
delegate void FreeFunc (IntPtr gch);
|
2003-05-19 07:18:52 +00:00
|
|
|
|
2005-03-23 20:35:15 +00:00
|
|
|
static CopyFunc copy;
|
|
|
|
static FreeFunc free;
|
|
|
|
static GType boxed_type = GType.Invalid;
|
2003-05-19 07:18:52 +00:00
|
|
|
|
2003-05-22 23:39:04 +00:00
|
|
|
[DllImport("libgobject-2.0-0.dll")]
|
2005-03-23 20:35:15 +00:00
|
|
|
static extern IntPtr g_boxed_type_register_static (IntPtr typename, CopyFunc copy_func, FreeFunc free_func);
|
2003-05-19 07:18:52 +00:00
|
|
|
|
2003-12-15 16:59:25 +00:00
|
|
|
public static GType GType {
|
2003-05-19 07:18:52 +00:00
|
|
|
get {
|
2003-12-15 16:59:25 +00:00
|
|
|
if (boxed_type == GType.Invalid) {
|
2003-05-19 07:18:52 +00:00
|
|
|
copy = new CopyFunc (Copy);
|
|
|
|
free = new FreeFunc (Free);
|
|
|
|
|
2005-03-08 21:28:08 +00:00
|
|
|
IntPtr name = Marshaller.StringToPtrGStrdup ("GtkSharpValue");
|
|
|
|
boxed_type = new GLib.GType (g_boxed_type_register_static (name, copy, free));
|
|
|
|
Marshaller.Free (name);
|
2003-05-19 07:18:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return boxed_type;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-03-23 20:35:15 +00:00
|
|
|
static IntPtr Copy (IntPtr ptr)
|
2003-05-19 07:18:52 +00:00
|
|
|
{
|
2005-03-23 20:35:15 +00:00
|
|
|
GCHandle gch = (GCHandle) ptr;
|
|
|
|
return (IntPtr) GCHandle.Alloc (gch.Target);
|
2003-05-19 07:18:52 +00:00
|
|
|
}
|
|
|
|
|
2005-03-23 20:35:15 +00:00
|
|
|
static void Free (IntPtr ptr)
|
2003-05-19 07:18:52 +00:00
|
|
|
{
|
2005-03-23 20:35:15 +00:00
|
|
|
GCHandle gch = (GCHandle) ptr;
|
|
|
|
gch.Free ();
|
2003-05-19 07:18:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public static IntPtr WrapObject (object obj)
|
|
|
|
{
|
2005-03-23 20:35:15 +00:00
|
|
|
return (IntPtr) GCHandle.Alloc (obj);
|
2003-05-19 07:18:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public static object ObjectForWrapper (IntPtr ptr)
|
|
|
|
{
|
2005-03-23 20:35:15 +00:00
|
|
|
return ((GCHandle)ptr).Target;
|
2003-05-19 07:18:52 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|