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