2 * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
18 using System.Collections.Generic;
22 public enum GenListItemType
29 public enum GenListMode
37 public class GenListItemEventArgs : EventArgs
39 public GenListItem Item { get; set; }
41 internal static GenListItemEventArgs CreateFromSmartEvent(IntPtr data, IntPtr obj, IntPtr info)
43 GenListItem item = ItemObject.GetItemByHandle(info) as GenListItem;
44 return new GenListItemEventArgs() { Item = item };
48 public enum ScrollToPosition
50 None = 0, // Scrolls to nowhere
51 In = (1 << 0), // Scrolls to the nearest viewport
52 Top = (1 << 1), // Scrolls to the top of the viewport
53 Middle = (1 << 2), // Scrolls to the middle of the viewport
54 Bottom = (1 << 3) // Scrolls to the bottom of the viewport
57 public class GenList : Layout
59 HashSet<GenListItem> _children = new HashSet<GenListItem>();
61 SmartEvent<GenListItemEventArgs> _selected;
62 SmartEvent<GenListItemEventArgs> _unselected;
63 SmartEvent<GenListItemEventArgs> _activated;
64 SmartEvent<GenListItemEventArgs> _pressed;
65 SmartEvent<GenListItemEventArgs> _released;
66 SmartEvent<GenListItemEventArgs> _doubleClicked;
67 SmartEvent<GenListItemEventArgs> _expanded;
68 SmartEvent<GenListItemEventArgs> _realized;
69 SmartEvent<GenListItemEventArgs> _unrealized;
70 SmartEvent<GenListItemEventArgs> _longpressed;
71 SmartEvent<GenListItemEventArgs> _moved;
72 SmartEvent<GenListItemEventArgs> _movedAfter;
73 SmartEvent<GenListItemEventArgs> _movedBefore;
74 SmartEvent _scrollAnimationStarted;
75 SmartEvent _scrollAnimationStopped;
78 public GenList(EvasObject parent) : base(parent)
80 InitializeSmartEvent();
83 public bool Homogeneous
87 return Interop.Elementary.elm_genlist_homogeneous_get(RealHandle);
91 Interop.Elementary.elm_genlist_homogeneous_set(RealHandle, value);
95 public GenListMode ListMode
99 return (GenListMode)Interop.Elementary.elm_genlist_mode_get(RealHandle);
103 Interop.Elementary.elm_genlist_mode_set(RealHandle, (int)value);
107 public GenListItem FirstItem
111 IntPtr handle = Interop.Elementary.elm_genlist_first_item_get(RealHandle);
112 return ItemObject.GetItemByHandle(handle) as GenListItem;
116 public GenListItem LastItem
120 IntPtr handle = Interop.Elementary.elm_genlist_last_item_get(RealHandle);
121 return ItemObject.GetItemByHandle(handle) as GenListItem;
125 public bool ReorderMode
129 return Interop.Elementary.elm_genlist_reorder_mode_get(RealHandle);
133 Interop.Elementary.elm_genlist_reorder_mode_set(RealHandle, value);
137 public event EventHandler<GenListItemEventArgs> ItemSelected;
138 public event EventHandler<GenListItemEventArgs> ItemUnselected;
139 public event EventHandler<GenListItemEventArgs> ItemPressed;
140 public event EventHandler<GenListItemEventArgs> ItemReleased;
141 public event EventHandler<GenListItemEventArgs> ItemActivated;
142 public event EventHandler<GenListItemEventArgs> ItemDoubleClicked;
143 public event EventHandler<GenListItemEventArgs> ItemExpanded;
144 public event EventHandler<GenListItemEventArgs> ItemRealized;
145 public event EventHandler<GenListItemEventArgs> ItemUnrealized;
146 public event EventHandler<GenListItemEventArgs> ItemLongPressed;
147 public event EventHandler<GenListItemEventArgs> ItemMoved;
148 public event EventHandler<GenListItemEventArgs> ItemMovedAfter;
149 public event EventHandler<GenListItemEventArgs> ItemMovedBefore;
151 public event EventHandler Changed
153 add { _changed.On += value; }
154 remove { _changed.On -= value; }
157 public event EventHandler ScrollAnimationStarted
159 add { _scrollAnimationStarted.On += value; }
160 remove { _scrollAnimationStarted.On -= value; }
163 public event EventHandler ScrollAnimationStopped
165 add { _scrollAnimationStopped.On += value; }
166 remove { _scrollAnimationStopped.On -= value; }
169 public GenListItem Append(GenItemClass itemClass, object data)
171 return Append(itemClass, data, GenListItemType.Normal);
174 public GenListItem Append(GenItemClass itemClass, object data, GenListItemType type)
176 return Append(itemClass, data, type, null);
179 public GenListItem Append(GenItemClass itemClass, object data, GenListItemType type, GenListItem parent)
181 GenListItem item = new GenListItem(data, itemClass);
182 IntPtr handle = Interop.Elementary.elm_genlist_item_append(RealHandle, itemClass.UnmanagedPtr, (IntPtr)item.Id, parent, (int)type, null, (IntPtr)item.Id);
183 item.Handle = handle;
188 public GenListItem Prepend(GenItemClass itemClass, object data)
190 return Prepend(itemClass, data, GenListItemType.Normal);
193 public GenListItem Prepend(GenItemClass itemClass, object data, GenListItemType type)
195 return Prepend(itemClass, data, type, null);
198 public GenListItem Prepend(GenItemClass itemClass, object data, GenListItemType type, GenListItem parent)
200 GenListItem item = new GenListItem(data, itemClass);
201 IntPtr handle = Interop.Elementary.elm_genlist_item_prepend(RealHandle, itemClass.UnmanagedPtr, (IntPtr)item.Id, parent, (int)type, null, (IntPtr)item.Id);
202 item.Handle = handle;
207 public GenListItem InsertBefore(GenItemClass itemClass, object data, GenListItem before)
209 return InsertBefore(itemClass, data, before, GenListItemType.Normal);
211 public GenListItem InsertBefore(GenItemClass itemClass, object data, GenListItem before, GenListItemType type)
213 return InsertBefore(itemClass, data, before, type, null);
215 public GenListItem InsertBefore(GenItemClass itemClass, object data, GenListItem before, GenListItemType type, GenListItem parent)
217 GenListItem item = new GenListItem(data, itemClass);
218 // insert before the `before` list item
219 IntPtr handle = Interop.Elementary.elm_genlist_item_insert_before(
220 RealHandle, // genlist handle
221 itemClass.UnmanagedPtr, // item class
222 (IntPtr)item.Id, // data
225 (int)type, // item type
226 null, // select callback
227 (IntPtr)item.Id); // callback data
228 item.Handle = handle;
233 public void ScrollTo(GenListItem item, ScrollToPosition position, bool animated)
237 Interop.Elementary.elm_genlist_item_bring_in(item.Handle, (Interop.Elementary.Elm_Genlist_Item_Scrollto_Type)position);
241 Interop.Elementary.elm_genlist_item_show(item.Handle, (Interop.Elementary.Elm_Genlist_Item_Scrollto_Type)position);
245 public void UpdateRealizedItems()
247 Interop.Elementary.elm_genlist_realized_items_update(RealHandle);
252 Interop.Elementary.elm_genlist_clear(RealHandle);
255 protected override IntPtr CreateHandle(EvasObject parent)
257 IntPtr handle = Interop.Elementary.elm_layout_add(parent.Handle);
258 Interop.Elementary.elm_layout_theme_set(handle, "layout", "elm_widget", "default");
260 RealHandle = Interop.Elementary.elm_genlist_add(handle);
261 Interop.Elementary.elm_object_part_content_set(handle, "elm.swallow.content", RealHandle);
266 void InitializeSmartEvent()
268 _selected = new SmartEvent<GenListItemEventArgs>(this, this.RealHandle, "selected", GenListItemEventArgs.CreateFromSmartEvent);
269 _unselected = new SmartEvent<GenListItemEventArgs>(this, this.RealHandle, "unselected", GenListItemEventArgs.CreateFromSmartEvent);
270 _activated = new SmartEvent<GenListItemEventArgs>(this, this.RealHandle, "activated", GenListItemEventArgs.CreateFromSmartEvent);
271 _pressed = new SmartEvent<GenListItemEventArgs>(this, this.RealHandle, "pressed", GenListItemEventArgs.CreateFromSmartEvent);
272 _released = new SmartEvent<GenListItemEventArgs>(this, this.RealHandle, "released", GenListItemEventArgs.CreateFromSmartEvent);
273 _doubleClicked = new SmartEvent<GenListItemEventArgs>(this, this.RealHandle, "clicked,double", GenListItemEventArgs.CreateFromSmartEvent);
274 _expanded = new SmartEvent<GenListItemEventArgs>(this, this.RealHandle, "expanded", GenListItemEventArgs.CreateFromSmartEvent);
275 _realized = new SmartEvent<GenListItemEventArgs>(this, this.RealHandle, "realized", GenListItemEventArgs.CreateFromSmartEvent);
276 _unrealized = new SmartEvent<GenListItemEventArgs>(this, this.RealHandle, "unrealized", GenListItemEventArgs.CreateFromSmartEvent);
277 _longpressed = new SmartEvent<GenListItemEventArgs>(this, this.RealHandle, "longpressed", GenListItemEventArgs.CreateFromSmartEvent);
278 _moved = new SmartEvent<GenListItemEventArgs>(this, this.RealHandle, "moved", GenListItemEventArgs.CreateFromSmartEvent);
279 _movedAfter = new SmartEvent<GenListItemEventArgs>(this, this.RealHandle, "moved,after", GenListItemEventArgs.CreateFromSmartEvent);
280 _movedBefore = new SmartEvent<GenListItemEventArgs>(this, this.RealHandle, "moved,before", GenListItemEventArgs.CreateFromSmartEvent);
281 _scrollAnimationStarted = new SmartEvent(this, this.RealHandle, "scroll,anim,start");
282 _scrollAnimationStopped = new SmartEvent(this, this.RealHandle, "scroll,anim,stop");
283 _changed = new SmartEvent(this, this.RealHandle, "changed");
285 _selected.On += (s, e) => { if (e.Item != null) ItemSelected?.Invoke(this, e); };
286 _unselected.On += (s, e) => { if (e.Item != null) ItemUnselected?.Invoke(this, e); };
287 _activated.On += (s, e) => { if (e.Item != null) ItemActivated?.Invoke(this, e); };
288 _pressed.On += (s, e) => { if (e.Item != null) ItemPressed?.Invoke(this, e); };
289 _released.On += (s, e) => { if (e.Item != null) ItemReleased?.Invoke(this, e); };
290 _doubleClicked.On += (s, e) => { if (e.Item != null) ItemDoubleClicked?.Invoke(this, e); };
291 _expanded.On += (s, e) => { if (e.Item != null) ItemExpanded?.Invoke(this, e); };
292 _realized.On += (s, e) => { if (e.Item != null) ItemRealized?.Invoke(this, e); };
293 _unrealized.On += (s, e) => { if (e.Item != null) ItemUnrealized?.Invoke(this, e); };
294 _longpressed.On += (s, e) => { if (e.Item != null) ItemLongPressed?.Invoke(this, e); };
295 _moved.On += (s, e) => { if (e.Item != null) ItemMoved?.Invoke(this, e); };
296 _movedAfter.On += (s, e) => { if (e.Item != null) ItemMovedAfter?.Invoke(this, e); };
297 _movedBefore.On += (s, e) => { if (e.Item != null) ItemMovedBefore?.Invoke(this, e); };
300 void AddInternal(GenListItem item)
303 item.Deleted += Item_Deleted;
306 void Item_Deleted(object sender, EventArgs e)
308 _children.Remove((GenListItem)sender);