diff --git a/ChangeLog b/ChangeLog index c5e27403e..8eda6e18b 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2009-04-21 Christian Hoff + + * gtk/Widget.custom: Deglued implementation of StyleGetProperty. + 2009-04-16 Christian Hoff * glib/Value.cs: Support for additional fundamental GTypes. Invoke diff --git a/glib/ParamSpec.cs b/glib/ParamSpec.cs index 885b83786..f59a6f227 100644 --- a/glib/ParamSpec.cs +++ b/glib/ParamSpec.cs @@ -30,7 +30,7 @@ namespace GLib { Writable = 1 << 1, } - internal class ParamSpec { + public class ParamSpec { IntPtr handle; diff --git a/gtk/Widget.custom b/gtk/Widget.custom index cda38afc1..e7541b923 100644 --- a/gtk/Widget.custom +++ b/gtk/Widget.custom @@ -329,31 +329,39 @@ static void ClassInit (GLib.GType gtype, Type t) GLib.Marshaller.Free (signame); } -[DllImport("gtksharpglue-2")] -static extern bool gtksharp_widget_style_get_property (IntPtr widget, IntPtr property, ref GLib.Value value); - -public object StyleGetProperty (string property_name) { - GLib.Value value = new GLib.Value (); - IntPtr name = GLib.Marshaller.StringToPtrGStrdup (property_name); - bool success = gtksharp_widget_style_get_property (Handle, name, ref value); - GLib.Marshaller.Free (name); - - if(success) { - object ret = value.Val; - value.Dispose (); - return ret; +public object StyleGetProperty (string property_name) +{ + GLib.Value value; + try { + value = StyleGetPropertyValue (property_name); + } catch (ArgumentException) { + return null; } - - return null; + object ret = value.Val; + value.Dispose (); + return ret; } -internal GLib.Value StyleGetPropertyValue (string property_name) { - GLib.Value value = new GLib.Value (); +[DllImport("libgtk-win32-2.0-0.dll")] +static extern IntPtr gtk_widget_class_find_style_property (IntPtr class_ptr, IntPtr property_name); - IntPtr name = GLib.Marshaller.StringToPtrGStrdup (property_name); - gtksharp_widget_style_get_property (Handle, name, ref value); - GLib.Marshaller.Free (name); - return value; +[DllImport("libgtk-win32-2.0-0.dll")] +static extern IntPtr gtk_widget_style_get_property (IntPtr inst, IntPtr property_name, ref GLib.Value value); + +internal GLib.Value StyleGetPropertyValue (string property_name) +{ + IntPtr native_name = GLib.Marshaller.StringToPtrGStrdup (property_name); + try { + IntPtr pspec_ptr = gtk_widget_class_find_style_property (this.LookupGType ().ClassPtr, native_name); + if (pspec_ptr == IntPtr.Zero) + throw new ArgumentException (String.Format ("Cannot find style property \"{0}\"", property_name)); + + GLib.Value value = new GLib.Value ((new GLib.ParamSpec (pspec_ptr)).ValueType); + gtk_widget_style_get_property (Handle, native_name, ref value); + return value; + } finally { + GLib.Marshaller.Free (native_name); + } } [DllImport("libgtk-win32-2.0-0.dll")] diff --git a/gtk/glue/widget.c b/gtk/glue/widget.c index 40cf2b789..48775bf3b 100644 --- a/gtk/glue/widget.c +++ b/gtk/glue/widget.c @@ -40,7 +40,6 @@ void gtksharp_gtk_widget_set_flags (GtkWidget *widget, int flags); int gtksharp_gtk_widget_style_get_int (GtkWidget *widget, const char *name); void gtksharp_widget_add_binding_signal (GType gtype, const char *sig_name, GCallback cb); void gtksharp_widget_register_binding (GType gtype, const char *sig_name, guint key, int mod, gpointer data); -gboolean gtksharp_widget_style_get_property (GtkWidget *widget, const gchar* property, GValue *value); /* */ GdkRectangle* @@ -170,15 +169,3 @@ gtksharp_widget_register_binding (GType gtype, const gchar *signame, guint key, GtkBindingSet *set = gtk_binding_set_by_class (klass); gtk_binding_entry_add_signal (set, key, mod, signame, 1, G_TYPE_LONG, data); } - -gboolean -gtksharp_widget_style_get_property (GtkWidget *widget, const gchar* property, GValue *value) -{ - GParamSpec *spec = gtk_widget_class_find_style_property (GTK_WIDGET_GET_CLASS (widget), property); - if (spec == NULL) - return FALSE; - g_value_init (value, spec->value_type); - gtk_widget_style_get_property (widget, property, value); - return TRUE; -} -