diff --git a/glib/Object.cs b/glib/Object.cs index 06ed9e4ac..1cd05830d 100644 --- a/glib/Object.cs +++ b/glib/Object.cs @@ -151,13 +151,14 @@ namespace GLib { } } - // Key: The pointer to the ParamSpec of the property - // Value: The corresponding PropertyInfo object - static Dictionary properties; - static Dictionary Properties { + // Key: The Type for the set of properties + // Value->SubKey: The pointer to the ParamSpec of the property + // Value->SubValue: The corresponding PropertyInfo object + static Dictionary> properties; + static Dictionary> Properties { get { if (properties == null) - properties = new Dictionary (); + properties = new Dictionary> (); return properties; } } @@ -288,7 +289,7 @@ namespace GLib { IntPtr declaring_class = gtype.GetClassPtr (); ParamSpec pspec = new ParamSpec ("gtk-sharp-managed-instance", "", "", GType.Pointer, ParamFlags.Writable | ParamFlags.ConstructOnly); g_object_class_install_property (declaring_class, idx, pspec.Handle); - idx++; + idx++; } foreach (PropertyInfo pinfo in t.GetProperties (BindingFlags.Instance | BindingFlags.Public | BindingFlags.DeclaredOnly)) { @@ -307,7 +308,13 @@ namespace GLib { PropertyAttribute property_attr = attr as PropertyAttribute; try { IntPtr param_spec = RegisterProperty (gtype, property_attr.Name, property_attr.Nickname, property_attr.Blurb, idx, (GType) pinfo.PropertyType, pinfo.CanRead, pinfo.CanWrite); - Properties.Add (param_spec, pinfo); + Type type = (Type)gtype; + Dictionary gtype_properties; + if (!Properties.TryGetValue (type, out gtype_properties)) { + gtype_properties = new Dictionary (); + Properties [type] = gtype_properties; + } + gtype_properties.Add (param_spec, pinfo); idx++; } catch (ArgumentException) { 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)); @@ -321,11 +328,18 @@ namespace GLib { static void GetPropertyCallback (IntPtr handle, uint property_id, ref GLib.Value value, IntPtr param_spec) { - if (!Properties.ContainsKey (param_spec)) + GLib.Object obj = GLib.Object.GetObject (handle, false); + var type = (Type)obj.LookupGType (); + + Dictionary props; + if (!Properties.TryGetValue (type, out props)) return; - GLib.Object obj = GLib.Object.GetObject (handle, false); - value.Val = Properties [param_spec].GetValue (obj, new object [0]); + PropertyInfo prop; + if (!props.TryGetValue (param_spec, out prop)) + return; + + value.Val = prop.GetValue (obj, new object [0]); } static GetPropertyDelegate get_property_handler; @@ -352,11 +366,18 @@ namespace GLib { o.Raw = handle; } } - if (!Properties.ContainsKey (param_spec)) + GLib.Object obj = GLib.Object.GetObject (handle, false); + var type = (Type)obj.LookupGType (); + + Dictionary props; + if (!Properties.TryGetValue (type, out props)) return; - GLib.Object obj = GLib.Object.GetObject (handle, false); - Properties [param_spec].SetValue (obj, value.Val, new object [0]); + PropertyInfo prop; + if (!props.TryGetValue (param_spec, out prop)) + return; + + prop.SetValue (obj, value.Val, new object [0]); } static SetPropertyDelegate set_property_handler; @@ -401,12 +422,17 @@ namespace GLib { if (attrs.Length == 0) continue; PropertyAttribute property_attr = attrs [0]; - PropertyInfo declared_prop = t.GetProperty (p.Name, BindingFlags.DeclaredOnly | BindingFlags.Public | BindingFlags.Instance); + PropertyInfo declared_prop = t.GetProperty (p.Name, BindingFlags.Public | BindingFlags.Instance); if (declared_prop == null) continue; IntPtr param_spec = FindInterfaceProperty (adapter.GType, property_attr.Name); - - Properties [param_spec] = declared_prop; + + Dictionary props; + if (!Properties.TryGetValue (t, out props)) { + props = new Dictionary (); + Properties [t] = props; + } + props [param_spec] = declared_prop; } } } diff --git a/glib/ParamSpec.cs b/glib/ParamSpec.cs index 74134eaf8..f75e99d78 100644 --- a/glib/ParamSpec.cs +++ b/glib/ParamSpec.cs @@ -116,7 +116,7 @@ namespace GLib { } } - public string ToString () + public override string ToString () { GParamSpec spec = (GParamSpec) Marshal.PtrToStructure (Handle, typeof (GParamSpec)); GType valtype= new GType (spec.value_type); diff --git a/sample/CustomScrollableWidget.cs b/sample/CustomScrollableWidget.cs index 768fc9bed..4c28161dc 100644 --- a/sample/CustomScrollableWidget.cs +++ b/sample/CustomScrollableWidget.cs @@ -9,14 +9,25 @@ class CustomScrollableWidgetTest { Window win = new Window ("Custom Scrollable Widget Test"); win.DeleteEvent += new DeleteEventHandler (OnQuit); + VPaned paned = new VPaned (); + ScrolledWindow scroll = new ScrolledWindow (); scroll.HscrollbarPolicy = PolicyType.Automatic; scroll.VscrollbarPolicy = PolicyType.Automatic; - CustomScrollableWidget cw = new CustomScrollableWidget ("This one label that is repeated"); + var cw = new DerivedScrollableWidget ("This one label that is repeated"); scroll.Add (cw); + paned.Pack1 (scroll, true, false); + + scroll = new ScrolledWindow (); + scroll.HscrollbarPolicy = PolicyType.Automatic; + scroll.VscrollbarPolicy = PolicyType.Automatic; - win.Add (scroll); + var cw2 = new DerivedScrollableWidget ("Another label that is repeated"); + scroll.Add (cw2); + paned.Pack2 (scroll, true, false); + + win.Add (paned); win.DefaultWidth = 200; win.DefaultHeight = 200; win.ShowAll (); @@ -36,7 +47,13 @@ abstract class CustomBase : Widget { } } -class CustomScrollableWidget : CustomBase, ScrollableImplementor { +class DerivedScrollableWidget : CustomScrollableWidget +{ + public DerivedScrollableWidget (string label) : base (label) + { } +} + +class CustomScrollableWidget : CustomBase, ScrollableImplementor { private int num_rows = 20; private string label; private Pango.Layout layout; @@ -166,8 +183,6 @@ class CustomScrollableWidget : CustomBase, ScrollableImplementor { if (hadjustment.Value + hadjustment.PageSize > hadjustment.Upper) { hadjustment.Value = hadjustment.Upper - hadjustment.PageSize; } - Console.WriteLine (String.Format ("H adj={0} upper={1} PageSize={2} PageInc={3}", - HadjustmentValue, hadjustment.Upper, hadjustment.PageSize, hadjustment.PageIncrement)); hadjustment.Change (); } @@ -177,8 +192,6 @@ class CustomScrollableWidget : CustomBase, ScrollableImplementor { if (vadjustment.Value + vadjustment.PageSize > vadjustment.Upper) { vadjustment.Value = vadjustment.Upper - vadjustment.PageSize; } - Console.WriteLine (String.Format ("V adj={0} upper={1} PageSize={2} PageInc={3}", - VadjustmentValue, vadjustment.Upper, vadjustment.PageSize, vadjustment.PageIncrement)); vadjustment.Change (); } }