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