Release 4.0.0-preview1-00051
[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     public enum TooltipOrientation
24     {
25         None,
26         TopLeft,
27         Top,
28         TopRight,
29         Left,
30         Center,
31         Right,
32         BottomLeft,
33         Bottom,
34         BottomRight,
35     }
36
37     public enum AspectControl
38     {
39         None = 0, /* Preference on scaling unset */
40         Neither = 1, /* Same effect as unset preference on scaling */
41         Horizontal = 2, /* Use all horizontal container space to place an object, using the given aspect */
42         Vertical = 3, /* Use all vertical container space to place an object, using the given aspect */
43         Both = 4 /* Use all horizontal @b and vertical container spaces to place an object (never growing it out of those bounds), using the given aspect */
44     }
45
46     /// <summary>
47     /// The EcasObject is a base class for other widget class
48     /// </summary>
49     public abstract class EvasObject
50     {
51         private IntPtr _realHandle = IntPtr.Zero;
52         private EvasCanvas _evasCanvas;
53
54         private event EventHandler _backButtonPressed;
55
56         private event EventHandler _moreButtonPressed;
57
58         private Interop.Eext.EextEventCallback _backButtonHandler;
59         private Interop.Eext.EextEventCallback _moreButtonHandler;
60
61         public IntPtr Handle { get; protected set; }
62         public EvasObject Parent { get; private set; }
63
64         public IntPtr RealHandle
65         {
66             get
67             {
68                 return _realHandle == IntPtr.Zero ? Handle : _realHandle;
69             }
70             protected set
71             {
72                 _realHandle = value;
73             }
74         }
75
76         EvasObjectEvent _deleted;
77         EvasObjectEvent<EvasKeyEventArgs> _keyup;
78         EvasObjectEvent<EvasKeyEventArgs> _keydown;
79         EvasObjectEvent _moved;
80         EvasObjectEvent _resized;
81         EventHandler _renderPost;
82         Interop.Evas.EvasCallback _renderPostCallback = null;
83         Interop.Elementary.Elm_Tooltip_Content_Cb _tooltipContentCallback = null;
84
85         GetTooltipContentDelegate _tooltipContentDelegate = null;
86
87         readonly HashSet<IInvalidatable> _eventStore = new HashSet<IInvalidatable>();
88
89         /// <summary>
90         /// Creates and initializes a new instance of the EvasObject class with parent EvasObject class parameter.
91         /// </summary>
92         /// <param name="parent">Parent EvasObject class </param>
93         protected EvasObject(EvasObject parent) : this()
94         {
95             Debug.Assert(parent == null || parent.IsRealized);
96             Realize(parent);
97         }
98
99         /// <summary>
100         /// Creates and initializes a new instance of the EvasObject class.
101         /// </summary>
102         protected EvasObject()
103         {
104             _backButtonHandler = new Interop.Eext.EextEventCallback((d, o, i) => { _backButtonPressed?.Invoke(this, EventArgs.Empty); });
105             _moreButtonHandler = new Interop.Eext.EextEventCallback((d, o, i) => { _moreButtonPressed?.Invoke(this, EventArgs.Empty); });
106
107             OnInstantiated();
108
109             _tooltipContentCallback = (d, o, t) =>
110             {
111                 return _tooltipContentDelegate?.Invoke();
112             };
113         }
114
115         // C# Finalizer was called on GC thread
116         // So, We can't access to EFL object
117         // And When Finalizer was called, Field can be already released.
118         //~EvasObject()
119         //{
120         //    Unrealize();
121         //}
122
123         /// <summary>
124         /// Deleted will be triggered when widght is deleted
125         /// </summary>
126         public event EventHandler Deleted;
127
128         /// <summary>
129         /// KeyUp will be triggered when key is loose
130         /// </summary>
131         public event EventHandler<EvasKeyEventArgs> KeyUp;
132
133         /// <summary>
134         /// KeyDown will be triggered when key is preesd down
135         /// </summary>
136         public event EventHandler<EvasKeyEventArgs> KeyDown;
137
138         /// <summary>
139         /// BackButtonPressed will be triggered when Back button is pressed
140         /// </summary>
141         public event EventHandler BackButtonPressed
142         {
143             add
144             {
145                 if (_backButtonPressed == null)
146                 {
147                     Interop.Eext.eext_object_event_callback_add(RealHandle, Interop.Eext.EextCallbackType.EEXT_CALLBACK_BACK, _backButtonHandler, IntPtr.Zero);
148                 }
149                 _backButtonPressed += value;
150             }
151             remove
152             {
153                 _backButtonPressed -= value;
154                 if (_backButtonPressed == null)
155                 {
156                     Interop.Eext.eext_object_event_callback_del(RealHandle, Interop.Eext.EextCallbackType.EEXT_CALLBACK_BACK, _backButtonHandler);
157                 }
158             }
159         }
160
161         /// <summary>
162         /// MoreButtonPressed will be triggered when More button is pressed
163         /// </summary>
164         public event EventHandler MoreButtonPressed
165         {
166             add
167             {
168                 if (_moreButtonPressed == null)
169                 {
170                     Interop.Eext.eext_object_event_callback_add(RealHandle, Interop.Eext.EextCallbackType.EEXT_CALLBACK_MORE, _moreButtonHandler, IntPtr.Zero);
171                 }
172                 _moreButtonPressed += value;
173             }
174             remove
175             {
176                 _moreButtonPressed -= value;
177                 if (_moreButtonPressed == null)
178                 {
179                     Interop.Eext.eext_object_event_callback_del(RealHandle, Interop.Eext.EextCallbackType.EEXT_CALLBACK_MORE, _moreButtonHandler);
180                 }
181             }
182         }
183
184         /// <summary>
185         /// Moved will be triggered when widght is moved
186         /// </summary>
187         public event EventHandler Moved
188         {
189             add { _moved.On += value; }
190             remove { _moved.On -= value; }
191         }
192
193         /// <summary>
194         /// Current widget's size Resized Event Handler
195         /// </summary>
196         public event EventHandler Resized
197         {
198             add { _resized.On += value; }
199             remove { _resized.On -= value; }
200         }
201
202         /// <summary>
203         /// Current widget RenderPost Event Handler
204         /// </summary>
205         public event EventHandler RenderPost
206         {
207             add
208             {
209                 _renderPost += value;
210                 if (_renderPostCallback == null)
211                 {
212                     _renderPostCallback = new Interop.Evas.EvasCallback((o, e, d) => _renderPost?.Invoke(this, EventArgs.Empty));
213                     Interop.Evas.evas_event_callback_add(Interop.Evas.evas_object_evas_get(RealHandle), Interop.Evas.ObjectCallbackType.RenderPost, _renderPostCallback, IntPtr.Zero);
214                 }
215             }
216             remove
217             {
218                 _renderPost -= value;
219                 if (_renderPost?.GetInvocationList().Length == 0)
220                 {
221                     Interop.Evas.evas_event_callback_del(Interop.Evas.evas_object_evas_get(RealHandle), Interop.Evas.ObjectCallbackType.RenderPost, _renderPostCallback);
222                     _renderPostCallback = null;
223                 }
224             }
225         }
226
227         /// <summary>
228         /// Called back when a widget's tooltip is activated and needs content.
229         /// </summary>
230         /// <returns></returns>
231         public delegate EvasObject GetTooltipContentDelegate();
232
233         /// <summary>
234         /// Get widget's status of Realized or not.
235         /// </summary>
236         public bool IsRealized { get { return Handle != IntPtr.Zero; } }
237
238         /// <summary>
239         /// Gets EvasCanvas
240         /// </summary>
241         public EvasCanvas EvasCanvas
242         {
243             get
244             {
245                 if (_evasCanvas == null)
246                     _evasCanvas = new EvasCanvas(Handle);
247                 return _evasCanvas;
248             }
249         }
250
251         /// <summary>
252         /// Gets the current class's Name.
253         /// </summary>
254         public string ClassName
255         {
256             get
257             {
258                 return Interop.Eo.eo_class_name_get(Interop.Eo.eo_class_get(RealHandle));
259             }
260         }
261
262         /// <summary>
263         /// Sets or gets the horizontal pointer hints for an object's weight.
264         /// </summary>
265         public double WeightX
266         {
267             get
268             {
269                 return Interop.Evas.GetWeightX(Handle);
270             }
271             set
272             {
273                 Interop.Evas.SetWeightX(Handle, value);
274             }
275         }
276
277         /// <summary>
278         /// Sets or gets the vertical pointer hints for an object's weight.
279         /// </summary>
280         public double WeightY
281         {
282             get
283             {
284                 return Interop.Evas.GetWeightY(Handle);
285             }
286             set
287             {
288                 Interop.Evas.SetWeightY(Handle, value);
289             }
290         }
291
292         /// <summary>
293         /// Sets or gets the horizontal alignment hint of an object's alignment.
294         /// </summary>
295         public virtual double AlignmentX
296         {
297             get
298             {
299                 return Interop.Evas.GetAlignX(Handle);
300             }
301             set
302             {
303                 Interop.Evas.SetAlignX(Handle, value);
304             }
305         }
306
307         /// <summary>
308         /// Sets or gets the vertical alignment hint of an object's alignment.
309         /// </summary>
310         public virtual double AlignmentY
311         {
312             get
313             {
314                 return Interop.Evas.GetAlignY(Handle);
315             }
316             set
317             {
318                 Interop.Evas.SetAlignY(Handle, value);
319             }
320         }
321
322         /// <summary>
323         /// Sets or gets the Width hints for an object's minimum size.
324         /// </summary>
325         public int MinimumWidth
326         {
327             get
328             {
329                 int w, h;
330                 Interop.Evas.evas_object_size_hint_min_get(RealHandle, out w, out h);
331                 return w;
332             }
333             set
334             {
335                 int h = MinimumHeight;
336                 Interop.Evas.evas_object_size_hint_min_set(RealHandle, value, h);
337             }
338         }
339
340         /// <summary>
341         /// Sets or gets the Height hints for an object's minimum size.
342         /// </summary>
343         public int MinimumHeight
344         {
345             get
346             {
347                 int w, h;
348                 Interop.Evas.evas_object_size_hint_min_get(RealHandle, out w, out h);
349                 return h;
350             }
351             set
352             {
353                 int w = MinimumWidth;
354                 Interop.Evas.evas_object_size_hint_min_set(RealHandle, w, value);
355             }
356         }
357
358         /// <summary>
359         /// Gets the visible state of the given Evas object.
360         /// </summary>
361         public bool IsVisible
362         {
363             get
364             {
365                 return Interop.Evas.evas_object_visible_get(Handle);
366             }
367         }
368
369         /// <summary>
370         /// Sets or gets the position and (rectangular) size of the given Evas object.
371         /// </summary>
372         public Rect Geometry
373         {
374             get
375             {
376                 int x, y, w, h;
377                 Interop.Evas.evas_object_geometry_get(Handle, out x, out y, out w, out h);
378                 Rect rect = new Rect(x, y, w, h);
379                 return rect;
380             }
381             set
382             {
383                 Interop.Evas.evas_object_geometry_set(Handle, value.X, value.Y, value.Width, value.Height);
384             }
385         }
386
387         /// <summary>
388         /// Sets or gets the general or main color of the given Evas object.
389         /// </summary>
390         public virtual Color Color
391         {
392             get
393             {
394                 int r, g, b, a;
395                 Interop.Evas.evas_object_color_get(RealHandle, out r, out g, out b, out a);
396                 return Color.FromRgba(r, g, b, a);
397             }
398             set
399             {
400                 Interop.Evas.SetPremultipliedColor(RealHandle, value.R, value.G, value.B, value.A);
401             }
402         }
403
404         /// <summary>
405         /// Sets or gets the map enabled state.
406         /// </summary>
407         public bool IsMapEnabled
408         {
409             get
410             {
411                 return Interop.Evas.evas_object_map_enable_get(Handle);
412             }
413             set
414             {
415                 Interop.Evas.evas_object_map_enable_set(Handle, value);
416             }
417         }
418
419         /// <summary>
420         /// Sets or gets current object transformation map.
421         /// </summary>
422         public EvasMap EvasMap
423         {
424             get
425             {
426                 IntPtr evasMap = Interop.Evas.evas_object_map_get(Handle);
427                 return new EvasMap(evasMap);
428             }
429             set
430             {
431                 Interop.Evas.evas_object_map_set(Handle, value.Handle);
432             }
433         }
434
435         /// <summary>
436         /// Sets or gets whether an object is to repeat events.
437         /// </summary>
438         public bool RepeatEvents
439         {
440             get
441             {
442                 return Interop.Evas.evas_object_repeat_events_get(RealHandle);
443             }
444             set
445             {
446                 Interop.Evas.evas_object_repeat_events_set(RealHandle, value);
447             }
448         }
449
450         /// <summary>
451         /// Sets or gets whether events on a smart object's member should get propagated up to its parent.
452         /// </summary>
453         public bool PropagateEvents
454         {
455             get
456             {
457                 return Interop.Evas.evas_object_propagate_events_get(RealHandle);
458             }
459             set
460             {
461                 Interop.Evas.evas_object_propagate_events_set(RealHandle, value);
462             }
463         }
464
465         /// <summary>
466         /// Sets or gets whether an object is set to pass (ignore) events.
467         /// </summary>
468         public bool PassEvents
469         {
470             get
471             {
472                 return Interop.Evas.evas_object_pass_events_get(RealHandle);
473             }
474             set
475             {
476                 Interop.Evas.evas_object_pass_events_set(RealHandle, value);
477             }
478         }
479
480         /// <summary>
481         /// Sets or Gets style for this object tooltip.
482         /// </summary>
483         public string TooltipStyle
484         {
485             get
486             {
487                 return Interop.Elementary.elm_object_tooltip_style_get(RealHandle);
488             }
489             set
490             {
491                 Interop.Elementary.elm_object_tooltip_style_set(RealHandle, value);
492             }
493         }
494
495         /// <summary>
496         /// Sets or gets the orientation of Tooltip.
497         /// </summary>
498         public TooltipOrientation TooltipOrientation
499         {
500             get
501             {
502                 return (TooltipOrientation)Interop.Elementary.elm_object_tooltip_orient_get(RealHandle);
503             }
504             set
505             {
506                 Interop.Elementary.elm_object_tooltip_orient_set(RealHandle, (int)value);
507             }
508         }
509
510         /// <summary>
511         /// Sets or gets size restriction state of an object's tooltip.
512         /// </summary>
513         public bool TooltipWindowMode
514         {
515             get
516             {
517                 return Interop.Elementary.elm_object_tooltip_window_mode_get(RealHandle);
518             }
519             set
520             {
521                 Interop.Elementary.elm_object_tooltip_window_mode_set(RealHandle, value);
522             }
523         }
524
525         /// <summary>
526         /// Sets the content to be shown in the tooltip object.
527         /// </summary>
528         public GetTooltipContentDelegate TooltipContentDelegate
529         {
530             get
531             {
532                 return _tooltipContentDelegate;
533             }
534             set
535             {
536                 _tooltipContentDelegate = value;
537                 if (value != null)
538                 {
539                     Interop.Elementary.elm_object_tooltip_content_cb_set(RealHandle, _tooltipContentCallback, IntPtr.Zero, null);
540                 }
541                 else
542                 {
543                     Interop.Elementary.elm_object_tooltip_content_cb_set(RealHandle, null, IntPtr.Zero, null);
544                 }
545             }
546         }
547
548         /// <summary>
549         /// Gets the movement freeze by 1
550         /// This gets the movement freeze count by one.
551         /// </summary>
552         public int TooltipMoveFreezeCount
553         {
554             get
555             {
556                 return Interop.Elementary.elm_object_tooltip_move_freeze_get(RealHandle);
557             }
558         }
559
560         /// <summary>
561         /// Sets or gets whether an Evas object is to freeze (discard) events.
562         /// </summary>
563         public bool AllEventsFrozen
564         {
565             get
566             {
567                 return Interop.Evas.evas_object_freeze_events_get(RealHandle);
568             }
569             set
570             {
571                 Interop.Evas.evas_object_freeze_events_set(RealHandle, value);
572             }
573         }
574
575         /// <summary>
576         /// Sets or gets the layer of its canvas that the given object will be part of.
577         /// </summary>
578         public virtual int Layer
579         {
580             get
581             {
582                 return Interop.Evas.evas_object_layer_get(Handle);
583             }
584             set
585             {
586                 Interop.Evas.evas_object_layer_set(Handle, value);
587             }
588         }
589
590         /// <summary>
591         /// Clips one object to another.
592         /// </summary>
593         /// <param name="clip">The object to clip object by</param>
594         public void SetClip(EvasObject clip)
595         {
596             Interop.Evas.evas_object_clip_set(Handle, clip);
597         }
598
599         /// <summary>
600         /// Sets the hints for an object's alignment.
601         /// </summary>
602         /// <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>
603         /// <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>
604         public void SetAlignment(double x, double y)
605         {
606             Interop.Evas.evas_object_size_hint_align_set(Handle, x, y);
607         }
608
609         /// <summary>
610         /// Sets the hints for an object's weight.
611         /// </summary>
612         /// <param name="x">The non-negative double value to use as horizontal weight hint</param>
613         /// <param name="y">The non-negative double value to use as vertical weight hint</param>
614         public void SetWeight(double x, double y)
615         {
616             Interop.Evas.evas_object_size_hint_weight_set(Handle, x, y);
617         }
618
619         /// <summary>
620         /// Sets the text for an object's tooltip.
621         /// </summary>
622         /// <param name="text">The text value to display inside the tooltip</param>
623         public void SetTooltipText(string text)
624         {
625             Interop.Elementary.elm_object_tooltip_text_set(RealHandle, text);
626         }
627
628         /// <summary>
629         /// Unsets an object's tooltip.
630         /// </summary>
631         public void UnsetTooltip()
632         {
633             Interop.Elementary.elm_object_tooltip_unset(RealHandle);
634         }
635
636         /// <summary>
637         /// This increments the tooltip movement freeze count by one.
638         /// If the count is more than 0, the tooltip position will be fixed.
639         /// </summary>
640         public void PushTooltipMoveFreeze()
641         {
642             Interop.Elementary.elm_object_tooltip_move_freeze_push(RealHandle);
643         }
644
645         /// <summary>
646         /// This decrements the tooltip freeze count by one.
647         /// </summary>
648         public void PopTooltipMoveFreeze()
649         {
650             Interop.Elementary.elm_object_tooltip_move_freeze_pop(RealHandle);
651         }
652
653         /// <summary>
654         /// Force hide tooltip of object.
655         /// </summary>
656         public void HideTooltip()
657         {
658             Interop.Elementary.elm_object_tooltip_hide(RealHandle);
659         }
660
661         /// <summary>
662         /// Force show tooltip of object.
663         /// </summary>
664         public void ShowTooltip()
665         {
666             Interop.Elementary.elm_object_tooltip_show(RealHandle);
667         }
668
669         /// <summary>
670         /// Makes the current object visible.
671         /// </summary>
672         public void Show()
673         {
674             Interop.Evas.evas_object_show(Handle);
675         }
676
677         /// <summary>
678         /// Makes the current object invisible.
679         /// </summary>
680         public void Hide()
681         {
682             Interop.Evas.evas_object_hide(Handle);
683         }
684
685         /// <summary>
686         /// Changes the size of the current object.
687         /// </summary>
688         /// <param name="w">The new width</param>
689         /// <param name="h">The new height</param>
690         public void Resize(int w, int h)
691         {
692             Interop.Evas.evas_object_resize(Handle, w, h);
693         }
694
695         /// <summary>
696         /// Moves the current object to the given location.
697         /// </summary>
698         /// <param name="x">The X position to move the object to.</param>
699         /// <param name="y">The Y position to move the object to.</param>
700         public void Move(int x, int y)
701         {
702             Interop.Evas.evas_object_move(Handle, x, y);
703         }
704
705         /// <summary>
706         /// Lowers obj to the bottom of its layer.
707         /// </summary>
708         public void Lower()
709         {
710             Interop.Evas.evas_object_lower(Handle);
711         }
712
713         /// <summary>
714         /// Define IntPtr operator
715         /// </summary>
716         /// <param name="obj">Parent object</param>
717         public static implicit operator IntPtr(EvasObject obj)
718         {
719             if (obj == null)
720                 return IntPtr.Zero;
721             return obj.Handle;
722         }
723
724         /// <summary>
725         /// Requests keyname key events be directed to current obj.
726         /// </summary>
727         /// <param name="keyname">The key to request events for</param>
728         /// <param name="exclusive">Set TRUE to request that the obj is the only object receiving the keyname events,otherwise set FALSE</param>
729         /// <returns>If the call succeeded is true,otherwise is false</returns>
730         public bool KeyGrab(string keyname, bool exclusive)
731         {
732             return Interop.Evas.evas_object_key_grab(Handle, keyname, 0, 0, exclusive);
733         }
734
735         /// <summary>
736         /// Removes the grab on keyname key events.
737         /// </summary>
738         /// <param name="keyname">The key the grab is set for</param>
739         public void KeyUngrab(string keyname)
740         {
741             Interop.Evas.evas_object_key_ungrab(Handle, keyname, 0, 0);
742         }
743
744         /// <summary>
745         /// Mark smart object as changed.
746         /// </summary>
747         public void MarkChanged()
748         {
749             Interop.Evas.evas_object_smart_changed(RealHandle);
750         }
751
752         /// <summary>
753         /// Call the calculate smart function immediately.
754         /// This will force immediate calculations needed for renderization of this object.
755         /// </summary>
756         public void Calculate()
757         {
758             Interop.Evas.evas_object_smart_calculate(RealHandle);
759         }
760
761         /// <summary>
762         /// Sets the hints for an object's aspect ratio.
763         /// </summary>
764         /// <param name="aspect">The policy or type of aspect ratio to apply to object</param>
765         /// <param name="w">The integer to use as aspect width ratio term</param>
766         /// <param name="h">The integer to use as aspect height ratio term</param>
767         public void SetSizeHintAspect(AspectControl aspect, int w, int h)
768         {
769             Interop.Evas.evas_object_size_hint_aspect_set(Handle, (int)aspect, w, h);
770         }
771
772         /// <summary>
773         /// Gets the hints for an object's aspect ratio.
774         /// </summary>
775         /// <param name="aspect">The policy or type of aspect ratio to apply to object</param>
776         /// <param name="w">The integer to use as aspect width ratio term</param>
777         /// <param name="h">The integer to use as aspect height ratio term</param>
778         public void GetSizeHintAspect(out AspectControl aspect, out int w, out int h)
779         {
780             int aspectRatio;
781             Interop.Evas.evas_object_size_hint_aspect_get(Handle, out aspectRatio, out w, out h);
782             aspect = (AspectControl)aspectRatio;
783         }
784
785         /// <summary>
786         /// Stack immediately below anchor.
787         /// </summary>
788         /// <param name="anchor">The object below which to stack.</param>
789         public void StackBelow(EvasObject anchor)
790         {
791             Interop.Evas.evas_object_stack_below(Handle, anchor);
792         }
793
794         /// <summary>
795         /// Stack immediately above anchor.
796         /// </summary>
797         /// <param name="anchor">The object above which to stack.</param>
798         public void StackAbove(EvasObject anchor)
799         {
800             Interop.Evas.evas_object_stack_above(Handle, anchor);
801         }
802
803         /// <summary>
804         /// Raise to the top of its layer.
805         /// </summary>
806         public void RaiseTop()
807         {
808             Interop.Evas.evas_object_raise(Handle);
809         }
810
811         /// <summary>
812         /// Get the geometry of a line number.
813         /// </summary>
814         /// <param name="lineNumber">the line number.</param>
815         /// <param name="x">x coord of the line.</param>
816         /// <param name="y">y coord of the line.</param>
817         /// <param name="w">w coord of the line.</param>
818         /// <param name="h">h coord of the line.</param>
819         /// <returns></returns>
820         public bool GetTextBlockGeometryByLineNumber(int lineNumber, out int x, out int y, out int w, out int h)
821         {
822             return Interop.Evas.evas_object_textblock_line_number_geometry_get(RealHandle, lineNumber, out x, out y, out w, out h);
823         }
824
825         internal IntPtr GetData(string key)
826         {
827             return Interop.Evas.evas_object_data_get(RealHandle, key);
828         }
829
830         internal void SetData(string key, IntPtr data)
831         {
832             Interop.Evas.evas_object_data_set(RealHandle, key, data);
833         }
834
835         internal IntPtr DeleteData(string key)
836         {
837             return Interop.Evas.evas_object_data_del(RealHandle, key);
838         }
839
840         /// <summary>
841         /// The callback of Invalidate Event
842         /// </summary>
843         protected virtual void OnInvalidate()
844         {
845         }
846
847         /// <summary>
848         /// The callback of Instantiated Event
849         /// </summary>
850         protected virtual void OnInstantiated()
851         {
852         }
853
854         /// <summary>
855         /// The callback of Realized Event
856         /// </summary>
857         protected virtual void OnRealized()
858         {
859         }
860
861         /// <summary>
862         /// The callback of Unrealize Event
863         /// </summary>
864         protected virtual void OnUnrealize()
865         {
866         }
867
868         /// <summary>
869         /// Creates a widget handle.
870         /// </summary>
871         /// <param name="parent">Parent EvasObject</param>
872         /// <returns>Handle IntPtr</returns>
873         protected abstract IntPtr CreateHandle(EvasObject parent);
874
875         /// <summary>
876         /// For this object bind Parent object.Init handle and all kinds of EvasObjectEvent.
877         /// </summary>
878         /// <param name="parent">Parent object</param>
879         public void Realize(EvasObject parent)
880         {
881             if (!IsRealized)
882             {
883                 Parent = parent;
884                 Handle = CreateHandle(parent);
885                 Debug.Assert(Handle != IntPtr.Zero);
886
887                 (parent as Window)?.AddChild(this);
888
889                 OnRealized();
890                 _deleted = new EvasObjectEvent(this, EvasObjectCallbackType.Del);
891                 _keydown = new EvasObjectEvent<EvasKeyEventArgs>(this, RealHandle, EvasObjectCallbackType.KeyDown, EvasKeyEventArgs.Create);
892                 _keyup = new EvasObjectEvent<EvasKeyEventArgs>(this, RealHandle, EvasObjectCallbackType.KeyUp, EvasKeyEventArgs.Create);
893                 _moved = new EvasObjectEvent(this, EvasObjectCallbackType.Move);
894                 _resized = new EvasObjectEvent(this, EvasObjectCallbackType.Resize);
895
896                 _deleted.On += (s, e) => MakeInvalidate();
897                 _keydown.On += (s, e) => KeyDown?.Invoke(this, e);
898                 _keyup.On += (s, e) => KeyUp?.Invoke(this, e);
899             }
900         }
901
902         /// <summary>
903         /// Removes current object relationship with others.
904         /// </summary>
905         public void Unrealize()
906         {
907             if (IsRealized)
908             {
909                 if (_renderPostCallback != null)
910                 {
911                     Interop.Evas.evas_event_callback_del(Interop.Evas.evas_object_evas_get(Handle), Interop.Evas.ObjectCallbackType.RenderPost, _renderPostCallback);
912                     _renderPostCallback = null;
913                 }
914
915                 OnUnrealize();
916                 IntPtr toBeDeleted = Handle;
917                 Handle = IntPtr.Zero;
918
919                 DisposeEvent();
920
921                 (Parent as Window)?.RemoveChild(this);
922
923                 Interop.Evas.evas_object_del(toBeDeleted);
924                 Parent = null;
925             }
926         }
927
928         private void MakeInvalidate()
929         {
930             Deleted?.Invoke(this, EventArgs.Empty);
931             OnInvalidate();
932             Handle = IntPtr.Zero;
933
934             MakeInvalidateEvent();
935
936             (Parent as Window)?.RemoveChild(this);
937             Parent = null;
938             _deleted = null;
939         }
940
941         private void DisposeEvent()
942         {
943             foreach (var evt in _eventStore)
944             {
945                 evt.Dispose();
946             }
947             _eventStore.Clear();
948         }
949
950         private void MakeInvalidateEvent()
951         {
952             foreach (var evt in _eventStore)
953             {
954                 evt.MakeInvalidate();
955             }
956             _eventStore.Clear();
957         }
958
959         internal void AddToEventLifeTracker(IInvalidatable item)
960         {
961             _eventStore.Add(item);
962         }
963     }
964 }