2008-12-19 Mike Kestner <mkestner@novell.com>

* generator/BoxedGen.cs: don't generate glue dependencies.
	* glib/*.cs: remove glibsharpglue usage except thread.c.
	* glib/glue/*.c: kill all but thread.c. need glib 2.20 to kill
	it eventually.
	* pango/Attr*.cs: kill glue usage.
	* pango/glue/*.c: kill all but generated.c. it's next.
	* gtk/TreeIter.custom: kill a dumb glibsharpglue usage.

svn path=/trunk/gtk-sharp/; revision=121880
This commit is contained in:
Mike Kestner 2008-12-19 18:57:42 +00:00
parent 8cf702ea12
commit 89afb3f49f
61 changed files with 1188 additions and 1197 deletions

View file

@ -1,3 +1,13 @@
2008-12-19 Mike Kestner <mkestner@novell.com>
* generator/BoxedGen.cs: don't generate glue dependencies.
* glib/*.cs: remove glibsharpglue usage except thread.c.
* glib/glue/*.c: kill all but thread.c. need glib 2.20 to kill
it eventually.
* pango/Attr*.cs: kill glue usage.
* pango/glue/*.c: kill all but generated.c. it's next.
* gtk/TreeIter.custom: kill a dumb glibsharpglue usage.
2008-12-12 Mike Kestner <mkestner@novell.com> 2008-12-12 Mike Kestner <mkestner@novell.com>
* bootstrap-2.12: tagged for 2.12.7. Bump svn version. * bootstrap-2.12: tagged for 2.12.7. Bump svn version.
@ -12,7 +22,7 @@
* generator/Ctor.cs: * generator/Ctor.cs:
* generator/Method.cs: * generator/Method.cs:
* generator/MethodBase.cs: refactor the Protection from Method to * generator/MethodBase.cs: refactor the Protection from Method to
MethodBase, generate ctors with the correct proteciton too. MethodBase, generate ctors with the correct protection too.
2008-12-01 Mike Kestner <mkestner@novell.com> 2008-12-01 Mike Kestner <mkestner@novell.com>

View file

@ -39,26 +39,19 @@ namespace GtkSharp.Generation {
StreamWriter sw = gen_info.Writer = gen_info.OpenStream (Name); StreamWriter sw = gen_info.Writer = gen_info.OpenStream (Name);
base.Generate (gen_info); base.Generate (gen_info);
sw.WriteLine ("\t\t[DllImport(\"glibsharpglue-2\")]");
sw.WriteLine ("\t\tstatic extern IntPtr glibsharp_value_get_boxed (ref GLib.Value val);");
sw.WriteLine ();
sw.WriteLine ("\t\t[DllImport(\"glibsharpglue-2\")]");
sw.WriteLine ("\t\tstatic extern void glibsharp_value_set_boxed (ref GLib.Value val, ref " + QualifiedName + " boxed);");
sw.WriteLine ();
sw.WriteLine ("\t\tpublic static explicit operator GLib.Value (" + QualifiedName + " boxed)"); sw.WriteLine ("\t\tpublic static explicit operator GLib.Value (" + QualifiedName + " boxed)");
sw.WriteLine ("\t\t{"); sw.WriteLine ("\t\t{");
sw.WriteLine ("\t\t\tGLib.Value val = GLib.Value.Empty;"); sw.WriteLine ("\t\t\tGLib.Value val = GLib.Value.Empty;");
sw.WriteLine ("\t\t\tval.Init (" + QualifiedName + ".GType);"); sw.WriteLine ("\t\t\tval.Init (" + QualifiedName + ".GType);");
sw.WriteLine ("\t\t\tglibsharp_value_set_boxed (ref val, ref boxed);"); sw.WriteLine ("\t\t\tval.Val = boxed;");
sw.WriteLine ("\t\t\treturn val;"); sw.WriteLine ("\t\t\treturn val;");
sw.WriteLine ("\t\t}"); sw.WriteLine ("\t\t}");
sw.WriteLine (); sw.WriteLine ();
sw.WriteLine ("\t\tpublic static explicit operator " + QualifiedName + " (GLib.Value val)"); sw.WriteLine ("\t\tpublic static explicit operator " + QualifiedName + " (GLib.Value val)");
sw.WriteLine ("\t\t{"); sw.WriteLine ("\t\t{");
sw.WriteLine ("\t\t\tIntPtr boxed_ptr = glibsharp_value_get_boxed (ref val);"); sw.WriteLine ("\t\t\treturn (" + QualifiedName + ") val.Val;");
sw.WriteLine ("\t\t\treturn New (boxed_ptr);");
sw.WriteLine ("\t\t}"); sw.WriteLine ("\t\t}");
if (copy != null && copy.IsDeprecated) { if (copy != null && copy.IsDeprecated) {

View file

@ -33,11 +33,16 @@ namespace GLib {
this.errptr = errptr; this.errptr = errptr;
} }
[DllImport("glibsharpglue-2")] struct GError {
static extern IntPtr gtksharp_error_get_message (IntPtr errptr); public int Domain;
public int Code;
public IntPtr Msg;
}
public override string Message { public override string Message {
get { get {
return Marshaller.Utf8PtrToString (gtksharp_error_get_message (errptr)); GError err = (GError) Marshal.PtrToStructure (errptr, typeof (GError));
return Marshaller.Utf8PtrToString (err.Msg);
} }
} }

View file

@ -27,12 +27,33 @@ namespace GLib {
using System.IO; using System.IO;
using System.Reflection; using System.Reflection;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using System.Text;
[StructLayout(LayoutKind.Sequential)] [StructLayout(LayoutKind.Sequential)]
public struct GType { public struct GType {
IntPtr val; IntPtr val;
struct GTypeInfo {
public ushort class_size;
IntPtr base_init;
IntPtr base_finalize;
IntPtr class_init;
IntPtr class_finalize;
IntPtr class_data;
public ushort instance_size;
ushort n_preallocs;
IntPtr instance_init;
IntPtr value_table;
}
struct GTypeQuery {
public IntPtr type;
public IntPtr type_name;
public uint class_size;
public uint instance_size;
}
public GType (IntPtr val) public GType (IntPtr val)
{ {
this.val = val; this.val = val;
@ -76,9 +97,6 @@ namespace GLib {
gtypes[type] = native_type; gtypes[type] = native_type;
} }
[DllImport("libgobject-2.0-0.dll")]
static extern void g_type_init ();
static GType () static GType ()
{ {
g_type_init (); g_type_init ();
@ -206,17 +224,7 @@ namespace GLib {
} }
public IntPtr Val { public IntPtr Val {
get { get { return val; }
return val;
}
}
public override bool Equals (object o)
{
if (!(o is GType))
return false;
return ((GType) o) == this;
} }
public static bool operator == (GType a, GType b) public static bool operator == (GType a, GType b)
@ -229,20 +237,122 @@ namespace GLib {
return a.Val != b.Val; return a.Val != b.Val;
} }
public override bool Equals (object o)
{
if (!(o is GType))
return false;
return ((GType) o) == this;
}
public override int GetHashCode () public override int GetHashCode ()
{ {
return val.GetHashCode (); return val.GetHashCode ();
} }
[DllImport("libgobject-2.0-0.dll")]
static extern IntPtr g_type_name (IntPtr raw);
[DllImport("libgobject-2.0-0.dll")]
static extern IntPtr g_type_from_name (string name);
public override string ToString () public override string ToString ()
{ {
return Marshaller.Utf8PtrToString (g_type_name (val)); return Marshaller.Utf8PtrToString (g_type_name (val));
} }
internal IntPtr ClassPtr {
get {
IntPtr klass = g_type_class_peek (val);
if (val == IntPtr.Zero)
klass = g_type_class_ref (val);
return klass;
}
}
internal void EnsureClass ()
{
if (g_type_class_peek (val) == IntPtr.Zero)
g_type_class_ref (val);
}
static int type_uid;
static string BuildEscapedName (System.Type t)
{
string qn = t.FullName;
// Just a random guess
StringBuilder sb = new StringBuilder (20 + qn.Length);
sb.Append ("__gtksharp_");
sb.Append (type_uid++);
sb.Append ("_");
foreach (char c in qn) {
if ((c >= '0' && c <= '9') || (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z'))
sb.Append (c);
else if (c == '.')
sb.Append ('_');
else if ((uint) c <= byte.MaxValue) {
sb.Append ('+');
sb.Append (((byte) c).ToString ("x2"));
} else {
sb.Append ('-');
sb.Append (((uint) c).ToString ("x4"));
}
}
return sb.ToString ();
}
internal static GType RegisterGObjectType (System.Type t)
{
GType parent_gtype = LookupGObjectType (t.BaseType);
string name = BuildEscapedName (t);
IntPtr native_name = GLib.Marshaller.StringToPtrGStrdup (name);
GTypeQuery query;
g_type_query (parent_gtype.Val, out query);
GTypeInfo info = new GTypeInfo ();
info.class_size = (ushort) query.class_size;
info.instance_size = (ushort) query.instance_size;
GType gtype = new GType (g_type_register_static (parent_gtype.Val, native_name, ref info, 0));
GLib.Marshaller.Free (native_name);
Register (gtype, t);
return gtype;
}
internal static GType LookupGObjectType (System.Type t)
{
if (gtypes.Contains (t))
return (GType) gtypes [t];
PropertyInfo pi = t.GetProperty ("GType", BindingFlags.DeclaredOnly | BindingFlags.Static | BindingFlags.Public);
if (pi != null)
return (GType) pi.GetValue (null, null);
return GLib.Object.RegisterGType (t);
}
internal static IntPtr ValFromInstancePtr (IntPtr handle)
{
if (handle == IntPtr.Zero)
return IntPtr.Zero;
// First field of instance is a GTypeClass*.
IntPtr klass = Marshal.ReadIntPtr (handle);
// First field of GTypeClass is a GType.
return Marshal.ReadIntPtr (klass);
}
[DllImport("libgobject-2.0-0.dll")]
static extern IntPtr g_type_class_peek (IntPtr gtype);
[DllImport("libgobject-2.0-0.dll")]
static extern IntPtr g_type_class_ref (IntPtr gtype);
[DllImport("libgobject-2.0-0.dll")]
static extern IntPtr g_type_from_name (string name);
[DllImport("libgobject-2.0-0.dll")]
static extern void g_type_init ();
[DllImport("libgobject-2.0-0.dll")]
static extern IntPtr g_type_name (IntPtr raw);
[DllImport("libgobject-2.0-0.dll")]
static extern void g_type_query (IntPtr type, out GTypeQuery query);
[DllImport("libgobject-2.0-0.dll")]
static extern IntPtr g_type_register_static (IntPtr parent, IntPtr name, ref GTypeInfo info, int flags);
} }
} }

View file

@ -34,22 +34,6 @@ namespace GLib {
return new List (g_list_copy (Handle)); return new List (g_list_copy (Handle));
} }
[DllImport("glibsharpglue-2")]
static extern IntPtr gtksharp_list_get_data (IntPtr l);
internal override IntPtr GetData (IntPtr current)
{
return gtksharp_list_get_data (current);
}
[DllImport("glibsharpglue-2")]
static extern IntPtr gtksharp_list_get_next (IntPtr l);
internal override IntPtr Next (IntPtr current)
{
return gtksharp_list_get_next (current);
}
[DllImport("libglib-2.0-0.dll")] [DllImport("libglib-2.0-0.dll")]
static extern int g_list_length (IntPtr l); static extern int g_list_length (IntPtr l);

View file

@ -35,8 +35,6 @@ namespace GLib {
protected System.Type element_type = null; protected System.Type element_type = null;
abstract internal IntPtr NthData (uint index); abstract internal IntPtr NthData (uint index);
abstract internal IntPtr GetData (IntPtr current);
abstract internal IntPtr Next (IntPtr current);
abstract internal int Length (IntPtr list); abstract internal int Length (IntPtr list);
abstract internal void Free (IntPtr list); abstract internal void Free (IntPtr list);
abstract internal IntPtr Append (IntPtr current, IntPtr raw); abstract internal IntPtr Append (IntPtr current, IntPtr raw);
@ -203,6 +201,18 @@ namespace GLib {
FreeList (); FreeList ();
} }
IntPtr GetData (IntPtr current)
{
// data field is at offset 0 for GList and GSList
return Marshal.ReadIntPtr (current);
}
IntPtr Next (IntPtr current)
{
// next field follows gpointer data field for GList and GSList
return Marshal.ReadIntPtr (current, IntPtr.Size);
}
private class ListEnumerator : IEnumerator private class ListEnumerator : IEnumerator
{ {
private IntPtr current = IntPtr.Zero; private IntPtr current = IntPtr.Zero;

View file

@ -55,6 +55,7 @@ sources = \
Object.cs \ Object.cs \
ObjectManager.cs \ ObjectManager.cs \
Opaque.cs \ Opaque.cs \
ParamSpec.cs \
PropertyAttribute.cs \ PropertyAttribute.cs \
PtrArray.cs \ PtrArray.cs \
Signal.cs \ Signal.cs \
@ -98,7 +99,7 @@ endif
$(ASSEMBLY): $(build_sources) gtk-sharp.snk AssemblyInfo.cs $(ASSEMBLY): $(build_sources) gtk-sharp.snk AssemblyInfo.cs
@rm -f $(ASSEMBLY).mdb @rm -f $(ASSEMBLY).mdb
$(CSC) $(CSFLAGS) -nowarn:0169,0612,0618 -out:$(ASSEMBLY) -target:library $(references) $(build_sources) $(CSC) $(CSFLAGS) -unsafe -nowarn:0169,0612,0618 -out:$(ASSEMBLY) -target:library $(references) $(build_sources)
$(GAPI_CDECL_INSERT) $(GAPI_CDECL_INSERT)
$(POLICY_ASSEMBLIES): $(top_builddir)/policy.config gtk-sharp.snk $(POLICY_ASSEMBLIES): $(top_builddir)/policy.config gtk-sharp.snk

View file

@ -67,15 +67,23 @@ namespace GLib {
return ret; return ret;
} }
[DllImport("glibsharpglue-2")] static unsafe ulong strlen (IntPtr s)
static extern UIntPtr glibsharp_strlen (IntPtr mem); {
ulong cnt = 0;
byte *b = (byte *)s;
while (*b != 0) {
b++;
cnt++;
}
return cnt;
}
public static string Utf8PtrToString (IntPtr ptr) public static string Utf8PtrToString (IntPtr ptr)
{ {
if (ptr == IntPtr.Zero) if (ptr == IntPtr.Zero)
return null; return null;
int len = (int) (uint)glibsharp_strlen (ptr); int len = (int) (uint) strlen (ptr);
byte[] bytes = new byte [len]; byte[] bytes = new byte [len];
Marshal.Copy (ptr, bytes, 0, len); Marshal.Copy (ptr, bytes, 0, len);
return System.Text.Encoding.UTF8.GetString (bytes); return System.Text.Encoding.UTF8.GetString (bytes);
@ -320,28 +328,44 @@ namespace GLib {
return local_epoch.AddSeconds (time_t.ToInt64 () + utc_offset); return local_epoch.AddSeconds (time_t.ToInt64 () + utc_offset);
} }
[DllImport("glibsharpglue-2")] [DllImport("libglib-2.0-0.dll")]
static extern IntPtr gtksharp_unichar_to_utf8_string (uint c); static extern IntPtr g_malloc0 (UIntPtr size);
[DllImport("libglib-2.0-0.dll")]
static extern int g_unichar_to_utf8 (uint c, IntPtr buf);
public static char GUnicharToChar (uint ucs4_char) public static char GUnicharToChar (uint ucs4_char)
{ {
if (ucs4_char == 0) if (ucs4_char == 0)
return (char) 0; return (char) 0;
IntPtr raw_ret = gtksharp_unichar_to_utf8_string (ucs4_char); string ret = GUnicharToString (ucs4_char);
string ret = GLib.Marshaller.PtrToStringGFree(raw_ret); if (ret.Length != 1)
if (ret.Length > 1)
throw new ArgumentOutOfRangeException ("ucs4char is not representable by a char."); throw new ArgumentOutOfRangeException ("ucs4char is not representable by a char.");
return ret [0]; return ret [0];
} }
[DllImport("glibsharpglue-2")] public static string GUnicharToString (uint ucs4_char)
static extern uint glibsharp_utf16_to_unichar (ushort c); {
if (ucs4_char == 0)
return String.Empty;
IntPtr buf = g_malloc0 (new UIntPtr (7));
g_unichar_to_utf8 (ucs4_char, buf);
return PtrToStringGFree (buf);
}
[DllImport("libglib-2.0-0.dll")]
static extern IntPtr g_utf16_to_ucs4 (ref ushort c, IntPtr len, IntPtr d1, IntPtr d2, IntPtr d3);
public static uint CharToGUnichar (char c) public static uint CharToGUnichar (char c)
{ {
return glibsharp_utf16_to_unichar ((ushort) c); ushort val = (ushort) c;
IntPtr ucs4_str = g_utf16_to_ucs4 (ref val, new IntPtr (1), IntPtr.Zero, IntPtr.Zero, IntPtr.Zero);
uint result = (uint) Marshal.ReadInt32 (ucs4_str);
g_free (ucs4_str);
return result;
} }
public static IntPtr StructureToPtrAlloc (object o) public static IntPtr StructureToPtrAlloc (object o)

View file

@ -185,11 +185,50 @@ namespace GLib {
} }
} }
[DllImport ("glibsharpglue-2")] struct GTypeClass {
static extern void gtksharp_override_property_handlers (IntPtr type, GetPropertyDelegate get_cb, SetPropertyDelegate set_cb); IntPtr gtype;
}
[DllImport ("glibsharpglue-2")] struct GObjectClass {
static extern IntPtr gtksharp_register_property (IntPtr type, IntPtr name, IntPtr nick, IntPtr blurb, uint property_id, IntPtr property_type, bool can_read, bool can_write); GTypeClass type_class;
IntPtr construct_props;
IntPtr constructor_cb;
public SetPropertyDelegate set_prop_cb;
public GetPropertyDelegate get_prop_cb;
IntPtr dispose;
IntPtr finalize;
IntPtr dispatch_properties_changed;
IntPtr notify;
IntPtr constructed;
IntPtr dummy1;
IntPtr dummy2;
IntPtr dummy3;
IntPtr dummy4;
IntPtr dummy5;
IntPtr dummy6;
IntPtr dummy7;
}
static void OverridePropertyHandlers (GType gtype, GetPropertyDelegate get_cb, SetPropertyDelegate set_cb)
{
IntPtr class_ptr = gtype.ClassPtr;
GObjectClass klass = (GObjectClass) Marshal.PtrToStructure (class_ptr, typeof (GObjectClass));
klass.get_prop_cb = get_cb;
klass.set_prop_cb = set_cb;
Marshal.StructureToPtr (klass, class_ptr, false);
}
[DllImport("libgobject-2.0-0.dll")]
static extern void g_object_class_install_property (IntPtr klass, uint prop_id, IntPtr param_spec);
static IntPtr RegisterProperty (GType type, string name, string nick, string blurb, uint property_id, GType property_type, bool can_read, bool can_write)
{
IntPtr declaring_class = type.ClassPtr;
ParamSpec pspec = new ParamSpec (name, nick, blurb, property_type, can_read, can_write);
g_object_class_install_property (declaring_class, property_id, pspec.Handle);
return pspec.Handle;
}
static void AddProperties (GType gtype, System.Type t) static void AddProperties (GType gtype, System.Type t)
{ {
@ -203,26 +242,17 @@ namespace GLib {
PropertyAttribute property_attr = attr as PropertyAttribute; PropertyAttribute property_attr = attr as PropertyAttribute;
if (!handlers_overridden) { if (!handlers_overridden) {
gtksharp_override_property_handlers (gtype.Val, GetPropertyHandler, SetPropertyHandler); OverridePropertyHandlers (gtype, GetPropertyHandler, SetPropertyHandler);
handlers_overridden = true; handlers_overridden = true;
} }
IntPtr native_name = GLib.Marshaller.StringToPtrGStrdup (property_attr.Name); try {
IntPtr native_nick = GLib.Marshaller.StringToPtrGStrdup (property_attr.Nickname); IntPtr param_spec = RegisterProperty (gtype, property_attr.Name, property_attr.Nickname, property_attr.Blurb, idx, (GType) pinfo.PropertyType, pinfo.CanRead, pinfo.CanWrite);
IntPtr native_blurb = GLib.Marshaller.StringToPtrGStrdup (property_attr.Blurb); Properties.Add (param_spec, pinfo);
idx++;
IntPtr param_spec = gtksharp_register_property (gtype.Val, native_name, native_nick, native_blurb, idx, ((GType) pinfo.PropertyType).Val, pinfo.CanRead, pinfo.CanWrite); } catch (ArgumentException) {
GLib.Marshaller.Free (native_name);
GLib.Marshaller.Free (native_nick);
GLib.Marshaller.Free (native_blurb);
if (param_spec == IntPtr.Zero)
// The GType of the property is not supported
throw new InvalidOperationException (String.Format ("GLib.PropertyAttribute cannot be applied to property {0} of type {1} because the return type of the property is not supported", pinfo.Name, t.FullName)); throw new InvalidOperationException (String.Format ("GLib.PropertyAttribute cannot be applied to property {0} of type {1} because the return type of the property is not supported", pinfo.Name, t.FullName));
}
Properties.Add (param_spec, pinfo);
idx++;
} }
} }
} }
@ -280,53 +310,17 @@ namespace GLib {
} }
} }
[DllImport("glibsharpglue-2")] protected internal static GType RegisterGType (System.Type t)
static extern IntPtr gtksharp_register_type (IntPtr name, IntPtr parent_type);
static int type_uid;
static string BuildEscapedName (System.Type t)
{ {
string qn = t.FullName; GType gtype = GType.RegisterGObjectType (t);
// Just a random guess
StringBuilder sb = new StringBuilder (20 + qn.Length);
sb.Append ("__gtksharp_");
sb.Append (type_uid++);
sb.Append ("_");
foreach (char c in qn) {
if ((c >= '0' && c <= '9') || (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z'))
sb.Append (c);
else if (c == '.')
sb.Append ('_');
else if ((uint) c <= byte.MaxValue) {
sb.Append ('+');
sb.Append (((byte) c).ToString ("x2"));
} else {
sb.Append ('-');
sb.Append (((uint) c).ToString ("x4"));
}
}
return sb.ToString ();
}
protected static GType RegisterGType (System.Type t)
{
GType parent_gtype = LookupGType (t.BaseType);
string name = BuildEscapedName (t);
IntPtr native_name = GLib.Marshaller.StringToPtrGStrdup (name);
GType gtype = new GType (gtksharp_register_type (native_name, parent_gtype.Val));
GLib.Marshaller.Free (native_name);
GLib.GType.Register (gtype, t);
AddProperties (gtype, t); AddProperties (gtype, t);
ConnectDefaultHandlers (gtype, t); ConnectDefaultHandlers (gtype, t);
InvokeClassInitializers (gtype, t); InvokeClassInitializers (gtype, t);
AddInterfaces (gtype, t); AddInterfaces (gtype, t);
g_types[t] = gtype;
return gtype; return gtype;
} }
static Hashtable g_types = new Hashtable ();
protected GType LookupGType () protected GType LookupGType ()
{ {
return LookupGType (GetType ()); return LookupGType (GetType ());
@ -334,14 +328,7 @@ namespace GLib {
protected internal static GType LookupGType (System.Type t) protected internal static GType LookupGType (System.Type t)
{ {
if (g_types.Contains (t)) return GType.LookupGObjectType (t);
return (GType) g_types [t];
PropertyInfo pi = t.GetProperty ("GType", BindingFlags.DeclaredOnly | BindingFlags.Static | BindingFlags.Public);
if (pi != null)
return (GType) pi.GetValue (null, null);
return RegisterGType (t);
} }
protected Object (IntPtr raw) protected Object (IntPtr raw)
@ -363,17 +350,24 @@ namespace GLib {
Raw = g_object_new (gtype.Val, IntPtr.Zero); Raw = g_object_new (gtype.Val, IntPtr.Zero);
} }
[DllImport("glibsharpglue-2")] struct GParameter {
static extern IntPtr gtksharp_object_newv (IntPtr gtype, int n_params, IntPtr[] names, GLib.Value[] vals); public IntPtr name;
public GLib.Value val;
}
[DllImport("libgobject-2.0-0.dll")]
static extern IntPtr g_object_newv (IntPtr gtype, int n_params, GParameter[] parms);
protected virtual void CreateNativeObject (string[] names, GLib.Value[] vals) protected virtual void CreateNativeObject (string[] names, GLib.Value[] vals)
{ {
IntPtr[] native_names = new IntPtr [names.Length]; GParameter[] parms = new GParameter [names.Length];
for (int i = 0; i < names.Length; i++) for (int i = 0; i < names.Length; i++) {
native_names [i] = GLib.Marshaller.StringToPtrGStrdup (names [i]); parms [i].name = GLib.Marshaller.StringToPtrGStrdup (names [i]);
Raw = gtksharp_object_newv (LookupGType ().Val, names.Length, native_names, vals); parms [i].val = vals [i];
foreach (IntPtr p in native_names) }
GLib.Marshaller.Free (p); Raw = g_object_newv (LookupGType ().Val, parms.Length, parms);
foreach (GParameter p in parms)
GLib.Marshaller.Free (p.name);
} }
protected virtual IntPtr Raw { protected virtual IntPtr Raw {
@ -405,12 +399,9 @@ namespace GLib {
} }
} }
[DllImport("glibsharpglue-2")]
static extern IntPtr gtksharp_get_type_name (IntPtr raw);
protected string TypeName { protected string TypeName {
get { get {
return Marshaller.Utf8PtrToString (gtksharp_get_type_name (Raw)); return NativeType.ToString ();
} }
} }
@ -586,33 +577,36 @@ namespace GLib {
GLib.Marshaller.Free (native_name); GLib.Marshaller.Free (native_name);
} }
[DllImport("glibsharpglue-2")]
static extern void gtksharp_override_virtual_method (IntPtr gtype, IntPtr name, Delegate cb);
protected static void OverrideVirtualMethod (GType gtype, string name, Delegate cb) protected static void OverrideVirtualMethod (GType gtype, string name, Delegate cb)
{ {
IntPtr native_name = GLib.Marshaller.StringToPtrGStrdup (name); Signal.OverrideDefaultHandler (gtype, name, cb);
gtksharp_override_virtual_method (gtype.Val, native_name, cb);
GLib.Marshaller.Free (native_name);
} }
[DllImport("libgobject-2.0-0.dll")] [DllImport("libgobject-2.0-0.dll")]
protected static extern void g_signal_chain_from_overridden (IntPtr args, ref GLib.Value retval); protected static extern void g_signal_chain_from_overridden (IntPtr args, ref GLib.Value retval);
[DllImport("glibsharpglue-2")] [DllImport("libgobject-2.0-0.dll")]
static extern bool gtksharp_is_object (IntPtr obj); static extern bool g_type_check_instance_is_a (IntPtr obj, IntPtr gtype);
internal static bool IsObject (IntPtr obj) internal static bool IsObject (IntPtr obj)
{ {
return gtksharp_is_object (obj); return g_type_check_instance_is_a (obj, GType.Object.Val);
} }
[DllImport("glibsharpglue-2")] struct GTypeInstance {
static extern int gtksharp_object_get_ref_count (IntPtr obj); public IntPtr g_class;
}
struct GObject {
public GTypeInstance type_instance;
public uint ref_count;
public IntPtr qdata;
}
protected int RefCount { protected int RefCount {
get { get {
return gtksharp_object_get_ref_count (Handle); GObject native = (GObject) Marshal.PtrToStructure (Handle, typeof (GObject));
return (int) native.ref_count;
} }
} }

View file

@ -69,7 +69,9 @@ namespace GLib {
static Type GetTypeOrParent (IntPtr obj) static Type GetTypeOrParent (IntPtr obj)
{ {
IntPtr typeid = gtksharp_get_type_id (obj); IntPtr typeid = GType.ValFromInstancePtr (obj);
if (typeid == GType.Invalid.Val)
return null;
Type result = GType.LookupType (typeid); Type result = GType.LookupType (typeid);
while (result == null) { while (result == null) {
@ -81,9 +83,6 @@ namespace GLib {
return result; return result;
} }
[DllImport("glibsharpglue-2")]
static extern IntPtr gtksharp_get_type_id (IntPtr raw);
[DllImport("libgobject-2.0-0.dll")] [DllImport("libgobject-2.0-0.dll")]
static extern IntPtr g_type_parent (IntPtr typ); static extern IntPtr g_type_parent (IntPtr typ);
} }

185
glib/ParamSpec.cs Normal file
View file

@ -0,0 +1,185 @@
// ParamSpec.cs - GParamSpec class wrapper implementation
//
// Authors: Mike Kestner <mkestner@novell.com>
//
// Copyright (c) 2008 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.
namespace GLib {
using System;
using System.Runtime.InteropServices;
internal enum ParamFlags {
None = 0,
Readable = 1 << 0,
Writable = 1 << 1,
}
internal class ParamSpec {
IntPtr handle;
public ParamSpec (string name, string nick, string blurb, GType type, bool readable, bool writable)
{
ParamFlags pflags = ParamFlags.None;
if (readable) pflags |= ParamFlags.Readable;
if (writable) pflags |= ParamFlags.Writable;
int flags = (int) pflags;
IntPtr p_name = GLib.Marshaller.StringToPtrGStrdup (name);
IntPtr p_nick = GLib.Marshaller.StringToPtrGStrdup (nick);
IntPtr p_blurb = GLib.Marshaller.StringToPtrGStrdup (blurb);
if (type == GType.Char)
handle = g_param_spec_char (p_name, p_nick, p_blurb, SByte.MinValue, SByte.MaxValue, 0, flags);
else if (type == GType.UChar)
handle = g_param_spec_uchar (p_name, p_nick, p_blurb, Byte.MinValue, Byte.MaxValue, 0, flags);
else if (type == GType.Boolean)
handle = g_param_spec_boolean (p_name, p_nick, p_blurb, false, flags);
else if (type == GType.Int)
handle = g_param_spec_int (p_name, p_nick, p_blurb, Int32.MinValue, Int32.MaxValue, 0, flags);
else if (type == GType.UInt)
handle = g_param_spec_uint (p_name, p_nick, p_blurb, 0, UInt32.MaxValue, 0, flags);
else if (type == GType.Long)
handle = g_param_spec_long (p_name, p_nick, p_blurb, IntPtr.Zero, IntPtr.Size == 4 ? new IntPtr (Int32.MaxValue) : new IntPtr (Int64.MaxValue), IntPtr.Zero, flags);
else if (type == GType.ULong)
handle = g_param_spec_ulong (p_name, p_nick, p_blurb, UIntPtr.Zero, UIntPtr.Size == 4 ? new UIntPtr (UInt32.MaxValue) : new UIntPtr (UInt64.MaxValue), UIntPtr.Zero, flags);
else if (type == GType.Int64)
handle = g_param_spec_int64 (p_name, p_nick, p_blurb, Int64.MinValue, Int64.MaxValue, 0, flags);
else if (type == GType.UInt64)
handle = g_param_spec_uint64 (p_name, p_nick, p_blurb, 0, UInt64.MaxValue, 0, flags);
/*
else if (type == GType.Enum)
else if (type == GType.Flags)
* TODO:
* Both g_param_spec_enum and g_param_spec_flags expect default property values and the members of the enum seemingly cannot be enumerated
*/
else if (type == GType.Float)
handle = g_param_spec_float (p_name, p_nick, p_blurb, Single.MinValue, Single.MaxValue, 0.0f, flags);
else if (type == GType.Double)
handle = g_param_spec_double (p_name, p_nick, p_blurb, Double.MinValue, Double.MaxValue, 0.0, flags);
else if (type == GType.String)
handle = g_param_spec_string (p_name, p_nick, p_blurb, IntPtr.Zero, flags);
else if (type == GType.Pointer)
handle = g_param_spec_pointer (p_name, p_nick, p_blurb, flags);
else if (type.Val == g_gtype_get_type ())
handle = g_param_spec_gtype (p_name, p_nick, p_blurb, GType.None.Val, flags);
else if (g_type_is_a (type.Val, GType.Boxed.Val))
handle = g_param_spec_boxed (p_name, p_nick, p_blurb, type.Val, flags);
else if (g_type_is_a (type.Val, GType.Object.Val))
handle = g_param_spec_object (p_name, p_nick, p_blurb, type.Val, flags);
else
throw new ArgumentException ("type");
GLib.Marshaller.Free (p_name);
GLib.Marshaller.Free (p_nick);
GLib.Marshaller.Free (p_blurb);
}
public ParamSpec (IntPtr native)
{
handle = native;
}
public IntPtr Handle {
get { return handle; }
}
public GType ValueType {
get {
GParamSpec spec = (GParamSpec) Marshal.PtrToStructure (Handle, typeof (GParamSpec));
return new GType (spec.value_type);
}
}
struct GTypeInstance {
IntPtr g_class;
}
struct GParamSpec {
GTypeInstance g_type_instance;
IntPtr name;
ParamFlags flags;
public IntPtr value_type;
IntPtr owner_type;
IntPtr _nick;
IntPtr _blurb;
IntPtr qdata;
uint ref_count;
uint param_id;
}
[DllImport("libgobject-2.0-0.dll")]
static extern IntPtr g_param_spec_char (IntPtr name, IntPtr nick, IntPtr blurb, sbyte min, sbyte max, sbyte dval, int flags);
[DllImport("libgobject-2.0-0.dll")]
static extern IntPtr g_param_spec_uchar (IntPtr name, IntPtr nick, IntPtr blurb, byte min, byte max, byte dval, int flags);
[DllImport("libgobject-2.0-0.dll")]
static extern IntPtr g_param_spec_boolean (IntPtr name, IntPtr nick, IntPtr blurb, bool dval, int flags);
[DllImport("libgobject-2.0-0.dll")]
static extern IntPtr g_param_spec_int (IntPtr name, IntPtr nick, IntPtr blurb, int min, int max, int dval, int flags);
[DllImport("libgobject-2.0-0.dll")]
static extern IntPtr g_param_spec_uint (IntPtr name, IntPtr nick, IntPtr blurb, uint min, uint max, uint dval, int flags);
[DllImport("libgobject-2.0-0.dll")]
static extern IntPtr g_param_spec_long (IntPtr name, IntPtr nick, IntPtr blurb, IntPtr min, IntPtr max, IntPtr dval, int flags);
[DllImport("libgobject-2.0-0.dll")]
static extern IntPtr g_param_spec_ulong (IntPtr name, IntPtr nick, IntPtr blurb, UIntPtr min, UIntPtr max, UIntPtr dval, int flags);
[DllImport("libgobject-2.0-0.dll")]
static extern IntPtr g_param_spec_int64 (IntPtr name, IntPtr nick, IntPtr blurb, long min, long max, long dval, int flags);
[DllImport("libgobject-2.0-0.dll")]
static extern IntPtr g_param_spec_uint64 (IntPtr name, IntPtr nick, IntPtr blurb, ulong min, ulong max, ulong dval, int flags);
[DllImport("libgobject-2.0-0.dll")]
static extern IntPtr g_param_spec_float (IntPtr name, IntPtr nick, IntPtr blurb, float min, float max, float dval, int flags);
[DllImport("libgobject-2.0-0.dll")]
static extern IntPtr g_param_spec_double (IntPtr name, IntPtr nick, IntPtr blurb, double min, double max, double dval, int flags);
[DllImport("libgobject-2.0-0.dll")]
static extern IntPtr g_param_spec_string (IntPtr name, IntPtr nick, IntPtr blurb, IntPtr dval, int flags);
[DllImport("libgobject-2.0-0.dll")]
static extern IntPtr g_param_spec_pointer (IntPtr name, IntPtr nick, IntPtr blurb, int flags);
[DllImport("libgobject-2.0-0.dll")]
static extern IntPtr g_param_spec_gtype (IntPtr name, IntPtr nick, IntPtr blurb, IntPtr dval, int flags);
[DllImport("libgobject-2.0-0.dll")]
static extern IntPtr g_param_spec_boxed (IntPtr name, IntPtr nick, IntPtr blurb, IntPtr return_type, int flags);
[DllImport("libgobject-2.0-0.dll")]
static extern IntPtr g_param_spec_object (IntPtr name, IntPtr nick, IntPtr blurb, IntPtr return_type, int flags);
[DllImport("libgobject-2.0-0.dll")]
static extern IntPtr g_gtype_get_type ();
[DllImport("libgobject-2.0-0.dll")]
static extern bool g_type_is_a (IntPtr a, IntPtr b);
}
}

