Release 4.0.0-preview1-00120
[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         [EditorBrowsable(EditorBrowsableState.Never)]
177         public override string Cursor
178         {
179             get
180             {
181                 return Interop.Elementary.elm_genlist_item_cursor_get(Handle);
182             }
183             set
184             {
185                 if (!string.IsNullOrEmpty(value))
186                 {
187                     Interop.Elementary.elm_genlist_item_cursor_set(Handle, value);
188                 }
189                 else
190                 {
191                     Interop.Elementary.elm_genlist_item_cursor_unset(Handle);
192                 }
193             }
194         }
195
196         [EditorBrowsable(EditorBrowsableState.Never)]
197         public override string CursorStyle
198         {
199             get
200             {
201                 return Interop.Elementary.elm_genlist_item_cursor_style_get(Handle);
202             }
203             set
204             {
205                 Interop.Elementary.elm_genlist_item_cursor_style_set(Handle, value);
206             }
207         }
208
209         [EditorBrowsable(EditorBrowsableState.Never)]
210         public override bool IsUseEngineCursor
211         {
212             get
213             {
214                 return Interop.Elementary.elm_genlist_item_cursor_engine_only_get(Handle);
215             }
216             set
217             {
218                 Interop.Elementary.elm_genlist_item_cursor_engine_only_set(Handle, value);
219             }
220         }
221
222         public override void SetTooltipText(string tooltip)
223         {
224             Interop.Elementary.elm_genlist_item_tooltip_text_set(Handle, tooltip);
225         }
226
227         public override void UnsetTooltip()
228         {
229             Interop.Elementary.elm_genlist_item_tooltip_unset(Handle);
230         }
231
232         /// <summary>
233         /// Gets or sets the style of given genlist item's tooltip.
234         /// </summary>
235         public override string TooltipStyle
236         {
237             get
238             {
239                 return Interop.Elementary.elm_genlist_item_tooltip_style_get(Handle);
240             }
241             set
242             {
243                 Interop.Elementary.elm_genlist_item_tooltip_style_set(Handle, value);
244             }
245         }
246
247         /// <summary>
248         /// Gets or sets whether disable size restrictions on an object's tooltip.
249         /// </summary>
250         public bool IsTooltipWindowMode
251         {
252             get
253             {
254                 return Interop.Elementary.elm_genlist_item_tooltip_window_mode_get(Handle);
255             }
256             set
257             {
258                 Interop.Elementary.elm_genlist_item_tooltip_window_mode_set(Handle, value);
259             }
260         }
261
262         /// <summary>
263         /// Gets the index of the item. It is only valid once displayed.
264         /// </summary>
265         public int Index
266         {
267             get
268             {
269                 return Interop.Elementary.elm_genlist_item_index_get(Handle);
270             }
271         }
272
273         /// <summary>
274         /// Gets the depth of expanded item.
275         /// </summary>
276         public int ExpandedItemDepth
277         {
278             get
279             {
280                 return Interop.Elementary.elm_genlist_item_expanded_depth_get(Handle);
281             }
282         }
283
284         /// <summary>
285         /// Remove all sub-items (children) of the given item.
286         /// </summary>
287         /// <remarks>
288         /// This removes all items that are children (and their descendants) of the given item it.
289         /// </remarks>
290         public void ClearSubitems()
291         {
292             Interop.Elementary.elm_genlist_item_subitems_clear(Handle);
293         }
294
295         /// <summary>
296         /// Update the item class of an item.
297         /// 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.
298         /// </summary>
299         /// <param name="itemClass">The item class for the item.</param>
300         /// <param name="data">The data for the item.</param>
301         public void UpdateItemClass(GenItemClass itemClass, object data)
302         {
303             Data = data;
304             ItemClass = itemClass;
305             Interop.Elementary.elm_genlist_item_item_class_update((IntPtr)Handle, itemClass.UnmanagedPtr);
306         }
307
308         protected override void UpdateTooltipDelegate()
309         {
310             Interop.Elementary.elm_genlist_item_tooltip_content_cb_set(Handle,
311                 TooltipContentDelegate != null ? _tooltipCb : null,
312                 IntPtr.Zero,
313                 null);
314         }
315     }
316 }