2001-10-02 Mike Kestner <mkestner@speakeasy.net>

* glib/Value.cs : Tried adding CallingConvention.Cdecl to all the
	DllImports, but still couldn't get reliable Propery setting without
	periodic NullReference exceptions.  When all else fails, drop back
	and punt.
	* glib/Object.cs : Rewrote Set|GetProperty methods.  Now they use
	g_object_get|set and don't rely on GValues. The int, bool, and string
	prop types are now working reliably.
	* gtk/Window.cs : Update all Properties to use new GLib.Object
	signatures.
	* sample/HelloWorld.cs : added some more property usage for testing
	purposes.

svn path=/trunk/gtk-sharp/; revision=1048
This commit is contained in:
Mike Kestner 2001-10-02 01:27:44 +00:00
parent 14cf53f336
commit bda62ac3b7
5 changed files with 180 additions and 84 deletions

View File

@ -1,3 +1,17 @@
2001-10-02 Mike Kestner <mkestner@speakeasy.net>
* glib/Value.cs : Tried adding CallingConvention.Cdecl to all the
DllImports, but still couldn't get reliable Propery setting without
periodic NullReference exceptions. When all else fails, drop back
and punt.
* glib/Object.cs : Rewrote Set|GetProperty methods. Now they use
g_object_get|set and don't rely on GValues. The int, bool, and string
prop types are now working reliably.
* gtk/Window.cs : Update all Properties to use new GLib.Object
signatures.
* sample/HelloWorld.cs : added some more property usage for testing
purposes.
2001-09-29 Mike Kestner <mkestner@speakeasy.net>
* glib/Value.cs (int ctor): New constructor for int-based values.

View File

