summaryrefslogtreecommitdiff
path: root/ElmSharp/ElmSharp/GenListItem.cs
blob: f019a25b5e3b61fcc82f355ee580cdec0e4fc444 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
/*
 * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
 *
 * Licensed under the Apache License, Version 2.0 (the License);
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an AS IS BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

using System;
using System.ComponentModel;

namespace ElmSharp
{

    /// <summary>
    /// The type of item's part type.
    /// </summary>
    [Flags]
    public enum GenListItemFieldType
    {
        /// <summary>
        /// All item's parts.
        /// </summary>
        All = 0,

        /// <summary>
        /// The text part type.
        /// </summary>
        Text = (1 << 0),

        /// <summary>
        /// The Content part type.
        /// </summary>
        Content = (1 << 1),

        /// <summary>
        /// The state of part.
        /// </summary>
        State = (1 << 2),

        /// <summary>
        /// No part type.
        /// </summary>
        None = (1 << 3)
    };

    /// <summary>
    /// It inherits <see cref="GenItem"/>.
    /// A instance to the genlist item added.
    /// It contains Update() method to update a genlist item which is given.
    /// </summary>
    public class GenListItem : GenItem
    {
        internal GenListItem(object data, GenItemClass itemClass) : base(data, itemClass)
        {
        }

        /// <summary>
        /// Gets or sets whether a given genlist item is selected.
        /// </summary>
        public override bool IsSelected
        {
            get
            {
                return Interop.Elementary.elm_genlist_item_selected_get(Handle);
            }
            set
            {
                Interop.Elementary.elm_genlist_item_selected_set(Handle, value);
            }
        }

        /// <summary>
        /// Gets or sets whether a given genlist item is expanded.
        /// </summary>
        public bool IsExpanded
        {
            get
            {
                return Interop.Elementary.elm_genlist_item_expanded_get(Handle);
            }
            set
            {
                Interop.Elementary.elm_genlist_item_expanded_set(Handle, value);
            }
        }

        /// <summary>
        /// Updates the content of an item.
        /// This updates an item by calling all the <see cref="GenItemClass"/> again to get the content, text, and states.
        /// Use this when the original item data has changed and the changes are desired to reflect.
        /// To update already realized items, use <see cref="GenList.UpdateRealizedItems"/>.
        /// </summary>
        /// <seealso cref="GenList.UpdateRealizedItems"/>
        public override void Update()
        {
            Interop.Elementary.elm_genlist_item_update(Handle);
        }

        /// <summary>
        /// Updates the part of an item.
        /// This updates an item's part by calling item's fetching functions again to get the contents, texts and states.
        /// Use this when the original item data has changed and the changes are desired to be reflected.
        /// To update an item's all property, use <see cref="GenList.UpdateRealizedItems"/>.
        /// </summary>
        /// <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>
        /// <param name="type">The type of item's part type.</param>
        /// <seealso cref="GenList.UpdateRealizedItems"/>
        public void UpdateField(string part, GenListItemFieldType type)
        {
            Interop.Elementary.elm_genlist_item_fields_update(Handle, part, (uint)type);
        }

        /// <summary>
        /// Demote an item to the end of the list.
        /// </summary>
        /// <param name="item">The genlistitem object</param>
        public void DemoteItem()
        {
            Interop.Elementary.elm_genlist_item_demote(Handle);
        }

        /// <summary>
        /// Gets or sets the genlist item's select mode.
        /// </summary>
        public override GenItemSelectionMode SelectionMode
        {
            get
            {
                return (GenItemSelectionMode)Interop.Elementary.elm_genlist_item_select_mode_get(Handle);
            }
            set
            {
                Interop.Elementary.elm_genlist_item_select_mode_set(Handle, (Interop.Elementary.Elm_Object_Select_Mode)value);
            }
        }

        /// <summary>
        /// Gets the next item in a genlist widget's internal list of items.
        /// </summary>
        /// <seealso cref="Previous"/>
        public GenListItem Next
        {
            get
            {
                IntPtr next = Interop.Elementary.elm_genlist_item_next_get(Handle);
                if (next == IntPtr.Zero)
                    return null;
                else
                    return GetItemByHandle(next) as GenListItem;
            }
        }

        /// <summary>
        /// Get the previous item in a genlist widget's internal list of items.
        /// </summary>
        /// <seealso cref="Next"/>
        public GenListItem Previous
        {
            get
            {
                IntPtr prev = Interop.Elementary.elm_genlist_item_prev_get(Handle);
                if (prev == IntPtr.Zero)
                    return null;
                else
                    return GetItemByHandle(prev) as GenListItem;
            }
        }

        /// <summary>
        /// Gets or sets the type of mouse pointer/cursor decoration to be shown, when the mouse pointer is over the given genlist widget item.
        /// <remarks>
        /// The cursor's changing area is restricted to the item's area, and not the whole widget's. Note that that item cursors have precedence over widget cursors, so that a mouse over item will always show cursor type.
        /// </remarks>>
        /// </summary>
        [EditorBrowsable(EditorBrowsableState.Never)]
        public override string Cursor
        {
            get
            {
                return Interop.Elementary.elm_genlist_item_cursor_get(Handle);
            }
            set
            {
                if (!string.IsNullOrEmpty(value))
                {
                    Interop.Elementary.elm_genlist_item_cursor_set(Handle, value);
                }
                else
                {
                    Interop.Elementary.elm_genlist_item_cursor_unset(Handle);
                }
            }
        }

        /// <summary>
        /// Gets or sets custom cursor for genlist item.
        /// </summary>
        [EditorBrowsable(EditorBrowsableState.Never)]
        public override string CursorStyle
        {
            get
            {
                return Interop.Elementary.elm_genlist_item_cursor_style_get(Handle);
            }
            set
            {
                Interop.Elementary.elm_genlist_item_cursor_style_set(Handle, value);
            }
        }

        /// <summary>
        /// Gets or sets whether to rely on the rendering engine.
        /// </summary>
        [EditorBrowsable(EditorBrowsableState.Never)]
        public override bool IsUseEngineCursor
        {
            get
            {
                return Interop.Elementary.elm_genlist_item_cursor_engine_only_get(Handle);
            }
            set
            {
                Interop.Elementary.elm_genlist_item_cursor_engine_only_set(Handle, value);
            }
        }

        public override void SetTooltipText(string tooltip)
        {
            Interop.Elementary.elm_genlist_item_tooltip_text_set(Handle, tooltip);
        }

        public override void UnsetTooltip()
        {
            Interop.Elementary.elm_genlist_item_tooltip_unset(Handle);
        }

        /// <summary>
        /// Gets or sets the style of given genlist item's tooltip.
        /// </summary>
        public override string TooltipStyle
        {
            get
            {
                return Interop.Elementary.elm_genlist_item_tooltip_style_get(Handle);
            }
            set
            {
                Interop.Elementary.elm_genlist_item_tooltip_style_set(Handle, value);
            }
        }

        /// <summary>
        /// Gets or sets whether disable size restrictions on an object's tooltip.
        /// </summary>
        public bool IsTooltipWindowMode
        {
            get
            {
                return Interop.Elementary.elm_genlist_item_tooltip_window_mode_get(Handle);
            }
            set
            {
                Interop.Elementary.elm_genlist_item_tooltip_window_mode_set(Handle, value);
            }
        }

        /// <summary>
        /// Gets the index of the item. It is only valid once displayed.
        /// </summary>
        public int Index
        {
            get
            {
                return Interop.Elementary.elm_genlist_item_index_get(Handle);
            }
        }

        /// <summary>
        /// Remove all sub-items (children) of the given item.
        /// </summary>
        /// <remark>
        /// This removes all items that are children (and their descendants) of the given item it.
        /// </remark>
        public void ClearSubitems()
        {
            Interop.Elementary.elm_genlist_item_subitems_clear(Handle);
        }

        /// <summary>
        /// Update the item class of an item.
        /// 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.
        /// </summary>
        /// <param name="itemClass">The item class for the item.</param>
        /// <param name="data">The data for the item.</param>
        public void UpdateItemClass(GenItemClass itemClass, object data)
        {
            Data = data;
            ItemClass = itemClass;
            Interop.Elementary.elm_genlist_item_item_class_update((IntPtr)Handle, itemClass.UnmanagedPtr);
        }

        protected override void UpdateTooltipDelegate()
        {
            Interop.Elementary.elm_genlist_item_tooltip_content_cb_set(Handle,
                TooltipContentDelegate != null ? _tooltipCb : null,
                IntPtr.Zero,
                null);
        }

    }
}