From 967e3e9c5a888d5885ed8d9909e3abd9cbc6eeb6 Mon Sep 17 00:00:00 2001 From: Rachel Hestilow Date: Tue, 30 Jul 2002 23:02:12 +0000 Subject: [PATCH] 2002-07-30 Rachel Hestilow * generator/ClassBase.cs: Change hasDefaultConstructor to protected, adjust now that it is an attr and not a subnode. Also add virtual property AssignToName (for ctors). * generator/Ctor.cs: Add property ForceStatic. (Generate): Optimize return code a bit for the static case. * generator/Method.cs: Assign to a "raw_ret" pointer before calling FromNativeReturn. * generator/Parameters.cs: Change "out ref" to "out", not "ref". * generator/Property.cs: Fix to work correctly with all object and struct types (mostly just some if-cases added). * generator/SignalHandler.cs: Remove args_type and argfields (unused). (Generate): Initialize struct if necessary. * generator/StructBase.cs: Massive reworking to support methods, ctors, etc. * generator/SymbolTable.cs: Add GdkAtom and gconstpointer simple types. * glib/Boxed.cs: Accept both IntPtr and object ctors. Add access for both. * glib/Opaque.cs: Fix copy/pasted copyright notice, remove data and event fields. Fix docs. * glib/Value.cs: Work correctly with boxed properties. * gnome/Modules.cs: Use new struct ctors. * gnome/Program.custom: Remove Get, this is being generated now. * parser/Gdk.metadata: Fix the drawable classes to inherit correctly. * parser/Metadata.pm: Change per-class attributes to actually be attributes. * parser/Gtk.metadata: Add a dummy attribute value for disabledefaultctor. * parser/gapi2xml.pl: Add hacks for the (broken) Drawable and Bitmap typedefs. * sample/test/TestColorSelection.cs: Display color string in hex format, update to use IsNull instead of == null, and size dialog to look pretty. * sample/Size.cs: Added. svn path=/trunk/gtk-sharp/; revision=6264 --- ChangeLog | 51 +++++++++++ generator/ClassBase.cs | 12 +-- generator/Ctor.cs | 26 ++++-- generator/Method.cs | 7 +- generator/Parameters.cs | 4 +- generator/Property.cs | 23 +++-- generator/SignalHandler.cs | 7 +- generator/StructBase.cs | 145 ++++++++++++++++++++++++------ generator/SymbolTable.cs | 3 + generator/gtkapi.xml | 11 ++- glib/Boxed.cs | 26 +++++- glib/Opaque.cs | 25 +++--- glib/Value.cs | 5 +- gnome/Modules.cs | 8 +- gnome/Program.custom | 13 --- parser/GAPI/Metadata.pm | 3 +- parser/Gdk.metadata | 14 +++ parser/Gtk.metadata | 1 + parser/Metadata.pm | 3 +- parser/gapi2xml.pl | 8 +- sample/Size.cs | 42 +++++++++ sample/test/TestColorSelection.cs | 35 ++++++-- sources/Gdk.metadata | 14 +++ sources/Gtk.metadata | 1 + 24 files changed, 376 insertions(+), 111 deletions(-) create mode 100644 sample/Size.cs diff --git a/ChangeLog b/ChangeLog index cfab12b58..e2d3282c1 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,54 @@ +2002-07-30 Rachel Hestilow + + * generator/ClassBase.cs: Change hasDefaultConstructor to protected, + adjust now that it is an attr and not a subnode. Also add virtual + property AssignToName (for ctors). + + * generator/Ctor.cs: Add property ForceStatic. + (Generate): Optimize return code a bit for the static case. + + * generator/Method.cs: Assign to a "raw_ret" pointer before calling + FromNativeReturn. + + * generator/Parameters.cs: Change "out ref" to "out", not "ref". + + * generator/Property.cs: Fix to work correctly with all object and + struct types (mostly just some if-cases added). + + * generator/SignalHandler.cs: Remove args_type and argfields (unused). + (Generate): Initialize struct if necessary. + + * generator/StructBase.cs: Massive reworking to support methods, ctors, + etc. + + * generator/SymbolTable.cs: Add GdkAtom and gconstpointer simple types. + + * glib/Boxed.cs: Accept both IntPtr and object ctors. Add access for both. + + * glib/Opaque.cs: Fix copy/pasted copyright notice, remove data and event + fields. Fix docs. + + * glib/Value.cs: Work correctly with boxed properties. + + * gnome/Modules.cs: Use new struct ctors. + + * gnome/Program.custom: Remove Get, this is being generated now. + + * parser/Gdk.metadata: Fix the drawable classes to inherit correctly. + + * parser/Metadata.pm: Change per-class attributes to actually be + attributes. + + * parser/Gtk.metadata: Add a dummy attribute value for disabledefaultctor. + + * parser/gapi2xml.pl: Add hacks for the (broken) Drawable and Bitmap + typedefs. + + * sample/test/TestColorSelection.cs: Display color string in hex format, + update to use IsNull instead of == null, and size dialog to look pretty. + + * sample/Size.cs: Added. + 2002-07-25 Rachel Hestilow [about 60% of the marshalling patch that I lost. diff --git a/generator/ClassBase.cs b/generator/ClassBase.cs index 68b815326..62df9fcff 100644 --- a/generator/ClassBase.cs +++ b/generator/ClassBase.cs @@ -19,7 +19,7 @@ namespace GtkSharp.Generation { protected ArrayList interfaces = null; protected ArrayList ctors = new ArrayList(); - private bool hasDefaultConstructor = true; + protected bool hasDefaultConstructor = true; private bool ctors_initted = false; private Hashtable clash_map; @@ -43,6 +43,8 @@ namespace GtkSharp.Generation { } protected ClassBase (XmlElement ns, XmlElement elem) : base (ns, elem) { + hasDefaultConstructor = !elem.HasAttribute ("disabledefaultconstructor"); + foreach (XmlNode node in elem.ChildNodes) { if (!(node is XmlElement)) continue; XmlElement member = (XmlElement) node; @@ -73,10 +75,6 @@ namespace GtkSharp.Generation { ctors.Add (new Ctor (LibraryName, member, this)); break; - case "disabledefaultconstructor": - hasDefaultConstructor = false; - break; - default: break; } @@ -123,6 +121,10 @@ namespace GtkSharp.Generation { return "Handle"; } + public virtual String AssignToName { + get { return "Raw"; } + } + public virtual String FromNative(String var) { return "(" + QualifiedName + ") GLib.Object.GetObject(" + var + ")"; diff --git a/generator/Ctor.cs b/generator/Ctor.cs index 3414d1dd6..319c723a8 100644 --- a/generator/Ctor.cs +++ b/generator/Ctor.cs @@ -19,12 +19,18 @@ namespace GtkSharp.Generation { private bool preferred; private String clashName = null; private ClassBase container_type; + private bool force_static; public bool Preferred { get { return preferred; } set { preferred = value; } } - + + public bool ForceStatic { + get { return force_static; } + set { force_static = value; } + } + public Ctor (string libname, XmlElement elem, ClassBase container_type) { this.libname = libname; this.elem = elem; @@ -71,7 +77,7 @@ namespace GtkSharp.Generation { } int clashes = (int) clash_map[sigtypes]; string cname = elem.GetAttribute("cname"); - if (clashes > 0 && !Preferred) { + if (force_static || (clashes > 0 && !Preferred)) { String mname = cname.Substring(cname.IndexOf("new")); mname = mname.Substring(0,1).ToUpper() + mname.Substring(1); int idx; @@ -126,20 +132,26 @@ namespace GtkSharp.Generation { sw.WriteLine("\t\tpublic static " + safety + modifiers + name + " " + clashName); sw.WriteLine("\t\t{"); - if (parms != null) - parms.Initialize(sw, false, ""); - sw.WriteLine("\t\t\tIntPtr ret = " + cname + call + ";"); + if (parms != null) parms.HandleException (sw, ""); - sw.WriteLine("\t\t\treturn new " + name + "(ret);"); + + sw.Write("\t\t\treturn "); + if (container_type is StructBase) + sw.Write ("{0}.New (", name); + else + sw.Write ("new {0} (", name); + sw.WriteLine (cname + call + ");"); } else { sw.WriteLine("\t\tpublic " + safety + name + sig); sw.WriteLine("\t\t{"); + if (parms != null) parms.Initialize(sw, false, ""); - sw.WriteLine("\t\t\tRaw = " + cname + call + ";"); + sw.WriteLine("\t\t\t{0} = {1}{2};", container_type.AssignToName, cname, call); if (parms != null) parms.HandleException (sw, ""); + } sw.WriteLine("\t\t}"); diff --git a/generator/Method.cs b/generator/Method.cs index 3a5279082..75ec83a8b 100644 --- a/generator/Method.cs +++ b/generator/Method.cs @@ -349,8 +349,11 @@ namespace GtkSharp.Generation { sw.WriteLine(indent +"\t\t\t" + s_ret + " ret = " + SymbolTable.FromNativeReturn(rettype, "raw_ret") + ";"); sw.WriteLine(indent + "\t\t\tif (ret == null) ret = new " + s_ret + "(raw_ret);"); } - else - sw.WriteLine(s_ret + " ret = " + SymbolTable.FromNativeReturn(rettype, cname + call) + ";"); + else { + sw.WriteLine(m_ret + " raw_ret = " + cname + call + ";"); + sw.Write(indent + "\t\t\t"); + sw.WriteLine(s_ret + " ret = " + SymbolTable.FromNativeReturn(rettype, "raw_ret") + ";"); + } } if (parms != null) diff --git a/generator/Parameters.cs b/generator/Parameters.cs index 37847567c..8f77fe8a4 100644 --- a/generator/Parameters.cs +++ b/generator/Parameters.cs @@ -226,8 +226,8 @@ namespace GtkSharp.Generation { } import_sig += (m_type + " " + name); // FIXME: lame - call_string = call_string.Replace ("out ref", "ref"); - import_sig = import_sig.Replace ("out ref", "ref"); + call_string = call_string.Replace ("out ref", "out"); + import_sig = import_sig.Replace ("out ref", "out"); i++; } diff --git a/generator/Property.cs b/generator/Property.cs index b6b9ee57b..df5b7aaee 100644 --- a/generator/Property.cs +++ b/generator/Property.cs @@ -74,7 +74,7 @@ namespace GtkSharp.Generation { Statistics.ThrottledCount++; return; } else if (SymbolTable.IsObject(c_type)) { - v_type = "(GLib.Object)"; + v_type = "(GLib.UnwrappedObject)"; } else if (SymbolTable.IsBoxed (c_type)) { v_type = "(GLib.Boxed)"; } else if (SymbolTable.IsOpaque (c_type)) { @@ -95,21 +95,18 @@ namespace GtkSharp.Generation { sw.WriteLine("\t\t\tget {"); sw.WriteLine("\t\t\t\tGLib.Value val = new GLib.Value (Handle, " + cname + ");"); sw.WriteLine("\t\t\t\tGetProperty(" + cname + ", val);"); - if (SymbolTable.IsObject (c_type) || SymbolTable.IsOpaque (c_type)) { - sw.WriteLine("\t\t\t\tSystem.IntPtr raw_ret = (System.IntPtr) (GLib.UnwrappedObject) val;"); + if (SymbolTable.IsObject (c_type) || SymbolTable.IsOpaque (c_type) || SymbolTable.IsBoxed (c_type)) { + sw.WriteLine("\t\t\t\tSystem.IntPtr raw_ret = (System.IntPtr) {0} val;", v_type); sw.WriteLine("\t\t\t\t" + cs_type + " ret = " + SymbolTable.FromNativeReturn(c_type, "raw_ret") + ";"); - sw.WriteLine("\t\t\t\tif (ret == null) ret = new " + cs_type + "(raw_ret);"); + if (!SymbolTable.IsBoxed (c_type)) + sw.WriteLine("\t\t\t\tif (ret == null) ret = new " + cs_type + "(raw_ret);"); } else { sw.Write("\t\t\t\t" + cs_type + " ret = "); - if (SymbolTable.IsBoxed (c_type)) { - sw.WriteLine ("({0}) (({1} val).Obj);", cs_type, v_type); - } else { - sw.Write ("(" + cs_type + ") "); - if (v_type != "") { - sw.Write(v_type + " "); - } - sw.WriteLine("val;"); + sw.Write ("(" + cs_type + ") "); + if (v_type != "") { + sw.Write(v_type + " "); } + sw.WriteLine("val;"); } sw.WriteLine("\t\t\t\treturn ret;"); @@ -124,7 +121,7 @@ namespace GtkSharp.Generation { } else if (SymbolTable.IsBoxed (c_type)) { sw.WriteLine("Handle, " + cname + ", new GLib.Boxed (value)));"); } else { - if (v_type != "") { + if (v_type != "" && !(SymbolTable.IsObject (c_type) || SymbolTable.IsOpaque (c_type))) { sw.Write(v_type + " "); } sw.WriteLine("value));"); diff --git a/generator/SignalHandler.cs b/generator/SignalHandler.cs index 637362705..354cb77ad 100644 --- a/generator/SignalHandler.cs +++ b/generator/SignalHandler.cs @@ -14,7 +14,6 @@ namespace GtkSharp.Generation { public class SignalHandler { private static Hashtable handlers = new Hashtable (); - private string args_type; public static String GetName(XmlElement sig) { @@ -40,7 +39,6 @@ namespace GtkSharp.Generation { string key = retval; string pinv = ""; string name = SymbolTable.GetName(retval); - string argfields = ""; int pcnt = 0; ArrayList parms = new ArrayList(); @@ -152,8 +150,11 @@ namespace GtkSharp.Generation { sw.WriteLine("= GLib.Object.GetObject(arg" + idx + ");"); } else { string ctype = (string) parms[idx]; - sw.WriteLine("\t\t\targs.Args[" + (idx-1) + "] = " + SymbolTable.FromNative (ctype, "arg" + idx) + ";"); ClassBase wrapper = SymbolTable.GetClassGen (ctype); + if (wrapper != null && (wrapper is StructBase)) { + sw.WriteLine("\t\t\targ{0}._Initialize ();", idx); + } + sw.WriteLine("\t\t\targs.Args[" + (idx-1) + "] = " + SymbolTable.FromNative (ctype, "arg" + idx) + ";"); if ((wrapper != null && ((wrapper is ObjectGen) || (wrapper is OpaqueGen))) || SymbolTable.IsManuallyWrapped (ctype)) { sw.WriteLine("\t\t\tif (args.Args[" + (idx-1) + "] == null)"); sw.WriteLine("\t\t\t\targs.Args[{0}] = new {1}(arg{2});", idx-1, SymbolTable.GetCSType (ctype), idx); diff --git a/generator/StructBase.cs b/generator/StructBase.cs index 5b402ccea..1e93a1635 100644 --- a/generator/StructBase.cs +++ b/generator/StructBase.cs @@ -13,8 +13,35 @@ namespace GtkSharp.Generation { using System.Xml; public class StructBase : ClassBase { - - public StructBase (XmlElement ns, XmlElement elem) : base (ns, elem) {} + + ArrayList fields = new ArrayList (); + uint bitfields; + + public StructBase (XmlElement ns, XmlElement elem) : base (ns, elem) + { + hasDefaultConstructor = false; + + foreach (XmlNode node in elem.ChildNodes) { + + if (!(node is XmlElement)) continue; + XmlElement member = (XmlElement) node; + + switch (node.Name) { + case "field": + fields.Add (member); + break; + + case "callback": + Statistics.IgnoreCount++; + break; + + default: + if (!IsNodeNameHandled (node.Name)) + Console.WriteLine ("Unexpected node " + node.Name + " in " + CName); + break; + } + } + } public override String MarshalType { get @@ -40,6 +67,10 @@ namespace GtkSharp.Generation { return "ref this"; } + public override String AssignToName { + get { return "raw"; } + } + public override String FromNative(String var) { return var; @@ -47,33 +78,71 @@ namespace GtkSharp.Generation { public override String FromNativeReturn(String var) { - return "new " + QualifiedName + " (" + var + ")"; + return QualifiedName + ".New (" + var + ")"; } + bool IsBit (XmlElement field) + { + return (field.HasAttribute("bits") && (field.GetAttribute("bits") == "1")); + } + + bool IsPointer (XmlElement field) + { + string c_type = field.GetAttribute("type"); + return (c_type[c_type.Length - 1] == '*'); + } + + protected void GenFields (StreamWriter sw) + { + bitfields = 0; + bool need_field = true; + foreach (XmlElement field in fields) { + if (IsBit (field)) { + if (need_field) + need_field = false; + else + continue; + } else + need_field = true; + GenField (field, sw); + } + } + + protected bool GetFieldInfo (XmlElement field, out string type, out string name) + { + name = ""; + if (IsBit (field)) + type = "uint"; + else if (IsPointer (field)) { + type = "IntPtr"; + name = "_"; + } else { + string c_type = field.GetAttribute ("type"); + type = SymbolTable.GetCSType (c_type); + if (type == "") { + Console.WriteLine ("Field has unknown Type {0}", c_type); + Statistics.ThrottledCount++; + return false; + } + } + + if (field.HasAttribute("array_len")) + type += "[]"; + + if (IsBit (field)) + name = String.Format ("_bitfield{0}", bitfields++); + else + name += MangleName (field.GetAttribute ("cname")); + + return true; + } + protected bool GenField (XmlElement field, StreamWriter sw) { - String c_type; - - if (field.HasAttribute("bits") && (field.GetAttribute("bits") == "1")) { - c_type = "gboolean"; - } else { - c_type = field.GetAttribute("type"); - } - char[] ast = {'*'}; - c_type = c_type.TrimEnd(ast); - String m_type = SymbolTable.GetMarshalType(c_type); - - if (m_type == "") { - Console.WriteLine ("Field has unknown Type {0}", c_type); - Statistics.ThrottledCount++; + string type, name; + if (!GetFieldInfo (field, out type, out name)) return false; - } - - sw.Write ("\t\t public " + m_type); - if (field.HasAttribute("array_len")) { - sw.Write ("[]"); - } - sw.WriteLine (" " + MangleName(field.GetAttribute("cname")) + ";"); + sw.WriteLine ("\t\tpublic {0} {1};", type, name); return true; } @@ -109,7 +178,10 @@ namespace GtkSharp.Generation { sw.WriteLine ("\tpublic struct " + Name + " {"); sw.WriteLine (); + GenFields (sw); + sw.WriteLine (); GenCtors (sw); + GenMethods (sw, null, null, true); AppendCustom(sw); sw.WriteLine ("\t}"); @@ -118,9 +190,30 @@ namespace GtkSharp.Generation { protected override void GenCtors (StreamWriter sw) { - sw.WriteLine("\t\tpublic " + Name + "(IntPtr raw) {}"); + sw.WriteLine ("\t\tbool _is_null;"); + sw.WriteLine ("\t\tpublic bool IsNull {"); + sw.WriteLine ("\t\t\tget { return _is_null; }"); + sw.WriteLine ("\t\t}"); + sw.WriteLine ("\t\tpublic void _Initialize () {"); + sw.WriteLine ("\t\t\t_is_null = false;"); + sw.WriteLine ("\t\t}"); sw.WriteLine(); - //base.GenCtors (sw); + sw.WriteLine ("\t\tpublic static " + QualifiedName + " New(IntPtr raw) {"); + sw.WriteLine ("\t\t\t{0} self = new {0}();", QualifiedName); + sw.WriteLine ("\t\t\tif (raw == IntPtr.Zero) {"); + sw.WriteLine ("\t\t\t\tself._is_null = true;"); + sw.WriteLine ("\t\t\t} else {"); + sw.WriteLine ("\t\t\t\tself = ({0}) Marshal.PtrToStructure (raw, self.GetType ());", QualifiedName); + sw.WriteLine ("\t\t\t\tself._is_null = false;"); + sw.WriteLine ("\t\t\t}"); + sw.WriteLine ("\t\t\treturn self;"); + sw.WriteLine ("\t\t}"); + sw.WriteLine(); + + foreach (Ctor ctor in Ctors) { + ctor.ForceStatic = true; + } + base.GenCtors (sw); } } diff --git a/generator/SymbolTable.cs b/generator/SymbolTable.cs index 764609d2b..03f0e07fe 100644 --- a/generator/SymbolTable.cs +++ b/generator/SymbolTable.cs @@ -26,6 +26,7 @@ namespace GtkSharp.Generation { simple_types.Add ("guint", "uint"); simple_types.Add ("glong", "long"); simple_types.Add ("gshort", "short"); + simple_types.Add ("gushort", "ushort"); simple_types.Add ("guint32", "uint"); simple_types.Add ("const-gchar", "string"); simple_types.Add ("const-char", "string"); @@ -71,6 +72,8 @@ namespace GtkSharp.Generation { simple_types.Add ("GHashTable", "System.IntPtr"); simple_types.Add ("va_list", "System.IntPtr"); simple_types.Add ("GParamSpec", "System.IntPtr"); + simple_types.Add ("GdkAtom", "System.IntPtr"); + simple_types.Add ("gconstpointer", "System.IntPtr"); manually_wrapped_types = new Hashtable (); manually_wrapped_types.Add ("GdkEvent", "Gdk.Event"); diff --git a/generator/gtkapi.xml b/generator/gtkapi.xml index 085ec3484..8ceff75d2 100644 --- a/generator/gtkapi.xml +++ b/generator/gtkapi.xml @@ -2624,7 +2624,7 @@ - + @@ -2752,7 +2752,7 @@ - + @@ -3254,7 +3254,7 @@ - + @@ -3265,7 +3265,7 @@ - + @@ -9051,7 +9051,7 @@ - + @@ -9147,7 +9147,6 @@ - diff --git a/glib/Boxed.cs b/glib/Boxed.cs index e0423f53f..1ab149a71 100644 --- a/glib/Boxed.cs +++ b/glib/Boxed.cs @@ -17,7 +17,8 @@ namespace GLib { /// public class Boxed { - object raw; + object obj; + IntPtr raw; /// /// Boxed Constructor @@ -29,7 +30,12 @@ namespace GLib { public Boxed (object o) { - this.raw = raw; + this.obj = obj; + } + + public Boxed (IntPtr ptr) + { + this.raw = ptr; } /// @@ -39,8 +45,7 @@ namespace GLib { /// /// Gets a marshallable IntPtr. /// - - public virtual object Obj { + public virtual IntPtr Handle { get { return raw; } @@ -48,5 +53,18 @@ namespace GLib { raw = value; } } + + public static explicit operator System.IntPtr (Boxed boxed) { + return boxed.Handle; + } + + public virtual object Obj { + get { + return obj; + } + set { + obj = value; + } + } } } diff --git a/glib/Opaque.cs b/glib/Opaque.cs index 32888c30f..9abd9411f 100644 --- a/glib/Opaque.cs +++ b/glib/Opaque.cs @@ -1,9 +1,10 @@ -// Object.cs - GObject class wrapper implementation +// Opaque .cs - Opaque struct wrapper implementation // // Authors: Bob Smith // Mike Kestner +// Rachel Hestilow // -// (c) 2001 Bob Smith and Mike Kestner +// (c) 2001 Bob Smith and Mike Kestner, 2002 Rachel Hestilow namespace GLib { @@ -24,8 +25,6 @@ namespace GLib { // Private class and instance members IntPtr _obj; - EventHandlerList _events; - Hashtable Data; static Hashtable Opaques = new Hashtable(); /// @@ -37,7 +36,7 @@ namespace GLib { /// given raw object pointer. This method is primarily /// used to wrap object references that are returned /// by either the signal system or raw class methods that - /// return GObject references. + /// return opaque struct references. /// /// /// @@ -52,7 +51,7 @@ namespace GLib { } /// - /// Object Constructor + /// Opaque Constructor /// /// /// @@ -62,11 +61,11 @@ namespace GLib { public Opaque () {} /// - /// Object Constructor + /// Opaque Constructor /// /// /// - /// Creates an object from a raw object reference. + /// Creates an opaque wrapper from a raw object reference. /// public Opaque (IntPtr raw) @@ -79,8 +78,8 @@ namespace GLib { /// /// /// - /// The raw GObject reference associated with this wrapper. - /// Only subclasses of Object can access this read/write + /// The raw Opaque reference associated with this wrapper. + /// Only subclasses of Opaque can access this read/write /// property. For public read-only access, use the /// Handle property. /// @@ -100,7 +99,7 @@ namespace GLib { /// /// /// - /// The raw GObject reference associated with this object. + /// The raw Opaque reference associated with this object. /// Subclasses can use Raw property for read/write /// access. /// @@ -134,5 +133,9 @@ namespace GLib { { return Handle.GetHashCode (); } + + public static explicit operator System.IntPtr (Opaque opaque) { + return opaque.Handle; + } } } diff --git a/glib/Value.cs b/glib/Value.cs index d1c91956c..e6df66de0 100755 --- a/glib/Value.cs +++ b/glib/Value.cs @@ -288,10 +288,7 @@ namespace GLib { public static explicit operator GLib.Boxed (Value val) { - // FIXME: Insert an appropriate exception here if - // _val.type indicates an error. - // FIXME: Figure out how to wrap this boxed type - return null; + return new GLib.Boxed (g_value_get_boxed (val._val)); } [DllImport("gobject-2.0")] diff --git a/gnome/Modules.cs b/gnome/Modules.cs index fb82ef84c..c99ee5642 100644 --- a/gnome/Modules.cs +++ b/gnome/Modules.cs @@ -11,11 +11,15 @@ namespace Gnome static extern System.IntPtr libgnomeui_module_info_get (); public static ModuleInfo LibGnome { - get { return new ModuleInfo (libgnome_module_info_get ()); } + get { + return ModuleInfo.New (libgnome_module_info_get ()); + } } public static ModuleInfo UI { - get { return new ModuleInfo (libgnomeui_module_info_get ()); } + get { + return ModuleInfo.New (libgnomeui_module_info_get ()); + } } } } diff --git a/gnome/Program.custom b/gnome/Program.custom index bcfc3a353..be9052d16 100644 --- a/gnome/Program.custom +++ b/gnome/Program.custom @@ -64,17 +64,4 @@ public void Quit () Gtk.Application.Quit (); } -[DllImport("libgnome-2.so.0")] -static extern System.IntPtr gnome_program_get (); - -public static Program Get () -{ - IntPtr raw = gnome_program_get (); - if (raw == IntPtr.Zero) - return null; - Program program = (Program) GLib.Object.GetObject (raw); - if (program == null) - program = new Program (raw); - return program; -} diff --git a/parser/GAPI/Metadata.pm b/parser/GAPI/Metadata.pm index 719842401..0e2c21695 100644 --- a/parser/GAPI/Metadata.pm +++ b/parser/GAPI/Metadata.pm @@ -150,8 +150,7 @@ sub addClassData { if (0 == scalar @nodes) { print STDERR "DEBUG> $class $$data[0] $$data[1] $$data[2] $$data[3] $$data[4] $$data[5] $$data[6]\n"; - my $new_node = $doc->createElement ($$data[5]); - $node->appendChild ($new_node); + $node->setAttribute ($$data[5], $$data[6]); } next; } diff --git a/parser/Gdk.metadata b/parser/Gdk.metadata index 44bd11052..1d4b52cf0 100644 --- a/parser/Gdk.metadata +++ b/parser/Gdk.metadata @@ -41,4 +41,18 @@ + + + + + + + + + parent + GdkDrawable + + + + diff --git a/parser/Gtk.metadata b/parser/Gtk.metadata index ff28b7d07..f23dcf303 100644 --- a/parser/Gtk.metadata +++ b/parser/Gtk.metadata @@ -1205,6 +1205,7 @@ disabledefaultconstructor + 1 diff --git a/parser/Metadata.pm b/parser/Metadata.pm index 719842401..0e2c21695 100644 --- a/parser/Metadata.pm +++ b/parser/Metadata.pm @@ -150,8 +150,7 @@ sub addClassData { if (0 == scalar @nodes) { print STDERR "DEBUG> $class $$data[0] $$data[1] $$data[2] $$data[3] $$data[4] $$data[5] $$data[6]\n"; - my $new_node = $doc->createElement ($$data[5]); - $node->appendChild ($new_node); + $node->setAttribute ($$data[5], $$data[6]); } next; } diff --git a/parser/gapi2xml.pl b/parser/gapi2xml.pl index 7401af0af..cb4f71ef8 100755 --- a/parser/gapi2xml.pl +++ b/parser/gapi2xml.pl @@ -50,6 +50,8 @@ while ($line = ) { $ptrs{$2} = $1; } elsif ($line =~ /typedef\s+(struct\s+\w+)\s+(\w+);/) { next if ($2 =~ /Private$/); + # fixme: siiigh + $2 = "GdkDrawable" if ($1 eq "_GdkDrawable"); $types{$2} = $1; } elsif ($line =~ /typedef\s+(\w+\s+\**)(\w+);/) { $types{$2} = $1; @@ -324,7 +326,11 @@ foreach $key (sort (keys (%types))) { $def = "privatestruct"; } - if (exists($boxdefs{$key})) { + + # fixme: hack + if ($key eq "GdkBitmap") { + $struct_el = addNameElem($ns_elem, 'object', $key, $ns); + } elsif (exists($boxdefs{$key})) { $struct_el = addNameElem($ns_elem, 'boxed', $key, $ns); } else { $struct_el = addNameElem($ns_elem, 'struct', $key, $ns); diff --git a/sample/Size.cs b/sample/Size.cs new file mode 100644 index 000000000..b135dc4c1 --- /dev/null +++ b/sample/Size.cs @@ -0,0 +1,42 @@ +// Size.cs - struct marshalling test +// +// Author: Rachel Hestilow +// +// (c) 2002 Rachel Hestilow + +namespace GtkSamples { + + using Gtk; + using Gdk; + using GtkSharp; + using System; + + public class SizeTest { + + public static int Main (string[] args) + { + Application.Init (); + Gtk.Window win = new Gtk.Window ("Gtk# Hello World"); + win.DeleteEvent += new DeleteEventHandler (Window_Delete); + win.SizeAllocated += new SizeAllocatedHandler (Size_Allocated); + win.ShowAll (); + Application.Run (); + return 0; + } + + static void Window_Delete (object obj, DeleteEventArgs args) + { + SignalArgs sa = (SignalArgs) args; + Application.Quit (); + sa.RetVal = true; + } + + static void Size_Allocated (object obj, SizeAllocatedArgs args) + { + Gdk.Rectangle rect = args.Allocation; + if (rect.IsNull) + Console.WriteLine ("ERROR: Allocation is null!"); + Console.WriteLine ("Size: ({0}, {1})", rect.width, rect.height); + } + } +} diff --git a/sample/test/TestColorSelection.cs b/sample/test/TestColorSelection.cs index 7b6cc2191..19569cae1 100644 --- a/sample/test/TestColorSelection.cs +++ b/sample/test/TestColorSelection.cs @@ -7,6 +7,7 @@ // using System; +using System.Text; using Gtk; using GtkSharp; @@ -59,20 +60,38 @@ namespace WidgetViewer { window.ColorSelection.HasPalette = ((ToggleButton )o).Active; } + static string HexFormat (Gdk.Color color) + { + StringBuilder s = new StringBuilder (); + ushort[] vals = { color.red, color.green, color.blue }; + char[] hexchars = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', + 'A', 'B', 'C', 'D', 'E', 'F'}; + + s.Append ('#'); + foreach (ushort val in vals) { + /* Convert to a range of 0-255, then lookup the + * digit for each half-byte */ + byte rounded = (byte) (val >> 8); + s.Append (hexchars[(rounded & 0xf0) >> 4]); + s.Append (hexchars[rounded & 0x0f]); + } + + return s.ToString (); + } + static void Color_Changed (object o, EventArgs args) { Gdk.Color color = window.ColorSelection.CurrentColor; + Console.WriteLine (HexFormat (color)); } static void Color_Selection_OK (object o, EventArgs args) { Gdk.Color selected = window.ColorSelection.CurrentColor; -/* - if (selected == null) { + if (selected.IsNull) { Console.WriteLine ("Color selection failed."); return; } -*/ Display_Result (selected); } @@ -85,20 +104,20 @@ namespace WidgetViewer { static void Display_Result (Gdk.Color color) { -/* - if (color == null) + if (color.IsNull) Console.WriteLine ("Null color"); -*/ dialog = new Dialog (); dialog.Title = "Selected Color"; + dialog.VBox.PackStart (new Gtk.Label (HexFormat (color)), + false, false, 0); + DrawingArea da = new DrawingArea (); da.ModifyBg (StateType.Normal, color); - Console.WriteLine (da); - dialog.VBox.PackStart (da, true, true, 0); + dialog.SetDefaultSize (200, 200); Button button = new Button ("OK"); button.Clicked += new EventHandler (Close_Button); diff --git a/sources/Gdk.metadata b/sources/Gdk.metadata index 44bd11052..1d4b52cf0 100644 --- a/sources/Gdk.metadata +++ b/sources/Gdk.metadata @@ -41,4 +41,18 @@ + + + + + + + + + parent + GdkDrawable + + + + diff --git a/sources/Gtk.metadata b/sources/Gtk.metadata index ff28b7d07..f23dcf303 100644 --- a/sources/Gtk.metadata +++ b/sources/Gtk.metadata @@ -1205,6 +1205,7 @@ disabledefaultconstructor + 1