mirror of
https://github.com/Ryujinx/GtkSharp.git
synced 2024-12-23 12:45:37 +00:00
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:
parent
14cf53f336
commit
bda62ac3b7
14
ChangeLog
14
ChangeLog
|
@ -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>
|
2001-09-29 Mike Kestner <mkestner@speakeasy.net>
|
||||||
|
|
||||||
* glib/Value.cs (int ctor): New constructor for int-based values.
|
* glib/Value.cs (int ctor): New constructor for int-based values.
|
||||||
|
|
116
glib/Object.cs
116
glib/Object.cs
|
@ -126,17 +126,61 @@ namespace GLib {
|
||||||
/// </summary>
|
/// </summary>
|
||||||
///
|
///
|
||||||
/// <remarks>
|
/// <remarks>
|
||||||
/// Accesses a raw Object Property.
|
/// Accesses a string Property.
|
||||||
/// </remarks>
|
/// </remarks>
|
||||||
|
|
||||||
[DllImport("gobject-1.3.dll")]
|
[DllImport("gobject-1.3.dll", CharSet=CharSet.Ansi,
|
||||||
static extern void g_object_get_property (IntPtr obj,
|
CallingConvention=CallingConvention.Cdecl)]
|
||||||
String name,
|
static extern void g_object_get (IntPtr obj, IntPtr name,
|
||||||
IntPtr val);
|
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>
|
/// <summary>
|
||||||
|
@ -144,17 +188,60 @@ namespace GLib {
|
||||||
/// </summary>
|
/// </summary>
|
||||||
///
|
///
|
||||||
/// <remarks>
|
/// <remarks>
|
||||||
/// Changes the value of a raw Object Property.
|
/// Changes the value of a string Property.
|
||||||
/// </remarks>
|
/// </remarks>
|
||||||
|
|
||||||
[DllImport("gobject-1.3.dll")]
|
[DllImport("gobject-1.3.dll", CharSet=CharSet.Ansi,
|
||||||
static extern void g_object_set_property (IntPtr obj,
|
CallingConvention=CallingConvention.Cdecl)]
|
||||||
String name,
|
static extern void g_object_set (IntPtr obj, IntPtr name,
|
||||||
IntPtr val);
|
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,
|
void g_object_watch_closure (GObject *object,
|
||||||
GClosure *closure);
|
GClosure *closure);
|
||||||
void g_object_run_dispose (GObject *object);
|
void g_object_run_dispose (GObject *object);
|
||||||
gpointer g_value_get_object (const GValue *value);
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -44,7 +44,8 @@ namespace GLib {
|
||||||
/// value to it.
|
/// value to it.
|
||||||
/// </remarks>
|
/// </remarks>
|
||||||
|
|
||||||
[DllImport("glib-1.3.dll")]
|
[DllImport("glib-1.3.dll",
|
||||||
|
CallingConvention=CallingConvention.Cdecl)]
|
||||||
static extern IntPtr g_malloc0 (long n_bytes);
|
static extern IntPtr g_malloc0 (long n_bytes);
|
||||||
|
|
||||||
public Value ()
|
public Value ()
|
||||||
|
@ -73,7 +74,8 @@ namespace GLib {
|
||||||
/// Constructs a Value from a specified boolean.
|
/// Constructs a Value from a specified boolean.
|
||||||
/// </remarks>
|
/// </remarks>
|
||||||
|
|
||||||
[DllImport("gobject-1.3.dll")]
|
[DllImport("gobject-1.3.dll",
|
||||||
|
CallingConvention=CallingConvention.Cdecl)]
|
||||||
static extern void g_value_set_boolean (IntPtr val,
|
static extern void g_value_set_boolean (IntPtr val,
|
||||||
bool data);
|
bool data);
|
||||||
public Value (bool val) : this ()
|
public Value (bool val) : this ()
|
||||||
|
@ -90,7 +92,8 @@ namespace GLib {
|
||||||
/// Constructs a Value from a specified integer.
|
/// Constructs a Value from a specified integer.
|
||||||
/// </remarks>
|
/// </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);
|
static extern void g_value_set_int (IntPtr val, int data);
|
||||||
|
|
||||||
public Value (int val) : this ()
|
public Value (int val) : this ()
|
||||||
|
@ -107,13 +110,15 @@ namespace GLib {
|
||||||
/// Constructs a Value from a specified string.
|
/// Constructs a Value from a specified string.
|
||||||
/// </remarks>
|
/// </remarks>
|
||||||
|
|
||||||
[DllImport("gobject-1.3.dll")]
|
[DllImport("gobject-1.3.dll",
|
||||||
|
CallingConvention=CallingConvention.Cdecl)]
|
||||||
static extern void g_value_set_string (IntPtr val,
|
static extern void g_value_set_string (IntPtr val,
|
||||||
String data);
|
IntPtr data);
|
||||||
public Value (String val) : this ()
|
public Value (String val) : this ()
|
||||||
{
|
{
|
||||||
g_value_init (_val, TypeFundamentals.TypeString);
|
g_value_init (_val, TypeFundamentals.TypeString);
|
||||||
g_value_set_string (_val, val);
|
g_value_set_string (_val,
|
||||||
|
Marshal.StringToHGlobalAnsi (val));
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -124,7 +129,8 @@ namespace GLib {
|
||||||
/// Prepares a raw value to hold a specified type.
|
/// Prepares a raw value to hold a specified type.
|
||||||
/// </remarks>
|
/// </remarks>
|
||||||
|
|
||||||
[DllImport("gobject-1.3.dll")]
|
[DllImport("gobject-1.3.dll",
|
||||||
|
CallingConvention=CallingConvention.Cdecl)]
|
||||||
static extern void g_value_init (IntPtr val,
|
static extern void g_value_init (IntPtr val,
|
||||||
TypeFundamentals type);
|
TypeFundamentals type);
|
||||||
|
|
||||||
|
@ -143,7 +149,8 @@ namespace GLib {
|
||||||
/// boolean value.
|
/// boolean value.
|
||||||
/// </remarks>
|
/// </remarks>
|
||||||
|
|
||||||
[DllImport("gobject-1.3.dll")]
|
[DllImport("gobject-1.3.dll",
|
||||||
|
CallingConvention=CallingConvention.Cdecl)]
|
||||||
static extern bool g_value_get_boolean (IntPtr val);
|
static extern bool g_value_get_boolean (IntPtr val);
|
||||||
|
|
||||||
public static explicit operator bool (Value val)
|
public static explicit operator bool (Value val)
|
||||||
|
@ -163,7 +170,8 @@ namespace GLib {
|
||||||
/// integer value.
|
/// integer value.
|
||||||
/// </remarks>
|
/// </remarks>
|
||||||
|
|
||||||
[DllImport("gobject-1.3.dll")]
|
[DllImport("gobject-1.3.dll",
|
||||||
|
CallingConvention=CallingConvention.Cdecl)]
|
||||||
static extern int g_value_get_int (IntPtr val);
|
static extern int g_value_get_int (IntPtr val);
|
||||||
|
|
||||||
public static explicit operator int (Value val)
|
public static explicit operator int (Value val)
|
||||||
|
@ -183,14 +191,16 @@ namespace GLib {
|
||||||
/// string value.
|
/// string value.
|
||||||
/// </remarks>
|
/// </remarks>
|
||||||
|
|
||||||
[DllImport("gobject-1.3.dll")]
|
[DllImport("gobject-1.3.dll",
|
||||||
static extern String g_value_get_string (IntPtr val);
|
CallingConvention=CallingConvention.Cdecl)]
|
||||||
|
static extern IntPtr g_value_get_string (IntPtr val);
|
||||||
|
|
||||||
public static explicit operator String (Value val)
|
public static explicit operator String (Value val)
|
||||||
{
|
{
|
||||||
// FIXME: Insert an appropriate exception here if
|
// FIXME: Insert an appropriate exception here if
|
||||||
// _val.type indicates an error.
|
// _val.type indicates an error.
|
||||||
return g_value_get_string (val._val);
|
return Marshal.PtrToStringAnsi (
|
||||||
|
g_value_get_string (val._val));
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|
|
@ -72,14 +72,12 @@ namespace Gtk {
|
||||||
|
|
||||||
public bool AllowGrow {
|
public bool AllowGrow {
|
||||||
get {
|
get {
|
||||||
Value val = new Value (
|
bool val;
|
||||||
TypeFundamentals.TypeBoolean);
|
GetProperty ("allow-grow", out val);
|
||||||
GetProperty ("allow-grow", val);
|
return (val);
|
||||||
return ((bool) val);
|
|
||||||
}
|
}
|
||||||
set {
|
set {
|
||||||
Value val = new Value (value);
|
SetProperty ("allow-grow", value);
|
||||||
SetProperty ("allow-grow", val);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -94,14 +92,12 @@ namespace Gtk {
|
||||||
|
|
||||||
public bool AllowShrink {
|
public bool AllowShrink {
|
||||||
get {
|
get {
|
||||||
Value val = new Value (
|
bool val;
|
||||||
TypeFundamentals.TypeBoolean);
|
GetProperty ("allow-shrink", out val);
|
||||||
GetProperty ("allow-shrink", val);
|
return (val);
|
||||||
return ((bool) val);
|
|
||||||
}
|
}
|
||||||
set {
|
set {
|
||||||
Value val = new Value (value);
|
SetProperty ("allow-shrink", value);
|
||||||
SetProperty ("allow-shrink", val);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -115,18 +111,15 @@ namespace Gtk {
|
||||||
|
|
||||||
public int DefaultHeight {
|
public int DefaultHeight {
|
||||||
get {
|
get {
|
||||||
Value val = new Value (
|
int val;
|
||||||
TypeFundamentals.TypeInt);
|
GetProperty ("default-height", out val);
|
||||||
GetProperty ("default-height", val);
|
return (val);
|
||||||
return ((int) val);
|
|
||||||
}
|
}
|
||||||
set {
|
set {
|
||||||
Value val = new Value (value);
|
SetProperty ("default-height", value);
|
||||||
SetProperty ("default-height", val);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// DefaultSize Property
|
/// DefaultSize Property
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
@ -137,14 +130,14 @@ namespace Gtk {
|
||||||
|
|
||||||
public Size DefaultSize {
|
public Size DefaultSize {
|
||||||
get {
|
get {
|
||||||
GValue val = GetProp ("default-size");
|
return new Size (DefaultWidth, DefaultHeight);
|
||||||
return (val != 0);
|
|
||||||
}
|
}
|
||||||
set {
|
set {
|
||||||
SetProp ("default-size", new GValue (value));
|
DefaultWidth = value.Width;
|
||||||
|
DefaultHeight = value.Height;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
*/
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// DefaultWidth Property
|
/// DefaultWidth Property
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
@ -155,14 +148,12 @@ namespace Gtk {
|
||||||
|
|
||||||
public int DefaultWidth {
|
public int DefaultWidth {
|
||||||
get {
|
get {
|
||||||
Value val = new Value (
|
int val;
|
||||||
TypeFundamentals.TypeInt);
|
GetProperty ("default-width", out val);
|
||||||
GetProperty ("default-width", val);
|
return (val);
|
||||||
return ((int) val);
|
|
||||||
}
|
}
|
||||||
set {
|
set {
|
||||||
Value val = new Value (value);
|
SetProperty ("default-width", value);
|
||||||
SetProperty ("default-width", val);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -178,14 +169,12 @@ namespace Gtk {
|
||||||
|
|
||||||
public bool DestroyWithParent {
|
public bool DestroyWithParent {
|
||||||
get {
|
get {
|
||||||
Value val = new Value (
|
bool val;
|
||||||
TypeFundamentals.TypeBoolean);
|
GetProperty ("destroy-with-parent", out val);
|
||||||
GetProperty ("destroy-with-parent", val);
|
return (val);
|
||||||
return ((bool) val);
|
|
||||||
}
|
}
|
||||||
set {
|
set {
|
||||||
Value val = new Value (value);
|
SetProperty ("destroy-with-parent", value);
|
||||||
SetProperty ("destroy-with-parent", val);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -202,14 +191,12 @@ namespace Gtk {
|
||||||
|
|
||||||
public bool Modal {
|
public bool Modal {
|
||||||
get {
|
get {
|
||||||
Value val = new Value (
|
bool val;
|
||||||
TypeFundamentals.TypeBoolean);
|
GetProperty ("modal", out val);
|
||||||
GetProperty ("modal", val);
|
return (val);
|
||||||
return ((bool) val);
|
|
||||||
}
|
}
|
||||||
set {
|
set {
|
||||||
Value val = new Value (value);
|
SetProperty ("modal", value);
|
||||||
SetProperty ("modal", val);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -244,14 +231,12 @@ namespace Gtk {
|
||||||
|
|
||||||
public bool Resizable {
|
public bool Resizable {
|
||||||
get {
|
get {
|
||||||
Value val = new Value (
|
bool val;
|
||||||
TypeFundamentals.TypeBoolean);
|
GetProperty ("resizable", out val);
|
||||||
GetProperty ("resizable", val);
|
return (val);
|
||||||
return ((bool) val);
|
|
||||||
}
|
}
|
||||||
set {
|
set {
|
||||||
Value val = new Value (value);
|
SetProperty ("resizable", value);
|
||||||
SetProperty ("resizable", val);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -263,18 +248,14 @@ namespace Gtk {
|
||||||
/// The Title displayed in the Window's Title Bar.
|
/// The Title displayed in the Window's Title Bar.
|
||||||
/// </remarks>
|
/// </remarks>
|
||||||
|
|
||||||
[DllImport("gobject-1.3.dll")]
|
|
||||||
static extern void g_object_set (IntPtr obj, String name,
|
|
||||||
IntPtr val, IntPtr term);
|
|
||||||
|
|
||||||
public String Title {
|
public String Title {
|
||||||
|
get {
|
||||||
|
String val;
|
||||||
|
GetProperty ("title", out val);
|
||||||
|
return val;
|
||||||
|
}
|
||||||
set {
|
set {
|
||||||
g_object_set (RawObject, "title",
|
SetProperty ("title", value);
|
||||||
Marshal.StringToHGlobalAnsi (value), new IntPtr (0));
|
|
||||||
/* FIXME: When the String value setting problem is solved.
|
|
||||||
Value val = new Value (value);
|
|
||||||
SetProperty ("title", val);
|
|
||||||
*/
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,6 +8,7 @@ namespace GtkSamples {
|
||||||
|
|
||||||
using Gtk;
|
using Gtk;
|
||||||
using System;
|
using System;
|
||||||
|
using System.Drawing;
|
||||||
|
|
||||||
public class HelloWorld {
|
public class HelloWorld {
|
||||||
|
|
||||||
|
@ -15,6 +16,10 @@ namespace GtkSamples {
|
||||||
{
|
{
|
||||||
Application.Init (ref args);
|
Application.Init (ref args);
|
||||||
Window win = new Window ("Gtk# Hello World");
|
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.DeleteEvent += new EventHandler (Window_Delete);
|
||||||
win.Show ();
|
win.Show ();
|
||||||
Application.Run ();
|
Application.Run ();
|
||||||
|
|
Loading…
Reference in a new issue