@ -126,17 +126,61 @@ namespace GLib {
/// </summary>
///
/// <remarks>
/// Accesses a raw Object Property.
/// Accesses a string Property.
/// </remarks>
[DllImport("gobject-1.3.dll")]
static extern void g_object_get_property (IntPtr obj,
String name,
IntPtr val);
[DllImport("gobject-1.3.dll", CharSet=CharSet.Ansi,
CallingConvention=CallingConvention.Cdecl)]
static extern void g_object_get (IntPtr obj, IntPtr name,
out IntPtr val, IntPtr term);
public void GetProperty (String name, Value val)
public void GetProperty (String name, out String val)
{
g_object_get_property (RawObject, name, val.MarshalAs);
IntPtr propval;
g_object_get (RawObject,
Marshal.StringToHGlobalAnsi (name),
out propval, new IntPtr (0));
val = Marshal.PtrToStringAnsi (propval);
}
/// <summary>
/// GetProperty Method
/// </summary>
///
/// <remarks>
/// Accesses a boolean Property.
/// </remarks>
[DllImport("gobject-1.3.dll", CharSet=CharSet.Ansi,
CallingConvention=CallingConvention.Cdecl)]
static extern void g_object_get (IntPtr obj, IntPtr name,
out bool val, IntPtr term);
public void GetProperty (String name, out bool val)
{
g_object_get (RawObject,
Marshal.StringToHGlobalAnsi (name),
out val, new IntPtr (0));
}
/// <summary>
/// GetProperty Method
/// </summary>
///
/// <remarks>
/// Accesses an integer Property.
/// </remarks>
[DllImport("gobject-1.3.dll", CharSet=CharSet.Ansi,
CallingConvention=CallingConvention.Cdecl)]
static extern void g_object_get (IntPtr obj, IntPtr name,
out int val, IntPtr term);
public void GetProperty (String name, out int val)
{
g_object_get (RawObject,
Marshal.StringToHGlobalAnsi (name),
out val, new IntPtr (0));
}
/// <summary>
@ -144,17 +188,60 @@ namespace GLib {
/// </summary>
///
/// <remarks>
/// Changes the value of a raw Object Property.
/// Changes the value of a string Property.
/// </remarks>
[DllImport("gobject-1.3.dll")]
static extern void g_object_set_property (IntPtr obj,
String name,
IntPtr val);
[DllImport("gobject-1.3.dll", CharSet=CharSet.Ansi,
CallingConvention=CallingConvention.Cdecl)]
static extern void g_object_set (IntPtr obj, IntPtr name,
IntPtr val, IntPtr term);
public void SetProperty (String name, Value val)
public void SetProperty (String name, String val)
{
g_object_set_property (RawObject, name, val.MarshalAs);
g_object_set (RawObject,
Marshal.StringToHGlobalAnsi (name),
Marshal.StringToHGlobalAnsi (val),
new IntPtr (0));
}
/// <summary>
/// SetProperty Method
/// </summary>
///
/// <remarks>
/// Changes the value of an integer Property.
/// </remarks>
[DllImport("gobject-1.3.dll", CharSet=CharSet.Ansi,
CallingConvention=CallingConvention.Cdecl)]
static extern void g_object_set (IntPtr obj, IntPtr name,
int val, IntPtr term);
public void SetProperty (String name, int val)
{
g_object_set (RawObject,
Marshal.StringToHGlobalAnsi (name),
val, new IntPtr (0));
}
/// <summary>
/// SetProperty Method
/// </summary>
///
/// <remarks>
/// Changes the value of a boolean Property.
/// </remarks>
[DllImport("gobject-1.3.dll", CharSet=CharSet.Ansi,
CallingConvention=CallingConvention.Cdecl)]
static extern void g_object_set (IntPtr obj, IntPtr name,
bool val, IntPtr term);
public void SetProperty (String name, bool val)
{
g_object_set (RawObject,
Marshal.StringToHGlobalAnsi (name),
val, new IntPtr (0));
}
/*
@ -218,7 +305,6 @@ gpointer g_object_steal_qdata (GObject *object,
void g_object_watch_closure (GObject *object,
GClosure *closure);
void g_object_run_dispose (GObject *object);
gpointer g_value_get_object (const GValue *value);
*/
}

View File

@ -44,7 +44,8 @@ namespace GLib {
/// value to it.
/// </remarks>
[DllImport("glib-1.3.dll")]
[DllImport("glib-1.3.dll",
CallingConvention=CallingConvention.Cdecl)]
static extern IntPtr g_malloc0 (long n_bytes);
public Value ()
@ -73,7 +74,8 @@ namespace GLib {
/// Constructs a Value from a specified boolean.
/// </remarks>
[DllImport("gobject-1.3.dll")]
[DllImport("gobject-1.3.dll",
CallingConvention=CallingConvention.Cdecl)]
static extern void g_value_set_boolean (IntPtr val,
bool data);
public Value (bool val) : this ()
@ -90,7 +92,8 @@ namespace GLib {
/// Constructs a Value from a specified integer.
/// </remarks>
[DllImport("gobject-1.3.dll")]
[DllImport("gobject-1.3.dll",
CallingConvention=CallingConvention.Cdecl)]
static extern void g_value_set_int (IntPtr val, int data);
public Value (int val) : this ()
@ -107,13 +110,15 @@ namespace GLib {
/// Constructs a Value from a specified string.
/// </remarks>
[DllImport("gobject-1.3.dll")]
[DllImport("gobject-1.3.dll",
CallingConvention=CallingConvention.Cdecl)]
static extern void g_value_set_string (IntPtr val,
String data);
IntPtr data);
public Value (String val) : this ()
{
g_value_init (_val, TypeFundamentals.TypeString);
g_value_set_string (_val, val);
g_value_set_string (_val,
Marshal.StringToHGlobalAnsi (val));
}
/// <summary>
@ -124,7 +129,8 @@ namespace GLib {
/// Prepares a raw value to hold a specified type.
/// </remarks>
[DllImport("gobject-1.3.dll")]
[DllImport("gobject-1.3.dll",
CallingConvention=CallingConvention.Cdecl)]
static extern void g_value_init (IntPtr val,
TypeFundamentals type);
@ -143,7 +149,8 @@ namespace GLib {
/// boolean value.
/// </remarks>
[DllImport("gobject-1.3.dll")]
[DllImport("gobject-1.3.dll",
CallingConvention=CallingConvention.Cdecl)]
static extern bool g_value_get_boolean (IntPtr val);
public static explicit operator bool (Value val)
@ -163,7 +170,8 @@ namespace GLib {
/// integer value.
/// </remarks>
[DllImport("gobject-1.3.dll")]
[DllImport("gobject-1.3.dll",
CallingConvention=CallingConvention.Cdecl)]
static extern int g_value_get_int (IntPtr val);
public static explicit operator int (Value val)
@ -183,14 +191,16 @@ namespace GLib {
/// string value.
/// </remarks>
[DllImport("gobject-1.3.dll")]
static extern String g_value_get_string (IntPtr val);
[DllImport("gobject-1.3.dll",
CallingConvention=CallingConvention.Cdecl)]
static extern IntPtr g_value_get_string (IntPtr val);
public static explicit operator String (Value val)
{
// FIXME: Insert an appropriate exception here if
// _val.type indicates an error.
return g_value_get_string (val._val);
return Marshal.PtrToStringAnsi (
g_value_get_string (val._val));
}
/// <summary>

View File

@ -72,14 +72,12 @@ namespace Gtk {
public bool AllowGrow {
get {
Value val = new Value (
TypeFundamentals.TypeBoolean);
GetProperty ("allow-grow", val);
return ((bool) val);
bool val;
GetProperty ("allow-grow", out val);
return (val);
}
set {
Value val = new Value (value);
SetProperty ("allow-grow", val);
SetProperty ("allow-grow", value);
}
}
@ -94,14 +92,12 @@ namespace Gtk {
public bool AllowShrink {
get {
Value val = new Value (
TypeFundamentals.TypeBoolean);
GetProperty ("allow-shrink", val);
return ((bool) val);
bool val;
GetProperty ("allow-shrink", out val);
return (val);
}
set {
Value val = new Value (value);
SetProperty ("allow-shrink", val);
SetProperty ("allow-shrink", value);
}
}
@ -115,18 +111,15 @@ namespace Gtk {
public int DefaultHeight {
get {
Value val = new Value (
TypeFundamentals.TypeInt);
GetProperty ("default-height", val);
return ((int) val);
int val;
GetProperty ("default-height", out val);
return (val);
}
set {
Value val = new Value (value);
SetProperty ("default-height", val);
SetProperty ("default-height", value);
}
}
/*
/// <summary>
/// DefaultSize Property
/// </summary>
@ -137,14 +130,14 @@ namespace Gtk {
public Size DefaultSize {
get {
GValue val = GetProp ("default-size");
return (val != 0);
return new Size (DefaultWidth, DefaultHeight);
}
set {
SetProp ("default-size", new GValue (value));
DefaultWidth = value.Width;
DefaultHeight = value.Height;
}
}
*/
/// <summary>
/// DefaultWidth Property
/// </summary>
@ -155,14 +148,12 @@ namespace Gtk {
public int DefaultWidth {
get {
Value val = new Value (
TypeFundamentals.TypeInt);
GetProperty ("default-width", val);
return ((int) val);
int val;
GetProperty ("default-width", out val);
return (val);
}
set {
Value val = new Value (value);
SetProperty ("default-width", val);
SetProperty ("default-width", value);
}
}
@ -178,14 +169,12 @@ namespace Gtk {
public bool DestroyWithParent {
get {
Value val = new Value (
TypeFundamentals.TypeBoolean);
GetProperty ("destroy-with-parent", val);
return ((bool) val);
bool val;
GetProperty ("destroy-with-parent", out val);
return (val);
}
set {
Value val = new Value (value);
SetProperty ("destroy-with-parent", val);
SetProperty ("destroy-with-parent", value);
}
}
@ -202,14 +191,12 @@ namespace Gtk {
public bool Modal {
get {
Value val = new Value (
TypeFundamentals.TypeBoolean);
GetProperty ("modal", val);
return ((bool) val);
bool val;
GetProperty ("modal", out val);
return (val);
}
set {
Value val = new Value (value);
SetProperty ("modal", val);
SetProperty ("modal", value);
}
}
@ -244,14 +231,12 @@ namespace Gtk {
public bool Resizable {
get {
Value val = new Value (
TypeFundamentals.TypeBoolean);
GetProperty ("resizable", val);
return ((bool) val);
bool val;
GetProperty ("resizable", out val);
return (val);
}
set {
Value val = new Value (value);
SetProperty ("resizable", val);
SetProperty ("resizable", value);
}
}
@ -263,18 +248,14 @@ namespace Gtk {
/// The Title displayed in the Window's Title Bar.
/// </remarks>
[DllImport("gobject-1.3.dll")]
static extern void g_object_set (IntPtr obj, String name,
IntPtr val, IntPtr term);
public String Title {
get {
String val;
GetProperty ("title", out val);
return val;
}
set {
g_object_set (RawObject, "title",
Marshal.StringToHGlobalAnsi (value), new IntPtr (0));
/* FIXME: When the String value setting problem is solved.
Value val = new Value (value);
SetProperty ("title", val);
*/
SetProperty ("title", value);
}
}
}

View File

@ -8,6 +8,7 @@ namespace GtkSamples {
using Gtk;
using System;
using System.Drawing;
public class HelloWorld {
@ -15,6 +16,10 @@ namespace GtkSamples {
{
Application.Init (ref args);
Window win = new Window ("Gtk# Hello World");
win.DefaultSize = new Size (400, 400);
System.Console.WriteLine (win.Title);
System.Console.WriteLine (win.DefaultSize);
System.Console.WriteLine (win.AllowShrink);
win.DeleteEvent += new EventHandler (Window_Delete);
win.Show ();
Application.Run ();