Tizen 2.1 base
[framework/osp/uifw.git] / src / ui / controls / FUiCtrlDateTimePicker.cpp
1 //
2 // Open Service Platform
3 // Copyright (c) 2012-2013 Samsung Electronics Co., Ltd.
4 //
5 // Licensed under the Flora License, Version 1.0 (the License);
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
8 //
9 //     http://floralicense.org/license/
10 //
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an AS IS BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
16 //
17 /**
18  * @file                FUiCtrlDateTimePicker.cpp
19  * @brief               This is the implementation file for the DateTimePicker class.
20  */
21
22 #include <FUiCtrlForm.h>
23 #include <FSysSystemTime.h>
24 #include <FUiCtrlDateTimePicker.h>
25 #include <FBaseSysLog.h>
26 #include "FUiCtrl_DateTimePickerImpl.h"
27
28 using namespace Tizen::Base;
29 using namespace Tizen::Graphics;
30 using namespace Tizen::System;
31
32 namespace Tizen { namespace Ui { namespace Controls
33 {
34
35 DateTimePicker::DateTimePicker(void)
36 {
37 }
38
39 DateTimePicker::~DateTimePicker(void)
40 {
41 }
42
43 result
44 DateTimePicker::Construct(const Tizen::Base::String& title)
45 {
46         _DateTimePickerImpl* pImpl = _DateTimePickerImpl::GetInstance(*this);
47         SysAssertf((pImpl == null),
48                         "Already constructed. Calling Construct() twice or more on a same instance is not allowed for this class.");
49
50         pImpl = _DateTimePickerImpl::CreateDateTimePickerImplN(this, title);
51         result r = GetLastResult();
52         SysTryReturn(NID_UI_CTRL, (pImpl != null), r, r, "[%s] Propagating.", GetErrorMessage(r));
53
54         _pControlImpl = pImpl;
55
56         pImpl->GetCore().SetResizable(false);
57         pImpl->GetCore().SetMovable(false);
58
59         return r;
60 }
61
62 void
63 DateTimePicker::AddDateTimeChangeEventListener(Tizen::Ui::IDateTimeChangeEventListener& listener)
64 {
65         _DateTimePickerImpl* pImpl = _DateTimePickerImpl::GetInstance(*this);
66         SysAssertf((pImpl != null), "Not yet constructed. Construct() should be called before use.");
67
68         result r = pImpl->AddDateTimeChangeEventListener(listener);
69         SysTryReturnVoidResult(NID_UI_CTRL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
70 }
71
72 void
73 DateTimePicker::RemoveDateTimeChangeEventListener(Tizen::Ui::IDateTimeChangeEventListener& listener)
74 {
75         _DateTimePickerImpl* pImpl = _DateTimePickerImpl::GetInstance(*this);
76         SysAssertf((pImpl != null), "Not yet constructed. Construct() should be called before use.");
77
78         result r = pImpl->RemoveDateTimeChangeEventListener(listener);
79         SysTryReturnVoidResult(NID_UI_CTRL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
80 }
81
82 void
83 DateTimePicker::SetDateTime(const Tizen::Base::DateTime& dateTime)
84 {
85         _DateTimePickerImpl* pImpl = _DateTimePickerImpl::GetInstance(*this);
86         SysAssertf((pImpl != null), "Not yet constructed. Construct() should be called before use.");
87
88         pImpl->SetDateTime(dateTime);
89         result r = GetLastResult();
90         SysTryReturnVoidResult(NID_UI_CTRL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
91 }
92
93 void
94 DateTimePicker::SetCurrentDateTime(void)
95 {
96         _DateTimePickerImpl* pImpl = _DateTimePickerImpl::GetInstance(*this);
97         SysAssertf((pImpl != null), "Not yet constructed. Construct() should be called before use.");
98
99         pImpl->SetCurrentDateTime();
100         result r = GetLastResult();
101         SysTryReturnVoidResult(NID_UI_CTRL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
102 }
103
104 result
105 DateTimePicker::SetYear(int year)
106 {
107         _DateTimePickerImpl* pImpl = _DateTimePickerImpl::GetInstance(*this);
108         SysAssertf((pImpl != null), "Not yet constructed. Construct() should be called before use.");
109
110         result r = pImpl->SetYear(year);
111         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
112
113         return r;
114 }
115
116 result
117 DateTimePicker::SetMonth(int month)
118 {
119         _DateTimePickerImpl* pImpl = _DateTimePickerImpl::GetInstance(*this);
120         SysAssertf((pImpl != null), "Not yet constructed. Construct() should be called before use.");
121
122         result r = pImpl->SetMonth(month);
123         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
124
125         return r;
126 }
127
128 result
129 DateTimePicker::SetDay(int day)
130 {
131         _DateTimePickerImpl* pImpl = _DateTimePickerImpl::GetInstance(*this);
132         SysAssertf((pImpl != null), "Not yet constructed. Construct() should be called before use.");
133
134         result r = pImpl->SetDay(day);
135         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
136
137         return r;
138 }
139
140 result
141 DateTimePicker::SetHour(int hour)
142 {
143         _DateTimePickerImpl* pImpl = _DateTimePickerImpl::GetInstance(*this);
144         SysAssertf((pImpl != null), "Not yet constructed. Construct() should be called before use.");
145
146         result r = pImpl->SetHour(hour);
147         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
148
149         return r;
150 }
151
152 result
153 DateTimePicker::SetMinute(int minute)
154 {
155         _DateTimePickerImpl* pImpl = _DateTimePickerImpl::GetInstance(*this);
156         SysAssertf((pImpl != null), "Not yet constructed. Construct() should be called before use.");
157
158         result r = pImpl->SetMinute(minute);
159         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
160
161         return r;
162 }
163
164 Tizen::Base::DateTime
165 DateTimePicker::GetDateTime(void) const
166 {
167         const _DateTimePickerImpl* pImpl = _DateTimePickerImpl::GetInstance(*this);
168         SysAssertf((pImpl != null), "Not yet constructed. Construct() should be called before use.");
169
170         DateTime dateTime = pImpl->GetDateTime();
171         result r = GetLastResult();
172         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, dateTime, r, "[%s] Propagating.", GetErrorMessage(r));
173
174         return dateTime;
175 }
176
177 int
178 DateTimePicker::GetYear(void) const
179 {
180         const _DateTimePickerImpl* pImpl = _DateTimePickerImpl::GetInstance(*this);
181         SysAssertf((pImpl != null), "Not yet constructed. Construct() should be called before use.");
182
183         int year = pImpl->GetYear();
184         result r = GetLastResult();
185         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, year, r, "[%s] Propagating.", GetErrorMessage(r));
186
187         return year;
188 }
189
190 int
191 DateTimePicker::GetMonth(void) const
192 {
193         const _DateTimePickerImpl* pImpl = _DateTimePickerImpl::GetInstance(*this);
194         SysAssertf((pImpl != null), "Not yet constructed. Construct() should be called before use.");
195
196         int month = pImpl->GetMonth();
197         result r = GetLastResult();
198         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, month, r, "[%s] Propagating.", GetErrorMessage(r));
199
200         return month;
201 }
202
203 int
204 DateTimePicker::GetDay(void) const
205 {
206         const _DateTimePickerImpl* pImpl = _DateTimePickerImpl::GetInstance(*this);
207         SysAssertf((pImpl != null), "Not yet constructed. Construct() should be called before use.");
208
209         int day = pImpl->GetDay();
210         result r = GetLastResult();
211         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, day, r, "[%s] Propagating.", GetErrorMessage(r));
212
213         return day;
214 }
215
216 int
217 DateTimePicker::GetHour(void) const
218 {
219         const _DateTimePickerImpl* pImpl = _DateTimePickerImpl::GetInstance(*this);
220         SysAssertf((pImpl != null), "Not yet constructed. Construct() should be called before use.");
221
222         int hour = pImpl->GetHour();
223         result r = GetLastResult();
224         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, hour, r, "[%s] Propagating.", GetErrorMessage(r));
225
226         return hour;
227 }
228
229 int
230 DateTimePicker::GetMinute(void) const
231 {
232         const _DateTimePickerImpl* pImpl = _DateTimePickerImpl::GetInstance(*this);
233         SysAssertf((pImpl != null), "Not yet constructed. Construct() should be called before use.");
234
235         int minute = pImpl->GetMinute();
236         result r = GetLastResult();
237         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, minute, r, "[%s] Propagating.", GetErrorMessage(r));
238
239         return minute;
240 }
241
242 void
243 DateTimePicker::Set24HourNotationEnabled(bool enable)
244 {
245         _DateTimePickerImpl* pImpl = _DateTimePickerImpl::GetInstance(*this);
246         SysAssertf((pImpl != null), "Not yet constructed. Construct() should be called before use.");
247
248         pImpl->Set24HourNotationEnabled(enable);
249         result r = GetLastResult();
250         SysTryReturnVoidResult(NID_UI_CTRL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
251 }
252
253 bool
254 DateTimePicker::Is24HourNotationEnabled(void) const
255 {
256         const _DateTimePickerImpl* pImpl = _DateTimePickerImpl::GetInstance(*this);
257         SysAssertf((pImpl != null), "Not yet constructed. Construct() should be called before use.");
258
259         bool enabled = pImpl->Is24HourNotationEnabled();
260         result r = GetLastResult();
261         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, enabled, r, "[%s] Propagating.", GetErrorMessage(r));
262
263         return enabled;
264 }
265
266 result
267 DateTimePicker::SetYearRange(int minYear, int maxYear)
268 {
269         _DateTimePickerImpl* pImpl = _DateTimePickerImpl::GetInstance(*this);
270         SysAssertf((pImpl != null), "Not yet constructed. Construct() should be called before use.");
271
272         result r = pImpl->SetYearRange(minYear, maxYear);
273         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
274
275         return r;
276 }
277
278 result
279 DateTimePicker::GetYearRange(int& minYear, int& maxYear) const
280 {
281         const _DateTimePickerImpl* pImpl = _DateTimePickerImpl::GetInstance(*this);
282         SysAssertf((pImpl != null), "Not yet constructed. Construct() should be called before use.");
283
284         return pImpl->GetYearRange(minYear, maxYear);
285 }
286
287 }}} // Tizen::Ui::Controls