GtkSharp/glib/Value.cs
Mike Kestner 25000abee7 2001-09-27 Mike Kestner <mkestner@speakeasy.net>
*.cs : Added .dll extension to a load of DllImports.
	* makefile : now can make the project with one make windows and on
	both NT and Win98.
	* gdk/Event.cs : Fixed some invalid symbol names and commented out a
	load of stuff.
	* gdk/SimpleEvent.cs : Relocated file from unnecessary subdir and fixed
	several event keyword clashing bugs. Need to relocate the EventArgs
	class out of here into its own file. Fixed loads of typos.
	* glib/Object.cs : Killed the Constructor, this should be a purely
	abstract class. made Events property public until I can fix the Signal
	proxying system's broken reliance on it.
	* glib/SimpleSignal.cs : Relocated, namespaces, and named this Class.
	Loads of bugfixes. Still doesn't work worth a damn, but it builds.
	* glib/TypeFundamentals.cs : New enum for use in the Value code.
	* glib/Value.cs : Implemented a more opaque approach with heap allocated
	memory and g_value_init and friends.  Still doesn't work.  Will probably
	switch to a more C# like approach and avoid GValues altogether.
	* gtk/Button.cs : Commented out some brokeness until I can get around
	to fixing it later.
	* gtk/Widget.cs : Commented out a bunch of the new signal stuff until
	I get around to it.
	* gtk/Window.cs (Title): using g_object_set until I work out the
	details of the new Value/SetProperty system.  It looks like g_object_set
	will end up being easier to use via PInvoke.

svn path=/trunk/gtk-sharp/; revision=1008
2001-09-27 17:17:33 +00:00

99 lines
2.2 KiB
C#
Executable file

// GLib.Value.cs - GLib Value class implementation
//
// Author: Mike Kestner <mkestner@speakeasy.net>
//
// (c) 2001 Mike Kestner
namespace GLib {
using System;
using System.Runtime.InteropServices;
/// <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>
public class Value {
IntPtr _val;
// We use g_malloc0 and g_free to put the GValue on the
// heap to avoid some marshalling pain.
[DllImport("glib-1.3.dll")]
static extern IntPtr g_malloc0 (long n_bytes);
[DllImport("glib-1.3.dll")]
static extern void g_free (IntPtr mem);
[DllImport("gobject-1.3.dll")]
static extern void g_value_init (IntPtr val,
TypeFundamentals type);
/// <summary>
/// Value Constructor
/// </summary>
///
/// <remarks>
/// Constructs a Value from a spectified string.
/// </remarks>
[DllImport("gobject-1.3.dll")]
static extern void g_value_set_string (IntPtr val,
String data);
[DllImport("gobject-1.3.dll")]
static extern void g_value_set_boolean (IntPtr val,
bool data);
public Value (bool val)
{
_val = g_malloc0 (5 * IntPtr.Size);
g_value_init (_val, TypeFundamentals.TypeBoolean);
g_value_set_boolean (_val, val);
}
public Value (String str)
{
_val = g_malloc0 (5 * IntPtr.Size);
g_value_init (_val, TypeFundamentals.TypeString);
g_value_set_string (_val, str);
}
/// <summary>
/// GetString Method
/// </summary>
///
/// <remarks>
/// Extracts a string from a Value. Note, this method
/// will produce an exception if the Value does not hold a
/// string value.
/// </remarks>
[DllImport("gobject-1.3.dll")]
static extern String g_value_get_string (IntPtr val);
public String GetString ()
{
// FIXME: Insert an appropriate exception here if
// _val.type indicates an error.
return g_value_get_string (_val);
}
/// <summary>
/// RawValue Property
/// </summary>
///
/// <remarks>
/// Read only. Accesses a pointer to the Raw GValue.
/// </remarks>
public IntPtr RawValue {
get {
return _val;
}
}
}
}