2 using System.Reflection;
3 using System.Collections;
4 using System.Collections.Generic;
5 using System.ComponentModel;
7 namespace Tizen.NUI.Binding
9 /// <since_tizen> 6 </since_tizen>
10 /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
11 [EditorBrowsable(EditorBrowsableState.Never)]
12 public abstract class TriggerBase : BindableObject, IAttachedObject
16 internal TriggerBase(Type targetType)
18 if (targetType == null)
19 throw new ArgumentNullException("targetType");
20 TargetType = targetType;
22 EnterActions = new SealedList<TriggerAction>();
23 ExitActions = new SealedList<TriggerAction>();
26 internal TriggerBase(Condition condition, Type targetType) : this(targetType)
28 Setters = new SealedList<Setter>();
29 Condition = condition;
30 Condition.ConditionChanged = OnConditionChanged;
33 /// <since_tizen> 6 </since_tizen>
34 /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
35 [EditorBrowsable(EditorBrowsableState.Never)]
36 public IList<TriggerAction> EnterActions { get; }
38 /// <since_tizen> 6 </since_tizen>
39 /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
40 [EditorBrowsable(EditorBrowsableState.Never)]
41 public IList<TriggerAction> ExitActions { get; }
43 /// <since_tizen> 6 </since_tizen>
44 /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
45 [EditorBrowsable(EditorBrowsableState.Never)]
48 get { return _isSealed; }
51 if (_isSealed == value)
54 throw new InvalidOperationException("What is sealed can not be unsealed.");
60 /// <since_tizen> 6 </since_tizen>
61 /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
62 [EditorBrowsable(EditorBrowsableState.Never)]
63 public Type TargetType { get; }
65 internal Condition Condition { get; }
67 //Setters and Condition are used by Trigger, DataTrigger and MultiTrigger
68 internal IList<Setter> Setters { get; }
70 void IAttachedObject.AttachTo(BindableObject bindable)
75 throw new ArgumentNullException("bindable");
76 if (!TargetType.IsInstanceOfType(bindable))
77 throw new InvalidOperationException("bindable not an instance of AssociatedType");
78 OnAttachedTo(bindable);
81 void IAttachedObject.DetachFrom(BindableObject bindable)
84 throw new ArgumentNullException("bindable");
85 OnDetachingFrom(bindable);
88 internal virtual void OnAttachedTo(BindableObject bindable)
90 if (Condition != null)
91 Condition.SetUp(bindable);
94 internal virtual void OnDetachingFrom(BindableObject bindable)
96 if (Condition != null)
97 Condition.TearDown(bindable);
100 internal virtual void OnSeal()
102 ((SealedList<TriggerAction>)EnterActions).IsReadOnly = true;
103 ((SealedList<TriggerAction>)ExitActions).IsReadOnly = true;
105 ((SealedList<Setter>)Setters).IsReadOnly = true;
106 if (Condition != null)
107 Condition.IsSealed = true;
110 void OnConditionChanged(BindableObject bindable, bool oldValue, bool newValue)
114 foreach (TriggerAction action in EnterActions)
115 action.DoInvoke(bindable);
116 foreach (Setter setter in Setters)
117 setter.Apply(bindable);
121 foreach (Setter setter in Setters)
122 setter.UnApply(bindable);
123 foreach (TriggerAction action in ExitActions)
124 action.DoInvoke(bindable);
128 internal class SealedList<T> : IList<T>
130 readonly IList<T> _actual;
136 _actual = new List<T>();
139 public void Add(T item)
142 throw new InvalidOperationException("This list is ReadOnly");
149 throw new InvalidOperationException("This list is ReadOnly");
153 public bool Contains(T item)
155 return _actual.Contains(item);
158 public void CopyTo(T[] array, int arrayIndex)
160 _actual.CopyTo(array, arrayIndex);
165 get { return _actual.Count; }
168 public bool IsReadOnly
170 get { return _isReadOnly; }
173 if (_isReadOnly == value)
176 throw new InvalidOperationException("Can't change this back to non readonly");
181 public bool Remove(T item)
184 throw new InvalidOperationException("This list is ReadOnly");
185 return _actual.Remove(item);
188 IEnumerator IEnumerable.GetEnumerator()
190 return ((IEnumerable)_actual).GetEnumerator();
193 public IEnumerator<T> GetEnumerator()
195 return _actual.GetEnumerator();
198 public int IndexOf(T item)
200 return _actual.IndexOf(item);
203 public void Insert(int index, T item)
206 throw new InvalidOperationException("This list is ReadOnly");
207 _actual.Insert(index, item);
210 public T this[int index]
212 get { return _actual[index]; }
216 throw new InvalidOperationException("This list is ReadOnly");
217 _actual[index] = value;
221 public void RemoveAt(int index)
224 throw new InvalidOperationException("This list is ReadOnly");
225 _actual.RemoveAt(index);