summaryrefslogtreecommitdiff
path: root/ElmSharp/ElmSharp/GenGrid.cs
blob: b5effb0a5d091ec4594907f4ae303b35a10e95d3 (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
/*
 * 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;

namespace ElmSharp
{
    /// <summary>
    /// It inherits System.EventArgs.
    /// It contains Item which is <see cref="GenGridItem"/> type.
    /// All events of GenGrid contain GenGridItemEventArgs as a parameter.
    /// </summary>
    public class GenGridItemEventArgs : EventArgs
    {
        /// <summary>
        /// Gets or sets GenGrid item.The return type is <see cref="GenGridItem"/>.
        /// </summary>
        public GenGridItem Item { get; set; }

        internal static GenGridItemEventArgs CreateFromSmartEvent(IntPtr data, IntPtr obj, IntPtr info)
        {
            GenGridItem item = ItemObject.GetItemByHandle(info) as GenGridItem;
            return new GenGridItemEventArgs() { Item = item };
        }
    }

    /// <summary>
    /// It inherits <see cref="Layout"/>.
    /// The GenGrid is a widget that aims to position objects in a grid layout while actually creating and rendering only the visible ones.
    /// It has two direction in which a given GenGrid widget expands while placing its items, horizontal and vertical.
    /// The GenGrid items are represented through <see cref="GenItemClass"/> definition field details.
    /// </summary>
    public class GenGrid : Layout
    {
        HashSet<GenGridItem> _children = new HashSet<GenGridItem>();

        SmartEvent<GenGridItemEventArgs> _selected;
        SmartEvent<GenGridItemEventArgs> _unselected;
        SmartEvent<GenGridItemEventArgs> _activated;
        SmartEvent<GenGridItemEventArgs> _pressed;
        SmartEvent<GenGridItemEventArgs> _released;
        SmartEvent<GenGridItemEventArgs> _doubleClicked;
        SmartEvent<GenGridItemEventArgs> _realized;
        SmartEvent<GenGridItemEventArgs> _unrealized;
        SmartEvent<GenGridItemEventArgs> _longpressed;
        SmartEvent _changed;

        /// <summary>
        /// Creates and initializes a new instance of the GenGrid class.
        /// </summary>
        /// <param name="parent">The parent is a given container which will be attached by GenGrid as a child. It's <see cref="EvasObject"/> type.</param>
        public GenGrid(EvasObject parent) : base(parent)
        {
            InitializeSmartEvent();
        }

        /// <summary>
        /// ItemSelected is raised when a new gengrid item is selected.
        /// </summary>
        public event EventHandler<GenGridItemEventArgs> ItemSelected;

        /// <summary>
        /// ItemUnselected is raised when the gengrid item is Unselected.
        /// </summary>
        public event EventHandler<GenGridItemEventArgs> ItemUnselected;

        /// <summary>
        /// ItemPressed is raised when a new gengrid item is pressed.
        /// </summary>
        public event EventHandler<GenGridItemEventArgs> ItemPressed;

        /// <summary>
        /// ItemReleased is raised when a new gengrid item is released.
        /// </summary>
        public event EventHandler<GenGridItemEventArgs> ItemReleased;

        /// <summary>
        /// ItemActivated is raised when a new gengrid item is double clicked or pressed (enter|return|spacebar).
        /// </summary>
        public event EventHandler<GenGridItemEventArgs> ItemActivated;

        /// <summary>
        /// ItemDoubleClicked is raised when a new gengrid item is double clicked.
        /// </summary>
        public event EventHandler<GenGridItemEventArgs> ItemDoubleClicked;

        /// <summary>
        /// ItemRealized is raised when a gengrid item is implementing through <see cref="GenItemClass"/>.
        /// </summary>
        public event EventHandler<GenGridItemEventArgs> ItemRealized;

        /// <summary>
        /// ItemUnrealized is raised when the gengrid item is deleted.
        /// </summary>
        public event EventHandler<GenGridItemEventArgs> ItemUnrealized;

        /// <summary>
        /// ItemLongPressed is raised when a gengrid item is pressed for a certain amount of time. By default it's 1 second.
        /// </summary>
        public event EventHandler<GenGridItemEventArgs> ItemLongPressed;

        /// <summary>
        ///  Changed is raised when an item is added, removed, resized or moved and when the gengrid is resized or gets "horizontal" property changes.
        /// </summary>
        public event EventHandler Changed;

        /// <summary>
        /// Gets or sets the item's grid alignment along x-axis within a given gengrid widget.
        /// The range is less than or equal to 1,and greater than or equal to 0.
        /// By default, value is 0.5, meaning that the gengrid has its items grid placed exactly in the middle along x-axis.
        /// </summary>
        public double ItemAlignmentX
        {
            get
            {
                double align;
                Interop.Elementary.elm_gengrid_align_get(RealHandle, out align, IntPtr.Zero);
                return align;
            }
            set
            {
                double aligny = ItemAlignmentY;
                Interop.Elementary.elm_gengrid_align_set(RealHandle, value, aligny);
            }
        }

        /// <summary>
        /// Gets or sets the item's grid alignment on y-axis within a given gengrid widget.
        /// The range is less than or equal to 1, and greater than or equal to 0.
        /// By default, value is 0.5, meaning that the gengrid has its items grid placed exactly in the middle along y-axis.
        /// </summary>
        public double ItemAlignmentY
        {
            get
            {
                double align;
                Interop.Elementary.elm_gengrid_align_get(RealHandle, IntPtr.Zero, out align);
                return align;
            }
            set
            {
                double alignx = ItemAlignmentX;
                Interop.Elementary.elm_gengrid_align_set(RealHandle, alignx, value);
            }
        }

        /// <summary>
        /// Gets or sets the manner in which the items grid is filled within a given gengrid widget.
        /// It is filled if true, otherwise false.
        /// </summary>
        public bool FillItems
        {
            get
            {
                return Interop.Elementary.elm_gengrid_filled_get(RealHandle);
            }
            set
            {
                Interop.Elementary.elm_gengrid_filled_set(RealHandle, value);
            }
        }

        /// <summary>
        /// Gets or sets whether multi-selection is enabled or disabled for a given gengrid widget.
        /// </summary>
        /// <remarks>
        /// Multi-selection is the ability to have more than one item selected, on a given gengrid, simultaneously.
        /// When it is enabled, a sequence of clicks on different items makes them all selected, progressively.
        /// A click on an already selected item unselects it. If interacting via the keyboard, multi-selection is enabled while holding the "Shift" key.
        /// By default, multi-selection is disabled.
        /// </remarks>
        public bool MultipleSelection
        {
            get
            {
                return Interop.Elementary.elm_gengrid_multi_select_get(RealHandle);
            }
            set
            {
                Interop.Elementary.elm_gengrid_multi_select_set(RealHandle, value);
            }
        }

        /// <summary>
        /// Gets or sets the width for the items of a given gengrid widget.
        /// </summary>
        /// <remarks>
        /// A gengrid, after creation, still has no information on the size to give to each of its cells.
        /// The default width and height just have one finger wide.
        /// Use this property to force a custom width for your items, making them as big as you wish.
        /// </remarks>
        public int ItemWidth
        {
            get
            {
                int width;
                Interop.Elementary.elm_gengrid_item_size_get(RealHandle, out width, IntPtr.Zero);
                return width;
            }
            set
            {
                int height = ItemHeight;
                Interop.Elementary.elm_gengrid_item_size_set(RealHandle, value, height);
            }
        }

        /// <summary>
        /// Gets or sets the height for the items of a given gengrid widget.
        /// </summary>
        /// <remarks>
        /// A gengrid, after creation, still has no information on the size to give to each of its cells.
        /// The default width and height just have one finger wide.
        /// Use this property to force a custom height for your items, making them as big as you wish.
        /// </remarks>
        public int ItemHeight
        {
            get
            {
                int height;
                Interop.Elementary.elm_gengrid_item_size_get(RealHandle, IntPtr.Zero, out height);
                return height;
            }
            set
            {
                int width = ItemWidth;
                Interop.Elementary.elm_gengrid_item_size_set(RealHandle, width, value);
            }
        }

        /// <summary>
        /// Gets or sets the gengrid select mode by <see cref="GenGridSelectionMode"/>.
        /// </summary>
        public GenItemSelectionMode SelectionMode
        {
            get
            {
                return (GenItemSelectionMode)Interop.Elementary.elm_gengrid_select_mode_get(RealHandle);
            }
            set
            {
                Interop.Elementary.elm_gengrid_select_mode_set(RealHandle, (int)value);
            }
        }

        /// <summary>
        /// Gets or sets the direction for which a given gengrid widget expands while placing its items.
        /// </summary>
        /// <remarks>
        /// If true, items are placed in columns from top to bottom and when the space for a column is filled, another one is started on the right, thus expanding the grid horizontally.
        /// If false, items are placed in rows from left to right, and when the space for a row is filled, another one is started below, thus expanding the grid vertically.
        /// </remarks>
        public bool IsHorizontal
        {
            get
            {
                return Interop.Elementary.elm_gengrid_horizontal_get(RealHandle);
            }
            set
            {
                Interop.Elementary.elm_gengrid_horizontal_set(RealHandle, value);
            }
        }

        /// <summary>
        /// Gets or sets whether the gengrid items should be highlighted when an item is selected.
        /// </summary>
        public bool IsHighlight
        {
            get
            {
                return Interop.Elementary.elm_gengrid_highlight_mode_get(RealHandle);
            }
            set
            {
                Interop.Elementary.elm_gengrid_highlight_mode_set(RealHandle, value);
            }
        }

        /// <summary>
        /// Sets or gets the value of HorizontalScrollBarVisiblePolicy
        /// </summary>
        /// <remarks>
        /// ScrollBarVisiblePolicy.Auto means the horizontal scrollbar is made visible if it is needed, and otherwise kept hidden.
        /// ScrollBarVisiblePolicy.Visible turns it on all the time, and ScrollBarVisiblePolicy.Invisible always keeps it off.
        /// </remarks>
        public ScrollBarVisiblePolicy HorizontalScrollBarVisiblePolicy
        {
            get
            {
                int policy;
                Interop.Elementary.elm_scroller_policy_get(RealHandle, out policy, IntPtr.Zero);
                return (ScrollBarVisiblePolicy)policy;
            }
            set
            {
                ScrollBarVisiblePolicy v = VerticalScrollBarVisiblePolicy;
                Interop.Elementary.elm_scroller_policy_set(RealHandle, (int)value, (int)v);
            }
        }

        /// <summary>
        /// Sets or gets the value of VerticalScrollBarVisiblePolicy
        /// </summary>
        /// <remarks>
        /// ScrollBarVisiblePolicy.Auto means the vertical scrollbar is made visible if it is needed, and otherwise kept hidden.
        /// ScrollBarVisiblePolicy.Visible turns it on all the time, and ScrollBarVisiblePolicy.Invisible always keeps it off.
        /// </remarks>
        public ScrollBarVisiblePolicy VerticalScrollBarVisiblePolicy
        {
            get
            {
                int policy;
                Interop.Elementary.elm_scroller_policy_get(RealHandle, IntPtr.Zero, out policy);
                return (ScrollBarVisiblePolicy)policy;
            }
            set
            {
                ScrollBarVisiblePolicy h = HorizontalScrollBarVisiblePolicy;
                Interop.Elementary.elm_scroller_policy_set(RealHandle, (int)h, (int)value);
            }
        }

        /// <summary>
        /// Gets the first item in a given gengrid widget.
        /// </summary>
        public GenGridItem FirstItem
        {
            get
            {
                IntPtr handle = Interop.Elementary.elm_gengrid_first_item_get(RealHandle);
                return ItemObject.GetItemByHandle(handle) as GenGridItem;
            }
        }

        /// <summary>
        /// Gets the last item in a given gengrid widget.
        /// </summary>
        public GenGridItem LastItem
        {
            get
            {
                IntPtr handle = Interop.Elementary.elm_gengrid_last_item_get(RealHandle);
                return ItemObject.GetItemByHandle(handle) as GenGridItem;
            }
        }

        /// <summary>
        /// Gets the items count in a given gengrid widget.
        /// </summary>
        public uint ItemCount
        {
            get
            {
                return Interop.Elementary.elm_gengrid_items_count(RealHandle);
            }
        }

        /// <summary>
        /// Gets the selected item in a given gengrid widget.
        /// </summary>
        public GenGridItem SelectedItem
        {
            get
            {
                IntPtr handle = Interop.Elementary.elm_gengrid_selected_item_get(RealHandle);
                return ItemObject.GetItemByHandle(handle) as GenGridItem;
            }
        }

        /// <summary>
        /// Gets or sets whether a given gengrid widget is or not able have items reordered.
        /// </summary>
        public bool ReorderMode
        {
            get
            {
                return Interop.Elementary.elm_gengrid_reorder_mode_get(RealHandle);
            }
            set
            {
                Interop.Elementary.elm_gengrid_reorder_mode_set(RealHandle, value);
            }
        }

        /// <summary>
        /// Appends a new item to a given gengrid widget. This adds an item to the end of the gengrid.
        /// </summary>
        /// <param name="itemClass">The itemClass defines how to display the data.</param>
        /// <param name="data">The item data.</param>
        /// <returns>Return a gengrid item that contains data and itemClass.</returns>
        /// <seealso cref="GenItemClass"/>
        /// <seealso cref="GenGridItem"/>
        public GenGridItem Append(GenItemClass itemClass, object data)
        {
            GenGridItem item = new GenGridItem(data, itemClass);
            IntPtr handle = Interop.Elementary.elm_gengrid_item_append(RealHandle, itemClass.UnmanagedPtr, (IntPtr)item.Id, null, (IntPtr)item.Id);
            item.Handle = handle;
            AddInternal(item);
            return item;
        }

        /// <summary>
        /// Prepends a new item to a given gengrid widget. This adds an item to the beginning of the gengrid.
        /// </summary>
        /// <param name="itemClass">The itemClass defines how to display the data.</param>
        /// <param name="data">The item data.</param>
        /// <returns>Return a gengrid item that contains data and itemClass.</returns>
        /// <seealso cref="GenItemClass"/>
        /// <seealso cref="GenGridItem"/>
        public GenGridItem Prepend(GenItemClass itemClass, object data)
        {
            GenGridItem item = new GenGridItem(data, itemClass);
            IntPtr handle = Interop.Elementary.elm_gengrid_item_prepend(RealHandle, itemClass.UnmanagedPtr, (IntPtr)item.Id, null, (IntPtr)item.Id);
            item.Handle = handle;
            AddInternal(item);
            return item;
        }

        /// <summary>
        /// Inserts an item before another in a gengrid widget. This inserts an item before another in the gengrid.
        /// </summary>
        /// <param name="itemClass">The itemClass defines how to display the data.</param>
        /// <param name="data">The item data.</param>
        /// <param name="before">The item before which to place this new one.</param>
        /// <returns>Return a gengrid item that contains data and itemClass./></returns>
        /// <seealso cref="GenItemClass"/>
        /// <seealso cref="GenGridItem"/>
        public GenGridItem InsertBefore(GenItemClass itemClass, object data, GenGridItem before)
        {
            GenGridItem item = new GenGridItem(data, itemClass);
            IntPtr handle = Interop.Elementary.elm_gengrid_item_insert_before(RealHandle, itemClass.UnmanagedPtr, (IntPtr)item.Id, before, null, (IntPtr)item.Id);
            item.Handle = handle;
            AddInternal(item);
            return item;
        }

        /// <summary>
        /// Inserts an item before another in a gengrid widget. This inserts an item after another in the gengrid.
        /// </summary>
        /// <param name="itemClass">The itemClass defines how to display the data.</param>
        /// <param name="data">The item data.</param>
        /// <param name="after">The item after which to place this new one.</param>
        /// <returns>Return a gengrid item that contains data and itemClass.</returns>
        /// <seealso cref="GenItemClass"/>
        /// <seealso cref="GenGridItem"/>
        public GenGridItem InsertAfter(GenItemClass itemClass, object data, GenGridItem after)
        {
            GenGridItem item = new GenGridItem(data, itemClass);
            IntPtr handle = Interop.Elementary.elm_gengrid_item_insert_after(RealHandle, itemClass.UnmanagedPtr, (IntPtr)item.Id, after, null, (IntPtr)item.Id);
            item.Handle = handle;
            AddInternal(item);
            return item;
        }

        /// <summary>
        /// Insert an item in a gengrid widget using a user-defined sort function.
        /// </summary>
        /// <param name="itemClass">The itemClass defines how to display the data.</param>
        /// <param name="data">The item data.</param>
        /// <param name="func">User defined comparison function that defines the sort order based on gengrid item and its data.</param>
        /// <returns>Return a gengrid item that contains data and itemClass.</returns>
        public GenGridItem InsertSorted(GenItemClass itemClass, object data, Comparison<GenGridItem> comparison)
        {
            Interop.Elementary.Eina_Compare_Cb compareCallback = (handle1, handle2) =>
            {
                GenGridItem item1 = ItemObject.GetItemByHandle(handle1) as GenGridItem;
                GenGridItem item2 = ItemObject.GetItemByHandle(handle2) as GenGridItem;
                return comparison(item1, item2);
            };

            GenGridItem item = new GenGridItem(data, itemClass);

            IntPtr handle = Interop.Elementary.elm_gengrid_item_sorted_insert(RealHandle, itemClass.UnmanagedPtr, (IntPtr)item.Id, compareCallback, null, (IntPtr)item.Id);
            item.Handle = handle;
            AddInternal(item);
            return item;
        }

        /// <summary>
        /// Shows a given item to the visible area of a gengrid.
        /// </summary>
        /// <param name="item">The gengrid item to display.</param>
        /// <param name="position">The position of the item in the viewport.</param>
        /// <param name="animated">The type of how to show the item.</param>
        /// <remarks>
        /// If animated is true, the gengrid shows item by scrolling if it's not fully visible.
        /// If animated is false, the gengrid shows item by jumping if it's not fully visible.
        /// </remarks>
        /// <seealso cref="ScrollToPosition"/>
        public void ScrollTo(GenGridItem item, ScrollToPosition position, bool animated)
        {
            if (animated)
            {
                Interop.Elementary.elm_gengrid_item_bring_in(item.Handle, (int)position);
            }
            else
            {
                Interop.Elementary.elm_gengrid_item_show(item.Handle, (int)position);
            }
        }

        /// <summary>
        /// Updates the contents of all the realized items.
        /// This updates all realized items by calling all the <see cref="GenItemClass"/> again to get the content, text, and states.
        /// Use this when the original item data has changed and the changes are desired to reflect.
        /// </summary>
        /// <remarks>
        /// <see cref="GenItem.Update()"/> to update just one item.
        /// </remarks>
        public void UpdateRealizedItems()
        {
            Interop.Elementary.elm_gengrid_realized_items_update(RealHandle);
        }

        /// <summary>
        /// Removes all items from a given gengrid widget.
        /// This removes(and deletes) all items in obj, making it empty.
        /// </summary>
        /// <remarks>
        /// <see cref="ItemObject.Delete()"/> to delete just one item.
        /// </remarks>
        public void Clear()
        {
            Interop.Elementary.elm_gengrid_clear(RealHandle);
        }

        /// <summary>
        /// Get the item that is at the x, y canvas coords.
        /// </summary>
        /// <param name="x">The input x coordinate</param>
        /// <param name="y">The input y coordinate</param>
        /// <param name="positionX">The position relative to the item returned here.
        /// -1, 0 or 1, depending if the coordinate is on the left portion of that item(-1), on the middle section(0) or on the right part(1).
        /// </param>
        /// <param name="positionY">The position relative to the item returned here
        /// -1, 0 or 1, depending if the coordinate is on the upper portion of that item (-1), on the middle section (0) or on the lower part (1).
        /// </param>
        /// <returns></returns>
        public GenGridItem GetItemByPosition(int x, int y, out int portionX, out int portionY)
        {
            IntPtr handle = Interop.Elementary.elm_gengrid_at_xy_item_get(RealHandle, x, y, out portionX, out portionY);
            return ItemObject.GetItemByHandle(handle) as GenGridItem;
        }

        protected override IntPtr CreateHandle(EvasObject parent)
        {
            IntPtr handle = Interop.Elementary.elm_layout_add(parent.Handle);
            Interop.Elementary.elm_layout_theme_set(handle, "layout", "elm_widget", "default");

            RealHandle = Interop.Elementary.elm_gengrid_add(handle);
            Interop.Elementary.elm_object_part_content_set(handle, "elm.swallow.content", RealHandle);

            return handle;
        }

        void InitializeSmartEvent()
        {
            _selected = new SmartEvent<GenGridItemEventArgs>(this, this.RealHandle, "selected", GenGridItemEventArgs.CreateFromSmartEvent);
            _unselected = new SmartEvent<GenGridItemEventArgs>(this, this.RealHandle, "unselected", GenGridItemEventArgs.CreateFromSmartEvent);
            _activated = new SmartEvent<GenGridItemEventArgs>(this, this.RealHandle, "activated", GenGridItemEventArgs.CreateFromSmartEvent);
            _pressed = new SmartEvent<GenGridItemEventArgs>(this, this.RealHandle, "pressed", GenGridItemEventArgs.CreateFromSmartEvent);
            _released = new SmartEvent<GenGridItemEventArgs>(this, this.RealHandle, "released", GenGridItemEventArgs.CreateFromSmartEvent);
            _doubleClicked = new SmartEvent<GenGridItemEventArgs>(this, this.RealHandle, "clicked,double", GenGridItemEventArgs.CreateFromSmartEvent);
            _realized = new SmartEvent<GenGridItemEventArgs>(this, this.RealHandle, "realized", GenGridItemEventArgs.CreateFromSmartEvent);
            _unrealized = new SmartEvent<GenGridItemEventArgs>(this, this.RealHandle, "unrealized", GenGridItemEventArgs.CreateFromSmartEvent);
            _longpressed = new SmartEvent<GenGridItemEventArgs>(this, this.RealHandle, "longpressed", GenGridItemEventArgs.CreateFromSmartEvent);
            _changed = new SmartEvent(this, this.RealHandle, "changed");

            _selected.On += (s, e) => { if (e.Item != null) ItemSelected?.Invoke(this, e); };
            _unselected.On += (s, e) => { if (e.Item != null) ItemUnselected?.Invoke(this, e); };
            _activated.On += (s, e) => { if (e.Item != null) ItemActivated?.Invoke(this, e); };
            _pressed.On += (s, e) => { if (e.Item != null) ItemPressed?.Invoke(this, e); };
            _released.On += (s, e) => { if (e.Item != null) ItemReleased?.Invoke(this, e); };
            _doubleClicked.On += (s, e) => { if (e.Item != null) ItemDoubleClicked?.Invoke(this, e); };
            _realized.On += (s, e) => { if (e.Item != null) ItemRealized?.Invoke(this, e); };
            _unrealized.On += (s, e) => { if (e.Item != null) ItemUnrealized?.Invoke(this, e); };
            _longpressed.On += (s, e) => { if (e.Item != null) ItemLongPressed?.Invoke(this, e); };
            _changed.On += (s, e) => { Changed?.Invoke(this, e); };
        }

        void AddInternal(GenGridItem item)
        {
            _children.Add(item);
            item.Deleted += Item_Deleted;
        }

        void Item_Deleted(object sender, EventArgs e)
        {
            _children.Remove((GenGridItem)sender);
        }
    }
}