Release 4.0.0-preview1-00051
[platform/core/csapi/tizenfx.git] / src / ElmSharp / ElmSharp / GenItem.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
19 namespace ElmSharp
20 {
21     public enum GenItemSelectionMode
22     {
23         /// <summary>
24         /// Default select mode.
25         /// </summary>
26         Default,
27
28         /// <summary>
29         /// Always select mode.
30         /// </summary>
31         Always,
32
33         /// <summary>
34         /// No select mode.
35         /// </summary>
36         None,
37
38         /// <summary>
39         /// No select mode with no finger size rule.
40         /// </summary>
41         DisplayOnly
42     }
43
44     /// <summary>
45     /// It inherits <see cref="ItemObject"/>.
46     /// A base class for <see cref="GenGridItem"/> and <see cref="GenListItem"/>.
47     /// It contains genitem class and data to display data.
48     /// </summary>
49     public abstract class GenItem : ItemObject
50     {
51         internal Interop.Elementary.Elm_Tooltip_Item_Content_Cb _tooltipCb;
52         GetTooltipContentDelegate _tooltipContentDelegate = null;
53
54         /// <summary>
55         /// The delegate returning the tooltip contents.
56         /// </summary>
57         public delegate EvasObject GetTooltipContentDelegate();
58
59         internal GenItem(object data, GenItemClass itemClass) : base(IntPtr.Zero)
60         {
61             Data = data;
62             ItemClass = itemClass;
63             _tooltipCb = (d, obj, tooltip, item) => { return TooltipContentDelegate(); };
64         }
65
66         /// <summary>
67         /// Gets the item class that defines how to display data. It returns <see cref="GenItemClass"/> type.
68         /// </summary>
69         public GenItemClass ItemClass { get; protected set; }
70
71         /// <summary>
72         /// It's a abstract property. It's implemented by <see cref="GenGridItem.TooltipContent"/> and <see cref="GenListItem.TooltipContent"/>.
73         /// </summary>
74         public GetTooltipContentDelegate TooltipContentDelegate
75         {
76             get
77             {
78                 return _tooltipContentDelegate;
79             }
80             set
81             {
82                 _tooltipContentDelegate = value;
83                 UpdateTooltipDelegate();
84             }
85         }
86
87         public abstract GenItemSelectionMode SelectionMode { get; set; }
88
89         public abstract string Cursor { get; set; }
90         public abstract string CursorStyle { get; set; }
91
92         public abstract bool IsUseEngineCursor { get; set; }
93
94         /// <summary>
95         /// Gets item data that is added through calling <see cref="GenGrid.Append(GenItemClass, object)"/>, <see cref="GenGrid.Prepend(GenItemClass, object)"/> or <see cref="GenGrid.InsertBefore(GenItemClass, object, GenGridItem)"/> methods.
96         /// </summary>
97         public object Data { get; protected set; }
98
99         /// <summary>
100         /// It's a abstract property. It's implemented by <see cref="GenGridItem.IsSelected"/> and <see cref="GenListItem.IsSelected"/>.
101         /// </summary>
102         public abstract bool IsSelected { get; set; }
103
104         /// <summary>
105         /// It's a abstract property. It's implemented by <see cref="GenGridItem.TooltipStyle"/> and <see cref="GenListItem.TooltipStyle"/>.
106         /// </summary>
107         public abstract string TooltipStyle { get; set; }
108
109         public abstract void SetTooltipText(string tooltip);
110         public abstract void UnsetTooltip();
111
112         /// <summary>
113         /// It's a abstract method. It's implemented by <see cref="GenGridItem.Update"/> and <see cref="GenListItem.Update"/>.
114         /// </summary>
115         public abstract void Update();
116
117         /// <summary>
118         /// The override method for delete item class and item data. It's called when the item is deleting.
119         /// </summary>
120         protected override void OnInvalidate()
121         {
122             ItemClass?.SendItemDeleted(Data);
123             Data = null;
124             ItemClass = null;
125         }
126
127         protected abstract void UpdateTooltipDelegate();
128     }
129 }