Merge "Add Additional Method for ColorSelector" into tizen
[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     public enum DateTimeFieldType
22     {
23         Year,
24         Month,
25         Date,
26         Hour,
27         Minute,
28         AmPm
29     }
30
31     public class DateTimeSelector : Layout
32     {
33         SmartEvent _changed;
34         DateTime _cacheDateTime;
35
36         public DateTimeSelector(EvasObject parent) : base(parent)
37         {
38             _changed = new SmartEvent(this, this.RealHandle, "changed");
39             _changed.On += (s, e) =>
40             {
41                 DateTime newDateTime = DateTime;
42                 DateTimeChanged?.Invoke(this, new DateChangedEventArgs(_cacheDateTime, newDateTime));
43                 DateTime = newDateTime;
44             };
45         }
46
47         public event EventHandler<DateChangedEventArgs> DateTimeChanged;
48
49         public string Format
50         {
51             get
52             {
53                 return Interop.Elementary.elm_datetime_format_get(RealHandle);
54             }
55             set
56             {
57                 Interop.Elementary.elm_datetime_format_set(RealHandle, value);
58             }
59         }
60
61         public DateTime MaximumDateTime
62         {
63             get
64             {
65                 var tm = new Interop.Libc.SystemTime();
66                 Interop.Elementary.elm_datetime_value_max_get(RealHandle, ref tm);
67                 return tm;
68             }
69             set
70             {
71                 Interop.Libc.SystemTime tm = value;
72                 Interop.Elementary.elm_datetime_value_max_set(RealHandle, ref tm);
73             }
74         }
75
76         public DateTime MinimumDateTime
77         {
78             get
79             {
80                 var tm = new Interop.Libc.SystemTime();
81                 Interop.Elementary.elm_datetime_value_min_get(RealHandle, ref tm);
82                 return tm;
83             }
84             set
85             {
86                 Interop.Libc.SystemTime tm = value;
87                 Interop.Elementary.elm_datetime_value_min_set(RealHandle, ref tm);
88             }
89         }
90
91         public DateTime DateTime
92         {
93             get
94             {
95                 var tm = new Interop.Libc.SystemTime();
96                 Interop.Elementary.elm_datetime_value_get(RealHandle, ref tm);
97                 return tm;
98             }
99             set
100             {
101                 Interop.Libc.SystemTime tm = value;
102                 Interop.Elementary.elm_datetime_value_set(RealHandle, ref tm);
103                 _cacheDateTime = value;
104             }
105         }
106
107         public bool IsFieldVisible(DateTimeFieldType type)
108         {
109             return Interop.Elementary.elm_datetime_field_visible_get(RealHandle, (int)type);
110         }
111
112         public void SetFieldLimit(DateTimeFieldType type, int minimum, int maximum)
113         {
114             Interop.Elementary.elm_datetime_field_limit_set(RealHandle, (int)type, minimum, maximum);
115         }
116
117         public void SetFieldVisible(DateTimeFieldType type, bool visible)
118         {
119             Interop.Elementary.elm_datetime_field_visible_set(RealHandle, (int)type, visible);
120         }
121
122         protected override IntPtr CreateHandle(EvasObject parent)
123         {
124             IntPtr handle = Interop.Elementary.elm_layout_add(parent.Handle);
125             Interop.Elementary.elm_layout_theme_set(handle, "layout", "elm_widget", "default");
126
127             RealHandle = Interop.Elementary.elm_datetime_add(handle);
128             Interop.Elementary.elm_object_part_content_set(handle, "elm.swallow.content", RealHandle);
129
130             return handle;
131         }
132     }
133 }