Add CircleSurface and Change Every circle object
[platform/core/csapi/tizenfx.git] / src / ElmSharp / ElmSharp / DateTimeSelector.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     /// <summary>
22     /// Enumeration of datetime field types for DateTimeSelector.
23     /// </summary>
24     public enum DateTimeFieldType
25     {
26         /// <summary>
27         /// Indicates Year field.
28         /// </summary>
29         Year,
30         /// <summary>
31         /// Indicates Month field.
32         /// </summary>
33         Month,
34         /// <summary>
35         /// Indicates Date field.
36         /// </summary>
37         Date,
38         /// <summary>
39         /// Indicates Hour field.
40         /// </summary>
41         Hour,
42         /// <summary>
43         /// Indicates Minute field.
44         /// </summary>
45         Minute,
46         /// <summary>
47         /// Indicates AM/PM field.
48         /// </summary>
49         AmPm
50     }
51
52     /// <summary>
53     /// It inherits <see cref="Layout"/>
54     /// DateTimeSelector is a widget to display and input date &amp; time values.
55     /// This widget displays date and time as per the system's locale settings
56     /// (Date includes Day, Month &amp; Year along with the defined separators and Time includes Hour, Minute &amp; AM/PM fields. Separator for AM/PM field is ignored.
57     /// </summary>
58     public class DateTimeSelector : Layout
59     {
60         SmartEvent _changed;
61         DateTime _cacheDateTime;
62
63         /// <summary>
64         /// Creates and initializes a new instance of the DateTimeSelector class.
65         /// </summary>
66         /// <param name="parent">The parent is a given container which will be attached by DateTimeSelector
67         ///as a child.It's <see cref="EvasObject"/> type.</param>
68         public DateTimeSelector(EvasObject parent) : base(parent)
69         {
70         }
71
72         /// <summary>
73         /// Creates and initializes a new instance of DateTimeSelector class.
74         /// </summary>
75         protected DateTimeSelector() : base()
76         {
77         }
78
79         /// <summary>
80         /// ItemSelected is raised when Datetime field value changed.
81         /// </summary>
82         public event EventHandler<DateChangedEventArgs> DateTimeChanged;
83
84         /// <summary>
85         /// Gets or sets the datetime format.
86         /// </summary>
87         /// <remarks>
88         /// format is a combination of allowed LIBC date format specifiers like: "%b %d, %Y %I : %M %p".
89         /// </remarks>
90         public string Format
91         {
92             get
93             {
94                 return Interop.Elementary.elm_datetime_format_get(RealHandle);
95             }
96             set
97             {
98                 Interop.Elementary.elm_datetime_format_set(RealHandle, value);
99             }
100         }
101
102         /// <summary>
103         /// Gets or sets the upper boundary of DateTime field.
104         /// </summary>
105         public DateTime MaximumDateTime
106         {
107             get
108             {
109                 var tm = new Interop.Libc.SystemTime();
110                 Interop.Elementary.elm_datetime_value_max_get(RealHandle, ref tm);
111                 return tm;
112             }
113             set
114             {
115                 Interop.Libc.SystemTime tm = value;
116                 Interop.Elementary.elm_datetime_value_max_set(RealHandle, ref tm);
117             }
118         }
119
120         /// <summary>
121         /// Gets or sets the lower boundary of DateTime field.
122         /// </summary>
123         public DateTime MinimumDateTime
124         {
125             get
126             {
127                 var tm = new Interop.Libc.SystemTime();
128                 Interop.Elementary.elm_datetime_value_min_get(RealHandle, ref tm);
129                 return tm;
130             }
131             set
132             {
133                 Interop.Libc.SystemTime tm = value;
134                 Interop.Elementary.elm_datetime_value_min_set(RealHandle, ref tm);
135             }
136         }
137
138         /// <summary>
139         /// Gets or sets the current value of DateTime field.
140         /// </summary>
141         public DateTime DateTime
142         {
143             get
144             {
145                 var tm = new Interop.Libc.SystemTime();
146                 Interop.Elementary.elm_datetime_value_get(RealHandle, ref tm);
147                 return tm;
148             }
149             set
150             {
151                 Interop.Libc.SystemTime tm = value;
152                 Interop.Elementary.elm_datetime_value_set(RealHandle, ref tm);
153                 _cacheDateTime = value;
154             }
155         }
156
157         /// <summary>
158         /// Gets whether a field can be visible.
159         /// </summary>
160         /// <param name="type">Enumeration <see cref="DateTimeFieldType"/></param>
161         /// <returns>
162         /// The field is visible or not.
163         /// Type is bool.If visible, return true.
164         /// </returns>
165         public bool IsFieldVisible(DateTimeFieldType type)
166         {
167             return Interop.Elementary.elm_datetime_field_visible_get(RealHandle, (int)type);
168         }
169
170         /// <summary>
171         /// Sets the field limits of a field.
172         /// </summary>
173         /// <param name="type">Enumeration <see cref="DateTimeFieldType"/></param>
174         /// <param name="minimum">minimum limit</param>
175         /// <param name="maximum">maximum limit</param>
176         public void SetFieldLimit(DateTimeFieldType type, int minimum, int maximum)
177         {
178             Interop.Elementary.elm_datetime_field_limit_set(RealHandle, (int)type, minimum, maximum);
179         }
180
181         /// <summary>
182         /// Gets whether a field can be visible.
183         /// </summary>
184         /// <param name="type">Enumeration <see cref="DateTimeFieldType"/></param>
185         /// <param name="visible">When set as true, the field type visible.</param>
186         public void SetFieldVisible(DateTimeFieldType type, bool visible)
187         {
188             Interop.Elementary.elm_datetime_field_visible_set(RealHandle, (int)type, visible);
189         }
190
191         /// <summary>
192         /// The callback of Realized Event
193         /// </summary>
194         protected override void OnRealized()
195         {
196             base.OnRealized();
197             _changed = new SmartEvent(this, this.RealHandle, "changed");
198             _changed.On += (s, e) =>
199             {
200                 DateTime newDateTime = DateTime;
201                 DateTimeChanged?.Invoke(this, new DateChangedEventArgs(_cacheDateTime, newDateTime));
202                 DateTime = newDateTime;
203             };
204         }
205
206         /// <summary>
207         /// Creates a widget handle.
208         /// </summary>
209         /// <param name="parent">Parent EvasObject</param>
210         /// <returns>Handle IntPtr</returns>
211         protected override IntPtr CreateHandle(EvasObject parent)
212         {
213             IntPtr handle = Interop.Elementary.elm_layout_add(parent.Handle);
214             Interop.Elementary.elm_layout_theme_set(handle, "layout", "elm_widget", "default");
215
216             RealHandle = Interop.Elementary.elm_datetime_add(handle);
217             Interop.Elementary.elm_object_part_content_set(handle, "elm.swallow.content", RealHandle);
218
219             return handle;
220         }
221     }
222 }