diff --git a/ChangeLog b/ChangeLog index 68e14a934..49461d95a 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2002-06-05 Mike Kestner + + * generator/Property.cs : Fix get{} GLib.Value passing. + * glib/Object.cs : GetProperty passes the GLib.Value now. + * glib/Value.cs : Add a ctor to create Values for props. + * glue/value.cs : add gtksharp_value_create_from_property. + 2002-05-29 Mike Kestner * */Makefile.in : remove generated source in clean target. diff --git a/generator/Property.cs b/generator/Property.cs index 259ce0020..00a6e0bec 100644 --- a/generator/Property.cs +++ b/generator/Property.cs @@ -51,6 +51,7 @@ namespace GtkSharp.Generation { if (name == parent.GetAttribute("name")) { name += "Prop"; } + string cname = "\"" + elem.GetAttribute("cname") + "\""; string v_type = ""; if (SymbolTable.IsEnum(c_type)) { @@ -71,8 +72,8 @@ namespace GtkSharp.Generation { sw.WriteLine("\t\tpublic " + cs_type + " " + name + " {"); if (elem.HasAttribute("readable")) { sw.WriteLine("\t\t\tget {"); - sw.WriteLine("\t\t\t\tGLib.Value val;"); - sw.WriteLine("\t\t\t\tGetProperty(\"" + elem.GetAttribute("cname") + "\", out val);"); + sw.WriteLine("\t\t\t\tGLib.Value val = new GLib.Value (Handle, " + cname + ");"); + sw.WriteLine("\t\t\t\tGetProperty(" + cname + ", val);"); sw.Write("\t\t\t\treturn (" + cs_type + ") "); if (v_type != "") { sw.Write("(" + v_type + ") "); @@ -83,7 +84,7 @@ namespace GtkSharp.Generation { if (elem.HasAttribute("writeable") && !elem.HasAttribute("construct-only")) { sw.WriteLine("\t\t\tset {"); - sw.Write("\t\t\t\tSetProperty(\"" + elem.GetAttribute("cname") + "\", new GLib.Value("); + sw.Write("\t\t\t\tSetProperty(" + cname + ", new GLib.Value("); if (v_type != "") { sw.Write("(" + v_type + ") "); } diff --git a/glib/Object.cs b/glib/Object.cs index 66ed88646..ce9b6bd36 100644 --- a/glib/Object.cs +++ b/glib/Object.cs @@ -165,10 +165,10 @@ namespace GLib { /// Accesses arbitrary data storage on the Object. /// - public object GetData (String key) + public object GetData (string key) { if (Data == null) - return null; + return String.Empty; return Data [key]; } @@ -181,7 +181,7 @@ namespace GLib { /// Stores arbitrary data on the Object. /// - public void SetData (String key, object val) + public void SetData (string key, object val) { if (Data == null) Data = new Hashtable (); @@ -199,13 +199,11 @@ namespace GLib { [DllImport("gobject-2.0")] static extern void g_object_get_property ( - IntPtr obj, string name, out IntPtr val); + IntPtr obj, string name, IntPtr val); - public void GetProperty (String name, out GLib.Value val) + public void GetProperty (String name, GLib.Value val) { - IntPtr v; - g_object_get_property (Raw, name, out v); - val = new GLib.Value (v, v); + g_object_get_property (Raw, name, val.Handle); } /// diff --git a/glib/Value.cs b/glib/Value.cs index 5b684d962..5bfe6d3ba 100755 --- a/glib/Value.cs +++ b/glib/Value.cs @@ -40,6 +40,9 @@ namespace GLib { [DllImport("gtksharpglue")] static extern IntPtr gtksharp_value_create(TypeFundamentals type); + [DllImport("gtksharpglue")] + static extern IntPtr gtksharp_value_create_from_property(IntPtr obj, string name); + // Constructor to wrap a raw GValue ref. We need the dummy param // to distinguish this ctor from the TypePointer ctor. @@ -48,6 +51,20 @@ namespace GLib { _val = val; } + /// + /// Value Constructor + /// + /// + /// + /// Constructs a Value corresponding to the type of the + /// specified property. + /// + + public Value (IntPtr obj, string prop_name) + { + _val = gtksharp_value_create_from_property (obj, prop_name); + } + /// /// Value Constructor /// diff --git a/glue/value.c b/glue/value.c index f4f255ff6..56dc72b99 100644 --- a/glue/value.c +++ b/glue/value.c @@ -15,4 +15,11 @@ gtksharp_value_create (GType g_type) return val; } +GValue * +gtksharp_value_create_from_property (GObject *obj, const gchar* name) +{ + GParamSpec *spec = g_object_class_find_property ( + G_OBJECT_GET_CLASS (obj), name); + return gtksharp_value_create (spec->value_type); +}