mirror of
https://github.com/Ryujinx/GtkSharp.git
synced 2025-03-01 15:28:10 +00:00
Merge pull request #29 from bl8/ginterface-fixes
GInterface properties fixes
This commit is contained in:
commit
63e9993fcf
|
@ -151,13 +151,14 @@ namespace GLib {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Key: The pointer to the ParamSpec of the property
|
// Key: The Type for the set of properties
|
||||||
// Value: The corresponding PropertyInfo object
|
// Value->SubKey: The pointer to the ParamSpec of the property
|
||||||
static Dictionary<IntPtr, PropertyInfo> properties;
|
// Value->SubValue: The corresponding PropertyInfo object
|
||||||
static Dictionary<IntPtr, PropertyInfo> Properties {
|
static Dictionary<Type, Dictionary<IntPtr, PropertyInfo>> properties;
|
||||||
|
static Dictionary<Type, Dictionary<IntPtr, PropertyInfo>> Properties {
|
||||||
get {
|
get {
|
||||||
if (properties == null)
|
if (properties == null)
|
||||||
properties = new Dictionary<IntPtr, PropertyInfo> ();
|
properties = new Dictionary<Type, Dictionary<IntPtr, PropertyInfo>> ();
|
||||||
return properties;
|
return properties;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -307,7 +308,13 @@ namespace GLib {
|
||||||
PropertyAttribute property_attr = attr as PropertyAttribute;
|
PropertyAttribute property_attr = attr as PropertyAttribute;
|
||||||
try {
|
try {
|
||||||
IntPtr param_spec = RegisterProperty (gtype, property_attr.Name, property_attr.Nickname, property_attr.Blurb, idx, (GType) pinfo.PropertyType, pinfo.CanRead, pinfo.CanWrite);
|
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<IntPtr, PropertyInfo> gtype_properties;
|
||||||
|
if (!Properties.TryGetValue (type, out gtype_properties)) {
|
||||||
|
gtype_properties = new Dictionary<IntPtr, PropertyInfo> ();
|
||||||
|
Properties [type] = gtype_properties;
|
||||||
|
}
|
||||||
|
gtype_properties.Add (param_spec, pinfo);
|
||||||
idx++;
|
idx++;
|
||||||
} catch (ArgumentException) {
|
} 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));
|
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)
|
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<IntPtr, PropertyInfo> props;
|
||||||
|
if (!Properties.TryGetValue (type, out props))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
GLib.Object obj = GLib.Object.GetObject (handle, false);
|
PropertyInfo prop;
|
||||||
value.Val = Properties [param_spec].GetValue (obj, new object [0]);
|
if (!props.TryGetValue (param_spec, out prop))
|
||||||
|
return;
|
||||||
|
|
||||||
|
value.Val = prop.GetValue (obj, new object [0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
static GetPropertyDelegate get_property_handler;
|
static GetPropertyDelegate get_property_handler;
|
||||||
|
@ -352,11 +366,18 @@ namespace GLib {
|
||||||
o.Raw = handle;
|
o.Raw = handle;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!Properties.ContainsKey (param_spec))
|
GLib.Object obj = GLib.Object.GetObject (handle, false);
|
||||||
|
var type = (Type)obj.LookupGType ();
|
||||||
|
|
||||||
|
Dictionary<IntPtr, PropertyInfo> props;
|
||||||
|
if (!Properties.TryGetValue (type, out props))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
GLib.Object obj = GLib.Object.GetObject (handle, false);
|
PropertyInfo prop;
|
||||||
Properties [param_spec].SetValue (obj, value.Val, new object [0]);
|
if (!props.TryGetValue (param_spec, out prop))
|
||||||
|
return;
|
||||||
|
|
||||||
|
prop.SetValue (obj, value.Val, new object [0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
static SetPropertyDelegate set_property_handler;
|
static SetPropertyDelegate set_property_handler;
|
||||||
|
@ -401,12 +422,17 @@ namespace GLib {
|
||||||
if (attrs.Length == 0)
|
if (attrs.Length == 0)
|
||||||
continue;
|
continue;
|
||||||
PropertyAttribute property_attr = attrs [0];
|
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)
|
if (declared_prop == null)
|
||||||
continue;
|
continue;
|
||||||
IntPtr param_spec = FindInterfaceProperty (adapter.GType, property_attr.Name);
|
IntPtr param_spec = FindInterfaceProperty (adapter.GType, property_attr.Name);
|
||||||
|
|
||||||
Properties [param_spec] = declared_prop;
|
Dictionary<IntPtr, PropertyInfo> props;
|
||||||
|
if (!Properties.TryGetValue (t, out props)) {
|
||||||
|
props = new Dictionary<IntPtr, PropertyInfo> ();
|
||||||
|
Properties [t] = props;
|
||||||
|
}
|
||||||
|
props [param_spec] = declared_prop;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -116,7 +116,7 @@ namespace GLib {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public string ToString ()
|
public override string ToString ()
|
||||||
{
|
{
|
||||||
GParamSpec spec = (GParamSpec) Marshal.PtrToStructure (Handle, typeof (GParamSpec));
|
GParamSpec spec = (GParamSpec) Marshal.PtrToStructure (Handle, typeof (GParamSpec));
|
||||||
GType valtype= new GType (spec.value_type);
|
GType valtype= new GType (spec.value_type);
|
||||||
|
|
|
@ -9,14 +9,25 @@ class CustomScrollableWidgetTest {
|
||||||
Window win = new Window ("Custom Scrollable Widget Test");
|
Window win = new Window ("Custom Scrollable Widget Test");
|
||||||
win.DeleteEvent += new DeleteEventHandler (OnQuit);
|
win.DeleteEvent += new DeleteEventHandler (OnQuit);
|
||||||
|
|
||||||
|
VPaned paned = new VPaned ();
|
||||||
|
|
||||||
ScrolledWindow scroll = new ScrolledWindow ();
|
ScrolledWindow scroll = new ScrolledWindow ();
|
||||||
scroll.HscrollbarPolicy = PolicyType.Automatic;
|
scroll.HscrollbarPolicy = PolicyType.Automatic;
|
||||||
scroll.VscrollbarPolicy = PolicyType.Automatic;
|
scroll.VscrollbarPolicy = PolicyType.Automatic;
|
||||||
|
|
||||||
CustomScrollableWidget cw = new CustomScrollableWidget ("This one label that is repeated");
|
var cw = new DerivedScrollableWidget<string> ("This one label that is repeated");
|
||||||
scroll.Add (cw);
|
scroll.Add (cw);
|
||||||
|
paned.Pack1 (scroll, true, false);
|
||||||
|
|
||||||
win.Add (scroll);
|
scroll = new ScrolledWindow ();
|
||||||
|
scroll.HscrollbarPolicy = PolicyType.Automatic;
|
||||||
|
scroll.VscrollbarPolicy = PolicyType.Automatic;
|
||||||
|
|
||||||
|
var cw2 = new DerivedScrollableWidget<object> ("Another label that is repeated");
|
||||||
|
scroll.Add (cw2);
|
||||||
|
paned.Pack2 (scroll, true, false);
|
||||||
|
|
||||||
|
win.Add (paned);
|
||||||
win.DefaultWidth = 200;
|
win.DefaultWidth = 200;
|
||||||
win.DefaultHeight = 200;
|
win.DefaultHeight = 200;
|
||||||
win.ShowAll ();
|
win.ShowAll ();
|
||||||
|
@ -36,7 +47,13 @@ abstract class CustomBase : Widget
|
||||||
{ }
|
{ }
|
||||||
}
|
}
|
||||||
|
|
||||||
class CustomScrollableWidget : CustomBase, ScrollableImplementor {
|
class DerivedScrollableWidget<T> : CustomScrollableWidget<T>
|
||||||
|
{
|
||||||
|
public DerivedScrollableWidget (string label) : base (label)
|
||||||
|
{ }
|
||||||
|
}
|
||||||
|
|
||||||
|
class CustomScrollableWidget<T> : CustomBase, ScrollableImplementor {
|
||||||
private int num_rows = 20;
|
private int num_rows = 20;
|
||||||
private string label;
|
private string label;
|
||||||
private Pango.Layout layout;
|
private Pango.Layout layout;
|
||||||
|
@ -166,8 +183,6 @@ class CustomScrollableWidget : CustomBase, ScrollableImplementor {
|
||||||
if (hadjustment.Value + hadjustment.PageSize > hadjustment.Upper) {
|
if (hadjustment.Value + hadjustment.PageSize > hadjustment.Upper) {
|
||||||
hadjustment.Value = hadjustment.Upper - hadjustment.PageSize;
|
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 ();
|
hadjustment.Change ();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -177,8 +192,6 @@ class CustomScrollableWidget : CustomBase, ScrollableImplementor {
|
||||||
if (vadjustment.Value + vadjustment.PageSize > vadjustment.Upper) {
|
if (vadjustment.Value + vadjustment.PageSize > vadjustment.Upper) {
|
||||||
vadjustment.Value = vadjustment.Upper - vadjustment.PageSize;
|
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 ();
|
vadjustment.Change ();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue