* glib/Value.cs: Obsolete the EnumWrapper and UnwrappedObject
constructors and casts. Add a new Enum cast. (Val): Handle Pointer values. Change the handling of Enum/Flags values to return the value directly rather than returning an EnumWrapper. Remove the Char (ie, "byte") handling since there aren't any char properties in all of gtk-sharp and the generator mistakenly converts them to strings anyway. * glib/EnumWrapper.cs: * glib/UnwrappedObject.cs: Mark these Obsolete. * glib/glue/type.c (gtksharp_get_parent_type, gtksharp_get_type_name_for_id): * glib/glue/value.c (gtksharp_value_get_value_type): Remove some unneeded glue methods. * generator/Ctor.cs (Generate): * generator/Property.cs (Generate): Simplify the enum and object property glue to not use EnumWrapper or UnwrappedObject. * sample/valtest/*: a regression test for GLib.Value * configure.in.in: add sample/valtest svn path=/trunk/gtk-sharp/; revision=47564
This commit is contained in:
parent
d37d940eb8
commit
196be89bc9
16 changed files with 1002 additions and 100 deletions
26
ChangeLog
26
ChangeLog
|
@ -1,3 +1,29 @@
|
|||
2005-07-21 Dan Winship <danw@novell.com>
|
||||
|
||||
* glib/Value.cs: Obsolete the EnumWrapper and UnwrappedObject
|
||||
constructors and casts. Add a new Enum cast.
|
||||
(Val): Handle Pointer values. Change the handling of Enum/Flags
|
||||
values to return the value directly rather than returning an
|
||||
EnumWrapper. Remove the Char (ie, "byte") handling since there
|
||||
aren't any char properties in all of gtk-sharp and the generator
|
||||
mistakenly converts them to strings anyway.
|
||||
|
||||
* glib/EnumWrapper.cs:
|
||||
* glib/UnwrappedObject.cs: Mark these Obsolete.
|
||||
|
||||
* glib/glue/type.c (gtksharp_get_parent_type,
|
||||
gtksharp_get_type_name_for_id):
|
||||
* glib/glue/value.c (gtksharp_value_get_value_type): Remove some
|
||||
unneeded glue methods.
|
||||
|
||||
* generator/Ctor.cs (Generate):
|
||||
* generator/Property.cs (Generate): Simplify the enum and object
|
||||
property glue to not use EnumWrapper or UnwrappedObject.
|
||||
|
||||
* sample/valtest/*: a regression test for GLib.Value
|
||||
|
||||
* configure.in.in: add sample/valtest
|
||||
|
||||
2005-07-21 Dan Winship <danw@novell.com>
|
||||
|
||||
* parser/gapi2xml.pl (parseInitFunc): handle interface properties
|
||||
|
|
|
@ -311,6 +311,8 @@ sample/gnomevfs/Makefile
|
|||
sample/pixmaps/Makefile
|
||||
sample/rsvg/Makefile
|
||||
sample/test/Makefile
|
||||
sample/valtest/Makefile
|
||||
sample/valtest/valtest.exe.config
|
||||
sample/cairo-sample.exe.config
|
||||
])
|
||||
|
||||
|
|
|
@ -89,8 +89,6 @@ namespace GtkSharp.Generation {
|
|||
StreamWriter sw = gen_info.Writer;
|
||||
gen_info.CurrentMember = CName;
|
||||
|
||||
SymbolTable table = SymbolTable.Table;
|
||||
|
||||
GenerateImport (sw);
|
||||
|
||||
if (IsStatic)
|
||||
|
@ -130,12 +128,7 @@ namespace GtkSharp.Generation {
|
|||
indent += "\t";
|
||||
}
|
||||
sw.WriteLine (indent + "names.Add (\"" + names [i] + "\");");
|
||||
sw.Write (indent + "vals.Add (");
|
||||
|
||||
if (table.IsEnum (p.CType))
|
||||
sw.WriteLine ("new GLib.Value (this, \"" + names[i] + "\", new GLib.EnumWrapper ((int)" + values[i] + ", " + (table.IsEnumFlags (p.CType) ? "true" : "false") + ")));");
|
||||
else
|
||||
sw.WriteLine ("new GLib.Value (" + values[i] + "));");
|
||||
sw.WriteLine (indent + "vals.Add (new GLib.Value (" + values[i] + "));");
|
||||
|
||||
if (p.Generatable is ClassBase && !(p.Generatable is StructBase))
|
||||
sw.WriteLine ("\t\t\t\t}");
|
||||
|
|
|
@ -108,12 +108,8 @@ namespace GtkSharp.Generation {
|
|||
string qpname = "\"" + CName + "\"";
|
||||
|
||||
string v_type = "";
|
||||
if (table.IsEnum(CType)) {
|
||||
v_type = "(int) (GLib.EnumWrapper)";
|
||||
} else if (table.IsObject(CType) || table.IsInterface (CType)) {
|
||||
v_type = "(GLib.UnwrappedObject)";
|
||||
} else if (table.IsBoxed (CType)) {
|
||||
v_type = "(GLib.Boxed)";
|
||||
if (table.IsInterface (CType)) {
|
||||
v_type = "(GLib.Object)";
|
||||
} else if (table.IsOpaque (CType)) {
|
||||
v_type = "(GLib.Opaque)";
|
||||
}
|
||||
|
@ -131,10 +127,7 @@ namespace GtkSharp.Generation {
|
|||
} else if (Readable) {
|
||||
sw.WriteLine(indent + "get {");
|
||||
sw.WriteLine(indent + "\tGLib.Value val = " + RawGetter (qpname) + ";");
|
||||
if (table.IsObject (CType) || table.IsInterface (CType)) {
|
||||
sw.WriteLine(indent + "\tSystem.IntPtr raw_ret = (System.IntPtr) {0} val;", v_type);
|
||||
sw.WriteLine(indent + "\t" + CSType + " ret = " + table.FromNativeReturn(CType, "raw_ret") + ";");
|
||||
} else if (table.IsOpaque (CType) || table.IsBoxed (CType)) {
|
||||
if (table.IsOpaque (CType) || table.IsBoxed (CType)) {
|
||||
sw.WriteLine(indent + "\t" + CSType + " ret = (" + CSType + ") val;");
|
||||
} else {
|
||||
sw.Write(indent + "\t" + CSType + " ret = ");
|
||||
|
@ -157,9 +150,7 @@ namespace GtkSharp.Generation {
|
|||
} else if (Writable) {
|
||||
sw.WriteLine(indent + "set {");
|
||||
sw.Write(indent + "\tGLib.Value val = ");
|
||||
if (table.IsEnum(CType)) {
|
||||
sw.WriteLine("new GLib.Value(new GLib.EnumWrapper ((int) value, {0}), \"{1}\");", table.IsEnumFlags (CType) ? "true" : "false", CType);
|
||||
} else if (table.IsBoxed (CType)) {
|
||||
if (table.IsBoxed (CType)) {
|
||||
sw.WriteLine("(GLib.Value) value;");
|
||||
} else if (table.IsOpaque (CType)) {
|
||||
sw.WriteLine("new GLib.Value(value, \"{0}\");", CType);
|
||||
|
|
|
@ -24,8 +24,7 @@ namespace GLib {
|
|||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
// <summary> Enum wrapping class </summary>
|
||||
// <remarks> </remarks>
|
||||
[Obsolete ("Replaced by direct enum type casts to/from GLib.Value")]
|
||||
public class EnumWrapper {
|
||||
int val;
|
||||
public bool flags;
|
||||
|
|
|
@ -24,8 +24,7 @@ namespace GLib {
|
|||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
// <summary> Unwrapped object class </summary>
|
||||
// <remarks> </remarks>
|
||||
[Obsolete ("Replaced by direct object-type casts to/from GLib.Value")]
|
||||
public class UnwrappedObject {
|
||||
IntPtr obj;
|
||||
|
||||
|
|
|
@ -82,6 +82,7 @@ namespace GLib {
|
|||
g_value_set_uint64 (ref this, val);
|
||||
}
|
||||
|
||||
[Obsolete ("Replaced by Value(object) constructor")]
|
||||
public Value (EnumWrapper wrap, string type_name)
|
||||
{
|
||||
type = IntPtr.Zero;
|
||||
|
@ -228,6 +229,7 @@ namespace GLib {
|
|||
return g_value_get_uint64 (ref val);
|
||||
}
|
||||
|
||||
[Obsolete ("Replaced by Enum cast")]
|
||||
public static explicit operator EnumWrapper (Value val)
|
||||
{
|
||||
if (glibsharp_value_holds_flags (ref val))
|
||||
|
@ -236,6 +238,14 @@ namespace GLib {
|
|||
return new EnumWrapper (g_value_get_enum (ref val), false);
|
||||
}
|
||||
|
||||
public static explicit operator Enum (Value val)
|
||||
{
|
||||
if (glibsharp_value_holds_flags (ref val))
|
||||
return (Enum)Enum.ToObject (GType.LookupType (val.type), g_value_get_flags (ref val));
|
||||
else
|
||||
return (Enum)Enum.ToObject (GType.LookupType (val.type), g_value_get_enum (ref val));
|
||||
}
|
||||
|
||||
public static explicit operator float (Value val)
|
||||
{
|
||||
return g_value_get_float (ref val);
|
||||
|
@ -272,6 +282,7 @@ namespace GLib {
|
|||
return GLib.Object.GetObject (g_value_get_object (ref val), false);
|
||||
}
|
||||
|
||||
[Obsolete ("Replaced by GLib.Object cast")]
|
||||
public static explicit operator GLib.UnwrappedObject (Value val)
|
||||
{
|
||||
return new UnwrappedObject (g_value_get_object (ref val));
|
||||
|
@ -295,86 +306,79 @@ namespace GLib {
|
|||
public object Val
|
||||
{
|
||||
get {
|
||||
GLib.GType type = new GLib.GType (gtksharp_value_get_value_type (ref this));
|
||||
if (type == GType.Char)
|
||||
return (char) this;
|
||||
else if (type == GType.Boolean)
|
||||
if (type == GType.Boolean.Val)
|
||||
return (bool) this;
|
||||
else if (type == GType.Int)
|
||||
else if (type == GType.Int.Val)
|
||||
return (int) this;
|
||||
else if (type == GType.UInt)
|
||||
else if (type == GType.UInt.Val)
|
||||
return (uint) this;
|
||||
else if (type == GType.Int64)
|
||||
else if (type == GType.Int64.Val)
|
||||
return (long) this;
|
||||
else if (type == GType.UInt64)
|
||||
else if (type == GType.UInt64.Val)
|
||||
return (ulong) this;
|
||||
else if (type == GType.Float)
|
||||
else if (g_type_is_a (type, GType.Enum.Val) ||
|
||||
g_type_is_a (type, GType.Flags.Val))
|
||||
return (Enum) this;
|
||||
else if (type == GType.Float.Val)
|
||||
return (float) this;
|
||||
else if (type == GType.Double)
|
||||
else if (type == GType.Double.Val)
|
||||
return (double) this;
|
||||
else if (type == GType.String)
|
||||
else if (type == GType.String.Val)
|
||||
return (string) this;
|
||||
else if (type == ManagedValue.GType)
|
||||
else if (type == GType.Pointer.Val)
|
||||
return (IntPtr) this;
|
||||
else if (type == ManagedValue.GType.Val)
|
||||
return ManagedValue.ObjectForWrapper (g_value_get_boxed (ref this));
|
||||
else if (g_type_is_a (type.Val, GLib.GType.Enum.Val))
|
||||
return (EnumWrapper) this;
|
||||
else if (g_type_is_a (type.Val, GLib.GType.Flags.Val))
|
||||
return (EnumWrapper) this;
|
||||
else if (g_type_is_a (type.Val, GType.Object.Val))
|
||||
else if (g_type_is_a (type, GType.Object.Val))
|
||||
return (GLib.Object) this;
|
||||
else
|
||||
throw new Exception ("Unknown type");
|
||||
throw new Exception ("Unknown type " + new GType (type).ToString ());
|
||||
}
|
||||
set {
|
||||
IntPtr buf;
|
||||
GType type = (GType) value.GetType();
|
||||
if (type == GType.Char)
|
||||
g_value_set_char (ref this, (char) value);
|
||||
else if (type == GType.Boolean)
|
||||
if (type == GType.Boolean.Val)
|
||||
g_value_set_boolean (ref this, (bool) value);
|
||||
else if (type == GType.Int)
|
||||
else if (type == GType.Int.Val)
|
||||
g_value_set_int (ref this, (int) value);
|
||||
else if (type == GType.UInt)
|
||||
else if (type == GType.UInt.Val)
|
||||
g_value_set_uint (ref this, (uint) value);
|
||||
else if (type == GType.Int64)
|
||||
else if (type == GType.Int64.Val)
|
||||
g_value_set_int64 (ref this, (long) value);
|
||||
else if (type == GType.UInt64)
|
||||
else if (type == GType.UInt64.Val)
|
||||
g_value_set_uint64 (ref this, (ulong) value);
|
||||
else if (type == GType.Float)
|
||||
else if (g_type_is_a (type, GType.Enum.Val))
|
||||
g_value_set_enum (ref this, (int)value);
|
||||
else if (g_type_is_a (type, GType.Flags.Val))
|
||||
g_value_set_flags (ref this, (uint)(int)value);
|
||||
else if (type == GType.Float.Val)
|
||||
g_value_set_float (ref this, (float) value);
|
||||
else if (type == GType.Double)
|
||||
else if (type == GType.Double.Val)
|
||||
g_value_set_double (ref this, (double) value);
|
||||
else if (type == GType.String) {
|
||||
else if (type == GType.String.Val) {
|
||||
IntPtr native = GLib.Marshaller.StringToPtrGStrdup ((string)value);
|
||||
g_value_set_string (ref this, native);
|
||||
GLib.Marshaller.Free (native);
|
||||
} else if (type == GType.Pointer) {
|
||||
} else if (type == GType.Pointer.Val) {
|
||||
if (value is IWrapper) {
|
||||
g_value_set_pointer (ref this, ((IWrapper)value).Handle);
|
||||
return;
|
||||
}
|
||||
buf = Marshal.AllocHGlobal (Marshal.SizeOf (value.GetType()));
|
||||
IntPtr buf = Marshal.AllocHGlobal (Marshal.SizeOf (value.GetType()));
|
||||
Marshal.StructureToPtr (value, buf, false);
|
||||
g_value_set_pointer (ref this, buf);
|
||||
} else if (type == ManagedValue.GType) {
|
||||
} else if (type == ManagedValue.GType.Val)
|
||||
g_value_set_boxed (ref this, ManagedValue.WrapObject (value));
|
||||
} else if (g_type_is_a (type.Val, GLib.GType.Enum.Val)) {
|
||||
g_value_set_enum (ref this, (int) value);
|
||||
} else if (g_type_is_a (type.Val, GLib.GType.Flags.Val)) {
|
||||
g_value_set_flags (ref this, (uint) value);
|
||||
} else if (g_type_is_a (type.Val, GLib.GType.Boxed.Val)) {
|
||||
else if (g_type_is_a (type, GType.Object.Val))
|
||||
g_value_set_object (ref this, ((GLib.Object) value).Handle);
|
||||
else if (g_type_is_a (type, GType.Boxed.Val)) {
|
||||
if (value is IWrapper) {
|
||||
g_value_set_boxed (ref this, ((IWrapper)value).Handle);
|
||||
return;
|
||||
}
|
||||
buf = Marshal.AllocHGlobal (Marshal.SizeOf (value.GetType()));
|
||||
Marshal.StructureToPtr (value, buf, false);
|
||||
IntPtr buf = Marshaller.StructureToPtrAlloc (value);
|
||||
g_value_set_boxed (ref this, buf);
|
||||
Marshal.FreeHGlobal (buf);
|
||||
} else if (g_type_is_a (type.Val, GType.Object.Val))
|
||||
g_value_set_object (ref this, ((GLib.Object) value).Handle);
|
||||
else
|
||||
throw new Exception ("Unknown type");
|
||||
} else
|
||||
throw new Exception ("Unknown type " + new GType (type).ToString ());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -430,8 +434,6 @@ namespace GLib {
|
|||
static extern void g_value_set_enum (ref Value val, int data);
|
||||
[DllImport("libgobject-2.0-0.dll")]
|
||||
static extern void g_value_set_flags (ref Value val, uint data);
|
||||
[DllImport("libgobject-2.0-0.dll")]
|
||||
static extern void g_value_set_char (ref Value val, char data);
|
||||
|
||||
[DllImport("libgobject-2.0-0.dll")]
|
||||
static extern bool g_value_get_boolean (ref Value val);
|
||||
|
@ -473,9 +475,6 @@ namespace GLib {
|
|||
[DllImport("glibsharpglue-2")]
|
||||
static extern bool glibsharp_value_holds_flags (ref Value val);
|
||||
|
||||
[DllImport("glibsharpglue-2")]
|
||||
static extern IntPtr gtksharp_value_get_value_type (ref Value val);
|
||||
|
||||
[DllImport("libgobject-2.0-0.dll")]
|
||||
static extern bool g_type_is_a (IntPtr type, IntPtr is_a_type);
|
||||
|
||||
|
|
|
@ -29,10 +29,6 @@ gboolean gtksharp_is_object (gpointer obj);
|
|||
|
||||
GType gtksharp_get_type_id (GObject *obj);
|
||||
|
||||
GType gtksharp_get_parent_type (GType typ);
|
||||
|
||||
G_CONST_RETURN gchar *gtksharp_get_type_name_for_id (GType typ);
|
||||
|
||||
GType gtksharp_register_type (gchar *name, GType parent);
|
||||
|
||||
void gtksharp_override_virtual_method (GType g_type, const gchar *name, GCallback callback);
|
||||
|
@ -56,18 +52,6 @@ gtksharp_get_type_id (GObject *obj)
|
|||
return G_TYPE_FROM_INSTANCE (obj);
|
||||
}
|
||||
|
||||
GType
|
||||
gtksharp_get_parent_type (GType typ)
|
||||
{
|
||||
return g_type_parent (typ);
|
||||
}
|
||||
|
||||
G_CONST_RETURN gchar *
|
||||
gtksharp_get_type_name_for_id (GType typ)
|
||||
{
|
||||
return g_type_name (typ);
|
||||
}
|
||||
|
||||
GType
|
||||
gtksharp_register_type (gchar *name, GType parent)
|
||||
{
|
||||
|
|
|
@ -25,7 +25,6 @@
|
|||
void gtksharp_value_create_from_property (GValue *value, GObject *obj, const gchar* name);
|
||||
void gtksharp_value_create_from_type_and_property (GValue *value, GType gtype, const gchar* name);
|
||||
void gtksharp_value_create_from_type_name (GValue *value, const gchar *type_name);
|
||||
GType gtksharp_value_get_value_type (GValue *value);
|
||||
gpointer glibsharp_value_get_boxed (GValue *value);
|
||||
void glibsharp_value_set_boxed (GValue *value, gpointer boxed);
|
||||
gboolean glibsharp_value_holds_flags (GValue *value);
|
||||
|
@ -51,14 +50,6 @@ gtksharp_value_create_from_type_name (GValue *value, const gchar *type_name)
|
|||
g_value_init (value, g_type_from_name (type_name));
|
||||
}
|
||||
|
||||
GType
|
||||
gtksharp_value_get_value_type (GValue *value)
|
||||
{
|
||||
g_return_val_if_fail (value != NULL, G_TYPE_INVALID);
|
||||
g_return_val_if_fail (G_IS_VALUE (value), G_TYPE_INVALID);
|
||||
return G_VALUE_TYPE (value);
|
||||
}
|
||||
|
||||
gpointer
|
||||
glibsharp_value_get_boxed (GValue *value)
|
||||
{
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
SUBDIRS = gconf rsvg test GtkDemo pixmaps gnomevfs
|
||||
SUBDIRS = gconf rsvg test GtkDemo pixmaps gnomevfs valtest
|
||||
|
||||
if ENABLE_GNOME
|
||||
GNOME_TARGETS=gnome-hello-world.exe canvas-example.exe fifteen.exe print.exe
|
||||
|
|
30
sample/valtest/Makefile.am
Normal file
30
sample/valtest/Makefile.am
Normal file
|
@ -0,0 +1,30 @@
|
|||
noinst_SCRIPTS = valtest.exe
|
||||
lib_LTLIBRARIES = libvalobj.la
|
||||
|
||||
assemblies=../../glib/glib-sharp.dll ../../pango/pango-sharp.dll ../../atk/atk-sharp.dll ../../gdk/gdk-sharp.dll ../../gtk/gtk-sharp.dll
|
||||
references=$(addprefix /r:, $(assemblies))
|
||||
|
||||
valtest.exe: Valtest.cs Valobj.cs $(assemblies)
|
||||
$(CSC) /out:valtest.exe $(references) $(srcdir)/Valtest.cs Valobj.cs
|
||||
|
||||
libvalobj_la_SOURCES = \
|
||||
valobj.c \
|
||||
valobj.h
|
||||
|
||||
libvalobj_la_LDFLAGS = -module -avoid-version -no-undefined
|
||||
|
||||
libvalobj_la_LIBADD = $(GTK_LIBS)
|
||||
|
||||
INCLUDES = $(GTK_CFLAGS)
|
||||
|
||||
Valobj.cs: valobj-api.xml
|
||||
$(RUNTIME) ../../generator/gapi_codegen.exe --generate valobj-api.xml --include ../../gtk/gtk-api.xml ../../gdk/gdk-api.xml --outdir=. --assembly-name=valobj-sharp
|
||||
|
||||
valobj-api.xml: valobj.c valobj.h valobj-sources.xml ../../parser/gapi-parser.exe
|
||||
PATH=../../parser:$PATH $(RUNTIME) ../../parser/gapi-parser.exe valobj-sources.xml
|
||||
|
||||
install:
|
||||
|
||||
CLEANFILES = \
|
||||
valobj-api.xml \
|
||||
Valobj.cs
|
349
sample/valtest/Valtest.cs
Normal file
349
sample/valtest/Valtest.cs
Normal file
|
@ -0,0 +1,349 @@
|
|||
// Valtest.cs: GLib.Value regression test
|
||||
//
|
||||
// Copyright (c) 2005 Novell, Inc.
|
||||
|
||||
using Gtksharp;
|
||||
using System;
|
||||
|
||||
public class Valtest {
|
||||
|
||||
static int errors = 0;
|
||||
|
||||
const bool BOOL_VAL = true;
|
||||
const int INT_VAL = -73523;
|
||||
const uint UINT_VAL = 99999U;
|
||||
const long INT64_VAL = -5000000000;
|
||||
const ulong UINT64_VAL = 5000000000U;
|
||||
const char UNICHAR_VAL = '\x20AC'; // euro
|
||||
const Gtk.ArrowType ENUM_VAL = Gtk.ArrowType.Left;
|
||||
const Gtk.AttachOptions FLAGS_VAL = Gtk.AttachOptions.Expand | Gtk.AttachOptions.Fill;
|
||||
const float FLOAT_VAL = 1.5f;
|
||||
const double DOUBLE_VAL = Math.PI;
|
||||
const string STRING_VAL = "This is a test";
|
||||
static Gdk.Rectangle BOXED_VAL;
|
||||
static IntPtr POINTER_VAL;
|
||||
static Gtk.Widget OBJECT_VAL;
|
||||
|
||||
public static int Main ()
|
||||
{
|
||||
Gtk.Application.Init ();
|
||||
|
||||
BOXED_VAL = new Gdk.Rectangle (1, 2, 3, 4);
|
||||
POINTER_VAL = (IntPtr) System.Runtime.InteropServices.GCHandle.Alloc ("foo");
|
||||
OBJECT_VAL = new Gtk.DrawingArea ();
|
||||
|
||||
// Part 1: Make sure values of all types round-trip correctly within Gtk#
|
||||
GLib.Value val;
|
||||
|
||||
try {
|
||||
val = new GLib.Value (BOOL_VAL);
|
||||
if ((bool)val != BOOL_VAL)
|
||||
CVError ("boolean cast", BOOL_VAL, (bool)val, val.Val);
|
||||
if ((bool)val.Val != BOOL_VAL)
|
||||
CVError ("boolean Val", BOOL_VAL, (bool)val, val.Val);
|
||||
} catch (Exception e) {
|
||||
ExceptionError ("boolean", e);
|
||||
}
|
||||
|
||||
try {
|
||||
val = new GLib.Value (INT_VAL);
|
||||
if ((int)val != INT_VAL)
|
||||
CVError ("int cast", INT_VAL, (int)val, val.Val);
|
||||
if ((int)val.Val != INT_VAL)
|
||||
CVError ("int Val", INT_VAL, (int)val, val.Val);
|
||||
} catch (Exception e) {
|
||||
ExceptionError ("int", e);
|
||||
}
|
||||
|
||||
try {
|
||||
val = new GLib.Value (UINT_VAL);
|
||||
if ((uint)val != UINT_VAL)
|
||||
CVError ("uint cast", UINT_VAL, (uint)val, val.Val);
|
||||
if ((uint)val.Val != UINT_VAL)
|
||||
CVError ("uint Val", UINT_VAL, (uint)val, val.Val);
|
||||
} catch (Exception e) {
|
||||
ExceptionError ("uint", e);
|
||||
}
|
||||
|
||||
try {
|
||||
val = new GLib.Value (INT64_VAL);
|
||||
if ((long)val != INT64_VAL)
|
||||
CVError ("int64 cast", INT64_VAL, (long)val, val.Val);
|
||||
if ((long)val.Val != INT64_VAL)
|
||||
CVError ("int64 Val", INT64_VAL, (long)val, val.Val);
|
||||
} catch (Exception e) {
|
||||
ExceptionError ("int64", e);
|
||||
}
|
||||
|
||||
try {
|
||||
val = new GLib.Value (UINT64_VAL);
|
||||
if ((ulong)val != UINT64_VAL)
|
||||
CVError ("uint64 cast", UINT64_VAL, (ulong)val, val.Val);
|
||||
if ((ulong)val.Val != UINT64_VAL)
|
||||
CVError ("uint64 Val", UINT64_VAL, (ulong)val, val.Val);
|
||||
} catch (Exception e) {
|
||||
ExceptionError ("uint64", e);
|
||||
}
|
||||
|
||||
// gunichar doesn't have its own GValue type, it shares with guint
|
||||
|
||||
try {
|
||||
val = new GLib.Value (ENUM_VAL);
|
||||
if ((Gtk.ArrowType)val != ENUM_VAL)
|
||||
CVError ("enum cast", ENUM_VAL, (Gtk.ArrowType)val, val.Val);
|
||||
if ((Gtk.ArrowType)val.Val != ENUM_VAL)
|
||||
CVError ("enum Val", ENUM_VAL, (Gtk.ArrowType)val, val.Val);
|
||||
} catch (Exception e) {
|
||||
ExceptionError ("enum", e);
|
||||
}
|
||||
|
||||
try {
|
||||
val = new GLib.Value (FLAGS_VAL);
|
||||
if ((Gtk.AttachOptions)val != FLAGS_VAL)
|
||||
CVError ("flags cast", FLAGS_VAL, (Gtk.AttachOptions)val, val.Val);
|
||||
if ((Gtk.AttachOptions)val.Val != FLAGS_VAL)
|
||||
CVError ("flags Val", FLAGS_VAL, (Gtk.AttachOptions)val, val.Val);
|
||||
} catch (Exception e) {
|
||||
ExceptionError ("flags", e);
|
||||
}
|
||||
|
||||
try {
|
||||
val = new GLib.Value (FLOAT_VAL);
|
||||
if ((float)val != FLOAT_VAL)
|
||||
CVError ("float cast", FLOAT_VAL, (float)val, val.Val);
|
||||
if ((float)val.Val != FLOAT_VAL)
|
||||
CVError ("float Val", FLOAT_VAL, (float)val, val.Val);
|
||||
} catch (Exception e) {
|
||||
ExceptionError ("float", e);
|
||||
}
|
||||
|
||||
try {
|
||||
val = new GLib.Value (DOUBLE_VAL);
|
||||
if ((double)val != DOUBLE_VAL)
|
||||
CVError ("double cast", DOUBLE_VAL, (double)val, val.Val);
|
||||
if ((double)val.Val != DOUBLE_VAL)
|
||||
CVError ("double Val", DOUBLE_VAL, (double)val, val.Val);
|
||||
} catch (Exception e) {
|
||||
ExceptionError ("double", e);
|
||||
}
|
||||
|
||||
try {
|
||||
val = new GLib.Value (STRING_VAL);
|
||||
if ((string)val != STRING_VAL)
|
||||
CVError ("string cast", STRING_VAL, (string)val, val.Val);
|
||||
if ((string)val.Val != STRING_VAL)
|
||||
CVError ("string Val", STRING_VAL, (string)val, val.Val);
|
||||
} catch (Exception e) {
|
||||
ExceptionError ("string", e);
|
||||
}
|
||||
|
||||
try {
|
||||
val = new GLib.Value (BOXED_VAL);
|
||||
if ((Gdk.Rectangle)val != BOXED_VAL)
|
||||
CVError ("boxed cast", BOXED_VAL, (Gdk.Rectangle)val, val.Val);
|
||||
// Can't currently use .Val on boxed types
|
||||
} catch (Exception e) {
|
||||
ExceptionError ("boxed", e);
|
||||
}
|
||||
|
||||
try {
|
||||
val = new GLib.Value (POINTER_VAL);
|
||||
if ((IntPtr)val != POINTER_VAL)
|
||||
CVError ("pointer cast", POINTER_VAL, (IntPtr)val, val.Val);
|
||||
if ((IntPtr)val.Val != POINTER_VAL)
|
||||
CVError ("pointer Val", POINTER_VAL, (IntPtr)val, val.Val);
|
||||
} catch (Exception e) {
|
||||
ExceptionError ("pointer", e);
|
||||
}
|
||||
|
||||
try {
|
||||
val = new GLib.Value (OBJECT_VAL);
|
||||
if ((Gtk.DrawingArea)val != OBJECT_VAL)
|
||||
CVError ("object cast", OBJECT_VAL, (Gtk.DrawingArea)val, val.Val);
|
||||
if ((Gtk.DrawingArea)val.Val != OBJECT_VAL)
|
||||
CVError ("object Val", OBJECT_VAL, (Gtk.DrawingArea)val, val.Val);
|
||||
} catch (Exception e) {
|
||||
ExceptionError ("object", e);
|
||||
}
|
||||
|
||||
// Test ManagedValue
|
||||
|
||||
Structtest st = new Structtest (5, "foo");
|
||||
try {
|
||||
val = new GLib.Value (st);
|
||||
// No direct GLib.Value -> ManagedValue cast
|
||||
Structtest st2 = (Structtest)val.Val;
|
||||
if (st.Int != st2.Int || st.String != st2.String)
|
||||
CVError ("ManagedValue Val", st, (Gtk.DrawingArea)val, val.Val);
|
||||
} catch (Exception e) {
|
||||
ExceptionError ("ManagedValue", e);
|
||||
}
|
||||
|
||||
// Part 2: method->unmanaged->property round trip
|
||||
Valobj vo;
|
||||
vo = new Valobj ();
|
||||
|
||||
vo.Boolean = BOOL_VAL;
|
||||
if (vo.BooleanProp != BOOL_VAL)
|
||||
MPError ("boolean method->prop", BOOL_VAL, vo.Boolean, vo.BooleanProp);
|
||||
|
||||
vo.Int = INT_VAL;
|
||||
if (vo.IntProp != INT_VAL)
|
||||
MPError ("int method->prop", INT_VAL, vo.Int, vo.IntProp);
|
||||
|
||||
vo.Uint = UINT_VAL;
|
||||
if (vo.UintProp != UINT_VAL)
|
||||
MPError ("uint method->prop", UINT_VAL, vo.Uint, vo.UintProp);
|
||||
|
||||
vo.Int64 = INT64_VAL;
|
||||
if (vo.Int64Prop != INT64_VAL)
|
||||
MPError ("int64 method->prop", INT64_VAL, vo.Int64, vo.Int64Prop);
|
||||
|
||||
vo.Uint64 = UINT64_VAL;
|
||||
if (vo.Uint64Prop != UINT64_VAL)
|
||||
MPError ("uint64 method->prop", UINT64_VAL, vo.Uint64, vo.Uint64Prop);
|
||||
|
||||
vo.Unichar = UNICHAR_VAL;
|
||||
if (vo.UnicharProp != UNICHAR_VAL)
|
||||
MPError ("unichar method->prop", UNICHAR_VAL, vo.Unichar, vo.UnicharProp);
|
||||
|
||||
vo.Enum = ENUM_VAL;
|
||||
if (vo.EnumProp != ENUM_VAL)
|
||||
MPError ("enum method->prop", ENUM_VAL, vo.Enum, vo.EnumProp);
|
||||
|
||||
vo.Flags = FLAGS_VAL;
|
||||
if (vo.FlagsProp != (FLAGS_VAL))
|
||||
MPError ("flags method->prop", FLAGS_VAL, vo.Flags, vo.FlagsProp);
|
||||
|
||||
vo.Float = FLOAT_VAL;
|
||||
if (vo.FloatProp != FLOAT_VAL)
|
||||
MPError ("float method->prop", FLOAT_VAL, vo.Float, vo.FloatProp);
|
||||
|
||||
vo.Double = DOUBLE_VAL;
|
||||
if (vo.DoubleProp != DOUBLE_VAL)
|
||||
MPError ("double method->prop", DOUBLE_VAL, vo.Double, vo.DoubleProp);
|
||||
|
||||
vo.String = STRING_VAL;
|
||||
if (vo.StringProp != STRING_VAL)
|
||||
MPError ("string method->prop", STRING_VAL, vo.String, vo.StringProp);
|
||||
|
||||
vo.Boxed = BOXED_VAL;
|
||||
if (vo.BoxedProp != BOXED_VAL)
|
||||
MPError ("boxed method->prop", BOXED_VAL, vo.Boxed, vo.BoxedProp);
|
||||
|
||||
vo.Pointer = POINTER_VAL;
|
||||
if (vo.PointerProp != POINTER_VAL)
|
||||
MPError ("pointer method->prop", POINTER_VAL, vo.Pointer, vo.PointerProp);
|
||||
|
||||
vo.Object = OBJECT_VAL;
|
||||
if (vo.ObjectProp != OBJECT_VAL) {
|
||||
MPError ("object method->prop", OBJECT_VAL.GetType().Name + " " + OBJECT_VAL.GetHashCode (),
|
||||
vo.Object == null ? "null" : vo.Object.GetType().Name + " " + vo.Object.GetHashCode (),
|
||||
vo.ObjectProp == null ? "null" : vo.ObjectProp.GetType().Name + " " + vo.ObjectProp.GetHashCode ());
|
||||
}
|
||||
|
||||
|
||||
// Part 3: property->unmanaged->method round trip
|
||||
vo = new Valobj ();
|
||||
|
||||
vo.BooleanProp = BOOL_VAL;
|
||||
if (vo.Boolean != BOOL_VAL)
|
||||
MPError ("boolean prop->method", BOOL_VAL, vo.Boolean, vo.BooleanProp);
|
||||
|
||||
vo.IntProp = INT_VAL;
|
||||
if (vo.Int != INT_VAL)
|
||||
MPError ("int prop->method", INT_VAL, vo.Int, vo.IntProp);
|
||||
|
||||
vo.UintProp = UINT_VAL;
|
||||
if (vo.Uint != UINT_VAL)
|
||||
MPError ("uint prop->method", UINT_VAL, vo.Uint, vo.UintProp);
|
||||
|
||||
vo.Int64Prop = INT64_VAL;
|
||||
if (vo.Int64 != INT64_VAL)
|
||||
MPError ("int64 prop->method", INT64_VAL, vo.Int64, vo.Int64Prop);
|
||||
|
||||
vo.Uint64Prop = UINT64_VAL;
|
||||
if (vo.Uint64 != UINT64_VAL)
|
||||
MPError ("uint64 prop->method", UINT64_VAL, vo.Uint64, vo.Uint64Prop);
|
||||
|
||||
vo.UnicharProp = UNICHAR_VAL;
|
||||
if (vo.Unichar != UNICHAR_VAL)
|
||||
MPError ("unichar prop->method", UNICHAR_VAL, vo.Unichar, vo.UnicharProp);
|
||||
|
||||
vo.EnumProp = ENUM_VAL;
|
||||
if (vo.Enum != ENUM_VAL)
|
||||
MPError ("enum prop->method", ENUM_VAL, vo.Enum, vo.EnumProp);
|
||||
|
||||
vo.FlagsProp = FLAGS_VAL;
|
||||
if (vo.Flags != (FLAGS_VAL))
|
||||
MPError ("flags prop->method", FLAGS_VAL, vo.Flags, vo.FlagsProp);
|
||||
|
||||
vo.FloatProp = FLOAT_VAL;
|
||||
if (vo.Float != FLOAT_VAL)
|
||||
MPError ("float prop->method", FLOAT_VAL, vo.Float, vo.FloatProp);
|
||||
|
||||
vo.DoubleProp = DOUBLE_VAL;
|
||||
if (vo.Double != DOUBLE_VAL)
|
||||
MPError ("double prop->method", DOUBLE_VAL, vo.Double, vo.DoubleProp);
|
||||
|
||||
vo.StringProp = STRING_VAL;
|
||||
if (vo.String != STRING_VAL)
|
||||
MPError ("string prop->method", STRING_VAL, vo.String, vo.StringProp);
|
||||
|
||||
vo.BoxedProp = BOXED_VAL;
|
||||
if (vo.Boxed != BOXED_VAL)
|
||||
MPError ("boxed prop->method", BOXED_VAL, vo.Boxed, vo.BoxedProp);
|
||||
|
||||
vo.PointerProp = POINTER_VAL;
|
||||
if (vo.Pointer != POINTER_VAL)
|
||||
MPError ("pointer prop->method", POINTER_VAL, vo.Pointer, vo.PointerProp);
|
||||
|
||||
vo.ObjectProp = OBJECT_VAL;
|
||||
if (vo.Object != OBJECT_VAL) {
|
||||
MPError ("object prop->method", OBJECT_VAL.GetType().Name + " " + OBJECT_VAL.GetHashCode (),
|
||||
vo.Object == null ? "null" : vo.Object.GetType().Name + " " + vo.Object.GetHashCode (),
|
||||
vo.ObjectProp == null ? "null" : vo.ObjectProp.GetType().Name + " " + vo.ObjectProp.GetHashCode ());
|
||||
}
|
||||
|
||||
Console.WriteLine ("{0} errors", errors);
|
||||
|
||||
return errors;
|
||||
}
|
||||
|
||||
static void CVError (string test, object expected, object cast, object value)
|
||||
{
|
||||
Console.Error.WriteLine ("Failed test {0}. Expected '{1}', got '{2}' from cast, '{3}' from Value",
|
||||
test, expected, cast, value);
|
||||
errors++;
|
||||
}
|
||||
|
||||
static void ExceptionError (string test, Exception e)
|
||||
{
|
||||
Console.Error.WriteLine ("Exception in test {0}: {1}",
|
||||
test, e.Message);
|
||||
errors++;
|
||||
}
|
||||
|
||||
static void MPError (string test, object expected, object method, object prop)
|
||||
{
|
||||
Console.Error.WriteLine ("Failed test {0}. Expected '{1}', got '{2}' from method, '{3}' from prop",
|
||||
test, expected, method, prop);
|
||||
errors++;
|
||||
}
|
||||
}
|
||||
|
||||
public struct Structtest {
|
||||
public int Int;
|
||||
public string String;
|
||||
|
||||
public Structtest (int Int, string String)
|
||||
{
|
||||
this.Int = Int;
|
||||
this.String = String;
|
||||
}
|
||||
|
||||
public override string ToString ()
|
||||
{
|
||||
return Int.ToString () + "/" + String.ToString ();
|
||||
}
|
||||
}
|
9
sample/valtest/valobj-sources.xml
Normal file
9
sample/valtest/valobj-sources.xml
Normal file
|
@ -0,0 +1,9 @@
|
|||
<gapi-parser-input>
|
||||
<api filename="valobj-api.xml">
|
||||
<library name="libvalobj.dll">
|
||||
<namespace name="Gtksharp">
|
||||
<dir>.</dir>
|
||||
</namespace>
|
||||
</library>
|
||||
</api>
|
||||
</gapi-parser-input>
|
436
sample/valtest/valobj.c
Normal file
436
sample/valtest/valobj.c
Normal file
|
@ -0,0 +1,436 @@
|
|||
/* valobj.c: An object with properties of each possible type
|
||||
*
|
||||
* Copyright (c) 2005 Novell, Inc.
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#include "valobj.h"
|
||||
|
||||
G_DEFINE_TYPE (GtksharpValobj, gtksharp_valobj, G_TYPE_OBJECT)
|
||||
|
||||
/* We actually don't do properties of type PARAM, VALUE_ARRAY, or OVERRIDE */
|
||||
|
||||
enum {
|
||||
PROP_0,
|
||||
|
||||
PROP_BOOLEAN,
|
||||
PROP_INT,
|
||||
PROP_UINT,
|
||||
PROP_INT64,
|
||||
PROP_UINT64,
|
||||
PROP_UNICHAR,
|
||||
PROP_ENUM,
|
||||
PROP_FLAGS,
|
||||
PROP_FLOAT,
|
||||
PROP_DOUBLE,
|
||||
PROP_STRING,
|
||||
PROP_BOXED,
|
||||
PROP_POINTER,
|
||||
PROP_OBJECT,
|
||||
|
||||
LAST_PROP
|
||||
};
|
||||
|
||||
static void set_property (GObject *object, guint prop_id,
|
||||
const GValue *value, GParamSpec *pspec);
|
||||
static void get_property (GObject *object, guint prop_id,
|
||||
GValue *value, GParamSpec *pspec);
|
||||
|
||||
static void
|
||||
gtksharp_valobj_init (GtksharpValobj *sock)
|
||||
{
|
||||
}
|
||||
|
||||
static void
|
||||
gtksharp_valobj_class_init (GtksharpValobjClass *valobj_class)
|
||||
{
|
||||
GObjectClass *object_class = G_OBJECT_CLASS (valobj_class);
|
||||
|
||||
/* virtual method override */
|
||||
object_class->set_property = set_property;
|
||||
object_class->get_property = get_property;
|
||||
|
||||
/* properties */
|
||||
g_object_class_install_property (
|
||||
object_class, PROP_BOOLEAN,
|
||||
g_param_spec_boolean ("boolean_prop", "Boolean", "boolean property",
|
||||
FALSE,
|
||||
G_PARAM_READWRITE | G_PARAM_CONSTRUCT));
|
||||
|
||||
g_object_class_install_property (
|
||||
object_class, PROP_INT,
|
||||
g_param_spec_int ("int_prop", "Int", "int property",
|
||||
G_MININT, G_MAXINT, 0,
|
||||
G_PARAM_READWRITE | G_PARAM_CONSTRUCT));
|
||||
g_object_class_install_property (
|
||||
object_class, PROP_UINT,
|
||||
g_param_spec_uint ("uint_prop", "Unsigned Int", "uint property",
|
||||
0, G_MAXUINT, 0,
|
||||
G_PARAM_READWRITE | G_PARAM_CONSTRUCT));
|
||||
|
||||
g_object_class_install_property (
|
||||
object_class, PROP_INT64,
|
||||
g_param_spec_int64 ("int64_prop", "Int64", "int64 property",
|
||||
G_MININT64, G_MAXINT64, 0,
|
||||
G_PARAM_READWRITE | G_PARAM_CONSTRUCT));
|
||||
g_object_class_install_property (
|
||||
object_class, PROP_UINT64,
|
||||
g_param_spec_uint64 ("uint64_prop", "Unsigned Int64", "uint64 property",
|
||||
0, G_MAXUINT64, 0,
|
||||
G_PARAM_READWRITE | G_PARAM_CONSTRUCT));
|
||||
|
||||
g_object_class_install_property (
|
||||
object_class, PROP_UNICHAR,
|
||||
g_param_spec_unichar ("unichar_prop", "Unichar", "unichar property",
|
||||
(gunichar)' ',
|
||||
G_PARAM_READWRITE | G_PARAM_CONSTRUCT));
|
||||
|
||||
g_object_class_install_property (
|
||||
object_class, PROP_ENUM,
|
||||
g_param_spec_enum ("enum_prop", "Enum", "enum property",
|
||||
GTK_TYPE_ARROW_TYPE, GTK_ARROW_UP,
|
||||
G_PARAM_READWRITE | G_PARAM_CONSTRUCT));
|
||||
g_object_class_install_property (
|
||||
object_class, PROP_FLAGS,
|
||||
g_param_spec_flags ("flags_prop", "Flags", "flags property",
|
||||
GTK_TYPE_ATTACH_OPTIONS, 0,
|
||||
G_PARAM_READWRITE | G_PARAM_CONSTRUCT));
|
||||
|
||||
g_object_class_install_property (
|
||||
object_class, PROP_FLOAT,
|
||||
g_param_spec_float ("float_prop", "Float", "float property",
|
||||
-G_MAXFLOAT, G_MAXFLOAT, 0.0f,
|
||||
G_PARAM_READWRITE | G_PARAM_CONSTRUCT));
|
||||
g_object_class_install_property (
|
||||
object_class, PROP_DOUBLE,
|
||||
g_param_spec_double ("double_prop", "Double", "double property",
|
||||
-G_MAXDOUBLE, G_MAXDOUBLE, 0.0f,
|
||||
G_PARAM_READWRITE | G_PARAM_CONSTRUCT));
|
||||
|
||||
g_object_class_install_property (
|
||||
object_class, PROP_STRING,
|
||||
g_param_spec_string ("string_prop", "String", "string property",
|
||||
"foo",
|
||||
G_PARAM_READWRITE | G_PARAM_CONSTRUCT));
|
||||
|
||||
g_object_class_install_property (
|
||||
object_class, PROP_BOXED,
|
||||
g_param_spec_boxed ("boxed_prop", "Boxed", "boxed property",
|
||||
GDK_TYPE_RECTANGLE,
|
||||
G_PARAM_READWRITE));
|
||||
|
||||
g_object_class_install_property (
|
||||
object_class, PROP_POINTER,
|
||||
g_param_spec_pointer ("pointer_prop", "Pointer", "pointer property",
|
||||
G_PARAM_READWRITE));
|
||||
|
||||
g_object_class_install_property (
|
||||
object_class, PROP_OBJECT,
|
||||
g_param_spec_object ("object_prop", "Object", "object property",
|
||||
GTK_TYPE_WIDGET,
|
||||
G_PARAM_READWRITE));
|
||||
}
|
||||
|
||||
static void
|
||||
set_property (GObject *object, guint prop_id,
|
||||
const GValue *value, GParamSpec *pspec)
|
||||
{
|
||||
GtksharpValobj *valobj = GTKSHARP_VALOBJ (object);
|
||||
|
||||
switch (prop_id) {
|
||||
case PROP_BOOLEAN:
|
||||
valobj->the_boolean = g_value_get_boolean (value);
|
||||
break;
|
||||
case PROP_INT:
|
||||
valobj->the_int = g_value_get_int (value);
|
||||
break;
|
||||
case PROP_UINT:
|
||||
valobj->the_uint = g_value_get_uint (value);
|
||||
break;
|
||||
case PROP_INT64:
|
||||
valobj->the_int64 = g_value_get_int64 (value);
|
||||
break;
|
||||
case PROP_UINT64:
|
||||
valobj->the_uint64 = g_value_get_uint64 (value);
|
||||
break;
|
||||
case PROP_UNICHAR:
|
||||
valobj->the_unichar = (gunichar)g_value_get_uint (value);
|
||||
break;
|
||||
case PROP_ENUM:
|
||||
valobj->the_enum = g_value_get_enum (value);
|
||||
break;
|
||||
case PROP_FLAGS:
|
||||
valobj->the_flags = g_value_get_flags (value);
|
||||
break;
|
||||
case PROP_FLOAT:
|
||||
valobj->the_float = g_value_get_float (value);
|
||||
break;
|
||||
case PROP_DOUBLE:
|
||||
valobj->the_double = g_value_get_double (value);
|
||||
break;
|
||||
case PROP_STRING:
|
||||
if (valobj->the_string)
|
||||
g_free (valobj->the_string);
|
||||
valobj->the_string = g_value_dup_string (value);
|
||||
break;
|
||||
case PROP_BOXED:
|
||||
valobj->the_rect = *(GdkRectangle *)g_value_get_boxed (value);
|
||||
break;
|
||||
case PROP_POINTER:
|
||||
valobj->the_pointer = g_value_get_pointer (value);
|
||||
break;
|
||||
case PROP_OBJECT:
|
||||
if (valobj->the_object)
|
||||
g_object_unref (valobj->the_object);
|
||||
valobj->the_object = (GtkWidget *)g_value_dup_object (value);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
get_property (GObject *object, guint prop_id,
|
||||
GValue *value, GParamSpec *pspec)
|
||||
{
|
||||
GtksharpValobj *valobj = GTKSHARP_VALOBJ (object);
|
||||
|
||||
switch (prop_id) {
|
||||
case PROP_BOOLEAN:
|
||||
g_value_set_boolean (value, valobj->the_boolean);
|
||||
break;
|
||||
case PROP_INT:
|
||||
g_value_set_int (value, valobj->the_int);
|
||||
break;
|
||||
case PROP_UINT:
|
||||
g_value_set_uint (value, valobj->the_uint);
|
||||
break;
|
||||
case PROP_INT64:
|
||||
g_value_set_int64 (value, valobj->the_int64);
|
||||
break;
|
||||
case PROP_UINT64:
|
||||
g_value_set_uint64 (value, valobj->the_uint64);
|
||||
break;
|
||||
case PROP_UNICHAR:
|
||||
g_value_set_uint (value, (guint)valobj->the_unichar);
|
||||
break;
|
||||
case PROP_ENUM:
|
||||
g_value_set_enum (value, valobj->the_enum);
|
||||
break;
|
||||
case PROP_FLAGS:
|
||||
g_value_set_flags (value, valobj->the_flags);
|
||||
break;
|
||||
case PROP_FLOAT:
|
||||
g_value_set_float (value, valobj->the_float);
|
||||
break;
|
||||
case PROP_DOUBLE:
|
||||
g_value_set_double (value, valobj->the_double);
|
||||
break;
|
||||
case PROP_STRING:
|
||||
g_value_set_string (value, valobj->the_string);
|
||||
break;
|
||||
case PROP_BOXED:
|
||||
g_value_set_boxed (value, &valobj->the_rect);
|
||||
break;
|
||||
case PROP_POINTER:
|
||||
g_value_set_pointer (value, valobj->the_pointer);
|
||||
break;
|
||||
case PROP_OBJECT:
|
||||
g_value_set_object (value, valobj->the_object);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
GtksharpValobj *
|
||||
gtksharp_valobj_new (void)
|
||||
{
|
||||
return g_object_new (GTKSHARP_TYPE_VALOBJ, NULL);
|
||||
}
|
||||
|
||||
|
||||
gboolean
|
||||
gtksharp_valobj_get_boolean (GtksharpValobj *valobj)
|
||||
{
|
||||
return valobj->the_boolean;
|
||||
}
|
||||
|
||||
void
|
||||
gtksharp_valobj_set_boolean (GtksharpValobj *valobj, gboolean val)
|
||||
{
|
||||
valobj->the_boolean = val;
|
||||
}
|
||||
|
||||
int
|
||||
gtksharp_valobj_get_int (GtksharpValobj *valobj)
|
||||
{
|
||||
return valobj->the_int;
|
||||
}
|
||||
|
||||
void
|
||||
gtksharp_valobj_set_int (GtksharpValobj *valobj, int val)
|
||||
{
|
||||
valobj->the_int = val;
|
||||
}
|
||||
|
||||
guint
|
||||
gtksharp_valobj_get_uint (GtksharpValobj *valobj)
|
||||
{
|
||||
return valobj->the_uint;
|
||||
}
|
||||
|
||||
void
|
||||
gtksharp_valobj_set_uint (GtksharpValobj *valobj, guint val)
|
||||
{
|
||||
valobj->the_uint = val;
|
||||
}
|
||||
|
||||
gint64
|
||||
gtksharp_valobj_get_int64 (GtksharpValobj *valobj)
|
||||
{
|
||||
return valobj->the_int64;
|
||||
}
|
||||
|
||||
void
|
||||
gtksharp_valobj_set_int64 (GtksharpValobj *valobj, gint64 val)
|
||||
{
|
||||
valobj->the_int64 = val;
|
||||
}
|
||||
|
||||
guint64
|
||||
gtksharp_valobj_get_uint64 (GtksharpValobj *valobj)
|
||||
{
|
||||
return valobj->the_uint64;
|
||||
}
|
||||
|
||||
void
|
||||
gtksharp_valobj_set_uint64 (GtksharpValobj *valobj, guint64 val)
|
||||
{
|
||||
valobj->the_uint64 = val;
|
||||
}
|
||||
|
||||
gunichar
|
||||
gtksharp_valobj_get_unichar (GtksharpValobj *valobj)
|
||||
{
|
||||
return valobj->the_unichar;
|
||||
}
|
||||
|
||||
void
|
||||
gtksharp_valobj_set_unichar (GtksharpValobj *valobj, gunichar val)
|
||||
{
|
||||
valobj->the_unichar = val;
|
||||
}
|
||||
|
||||
GtkArrowType
|
||||
gtksharp_valobj_get_enum (GtksharpValobj *valobj)
|
||||
{
|
||||
return valobj->the_enum;
|
||||
}
|
||||
|
||||
void
|
||||
gtksharp_valobj_set_enum (GtksharpValobj *valobj, GtkArrowType val)
|
||||
{
|
||||
valobj->the_enum = val;
|
||||
}
|
||||
|
||||
GtkAttachOptions
|
||||
gtksharp_valobj_get_flags (GtksharpValobj *valobj)
|
||||
{
|
||||
return valobj->the_flags;
|
||||
}
|
||||
|
||||
void
|
||||
gtksharp_valobj_set_flags (GtksharpValobj *valobj, GtkAttachOptions val)
|
||||
{
|
||||
valobj->the_flags = val;
|
||||
}
|
||||
|
||||
float
|
||||
gtksharp_valobj_get_float (GtksharpValobj *valobj)
|
||||
{
|
||||
return valobj->the_float;
|
||||
}
|
||||
|
||||
void
|
||||
gtksharp_valobj_set_float (GtksharpValobj *valobj, float val)
|
||||
{
|
||||
valobj->the_float = val;
|
||||
}
|
||||
|
||||
double
|
||||
gtksharp_valobj_get_double (GtksharpValobj *valobj)
|
||||
{
|
||||
return valobj->the_double;
|
||||
}
|
||||
|
||||
void
|
||||
gtksharp_valobj_set_double (GtksharpValobj *valobj, double val)
|
||||
{
|
||||
valobj->the_double = val;
|
||||
}
|
||||
|
||||
char *
|
||||
gtksharp_valobj_get_string (GtksharpValobj *valobj)
|
||||
{
|
||||
return valobj->the_string;
|
||||
}
|
||||
|
||||
void
|
||||
gtksharp_valobj_set_string (GtksharpValobj *valobj, const char *val)
|
||||
{
|
||||
if (valobj->the_string)
|
||||
g_free (valobj->the_string);
|
||||
valobj->the_string = g_strdup (val);
|
||||
}
|
||||
|
||||
GdkRectangle *
|
||||
gtksharp_valobj_get_boxed (GtksharpValobj *valobj)
|
||||
{
|
||||
return &valobj->the_rect;
|
||||
}
|
||||
|
||||
void
|
||||
gtksharp_valobj_set_boxed (GtksharpValobj *valobj, GdkRectangle *val)
|
||||
{
|
||||
valobj->the_rect = *val;
|
||||
}
|
||||
|
||||
gpointer
|
||||
gtksharp_valobj_get_pointer (GtksharpValobj *valobj)
|
||||
{
|
||||
return valobj->the_pointer;
|
||||
}
|
||||
|
||||
void
|
||||
gtksharp_valobj_set_pointer (GtksharpValobj *valobj, gpointer val)
|
||||
{
|
||||
valobj->the_pointer = val;
|
||||
}
|
||||
|
||||
GtkWidget *
|
||||
gtksharp_valobj_get_object (GtksharpValobj *valobj)
|
||||
{
|
||||
return valobj->the_object;
|
||||
}
|
||||
|
||||
void
|
||||
gtksharp_valobj_set_object (GtksharpValobj *valobj, GtkWidget *val)
|
||||
{
|
||||
if (valobj->the_object)
|
||||
g_object_unref (valobj->the_object);
|
||||
valobj->the_object = g_object_ref (val);
|
||||
}
|
91
sample/valtest/valobj.h
Normal file
91
sample/valtest/valobj.h
Normal file
|
@ -0,0 +1,91 @@
|
|||
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
|
||||
/*
|
||||
* Copyright (C) 2000-2003, Ximian, Inc.
|
||||
*/
|
||||
|
||||
#ifndef GTKSHARP_VALOBJ_H
|
||||
#define GTKSHARP_VALOBJ_H 1
|
||||
|
||||
#include <gtk/gtkwidget.h>
|
||||
#include <gtk/gtkenums.h>
|
||||
|
||||
#define GTKSHARP_TYPE_VALOBJ (gtksharp_valobj_get_type ())
|
||||
#define GTKSHARP_VALOBJ(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTKSHARP_TYPE_VALOBJ, GtksharpValobj))
|
||||
#define GTKSHARP_VALOBJ_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GTKSHARP_TYPE_VALOBJ, GtksharpValobjClass))
|
||||
#define GTKSHARP_IS_VALOBJ(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GTKSHARP_TYPE_VALOBJ))
|
||||
#define GTKSHARP_IS_VALOBJ_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((obj), GTKSHARP_TYPE_VALOBJ))
|
||||
#define GTKSHARP_VALOBJ_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GTKSHARP_TYPE_VALOBJ, GtksharpValobjClass))
|
||||
|
||||
typedef struct {
|
||||
GObject parent;
|
||||
|
||||
/*< private >*/
|
||||
gboolean the_boolean;
|
||||
int the_int;
|
||||
guint the_uint;
|
||||
gint64 the_int64;
|
||||
guint64 the_uint64;
|
||||
gunichar the_unichar;
|
||||
GtkArrowType the_enum;
|
||||
GtkAttachOptions the_flags;
|
||||
float the_float;
|
||||
double the_double;
|
||||
char *the_string;
|
||||
GdkRectangle the_rect;
|
||||
gpointer the_pointer;
|
||||
GtkWidget *the_object;
|
||||
} GtksharpValobj;
|
||||
|
||||
typedef struct {
|
||||
GObjectClass parent_class;
|
||||
|
||||
} GtksharpValobjClass;
|
||||
|
||||
GType gtksharp_valobj_get_type (void);
|
||||
|
||||
GtksharpValobj *gtksharp_valobj_new (void);
|
||||
|
||||
gboolean gtksharp_valobj_get_boolean (GtksharpValobj *valobj);
|
||||
void gtksharp_valobj_set_boolean (GtksharpValobj *valobj,
|
||||
gboolean val);
|
||||
int gtksharp_valobj_get_int (GtksharpValobj *valobj);
|
||||
void gtksharp_valobj_set_int (GtksharpValobj *valobj,
|
||||
int val);
|
||||
guint gtksharp_valobj_get_uint (GtksharpValobj *valobj);
|
||||
void gtksharp_valobj_set_uint (GtksharpValobj *valobj,
|
||||
guint val);
|
||||
gint64 gtksharp_valobj_get_int64 (GtksharpValobj *valobj);
|
||||
void gtksharp_valobj_set_int64 (GtksharpValobj *valobj,
|
||||
gint64 val);
|
||||
guint64 gtksharp_valobj_get_uint64 (GtksharpValobj *valobj);
|
||||
void gtksharp_valobj_set_uint64 (GtksharpValobj *valobj,
|
||||
guint64 val);
|
||||
gunichar gtksharp_valobj_get_unichar (GtksharpValobj *valobj);
|
||||
void gtksharp_valobj_set_unichar (GtksharpValobj *valobj,
|
||||
gunichar val);
|
||||
GtkArrowType gtksharp_valobj_get_enum (GtksharpValobj *valobj);
|
||||
void gtksharp_valobj_set_enum (GtksharpValobj *valobj,
|
||||
GtkArrowType val);
|
||||
GtkAttachOptions gtksharp_valobj_get_flags (GtksharpValobj *valobj);
|
||||
void gtksharp_valobj_set_flags (GtksharpValobj *valobj,
|
||||
GtkAttachOptions val);
|
||||
float gtksharp_valobj_get_float (GtksharpValobj *valobj);
|
||||
void gtksharp_valobj_set_float (GtksharpValobj *valobj,
|
||||
float val);
|
||||
double gtksharp_valobj_get_double (GtksharpValobj *valobj);
|
||||
void gtksharp_valobj_set_double (GtksharpValobj *valobj,
|
||||
double val);
|
||||
char *gtksharp_valobj_get_string (GtksharpValobj *valobj);
|
||||
void gtksharp_valobj_set_string (GtksharpValobj *valobj,
|
||||
const char *val);
|
||||
GdkRectangle *gtksharp_valobj_get_boxed (GtksharpValobj *valobj);
|
||||
void gtksharp_valobj_set_boxed (GtksharpValobj *valobj,
|
||||
GdkRectangle *val);
|
||||
gpointer gtksharp_valobj_get_pointer (GtksharpValobj *valobj);
|
||||
void gtksharp_valobj_set_pointer (GtksharpValobj *valobj,
|
||||
gpointer val);
|
||||
GtkWidget *gtksharp_valobj_get_object (GtksharpValobj *valobj);
|
||||
void gtksharp_valobj_set_object (GtksharpValobj *valobj,
|
||||
GtkWidget *val);
|
||||
|
||||
#endif /* GTKSHARP_VALOBJ_H */
|
3
sample/valtest/valtest.exe.config.in
Normal file
3
sample/valtest/valtest.exe.config.in
Normal file
|
@ -0,0 +1,3 @@
|
|||
<configuration>
|
||||
<dllmap dll="libvalobj.dll" target=".libs/libvalobj@LIB_PREFIX@@LIB_SUFFIX@"/>
|
||||
</configuration>
|
Loading…
Reference in a new issue