Skip to content

Commit 825f166

Browse files
committed
Updated to NoesisGUI 3.1.1 version
1 parent 3f38f45 commit 825f166

30 files changed

+549
-169
lines changed

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -244,4 +244,6 @@ project.lock.json
244244

245245
Src/Samples/
246246
BuildManagedSDK.py
247-
Samples.sln
247+
Samples.sln
248+
249+
Src/NoesisApp/Controls/*

Src/Noesis/Core/Src/Core/ContentPropertyAttribute.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,7 @@ public sealed class ContentPropertyAttribute : Attribute
1212

1313
/// <summary>Gets the name of the property that is the content property.</summary>
1414
/// <returns>The name of the property that is the content property.</returns>
15-
public string Name { get{ return this._name; }
16-
}
15+
public string Name { get{ return this._name; } }
1716

1817
/// <summary>Initializes a new instance of the ContentPropertyAttribute class.</summary>
1918
public ContentPropertyAttribute() { }

Src/Noesis/Core/Src/Core/Events.cs

Lines changed: 4 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ public static void AddHandler(UIElement element, IntPtr routedEventPtr, Delegate
168168
{
169169
events = new EventHandlerStore(element);
170170
_elements.Add(ptr, events);
171-
Noesis_Dependency_RegisterDestroyed(cPtr);
171+
element.Destroyed += OnElementDestroyed;
172172
}
173173

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

223223
if (events._binds.Count == 0)
224224
{
225-
Noesis_Dependency_UnregisterDestroyed(cPtr);
225+
element.Destroyed -= OnElementDestroyed;
226226
_elements.Remove(ptr);
227227
}
228228
}
@@ -302,7 +302,7 @@ public static void AddHandler(UIElement element, string eventId, Delegate handle
302302
{
303303
events = new EventHandlerStore(element);
304304
_elements.Add(ptr, events);
305-
Noesis_Dependency_RegisterDestroyed(cPtr);
305+
element.Destroyed += OnElementDestroyed;
306306
}
307307

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

363363
if (events._binds.Count == 0)
364364
{
365-
Noesis_Dependency_UnregisterDestroyed(cPtr);
365+
element.Destroyed -= OnElementDestroyed;
366366
_elements.Remove(ptr);
367367
}
368368
}
@@ -416,11 +416,6 @@ private static void RaiseEvent(IntPtr cPtrType, IntPtr cPtr, string eventId,
416416
#endregion
417417

418418
#region Private members
419-
static EventHandlerStore()
420-
{
421-
Noesis_Dependency_SetDestroyedCallback(_destroyedCallback);
422-
}
423-
424419
private EventHandlerStore(UIElement element)
425420
{
426421
_element = BaseComponent.getCPtr(element).Handle;
@@ -446,14 +441,8 @@ internal static void Clear(EventHandlerStore[] events)
446441
View._Rendering.Clear();
447442
}
448443

449-
private delegate void DestroyedCallback(IntPtr d);
450-
private static DestroyedCallback _destroyedCallback = OnElementDestroyed;
451-
452-
[MonoPInvokeCallback(typeof(DestroyedCallback))]
453444
private static void OnElementDestroyed(IntPtr d)
454445
{
455-
Noesis_Dependency_UnregisterDestroyed(d);
456-
457446
EventHandlerStore events;
458447
long ptr = d.ToInt64();
459448
if (_elements.TryGetValue(ptr, out events))
@@ -485,15 +474,6 @@ private static extern void Noesis_Event_Bind(RaiseEventCallback callback,
485474
[DllImport(Library.Name)]
486475
private static extern void Noesis_Event_Unbind(RaiseEventCallback callback,
487476
IntPtr element, [MarshalAs(UnmanagedType.LPWStr)]string eventId);
488-
489-
[DllImport(Library.Name)]
490-
private static extern void Noesis_Dependency_SetDestroyedCallback(DestroyedCallback callback);
491-
492-
[DllImport(Library.Name)]
493-
private static extern void Noesis_Dependency_RegisterDestroyed(IntPtr cPtr);
494-
495-
[DllImport(Library.Name)]
496-
private static extern void Noesis_Dependency_UnregisterDestroyed(IntPtr cPtr);
497477
#endregion
498478
}
499479

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

Lines changed: 35 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@ public static void RegisterCallbacks()
121121
_frameworkElementMeasure,
122122
_frameworkElementArrange,
123123
_frameworkElementConnectEvent,
124+
_frameworkElementApplyTemplate,
124125
_freezableClone,
125126

126127
_toString,
@@ -250,7 +251,7 @@ public static void UnregisterCallbacks()
250251
Noesis_RegisterReflectionCallbacks(
251252
null,
252253
null,
253-
null, null, null, null, null,
254+
null, null, null, null, null, null,
254255
null, null,
255256
null, null,
256257
null, null, null, null,
@@ -1174,7 +1175,8 @@ private enum ExtendTypeOverrides
11741175
Measure = 8,
11751176
Arrange = 16,
11761177
Connect = 32,
1177-
Clone = 64
1178+
Template = 64,
1179+
Clone = 128
11781180
}
11791181

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

1496+
MethodInfo templateMethod = FindMethod(type, "OnApplyTemplate", new Type[] { });
1497+
if (IsOverride(templateMethod)) overrides |= ExtendTypeOverrides.Template;
1498+
14941499
MethodInfo cloneMethod = FindMethod(type, "CloneCommonCore", new Type[] { typeof(Freezable) });
14951500
if (IsOverride(cloneMethod)) overrides |= ExtendTypeOverrides.Clone;
14961501

@@ -1973,6 +1978,27 @@ private static bool FrameworkElementConnectEvent(IntPtr cPtr,
19731978
return false;
19741979
}
19751980

1981+
////////////////////////////////////////////////////////////////////////////////////////////////
1982+
private delegate void Callback_FrameworkElementApplyTemplate(IntPtr cPtr);
1983+
private static Callback_FrameworkElementApplyTemplate _frameworkElementApplyTemplate = FrameworkElementApplyTemplate;
1984+
1985+
[MonoPInvokeCallback(typeof(Callback_FrameworkElementApplyTemplate))]
1986+
private static void FrameworkElementApplyTemplate(IntPtr cPtr)
1987+
{
1988+
try
1989+
{
1990+
FrameworkElement element = (FrameworkElement)GetExtendInstance(cPtr);
1991+
if (element != null)
1992+
{
1993+
element.OnApplyTemplate();
1994+
}
1995+
}
1996+
catch (Exception e)
1997+
{
1998+
Error.UnhandledException(e);
1999+
}
2000+
}
2001+
19762002
////////////////////////////////////////////////////////////////////////////////////////////////
19772003
private delegate void Callback_FreezableClone(IntPtr cPtrType, IntPtr cPtrClone,
19782004
IntPtr cPtrSource);
@@ -4940,10 +4966,10 @@ private static BaseComponent GetProxyInstance(IntPtr cPtr, bool ownMemory, Nativ
49404966
return (BaseComponent)Binding.DoNothing;
49414967
}
49424968

4943-
long ptr = cPtr.ToInt64();
49444969
lock (_proxies)
49454970
{
49464971
WeakReference wr;
4972+
long ptr = cPtr.ToInt64();
49474973
if (_proxies.TryGetValue(ptr, out wr))
49484974
{
49494975
if (wr != null)
@@ -4966,7 +4992,12 @@ private static BaseComponent GetProxyInstance(IntPtr cPtr, bool ownMemory, Nativ
49664992
}
49674993
}
49684994

4969-
return ((NativeTypeComponentInfo)info).Creator(cPtr, ownMemory);
4995+
if (BaseComponent.GetNumReferences(cPtr) > 0)
4996+
{
4997+
return ((NativeTypeComponentInfo)info).Creator(cPtr, ownMemory);
4998+
}
4999+
5000+
return null;
49705001
}
49715002

49725003
////////////////////////////////////////////////////////////////////////////////////////////////

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ static extern void Noesis_RegisterReflectionCallbacks(
5454
Callback_FrameworkElementMeasure callback_FrameworkElementMeasure,
5555
Callback_FrameworkElementArrange callback_FrameworkElementArrange,
5656
Callback_FrameworkElementConnectEvent callback_FrameworkElementConnectEvent,
57+
Callback_FrameworkElementApplyTemplate callback_FrameworkElementApplyTemplate,
5758
Callback_FreezableClone callback_FreezableClone,
5859
Callback_ToString callback_ToString,
5960
Callback_Equals callback_Equals,
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
using System;
2+
3+
namespace Noesis
4+
{
5+
/// <summary>
6+
/// This attribute is applied to the class and determine the target type which should be used for
7+
/// the properties of type Style. The definition inherits to the subclasses or the derived class
8+
/// can redefine the target type for the property already defined in the base class.
9+
/// </summary>
10+
[AttributeUsage(AttributeTargets.Class, AllowMultiple = true)]
11+
public sealed class StyleTypedPropertyAttribute : Attribute
12+
{
13+
/// <summary>Default constructor</summary>
14+
public StyleTypedPropertyAttribute() { }
15+
16+
/// <summary>
17+
/// The property name of type Style
18+
/// </summary>
19+
public string Property
20+
{
21+
get { return _property; }
22+
set { _property = value; }
23+
}
24+
25+
/// <summary>
26+
/// Target type of the Style that should be used for the Property
27+
/// </summary>
28+
public Type StyleTargetType
29+
{
30+
get { return _styleTargetType; }
31+
set { _styleTargetType = value; }
32+
}
33+
34+
private string _property;
35+
private Type _styleTargetType;
36+
}
37+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
using System;
2+
3+
namespace Noesis
4+
{
5+
/// <summary>
6+
/// Style authors should be able to identify the part type used for styling the specific class.
7+
/// The part is usually required in the style and should have a specific predefined name.
8+
/// </summary>
9+
[AttributeUsage(AttributeTargets.Class, AllowMultiple = true)]
10+
public sealed class TemplatePartAttribute : Attribute
11+
{
12+
/// <summary>Default constructor</summary>
13+
public TemplatePartAttribute() { }
14+
15+
/// <summary>
16+
/// Part name used by the class to indentify required element in the style
17+
/// </summary>
18+
public string Name
19+
{
20+
get { return _name; }
21+
set { _name = value; }
22+
}
23+
24+
/// <summary>
25+
/// Type of the element that should be used as a part with specified name
26+
/// </summary>
27+
public Type Type
28+
{
29+
get { return _type; }
30+
set { _type = value; }
31+
}
32+
33+
private string _name;
34+
private Type _type;
35+
}
36+
}

Src/Noesis/Core/Src/Proxies/BaseComponent.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,11 @@ internal static void Release(IntPtr cPtr) {
6262
NoesisGUI_PINVOKE.BaseComponent_Release(cPtr);
6363
}
6464

65+
public static int GetNumReferences(IntPtr cPtr) {
66+
int ret = NoesisGUI_PINVOKE.BaseComponent_GetNumReferences(cPtr);
67+
return ret;
68+
}
69+
6570
internal static IntPtr Extend(string typeName) {
6671
return NoesisGUI_PINVOKE.Extend_BaseComponent(Marshal.StringToHGlobalAnsi(typeName));
6772
}

Src/Noesis/Core/Src/Proxies/ColumnDefinition.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,13 @@ protected override IntPtr CreateCPtr(Type type, out bool registerExtend) {
9393
}
9494
}
9595

96+
public new float ActualWidth {
97+
get {
98+
float ret = NoesisGUI_PINVOKE.ColumnDefinition_ActualWidth_get(swigCPtr);
99+
return ret;
100+
}
101+
}
102+
96103
}
97104

98105
}

Src/Noesis/Core/Src/Proxies/ComboBox.cs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,13 @@ public static DependencyProperty MaxDropDownHeightProperty {
7272
}
7373
}
7474

75+
public static DependencyProperty PlaceholderProperty {
76+
get {
77+
IntPtr cPtr = NoesisGUI_PINVOKE.ComboBox_PlaceholderProperty_get();
78+
return (DependencyProperty)Noesis.Extend.GetProxy(cPtr, false);
79+
}
80+
}
81+
7582
public static DependencyProperty SelectionBoxItemProperty {
7683
get {
7784
IntPtr cPtr = NoesisGUI_PINVOKE.ComboBox_SelectionBoxItemProperty_get();
@@ -175,6 +182,17 @@ public string Text {
175182
}
176183
}
177184

185+
public string Placeholder {
186+
set {
187+
NoesisGUI_PINVOKE.ComboBox_Placeholder_set(swigCPtr, value != null ? value : string.Empty);
188+
}
189+
get {
190+
IntPtr strPtr = NoesisGUI_PINVOKE.ComboBox_Placeholder_get(swigCPtr);
191+
string str = Noesis.Extend.StringFromNativeUtf8(strPtr);
192+
return str;
193+
}
194+
}
195+
178196
internal new static IntPtr Extend(string typeName) {
179197
return NoesisGUI_PINVOKE.Extend_ComboBox(Marshal.StringToHGlobalAnsi(typeName));
180198
}

0 commit comments

Comments
 (0)