Skip to content

Commit 151a432

Browse files
committed
Updated to 3.0.9 version.
1 parent 8c4e9c0 commit 151a432

34 files changed

+612
-76
lines changed

Src/Noesis/Core/Src/Core/Extend.cs

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,8 @@ public static void RegisterCallbacks()
197197
_scrollInfoSetVerticalOffset,
198198
_scrollInfoMakeVisible,
199199

200+
_markupExtensionProvideValue,
201+
200202
_getPropertyValue_Bool,
201203
_getPropertyValue_Float,
202204
_getPropertyValue_Double,
@@ -263,6 +265,7 @@ public static void UnregisterCallbacks()
263265
null, null, null, null, null,
264266
null, null, null, null, null, null,
265267
null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null,
268+
null,
266269
null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null,
267270
null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null,
268271
null, null, null);
@@ -1744,7 +1747,7 @@ public static string StringFromNativeUtf8(IntPtr nativeUtf8)
17441747
{
17451748
if (nativeUtf8 == IntPtr.Zero)
17461749
{
1747-
return null;
1750+
return string.Empty;
17481751
}
17491752

17501753
#if __MonoCS__
@@ -3527,6 +3530,29 @@ private static void ScrollInfoMakeVisible(IntPtr cPtr, IntPtr visualType, IntPtr
35273530
}
35283531
}
35293532

