[NUI] Add CursorPositionChanged Event (#3400)
[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 SetFocusableInTouch(bool enabled)
930         {
931             Interop.ActorInternal.SetFocusableInTouch(SwigCPtr, enabled);
932             if (NDalicPINVOKE.SWIGPendingException.Pending)
933                 throw NDalicPINVOKE.SWIGPendingException.Retrieve();
934         }
935
936         internal bool IsFocusableInTouch()
937         {
938             bool ret = Interop.ActorInternal.IsFocusableInTouch(SwigCPtr);
939             if (NDalicPINVOKE.SWIGPendingException.Pending)
940                 throw NDalicPINVOKE.SWIGPendingException.Retrieve();
941             return ret;
942         }
943
944         internal void SetResizePolicy(ResizePolicyType policy, DimensionType dimension)
945         {
946             Interop.Actor.SetResizePolicy(SwigCPtr, (int)policy, (int)dimension);
947             if (NDalicPINVOKE.SWIGPendingException.Pending)
948                 throw NDalicPINVOKE.SWIGPendingException.Retrieve();
949         }
950
951         internal ResizePolicyType GetResizePolicy(DimensionType dimension)
952         {
953             ResizePolicyType ret = (ResizePolicyType)Interop.Actor.GetResizePolicy(SwigCPtr, (int)dimension);
954             if (NDalicPINVOKE.SWIGPendingException.Pending)
955                 throw NDalicPINVOKE.SWIGPendingException.Retrieve();
956             return ret;
957         }
958
959         internal Vector3 GetSizeModeFactor()
960         {
961             Vector3 ret = new Vector3(Interop.Actor.GetSizeModeFactor(SwigCPtr), true);
962             if (NDalicPINVOKE.SWIGPendingException.Pending)
963                 throw NDalicPINVOKE.SWIGPendingException.Retrieve();
964             return ret;
965         }
966
967         internal void SetMinimumSize(Vector2 size)
968         {
969             Interop.ActorInternal.SetMinimumSize(SwigCPtr, Vector2.getCPtr(size));
970             if (NDalicPINVOKE.SWIGPendingException.Pending)
971                 throw NDalicPINVOKE.SWIGPendingException.Retrieve();
972         }
973
974         internal Vector2 GetMinimumSize()
975         {
976             Vector2 ret = new Vector2(Interop.ActorInternal.GetMinimumSize(SwigCPtr), true);
977             if (NDalicPINVOKE.SWIGPendingException.Pending)
978                 throw NDalicPINVOKE.SWIGPendingException.Retrieve();
979             return ret;
980         }
981
982         internal void SetMaximumSize(Vector2 size)
983         {
984             Interop.ActorInternal.SetMaximumSize(SwigCPtr, Vector2.getCPtr(size));
985             if (NDalicPINVOKE.SWIGPendingException.Pending)
986                 throw NDalicPINVOKE.SWIGPendingException.Retrieve();
987         }
988
989         internal Vector2 GetMaximumSize()
990         {
991             Vector2 ret = new Vector2(Interop.ActorInternal.GetMaximumSize(SwigCPtr), true);
992             if (NDalicPINVOKE.SWIGPendingException.Pending)
993                 throw NDalicPINVOKE.SWIGPendingException.Retrieve();
994             return ret;
995         }
996
997         internal int GetHierarchyDepth()
998         {
999             int ret = Interop.Actor.GetHierarchyDepth(SwigCPtr);
1000             if (NDalicPINVOKE.SWIGPendingException.Pending)
1001                 throw NDalicPINVOKE.SWIGPendingException.Retrieve();
1002             return ret;
1003         }
1004
1005         internal uint GetRendererCount()
1006         {
1007             uint ret = Interop.Actor.GetRendererCount(SwigCPtr);
1008             if (NDalicPINVOKE.SWIGPendingException.Pending)
1009                 throw NDalicPINVOKE.SWIGPendingException.Retrieve();
1010             return ret;
1011         }
1012
1013         internal static global::System.Runtime.InteropServices.HandleRef getCPtr(View obj)
1014         {
1015             return (obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.SwigCPtr;
1016         }
1017
1018         internal bool IsTopLevelView()
1019         {
1020             if (GetParent() is Layer)
1021             {
1022                 return true;
1023             }
1024             return false;
1025         }
1026
1027         internal void SetKeyInputFocus()
1028         {
1029             Interop.ViewInternal.SetKeyInputFocus(SwigCPtr);
1030             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
1031         }
1032
1033         internal void ClearKeyInputFocus()
1034         {
1035             Interop.ViewInternal.ClearKeyInputFocus(SwigCPtr);
1036             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
1037         }
1038
1039         internal PinchGestureDetector GetPinchGestureDetector()
1040         {
1041             PinchGestureDetector ret = new PinchGestureDetector(Interop.ViewInternal.GetPinchGestureDetector(SwigCPtr), true);
1042             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
1043             return ret;
1044         }
1045
1046         internal PanGestureDetector GetPanGestureDetector()
1047         {
1048             PanGestureDetector ret = new PanGestureDetector(Interop.ViewInternal.GetPanGestureDetector(SwigCPtr), true);
1049             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
1050             return ret;
1051         }
1052
1053         internal TapGestureDetector GetTapGestureDetector()
1054         {
1055             TapGestureDetector ret = new TapGestureDetector(Interop.ViewInternal.GetTapGestureDetector(SwigCPtr), true);
1056             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
1057             return ret;
1058         }
1059
1060         internal LongPressGestureDetector GetLongPressGestureDetector()
1061         {
1062             LongPressGestureDetector ret = new LongPressGestureDetector(Interop.ViewInternal.GetLongPressGestureDetector(SwigCPtr), true);
1063             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
1064             return ret;
1065         }
1066
1067         internal IntPtr GetPtrfromView()
1068         {
1069             return (IntPtr)SwigCPtr;
1070         }
1071
1072         internal void RemoveChild(View child)
1073         {
1074             // Do actual child removal
1075             Interop.Actor.Remove(SwigCPtr, View.getCPtr(child));
1076             if (NDalicPINVOKE.SWIGPendingException.Pending)
1077                 throw NDalicPINVOKE.SWIGPendingException.Retrieve();
1078
1079             Children.Remove(child);
1080             child.InternalParent = null;
1081
1082             RemoveChildBindableObject(child);
1083
1084             if (ChildRemoved != null)
1085             {
1086                 ChildRemovedEventArgs e = new ChildRemovedEventArgs
1087                 {
1088                     Removed = child
1089                 };
1090                 ChildRemoved(this, e);
1091             }
1092         }
1093
1094         /// <summary>
1095         /// Removes the layout from this View.
1096         /// </summary>
1097         internal void ResetLayout()
1098         {
1099             layout = null;
1100         }
1101
1102         internal ResourceLoadingStatusType GetBackgroundResourceStatus()
1103         {
1104             return (ResourceLoadingStatusType)Interop.View.GetVisualResourceStatus(this.SwigCPtr, Property.BACKGROUND);
1105         }
1106
1107         /// TODO open as a protected level
1108         internal virtual void ApplyCornerRadius()
1109         {
1110             if (backgroundExtraData == null) return;
1111
1112             var cornerRadius = backgroundExtraData.CornerRadius == null ? new PropertyValue() : new PropertyValue(backgroundExtraData.CornerRadius);
1113
1114             // Apply to the background visual
1115             PropertyMap backgroundMap = new PropertyMap();
1116             PropertyValue background = Tizen.NUI.Object.GetProperty(SwigCPtr, View.Property.BACKGROUND);
1117
1118             if (background.Get(backgroundMap) && !backgroundMap.Empty())
1119             {
1120                 backgroundMap[Visual.Property.CornerRadius] = cornerRadius;
1121                 backgroundMap[Visual.Property.CornerRadiusPolicy] = new PropertyValue((int)backgroundExtraData.CornerRadiusPolicy);
1122                 var temp = new PropertyValue(backgroundMap);
1123                 Tizen.NUI.Object.SetProperty(SwigCPtr, View.Property.BACKGROUND, temp);
1124                 temp.Dispose();
1125             }
1126             backgroundMap.Dispose();
1127             background.Dispose();
1128
1129             // Apply to the shadow visual
1130             PropertyMap shadowMap = new PropertyMap();
1131             PropertyValue shadow = Tizen.NUI.Object.GetProperty(SwigCPtr, View.Property.SHADOW);
1132             if (shadow.Get(shadowMap) && !shadowMap.Empty())
1133             {
1134                 shadowMap[Visual.Property.CornerRadius] = cornerRadius;
1135                 shadowMap[Visual.Property.CornerRadiusPolicy] = new PropertyValue((int)backgroundExtraData.CornerRadiusPolicy);
1136                 var temp = new PropertyValue(shadowMap);
1137                 Tizen.NUI.Object.SetProperty(SwigCPtr, View.Property.SHADOW, temp);
1138                 temp.Dispose();
1139             }
1140             shadowMap.Dispose();
1141             shadow.Dispose();
1142             cornerRadius.Dispose();
1143         }
1144
1145         /// TODO open as a protected level
1146         internal virtual void ApplyBorderline()
1147         {
1148             if (backgroundExtraData == null) return;
1149
1150             var borderlineColor = backgroundExtraData.BorderlineColor == null ? new PropertyValue(Color.Black) : new PropertyValue(backgroundExtraData.BorderlineColor);
1151
1152             // Apply to the background visual
1153             PropertyMap backgroundMap = new PropertyMap();
1154             PropertyValue background = Tizen.NUI.Object.GetProperty(SwigCPtr, View.Property.BACKGROUND);
1155             if (background.Get(backgroundMap) && !backgroundMap.Empty())
1156             {
1157                 backgroundMap[Visual.Property.BorderlineWidth] = new PropertyValue(backgroundExtraData.BorderlineWidth);
1158                 backgroundMap[Visual.Property.BorderlineColor] = borderlineColor;
1159                 backgroundMap[Visual.Property.BorderlineOffset] = new PropertyValue(backgroundExtraData.BorderlineOffset);
1160                 var temp = new PropertyValue(backgroundMap);
1161                 Tizen.NUI.Object.SetProperty(SwigCPtr, View.Property.BACKGROUND, temp);
1162                 temp.Dispose();
1163             }
1164             backgroundMap.Dispose();
1165             background.Dispose();
1166             borderlineColor.Dispose();
1167         }
1168
1169         /// <summary>
1170         /// Get selector value from the triggerable selector or related property.
1171         /// </summary>
1172         internal Selector<T> GetSelector<T>(TriggerableSelector<T> triggerableSelector, NUI.Binding.BindableProperty relatedProperty)
1173         {
1174             var selector = triggerableSelector?.Get();
1175             if (selector != null)
1176             {
1177                 return selector;
1178             }
1179
1180             var value = (T)GetValue(relatedProperty);
1181             return value == null ? null : new Selector<T>(value);
1182         }
1183
1184         internal void SetThemeApplied()
1185         {
1186             if (themeData == null) themeData = new ThemeData();
1187             themeData.ThemeApplied = true;
1188
1189             if (ThemeChangeSensitive && !themeData.ListeningThemeChangeEvent)
1190             {
1191                 themeData.ListeningThemeChangeEvent = true;
1192                 ThemeManager.ThemeChangedInternal.Add(OnThemeChanged);
1193             }
1194         }
1195
1196         /// <summary>
1197         /// you can override it to clean-up your own resources.
1198         /// </summary>
1199         /// <param name="type">DisposeTypes</param>
1200         /// <since_tizen> 3 </since_tizen>
1201         protected override void Dispose(DisposeTypes type)
1202         {
1203             if (disposed)
1204             {
1205                 return;
1206             }
1207
1208             //_mergedStyle = null;
1209
1210             if (type == DisposeTypes.Explicit)
1211             {
1212                 //Called by User
1213                 //Release your own managed resources here.
1214                 //You should release all of your own disposable objects here.
1215                 if (themeData != null)
1216                 {
1217                     themeData.selectorData?.Reset(this);
1218                     if (themeData.ListeningThemeChangeEvent)
1219                     {
1220                         ThemeManager.ThemeChangedInternal.Remove(OnThemeChanged);
1221                     }
1222                 }
1223                 if(widthConstraint != null)
1224                 {
1225                     widthConstraint.Remove();
1226                     widthConstraint.Dispose();
1227                 }
1228                 if(heightConstraint != null)
1229                 {
1230                     heightConstraint.Remove();
1231                     heightConstraint.Dispose();
1232                 }
1233
1234                 Unparent();
1235             }
1236
1237             //Release your own unmanaged resources here.
1238             //You should not access any managed member here except static instance.
1239             //because the execution order of Finalizes is non-deterministic.
1240
1241             // equivalent to "if (this != null)". more clear to understand.
1242             if (this.HasBody())
1243             {
1244                 DisConnectFromSignals();
1245
1246                 foreach (View view in Children)
1247                 {
1248                     view.InternalParent = null;
1249                 }
1250
1251             }
1252
1253             base.Dispose(type);
1254         }
1255
1256         /// This will not be public opened.
1257         [EditorBrowsable(EditorBrowsableState.Never)]
1258         protected override void ReleaseSwigCPtr(System.Runtime.InteropServices.HandleRef swigCPtr)
1259         {
1260             Interop.View.DeleteView(swigCPtr);
1261         }
1262
1263         /// <summary>
1264         /// The touch event handler for ControlState.
1265         /// Please change ControlState value by touch state if needed.
1266         /// </summary>
1267         /// <exception cref="ArgumentNullException"> Thrown when touch is null. </exception>
1268         [EditorBrowsable(EditorBrowsableState.Never)]
1269         protected virtual bool HandleControlStateOnTouch(Touch touch)
1270         {
1271             if (touch == null)
1272             {
1273                 throw new global::System.ArgumentNullException(nameof(touch));
1274             }
1275
1276             switch (touch.GetState(0))
1277             {
1278                 case PointStateType.Down:
1279                     ControlState += ControlState.Pressed;
1280                     break;
1281                 case PointStateType.Interrupted:
1282                 case PointStateType.Up:
1283                     if (ControlState.Contains(ControlState.Pressed))
1284                     {
1285                         ControlState -= ControlState.Pressed;
1286                     }
1287                     break;
1288                 default:
1289                     break;
1290             }
1291             return false;
1292         }
1293
1294         private void DisConnectFromSignals()
1295         {
1296             // Save current CPtr.
1297             global::System.Runtime.InteropServices.HandleRef currentCPtr = SwigCPtr;
1298
1299             // Use BaseHandle CPtr as current might have been deleted already in derived classes.
1300             SwigCPtr = GetBaseHandleCPtrHandleRef;
1301
1302             if (onRelayoutEventCallback != null)
1303             {
1304                 ViewSignal signal = this.OnRelayoutSignal();
1305                 signal?.Disconnect(onRelayoutEventCallback);
1306                 signal?.Dispose();
1307                 onRelayoutEventCallback = null;
1308             }
1309
1310             if (offWindowEventCallback != null)
1311             {
1312                 ViewSignal signal = this.OffWindowSignal();
1313                 signal?.Disconnect(offWindowEventCallback);
1314                 signal?.Dispose();
1315                 offWindowEventCallback = null;
1316             }
1317
1318             if (onWindowEventCallback != null)
1319             {
1320                 ViewSignal signal = this.OnWindowSignal();
1321                 signal?.Disconnect(onWindowEventCallback);
1322                 signal?.Dispose();
1323                 onWindowEventCallback = null;
1324             }
1325
1326             if (wheelEventCallback != null)
1327             {
1328                 WheelSignal signal = this.WheelEventSignal();
1329                 signal?.Disconnect(wheelEventCallback);
1330                 signal?.Dispose();
1331             }
1332
1333             if (WindowWheelEventHandler != null)
1334             {
1335                 NUIApplication.GetDefaultWindow().WheelEvent -= OnWindowWheelEvent;
1336             }
1337
1338             if (hoverEventCallback != null)
1339             {
1340                 HoverSignal signal = this.HoveredSignal();
1341                 signal?.Disconnect(hoverEventCallback);
1342                 signal?.Dispose();
1343             }
1344
1345             if (interceptTouchDataCallback != null)
1346             {
1347                 TouchDataSignal signal = this.InterceptTouchSignal();
1348                 signal?.Disconnect(interceptTouchDataCallback);
1349                 signal?.Dispose();
1350             }
1351
1352             if (touchDataCallback != null)
1353             {
1354                 TouchDataSignal signal = this.TouchSignal();
1355                 signal?.Disconnect(touchDataCallback);
1356                 signal?.Dispose();
1357             }
1358
1359             if (ResourcesLoadedCallback != null)
1360             {
1361                 ViewSignal signal = this.ResourcesLoadedSignal();
1362                 signal?.Disconnect(ResourcesLoadedCallback);
1363                 signal?.Dispose();
1364                 ResourcesLoadedCallback = null;
1365             }
1366
1367             if (keyCallback != null)
1368             {
1369                 ControlKeySignal signal = this.KeyEventSignal();
1370                 signal?.Disconnect(keyCallback);
1371                 signal?.Dispose();
1372             }
1373
1374             if (keyInputFocusLostCallback != null)
1375             {
1376                 KeyInputFocusSignal signal = this.KeyInputFocusLostSignal();
1377                 signal?.Disconnect(keyInputFocusLostCallback);
1378                 signal?.Dispose();
1379             }
1380
1381             if (keyInputFocusGainedCallback != null)
1382             {
1383                 KeyInputFocusSignal signal = this.KeyInputFocusGainedSignal();
1384                 signal?.Disconnect(keyInputFocusGainedCallback);
1385                 signal?.Dispose();
1386             }
1387
1388             if (backgroundResourceLoadedCallback != null)
1389             {
1390                 ViewSignal signal = this.ResourcesLoadedSignal();
1391                 signal?.Disconnect(backgroundResourceLoadedCallback);
1392                 signal?.Dispose();
1393                 backgroundResourceLoadedCallback = null;
1394             }
1395
1396             if (onWindowSendEventCallback != null)
1397             {
1398                 ViewSignal signal = this.OnWindowSignal();
1399                 signal?.Disconnect(onWindowSendEventCallback);
1400                 signal?.Dispose();
1401                 onWindowSendEventCallback = null;
1402             }
1403
1404             // BaseHandle CPtr is used in Registry and there is danger of deletion if we keep using it here.
1405             // Restore current CPtr.
1406             SwigCPtr = currentCPtr;
1407         }
1408
1409         /// <summary>
1410         /// Apply initial style to the view.
1411         /// </summary>
1412         [EditorBrowsable(EditorBrowsableState.Never)]
1413         protected virtual void InitializeStyle(ViewStyle style = null)
1414         {
1415             var initialStyle = ThemeManager.GetInitialStyleWithoutClone(GetType());
1416             if (style == null)
1417             {
1418                 ApplyStyle(initialStyle);
1419             }
1420             else
1421             {
1422                 var refinedStyle = style;
1423                 if (style.IncludeDefaultStyle)
1424                 {
1425                     refinedStyle = initialStyle?.Merge(style);
1426                 }
1427                 ApplyStyle(refinedStyle);
1428             }
1429
1430             // Listen theme change event if needs.
1431             if (ThemeManager.PlatformThemeEnabled && initialStyle != null)
1432             {
1433                 SetThemeApplied();
1434             }
1435         }
1436
1437         private View ConvertIdToView(uint id)
1438         {
1439             View view = GetParent()?.FindCurrentChildById(id);
1440
1441             //If we can't find the parent's children, find in the top layer.
1442             if (!view)
1443             {
1444                 Container parent = GetParent();
1445                 while ((parent is View) && (parent != null))
1446                 {
1447                     parent = parent.GetParent();
1448                     if (parent is Layer)
1449                     {
1450                         view = parent.FindCurrentChildById(id);
1451                         break;
1452                     }
1453                 }
1454             }
1455
1456             return view;
1457         }
1458
1459         private void OnScaleChanged(float x, float y, float z)
1460         {
1461             Scale = new Vector3(x, y, z);
1462         }
1463
1464         private void OnBackgroundColorChanged(float r, float g, float b, float a)
1465         {
1466             BackgroundColor = new Color(r, g, b, a);
1467         }
1468
1469         private void OnPaddingChanged(ushort start, ushort end, ushort top, ushort bottom)
1470         {
1471             Padding = new Extents(start, end, top, bottom);
1472         }
1473
1474         private void OnMarginChanged(ushort start, ushort end, ushort top, ushort bottom)
1475         {
1476             Margin = new Extents(start, end, top, bottom);
1477         }
1478
1479         private void OnColorChanged(float r, float g, float b, float a)
1480         {
1481             Color = new Color(r, g, b, a);
1482         }
1483
1484         private void OnAnchorPointChanged(float x, float y, float z)
1485         {
1486             AnchorPoint = new Position(x, y, z);
1487         }
1488
1489         private void OnCellIndexChanged(float x, float y)
1490         {
1491             CellIndex = new Vector2(x, y);
1492         }
1493
1494         private void OnFlexMarginChanged(float x, float y, float z, float w)
1495         {
1496             FlexMargin = new Vector4(x, y, z, w);
1497         }
1498
1499         private void OnPaddingEXChanged(ushort start, ushort end, ushort top, ushort bottom)
1500         {
1501             PaddingEX = new Extents(start, end, top, bottom);
1502         }
1503
1504         private void OnSizeModeFactorChanged(float x, float y, float z)
1505         {
1506             SizeModeFactor = new Vector3(x, y, z);
1507         }
1508
1509         private bool EmptyOnTouch(object target, TouchEventArgs args)
1510         {
1511             return false;
1512         }
1513
1514         private ViewSelectorData EnsureSelectorData()
1515         {
1516             if (themeData == null) themeData = new ThemeData();
1517
1518             return themeData.selectorData ?? (themeData.selectorData = new ViewSelectorData());
1519         }
1520     }
1521 }