[Xaml] Add MergeStyle to View
[platform/core/csapi/tizenfx.git] / src / Tizen.NUI / src / public / BaseComponents / ViewInternal.cs
1 /*
2  * Copyright(c) 2021 Samsung Electronics Co., Ltd.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  */
17
18 using System;
19 using System.Collections.Generic;
20 using System.ComponentModel;
21 using System.Diagnostics;
22 using System.Runtime.CompilerServices;
23 using Tizen.NUI.Binding;
24
25 namespace Tizen.NUI.BaseComponents
26 {
27     /// <summary>
28     /// View is the base class for all views.
29     /// </summary>
30     /// <since_tizen> 3 </since_tizen>
31     public partial class View
32     {
33         private MergedStyle mergedStyle = null;
34         internal string styleName;
35
36         internal MergedStyle MergedStyle
37         {
38             get
39             {
40                 if (null == mergedStyle)
41                 {
42                     mergedStyle = new MergedStyle(GetType(), this);
43                 }
44
45                 return mergedStyle;
46             }
47         }
48
49         internal class ThemeData
50         {
51             [Flags]
52             private enum States : byte
53             {
54                 None = 0,
55                 ControlStatePropagation = 1 << 0,
56                 ThemeChangeSensitive = 1 << 1,
57                 ThemeApplied = 1 << 2, // It is true when the view has valid style name or the platform theme has a component style for this view type.
58                                        // That indicates the view can have different styles by theme.
59                                        // Hence if the current state has ThemeApplied and ThemeChangeSensitive, the view will change its style by theme changing.
60                 ListeningThemeChangeEvent = 1 << 3,
61             };
62
63             private States states = ThemeManager.ApplicationThemeChangeSensitive ? States.ThemeChangeSensitive : States.None;
64             public ViewStyle viewStyle;
65             public ControlState controlStates = ControlState.Normal;
66             public ViewSelectorData selectorData;
67
68             public bool ControlStatePropagation
69             {
70                 get => ((states & States.ControlStatePropagation) != 0);
71                 set => SetOption(States.ControlStatePropagation, value);
72             }
73
74             public bool ThemeChangeSensitive
75             {
76                 get => ((states & States.ThemeChangeSensitive) != 0);
77                 set => SetOption(States.ThemeChangeSensitive, value);
78             }
79
80             public bool ThemeApplied
81             {
82                 get => ((states & States.ThemeApplied) != 0);
83                 set => SetOption(States.ThemeApplied, value);
84             }
85
86             public bool ListeningThemeChangeEvent
87             {
88                 get => ((states & States.ListeningThemeChangeEvent) != 0);
89                 set => SetOption(States.ListeningThemeChangeEvent, value);
90             }
91
92             private void SetOption(States option, bool value)
93             {
94                 if (value) states |= option;
95                 else states &= ~option;
96             }
97         }
98
99         /// <summary>
100         /// The color mode of View.
101         /// This specifies whether the View uses its own color, or inherits its parent color.
102         /// The default is ColorMode.UseOwnMultiplyParentColor.
103         /// </summary>
104         internal ColorMode ColorMode
105         {
106             set
107             {
108                 SetColorMode(value);
109             }
110             get
111             {
112                 return GetColorMode();
113             }
114         }
115
116         internal LayoutLength SuggestedMinimumWidth
117         {
118             get
119             {
120                 float result = Interop.Actor.GetSuggestedMinimumWidth(SwigCPtr);
121                 if (NDalicPINVOKE.SWIGPendingException.Pending)
122                     throw NDalicPINVOKE.SWIGPendingException.Retrieve();
123                 return new LayoutLength(result);
124             }
125         }
126
127         internal LayoutLength SuggestedMinimumHeight
128         {
129             get
130             {
131                 float result = Interop.Actor.GetSuggestedMinimumHeight(SwigCPtr);
132                 if (NDalicPINVOKE.SWIGPendingException.Pending)
133                     throw NDalicPINVOKE.SWIGPendingException.Retrieve();
134                 return new LayoutLength(result);
135             }
136         }
137
138         internal float WorldPositionX
139         {
140             get
141             {
142                 float returnValue = 0.0f;
143                 PropertyValue wordPositionX = GetProperty(View.Property.WorldPositionX);
144                 wordPositionX?.Get(out returnValue);
145                 wordPositionX?.Dispose();
146                 return returnValue;
147             }
148         }
149
150         internal float WorldPositionY
151         {
152             get
153             {
154                 float returnValue = 0.0f;
155                 PropertyValue wordPositionY = GetProperty(View.Property.WorldPositionY);
156                 wordPositionY?.Get(out returnValue);
157                 wordPositionY?.Dispose();
158                 return returnValue;
159             }
160         }
161
162         internal float WorldPositionZ
163         {
164             get
165             {
166                 float returnValue = 0.0f;
167                 PropertyValue wordPositionZ = GetProperty(View.Property.WorldPositionZ);
168                 wordPositionZ?.Get(out returnValue);
169                 wordPositionZ?.Dispose();
170                 return returnValue;
171             }
172         }
173
174         internal bool FocusState
175         {
176             get
177             {
178                 return IsKeyboardFocusable();
179             }
180             set
181             {
182                 SetKeyboardFocusable(value);
183             }
184         }
185
186         internal void SetLayout(LayoutItem layout)
187         {
188             Window.Instance.LayoutController.CreateProcessCallback();
189             this.layout = layout;
190             this.layout?.AttachToOwner(this);
191             this.layout?.RequestLayout();
192         }
193
194         internal void AttachTransitionsToChildren(LayoutTransition transition)
195         {
196             // Iterate children, adding the transition unless a transition
197             // for the same condition and property has already been
198             // explicitly added.
199             foreach (View view in Children)
200             {
201                 LayoutTransitionsHelper.AddTransitionForCondition(view.LayoutTransitions, transition.Condition, transition, false);
202             }
203         }
204
205         internal float ParentOriginX
206         {
207             get
208             {
209                 float returnValue = 0.0f;
210                 PropertyValue parentOriginX = GetProperty(View.Property.ParentOriginX);
211                 parentOriginX?.Get(out returnValue);
212                 parentOriginX?.Dispose();
213                 return returnValue;
214             }
215             set
216             {
217                 PropertyValue setValue = new Tizen.NUI.PropertyValue(value);
218                 SetProperty(View.Property.ParentOriginX, setValue);
219                 setValue.Dispose();
220                 NotifyPropertyChanged();
221             }
222         }
223
224         internal float ParentOriginY
225         {
226             get
227             {
228                 float returnValue = 0.0f;
229                 PropertyValue parentOriginY = GetProperty(View.Property.ParentOriginY);
230                 parentOriginY?.Get(out returnValue);
231                 parentOriginY?.Dispose();
232                 return returnValue;
233             }
234             set
235             {
236                 PropertyValue setValue = new Tizen.NUI.PropertyValue(value);
237                 SetProperty(View.Property.ParentOriginY, setValue);
238                 setValue.Dispose();
239                 NotifyPropertyChanged();
240             }
241         }
242
243         internal float ParentOriginZ
244         {
245             get
246             {
247                 float returnValue = 0.0f;
248                 PropertyValue parentOriginZ = GetProperty(View.Property.ParentOriginZ);
249                 parentOriginZ?.Get(out returnValue);
250                 parentOriginZ?.Dispose();
251                 return returnValue;
252             }
253             set
254             {
255                 PropertyValue setValue = new Tizen.NUI.PropertyValue(value);
256                 SetProperty(View.Property.ParentOriginZ, setValue);
257                 setValue.Dispose();
258                 NotifyPropertyChanged();
259             }
260         }
261
262         internal float PivotPointX
263         {
264             get
265             {
266                 float returnValue = 0.0f;
267                 PropertyValue anchorPointX = GetProperty(View.Property.AnchorPointX);
268                 anchorPointX?.Get(out returnValue);
269                 anchorPointX?.Dispose();
270                 return returnValue;
271             }
272             set
273             {
274                 PropertyValue setValue = new Tizen.NUI.PropertyValue(value);
275                 SetProperty(View.Property.AnchorPointX, setValue);
276                 setValue.Dispose();
277             }
278         }
279
280         internal float PivotPointY
281         {
282             get
283             {
284                 float returnValue = 0.0f;
285                 PropertyValue anchorPointY = GetProperty(View.Property.AnchorPointY);
286                 anchorPointY?.Get(out returnValue);
287                 anchorPointY?.Dispose();
288                 return returnValue;
289             }
290             set
291             {
292                 PropertyValue setValue = new Tizen.NUI.PropertyValue(value);
293                 SetProperty(View.Property.AnchorPointY, setValue);
294                 setValue.Dispose();
295             }
296         }
297
298         internal float PivotPointZ
299         {
300             get
301             {
302                 float returnValue = 0.0f;
303                 PropertyValue anchorPointZ = GetProperty(View.Property.AnchorPointZ);
304                 anchorPointZ?.Get(out returnValue);
305                 anchorPointZ?.Dispose();
306                 return returnValue;
307             }
308             set
309             {
310                 PropertyValue setValue = new Tizen.NUI.PropertyValue(value);
311                 SetProperty(View.Property.AnchorPointZ, setValue);
312                 setValue.Dispose();
313             }
314         }
315
316         internal Matrix WorldMatrix
317         {
318             get
319             {
320                 Matrix returnValue = new Matrix();
321                 PropertyValue wordMatrix = GetProperty(View.Property.WorldMatrix);
322                 wordMatrix?.Get(returnValue);
323                 wordMatrix?.Dispose();
324                 return returnValue;
325             }
326         }
327
328         /// <summary>
329         /// Indicates that this View should listen Touch event to handle its ControlState.
330         /// </summary>
331         private bool enableControlState = false;
332
333         private int LeftFocusableViewId
334         {
335             get
336             {
337                 int returnValue = 0;
338                 PropertyValue leftFocusableViewId = GetProperty(View.Property.LeftFocusableViewId);
339                 leftFocusableViewId?.Get(out returnValue);
340                 leftFocusableViewId?.Dispose();
341                 return returnValue;
342             }
343             set
344             {
345                 PropertyValue setValue = new Tizen.NUI.PropertyValue(value);
346                 SetProperty(View.Property.LeftFocusableViewId, setValue);
347                 setValue.Dispose();
348             }
349         }
350
351         private int RightFocusableViewId
352         {
353             get
354             {
355                 int returnValue = 0;
356                 PropertyValue rightFocusableViewId = GetProperty(View.Property.RightFocusableViewId);
357                 rightFocusableViewId?.Get(out returnValue);
358                 rightFocusableViewId?.Dispose();
359                 return returnValue;
360             }
361             set
362             {
363                 PropertyValue setValue = new Tizen.NUI.PropertyValue(value);
364                 SetProperty(View.Property.RightFocusableViewId, setValue);
365                 setValue.Dispose();
366             }
367         }
368
369         private int UpFocusableViewId
370         {
371             get
372             {
373                 int returnValue = 0;
374                 PropertyValue upFocusableViewId = GetProperty(View.Property.UpFocusableViewId);
375                 upFocusableViewId?.Get(out returnValue);
376                 upFocusableViewId?.Dispose();
377                 return returnValue;
378             }
379             set
380             {
381                 PropertyValue setValue = new Tizen.NUI.PropertyValue(value);
382                 SetProperty(View.Property.UpFocusableViewId, setValue);
383                 setValue.Dispose();
384             }
385         }
386
387         private int DownFocusableViewId
388         {
389             get
390             {
391                 int returnValue = 0;
392                 PropertyValue downFocusableViewId = GetProperty(View.Property.DownFocusableViewId);
393                 downFocusableViewId?.Get(out returnValue);
394                 downFocusableViewId?.Dispose();
395                 return returnValue;
396             }
397             set
398             {
399                 PropertyValue setValue = new Tizen.NUI.PropertyValue(value);
400                 SetProperty(View.Property.DownFocusableViewId, setValue);
401                 setValue.Dispose();
402             }
403         }
404
405         internal void Raise()
406         {
407             var parentChildren = GetParent()?.Children;
408
409             if (parentChildren != null)
410             {
411                 int currentIndex = parentChildren.IndexOf(this);
412
413                 // If the view is not already the last item in the list.
414                 if (currentIndex >= 0 && currentIndex < parentChildren.Count - 1)
415                 {
416                     View temp = parentChildren[currentIndex + 1];
417                     parentChildren[currentIndex + 1] = this;
418                     parentChildren[currentIndex] = temp;
419
420                     Interop.NDalic.Raise(SwigCPtr);
421                     if (NDalicPINVOKE.SWIGPendingException.Pending)
422                         throw NDalicPINVOKE.SWIGPendingException.Retrieve();
423                 }
424             }
425         }
426
427         internal void Lower()
428         {
429             var parentChildren = GetParent()?.Children;
430
431             if (parentChildren != null)
432             {
433                 int currentIndex = parentChildren.IndexOf(this);
434
435                 // If the view is not already the first item in the list.
436                 if (currentIndex > 0 && currentIndex < parentChildren.Count)
437                 {
438                     View temp = parentChildren[currentIndex - 1];
439                     parentChildren[currentIndex - 1] = this;
440                     parentChildren[currentIndex] = temp;
441
442                     Interop.NDalic.Lower(SwigCPtr);
443                     if (NDalicPINVOKE.SWIGPendingException.Pending)
444                         throw NDalicPINVOKE.SWIGPendingException.Retrieve();
445                 }
446             }
447         }
448
449         /// <summary>
450         /// Raises the view to above the target view.
451         /// </summary>
452         /// <remarks>The sibling order of views within the parent will be updated automatically.
453         /// Views on the level above the target view will still be shown above this view.
454         /// Raising this view above views with the same sibling order as each other will raise this view above them.
455         /// Once a raise or lower API is used that view will then have an exclusive sibling order independent of insertion.
456         /// </remarks>
457         /// <param name="target">Will be raised above this view.</param>
458         internal void RaiseAbove(View target)
459         {
460             var parentChildren = GetParent()?.Children;
461
462             if (parentChildren != null)
463             {
464                 int currentIndex = parentChildren.IndexOf(this);
465                 int targetIndex = parentChildren.IndexOf(target);
466
467                 if (currentIndex < 0 || targetIndex < 0 ||
468                     currentIndex >= parentChildren.Count || targetIndex >= parentChildren.Count)
469                 {
470                     NUILog.Error("index should be bigger than 0 and less than children of layer count");
471                     return;
472                 }
473                 // If the currentIndex is less than the target index and the target has the same parent.
474                 if (currentIndex < targetIndex)
475                 {
476                     parentChildren.Remove(this);
477                     parentChildren.Insert(targetIndex, this);
478
479                     Interop.NDalic.RaiseAbove(SwigCPtr, View.getCPtr(target));
480                     if (NDalicPINVOKE.SWIGPendingException.Pending)
481                         throw NDalicPINVOKE.SWIGPendingException.Retrieve();
482                 }
483             }
484
485         }
486
487         /// <summary>
488         /// Lowers the view to below the target view.
489         /// </summary>
490         /// <remarks>The sibling order of views within the parent will be updated automatically.
491         /// Lowering this view below views with the same sibling order as each other will lower this view above them.
492         /// Once a raise or lower API is used that view will then have an exclusive sibling order independent of insertion.
493         /// </remarks>
494         /// <param name="target">Will be lowered below this view.</param>
495         internal void LowerBelow(View target)
496         {
497             var parentChildren = GetParent()?.Children;
498
499             if (parentChildren != null)
500             {
501                 int currentIndex = parentChildren.IndexOf(this);
502                 int targetIndex = parentChildren.IndexOf(target);
503                 if (currentIndex < 0 || targetIndex < 0 ||
504                    currentIndex >= parentChildren.Count || targetIndex >= parentChildren.Count)
505                 {
506                     NUILog.Error("index should be bigger than 0 and less than children of layer count");
507                     return;
508                 }
509
510                 // If the currentIndex is not already the 0th index and the target has the same parent.
511                 if ((currentIndex != 0) && (targetIndex != -1) &&
512                     (currentIndex > targetIndex))
513                 {
514                     parentChildren.Remove(this);
515                     parentChildren.Insert(targetIndex, this);
516
517                     Interop.NDalic.LowerBelow(SwigCPtr, View.getCPtr(target));
518                     if (NDalicPINVOKE.SWIGPendingException.Pending)
519                         throw NDalicPINVOKE.SWIGPendingException.Retrieve();
520                 }
521             }
522
523         }
524
525         internal string GetName()
526         {
527             string ret = Interop.Actor.GetName(SwigCPtr);
528             if (NDalicPINVOKE.SWIGPendingException.Pending)
529                 throw NDalicPINVOKE.SWIGPendingException.Retrieve();
530             return ret;
531         }
532
533         internal void SetName(string name)
534         {
535             Interop.Actor.SetName(SwigCPtr, name);
536             if (NDalicPINVOKE.SWIGPendingException.Pending)
537                 throw NDalicPINVOKE.SWIGPendingException.Retrieve();
538         }
539
540         internal uint GetId()
541         {
542             uint ret = Interop.Actor.GetId(SwigCPtr);
543             if (NDalicPINVOKE.SWIGPendingException.Pending)
544                 throw NDalicPINVOKE.SWIGPendingException.Retrieve();
545             return ret;
546         }
547
548         internal bool IsRoot()
549         {
550             bool ret = Interop.ActorInternal.IsRoot(SwigCPtr);
551             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
552             return ret;
553         }
554
555         internal bool OnWindow()
556         {
557             bool ret = Interop.Actor.OnStage(SwigCPtr);
558             if (NDalicPINVOKE.SWIGPendingException.Pending)
559                 throw NDalicPINVOKE.SWIGPendingException.Retrieve();
560             return ret;
561         }
562
563         internal View FindChildById(uint id)
564         {
565             //to fix memory leak issue, match the handle count with native side.
566             IntPtr cPtr = Interop.Actor.FindChildById(SwigCPtr, id);
567             View ret = this.GetInstanceSafely<View>(cPtr);
568             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
569             return ret;
570         }
571
572         internal override View FindCurrentChildById(uint id)
573         {
574             return FindChildById(id);
575         }
576
577         internal void SetParentOrigin(Vector3 origin)
578         {
579             Interop.ActorInternal.SetParentOrigin(SwigCPtr, Vector3.getCPtr(origin));
580             if (NDalicPINVOKE.SWIGPendingException.Pending)
581                 throw NDalicPINVOKE.SWIGPendingException.Retrieve();
582         }
583
584         internal Vector3 GetCurrentParentOrigin()
585         {
586             Vector3 ret = new Vector3(Interop.ActorInternal.GetCurrentParentOrigin(SwigCPtr), true);
587             if (NDalicPINVOKE.SWIGPendingException.Pending)
588                 throw NDalicPINVOKE.SWIGPendingException.Retrieve();
589             return ret;
590         }
591
592         internal void SetAnchorPoint(Vector3 anchorPoint)
593         {
594             Interop.Actor.SetAnchorPoint(SwigCPtr, Vector3.getCPtr(anchorPoint));
595             if (NDalicPINVOKE.SWIGPendingException.Pending)
596                 throw NDalicPINVOKE.SWIGPendingException.Retrieve();
597         }
598
599         internal Vector3 GetCurrentAnchorPoint()
600         {
601             Vector3 ret = new Vector3(Interop.ActorInternal.GetCurrentAnchorPoint(SwigCPtr), true);
602             if (NDalicPINVOKE.SWIGPendingException.Pending)
603                 throw NDalicPINVOKE.SWIGPendingException.Retrieve();
604             return ret;
605         }
606
607         internal void SetSize(float width, float height)
608         {
609             Interop.ActorInternal.SetSize(SwigCPtr, width, height);
610             if (NDalicPINVOKE.SWIGPendingException.Pending)
611                 throw NDalicPINVOKE.SWIGPendingException.Retrieve();
612         }
613
614         internal void SetSize(float width, float height, float depth)
615         {
616             Interop.ActorInternal.SetSize(SwigCPtr, width, height, depth);
617             if (NDalicPINVOKE.SWIGPendingException.Pending)
618                 throw NDalicPINVOKE.SWIGPendingException.Retrieve();
619         }
620
621         internal void SetSize(Vector2 size)
622         {
623             Interop.ActorInternal.SetSizeVector2(SwigCPtr, Vector2.getCPtr(size));
624             if (NDalicPINVOKE.SWIGPendingException.Pending)
625                 throw NDalicPINVOKE.SWIGPendingException.Retrieve();
626         }
627
628         internal void SetSize(Vector3 size)
629         {
630             Interop.ActorInternal.SetSizeVector3(SwigCPtr, Vector3.getCPtr(size));
631             if (NDalicPINVOKE.SWIGPendingException.Pending)
632                 throw NDalicPINVOKE.SWIGPendingException.Retrieve();
633         }
634
635         internal Vector3 GetTargetSize()
636         {
637             Vector3 ret = new Vector3(Interop.ActorInternal.GetTargetSize(SwigCPtr), true);
638             if (NDalicPINVOKE.SWIGPendingException.Pending)
639                 throw NDalicPINVOKE.SWIGPendingException.Retrieve();
640             return ret;
641         }
642
643         internal Size2D GetCurrentSize()
644         {
645             Size ret = new Size(Interop.Actor.GetCurrentSize(SwigCPtr), true);
646             if (NDalicPINVOKE.SWIGPendingException.Pending)
647                 throw NDalicPINVOKE.SWIGPendingException.Retrieve();
648             Size2D size = new Size2D((int)ret.Width, (int)ret.Height);
649             ret.Dispose();
650             return size;
651         }
652
653         internal Size2D GetCurrentSizeFloat()
654         {
655             Size ret = new Size(Interop.Actor.GetCurrentSize(SwigCPtr), true);
656             if (NDalicPINVOKE.SWIGPendingException.Pending)
657                 throw NDalicPINVOKE.SWIGPendingException.Retrieve();
658             return ret;
659         }
660
661         internal Vector3 GetNaturalSize()
662         {
663             Vector3 ret = new Vector3(Interop.Actor.GetNaturalSize(SwigCPtr), true);
664             if (NDalicPINVOKE.SWIGPendingException.Pending)
665                 throw NDalicPINVOKE.SWIGPendingException.Retrieve();
666             return ret;
667         }
668
669         internal void SetPosition(float x, float y)
670         {
671             Interop.ActorInternal.SetPosition(SwigCPtr, x, y);
672             if (NDalicPINVOKE.SWIGPendingException.Pending)
673                 throw NDalicPINVOKE.SWIGPendingException.Retrieve();
674         }
675
676         internal void SetPosition(float x, float y, float z)
677         {
678             Interop.ActorInternal.SetPosition(SwigCPtr, x, y, z);
679             if (NDalicPINVOKE.SWIGPendingException.Pending)
680                 throw NDalicPINVOKE.SWIGPendingException.Retrieve();
681         }
682
683         internal void SetPosition(Vector3 position)
684         {
685             Interop.ActorInternal.SetPosition(SwigCPtr, Vector3.getCPtr(position));
686             if (NDalicPINVOKE.SWIGPendingException.Pending)
687                 throw NDalicPINVOKE.SWIGPendingException.Retrieve();
688         }
689
690         internal void SetX(float x)
691         {
692             Interop.ActorInternal.SetX(SwigCPtr, x);
693             if (NDalicPINVOKE.SWIGPendingException.Pending)
694                 throw NDalicPINVOKE.SWIGPendingException.Retrieve();
695         }
696
697         internal void SetY(float y)
698         {
699             Interop.ActorInternal.SetY(SwigCPtr, y);
700             if (NDalicPINVOKE.SWIGPendingException.Pending)
701                 throw NDalicPINVOKE.SWIGPendingException.Retrieve();
702         }
703
704         internal void SetZ(float z)
705         {
706             Interop.ActorInternal.SetZ(SwigCPtr, z);
707             if (NDalicPINVOKE.SWIGPendingException.Pending)
708                 throw NDalicPINVOKE.SWIGPendingException.Retrieve();
709         }
710
711         internal void TranslateBy(Vector3 distance)
712         {
713             Interop.ActorInternal.TranslateBy(SwigCPtr, Vector3.getCPtr(distance));
714             if (NDalicPINVOKE.SWIGPendingException.Pending)
715                 throw NDalicPINVOKE.SWIGPendingException.Retrieve();
716         }
717
718         internal Position GetCurrentPosition()
719         {
720             Position ret = new Position(Interop.Actor.GetCurrentPosition(SwigCPtr), true);
721             if (NDalicPINVOKE.SWIGPendingException.Pending)
722                 throw NDalicPINVOKE.SWIGPendingException.Retrieve();
723             return ret;
724         }
725
726         internal Vector3 GetCurrentWorldPosition()
727         {
728             Vector3 ret = new Vector3(Interop.ActorInternal.GetCurrentWorldPosition(SwigCPtr), true);
729             if (NDalicPINVOKE.SWIGPendingException.Pending)
730                 throw NDalicPINVOKE.SWIGPendingException.Retrieve();
731             return ret;
732         }
733
734         internal void SetInheritPosition(bool inherit)
735         {
736             Interop.ActorInternal.SetInheritPosition(SwigCPtr, inherit);
737             if (NDalicPINVOKE.SWIGPendingException.Pending)
738                 throw NDalicPINVOKE.SWIGPendingException.Retrieve();
739         }
740
741         internal bool IsPositionInherited()
742         {
743             bool ret = Interop.ActorInternal.IsPositionInherited(SwigCPtr);
744             if (NDalicPINVOKE.SWIGPendingException.Pending)
745                 throw NDalicPINVOKE.SWIGPendingException.Retrieve();
746             return ret;
747         }
748
749         internal void SetOrientation(Degree angle, Vector3 axis)
750         {
751             Interop.ActorInternal.SetOrientationDegree(SwigCPtr, Degree.getCPtr(angle), Vector3.getCPtr(axis));
752             if (NDalicPINVOKE.SWIGPendingException.Pending)
753                 throw NDalicPINVOKE.SWIGPendingException.Retrieve();
754         }
755
756         internal void SetOrientation(Radian angle, Vector3 axis)
757         {
758             Interop.ActorInternal.SetOrientationRadian(SwigCPtr, Radian.getCPtr(angle), Vector3.getCPtr(axis));
759             if (NDalicPINVOKE.SWIGPendingException.Pending)
760                 throw NDalicPINVOKE.SWIGPendingException.Retrieve();
761         }
762
763         internal void SetOrientation(Rotation orientation)
764         {
765             Interop.ActorInternal.SetOrientationQuaternion(SwigCPtr, Rotation.getCPtr(orientation));
766             if (NDalicPINVOKE.SWIGPendingException.Pending)
767                 throw NDalicPINVOKE.SWIGPendingException.Retrieve();
768         }
769
770         internal Rotation GetCurrentOrientation()
771         {
772             Rotation ret = new Rotation(Interop.ActorInternal.GetCurrentOrientation(SwigCPtr), true);
773             if (NDalicPINVOKE.SWIGPendingException.Pending)
774                 throw NDalicPINVOKE.SWIGPendingException.Retrieve();
775             return ret;
776         }
777
778         internal void SetInheritOrientation(bool inherit)
779         {
780             Interop.ActorInternal.SetInheritOrientation(SwigCPtr, inherit);
781             if (NDalicPINVOKE.SWIGPendingException.Pending)
782                 throw NDalicPINVOKE.SWIGPendingException.Retrieve();
783         }
784
785         internal bool IsOrientationInherited()
786         {
787             bool ret = Interop.ActorInternal.IsOrientationInherited(SwigCPtr);
788             if (NDalicPINVOKE.SWIGPendingException.Pending)
789                 throw NDalicPINVOKE.SWIGPendingException.Retrieve();
790             return ret;
791         }
792
793         internal Rotation GetCurrentWorldOrientation()
794         {
795             Rotation ret = new Rotation(Interop.ActorInternal.GetCurrentWorldOrientation(SwigCPtr), true);
796             if (NDalicPINVOKE.SWIGPendingException.Pending)
797                 throw NDalicPINVOKE.SWIGPendingException.Retrieve();
798             return ret;
799         }
800
801         internal void SetScale(float scale)
802         {
803             Interop.ActorInternal.SetScale(SwigCPtr, scale);
804             if (NDalicPINVOKE.SWIGPendingException.Pending)
805                 throw NDalicPINVOKE.SWIGPendingException.Retrieve();
806         }
807
808         internal void SetScale(float scaleX, float scaleY, float scaleZ)
809         {
810             Interop.ActorInternal.SetScale(SwigCPtr, scaleX, scaleY, scaleZ);
811             if (NDalicPINVOKE.SWIGPendingException.Pending)
812                 throw NDalicPINVOKE.SWIGPendingException.Retrieve();
813         }
814
815         internal void SetScale(Vector3 scale)
816         {
817             Interop.ActorInternal.SetScale(SwigCPtr, Vector3.getCPtr(scale));
818             if (NDalicPINVOKE.SWIGPendingException.Pending)
819                 throw NDalicPINVOKE.SWIGPendingException.Retrieve();
820         }
821
822         internal Vector3 GetCurrentScale()
823         {
824             Vector3 ret = new Vector3(Interop.ActorInternal.GetCurrentScale(SwigCPtr), true);
825             if (NDalicPINVOKE.SWIGPendingException.Pending)
826                 throw NDalicPINVOKE.SWIGPendingException.Retrieve();
827             return ret;
828         }
829
830         internal Vector3 GetCurrentWorldScale()
831         {
832             Vector3 ret = new Vector3(Interop.ActorInternal.GetCurrentWorldScale(SwigCPtr), true);
833             if (NDalicPINVOKE.SWIGPendingException.Pending)
834                 throw NDalicPINVOKE.SWIGPendingException.Retrieve();
835             return ret;
836         }
837
838         internal void SetInheritScale(bool inherit)
839         {
840             Interop.ActorInternal.SetInheritScale(SwigCPtr, inherit);
841             if (NDalicPINVOKE.SWIGPendingException.Pending)
842                 throw NDalicPINVOKE.SWIGPendingException.Retrieve();
843         }
844
845         internal bool IsScaleInherited()
846         {
847             bool ret = Interop.ActorInternal.IsScaleInherited(SwigCPtr);
848             if (NDalicPINVOKE.SWIGPendingException.Pending)
849                 throw NDalicPINVOKE.SWIGPendingException.Retrieve();
850             return ret;
851         }
852
853         internal Matrix GetCurrentWorldMatrix()
854         {
855             Matrix ret = new Matrix(Interop.ActorInternal.GetCurrentWorldMatrix(SwigCPtr), true);
856             if (NDalicPINVOKE.SWIGPendingException.Pending)
857                 throw NDalicPINVOKE.SWIGPendingException.Retrieve();
858             return ret;
859         }
860
861         internal void SetVisible(bool visible)
862         {
863             Interop.Actor.SetVisible(SwigCPtr, visible);
864             if (NDalicPINVOKE.SWIGPendingException.Pending)
865                 throw NDalicPINVOKE.SWIGPendingException.Retrieve();
866         }
867
868         internal bool IsVisible()
869         {
870             bool ret = Interop.ActorInternal.IsVisible(SwigCPtr);
871             if (NDalicPINVOKE.SWIGPendingException.Pending)
872                 throw NDalicPINVOKE.SWIGPendingException.Retrieve();
873             return ret;
874         }
875
876         internal void SetOpacity(float opacity)
877         {
878             Interop.ActorInternal.SetOpacity(SwigCPtr, opacity);
879             if (NDalicPINVOKE.SWIGPendingException.Pending)
880                 throw NDalicPINVOKE.SWIGPendingException.Retrieve();
881         }
882
883         internal float GetCurrentOpacity()
884         {
885             float ret = Interop.ActorInternal.GetCurrentOpacity(SwigCPtr);
886             if (NDalicPINVOKE.SWIGPendingException.Pending)
887                 throw NDalicPINVOKE.SWIGPendingException.Retrieve();
888             return ret;
889         }
890
891         internal Vector4 GetCurrentColor()
892         {
893             Vector4 ret = new Vector4(Interop.ActorInternal.GetCurrentColor(SwigCPtr), true);
894             if (NDalicPINVOKE.SWIGPendingException.Pending)
895                 throw NDalicPINVOKE.SWIGPendingException.Retrieve();
896             return ret;
897         }
898         internal ColorMode GetColorMode()
899         {
900             ColorMode ret = (ColorMode)Interop.ActorInternal.GetColorMode(SwigCPtr);
901             if (NDalicPINVOKE.SWIGPendingException.Pending)
902                 throw NDalicPINVOKE.SWIGPendingException.Retrieve();
903             return ret;
904         }
905
906         internal Vector4 GetCurrentWorldColor()
907         {
908             Vector4 ret = new Vector4(Interop.ActorInternal.GetCurrentWorldColor(SwigCPtr), true);
909             if (NDalicPINVOKE.SWIGPendingException.Pending)
910                 throw NDalicPINVOKE.SWIGPendingException.Retrieve();
911             return ret;
912         }
913
914         internal void SetDrawMode(DrawModeType drawMode)
915         {
916             Interop.ActorInternal.SetDrawMode(SwigCPtr, (int)drawMode);
917             if (NDalicPINVOKE.SWIGPendingException.Pending)
918                 throw NDalicPINVOKE.SWIGPendingException.Retrieve();
919         }
920
921         internal DrawModeType GetDrawMode()
922         {
923             DrawModeType ret = (DrawModeType)Interop.ActorInternal.GetDrawMode(SwigCPtr);
924             if (NDalicPINVOKE.SWIGPendingException.Pending)
925                 throw NDalicPINVOKE.SWIGPendingException.Retrieve();
926             return ret;
927         }
928
929         internal void SetKeyboardFocusable(bool focusable)
930         {
931             Interop.ActorInternal.SetKeyboardFocusable(SwigCPtr, focusable);
932             if (NDalicPINVOKE.SWIGPendingException.Pending)
933                 throw NDalicPINVOKE.SWIGPendingException.Retrieve();
934         }
935
936         internal bool IsKeyboardFocusable()
937         {
938             bool ret = Interop.ActorInternal.IsKeyboardFocusable(SwigCPtr);
939             if (NDalicPINVOKE.SWIGPendingException.Pending)
940                 throw NDalicPINVOKE.SWIGPendingException.Retrieve();
941             return ret;
942         }
943
944         internal void SetKeyboardFocusableChildren(bool focusable)
945         {
946             Interop.ActorInternal.SetKeyboardFocusableChildren(SwigCPtr, focusable);
947             if (NDalicPINVOKE.SWIGPendingException.Pending)
948                 throw NDalicPINVOKE.SWIGPendingException.Retrieve();
949         }
950
951         internal bool AreChildrenKeyBoardFocusable()
952         {
953             bool ret = Interop.ActorInternal.AreChildrenKeyBoardFocusable(SwigCPtr);
954             if (NDalicPINVOKE.SWIGPendingException.Pending)
955                 throw NDalicPINVOKE.SWIGPendingException.Retrieve();
956             return ret;
957         }
958
959         internal void SetFocusableInTouch(bool enabled)
960         {
961             Interop.ActorInternal.SetFocusableInTouch(SwigCPtr, enabled);
962             if (NDalicPINVOKE.SWIGPendingException.Pending)
963                 throw NDalicPINVOKE.SWIGPendingException.Retrieve();
964         }
965
966         internal bool IsFocusableInTouch()
967         {
968             bool ret = Interop.ActorInternal.IsFocusableInTouch(SwigCPtr);
969             if (NDalicPINVOKE.SWIGPendingException.Pending)
970                 throw NDalicPINVOKE.SWIGPendingException.Retrieve();
971             return ret;
972         }
973
974         internal void SetResizePolicy(ResizePolicyType policy, DimensionType dimension)
975         {
976             Interop.Actor.SetResizePolicy(SwigCPtr, (int)policy, (int)dimension);
977             if (NDalicPINVOKE.SWIGPendingException.Pending)
978                 throw NDalicPINVOKE.SWIGPendingException.Retrieve();
979         }
980
981         internal ResizePolicyType GetResizePolicy(DimensionType dimension)
982         {
983             ResizePolicyType ret = (ResizePolicyType)Interop.Actor.GetResizePolicy(SwigCPtr, (int)dimension);
984             if (NDalicPINVOKE.SWIGPendingException.Pending)
985                 throw NDalicPINVOKE.SWIGPendingException.Retrieve();
986             return ret;
987         }
988
989         internal Vector3 GetSizeModeFactor()
990         {
991             Vector3 ret = new Vector3(Interop.Actor.GetSizeModeFactor(SwigCPtr), true);
992             if (NDalicPINVOKE.SWIGPendingException.Pending)
993                 throw NDalicPINVOKE.SWIGPendingException.Retrieve();
994             return ret;
995         }
996
997         internal void SetMinimumSize(Vector2 size)
998         {
999             Interop.ActorInternal.SetMinimumSize(SwigCPtr, Vector2.getCPtr(size));
1000             if (NDalicPINVOKE.SWIGPendingException.Pending)
1001                 throw NDalicPINVOKE.SWIGPendingException.Retrieve();
1002         }
1003
1004         internal Vector2 GetMinimumSize()
1005         {
1006             Vector2 ret = new Vector2(Interop.ActorInternal.GetMinimumSize(SwigCPtr), true);
1007             if (NDalicPINVOKE.SWIGPendingException.Pending)
1008                 throw NDalicPINVOKE.SWIGPendingException.Retrieve();
1009             return ret;
1010         }
1011
1012         internal void SetMaximumSize(Vector2 size)
1013         {
1014             Interop.ActorInternal.SetMaximumSize(SwigCPtr, Vector2.getCPtr(size));
1015             if (NDalicPINVOKE.SWIGPendingException.Pending)
1016                 throw NDalicPINVOKE.SWIGPendingException.Retrieve();
1017         }
1018
1019         internal Vector2 GetMaximumSize()
1020         {
1021             Vector2 ret = new Vector2(Interop.ActorInternal.GetMaximumSize(SwigCPtr), true);
1022             if (NDalicPINVOKE.SWIGPendingException.Pending)
1023                 throw NDalicPINVOKE.SWIGPendingException.Retrieve();
1024             return ret;
1025         }
1026
1027         internal int GetHierarchyDepth()
1028         {
1029             int ret = Interop.Actor.GetHierarchyDepth(SwigCPtr);
1030             if (NDalicPINVOKE.SWIGPendingException.Pending)
1031                 throw NDalicPINVOKE.SWIGPendingException.Retrieve();
1032             return ret;
1033         }
1034
1035         internal uint GetRendererCount()
1036         {
1037             uint ret = Interop.Actor.GetRendererCount(SwigCPtr);
1038             if (NDalicPINVOKE.SWIGPendingException.Pending)
1039                 throw NDalicPINVOKE.SWIGPendingException.Retrieve();
1040             return ret;
1041         }
1042
1043         internal static global::System.Runtime.InteropServices.HandleRef getCPtr(View obj)
1044         {
1045             return (obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.SwigCPtr;
1046         }
1047
1048         internal bool IsTopLevelView()
1049         {
1050             if (GetParent() is Layer)
1051             {
1052                 return true;
1053             }
1054             return false;
1055         }
1056
1057         internal void SetKeyInputFocus()
1058         {
1059             Interop.ViewInternal.SetKeyInputFocus(SwigCPtr);
1060             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
1061         }
1062
1063         internal void ClearKeyInputFocus()
1064         {
1065             Interop.ViewInternal.ClearKeyInputFocus(SwigCPtr);
1066             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
1067         }
1068
1069         internal PinchGestureDetector GetPinchGestureDetector()
1070         {
1071             PinchGestureDetector ret = new PinchGestureDetector(Interop.ViewInternal.GetPinchGestureDetector(SwigCPtr), true);
1072             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
1073             return ret;
1074         }
1075
1076         internal PanGestureDetector GetPanGestureDetector()
1077         {
1078             PanGestureDetector ret = new PanGestureDetector(Interop.ViewInternal.GetPanGestureDetector(SwigCPtr), true);
1079             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
1080             return ret;
1081         }
1082
1083         internal TapGestureDetector GetTapGestureDetector()
1084         {
1085             TapGestureDetector ret = new TapGestureDetector(Interop.ViewInternal.GetTapGestureDetector(SwigCPtr), true);
1086             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
1087             return ret;
1088         }
1089
1090         internal LongPressGestureDetector GetLongPressGestureDetector()
1091         {
1092             LongPressGestureDetector ret = new LongPressGestureDetector(Interop.ViewInternal.GetLongPressGestureDetector(SwigCPtr), true);
1093             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
1094             return ret;
1095         }
1096
1097         internal IntPtr GetPtrfromView()
1098         {
1099             return (IntPtr)SwigCPtr;
1100         }
1101
1102         internal void RemoveChild(View child)
1103         {
1104             // Do actual child removal
1105             Interop.Actor.Remove(SwigCPtr, View.getCPtr(child));
1106             if (NDalicPINVOKE.SWIGPendingException.Pending)
1107                 throw NDalicPINVOKE.SWIGPendingException.Retrieve();
1108
1109             Children.Remove(child);
1110             child.InternalParent = null;
1111
1112             RemoveChildBindableObject(child);
1113
1114             if (ChildRemoved != null)
1115             {
1116                 ChildRemovedEventArgs e = new ChildRemovedEventArgs
1117                 {
1118                     Removed = child
1119                 };
1120                 ChildRemoved(this, e);
1121             }
1122         }
1123
1124         /// <summary>
1125         /// Removes the layout from this View.
1126         /// </summary>
1127         internal void ResetLayout()
1128         {
1129             layout = null;
1130         }
1131
1132         internal ResourceLoadingStatusType GetBackgroundResourceStatus()
1133         {
1134             return (ResourceLoadingStatusType)Interop.View.GetVisualResourceStatus(this.SwigCPtr, Property.BACKGROUND);
1135         }
1136
1137         /// TODO open as a protected level
1138         internal virtual void ApplyCornerRadius()
1139         {
1140             if (backgroundExtraData == null) return;
1141
1142             var cornerRadius = backgroundExtraData.CornerRadius == null ? new PropertyValue() : new PropertyValue(backgroundExtraData.CornerRadius);
1143
1144             // Apply to the background visual
1145             PropertyMap backgroundMap = new PropertyMap();
1146             PropertyValue background = Tizen.NUI.Object.GetProperty(SwigCPtr, View.Property.BACKGROUND);
1147
1148             if (background.Get(backgroundMap) && !backgroundMap.Empty())
1149             {
1150                 backgroundMap[Visual.Property.CornerRadius] = cornerRadius;
1151                 backgroundMap[Visual.Property.CornerRadiusPolicy] = new PropertyValue((int)backgroundExtraData.CornerRadiusPolicy);
1152                 var temp = new PropertyValue(backgroundMap);
1153                 Tizen.NUI.Object.SetProperty(SwigCPtr, View.Property.BACKGROUND, temp);
1154                 temp.Dispose();
1155             }
1156             backgroundMap.Dispose();
1157             background.Dispose();
1158
1159             // Apply to the shadow visual
1160             PropertyMap shadowMap = new PropertyMap();
1161             PropertyValue shadow = Tizen.NUI.Object.GetProperty(SwigCPtr, View.Property.SHADOW);
1162             if (shadow.Get(shadowMap) && !shadowMap.Empty())
1163             {
1164                 shadowMap[Visual.Property.CornerRadius] = cornerRadius;
1165                 shadowMap[Visual.Property.CornerRadiusPolicy] = new PropertyValue((int)backgroundExtraData.CornerRadiusPolicy);
1166                 var temp = new PropertyValue(shadowMap);
1167                 Tizen.NUI.Object.SetProperty(SwigCPtr, View.Property.SHADOW, temp);
1168                 temp.Dispose();
1169             }
1170             shadowMap.Dispose();
1171             shadow.Dispose();
1172             cornerRadius.Dispose();
1173         }
1174
1175         /// TODO open as a protected level
1176         internal virtual void ApplyBorderline()
1177         {
1178             if (backgroundExtraData == null) return;
1179
1180             var borderlineColor = backgroundExtraData.BorderlineColor == null ? new PropertyValue(Color.Black) : new PropertyValue(backgroundExtraData.BorderlineColor);
1181
1182             // Apply to the background visual
1183             PropertyMap backgroundMap = new PropertyMap();
1184             PropertyValue background = Tizen.NUI.Object.GetProperty(SwigCPtr, View.Property.BACKGROUND);
1185             if (background.Get(backgroundMap) && !backgroundMap.Empty())
1186             {
1187                 backgroundMap[Visual.Property.BorderlineWidth] = new PropertyValue(backgroundExtraData.BorderlineWidth);
1188                 backgroundMap[Visual.Property.BorderlineColor] = borderlineColor;
1189                 backgroundMap[Visual.Property.BorderlineOffset] = new PropertyValue(backgroundExtraData.BorderlineOffset);
1190                 var temp = new PropertyValue(backgroundMap);
1191                 Tizen.NUI.Object.SetProperty(SwigCPtr, View.Property.BACKGROUND, temp);
1192                 temp.Dispose();
1193             }
1194             backgroundMap.Dispose();
1195             background.Dispose();
1196             borderlineColor.Dispose();
1197         }
1198
1199         /// <summary>
1200         /// Get selector value from the triggerable selector or related property.
1201         /// </summary>
1202         internal Selector<T> GetSelector<T>(TriggerableSelector<T> triggerableSelector, NUI.Binding.BindableProperty relatedProperty)
1203         {
1204             var selector = triggerableSelector?.Get();
1205             if (selector != null)
1206             {
1207                 return selector;
1208             }
1209
1210             var value = (T)GetValue(relatedProperty);
1211             return value == null ? null : new Selector<T>(value);
1212         }
1213
1214         internal void SetThemeApplied()
1215         {
1216             if (themeData == null) themeData = new ThemeData();
1217             themeData.ThemeApplied = true;
1218
1219             if (ThemeChangeSensitive && !themeData.ListeningThemeChangeEvent)
1220             {
1221                 themeData.ListeningThemeChangeEvent = true;
1222                 ThemeManager.ThemeChangedInternal.Add(OnThemeChanged);
1223             }
1224         }
1225
1226         /// <summary>
1227         /// you can override it to clean-up your own resources.
1228         /// </summary>
1229         /// <param name="type">DisposeTypes</param>
1230         /// <since_tizen> 3 </since_tizen>
1231         protected override void Dispose(DisposeTypes type)
1232         {
1233             if (disposed)
1234             {
1235                 return;
1236             }
1237
1238             //_mergedStyle = null;
1239
1240             if (type == DisposeTypes.Explicit)
1241             {
1242                 //Called by User
1243                 //Release your own managed resources here.
1244                 //You should release all of your own disposable objects here.
1245                 if (themeData != null)
1246                 {
1247                     themeData.selectorData?.Reset(this);
1248                     if (themeData.ListeningThemeChangeEvent)
1249                     {
1250                         ThemeManager.ThemeChangedInternal.Remove(OnThemeChanged);
1251                     }
1252                 }
1253                 if(widthConstraint != null)
1254                 {
1255                     widthConstraint.Remove();
1256                     widthConstraint.Dispose();
1257                 }
1258                 if(heightConstraint != null)
1259                 {
1260                     heightConstraint.Remove();
1261                     heightConstraint.Dispose();
1262                 }
1263             }
1264
1265             //Release your own unmanaged resources here.
1266             //You should not access any managed member here except static instance.
1267             //because the execution order of Finalizes is non-deterministic.
1268
1269             // equivalent to "if (this != null)". more clear to understand.
1270             if (this.HasBody())
1271             {
1272                 DisConnectFromSignals();
1273
1274                 foreach (View view in Children)
1275                 {
1276                     view.InternalParent = null;
1277                 }
1278
1279             }
1280
1281             base.Dispose(type);
1282         }
1283
1284         /// This will not be public opened.
1285         [EditorBrowsable(EditorBrowsableState.Never)]
1286         protected override void ReleaseSwigCPtr(System.Runtime.InteropServices.HandleRef swigCPtr)
1287         {
1288             Interop.View.DeleteView(swigCPtr);
1289         }
1290
1291         /// <summary>
1292         /// The touch event handler for ControlState.
1293         /// Please change ControlState value by touch state if needed.
1294         /// </summary>
1295         /// <exception cref="ArgumentNullException"> Thrown when touch is null. </exception>
1296         [EditorBrowsable(EditorBrowsableState.Never)]
1297         protected virtual bool HandleControlStateOnTouch(Touch touch)
1298         {
1299             if (touch == null)
1300             {
1301                 throw new global::System.ArgumentNullException(nameof(touch));
1302             }
1303
1304             switch (touch.GetState(0))
1305             {
1306                 case PointStateType.Down:
1307                     ControlState += ControlState.Pressed;
1308                     break;
1309                 case PointStateType.Interrupted:
1310                 case PointStateType.Up:
1311                     if (ControlState.Contains(ControlState.Pressed))
1312                     {
1313                         ControlState -= ControlState.Pressed;
1314                     }
1315                     break;
1316                 default:
1317                     break;
1318             }
1319             return false;
1320         }
1321
1322         private void DisConnectFromSignals()
1323         {
1324             // Save current CPtr.
1325             global::System.Runtime.InteropServices.HandleRef currentCPtr = SwigCPtr;
1326
1327             // Use BaseHandle CPtr as current might have been deleted already in derived classes.
1328             SwigCPtr = GetBaseHandleCPtrHandleRef;
1329
1330             if (onRelayoutEventCallback != null)
1331             {
1332                 ViewSignal signal = this.OnRelayoutSignal();
1333                 signal?.Disconnect(onRelayoutEventCallback);
1334                 signal?.Dispose();
1335                 onRelayoutEventCallback = null;
1336             }
1337
1338             if (offWindowEventCallback != null)
1339             {
1340                 ViewSignal signal = this.OffWindowSignal();
1341                 signal?.Disconnect(offWindowEventCallback);
1342                 signal?.Dispose();
1343                 offWindowEventCallback = null;
1344             }
1345
1346             if (onWindowEventCallback != null)
1347             {
1348                 ViewSignal signal = this.OnWindowSignal();
1349                 signal?.Disconnect(onWindowEventCallback);
1350                 signal?.Dispose();
1351                 onWindowEventCallback = null;
1352             }
1353
1354             if (wheelEventCallback != null)
1355             {
1356                 WheelSignal signal = this.WheelEventSignal();
1357                 signal?.Disconnect(wheelEventCallback);
1358                 signal?.Dispose();
1359             }
1360
1361             if (WindowWheelEventHandler != null)
1362             {
1363                 NUIApplication.GetDefaultWindow().WheelEvent -= OnWindowWheelEvent;
1364             }
1365
1366             if (hoverEventCallback != null)
1367             {
1368                 HoverSignal signal = this.HoveredSignal();
1369                 signal?.Disconnect(hoverEventCallback);
1370                 signal?.Dispose();
1371             }
1372
1373             if (interceptTouchDataCallback != null)
1374             {
1375                 TouchDataSignal signal = this.InterceptTouchSignal();
1376                 signal?.Disconnect(interceptTouchDataCallback);
1377                 signal?.Dispose();
1378             }
1379
1380             if (touchDataCallback != null)
1381             {
1382                 TouchDataSignal signal = this.TouchSignal();
1383                 signal?.Disconnect(touchDataCallback);
1384                 signal?.Dispose();
1385             }
1386
1387             if (ResourcesLoadedCallback != null)
1388             {
1389                 ViewSignal signal = this.ResourcesLoadedSignal();
1390                 signal?.Disconnect(ResourcesLoadedCallback);
1391                 signal?.Dispose();
1392                 ResourcesLoadedCallback = null;
1393             }
1394
1395             if (keyCallback != null)
1396             {
1397                 ControlKeySignal signal = this.KeyEventSignal();
1398                 signal?.Disconnect(keyCallback);
1399                 signal?.Dispose();
1400             }
1401
1402             if (keyInputFocusLostCallback != null)
1403             {
1404                 KeyInputFocusSignal signal = this.KeyInputFocusLostSignal();
1405                 signal?.Disconnect(keyInputFocusLostCallback);
1406                 signal?.Dispose();
1407             }
1408
1409             if (keyInputFocusGainedCallback != null)
1410             {
1411                 KeyInputFocusSignal signal = this.KeyInputFocusGainedSignal();
1412                 signal?.Disconnect(keyInputFocusGainedCallback);
1413                 signal?.Dispose();
1414             }
1415
1416             if (backgroundResourceLoadedCallback != null)
1417             {
1418                 ViewSignal signal = this.ResourcesLoadedSignal();
1419                 signal?.Disconnect(backgroundResourceLoadedCallback);
1420                 signal?.Dispose();
1421                 backgroundResourceLoadedCallback = null;
1422             }
1423
1424             if (onWindowSendEventCallback != null)
1425             {
1426                 ViewSignal signal = this.OnWindowSignal();
1427                 signal?.Disconnect(onWindowSendEventCallback);
1428                 signal?.Dispose();
1429                 onWindowSendEventCallback = null;
1430             }
1431
1432             // BaseHandle CPtr is used in Registry and there is danger of deletion if we keep using it here.
1433             // Restore current CPtr.
1434             SwigCPtr = currentCPtr;
1435         }
1436
1437         /// <summary>
1438         /// Apply initial style to the view.
1439         /// </summary>
1440         [EditorBrowsable(EditorBrowsableState.Never)]
1441         protected virtual void InitializeStyle(ViewStyle style = null)
1442         {
1443             var initialStyle = ThemeManager.GetInitialStyleWithoutClone(GetType());
1444             if (style == null)
1445             {
1446                 ApplyStyle(initialStyle);
1447             }
1448             else
1449             {
1450                 var refinedStyle = style;
1451                 if (style.IncludeDefaultStyle)
1452                 {
1453                     refinedStyle = initialStyle?.Merge(style);
1454                 }
1455                 ApplyStyle(refinedStyle);
1456             }
1457
1458             // Listen theme change event if needs.
1459             if (ThemeManager.PlatformThemeEnabled && initialStyle != null)
1460             {
1461                 SetThemeApplied();
1462             }
1463         }
1464
1465         private View ConvertIdToView(uint id)
1466         {
1467             View view = GetParent()?.FindCurrentChildById(id);
1468
1469             //If we can't find the parent's children, find in the top layer.
1470             if (!view)
1471             {
1472                 Container parent = GetParent();
1473                 while ((parent is View) && (parent != null))
1474                 {
1475                     parent = parent.GetParent();
1476                     if (parent is Layer)
1477                     {
1478                         view = parent.FindCurrentChildById(id);
1479                         break;
1480                     }
1481                 }
1482             }
1483
1484             return view;
1485         }
1486
1487         private void OnScaleChanged(float x, float y, float z)
1488         {
1489             Scale = new Vector3(x, y, z);
1490         }
1491
1492         private void OnBackgroundColorChanged(float r, float g, float b, float a)
1493         {
1494             BackgroundColor = new Color(r, g, b, a);
1495         }
1496
1497         private void OnPaddingChanged(ushort start, ushort end, ushort top, ushort bottom)
1498         {
1499             Padding = new Extents(start, end, top, bottom);
1500         }
1501
1502         private void OnMarginChanged(ushort start, ushort end, ushort top, ushort bottom)
1503         {
1504             Margin = new Extents(start, end, top, bottom);
1505         }
1506
1507         private void OnColorChanged(float r, float g, float b, float a)
1508         {
1509             Color = new Color(r, g, b, a);
1510         }
1511
1512         private void OnAnchorPointChanged(float x, float y, float z)
1513         {
1514             AnchorPoint = new Position(x, y, z);
1515         }
1516
1517         private void OnCellIndexChanged(float x, float y)
1518         {
1519             CellIndex = new Vector2(x, y);
1520         }
1521
1522         private void OnFlexMarginChanged(float x, float y, float z, float w)
1523         {
1524             FlexMargin = new Vector4(x, y, z, w);
1525         }
1526
1527         private void OnPaddingEXChanged(ushort start, ushort end, ushort top, ushort bottom)
1528         {
1529             PaddingEX = new Extents(start, end, top, bottom);
1530         }
1531
1532         private void OnSizeModeFactorChanged(float x, float y, float z)
1533         {
1534             SizeModeFactor = new Vector3(x, y, z);
1535         }
1536
1537         private bool EmptyOnTouch(object target, TouchEventArgs args)
1538         {
1539             return false;
1540         }
1541
1542         private ViewSelectorData EnsureSelectorData()
1543         {
1544             if (themeData == null) themeData = new ThemeData();
1545
1546             return themeData.selectorData ?? (themeData.selectorData = new ViewSelectorData());
1547         }
1548     }
1549 }