b21c5501c1951913add61a20ccf1c1ee0f0f0b0e
[platform/core/csapi/tizenfx.git] / src / ElmSharp / ElmSharp / GenListItem.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.ComponentModel;
19
20 namespace ElmSharp
21 {
22     /// <summary>
23     /// The type of item's part type.
24     /// </summary>
25     [Flags]
26     public enum GenListItemFieldType
27     {
28         /// <summary>
29         /// All item's parts.
30         /// </summary>
31         All = 0,
32
33         /// <summary>
34         /// The text part type.
35         /// </summary>
36         Text = (1 << 0),
37
38         /// <summary>
39         /// The Content part type.
40         /// </summary>
41         Content = (1 << 1),
42
43         /// <summary>
44         /// The state of part.
45         /// </summary>
46         State = (1 << 2),
47
48         /// <summary>
49         /// No part type.
50         /// </summary>
51         None = (1 << 3)
52     };
53
54     /// <summary>
55     /// It inherits <see cref="GenItem"/>.
56     /// A instance to the genlist item added.
57     /// It contains Update() method to update a genlist item which is given.
58     /// </summary>
59     public class GenListItem : GenItem
60     {
61         internal GenListItem(object data, GenItemClass itemClass) : base(data, itemClass)
62         {
63         }
64
65         /// <summary>
66         /// Gets or sets whether a given genlist item is selected.
67         /// </summary>
68         public override bool IsSelected
69         {
70             get
71             {
72                 return Interop.Elementary.elm_genlist_item_selected_get(Handle);
73             }
74             set
75             {
76                 Interop.Elementary.elm_genlist_item_selected_set(Handle, value);
77             }
78         }
79
80         /// <summary>
81         /// Gets or sets whether a given genlist item is expanded.
82         /// </summary>
83         public bool IsExpanded
84         {
85             get
86             {
87                 return Interop.Elementary.elm_genlist_item_expanded_get(Handle);
88             }
89             set
90             {
91                 Interop.Elementary.elm_genlist_item_expanded_set(Handle, value);
92             }
93         }
94
95         /// <summary>
96         /// Updates the content of an item.
97         /// This updates an item by calling all the <see cref="GenItemClass"/> again to get the content, text, and states.
98         /// Use this when the original item data has changed and the changes are desired to reflect.
99         /// To update already realized items, use <see cref="GenList.UpdateRealizedItems"/>.
100         /// </summary>
101         /// <seealso cref="GenList.UpdateRealizedItems"/>
102         public override void Update()
103         {
104             Interop.Elementary.elm_genlist_item_update(Handle);
105         }
106
107         /// <summary>
108         /// Updates the part of an item.
109         /// This updates an item's part by calling item's fetching functions again to get the contents, texts and states.
110         /// Use this when the original item data has changed and the changes are desired to be reflected.
111         /// To update an item's all property, use <see cref="GenList.UpdateRealizedItems"/>.
112         /// </summary>
113         /// <param name="part">The part could be "elm.text", "elm.swalllow.icon", "elm.swallow.end", "elm.swallow.content" and so on. It is also used for globbing to match '*', '?', and '.'. It can be used at updating multi fields.</param>
114         /// <param name="type">The type of item's part type.</param>
115         /// <seealso cref="GenList.UpdateRealizedItems"/>
116         public void UpdateField(string part, GenListItemFieldType type)
117         {
118             Interop.Elementary.elm_genlist_item_fields_update(Handle, part, (uint)type);
119         }
120
121         /// <summary>
122         /// Demote an item to the end of the list.
123         /// </summary>
124         public void DemoteItem()
125         {
126             Interop.Elementary.elm_genlist_item_demote(Handle);
127         }
128
129         /// <summary>
130         /// Gets or sets the genlist item's select mode.
131         /// </summary>
132         public override GenItemSelectionMode SelectionMode
133         {
134             get
135             {
136                 return (GenItemSelectionMode)Interop.Elementary.elm_genlist_item_select_mode_get(Handle);
137             }
138             set
139             {
140                 Interop.Elementary.elm_genlist_item_select_mode_set(Handle, (Interop.Elementary.Elm_Object_Select_Mode)value);
141             }
142         }
143
144         /// <summary>
145         /// Gets the next item in a genlist widget's internal list of items.
146         /// </summary>
147         /// <seealso cref="Previous"/>
148         public GenListItem Next
149         {
150             get
151             {
152                 IntPtr next = Interop.Elementary.elm_genlist_item_next_get(Handle);
153                 if (next == IntPtr.Zero)
154                     return null;
155                 else
156                     return GetItemByHandle(next) as GenListItem;
157             }
158         }
159
160         /// <summary>
161         /// Get the previous item in a genlist widget's internal list of items.
162         /// </summary>
163         /// <seealso cref="Next"/>
164         public GenListItem Previous
165         {
166             get
167             {
168                 IntPtr prev = Interop.Elementary.elm_genlist_item_prev_get(Handle);
169                 if (prev == IntPtr.Zero)
170                     return null;
171                 else
172                     return GetItemByHandle(prev) as GenListItem;
173             }
174         }
175
176         /// <summary>
177         /// Sets or gets the content to be shown in the tooltip item
178         /// </summary>
179         [EditorBrowsable(EditorBrowsableState.Never)]
180         public override string Cursor
181         {
182             get
183             {
184                 return Interop.Elementary.elm_genlist_item_cursor_get(Handle);
185             }
186             set
187             {
188                 if (!string.IsNullOrEmpty(value))
189                 {
190                     Interop.Elementary.elm_genlist_item_cursor_set(Handle, value);
191                 }
192                 else
193                 {
194                     Interop.Elementary.elm_genlist_item_cursor_unset(Handle);
195                 }
196             }
197         }
198
199         /// <summary>
200         /// Sets or gets the style for this item cursor.
201         /// </summary>
202         [EditorBrowsable(EditorBrowsableState.Never)]
203         public override string CursorStyle
204         {
205             get
206             {
207                 return Interop.Elementary.elm_genlist_item_cursor_style_get(Handle);
208             }
209             set
210             {
211                 Interop.Elementary.elm_genlist_item_cursor_style_set(Handle, value);
212             }
213         }
214
215         /// <summary>
216         /// Sets or gets the cursor engine only usage for this item cursor.
217         /// </summary>
218         [EditorBrowsable(EditorBrowsableState.Never)]
219         public override bool IsUseEngineCursor
220         {
221             get
222             {
223                 return Interop.Elementary.elm_genlist_item_cursor_engine_only_get(Handle);
224             }
225             set
226             {
227                 Interop.Elementary.elm_genlist_item_cursor_engine_only_set(Handle, value);
228             }
229         }
230
231         /// <summary>
232         /// Set the text to be shown in the genlist item.
233         /// </summary>
234         /// <param name="tooltip">The text to set in the content.</param>
235         public override void SetTooltipText(string tooltip)
236         {
237             Interop.Elementary.elm_genlist_item_tooltip_text_set(Handle, tooltip);
238         }
239
240         /// <summary>
241         /// Unset tooltip from item.
242         /// </summary>
243         public override void UnsetTooltip()
244         {
245             Interop.Elementary.elm_genlist_item_tooltip_unset(Handle);
246         }
247
248         /// <summary>
249         /// Gets or sets the style of given genlist item's tooltip.
250         /// </summary>
251         public override string TooltipStyle
252         {
253             get
254             {
255                 return Interop.Elementary.elm_genlist_item_tooltip_style_get(Handle);
256             }
257             set
258             {
259                 Interop.Elementary.elm_genlist_item_tooltip_style_set(Handle, value);
260             }
261         }
262
263         /// <summary>
264         /// Gets or sets whether disable size restrictions on an object's tooltip.
265         /// </summary>
266         public bool IsTooltipWindowMode
267         {
268             get
269             {
270                 return Interop.Elementary.elm_genlist_item_tooltip_window_mode_get(Handle);
271             }
272             set
273             {
274                 Interop.Elementary.elm_genlist_item_tooltip_window_mode_set(Handle, value);
275             }
276         }
277
278         /// <summary>
279         /// Gets the index of the item. It is only valid once displayed.
280         /// </summary>
281         public int Index
282         {
283             get
284             {
285                 return Interop.Elementary.elm_genlist_item_index_get(Handle);
286             }
287         }
288
289         /// <summary>
290         /// Gets the depth of expanded item.
291         /// </summary>
292         public int ExpandedItemDepth
293         {
294             get
295             {
296                 return Interop.Elementary.elm_genlist_item_expanded_depth_get(Handle);
297             }
298         }
299
300         /// <summary>
301         /// Remove all sub-items (children) of the given item.
302         /// </summary>
303         /// <remarks>
304         /// This removes all items that are children (and their descendants) of the given item it.
305         /// </remarks>
306         public void ClearSubitems()
307         {
308             Interop.Elementary.elm_genlist_item_subitems_clear(Handle);
309         }
310
311         /// <summary>
312         /// Update the item class of an item.
313         /// This sets another class of the item, changing the way that it is displayed. After changing the item class, <see cref="Update"/> is called on the item.
314         /// </summary>
315         /// <param name="itemClass">The item class for the item.</param>
316         /// <param name="data">The data for the item.</param>
317         public void UpdateItemClass(GenItemClass itemClass, object data)
318         {
319             Data = data;
320             ItemClass = itemClass;
321             Interop.Elementary.elm_genlist_item_item_class_update((IntPtr)Handle, itemClass.UnmanagedPtr);
322         }
323
324         /// <summary>
325         /// Set the content to be shown in the tooltip item.
326         /// </summary>
327         protected override void UpdateTooltipDelegate()
328         {
329             Interop.Elementary.elm_genlist_item_tooltip_content_cb_set(Handle,
330                 TooltipContentDelegate != null ? _tooltipCb : null,
331                 IntPtr.Zero,
332                 null);
333         }
334     }
335 }