View file

@ -114,12 +114,9 @@ namespace GLib {
} }
} }
[DllImport("glibsharpglue-2")]
static extern IntPtr gtksharp_ptr_array_get_array (IntPtr raw);
public IntPtr ArrayPtr { public IntPtr ArrayPtr {
get { get {
return gtksharp_ptr_array_get_array (Handle); return Marshal.ReadIntPtr (Handle);
} }
} }
@ -147,19 +144,19 @@ namespace GLib {
g_ptr_array_remove_range (Handle, index, length); g_ptr_array_remove_range (Handle, index, length);
} }
[DllImport("glibsharpglue-2")] struct GPtrArray {
static extern int gtksharp_ptr_array_get_count (IntPtr raw); IntPtr pdata;
public uint len;
}
// ICollection // ICollection
public int Count { public int Count {
get { get {
return gtksharp_ptr_array_get_count (Handle); GPtrArray native = (GPtrArray) Marshal.PtrToStructure (Handle, typeof (GPtrArray));
return (int) native.len;
} }
} }
[DllImport("glibsharpglue-2")]
static extern IntPtr gtksharp_ptr_array_get_nth (IntPtr raw, uint idx);
public object this [int index] { public object this [int index] {
get { get {
IntPtr data = NthData ((uint) index); IntPtr data = NthData ((uint) index);
@ -196,7 +193,7 @@ namespace GLib {
internal IntPtr NthData (uint index) internal IntPtr NthData (uint index)
{ {
return gtksharp_ptr_array_get_nth (Handle, index);; return Marshal.ReadIntPtr (ArrayPtr, (int) index * IntPtr.Size);;
} }
// Synchronization could be tricky here. Hmm. // Synchronization could be tricky here. Hmm.

View file

@ -34,22 +34,6 @@ namespace GLib {
return new SList (g_slist_copy (Handle)); return new SList (g_slist_copy (Handle));
} }
[DllImport("glibsharpglue-2")]
static extern IntPtr gtksharp_slist_get_data (IntPtr l);
internal override IntPtr GetData (IntPtr current)
{
return gtksharp_slist_get_data (current);
}
[DllImport("glibsharpglue-2")]
static extern IntPtr gtksharp_slist_get_next (IntPtr l);
internal override IntPtr Next (IntPtr current)
{
return gtksharp_slist_get_next (current);
}
[DllImport("libglib-2.0-0.dll")] [DllImport("libglib-2.0-0.dll")]
static extern int g_slist_length (IntPtr l); static extern int g_slist_length (IntPtr l);

View file

@ -52,6 +52,17 @@ namespace GLib {
public Flags run_type; public Flags run_type;
} }
[StructLayout (LayoutKind.Sequential)]
struct Query {
public uint signal_id;
public IntPtr signal_name;
public IntPtr itype;
public Flags signal_flags;
public IntPtr return_type;
public uint n_params;
public IntPtr param_types;
}
[CDeclCallback] [CDeclCallback]
public delegate bool EmissionHookNative (ref InvocationHint hint, uint n_pvals, IntPtr pvals, IntPtr data); public delegate bool EmissionHookNative (ref InvocationHint hint, uint n_pvals, IntPtr pvals, IntPtr data);
@ -321,7 +332,9 @@ namespace GLib {
} }
object ret_obj = null; object ret_obj = null;
if (glibsharp_signal_get_return_type (signal_id) != GType.None.Val) { Query query;
g_signal_query (signal_id, out query);
if (query.return_type != GType.None.Val) {
GLib.Value ret = GLib.Value.Empty; GLib.Value ret = GLib.Value.Empty;
g_signal_emitv (inst_and_params.ArrayPtr, signal_id, gquark, ref ret); g_signal_emitv (inst_and_params.ArrayPtr, signal_id, gquark, ref ret);
ret_obj = ret.Val; ret_obj = ret.Val;
@ -344,7 +357,7 @@ namespace GLib {
private static uint GetSignalId (string signal_name, GLib.Object obj) private static uint GetSignalId (string signal_name, GLib.Object obj)
{ {
IntPtr typeid = gtksharp_get_type_id (obj.Handle); IntPtr typeid = GType.ValFromInstancePtr (obj.Handle);
return GetSignalId (signal_name, typeid); return GetSignalId (signal_name, typeid);
} }
@ -367,6 +380,17 @@ namespace GLib {
return g_signal_add_emission_hook (signal_id, gquark, new EmissionHookMarshaler (handler_func).Callback, IntPtr.Zero, IntPtr.Zero); return g_signal_add_emission_hook (signal_id, gquark, new EmissionHookMarshaler (handler_func).Callback, IntPtr.Zero, IntPtr.Zero);
} }
internal static void OverrideDefaultHandler (GType gtype, string name, Delegate cb)
{
IntPtr closure = g_cclosure_new (cb, IntPtr.Zero, IntPtr.Zero);
gtype.EnsureClass ();
uint id = GetSignalId (name, gtype.Val);
g_signal_override_class_closure (id, gtype.Val, closure);
}
[DllImport("libgobject-2.0-0.dll")]
static extern IntPtr g_cclosure_new (Delegate cb, IntPtr data, IntPtr notify);
[DllImport("libgobject-2.0-0.dll")] [DllImport("libgobject-2.0-0.dll")]
static extern IntPtr g_signal_get_invocation_hint (IntPtr instance); static extern IntPtr g_signal_get_invocation_hint (IntPtr instance);
@ -376,19 +400,19 @@ namespace GLib {
[DllImport("libgobject-2.0-0.dll")] [DllImport("libgobject-2.0-0.dll")]
static extern void g_signal_emitv (IntPtr instance_and_params, uint signal_id, uint gquark_detail, IntPtr return_value); static extern void g_signal_emitv (IntPtr instance_and_params, uint signal_id, uint gquark_detail, IntPtr return_value);
[DllImport("glibsharpglue-2")]
static extern IntPtr glibsharp_signal_get_return_type (uint signal_id);
[DllImport("libgobject-2.0-0.dll")] [DllImport("libgobject-2.0-0.dll")]
static extern uint g_signal_lookup (IntPtr name, IntPtr itype); static extern uint g_signal_lookup (IntPtr name, IntPtr itype);
[DllImport("libgobject-2.0-0.dll")]
static extern void g_signal_override_class_closure (uint id, IntPtr gtype, IntPtr closure);
[DllImport("libgobject-2.0-0.dll")]
static extern void g_signal_query (uint signal_id, out Query query);
//better not to expose g_quark_from_static_string () due to memory allocation issues //better not to expose g_quark_from_static_string () due to memory allocation issues
[DllImport("libglib-2.0-0.dll")] [DllImport("libglib-2.0-0.dll")]
static extern uint g_quark_from_string (IntPtr str); static extern uint g_quark_from_string (IntPtr str);
[DllImport("glibsharpglue-2")]
static extern IntPtr gtksharp_get_type_id (IntPtr raw);
[DllImport("libgobject-2.0-0.dll")] [DllImport("libgobject-2.0-0.dll")]
static extern ulong g_signal_add_emission_hook (uint signal_id, uint gquark_detail, EmissionHookNative hook_func, IntPtr hook_data, IntPtr data_destroy); static extern ulong g_signal_add_emission_hook (uint signal_id, uint gquark_detail, EmissionHookNative hook_func, IntPtr hook_data, IntPtr data_destroy);

View file

@ -50,6 +50,13 @@ namespace GLib {
} }
} }
struct GClosure {
long fields;
IntPtr marshaler;
IntPtr data;
IntPtr notifiers;
}
internal delegate void ClosureInvokedHandler (object o, ClosureInvokedArgs args); internal delegate void ClosureInvokedHandler (object o, ClosureInvokedArgs args);
internal class SignalClosure : IDisposable { internal class SignalClosure : IDisposable {
@ -66,7 +73,9 @@ namespace GLib {
public SignalClosure (IntPtr obj, string signal_name, System.Type args_type) public SignalClosure (IntPtr obj, string signal_name, System.Type args_type)
{ {
raw_closure = glibsharp_closure_new (Marshaler, Notify, IntPtr.Zero); raw_closure = g_closure_new_simple (Marshal.SizeOf (typeof (GClosure)), IntPtr.Zero);
g_closure_set_marshal (raw_closure, Marshaler);
g_closure_add_finalize_notifier (raw_closure, IntPtr.Zero, Notify);
closures [raw_closure] = this; closures [raw_closure] = this;
handle = obj; handle = obj;
name = signal_name; name = signal_name;
@ -193,12 +202,18 @@ namespace GLib {
} }
} }
[DllImport("glibsharpglue-2")]
static extern IntPtr glibsharp_closure_new (ClosureMarshal marshaler, ClosureNotify notify, IntPtr gch);
[DllImport("libgobject-2.0-0.dll")] [DllImport("libgobject-2.0-0.dll")]
static extern IntPtr g_cclosure_new (Delegate cb, IntPtr user_data, ClosureNotify notify); static extern IntPtr g_cclosure_new (Delegate cb, IntPtr user_data, ClosureNotify notify);
[DllImport("libgobject-2.0-0.dll")]
static extern IntPtr g_closure_new_simple (int closure_size, IntPtr dummy);
[DllImport("libgobject-2.0-0.dll")]
static extern void g_closure_set_marshal (IntPtr closure, ClosureMarshal marshaler);
[DllImport("libgobject-2.0-0.dll")]
static extern void g_closure_add_finalize_notifier (IntPtr closure, IntPtr dummy, ClosureNotify notify);
[DllImport("libgobject-2.0-0.dll")] [DllImport("libgobject-2.0-0.dll")]
static extern uint g_signal_connect_closure (IntPtr obj, IntPtr name, IntPtr closure, bool is_after); static extern uint g_signal_connect_closure (IntPtr obj, IntPtr name, IntPtr closure, bool is_after);

View file

@ -98,9 +98,7 @@ namespace GLib {
{ {
type = IntPtr.Zero; type = IntPtr.Zero;
pad_1 = pad_2 = 0; pad_1 = pad_2 = 0;
IntPtr native = GLib.Marshaller.StringToPtrGStrdup (type_name); g_value_init (ref this, GType.FromName (type_name).Val);
gtksharp_value_create_from_type_name (ref this, native);
GLib.Marshaller.Free (native);
if (wrap.flags) if (wrap.flags)
g_value_set_flags (ref this, (uint) (int) wrap); g_value_set_flags (ref this, (uint) (int) wrap);
else else
@ -133,9 +131,7 @@ namespace GLib {
{ {
type = IntPtr.Zero; type = IntPtr.Zero;
pad_1 = pad_2 = 0; pad_1 = pad_2 = 0;
IntPtr native = GLib.Marshaller.StringToPtrGStrdup (type_name); g_value_init (ref this, GType.FromName (type_name).Val);
gtksharp_value_create_from_type_name (ref this, native);
GLib.Marshaller.Free (native);
g_value_set_boxed (ref this, val.Handle); g_value_set_boxed (ref this, val.Handle);
} }
@ -153,9 +149,7 @@ namespace GLib {
{ {
type = IntPtr.Zero; type = IntPtr.Zero;
pad_1 = pad_2 = 0; pad_1 = pad_2 = 0;
IntPtr prop = GLib.Marshaller.StringToPtrGStrdup (prop_name); InitForProperty (obj, prop_name);
gtksharp_value_create_from_property (ref this, obj.Handle, prop);
GLib.Marshaller.Free (prop);
} }
[Obsolete] [Obsolete]
@ -163,9 +157,7 @@ namespace GLib {
{ {
type = IntPtr.Zero; type = IntPtr.Zero;
pad_1 = pad_2 = 0; pad_1 = pad_2 = 0;
IntPtr native = GLib.Marshaller.StringToPtrGStrdup (prop_name); InitForProperty (obj.NativeType, prop_name);
gtksharp_value_create_from_type_and_property (ref this, obj.NativeType.Val, native);
GLib.Marshaller.Free (native);
if (wrap.flags) if (wrap.flags)
g_value_set_flags (ref this, (uint) (int) wrap); g_value_set_flags (ref this, (uint) (int) wrap);
else else
@ -177,9 +169,7 @@ namespace GLib {
{ {
type = IntPtr.Zero; type = IntPtr.Zero;
pad_1 = pad_2 = 0; pad_1 = pad_2 = 0;
IntPtr native = GLib.Marshaller.StringToPtrGStrdup (prop_name); InitForProperty (GLib.Object.GetObject (obj), prop_name);
gtksharp_value_create_from_property (ref this, obj, native);
GLib.Marshaller.Free (native);
g_value_set_boxed (ref this, val.Handle); g_value_set_boxed (ref this, val.Handle);
} }
@ -257,7 +247,7 @@ namespace GLib {
[Obsolete ("Replaced by Enum cast")] [Obsolete ("Replaced by Enum cast")]
public static explicit operator EnumWrapper (Value val) public static explicit operator EnumWrapper (Value val)
{ {
if (glibsharp_value_holds_flags (ref val)) if (val.HoldsFlags)
return new EnumWrapper ((int)g_value_get_flags (ref val), true); return new EnumWrapper ((int)g_value_get_flags (ref val), true);
else else
return new EnumWrapper (g_value_get_enum (ref val), false); return new EnumWrapper (g_value_get_enum (ref val), false);
@ -265,7 +255,7 @@ namespace GLib {
public static explicit operator Enum (Value val) public static explicit operator Enum (Value val)
{ {
if (glibsharp_value_holds_flags (ref val)) if (val.HoldsFlags)
return (Enum)Enum.ToObject (GType.LookupType (val.type), g_value_get_flags (ref val)); return (Enum)Enum.ToObject (GType.LookupType (val.type), g_value_get_flags (ref val));
else else
return (Enum)Enum.ToObject (GType.LookupType (val.type), g_value_get_enum (ref val)); return (Enum)Enum.ToObject (GType.LookupType (val.type), g_value_get_enum (ref val));
@ -453,21 +443,36 @@ namespace GLib {
Marshal.StructureToPtr (val, g_value_get_boxed (ref this), false); Marshal.StructureToPtr (val, g_value_get_boxed (ref this), false);
} }
bool HoldsFlags {
get { return g_type_check_value_holds (ref this, GType.Flags.Val); }
}
void InitForProperty (Object obj, string name)
{
GType gtype = Object.LookupGType (obj.GetType ());
InitForProperty (gtype, name);
}
void InitForProperty (GType gtype, string name)
{
IntPtr p_name = Marshaller.StringToPtrGStrdup (name);
ParamSpec spec = new ParamSpec (g_object_class_find_property (gtype.ClassPtr, p_name));
Marshaller.Free (p_name);
g_value_init (ref this, spec.ValueType.Val);
}
[DllImport("libgobject-2.0-0.dll")]
static extern IntPtr g_object_class_find_property (IntPtr klass, IntPtr name);
[DllImport("libgobject-2.0-0.dll")]
static extern bool g_type_check_value_holds (ref Value val, IntPtr gtype);
[DllImport("libgobject-2.0-0.dll")] [DllImport("libgobject-2.0-0.dll")]
static extern void g_value_init (ref GLib.Value val, IntPtr gtype); static extern void g_value_init (ref GLib.Value val, IntPtr gtype);
[DllImport("libgobject-2.0-0.dll")] [DllImport("libgobject-2.0-0.dll")]
static extern void g_value_unset (ref GLib.Value val); static extern void g_value_unset (ref GLib.Value val);
[DllImport("glibsharpglue-2")]
static extern IntPtr gtksharp_value_create_from_property(ref GLib.Value val, IntPtr obj, IntPtr name);
[DllImport("glibsharpglue-2")]
static extern IntPtr gtksharp_value_create_from_type_and_property(ref GLib.Value val, IntPtr gtype, IntPtr name);
[DllImport("glibsharpglue-2")]
static extern IntPtr gtksharp_value_create_from_type_name(ref GLib.Value val, IntPtr type_name);
[DllImport("libgobject-2.0-0.dll")] [DllImport("libgobject-2.0-0.dll")]
static extern void g_value_set_boolean (ref Value val, bool data); static extern void g_value_set_boolean (ref Value val, bool data);
@ -561,8 +566,6 @@ namespace GLib {
static extern int g_value_get_enum (ref Value val); static extern int g_value_get_enum (ref Value val);
[DllImport("libgobject-2.0-0.dll")] [DllImport("libgobject-2.0-0.dll")]
static extern uint g_value_get_flags (ref Value val); static extern uint g_value_get_flags (ref Value val);
[DllImport("glibsharpglue-2")]
static extern bool glibsharp_value_holds_flags (ref Value val);
[DllImport("libgobject-2.0-0.dll")] [DllImport("libgobject-2.0-0.dll")]
static extern bool g_type_is_a (IntPtr type, IntPtr is_a_type); static extern bool g_type_is_a (IntPtr type, IntPtr is_a_type);

View file

@ -101,13 +101,18 @@ namespace GLib {
} }
} }
[DllImport("glibsharpglue-2")] struct NativeStruct {
static extern IntPtr gtksharp_value_array_get_array (IntPtr raw); public uint n_values;
public IntPtr values;
public uint n_prealloced;
}
NativeStruct Native {
get { return (NativeStruct) Marshal.PtrToStructure (Handle, typeof(NativeStruct)); }
}
public IntPtr ArrayPtr { public IntPtr ArrayPtr {
get { get { return Native.values; }
return gtksharp_value_array_get_array (Handle);
}
} }
[DllImport("libgobject-2.0-0.dll")] [DllImport("libgobject-2.0-0.dll")]
@ -142,14 +147,9 @@ namespace GLib {
g_value_array_remove (Handle, idx); g_value_array_remove (Handle, idx);
} }
[DllImport("glibsharpglue-2")]
static extern int gtksharp_value_array_get_count (IntPtr raw);
// ICollection // ICollection
public int Count { public int Count {
get { get { return (int) Native.n_values; }
return gtksharp_value_array_get_count (Handle);
}
} }
[DllImport("libgobject-2.0-0.dll")] [DllImport("libgobject-2.0-0.dll")]

View file

@ -3,17 +3,6 @@ lib_LTLIBRARIES = libglibsharpglue-2.la
libglibsharpglue_2_la_LDFLAGS = -module -avoid-version -no-undefined libglibsharpglue_2_la_LDFLAGS = -module -avoid-version -no-undefined
libglibsharpglue_2_la_SOURCES = \ libglibsharpglue_2_la_SOURCES = \
closure.c \
error.c \
list.c \
object.c \
ptrarray.c \
signal.c \
slist.c \
type.c \
unichar.c \
value.c \
valuearray.c \
thread.c thread.c
# Adding a new glue file? # Adding a new glue file?

View file

@ -1,35 +0,0 @@
/* closure.c : Native closure implementation
*
* Author: Mike Kestner <mkestner@novell.com>
*
* Copyright (c) 2008 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 <glib-object.h>
/* Forward declarations */
GClosure* glibsharp_closure_new (GClosureMarshal marshaler, GClosureNotify notify, gpointer data);
/* */
GClosure*
glibsharp_closure_new (GClosureMarshal marshaler, GClosureNotify notify, gpointer data)
{
GClosure *closure = g_closure_new_simple (sizeof (GClosure), data);
g_closure_set_marshal (closure, marshaler);
g_closure_add_finalize_notifier (closure, data, notify);
return closure;
}

View file

@ -1,33 +0,0 @@
/* error.c : Glue to access GError values.
*
* Author: Mike Kestner <mkestner@speakeasy.net>
*
* Copyright (c) 2002 Mike Kestner
*
* 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 <glib.h>
/* Forward declarations */
gchar *gtksharp_error_get_message (GError *err);
/* */
gchar *
gtksharp_error_get_message (GError *err)
{
return err->message;
}

View file

@ -1,40 +0,0 @@
/* list.c : Glue to access fields in GList.
*
* Author: Rachel Hestilow <hestilow@ximian.com>
*
* Copyright (c) 2002 Rachel Hestilow, Mike Kestner
*
* 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 <glib/glist.h>
/* Forward declarations */
gpointer gtksharp_list_get_data (GList *l);
GList *gtksharp_list_get_next (GList *l);
/* */
gpointer
gtksharp_list_get_data (GList *l)
{
return l->data;
}
GList*
gtksharp_list_get_next (GList *l)
{
return l->next;
}

View file

@ -1,149 +0,0 @@
/* object.c : Glue to clean up GtkObject references.
*
* Author: Mike Kestner <mkestner@speakeasy.net>
*
* Copyright (c) 2002 Mike Kestner
*
* 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 <glib-object.h>
/* Forward declarations */
int gtksharp_object_get_ref_count (GObject *obj);
GObject *gtksharp_object_newv (GType type, gint cnt, gchar **names, GValue *vals);
void gtksharp_override_property_handlers(GType type, gpointer get_property_cb, gpointer set_property_cb);
GParamSpec *gtksharp_register_property(GType declaring_type, const gchar *name, const gchar *nick, const gchar *blurb, guint id, GType return_type, gboolean can_read, gboolean can_write);
/* */
int
gtksharp_object_get_ref_count (GObject *obj)
{
return obj->ref_count;
}
GObject *
gtksharp_object_newv (GType type, gint cnt, gchar **names, GValue *vals)
{
int i;
GParameter *parms = NULL;
GObject *result;
if (cnt > 0)
parms = g_new0 (GParameter, cnt);
for (i = 0; i < cnt; i++) {
parms[i].name = names[i];
parms[i].value = vals[i];
}
result = g_object_newv (type, cnt, parms);
g_free (parms);
return result;
}
void
gtksharp_override_property_handlers(GType type, gpointer get_property_cb, gpointer set_property_cb)
{
GObjectClass *type_class = g_type_class_peek (type);
if(!type_class)
type_class = g_type_class_ref (type);
type_class->get_property = get_property_cb;
type_class->set_property = set_property_cb;
}
GParamSpec *
gtksharp_register_property(GType declaring_type, const gchar *name, const gchar *nick, const gchar *blurb, guint id, GType return_type, gboolean can_read, gboolean can_write)
{
GParamSpec *param_spec;
GParamFlags flags = 0;
GObjectClass *declaring_class = g_type_class_peek (declaring_type);
if (!declaring_class)
declaring_class = g_type_class_ref (declaring_type);
if (can_read)
flags |= G_PARAM_READABLE;
if (can_write)
flags |= G_PARAM_WRITABLE;
/* Create the ParamSpec for the property
* These are used to hold default values and to validate values
* Both is not needed since the check for invalid values takes place in the managed set accessor of the property and properties do not
* contain default values. Therefore the ParamSpecs must allow every value that can be assigned to the property type.
* Furthermore the default value that is specified in the constructors will never be used and assigned to the property;
* they are not relevant, but have to be passed
*/
switch (return_type) {
case G_TYPE_CHAR:
param_spec = g_param_spec_char (name, nick, blurb, G_MININT8, G_MAXINT8, 0, flags);
break;
case G_TYPE_UCHAR:
param_spec = g_param_spec_uchar (name, nick, blurb, 0, G_MAXUINT8, 0, flags);
break;
case G_TYPE_BOOLEAN:
param_spec = g_param_spec_boolean (name, nick, blurb, FALSE, flags);
break;
case G_TYPE_INT:
param_spec = g_param_spec_int (name, nick, blurb, G_MININT, G_MAXINT, 0, flags);
break;
case G_TYPE_UINT:
param_spec = g_param_spec_uint (name, nick, blurb, 0, G_MAXUINT, 0, flags);
break;
case G_TYPE_LONG:
param_spec = g_param_spec_long (name, nick, blurb, G_MINLONG, G_MAXLONG, 0, flags);
break;
case G_TYPE_ULONG:
param_spec = g_param_spec_ulong (name, nick, blurb, 0, G_MAXULONG, 0, flags);
break;
case G_TYPE_INT64:
param_spec = g_param_spec_int64 (name, nick, blurb, G_MININT64, G_MAXINT64, 0, flags);
break;
case G_TYPE_UINT64:
param_spec = g_param_spec_uint64 (name, nick, blurb, 0, G_MAXUINT64, 0, flags);
break;
/* case G_TYPE_ENUM:
* case G_TYPE_FLAGS:
* TODO: Implement both G_TYPE_ENUM and G_TYPE_FLAGS
* My problem: Both g_param_spec_enum and g_param_spec_flags expect default property values and the members of the enum seemingly cannot be enumerated
*/
case G_TYPE_FLOAT:
param_spec = g_param_spec_float (name, nick, blurb, G_MINFLOAT, G_MAXFLOAT, 0, flags);
break;
case G_TYPE_DOUBLE:
param_spec = g_param_spec_double (name, nick, blurb, G_MINDOUBLE, G_MAXDOUBLE, 0, flags);
break;
case G_TYPE_STRING:
param_spec = g_param_spec_string (name, nick, blurb, NULL, flags);
break;
case G_TYPE_POINTER:
param_spec = g_param_spec_pointer (name, nick, blurb, flags);
break;
default:
if(return_type == G_TYPE_GTYPE)
param_spec = g_param_spec_gtype (name, nick, blurb, G_TYPE_NONE, flags);
else if(g_type_is_a (return_type, G_TYPE_BOXED))
param_spec = g_param_spec_boxed (name, nick, blurb, return_type, flags);
else if(g_type_is_a (return_type, G_TYPE_OBJECT))
param_spec = g_param_spec_object (name, nick, blurb, return_type, flags);
else
// The property's return type is not supported
return NULL;
}
g_object_class_install_property (declaring_class, id, param_spec);
return param_spec;
}

View file

@ -1,45 +0,0 @@
/* ptrarray.c : Glue to access GPtrArray fields
*
* Author: Mike Gorse <mgorse@novell.com>
*
* Copyright (c) 2008 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 <glib-object.h>
void *gtksharp_ptr_array_get_array (GPtrArray *pa);
guint gtksharp_ptr_array_get_count (GPtrArray *pa);
void *gtksharp_ptr_array_get_nth (GPtrArray *pa, int index);
void *
gtksharp_ptr_array_get_array (GPtrArray *pa)
{
return pa->pdata;
}
guint
gtksharp_ptr_array_get_count (GPtrArray *pa)
{
return pa->len;
}
void *
gtksharp_ptr_array_get_nth (GPtrArray *pa, int index)
{
return g_ptr_array_index (pa, index);
}

View file

@ -1,34 +0,0 @@
/* signal.c : Glue for signaling stuff
*
* Author: Andrés G. Aragoneses <aaragoneses@novell.com>
*
* Copyright (c) 2008 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 <glib-object.h>
/* Forward declarations */
GType glibsharp_signal_get_return_type (guint signal_id);
/* */
GType
glibsharp_signal_get_return_type (guint signal_id)
{
GSignalQuery query;
g_signal_query (signal_id, &query);
return query.return_type;
}

View file

@ -1,41 +0,0 @@
/* slist.c : Glue to access fields in GSList.
*
* Author: Rachel Hestilow <hestilow@ximian.com>
*
* Copyright (c) 2002 Rachel Hestilow, Mike Kestner
*
* 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 <glib/gslist.h>
/* Forward declarations */
gpointer gtksharp_slist_get_data (GSList *l);
GSList *gtksharp_slist_get_next (GSList *l);
/* */
gpointer
gtksharp_slist_get_data (GSList *l)
{
return l->data;
}
GSList*
gtksharp_slist_get_next (GSList *l)
{
return l->next;
}

View file

@ -1,79 +0,0 @@
/* type.c : GType utilities
*
* Author: Mike Kestner <mkestner@speakeasy.net>
*
* Copyright (c) 2002 Mike Kestner
*
* 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 <glib-object.h>
#include <stdio.h>
/* Forward declarations */
G_CONST_RETURN gchar *gtksharp_get_type_name (GObject *obj);
gboolean gtksharp_is_object (gpointer obj);
GType gtksharp_get_type_id (GObject *obj);
GType gtksharp_register_type (gchar *name, GType parent);
void gtksharp_override_virtual_method (GType g_type, const gchar *name, GCallback callback);
/* */
G_CONST_RETURN gchar *
gtksharp_get_type_name (GObject *obj)
{
return G_OBJECT_TYPE_NAME (obj);
}
gboolean
gtksharp_is_object (gpointer obj)
{
return G_IS_OBJECT (obj);
}
GType
gtksharp_get_type_id (GObject *obj)
{
return G_TYPE_FROM_INSTANCE (obj);
}
GType
gtksharp_register_type (gchar *name, GType parent)
{
GTypeQuery query;
GTypeInfo info = {0, NULL, NULL, NULL, NULL, NULL, 0, 0, NULL, NULL };
g_type_query (parent, &query);
info.class_size = query.class_size;
info.instance_size = query.instance_size;
return g_type_register_static (parent, name, &info, 0);
}
void
gtksharp_override_virtual_method (GType g_type, const gchar *name, GCallback callback)
{
guint id;
GClosure *closure;
if (g_type_class_peek (g_type) == NULL)
g_type_class_ref (g_type);
id = g_signal_lookup (name, g_type);
closure = g_cclosure_new (callback, NULL, NULL);
g_signal_override_class_closure (id, g_type, closure);
}

View file

@ -1,59 +0,0 @@
/* unichar.c : Glue to access unichars as strings.
*
* Author: Mike Kestner <mkestner@ximian.com>
*
* Copyright (c) 2004 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 <glib.h>
/* Forward declarations */
gchar *gtksharp_unichar_to_utf8_string (gunichar chr);
gunichar glibsharp_utf16_to_unichar (guint16 chr);
gssize glibsharp_strlen (gchar *s);
/* */
gchar *
gtksharp_unichar_to_utf8_string (gunichar chr)
{
gchar *buf = g_new0 (gchar, 7);
gint cnt = g_unichar_to_utf8 (chr, buf);
buf [cnt] = 0;
return buf;
}
gunichar
glibsharp_utf16_to_unichar (guint16 chr)
{
gunichar *ucs4_str;
gunichar result;
ucs4_str = g_utf16_to_ucs4 (&chr, 1, NULL, NULL, NULL);
result = *ucs4_str;
g_free (ucs4_str);
return result;
}
gssize
glibsharp_strlen (gchar *s)
{
gssize cnt = 0;
for (cnt = 0; *s; s++, cnt++);
return cnt;
}

View file

@ -1,69 +0,0 @@
/* value.c : Glue to allocate GValues on the heap.
*
* Author: Mike Kestner <mkestner@speakeasy.net>
*
* Copyright (c) 2002 Mike Kestner
*
* 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 <glib-object.h>
/* Forward declarations */
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);
gpointer glibsharp_value_get_boxed (GValue *value);
void glibsharp_value_set_boxed (GValue *value, gpointer boxed);
gboolean glibsharp_value_holds_flags (GValue *value);
/* */
void
gtksharp_value_create_from_property (GValue *value, GObject *obj, const gchar* name)
{
GParamSpec *spec = g_object_class_find_property (G_OBJECT_GET_CLASS (obj), name);
g_value_init (value, spec->value_type);
}
void
gtksharp_value_create_from_type_and_property (GValue *value, GType gtype, const gchar* name)
{
GParamSpec *spec = g_object_class_find_property (g_type_class_ref (gtype), name);
g_value_init (value, spec->value_type);
}
void
gtksharp_value_create_from_type_name (GValue *value, const gchar *type_name)
{
g_value_init (value, g_type_from_name (type_name));
}
gpointer
glibsharp_value_get_boxed (GValue *value)
{
return g_value_get_boxed (value);
}
void
glibsharp_value_set_boxed (GValue *value, gpointer boxed)
{
g_value_set_boxed (value, boxed);
}
gboolean
glibsharp_value_holds_flags (GValue *value)
{
return G_VALUE_HOLDS_FLAGS (value);
}

View file

@ -1,38 +0,0 @@
/* valuearray.c : Glue to access GValueArray fields
*
* Author: Mike Kestner <mkestner@ximian.com>
*
* Copyright (c) 2004 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 <glib-object.h>
GValue *gtksharp_value_array_get_array (GValueArray *va);
guint gtksharp_value_array_get_count (GValueArray *va);
GValue *
gtksharp_value_array_get_array (GValueArray *va)
{
return va->values;
}
guint
gtksharp_value_array_get_count (GValueArray *va)
{
return va->n_values;
}

View file

@ -19,17 +19,12 @@
// Boston, MA 02111-1307, USA. // Boston, MA 02111-1307, USA.
[DllImport("glibsharpglue-2")]
static extern IntPtr gtksharp_unichar_to_utf8_string (int raw);
[DllImport("libgtk-win32-2.0-0.dll")] [DllImport("libgtk-win32-2.0-0.dll")]
static extern int gtk_text_iter_get_char(ref Gtk.TextIter raw); static extern uint gtk_text_iter_get_char(ref Gtk.TextIter raw);
public string Char { public string Char {
get { get {
IntPtr raw_ret = gtksharp_unichar_to_utf8_string (gtk_text_iter_get_char (ref this)); return GLib.Marshaller.GUnicharToString (gtk_text_iter_get_char (ref this));
string ret = GLib.Marshaller.PtrToStringGFree(raw_ret);
return ret;
} }
} }

View file

@ -32,12 +32,9 @@ namespace Pango {
internal AttrBackground (IntPtr raw) : base (raw) {} internal AttrBackground (IntPtr raw) : base (raw) {}
[DllImport("pangosharpglue-2")]
static extern Pango.Color pangosharp_attr_color_get_color (IntPtr raw);
public Pango.Color Color { public Pango.Color Color {
get { get {
return pangosharp_attr_color_get_color (Handle); return AttrColor.New (Handle).Color;
} }
} }
} }

33
pango/AttrColor.cs Normal file
View file

@ -0,0 +1,33 @@
// Pango.AttrColor - Pango.Attribute for Colors
//
// Copyright (c) 2008 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.
namespace Pango {
using System;
using System.Runtime.InteropServices;
internal struct AttrColor {
Attribute.NativeStruct attr;
public Color Color;
public static AttrColor New (IntPtr raw)
{
return (AttrColor) Marshal.PtrToStructure (raw, typeof (AttrColor));
}
}
}

View file

@ -30,12 +30,9 @@ namespace Pango {
internal AttrFallback (IntPtr raw) : base (raw) {} internal AttrFallback (IntPtr raw) : base (raw) {}
[DllImport("pangosharpglue-2")]
static extern int pangosharp_attr_int_get_value (IntPtr raw);
public bool Fallback { public bool Fallback {
get { get {
return pangosharp_attr_int_get_value (Handle) != 0; return AttrInt.New (Handle).Value != 0;
} }
} }
} }

View file

@ -38,13 +38,15 @@ namespace Pango {
internal AttrFamily (IntPtr raw) : base (raw) {} internal AttrFamily (IntPtr raw) : base (raw) {}
[DllImport("pangosharpglue-2")] new struct NativeStruct {
static extern IntPtr pangosharp_attr_string_get_value (IntPtr raw); Attribute.NativeStruct attr;
public IntPtr value;
}
public string Family { public string Family {
get { get {
IntPtr raw_family = pangosharp_attr_string_get_value (Handle); NativeStruct native = (NativeStruct) Marshal.PtrToStructure (Handle, typeof (NativeStruct));
return GLib.Marshaller.Utf8PtrToString (raw_family); return GLib.Marshaller.Utf8PtrToString (native.value);
} }
} }
} }

33
pango/AttrFloat.cs Normal file
View file

@ -0,0 +1,33 @@
// Pango.AttrFloat - Pango.Attribute for floating point values
//
// Copyright (c) 2008 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.
namespace Pango {
using System;
using System.Runtime.InteropServices;
internal struct AttrFloat {
Attribute.NativeStruct attr;
public double Value;
public static AttrFloat New (IntPtr raw)
{
return (AttrFloat) Marshal.PtrToStructure (raw, typeof (AttrFloat));
}
}
}

View file

@ -33,13 +33,15 @@ namespace Pango {
internal AttrFontDesc (IntPtr raw) : base (raw) {} internal AttrFontDesc (IntPtr raw) : base (raw) {}
[DllImport("pangosharpglue-2")] new struct NativeStruct {
static extern IntPtr pangosharp_attr_font_desc_get_desc (IntPtr raw); Attribute.NativeStruct attr;
public IntPtr desc;
}
public Pango.FontDescription Desc { public Pango.FontDescription Desc {
get { get {
IntPtr raw_ret = pangosharp_attr_font_desc_get_desc (Handle); NativeStruct native = (NativeStruct) Marshal.PtrToStructure (Handle, typeof (NativeStruct));
return new Pango.FontDescription (raw_ret); return new Pango.FontDescription (native.desc);
} }
} }
} }

View file

@ -32,12 +32,9 @@ namespace Pango {
internal AttrForeground (IntPtr raw) : base (raw) {} internal AttrForeground (IntPtr raw) : base (raw) {}
[DllImport("pangosharpglue-2")]
static extern Pango.Color pangosharp_attr_color_get_color (IntPtr raw);
public Pango.Color Color { public Pango.Color Color {
get { get {
return pangosharp_attr_color_get_color (Handle); return AttrColor.New (Handle).Color;
} }
} }
} }

View file

@ -30,12 +30,9 @@ namespace Pango {
internal AttrGravity (IntPtr raw) : base (raw) {} internal AttrGravity (IntPtr raw) : base (raw) {}
[DllImport("pangosharpglue-2")]
static extern int pangosharp_attr_int_get_value (IntPtr raw);
public Gravity Gravity { public Gravity Gravity {
get { get {
return (Gravity) pangosharp_attr_int_get_value (Handle); return (Gravity) (AttrInt.New (Handle).Value);
} }
} }
} }

View file

@ -30,12 +30,9 @@ namespace Pango {
internal AttrGravityHint (IntPtr raw) : base (raw) {} internal AttrGravityHint (IntPtr raw) : base (raw) {}
[DllImport("pangosharpglue-2")]
static extern int pangosharp_attr_int_get_value (IntPtr raw);
public GravityHint GravityHint { public GravityHint GravityHint {
get { get {
return (GravityHint) pangosharp_attr_int_get_value (Handle); return (GravityHint) (AttrInt.New (Handle).Value);
} }
} }
} }

33
pango/AttrInt.cs Normal file
View file

@ -0,0 +1,33 @@
// Pango.AttrInt - Pango.Attribute for integer values
//
// Copyright (c) 2008 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.
namespace Pango {
using System;
using System.Runtime.InteropServices;
internal struct AttrInt {
Attribute.NativeStruct attr;
public int Value;
public static AttrInt New (IntPtr raw)
{
return (AttrInt) Marshal.PtrToStructure (raw, typeof (AttrInt));
}
}
}

View file

@ -30,13 +30,15 @@ namespace Pango {
internal AttrLanguage (IntPtr raw) : base (raw) {} internal AttrLanguage (IntPtr raw) : base (raw) {}
[DllImport("pangosharpglue-2")] new struct NativeStruct {
static extern IntPtr pangosharp_attr_language_get_value (IntPtr raw); Attribute.NativeStruct attr;
public IntPtr value;
}
public Pango.Language Language { public Pango.Language Language {
get { get {
IntPtr raw_ret = pangosharp_attr_language_get_value (Handle); NativeStruct native = (NativeStruct) Marshal.PtrToStructure (Handle, typeof (NativeStruct));
return new Pango.Language (raw_ret); return new Pango.Language (native.value);
} }
} }
} }

View file

@ -30,12 +30,9 @@ namespace Pango {
internal AttrLetterSpacing (IntPtr raw) : base (raw) {} internal AttrLetterSpacing (IntPtr raw) : base (raw) {}
[DllImport("pangosharpglue-2")]
static extern int pangosharp_attr_int_get_value (IntPtr raw);
public int LetterSpacing { public int LetterSpacing {
get { get {
return pangosharp_attr_int_get_value (Handle); return AttrInt.New (Handle).Value;
} }
} }
} }

View file

@ -30,12 +30,9 @@ namespace Pango {
internal AttrRise (IntPtr raw) : base (raw) {} internal AttrRise (IntPtr raw) : base (raw) {}
[DllImport("pangosharpglue-2")]
static extern int pangosharp_attr_int_get_value (IntPtr raw);
public int Rise { public int Rise {
get { get {
return pangosharp_attr_int_get_value (Handle); return AttrInt.New (Handle).Value;
} }
} }
} }

View file

@ -30,12 +30,9 @@ namespace Pango {
internal AttrScale (IntPtr raw) : base (raw) {} internal AttrScale (IntPtr raw) : base (raw) {}
[DllImport("pangosharpglue-2")]
static extern double pangosharp_attr_float_get_value (IntPtr raw);
public double Scale { public double Scale {
get { get {
return pangosharp_attr_float_get_value (Handle); return AttrFloat.New (Handle).Value;
} }
} }
} }

View file

@ -30,21 +30,26 @@ namespace Pango {
internal AttrShape (IntPtr raw) : base (raw) {} internal AttrShape (IntPtr raw) : base (raw) {}
[DllImport("pangosharpglue-2")] new struct NativeStruct {
static extern Pango.Rectangle pangosharp_attr_shape_get_ink_rect (IntPtr raw); Attribute.NativeStruct attr;
public Rectangle ink_rect;
public Rectangle logical_rect;
IntPtr data;
IntPtr copy_func;
IntPtr destroy_func;
}
public Pango.Rectangle InkRect { public Pango.Rectangle InkRect {
get { get {
return pangosharp_attr_shape_get_ink_rect (Handle); NativeStruct native = (NativeStruct) Marshal.PtrToStructure (Handle, typeof (NativeStruct));
return native.ink_rect;
} }
} }
[DllImport("pangosharpglue-2")]
static extern Pango.Rectangle pangosharp_attr_shape_get_logical_rect (IntPtr raw);
public Pango.Rectangle LogicalRect { public Pango.Rectangle LogicalRect {
get { get {
return pangosharp_attr_shape_get_logical_rect (Handle); NativeStruct native = (NativeStruct) Marshal.PtrToStructure (Handle, typeof (NativeStruct));
return native.logical_rect;
} }
} }
} }

View file

@ -35,21 +35,23 @@ namespace Pango {
internal AttrSize (IntPtr raw) : base (raw) {} internal AttrSize (IntPtr raw) : base (raw) {}
[DllImport("pangosharpglue-2")] new struct NativeStruct {
static extern int pangosharp_attr_size_get_size (IntPtr raw); Attribute.NativeStruct attr;
public int sz;
public uint absolute;
}
public int Size { public int Size {
get { get {
return pangosharp_attr_size_get_size (Handle); NativeStruct native = (NativeStruct) Marshal.PtrToStructure (Handle, typeof (NativeStruct));
return native.sz;
} }
} }
[DllImport("pangosharpglue-2")]
static extern bool pangosharp_attr_size_get_absolute (IntPtr raw);
public bool Absolute { public bool Absolute {
get { get {
return pangosharp_attr_size_get_absolute (Handle); NativeStruct native = (NativeStruct) Marshal.PtrToStructure (Handle, typeof (NativeStruct));
return native.absolute != 0;
} }
} }
} }

View file

@ -30,12 +30,9 @@ namespace Pango {
internal AttrStretch (IntPtr raw) : base (raw) {} internal AttrStretch (IntPtr raw) : base (raw) {}
[DllImport("pangosharpglue-2")]
static extern int pangosharp_attr_int_get_value (IntPtr raw);
public Pango.Stretch Stretch { public Pango.Stretch Stretch {
get { get {
return (Pango.Stretch)pangosharp_attr_int_get_value (Handle); return (Pango.Stretch) (AttrInt.New (Handle).Value);
} }
} }
} }

View file

@ -30,12 +30,9 @@ namespace Pango {
internal AttrStrikethrough (IntPtr raw) : base (raw) {} internal AttrStrikethrough (IntPtr raw) : base (raw) {}
[DllImport("pangosharpglue-2")]
static extern int pangosharp_attr_int_get_value (IntPtr raw);
public bool Strikethrough { public bool Strikethrough {
get { get {
return pangosharp_attr_int_get_value (Handle) != 0; return AttrInt.New (Handle).Value != 0;
} }
} }
} }

View file

@ -32,12 +32,9 @@ namespace Pango {
internal AttrStrikethroughColor (IntPtr raw) : base (raw) {} internal AttrStrikethroughColor (IntPtr raw) : base (raw) {}
[DllImport("pangosharpglue-2")]
static extern Pango.Color pangosharp_attr_color_get_color (IntPtr raw);
public Pango.Color Color { public Pango.Color Color {
get { get {
return pangosharp_attr_color_get_color (Handle); return AttrColor.New (Handle).Color;
} }
} }
} }

View file

@ -30,12 +30,9 @@ namespace Pango {
internal AttrStyle (IntPtr raw) : base (raw) {} internal AttrStyle (IntPtr raw) : base (raw) {}
[DllImport("pangosharpglue-2")]
static extern int pangosharp_attr_int_get_value (IntPtr raw);
public Pango.Style Style { public Pango.Style Style {
get { get {
return (Pango.Style)pangosharp_attr_int_get_value (Handle); return (Pango.Style) (AttrInt.New (Handle).Value);
} }
} }
} }

View file

@ -30,12 +30,9 @@ namespace Pango {
internal AttrUnderline (IntPtr raw) : base (raw) {} internal AttrUnderline (IntPtr raw) : base (raw) {}
[DllImport("pangosharpglue-2")]
static extern int pangosharp_attr_int_get_value (IntPtr raw);
public Pango.Underline Underline { public Pango.Underline Underline {
get { get {
return (Pango.Underline)pangosharp_attr_int_get_value (Handle); return (Pango.Underline) (AttrInt.New (Handle).Value);
} }
} }
} }

View file

@ -32,12 +32,9 @@ namespace Pango {
internal AttrUnderlineColor (IntPtr raw) : base (raw) {} internal AttrUnderlineColor (IntPtr raw) : base (raw) {}
[DllImport("pangosharpglue-2")]
static extern Pango.Color pangosharp_attr_color_get_color (IntPtr raw);
public Pango.Color Color { public Pango.Color Color {
get { get {
return pangosharp_attr_color_get_color (Handle); return AttrColor.New (Handle).Color;
} }
} }
} }

View file

@ -30,12 +30,9 @@ namespace Pango {
internal AttrVariant (IntPtr raw) : base (raw) {} internal AttrVariant (IntPtr raw) : base (raw) {}
[DllImport("pangosharpglue-2")]
static extern int pangosharp_attr_int_get_value (IntPtr raw);
public Pango.Variant Variant { public Pango.Variant Variant {
get { get {
return (Pango.Variant)pangosharp_attr_int_get_value (Handle); return (Pango.Variant) (AttrInt.New (Handle).Value);
} }
} }
} }

View file

@ -30,12 +30,9 @@ namespace Pango {
internal AttrWeight (IntPtr raw) : base (raw) {} internal AttrWeight (IntPtr raw) : base (raw) {}
[DllImport("pangosharpglue-2")]
static extern int pangosharp_attr_int_get_value (IntPtr raw);
public Pango.Weight Weight { public Pango.Weight Weight {
get { get {
return (Pango.Weight)pangosharp_attr_int_get_value (Handle); return (Pango.Weight) (AttrInt.New (Handle).Value);
} }
} }
} }

View file

@ -1,6 +1,6 @@
// Pango.Attribute - Attribute "base class" // Pango.Attribute - Attribute "base class"
// //
// Copyright (c) 2005, 2007 Novell, Inc. // Copyright (c) 2005, 2007, 2008 Novell, Inc.
// //
// This program is free software; you can redistribute it and/or // This program is free software; you can redistribute it and/or
// modify it under the terms of version 2 of the Lesser GNU General // modify it under the terms of version 2 of the Lesser GNU General
@ -30,12 +30,17 @@ namespace Pango {
this.raw = raw; this.raw = raw;
} }
[DllImport("pangosharpglue-2")] static Pango.AttrType GetAttrType (IntPtr raw)
static extern Pango.AttrType pangosharp_attribute_get_attr_type (IntPtr raw); {
if (raw == IntPtr.Zero)
return AttrType.Invalid;
IntPtr klass = Marshal.ReadIntPtr (raw);
return (AttrType) Marshal.ReadInt32 (klass);
}
public static Attribute GetAttribute (IntPtr raw) public static Attribute GetAttribute (IntPtr raw)
{ {
switch (pangosharp_attribute_get_attr_type (raw)) { switch (GetAttrType (raw)) {
case Pango.AttrType.Language: case Pango.AttrType.Language:
return new AttrLanguage (raw); return new AttrLanguage (raw);
case Pango.AttrType.Family: case Pango.AttrType.Family:
@ -117,38 +122,34 @@ namespace Pango {
} }
public Pango.AttrType Type { public Pango.AttrType Type {
get { get { return GetAttrType (raw); }
return pangosharp_attribute_get_attr_type (raw);
}
} }
[DllImport("pangosharpglue-2")] internal struct NativeStruct {
static extern uint pangosharp_attribute_get_start_index (IntPtr raw); IntPtr klass;
public uint start_index;
public uint end_index;
}
[DllImport("pangosharpglue-2")] NativeStruct Native {
static extern void pangosharp_attribute_set_start_index (IntPtr raw, uint index); get { return (NativeStruct) Marshal.PtrToStructure (raw, typeof(NativeStruct)); }
}
public uint StartIndex { public uint StartIndex {
get { get { return Native.start_index; }
return pangosharp_attribute_get_start_index (raw);
}
set { set {
pangosharp_attribute_set_start_index (raw, value); NativeStruct native = Native;
native.start_index = value;
Marshal.StructureToPtr (native, raw, false);
} }
} }
[DllImport("pangosharpglue-2")]
static extern uint pangosharp_attribute_get_end_index (IntPtr raw);
[DllImport("pangosharpglue-2")]
static extern void pangosharp_attribute_set_end_index (IntPtr raw, uint index);
public uint EndIndex { public uint EndIndex {
get { get { return Native.end_index; }
return pangosharp_attribute_get_end_index (raw);
}
set { set {
pangosharp_attribute_set_end_index (raw, value); NativeStruct native = Native;
native.end_index = value;
Marshal.StructureToPtr (native, raw, false);
} }
} }

View file

@ -15,12 +15,15 @@ glue_includes = pango/pango.h
sources = \ sources = \
Attribute.cs \ Attribute.cs \
AttrBackground.cs \ AttrBackground.cs \
AttrColor.cs \
AttrFallback.cs \ AttrFallback.cs \
AttrFamily.cs \ AttrFamily.cs \
AttrFloat.cs \
AttrFontDesc.cs \ AttrFontDesc.cs \
AttrForeground.cs \ AttrForeground.cs \
AttrGravity.cs \ AttrGravity.cs \
AttrGravityHint.cs \ AttrGravityHint.cs \
AttrInt.cs \
AttrLanguage.cs \ AttrLanguage.cs \
AttrLetterSpacing.cs \ AttrLetterSpacing.cs \
AttrRise.cs \ AttrRise.cs \

View file

@ -20,19 +20,13 @@
private Units () {} private Units () {}
[DllImport("pangosharpglue-2")]
static extern int pangosharp_pixels (int units);
[DllImport("pangosharpglue-2")]
static extern int pangosharp_scale ();
public static int FromPixels (int pixels) public static int FromPixels (int pixels)
{ {
return pixels * pangosharp_scale (); return pixels * 1024;
} }
public static int ToPixels (int units) public static int ToPixels (int units)
{ {
return pangosharp_pixels (units); return (units + 512) >> 10;
} }

View file

@ -1,8 +1,6 @@
lib_LTLIBRARIES = libpangosharpglue-2.la lib_LTLIBRARIES = libpangosharpglue-2.la
libpangosharpglue_2_la_SOURCES = \ libpangosharpglue_2_la_SOURCES =
attribute.c \
units.c
nodist_libpangosharpglue_2_la_SOURCES = generated.c nodist_libpangosharpglue_2_la_SOURCES = generated.c

View file

@ -1,134 +0,0 @@
/* attribute.c : Glue to access fields in PangoAttribute and
* subclasses.
*
* 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 <pango/pango-attributes.h>
/* Forward declarations */
PangoAttrType pangosharp_attribute_get_attr_type (PangoAttribute *attr);
guint pangosharp_attribute_get_start_index (PangoAttribute *attr);
void pangosharp_attribute_set_start_index (PangoAttribute *attr, guint ind);
guint pangosharp_attribute_get_end_index (PangoAttribute *attr);
void pangosharp_attribute_set_end_index (PangoAttribute *attr, guint ind);
const char *pangosharp_attr_string_get_value (PangoAttrString *attr);
PangoLanguage *pangosharp_attr_language_get_value (PangoAttrLanguage *attr);
PangoColor pangosharp_attr_color_get_color (PangoAttrColor *attr);
int pangosharp_attr_int_get_value (PangoAttrInt *attr);
double pangosharp_attr_float_get_value (PangoAttrFloat *attr);
PangoFontDescription *pangosharp_attr_font_desc_get_desc (PangoAttrFontDesc *attr);
PangoRectangle pangosharp_attr_shape_get_ink_rect (PangoAttrShape *attr);
PangoRectangle pangosharp_attr_shape_get_logical_rect (PangoAttrShape *attr);
#ifdef GTK_SHARP_2_6
int pangosharp_attr_size_get_size (PangoAttrSize *attr);
gboolean pangosharp_attr_size_get_absolute (PangoAttrSize *attr);
#endif
/* */
PangoAttrType
pangosharp_attribute_get_attr_type (PangoAttribute *attr)
{
return attr->klass->type;
}
guint
pangosharp_attribute_get_start_index (PangoAttribute *attr)
{
return attr->start_index;
}
void
pangosharp_attribute_set_start_index (PangoAttribute *attr, guint ind)
{
attr->start_index = ind;
}
guint
pangosharp_attribute_get_end_index (PangoAttribute *attr)
{
return attr->end_index;
}
void
pangosharp_attribute_set_end_index (PangoAttribute *attr, guint ind)
{
attr->end_index = ind;
}
const char *
pangosharp_attr_string_get_value (PangoAttrString *attr)
{
return attr->value;
}
PangoLanguage *
pangosharp_attr_language_get_value (PangoAttrLanguage *attr)
{
return attr->value;
}
PangoColor
pangosharp_attr_color_get_color (PangoAttrColor *attr)
{
return attr->color;
}
int
pangosharp_attr_int_get_value (PangoAttrInt *attr)
{
return attr->value;
}
double
pangosharp_attr_float_get_value (PangoAttrFloat *attr)
{
return attr->value;
}
PangoFontDescription *
pangosharp_attr_font_desc_get_desc (PangoAttrFontDesc *attr)
{
return attr->desc;
}
PangoRectangle
pangosharp_attr_shape_get_ink_rect (PangoAttrShape *attr)
{
return attr->ink_rect;
}
PangoRectangle
pangosharp_attr_shape_get_logical_rect (PangoAttrShape *attr)
{
return attr->logical_rect;
}
#ifdef GTK_SHARP_2_6
int
pangosharp_attr_size_get_size (PangoAttrSize *attr)
{
return attr->size;
}
gboolean
pangosharp_attr_size_get_absolute (PangoAttrSize *attr)
{
return attr->absolute;
}
#endif

View file

@ -1,39 +0,0 @@
/* units.c : Glue to access unit macros.
*
* Author: Mike Kestner <mkestner@novell.com>
*
* 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 <pango/pango.h>
/* Forward declarations */
int pangosharp_scale (void);
int pangosharp_pixels (int units);
/* */
gint
pangosharp_scale ()
{
return PANGO_SCALE;
}
gint
pangosharp_pixels (gint units)
{
return PANGO_PIXELS (units);
}

View file

@ -14,31 +14,435 @@ namespace GtkSamples {
{ {
GLib.GType.Init (); GLib.GType.Init ();
TestObject obj = new TestObject (); TestObject obj = new TestObject ();
GLib.Value val = new GLib.Value (42); obj.TestInt ();
obj.SetProperty ("my_prop", val); obj.TestUInt ();
val.Dispose (); obj.TestLong ();
if (obj.MyProp != 42) { obj.TestULong ();
Console.Error.WriteLine ("Property setter did not run."); obj.TestByte ();
return 1; obj.TestSByte ();
} obj.TestBool ();
GLib.Value val2 = obj.GetProperty ("my_prop"); obj.TestFloat ();
if ((int)val2.Val != 42) { obj.TestDouble ();
Console.Error.WriteLine ("Property set/get roundtrip failed."); obj.TestString ();
return 1; //obj.TestIntPtr ();
} //obj.TestBoxed ();
Console.WriteLine ("Round trip succeeded."); obj.TestGObject ();
Console.WriteLine ("All properties succeeded.");
return 0; return 0;
} }
int my_prop; int my_int;
[GLib.Property ("my_int")]
[GLib.Property ("my_prop")] public int MyInt {
public int MyProp { get { return my_int; }
get { return my_prop; } set { my_int = value; }
set {
my_prop = value;
Console.WriteLine ("Property setter invoked.");
}
} }
public void TestInt ()
{
GLib.Value val = new GLib.Value (42);
SetProperty ("my_int", val);
val.Dispose ();
if (MyInt != 42) {
Console.Error.WriteLine ("int Property setter did not run.");
Environment.Exit (1);
}
GLib.Value val2 = GetProperty ("my_int");
if ((int)val2.Val != 42) {
Console.Error.WriteLine ("int Property set/get roundtrip failed.");
Environment.Exit (1);
}
Console.WriteLine ("int succeeded.");
}
uint my_uint;
[GLib.Property ("my_uint")]
public uint MyUInt {
get { return my_uint; }
set { my_uint = value; }
}
public void TestUInt ()
{
GLib.Value val = new GLib.Value ((uint)42);
SetProperty ("my_uint", val);
val.Dispose ();
if (MyUInt != 42) {
Console.Error.WriteLine ("uint Property setter did not run.");
Environment.Exit (1);
}
GLib.Value val2 = GetProperty ("my_uint");
if ((uint)val2.Val != 42) {
Console.Error.WriteLine ("uint Property set/get roundtrip failed.");
Environment.Exit (1);
}
Console.WriteLine ("uint succeeded.");
}
long my_long;
[GLib.Property ("my_long")]
public long MyLong {
get { return my_long; }
set { my_long = value; }
}
public void TestLong ()
{
GLib.Value val = new GLib.Value ((long)42);
SetProperty ("my_long", val);
val.Dispose ();
if (MyLong != 42) {
Console.Error.WriteLine ("long Property setter did not run.");
Environment.Exit (1);
}
GLib.Value val2 = GetProperty ("my_long");
if ((long)val2.Val != 42) {
Console.Error.WriteLine ("long Property set/get roundtrip failed.");
Environment.Exit (1);
}
Console.WriteLine ("long succeeded.");
}
ulong my_ulong;
[GLib.Property ("my_ulong")]
public ulong MyULong {
get { return my_ulong; }
set { my_ulong = value; }
}
public void TestULong ()
{
GLib.Value val = new GLib.Value ((ulong)42);
SetProperty ("my_ulong", val);
val.Dispose ();
if (MyULong != 42) {
Console.Error.WriteLine ("ulong Property setter did not run.");
Environment.Exit (1);
}
GLib.Value val2 = GetProperty ("my_ulong");
if ((ulong)val2.Val != 42) {
Console.Error.WriteLine ("ulong Property set/get roundtrip failed.");
Environment.Exit (1);
}
Console.WriteLine ("ulong succeeded.");
}
byte my_byte;
[GLib.Property ("my_byte")]
public byte MyByte {
get { return my_byte; }
set { my_byte = value; }
}
public void TestByte ()
{
GLib.Value val = new GLib.Value ((byte)42);
SetProperty ("my_byte", val);
val.Dispose ();
if (MyByte != 42) {
Console.Error.WriteLine ("byte Property setter did not run.");
Environment.Exit (1);
}
GLib.Value val2 = GetProperty ("my_byte");
if ((byte)val2.Val != 42) {
Console.Error.WriteLine ("byte Property set/get roundtrip failed.");
Environment.Exit (1);
}
Console.WriteLine ("byte succeeded.");
}
sbyte my_sbyte;
[GLib.Property ("my_sbyte")]
public sbyte MySByte {
get { return my_sbyte; }
set { my_sbyte = value; }
}
public void TestSByte ()
{
GLib.Value val = new GLib.Value ((sbyte)42);
SetProperty ("my_sbyte", val);
val.Dispose ();
if (MySByte != 42) {
Console.Error.WriteLine ("sbyte Property setter did not run.");
Environment.Exit (1);
}
GLib.Value val2 = GetProperty ("my_sbyte");
if ((sbyte)val2.Val != 42) {
Console.Error.WriteLine ("sbyte Property set/get roundtrip failed.");
Environment.Exit (1);
}
Console.WriteLine ("sbyte succeeded.");
}
bool my_bool;
[GLib.Property ("my_bool")]
public bool MyBool {
get { return my_bool; }
set { my_bool = value; }
}
public void TestBool ()
{
GLib.Value val = new GLib.Value (true);
SetProperty ("my_bool", val);
val.Dispose ();
if (!MyBool) {
Console.Error.WriteLine ("bool Property setter did not run.");
Environment.Exit (1);
}
GLib.Value val2 = GetProperty ("my_bool");
if (!((bool)val2.Val)) {
Console.Error.WriteLine ("bool Property set/get roundtrip failed.");
Environment.Exit (1);
}
Console.WriteLine ("bool succeeded.");
}
float my_float;
[GLib.Property ("my_float")]
public float MyFloat {
get { return my_float; }
set { my_float = value; }
}
public void TestFloat ()
{
GLib.Value val = new GLib.Value (42.0f);
SetProperty ("my_float", val);
val.Dispose ();
if (MyFloat != 42.0f) {
Console.Error.WriteLine ("float Property setter did not run.");
Environment.Exit (1);
}
GLib.Value val2 = GetProperty ("my_float");
if ((float)val2.Val != 42.0f) {
Console.Error.WriteLine ("float Property set/get roundtrip failed.");
Environment.Exit (1);
}
Console.WriteLine ("float succeeded.");
}
double my_double;
[GLib.Property ("my_double")]
public double MyDouble {
get { return my_double; }
set { my_double = value; }
}
public void TestDouble ()
{
GLib.Value val = new GLib.Value (42.0);
SetProperty ("my_double", val);
val.Dispose ();
if (MyDouble != 42.0) {
Console.Error.WriteLine ("double Property setter did not run.");
Environment.Exit (1);
}
GLib.Value val2 = GetProperty ("my_double");
if ((double)val2.Val != 42.0) {
Console.Error.WriteLine ("double Property set/get roundtrip failed.");
Environment.Exit (1);
}
Console.WriteLine ("double succeeded.");
}
string my_string;
[GLib.Property ("my_string")]
public string MyString {
get { return my_string; }
set { my_string = value; }
}
public void TestString ()
{
GLib.Value val = new GLib.Value ("42");
SetProperty ("my_string", val);
val.Dispose ();
if (MyString != "42") {
Console.Error.WriteLine ("string Property setter did not run.");
Environment.Exit (1);
}
GLib.Value val2 = GetProperty ("my_string");
if ((string)val2.Val != "42") {
Console.Error.WriteLine ("string Property set/get roundtrip failed.");
Environment.Exit (1);
}
Console.WriteLine ("string succeeded.");
}
#if false
IntPtr my_intptr;
[GLib.Property ("my_intptr")]
public IntPtr MyIntPtr {
get { return my_intptr; }
set { my_intptr = value; }
}
public void TestIntPtr ()
{
IntPtr ptr = System.Runtime.InteropServices.Marshal.AllocHGlobal (4);
Console.WriteLine (ptr);
GLib.Value val = new GLib.Value (ptr);
SetProperty ("my_intptr", val);
val.Dispose ();
if (MyIntPtr != ptr) {
Console.Error.WriteLine ("IntPtr Property setter did not run.");
Environment.Exit (1);
}
GLib.Value val2 = GetProperty ("my_intptr");
Console.WriteLine (val2.Val);
if (!val2.Val.Equals (ptr)) {
Console.Error.WriteLine ("IntPtr Property set/get roundtrip failed.");
Environment.Exit (1);
}
Console.WriteLine ("IntPtr succeeded.");
}
Gdk.Color my_boxed;
[GLib.Property ("my_boxed")]
public Gdk.Color MyBoxed {
get { return my_boxed; }
set { my_boxed = value; }
}
public void TestBoxed ()
{
Gdk.Color color = new Gdk.Color (0, 0, 0);
GLib.Value val = (GLib.Value) color;
SetProperty ("my_boxed", val);
val.Dispose ();
if (!MyBoxed.Equals (color)) {
Console.Error.WriteLine ("boxed Property setter did not run.");
Environment.Exit (1);
}
GLib.Value val2 = GetProperty ("my_boxed");
if (color.Equals ((Gdk.Color)val2.Val)) {
Console.Error.WriteLine ("boxed Property set/get roundtrip failed.");
Environment.Exit (1);
}
Console.WriteLine ("boxed succeeded.");
}
#endif
GLib.Object my_object;
[GLib.Property ("my_object")]
public GLib.Object MyObject {
get { return my_object; }
set { my_object = value; }
}
public void TestGObject ()
{
Gtk.Window win = new Gtk.Window ("test");
GLib.Value val = new GLib.Value (win);
SetProperty ("my_object", val);
val.Dispose ();
if (MyObject != win) {
Console.Error.WriteLine ("GObject Property setter did not run.");
Environment.Exit (1);
}
GLib.Value val2 = GetProperty ("my_object");
if ((GLib.Object)val2.Val != win) {
Console.Error.WriteLine ("GObject Property set/get roundtrip failed.");
Environment.Exit (1);
}
Console.WriteLine ("GObject succeeded.");
}
#if false
int my_int;
[GLib.Property ("my_int")]
public int MyInt {
get { return my_int; }
set { my_int = value; }
}
public void TestInt ()
{
GLib.Value val = new GLib.Value (42);
SetProperty ("my_int", val);
val.Dispose ();
if (MyInt != 42) {
Console.Error.WriteLine ("Property setter did not run.");
Environment.Exit (1);
}
GLib.Value val2 = GetProperty ("my_int");
if ((int)val2.Val != 42) {
Console.Error.WriteLine ("Property set/get roundtrip failed.");
Environment.Exit (1);
}
}
int my_int;
[GLib.Property ("my_int")]
public int MyInt {
get { return my_int; }
set { my_int = value; }
}
public void TestInt ()
{
GLib.Value val = new GLib.Value (42);
SetProperty ("my_int", val);
val.Dispose ();
if (MyInt != 42) {
Console.Error.WriteLine ("Property setter did not run.");
Environment.Exit (1);
}
GLib.Value val2 = GetProperty ("my_int");
if ((int)val2.Val != 42) {
Console.Error.WriteLine ("Property set/get roundtrip failed.");
Environment.Exit (1);
}
}
int my_int;
[GLib.Property ("my_int")]
public int MyInt {
get { return my_int; }
set { my_int = value; }
}
public void TestInt ()
{
GLib.Value val = new GLib.Value (42);
SetProperty ("my_int", val);
val.Dispose ();
if (MyInt != 42) {
Console.Error.WriteLine ("Property setter did not run.");
Environment.Exit (1);
}
GLib.Value val2 = GetProperty ("my_int");
if ((int)val2.Val != 42) {
Console.Error.WriteLine ("Property set/get roundtrip failed.");
Environment.Exit (1);
}
}
int my_int;
[GLib.Property ("my_int")]
public int MyInt {
get { return my_int; }
set { my_int = value; }
}
public void TestInt ()
{
GLib.Value val = new GLib.Value (42);
SetProperty ("my_int", val);
val.Dispose ();
if (MyInt != 42) {
Console.Error.WriteLine ("Property setter did not run.");
Environment.Exit (1);
}
GLib.Value val2 = GetProperty ("my_int");
if ((int)val2.Val != 42) {
Console.Error.WriteLine ("Property set/get roundtrip failed.");
Environment.Exit (1);
}
}
#endif
} }
} }