[ACR-564] deprecate unused API
[platform/core/csapi/tizenfx.git] / src / ElmSharp / ElmSharp / List.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 the list's resizing behavior, transverse axis scrolling, and items cropping.
24     /// </summary>
25     /// <since_tizen> preview </since_tizen>
26     [Obsolete("This has been deprecated in API12")]
27     public enum ListMode
28     {
29         /// <summary>
30         /// The list won't set any of its size hints to inform how a possible container should resize it.
31         /// Then, if it's not created as a "resize object", it might end with zeroed dimensions.
32         /// 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.
33         /// </summary>
34         Compress = 0,
35         /// <summary>
36         /// 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.
37         /// </summary>
38         Scroll,
39         /// <summary>
40         /// Sets a minimum size hint on the genlist object, so that the containers may respect it (and resize itself to fit the child properly).
41         /// More specifically, a minimum size hint will be set for its transverse axis, so that the largest item in that direction fits well.
42         /// This is naturally bound by the list object's maximum size hints, set externally.
43         /// </summary>
44         Limit,
45         /// <summary>
46         /// Besides setting a minimum size on the transverse axis, just like on limit, the list will set a minimum size on the longitudinal axis, trying to reserve space to all its children to be visible at a time.
47         /// This is naturally bound by the list object's maximum size hints, set externally.
48         /// </summary>
49         Expand
50     }
51
52     /// <summary>
53     /// It inherits System.EventArgs.
54     /// It contains an item which is <see cref="ListItem"/> type.
55     /// All the events of a list contain ListItemEventArgs as a parameter.
56     /// </summary>
57     /// <since_tizen> preview </since_tizen>
58     [Obsolete("This has been deprecated in API12")]
59     public class ListItemEventArgs : EventArgs
60     {
61         /// <summary>
62         /// Gets or sets the list item. The return type is <see cref="ListItem"/>.
63         /// </summary>
64         /// <since_tizen> preview </since_tizen>
65         [Obsolete("This has been deprecated in API12")]
66         public ListItem Item { get; set; }
67
68         internal static ListItemEventArgs CreateFromSmartEvent(IntPtr data, IntPtr obj, IntPtr info)
69         {
70             ListItem item = ItemObject.GetItemByHandle(info) as ListItem;
71             return new ListItemEventArgs() { Item = item };
72         }
73     }
74
75     /// <summary>
76     /// It inherits <see cref="Layout"/>.
77     /// The List is a widget that aims to display a simple list item which has 2 icons, 1 text, and can be selected.
78     /// For more robust lists, <see cref="GenList"/> should probably be used.
79     /// </summary>
80     /// <seealso cref="GenList"/>
81     /// <seealso cref="GenGrid"/>
82     /// <since_tizen> preview </since_tizen>
83     [Obsolete("This has been deprecated in API12")]
84     public class List : Layout
85     {
86         HashSet<ListItem> _children = new HashSet<ListItem>();
87         SmartEvent<ListItemEventArgs> _selected;
88         SmartEvent<ListItemEventArgs> _unselected;
89         SmartEvent<ListItemEventArgs> _doubleClicked;
90         SmartEvent<ListItemEventArgs> _longpressed;
91         SmartEvent<ListItemEventArgs> _activated;
92
93         /// <summary>
94         /// Creates and initializes a new instance of the List class.
95         /// </summary>
96         /// <param name="parent">The parent is a given container, which will be attached by the list as a child. It's <see cref="EvasObject"/> type.</param>
97         /// <since_tizen> preview </since_tizen>
98         [Obsolete("This has been deprecated in API12")]
99         public List(EvasObject parent) : base(parent)
100         {
101             _selected = new SmartEvent<ListItemEventArgs>(this, this.RealHandle, "selected", ListItemEventArgs.CreateFromSmartEvent);
102             _unselected = new SmartEvent<ListItemEventArgs>(this, this.RealHandle, "unselected", ListItemEventArgs.CreateFromSmartEvent);
103             _doubleClicked = new SmartEvent<ListItemEventArgs>(this, this.RealHandle, "clicked,double", ListItemEventArgs.CreateFromSmartEvent);
104             _longpressed = new SmartEvent<ListItemEventArgs>(this, this.RealHandle, "longpressed", ListItemEventArgs.CreateFromSmartEvent);
105             _activated = new SmartEvent<ListItemEventArgs>(this, this.RealHandle, "activated", ListItemEventArgs.CreateFromSmartEvent);
106             _selected.On += (s, e) => { ItemSelected?.Invoke(this, e); };
107             _unselected.On += (s, e) => { ItemUnselected?.Invoke(this, e); };
108             _doubleClicked.On += (s, e) => { ItemDoubleClicked?.Invoke(this, e); };
109             _longpressed.On += (s, e) => { ItemLongPressed?.Invoke(this, e); };
110             _activated.On += (s, e) => { ItemActivated?.Invoke(this, e); };
111         }
112
113         /// <summary>
114         /// Gets or sets which mode to be used for the list.
115         /// </summary>
116         /// <since_tizen> preview </since_tizen>
117         [Obsolete("This has been deprecated in API12")]
118         public ListMode Mode
119         {
120             get
121             {
122                 return (ListMode)Interop.Elementary.elm_list_mode_get(RealHandle);
123             }
124             set
125             {
126                 Interop.Elementary.elm_list_mode_set(RealHandle, (Interop.Elementary.Elm_List_Mode)value);
127             }
128         }
129
130         /// <summary>
131         /// Gets the selected item.
132         /// </summary>
133         /// <since_tizen> preview </since_tizen>
134         [Obsolete("This has been deprecated in API12")]
135         public ListItem SelectedItem
136         {
137             get
138             {
139                 IntPtr item = Interop.Elementary.elm_list_selected_item_get(RealHandle);
140                 return ItemObject.GetItemByHandle(item) as ListItem;
141             }
142         }
143
144         /// <summary>
145         /// ItemSelected is raised when a new list item is selected.
146         /// </summary>
147         /// <since_tizen> preview </since_tizen>
148         [Obsolete("This has been deprecated in API12")]
149         public event EventHandler<ListItemEventArgs> ItemSelected;
150
151         /// <summary>
152         /// ItemUnselected is raised when a list item is Unselected.
153         /// </summary>
154         /// <since_tizen> preview </since_tizen>
155         [Obsolete("This has been deprecated in API12")]
156         public event EventHandler<ListItemEventArgs> ItemUnselected;
157
158         /// <summary>
159         /// ItemDoubleClicked is raised when a new list item is double-clicked.
160         /// </summary>
161         /// <since_tizen> preview </since_tizen>
162         [Obsolete("This has been deprecated in API12")]
163         public event EventHandler<ListItemEventArgs> ItemDoubleClicked;
164
165         /// <summary>
166         /// ItemLongPressed is raised when a list item is pressed for a certain amount of time. By default, it's 1 second.
167         /// </summary>
168         /// <since_tizen> preview </since_tizen>
169         [Obsolete("This has been deprecated in API12")]
170         public event EventHandler<ListItemEventArgs> ItemLongPressed;
171
172         /// <summary>
173         /// ItemActivated is raised when a new list item is double-clicked or pressed (enter|return|spacebar).
174         /// </summary>
175         /// <since_tizen> preview </since_tizen>
176         [Obsolete("This has been deprecated in API12")]
177         public event EventHandler<ListItemEventArgs> ItemActivated;
178
179         /// <summary>
180         /// Starts the list.
181         /// Called before running <see cref="EvasObject.Show"/> on the list object.
182         /// If not called, it won't display the list properly.
183         /// </summary>
184         /// <since_tizen> preview </since_tizen>
185         [Obsolete("This has been deprecated in API12")]
186         public void Update()
187         {
188             Interop.Elementary.elm_list_go(RealHandle);
189         }
190
191         /// <summary>
192         /// Appends a new item with a text to the end of a given list widget.
193         /// </summary>
194         /// <param name="label">The text for the item.</param>
195         /// <returns>Return a new added list item that contains a text.</returns>
196         /// <seealso cref="ListItem"/>
197         /// <since_tizen> preview </since_tizen>
198         [Obsolete("This has been deprecated in API12")]
199         public ListItem Append(string label)
200         {
201             return Append(label, null, null);
202         }
203
204         /// <summary>
205         /// Appends a new item with a text and 2 icons to the end of a given list widget.
206         /// </summary>
207         /// <param name="label">The text for the item.</param>
208         /// <param name="leftIcon">The left icon for the item.</param>
209         /// <param name="rightIcon">The right icon for the item.</param>
210         /// <returns>Return a new added list item that contains a text and 2 icons.</returns>
211         /// <seealso cref="ListItem"/>
212         /// <since_tizen> preview </since_tizen>
213         [Obsolete("This has been deprecated in API12")]
214         public ListItem Append(string label, EvasObject leftIcon, EvasObject rightIcon)
215         {
216             ListItem item = new ListItem(label, leftIcon, rightIcon, this);
217             item.Handle = Interop.Elementary.elm_list_item_append(RealHandle, label, leftIcon, rightIcon, null, (IntPtr)item.Id);
218             AddInternal(item);
219             return item;
220         }
221
222         /// <summary>
223         /// Prepends a new item with a text to the beginning of a given list widget.
224         /// </summary>
225         /// <param name="label">The text for the item.</param>
226         /// <returns>Return a new added list item that contains a text.</returns>
227         /// <since_tizen> preview </since_tizen>
228         [Obsolete("This has been deprecated in API12")]
229         public ListItem Prepend(string label)
230         {
231             return Prepend(label, null, null);
232         }
233
234         /// <summary>
235         /// Prepends a new item with a text and 2 icons to the beginning of a given list widget.
236         /// </summary>
237         /// <param name="label">The text for the item.</param>
238         /// <param name="leftIcon">The left icon for the item.</param>
239         /// <param name="rigthIcon">The right icon for the item.</param>
240         /// <returns>Return a new added list item that contains a text and 2 icons.</returns>
241         /// <since_tizen> preview </since_tizen>
242         [Obsolete("This has been deprecated in API12")]
243         public ListItem Prepend(string label, EvasObject leftIcon, EvasObject rigthIcon)
244         {
245             ListItem item = new ListItem(label, leftIcon, rigthIcon, this);
246             item.Handle = Interop.Elementary.elm_list_item_prepend(RealHandle, label, leftIcon, rigthIcon, null, (IntPtr)item.Id);
247             AddInternal(item);
248             return item;
249         }
250
251         /// <summary>
252         /// Removes all the items from a given list widget.
253         /// To delete just one item, use <see cref="ItemObject.Delete"/>.
254         /// </summary>
255         /// <since_tizen> preview </since_tizen>
256         [Obsolete("This has been deprecated in API12")]
257         public void Clear()
258         {
259             Interop.Elementary.elm_list_clear(RealHandle);
260             foreach (var item in _children)
261             {
262                 item.Deleted -= Item_Deleted;
263             }
264             _children.Clear();
265         }
266
267         /// <summary>
268         /// Creates a widget handle.
269         /// </summary>
270         /// <param name="parent">Parent EvasObject.</param>
271         /// <returns>Handle IntPtr.</returns>
272         /// <since_tizen> preview </since_tizen>
273         [Obsolete("This has been deprecated in API12")]
274         protected override IntPtr CreateHandle(EvasObject parent)
275         {
276             IntPtr handle = Interop.Elementary.elm_layout_add(parent.Handle);
277             Interop.Elementary.elm_layout_theme_set(handle, "layout", "elm_widget", "default");
278
279             RealHandle = Interop.Elementary.elm_list_add(handle);
280             Interop.Elementary.elm_object_part_content_set(handle, "elm.swallow.content", RealHandle);
281
282             return handle;
283         }
284
285         void AddInternal(ListItem item)
286         {
287             _children.Add(item);
288             item.Deleted += Item_Deleted;
289         }
290
291         void Item_Deleted(object sender, EventArgs e)
292         {
293             _children.Remove((ListItem)sender);
294         }
295     }
296 }