Revert "[NUI] Fix ConvertIdToView (#877)" (#889)
[platform/core/csapi/tizenfx.git] / src / Tizen.NUI.Xaml / src / internal / XamlBinding / Effect.cs
1 using System;
2 using System.ComponentModel;
3
4 namespace Tizen.NUI.XamlBinding
5 {
6     /// <summary>
7     /// A collection of styles and properties that can be added to an element at run time.
8     /// </summary>
9     internal abstract class Effect
10     {
11         internal Effect()
12         {
13         }
14
15         /// <summary>
16         /// Gets the element to which the style is attached.
17         /// </summary>
18         public Element Element { get; internal set; }
19
20         /// <summary>
21         /// Gets a value that tells whether the effect is attached to an element.
22         /// </summary>
23         public bool IsAttached { get; private set; }
24
25         /// <summary>
26         /// Gets the ID that is used to resolve this effect at runtime.
27         /// </summary>
28         public string ResolveId { get; internal set; }
29
30         #region Statics
31         /// <summary>
32         /// Returns an Effect for the specified name, which is of the form ResolutionGroupName.ExportEffect.
33         /// </summary>
34         /// <param name="name">The name of the effect to get.</param>
35         /// <returns>The uniquely identified effect.</returns>
36         public static Effect Resolve(string name)
37         {
38             Effect result = null;
39             if (Tizen.NUI.XamlBinding.Internals.Registrar.Effects.TryGetValue(name, out Type effectType))
40             {
41                 result = (Effect)DependencyResolver.ResolveOrCreate(effectType);
42             }
43
44             if (result == null)
45                 result = new NullEffect();
46             result.ResolveId = name;
47             return result;
48         }
49
50         #endregion
51
52         /// <summary>
53         /// Method that is called after the effect is attached and made valid.
54         /// </summary>
55         protected abstract void OnAttached();
56
57         /// <summary>
58         /// Method that is called after the effect is detached and invalidated.
59         /// </summary>
60         protected abstract void OnDetached();
61
62         internal virtual void ClearEffect()
63         {
64             if (IsAttached)
65                 SendDetached();
66             Element = null;
67         }
68
69         internal virtual void SendAttached()
70         {
71             if (IsAttached)
72                 return;
73             OnAttached();
74             IsAttached = true;
75         }
76
77         internal virtual void SendDetached()
78         {
79             if (!IsAttached)
80                 return;
81             OnDetached();
82             IsAttached = false;
83         }
84
85         internal virtual void SendOnElementPropertyChanged(PropertyChangedEventArgs args)
86         {
87         }
88     }
89 }