{
// ViewRegistry registers control type with DALi type registery
// also uses introspection to find any properties that need to be registered with type registry
- ViewRegistry.Instance.Register(CreateInstance, typeof(StarRating) );
+ CustomViewRegistry.Instance.Register(CreateInstance, typeof(StarRating) );
}
public StarRating() : base(typeof(StarRating).Name, CustomViewBehaviour.ViewBehaviourDefault)
static ContactView()
{
- ViewRegistry.Instance.Register( CreateInstance, typeof(ContactView));
+ CustomViewRegistry.Instance.Register( CreateInstance, typeof(ContactView));
}
public ContactView() : base(typeof(ContactView).Name, CustomViewBehaviour.RequiresKeyboardNavigationSupport)
/// The main entry point for the application.
/// </summary>
[STAThread]
- static void Main(string[] args)
+ static void _Main(string[] args)
{
VisualsExample visualsExample = new VisualsExample();
visualsExample.Run(args);
//You should not access any managed member here except static instance.
//because the execution order of Finalizes is non-deterministic.
- //Unreference this from if a static instance refer to this.
- ViewRegistry.UnregisterView(this);
+ //Unreference this from if a static instance refer to this.
+ Registry.Unregister(this);
if (swigCPtr.Handle != global::System.IntPtr.Zero)
{
//You should not access any managed member here except static instance.
//because the execution order of Finalizes is non-deterministic.
- //Unreference this from if a static instance refer to this.
- ViewRegistry.UnregisterView(this);
+ //Unreference this from if a static instance refer to this.
+ Registry.Unregister(this);
if (swigCPtr.Handle != global::System.IntPtr.Zero)
{
//because the execution order of Finalizes is non-deterministic.
//Unreference this from if a static instance refer to this.
- ViewRegistry.UnregisterView(this);
+ Registry.Unregister(this);
if (swigCPtr.Handle != global::System.IntPtr.Zero)
{
//You should not access any managed member here except static instance.
//because the execution order of Finalizes is non-deterministic.
- //Unreference this from if a static instance refer to this.
- ViewRegistry.UnregisterView(this);
+ //Unreference this from if a static instance refer to this.
+ Registry.Unregister(this);
if (swigCPtr.Handle != global::System.IntPtr.Zero)
{
//You should not access any managed member here except static instance.
//because the execution order of Finalizes is non-deterministic.
- //Unreference this from if a static instance refer to this.
- ViewRegistry.UnregisterView(this);
+ //Unreference this from if a static instance refer to this.
+ Registry.Unregister(this);
if (swigCPtr.Handle != global::System.IntPtr.Zero)
{
//You should not access any managed member here except static instance.
//because the execution order of Finalizes is non-deterministic.
- //Unreference this from if a static instance refer to this.
- ViewRegistry.UnregisterView(this);
+ //Unreference this from if a static instance refer to this.
+ Registry.Unregister(this);
if (swigCPtr.Handle != global::System.IntPtr.Zero)
{
//You should not access any managed member here except static instance.
//because the execution order of Finalizes is non-deterministic.
- //Unreference this from if a static instance refer to this.
- ViewRegistry.UnregisterView(this);
+ //Unreference this from if a static instance refer to this.
+ Registry.Unregister(this);
if (swigCPtr.Handle != global::System.IntPtr.Zero)
{
--- /dev/null
+
+//#define DOT_NET_CORE
+#if (DOT_NET_CORE)
+using System.Reflection;
+#endif
+using System;
+using System.Runtime.InteropServices;
+using System.Collections.Generic;
+using Tizen.NUI.BaseComponents;
+
+namespace Tizen.NUI
+{
+ /// <summary>
+ /// This is used to store a mapping between C++ base handle objects and it's C# instances.
+ ///
+ /// </summary>
+ internal sealed class Registry
+ {
+ /// <summary>
+ /// Registry is a singleton
+ /// </summary>
+ private static Registry instance = null;
+
+ /// <summary>
+ /// Given a C++ object the dictionary allows us to find which C# object it belongs to.
+ /// By keeping the weak reference only, it will allow the object to be garbage collected.
+ /// </summary>
+ private Dictionary<IntPtr, WeakReference> _controlMap;
+
+ private Registry()
+ {
+ _controlMap = new Dictionary<IntPtr, WeakReference>();
+ }
+
+
+ /// <summary>
+ /// Store the mapping between this instance of BaseHandle (C# base class) and native part.
+ /// </summary>
+ /// <param name="baseHandle"> The instance of BaseHandle (C# base class)</param>
+ internal static void Register(BaseHandle baseHandle)
+ {
+ // We store a pointer to the RefObject for the control
+ RefObject refObj = baseHandle.GetObjectPtr();
+ IntPtr refCptr = (IntPtr)RefObject.getCPtr(refObj);
+
+#if DEBUG_ON
+ Tizen.Log.Debug("NUI", "________Storing ref object cptr in control map Hex: {0:X}" + refCptr);
+#endif
+ if (!Instance._controlMap.ContainsKey(refCptr))
+ {
+ Instance._controlMap.Add(refCptr, new WeakReference(baseHandle, false));
+ }
+
+ return;
+ }
+
+ /// <summary>
+ /// Remove the this instance of BaseHandle (C# base class) and native part from the mapping table.
+ /// </summary>
+ /// <param name="view"> The instance of BaseHandle (C# base class)</param>
+ internal static void Unregister(BaseHandle baseHandle)
+ {
+ RefObject refObj = baseHandle.GetObjectPtr();
+ IntPtr refCptr = (IntPtr)RefObject.getCPtr(refObj);
+
+ if (Instance._controlMap.ContainsKey(refCptr))
+ {
+ Instance._controlMap.Remove(refCptr);
+ }
+
+ return;
+ }
+
+ private static Registry Instance
+ {
+ get
+ {
+ if (instance == null)
+ {
+ instance = new Registry();
+ }
+ return instance;
+ }
+ }
+
+ internal static BaseHandle GetManagedBaseHandleFromNativePtr(BaseHandle baseHandle)
+ {
+ // we store a dictionary of ref-obects (C++ land) to managed obects (C# land)
+
+ RefObject refObj = baseHandle.GetObjectPtr();
+ IntPtr refObjectPtr = (IntPtr)RefObject.getCPtr(refObj);
+
+ WeakReference viewReference;
+ if (Instance._controlMap.TryGetValue(refObjectPtr, out viewReference))
+ {
+ BaseHandle ret = viewReference.Target as BaseHandle;
+ return ret;
+ }
+ else
+ {
+ return null;
+ }
+ }
+
+ internal static BaseHandle GetManagedBaseHandleFromRefObject(IntPtr refObjectPtr)
+ {
+ // we store a dictionary of ref-obects (C++ land) to managed obects (C# land)
+
+ WeakReference weakReference;
+ if (Instance._controlMap.TryGetValue(refObjectPtr, out weakReference))
+ {
+ BaseHandle ret = weakReference.Target as BaseHandle;
+ return ret;
+ }
+ else
+ {
+ return null;
+ }
+ }
+
+ }
+}
//because the execution order of Finalizes is non-deterministic.
//Unreference this from if a static instance refer to this.
- ViewRegistry.UnregisterView(this);
+ Registry.Unregister(this);
if (swigCPtr.Handle != global::System.IntPtr.Zero)
{
{
swigCPtr = new global::System.Runtime.InteropServices.HandleRef(this, cPtr);
- // Register this instance of view in the view registry.
- ViewRegistry.RegisterView(this);
+ // Register this instance of view in the registry.
+ Registry.Register(this);
}
internal static global::System.Runtime.InteropServices.HandleRef getCPtr(View obj)
//because the execution order of Finalizes is non-deterministic.
//Unreference this from if a static instance refer to this.
- ViewRegistry.UnregisterView(this);
+ Registry.Unregister(this);
if (swigCPtr.Handle != global::System.IntPtr.Zero)
{
/// <returns>A object which inherit View</returns>
public static T DownCast<T>(View view) where T : View
{
- View ret = ViewRegistry.GetViewFromBaseHandle(view);
+ View ret = Registry.GetManagedBaseHandleFromNativePtr(view) as View;
if (ret != null)
{
return (T)ret;
BaseHandle ret = new BaseHandle(cPtr, false);
- View temp = ViewRegistry.GetViewFromBaseHandle(ret);
+ View temp = Registry.GetManagedBaseHandleFromNativePtr(ret) as View;
if (NDalicPINVOKE.SWIGPendingException.Pending)
throw NDalicPINVOKE.SWIGPendingException.Retrieve();
{
// ViewRegistry registers control type with DALi type registery
// also uses introspection to find any properties that need to be registered with type registry
- ViewRegistry.Instance.Register(CreateInstance, typeof(VisualView));
+ CustomViewRegistry.Instance.Register(CreateInstance, typeof(VisualView));
}
public VisualView() : base(typeof(VisualView).Name, CustomViewBehaviour.ViewBehaviourDefault)
}
- //temporary fix to pass TCT
+ //temporary fix to pass TCT
public Animation VisualAnimate(Tizen.NUI.VisualAnimator visualMap)
{
foreach (var item in _visualDictionary.ToList())
}
return null;
}
- //temporary fix to pass TCT
+ //temporary fix to pass TCT
}
}
{
// ViewRegistry registers control type with DALi type registery
// also uses introspection to find any properties that need to be registered with type registry
- ViewRegistry.Instance.Register(CreateInstance, typeof(Spin));
+ CustomViewRegistry.Instance.Register(CreateInstance, typeof(Spin));
}
/// <summary>
/// </remarks>
///
///
- internal class ScriptableProperty : System.Attribute
+ public class ScriptableProperty : System.Attribute
{
public enum ScriptableType
{
///
///
/// </summary>
- public sealed class ViewRegistry
+ public sealed class CustomViewRegistry
{
/// <summary>
/// ViewRegistry is a singleton
/// </summary>
- private static ViewRegistry instance = null;
+ private static CustomViewRegistry instance = null;
[UnmanagedFunctionPointer(CallingConvention.StdCall)]
- delegate IntPtr CreateControlDelegate(IntPtr cPtrControlName);
+ private delegate IntPtr CreateControlDelegate(IntPtr cPtrControlName);
[UnmanagedFunctionPointer(CallingConvention.StdCall)]
- delegate IntPtr GetPropertyDelegate(IntPtr controlPtr, IntPtr propertyName);
+ private delegate IntPtr GetPropertyDelegate(IntPtr controlPtr, IntPtr propertyName);
[UnmanagedFunctionPointer(CallingConvention.StdCall)]
- delegate void SetPropertyDelegate(IntPtr controlPtr, IntPtr propertyName, IntPtr propertyValue);
+ private delegate void SetPropertyDelegate(IntPtr controlPtr, IntPtr propertyName, IntPtr propertyValue);
private CreateControlDelegate _createCallback;
private SetPropertyDelegate _setPropertyCallback;
private GetPropertyDelegate _getPropertyCallback;
private PropertyRangeManager _propertyRangeManager;
- /// <summary>
- /// Given a C++ control the dictionary allows us to find which C# control (View) it belongs to.
- /// By keeping the weak reference only, it will allow the object to be garbage collected.
- /// </summary>
- private Dictionary<IntPtr, WeakReference> _controlMap;
-
///<summary>
// Maps the name of a custom view to a create instance function
/// E.g. given a string "Spin", we can get a function used to create the Spin View.
};
- private ViewRegistry()
+ private CustomViewRegistry()
{
_createCallback = new CreateControlDelegate(CreateControl);
_getPropertyCallback = new GetPropertyDelegate(GetProperty);
_setPropertyCallback = new SetPropertyDelegate(SetProperty);
- _controlMap = new Dictionary<IntPtr, WeakReference>();
_constructorMap = new Dictionary<string, Func<CustomView>>();
_propertyRangeManager = new PropertyRangeManager();
-
}
private Tizen.NUI.PropertyType GetDaliPropertyType(string cSharpTypeName)
}
}
- /// <summary>
- /// Store the mapping between this instance of control (View) and native part.
- /// </summary>
- /// <param name="view"> The instance of control (View)</param>
- internal static void RegisterView(View view)
- {
- // We store a pointer to the RefObject for the control
- RefObject refObj = view.GetObjectPtr();
- IntPtr refCptr = (IntPtr)RefObject.getCPtr(refObj);
-
-#if DEBUG_ON
- Tizen.Log.Debug("NUI", "________Storing ref object cptr in control map Hex: {0:X}" + refCptr);
-#endif
- if (!Instance._controlMap.ContainsKey(refCptr))
- {
- Instance._controlMap.Add(refCptr, new WeakReference(view, false));
- }
-
- return;
- }
-
- /// <summary>
- /// Remove the this instance of control (View) and native part from the mapping table.
- /// </summary>
- /// <param name="view"> The instance of control (View)</param>
- internal static void UnregisterView(View view)
- {
- RefObject refObj = view.GetObjectPtr();
- IntPtr refCptr = (IntPtr)RefObject.getCPtr(refObj);
-
- if (Instance._controlMap.ContainsKey(refCptr))
- {
- Instance._controlMap.Remove(refCptr);
- }
-
- return;
- }
-
private static IntPtr GetProperty(IntPtr controlPtr, IntPtr propertyName)
{
string name = System.Runtime.InteropServices.Marshal.PtrToStringAnsi(propertyName);
}
- public static ViewRegistry Instance
+ public static CustomViewRegistry Instance
{
get
{
if (instance == null)
{
- instance = new ViewRegistry();
+ instance = new CustomViewRegistry();
}
return instance;
}
}
-
- internal static View GetViewFromBaseHandle(BaseHandle baseHandle)
- {
- // we store a dictionary of ref-obects (C++ land) to custom views (C# land)
-
- RefObject refObj = baseHandle.GetObjectPtr();
- IntPtr refObjectPtr = (IntPtr)RefObject.getCPtr(refObj);
-
- WeakReference viewReference;
- if (Instance._controlMap.TryGetValue(refObjectPtr, out viewReference))
- {
- View retview = viewReference.Target as View;
- return retview;
- }
- else
- {
- return null;
- }
- }
-
-
/// <summary>
/// Function which registers a view and all it's scriptable properties with DALi's type registry.
/// Means the View can be created / configured from a JSON script.
/// Get a property value from a View
///
/// </summary>
- private IntPtr GetPropertyValue(IntPtr controlPtr, string propertyName)
+ private IntPtr GetPropertyValue(IntPtr refObjectPtr, string propertyName)
{
// Get the C# control that maps to the C++ control
- BaseHandle baseHandle = new BaseHandle(controlPtr, false);
-
- RefObject refObj = baseHandle.GetObjectPtr();
-
- IntPtr refObjectPtr = (IntPtr)RefObject.getCPtr(refObj);
-
- WeakReference viewReference;
- if (_controlMap.TryGetValue(refObjectPtr, out viewReference))
+ View view = Registry.GetManagedBaseHandleFromRefObject(refObjectPtr) as View;
+ if (view != null)
{
- View view = viewReference.Target as View;
-
// call the get property function
System.Object val = view.GetType().GetProperty(propertyName).GetAccessors()[0].Invoke(view, null);
/// Set a property value on a View
///
/// </summary>
- private void SetPropertyValue(IntPtr controlPtr, string propertyName, IntPtr propertyValuePtr)
+ private void SetPropertyValue(IntPtr refObjectPtr, string propertyName, IntPtr propertyValuePtr)
{
// Get the C# control that maps to the C++ control
#if DEBUG_ON
- Tizen.Log.Debug("NUI", "SetPropertyValue refObjectPtr = {0:X}" + controlPtr);
+ Tizen.Log.Debug("NUI", "SetPropertyValue refObjectPtr = {0:X}" + refObjectPtr);
#endif
PropertyValue propValue = new PropertyValue(propertyValuePtr, false);
- WeakReference viewReference;
- if (_controlMap.TryGetValue(controlPtr, out viewReference))
+ // Get the C# control that maps to the C++ control
+ View view = Registry.GetManagedBaseHandleFromRefObject(refObjectPtr) as View;
+ if (view != null)
{
- View view = viewReference.Target as View;
System.Reflection.PropertyInfo propertyInfo = view.GetType().GetProperty(propertyName);
// We know the property name, we know it's type, we just need to convert from a DALi property value to native C# type
}
else
{
- throw new global::System.InvalidOperationException("failed to find the control to write a property to: cptr = " + controlPtr);
+ throw new global::System.InvalidOperationException("failed to find the control to write a property to: cptr = " + refObjectPtr);
}
}
}
-
-
}
BaseHandle ret = new BaseHandle(cPtr, false);
- View temp = ViewRegistry.GetViewFromBaseHandle(ret);
+ View temp = Registry.GetManagedBaseHandleFromNativePtr(ret) as View;
if (NDalicPINVOKE.SWIGPendingException.Pending)
throw NDalicPINVOKE.SWIGPendingException.Retrieve();
//because the execution order of Finalizes is non-deterministic.
//Unreference this from if a static instance refer to this.
- ViewRegistry.UnregisterView(this);
+ Registry.Unregister(this);
if (swigCPtr.Handle != global::System.IntPtr.Zero)
{
//because the execution order of Finalizes is non-deterministic.
//Unreference this from if a static instance refer to this.
- ViewRegistry.UnregisterView(this);
+ Registry.Unregister(this);
if (swigCPtr.Handle != global::System.IntPtr.Zero)
{
//You should not access any managed member here except static instance.
//because the execution order of Finalizes is non-deterministic.
- //Unreference this from if a static instance refer to this.
- ViewRegistry.UnregisterView(this);
+ //Unreference this from if a static instance refer to this.
+ Registry.Unregister(this);
if (swigCPtr.Handle != global::System.IntPtr.Zero)
{
//because the execution order of Finalizes is non-deterministic.
//Unreference this from if a static instance refer to this.
- ViewRegistry.UnregisterView(this);
+ Registry.Unregister(this);
if (swigCPtr.Handle != global::System.IntPtr.Zero)
{
//because the execution order of Finalizes is non-deterministic.
//Unreference this from if a static instance refer to this.
- ViewRegistry.UnregisterView(this);
+ Registry.Unregister(this);
if (swigCPtr.Handle != global::System.IntPtr.Zero)
{
//because the execution order of Finalizes is non-deterministic.
//Unreference this from if a static instance refer to this.
- ViewRegistry.UnregisterView(this);
+ Registry.Unregister(this);
if (swigCPtr.Handle != global::System.IntPtr.Zero)
{
//because the execution order of Finalizes is non-deterministic.
//Unreference this from if a static instance refer to this.
- ViewRegistry.UnregisterView(this);
+ Registry.Unregister(this);
if (swigCPtr.Handle != global::System.IntPtr.Zero)
{
//because the execution order of Finalizes is non-deterministic.
//Unreference this from if a static instance refer to this.
- ViewRegistry.UnregisterView(this);
+ Registry.Unregister(this);
if (swigCPtr.Handle != global::System.IntPtr.Zero)
{