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 of datetime field types for DateTimeSelector.
24 public enum DateTimeFieldType
27 /// Indicates Year field.
31 /// Indicates Month field.
35 /// Indicates Date field.
39 /// Indicates Hour field.
43 /// Indicates Minute field.
47 /// Indicates AM/PM field.
53 /// It inherits <see cref="Layout"/>
54 /// DateTimeSelector is a widget to display and input date & time values.
55 /// This widget displays date and time as per the system's locale settings
56 /// (Date includes Day, Month & Year along with the defined separators and Time includes Hour, Minute & AM/PM fields. Separator for AM/PM field is ignored.
58 public class DateTimeSelector : Layout
61 DateTime _cacheDateTime;
64 /// Creates and initializes a new instance of the DateTimeSelector class.
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)
70 _changed = new SmartEvent(this, this.RealHandle, "changed");
71 _changed.On += (s, e) =>
73 DateTime newDateTime = DateTime;
74 DateTimeChanged?.Invoke(this, new DateChangedEventArgs(_cacheDateTime, newDateTime));
75 DateTime = newDateTime;
80 /// ItemSelected is raised when Datetime field value changed.
82 public event EventHandler<DateChangedEventArgs> DateTimeChanged;
85 /// Gets or sets the datetime format.
88 /// format is a combination of allowed LIBC date format specifiers like: "%b %d, %Y %I : %M %p".
94 return Interop.Elementary.elm_datetime_format_get(RealHandle);
98 Interop.Elementary.elm_datetime_format_set(RealHandle, value);
103 /// Gets or sets the upper boundary of DateTime field.
105 public DateTime MaximumDateTime
109 var tm = new Interop.Libc.SystemTime();
110 Interop.Elementary.elm_datetime_value_max_get(RealHandle, ref tm);
115 Interop.Libc.SystemTime tm = value;
116 Interop.Elementary.elm_datetime_value_max_set(RealHandle, ref tm);
121 /// Gets or sets the lower boundary of DateTime field.
123 public DateTime MinimumDateTime
127 var tm = new Interop.Libc.SystemTime();
128 Interop.Elementary.elm_datetime_value_min_get(RealHandle, ref tm);
133 Interop.Libc.SystemTime tm = value;
134 Interop.Elementary.elm_datetime_value_min_set(RealHandle, ref tm);
139 /// Gets or sets the current value of DateTime field.
141 public DateTime DateTime
145 var tm = new Interop.Libc.SystemTime();
146 Interop.Elementary.elm_datetime_value_get(RealHandle, ref tm);
151 Interop.Libc.SystemTime tm = value;
152 Interop.Elementary.elm_datetime_value_set(RealHandle, ref tm);
153 _cacheDateTime = value;
158 /// Gets whether a field can be visible.
160 /// <param name="type">Enumeration <see cref="DateTimeFieldType"/></param>
162 /// The field is visible or not.
163 /// Type is bool.If visible, return true.
165 public bool IsFieldVisible(DateTimeFieldType type)
167 return Interop.Elementary.elm_datetime_field_visible_get(RealHandle, (int)type);
171 /// Sets the field limits of a field.
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)
178 Interop.Elementary.elm_datetime_field_limit_set(RealHandle, (int)type, minimum, maximum);
182 /// Gets whether a field can be visible.
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)
188 Interop.Elementary.elm_datetime_field_visible_set(RealHandle, (int)type, visible);
192 /// Creates a widget handle.
194 /// <param name="parent">Parent EvasObject</param>
195 /// <returns>Handle IntPtr</returns>
196 protected override IntPtr CreateHandle(EvasObject parent)
198 IntPtr handle = Interop.Elementary.elm_layout_add(parent.Handle);
199 Interop.Elementary.elm_layout_theme_set(handle, "layout", "elm_widget", "default");
201 RealHandle = Interop.Elementary.elm_datetime_add(handle);
202 Interop.Elementary.elm_object_part_content_set(handle, "elm.swallow.content", RealHandle);