Skip to content

Commit

Permalink
Updated to 3.0.9 version.
Browse files Browse the repository at this point in the history
  • Loading branch information
s-fernandez-v committed Jan 12, 2021
1 parent 8c4e9c0 commit 151a432
Show file tree
Hide file tree
Showing 34 changed files with 612 additions and 76 deletions.
28 changes: 27 additions & 1 deletion Src/Noesis/Core/Src/Core/Extend.cs
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,8 @@ public static void RegisterCallbacks()
_scrollInfoSetVerticalOffset,
_scrollInfoMakeVisible,

_markupExtensionProvideValue,

_getPropertyValue_Bool,
_getPropertyValue_Float,
_getPropertyValue_Double,
Expand Down Expand Up @@ -263,6 +265,7 @@ public static void UnregisterCallbacks()
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, 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, 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);
Expand Down Expand Up @@ -1744,7 +1747,7 @@ public static string StringFromNativeUtf8(IntPtr nativeUtf8)
{
if (nativeUtf8 == IntPtr.Zero)
{
return null;
return string.Empty;
}

#if __MonoCS__
Expand Down Expand Up @@ -3527,6 +3530,29 @@ private static void ScrollInfoMakeVisible(IntPtr cPtr, IntPtr visualType, IntPtr
}
}

////////////////////////////////////////////////////////////////////////////////////////////////
private delegate IntPtr Callback_MarkupExtensionProvideValue(IntPtr cPtr, IntPtr provider);
private static Callback_MarkupExtensionProvideValue _markupExtensionProvideValue = MarkupExtensionProvideValue;

[MonoPInvokeCallback(typeof(Callback_MarkupExtensionProvideValue))]
private static IntPtr MarkupExtensionProvideValue(IntPtr cPtr, IntPtr provider)
{
try
{
var extension = (MarkupExtension)GetExtendInstance(cPtr);
MarkupExtensionProvider provider_ = new MarkupExtensionProvider(provider);
object value = extension != null ? extension.ProvideValue(provider_) : null;
HandleRef itemPtr = GetInstanceHandle(value);
BaseComponent.AddReference(itemPtr.Handle); // released by native bindings
return itemPtr.Handle;
}
catch (Exception e)
{
Error.UnhandledException(e);
return IntPtr.Zero;
}
}

