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;
23 /// Enumeration for setting list's resizing behavior, transverse axis scrolling and items cropping.
25 /// <since_tizen> preview </since_tizen>
29 /// The list won't set any of its size hints to inform how a possible container should resize it.
30 /// Then, if it's not created as a "resize object", it might end with zeroed dimensions.
31 /// The list 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.
35 /// 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.
39 /// Sets a minimum size hint on the genlist object, so that containers may respect it (and resize itself to fit the child properly).
40 /// More specifically, a minimum size hint will be set for its transverse axis, so that the largest item in that direction fits well.
41 /// This is naturally bound by the list object's maximum size hints, set externally.
45 /// Besides setting a minimum size on the transverse axis, just like on Limit, the list will set a minimum size on th longitudinal axis, trying to reserve space to all its children to be visible at a time.
46 /// This is naturally bound by the list object's maximum size hints, set externally.
52 /// It inherits System.EventArgs.
53 /// It contains Item which is <see cref="ListItem"/> type.
54 /// All events of List contain ListItemEventArgs as a parameter.
56 /// <since_tizen> preview </since_tizen>
57 public class ListItemEventArgs : EventArgs
60 /// Gets or sets List item. The return type is <see cref="ListItem"/>.
62 /// <since_tizen> preview </since_tizen>
63 public ListItem Item { get; set; }
65 internal static ListItemEventArgs CreateFromSmartEvent(IntPtr data, IntPtr obj, IntPtr info)
67 ListItem item = ItemObject.GetItemByHandle(info) as ListItem;
68 return new ListItemEventArgs() { Item = item };
73 /// It inherits <see cref="Layout"/>.
74 /// The List is a widget that aims to display simple list item which has 2 icons and 1 text, and can be selected.
75 /// For more robust lists, <see cref="GenList"/> should probably be used.
77 /// <seealso cref="GenList"/>
78 /// <seealso cref="GenGrid"/>
79 /// <since_tizen> preview </since_tizen>
80 public class List : Layout
82 HashSet<ListItem> _children = new HashSet<ListItem>();
83 SmartEvent<ListItemEventArgs> _selected;
84 SmartEvent<ListItemEventArgs> _unselected;
85 SmartEvent<ListItemEventArgs> _doubleClicked;
86 SmartEvent<ListItemEventArgs> _longpressed;
87 SmartEvent<ListItemEventArgs> _activated;
90 /// Creates and initializes a new instance of the List class.
92 /// <param name="parent">The parent is a given container which will be attached by List as a child. It's <see cref="EvasObject"/> type.</param>
93 /// <since_tizen> preview </since_tizen>
94 public List(EvasObject parent) : base(parent)
96 _selected = new SmartEvent<ListItemEventArgs>(this, this.RealHandle, "selected", ListItemEventArgs.CreateFromSmartEvent);
97 _unselected = new SmartEvent<ListItemEventArgs>(this, this.RealHandle, "unselected", ListItemEventArgs.CreateFromSmartEvent);
98 _doubleClicked = new SmartEvent<ListItemEventArgs>(this, this.RealHandle, "clicked,double", ListItemEventArgs.CreateFromSmartEvent);
99 _longpressed = new SmartEvent<ListItemEventArgs>(this, this.RealHandle, "longpressed", ListItemEventArgs.CreateFromSmartEvent);
100 _activated = new SmartEvent<ListItemEventArgs>(this, this.RealHandle, "activated", ListItemEventArgs.CreateFromSmartEvent);
101 _selected.On += (s, e) => { ItemSelected?.Invoke(this, e); };
102 _unselected.On += (s, e) => { ItemUnselected?.Invoke(this, e); };
103 _doubleClicked.On += (s, e) => { ItemDoubleClicked?.Invoke(this, e); };
104 _longpressed.On += (s, e) => { ItemLongPressed?.Invoke(this, e); };
105 _activated.On += (s, e) => { ItemActivated?.Invoke(this, e); };
109 /// Gets or sets which mode to use for the list.
111 /// <since_tizen> preview </since_tizen>
116 return (ListMode)Interop.Elementary.elm_list_mode_get(RealHandle);
120 Interop.Elementary.elm_list_mode_set(RealHandle, (Interop.Elementary.Elm_List_Mode)value);
125 /// Gets the selected item.
127 /// <since_tizen> preview </since_tizen>
128 public ListItem SelectedItem
132 IntPtr item = Interop.Elementary.elm_list_selected_item_get(RealHandle);
133 return ItemObject.GetItemByHandle(item) as ListItem;
138 /// ItemSelected is raised when a new list item is selected.
140 /// <since_tizen> preview </since_tizen>
141 public event EventHandler<ListItemEventArgs> ItemSelected;
144 /// ItemUnselected is raised when the list item is Unselected.
146 /// <since_tizen> preview </since_tizen>
147 public event EventHandler<ListItemEventArgs> ItemUnselected;
150 /// ItemDoubleClicked is raised when a new list item is double clicked.
152 /// <since_tizen> preview </since_tizen>
153 public event EventHandler<ListItemEventArgs> ItemDoubleClicked;
156 /// ItemLongPressed is raised when a list item is pressed for a certain amount of time. By default it's 1 second.
158 /// <since_tizen> preview </since_tizen>
159 public event EventHandler<ListItemEventArgs> ItemLongPressed;
162 /// ItemActivated is raised when a new list item is double clicked or pressed (enter|return|spacebar).
164 /// <since_tizen> preview </since_tizen>
165 public event EventHandler<ListItemEventArgs> ItemActivated;
169 /// Call before running <see cref="EvasObject.Show"/> on the list object.
170 /// If not called, it won't display the list properly.
172 /// <since_tizen> preview </since_tizen>
175 Interop.Elementary.elm_list_go(RealHandle);
179 /// Appends a new item with a text to the end of a given list widget.
181 /// <param name="label">The text for the item.</param>
182 /// <returns>Return a new added list item that contains a text.</returns>
183 /// <seealso cref="ListItem"/>
184 /// <since_tizen> preview </since_tizen>
185 public ListItem Append(string label)
187 return Append(label, null, null);
191 /// Appends a new item with a text and 2 icons to the end of a given list widget.
193 /// <param name="label">The text for the item.</param>
194 /// <param name="leftIcon">The left icon for the item.</param>
195 /// <param name="rightIcon">The right icon for the item.</param>
196 /// <returns>Return a new added list item that contains a text and 2 icons.</returns>
197 /// <seealso cref="ListItem"/>
198 /// <since_tizen> preview </since_tizen>
199 public ListItem Append(string label, EvasObject leftIcon, EvasObject rightIcon)
201 ListItem item = new ListItem(label, leftIcon, rightIcon);
202 item.Handle = Interop.Elementary.elm_list_item_append(RealHandle, label, leftIcon, rightIcon, null, (IntPtr)item.Id);
208 /// Prepends a new item with a text to the beginning of a given list widget.
210 /// <param name="label">The text for the item.</param>
211 /// <returns>Return a new added list item that contains a text.</returns>
212 /// <since_tizen> preview </since_tizen>
213 public ListItem Prepend(string label)
215 return Prepend(label, null, null);
219 /// Prepends a new item with a text and 2 icons to the beginning of a given list widget.
221 /// <param name="label">The text for the item.</param>
222 /// <param name="leftIcon">The left icon for the item.</param>
223 /// <param name="rigthIcon">The right icon for the item.</param>
224 /// <returns>Return a new added list item that contains a text and 2 icons.</returns>
225 /// <since_tizen> preview </since_tizen>
226 public ListItem Prepend(string label, EvasObject leftIcon, EvasObject rigthIcon)
228 ListItem item = new ListItem(label, leftIcon, rigthIcon);
229 item.Handle = Interop.Elementary.elm_list_item_prepend(RealHandle, label, leftIcon, rigthIcon, null, (IntPtr)item.Id);
235 /// Removes all items from a given list widget.
236 /// To delete just one item, use <see cref="ItemObject.Delete"/>.
238 /// <since_tizen> preview </since_tizen>
241 Interop.Elementary.elm_list_clear(RealHandle);
242 foreach (var item in _children)
244 item.Deleted -= Item_Deleted;
250 /// Creates a widget handle.
252 /// <param name="parent">Parent EvasObject</param>
253 /// <returns>Handle IntPtr</returns>
254 /// <since_tizen> preview </since_tizen>
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_list_add(handle);
261 Interop.Elementary.elm_object_part_content_set(handle, "elm.swallow.content", RealHandle);
266 void AddInternal(ListItem item)
269 item.Deleted += Item_Deleted;
272 void Item_Deleted(object sender, EventArgs e)
274 _children.Remove((ListItem)sender);