Changed indicator bg color.
[platform/framework/native/uifw.git] / src / ui / controls / FUiCtrl_DateTimePicker.cpp
1 //
2 // Open Service Platform
3 // Copyright (c) 2012-2013 Samsung Electronics Co., Ltd.
4 //
5 // Licensed under the Apache License, Version 2.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://www.apache.org/licenses/LICENSE-2.0/
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 /**
19  * @file                FUiCtrl_DateTimePicker.cpp
20  * @brief               This is the implementation file for the _DateTimePicker class.
21  */
22
23 #include <FGrpDimension.h>
24 #include <FBaseColIEnumeratorT.h>
25 #include <FBaseSysLog.h>
26 #include <FGrp_BitmapImpl.h>
27 #include <FSysSettingInfo.h>
28
29 #include "FUiCtrl_DateTimePicker.h"
30 #include "FUiAnim_VisualElement.h"
31 #include "FUiCtrl_DateTimeDefine.h"
32 #include "FUiCtrl_DateTimePresenter.h"
33 #include "FUiCtrl_DateTimeDisplayBox.h"
34 #include "FUiCtrl_Form.h"
35 #include "FUiCtrl_Frame.h"
36 #include "FUiCtrl_Button.h"
37 #include "FUiCtrl_Toolbar.h"
38 #include "FUiCtrl_DateTimeChangeEvent.h"
39 #include "FUiCtrl_IDateTimeChangeEventListener.h"
40 #include "FUiCtrl_DateTimeUtils.h"
41 #include "FUi_AccessibilityContainer.h"
42 #include "FUi_AccessibilityElement.h"
43 #include "FUi_AccessibilityManager.h"
44 #include "FUi_UiTouchEvent.h"
45 #include "FUi_ResourceManager.h"
46 #include "FUi_CoordinateSystemUtils.h"
47
48 using namespace Tizen::Base;
49 using namespace Tizen::Base::Collection;
50 using namespace Tizen::Graphics;
51 using namespace Tizen::Ui;
52 using namespace Tizen::Ui::Animations;
53 using namespace Tizen::System;
54
55 namespace Tizen { namespace Ui { namespace Controls
56 {
57
58 IMPLEMENT_PROPERTY(_DateTimePicker);
59
60 _DateTimePicker::_DateTimePicker(_DateTimePresenter* pPresenter, const String& title)
61         : __pPresenter(pPresenter)
62         , __pFooter(null)
63         , __title(title)
64         , __pDateTimeChangeEvent(null)
65         , __pFont(null)
66         , __pDisplayVisualElement(null)
67 {
68 }
69
70 _DateTimePicker::~_DateTimePicker(void)
71 {
72         SettingInfo::RemoveSettingEventListener(*this);
73
74         if (__pDateTimeChangeEvent != null)
75         {
76                 delete __pDateTimeChangeEvent;
77                 __pDateTimeChangeEvent = null;
78         }
79
80         if (__pFooter != null)
81         {
82                 DetachSystemChild(*__pFooter);
83                 delete __pFooter;
84                 __pFooter = null;
85         }
86
87         if (__pDisplayVisualElement != null)
88         {
89                 __pDisplayVisualElement->Destroy();
90                 __pDisplayVisualElement = null;
91         }
92
93         delete __pPresenter;
94         __pPresenter = null;
95 }
96
97 _DateTimePicker*
98 _DateTimePicker::CreateDateTimePickerN(int style, const String& title)
99 {
100         result r = E_SUCCESS;
101         FloatDimension pickerSize(0.0f, 0.0f);
102         FloatDimension screenSize(0.0f, 0.0f);
103         _ControlOrientation orientation = _CONTROL_ORIENTATION_PORTRAIT;
104         _DateTimePresenter* pPresenter = null;
105         _DateTimePicker* pView = null;
106
107         SysTryReturn(NID_UI_CTRL, ((style & DATETIME_OUTPUT_STYLE_DATETIME) != DATETIME_OUTPUT_STYLE_INVALID), null, E_INVALID_ARG,
108                                 "[E_INVALID_ARG] Invalid argument(s) is used. The style provided is not present in the _DateTimeOutputStyle list.");
109
110         pPresenter = new (std::nothrow) _DateTimePresenter(style, title);
111         SysTryReturn(NID_UI_CTRL, (pPresenter != null), null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
112
113         pView = new (std::nothrow) _DateTimePicker(pPresenter, title);
114         SysTryCatch(NID_UI_CTRL, (pView != null), , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
115
116         r = pView->InitializeFont();
117         SysTryCatch(NID_UI_CTRL, (r == E_SUCCESS), , E_SYSTEM, "[E_SYSTEM] A system error has occurred. Failed to set the Font.");
118
119         r = pView->CreateRootVisualElement();
120         SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
121
122         orientation = pView->GetOrientation();
123         screenSize = _ControlManager::GetInstance()->GetScreenSizeF();
124         pickerSize = screenSize;
125         if (orientation == _CONTROL_ORIENTATION_LANDSCAPE)
126         {
127                 pickerSize.width = screenSize.height;
128                 pickerSize.height = screenSize.width;
129         }
130
131         r = pView->SetSize(pickerSize);
132         SysTryCatch(NID_UI_CTRL, (r == E_SUCCESS), , E_SYSTEM,
133                                 "[E_SYSTEM] A system error has occurred. Failed to set the size for this control");
134
135         r = pView->CreateFooter();
136         SysTryCatch(NID_UI_CTRL, (r == E_SUCCESS), , E_SYSTEM,
137                                         "[E_SYSTEM] A system error has occurred. Failed to create the footer for this control");
138
139         r = pView->CreateDisplayVisualElement();
140         SysTryCatch(NID_UI_CTRL, (r == E_SUCCESS), , E_SYSTEM,
141                                         "[E_SYSTEM] A system error has occurred. Failed to create the display visual element for this control");
142
143         r = pPresenter->Construct(*pView);
144         SysTryCatch(NID_UI_CTRL, (r == E_SUCCESS), , E_SYSTEM,
145                                         "[E_SYSTEM] A system error has occurred. Failed to construct the presenter instance for this control");
146
147         pView->AcquireHandle();
148
149         pView->__pDateTimeChangeEvent = new (std::nothrow) _DateTimeChangeEvent(*pView);
150         SysTryCatch(NID_UI_CTRL, (pView->__pDateTimeChangeEvent != null), , E_OUT_OF_MEMORY,
151                            "[E_OUT_OF_MEMORY] Memory allocation failed.");
152
153         if (pView->GetAccessibilityContainer() != null)
154         {
155                 pView->GetAccessibilityContainer()->Activate(true);
156         }
157
158         r = SettingInfo::AddSettingEventListener(*pView);
159         SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
160
161         return pView;
162
163 CATCH:
164         delete pPresenter;
165         delete pView;
166
167         return null;
168 }
169
170 result
171 _DateTimePicker::CreateFooter(void)
172 {
173         result r = E_SUCCESS;
174         _Button* pSaveButton = null;
175         _Button* pCancelButton = null;
176         FloatRectangle bounds;
177         String text;
178         _ControlOrientation orientation = GetOrientation();
179
180         _Toolbar* pFooter = _Toolbar::CreateToolbarN(false);
181         r = GetLastResult();
182         SysTryReturnResult(NID_UI_CTRL, (pFooter != null), r, "[%s] Propagating.", GetErrorMessage(r));
183
184         r = AttachSystemChild(*pFooter);
185         SysTryCatch(NID_UI_CTRL, (r == E_SUCCESS), , r, "[%s] Propagating.", GetErrorMessage(r));
186
187         GET_SHAPE_CONFIG(DATETIMEPICKER::FOOTER_HEIGHT, orientation, bounds.height);
188         GET_SHAPE_CONFIG(DATETIMEPICKER::INPUTPAD_HEIGHT, orientation, bounds.y);
189
190         bounds.x = 0.0f;
191         bounds.y = GetBoundsF().height - bounds.y - bounds.height;
192         bounds.width = GetBoundsF().width;
193
194         pFooter->SetMovable(true);
195         pFooter->SetResizable(true);
196
197         r = pFooter->SetBounds(bounds);
198         SysTryCatch(NID_UI_CTRL, (r == E_SUCCESS), , r, "[%s] Propagating.", GetErrorMessage(r));
199
200         pFooter->SetMovable(false);
201         pFooter->SetResizable(false);
202
203         pFooter->AddActionEventListener(*this);
204
205         r = pFooter->SetStyle(TOOLBAR_TEXT);
206         SysTryCatch(NID_UI_CTRL, (r == E_SUCCESS), , r, "[%s] Propagating.", GetErrorMessage(r));
207
208         // Create 'Save' button
209         pSaveButton = _Button::CreateButtonN();
210         r = GetLastResult();
211         SysTryCatch(NID_UI_CTRL, (r == E_SUCCESS), , r, "[%s] Propagating.", GetErrorMessage(r));
212
213         r = pSaveButton->SetActionId(DATETIME_EVENT_ID_SAVE);
214         SysTryCatch(NID_UI_CTRL, (r == E_SUCCESS), , r, "[%s] Propagating.", GetErrorMessage(r));
215
216         GET_STRING_CONFIG(IDS_TPLATFORM_BUTTON_SAVE, text);
217
218         r = pSaveButton->SetText(text);
219         SysTryCatch(NID_UI_CTRL, (r == E_SUCCESS), , r, "[%s] Propagating.", GetErrorMessage(r));
220
221         // Create 'Cancel' button
222         pCancelButton = _Button::CreateButtonN();
223         r = GetLastResult();
224         SysTryCatch(NID_UI_CTRL, (r == E_SUCCESS), , r, "[%s] Propagating.", GetErrorMessage(r));
225
226         r = pCancelButton->SetActionId(DATETIME_EVENT_ID_CANCEL);
227         SysTryCatch(NID_UI_CTRL, (r == E_SUCCESS), , r, "[%s] Propagating.", GetErrorMessage(r));
228
229         GET_STRING_CONFIG(IDS_TPLATFORM_BUTTON_CANCEL_ABB, text);
230
231         r = pCancelButton->SetText(text);
232         SysTryCatch(NID_UI_CTRL, (r == E_SUCCESS), , r, "[%s] Propagating.", GetErrorMessage(r));
233
234         r = pFooter->AddItem(pSaveButton);
235         SysTryCatch(NID_UI_CTRL, (r == E_SUCCESS), , r, "[%s] Propagating.", GetErrorMessage(r));
236
237         r = pFooter->AddItem(pCancelButton);
238         SysTryCatch(NID_UI_CTRL, (r == E_SUCCESS), , r, "[%s] Propagating.");
239
240         if (__pFooter != null)
241         {
242                 DetachSystemChild(*__pFooter);
243
244                 delete __pFooter;
245                 __pFooter = null;
246         }
247
248         __pFooter = pFooter;
249
250         return E_SUCCESS;
251 CATCH:
252         DetachSystemChild(*pFooter);
253
254         delete pFooter;
255         delete pSaveButton;
256         delete pCancelButton;
257
258         return r;
259 }
260
261 result
262 _DateTimePicker::DestroyFooter(void)
263 {
264         if (__pFooter != null)
265         {
266                 DetachSystemChild(*__pFooter);
267
268                 delete __pFooter;
269                 __pFooter = null;
270         }
271
272         return E_SUCCESS;
273 }
274
275 result
276 _DateTimePicker::CreateDisplayVisualElement(void)
277 {
278         result r = E_SUCCESS;
279
280         __pDisplayVisualElement = new (std::nothrow) _VisualElement();
281         SysTryReturnResult(NID_UI_CTRL, __pDisplayVisualElement, E_OUT_OF_MEMORY, "Memory allocation failed.");
282
283         r = __pDisplayVisualElement->Construct();
284         SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
285
286         __pDisplayVisualElement->SetShowState(true);
287         __pDisplayVisualElement->SetImplicitAnimationEnabled(false);
288
289         r = GetVisualElement()->AttachChild(*__pDisplayVisualElement);
290         SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
291
292         return r;
293
294 CATCH:
295         __pDisplayVisualElement->Destroy();
296         __pDisplayVisualElement = null;
297
298         return r;
299 }
300
301 void
302 _DateTimePicker::SetDisplayVisualElementBounds(FloatRectangle bounds)
303 {
304         if (__pDisplayVisualElement != null)
305         {
306                 __pDisplayVisualElement->SetBounds(FloatRectangle(bounds.x, bounds.y, bounds.width, bounds.height));
307         }
308
309         return;
310 }
311
312 _VisualElement*
313 _DateTimePicker::GetDisplayVisualElement(void)
314 {
315         return __pDisplayVisualElement;
316 }
317
318 result
319 _DateTimePicker::AddDateTimeChangeEventListener(const Controls::_IDateTimeChangeEventListener& listener)
320 {
321         SysTryReturnResult(NID_UI_CTRL, (__pDateTimeChangeEvent != null), E_SYSTEM,
322                                            "A system error has occurred. The _DateTimeChangeEvent instance is null.");
323
324         result r = __pDateTimeChangeEvent->AddListener(listener);
325         SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Propagating.");
326
327         return r;
328 }
329
330 result
331 _DateTimePicker::RemoveDateTimeChangeEventListener(const Controls::_IDateTimeChangeEventListener& listener)
332 {
333         SysTryReturnResult(NID_UI_CTRL, (__pDateTimeChangeEvent != null), E_SYSTEM,
334                                            "A system error has occurred. The _DateTimeChangeEvent instance is null.");
335
336         result r = __pDateTimeChangeEvent->RemoveListener(listener);
337         SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Propagating.");
338
339         return r;
340 }
341
342 result
343 _DateTimePicker::FireDateTimeChangeEvent(_DateTimeChangeStatus status, DateTime& dateTime)
344 {
345         SysTryReturnResult(NID_UI_CTRL, (__pDateTimeChangeEvent != null), E_SYSTEM,
346                                            "A system error has occurred. The _DateTimeChangeEvent instance is null");
347
348         SysTryReturnResult(NID_UI_CTRL, (status >= DATE_INTERNAL_CHANGE_SAVED && status <= TIME_INTERNAL_CHANGE_CANCELED), E_INVALID_ARG,
349                                            "Invalid argument(s) is used. The status provided is not present in the _DateTimeChangeStatus list.");
350
351         _DateTimeChangeEventArg* pDateTimeEventArg = new (std::nothrow) _DateTimeChangeEventArg(status);
352         SysTryReturnResult(NID_UI_CTRL, (pDateTimeEventArg != null), E_OUT_OF_MEMORY, "Memory allocation failed.");
353
354         pDateTimeEventArg->SetDateTime(dateTime);
355         pDateTimeEventArg->SetDate(dateTime.GetYear(), dateTime.GetMonth(), dateTime.GetDay());
356         pDateTimeEventArg->SetTime(dateTime.GetHour(), dateTime.GetMinute());
357         __pDateTimeChangeEvent->Fire(*pDateTimeEventArg);
358
359         return E_SUCCESS;
360 }
361
362 result
363 _DateTimePicker::SetPropertyYear(const Variant& year)
364 {
365         int yearValue = year.ToInt();
366
367         SysTryReturnResult(NID_UI_CTRL, (yearValue >= DATETIME_YEAR_MIN && yearValue <= DATETIME_YEAR_MAX), E_INVALID_ARG,
368                                            "Invalid argument(s) is used. The year (%d) must be greater than or equal to (%d) and less than or equal to (%d).", yearValue, DATETIME_YEAR_MIN, DATETIME_YEAR_MAX);
369
370         int day;
371         int maxValue = -1;
372
373         _DateTimeUtils dateTimeUtils;
374
375         maxValue = dateTimeUtils.CalculateMaxDay(yearValue, GetMonth());
376         day = __pPresenter->GetDay();
377
378         if (day > maxValue)
379         {
380                 __pPresenter->SetDay(maxValue);
381         }
382
383         return __pPresenter->SetYear(yearValue);
384 }
385
386 result
387 _DateTimePicker::SetYear(int year)
388 {
389         return SetProperty("year", Variant(year));
390 }
391
392 Variant
393 _DateTimePicker::GetPropertyYear(void) const
394 {
395         int year = -1;
396
397         year = __pPresenter->GetYear();
398
399         return Variant(year);
400 }
401
402 int
403 _DateTimePicker::GetYear(void) const
404 {
405         Variant year = GetProperty("year");
406
407         return year.ToInt();
408 }
409
410 result
411 _DateTimePicker::SetPropertyMonth(const Variant& month)
412 {
413         int monthValue = month.ToInt();
414
415         SysTryReturnResult(NID_UI_CTRL, (monthValue >= DATETIME_MONTH_MIN && monthValue <= DATETIME_MONTH_MAX), E_INVALID_ARG,
416                                            "Invalid argument(s) is used. The month (%d) must be greater than or equal to (%d) and less than or equal to (%d).", monthValue, DATETIME_MONTH_MIN, DATETIME_MONTH_MAX);
417
418         int day;
419         int maxValue = -1;
420
421         _DateTimeUtils dateTimeUtils;
422
423         maxValue = dateTimeUtils.CalculateMaxDay(GetYear(), monthValue);
424         day = __pPresenter->GetDay();
425
426         if (day > maxValue)
427         {
428                 __pPresenter->SetDay(maxValue);
429         }
430
431         return __pPresenter->SetMonth(monthValue);
432 }
433
434 result
435 _DateTimePicker::SetMonth(int month)
436 {
437         return SetProperty("month", Variant(month));
438 }
439
440 Variant
441 _DateTimePicker::GetPropertyMonth(void) const
442 {
443         int month = -1;
444
445         month = __pPresenter->GetMonth();
446
447         return Variant(month);
448 }
449
450 int
451 _DateTimePicker::GetMonth(void) const
452 {
453         Variant month = GetProperty("month");
454
455         return month.ToInt();
456 }
457
458 result
459 _DateTimePicker::SetPropertyDay(const Variant& day)
460 {
461         int dayValue = day.ToInt();
462
463         SysTryReturnResult(NID_UI_CTRL, (dayValue >= DATETIME_DAY_MIN && dayValue <= DATETIME_DAY_MAX), E_INVALID_ARG,
464                                            "Invalid argument(s) is used. The day (%d) must be greater than or equal to (%d) and less than or equal to (%d).", dayValue, DATETIME_DAY_MIN, DATETIME_DAY_MAX);
465
466         int maxValue = -1;
467         _DateTimeUtils dateTimeUtils;
468         maxValue = dateTimeUtils.CalculateMaxDay(GetYear(), GetMonth());
469
470         SysTryReturn(NID_UI_CTRL, (dayValue <= maxValue), E_INVALID_ARG, E_INVALID_ARG,
471                         "[E_INVALID_ARG] Invalid argument is used. day (%d), month (%d)", dayValue, GetMonth());
472
473         return __pPresenter->SetDay(dayValue);
474 }
475
476 result
477 _DateTimePicker::SetDay(int day)
478 {
479         return SetProperty("day", Variant(day));
480 }
481
482 Variant
483 _DateTimePicker::GetPropertyDay(void) const
484 {
485         int day = -1;
486
487         day = __pPresenter->GetDay();
488
489         return Variant(day);
490 }
491
492 int
493 _DateTimePicker::GetDay(void) const
494 {
495         Variant day = GetProperty("day");
496
497         return day.ToInt();
498 }
499
500 result
501 _DateTimePicker::SetPropertyHour(const Variant& hour)
502 {
503         int hourValue = hour.ToInt();
504
505         SysTryReturnResult(NID_UI_CTRL, (hourValue >= DATETIME_HOUR_MIN && hourValue <= DATETIME_HOUR_MAX), E_INVALID_ARG,
506                                            "Invalid argument(s) is used. The hour (%d) must be greater than or equal to (%d) and less than or equal to (%d).", hourValue, DATETIME_HOUR_MIN, DATETIME_HOUR_MAX);
507
508         return __pPresenter->SetHour(hourValue);
509
510 }
511
512 result
513 _DateTimePicker::SetHour(int hour)
514 {
515         return SetProperty("hour", Variant(hour));
516 }
517
518 Variant
519 _DateTimePicker::GetPropertyHour(void) const
520 {
521         int hour = -1;
522
523         hour = __pPresenter->GetHour();
524
525         return Variant(hour);
526 }
527
528 int
529 _DateTimePicker::GetHour(void) const
530 {
531         Variant hour = GetProperty("hour");
532
533         return hour.ToInt();
534 }
535
536 result
537 _DateTimePicker::SetPropertyMinute(const Variant& minute)
538 {
539         int minuteValue = minute.ToInt();
540
541         SysTryReturnResult(NID_UI_CTRL, (minuteValue >= DATETIME_MINUTE_MIN && minuteValue <= DATETIME_MINUTE_MAX), E_INVALID_ARG,
542                                            "Invalid argument(s) is used. The minute (%d) must be greater than or equal to (%d) and less than or equal to (%d).", minuteValue, DATETIME_MINUTE_MIN, DATETIME_MINUTE_MAX);
543
544         return __pPresenter->SetMinute(minuteValue);
545
546 }
547
548 result
549 _DateTimePicker::SetMinute(int minute)
550 {
551         return SetProperty("minute", Variant(minute));
552 }
553
554 Variant
555 _DateTimePicker::GetPropertyMinute(void) const
556 {
557         int minute = -1;
558
559         minute = __pPresenter->GetMinute();
560
561         return Variant(minute);
562 }
563
564 int
565 _DateTimePicker::GetMinute(void) const
566 {
567         Variant minute = GetProperty("minute");
568
569         return minute.ToInt();
570 }
571
572 result
573 _DateTimePicker::SetProperty24HourNotation(const Variant& enable)
574 {
575         bool enableValue = enable.ToBool();
576
577         __pPresenter->Set24HourNotationEnabled(enableValue);
578
579         return E_SUCCESS;
580 }
581
582 void
583 _DateTimePicker::Set24HourNotationEnabled(bool enable)
584 {
585         SetProperty("24hourNotation", Variant(enable));
586
587         return;
588 }
589
590 Variant
591 _DateTimePicker::GetProperty24HourNotation(void) const
592 {
593         bool is24HourNotation = false;
594
595         is24HourNotation = __pPresenter->Is24HourNotationEnabled();
596
597         return Variant(is24HourNotation);
598 }
599
600 bool
601 _DateTimePicker::Is24HourNotationEnabled(void) const
602 {
603         Variant enable = GetProperty("24hourNotation");
604
605         return enable.ToBool();
606 }
607
608 result
609 _DateTimePicker::SetPropertyMinYearRange(const Variant& minYear)
610 {
611         int minYearValue = minYear.ToInt();
612         int currentMinYear = DATETIME_YEAR_MIN;
613         int currentMaxYear = DATETIME_YEAR_MAX;
614
615         SysTryReturnResult(NID_UI_CTRL, (minYearValue >= DATETIME_YEAR_MIN && minYearValue <= DATETIME_YEAR_MAX), E_INVALID_ARG,
616                                            "Invalid argument(s) is used. The min year (%d) must be greater than or equal to (%d) and less than or equal to (%d).", minYearValue, DATETIME_YEAR_MIN, DATETIME_YEAR_MAX);
617
618         __pPresenter->GetYearRange(currentMinYear, currentMaxYear);
619
620         SysTryReturnResult(NID_UI_CTRL, (currentMaxYear >= minYearValue), E_INVALID_ARG,
621                                            "Invalid argument(s) is used. The year (%d) must be less than or equal to (%d).", minYearValue, currentMaxYear);
622
623         return __pPresenter->SetYearRange(minYearValue, currentMaxYear);
624 }
625
626 Variant
627 _DateTimePicker::GetPropertyMinYearRange(void) const
628 {
629         int currentMinYear = DATETIME_YEAR_MIN;
630         int currentMaxYear = DATETIME_YEAR_MAX;
631
632         __pPresenter->GetYearRange(currentMinYear, currentMaxYear);
633
634         return Variant(currentMinYear);
635 }
636
637 result
638 _DateTimePicker::SetPropertyMaxYearRange(const Variant& maxYear)
639 {
640         int maxYearValue = maxYear.ToInt();
641         int currentMinYear = DATETIME_YEAR_MIN;
642         int currentMaxYear = DATETIME_YEAR_MAX;
643
644         SysTryReturnResult(NID_UI_CTRL, (maxYearValue >= DATETIME_YEAR_MIN && maxYearValue <= DATETIME_YEAR_MAX), E_INVALID_ARG,
645                                            "Invalid argument(s) is used. The year (%d) must be greater than or equal to (%d) and less than or equal to (%d).", maxYearValue, DATETIME_YEAR_MIN, DATETIME_YEAR_MAX);
646
647         __pPresenter->GetYearRange(currentMinYear, currentMaxYear);
648
649         SysTryReturnResult(NID_UI_CTRL, (maxYearValue >= currentMinYear), E_INVALID_ARG,
650                                            "Invalid argument(s) is used. The year (%d) must be greater than or equal to (%d).", maxYearValue, currentMinYear);
651
652         return __pPresenter->SetYearRange(currentMinYear, maxYearValue);
653 }
654
655 Variant
656 _DateTimePicker::GetPropertyMaxYearRange(void) const
657 {
658         int currentMinYear = DATETIME_YEAR_MIN;
659         int currentMaxYear = DATETIME_YEAR_MAX;
660
661         __pPresenter->GetYearRange(currentMinYear, currentMaxYear);
662
663         return  Variant(currentMaxYear);
664 }
665
666 result
667 _DateTimePicker::SetYearRange(int minYear, int maxYear)
668 {
669         result r = E_SUCCESS;
670
671         SysTryReturnResult(NID_UI_CTRL, (minYear >= DATETIME_YEAR_MIN && minYear <= DATETIME_YEAR_MAX), E_INVALID_ARG,
672                                            "Invalid argument(s) is used. The minYear (%d) must be greater than or equal to (%d) and less than or equal to (%d).", minYear, DATETIME_YEAR_MIN, DATETIME_YEAR_MAX);
673         SysTryReturnResult(NID_UI_CTRL, (maxYear >= DATETIME_YEAR_MIN && maxYear <= DATETIME_YEAR_MAX), E_INVALID_ARG,
674                                            "Invalid argument(s) is used. The maxYear (%d) must be greater than or equal to (%d) and less than or equal to (%d).", maxYear, DATETIME_YEAR_MIN, DATETIME_YEAR_MAX);
675         SysTryReturnResult(NID_UI_CTRL, (maxYear >= minYear), E_INVALID_ARG,
676                                            "Invalid argument(s) is used. The maxYear (%d) must be greater than or equal to minYear (%d).", maxYear, minYear);
677
678         r = SetProperty("minYearRange", Variant(minYear));
679         if (r != E_SUCCESS )
680         {
681                 return r;
682         }
683
684         r = SetProperty("maxYearRange", Variant(maxYear));
685
686         return r;
687 }
688
689 result
690 _DateTimePicker::GetYearRange(int& minYear, int& maxYear) const
691 {
692         Variant currentMinYear = GetProperty("minYearRange");
693         Variant currentMaxYear = GetProperty("maxYearRange");
694
695         minYear = currentMinYear.ToInt();
696         maxYear = currentMaxYear.ToInt();
697
698         return E_SUCCESS;
699 }
700
701 result
702 _DateTimePicker::SetPropertyDateTime(const Variant& varDateTime)
703 {
704         DateTime dateTime = varDateTime.ToDateTime();
705
706         SysTryReturnResult(NID_UI_CTRL, (dateTime.GetYear() >= DATETIME_YEAR_MIN && dateTime.GetYear() <= DATETIME_YEAR_MAX), E_INVALID_ARG,
707                         "[E_INVALID_ARG] Invalid argument is used. year (%d).", dateTime.GetYear());
708
709         int minYear = -1;
710         int maxYear = -1;
711
712         GetYearRange(minYear, maxYear);
713
714         DateTime date;
715
716         if (dateTime.GetYear() < minYear)
717         {
718                 date.SetValue(minYear, dateTime.GetMonth(), dateTime.GetDay(), dateTime.GetHour(), dateTime.GetMinute(), dateTime.GetSecond());
719         }
720         else if (dateTime.GetYear() > maxYear)
721         {
722                 date.SetValue(maxYear, dateTime.GetMonth(), dateTime.GetDay(), dateTime.GetHour(), dateTime.GetMinute(), dateTime.GetSecond());
723         }
724         else
725         {
726                 date.SetValue(dateTime);
727         }
728
729         __pPresenter->SetDateTime(date);
730
731         return E_SUCCESS;
732 }
733
734 void
735 _DateTimePicker::SetDateTime(const DateTime& dateTime)
736 {
737         SetProperty("dateTime", Variant(dateTime));
738
739         return;
740 }
741
742 Variant
743 _DateTimePicker::GetPropertyDateTime(void) const
744 {
745         DateTime dateTime = DateTime();
746
747         dateTime = __pPresenter->GetDateTime();
748
749         return Variant(dateTime);
750 }
751
752 DateTime
753 _DateTimePicker::GetDateTime(void) const
754 {
755         Variant dateTime = GetProperty("dateTime");
756
757         return dateTime.ToDateTime();
758 }
759
760 void
761 _DateTimePicker::SetCurrentDateTime(void)
762 {
763         __pPresenter->SetCurrentDateTime();
764
765         return;
766 }
767
768 void
769 _DateTimePicker::SetFocusBoxId(int boxId)
770 {
771         __pPresenter->SetFocusBoxId(boxId);
772
773         return;
774 }
775
776 void
777 _DateTimePicker::SetAccessibilityElementText(int index, const String& text, bool isAmPm)
778 {
779         _AccessibilityElement* pElement = null;
780
781         if (__accessibilityElements.GetAt(index, pElement) == E_SUCCESS)
782         {
783                 result r = GetLastResult();
784                 SysTryReturnVoidResult(NID_UI_CTRL, (pElement != null), r, "[%s] Propagating.", GetErrorMessage(r));
785
786                 pElement->SetLabel(text);
787
788                 if (isAmPm)
789                 {
790                         String amText;
791                         String pmText;
792
793                         _DateTimeUtils dateTimeUtils;
794                         dateTimeUtils.GetAmPm(amText, AM_TYPE);
795                         dateTimeUtils.GetAmPm(pmText, PM_TYPE);
796
797                         pElement->SetHintWithStringId("IDS_TPLATFORM_BODY_DOUBLE_TAP_TO_CHANGE_T_TTS");
798                 }
799         }
800
801         SetLastResult(E_SUCCESS);
802
803         return;
804 }
805
806 bool
807 _DateTimePicker::OnTouchPressed(const _Control& source, const _TouchInfo& touchinfo)
808 {
809         return __pPresenter->OnTouchPressed(source, touchinfo);
810 }
811
812 bool
813 _DateTimePicker::OnTouchMoved(const _Control& source, const _TouchInfo& touchinfo)
814 {
815         return __pPresenter->OnTouchMoved(source, touchinfo);
816 }
817
818 bool
819 _DateTimePicker::OnTouchReleased(const _Control& source, const _TouchInfo& touchinfo)
820 {
821         return __pPresenter->OnTouchReleased(source, touchinfo);
822 }
823
824 bool
825 _DateTimePicker::OnTouchCanceled(const _Control& source, const _TouchInfo& touchinfo)
826 {
827         return __pPresenter->OnTouchCanceled(source, touchinfo);
828 }
829
830 result
831 _DateTimePicker::OnAttachedToMainTree(void)
832 {
833         return CreateAllAccessibilityElements();
834 }
835
836 result
837 _DateTimePicker::OnDetachingFromMainTree(void)
838 {
839         RemoveAllAccessibilityElements();
840
841         return _Window::OnDetachingFromMainTree();
842 }
843
844 void
845 _DateTimePicker::OnChangeLayout(_ControlOrientation orientation)
846 {
847         result r = E_SUCCESS;
848         FloatDimension pickerSize(0.0f, 0.0f);
849         FloatDimension screenSize(0.0f, 0.0f);
850
851         screenSize = _ControlManager::GetInstance()->GetScreenSizeF();
852         pickerSize = screenSize;
853         if (orientation == _CONTROL_ORIENTATION_LANDSCAPE)
854         {
855                 pickerSize.width = screenSize.height;
856                 pickerSize.height = screenSize.width;
857         }
858
859         SetMovable(true);
860         SetResizable(true);
861
862         SetSize(pickerSize);
863
864         SetMovable(false);
865         SetResizable(false);
866
867         r = DestroyFooter();
868         SysTryReturnVoidResult(NID_UI_CTRL, (r == E_SUCCESS), E_SYSTEM,
869                                                   "[E_SYSTEM] A system error has occurred. Failed to destroy the footer for this control.");
870
871         r = CreateFooter();
872         SysTryReturnVoidResult(NID_UI_CTRL, (r == E_SUCCESS), E_SYSTEM,
873                                                   "[E_SYSTEM] A system error has occurred. Failed to create the footer for this control.");
874
875         __pPresenter->OnChangeLayout(orientation);
876
877         const _DateTimeDisplayBox* pBox = null;
878         IEnumeratorT<_AccessibilityElement*>* pEnumerator = __accessibilityElements.GetEnumeratorN();
879         SysTryReturnVoidResult(NID_UI_CTRL, (pEnumerator != null), GetLastResult(),
880                         "[%s] Propagating.", GetErrorMessage(GetLastResult()));
881
882         _AccessibilityElement* pElement = null;
883         int index = 0;
884         while (pEnumerator->MoveNext() == E_SUCCESS)
885         {
886                 if (pEnumerator->GetCurrent(pElement) == E_SUCCESS)
887                 {
888                         pBox = __pPresenter->GetDisplayBox(index);
889                         if (pBox != null)
890                         {
891                                 FloatRectangle displayBoxBounds = pBox->GetDisplayBoxBounds();
892
893                                 if (__pDisplayVisualElement)
894                                 {
895                                         displayBoxBounds.y += __pDisplayVisualElement->GetBounds().y;
896                                 }
897
898                                 pElement->SetBounds(displayBoxBounds);
899                         }
900                 }
901                 index++;
902         }
903         delete pEnumerator;
904
905         return;
906 }
907
908 void
909 _DateTimePicker::OnDraw(void)
910 {
911         __pPresenter->Draw();
912
913         return;
914 }
915
916 void
917 _DateTimePicker::OnActionPerformed(const _Control& source, int actionId)
918 {
919         __pPresenter->OnActionPerformed(source, actionId);
920
921         return;
922 }
923
924 bool
925 _DateTimePicker::OnAccessibilityActionPerformed(const _AccessibilityContainer& control, const _AccessibilityElement& element)
926 {
927         String amString = L"";
928         String pmString = L"";
929         String label = L"";
930
931         label = element.GetLabel();
932
933         _DateTimeUtils dateTimeUtils;
934         dateTimeUtils.GetAmPm(amString, AM_TYPE);
935         dateTimeUtils.GetAmPm(pmString, PM_TYPE);
936
937         if (label == amString || label == pmString)
938         {
939                 label.Append(L" Selected");
940                 _AccessibilityManager::GetInstance()->ReadContent(label);
941         }
942
943         return true;
944 }
945
946 void
947 _DateTimePicker::OnFontChanged(Font* pFont)
948 {
949         result r = E_SUCCESS;
950
951         if (pFont != null)
952         {
953                 if (__pPresenter != null)
954                 {
955                         r = __pPresenter->SetFont(pFont);
956                         SysTryReturnVoidResult(NID_UI_CTRL, (r == E_SUCCESS), r, "[%s] Propagating.");
957                 }
958
959                 if (__pFooter != null)
960                 {
961                         for (int i=0; i < __pFooter->GetItemCount(); i++)
962                         {
963                                 _Button* pButton = __pFooter->GetItem(i);
964
965                                 if (pButton != null)
966                                 {
967                                         r = pButton->SetFont(pFont->GetFaceName());
968                                         SysTryReturnVoidResult(NID_UI_CTRL, (r == E_SUCCESS), r, "[%s] Propagating.", GetErrorMessage(r));
969                                 }
970                         }
971                 }
972
973                 __pFont = pFont;
974         }
975
976         return;
977 }
978
979 void
980 _DateTimePicker::OnFontInfoRequested(unsigned long& style, float& size)
981 {
982         style = FONT_STYLE_PLAIN;
983
984         GET_SHAPE_CONFIG(DATETIMEPICKER::FONT_SIZE, GetOrientation(), size);
985
986         return;
987 }
988
989 bool
990 _DateTimePicker::OnKeyPressed(const _Control& source, const _KeyInfo& keyInfo)
991 {
992         if (&source != this)
993         {
994                 return false;
995         }
996
997         return __pPresenter->OnKeyPressed(source, keyInfo);
998 }
999
1000 bool
1001 _DateTimePicker::OnKeyReleased(const _Control& source, const _KeyInfo& keyInfo)
1002 {
1003         if (&source != this)
1004         {
1005                 return false;
1006         }
1007
1008         return __pPresenter->OnKeyReleased(source, keyInfo);
1009 }
1010
1011 void
1012 _DateTimePicker::OnDrawFocus(void)
1013 {
1014         __pPresenter->DrawFocus();
1015         return;
1016 }
1017
1018 bool
1019 _DateTimePicker::OnFocusGained(const _Control& source)
1020 {
1021         return _Control::OnFocusGained(source);
1022 }
1023
1024 bool
1025 _DateTimePicker::OnFocusLost(const _Control& source)
1026 {
1027         result r = __pPresenter->ReleaseFocus();
1028         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, false, r, "[%s] Propagating.", GetErrorMessage(r));
1029
1030         _Control::OnFocusLost(source);
1031         return true;
1032 }
1033
1034 void
1035 _DateTimePicker::OnFocusModeStateChanged(void)
1036 {
1037         __pPresenter->ReleaseFocus();
1038         return;
1039 }
1040
1041 void
1042 _DateTimePicker::OnSettingChanged(Tizen::Base::String& key)
1043 {
1044          if (key.Equals(L"http://tizen.org/setting/locale.date.format", false)
1045                          || key.Equals(L"http://tizen.org/setting/locale.time.format.24hour", false))
1046          {
1047                  __pPresenter->UpdateLocaleDateTimeFormat();
1048                  Invalidate();
1049                  RemoveAllAccessibilityElements();
1050                  CreateAllAccessibilityElements();
1051          }
1052
1053          return;
1054 }
1055
1056 Font*
1057 _DateTimePicker::GetDateTimeFont(void)
1058 {
1059         return __pFont;
1060 }
1061
1062 result
1063 _DateTimePicker::InitializeFont(void)
1064 {
1065         result r = E_SUCCESS;
1066
1067         __pFont = GetFallbackFont();
1068         r = GetLastResult();
1069         SysTryReturnResult(NID_UI_CTRL, (__pFont != null), r, "[%s] Propagating.", GetErrorMessage(r));
1070
1071         return r;
1072 }
1073
1074 result
1075 _DateTimePicker::CreateAllAccessibilityElements(void)
1076 {
1077         _AccessibilityContainer* pContainer = GetAccessibilityContainer();
1078         if (pContainer != null)
1079         {
1080                 float dateTimeDisplayBoxHeight = 0.0f;
1081                 float amPmDisplayBoxHeight = 0.0f;
1082                 float topMargin = 0.0f;
1083                 float leftMargin = 0.0f;
1084                 const _DateTimeDisplayBox* pBox = null;
1085                 const _DateTimeDisplayBox* pAmPmBox = null;
1086
1087                 GET_SHAPE_CONFIG(DATETIMEPICKER::LEFT_MARGIN, GetOrientation(), leftMargin);
1088
1089                 pContainer->AddListener(*this);
1090
1091                 // Display Box
1092                 for (int index = 0; index < DATETIME_ID_MAX; index++)
1093                 {
1094                         pBox = __pPresenter->GetDisplayBox(index);
1095                         if (pBox != null)
1096                         {
1097                                 _AccessibilityElement* pElement = new (std::nothrow) _AccessibilityElement(true);
1098                                 SysTryReturnResult(NID_UI_CTRL, (pElement != null), E_OUT_OF_MEMORY, "Memory allocation failed.");
1099
1100                                 FloatRectangle displayBoxBounds = pBox->GetDisplayBoxBounds();
1101                                 int displayBoxId = pBox->GetDisplayBoxId();
1102
1103                                 String hintText(L"Double tap to edit");
1104
1105                                 switch (displayBoxId)
1106                                 {
1107                                 case DATETIME_ID_DAY:
1108                                         pElement->SetTraitWithStringId("IDS_TPLATFORM_BODY_DAY_LC");
1109                                         pElement->SetHint(hintText);
1110                                         break;
1111                                 case DATETIME_ID_MONTH:
1112                                         pElement->SetTraitWithStringId("IDS_TPLATFORM_BODY_MONTH_LC");
1113                                         pElement->SetHint(hintText);
1114                                         break;
1115                                 case DATETIME_ID_YEAR:
1116                                         pElement->SetTraitWithStringId("IDS_TPLATFORM_BODY_YEAR_LC");
1117                                         pElement->SetHint(hintText);
1118                                         break;
1119                                 case DATETIME_ID_HOUR:
1120                                         pElement->SetTraitWithStringId("IDS_TPLATFORM_BODY_HOUR_LC");
1121                                         pElement->SetHint(hintText);
1122                                         break;
1123                                 case DATETIME_ID_MINUTE:
1124                                         pElement->SetTraitWithStringId("IDS_TPLATFORM_BODY_MINUTE_LC");
1125                                         pElement->SetHint(hintText);
1126                                         break;
1127                                 }
1128
1129                                 GET_SHAPE_CONFIG(DATETIMEPICKER::DATETIME_DISPLAY_BOX_HEIGHT, GetOrientation(), dateTimeDisplayBoxHeight);
1130                                 GET_SHAPE_CONFIG(DATETIMEPICKER::AMPM_DISPLAY_BOX_HEIGHT, GetOrientation(), amPmDisplayBoxHeight);
1131                                 topMargin = (amPmDisplayBoxHeight - dateTimeDisplayBoxHeight) / 2.0f;
1132
1133                                 displayBoxBounds.x += leftMargin;
1134                                 displayBoxBounds.y -= topMargin;
1135                                 displayBoxBounds.height += 2 * topMargin;
1136
1137                                 if (__pDisplayVisualElement)
1138                                 {
1139                                         displayBoxBounds.y += __pDisplayVisualElement->GetBounds().y;
1140                                 }
1141
1142                                 pElement->SetLabel(pBox->GetText());
1143                                 pElement->SetBounds(displayBoxBounds);
1144                                 pContainer->AddElement(*pElement);
1145                         }
1146                 }
1147
1148                 pAmPmBox = __pPresenter->GetAmPmBox();
1149                 if (pAmPmBox != null)
1150                 {
1151                         _AccessibilityElement* pElement = new (std::nothrow) _AccessibilityElement(true);
1152                         SysTryReturnResult(NID_UI_CTRL, (pElement != null), E_OUT_OF_MEMORY, "Memory allocation failed.");
1153
1154                         FloatRectangle amPmBoxBounds = pAmPmBox->GetDisplayBoxBounds();
1155
1156                         amPmBoxBounds.x += leftMargin;
1157
1158                         if (__pDisplayVisualElement)
1159                         {
1160                                 amPmBoxBounds.y += __pDisplayVisualElement->GetBounds().y;
1161                         }
1162
1163                         pElement->SetLabel(pAmPmBox->GetText());
1164                         pElement->SetBounds(amPmBoxBounds);
1165                         pElement->SetTraitWithStringId("IDS_TPLATFORM_BODY_BUTTON_T_TTS");
1166                         pElement->SetHintWithStringId("IDS_TPLATFORM_BODY_DOUBLE_TAP_TO_CHANGE_T_TTS");
1167                         pContainer->AddElement(*pElement);
1168                 }
1169
1170                 pContainer->GetElements(__accessibilityElements);
1171                 _AccessibilityManager::GetInstance()->RequestAutoReading(_ACCESSIBILITY_AUTO_READING_MODE_FIRST_ITEM);
1172
1173         }
1174
1175         return E_SUCCESS;
1176 }
1177
1178 void
1179 _DateTimePicker::RemoveAllAccessibilityElements(void)
1180 {
1181         _AccessibilityContainer* pContainer = GetAccessibilityContainer();
1182         SysTryReturnVoidResult(NID_UI_CTRL, (pContainer != null), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1183
1184         _AccessibilityElement* pAccessibilityElement = null;
1185
1186         pContainer->RemoveListener(*this);
1187
1188         while (__accessibilityElements.GetCount() > 0)
1189         {
1190                 if ((__accessibilityElements.GetAt(0, pAccessibilityElement)) == E_SUCCESS)
1191                 {
1192                         __accessibilityElements.RemoveAt(0);
1193                         pContainer->RemoveElement(*pAccessibilityElement);
1194                 }
1195                 else
1196                 {
1197                         __accessibilityElements.RemoveAt(0);
1198                 }
1199         }
1200 }
1201
1202 }}} // Tizen::Ui::Controls