X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=plugins%2Fdali-swig%2Fmanual%2Fcsharp%2FViewRegistry.cs;h=b055a7dc23e57c3fec4c922c844ccfe240248851;hb=3705a737006a61c9796ee5f237c88d623fc65cbc;hp=bd9fecbbae11ce299b12e7b69cd548c52d32cf11;hpb=ee0a89caeed19cf95b4388a19651fb2403102671;p=platform%2Fcore%2Fuifw%2Fdali-toolkit.git
diff --git a/plugins/dali-swig/manual/csharp/ViewRegistry.cs b/plugins/dali-swig/manual/csharp/ViewRegistry.cs
index bd9fecb..b055a7d 100644
--- a/plugins/dali-swig/manual/csharp/ViewRegistry.cs
+++ b/plugins/dali-swig/manual/csharp/ViewRegistry.cs
@@ -139,9 +139,10 @@ namespace Dali
private PropertyRangeManager _propertyRangeManager;
///
- /// Given a C++ control the dictionary allows us to find which C# control (View) it belongs to
+ /// 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.
///
- private Dictionary _controlMap;
+ private Dictionary _controlMap;
///
// Maps the name of a custom view to a create instance function
@@ -177,7 +178,7 @@ namespace Dali
_getPropertyCallback = new GetPropertyDelegate (GetProperty);
_setPropertyCallback = new SetPropertyDelegate (SetProperty);
- _controlMap = new Dictionary();
+ _controlMap = new Dictionary();
_constructorMap = new Dictionary>();
_propertyRangeManager = new PropertyRangeManager();
@@ -237,7 +238,24 @@ namespace Dali
//Console.WriteLine ("________Storing ref object cptr in control map Hex: {0:X}", refCptr);
if ( !Instance._controlMap.ContainsKey(refCptr) )
{
- Instance._controlMap.Add(refCptr, view );
+ Instance._controlMap.Add(refCptr, new WeakReference(view, false));
+ }
+
+ return;
+ }
+
+ ///
+ /// Remove the this instance of control (View) and native part from the mapping table.
+ ///
+ /// The instance of control (View)
+ public 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;
@@ -272,13 +290,14 @@ namespace Dali
public static View GetViewFromActor( Actor actor )
{
// we store a dictionary of ref-obects (C++ land) to custom views (C# land)
- Dali.View view;
RefObject refObj = actor.GetObjectPtr ();
IntPtr refObjectPtr = (IntPtr) RefObject.getCPtr(refObj);
- if ( Instance._controlMap.TryGetValue ( refObjectPtr, out view) )
+ WeakReference viewReference;
+ if ( Instance._controlMap.TryGetValue ( refObjectPtr, out viewReference) )
{
+ View view = viewReference.Target as View;
return view;
}
else
@@ -352,16 +371,17 @@ namespace Dali
private IntPtr GetPropertyValue ( IntPtr controlPtr, string propertyName)
{
// Get the C# control that maps to the C++ control
- Dali.View view;
-
BaseHandle baseHandle = new BaseHandle (controlPtr, false);
RefObject refObj = baseHandle.GetObjectPtr ();
IntPtr refObjectPtr = (IntPtr) RefObject.getCPtr(refObj);
- if ( _controlMap.TryGetValue ( refObjectPtr, out view) )
+ WeakReference viewReference;
+ if ( _controlMap.TryGetValue ( refObjectPtr, out viewReference) )
{
+ View view = viewReference.Target as View;
+
// call the get property function
System.Object val = view.GetType ().GetProperty (propertyName).GetAccessors () [0].Invoke (view, null);
@@ -382,15 +402,15 @@ namespace Dali
private void SetPropertyValue ( IntPtr controlPtr, string propertyName, IntPtr propertyValuePtr)
{
// Get the C# control that maps to the C++ control
- Dali.View view;
//Console.WriteLine ("SetPropertyValue refObjectPtr = {0:X}", controlPtr);
Property.Value propValue = new Property.Value (propertyValuePtr, false);
- if ( _controlMap.TryGetValue ( controlPtr, out view) )
+ WeakReference viewReference;
+ if ( _controlMap.TryGetValue ( controlPtr, out viewReference) )
{
-
+ 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