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