3533+
////////////////////////////////////////////////////////////////////////////////////////////////
3534+
private delegate IntPtr Callback_MarkupExtensionProvideValue(IntPtr cPtr, IntPtr provider);
3535+
private static Callback_MarkupExtensionProvideValue _markupExtensionProvideValue = MarkupExtensionProvideValue;
3536+
3537+
[MonoPInvokeCallback(typeof(Callback_MarkupExtensionProvideValue))]
3538+
private static IntPtr MarkupExtensionProvideValue(IntPtr cPtr, IntPtr provider)
3539+
{
3540+
try
3541+
{
3542+
var extension = (MarkupExtension)GetExtendInstance(cPtr);
3543+
MarkupExtensionProvider provider_ = new MarkupExtensionProvider(provider);
3544+
object value = extension != null ? extension.ProvideValue(provider_) : null;
3545+
HandleRef itemPtr = GetInstanceHandle(value);
3546+
BaseComponent.AddReference(itemPtr.Handle); // released by native bindings
3547+
return itemPtr.Handle;
3548+
}
3549+
catch (Exception e)
3550+
{
3551+
Error.UnhandledException(e);
3552+
return IntPtr.Zero;
3553+
}
3554+
}
3555+
35303556
////////////////////////////////////////////////////////////////////////////////////////////////
35313557
private enum NativePropertyType
35323558
{

Src/Noesis/Core/Src/Core/ExtendImports.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ static extern void Noesis_RegisterReflectionCallbacks(
117117
Callback_ScrollInfoSetHorizontalOffset callback_ScrollInfoSetHorizontalOffset,
118118
Callback_ScrollInfoSetVerticalOffset callback_ScrollInfoSetVerticalOffset,
119119
Callback_ScrollInfoMakeVisible callback_ScrollInfoMakeVisible,
120+
Callback_MarkupExtensionProvideValue callback_MarkupExtensionProvideValue,
120121
Callback_GetPropertyValue_Bool callback_GetPropertyValue_Bool,
121122
Callback_GetPropertyValue_Float callback_GetPropertyValue_Float,
122123
Callback_GetPropertyValue_Double callback_GetPropertyValue_Double,

Src/Noesis/Core/Src/Core/Library.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ namespace Noesis
22
{
33
public class Library
44
{
5-
#if (UNITY_IOS || UNITY_WEBGL) && !UNITY_EDITOR
5+
#if (UNITY_IOS || UNITY_TVOS || UNITY_WEBGL) && !UNITY_EDITOR
66
public const string Name = "__Internal";
77
#else
88
public const string Name = "Noesis";
Lines changed: 179 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,179 @@
1+
using System;
2+
using System.Runtime.InteropServices;
3+
4+
namespace Noesis
5+
{
6+
/// <summary>
7+
/// Represents a service that reports situational object-property relationships for markup extension evaluation.
8+
/// </summary>
9+
public interface IProvideValueTarget
10+
{
11+
/// <summary>
12+
/// Gets the target object being reported.
13+
/// </summary>
14+
object TargetObject { get; }
15+
16+
/// <summary>
17+
/// Gets an identifier for the target property being reported.
18+
/// </summary>
19+
object TargetProperty { get; }
20+
}
21+
22+
/// <summary>
23+
/// Represents a service that can use application context to resolve a provided relative URI to an absolute URI.
24+
/// </summary>
25+
public interface IUriContext
26+
{
27+
/// <summary>
28+
/// Gets or sets the base URI of the current application context.
29+
/// </summary>
30+
Uri BaseUri { get; }
31+
}
32+
33+
/// <summary>
34+
/// Represents a service that resolves from named elements in XAML markup to the appropriate type.
35+
/// </summary>
36+
public interface IXamlTypeResolver
37+
{
38+
/// <summary>
39+
/// Resolves a named XAML type to the corresponding Type. The type name is optionally qualified
40+
/// by the prefix for a XML namespace, otherwise the current default XML namespace is assumed.
41+
/// </summary>
42+
Type Resolve(string qualifiedTypeName);
43+
}
44+
45+
/// <summary>
46+
/// Describes a service that can return a XAML namespace that is based on its prefix as it is mapped in XAML markup.
47+
/// </summary>
48+
public interface IXamlNamespaceResolver
49+
{
50+
/// <summary>
51+
/// Retrieves a XAML namespace identifier for the specified prefix string.
52+
/// </summary>
53+
string GetNamespace(string prefix);
54+
}
55+
56+
/// <summary>
57+
/// Describes a service that can return objects that are specified by XAML name, or alternatively, returns a token that defers name resolution. The service can also return an enumerable set of all named objects that are in the XAML namescope.
58+
/// </summary>
59+
public interface IXamlNameResolver
60+
{
61+
/// <summary>
62+
/// Resolves an object from a name reference.
63+
/// </summary>
64+
object Resolve(string name);
65+
}
66+
67+
/// <summary>
68+
/// Implementation of XAML service providers available for MarkupExtensions
69+
/// </summary>
70+
internal class MarkupExtensionProvider : IServiceProvider, IProvideValueTarget, IUriContext, IXamlTypeResolver, IXamlNamespaceResolver, IXamlNameResolver
71+
{
72+
object IServiceProvider.GetService(Type serviceType)
73+
{
74+
if (serviceType == typeof(IProvideValueTarget))
75+
{
76+
return this;
77+
}
78+
if (serviceType == typeof(IUriContext))
79+
{
80+
return this;
81+
}
82+
if (serviceType == typeof(IXamlTypeResolver))
83+
{
84+
return this;
85+
}
86+
if (serviceType == typeof(IXamlNamespaceResolver))
87+
{
88+
return this;
89+
}
90+
if (serviceType == typeof(IXamlNameResolver))
91+
{
92+
return this;
93+
}
94+
95+
return null;
96+
}
97+
98+
object IProvideValueTarget.TargetObject
99+
{
100+
get
101+
{
102+
IntPtr targetPtr = MarkupExtensionProvider_TargetObject(_provider);
103+
return Extend.GetProxy(targetPtr, false);
104+
}
105+
}
106+
107+
object IProvideValueTarget.TargetProperty
108+
{
109+
get
110+
{
111+
IntPtr propPtr = MarkupExtensionProvider_TargetProperty(_provider);
112+
return Extend.GetProxy(propPtr, false);
113+
}
114+
}
115+
116+
Uri IUriContext.BaseUri
117+
{
118+
get
119+
{
120+
IntPtr uriPtr = MarkupExtensionProvider_BaseUri(_provider);
121+
string uri = Extend.StringFromNativeUtf8(uriPtr);
122+
NoesisGUI_PINVOKE.FreeString(uriPtr);
123+
return new Uri(uri, UriKind.Relative);
124+
}
125+
}
126+
127+
Type IXamlTypeResolver.Resolve(string qualifiedTypeName)
128+
{
129+
IntPtr cPtr = MarkupExtensionProvider_ResolveType(_provider, qualifiedTypeName);
130+
if (cPtr != IntPtr.Zero)
131+
{
132+
Extend.NativeTypeInfo info = Extend.GetNativeTypeInfo(cPtr);
133+
return info.Type;
134+
}
135+
return null;
136+
}
137+
138+
string IXamlNamespaceResolver.GetNamespace(string prefix)
139+
{
140+
IntPtr strPtr = MarkupExtensionProvider_GetNamespace(_provider, prefix);
141+
return Extend.StringFromNativeUtf8(strPtr);
142+
}
143+
144+
object IXamlNameResolver.Resolve(string name)
145+
{
146+
IntPtr objectPtr = MarkupExtensionProvider_ResolveName(_provider, name);
147+
return Extend.GetProxy(objectPtr, false);
148+
}
149+
150+
#region Private members
151+
152+
internal MarkupExtensionProvider(IntPtr cPtr)
153+
{
154+
_provider = new HandleRef(this, cPtr);
155+
}
156+
157+
private HandleRef _provider;
158+
159+
[DllImport(Library.Name)]
160+
static extern IntPtr MarkupExtensionProvider_TargetObject(HandleRef provider);
161+
162+
[DllImport(Library.Name)]
163+
static extern IntPtr MarkupExtensionProvider_TargetProperty(HandleRef provider);
164+
165+
[DllImport(Library.Name)]
166+
static extern IntPtr MarkupExtensionProvider_BaseUri(HandleRef provider);
167+
168+
[DllImport(Library.Name)]
169+
static extern IntPtr MarkupExtensionProvider_ResolveType(HandleRef provider, [MarshalAs(UnmanagedType.LPWStr)]string name);
170+
171+
[DllImport(Library.Name)]
172+
static extern IntPtr MarkupExtensionProvider_GetNamespace(HandleRef provider, [MarshalAs(UnmanagedType.LPWStr)]string name);
173+
174+
[DllImport(Library.Name)]
175+
static extern IntPtr MarkupExtensionProvider_ResolveName(HandleRef provider, [MarshalAs(UnmanagedType.LPWStr)]string name);
176+
177+
#endregion
178+
}
179+
}

Src/Noesis/Core/Src/Core/View.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,14 @@ public void SetProjectionMatrix(Matrix4 projection)
9898
{
9999
Noesis_View_SetProjectionMatrix(CPtr, ref projection);
100100
}
101+
102+
/// <summary>
103+
/// Indicates if touch input events are emulated by the mouse
104+
/// </summary>
105+
public void SetEmulateTouch(bool emulate)
106+
{
107+
Noesis_View_SetEmulateTouch(CPtr, emulate);
108+
}
101109
#endregion
102110

103111
#region Input management
@@ -522,6 +530,9 @@ protected override IntPtr CreateCPtr(Type type, out bool registerExtend)
522530
[DllImport(Library.Name)]
523531
static extern int Noesis_View_SetProjectionMatrix(HandleRef view, ref Matrix4 projection);
524532

533+
[DllImport(Library.Name)]
534+
static extern int Noesis_View_SetEmulateTouch(HandleRef view, bool emulate);
535+
525536
[DllImport(Library.Name)]
526537
static extern void Noesis_View_Activate(HandleRef view);
527538

Src/Noesis/Core/Src/Proxies/Binding.cs

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,15 @@ internal static HandleRef getCPtr(Binding obj) {
2727
return (obj == null) ? new HandleRef(null, IntPtr.Zero) : obj.swigCPtr;
2828
}
2929

30-
public object ProvideValue(object targetObject, DependencyProperty targetProperty) {
31-
IntPtr cPtr = ProvideValueHelper(targetObject, targetProperty);
32-
return Noesis.Extend.GetProxy(cPtr, true);
30+
public override object ProvideValue(IServiceProvider serviceProvider) {
31+
IProvideValueTarget valueTarget = serviceProvider as IProvideValueTarget;
32+
if (valueTarget != null) {
33+
object target = valueTarget.TargetObject;
34+
object prop = valueTarget.TargetProperty;
35+
IntPtr cPtr = ProvideValueHelper(target, prop as DependencyProperty);
36+
return Noesis.Extend.GetProxy(cPtr, true);
37+
}
38+
return null;
3339
}
3440

3541
public static object DoNothing {
@@ -51,8 +57,13 @@ public Binding() {
5157
}
5258

5359
protected override IntPtr CreateCPtr(Type type, out bool registerExtend) {
54-
registerExtend = false;
55-
return NoesisGUI_PINVOKE.new_Binding__SWIG_0();
60+
if (type == typeof(Binding)) {
61+
registerExtend = false;
62+
return NoesisGUI_PINVOKE.new_Binding__SWIG_0();
63+
}
64+
else {
65+
return base.CreateExtendCPtr(type, out registerExtend);
66+
}
5667
}
5768

5869
public Binding(string path) : this(NoesisGUI_PINVOKE.new_Binding__SWIG_1(path != null ? path : string.Empty), true) {
@@ -169,6 +180,9 @@ private void SetConverterHelper(object converter) {
169180
NoesisGUI_PINVOKE.Binding_SetConverterHelper(swigCPtr, Noesis.Extend.GetInstanceHandle(converter));
170181
}
171182

183+
internal new static IntPtr Extend(string typeName) {
184+
return NoesisGUI_PINVOKE.Extend_Binding(Marshal.StringToHGlobalAnsi(typeName));
185+
}
172186
}
173187

174188
}

Src/Noesis/Core/Src/Proxies/BindingBase.cs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,7 @@
1515
namespace Noesis
1616
{
1717

18-
public class BindingBase : MarkupExtension {
19-
internal new static BindingBase CreateProxy(IntPtr cPtr, bool cMemoryOwn) {
20-
return new BindingBase(cPtr, cMemoryOwn);
21-
}
22-
18+
public abstract class BindingBase : MarkupExtension {
2319
internal BindingBase(IntPtr cPtr, bool cMemoryOwn) : base(cPtr, cMemoryOwn) {
2420
}
2521

Src/Noesis/Core/Src/Proxies/FontProvider.cs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,11 +55,19 @@ protected void RegisterFont(string folder, string id) {
5555
RegisterFontHelper(folder, id);
5656
}
5757

58+
/// <summary>
59+
/// Notifies of changes to the specified texture file
60+
/// </summary>
61+
public delegate void FontChangedHandler(string baseUri, string familyName, FontWeight weight,
62+
FontStretch stretch, FontStyle style);
63+
public event FontChangedHandler FontChanged;
64+
5865
/// <summary>
5966
/// Raises XamlChanged event notifying Noesis that it should reload the specified xaml
6067
/// </summary>
61-
protected void RaiseFontChanged(string baseUri, string familyName, FontWeight weight,
68+
public void RaiseFontChanged(string baseUri, string familyName, FontWeight weight,
6269
FontStretch stretch, FontStyle style) {
70+
FontChanged?.Invoke(baseUri, familyName, weight, stretch, style);
6371
Noesis_RaiseFontChanged(swigCPtr, baseUri, familyName, (int)weight, (int)stretch, (int)style);
6472
}
6573

Src/Noesis/Core/Src/Proxies/ItemContainerGenerator.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,14 @@ public object ItemFromContainer(DependencyObject container) {
271271
return Noesis.Extend.GetProxy(cPtr, false);
272272
}
273273

274+
public void StartBatch() {
275+
NoesisGUI_PINVOKE.ItemContainerGenerator_StartBatch(swigCPtr);
276+
}
277+
278+
public void StopBatch() {
279+
NoesisGUI_PINVOKE.ItemContainerGenerator_StopBatch(swigCPtr);
280+
}
281+
274282
public GeneratorStatus Status {
275283
get {
276284
GeneratorStatus ret = (GeneratorStatus)NoesisGUI_PINVOKE.ItemContainerGenerator_Status_get(swigCPtr);

Src/Noesis/Core/Src/Proxies/LogicalTreeHelper.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,17 @@ namespace Noesis
1818

1919
public static class LogicalTreeHelper {
2020
public static DependencyObject GetParent(DependencyObject current) {
21+
if (current == null) throw new ArgumentNullException("current");
2122
return GetParentHelper(current);
2223
}
2324

2425
public static IEnumerable GetChildren(DependencyObject current) {
26+
if (current == null) throw new ArgumentNullException("current");
2527
return new ChildrenEnumerable(current);
2628
}
2729

2830
public static DependencyObject FindLogicalNode(DependencyObject current, string name) {
31+
if (current == null) throw new ArgumentNullException("current");
2932
IntPtr cPtr = FindLogicalNodeHelper(current, name);
3033
return (DependencyObject)Noesis.Extend.GetProxy(cPtr, true);
3134
}

0 commit comments

Comments
 (0)