////////////////////////////////////////////////////////////////////////////////////////////////
private enum NativePropertyType
{
Expand Down
1 change: 1 addition & 0 deletions Src/Noesis/Core/Src/Core/ExtendImports.cs
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ static extern void Noesis_RegisterReflectionCallbacks(
Callback_ScrollInfoSetHorizontalOffset callback_ScrollInfoSetHorizontalOffset,
Callback_ScrollInfoSetVerticalOffset callback_ScrollInfoSetVerticalOffset,
Callback_ScrollInfoMakeVisible callback_ScrollInfoMakeVisible,
Callback_MarkupExtensionProvideValue callback_MarkupExtensionProvideValue,
Callback_GetPropertyValue_Bool callback_GetPropertyValue_Bool,
Callback_GetPropertyValue_Float callback_GetPropertyValue_Float,
Callback_GetPropertyValue_Double callback_GetPropertyValue_Double,
Expand Down
2 changes: 1 addition & 1 deletion Src/Noesis/Core/Src/Core/Library.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ namespace Noesis
{
public class Library
{
#if (UNITY_IOS || UNITY_WEBGL) && !UNITY_EDITOR
#if (UNITY_IOS || UNITY_TVOS || UNITY_WEBGL) && !UNITY_EDITOR
public const string Name = "__Internal";
#else
public const string Name = "Noesis";
Expand Down
179 changes: 179 additions & 0 deletions Src/Noesis/Core/Src/Core/MarkupExtensionProvider.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,179 @@
using System;
using System.Runtime.InteropServices;

namespace Noesis
{
/// <summary>
/// Represents a service that reports situational object-property relationships for markup extension evaluation.
/// </summary>
public interface IProvideValueTarget
{
/// <summary>
/// Gets the target object being reported.
/// </summary>
object TargetObject { get; }

/// <summary>
/// Gets an identifier for the target property being reported.
/// </summary>
object TargetProperty { get; }
}

/// <summary>
/// Represents a service that can use application context to resolve a provided relative URI to an absolute URI.
/// </summary>
public interface IUriContext
{
/// <summary>
/// Gets or sets the base URI of the current application context.
/// </summary>
Uri BaseUri { get; }
}

/// <summary>
/// Represents a service that resolves from named elements in XAML markup to the appropriate type.
/// </summary>
public interface IXamlTypeResolver
{
/// <summary>
/// Resolves a named XAML type to the corresponding Type. The type name is optionally qualified
/// by the prefix for a XML namespace, otherwise the current default XML namespace is assumed.
/// </summary>
Type Resolve(string qualifiedTypeName);
}

/// <summary>
/// Describes a service that can return a XAML namespace that is based on its prefix as it is mapped in XAML markup.
/// </summary>
public interface IXamlNamespaceResolver
{
/// <summary>
/// Retrieves a XAML namespace identifier for the specified prefix string.
/// </summary>
string GetNamespace(string prefix);
}

/// <summary>
/// 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.
/// </summary>
public interface IXamlNameResolver
{
/// <summary>
/// Resolves an object from a name reference.
/// </summary>
object Resolve(string name);
}

/// <summary>
/// Implementation of XAML service providers available for MarkupExtensions
/// </summary>
internal class MarkupExtensionProvider : IServiceProvider, IProvideValueTarget, IUriContext, IXamlTypeResolver, IXamlNamespaceResolver, IXamlNameResolver
{
object IServiceProvider.GetService(Type serviceType)
{
if (serviceType == typeof(IProvideValueTarget))
{
return this;
}
if (serviceType == typeof(IUriContext))
{
return this;
}
if (serviceType == typeof(IXamlTypeResolver))
{
return this;
}
if (serviceType == typeof(IXamlNamespaceResolver))
{
return this;
}
if (serviceType == typeof(IXamlNameResolver))
{
return this;
}

return null;
}

object IProvideValueTarget.TargetObject
{
get
{
IntPtr targetPtr = MarkupExtensionProvider_TargetObject(_provider);
return Extend.GetProxy(targetPtr, false);
}
}

object IProvideValueTarget.TargetProperty
{
get
{
IntPtr propPtr = MarkupExtensionProvider_TargetProperty(_provider);
return Extend.GetProxy(propPtr, false);
}
}

Uri IUriContext.BaseUri
{
get
{
IntPtr uriPtr = MarkupExtensionProvider_BaseUri(_provider);
string uri = Extend.StringFromNativeUtf8(uriPtr);
NoesisGUI_PINVOKE.FreeString(uriPtr);
return new Uri(uri, UriKind.Relative);
}
}

Type IXamlTypeResolver.Resolve(string qualifiedTypeName)
{
IntPtr cPtr = MarkupExtensionProvider_ResolveType(_provider, qualifiedTypeName);
if (cPtr != IntPtr.Zero)
{
Extend.NativeTypeInfo info = Extend.GetNativeTypeInfo(cPtr);
return info.Type;
}
return null;
}

string IXamlNamespaceResolver.GetNamespace(string prefix)
{
IntPtr strPtr = MarkupExtensionProvider_GetNamespace(_provider, prefix);
return Extend.StringFromNativeUtf8(strPtr);
}

object IXamlNameResolver.Resolve(string name)
{
IntPtr objectPtr = MarkupExtensionProvider_ResolveName(_provider, name);
return Extend.GetProxy(objectPtr, false);
}

#region Private members

internal MarkupExtensionProvider(IntPtr cPtr)
{
_provider = new HandleRef(this, cPtr);
}

private HandleRef _provider;

[DllImport(Library.Name)]
static extern IntPtr MarkupExtensionProvider_TargetObject(HandleRef provider);

[DllImport(Library.Name)]
static extern IntPtr MarkupExtensionProvider_TargetProperty(HandleRef provider);

[DllImport(Library.Name)]
static extern IntPtr MarkupExtensionProvider_BaseUri(HandleRef provider);

[DllImport(Library.Name)]
static extern IntPtr MarkupExtensionProvider_ResolveType(HandleRef provider, [MarshalAs(UnmanagedType.LPWStr)]string name);

[DllImport(Library.Name)]
static extern IntPtr MarkupExtensionProvider_GetNamespace(HandleRef provider, [MarshalAs(UnmanagedType.LPWStr)]string name);

[DllImport(Library.Name)]
static extern IntPtr MarkupExtensionProvider_ResolveName(HandleRef provider, [MarshalAs(UnmanagedType.LPWStr)]string name);

#endregion
}
}
11 changes: 11 additions & 0 deletions Src/Noesis/Core/Src/Core/View.cs
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,14 @@ public void SetProjectionMatrix(Matrix4 projection)
{
Noesis_View_SetProjectionMatrix(CPtr, ref projection);
}

/// <summary>
/// Indicates if touch input events are emulated by the mouse
/// </summary>
public void SetEmulateTouch(bool emulate)
{
Noesis_View_SetEmulateTouch(CPtr, emulate);
}
#endregion

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

[DllImport(Library.Name)]
static extern int Noesis_View_SetEmulateTouch(HandleRef view, bool emulate);

[DllImport(Library.Name)]
static extern void Noesis_View_Activate(HandleRef view);

Expand Down
24 changes: 19 additions & 5 deletions Src/Noesis/Core/Src/Proxies/Binding.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,15 @@ internal static HandleRef getCPtr(Binding obj) {
return (obj == null) ? new HandleRef(null, IntPtr.Zero) : obj.swigCPtr;
}

public object ProvideValue(object targetObject, DependencyProperty targetProperty) {
IntPtr cPtr = ProvideValueHelper(targetObject, targetProperty);
return Noesis.Extend.GetProxy(cPtr, true);
public override object ProvideValue(IServiceProvider serviceProvider) {
IProvideValueTarget valueTarget = serviceProvider as IProvideValueTarget;
if (valueTarget != null) {
object target = valueTarget.TargetObject;
object prop = valueTarget.TargetProperty;
IntPtr cPtr = ProvideValueHelper(target, prop as DependencyProperty);
return Noesis.Extend.GetProxy(cPtr, true);
}
return null;
}

public static object DoNothing {
Expand All @@ -51,8 +57,13 @@ public Binding() {
}

protected override IntPtr CreateCPtr(Type type, out bool registerExtend) {
registerExtend = false;
return NoesisGUI_PINVOKE.new_Binding__SWIG_0();
if (type == typeof(Binding)) {
registerExtend = false;
return NoesisGUI_PINVOKE.new_Binding__SWIG_0();
}
else {
return base.CreateExtendCPtr(type, out registerExtend);
}
}

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

internal new static IntPtr Extend(string typeName) {
return NoesisGUI_PINVOKE.Extend_Binding(Marshal.StringToHGlobalAnsi(typeName));
}
}

}
Expand Down
6 changes: 1 addition & 5 deletions Src/Noesis/Core/Src/Proxies/BindingBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,7 @@
namespace Noesis
{

public class BindingBase : MarkupExtension {
internal new static BindingBase CreateProxy(IntPtr cPtr, bool cMemoryOwn) {
return new BindingBase(cPtr, cMemoryOwn);
}

public abstract class BindingBase : MarkupExtension {
internal BindingBase(IntPtr cPtr, bool cMemoryOwn) : base(cPtr, cMemoryOwn) {
}

Expand Down
10 changes: 9 additions & 1 deletion Src/Noesis/Core/Src/Proxies/FontProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,19 @@ protected void RegisterFont(string folder, string id) {
RegisterFontHelper(folder, id);
}

/// <summary>
/// Notifies of changes to the specified texture file
/// </summary>
public delegate void FontChangedHandler(string baseUri, string familyName, FontWeight weight,
FontStretch stretch, FontStyle style);
public event FontChangedHandler FontChanged;

/// <summary>
/// Raises XamlChanged event notifying Noesis that it should reload the specified xaml
/// </summary>
protected void RaiseFontChanged(string baseUri, string familyName, FontWeight weight,
public void RaiseFontChanged(string baseUri, string familyName, FontWeight weight,
FontStretch stretch, FontStyle style) {
FontChanged?.Invoke(baseUri, familyName, weight, stretch, style);
Noesis_RaiseFontChanged(swigCPtr, baseUri, familyName, (int)weight, (int)stretch, (int)style);
}

Expand Down
8 changes: 8 additions & 0 deletions Src/Noesis/Core/Src/Proxies/ItemContainerGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,14 @@ public object ItemFromContainer(DependencyObject container) {
return Noesis.Extend.GetProxy(cPtr, false);
}

public void StartBatch() {
NoesisGUI_PINVOKE.ItemContainerGenerator_StartBatch(swigCPtr);
}

public void StopBatch() {
NoesisGUI_PINVOKE.ItemContainerGenerator_StopBatch(swigCPtr);
}

public GeneratorStatus Status {
get {
GeneratorStatus ret = (GeneratorStatus)NoesisGUI_PINVOKE.ItemContainerGenerator_Status_get(swigCPtr);
Expand Down
3 changes: 3 additions & 0 deletions Src/Noesis/Core/Src/Proxies/LogicalTreeHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,17 @@ namespace Noesis

public static class LogicalTreeHelper {
public static DependencyObject GetParent(DependencyObject current) {
if (current == null) throw new ArgumentNullException("current");
return GetParentHelper(current);
}

public static IEnumerable GetChildren(DependencyObject current) {
if (current == null) throw new ArgumentNullException("current");
return new ChildrenEnumerable(current);
}

public static DependencyObject FindLogicalNode(DependencyObject current, string name) {
if (current == null) throw new ArgumentNullException("current");
IntPtr cPtr = FindLogicalNodeHelper(current, name);
return (DependencyObject)Noesis.Extend.GetProxy(cPtr, true);
}
Expand Down
Loading

0 comments on commit 151a432

Please sign in to comment.