2 * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
22 /// Enumeration for the datetime field types for DateTimeSelector.
24 /// <since_tizen> preview </since_tizen>
25 public enum DateTimeFieldType
28 /// Indicates the Year field.
32 /// Indicates the Month field.
36 /// Indicates the Date field.
40 /// Indicates the Hour field.
44 /// Indicates the Minute field.
48 /// Indicates the AM/PM field.
54 /// It inherits <see cref="Layout"/>.
55 /// The DateTimeSelector is a widget to display and input the date & time values.
56 /// This widget displays the date and time as per the system's locale settings
57 /// (Date includes Day, Month & Year) along with the defined separators and time including hour, minute & AM/PM fields. Separator for the AM/PM field is ignored.
59 /// <since_tizen> preview </since_tizen>
60 public class DateTimeSelector : Layout
63 DateTime _cacheDateTime;
66 /// Creates and initializes a new instance of the DateTimeSelector class.
68 /// <param name="parent">The parent is a given container, which will be attached by the DateTimeSelector
69 /// as a child. It's <see cref="EvasObject"/> type.</param>
70 /// <since_tizen> preview </since_tizen>
71 public DateTimeSelector(EvasObject parent) : base(parent)
76 /// Creates and initializes a new instance of the DateTimeSelector class.
78 /// <since_tizen> preview </since_tizen>
79 protected DateTimeSelector() : base()
84 /// ItemSelected is raised when the DateTime field value is changed.
86 /// <since_tizen> preview </since_tizen>
87 public event EventHandler<DateChangedEventArgs> DateTimeChanged;
90 /// Gets or sets the datetime format.
93 /// Format is a combination of the allowed LIBC date format specifiers like: "%b %d, %Y %I : %M %p".
95 /// <since_tizen> preview </since_tizen>
100 return Interop.Elementary.elm_datetime_format_get(RealHandle);
104 Interop.Elementary.elm_datetime_format_set(RealHandle, value);
109 /// Gets or sets the upper boundary of the DateTime field.
111 /// <since_tizen> preview </since_tizen>
112 public DateTime MaximumDateTime
116 var tm = new Interop.Libc.SystemTime();
117 Interop.Elementary.elm_datetime_value_max_get(RealHandle, ref tm);
122 Interop.Libc.SystemTime tm = value;
123 Interop.Elementary.elm_datetime_value_max_set(RealHandle, ref tm);
128 /// Gets or sets the lower boundary of the DateTime field.
130 /// <since_tizen> preview </since_tizen>
131 public DateTime MinimumDateTime
135 var tm = new Interop.Libc.SystemTime();
136 Interop.Elementary.elm_datetime_value_min_get(RealHandle, ref tm);
141 Interop.Libc.SystemTime tm = value;
142 Interop.Elementary.elm_datetime_value_min_set(RealHandle, ref tm);
147 /// Gets or sets the current value of the DateTime field.
149 /// <since_tizen> preview </since_tizen>
150 public DateTime DateTime
154 var tm = new Interop.Libc.SystemTime();
155 Interop.Elementary.elm_datetime_value_get(RealHandle, ref tm);
160 Interop.Libc.SystemTime tm = value;
161 Interop.Elementary.elm_datetime_value_set(RealHandle, ref tm);
162 _cacheDateTime = value;
167 /// Gets whether a field can be visible.
169 /// <param name="type">Enumeration for <see cref="DateTimeFieldType"/>.</param>
171 /// The field is visible or not.
172 /// Type is bool. If visible, return true.
174 /// <since_tizen> preview </since_tizen>
175 public bool IsFieldVisible(DateTimeFieldType type)
177 return Interop.Elementary.elm_datetime_field_visible_get(RealHandle, (int)type);
181 /// Sets the field limits of a field.
183 /// <param name="type">Enumeration for <see cref="DateTimeFieldType"/>.</param>
184 /// <param name="minimum">The minimum limit.</param>
185 /// <param name="maximum">The maximum limit.</param>
186 /// <since_tizen> preview </since_tizen>
187 public void SetFieldLimit(DateTimeFieldType type, int minimum, int maximum)
189 Interop.Elementary.elm_datetime_field_limit_set(RealHandle, (int)type, minimum, maximum);
193 /// Gets whether a field can be visible.
195 /// <param name="type">Enumeration for <see cref="DateTimeFieldType"/>.</param>
196 /// <param name="visible">When set as true, the field type is visible.</param>
197 /// <since_tizen> preview </since_tizen>
198 public void SetFieldVisible(DateTimeFieldType type, bool visible)
200 Interop.Elementary.elm_datetime_field_visible_set(RealHandle, (int)type, visible);
204 /// The callback of the Realized event.
206 /// <since_tizen> preview </since_tizen>
207 protected override void OnRealized()
210 _changed = new SmartEvent(this, this.RealHandle, "changed");
211 _changed.On += (s, e) =>
213 DateTime newDateTime = DateTime;
214 DateTimeChanged?.Invoke(this, new DateChangedEventArgs(_cacheDateTime, newDateTime));
215 DateTime = newDateTime;
220 /// Creates a widget handle.
222 /// <param name="parent">Parent EvasObject.</param>
223 /// <returns>Handle IntPtr.</returns>
224 /// <since_tizen> preview </since_tizen>
225 protected override IntPtr CreateHandle(EvasObject parent)
227 IntPtr handle = Interop.Elementary.elm_layout_add(parent.Handle);
228 Interop.Elementary.elm_layout_theme_set(handle, "layout", "elm_widget", "default");
230 RealHandle = Interop.Elementary.elm_datetime_add(handle);
231 Interop.Elementary.elm_object_part_content_set(handle, "elm.swallow.content", RealHandle);