Release 4.0.0-preview1-00051
[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         /// <param name="item">The genlistitem object</param>
125         public void DemoteItem()
126         {
127             Interop.Elementary.elm_genlist_item_demote(Handle);
128         }
129
130         /// <summary>
131         /// Gets or sets the genlist item's select mode.
132         /// </summary>
133         public override GenItemSelectionMode SelectionMode
134         {
135             get
136             {
137                 return (GenItemSelectionMode)Interop.Elementary.elm_genlist_item_select_mode_get(Handle);
138             }
139             set
140             {
141                 Interop.Elementary.elm_genlist_item_select_mode_set(Handle, (Interop.Elementary.Elm_Object_Select_Mode)value);
142             }
143         }
144
145         /// <summary>
146         /// Gets the next item in a genlist widget's internal list of items.
147         /// </summary>
148         /// <seealso cref="Previous"/>
149         public GenListItem Next
150         {
151             get
152             {
153                 IntPtr next = Interop.Elementary.elm_genlist_item_next_get(Handle);
154                 if (next == IntPtr.Zero)
155                     return null;
156                 else
157                     return GetItemByHandle(next) as GenListItem;
158             }
159         }
160
161         /// <summary>
162         /// Get the previous item in a genlist widget's internal list of items.
163         /// </summary>
164         /// <seealso cref="Next"/>
165         public GenListItem Previous
166         {
167             get
168             {
169                 IntPtr prev = Interop.Elementary.elm_genlist_item_prev_get(Handle);
170                 if (prev == IntPtr.Zero)
171                     return null;
172                 else
173                     return GetItemByHandle(prev) as GenListItem;
174             }
175         }
176
177         [EditorBrowsable(EditorBrowsableState.Never)]
178         public override string Cursor
179         {
180             get
181             {
182                 return Interop.Elementary.elm_genlist_item_cursor_get(Handle);
183             }
184             set
185             {
186                 if (!string.IsNullOrEmpty(value))
187                 {
188                     Interop.Elementary.elm_genlist_item_cursor_set(Handle, value);
189                 }
190                 else
191                 {
192                     Interop.Elementary.elm_genlist_item_cursor_unset(Handle);
193                 }
194             }
195         }
196
197         [EditorBrowsable(EditorBrowsableState.Never)]
198         public override string CursorStyle
199         {
200             get
201             {
202                 return Interop.Elementary.elm_genlist_item_cursor_style_get(Handle);
203             }
204             set
205             {
206                 Interop.Elementary.elm_genlist_item_cursor_style_set(Handle, value);
207             }
208         }
209
210         [EditorBrowsable(EditorBrowsableState.Never)]
211         public override bool IsUseEngineCursor
212         {
213             get
214             {
215                 return Interop.Elementary.elm_genlist_item_cursor_engine_only_get(Handle);
216             }
217             set
218             {
219                 Interop.Elementary.elm_genlist_item_cursor_engine_only_set(Handle, value);
220             }
221         }
222
223         public override void SetTooltipText(string tooltip)
224         {
225             Interop.Elementary.elm_genlist_item_tooltip_text_set(Handle, tooltip);
226         }
227
228         public override void UnsetTooltip()
229         {
230             Interop.Elementary.elm_genlist_item_tooltip_unset(Handle);
231         }
232
233         /// <summary>
234         /// Gets or sets the style of given genlist item's tooltip.
235         /// </summary>
236         public override string TooltipStyle
237         {
238             get
239             {
240                 return Interop.Elementary.elm_genlist_item_tooltip_style_get(Handle);
241             }
242             set
243             {
244                 Interop.Elementary.elm_genlist_item_tooltip_style_set(Handle, value);
245             }
246         }
247
248         /// <summary>
249         /// Gets or sets whether disable size restrictions on an object's tooltip.
250         /// </summary>
251         public bool IsTooltipWindowMode
252         {
253             get
254             {
255                 return Interop.Elementary.elm_genlist_item_tooltip_window_mode_get(Handle);
256             }
257             set
258             {
259                 Interop.Elementary.elm_genlist_item_tooltip_window_mode_set(Handle, value);
260             }
261         }
262
263         /// <summary>
264         /// Gets the index of the item. It is only valid once displayed.
265         /// </summary>
266         public int Index
267         {
268             get
269             {
270                 return Interop.Elementary.elm_genlist_item_index_get(Handle);
271             }
272         }
273
274         /// <summary>
275         /// Gets the depth of expanded item.
276         /// </summary>
277         public int ExpandedItemDepth
278         {
279             get
280             {
281                 return Interop.Elementary.elm_genlist_item_expanded_depth_get(Handle);
282             }
283         }
284
285         /// <summary>
286         /// Remove all sub-items (children) of the given item.
287         /// </summary>
288         /// <remark>
289         /// This removes all items that are children (and their descendants) of the given item it.
290         /// </remark>
291         public void ClearSubitems()
292         {
293             Interop.Elementary.elm_genlist_item_subitems_clear(Handle);
294         }
295
296         /// <summary>
297         /// Update the item class of an item.
298         /// 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.
299         /// </summary>
300         /// <param name="itemClass">The item class for the item.</param>
301         /// <param name="data">The data for the item.</param>
302         public void UpdateItemClass(GenItemClass itemClass, object data)
303         {
304             Data = data;
305             ItemClass = itemClass;
306             Interop.Elementary.elm_genlist_item_item_class_update((IntPtr)Handle, itemClass.UnmanagedPtr);
307         }
308
309         protected override void UpdateTooltipDelegate()
310         {
311             Interop.Elementary.elm_genlist_item_tooltip_content_cb_set(Handle,
312                 TooltipContentDelegate != null ? _tooltipCb : null,
313                 IntPtr.Zero,
314                 null);
315         }
316     }
317 }