47b4dec2521d16d1d0c8502976528877be45361a
[platform/core/csapi/tizenfx.git] / src / Tizen.NUI / src / public / BaseComponents / ViewInternal.cs
1 /*
2  * Copyright(c) 2022 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.ComponentModel;
20 using global::System.Diagnostics;
21 using Tizen.NUI;
22
23 namespace Tizen.NUI.BaseComponents
24 {
25     /// <summary>
26     /// View is the base class for all views.
27     /// </summary>
28     /// <since_tizen> 3 </since_tizen>
29     public partial class View
30     {
31         internal string styleName;
32
33         [Flags]
34         internal enum BackgroundExtraDataUpdatedFlag : byte
35         {
36             BackgroundCornerRadius = 1 << 0,
37             BackgroundBorderline = 1 << 1,
38             ShadowCornerRadius = 1 << 2,
39             ContentsCornerRadius = 1 << 3, /// Subclass cases.
40             ContentsBorderline = 1 << 4, /// Subclass cases.
41
42             Background = BackgroundCornerRadius | BackgroundBorderline,
43             Shadow = ShadowCornerRadius,
44
45             CornerRadius = BackgroundCornerRadius | ShadowCornerRadius | ContentsCornerRadius,
46             Borderline = BackgroundBorderline | ContentsBorderline,
47
48             None = 0,
49             All = Background | Shadow,
50         }
51
52         internal BackgroundExtraDataUpdatedFlag backgroundExtraDataUpdatedFlag = BackgroundExtraDataUpdatedFlag.None;
53
54         private bool backgroundExtraDataUpdateProcessAttachedFlag = false;
55
56         internal virtual LayoutItem CreateDefaultLayout()
57         {
58             return new AbsoluteLayout();
59         }
60
61         internal class ThemeData
62         {
63             [Flags]
64             private enum States : byte
65             {
66                 None = 0,
67                 ControlStatePropagation = 1 << 0,
68                 ThemeChangeSensitive = 1 << 1,
69                 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.
70                                        // That indicates the view can have different styles by theme.
71                                        // Hence if the current state has ThemeApplied and ThemeChangeSensitive, the view will change its style by theme changing.
72                 ListeningThemeChangeEvent = 1 << 3,
73             };
74
75             private States states = ThemeManager.ApplicationThemeChangeSensitive ? States.ThemeChangeSensitive : States.None;
76             public ViewStyle viewStyle;
77             public ControlState controlStates = ControlState.Normal;
78             public ViewSelectorData selectorData;
79
80             public bool ControlStatePropagation
81             {
82                 get => ((states & States.ControlStatePropagation) != 0);
83                 set => SetOption(States.ControlStatePropagation, value);
84             }
85
86             public bool ThemeChangeSensitive
87             {
88                 get => ((states & States.ThemeChangeSensitive) != 0);
89                 set => SetOption(States.ThemeChangeSensitive, value);
90             }
91
92             public bool ThemeApplied
93             {
94                 get => ((states & States.ThemeApplied) != 0);
95                 set => SetOption(States.ThemeApplied, value);
96             }
97
98             public bool ListeningThemeChangeEvent
99             {
100                 get => ((states & States.ListeningThemeChangeEvent) != 0);
101                 set => SetOption(States.ListeningThemeChangeEvent, value);
102             }
103
104             private void SetOption(States option, bool value)
105             {
106                 if (value) states |= option;
107                 else states &= ~option;
108             }
109         }
110
111         /// <summary>
112         /// The color mode of View.
113         /// This specifies whether the View uses its own color, or inherits its parent color.
114         /// The default is ColorMode.UseOwnMultiplyParentColor.
115         /// </summary>
116         internal ColorMode ColorMode
117         {
118             set
119             {
120                 SetColorMode(value);
121             }
122             get
123             {
124                 return GetColorMode();
125             }
126         }
127
128         internal LayoutLength SuggestedMinimumWidth
129         {
130             get
131             {
132                 float result = Interop.Actor.GetSuggestedMinimumWidth(SwigCPtr);
133                 if (NDalicPINVOKE.SWIGPendingException.Pending)
134                     throw NDalicPINVOKE.SWIGPendingException.Retrieve();
135                 return new LayoutLength(result);
136             }
137         }
138
139         internal LayoutLength SuggestedMinimumHeight
140         {
141             get
142             {
143                 float result = Interop.Actor.GetSuggestedMinimumHeight(SwigCPtr);
144                 if (NDalicPINVOKE.SWIGPendingException.Pending)
145                     throw NDalicPINVOKE.SWIGPendingException.Retrieve();
146                 return new LayoutLength(result);
147             }
148         }
149
150         internal float WorldPositionX
151         {
152             get
153             {
154
155                 return Object.InternalGetPropertyFloat(SwigCPtr, View.Property.WorldPositionX);
156             }
157         }
158
159         internal float WorldPositionY
160         {
161             get
162             {
163
164                 return Object.InternalGetPropertyFloat(SwigCPtr, View.Property.WorldPositionY);
165             }
166         }
167
168         internal float WorldPositionZ
169         {
170             get
171             {
172
173                 return Object.InternalGetPropertyFloat(SwigCPtr, View.Property.WorldPositionZ);
174             }
175         }
176
177         internal bool FocusState
178         {
179             get
180             {
181                 return IsKeyboardFocusable();
182             }
183             set
184             {
185                 SetKeyboardFocusable(value);
186             }
187         }
188
189         internal void SetLayout(LayoutItem layout)
190         {
191             LayoutCount++;
192
193             this.layout = layout;
194             this.layout?.AttachToOwner(this);
195             this.layout?.RequestLayout();
196         }
197
198         internal void AttachTransitionsToChildren(LayoutTransition transition)
199         {
200             // Iterate children, adding the transition unless a transition
201             // for the same condition and property has already been
202             // explicitly added.
203             foreach (View view in Children)
204             {
205                 LayoutTransitionsHelper.AddTransitionForCondition(view.LayoutTransitions, transition.Condition, transition, false);
206             }
207         }
208
209         internal float ParentOriginX
210         {
211             get
212             {
213
214                 return Object.InternalGetPropertyFloat(SwigCPtr, View.Property.ParentOriginX);
215             }
216             set
217             {
218
219                 Object.InternalSetPropertyFloat(SwigCPtr, View.Property.WorldPositionX, value);
220                 NotifyPropertyChanged();
221             }
222         }
223
224         internal float ParentOriginY
225         {
226             get
227             {
228
229                 return Object.InternalGetPropertyFloat(SwigCPtr, View.Property.ParentOriginY);
230             }
231             set
232             {
233
234                 Object.InternalSetPropertyFloat(SwigCPtr, View.Property.ParentOriginY, value);
235                 NotifyPropertyChanged();
236             }
237         }
238
239         internal float ParentOriginZ
240         {
241             get
242             {
243
244                 return Object.InternalGetPropertyFloat(SwigCPtr, View.Property.ParentOriginZ);
245             }
246             set
247             {
248
249                 Object.InternalSetPropertyFloat(SwigCPtr, View.Property.ParentOriginZ, value);
250                 NotifyPropertyChanged();
251             }
252         }
253
254         internal float PivotPointX
255         {
256             get
257             {
258
259                 return Object.InternalGetPropertyFloat(SwigCPtr, View.Property.AnchorPointX);
260             }
261             set
262             {
263
264                 Object.InternalSetPropertyFloat(SwigCPtr, View.Property.AnchorPointX, value);
265             }
266         }
267
268         internal float PivotPointY
269         {
270             get
271             {
272
273                 return Object.InternalGetPropertyFloat(SwigCPtr, View.Property.AnchorPointY);
274             }
275             set
276             {
277
278                 Object.InternalSetPropertyFloat(SwigCPtr, View.Property.AnchorPointY, value);
279             }
280         }
281
282         internal float PivotPointZ
283         {
284             get
285             {
286
287                 return Object.InternalGetPropertyFloat(SwigCPtr, View.Property.AnchorPointZ);
288             }
289             set
290             {
291
292                 Object.InternalSetPropertyFloat(SwigCPtr, View.Property.AnchorPointZ, value);
293             }
294         }
295
296         internal Matrix WorldMatrix
297         {
298             get
299             {
300                 Matrix returnValue = new Matrix();
301                 PropertyValue wordMatrix = GetProperty(View.Property.WorldMatrix);
302                 wordMatrix?.Get(returnValue);
303                 wordMatrix?.Dispose();
304                 return returnValue;
305             }
306         }
307
308         /// <summary>
309         /// The number of layouts including view's layout and children's layouts.
310         /// This can be used to set/unset Process callback to calculate Layout.
311         /// </summary>
312         internal int LayoutCount
313         {
314             get
315             {
316                 return layoutCount;
317             }
318
319             set
320             {
321                 if (layoutCount == value) return;
322
323                 if (value < 0) throw new global::System.ArgumentOutOfRangeException(nameof(LayoutCount), "LayoutCount(" + LayoutCount + ") should not be less than zero");
324
325                 int diff = value - layoutCount;
326                 layoutCount = value;
327
328                 if (InternalParent != null)
329                 {
330                     var parentView = InternalParent as View;
331                     if (parentView != null)
332                     {
333                         parentView.LayoutCount += diff;
334                     }
335                     else
336                     {
337                         var parentLayer = InternalParent as Layer;
338                         if (parentLayer != null)
339                         {
340                             parentLayer.LayoutCount += diff;
341                         }
342                     }
343                 }
344             }
345         }
346
347         /// <summary>
348         /// Indicates that this View should listen Touch event to handle its ControlState.
349         /// </summary>
350         private bool enableControlState = false;
351
352         private int LeftFocusableViewId
353         {
354             get
355             {
356
357                 return Object.InternalGetPropertyInt(SwigCPtr, View.Property.LeftFocusableViewId);
358             }
359             set
360             {
361
362                 Object.InternalSetPropertyInt(SwigCPtr, View.Property.LeftFocusableViewId, value);
363             }
364         }
365
366         private int RightFocusableViewId
367         {
368             get
369             {
370
371                 return Object.InternalGetPropertyInt(SwigCPtr, View.Property.RightFocusableViewId);
372             }
373             set
374             {
375
376                 Object.InternalSetPropertyInt(SwigCPtr, View.Property.RightFocusableViewId, value);
377             }
378         }
379
380         private int UpFocusableViewId
381         {
382             get
383             {
384
385                 return Object.InternalGetPropertyInt(SwigCPtr, View.Property.UpFocusableViewId);
386             }
387             set
388             {
389
390                 Object.InternalSetPropertyInt(SwigCPtr, View.Property.UpFocusableViewId, value);
391             }
392         }
393
394         private int DownFocusableViewId
395         {
396             get
397             {
398
399                 return Object.InternalGetPropertyInt(SwigCPtr, View.Property.DownFocusableViewId);
400             }
401             set
402             {
403
404                 Object.InternalSetPropertyInt(SwigCPtr, View.Property.DownFocusableViewId, value);
405             }
406         }
407
408         private int ClockwiseFocusableViewId
409         {
410             get
411             {
412
413                 return Object.InternalGetPropertyInt(SwigCPtr, View.Property.ClockwiseFocusableViewId);
414             }
415             set
416             {
417
418                 Object.InternalSetPropertyInt(SwigCPtr, View.Property.ClockwiseFocusableViewId, value);
419             }
420         }
421
422         private int CounterClockwiseFocusableViewId
423         {
424             get
425             {
426
427                 return Object.InternalGetPropertyInt(SwigCPtr, View.Property.CounterClockwiseFocusableViewId);
428             }
429             set
430             {
431
432                 Object.InternalSetPropertyInt(SwigCPtr, View.Property.CounterClockwiseFocusableViewId, value);
433             }
434         }
435
436         internal string GetName()
437         {
438             string ret = Interop.Actor.GetName(SwigCPtr);
439             if (NDalicPINVOKE.SWIGPendingException.Pending)
440                 throw NDalicPINVOKE.SWIGPendingException.Retrieve();
441             return ret;
442         }
443
444         internal void SetName(string name)
445         {
446             Interop.Actor.SetName(SwigCPtr, name);
447             if (NDalicPINVOKE.SWIGPendingException.Pending)
448                 throw NDalicPINVOKE.SWIGPendingException.Retrieve();
449         }
450
451         internal uint GetId()
452         {
453             uint ret = Interop.Actor.GetId(SwigCPtr);
454             if (NDalicPINVOKE.SWIGPendingException.Pending)
455                 throw NDalicPINVOKE.SWIGPendingException.Retrieve();
456             return ret;
457         }
458
459         internal bool IsRoot()
460         {
461             bool ret = Interop.ActorInternal.IsRoot(SwigCPtr);
462             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
463             return ret;
464         }
465
466         internal bool OnWindow()
467         {
468             bool ret = Interop.Actor.OnStage(SwigCPtr);
469             if (NDalicPINVOKE.SWIGPendingException.Pending)
470                 throw NDalicPINVOKE.SWIGPendingException.Retrieve();
471             return ret;
472         }
473
474         internal View FindChildById(uint id)
475         {
476             //to fix memory leak issue, match the handle count with native side.
477             IntPtr cPtr = Interop.Actor.FindChildById(SwigCPtr, id);
478             View ret = this.GetInstanceSafely<View>(cPtr);
479             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
480             return ret;
481         }
482
483         internal override View FindCurrentChildById(uint id)
484         {
485             return FindChildById(id);
486         }
487
488         internal void SetParentOrigin(Position origin)
489         {
490             Interop.ActorInternal.SetParentOrigin(SwigCPtr, Position.getCPtr(origin));
491             if (NDalicPINVOKE.SWIGPendingException.Pending)
492                 throw NDalicPINVOKE.SWIGPendingException.Retrieve();
493         }
494
495         internal Position GetCurrentParentOrigin()
496         {
497
498             if(internalCurrentParentOrigin == null)
499             {
500                 internalCurrentParentOrigin = new Position(0, 0, 0);
501             }
502
503             Interop.ActorInternal.RetrieveCurrentPropertyVector3(SwigCPtr, View.Property.ParentOrigin, internalCurrentParentOrigin.SwigCPtr);
504
505             if (NDalicPINVOKE.SWIGPendingException.Pending)
506             {
507                 throw NDalicPINVOKE.SWIGPendingException.Retrieve();
508             }
509             return internalCurrentParentOrigin;
510         }
511
512         internal void SetAnchorPoint(Position anchorPoint)
513         {
514             Interop.Actor.SetAnchorPoint(SwigCPtr, Position.getCPtr(anchorPoint));
515             if (NDalicPINVOKE.SWIGPendingException.Pending)
516                 throw NDalicPINVOKE.SWIGPendingException.Retrieve();
517         }
518
519         internal Position GetCurrentAnchorPoint()
520         {
521
522             if(internalCurrentAnchorPoint == null)
523             {
524                 internalCurrentAnchorPoint = new Position(0, 0, 0);
525             }
526
527             Interop.ActorInternal.RetrieveCurrentPropertyVector3(SwigCPtr, View.Property.AnchorPoint, internalCurrentAnchorPoint.SwigCPtr);
528
529             if (NDalicPINVOKE.SWIGPendingException.Pending)
530             {
531                 throw NDalicPINVOKE.SWIGPendingException.Retrieve();
532             }
533             return internalCurrentAnchorPoint;
534         }
535
536         internal void SetSize(float width, float height)
537         {
538             Interop.ActorInternal.SetSize(SwigCPtr, width, height);
539             if (NDalicPINVOKE.SWIGPendingException.Pending)
540                 throw NDalicPINVOKE.SWIGPendingException.Retrieve();
541         }
542
543         internal void SetSize(float width, float height, float depth)
544         {
545             Interop.ActorInternal.SetSize(SwigCPtr, width, height, depth);
546             if (NDalicPINVOKE.SWIGPendingException.Pending)
547                 throw NDalicPINVOKE.SWIGPendingException.Retrieve();
548         }
549
550         internal void SetSize(Vector2 size)
551         {
552             Interop.ActorInternal.SetSizeVector2(SwigCPtr, Vector2.getCPtr(size));
553             if (NDalicPINVOKE.SWIGPendingException.Pending)
554                 throw NDalicPINVOKE.SWIGPendingException.Retrieve();
555         }
556
557         internal void SetSize(Vector3 size)
558         {
559             Interop.ActorInternal.SetSizeVector3(SwigCPtr, Vector3.getCPtr(size));
560             if (NDalicPINVOKE.SWIGPendingException.Pending)
561                 throw NDalicPINVOKE.SWIGPendingException.Retrieve();
562         }
563
564         internal Vector3 GetTargetSize()
565         {
566
567             if(internalTargetSize == null)
568             {
569                 internalTargetSize = new Vector3(0, 0, 0);
570             }
571
572             Interop.ActorInternal.RetrieveTargetSize(SwigCPtr, internalTargetSize.SwigCPtr);
573
574             if (NDalicPINVOKE.SWIGPendingException.Pending)
575             {
576                 throw NDalicPINVOKE.SWIGPendingException.Retrieve();
577             }
578             return internalTargetSize;
579         }
580
581         internal Size2D GetCurrentSize()
582         {
583
584             if(internalCurrentSize == null)
585             {
586                 internalCurrentSize = new Size2D(0, 0);
587             }
588
589             Interop.ActorInternal.RetrieveCurrentPropertyVector2ActualVector3(SwigCPtr, Property.SIZE, internalCurrentSize.SwigCPtr);
590
591             if (NDalicPINVOKE.SWIGPendingException.Pending)
592             {
593                 throw NDalicPINVOKE.SWIGPendingException.Retrieve();
594             }
595             return internalCurrentSize;
596         }
597
598         internal Size2D GetCurrentSizeFloat()
599         {
600             Size ret = new Size(Interop.Actor.GetCurrentSize(SwigCPtr), true);
601             if (NDalicPINVOKE.SWIGPendingException.Pending)
602                 throw NDalicPINVOKE.SWIGPendingException.Retrieve();
603             return ret;
604         }
605
606         /// <summary>
607         /// GetNaturalSize() function behaviour can be changed for each subclass of View.
608         /// So we make GetNaturalSize() function virtual, and make subclass can define it's owned logic
609         /// </summary>
610         internal virtual Vector3 GetNaturalSize()
611         {
612             Vector3 ret = new Vector3(Interop.Actor.GetNaturalSize(SwigCPtr), true);
613             if (NDalicPINVOKE.SWIGPendingException.Pending)
614                 throw NDalicPINVOKE.SWIGPendingException.Retrieve();
615             return ret;
616         }
617
618         internal void SetX(float x)
619         {
620             Interop.ActorInternal.SetX(SwigCPtr, x);
621             if (NDalicPINVOKE.SWIGPendingException.Pending)
622                 throw NDalicPINVOKE.SWIGPendingException.Retrieve();
623         }
624
625         internal void SetY(float y)
626         {
627             Interop.ActorInternal.SetY(SwigCPtr, y);
628             if (NDalicPINVOKE.SWIGPendingException.Pending)
629                 throw NDalicPINVOKE.SWIGPendingException.Retrieve();
630         }
631
632         internal void SetZ(float z)
633         {
634             Interop.ActorInternal.SetZ(SwigCPtr, z);
635             if (NDalicPINVOKE.SWIGPendingException.Pending)
636                 throw NDalicPINVOKE.SWIGPendingException.Retrieve();
637         }
638
639         internal void TranslateBy(Vector3 distance)
640         {
641             Interop.ActorInternal.TranslateBy(SwigCPtr, Vector3.getCPtr(distance));
642             if (NDalicPINVOKE.SWIGPendingException.Pending)
643                 throw NDalicPINVOKE.SWIGPendingException.Retrieve();
644         }
645
646         internal Position GetCurrentPosition()
647         {
648
649             if(internalCurrentPosition == null)
650             {
651                 internalCurrentPosition = new Position(0, 0, 0);
652             }
653
654             Interop.ActorInternal.RetrieveCurrentPropertyVector3(SwigCPtr, Property.POSITION, internalCurrentPosition.SwigCPtr);
655
656             if (NDalicPINVOKE.SWIGPendingException.Pending)
657             {
658                 throw NDalicPINVOKE.SWIGPendingException.Retrieve();
659             }
660             return internalCurrentPosition;
661         }
662         internal Vector3 GetCurrentWorldPosition()
663         {
664
665             if(internalCurrentWorldPosition == null)
666             {
667                 internalCurrentWorldPosition = new Vector3(0, 0, 0);
668             }
669
670             Interop.ActorInternal.RetrieveCurrentPropertyVector3(SwigCPtr, View.Property.WorldPosition, internalCurrentWorldPosition.SwigCPtr);
671
672             if (NDalicPINVOKE.SWIGPendingException.Pending)
673             {
674                 throw NDalicPINVOKE.SWIGPendingException.Retrieve();
675             }
676             return internalCurrentWorldPosition;
677         }
678
679         internal Vector2 GetCurrentScreenPosition()
680         {
681
682             if(internalCurrentScreenPosition == null)
683             {
684                 internalCurrentScreenPosition = new Vector2(0, 0);
685             }
686
687             Object.InternalRetrievingPropertyVector2(SwigCPtr, View.Property.ScreenPosition, internalCurrentScreenPosition.SwigCPtr);
688
689             if (NDalicPINVOKE.SWIGPendingException.Pending)
690             {
691                 throw NDalicPINVOKE.SWIGPendingException.Retrieve();
692             }
693             return internalCurrentScreenPosition;
694         }
695
696         internal Vector4 GetCurrentScreenPositionSize()
697         {
698             Vector4 ret = new Vector4(Interop.Actor.CurrentScreenExtents(SwigCPtr), true);
699             if (NDalicPINVOKE.SWIGPendingException.Pending) throw new InvalidOperationException("FATAL: get Exception", NDalicPINVOKE.SWIGPendingException.Retrieve());
700             return ret;
701         }
702
703         internal void SetInheritPosition(bool inherit)
704         {
705             Interop.ActorInternal.SetInheritPosition(SwigCPtr, inherit);
706             if (NDalicPINVOKE.SWIGPendingException.Pending)
707                 throw NDalicPINVOKE.SWIGPendingException.Retrieve();
708         }
709
710         internal bool IsPositionInherited()
711         {
712             bool ret = Interop.ActorInternal.IsPositionInherited(SwigCPtr);
713             if (NDalicPINVOKE.SWIGPendingException.Pending)
714                 throw NDalicPINVOKE.SWIGPendingException.Retrieve();
715             return ret;
716         }
717
718         internal void SetOrientation(Degree angle, Vector3 axis)
719         {
720             Interop.ActorInternal.SetOrientationDegree(SwigCPtr, Degree.getCPtr(angle), Vector3.getCPtr(axis));
721             if (NDalicPINVOKE.SWIGPendingException.Pending)
722                 throw NDalicPINVOKE.SWIGPendingException.Retrieve();
723         }
724
725         internal void SetOrientation(Radian angle, Vector3 axis)
726         {
727             Interop.ActorInternal.SetOrientationRadian(SwigCPtr, Radian.getCPtr(angle), Vector3.getCPtr(axis));
728             if (NDalicPINVOKE.SWIGPendingException.Pending)
729                 throw NDalicPINVOKE.SWIGPendingException.Retrieve();
730         }
731
732         internal void SetOrientation(Rotation orientation)
733         {
734             Interop.ActorInternal.SetOrientationQuaternion(SwigCPtr, Rotation.getCPtr(orientation));
735             if (NDalicPINVOKE.SWIGPendingException.Pending)
736                 throw NDalicPINVOKE.SWIGPendingException.Retrieve();
737         }
738
739         internal Rotation GetCurrentOrientation()
740         {
741             Rotation ret = new Rotation(Interop.ActorInternal.GetCurrentOrientation(SwigCPtr), true);
742             if (NDalicPINVOKE.SWIGPendingException.Pending)
743                 throw NDalicPINVOKE.SWIGPendingException.Retrieve();
744             return ret;
745         }
746
747         internal void SetInheritOrientation(bool inherit)
748         {
749             Interop.ActorInternal.SetInheritOrientation(SwigCPtr, inherit);
750             if (NDalicPINVOKE.SWIGPendingException.Pending)
751                 throw NDalicPINVOKE.SWIGPendingException.Retrieve();
752         }
753
754         internal bool IsOrientationInherited()
755         {
756             bool ret = Interop.ActorInternal.IsOrientationInherited(SwigCPtr);
757             if (NDalicPINVOKE.SWIGPendingException.Pending)
758                 throw NDalicPINVOKE.SWIGPendingException.Retrieve();
759             return ret;
760         }
761
762         internal Rotation GetCurrentWorldOrientation()
763         {
764             Rotation ret = new Rotation(Interop.ActorInternal.GetCurrentWorldOrientation(SwigCPtr), true);
765             if (NDalicPINVOKE.SWIGPendingException.Pending)
766                 throw NDalicPINVOKE.SWIGPendingException.Retrieve();
767             return ret;
768         }
769
770         internal void SetScale(float scale)
771         {
772             Interop.ActorInternal.SetScale(SwigCPtr, scale);
773             if (NDalicPINVOKE.SWIGPendingException.Pending)
774                 throw NDalicPINVOKE.SWIGPendingException.Retrieve();
775         }
776
777         internal void SetScale(float scaleX, float scaleY, float scaleZ)
778         {
779             Interop.ActorInternal.SetScale(SwigCPtr, scaleX, scaleY, scaleZ);
780             if (NDalicPINVOKE.SWIGPendingException.Pending)
781                 throw NDalicPINVOKE.SWIGPendingException.Retrieve();
782         }
783
784         internal void SetScale(Vector3 scale)
785         {
786             Interop.ActorInternal.SetScale(SwigCPtr, Vector3.getCPtr(scale));
787             if (NDalicPINVOKE.SWIGPendingException.Pending)
788                 throw NDalicPINVOKE.SWIGPendingException.Retrieve();
789         }
790
791         internal Vector3 GetCurrentScale()
792         {
793
794             if(internalCurrentScale == null)
795             {
796                 internalCurrentScale = new Vector3(0, 0, 0);
797             }
798
799             Interop.ActorInternal.RetrieveCurrentPropertyVector3(SwigCPtr, View.Property.SCALE, internalCurrentScale.SwigCPtr);
800
801             if (NDalicPINVOKE.SWIGPendingException.Pending)
802             {
803                 throw NDalicPINVOKE.SWIGPendingException.Retrieve();
804             }
805             return internalCurrentScale;
806         }
807
808         internal Vector3 GetCurrentWorldScale()
809         {
810
811             if(internalCurrentWorldScale == null)
812             {
813                 internalCurrentWorldScale = new Vector3(0, 0, 0);
814             }
815
816             Interop.ActorInternal.RetrieveCurrentPropertyVector3(SwigCPtr, View.Property.WorldScale, internalCurrentWorldScale.SwigCPtr);
817
818             if (NDalicPINVOKE.SWIGPendingException.Pending)
819             {
820                 throw NDalicPINVOKE.SWIGPendingException.Retrieve();
821             }
822             return internalCurrentWorldScale;
823         }
824
825         internal void SetInheritScale(bool inherit)
826         {
827             Interop.ActorInternal.SetInheritScale(SwigCPtr, inherit);
828             if (NDalicPINVOKE.SWIGPendingException.Pending)
829                 throw NDalicPINVOKE.SWIGPendingException.Retrieve();
830         }
831
832         internal bool IsScaleInherited()
833         {
834             bool ret = Interop.ActorInternal.IsScaleInherited(SwigCPtr);
835             if (NDalicPINVOKE.SWIGPendingException.Pending)
836                 throw NDalicPINVOKE.SWIGPendingException.Retrieve();
837             return ret;
838         }
839
840         internal Matrix GetCurrentWorldMatrix()
841         {
842             Matrix ret = new Matrix(Interop.ActorInternal.GetCurrentWorldMatrix(SwigCPtr), true);
843             if (NDalicPINVOKE.SWIGPendingException.Pending)
844                 throw NDalicPINVOKE.SWIGPendingException.Retrieve();
845             return ret;
846         }
847
848         internal void SetVisible(bool visible)
849         {
850             Interop.Actor.SetVisible(SwigCPtr, visible);
851             if (NDalicPINVOKE.SWIGPendingException.Pending)
852                 throw NDalicPINVOKE.SWIGPendingException.Retrieve();
853         }
854
855         /// <summary>
856         /// Retrieve the View's current Visibility.
857         /// </summary>
858         /// <remarks>
859         /// The <see cref="Visibility"/> property is set in the main thread, so it is not updated in real time when the value is changed in the render thread.
860         /// However, this method can get the current actual value updated in real time.
861         /// </remarks>
862         internal bool IsVisible()
863         {
864             bool ret = Interop.ActorInternal.IsVisible(SwigCPtr);
865             if (NDalicPINVOKE.SWIGPendingException.Pending)
866                 throw NDalicPINVOKE.SWIGPendingException.Retrieve();
867             return ret;
868         }
869
870         internal void SetOpacity(float opacity)
871         {
872             Interop.ActorInternal.SetOpacity(SwigCPtr, opacity);
873             if (NDalicPINVOKE.SWIGPendingException.Pending)
874                 throw NDalicPINVOKE.SWIGPendingException.Retrieve();
875         }
876
877         internal float GetCurrentOpacity()
878         {
879             float ret = Interop.ActorInternal.GetCurrentOpacity(SwigCPtr);
880             if (NDalicPINVOKE.SWIGPendingException.Pending)
881                 throw NDalicPINVOKE.SWIGPendingException.Retrieve();
882             return ret;
883         }
884
885         internal Vector4 GetCurrentColor()
886         {
887
888             if(internalCurrentColor == null)
889             {
890                 internalCurrentColor = new Vector4(0, 0, 0, 0);
891             }
892
893             Interop.ActorInternal.RetrieveCurrentPropertyVector4(SwigCPtr, Interop.ActorProperty.ColorGet(), internalCurrentColor.SwigCPtr);
894
895             if (NDalicPINVOKE.SWIGPendingException.Pending)
896             {
897                 throw NDalicPINVOKE.SWIGPendingException.Retrieve();
898             }
899             return internalCurrentColor;
900         }
901         internal ColorMode GetColorMode()
902         {
903             ColorMode ret = (ColorMode)Interop.ActorInternal.GetColorMode(SwigCPtr);
904             if (NDalicPINVOKE.SWIGPendingException.Pending)
905                 throw NDalicPINVOKE.SWIGPendingException.Retrieve();
906             return ret;
907         }
908
909         internal Vector4 GetCurrentWorldColor()
910         {
911
912             if(internalCurrentWorldColor == null)
913             {
914                 internalCurrentWorldColor = new Vector4(0, 0, 0, 0);
915             }
916
917             Interop.ActorInternal.RetrieveCurrentPropertyVector4(SwigCPtr, Property.WorldColor, internalCurrentWorldColor.SwigCPtr);
918
919             if (NDalicPINVOKE.SWIGPendingException.Pending)
920             {
921                 throw NDalicPINVOKE.SWIGPendingException.Retrieve();
922             }
923             return internalCurrentWorldColor;
924         }
925
926         internal void SetDrawMode(DrawModeType drawMode)
927         {
928             Interop.ActorInternal.SetDrawMode(SwigCPtr, (int)drawMode);
929             if (NDalicPINVOKE.SWIGPendingException.Pending)
930                 throw NDalicPINVOKE.SWIGPendingException.Retrieve();
931         }
932
933         internal DrawModeType GetDrawMode()
934         {
935             DrawModeType ret = (DrawModeType)Interop.ActorInternal.GetDrawMode(SwigCPtr);
936             if (NDalicPINVOKE.SWIGPendingException.Pending)
937                 throw NDalicPINVOKE.SWIGPendingException.Retrieve();
938             return ret;
939         }
940
941         internal void SetKeyboardFocusable(bool focusable)
942         {
943             Interop.ActorInternal.SetKeyboardFocusable(SwigCPtr, focusable);
944             if (NDalicPINVOKE.SWIGPendingException.Pending)
945                 throw NDalicPINVOKE.SWIGPendingException.Retrieve();
946         }
947
948         internal bool IsKeyboardFocusable()
949         {
950             bool ret = Interop.ActorInternal.IsKeyboardFocusable(SwigCPtr);
951             if (NDalicPINVOKE.SWIGPendingException.Pending)
952                 throw NDalicPINVOKE.SWIGPendingException.Retrieve();
953             return ret;
954         }
955
956         internal void SetKeyboardFocusableChildren(bool focusable)
957         {
958             Interop.ActorInternal.SetKeyboardFocusableChildren(SwigCPtr, focusable);
959             if (NDalicPINVOKE.SWIGPendingException.Pending)
960                 throw NDalicPINVOKE.SWIGPendingException.Retrieve();
961         }
962
963         internal bool AreChildrenKeyBoardFocusable()
964         {
965             bool ret = Interop.ActorInternal.AreChildrenKeyBoardFocusable(SwigCPtr);
966             if (NDalicPINVOKE.SWIGPendingException.Pending)
967                 throw NDalicPINVOKE.SWIGPendingException.Retrieve();
968             return ret;
969         }
970
971         internal void SetFocusableInTouch(bool enabled)
972         {
973             Interop.ActorInternal.SetFocusableInTouch(SwigCPtr, enabled);
974             if (NDalicPINVOKE.SWIGPendingException.Pending)
975                 throw NDalicPINVOKE.SWIGPendingException.Retrieve();
976         }
977
978         internal bool IsFocusableInTouch()
979         {
980             bool ret = Interop.ActorInternal.IsFocusableInTouch(SwigCPtr);
981             if (NDalicPINVOKE.SWIGPendingException.Pending)
982                 throw NDalicPINVOKE.SWIGPendingException.Retrieve();
983             return ret;
984         }
985
986         internal void SetResizePolicy(ResizePolicyType policy, DimensionType dimension)
987         {
988             Interop.Actor.SetResizePolicy(SwigCPtr, (int)policy, (int)dimension);
989             if (NDalicPINVOKE.SWIGPendingException.Pending)
990                 throw NDalicPINVOKE.SWIGPendingException.Retrieve();
991         }
992
993         internal ResizePolicyType GetResizePolicy(DimensionType dimension)
994         {
995             ResizePolicyType ret = (ResizePolicyType)Interop.Actor.GetResizePolicy(SwigCPtr, (int)dimension);
996             if (NDalicPINVOKE.SWIGPendingException.Pending)
997                 throw NDalicPINVOKE.SWIGPendingException.Retrieve();
998             return ret;
999         }
1000
1001         internal Vector3 GetSizeModeFactor()
1002         {
1003
1004                 if (internalSizeModeFactor == null)
1005                 {
1006                     internalSizeModeFactor = new Vector3(OnSizeModeFactorChanged, 0, 0, 0);
1007                 }
1008                 Object.InternalRetrievingPropertyVector3(SwigCPtr, View.Property.SizeModeFactor, internalSizeModeFactor.SwigCPtr);
1009                 return internalSizeModeFactor;
1010         }
1011
1012         internal void SetMinimumSize(Vector2 size)
1013         {
1014             Interop.ActorInternal.SetMinimumSize(SwigCPtr, Vector2.getCPtr(size));
1015             if (NDalicPINVOKE.SWIGPendingException.Pending)
1016                 throw NDalicPINVOKE.SWIGPendingException.Retrieve();
1017         }
1018
1019         internal Vector2 GetMinimumSize()
1020         {
1021
1022             if (internalMinimumSize == null)
1023             {
1024                 internalMinimumSize = new Size2D(OnMinimumSizeChanged, 0, 0);
1025             }
1026             Object.InternalRetrievingPropertyVector2(SwigCPtr, View.Property.MinimumSize, internalMinimumSize.SwigCPtr);
1027             return internalMinimumSize;
1028         }
1029
1030         internal void SetMaximumSize(Vector2 size)
1031         {
1032             Interop.ActorInternal.SetMaximumSize(SwigCPtr, Vector2.getCPtr(size));
1033             if (NDalicPINVOKE.SWIGPendingException.Pending)
1034                 throw NDalicPINVOKE.SWIGPendingException.Retrieve();
1035         }
1036
1037         internal Vector2 GetMaximumSize()
1038         {
1039
1040             if (internalMaximumSize == null)
1041             {
1042                 internalMaximumSize = new Size2D(OnMaximumSizeChanged, 0, 0);
1043             }
1044             Object.InternalRetrievingPropertyVector2(SwigCPtr, View.Property.MaximumSize, internalMaximumSize.SwigCPtr);
1045             return internalMaximumSize;
1046         }
1047
1048         internal int GetHierarchyDepth()
1049         {
1050             int ret = Interop.Actor.GetHierarchyDepth(SwigCPtr);
1051             if (NDalicPINVOKE.SWIGPendingException.Pending)
1052                 throw NDalicPINVOKE.SWIGPendingException.Retrieve();
1053             return ret;
1054         }
1055
1056         internal uint GetRendererCount()
1057         {
1058             uint ret = Interop.Actor.GetRendererCount(SwigCPtr);
1059             if (NDalicPINVOKE.SWIGPendingException.Pending)
1060                 throw NDalicPINVOKE.SWIGPendingException.Retrieve();
1061             return ret;
1062         }
1063
1064         internal static global::System.Runtime.InteropServices.HandleRef getCPtr(View obj)
1065         {
1066             return (obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.SwigCPtr;
1067         }
1068
1069         internal bool IsTopLevelView()
1070         {
1071             if (GetParent() is Layer)
1072             {
1073                 return true;
1074             }
1075             return false;
1076         }
1077
1078         /// <summary>
1079         /// Check whether Current view don't has BackgroundVisual or not.
1080         /// Some API (like Animation, Borderline) required non-empty backgrounds.
1081         /// </summary>
1082         internal bool IsBackgroundEmpty()
1083         {
1084             int visualType = (int)Visual.Type.Invalid;
1085             Interop.View.InternalRetrievingVisualPropertyInt(this.SwigCPtr, Property.BACKGROUND, Visual.Property.Type, out visualType);
1086             return visualType == (int)Visual.Type.Invalid;
1087         }
1088
1089         /// <summary>
1090         /// Check whether Current view don't has ShadowVisual or not.
1091         /// </summary>
1092         internal bool IsShadowEmpty()
1093         {
1094             int visualType = (int)Visual.Type.Invalid;
1095             Interop.View.InternalRetrievingVisualPropertyInt(this.SwigCPtr, Property.SHADOW, Visual.Property.Type, out visualType);
1096             return visualType == (int)Visual.Type.Invalid;
1097         }
1098
1099         internal void SetKeyInputFocus()
1100         {
1101             Interop.ViewInternal.SetKeyInputFocus(SwigCPtr);
1102             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
1103         }
1104
1105         internal void ClearKeyInputFocus()
1106         {
1107             Interop.ViewInternal.ClearKeyInputFocus(SwigCPtr);
1108             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
1109         }
1110
1111         internal PinchGestureDetector GetPinchGestureDetector()
1112         {
1113             PinchGestureDetector ret = new PinchGestureDetector(Interop.ViewInternal.GetPinchGestureDetector(SwigCPtr), true);
1114             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
1115             return ret;
1116         }
1117
1118         internal PanGestureDetector GetPanGestureDetector()
1119         {
1120             PanGestureDetector ret = new PanGestureDetector(Interop.ViewInternal.GetPanGestureDetector(SwigCPtr), true);
1121             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
1122             return ret;
1123         }
1124
1125         internal TapGestureDetector GetTapGestureDetector()
1126         {
1127             TapGestureDetector ret = new TapGestureDetector(Interop.ViewInternal.GetTapGestureDetector(SwigCPtr), true);
1128             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
1129             return ret;
1130         }
1131
1132         internal LongPressGestureDetector GetLongPressGestureDetector()
1133         {
1134             LongPressGestureDetector ret = new LongPressGestureDetector(Interop.ViewInternal.GetLongPressGestureDetector(SwigCPtr), true);
1135             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
1136             return ret;
1137         }
1138
1139         internal IntPtr GetPtrfromView()
1140         {
1141             return (IntPtr)SwigCPtr;
1142         }
1143
1144         internal void RemoveChild(View child)
1145         {
1146             // If the view had focus, it clears focus.
1147             if (child == FocusManager.Instance.GetCurrentFocusView())
1148             {
1149                 FocusManager.Instance.ClearFocus();
1150             }
1151             // Do actual child removal
1152             Interop.Actor.Remove(SwigCPtr, View.getCPtr(child));
1153             if (NDalicPINVOKE.SWIGPendingException.Pending)
1154                 throw NDalicPINVOKE.SWIGPendingException.Retrieve();
1155
1156             Children.Remove(child);
1157             child.InternalParent = null;
1158             LayoutCount -= child.LayoutCount;
1159
1160             OnChildRemoved(child);
1161             if (ChildRemoved != null)
1162             {
1163                 ChildRemovedEventArgs e = new ChildRemovedEventArgs
1164                 {
1165                     Removed = child
1166                 };
1167                 ChildRemoved(this, e);
1168             }
1169         }
1170
1171         /// <summary>
1172         /// Removes the layout from this View.
1173         /// </summary>
1174         internal void ResetLayout()
1175         {
1176             LayoutCount--;
1177
1178             layout = null;
1179         }
1180
1181         internal ResourceLoadingStatusType GetBackgroundResourceStatus()
1182         {
1183             return (ResourceLoadingStatusType)Interop.View.GetVisualResourceStatus(this.SwigCPtr, Property.BACKGROUND);
1184         }
1185
1186         /// <summary>
1187         /// Lazy call to UpdateBackgroundExtraData.
1188         /// Collect Properties need to be update, and set properties that starts the Processing.
1189         /// </summary>
1190         internal virtual void UpdateBackgroundExtraData(BackgroundExtraDataUpdatedFlag flag)
1191         {
1192             if (backgroundExtraData == null)
1193             {
1194                 return;
1195             }
1196
1197             if (!backgroundExtraDataUpdatedFlag.HasFlag(flag))
1198             {
1199                 backgroundExtraDataUpdatedFlag |= flag;
1200                 // TODO : Re-open this API when we resolve Animation issue.
1201                 // Instead, let we call UpdateBackgroundExtraData() synchronously.
1202                 UpdateBackgroundExtraData();
1203                 // if (!backgroundExtraDataUpdateProcessAttachedFlag)
1204                 // {
1205                 //     backgroundExtraDataUpdateProcessAttachedFlag = true;
1206                 //     ProcessorController.Instance.ProcessorOnceEvent += UpdateBackgroundExtraData;
1207                 //     // Call process hardly.
1208                 //     ProcessorController.Instance.Awake();
1209                 // }
1210             }
1211         }
1212
1213         /// <summary>
1214         /// Callback function to Lazy UpdateBackgroundExtraData.
1215         /// </summary>
1216         private void UpdateBackgroundExtraData(object source, EventArgs e)
1217         {
1218             // Note : To allow event attachment during UpdateBackgroundExtraData, let we make flag as false before call UpdateBackgroundExtraData().
1219             backgroundExtraDataUpdateProcessAttachedFlag = false;
1220             UpdateBackgroundExtraData();
1221         }
1222
1223         /// <summary>
1224         /// Update background extra data properties synchronously.
1225         /// After call this API, All background extra data properties updated.
1226         /// </summary>
1227         internal virtual void UpdateBackgroundExtraData()
1228         {
1229             if (backgroundExtraData == null)
1230             {
1231                 return;
1232             }
1233
1234             if (IsShadowEmpty())
1235             {
1236                 backgroundExtraDataUpdatedFlag &= ~BackgroundExtraDataUpdatedFlag.Shadow;
1237             }
1238             if (!Rectangle.IsNullOrZero(backgroundExtraData.BackgroundImageBorder))
1239             {
1240                 backgroundExtraDataUpdatedFlag &= ~BackgroundExtraDataUpdatedFlag.Background;
1241             }
1242
1243             if (backgroundExtraDataUpdatedFlag == BackgroundExtraDataUpdatedFlag.None)
1244             {
1245                 return;
1246             }
1247
1248             if ((backgroundExtraDataUpdatedFlag & BackgroundExtraDataUpdatedFlag.Borderline) != BackgroundExtraDataUpdatedFlag.None)
1249             {
1250                 ApplyBorderline();
1251             }
1252             if ((backgroundExtraDataUpdatedFlag & BackgroundExtraDataUpdatedFlag.CornerRadius) != BackgroundExtraDataUpdatedFlag.None)
1253             {
1254                 ApplyCornerRadius();
1255             }
1256             backgroundExtraDataUpdatedFlag = BackgroundExtraDataUpdatedFlag.None;
1257         }
1258
1259         /// TODO open as a protected level
1260         internal virtual void ApplyCornerRadius()
1261         {
1262             if (backgroundExtraData == null) return;
1263
1264             // Update corner radius properties to background and shadow by ActionUpdateProperty
1265             if (backgroundExtraDataUpdatedFlag.HasFlag(BackgroundExtraDataUpdatedFlag.BackgroundCornerRadius))
1266             {
1267                 if (backgroundExtraData.CornerRadius != null)
1268                 {
1269                     Interop.View.InternalUpdateVisualPropertyVector4(this.SwigCPtr, View.Property.BACKGROUND, Visual.Property.CornerRadius, Vector4.getCPtr(backgroundExtraData.CornerRadius));
1270                 }
1271                 Interop.View.InternalUpdateVisualPropertyInt(this.SwigCPtr, View.Property.BACKGROUND, Visual.Property.CornerRadiusPolicy, (int)backgroundExtraData.CornerRadiusPolicy);
1272             }
1273             if (backgroundExtraDataUpdatedFlag.HasFlag(BackgroundExtraDataUpdatedFlag.ShadowCornerRadius))
1274             {
1275                 if (backgroundExtraData.CornerRadius != null)
1276                 {
1277                     Interop.View.InternalUpdateVisualPropertyVector4(this.SwigCPtr, View.Property.SHADOW, Visual.Property.CornerRadius, Vector4.getCPtr(backgroundExtraData.CornerRadius));
1278                 }
1279                 Interop.View.InternalUpdateVisualPropertyInt(this.SwigCPtr, View.Property.SHADOW, Visual.Property.CornerRadiusPolicy, (int)backgroundExtraData.CornerRadiusPolicy);
1280             }
1281         }
1282
1283         /// TODO open as a protected level
1284         internal virtual void ApplyBorderline()
1285         {
1286             if (backgroundExtraData == null) return;
1287
1288             // ActionUpdateProperty works well only if BACKGROUND visual setup before.
1289             // If view don't have BACKGROUND visual, we set transparent background color in default.
1290             if (IsBackgroundEmpty())
1291             {
1292                 // BACKGROUND visual doesn't exist.
1293                 SetBackgroundColor(Color.Transparent);
1294                 // SetBackgroundColor function apply borderline internally.
1295                 // So we can just return now.
1296                 return;
1297             }
1298
1299             // Update borderline properties to background by ActionUpdateProperty
1300             if (backgroundExtraDataUpdatedFlag.HasFlag(BackgroundExtraDataUpdatedFlag.BackgroundBorderline))
1301             {
1302                 Interop.View.InternalUpdateVisualPropertyFloat(this.SwigCPtr, View.Property.BACKGROUND, Visual.Property.BorderlineWidth, backgroundExtraData.BorderlineWidth);
1303                 Interop.View.InternalUpdateVisualPropertyVector4(this.SwigCPtr, View.Property.BACKGROUND, Visual.Property.BorderlineColor, Vector4.getCPtr(backgroundExtraData.BorderlineColor ?? Color.Black));
1304                 Interop.View.InternalUpdateVisualPropertyFloat(this.SwigCPtr, View.Property.BACKGROUND, Visual.Property.BorderlineOffset, backgroundExtraData.BorderlineOffset);
1305             }
1306         }
1307
1308         /// <summary>
1309         /// Get selector value from the triggerable selector or related property.
1310         /// </summary>
1311         internal Selector<T> GetSelector<T>(TriggerableSelector<T> triggerableSelector, NUI.Binding.BindableProperty relatedProperty)
1312         {
1313             var selector = triggerableSelector?.Get();
1314             if (selector != null)
1315             {
1316                 return selector;
1317             }
1318
1319             var value = (T)GetValue(relatedProperty);
1320             return value == null ? null : new Selector<T>(value);
1321         }
1322
1323         internal void SetThemeApplied()
1324         {
1325             if (themeData == null) themeData = new ThemeData();
1326             themeData.ThemeApplied = true;
1327
1328             if (ThemeChangeSensitive && !themeData.ListeningThemeChangeEvent)
1329             {
1330                 themeData.ListeningThemeChangeEvent = true;
1331                 ThemeManager.ThemeChangedInternal.Add(OnThemeChanged);
1332             }
1333         }
1334
1335         /// <summary>
1336         /// you can override it to clean-up your own resources.
1337         /// </summary>
1338         /// <param name="type">DisposeTypes</param>
1339         /// <since_tizen> 3 </since_tizen>
1340         protected override void Dispose(DisposeTypes type)
1341         {
1342             if (disposed)
1343             {
1344                 return;
1345             }
1346
1347             disposeDebugging(type);
1348
1349             if (SwigCMemOwn && !IsNativeHandleInvalid())
1350             {
1351                 Interop.ControlDevel.DaliAccessibilityDetachAccessibleObject(SwigCPtr);
1352                 NDalicPINVOKE.ThrowExceptionIfExists();
1353             }
1354
1355             //_mergedStyle = null;
1356
1357             internalMaximumSize?.Dispose();
1358             internalMaximumSize = null;
1359             internalMinimumSize?.Dispose();
1360             internalMinimumSize = null;
1361             internalMargin?.Dispose();
1362             internalMargin = null;
1363             internalPadding?.Dispose();
1364             internalPadding = null;
1365             internalSizeModeFactor?.Dispose();
1366             internalSizeModeFactor = null;
1367             internalCellIndex?.Dispose();
1368             internalCellIndex = null;
1369             internalBackgroundColor?.Dispose();
1370             internalBackgroundColor = null;
1371             internalColor?.Dispose();
1372             internalColor = null;
1373             internalPivotPoint?.Dispose();
1374             internalPivotPoint = null;
1375             internalPosition?.Dispose();
1376             internalPosition = null;
1377             internalPosition2D?.Dispose();
1378             internalPosition2D = null;
1379             internalScale?.Dispose();
1380             internalScale = null;
1381             internalSize?.Dispose();
1382             internalSize = null;
1383             internalSize2D?.Dispose();
1384             internalSize2D = null;
1385
1386             panGestureDetector?.Dispose();
1387             panGestureDetector = null;
1388             longGestureDetector?.Dispose();
1389             longGestureDetector = null;
1390             pinchGestureDetector?.Dispose();
1391             pinchGestureDetector = null;
1392             tapGestureDetector?.Dispose();
1393             tapGestureDetector = null;
1394             rotationGestureDetector?.Dispose();
1395             rotationGestureDetector = null;
1396
1397             internalCurrentParentOrigin?.Dispose();
1398             internalCurrentParentOrigin = null;
1399             internalCurrentAnchorPoint?.Dispose();
1400             internalCurrentAnchorPoint = null;
1401             internalTargetSize?.Dispose();
1402             internalTargetSize = null;
1403             internalCurrentSize?.Dispose();
1404             internalCurrentSize = null;
1405             internalCurrentPosition?.Dispose();
1406             internalCurrentPosition = null;
1407             internalCurrentWorldPosition?.Dispose();
1408             internalCurrentWorldPosition = null;
1409             internalCurrentScale?.Dispose();
1410             internalCurrentScale = null;
1411             internalCurrentWorldScale?.Dispose();
1412             internalCurrentWorldScale = null;
1413             internalCurrentColor?.Dispose();
1414             internalCurrentColor = null;
1415             internalCurrentWorldColor?.Dispose();
1416             internalCurrentWorldColor = null;
1417             internalSizeModeFactor?.Dispose();
1418             internalSizeModeFactor = null;
1419             internalCurrentScreenPosition?.Dispose();
1420             internalCurrentScreenPosition = null;
1421
1422             if (type == DisposeTypes.Explicit)
1423             {
1424                 //Called by User
1425                 //Release your own managed resources here.
1426                 //You should release all of your own disposable objects here.
1427                 if (themeData != null)
1428                 {
1429                     themeData.selectorData?.Reset(this);
1430                     if (themeData.ListeningThemeChangeEvent)
1431                     {
1432                         ThemeManager.ThemeChangedInternal.Remove(OnThemeChanged);
1433                     }
1434                 }
1435                 if (widthConstraint != null)
1436                 {
1437                     widthConstraint.Remove();
1438                     widthConstraint.Dispose();
1439                 }
1440                 if (heightConstraint != null)
1441                 {
1442                     heightConstraint.Remove();
1443                     heightConstraint.Dispose();
1444                 }
1445             }
1446
1447             //Release your own unmanaged resources here.
1448             //You should not access any managed member here except static instance.
1449             //because the execution order of Finalizes is non-deterministic.
1450
1451             DisConnectFromSignals();
1452
1453             foreach (View view in Children)
1454             {
1455                 view.InternalParent = null;
1456             }
1457
1458             backgroundExtraDataUpdatedFlag = BackgroundExtraDataUpdatedFlag.None;
1459             if (backgroundExtraDataUpdateProcessAttachedFlag)
1460             {
1461                 ProcessorController.Instance.ProcessorOnceEvent -= UpdateBackgroundExtraData;
1462                 backgroundExtraDataUpdateProcessAttachedFlag = false;
1463             }
1464
1465             LayoutCount = 0;
1466
1467             NUILog.Debug($"[Dispose] View.Dispose({type}) END");
1468             NUILog.Debug($"=============================");
1469
1470             base.Dispose(type);
1471             
1472             aliveCount--;
1473         }
1474
1475         /// This will not be public opened.
1476         [EditorBrowsable(EditorBrowsableState.Never)]
1477         protected override void ReleaseSwigCPtr(System.Runtime.InteropServices.HandleRef swigCPtr)
1478         {
1479             Interop.View.DeleteView(swigCPtr);
1480         }
1481
1482         /// <summary>
1483         /// The touch event handler for ControlState.
1484         /// Please change ControlState value by touch state if needed.
1485         /// </summary>
1486         /// <exception cref="ArgumentNullException"> Thrown when touch is null. </exception>
1487         [EditorBrowsable(EditorBrowsableState.Never)]
1488         protected virtual bool HandleControlStateOnTouch(Touch touch)
1489         {
1490             if (touch == null)
1491             {
1492                 throw new global::System.ArgumentNullException(nameof(touch));
1493             }
1494
1495             switch (touch.GetState(0))
1496             {
1497                 case PointStateType.Down:
1498                     ControlState += ControlState.Pressed;
1499                     break;
1500                 case PointStateType.Interrupted:
1501                 case PointStateType.Up:
1502                     if (ControlState.Contains(ControlState.Pressed))
1503                     {
1504                         ControlState -= ControlState.Pressed;
1505                     }
1506                     break;
1507                 default:
1508                     break;
1509             }
1510             return false;
1511         }
1512
1513         /// <summary>
1514         /// Internal callback of enabled property changes.
1515         /// Inherited view can override this method to implements enabled property changes.
1516         /// </summary>
1517         [EditorBrowsable(EditorBrowsableState.Never)]
1518         protected virtual void OnEnabled(bool enabled)
1519         {
1520             if (enabled)
1521             {
1522                 if (State == View.States.Disabled)
1523                 {
1524                     State = View.States.Normal;
1525                 }
1526                 if (enableControlState)
1527                 {
1528                     ControlState -= ControlState.Disabled;
1529                 }
1530             }
1531             else
1532             {
1533                 State = View.States.Disabled;
1534                 if (enableControlState)
1535                 {
1536                     ControlState += ControlState.Disabled;
1537                 }
1538             }
1539         }
1540
1541
1542         private void DisConnectFromSignals()
1543         {
1544             if (HasBody() == false)
1545             {
1546                 NUILog.Debug($"[Dispose] DisConnectFromSignals() No native body! No need to Disconnect Signals!");
1547                 return;
1548             }
1549             NUILog.Debug($"[Dispose] DisConnectFromSignals START");
1550             NUILog.Debug($"[Dispose] View.DisConnectFromSignals() type:{GetType()} copyNativeHandle:{GetBaseHandleCPtrHandleRef.Handle.ToString("X8")}");
1551             NUILog.Debug($"[Dispose] ID:{Interop.Actor.GetId(GetBaseHandleCPtrHandleRef)} Name:{Interop.Actor.GetName(GetBaseHandleCPtrHandleRef)}");
1552
1553             if (onRelayoutEventCallback != null)
1554             {
1555                 NUILog.Debug($"[Dispose] onRelayoutEventCallback");
1556
1557                 Interop.ActorSignal.OnRelayoutDisconnect(GetBaseHandleCPtrHandleRef, onRelayoutEventCallback.ToHandleRef(this));
1558                 NDalicPINVOKE.ThrowExceptionIfExistsDebug();
1559                 onRelayoutEventCallback = null;
1560             }
1561
1562             if (offWindowEventCallback != null)
1563             {
1564                 NUILog.Debug($"[Dispose] offWindowEventCallback");
1565
1566                 Interop.ActorSignal.OffSceneDisconnect(GetBaseHandleCPtrHandleRef, offWindowEventCallback.ToHandleRef(this));
1567                 NDalicPINVOKE.ThrowExceptionIfExistsDebug();
1568                 offWindowEventCallback = null;
1569             }
1570
1571             if (onWindowEventCallback != null)
1572             {
1573                 NUILog.Debug($"[Dispose] onWindowEventCallback");
1574
1575                 Interop.ActorSignal.OnSceneDisconnect(GetBaseHandleCPtrHandleRef, onWindowEventCallback.ToHandleRef(this));
1576                 NDalicPINVOKE.ThrowExceptionIfExistsDebug();
1577                 onWindowEventCallback = null;
1578             }
1579
1580             if (interceptWheelCallback != null)
1581             {
1582                 NUILog.Debug($"[Dispose] interceptWheelCallback");
1583
1584                 Interop.ActorSignal.InterceptWheelDisconnect(GetBaseHandleCPtrHandleRef, interceptWheelCallback.ToHandleRef(this));
1585                 NDalicPINVOKE.ThrowExceptionIfExistsDebug();
1586                 interceptWheelCallback = null;
1587             }
1588
1589             if (wheelEventCallback != null)
1590             {
1591                 NUILog.Debug($"[Dispose] wheelEventCallback");
1592
1593                 Interop.ActorSignal.WheelEventDisconnect(GetBaseHandleCPtrHandleRef, wheelEventCallback.ToHandleRef(this));
1594                 NDalicPINVOKE.ThrowExceptionIfExistsDebug();
1595                 wheelEventCallback = null;
1596             }
1597
1598             if (hoverEventCallback != null)
1599             {
1600                 NUILog.Debug($"[Dispose] hoverEventCallback");
1601
1602                 Interop.ActorSignal.HoveredDisconnect(GetBaseHandleCPtrHandleRef, hoverEventCallback.ToHandleRef(this));
1603                 NDalicPINVOKE.ThrowExceptionIfExistsDebug();
1604                 hoverEventCallback = null;
1605             }
1606
1607             if (hitTestResultDataCallback != null)
1608             {
1609                 NUILog.Debug($"[Dispose] hitTestResultDataCallback");
1610
1611                 Interop.ActorSignal.HitTestResultDisconnect(GetBaseHandleCPtrHandleRef, hitTestResultDataCallback.ToHandleRef(this));
1612                 NDalicPINVOKE.ThrowExceptionIfExistsDebug();
1613                 hitTestResultDataCallback = null;
1614             }
1615
1616
1617             if (interceptTouchDataCallback != null)
1618             {
1619                 NUILog.Debug($"[Dispose] interceptTouchDataCallback");
1620
1621                 Interop.ActorSignal.InterceptTouchDisconnect(GetBaseHandleCPtrHandleRef, interceptTouchDataCallback.ToHandleRef(this));
1622                 NDalicPINVOKE.ThrowExceptionIfExistsDebug();
1623                 interceptTouchDataCallback = null;
1624             }
1625
1626             if (touchDataCallback != null)
1627             {
1628                 NUILog.Debug($"[Dispose] touchDataCallback");
1629
1630                 Interop.ActorSignal.TouchDisconnect(GetBaseHandleCPtrHandleRef, touchDataCallback.ToHandleRef(this));
1631                 NDalicPINVOKE.ThrowExceptionIfExistsDebug();
1632                 touchDataCallback = null;
1633             }
1634
1635             if (resourcesLoadedCallback != null)
1636             {
1637                 NUILog.Debug($"[Dispose] ResourcesLoadedCallback");
1638
1639                 Interop.ViewSignal.ResourceReadyDisconnect(GetBaseHandleCPtrHandleRef, resourcesLoadedCallback.ToHandleRef(this));
1640                 NDalicPINVOKE.ThrowExceptionIfExistsDebug();
1641                 resourcesLoadedCallback = null;
1642             }
1643
1644             if (keyCallback != null)
1645             {
1646                 NUILog.Debug($"[Dispose] keyCallback");
1647
1648                 Interop.ViewSignal.KeyEventDisconnect(GetBaseHandleCPtrHandleRef, keyCallback.ToHandleRef(this));
1649                 NDalicPINVOKE.ThrowExceptionIfExistsDebug();
1650                 keyCallback = null;
1651             }
1652
1653             if (keyInputFocusLostCallback != null)
1654             {
1655                 NUILog.Debug($"[Dispose] keyInputFocusLostCallback");
1656
1657                 Interop.ViewSignal.KeyInputFocusLostDisconnect(GetBaseHandleCPtrHandleRef, keyInputFocusLostCallback.ToHandleRef(this));
1658                 NDalicPINVOKE.ThrowExceptionIfExistsDebug();
1659                 keyInputFocusLostCallback = null;
1660                 keyInputFocusLostEventHandler = null;
1661             }
1662
1663             if (keyInputFocusGainedCallback != null)
1664             {
1665                 NUILog.Debug($"[Dispose] keyInputFocusGainedCallback");
1666
1667                 Interop.ViewSignal.KeyInputFocusGainedDisconnect(GetBaseHandleCPtrHandleRef, keyInputFocusGainedCallback.ToHandleRef(this));
1668                 NDalicPINVOKE.ThrowExceptionIfExistsDebug();
1669                 keyInputFocusGainedCallback = null;
1670                 keyInputFocusGainedEventHandler = null;
1671             }
1672
1673             if (backgroundResourceLoadedCallback != null)
1674             {
1675                 NUILog.Debug($"[Dispose] backgroundResourceLoadedCallback");
1676
1677                 Interop.ViewSignal.ResourceReadyDisconnect(GetBaseHandleCPtrHandleRef, backgroundResourceLoadedCallback.ToHandleRef(this));
1678                 NDalicPINVOKE.ThrowExceptionIfExistsDebug();
1679                 backgroundResourceLoadedCallback = null;
1680             }
1681
1682             NDalicPINVOKE.ThrowExceptionIfExists();
1683             NUILog.Debug($"[Dispose] DisConnectFromSignals END");
1684         }
1685
1686         /// <summary>
1687         /// Apply initial style to the view.
1688         /// </summary>
1689         [EditorBrowsable(EditorBrowsableState.Never)]
1690         protected virtual void InitializeStyle(ViewStyle style = null)
1691         {
1692             if (style == null && ThemeManager.InitialThemeDisabled)
1693             {
1694                 // Fast return in most TV cases.
1695                 return;
1696             }
1697
1698             var initialStyle = ThemeManager.GetInitialStyleWithoutClone(GetType());
1699             if (style == null)
1700             {
1701                 ApplyStyle(initialStyle);
1702             }
1703             else
1704             {
1705                 var refinedStyle = style;
1706                 if (style.IncludeDefaultStyle)
1707                 {
1708                     refinedStyle = initialStyle?.Merge(style);
1709                 }
1710                 ApplyStyle(refinedStyle);
1711             }
1712
1713             // Listen theme change event if needs.
1714             if (initialStyle != null)
1715             {
1716                 SetThemeApplied();
1717             }
1718         }
1719
1720         private View ConvertIdToView(uint id)
1721         {
1722             View view = GetParent()?.FindCurrentChildById(id);
1723
1724             //If we can't find the parent's children, find in the top layer.
1725             if (!view)
1726             {
1727                 Container parent = GetParent();
1728                 while ((parent is View) && (parent != null))
1729                 {
1730                     parent = parent.GetParent();
1731                     if (parent is Layer)
1732                     {
1733                         view = parent.FindCurrentChildById(id);
1734                         break;
1735                     }
1736                 }
1737             }
1738
1739             return view;
1740         }
1741
1742         private void OnScaleChanged(float x, float y, float z)
1743         {
1744             Scale = new Vector3(x, y, z);
1745         }
1746
1747         private void OnBackgroundColorChanged(float r, float g, float b, float a)
1748         {
1749             BackgroundColor = new Color(r, g, b, a);
1750         }
1751
1752         private void OnPaddingChanged(ushort start, ushort end, ushort top, ushort bottom)
1753         {
1754             Padding = new Extents(start, end, top, bottom);
1755         }
1756
1757         private void OnMarginChanged(ushort start, ushort end, ushort top, ushort bottom)
1758         {
1759             Margin = new Extents(start, end, top, bottom);
1760         }
1761
1762         private void OnAnchorPointChanged(float x, float y, float z)
1763         {
1764             AnchorPoint = new Position(x, y, z);
1765         }
1766
1767         private void OnCellIndexChanged(float x, float y)
1768         {
1769             CellIndex = new Vector2(x, y);
1770         }
1771
1772         private void OnFlexMarginChanged(float x, float y, float z, float w)
1773         {
1774             FlexMargin = new Vector4(x, y, z, w);
1775         }
1776
1777         private void OnPaddingEXChanged(ushort start, ushort end, ushort top, ushort bottom)
1778         {
1779             PaddingEX = new Extents(start, end, top, bottom);
1780         }
1781
1782         private void OnSizeModeFactorChanged(float x, float y, float z)
1783         {
1784             SizeModeFactor = new Vector3(x, y, z);
1785         }
1786
1787         private bool EmptyOnTouch(object target, TouchEventArgs args)
1788         {
1789             return false;
1790         }
1791
1792         [EditorBrowsable(EditorBrowsableState.Never)]
1793         protected virtual bool CheckResourceReady()
1794         {
1795             return true;
1796         }
1797
1798         private ViewSelectorData EnsureSelectorData()
1799         {
1800             if (themeData == null) themeData = new ThemeData();
1801
1802             return themeData.selectorData ?? (themeData.selectorData = new ViewSelectorData());
1803         }
1804
1805         [Conditional("NUI_DISPOSE_DEBUG_ON")]
1806         private void disposeDebugging(DisposeTypes type)
1807         {
1808             DebugFileLogging.Instance.WriteLog($"View.Dispose({type}) START");
1809             DebugFileLogging.Instance.WriteLog($"type:{GetType()} copyNativeHandle:{GetBaseHandleCPtrHandleRef.Handle.ToString("X8")}");
1810             if (HasBody())
1811             {
1812                 DebugFileLogging.Instance.WriteLog($"ID:{Interop.Actor.GetId(GetBaseHandleCPtrHandleRef)} Name:{Interop.Actor.GetName(GetBaseHandleCPtrHandleRef)}");
1813             }
1814             else
1815             {
1816                 DebugFileLogging.Instance.WriteLog($"has no native body!");
1817             }
1818         }
1819
1820     }
1821 }