3 using System.Reflection;
5 using System.Runtime.InteropServices;
6 using System.Collections.Generic;
7 using Tizen.NUI.BaseComponents;
12 /// The helper class for calculating what property indexes should be assigned to the C# View (view) classes.
14 internal class PropertyRangeManager
16 private Dictionary<String, PropertyRange> _propertyRange;
19 /// Initializes a new instance of the <see cref="Tizen.NUI.PropertyRangeManager"/> class.
21 public PropertyRangeManager()
23 _propertyRange = new Dictionary<String, PropertyRange>();
27 /// Only called if a view has scriptable properties.
29 private PropertyRange RegisterView(string viewName, System.Type viewType)
33 if (_propertyRange.TryGetValue(viewName, out range))
39 // Find out the event and animatable start indexes for the type
40 range = new PropertyRange();
42 GetPropertyStartRange(viewType, ref range);
44 // add it to our dictionary
45 _propertyRange.Add(viewName, range);
52 /// Gets the index of the property.
53 /// Each property has to have unique index for this view type.
55 /// <returns>The property index.</returns>
56 /// <param name="viewName">The view name.</param>
57 /// <param name="viewType">The view type.</param>
58 /// <param name="type">Type.</param>
59 public int GetPropertyIndex(string viewName, System.Type viewType, ScriptableProperty.ScriptableType type)
64 if (!_propertyRange.TryGetValue(viewName, out range))
66 // view not found, register it now
67 range = RegisterView(viewName, viewType);
70 int index = range.GetNextFreePropertyIndex(type);
72 // update the dictionary
73 _propertyRange[viewName] = range;
80 /// We calculate the start property indices, based on the type and it's class hierarchy, for example, DateView (70,000)- > Spin (60,000) -> View (50,000).
82 private void GetPropertyStartRange(System.Type viewType, ref PropertyRange range)
84 const int maxCountPerDerivation = 1000; // For child and animtable properties we use a gap of 1000 between each
85 // views property range in the heirachy
87 // custom views start there property index, at view_PROPERTY_END_INDEX
88 // we add 1000, just incase View class (our C# custom view base) starts using scriptable properties
89 int startEventPropertyIndex = (int)View.PropertyRange.CONTROL_PROPERTY_END_INDEX + maxCountPerDerivation;
91 // for animatable properties current range starts at ANIMATABLE_PROPERTY_REGISTRATION_START_INDEX,
92 // we add 1000, just incase View class starts using animatable properties
93 int startAnimatablePropertyIndex = (int)Tizen.NUI.PropertyRanges.ANIMATABLE_PROPERTY_REGISTRATION_START_INDEX + maxCountPerDerivation;
95 while (viewType.GetTypeInfo().BaseType.Name != "CustomView") // custom view is our C# view base class. we don't go any deeper.
97 // for every base class increase property start index
98 startEventPropertyIndex += (int)Tizen.NUI.PropertyRanges.DEFAULT_PROPERTY_MAX_COUNT_PER_DERIVATION; // DALi uses 10,000
99 startAnimatablePropertyIndex += maxCountPerDerivation;
100 NUILog.Debug("getStartPropertyIndex = " + viewType.Name + "current index " + startEventPropertyIndex);
101 viewType = viewType.GetTypeInfo().BaseType;
104 range.startEventIndex = startEventPropertyIndex;
105 range.lastUsedEventIndex = startEventPropertyIndex;
107 range.startAnimationIndex = startAnimatablePropertyIndex;
108 range.lastUsedAnimationIndex = startAnimatablePropertyIndex;
113 /// <since_tizen> 3 </since_tizen>
114 public struct PropertyRange
117 /// <since_tizen> 3 </since_tizen>
118 public int GetNextFreePropertyIndex(ScriptableProperty.ScriptableType type)
120 if (type == ScriptableProperty.ScriptableType.Default)
122 lastUsedEventIndex++;
123 return lastUsedEventIndex;
127 lastUsedAnimationIndex++;
128 return lastUsedAnimationIndex;
133 /// <since_tizen> 3 </since_tizen>
134 public int startEventIndex; // start of the property range
135 /// <since_tizen> 3 </since_tizen>
136 public int lastUsedEventIndex; // last used of the property index
138 /// <since_tizen> 3 </since_tizen>
139 public int startAnimationIndex; // start of the property range
140 /// <since_tizen> 3 </since_tizen>
141 public int lastUsedAnimationIndex; // last used of the property index