Skip to content

Commit

Permalink
Updated to NoesisGUI 3.1.1 version
Browse files Browse the repository at this point in the history
  • Loading branch information
s-fernandez-v committed Sep 15, 2021
1 parent 3f38f45 commit 825f166
Show file tree
Hide file tree
Showing 30 changed files with 549 additions and 169 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -244,4 +244,6 @@ project.lock.json

Src/Samples/
BuildManagedSDK.py
Samples.sln
Samples.sln

Src/NoesisApp/Controls/*
3 changes: 1 addition & 2 deletions Src/Noesis/Core/Src/Core/ContentPropertyAttribute.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@ public sealed class ContentPropertyAttribute : Attribute

/// <summary>Gets the name of the property that is the content property.</summary>
/// <returns>The name of the property that is the content property.</returns>
public string Name { get{ return this._name; }
}
public string Name { get{ return this._name; } }

/// <summary>Initializes a new instance of the ContentPropertyAttribute class.</summary>
public ContentPropertyAttribute() { }
Expand Down
28 changes: 4 additions & 24 deletions Src/Noesis/Core/Src/Core/Events.cs
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ public static void AddHandler(UIElement element, IntPtr routedEventPtr, Delegate
{
events = new EventHandlerStore(element);
_elements.Add(ptr, events);
Noesis_Dependency_RegisterDestroyed(cPtr);
element.Destroyed += OnElementDestroyed;
}

long routedEventKey = routedEventPtr.ToInt64();
Expand Down Expand Up @@ -222,7 +222,7 @@ public static void RemoveHandler(UIElement element, IntPtr routedEventPtr, Deleg

if (events._binds.Count == 0)
{
Noesis_Dependency_UnregisterDestroyed(cPtr);
element.Destroyed -= OnElementDestroyed;
_elements.Remove(ptr);
}
}
Expand Down Expand Up @@ -302,7 +302,7 @@ public static void AddHandler(UIElement element, string eventId, Delegate handle
{
events = new EventHandlerStore(element);
_elements.Add(ptr, events);
Noesis_Dependency_RegisterDestroyed(cPtr);
element.Destroyed += OnElementDestroyed;
}

long eventKey = eventId.GetHashCode();
Expand Down Expand Up @@ -362,7 +362,7 @@ public static void RemoveHandler(UIElement element, string eventId, Delegate han

if (events._binds.Count == 0)
{
Noesis_Dependency_UnregisterDestroyed(cPtr);
element.Destroyed -= OnElementDestroyed;
_elements.Remove(ptr);
}
}
Expand Down Expand Up @@ -416,11 +416,6 @@ private static void RaiseEvent(IntPtr cPtrType, IntPtr cPtr, string eventId,
#endregion

#region Private members
static EventHandlerStore()
{
Noesis_Dependency_SetDestroyedCallback(_destroyedCallback);
}

private EventHandlerStore(UIElement element)
{
_element = BaseComponent.getCPtr(element).Handle;
Expand All @@ -446,14 +441,8 @@ internal static void Clear(EventHandlerStore[] events)
View._Rendering.Clear();
}

private delegate void DestroyedCallback(IntPtr d);
private static DestroyedCallback _destroyedCallback = OnElementDestroyed;

[MonoPInvokeCallback(typeof(DestroyedCallback))]
private static void OnElementDestroyed(IntPtr d)
{
Noesis_Dependency_UnregisterDestroyed(d);

EventHandlerStore events;
long ptr = d.ToInt64();
if (_elements.TryGetValue(ptr, out events))
Expand Down Expand Up @@ -485,15 +474,6 @@ private static extern void Noesis_Event_Bind(RaiseEventCallback callback,
[DllImport(Library.Name)]
private static extern void Noesis_Event_Unbind(RaiseEventCallback callback,
IntPtr element, [MarshalAs(UnmanagedType.LPWStr)]string eventId);

[DllImport(Library.Name)]
private static extern void Noesis_Dependency_SetDestroyedCallback(DestroyedCallback callback);

[DllImport(Library.Name)]
private static extern void Noesis_Dependency_RegisterDestroyed(IntPtr cPtr);

[DllImport(Library.Name)]
private static extern void Noesis_Dependency_UnregisterDestroyed(IntPtr cPtr);
#endregion
}

Expand Down
39 changes: 35 additions & 4 deletions Src/Noesis/Core/Src/Core/Extend.cs
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ public static void RegisterCallbacks()
_frameworkElementMeasure,
_frameworkElementArrange,
_frameworkElementConnectEvent,
_frameworkElementApplyTemplate,
_freezableClone,

_toString,
Expand Down Expand Up @@ -250,7 +251,7 @@ public static void UnregisterCallbacks()
Noesis_RegisterReflectionCallbacks(
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 @@ -1174,7 +1175,8 @@ private enum ExtendTypeOverrides
Measure = 8,
Arrange = 16,
Connect = 32,
Clone = 64
Template = 64,
Clone = 128
}

private struct ExtendPropertyData
Expand Down Expand Up @@ -1491,6 +1493,9 @@ private static ExtendTypeData CreateNativeTypeData(System.Type type, IntPtr nati
MethodInfo connectMethod = FindMethod(type, "ConnectEvent", new Type[] { typeof(object), typeof(string), typeof(string) });
if (IsOverride(connectMethod)) overrides |= ExtendTypeOverrides.Connect;

MethodInfo templateMethod = FindMethod(type, "OnApplyTemplate", new Type[] { });
if (IsOverride(templateMethod)) overrides |= ExtendTypeOverrides.Template;

MethodInfo cloneMethod = FindMethod(type, "CloneCommonCore", new Type[] { typeof(Freezable) });
if (IsOverride(cloneMethod)) overrides |= ExtendTypeOverrides.Clone;

Expand Down Expand Up @@ -1973,6 +1978,27 @@ private static bool FrameworkElementConnectEvent(IntPtr cPtr,
return false;
}

////////////////////////////////////////////////////////////////////////////////////////////////
private delegate void Callback_FrameworkElementApplyTemplate(IntPtr cPtr);
private static Callback_FrameworkElementApplyTemplate _frameworkElementApplyTemplate = FrameworkElementApplyTemplate;

[MonoPInvokeCallback(typeof(Callback_FrameworkElementApplyTemplate))]
private static void FrameworkElementApplyTemplate(IntPtr cPtr)
{
try
{
FrameworkElement element = (FrameworkElement)GetExtendInstance(cPtr);
if (element != null)
{
element.OnApplyTemplate();
}
}
catch (Exception e)
{
Error.UnhandledException(e);
}
}

////////////////////////////////////////////////////////////////////////////////////////////////
private delegate void Callback_FreezableClone(IntPtr cPtrType, IntPtr cPtrClone,
IntPtr cPtrSource);
Expand Down Expand Up @@ -4940,10 +4966,10 @@ private static BaseComponent GetProxyInstance(IntPtr cPtr, bool ownMemory, Nativ
return (BaseComponent)Binding.DoNothing;
}

long ptr = cPtr.ToInt64();
lock (_proxies)
{
WeakReference wr;
long ptr = cPtr.ToInt64();
if (_proxies.TryGetValue(ptr, out wr))
{
if (wr != null)
Expand All @@ -4966,7 +4992,12 @@ private static BaseComponent GetProxyInstance(IntPtr cPtr, bool ownMemory, Nativ
}
}

return ((NativeTypeComponentInfo)info).Creator(cPtr, ownMemory);
if (BaseComponent.GetNumReferences(cPtr) > 0)
{
return ((NativeTypeComponentInfo)info).Creator(cPtr, ownMemory);
}

return null;
}

////////////////////////////////////////////////////////////////////////////////////////////////
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 @@ -54,6 +54,7 @@ static extern void Noesis_RegisterReflectionCallbacks(
Callback_FrameworkElementMeasure callback_FrameworkElementMeasure,
Callback_FrameworkElementArrange callback_FrameworkElementArrange,
Callback_FrameworkElementConnectEvent callback_FrameworkElementConnectEvent,
Callback_FrameworkElementApplyTemplate callback_FrameworkElementApplyTemplate,
Callback_FreezableClone callback_FreezableClone,
Callback_ToString callback_ToString,
Callback_Equals callback_Equals,
Expand Down
37 changes: 37 additions & 0 deletions Src/Noesis/Core/Src/Core/StyleTypedPropertyAttribute.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
using System;

namespace Noesis
{
/// <summary>
/// This attribute is applied to the class and determine the target type which should be used for
/// the properties of type Style. The definition inherits to the subclasses or the derived class
/// can redefine the target type for the property already defined in the base class.
/// </summary>
[AttributeUsage(AttributeTargets.Class, AllowMultiple = true)]
public sealed class StyleTypedPropertyAttribute : Attribute
{
/// <summary>Default constructor</summary>
public StyleTypedPropertyAttribute() { }

/// <summary>
/// The property name of type Style
/// </summary>
public string Property
{
get { return _property; }
set { _property = value; }
}

/// <summary>
/// Target type of the Style that should be used for the Property
/// </summary>
public Type StyleTargetType
{
get { return _styleTargetType; }
set { _styleTargetType = value; }
}

private string _property;
private Type _styleTargetType;
}
}
36 changes: 36 additions & 0 deletions Src/Noesis/Core/Src/Core/TemplatePartAttribute.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
using System;

namespace Noesis
{
/// <summary>
/// Style authors should be able to identify the part type used for styling the specific class.
/// The part is usually required in the style and should have a specific predefined name.
/// </summary>
[AttributeUsage(AttributeTargets.Class, AllowMultiple = true)]
public sealed class TemplatePartAttribute : Attribute
{
/// <summary>Default constructor</summary>
public TemplatePartAttribute() { }

/// <summary>
/// Part name used by the class to indentify required element in the style
/// </summary>
public string Name
{
get { return _name; }
set { _name = value; }
}

/// <summary>
/// Type of the element that should be used as a part with specified name
/// </summary>
public Type Type
{
get { return _type; }
set { _type = value; }
}

private string _name;
private Type _type;
}
}
5 changes: 5 additions & 0 deletions Src/Noesis/Core/Src/Proxies/BaseComponent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,11 @@ internal static void Release(IntPtr cPtr) {
NoesisGUI_PINVOKE.BaseComponent_Release(cPtr);
}

public static int GetNumReferences(IntPtr cPtr) {
int ret = NoesisGUI_PINVOKE.BaseComponent_GetNumReferences(cPtr);
return ret;
}

internal static IntPtr Extend(string typeName) {
return NoesisGUI_PINVOKE.Extend_BaseComponent(Marshal.StringToHGlobalAnsi(typeName));
}
Expand Down
7 changes: 7 additions & 0 deletions Src/Noesis/Core/Src/Proxies/ColumnDefinition.cs
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,13 @@ protected override IntPtr CreateCPtr(Type type, out bool registerExtend) {
}
}

public new float ActualWidth {
get {
float ret = NoesisGUI_PINVOKE.ColumnDefinition_ActualWidth_get(swigCPtr);
return ret;
}
}

}

}
Expand Down
18 changes: 18 additions & 0 deletions Src/Noesis/Core/Src/Proxies/ComboBox.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,13 @@ public static DependencyProperty MaxDropDownHeightProperty {
}
}

public static DependencyProperty PlaceholderProperty {
get {
IntPtr cPtr = NoesisGUI_PINVOKE.ComboBox_PlaceholderProperty_get();
return (DependencyProperty)Noesis.Extend.GetProxy(cPtr, false);
}
}

public static DependencyProperty SelectionBoxItemProperty {
get {
IntPtr cPtr = NoesisGUI_PINVOKE.ComboBox_SelectionBoxItemProperty_get();
Expand Down Expand Up @@ -175,6 +182,17 @@ public string Text {
}
}

public string Placeholder {
set {
NoesisGUI_PINVOKE.ComboBox_Placeholder_set(swigCPtr, value != null ? value : string.Empty);
}
get {
IntPtr strPtr = NoesisGUI_PINVOKE.ComboBox_Placeholder_get(swigCPtr);
string str = Noesis.Extend.StringFromNativeUtf8(strPtr);
return str;
}
}

internal new static IntPtr Extend(string typeName) {
return NoesisGUI_PINVOKE.Extend_ComboBox(Marshal.StringToHGlobalAnsi(typeName));
}
Expand Down
Loading

0 comments on commit 825f166

Please sign in to comment.