dali 1.2.28 version upgrade
[platform/core/csapi/nui.git] / Tizen.NUI / src / internal / PropertyRangeManager.cs
1 using System;
2 using System.Runtime.InteropServices;
3 using System.Collections.Generic;
4 using System.Reflection;
5
6 namespace Tizen.NUI
7 {\r
8     /// <summary>
9     /// Helper class for calculating what property indexes should be assigned to C# View (view) classes.
10     /// </summary>
11     internal class PropertyRangeManager
12   {
13     private Dictionary<String, PropertyRange > _propertyRange;
14
15     /// <summary>
16     /// Initializes a new instance of the <see cref="Tizen.NUI.PropertyRangeManager"/> class.
17     /// </summary>
18     public PropertyRangeManager ()
19     {
20       _propertyRange = new Dictionary<String, PropertyRange > ();
21     }
22
23     /// <summary>
24     /// Only called if a View has scriptable properties
25     /// </summary>
26     private PropertyRange RegisterView( string viewName, System.Type viewType )
27     {
28       PropertyRange range;
29
30       if ( _propertyRange.TryGetValue (viewName, out range) )
31       {
32         // already registered
33         return range;
34       }
35
36       // Find out the event and animatable start indexes for the type
37       range = new PropertyRange();
38
39       GetPropertyStartRange( viewType, ref range);
40
41       // add it to our dictionary
42       _propertyRange.Add( viewName, range );
43
44       return range;
45
46      }
47
48     /// <summary>
49     /// Gets the index of the property.
50     /// Each property has to have unique index for this view type
51     /// </summary>
52     /// <returns>The property index.</returns>
53     /// <param name="viewName">View name</param>
54     /// <param name="viewType">View type</param>
55     /// <param name="type">Type.</param>
56     public int GetPropertyIndex( string viewName, System.Type viewType, ScriptableProperty.ScriptableType type )
57     {
58
59       PropertyRange range;
60
61       if (!  _propertyRange.TryGetValue (viewName, out range) )
62       {
63          // view not found, register it now
64           range = RegisterView( viewName, viewType);
65       }
66
67       int index =  range.GetNextFreePropertyIndex ( type );
68
69       // update the dictionary
70       _propertyRange[viewName]=range;
71
72       return index;
73
74     }
75
76     ///<summary>
77     /// We calculate the start property indices, based on the type and it's class  heirachy, e.g. DateView (70,000)- > Spin (60,000) -> View (50,000)
78     /// </summary>
79     private void GetPropertyStartRange( System.Type viewType, ref PropertyRange range )
80     {
81       const int maxCountPerDerivation = 1000; // For child and animtable properties we use a gap of 1000 between each
82       // views property range in the heirachy
83
84       // custom views start there property index, at view_PROPERTY_END_INDEX
85       // we add 1000, just incase View class (our C# custom view base) starts using scriptable properties
86       int startEventPropertyIndex = (int)View.PropertyRange.CONTROL_PROPERTY_END_INDEX+maxCountPerDerivation;
87
88       // for animatable properties current range starts at ANIMATABLE_PROPERTY_REGISTRATION_START_INDEX,
89       // we add 1000, just incase View class starts using animatable properties
90       int startAnimatablePropertyIndex = (int)Tizen.NUI.PropertyRanges.ANIMATABLE_PROPERTY_REGISTRATION_START_INDEX +maxCountPerDerivation;
91
92       while ( viewType.GetTypeInfo().BaseType.Name != "CustomView" )   // custom view is our C# view base class. we don't go any deeper.
93       {
94         // for every base class increase property start index
95         startEventPropertyIndex += (int)Tizen.NUI.PropertyRanges.DEFAULT_PROPERTY_MAX_COUNT_PER_DERIVATION; // DALi uses 10,000
96         startAnimatablePropertyIndex += maxCountPerDerivation;
97
98         //Console.WriteLine ("getStartPropertyIndex =  " + viewType.Name +"current index " + startEventPropertyIndex);
99         viewType = viewType.GetTypeInfo().BaseType;
100       }
101
102       range.startEventIndex = startEventPropertyIndex;
103       range.lastUsedEventIndex = startEventPropertyIndex;
104
105       range.startAnimationIndex = startAnimatablePropertyIndex;
106       range.lastUsedAnimationIndex = startAnimatablePropertyIndex;
107
108     }
109
110
111     public struct PropertyRange
112     {
113
114       public int GetNextFreePropertyIndex( ScriptableProperty.ScriptableType type)
115       {
116         if ( type == ScriptableProperty.ScriptableType.Default )
117         {
118            lastUsedEventIndex++;
119            return lastUsedEventIndex;
120         }
121         else
122         {
123           lastUsedAnimationIndex++;
124           return lastUsedAnimationIndex ;
125         }
126       }
127
128
129       public int startEventIndex;    /// start of the property range
130       public int lastUsedEventIndex;    /// last used of the property index
131
132       public int startAnimationIndex;  /// start of the property range
133       public int lastUsedAnimationIndex; /// last used of the property index
134     };
135
136
137
138 }
139 }