cb65a04fa33cd4df696663d06f4c891d6cc0dbf8
[platform/core/csapi/tizenfx.git] / src / ElmSharp / ElmSharp / EvasObject.cs
1 /*
2  * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
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 using System;
18 using System.Collections.Generic;
19 using System.Diagnostics;
20
21 namespace ElmSharp
22 {
23     /// <summary>
24     /// Enumeration for the Tooltip orientation.
25     /// </summary>
26     /// <since_tizen> preview </since_tizen>
27     public enum TooltipOrientation
28     {
29         /// <summary>
30         /// Default value. Tooltip moves with a mouse pointer.
31         /// </summary>
32         None,
33
34         /// <summary>
35         /// Tooltip should appear to the top left of the parent.
36         /// </summary>
37         TopLeft,
38
39         /// <summary>
40         /// Tooltip should appear to the left of the parent.
41         /// </summary>
42         Top,
43
44         /// <summary>
45         /// Tooltip should appear to the top right of the parent.
46         /// </summary>
47         TopRight,
48
49         /// <summary>
50         /// Tooltip should appear to the left of the parent.
51         /// </summary>
52         Left,
53
54         /// <summary>
55         /// Tooltip should appear to the center of the parent.
56         /// </summary>
57         Center,
58
59         /// <summary>
60         /// Tooltip should appear to the right of the parent.
61         /// </summary>
62         Right,
63
64         /// <summary>
65         /// Tooltip should appear to the bottom left of the parent.
66         /// </summary>
67         BottomLeft,
68
69         /// <summary>
70         /// Tooltip should appear to the bottom of the parent.
71         /// </summary>
72         Bottom,
73
74         /// <summary>
75         /// Tooltip should appear to the bottom right of the parent.
76         /// </summary>
77         BottomRight,
78     }
79
80     /// <summary>
81     /// Enumeration for the aspect control.
82     /// </summary>
83     /// <since_tizen> preview </since_tizen>
84     public enum AspectControl
85     {
86         /// <summary>
87         /// Preference on the scaling unset.
88         /// </summary>
89         None = 0,
90
91         /// <summary>
92         /// Same effect as the unset preference on the scaling.
93         /// </summary>
94         Neither = 1,
95
96         /// <summary>
97         /// Use all horizontal container space to place an object using the given aspect.
98         /// </summary>
99         Horizontal = 2,
100
101         /// <summary>
102         /// Use all vertical container space to place an object using the given aspect.
103         /// </summary>
104         Vertical = 3,
105
106         /// <summary>
107         /// Use all horizontal @b and vertical container spaces to place an object (never growing it out of those bounds), using the given aspect.
108         /// </summary>
109         Both = 4
110     }
111
112     /// <summary>
113     /// How the object should be rendered to output.
114     /// </summary>
115     /// <since_tizen> 5 </since_tizen>
116     public enum RenderOp
117     {
118         /// <summary>
119         /// default op: d = d * (1 - sa) + s
120         /// </summary>
121         Blend = 0,
122
123         /// <summary>
124         /// d = d*(1 - sa) + s*da
125         /// </summary>
126         BlendRel = 1,
127
128         /// <summary>
129         /// d = s
130         /// </summary>
131         Copy = 2,
132
133         /// <summary>
134         /// d = s*da
135         /// </summary>
136         CopyRel = 3,
137
138         /// <summary>
139         /// d = d + s
140         /// </summary>
141         Add = 4,
142
143         /// <summary>
144         /// d = d + s*da
145         /// </summary>
146         AddRel = 5,
147
148         /// <summary>
149         /// d = d - s
150         /// </summary>
151         Sub = 6,
152
153         /// <summary>
154         /// d = d - s*da
155         /// </summary>
156         SubRel = 7,
157
158         /// <summary>
159         /// d = d*s + d*(1 - sa) + s*(1 - da)
160         /// </summary>
161         Tint = 8,
162
163         /// <summary>
164         /// d = d*(1 - sa + s)
165         /// </summary>
166         TintRel = 9,
167
168         /// <summary>
169         /// d = d*sa
170         /// </summary>
171         Mask = 10,
172
173         /// <summary>
174         /// d = d*s
175         /// </summary>
176         Mul = 11
177     }
178
179     /// <summary>
180     /// The EvasObject is a base class for other widget classes.
181     /// </summary>
182     /// <since_tizen> preview </since_tizen>
183     public abstract class EvasObject
184     {
185         private IntPtr _realHandle = IntPtr.Zero;
186         private EvasCanvas _evasCanvas;
187         private string _automationId;
188
189         private event EventHandler _backButtonPressed;
190
191         private event EventHandler _moreButtonPressed;
192
193         private Interop.Eext.EextEventCallback _backButtonHandler;
194         private Interop.Eext.EextEventCallback _moreButtonHandler;
195
196         private static Dictionary<IntPtr, EvasObject> s_handleTable = new Dictionary<IntPtr, EvasObject>();
197
198         /// <summary>
199         /// Sets or gets the handle for EvasObject.
200         /// </summary>
201         /// <since_tizen> preview </since_tizen>
202         public IntPtr Handle { get; protected set; }
203
204         /// <summary>
205         /// Gets the parent object for EvasObject.
206         /// </summary>
207         /// <since_tizen> preview </since_tizen>
208         public EvasObject Parent { get; private set; }
209
210         /// <summary>
211         /// Sets or gets the real handle for EvasObject.
212         /// </summary>
213         /// <since_tizen> preview </since_tizen>
214         public IntPtr RealHandle
215         {
216             get
217             {
218                 return _realHandle == IntPtr.Zero ? Handle : _realHandle;
219             }
220             protected set
221             {
222                 _realHandle = value;
223                 Interop.Evas.evas_object_show(_realHandle);
224             }
225         }
226
227         EvasObjectEvent _deleted;
228         EvasObjectEvent<EvasKeyEventArgs> _keyup;
229         EvasObjectEvent<EvasKeyEventArgs> _keydown;
230         EvasObjectEvent _moved;
231         EvasObjectEvent _resized;
232         EvasObjectEvent _shown;
233         EvasObjectEvent _hidden;
234         EventHandler _renderPost;
235         Interop.Evas.EvasCallback _renderPostCallback = null;
236         Interop.Elementary.Elm_Tooltip_Content_Cb _tooltipContentCallback = null;
237
238         GetTooltipContentDelegate _tooltipContentDelegate = null;
239
240         readonly HashSet<IInvalidatable> _eventStore = new HashSet<IInvalidatable>();
241
242         /// <summary>
243         /// Creates and initializes a new instance of the EvasObject class with the parent EvasObject class parameter.
244         /// </summary>
245         /// <param name="parent">Parent EvasObject class.</param>
246         /// <since_tizen> preview </since_tizen>
247         protected EvasObject(EvasObject parent) : this()
248         {
249             Debug.Assert(parent == null || parent.IsRealized);
250             Realize(parent);
251         }
252
253         /// <summary>
254         /// Creates and initializes a new instance of the EvasObject class.
255         /// </summary>
256         /// <since_tizen> preview </since_tizen>
257         protected EvasObject()
258         {
259             _backButtonHandler = new Interop.Eext.EextEventCallback((d, o, i) => { _backButtonPressed?.Invoke(this, EventArgs.Empty); });
260             _moreButtonHandler = new Interop.Eext.EextEventCallback((d, o, i) => { _moreButtonPressed?.Invoke(this, EventArgs.Empty); });
261
262             OnInstantiated();
263
264             _tooltipContentCallback = (d, o, t) =>
265             {
266                 return _tooltipContentDelegate?.Invoke();
267             };
268         }
269
270         // C# Finalizer was called on GC thread
271         // So, We can't access to EFL object
272         // And When Finalizer was called, Field can be already released.
273         //~EvasObject()
274         //{
275         //    Unrealize();
276         //}
277
278         /// <summary>
279         /// Deleted will be triggered when the widght is deleted.
280         /// </summary>
281         /// <since_tizen> preview </since_tizen>
282         public event EventHandler Deleted;
283
284         /// <summary>
285         /// KeyUp will be triggered when the key is loose.
286         /// </summary>
287         /// <since_tizen> preview </since_tizen>
288         public event EventHandler<EvasKeyEventArgs> KeyUp
289         {
290             add { _keyup.On += value; }
291             remove { _keyup.On -= value; }
292         }
293
294         /// <summary>
295         /// KeyDown will be triggered when the key is pressed down.
296         /// </summary>
297         /// <since_tizen> preview </since_tizen>
298         public event EventHandler<EvasKeyEventArgs> KeyDown
299         {
300             add { _keydown.On += value; }
301             remove { _keydown.On -= value; }
302         }
303
304         /// <summary>
305         /// BackButtonPressed will be triggered when the Back button is pressed.
306         /// </summary>
307         /// <since_tizen> preview </since_tizen>
308         public event EventHandler BackButtonPressed
309         {
310             add
311             {
312                 if (_backButtonPressed == null)
313                 {
314                     Interop.Eext.eext_object_event_callback_add(RealHandle, Interop.Eext.EextCallbackType.EEXT_CALLBACK_BACK, _backButtonHandler, IntPtr.Zero);
315                 }
316                 _backButtonPressed += value;
317             }
318             remove
319             {
320                 _backButtonPressed -= value;
321                 if (_backButtonPressed == null)
322                 {
323                     Interop.Eext.eext_object_event_callback_del(RealHandle, Interop.Eext.EextCallbackType.EEXT_CALLBACK_BACK, _backButtonHandler);
324                 }
325             }
326         }
327
328         /// <summary>
329         /// MoreButtonPressed will be triggered when the More button is pressed.
330         /// </summary>
331         /// <since_tizen> preview </since_tizen>
332         public event EventHandler MoreButtonPressed
333         {
334             add
335             {
336                 if (_moreButtonPressed == null)
337                 {
338                     Interop.Eext.eext_object_event_callback_add(RealHandle, Interop.Eext.EextCallbackType.EEXT_CALLBACK_MORE, _moreButtonHandler, IntPtr.Zero);
339                 }
340                 _moreButtonPressed += value;
341             }
342             remove
343             {
344                 _moreButtonPressed -= value;
345                 if (_moreButtonPressed == null)
346                 {
347                     Interop.Eext.eext_object_event_callback_del(RealHandle, Interop.Eext.EextCallbackType.EEXT_CALLBACK_MORE, _moreButtonHandler);
348                 }
349             }
350         }
351
352         /// <summary>
353         /// Moved will be triggered when the widght is moved.
354         /// </summary>
355         /// <since_tizen> preview </since_tizen>
356         public event EventHandler Moved
357         {
358             add { _moved.On += value; }
359             remove { _moved.On -= value; }
360         }
361
362         /// <summary>
363         /// Resized Event Handler of the current widget's size.
364         /// </summary>
365         /// <since_tizen> preview </since_tizen>
366         public event EventHandler Resized
367         {
368             add { _resized.On += value; }
369             remove { _resized.On -= value; }
370         }
371
372         /// <summary>
373         /// Shown will be triggered when the widget is shown.
374         /// </summary>
375         /// <since_tizen> preview </since_tizen>
376         public event EventHandler Shown
377         {
378             add { _shown.On += value; }
379             remove { _shown.On -= value; }
380         }
381         
382         /// <summary>
383         /// Hidden will be triggered when the widget is hidden.
384         /// </summary>
385         /// <since_tizen> preview </since_tizen>
386         public event EventHandler Hidden
387         {
388             add { _hidden.On += value; }
389             remove { _hidden.On -= value; }
390         }
391
392         /// <summary>
393         /// RenderPost Event Handler of the current widget.
394         /// </summary>
395         /// <since_tizen> preview </since_tizen>
396         public event EventHandler RenderPost
397         {
398             add
399             {
400                 _renderPost += value;
401                 if (_renderPostCallback == null)
402                 {
403                     _renderPostCallback = new Interop.Evas.EvasCallback((o, e, d) => _renderPost?.Invoke(this, EventArgs.Empty));
404                     Interop.Evas.evas_event_callback_add(Interop.Evas.evas_object_evas_get(RealHandle), Interop.Evas.ObjectCallbackType.RenderPost, _renderPostCallback, IntPtr.Zero);
405                 }
406             }
407             remove
408             {
409                 _renderPost -= value;
410                 if (_renderPost == null)
411                 {
412                     Interop.Evas.evas_event_callback_del(Interop.Evas.evas_object_evas_get(RealHandle), Interop.Evas.ObjectCallbackType.RenderPost, _renderPostCallback);
413                     _renderPostCallback = null;
414                 }
415             }
416         }
417
418         /// <summary>
419         /// Called when a widget's tooltip is activated and needs content.
420         /// </summary>
421         /// <returns></returns>
422         /// <since_tizen> preview </since_tizen>
423         public delegate EvasObject GetTooltipContentDelegate();
424
425         /// <summary>
426         /// Gets a widget's status of realized or not.
427         /// </summary>
428         /// <since_tizen> preview </since_tizen>
429         public bool IsRealized { get { return Handle != IntPtr.Zero; } }
430
431         /// <summary>
432         /// Gets EvasCanvas.
433         /// </summary>
434         /// <since_tizen> preview </since_tizen>
435         public EvasCanvas EvasCanvas
436         {
437             get
438             {
439                 if (_evasCanvas == null)
440                     _evasCanvas = new EvasCanvas(Handle);
441                 return _evasCanvas;
442             }
443         }
444
445         /// <summary>
446         /// Sets of gets a value that allow the automation framework to find and interact with this object.
447         /// </summary>
448         /// <since_tizen> preview </since_tizen>
449         public string AutomationId
450         {
451             get
452             {
453                 return _automationId;
454             }
455             set
456             {
457                 if (_automationId != null)
458                     throw new InvalidOperationException("AutomationId may only be set one time.");
459                 _automationId = value;
460             }
461         }
462
463         /// <summary>
464         /// Gets the current class's Name.
465         /// </summary>
466         /// <since_tizen> preview </since_tizen>
467         public string ClassName
468         {
469             get
470             {
471                 return Interop.Eo.efl_class_name_get(Interop.Eo.efl_class_get(RealHandle));
472             }
473         }
474
475         /// <summary>
476         /// Sets or gets the horizontal pointer hints for an object's weight.
477         /// </summary>
478         /// <since_tizen> preview </since_tizen>
479         public double WeightX
480         {
481             get
482             {
483                 return Interop.Evas.GetWeightX(Handle);
484             }
485             set
486             {
487                 Interop.Evas.SetWeightX(Handle, value);
488             }
489         }
490
491         /// <summary>
492         /// Sets or gets the vertical pointer hints for an object's weight.
493         /// </summary>
494         /// <since_tizen> preview </since_tizen>
495         public double WeightY
496         {
497             get
498             {
499                 return Interop.Evas.GetWeightY(Handle);
500             }
501             set
502             {
503                 Interop.Evas.SetWeightY(Handle, value);
504             }
505         }
506
507         /// <summary>
508         /// Sets or gets the horizontal alignment hint of an object's alignment.
509         /// </summary>
510         /// <since_tizen> preview </since_tizen>
511         public virtual double AlignmentX
512         {
513             get
514             {
515                 return Interop.Evas.GetAlignX(Handle);
516             }
517             set
518             {
519                 Interop.Evas.SetAlignX(Handle, value);
520             }
521         }
522
523         /// <summary>
524         /// Sets or gets the vertical alignment hint of an object's alignment.
525         /// </summary>
526         /// <since_tizen> preview </since_tizen>
527         public virtual double AlignmentY
528         {
529             get
530             {
531                 return Interop.Evas.GetAlignY(Handle);
532             }
533             set
534             {
535                 Interop.Evas.SetAlignY(Handle, value);
536             }
537         }
538
539         /// <summary>
540         /// Sets or gets the width hints for an object's minimum size.
541         /// </summary>
542         /// <since_tizen> preview </since_tizen>
543         public int MinimumWidth
544         {
545             get
546             {
547                 int w, h;
548                 Interop.Evas.evas_object_size_hint_min_get(RealHandle, out w, out h);
549                 return w;
550             }
551             set
552             {
553                 int h = MinimumHeight;
554                 Interop.Evas.evas_object_size_hint_min_set(RealHandle, value, h);
555             }
556         }
557
558         /// <summary>
559         /// Sets or gets the height hints for an object's minimum size.
560         /// </summary>
561         /// <since_tizen> preview </since_tizen>
562         public int MinimumHeight
563         {
564             get
565             {
566                 int w, h;
567                 Interop.Evas.evas_object_size_hint_min_get(RealHandle, out w, out h);
568                 return h;
569             }
570             set
571             {
572                 int w = MinimumWidth;
573                 Interop.Evas.evas_object_size_hint_min_set(RealHandle, w, value);
574             }
575         }
576
577         /// <summary>
578         /// Gets the visible state of the given Evas object.
579         /// </summary>
580         /// <since_tizen> preview </since_tizen>
581         public bool IsVisible
582         {
583             get
584             {
585                 return Interop.Evas.evas_object_visible_get(Handle);
586             }
587         }
588
589         /// <summary>
590         /// Sets or gets the position and (rectangular) size of the given Evas object.
591         /// </summary>
592         /// <since_tizen> preview </since_tizen>
593         public Rect Geometry
594         {
595             get
596             {
597                 int x, y, w, h;
598                 Interop.Evas.evas_object_geometry_get(Handle, out x, out y, out w, out h);
599                 Rect rect = new Rect(x, y, w, h);
600                 return rect;
601             }
602             set
603             {
604                 Interop.Evas.evas_object_geometry_set(Handle, value.X, value.Y, value.Width, value.Height);
605             }
606         }
607
608         /// <summary>
609         /// Sets or gets the general or main color of the given Evas object.
610         /// </summary>
611         /// <since_tizen> preview </since_tizen>
612         public virtual Color Color
613         {
614             get
615             {
616                 int r, g, b, a;
617                 Interop.Evas.evas_object_color_get(RealHandle, out r, out g, out b, out a);
618                 return Color.FromRgba(r, g, b, a);
619             }
620             set
621             {
622                 Interop.Evas.SetPremultipliedColor(RealHandle, value.R, value.G, value.B, value.A);
623             }
624         }
625
626         /// <summary>
627         /// Sets or gets the map enabled state.
628         /// </summary>
629         /// <since_tizen> preview </since_tizen>
630         public bool IsMapEnabled
631         {
632             get
633             {
634                 return Interop.Evas.evas_object_map_enable_get(Handle);
635             }
636             set
637             {
638                 Interop.Evas.evas_object_map_enable_set(Handle, value);
639             }
640         }
641
642         /// <summary>
643         /// Sets or gets the current object's transformation map.
644         /// </summary>
645         /// <since_tizen> preview </since_tizen>
646         public EvasMap EvasMap
647         {
648             get
649             {
650                 IntPtr evasMap = Interop.Evas.evas_object_map_get(Handle);
651                 return new EvasMap(evasMap);
652             }
653             set
654             {
655                 Interop.Evas.evas_object_map_set(Handle, value.Handle);
656             }
657         }
658
659         /// <summary>
660         /// Sets or gets whether an object is to repeat events.
661         /// </summary>
662         /// <since_tizen> preview </since_tizen>
663         public bool RepeatEvents
664         {
665             get
666             {
667                 var result = Interop.Evas.evas_object_repeat_events_get(Handle);
668                 Debug.Assert(Handle == RealHandle || result == Interop.Evas.evas_object_repeat_events_get(RealHandle));
669                 return result;
670             }
671             set
672             {
673                 if (Handle != RealHandle)
674                 {
675                     Interop.Evas.evas_object_repeat_events_set(RealHandle, value);
676                 }
677                 Interop.Evas.evas_object_repeat_events_set(Handle, value);
678             }
679         }
680
681         /// <summary>
682         /// Sets or gets whether events on a smart object's member should get propagated up to its parent.
683         /// </summary>
684         /// <since_tizen> preview </since_tizen>
685         public bool PropagateEvents
686         {
687             get
688             {
689                 var result = Interop.Evas.evas_object_propagate_events_get(Handle);
690                 Debug.Assert(Handle == RealHandle || result == Interop.Evas.evas_object_propagate_events_get(RealHandle));
691                 return result;
692             }
693             set
694             {
695                 if (Handle != RealHandle)
696                 {
697                     Interop.Evas.evas_object_propagate_events_set(RealHandle, value);
698                 }
699                 Interop.Evas.evas_object_propagate_events_set(Handle, value);
700             }
701         }
702
703         /// <summary>
704         /// Sets or gets whether an object is set to pass (ignore) events.
705         /// </summary>
706         /// <since_tizen> preview </since_tizen>
707         public bool PassEvents
708         {
709             get
710             {
711                 var result = Interop.Evas.evas_object_pass_events_get(Handle);
712                 Debug.Assert(Handle == RealHandle || result == Interop.Evas.evas_object_pass_events_get(RealHandle));
713                 return result;
714             }
715             set
716             {
717                 if (Handle != RealHandle)
718                 {
719                     Interop.Evas.evas_object_pass_events_set(RealHandle, value);
720                 }
721                 Interop.Evas.evas_object_pass_events_set(Handle, value);
722             }
723         }
724
725         /// <summary>
726         /// Sets or gets the style for this object tooltip.
727         /// </summary>
728         /// <since_tizen> preview </since_tizen>
729         public string TooltipStyle
730         {
731             get
732             {
733                 return Interop.Elementary.elm_object_tooltip_style_get(RealHandle);
734             }
735             set
736             {
737                 Interop.Elementary.elm_object_tooltip_style_set(RealHandle, value);
738             }
739         }
740
741         /// <summary>
742         /// Sets or gets the orientation of tooltip.
743         /// </summary>
744         /// <since_tizen> preview </since_tizen>
745         public TooltipOrientation TooltipOrientation
746         {
747             get
748             {
749                 return (TooltipOrientation)Interop.Elementary.elm_object_tooltip_orient_get(RealHandle);
750             }
751             set
752             {
753                 Interop.Elementary.elm_object_tooltip_orient_set(RealHandle, (int)value);
754             }
755         }
756
757         /// <summary>
758         /// Sets or gets size restriction state of an object's tooltip.
759         /// </summary>
760         /// <since_tizen> preview </since_tizen>
761         public bool TooltipWindowMode
762         {
763             get
764             {
765                 return Interop.Elementary.elm_object_tooltip_window_mode_get(RealHandle);
766             }
767             set
768             {
769                 Interop.Elementary.elm_object_tooltip_window_mode_set(RealHandle, value);
770             }
771         }
772
773         /// <summary>
774         /// Sets the content to be shown in the tooltip object.
775         /// </summary>
776         /// <since_tizen> preview </since_tizen>
777         public GetTooltipContentDelegate TooltipContentDelegate
778         {
779             get
780             {
781                 return _tooltipContentDelegate;
782             }
783             set
784             {
785                 _tooltipContentDelegate = value;
786                 if (value != null)
787                 {
788                     Interop.Elementary.elm_object_tooltip_content_cb_set(RealHandle, _tooltipContentCallback, IntPtr.Zero, null);
789                 }
790                 else
791                 {
792                     Interop.Elementary.elm_object_tooltip_content_cb_set(RealHandle, null, IntPtr.Zero, null);
793                 }
794             }
795         }
796
797         /// <summary>
798         /// Gets the movement freeze by 1.
799         /// This gets the movement freeze count by one.
800         /// </summary>
801         /// <since_tizen> preview </since_tizen>
802         public int TooltipMoveFreezeCount
803         {
804             get
805             {
806                 return Interop.Elementary.elm_object_tooltip_move_freeze_get(RealHandle);
807             }
808         }
809
810         /// <summary>
811         /// Sets or gets whether an Evas object is to freeze (discard) events.
812         /// </summary>
813         /// <since_tizen> preview </since_tizen>
814         public bool AllEventsFrozen
815         {
816             get
817             {
818                 var result = Interop.Evas.evas_object_freeze_events_get(Handle);
819                 Debug.Assert(Handle == RealHandle || result == Interop.Evas.evas_object_freeze_events_get(RealHandle));
820                 return result;
821             }
822             set
823             {
824                 if (Handle != RealHandle)
825                 {
826                     Interop.Evas.evas_object_freeze_events_set(RealHandle, value);
827                 }
828                 Interop.Evas.evas_object_freeze_events_set(Handle, value);
829             }
830         }
831
832         /// <summary>
833         /// Sets or gets the layer of its canvas that the given object will be part of.
834         /// </summary>
835         /// <since_tizen> preview </since_tizen>
836         public virtual int Layer
837         {
838             get
839             {
840                 return Interop.Evas.evas_object_layer_get(Handle);
841             }
842             set
843             {
844                 Interop.Evas.evas_object_layer_set(Handle, value);
845             }
846         }
847
848         /// <summary>
849         /// Sets or gets the render operation to be used for rendering the Evas object.
850         /// </summary>
851         /// <since_tizen> 5 </since_tizen>
852         public RenderOp RenderOperation
853         {
854             get
855             {
856                 return (RenderOp)Interop.Evas.evas_object_render_op_get(RealHandle);
857             }
858             set
859             {
860                 Interop.Evas.evas_object_render_op_set(RealHandle, (Interop.Evas.RenderOp)value);
861             }
862         }
863
864
865         /// <summary>
866         /// Clips one object to another.
867         /// </summary>
868         /// <param name="clip">The object to clip object by.</param>
869         /// <since_tizen> preview </since_tizen>
870         public void SetClip(EvasObject clip)
871         {
872             Interop.Evas.evas_object_clip_set(Handle, clip);
873         }
874
875         /// <summary>
876         /// Sets the hints for an object's alignment.
877         /// </summary>
878         /// <param name="x">The horizontal alignment hint as double value ranging from 0.0 to 1.0. The default alignment hint value is 0.5.</param>
879         /// <param name="y">The vertical alignment hint as double value ranging from 0.0 to 1.0. The default alignment hint value is 0.5.</param>
880         /// <since_tizen> preview </since_tizen>
881         public void SetAlignment(double x, double y)
882         {
883             Interop.Evas.evas_object_size_hint_align_set(Handle, x, y);
884         }
885
886         /// <summary>
887         /// Sets the hints for an object's weight.
888         /// </summary>
889         /// <param name="x">The non-negative double value to be used as horizontal weight hint.</param>
890         /// <param name="y">The non-negative double value to be used as vertical weight hint.</param>
891         /// <since_tizen> preview </since_tizen>
892         public void SetWeight(double x, double y)
893         {
894             Interop.Evas.evas_object_size_hint_weight_set(Handle, x, y);
895         }
896
897         /// <summary>
898         /// Sets the text for an object's tooltip.
899         /// </summary>
900         /// <param name="text">The text value to display inside the tooltip.</param>
901         /// <since_tizen> preview </since_tizen>
902         public void SetTooltipText(string text)
903         {
904             Interop.Elementary.elm_object_tooltip_text_set(RealHandle, text);
905         }
906
907         /// <summary>
908         /// Unsets an object's tooltip.
909         /// </summary>
910         /// <since_tizen> preview </since_tizen>
911         public void UnsetTooltip()
912         {
913             Interop.Elementary.elm_object_tooltip_unset(RealHandle);
914         }
915
916         /// <summary>
917         /// This increments the tooltip movement freeze count by one.
918         /// If the count is more than 0, the tooltip position will be fixed.
919         /// </summary>
920         /// <since_tizen> preview </since_tizen>
921         public void PushTooltipMoveFreeze()
922         {
923             Interop.Elementary.elm_object_tooltip_move_freeze_push(RealHandle);
924         }
925
926         /// <summary>
927         /// This decrements the tooltip freeze count by one.
928         /// </summary>
929         /// <since_tizen> preview </since_tizen>
930         public void PopTooltipMoveFreeze()
931         {
932             Interop.Elementary.elm_object_tooltip_move_freeze_pop(RealHandle);
933         }
934
935         /// <summary>
936         /// Force hide the tooltip of the object.
937         /// </summary>
938         /// <since_tizen> preview </since_tizen>
939         public void HideTooltip()
940         {
941             Interop.Elementary.elm_object_tooltip_hide(RealHandle);
942         }
943
944         /// <summary>
945         /// Force show the tooltip of the object.
946         /// </summary>
947         /// <since_tizen> preview </since_tizen>
948         public void ShowTooltip()
949         {
950             Interop.Elementary.elm_object_tooltip_show(RealHandle);
951         }
952
953         /// <summary>
954         /// Makes the current object visible.
955         /// </summary>
956         /// <since_tizen> preview </since_tizen>
957         public void Show()
958         {
959             Interop.Evas.evas_object_show(Handle);
960         }
961
962         /// <summary>
963         /// Makes the current object invisible.
964         /// </summary>
965         /// <since_tizen> preview </since_tizen>
966         public void Hide()
967         {
968             Interop.Evas.evas_object_hide(Handle);
969         }
970
971         /// <summary>
972         /// Changes the size of the current object.
973         /// </summary>
974         /// <param name="w">The new width.</param>
975         /// <param name="h">The new height.</param>
976         /// <since_tizen> preview </since_tizen>
977         public void Resize(int w, int h)
978         {
979             Interop.Evas.evas_object_resize(Handle, w, h);
980         }
981
982         /// <summary>
983         /// Moves the current object to the given location.
984         /// </summary>
985         /// <param name="x">The X position to move the object.</param>
986         /// <param name="y">The Y position to move the object.</param>
987         /// <since_tizen> preview </since_tizen>
988         public void Move(int x, int y)
989         {
990             Interop.Evas.evas_object_move(Handle, x, y);
991         }
992
993         /// <summary>
994         /// Lowers the object to the bottom of its layer.
995         /// </summary>
996         /// <since_tizen> preview </since_tizen>
997         public void Lower()
998         {
999             Interop.Evas.evas_object_lower(Handle);
1000         }
1001
1002         /// <summary>
1003         /// Define the IntPtr operator.
1004         /// </summary>
1005         /// <param name="obj">Parent object.</param>
1006         /// <since_tizen> preview </since_tizen>
1007         public static implicit operator IntPtr(EvasObject obj)
1008         {
1009             if (obj == null)
1010                 return IntPtr.Zero;
1011             return obj.Handle;
1012         }
1013
1014         /// <summary>
1015         /// Define cast to EvasObject operator from IntPtr
1016         /// </summary>
1017         /// <param name="handle">Native handle to EvasObject</param>
1018         /// <since_tizen> preview </since_tizen>
1019         public static explicit operator EvasObject(IntPtr handle) => EvasObject.s_handleTable.TryGetValue(handle, out EvasObject obj) ? obj : null;
1020
1021         /// <summary>
1022         /// Requests the keyname key events to be directed to the current object.
1023         /// </summary>
1024         /// <param name="keyname">The key to request events for.</param>
1025         /// <param name="exclusive">Set TRUE to request that the obj is the only object receiving the keyname events, otherwise set to FALSE.</param>
1026         /// <returns>If the call succeeds then true, otherwise false.</returns>
1027         /// <since_tizen> preview </since_tizen>
1028         public bool KeyGrab(string keyname, bool exclusive)
1029         {
1030             return Interop.Evas.evas_object_key_grab(Handle, keyname, 0, 0, exclusive);
1031         }
1032
1033         /// <summary>
1034         /// Removes the grab on the keyname key events.
1035         /// </summary>
1036         /// <param name="keyname">The key the grab is set for.</param>
1037         /// <since_tizen> preview </since_tizen>
1038         public void KeyUngrab(string keyname)
1039         {
1040             Interop.Evas.evas_object_key_ungrab(Handle, keyname, 0, 0);
1041         }
1042
1043         /// <summary>
1044         /// Marks the smart object as changed.
1045         /// </summary>
1046         /// <since_tizen> preview </since_tizen>
1047         public void MarkChanged()
1048         {
1049             Interop.Evas.evas_object_smart_changed(RealHandle);
1050         }
1051
1052         /// <summary>
1053         /// Calls the calculate smart function immediately.
1054         /// This will force immediate calculations needed for renderization of this object.
1055         /// </summary>
1056         /// <since_tizen> preview </since_tizen>
1057         public void Calculate()
1058         {
1059             Interop.Evas.evas_object_smart_calculate(RealHandle);
1060         }
1061
1062         /// <summary>
1063         /// Sets the hints for an object's aspect ratio.
1064         /// </summary>
1065         /// <param name="aspect">The policy or type of aspect ratio to apply to an object.</param>
1066         /// <param name="w">The integer to be used as aspect width ratio term.</param>
1067         /// <param name="h">The integer to be used as aspect height ratio term.</param>
1068         /// <since_tizen> preview </since_tizen>
1069         public void SetSizeHintAspect(AspectControl aspect, int w, int h)
1070         {
1071             Interop.Evas.evas_object_size_hint_aspect_set(Handle, (int)aspect, w, h);
1072         }
1073
1074         /// <summary>
1075         /// Gets the hints for an object's aspect ratio.
1076         /// </summary>
1077         /// <param name="aspect">The policy or type of aspect ratio to apply to an object.</param>
1078         /// <param name="w">The integer to be used as aspect width ratio term.</param>
1079         /// <param name="h">The integer to be used as aspect height ratio term.</param>
1080         /// <since_tizen> preview </since_tizen>
1081         public void GetSizeHintAspect(out AspectControl aspect, out int w, out int h)
1082         {
1083             int aspectRatio;
1084             Interop.Evas.evas_object_size_hint_aspect_get(Handle, out aspectRatio, out w, out h);
1085             aspect = (AspectControl)aspectRatio;
1086         }
1087
1088         /// <summary>
1089         /// Stacks immediately below anchor.
1090         /// </summary>
1091         /// <param name="anchor">The object below which to stack.</param>
1092         /// <since_tizen> preview </since_tizen>
1093         public void StackBelow(EvasObject anchor)
1094         {
1095             Interop.Evas.evas_object_stack_below(Handle, anchor);
1096         }
1097
1098         /// <summary>
1099         /// Stacks immediately above anchor.
1100         /// </summary>
1101         /// <param name="anchor">The object above which to stack.</param>
1102         /// <since_tizen> preview </since_tizen>
1103         public void StackAbove(EvasObject anchor)
1104         {
1105             Interop.Evas.evas_object_stack_above(Handle, anchor);
1106         }
1107
1108         /// <summary>
1109         /// Raises to the top of its layer.
1110         /// </summary>
1111         /// <since_tizen> preview </since_tizen>
1112         public void RaiseTop()
1113         {
1114             Interop.Evas.evas_object_raise(Handle);
1115         }
1116
1117         /// <summary>
1118         /// Gets the geometry of a line number.
1119         /// </summary>
1120         /// <param name="lineNumber">The line number.</param>
1121         /// <param name="x">x coordinate of the line.</param>
1122         /// <param name="y">y coordinate of the line.</param>
1123         /// <param name="w">w coordinate of the line.</param>
1124         /// <param name="h">h coordinate of the line.</param>
1125         /// <returns>True on success, or False on error.</returns>
1126         /// <since_tizen> preview </since_tizen>
1127         [Obsolete("GetTextBlockGeometryByLineNumber is obsolete as of version 5.0.0.14299 and is no longer supported.")]
1128         public bool GetTextBlockGeometryByLineNumber(int lineNumber, out int x, out int y, out int w, out int h)
1129         {
1130             x = -1; y = -1; w = -1; h = -1;
1131
1132             IntPtr _edjeHandle = Interop.Elementary.elm_layout_edje_get(RealHandle);
1133             if (_edjeHandle == IntPtr.Zero)
1134             {
1135                 return false;
1136             }
1137
1138             IntPtr _textblock = Interop.Elementary.edje_object_part_object_get(_edjeHandle, "elm.text");
1139             if (_textblock == IntPtr.Zero)
1140             {
1141                 return false;
1142             }
1143
1144             return Interop.Evas.evas_object_textblock_line_number_geometry_get(_textblock, lineNumber, out x, out y, out w, out h);
1145         }
1146
1147         internal IntPtr GetData(string key)
1148         {
1149             return Interop.Evas.evas_object_data_get(RealHandle, key);
1150         }
1151
1152         internal void SetData(string key, IntPtr data)
1153         {
1154             Interop.Evas.evas_object_data_set(RealHandle, key, data);
1155         }
1156
1157         internal IntPtr DeleteData(string key)
1158         {
1159             return Interop.Evas.evas_object_data_del(RealHandle, key);
1160         }
1161
1162         /// <summary>
1163         /// The callback of the Invalidate Event.
1164         /// </summary>
1165         /// <since_tizen> preview </since_tizen>
1166         protected virtual void OnInvalidate()
1167         {
1168         }
1169
1170         /// <summary>
1171         /// The callback of the Instantiated Event.
1172         /// </summary>
1173         /// <since_tizen> preview </since_tizen>
1174         protected virtual void OnInstantiated()
1175         {
1176         }
1177
1178         /// <summary>
1179         /// The callback of the Realized Event.
1180         /// </summary>
1181         /// <since_tizen> preview </since_tizen>
1182         protected virtual void OnRealized()
1183         {
1184         }
1185
1186         /// <summary>
1187         /// The callback of the Unrealize Event.
1188         /// </summary>
1189         /// <since_tizen> preview </since_tizen>
1190         protected virtual void OnUnrealize()
1191         {
1192         }
1193
1194         /// <summary>
1195         /// Creates a widget handle.
1196         /// </summary>
1197         /// <param name="parent">Parent EvasObject.</param>
1198         /// <returns>Handle IntPtr.</returns>
1199         /// <since_tizen> preview </since_tizen>
1200         protected abstract IntPtr CreateHandle(EvasObject parent);
1201
1202         /// <summary>
1203         /// For this object bind Parent object.Init handle and all kinds of EvasObjectEvent.
1204         /// </summary>
1205         /// <param name="parent">Parent object.</param>
1206         /// <since_tizen> preview </since_tizen>
1207         public void Realize(EvasObject parent)
1208         {
1209             if (!IsRealized)
1210             {
1211                 Parent = parent;
1212                 Handle = CreateHandle(parent);
1213                 Debug.Assert(Handle != IntPtr.Zero);
1214
1215                 s_handleTable[Handle] = this;
1216
1217                 (parent as Window)?.AddChild(this);
1218
1219                 OnRealized();
1220                 _deleted = new EvasObjectEvent(this, EvasObjectCallbackType.Del);
1221                 _keydown = new EvasObjectEvent<EvasKeyEventArgs>(this, RealHandle, EvasObjectCallbackType.KeyDown, EvasKeyEventArgs.Create);
1222                 _keyup = new EvasObjectEvent<EvasKeyEventArgs>(this, RealHandle, EvasObjectCallbackType.KeyUp, EvasKeyEventArgs.Create);
1223                 _moved = new EvasObjectEvent(this, EvasObjectCallbackType.Move);
1224                 _resized = new EvasObjectEvent(this, EvasObjectCallbackType.Resize);
1225                 _shown = new EvasObjectEvent(this, EvasObjectCallbackType.Show);
1226                 _hidden = new EvasObjectEvent(this, EvasObjectCallbackType.Hide);
1227
1228                 _deleted.On += (s, e) => MakeInvalidate();
1229
1230                 Elementary.SendEvasObjectRealized(this);
1231             }
1232         }
1233
1234         /// <summary>
1235         /// Removes the current object relationship with others.
1236         /// </summary>
1237         /// <since_tizen> preview </since_tizen>
1238         public void Unrealize()
1239         {
1240             if (IsRealized)
1241             {
1242                 if (_renderPostCallback != null)
1243                 {
1244                     Interop.Evas.evas_event_callback_del(Interop.Evas.evas_object_evas_get(Handle), Interop.Evas.ObjectCallbackType.RenderPost, _renderPostCallback);
1245                     _renderPostCallback = null;
1246                 }
1247
1248                 OnUnrealize();
1249                 IntPtr toBeDeleted = Handle;
1250                 Handle = IntPtr.Zero;
1251
1252                 DisposeEvent();
1253
1254                 (Parent as Window)?.RemoveChild(this);
1255
1256                 Interop.Evas.evas_object_del(toBeDeleted);
1257                 Deleted?.Invoke(this, EventArgs.Empty);
1258                 Parent = null;
1259                 s_handleTable.Remove(toBeDeleted);
1260             }
1261         }
1262
1263         private void MakeInvalidate()
1264         {
1265             Deleted?.Invoke(this, EventArgs.Empty);
1266             OnInvalidate();
1267             IntPtr toBeDeleted = Handle;
1268             Handle = IntPtr.Zero;
1269
1270             MakeInvalidateEvent();
1271
1272             (Parent as Window)?.RemoveChild(this);
1273             Parent = null;
1274             _deleted = null;
1275
1276             s_handleTable.Remove(toBeDeleted);
1277         }
1278
1279         private void DisposeEvent()
1280         {
1281             foreach (var evt in _eventStore)
1282             {
1283                 evt.Dispose();
1284             }
1285             _eventStore.Clear();
1286         }
1287
1288         private void MakeInvalidateEvent()
1289         {
1290             foreach (var evt in _eventStore)
1291             {
1292                 evt.MakeInvalidate();
1293             }
1294             _eventStore.Clear();
1295         }
1296
1297         internal void AddToEventLifeTracker(IInvalidatable item)
1298         {
1299             _eventStore.Add(item);
1300         }
1301     }
1302 }