Merge "Added GenList default mode (Compress)" into tizen
[platform/core/csapi/tizenfx.git] / src / ElmSharp / ElmSharp / GenList.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
20 namespace ElmSharp
21 {
22     /// <summary>
23     /// Enumeration for setting genlist item type.
24     /// </summary>
25     public enum GenListItemType
26     {
27         /// <summary>
28         /// if Normal is set then this item is normal item.
29         /// </summary>
30         Normal = 0,
31         /// <summary>
32         /// If tree is set then this item is displayed as an item that is able to expand and have child items.
33         /// </summary>
34         Tree = (1 << 0),
35         /// <summary>
36         /// if Group is set then this item is group index item that is displayed at the top until the next group comes.
37         /// </summary>
38         Group = (1 << 1),
39     }
40
41     /// <summary>
42     /// Enumeration for setting genlist's resizing behavior, transverse axis scrolling and items cropping.
43     /// </summary>
44     public enum GenListMode
45     {
46         /// <summary>
47         /// The genlist won't set any of its size hints to inform how a possible container should resize it.
48         /// Then, if it's not created as a "resize object", it might end with zeroed dimensions.
49         /// The genlist will respect the container's geometry and, if any of its items won't fit into its transverse axis, one won't be able to scroll it in that direction.
50         /// </summary>
51         Compress = 0,
52         /// <summary>
53         /// This is the same as Compress, with the exception that if any of its items won't fit into its transverse axis, one will be able to scroll it in that direction.
54         /// </summary>
55         Scroll,
56         /// <summary>
57         /// Sets a minimum size hint on the genlist object, so that containers may respect it (and resize itself to fit the child properly).
58         /// More specifically, a minimum size hint will be set for its transverse axis, so that the largest item in that direction fits well.
59         /// This is naturally bound by the genlist object's maximum size hints, set externally.
60         /// </summary>
61         Limit,
62         /// <summary>
63         /// Besides setting a minimum size on the transverse axis, just like on Limit, the genlist will set a minimum size on th longitudinal axis, trying to reserve space to all its children to be visible at a time.
64         /// This is naturally bound by the genlist object's maximum size hints, set externally.
65         /// </summary>
66         Expand
67     }
68
69     /// <summary>
70     /// It inherits System.EventArgs.
71     /// It contains Item which is <see cref="GenListItem"/> type.
72     /// All events of GenList contain GenListItemEventArgs as a parameter.
73     /// </summary>
74     public class GenListItemEventArgs : EventArgs
75     {
76         /// <summary>
77         /// Gets or sets GenList item. The return type is <see cref="GenListItem"/>.
78         /// </summary>
79         public GenListItem Item { get; set; }
80
81         internal static GenListItemEventArgs CreateFromSmartEvent(IntPtr data, IntPtr obj, IntPtr info)
82         {
83             GenListItem item = ItemObject.GetItemByHandle(info) as GenListItem;
84             return new GenListItemEventArgs() { Item = item };
85         }
86     }
87
88     /// <summary>
89     /// Enumeration that defines where to position the item in the genlist.
90     /// </summary>
91     public enum ScrollToPosition
92     {
93         /// <summary>
94         /// Scrolls to nowhere.
95         /// </summary>
96         None = 0,
97         /// <summary>
98         /// Scrolls to the nearest viewport.
99         /// </summary>
100         In = (1 << 0),
101         /// <summary>
102         /// Scrolls to the top of the viewport.
103         /// </summary>
104         Top = (1 << 1),
105         /// <summary>
106         /// Scrolls to the middle of the viewport.
107         /// </summary>
108         Middle = (1 << 2),
109         /// <summary>
110         /// Scrolls to the bottom of the viewport.
111         /// </summary>
112         Bottom = (1 << 3)
113     }
114
115     /// <summary>
116     /// It inherits <see cref="Layout"/>.
117     /// The GenList is a widget that aims to have more expansive list than the simple <see cref="List"/> in ElmSharp that could have more flexible items and allow many more entries while still being fast and low on memory usage.
118     /// At the same time it was also made to be able to do tree structures.
119     /// But the price to pay is more complexity when it comes to usage.
120     /// If all you want is a simple list with icons and a single text, use the <see cref="List"/> widget.
121     /// </summary>
122     public class GenList : Layout
123     {
124         HashSet<GenListItem> _children = new HashSet<GenListItem>();
125
126         SmartEvent<GenListItemEventArgs> _selected;
127         SmartEvent<GenListItemEventArgs> _unselected;
128         SmartEvent<GenListItemEventArgs> _activated;
129         SmartEvent<GenListItemEventArgs> _pressed;
130         SmartEvent<GenListItemEventArgs> _released;
131         SmartEvent<GenListItemEventArgs> _doubleClicked;
132         SmartEvent<GenListItemEventArgs> _expanded;
133         SmartEvent<GenListItemEventArgs> _realized;
134         SmartEvent<GenListItemEventArgs> _unrealized;
135         SmartEvent<GenListItemEventArgs> _longpressed;
136         SmartEvent<GenListItemEventArgs> _moved;
137         SmartEvent<GenListItemEventArgs> _movedAfter;
138         SmartEvent<GenListItemEventArgs> _movedBefore;
139         SmartEvent _scrollAnimationStarted;
140         SmartEvent _scrollAnimationStopped;
141         SmartEvent _changed;
142
143         /// <summary>
144         /// Creates and initializes a new instance of the GenList class.
145         /// </summary>
146         /// <param name="parent">The parent is a given container which will be attached by GenList as a child. It's <see cref="EvasObject"/> type.</param>
147         public GenList(EvasObject parent) : base(parent)
148         {
149             ListMode = GenListMode.Compress;
150             InitializeSmartEvent();
151         }
152
153         /// <summary>
154         /// Gets or sets whether the homogeneous mode is enabled.
155         /// </summary>
156         /// <remarks>
157         /// If true, the genlist items have same height and width.
158         /// </remarks>
159         public bool Homogeneous
160         {
161             get
162             {
163                 return Interop.Elementary.elm_genlist_homogeneous_get(RealHandle);
164             }
165             set
166             {
167                 Interop.Elementary.elm_genlist_homogeneous_set(RealHandle, value);
168             }
169         }
170
171         /// <summary>
172         /// Gets or sets the horizontal stretching mode. This mode used for sizing items horizontally.
173         /// The default value is <see cref="GenListMode.Scroll"/> which means that if items are too wide to fit, the scroller scrolls horizontally.
174         /// If set <see cref="GenListMode.Compress"/> which means that the item width is fixed (restricted to a minimum of) to the list width when calculating its size in order to allow the height to be calculated based on it.
175         /// If set <see cref="GenListMode.Limit"/> which means that items are expanded to the viewport width and limited to that size.
176         /// if set <see cref="GenListMode.Expand"/> which means that genlist try to reserve space to all its items to be visible at a time.
177         /// </summary>
178         /// <remarks>
179         /// Compress makes genlist resize slower as it recalculates every item height again whenever the list width changes.
180         /// The homogeneous mode is so that all items in the genlist are of the same width/height. With Compress, genlist items are initialized fast.
181         /// However, there are no sub-objects in the genlist which can be on the flying resizable (such as TEXTBLOCK).
182         /// If so, then some dynamic resizable objects in the genlist would not be diplayed properly.
183         /// </remarks>
184         public GenListMode ListMode
185         {
186             get
187             {
188                 return (GenListMode)Interop.Elementary.elm_genlist_mode_get(RealHandle);
189             }
190             set
191             {
192                 Interop.Elementary.elm_genlist_mode_set(RealHandle, (int)value);
193             }
194         }
195
196         /// <summary>
197         /// Gets the first item in the genlist.
198         /// </summary>
199         public GenListItem FirstItem
200         {
201             get
202             {
203                 IntPtr handle = Interop.Elementary.elm_genlist_first_item_get(RealHandle);
204                 return ItemObject.GetItemByHandle(handle) as GenListItem;
205             }
206         }
207
208         /// <summary>
209         /// Gets the last item in the genlist.
210         /// </summary>
211         public GenListItem LastItem
212         {
213             get
214             {
215                 IntPtr handle = Interop.Elementary.elm_genlist_last_item_get(RealHandle);
216                 return ItemObject.GetItemByHandle(handle) as GenListItem;
217             }
218         }
219
220         /// <summary>
221         /// Gets or sets the reorder mode.
222         /// After turning on the reorder mode, longpress on a normal item triggers reordering of the item.
223         /// You can move the item up and down. However, reordering does not work with group items.
224         /// </summary>
225         public bool ReorderMode
226         {
227             get
228             {
229                 return Interop.Elementary.elm_genlist_reorder_mode_get(RealHandle);
230             }
231             set
232             {
233                 Interop.Elementary.elm_genlist_reorder_mode_set(RealHandle, value);
234             }
235         }
236
237         /// <summary>
238         /// ItemSelected is raised when a new genlist item is selected.
239         /// </summary>
240         public event EventHandler<GenListItemEventArgs> ItemSelected;
241
242         /// <summary>
243         /// ItemUnselected is raised when the genlist item is Unselected.
244         /// </summary>
245         public event EventHandler<GenListItemEventArgs> ItemUnselected;
246
247         /// <summary>
248         /// ItemPressed is raised when a new genlist item is pressed.
249         /// </summary>
250         public event EventHandler<GenListItemEventArgs> ItemPressed;
251
252         /// <summary>
253         /// ItemReleased is raised when a new genlist item is released.
254         /// </summary>
255         public event EventHandler<GenListItemEventArgs> ItemReleased;
256
257         /// <summary>
258         /// ItemActivated is raised when a new genlist item is double clicked or pressed (enter|return|spacebar).
259         /// </summary>
260         public event EventHandler<GenListItemEventArgs> ItemActivated;
261
262         /// <summary>
263         /// ItemDoubleClicked is raised when a new genlist item is double clicked.
264         /// </summary>
265         public event EventHandler<GenListItemEventArgs> ItemDoubleClicked;
266
267         /// <summary>
268         /// ItemExpanded is raised when a new genlist item is indicated to expand.
269         /// </summary>
270         public event EventHandler<GenListItemEventArgs> ItemExpanded;
271
272         /// <summary>
273         /// ItemRealized is raised when a new genlist item is created as a real object.
274         /// </summary>
275         public event EventHandler<GenListItemEventArgs> ItemRealized;
276
277         /// <summary>
278         /// ItemUnrealized is raised when a new genlist item is unrealized.
279         /// After calling unrealize, the item's content objects are deleted and the item object itself is deleted or is put into a floating cache.
280         /// </summary>
281         public event EventHandler<GenListItemEventArgs> ItemUnrealized;
282
283         /// <summary>
284         /// ItemLongPressed is raised when a genlist item is pressed for a certain amount of time. By default it's 1 second.
285         /// </summary>
286         public event EventHandler<GenListItemEventArgs> ItemLongPressed;
287
288         /// <summary>
289         /// ItemMoved is raised when a genlist item is moved in the reorder mode.
290         /// </summary>
291         public event EventHandler<GenListItemEventArgs> ItemMoved;
292
293         /// <summary>
294         /// ItemMovedAfter is raised when a genlist item is moved after another item in the reorder mode.
295         /// To get the relative previous item, use <see cref="GenListItem.Previous"/>.
296         /// </summary>
297         public event EventHandler<GenListItemEventArgs> ItemMovedAfter;
298
299         /// <summary>
300         /// ItemMovedBefore is raised when a genlist item is moved before another item in the reorder mode.
301         /// To get the relative next item, use <see cref="GenListItem.Next"/>.
302         /// </summary>
303         public event EventHandler<GenListItemEventArgs> ItemMovedBefore;
304
305         /// <summary>
306         /// Changed is raised when genlist is changed.
307         /// </summary>
308         public event EventHandler Changed
309         {
310             add { _changed.On += value; }
311             remove { _changed.On -= value; }
312         }
313
314         /// <summary>
315         /// ScrollAnimationStarted is raised when scrolling animation has started.
316         /// </summary>
317         public event EventHandler ScrollAnimationStarted
318         {
319             add { _scrollAnimationStarted.On += value; }
320             remove { _scrollAnimationStarted.On -= value; }
321         }
322
323         /// <summary>
324         /// ScrollAnimationStopped is raised when scrolling animation has stopped.
325         /// </summary>
326         public event EventHandler ScrollAnimationStopped
327         {
328             add { _scrollAnimationStopped.On += value; }
329             remove { _scrollAnimationStopped.On -= value; }
330         }
331
332         /// <summary>
333         /// Appends a new item to the end of a given genlist widget.
334         /// </summary>
335         /// <param name="itemClass">The itemClass defines how to display the data.</param>
336         /// <param name="data">The item data.</param>
337         /// <returns>Return a new added genlist item that contains data and itemClass.</returns>
338         /// <seealso cref="GenItemClass"/>
339         /// <seealso cref="GenListItem"/>
340         public GenListItem Append(GenItemClass itemClass, object data)
341         {
342             return Append(itemClass, data, GenListItemType.Normal);
343         }
344
345         /// <summary>
346         /// Appends a new item with <see cref="GenListItemType"/> to the end of a given genlist widget.
347         /// </summary>
348         /// <param name="itemClass">The itemClass defines how to display the data.</param>
349         /// <param name="data">The item data.</param>
350         /// <param name="type">The genlist item type.</param>
351         /// <returns>Return a new added genlist item that contains data and itemClass.</returns>
352         public GenListItem Append(GenItemClass itemClass, object data, GenListItemType type)
353         {
354             return Append(itemClass, data, type, null);
355         }
356
357         /// <summary>
358         /// Appends a new item with <see cref="GenListItemType"/> to the end of a given genlist widget or the end of the children list if the parent is given.
359         /// </summary>
360         /// <param name="itemClass">The itemClass defines how to display the data.</param>
361         /// <param name="data">The item data.</param>
362         /// <param name="type">The genlist item type.</param>
363         /// <param name="parent">The parent item, otherwise null if there is no parent item.</param>
364         /// <returns>Return a new added genlist item that contains data and itemClass.</returns>
365         public GenListItem Append(GenItemClass itemClass, object data, GenListItemType type, GenListItem parent)
366         {
367             GenListItem item = new GenListItem(data, itemClass);
368             IntPtr handle = Interop.Elementary.elm_genlist_item_append(RealHandle, itemClass.UnmanagedPtr, (IntPtr)item.Id, parent, (int)type, null, (IntPtr)item.Id);
369             item.Handle = handle;
370             AddInternal(item);
371             return item;
372         }
373
374         /// <summary>
375         /// Prepends a new item to the beginning of a given genlist widget.
376         /// </summary>
377         /// <param name="itemClass">The itemClass defines how to display the data.</param>
378         /// <param name="data">The item data.</param>
379         /// <returns>Return a new added genlist item that contains data and itemClass.</returns>
380         public GenListItem Prepend(GenItemClass itemClass, object data)
381         {
382             return Prepend(itemClass, data, GenListItemType.Normal);
383         }
384
385         /// <summary>
386         /// Prepends a new item with <see cref="GenListItemType"/> to the beginning of a given genlist widget.
387         /// </summary>
388         /// <param name="itemClass">The itemClass defines how to display the data.</param>
389         /// <param name="data">The item data.</param>
390         /// <param name="type">The genlist item type.</param>
391         /// <param name="parent">The parent item, otherwise null if there is no parent item.</param>
392         /// <returns>Return a new added genlist item that contains data and itemClass.</returns>
393         public GenListItem Prepend(GenItemClass itemClass, object data, GenListItemType type)
394         {
395             return Prepend(itemClass, data, type, null);
396         }
397
398         /// <summary>
399         /// Prepends a new item with <see cref="GenListItemType"/> to the beginning of a given genlist widget or the beginning of the children list if the parent is given.
400         /// </summary>
401         /// <param name="itemClass">The itemClass defines how to display the data.</param>
402         /// <param name="data">The item data.</param>
403         /// <param name="type">The genlist item type.</param>
404         /// <param name="parent">The parent item, otherwise null if there is no parent item.</param>
405         /// <returns>Return a new added genlist item that contains data and itemClass.</returns>
406         public GenListItem Prepend(GenItemClass itemClass, object data, GenListItemType type, GenListItem parent)
407         {
408             GenListItem item = new GenListItem(data, itemClass);
409             IntPtr handle = Interop.Elementary.elm_genlist_item_prepend(RealHandle, itemClass.UnmanagedPtr, (IntPtr)item.Id, parent, (int)type, null, (IntPtr)item.Id);
410             item.Handle = handle;
411             AddInternal(item);
412             return item;
413         }
414
415         /// <summary>
416         /// Inserts an item before another item in a genlist widget.
417         /// It is the same tree level or group as the item before which it is inserted.????
418         /// </summary>
419         /// <param name="itemClass">The itemClass defines how to display the data.</param>
420         /// <param name="data">The item data.</param>
421         /// <param name="before">The item before which to place this new one.</param>
422         /// <returns>Return a new added genlist item that contains data and itemClass.</returns>
423         public GenListItem InsertBefore(GenItemClass itemClass, object data, GenListItem before)
424         {
425             return InsertBefore(itemClass, data, before, GenListItemType.Normal);
426         }
427
428         /// <summary>
429         /// Inserts an item with <see cref="GenListItemType"/> before another item in a genlist widget.
430         /// It is the same tree level or group as the item before which it is inserted.????
431         /// </summary>
432         /// <param name="itemClass">The itemClass defines how to display the data.</param>
433         /// <param name="data">The item data.</param>
434         /// <param name="before">The item before which to place this new one.</param>
435         /// <param name="type">The genlist item type.</param>
436         /// <returns>Return a new added genlist item that contains data and itemClass.</returns>
437         public GenListItem InsertBefore(GenItemClass itemClass, object data, GenListItem before, GenListItemType type)
438         {
439             return InsertBefore(itemClass, data, before, type, null);
440         }
441
442         /// <summary>
443         /// Inserts an item with <see cref="GenListItemType"/> before another item under a parent in a genlist widget.
444         /// </summary>
445         /// <param name="itemClass">The itemClass defines how to display the data.</param>
446         /// <param name="data">The item data.</param>
447         /// <param name="before">The item before which to place this new one.</param>
448         /// <param name="type">The genlist item type.</param>
449         /// <param name="parent">The parent item, otherwise null if there is no parent item.</param>
450         /// <returns>Return a new added genlist item that contains data and itemClass.</returns>
451         public GenListItem InsertBefore(GenItemClass itemClass, object data, GenListItem before, GenListItemType type, GenListItem parent)
452         {
453             GenListItem item = new GenListItem(data, itemClass);
454             // insert before the `before` list item
455             IntPtr handle = Interop.Elementary.elm_genlist_item_insert_before(
456                 RealHandle, // genlist handle
457                 itemClass.UnmanagedPtr, // item class
458                 (IntPtr)item.Id, // data
459                 parent, // parent
460                 before, // before
461                 (int)type, // item type
462                 null, // select callback
463                 (IntPtr)item.Id); // callback data
464             item.Handle = handle;
465             AddInternal(item);
466             return item;
467         }
468
469         /// <summary>
470         /// Shows the given item with position type in a genlist.
471         /// When animated is true, genlist will jump to the given item and display it (by animatedly scrolling), if it is not fully visible. This may use animation and may take some time.
472         /// When animated is false, genlist will jump to the given item and display it (by jumping to that position), if it is not fully visible.
473         /// </summary>
474         /// <param name="item">The item to display.</param>
475         /// <param name="position">The position to show the given item to <see cref="ScrollToPosition"/>.</param>
476         /// <param name="animated">The animated indicates how to display the item, by scrolling or by jumping.</param>
477         public void ScrollTo(GenListItem item, ScrollToPosition position, bool animated)
478         {
479             if (animated)
480             {
481                 Interop.Elementary.elm_genlist_item_bring_in(item.Handle, (Interop.Elementary.Elm_Genlist_Item_Scrollto_Type)position);
482             }
483             else
484             {
485                 Interop.Elementary.elm_genlist_item_show(item.Handle, (Interop.Elementary.Elm_Genlist_Item_Scrollto_Type)position);
486             }
487         }
488
489         /// <summary>
490         /// Updates the content of all the realized items.
491         /// This updates all the realized items by calling all the <see cref="GenItemClass"/> again to get the content, text and states.
492         /// Use this when the original item data has changed and the changes are desired to reflect.
493         /// To update just one item, use <see cref="GenListItem.Update"/>.
494         /// </summary>
495         /// <seealso cref="GenListItem.Update"/>
496         public void UpdateRealizedItems()
497         {
498             Interop.Elementary.elm_genlist_realized_items_update(RealHandle);
499         }
500
501         /// <summary>
502         /// Removes all items from a given genlist widget.
503         /// This removes (and deletes) all items in obj, making it empty.
504         /// To delete just one item, use <see cref="ItemObject.Delete"/>.
505         /// </summary>
506         /// <seealso cref="ItemObject.Delete"/>
507         public void Clear()
508         {
509             Interop.Elementary.elm_genlist_clear(RealHandle);
510         }
511
512         protected override IntPtr CreateHandle(EvasObject parent)
513         {
514             IntPtr handle = Interop.Elementary.elm_layout_add(parent.Handle);
515             Interop.Elementary.elm_layout_theme_set(handle, "layout", "elm_widget", "default");
516
517             RealHandle = Interop.Elementary.elm_genlist_add(handle);
518             Interop.Elementary.elm_object_part_content_set(handle, "elm.swallow.content", RealHandle);
519
520             return handle;
521         }
522
523         void InitializeSmartEvent()
524         {
525             _selected = new SmartEvent<GenListItemEventArgs>(this, this.RealHandle, "selected", GenListItemEventArgs.CreateFromSmartEvent);
526             _unselected = new SmartEvent<GenListItemEventArgs>(this, this.RealHandle, "unselected", GenListItemEventArgs.CreateFromSmartEvent);
527             _activated = new SmartEvent<GenListItemEventArgs>(this, this.RealHandle, "activated", GenListItemEventArgs.CreateFromSmartEvent);
528             _pressed = new SmartEvent<GenListItemEventArgs>(this, this.RealHandle, "pressed", GenListItemEventArgs.CreateFromSmartEvent);
529             _released = new SmartEvent<GenListItemEventArgs>(this, this.RealHandle, "released", GenListItemEventArgs.CreateFromSmartEvent);
530             _doubleClicked = new SmartEvent<GenListItemEventArgs>(this, this.RealHandle, "clicked,double", GenListItemEventArgs.CreateFromSmartEvent);
531             _expanded = new SmartEvent<GenListItemEventArgs>(this, this.RealHandle, "expanded", GenListItemEventArgs.CreateFromSmartEvent);
532             _realized = new SmartEvent<GenListItemEventArgs>(this, this.RealHandle, "realized", GenListItemEventArgs.CreateFromSmartEvent);
533             _unrealized = new SmartEvent<GenListItemEventArgs>(this, this.RealHandle, "unrealized", GenListItemEventArgs.CreateFromSmartEvent);
534             _longpressed = new SmartEvent<GenListItemEventArgs>(this, this.RealHandle, "longpressed", GenListItemEventArgs.CreateFromSmartEvent);
535             _moved = new SmartEvent<GenListItemEventArgs>(this, this.RealHandle, "moved", GenListItemEventArgs.CreateFromSmartEvent);
536             _movedAfter = new SmartEvent<GenListItemEventArgs>(this, this.RealHandle, "moved,after", GenListItemEventArgs.CreateFromSmartEvent);
537             _movedBefore = new SmartEvent<GenListItemEventArgs>(this, this.RealHandle, "moved,before", GenListItemEventArgs.CreateFromSmartEvent);
538             _scrollAnimationStarted = new SmartEvent(this, this.RealHandle, "scroll,anim,start");
539             _scrollAnimationStopped = new SmartEvent(this, this.RealHandle, "scroll,anim,stop");
540             _changed = new SmartEvent(this, this.RealHandle, "changed");
541
542             _selected.On += (s, e) => { if (e.Item != null) ItemSelected?.Invoke(this, e); };
543             _unselected.On += (s, e) => { if (e.Item != null) ItemUnselected?.Invoke(this, e); };
544             _activated.On += (s, e) => { if (e.Item != null) ItemActivated?.Invoke(this, e); };
545             _pressed.On += (s, e) => { if (e.Item != null) ItemPressed?.Invoke(this, e); };
546             _released.On += (s, e) => { if (e.Item != null) ItemReleased?.Invoke(this, e); };
547             _doubleClicked.On += (s, e) => { if (e.Item != null) ItemDoubleClicked?.Invoke(this, e); };
548             _expanded.On += (s, e) => { if (e.Item != null) ItemExpanded?.Invoke(this, e); };
549             _realized.On += (s, e) => { if (e.Item != null) ItemRealized?.Invoke(this, e); };
550             _unrealized.On += (s, e) => { if (e.Item != null) ItemUnrealized?.Invoke(this, e); };
551             _longpressed.On += (s, e) => { if (e.Item != null) ItemLongPressed?.Invoke(this, e); };
552             _moved.On += (s, e) => { if (e.Item != null) ItemMoved?.Invoke(this, e); };
553             _movedAfter.On += (s, e) => { if (e.Item != null) ItemMovedAfter?.Invoke(this, e); };
554             _movedBefore.On += (s, e) => { if (e.Item != null) ItemMovedBefore?.Invoke(this, e); };
555         }
556
557         void AddInternal(GenListItem item)
558         {
559             _children.Add(item);
560             item.Deleted += Item_Deleted;
561         }
562
563         void Item_Deleted(object sender, EventArgs e)
564         {
565             _children.Remove((GenListItem)sender);
566         }
567     }
568 }