[NUI] TCSACR-226 code change (#1032)
[platform/core/csapi/tizenfx.git] / src / ElmSharp / ElmSharp / GenGrid.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     /// It inherits System.EventArgs.
24     /// It contains the item which is the <see cref="GenGridItem"/> type.
25     /// All events of the GenGrid contain GenGridItemEventArgs as a parameter.
26     /// </summary>
27     /// <since_tizen> preview </since_tizen>
28     public class GenGridItemEventArgs : EventArgs
29     {
30         /// <summary>
31         /// Gets or sets the gengrid item. The return type is <see cref="GenGridItem"/>.
32         /// </summary>
33         /// <since_tizen> preview </since_tizen>
34         public GenGridItem Item { get; set; }
35
36         internal static GenGridItemEventArgs CreateFromSmartEvent(IntPtr data, IntPtr obj, IntPtr info)
37         {
38             GenGridItem item = ItemObject.GetItemByHandle(info) as GenGridItem;
39             return new GenGridItemEventArgs { Item = item };
40         }
41     }
42
43     /// <summary>
44     /// It inherits <see cref="Layout"/>.
45     /// The GenGrid is a widget that aims to position objects in a grid layout, while actually creating and rendering only the visible ones.
46     /// It has two directions in which a given GenGrid widget expands while placing its items, horizontal and vertical.
47     /// The gengrid items are represented through the <see cref="GenItemClass"/> definition field details.
48     /// </summary>
49     /// <since_tizen> preview </since_tizen>
50     public class GenGrid : Layout
51     {
52         HashSet<GenGridItem> _children = new HashSet<GenGridItem>();
53
54         SmartEvent<GenGridItemEventArgs> _selected;
55         SmartEvent<GenGridItemEventArgs> _unselected;
56         SmartEvent<GenGridItemEventArgs> _activated;
57         SmartEvent<GenGridItemEventArgs> _pressed;
58         SmartEvent<GenGridItemEventArgs> _released;
59         SmartEvent<GenGridItemEventArgs> _doubleClicked;
60         SmartEvent<GenGridItemEventArgs> _realized;
61         SmartEvent<GenGridItemEventArgs> _unrealized;
62         SmartEvent<GenGridItemEventArgs> _longpressed;
63         SmartEvent<GenGridItemEventArgs> _focused;
64         SmartEvent<GenGridItemEventArgs> _unfocused;
65         SmartEvent _changed;
66
67         /// <summary>
68         /// Creates and initializes a new instance of the GenGrid class.
69         /// </summary>
70         /// <param name="parent">The parent is a given container which will be attached by GenGrid as a child. It's the <see cref="EvasObject"/> type.</param>
71         /// <since_tizen> preview </since_tizen>
72         public GenGrid(EvasObject parent) : base(parent)
73         {
74             InitializeSmartEvent();
75         }
76
77         /// <summary>
78         /// ItemSelected is raised when a new GenGrid item is selected.
79         /// </summary>
80         /// <since_tizen> preview </since_tizen>
81         public event EventHandler<GenGridItemEventArgs> ItemSelected;
82
83         /// <summary>
84         /// ItemUnselected is raised when the gengrid item is unselected.
85         /// </summary>
86         /// <since_tizen> preview </since_tizen>
87         public event EventHandler<GenGridItemEventArgs> ItemUnselected;
88
89         /// <summary>
90         /// ItemPressed is raised when a new gengrid item is pressed.
91         /// </summary>
92         /// <since_tizen> preview </since_tizen>
93         public event EventHandler<GenGridItemEventArgs> ItemPressed;
94
95         /// <summary>
96         /// ItemReleased is raised when a new gengrid item is released.
97         /// </summary>
98         /// <since_tizen> preview </since_tizen>
99         public event EventHandler<GenGridItemEventArgs> ItemReleased;
100
101         /// <summary>
102         /// ItemActivated is raised when a new gengrid item is double-clicked or pressed (enter|return|spacebar).
103         /// </summary>
104         /// <since_tizen> preview </since_tizen>
105         public event EventHandler<GenGridItemEventArgs> ItemActivated;
106
107         /// <summary>
108         /// ItemDoubleClicked is raised when a new gengrid item is double-clicked.
109         /// </summary>
110         /// <since_tizen> preview </since_tizen>
111         public event EventHandler<GenGridItemEventArgs> ItemDoubleClicked;
112
113         /// <summary>
114         /// ItemRealized is raised when a gengrid item is implemented through <see cref="GenItemClass"/>.
115         /// </summary>
116         /// <since_tizen> preview </since_tizen>
117         public event EventHandler<GenGridItemEventArgs> ItemRealized;
118
119         /// <summary>
120         /// ItemUnrealized is raised when the gengrid item is deleted.
121         /// </summary>
122         /// <since_tizen> preview </since_tizen>
123         public event EventHandler<GenGridItemEventArgs> ItemUnrealized;
124
125         /// <summary>
126         /// ItemLongPressed is raised when a gengrid item is pressed for a certain amount of time. By default it's 1 second.
127         /// </summary>
128         /// <since_tizen> preview </since_tizen>
129         public event EventHandler<GenGridItemEventArgs> ItemLongPressed;
130
131         /// <summary>
132         /// ItemFocussed is raised when a gengrid item has received focus.
133         /// </summary>
134         /// <since_tizen> preview </since_tizen>
135         public event EventHandler<GenGridItemEventArgs> ItemFocused;
136
137         /// <summary>
138         /// ItemUnfocussed is raised when a gengrid item has lost focus.
139         /// </summary>
140         /// <since_tizen> preview </since_tizen>
141         public event EventHandler<GenGridItemEventArgs> ItemUnfocused;
142
143         /// <summary>
144         ///  Changed is raised when an item is added, removed, resized or moved and when the gengrid is resized or gets "horizontal" property changes.
145         /// </summary>
146         /// <since_tizen> preview </since_tizen>
147         public event EventHandler Changed;
148
149         /// <summary>
150         /// Gets or sets the item's grid alignment along X-axis within a given GenGrid widget.
151         /// Accepted values are in the 0.0 to 1.0 range, with the special value -1.0 used to specify "justify" or "fill" by some users.
152         /// By default, value is 0.0, meaning that the gengrid has its items grid placed exactly in the left along X-axis.
153         /// </summary>
154         /// <since_tizen> preview </since_tizen>
155         public double ItemAlignmentX
156         {
157             get
158             {
159                 double align;
160                 Interop.Elementary.elm_gengrid_align_get(RealHandle, out align, IntPtr.Zero);
161                 return align;
162             }
163             set
164             {
165                 double aligny = ItemAlignmentY;
166                 Interop.Elementary.elm_gengrid_align_set(RealHandle, value, aligny);
167             }
168         }
169
170         /// <summary>
171         /// Gets or sets the item's grid alignment on Y-axis within a given GenGrid widget.
172         /// Accepted values are in the 0.0 to 1.0 range, with the special value -1.0 used to specify "justify" or "fill" by some users.
173         /// By default, value is 0.0, meaning that the gengrid has its items grid placed exactly in the top along Y-axis.
174         /// </summary>
175         /// <since_tizen> preview </since_tizen>
176         public double ItemAlignmentY
177         {
178             get
179             {
180                 double align;
181                 Interop.Elementary.elm_gengrid_align_get(RealHandle, IntPtr.Zero, out align);
182                 return align;
183             }
184             set
185             {
186                 double alignx = ItemAlignmentX;
187                 Interop.Elementary.elm_gengrid_align_set(RealHandle, alignx, value);
188             }
189         }
190
191         /// <summary>
192         /// Gets or sets the manner in which the items grid is filled within a given GenGrid widget.
193         /// It is filled if true, otherwise not filled if false.
194         /// </summary>
195         /// <since_tizen> preview </since_tizen>
196         public bool FillItems
197         {
198             get
199             {
200                 return Interop.Elementary.elm_gengrid_filled_get(RealHandle);
201             }
202             set
203             {
204                 Interop.Elementary.elm_gengrid_filled_set(RealHandle, value);
205             }
206         }
207
208         /// <summary>
209         /// Gets or sets whether multi-selection is enabled or disabled for a given GenGrid widget.
210         /// </summary>
211         /// <remarks>
212         /// Multi-selection is the ability to have more than one item selected, on a given gengrid, simultaneously.
213         /// When it is enabled, a sequence of clicks on different items makes them all selected, progressively.
214         /// A click on an already selected item unselects it. If interacting via the keyboard, multi-selection is enabled while holding the "Shift" key.
215         /// By default, multi-selection is disabled.
216         /// </remarks>
217         /// <since_tizen> preview </since_tizen>
218         public bool MultipleSelection
219         {
220             get
221             {
222                 return Interop.Elementary.elm_gengrid_multi_select_get(RealHandle);
223             }
224             set
225             {
226                 Interop.Elementary.elm_gengrid_multi_select_set(RealHandle, value);
227             }
228         }
229
230         /// <summary>
231         /// Gets or sets the width for the items of a given GenGrid widget.
232         /// </summary>
233         /// <remarks>
234         /// A gengrid, after creation, still has no information on the size to give to each of its cells.
235         /// The default width and height just are one finger wide.
236         /// Use this property to force a custom width for your items, making them as big as you wish.
237         /// </remarks>
238         /// <since_tizen> preview </since_tizen>
239         public int ItemWidth
240         {
241             get
242             {
243                 int width;
244                 Interop.Elementary.elm_gengrid_item_size_get(RealHandle, out width, IntPtr.Zero);
245                 return width;
246             }
247             set
248             {
249                 int height = ItemHeight;
250                 Interop.Elementary.elm_gengrid_item_size_set(RealHandle, value, height);
251             }
252         }
253
254         /// <summary>
255         /// Gets or sets the height for the items of a given GenGrid widget.
256         /// </summary>
257         /// <remarks>
258         /// A gengrid, after creation, still has no information on the size to give to each of its cells.
259         /// The default width and height just are one finger wide.
260         /// Use this property to force a custom height for your items, making them as big as you wish.
261         /// </remarks>
262         /// <since_tizen> preview </since_tizen>
263         public int ItemHeight
264         {
265             get
266             {
267                 int height;
268                 Interop.Elementary.elm_gengrid_item_size_get(RealHandle, IntPtr.Zero, out height);
269                 return height;
270             }
271             set
272             {
273                 int width = ItemWidth;
274                 Interop.Elementary.elm_gengrid_item_size_set(RealHandle, width, value);
275             }
276         }
277
278         /// <summary>
279         /// Gets or sets the gengrid select mode by <see cref="GenItemSelectionMode"/>.
280         /// </summary>
281         /// <since_tizen> preview </since_tizen>
282         public GenItemSelectionMode SelectionMode
283         {
284             get
285             {
286                 return (GenItemSelectionMode)Interop.Elementary.elm_gengrid_select_mode_get(RealHandle);
287             }
288             set
289             {
290                 Interop.Elementary.elm_gengrid_select_mode_set(RealHandle, (int)value);
291             }
292         }
293
294         /// <summary>
295         /// Gets or sets the direction for which a given GenGrid widget expands while placing its items.
296         /// </summary>
297         /// <remarks>
298         /// 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.
299         /// 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.
300         /// </remarks>
301         /// <since_tizen> preview </since_tizen>
302         public bool IsHorizontal
303         {
304             get
305             {
306                 return Interop.Elementary.elm_gengrid_horizontal_get(RealHandle);
307             }
308             set
309             {
310                 Interop.Elementary.elm_gengrid_horizontal_set(RealHandle, value);
311             }
312         }
313
314         /// <summary>
315         /// Gets or sets whether the gengrid items should be highlighted when an item is selected.
316         /// </summary>
317         /// <since_tizen> preview </since_tizen>
318         public bool IsHighlight
319         {
320             get
321             {
322                 return Interop.Elementary.elm_gengrid_highlight_mode_get(RealHandle);
323             }
324             set
325             {
326                 Interop.Elementary.elm_gengrid_highlight_mode_set(RealHandle, value);
327             }
328         }
329
330         /// <summary>
331         /// Sets or gets the value of HorizontalScrollBarVisiblePolicy.
332         /// </summary>
333         /// <remarks>
334         /// ScrollBarVisiblePolicy.Auto means the horizontal scrollbar is made visible if it is needed, and otherwise kept hidden.
335         /// ScrollBarVisiblePolicy.Visible turns it on all the time, and ScrollBarVisiblePolicy.Invisible always keeps it off.
336         /// </remarks>
337         /// <since_tizen> preview </since_tizen>
338         public ScrollBarVisiblePolicy HorizontalScrollBarVisiblePolicy
339         {
340             get
341             {
342                 int policy;
343                 Interop.Elementary.elm_scroller_policy_get(RealHandle, out policy, IntPtr.Zero);
344                 return (ScrollBarVisiblePolicy)policy;
345             }
346             set
347             {
348                 ScrollBarVisiblePolicy v = VerticalScrollBarVisiblePolicy;
349                 Interop.Elementary.elm_scroller_policy_set(RealHandle, (int)value, (int)v);
350             }
351         }
352
353         /// <summary>
354         /// Sets or gets the value of VerticalScrollBarVisiblePolicy.
355         /// </summary>
356         /// <remarks>
357         /// ScrollBarVisiblePolicy.Auto means the vertical scrollbar is made visible if it is needed, and otherwise kept hidden.
358         /// ScrollBarVisiblePolicy.Visible turns it on all the time, and ScrollBarVisiblePolicy.Invisible always keeps it off.
359         /// </remarks>
360         /// <since_tizen> preview </since_tizen>
361         public ScrollBarVisiblePolicy VerticalScrollBarVisiblePolicy
362         {
363             get
364             {
365                 int policy;
366                 Interop.Elementary.elm_scroller_policy_get(RealHandle, IntPtr.Zero, out policy);
367                 return (ScrollBarVisiblePolicy)policy;
368             }
369             set
370             {
371                 ScrollBarVisiblePolicy h = HorizontalScrollBarVisiblePolicy;
372                 Interop.Elementary.elm_scroller_policy_set(RealHandle, (int)h, (int)value);
373             }
374         }
375
376         /// <summary>
377         /// Gets the first item in a given GenGrid widget.
378         /// </summary>
379         /// <since_tizen> preview </since_tizen>
380         public GenGridItem FirstItem
381         {
382             get
383             {
384                 IntPtr handle = Interop.Elementary.elm_gengrid_first_item_get(RealHandle);
385                 return ItemObject.GetItemByHandle(handle) as GenGridItem;
386             }
387         }
388
389         /// <summary>
390         /// Gets the last item in a given GenGrid widget.
391         /// </summary>
392         /// <since_tizen> preview </since_tizen>
393         public GenGridItem LastItem
394         {
395             get
396             {
397                 IntPtr handle = Interop.Elementary.elm_gengrid_last_item_get(RealHandle);
398                 return ItemObject.GetItemByHandle(handle) as GenGridItem;
399             }
400         }
401
402         /// <summary>
403         /// Gets the items count in a given GenGrid widget.
404         /// </summary>
405         /// <since_tizen> preview </since_tizen>
406         public uint ItemCount
407         {
408             get
409             {
410                 return Interop.Elementary.elm_gengrid_items_count(RealHandle);
411             }
412         }
413
414         /// <summary>
415         /// Gets the selected item in a given GenGrid widget.
416         /// </summary>
417         /// <since_tizen> preview </since_tizen>
418         public GenGridItem SelectedItem
419         {
420             get
421             {
422                 IntPtr handle = Interop.Elementary.elm_gengrid_selected_item_get(RealHandle);
423                 return ItemObject.GetItemByHandle(handle) as GenGridItem;
424             }
425         }
426
427         /// <summary>
428         /// Gets or sets whether a given GenGrid widget is able to or not able to have items reordered.
429         /// </summary>
430         /// <since_tizen> preview </since_tizen>
431         public bool ReorderMode
432         {
433             get
434             {
435                 return Interop.Elementary.elm_gengrid_reorder_mode_get(RealHandle);
436             }
437             set
438             {
439                 Interop.Elementary.elm_gengrid_reorder_mode_set(RealHandle, value);
440             }
441         }
442
443         /// <summary>
444         /// Appends a new item to a given GenGrid widget. This adds an item to the end of the gengrid.
445         /// </summary>
446         /// <param name="itemClass">The itemClass defines how to display the data.</param>
447         /// <param name="data">The item data.</param>
448         /// <returns>Return a gengrid item that contains the data and itemClass.</returns>
449         /// <seealso cref="GenItemClass"/>
450         /// <seealso cref="GenGridItem"/>
451         /// <since_tizen> preview </since_tizen>
452         public GenGridItem Append(GenItemClass itemClass, object data)
453         {
454             GenGridItem item = new GenGridItem(data, itemClass, this);
455             item.Handle = Interop.Elementary.elm_gengrid_item_append(RealHandle, itemClass.UnmanagedPtr, (IntPtr)item.Id, null, (IntPtr)item.Id);
456             AddInternal(item);
457             return item;
458         }
459
460         /// <summary>
461         /// Prepends a new item to a given GenGrid widget. This adds an item to the beginning of the gengrid.
462         /// </summary>
463         /// <param name="itemClass">The itemClass defines how to display the data.</param>
464         /// <param name="data">The item data.</param>
465         /// <returns>Return a gengrid item that contains the data and itemClass.</returns>
466         /// <seealso cref="GenItemClass"/>
467         /// <seealso cref="GenGridItem"/>
468         /// <since_tizen> preview </since_tizen>
469         public GenGridItem Prepend(GenItemClass itemClass, object data)
470         {
471             GenGridItem item = new GenGridItem(data, itemClass, this);
472             item.Handle = Interop.Elementary.elm_gengrid_item_prepend(RealHandle, itemClass.UnmanagedPtr, (IntPtr)item.Id, null, (IntPtr)item.Id);
473             AddInternal(item);
474             return item;
475         }
476
477         /// <summary>
478         /// Inserts an item before another in a GenGrid widget. This inserts an item before another in the gengrid.
479         /// </summary>
480         /// <param name="itemClass">The itemClass defines how to display the data.</param>
481         /// <param name="data">The item data.</param>
482         /// <param name="before">The item before which to place this new one.</param>
483         /// <returns>Return a gengrid item that contains the data and itemClass.</returns>
484         /// <seealso cref="GenItemClass"/>
485         /// <seealso cref="GenGridItem"/>
486         /// <since_tizen> preview </since_tizen>
487         public GenGridItem InsertBefore(GenItemClass itemClass, object data, GenGridItem before)
488         {
489             GenGridItem item = new GenGridItem(data, itemClass, this);
490             item.Handle = Interop.Elementary.elm_gengrid_item_insert_before(RealHandle, itemClass.UnmanagedPtr, (IntPtr)item.Id, before, null, (IntPtr)item.Id);
491             AddInternal(item);
492             return item;
493         }
494
495         /// <summary>
496         /// Inserts an item after another in a GenGrid widget. This inserts an item after another in the gengrid.
497         /// </summary>
498         /// <param name="itemClass">The itemClass defines how to display the data.</param>
499         /// <param name="data">The item data.</param>
500         /// <param name="after">The item after which to place this new one.</param>
501         /// <returns>Return a gengrid item that contains the data and itemClass.</returns>
502         /// <seealso cref="GenItemClass"/>
503         /// <seealso cref="GenGridItem"/>
504         /// <since_tizen> preview </since_tizen>
505         public GenGridItem InsertAfter(GenItemClass itemClass, object data, GenGridItem after)
506         {
507             GenGridItem item = new GenGridItem(data, itemClass, this);
508             item.Handle = Interop.Elementary.elm_gengrid_item_insert_after(RealHandle, itemClass.UnmanagedPtr, (IntPtr)item.Id, after, null, (IntPtr)item.Id);
509             AddInternal(item);
510             return item;
511         }
512
513         /// <summary>
514         /// Inserts an item in a GenGrid widget using a user-defined sort function.
515         /// </summary>
516         /// <param name="itemClass">The itemClass defines how to display the data.</param>
517         /// <param name="data">The item data.</param>
518         /// <param name="comparison">User defined comparison function that defines the sort order based on the gengrid item and its data.</param>
519         /// <returns>Return a gengrid item that contains the data and itemClass.</returns>
520         /// <since_tizen> preview </since_tizen>
521         public GenGridItem InsertSorted(GenItemClass itemClass, object data, Comparison<object> comparison)
522         {
523             GenGridItem item = new GenGridItem(data, itemClass, this);
524
525             Interop.Elementary.Eina_Compare_Cb compareCallback = (handle1, handle2) =>
526             {
527                 GenGridItem first = (ItemObject.GetItemByHandle(handle1) as GenGridItem) ?? item;
528                 GenGridItem second = (ItemObject.GetItemByHandle(handle2) as GenGridItem) ?? item;
529                 return comparison(first.Data, second.Data);
530             };
531
532             item.Handle = Interop.Elementary.elm_gengrid_item_sorted_insert(RealHandle, itemClass.UnmanagedPtr, (IntPtr)item.Id, compareCallback, null, (IntPtr)item.Id);
533             AddInternal(item);
534             return item;
535         }
536
537         /// <summary>
538         /// Shows a given item to the visible area of a gengrid.
539         /// </summary>
540         /// <param name="item">The gengrid item to display.</param>
541         /// <param name="position">The position of the item in the viewport.</param>
542         /// <param name="animated">The type of how to show the item.</param>
543         /// <remarks>
544         /// If animated is true, the gengrid shows the item by scrolling if it's not fully visible.
545         /// If animated is false, the gengrid shows the item by jumping if it's not fully visible.
546         /// </remarks>
547         /// <seealso cref="ScrollToPosition"/>
548         /// <since_tizen> preview </since_tizen>
549         public void ScrollTo(GenGridItem item, ScrollToPosition position, bool animated)
550         {
551             if (animated)
552             {
553                 Interop.Elementary.elm_gengrid_item_bring_in(item.Handle, (int)position);
554             }
555             else
556             {
557                 Interop.Elementary.elm_gengrid_item_show(item.Handle, (int)position);
558             }
559         }
560
561         /// <summary>
562         /// Updates the contents of all the realized items.
563         /// This updates all realized items by calling all the <see cref="GenItemClass"/> again to get the content, text, and states.
564         /// Use this when the original item data has changed and the changes are desired to reflect.
565         /// </summary>
566         /// <remarks>
567         /// <see cref="GenItem.Update()"/> to update just one item.
568         /// </remarks>
569         /// <since_tizen> preview </since_tizen>
570         public void UpdateRealizedItems()
571         {
572             Interop.Elementary.elm_gengrid_realized_items_update(RealHandle);
573         }
574
575         /// <summary>
576         /// Removes all the items from a given GenGrid widget.
577         /// This removes (and deletes) all the items in the object, making it empty.
578         /// </summary>
579         /// <remarks>
580         /// <see cref="ItemObject.Delete()"/> to delete just one item.
581         /// </remarks>
582         /// <since_tizen> preview </since_tizen>
583         public void Clear()
584         {
585             Interop.Elementary.elm_gengrid_clear(RealHandle);
586         }
587
588         /// <summary>
589         /// Gets the item that is at the X, Y canvas coordinates.
590         /// </summary>
591         /// <param name="x">The input X coordinate.</param>
592         /// <param name="y">The input Y coordinate.</param>
593         /// <param name="portionX">The position relative to the item returned here.
594         /// -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).
595         /// </param>
596         /// <param name="portionY">The position relative to the item returned here.
597         /// -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).
598         /// </param>
599         /// <returns></returns>
600         /// <since_tizen> preview </since_tizen>
601         public GenGridItem GetItemByPosition(int x, int y, out int portionX, out int portionY)
602         {
603             IntPtr handle = Interop.Elementary.elm_gengrid_at_xy_item_get(RealHandle, x, y, out portionX, out portionY);
604             return ItemObject.GetItemByHandle(handle) as GenGridItem;
605         }
606
607         /// <summary>
608         /// Creates a widget handle.
609         /// </summary>
610         /// <param name="parent">Parent EvasObject.</param>
611         /// <returns>Handle IntPtr.</returns>
612         /// <since_tizen> preview </since_tizen>
613         protected override IntPtr CreateHandle(EvasObject parent)
614         {
615             IntPtr handle = Interop.Elementary.elm_layout_add(parent.Handle);
616             Interop.Elementary.elm_layout_theme_set(handle, "layout", "elm_widget", "default");
617
618             RealHandle = Interop.Elementary.elm_gengrid_add(handle);
619             Interop.Elementary.elm_object_part_content_set(handle, "elm.swallow.content", RealHandle);
620
621             return handle;
622         }
623
624         void InitializeSmartEvent()
625         {
626             _selected = new SmartEvent<GenGridItemEventArgs>(this, this.RealHandle, "selected", GenGridItemEventArgs.CreateFromSmartEvent);
627             _unselected = new SmartEvent<GenGridItemEventArgs>(this, this.RealHandle, "unselected", GenGridItemEventArgs.CreateFromSmartEvent);
628             _activated = new SmartEvent<GenGridItemEventArgs>(this, this.RealHandle, "activated", GenGridItemEventArgs.CreateFromSmartEvent);
629             _pressed = new SmartEvent<GenGridItemEventArgs>(this, this.RealHandle, "pressed", GenGridItemEventArgs.CreateFromSmartEvent);
630             _released = new SmartEvent<GenGridItemEventArgs>(this, this.RealHandle, "released", GenGridItemEventArgs.CreateFromSmartEvent);
631             _doubleClicked = new SmartEvent<GenGridItemEventArgs>(this, this.RealHandle, "clicked,double", GenGridItemEventArgs.CreateFromSmartEvent);
632             _realized = new SmartEvent<GenGridItemEventArgs>(this, this.RealHandle, "realized", GenGridItemEventArgs.CreateFromSmartEvent);
633             _unrealized = new SmartEvent<GenGridItemEventArgs>(this, this.RealHandle, "unrealized", GenGridItemEventArgs.CreateFromSmartEvent);
634             _longpressed = new SmartEvent<GenGridItemEventArgs>(this, this.RealHandle, "longpressed", GenGridItemEventArgs.CreateFromSmartEvent);
635             _focused = new SmartEvent<GenGridItemEventArgs>(this, this.RealHandle, "item,focused", GenGridItemEventArgs.CreateFromSmartEvent);
636             _unfocused = new SmartEvent<GenGridItemEventArgs>(this, this.RealHandle, "item,unfocused", GenGridItemEventArgs.CreateFromSmartEvent);
637             _changed = new SmartEvent(this, this.RealHandle, "changed");
638
639             _selected.On += (s, e) => { if (e.Item != null) ItemSelected?.Invoke(this, e); };
640             _unselected.On += (s, e) => { if (e.Item != null) ItemUnselected?.Invoke(this, e); };
641             _activated.On += (s, e) => { if (e.Item != null) ItemActivated?.Invoke(this, e); };
642             _pressed.On += (s, e) => { if (e.Item != null) ItemPressed?.Invoke(this, e); };
643             _released.On += (s, e) => { if (e.Item != null) ItemReleased?.Invoke(this, e); };
644             _doubleClicked.On += (s, e) => { if (e.Item != null) ItemDoubleClicked?.Invoke(this, e); };
645             _realized.On += (s, e) => { if (e.Item != null) ItemRealized?.Invoke(this, e); };
646             _unrealized.On += (s, e) => { if (e.Item != null) ItemUnrealized?.Invoke(this, e); };
647             _longpressed.On += (s, e) => { if (e.Item != null) ItemLongPressed?.Invoke(this, e); };
648             _focused.On += (s, e) => { if (e.Item != null) ItemFocused?.Invoke(this, e); };
649             _unfocused.On += (s, e) => { if (e.Item != null) ItemUnfocused?.Invoke(this, e); };
650             _changed.On += (s, e) => { Changed?.Invoke(this, e); };
651         }
652
653         void AddInternal(GenGridItem item)
654         {
655             _children.Add(item);
656             item.Deleted += Item_Deleted;
657         }
658
659         void Item_Deleted(object sender, EventArgs e)
660         {
661             _children.Remove((GenGridItem)sender);
662         }
663     }
664 }