summaryrefslogtreecommitdiff
path: root/ElmSharp/ElmSharp/EvasObject.cs
blob: 5bc3f7c64f53eaf0e0c6f16a7ba45ac90508b06e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
/*
 * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
 *
 * Licensed under the Apache License, Version 2.0 (the License);
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an AS IS BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

using System;
using System.Collections.Generic;
using System.Diagnostics;

namespace ElmSharp
{
    public enum TooltipOrientation
    {
        None,
        TopLeft,
        Top,
        TopRight,
        Left,
        Center,
        Right,
        BottomLeft,
        Bottom,
        BottomRight,
    }

    /// <summary>
    /// The EcasObject is a base class for other widget class
    /// </summary>
    public abstract class EvasObject
    {
        private IntPtr _realHandle = IntPtr.Zero;

        private event EventHandler _backButtonPressed;

        private event EventHandler _moreButtonPressed;

        private Interop.Eext.EextEventCallback _backButtonHandler;
        private Interop.Eext.EextEventCallback _moreButtonHandler;

        public IntPtr Handle { get; protected set; }
        public EvasObject Parent { get; private set; }

        public IntPtr RealHandle
        {
            get
            {
                return _realHandle == IntPtr.Zero ? Handle : _realHandle;
            }
            protected set
            {
                _realHandle = value;
            }
        }

        EvasObjectEvent _deleted;
        EvasObjectEvent<EvasKeyEventArgs> _keyup;
        EvasObjectEvent<EvasKeyEventArgs> _keydown;
        EvasObjectEvent _moved;
        EvasObjectEvent _resized;
        EventHandler _renderPost;
        Interop.Evas.EvasCallback _renderPostCallback = null;
        Interop.Elementary.Elm_Tooltip_Content_Cb _tooltipContentCallback = null;

        GetTooltipContentDelegate _tooltipContentDelegate = null;

        readonly HashSet<IInvalidatable> _eventStore = new HashSet<IInvalidatable>();

        /// <summary>
        /// Creates and initializes a new instance of the EvasObject class with parent EvasObject class parameter.
        /// </summary>
        /// <param name="parent">Parent EvasObject class </param>
        protected EvasObject(EvasObject parent) : this()
        {
            Debug.Assert(parent == null || parent.IsRealized);
            Realize(parent);
        }

        /// <summary>
        /// Creates and initializes a new instance of the EvasObject class.
        /// </summary>
        protected EvasObject()
        {
            _backButtonHandler = new Interop.Eext.EextEventCallback((d, o, i) => { _backButtonPressed?.Invoke(this, EventArgs.Empty); });
            _moreButtonHandler = new Interop.Eext.EextEventCallback((d, o, i) => { _moreButtonPressed?.Invoke(this, EventArgs.Empty); });

            OnInstantiated();

            _tooltipContentCallback = (d, o, t) =>
            {
                return _tooltipContentDelegate?.Invoke();
            };
        }

        // C# Finalizer was called on GC thread
        // So, We can't access to EFL object
        // And When Finalizer was called, Field can be already released.
        //~EvasObject()
        //{
        //    Unrealize();
        //}

        /// <summary>
        /// Deleted will be triggered when widght is deleted
        /// </summary>
        public event EventHandler Deleted;

        /// <summary>
        /// KeyUp will be triggered when key is loose
        /// </summary>
        public event EventHandler<EvasKeyEventArgs> KeyUp;

        /// <summary>
        /// KeyDown will be triggered when key is preesd down
        /// </summary>
        public event EventHandler<EvasKeyEventArgs> KeyDown;

        /// <summary>
        /// BackButtonPressed will be triggered when Back button is pressed
        /// </summary>
        public event EventHandler BackButtonPressed
        {
            add
            {
                if (_backButtonPressed == null)
                {
                    Interop.Eext.eext_object_event_callback_add(RealHandle, Interop.Eext.EextCallbackType.EEXT_CALLBACK_BACK, _backButtonHandler, IntPtr.Zero);
                }
                _backButtonPressed += value;
            }
            remove
            {
                _backButtonPressed -= value;
                if (_backButtonPressed == null)
                {
                    Interop.Eext.eext_object_event_callback_del(RealHandle, Interop.Eext.EextCallbackType.EEXT_CALLBACK_BACK, _backButtonHandler);
                }
            }
        }

        /// <summary>
        /// MoreButtonPressed will be triggered when More button is pressed
        /// </summary>
        public event EventHandler MoreButtonPressed
        {
            add
            {
                if (_moreButtonPressed == null)
                {
                    Interop.Eext.eext_object_event_callback_add(RealHandle, Interop.Eext.EextCallbackType.EEXT_CALLBACK_MORE, _moreButtonHandler, IntPtr.Zero);
                }
                _moreButtonPressed += value;
            }
            remove
            {
                _moreButtonPressed -= value;
                if (_moreButtonPressed == null)
                {
                    Interop.Eext.eext_object_event_callback_del(RealHandle, Interop.Eext.EextCallbackType.EEXT_CALLBACK_MORE, _moreButtonHandler);
                }
            }
        }

        /// <summary>
        /// Moved will be triggered when widght is moved
        /// </summary>
        public event EventHandler Moved
        {
            add { _moved.On += value; }
            remove { _moved.On -= value; }
        }

        /// <summary>
        /// Current widget's size Resized Event Handler
        /// </summary>
        public event EventHandler Resized
        {
            add { _resized.On += value; }
            remove { _resized.On -= value; }
        }

        /// <summary>
        /// Current widget RenderPost Event Handler
        /// </summary>
        public event EventHandler RenderPost
        {
            add
            {
                _renderPost += value;
                if (_renderPostCallback == null)
                {
                    _renderPostCallback = new Interop.Evas.EvasCallback((o, e, d) => _renderPost?.Invoke(this, EventArgs.Empty));
                    Interop.Evas.evas_event_callback_add(Interop.Evas.evas_object_evas_get(RealHandle), Interop.Evas.ObjectCallbackType.RenderPost, _renderPostCallback, IntPtr.Zero);
                }
            }
            remove
            {
                _renderPost -= value;
                if (_renderPost?.GetInvocationList().Length == 0)
                {
                    Interop.Evas.evas_event_callback_del(Interop.Evas.evas_object_evas_get(RealHandle), Interop.Evas.ObjectCallbackType.RenderPost, _renderPostCallback);
                    _renderPostCallback = null;
                }
            }
        }

        /// <summary>
        /// Called back when a widget's tooltip is activated and needs content.
        /// </summary>
        /// <returns></returns>
        public delegate EvasObject GetTooltipContentDelegate();

        /// <summary>
        /// Get widget's status of Realized or not.
        /// </summary>
        public bool IsRealized { get { return Handle != IntPtr.Zero; } }

        /// <summary>
        /// Gets the current class's Name.
        /// </summary>
        public string ClassName
        {
            get
            {
                return Interop.Eo.eo_class_name_get(Interop.Eo.eo_class_get(RealHandle));
            }
        }

        /// <summary>
        /// Sets or gets the horizontal pointer hints for an object's weight.
        /// </summary>
        public double WeightX
        {
            get
            {
                return Interop.Evas.GetWeightX(Handle);
            }
            set
            {
                Interop.Evas.SetWeightX(Handle, value);
            }
        }

        /// <summary>
        /// Sets or gets the vertical pointer hints for an object's weight.
        /// </summary>
        public double WeightY
        {
            get
            {
                return Interop.Evas.GetWeightY(Handle);
            }
            set
            {
                Interop.Evas.SetWeightY(Handle, value);
            }
        }

        /// <summary>
        /// Sets or gets the horizontal alignment hint of an object's alignment.
        /// </summary>
        public virtual double AlignmentX
        {
            get
            {
                return Interop.Evas.GetAlignX(Handle);
            }
            set
            {
                Interop.Evas.SetAlignX(Handle, value);
            }
        }

        /// <summary>
        /// Sets or gets the vertical alignment hint of an object's alignment.
        /// </summary>
        public virtual double AlignmentY
        {
            get
            {
                return Interop.Evas.GetAlignY(Handle);
            }
            set
            {
                Interop.Evas.SetAlignY(Handle, value);
            }
        }

        /// <summary>
        /// Sets or gets the Width hints for an object's minimum size.
        /// </summary>
        public int MinimumWidth
        {
            get
            {
                int w, h;
                Interop.Evas.evas_object_size_hint_min_get(RealHandle, out w, out h);
                return w;
            }
            set
            {
                int h = MinimumHeight;
                Interop.Evas.evas_object_size_hint_min_set(RealHandle, value, h);
            }
        }

        /// <summary>
        /// Sets or gets the Height hints for an object's minimum size.
        /// </summary>
        public int MinimumHeight
        {
            get
            {
                int w, h;
                Interop.Evas.evas_object_size_hint_min_get(RealHandle, out w, out h);
                return h;
            }
            set
            {
                int w = MinimumWidth;
                Interop.Evas.evas_object_size_hint_min_set(RealHandle, w, value);
            }
        }

        /// <summary>
        /// Gets the visible state of the given Evas object.
        /// </summary>
        public bool IsVisible
        {
            get
            {
                return Interop.Evas.evas_object_visible_get(Handle);
            }
        }

        /// <summary>
        /// Sets or gets the position and (rectangular) size of the given Evas object.
        /// </summary>
        public Rect Geometry
        {
            get
            {
                int x, y, w, h;
                Interop.Evas.evas_object_geometry_get(Handle, out x, out y, out w, out h);
                Rect rect = new Rect(x, y, w, h);
                return rect;
            }
            set
            {
                Interop.Evas.evas_object_geometry_set(Handle, value.X, value.Y, value.Width, value.Height);
            }
        }

        /// <summary>
        /// Sets or gets the general or main color of the given Evas object.
        /// </summary>
        public virtual Color Color
        {
            get
            {
                int r, g, b, a;
                Interop.Evas.evas_object_color_get(RealHandle, out r, out g, out b, out a);
                return Color.FromRgba(r, g, b, a);
            }
            set
            {
                Interop.Evas.SetPremultipliedColor(RealHandle, value.R, value.G, value.B, value.A);
            }
        }

        /// <summary>
        /// Sets or gets the map enabled state.
        /// </summary>
        public bool IsMapEnabled
        {
            get
            {
                return Interop.Evas.evas_object_map_enable_get(Handle);
            }
            set
            {
                Interop.Evas.evas_object_map_enable_set(Handle, value);
            }
        }

        /// <summary>
        /// Sets or gets current object transformation map.
        /// </summary>
        public EvasMap EvasMap
        {
            get
            {
                IntPtr evasMap = Interop.Evas.evas_object_map_get(Handle);
                return new EvasMap(evasMap);
            }
            set
            {
                Interop.Evas.evas_object_map_set(Handle, value.Handle);
            }
        }

        /// <summary>
        /// Sets or gets whether an object is to repeat events.
        /// </summary>
        public bool RepeatEvents
        {
            get
            {
                return Interop.Evas.evas_object_repeat_events_get(RealHandle);
            }
            set
            {
                Interop.Evas.evas_object_repeat_events_set(RealHandle, value);
            }
        }

        /// <summary>
        /// Sets or gets whether events on a smart object's member should get propagated up to its parent.
        /// </summary>
        public bool PropagateEvents
        {
            get
            {
                return Interop.Evas.evas_object_propagate_events_get(RealHandle);
            }
            set
            {
                Interop.Evas.evas_object_propagate_events_set(RealHandle, value);
            }
        }

        /// <summary>
        /// Sets or gets whether an object is set to pass (ignore) events.
        /// </summary>
        public bool PassEvents
        {
            get
            {
                return Interop.Evas.evas_object_pass_events_get(RealHandle);
            }
            set
            {
                Interop.Evas.evas_object_pass_events_set(RealHandle, value);
            }
        }

        /// <summary>
        /// Sets or Gets style for this object tooltip.
        /// </summary>
        public string TooltipStyle
        {
            get
            {
                return Interop.Elementary.elm_object_tooltip_style_get(RealHandle);
            }
            set
            {
                Interop.Elementary.elm_object_tooltip_style_set(RealHandle, value);
            }
        }

        /// <summary>
        /// Sets or gets the orientation of Tooltip.
        /// </summary>
        public TooltipOrientation TooltipOrientation
        {
            get
            {
                return (TooltipOrientation)Interop.Elementary.elm_object_tooltip_orient_get(RealHandle);
            }
            set
            {
                Interop.Elementary.elm_object_tooltip_orient_set(RealHandle, (int)value);
            }
        }

        /// <summary>
        /// Sets or gets size restriction state of an object's tooltip.
        /// </summary>
        public bool TooltipWindowMode
        {
            get
            {
                return Interop.Elementary.elm_object_tooltip_window_mode_get(RealHandle);
            }
            set
            {
                Interop.Elementary.elm_object_tooltip_window_mode_set(RealHandle, value);
            }
        }

        /// <summary>
        /// Sets the content to be shown in the tooltip object.
        /// </summary>
        public GetTooltipContentDelegate TooltipContentDelegate
        {
            get
            {
                return _tooltipContentDelegate;
            }
            set
            {
                _tooltipContentDelegate = value;
                if (value != null)
                {
                    Interop.Elementary.elm_object_tooltip_content_cb_set(RealHandle, _tooltipContentCallback, IntPtr.Zero, null);
                }
                else
                {
                    Interop.Elementary.elm_object_tooltip_content_cb_set(RealHandle, null, IntPtr.Zero, null);
                }
            }
        }

        /// <summary>
        /// Gets the movement freeze by 1
        /// This gets the movement freeze count by one.
        /// </summary>
        public int TooltipMoveFreezeCount
        {
            get
            {
                return Interop.Elementary.elm_object_tooltip_move_freeze_get(RealHandle);
            }
        }

        /// <summary>
        /// Clips one object to another.
        /// </summary>
        /// <param name="clip">The object to clip object by</param>
        public void SetClip(EvasObject clip)
        {
            Interop.Evas.evas_object_clip_set(Handle, clip);
        }

        /// <summary>
        /// Sets the hints for an object's alignment.
        /// </summary>
        /// <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>
        /// <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>
        public void SetAlignment(double x, double y)
        {
            Interop.Evas.evas_object_size_hint_align_set(Handle, x, y);
        }

        /// <summary>
        /// Sets the hints for an object's weight.
        /// </summary>
        /// <param name="x">The non-negative double value to use as horizontal weight hint</param>
        /// <param name="y">The non-negative double value to use as vertical weight hint</param>
        public void SetWeight(double x, double y)
        {
            Interop.Evas.evas_object_size_hint_weight_set(Handle, x, y);
        }

        /// <summary>
        /// Sets the text for an object's tooltip.
        /// </summary>
        /// <param name="text">The text value to display inside the tooltip</param>
        public void SetTooltipText(string text)
        {
            Interop.Elementary.elm_object_tooltip_text_set(RealHandle, text);
        }

        /// <summary>
        /// Unsets an object's tooltip.
        /// </summary>
        public void UnsetTooltip()
        {
            Interop.Elementary.elm_object_tooltip_unset(RealHandle);
        }

        /// <summary>
        /// This increments the tooltip movement freeze count by one.
        /// If the count is more than 0, the tooltip position will be fixed.
        /// </summary>
        public void PushTooltipMoveFreeze()
        {
            Interop.Elementary.elm_object_tooltip_move_freeze_push(RealHandle);
        }

        /// <summary>
        /// This decrements the tooltip freeze count by one.
        /// </summary>
        public void PopTooltipMoveFreeze()
        {
            Interop.Elementary.elm_object_tooltip_move_freeze_pop(RealHandle);
        }

        /// <summary>
        /// Force hide tooltip of object.
        /// </summary>
        public void HideTooltip()
        {
            Interop.Elementary.elm_object_tooltip_hide(RealHandle);
        }

        /// <summary>
        /// Force show tooltip of object.
        /// </summary>
        public void ShowTooltip()
        {
            Interop.Elementary.elm_object_tooltip_show(RealHandle);
        }

        /// <summary>
        /// Makes the current object visible.
        /// </summary>
        public void Show()
        {
            Interop.Evas.evas_object_show(Handle);
        }

        /// <summary>
        /// Makes the current object invisible.
        /// </summary>
        public void Hide()
        {
            Interop.Evas.evas_object_hide(Handle);
        }

        /// <summary>
        /// Changes the size of the current object.
        /// </summary>
        /// <param name="w">The new width</param>
        /// <param name="h">The new height</param>
        public void Resize(int w, int h)
        {
            Interop.Evas.evas_object_resize(Handle, w, h);
        }

        /// <summary>
        /// Moves the current object to the given location.
        /// </summary>
        /// <param name="x">The X position to move the object to.</param>
        /// <param name="y">The Y position to move the object to.</param>
        public void Move(int x, int y)
        {
            Interop.Evas.evas_object_move(Handle, x, y);
        }

        /// <summary>
        /// Lowers obj to the bottom of its layer.
        /// </summary>
        public void Lower()
        {
            Interop.Evas.evas_object_lower(Handle);
        }

        /// <summary>
        /// Define IntPtr operator
        /// </summary>
        /// <param name="obj">Parent object</param>
        public static implicit operator IntPtr(EvasObject obj)
        {
            if (obj == null)
                return IntPtr.Zero;
            return obj.Handle;
        }

        /// <summary>
        /// Requests keyname key events be directed to current obj.
        /// </summary>
        /// <param name="keyname">The key to request events for</param>
        /// <param name="exclusive">Set TRUE to request that the obj is the only object receiving the keyname events,otherwise set FALSE</param>
        /// <returns>If the call succeeded is true,otherwise is false</returns>
        public bool KeyGrab(string keyname, bool exclusive)
        {
            return Interop.Evas.evas_object_key_grab(Handle, keyname, 0, 0, exclusive);
        }

        /// <summary>
        /// Removes the grab on keyname key events.
        /// </summary>
        /// <param name="keyname">The key the grab is set for</param>
        public void KeyUngrab(string keyname)
        {
            Interop.Evas.evas_object_key_ungrab(Handle, keyname, 0, 0);
        }

        /// <summary>
        /// Mark smart object as changed.
        /// </summary>
        public void MarkChanged()
        {
            Interop.Evas.evas_object_smart_changed(RealHandle);
        }

        /// <summary>
        /// The callback of Invalidate Event
        /// </summary>
        protected virtual void OnInvalidate()
        {
        }

        /// <summary>
        /// The callback of Instantiated Event
        /// </summary>
        protected virtual void OnInstantiated()
        {
        }

        /// <summary>
        /// The callback of Realized Event
        /// </summary>
        protected virtual void OnRealized()
        {
        }

        /// <summary>
        /// The callback of Unrealize Event
        /// </summary>
        protected virtual void OnUnrealize()
        {
        }

        /// <summary>
        /// Creates a widget handle.
        /// </summary>
        /// <param name="parent">Parent EvasObject</param>
        /// <returns>Handle IntPtr</returns>
        protected abstract IntPtr CreateHandle(EvasObject parent);

        /// <summary>
        /// For this object bind Parent object.Init handle and all kinds of EvasObjectEvent.
        /// </summary>
        /// <param name="parent">Parent object</param>
        public void Realize(EvasObject parent)
        {
            if (!IsRealized)
            {
                Parent = parent;
                Handle = CreateHandle(parent);
                Debug.Assert(Handle != IntPtr.Zero);

                (parent as Window)?.AddChild(this);

                OnRealized();
                _deleted = new EvasObjectEvent(this, EvasObjectCallbackType.Del);
                _keydown = new EvasObjectEvent<EvasKeyEventArgs>(this, EvasObjectCallbackType.KeyDown, EvasKeyEventArgs.Create);
                _keyup = new EvasObjectEvent<EvasKeyEventArgs>(this, EvasObjectCallbackType.KeyUp, EvasKeyEventArgs.Create);
                _moved = new EvasObjectEvent(this, EvasObjectCallbackType.Move);
                _resized = new EvasObjectEvent(this, EvasObjectCallbackType.Resize);

                _deleted.On += (s, e) => MakeInvalidate();
                _keydown.On += (s, e) => KeyDown?.Invoke(this, e);
                _keyup.On += (s, e) => KeyUp?.Invoke(this, e);
            }
        }

        /// <summary>
        /// Removes current object relationship with others.
        /// </summary>
        public void Unrealize()
        {
            if (IsRealized)
            {
                if (_renderPostCallback != null)
                {
                    Interop.Evas.evas_event_callback_del(Interop.Evas.evas_object_evas_get(Handle), Interop.Evas.ObjectCallbackType.RenderPost, _renderPostCallback);
                    _renderPostCallback = null;
                }

                OnUnrealize();
                IntPtr toBeDeleted = Handle;
                Handle = IntPtr.Zero;

                DisposeEvent();

                (Parent as Window)?.RemoveChild(this);

                Interop.Evas.evas_object_del(toBeDeleted);
                Parent = null;
            }
        }

        private void MakeInvalidate()
        {
            Deleted?.Invoke(this, EventArgs.Empty);
            OnInvalidate();
            Handle = IntPtr.Zero;

            MakeInvalidateEvent();

            (Parent as Window)?.RemoveChild(this);
            Parent = null;
            _deleted = null;
        }

        private void DisposeEvent()
        {
            foreach (var evt in _eventStore)
            {
                evt.Dispose();
            }
            _eventStore.Clear();
        }

        private void MakeInvalidateEvent()
        {
            foreach (var evt in _eventStore)
            {
                evt.MakeInvalidate();
            }
            _eventStore.Clear();
        }

        internal void AddToEventLifeTracker(IInvalidatable item)
        {
            _eventStore.Add(item);
        }
    }
}