[NUI] Make internal API for calculate screen position and extents.
[platform/core/csapi/tizenfx.git] / src / Tizen.NUI / src / public / BaseComponents / ViewPublicMethods.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 System.Reflection;
21 using System.Runtime.InteropServices;
22 using Tizen.NUI.Binding;
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         /// <summary>
33         /// Perform an action on a visual registered to this view. <br />
34         /// Visuals will have actions. This API is used to perform one of these actions with the given attributes.
35         /// </summary>
36         /// <param name="propertyIndexOfVisual">The Property index of the visual.</param>
37         /// <param name="propertyIndexOfActionId">The action to perform. See Visual to find the supported actions.</param>
38         /// <param name="attributes">Optional attributes for the action.</param>
39         /// <since_tizen> 5 </since_tizen>
40         public void DoAction(int propertyIndexOfVisual, int propertyIndexOfActionId, PropertyValue attributes)
41         {
42             Interop.View.DoAction(SwigCPtr, propertyIndexOfVisual, propertyIndexOfActionId, PropertyValue.getCPtr(attributes));
43             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
44         }
45
46         /// <summary>
47         /// Creates an animation to animate the background color visual. If there is no
48         /// background visual, creates one with transparent black as it's mixColor.
49         /// </summary>
50         /// <since_tizen> 3 </since_tizen>
51         public Animation AnimateBackgroundColor(object destinationValue,
52                                                  int startTime,
53                                                  int endTime,
54                                                  AlphaFunction.BuiltinFunctions? alphaFunction = null,
55                                                  object initialValue = null)
56         {
57             if (IsBackgroundEmpty())
58             {
59                 // If there is no background yet, ensure there is a transparent
60                 // color visual
61                 BackgroundColor = new Color(0.0f, 0.0f, 0.0f, 0.0f);
62             }
63             return AnimateColor("background", destinationValue, startTime, endTime, alphaFunction, initialValue);
64         }
65
66         /// <summary>
67         /// Creates an animation to animate the mixColor of the named visual.
68         /// </summary>
69         /// <since_tizen> 3 </since_tizen>
70         public Animation AnimateColor(string targetVisual, object destinationColor, int startTime, int endTime, AlphaFunction.BuiltinFunctions? alphaFunction = null, object initialColor = null)
71         {
72             Animation animation = null;
73             using (PropertyMap animator = new PropertyMap())
74             using (PropertyMap timePeriod = new PropertyMap())
75             using (PropertyValue pvDuration = new PropertyValue((endTime - startTime) / 1000.0f))
76             using (PropertyValue pvDelay = new PropertyValue(startTime / 1000.0f))
77             using (PropertyMap transition = new PropertyMap())
78             using (PropertyValue pvTarget = new PropertyValue(targetVisual))
79             using (PropertyValue pvProperty = new PropertyValue("mixColor"))
80             using (PropertyValue destValue = PropertyValue.CreateFromObject(destinationColor))
81             {
82                 if (alphaFunction != null)
83                 {
84                     using (PropertyValue pvAlpha = new PropertyValue(AlphaFunction.BuiltinToPropertyKey(alphaFunction)))
85                     {
86                         animator.Add("alphaFunction", pvAlpha);
87                     }
88                 }
89
90                 timePeriod.Add("duration", pvDuration);
91                 timePeriod.Add("delay", pvDelay);
92                 using (PropertyValue pvTimePeriod = new PropertyValue(timePeriod))
93                 {
94                     animator.Add("timePeriod", pvTimePeriod);
95                 }
96                 using (PropertyValue pvAnimator = new PropertyValue(animator))
97                 {
98                     transition.Add("animator", pvAnimator);
99                 }
100                 transition.Add("target", pvTarget);
101                 transition.Add("property", pvProperty);
102
103                 if (initialColor != null)
104                 {
105                     using (PropertyValue initValue = PropertyValue.CreateFromObject(initialColor))
106                     {
107                         transition.Add("initialValue", initValue);
108                     }
109                 }
110
111                 transition.Add("targetValue", destValue);
112                 using (TransitionData transitionData = new TransitionData(transition))
113                 {
114                     animation = new Animation(Interop.View.CreateTransition(SwigCPtr, TransitionData.getCPtr(transitionData)), true);
115                 }
116                 if (NDalicPINVOKE.SWIGPendingException.Pending)
117                     throw NDalicPINVOKE.SWIGPendingException.Retrieve();
118             }
119             return animation;
120         }
121
122         // From Container Base class
123         /// <summary>
124         /// Adds a child view to this view.
125         /// </summary>
126         /// <seealso cref="Container.Add" />
127         /// <since_tizen> 4 </since_tizen>
128         public override void Add(View child)
129         {
130             bool hasLayout = (layout != null);
131
132             if (null == child)
133             {
134                 Tizen.Log.Fatal("NUI", "Child is null");
135                 return;
136             }
137
138             Container oldParent = child.GetParent();
139             if (oldParent != this)
140             {
141                 // If child already has a parent then re-parent child
142                 if (oldParent != null)
143                 {
144                     if (child.Layout != null)
145                     {
146                         child.Layout.SetReplaceFlag();
147                     }
148                     oldParent.Remove(child);
149                 }
150                 child.InternalParent = this;
151                 LayoutCount += child.LayoutCount;
152
153                 Interop.Actor.Add(SwigCPtr, View.getCPtr(child));
154
155                 if (NDalicPINVOKE.SWIGPendingException.Pending)
156                     throw NDalicPINVOKE.SWIGPendingException.Retrieve();
157                 Children.Add(child);
158                 OnChildAdded(child);
159
160                 if (ChildAdded != null)
161                 {
162                     ChildAddedEventArgs e = new ChildAddedEventArgs
163                     {
164                         Added = child
165                     };
166                     ChildAdded(this, e);
167                 }
168             }
169         }
170
171         /// <summary>
172         /// Removes a child view from this View. If the view was not a child of this view, this is a no-op.
173         /// </summary>
174         /// <seealso cref="Container.Remove" />
175         /// <since_tizen> 4 </since_tizen>
176         /// <exception cref="InvalidOperationException">Thrown when deleting a view that is not a child of this view</exception>
177         public override void Remove(View child)
178         {
179             if (child == null || child.GetParent() == null) // Early out if child null.
180                 return;
181
182             if (child.GetParent() != this)
183             {
184                 //throw new System.InvalidOperationException("You have deleted a view that is not a child of this view.");
185                 Tizen.Log.Error("NUI", "You have deleted a view that is not a child of this view.");
186                 return;
187             }
188
189             bool hasLayout = (layout != null);
190
191             // If View has a layout then do a deferred child removal
192             // Actual child removal is performed by the layouting system so
193             // transitions can be completed.
194             if (hasLayout)
195             {
196                 (layout as LayoutGroup)?.RemoveChildFromLayoutGroup(child);
197             }
198
199             RemoveChild(child);
200         }
201
202         /// <summary>
203         /// Retrieves a child view by index.
204         /// </summary>
205         /// <seealso cref="Container.GetChildAt" />
206         /// <since_tizen> 4 </since_tizen>
207         public override View GetChildAt(uint index)
208         {
209             if (index < Children.Count)
210             {
211                 return Children[Convert.ToInt32(index)];
212             }
213             else
214             {
215                 return null;
216             }
217         }
218
219         /// <summary>
220         /// Retrieves a child view as Animatable by index.
221         /// </summary>
222         /// <param name="index">The index of the Animatable to find.</param>
223         /// <returns>A handle to the view as Animatable if found, or an empty handle if not.</returns>
224         /// This will not be public opened.
225         [EditorBrowsable(EditorBrowsableState.Never)]
226         public Animatable GetChildAnimatableAt(uint index)
227         {
228             if (index < Children.Count)
229             {
230                 return Children[Convert.ToInt32(index)] as Animatable;
231             }
232             else
233             {
234                 return null;
235             }
236         }
237
238         /// <summary>
239         /// Retrieves the number of children held by the view.
240         /// </summary>
241         /// <seealso cref="Container.GetChildCount" />
242         /// <since_tizen> 4 </since_tizen>
243         [Obsolete("This has been deprecated in API9 and will be removed in API11. Use ChildCount property instead.")]
244         public override uint GetChildCount()
245         {
246             return Convert.ToUInt32(Children.Count);
247         }
248
249         /// <summary>
250         /// Gets the views parent.
251         /// </summary>
252         /// <seealso cref="Container.GetParent()" />
253         /// <since_tizen> 4 </since_tizen>
254         public override Container GetParent()
255         {
256             return InternalParent as Container;
257         }
258
259         /// <summary>
260         /// Queries whether the view has a focus.
261         /// </summary>
262         /// <returns>True if this view has a focus.</returns>
263         /// <since_tizen> 3 </since_tizen>
264         public bool HasFocus()
265         {
266             bool ret = false;
267             if (SwigCPtr.Handle != global::System.IntPtr.Zero)
268             {
269                 ret = Interop.View.HasKeyInputFocus(SwigCPtr);
270                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
271             }
272             else
273             {
274                 Tizen.Log.Error("NUI", "swigCPtr of view is already disposed.");
275             }
276             return ret;
277         }
278
279         /// <summary>
280         /// Sets the name of the style to be applied to the view.
281         /// </summary>
282         /// <param name="styleName">A string matching a style described in a stylesheet.</param>
283         /// <since_tizen> 3 </since_tizen>
284         [Obsolete("This has been deprecated in API9 and will be removed in API11. Use StyleName property instead.")]
285         public void SetStyleName(string styleName)
286         {
287             Interop.View.SetStyleName(SwigCPtr, styleName);
288             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
289         }
290
291         /// <summary>
292         /// Retrieves the name of the style to be applied to the view (if any).
293         /// </summary>
294         /// <returns>A string matching a style, or an empty string.</returns>
295         /// <since_tizen> 3 </since_tizen>
296         [Obsolete("This has been deprecated in API9 and will be removed in API11. Use StyleName property instead.")]
297         public string GetStyleName()
298         {
299             string ret = Interop.View.GetStyleName(SwigCPtr);
300             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
301             return ret;
302         }
303
304         /// <summary>
305         /// Clears the background.
306         /// </summary>
307         /// <since_tizen> 3 </since_tizen>
308         public void ClearBackground()
309         {
310             Interop.View.ClearBackground(SwigCPtr);
311             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
312         }
313
314         /// <summary>
315         /// Shows the view.
316         /// </summary>
317         /// <remarks>
318         /// This is an asynchronous method.
319         /// </remarks>
320         /// <since_tizen> 3 </since_tizen>
321         public void Show()
322         {
323             SetVisible(true);
324
325             if (GetAccessibilityStates()[AccessibilityState.Modal])
326             {
327                 RegisterDefaultLabel();
328
329                 if (Accessibility.Accessibility.IsEnabled)
330                 {
331                     EmitAccessibilityStateChangedEvent(AccessibilityState.Showing, true);
332                 }
333             }
334         }
335
336         /// <summary>
337         /// Hides the view.
338         /// </summary>
339         /// <remarks>
340         /// This is an asynchronous method.
341         /// If the view is hidden, then the view and its children will not be rendered.
342         /// This is regardless of the individual visibility of the children, i.e., the view will only be rendered if all of its parents are shown.
343         /// </remarks>
344         /// <since_tizen> 3 </since_tizen>
345         public void Hide()
346         {
347             SetVisible(false);
348
349             if (GetAccessibilityStates()[AccessibilityState.Modal])
350             {
351                 UnregisterDefaultLabel();
352
353                 if (Accessibility.Accessibility.IsEnabled)
354                 {
355                     EmitAccessibilityStateChangedEvent(AccessibilityState.Showing, false);
356                 }
357             }
358         }
359
360         /// <summary>
361         /// Raises the view above all other views.
362         /// </summary>
363         /// <remarks>
364         /// Sibling order of views within the parent will be updated automatically.
365         /// Once a raise or lower API is used, that view will then have an exclusive sibling order independent of insertion.
366         /// </remarks>
367         /// <since_tizen> 3 </since_tizen>
368         public void RaiseToTop()
369         {
370             var parentChildren = GetParent()?.Children;
371
372             if (parentChildren != null)
373             {
374                 parentChildren.Remove(this);
375                 parentChildren.Add(this);
376
377                 LayoutGroup layout = Layout as LayoutGroup;
378                 layout?.ChangeLayoutSiblingOrder(parentChildren.Count - 1);
379
380                 Interop.NDalic.RaiseToTop(SwigCPtr);
381                 if (NDalicPINVOKE.SWIGPendingException.Pending)
382                     throw NDalicPINVOKE.SWIGPendingException.Retrieve();
383             }
384
385         }
386
387         /// <summary>
388         /// Lowers the view to the bottom of all views.
389         /// </summary>
390         /// <remarks>
391         /// The sibling order of views within the parent will be updated automatically.
392         /// Once a raise or lower API is used that view will then have an exclusive sibling order independent of insertion.
393         /// </remarks>
394         /// <since_tizen> 3 </since_tizen>
395         public void LowerToBottom()
396         {
397             var parentChildren = GetParent()?.Children;
398
399             if (parentChildren != null)
400             {
401                 parentChildren.Remove(this);
402                 parentChildren.Insert(0, this);
403
404                 LayoutGroup layout = Layout as LayoutGroup;
405                 layout?.ChangeLayoutSiblingOrder(0);
406
407                 Interop.NDalic.LowerToBottom(SwigCPtr);
408                 if (NDalicPINVOKE.SWIGPendingException.Pending)
409                     throw NDalicPINVOKE.SWIGPendingException.Retrieve();
410             }
411         }
412
413         /// <summary>
414         /// Queries if all resources required by a view are loaded and ready.
415         /// </summary>
416         /// <remarks>Most resources are only loaded when the control is placed on the stage.
417         /// </remarks>
418         /// <since_tizen> 3 </since_tizen>
419         public bool IsResourceReady()
420         {
421             bool ret = Interop.View.IsResourceReady(SwigCPtr);
422             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
423             return ret;
424         }
425
426         /// <summary>
427         /// Gets the parent layer of this view.If a view has no parent, this method does not do anything.
428         /// </summary>
429         /// <pre>The view has been initialized. </pre>
430         /// <returns>The parent layer of view </returns>
431         /// <since_tizen> 5 </since_tizen>
432         public Layer GetLayer()
433         {
434             //to fix memory leak issue, match the handle count with native side.
435             IntPtr cPtr = Interop.Actor.GetLayer(SwigCPtr);
436             Layer ret = this.GetInstanceSafely<Layer>(cPtr);
437             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
438             return ret;
439         }
440
441         /// <summary>
442         /// Removes a view from its parent view or layer. If a view has no parent, this method does nothing.
443         /// </summary>
444         /// <pre>The (child) view has been initialized. </pre>
445         /// <since_tizen> 4 </since_tizen>
446         public void Unparent()
447         {
448             GetParent()?.Remove(this);
449         }
450
451         /// <summary>
452         /// Search through this view's hierarchy for a view with the given name.
453         /// The view itself is also considered in the search.
454         /// </summary>
455         /// <pre>The view has been initialized.</pre>
456         /// <param name="viewName">The name of the view to find.</param>
457         /// <returns>A handle to the view if found, or an empty handle if not.</returns>
458         /// <since_tizen> 3 </since_tizen>
459         public View FindChildByName(string viewName)
460         {
461             //to fix memory leak issue, match the handle count with native side.
462             IntPtr cPtr = Interop.Actor.FindChildByName(SwigCPtr, viewName);
463             View ret = this.GetInstanceSafely<View>(cPtr);
464             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
465             return ret;
466         }
467
468         /// <summary>
469         /// Search through this view's hierarchy for a view as Animatable with the given name.
470         /// The view itself is also considered in the search.
471         /// </summary>
472         /// <pre>The view has been initialized.</pre>
473         /// <param name="childName">The name of the Animatable to find.</param>
474         /// <returns>A handle to the view as Animatable if found, or an empty handle if not.</returns>
475         /// This will not be public opened.
476         [EditorBrowsable(EditorBrowsableState.Never)]
477         public Animatable FindChildAnimatableByName(string childName)
478         {
479             //to fix memory leak issue, match the handle count with native side.
480             IntPtr cPtr = Interop.Actor.FindChildByName(SwigCPtr, childName);
481             Animatable ret = Registry.GetManagedBaseHandleFromNativePtr(cPtr) as Animatable;
482             if(ret == null)
483             {
484                 // Register new camera into Registry.
485                 ret = new Animatable(cPtr, true);
486             }
487             else
488             {
489                 // We found matched NUI camera. Reduce cPtr reference count.
490                 HandleRef handle = new HandleRef(this, cPtr);
491                 Interop.Actor.DeleteActor(handle);
492                 handle = new HandleRef(null, IntPtr.Zero);
493             }
494             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
495             return ret;
496         }
497
498         /// <summary>
499         /// Converts screen coordinates into the view's coordinate system using the default camera.
500         /// </summary>
501         /// <pre>The view has been initialized.</pre>
502         /// <remarks>The view coordinates are relative to the top-left(0.0, 0.0, 0.5).</remarks>
503         /// <param name="localX">On return, the X-coordinate relative to the view.</param>
504         /// <param name="localY">On return, the Y-coordinate relative to the view.</param>
505         /// <param name="screenX">The screen X-coordinate.</param>
506         /// <param name="screenY">The screen Y-coordinate.</param>
507         /// <returns>True if the conversion succeeded.</returns>
508         /// <since_tizen> 3 </since_tizen>
509         public bool ScreenToLocal(out float localX, out float localY, float screenX, float screenY)
510         {
511             bool ret = Interop.Actor.ScreenToLocal(SwigCPtr, out localX, out localY, screenX, screenY);
512             if (NDalicPINVOKE.SWIGPendingException.Pending)
513                 throw NDalicPINVOKE.SWIGPendingException.Retrieve();
514             return ret;
515         }
516
517         /// <summary>
518         /// Sets the relative to parent size factor of the view.<br />
519         /// This factor is only used when ResizePolicy is set to either:
520         /// ResizePolicy::SIZE_RELATIVE_TO_PARENT or ResizePolicy::SIZE_FIXED_OFFSET_FROM_PARENT.<br />
521         /// This view's size is set to the view's size multiplied by or added to this factor, depending on ResizePolicy.<br />
522         /// </summary>
523         /// <pre>The view has been initialized.</pre>
524         /// <param name="factor">A Vector3 representing the relative factor to be applied to each axis.</param>
525         /// <since_tizen> 3 </since_tizen>
526         public void SetSizeModeFactor(Vector3 factor)
527         {
528             Interop.Actor.SetSizeModeFactor(SwigCPtr, Vector3.getCPtr(factor));
529             if (NDalicPINVOKE.SWIGPendingException.Pending)
530                 throw NDalicPINVOKE.SWIGPendingException.Retrieve();
531         }
532         /// <summary>
533         /// Calculates the height of the view given a width.<br />
534         /// The natural size is used for default calculation.<br />
535         /// Size 0 is treated as aspect ratio 1:1.<br />
536         /// </summary>
537         /// <param name="width">The width to use.</param>
538         /// <returns>The height based on the width.</returns>
539         /// <since_tizen> 3 </since_tizen>
540         public float GetHeightForWidth(float width)
541         {
542             float ret = Interop.Actor.GetHeightForWidth(SwigCPtr, width);
543             if (NDalicPINVOKE.SWIGPendingException.Pending)
544                 throw NDalicPINVOKE.SWIGPendingException.Retrieve();
545             return ret;
546         }
547
548         /// <summary>
549         /// Calculates the width of the view given a height.<br />
550         /// The natural size is used for default calculation.<br />
551         /// Size 0 is treated as aspect ratio 1:1.<br />
552         /// </summary>
553         /// <param name="height">The height to use.</param>
554         /// <returns>The width based on the height.</returns>
555         /// <since_tizen> 3 </since_tizen>
556         public float GetWidthForHeight(float height)
557         {
558             float ret = Interop.Actor.GetWidthForHeight(SwigCPtr, height);
559             if (NDalicPINVOKE.SWIGPendingException.Pending)
560                 throw NDalicPINVOKE.SWIGPendingException.Retrieve();
561             return ret;
562         }
563
564         /// <summary>
565         /// Return the amount of size allocated for relayout.
566         /// </summary>
567         /// <param name="dimension">The dimension to retrieve.</param>
568         /// <returns>Return the size.</returns>
569         /// <since_tizen> 3 </since_tizen>
570         public float GetRelayoutSize(DimensionType dimension)
571         {
572             float ret = Interop.Actor.GetRelayoutSize(SwigCPtr, (int)dimension);
573             if (NDalicPINVOKE.SWIGPendingException.Pending)
574                 throw NDalicPINVOKE.SWIGPendingException.Retrieve();
575             return ret;
576         }
577
578         /// <summary>
579         /// Set the padding for the view.
580         /// </summary>
581         /// <param name="padding">Padding for the view.</param>
582         /// <since_tizen> 3 </since_tizen>
583         // [Obsolete("This has been deprecated in API9 and will be removed in API11. Use Padding property instead.")]
584         public void SetPadding(PaddingType padding)
585         {
586             Interop.Actor.SetPadding(SwigCPtr, PaddingType.getCPtr(padding));
587             if (NDalicPINVOKE.SWIGPendingException.Pending)
588                 throw NDalicPINVOKE.SWIGPendingException.Retrieve();
589         }
590
591         /// <summary>
592         /// Return the value of padding for the view.
593         /// </summary>
594         /// <param name="paddingOut">the value of padding for the view</param>
595         /// <since_tizen> 3 </since_tizen>
596         [Obsolete("This has been deprecated in API9 and will be removed in API11. Use Padding property instead.")]
597         public void GetPadding(PaddingType paddingOut)
598         {
599             Interop.Actor.GetPadding(SwigCPtr, PaddingType.getCPtr(paddingOut));
600             if (NDalicPINVOKE.SWIGPendingException.Pending)
601                 throw NDalicPINVOKE.SWIGPendingException.Retrieve();
602         }
603
604         /// <since_tizen> 3 </since_tizen>
605         public uint AddRenderer(Renderer renderer)
606         {
607             uint ret = Interop.Actor.AddRenderer(SwigCPtr, Renderer.getCPtr(renderer));
608             if (NDalicPINVOKE.SWIGPendingException.Pending)
609                 throw NDalicPINVOKE.SWIGPendingException.Retrieve();
610             return ret;
611         }
612
613         /// <since_tizen> 3 </since_tizen>
614         public Renderer GetRendererAt(uint index)
615         {
616             //to fix memory leak issue, match the handle count with native side.
617             IntPtr cPtr = Interop.Actor.GetRendererAt(SwigCPtr, index);
618             HandleRef CPtr = new global::System.Runtime.InteropServices.HandleRef(this, cPtr);
619             Renderer ret = Registry.GetManagedBaseHandleFromNativePtr(CPtr.Handle) as Renderer;
620             if (cPtr != null && ret == null)
621             {
622                 ret = new Renderer(cPtr, false);
623                 if (NDalicPINVOKE.SWIGPendingException.Pending)
624                     throw NDalicPINVOKE.SWIGPendingException.Retrieve();
625                 return ret;
626             }
627             Interop.BaseHandle.DeleteBaseHandle(CPtr);
628             CPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero);
629
630             if (NDalicPINVOKE.SWIGPendingException.Pending)
631                 throw NDalicPINVOKE.SWIGPendingException.Retrieve();
632             return ret;
633         }
634
635         /// <since_tizen> 3 </since_tizen>
636         public void RemoveRenderer(Renderer renderer)
637         {
638             Interop.Actor.RemoveRenderer(SwigCPtr, Renderer.getCPtr(renderer));
639             if (NDalicPINVOKE.SWIGPendingException.Pending)
640                 throw NDalicPINVOKE.SWIGPendingException.Retrieve();
641         }
642
643         /// <since_tizen> 3 </since_tizen>
644         public void RemoveRenderer(uint index)
645         {
646             Interop.Actor.RemoveRenderer(SwigCPtr, index);
647             if (NDalicPINVOKE.SWIGPendingException.Pending)
648                 throw NDalicPINVOKE.SWIGPendingException.Retrieve();
649         }
650
651         /// This will be public opened in tizen_next after ACR done. Before ACR, need to be hidden as inhouse API.
652         [EditorBrowsable(EditorBrowsableState.Never)]
653         public void RotateBy(Degree angle, Vector3 axis)
654         {
655             Interop.ActorInternal.RotateByDegree(SwigCPtr, Degree.getCPtr(angle), Vector3.getCPtr(axis));
656             if (NDalicPINVOKE.SWIGPendingException.Pending)
657                 throw NDalicPINVOKE.SWIGPendingException.Retrieve();
658         }
659
660         /// This will be public opened in tizen_next after ACR done. Before ACR, need to be hidden as inhouse API.
661         [EditorBrowsable(EditorBrowsableState.Never)]
662         public void RotateBy(Radian angle, Vector3 axis)
663         {
664             Interop.ActorInternal.RotateByRadian(SwigCPtr, Radian.getCPtr(angle), Vector3.getCPtr(axis));
665             if (NDalicPINVOKE.SWIGPendingException.Pending)
666                 throw NDalicPINVOKE.SWIGPendingException.Retrieve();
667         }
668
669         /// This will be public opened in tizen_next after ACR done. Before ACR, need to be hidden as inhouse API.
670         [EditorBrowsable(EditorBrowsableState.Never)]
671         public void RotateBy(Rotation relativeRotation)
672         {
673             Interop.ActorInternal.RotateByQuaternion(SwigCPtr, Rotation.getCPtr(relativeRotation));
674             if (NDalicPINVOKE.SWIGPendingException.Pending)
675                 throw NDalicPINVOKE.SWIGPendingException.Retrieve();
676         }
677
678         /// This will be public opened in tizen_next after ACR done. Before ACR, need to be hidden as inhouse API.
679         [EditorBrowsable(EditorBrowsableState.Never)]
680         public void ScaleBy(Vector3 relativeScale)
681         {
682             Interop.ActorInternal.ScaleBy(SwigCPtr, Vector3.getCPtr(relativeScale));
683             if (NDalicPINVOKE.SWIGPendingException.Pending)
684                 throw NDalicPINVOKE.SWIGPendingException.Retrieve();
685         }
686
687         /// <summary>
688         /// Rotate the view look at specific position.
689         /// It will change the view's orientation property.
690         /// </summary>
691         /// <remark>Target position should be setup by world coordinates.</remark>
692         /// <param name="target">The target world position to look at.</param>
693         /// <param name="up">The up vector after target look at. If it is null, up vector become +Y axis</param>
694         /// <param name="localForward">The forward vector of view when it's orientation is not applied. If it is null, localForward vector become +Z axis</param>
695         /// <param name="localUp">The up vector of view when it's orientation is not applied. If it is null, localUp vector become +Y axis</param>
696         /// This will be public opened in tizen_next after ACR done. Before ACR, need to be hidden as inhouse API.
697         [EditorBrowsable(EditorBrowsableState.Never)]
698         public void LookAt(Vector3 target, Vector3 up = null, Vector3 localForward = null, Vector3 localUp = null)
699         {
700             Interop.ActorInternal.LookAt(SwigCPtr, Vector3.getCPtr(target), Vector3.getCPtr(up), Vector3.getCPtr(localForward), Vector3.getCPtr(localUp));
701             if (NDalicPINVOKE.SWIGPendingException.Pending)
702                 throw NDalicPINVOKE.SWIGPendingException.Retrieve();
703         }
704
705         /// This will be public opened in next tizen after ACR done. Before ACR, need to be hidden as inhouse API.
706         [EditorBrowsable(EditorBrowsableState.Never)]
707         public void SetColorMode(ColorMode colorMode)
708         {
709             Interop.ActorInternal.SetColorMode(SwigCPtr, (int)colorMode);
710             if (NDalicPINVOKE.SWIGPendingException.Pending)
711                 throw NDalicPINVOKE.SWIGPendingException.Retrieve();
712         }
713
714         /// This will be public opened in tizen_next after ACR done. Before ACR, need to be hidden as inhouse API.
715         [EditorBrowsable(EditorBrowsableState.Never)]
716         public void ObjectDump()
717         {
718             if (0 == Children.Count)
719             {
720                 Type type = this.GetType();
721                 PropertyInfo[] properties = type.GetProperties(BindingFlags.Public | BindingFlags.Instance);
722                 foreach (var property in properties)
723                 {
724                     if (null != property && property.CanRead)
725                     {
726                         Tizen.Log.Fatal("NUI", $"{type.Name} {property.Name} ({property.PropertyType.Name}): {property.GetValueString(this, property.PropertyType)}");
727                     }
728                 }
729                 return;
730             }
731
732             foreach (View view in Children)
733             {
734                 view.ObjectDump();
735             }
736         }
737
738         /// <summary>
739         /// Search through this View's hierarchy for a View with the given unique ID.
740         /// The View itself is also considered in the search.
741         /// </summary>
742         /// <param name="id">The ID of the View to find</param>
743         /// <returns>A View if found or a null if not</returns>
744         [EditorBrowsable(EditorBrowsableState.Never)]
745         [Obsolete("This will be removed at API11. Use FindDescendantByID(uint id) instead.")]
746         public View FindChildByID(uint id)
747         {
748             IntPtr cPtr = Interop.Actor.FindChildById(SwigCPtr, id);
749             View ret = this.GetInstanceSafely<View>(cPtr);
750             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
751             return ret;
752         }
753
754         /// <summary>
755         /// Search through this View's hierarchy for a View with the given unique ID.
756         /// </summary>
757         /// <param name="id">The ID of the View to find.</param>
758         /// <returns>A handle to the View if found, or an empty handle if not.</returns>
759         /// <since_tizen> 9 </since_tizen>
760         public View FindDescendantByID(uint id)
761         {
762             return FindChildById(id);
763         }
764
765         /// <summary>
766         /// Raise view above the next sibling view.
767         /// </summary>
768         /// <since_tizen> 9 </since_tizen>
769         public void Raise()
770         {
771             var parentChildren = GetParent()?.Children;
772
773             if (parentChildren != null)
774             {
775                 int currentIndex = parentChildren.IndexOf(this);
776
777                 // If the view is not already the last item in the list.
778                 if (currentIndex >= 0 && currentIndex < parentChildren.Count - 1)
779                 {
780                     View temp = parentChildren[currentIndex + 1];
781                     parentChildren[currentIndex + 1] = this;
782                     parentChildren[currentIndex] = temp;
783
784                     Interop.NDalic.Raise(SwigCPtr);
785                     if (NDalicPINVOKE.SWIGPendingException.Pending)
786                         throw NDalicPINVOKE.SWIGPendingException.Retrieve();
787                 }
788             }
789         }
790
791         /// <summary>
792         /// Lower the view below the previous sibling view.
793         /// </summary>
794         /// <since_tizen> 9 </since_tizen>
795         public void Lower()
796         {
797             var parentChildren = GetParent()?.Children;
798
799             if (parentChildren != null)
800             {
801                 int currentIndex = parentChildren.IndexOf(this);
802
803                 // If the view is not already the first item in the list.
804                 if (currentIndex > 0 && currentIndex < parentChildren.Count)
805                 {
806                     View temp = parentChildren[currentIndex - 1];
807                     parentChildren[currentIndex - 1] = this;
808                     parentChildren[currentIndex] = temp;
809
810                     Interop.NDalic.Lower(SwigCPtr);
811                     if (NDalicPINVOKE.SWIGPendingException.Pending)
812                         throw NDalicPINVOKE.SWIGPendingException.Retrieve();
813                 }
814             }
815         }
816
817         /// <summary>
818         /// Raises the view to above the target view.
819         /// </summary>
820         /// <remarks>The sibling order of views within the parent will be updated automatically.
821         /// Views on the level above the target view will still be shown above this view.
822         /// Once a raise or lower API is used then that view will have an exclusive sibling order independent of insertion.
823         /// </remarks>
824         /// <param name="target">Will be raised above this view.</param>
825         /// <since_tizen> 9 </since_tizen>
826         public void RaiseAbove(View target)
827         {
828             var parentChildren = GetParent()?.Children;
829
830             if (parentChildren != null)
831             {
832                 int currentIndex = parentChildren.IndexOf(this);
833                 int targetIndex = parentChildren.IndexOf(target);
834
835                 if (currentIndex < 0 || targetIndex < 0 ||
836                     currentIndex >= parentChildren.Count || targetIndex >= parentChildren.Count)
837                 {
838                     NUILog.Error("index should be bigger than 0 and less than children of layer count");
839                     return;
840                 }
841                 // If the currentIndex is less than the target index and the target has the same parent.
842                 if (currentIndex < targetIndex)
843                 {
844                     parentChildren.Remove(this);
845                     parentChildren.Insert(targetIndex, this);
846
847                     Interop.NDalic.RaiseAbove(SwigCPtr, View.getCPtr(target));
848                     if (NDalicPINVOKE.SWIGPendingException.Pending)
849                         throw NDalicPINVOKE.SWIGPendingException.Retrieve();
850                 }
851             }
852
853         }
854
855         /// <summary>
856         /// Lowers the view to below the target view.
857         /// </summary>
858         /// <remarks>The sibling order of views within the parent will be updated automatically.
859         /// Once a raise or lower API is used then that view will have an exclusive sibling order independent of insertion.
860         /// </remarks>
861         /// <param name="target">Will be lowered below this view.</param>
862         /// <since_tizen> 9 </since_tizen>
863         public void LowerBelow(View target)
864         {
865             var parentChildren = GetParent()?.Children;
866
867             if (parentChildren != null)
868             {
869                 int currentIndex = parentChildren.IndexOf(this);
870                 int targetIndex = parentChildren.IndexOf(target);
871                 if (currentIndex < 0 || targetIndex < 0 ||
872                    currentIndex >= parentChildren.Count || targetIndex >= parentChildren.Count)
873                 {
874                     NUILog.Error("index should be bigger than 0 and less than children of layer count");
875                     return;
876                 }
877
878                 // If the currentIndex is not already the 0th index and the target has the same parent.
879                 if ((currentIndex != 0) && (targetIndex != -1) &&
880                     (currentIndex > targetIndex))
881                 {
882                     parentChildren.Remove(this);
883                     parentChildren.Insert(targetIndex, this);
884
885                     Interop.NDalic.LowerBelow(SwigCPtr, View.getCPtr(target));
886                     if (NDalicPINVOKE.SWIGPendingException.Pending)
887                         throw NDalicPINVOKE.SWIGPendingException.Retrieve();
888                 }
889             }
890
891         }
892
893         /// <summary>
894         /// Sets the position of the View.
895         /// The coordinates are relative to the View's parent.
896         /// The View's z position will be set to 0.0f.
897         /// </summary>
898         /// <param name="x">The new x position</param>
899         /// <param name="y">The new y position</param>
900         /// <remarks>
901         /// This is a hidden API(inhouse API) only for internal purpose.
902         /// </remarks>
903         [EditorBrowsable(EditorBrowsableState.Never)]
904         public void SetPosition(float x, float y)
905         {
906             Interop.ActorInternal.SetPosition(SwigCPtr, x, y);
907             if (NDalicPINVOKE.SWIGPendingException.Pending)
908                 throw NDalicPINVOKE.SWIGPendingException.Retrieve();
909         }
910
911         /// <summary>
912         /// Sets the position of the View.
913         /// The coordinates are relative to the View's parent.
914         /// </summary>
915         /// <param name="x">The new x position</param>
916         /// <param name="y">The new y position</param>
917         /// <param name="z">The new z position</param>
918         /// <remarks>
919         /// This is a hidden API(inhouse API) only for internal purpose.
920         /// </remarks>
921         [EditorBrowsable(EditorBrowsableState.Never)]
922         public void SetPosition(float x, float y, float z)
923         {
924             Interop.ActorInternal.SetPosition(SwigCPtr, x, y, z);
925             if (NDalicPINVOKE.SWIGPendingException.Pending)
926                 throw NDalicPINVOKE.SWIGPendingException.Retrieve();
927         }
928
929         /// <summary>
930         /// Sets the position of the View.
931         /// The coordinates are relative to the View's parent.
932         /// </summary>
933         /// <param name="position">The new position</param>
934         /// <remarks>
935         /// This is a hidden API(inhouse API) only for internal purpose.
936         /// </remarks>
937         [EditorBrowsable(EditorBrowsableState.Never)]
938         public void SetPosition(Vector3 position)
939         {
940             Interop.ActorInternal.SetPosition(SwigCPtr, Vector3.getCPtr(position));
941             if (NDalicPINVOKE.SWIGPendingException.Pending)
942                 throw NDalicPINVOKE.SWIGPendingException.Retrieve();
943         }
944
945         /// <summary>
946         /// Register custom HitTest function for this view.
947         /// </summary>
948         /// <seealso cref="View.HitTest" />
949         /// <remarks>
950         /// This is a hidden API(inhouse API) only for internal purpose.
951         /// </remarks>
952         [EditorBrowsable(EditorBrowsableState.Never)]
953         protected void RegisterHitTestCallback()
954         {
955             if (hitTestResultDataCallback == null)
956             {
957                 hitTestResultDataCallback = OnHitTestResult;
958                 Interop.ActorSignal.HitTestResultConnect(SwigCPtr, hitTestResultDataCallback.ToHandleRef(this));
959                 NDalicPINVOKE.ThrowExceptionIfExistsDebug();
960             }
961         }
962
963         /// <summary>
964         /// Unregister custom HitTest function.
965         /// </summary>
966         /// <remarks>
967         /// This is a hidden API(inhouse API) only for internal purpose.
968         /// </remarks>
969         [EditorBrowsable(EditorBrowsableState.Never)]
970         protected void UnregisterHitTestCallback()
971         {
972             if (hitTestResultDataCallback != null)
973             {
974                 Interop.ActorSignal.HitTestResultDisconnect(SwigCPtr, hitTestResultDataCallback.ToHandleRef(this));
975                 NDalicPINVOKE.ThrowExceptionIfExistsDebug();
976                 hitTestResultDataCallback = null;
977             }
978         }
979
980         /// <summary>
981         /// Calculate the screen position of the view.<br />
982         /// </summary>
983         /// <remarks>
984         /// This is a hidden API(inhouse API) only for internal purpose.
985         /// </remarks>
986         [EditorBrowsable(EditorBrowsableState.Never)]
987         public Vector2 CalculateScreenPosition()
988         {
989             Vector2 ret = new Vector2(Interop.Actor.CalculateScreenPosition(SwigCPtr), true);
990             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
991             return ret;
992         }
993
994         /// <summary>
995         /// Calculate the screen position and size of the view.<br />
996         /// </summary>
997         /// <remarks>
998         /// The float type Rectangle class is not ready yet.
999         /// Therefore, it transmits data in Vector4 class.
1000         /// This type should later be changed to the appropriate data type.
1001         /// </remarks>
1002         /// <remarks>
1003         /// This is a hidden API(inhouse API) only for internal purpose.
1004         /// </remarks>
1005         [EditorBrowsable(EditorBrowsableState.Never)]
1006         public Vector4 CalculateScreenPositionSize()
1007         {
1008             Vector4 ret = new Vector4(Interop.Actor.CalculateScreenExtents(SwigCPtr), true);
1009             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
1010             return ret;
1011         }
1012     }
1013 }