2 // Open Service Platform
3 // Copyright (c) 2012-2013 Samsung Electronics Co., Ltd.
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
9 // http://www.apache.org/licenses/LICENSE-2.0/
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.
19 * @file FUiCtrl_DateTimePicker.cpp
20 * @brief This is the implementation file for the _DateTimePicker class.
23 #include <FGrpDimension.h>
24 #include <FBaseColIEnumeratorT.h>
25 #include <FBaseSysLog.h>
26 #include <FGrp_BitmapImpl.h>
28 #include "FUiCtrl_DateTimePicker.h"
29 #include "FUiAnim_VisualElement.h"
30 #include "FUiCtrl_DateTimeDefine.h"
31 #include "FUiCtrl_DateTimePresenter.h"
32 #include "FUiCtrl_DateTimeDisplayBox.h"
33 #include "FUiCtrl_Form.h"
34 #include "FUiCtrl_Frame.h"
35 #include "FUiCtrl_Button.h"
36 #include "FUiCtrl_Toolbar.h"
37 #include "FUiCtrl_DateTimeChangeEvent.h"
38 #include "FUiCtrl_IDateTimeChangeEventListener.h"
39 #include "FUiCtrl_DateTimeUtils.h"
40 #include "FUi_AccessibilityContainer.h"
41 #include "FUi_AccessibilityElement.h"
42 #include "FUi_AccessibilityManager.h"
43 #include "FUi_UiTouchEvent.h"
44 #include "FUi_ResourceManager.h"
45 #include "FUi_CoordinateSystemUtils.h"
47 using namespace Tizen::Base;
48 using namespace Tizen::Base::Collection;
49 using namespace Tizen::Graphics;
50 using namespace Tizen::Ui;
51 using namespace Tizen::Ui::Animations;
53 namespace Tizen { namespace Ui { namespace Controls
56 IMPLEMENT_PROPERTY(_DateTimePicker);
58 _DateTimePicker::_DateTimePicker(_DateTimePresenter* pPresenter, const String& title)
59 : __pPresenter(pPresenter)
62 , __pDateTimeChangeEvent(null)
64 , __pDisplayVisualElement(null)
68 _DateTimePicker::~_DateTimePicker(void)
70 if (__pDateTimeChangeEvent != null)
72 delete __pDateTimeChangeEvent;
73 __pDateTimeChangeEvent = null;
76 if (__pFooter != null)
78 DetachSystemChild(*__pFooter);
83 if (__pDisplayVisualElement != null)
85 __pDisplayVisualElement->Destroy();
86 __pDisplayVisualElement = null;
94 _DateTimePicker::CreateDateTimePickerN(int style, const String& title)
97 FloatDimension pickerSize(0.0f, 0.0f);
98 FloatDimension screenSize(0.0f, 0.0f);
99 _ControlOrientation orientation = _CONTROL_ORIENTATION_PORTRAIT;
100 _DateTimePresenter* pPresenter = null;
101 _DateTimePicker* pView = null;
103 SysTryReturn(NID_UI_CTRL, ((style & DATETIME_OUTPUT_STYLE_DATETIME) != DATETIME_OUTPUT_STYLE_INVALID), null, E_INVALID_ARG,
104 "[E_INVALID_ARG] Invalid argument(s) is used. The style provided is not present in the _DateTimeOutputStyle list.");
106 pPresenter = new (std::nothrow) _DateTimePresenter(style, title);
107 SysTryReturn(NID_UI_CTRL, (pPresenter != null), null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
109 pView = new (std::nothrow) _DateTimePicker(pPresenter, title);
110 SysTryCatch(NID_UI_CTRL, (pView != null), , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
112 r = pView->InitializeFont();
113 SysTryCatch(NID_UI_CTRL, (r == E_SUCCESS), , E_SYSTEM, "[E_SYSTEM] A system error has occurred. Failed to set the Font.");
115 r = pView->CreateRootVisualElement();
116 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
118 orientation = pView->GetOrientation();
119 screenSize = _ControlManager::GetInstance()->GetScreenSizeF();
120 pickerSize = screenSize;
121 if (orientation == _CONTROL_ORIENTATION_LANDSCAPE)
123 pickerSize.width = screenSize.height;
124 pickerSize.height = screenSize.width;
127 r = pView->SetSize(pickerSize);
128 SysTryCatch(NID_UI_CTRL, (r == E_SUCCESS), , E_SYSTEM,
129 "[E_SYSTEM] A system error has occurred. Failed to set the size for this control");
131 r = pView->CreateFooter();
132 SysTryCatch(NID_UI_CTRL, (r == E_SUCCESS), , E_SYSTEM,
133 "[E_SYSTEM] A system error has occurred. Failed to create the footer for this control");
135 r = pView->CreateDisplayVisualElement();
136 SysTryCatch(NID_UI_CTRL, (r == E_SUCCESS), , E_SYSTEM,
137 "[E_SYSTEM] A system error has occurred. Failed to create the display visual element for this control");
139 r = pPresenter->Construct(*pView);
140 SysTryCatch(NID_UI_CTRL, (r == E_SUCCESS), , E_SYSTEM,
141 "[E_SYSTEM] A system error has occurred. Failed to construct the presenter instance for this control");
143 pView->AcquireHandle();
145 pView->__pDateTimeChangeEvent = new (std::nothrow) _DateTimeChangeEvent(*pView);
146 SysTryCatch(NID_UI_CTRL, (pView->__pDateTimeChangeEvent != null), , E_OUT_OF_MEMORY,
147 "[E_OUT_OF_MEMORY] Memory allocation failed.");
149 if (pView->GetAccessibilityContainer() != null)
151 pView->GetAccessibilityContainer()->Activate(true);
164 _DateTimePicker::CreateFooter(void)
166 result r = E_SUCCESS;
167 _Button* pSaveButton = null;
168 _Button* pCancelButton = null;
169 FloatRectangle bounds;
171 _ControlOrientation orientation = GetOrientation();
173 _Toolbar* pFooter = _Toolbar::CreateToolbarN(false);
175 SysTryReturnResult(NID_UI_CTRL, (pFooter != null), r, "[%s] Propagating.", GetErrorMessage(r));
177 r = AttachSystemChild(*pFooter);
178 SysTryCatch(NID_UI_CTRL, (r == E_SUCCESS), , r, "[%s] Propagating.", GetErrorMessage(r));
180 GET_SHAPE_CONFIG(DATETIMEPICKER::FOOTER_HEIGHT, orientation, bounds.height);
181 GET_SHAPE_CONFIG(DATETIMEPICKER::INPUTPAD_HEIGHT, orientation, bounds.y);
184 bounds.y = GetBoundsF().height - bounds.y - bounds.height;
185 bounds.width = GetBoundsF().width;
187 pFooter->SetMovable(true);
188 pFooter->SetResizable(true);
190 r = pFooter->SetBounds(bounds);
191 SysTryCatch(NID_UI_CTRL, (r == E_SUCCESS), , r, "[%s] Propagating.", GetErrorMessage(r));
193 pFooter->SetMovable(false);
194 pFooter->SetResizable(false);
196 pFooter->AddActionEventListener(*this);
198 r = pFooter->SetStyle(TOOLBAR_TEXT);
199 SysTryCatch(NID_UI_CTRL, (r == E_SUCCESS), , r, "[%s] Propagating.", GetErrorMessage(r));
201 // Create 'Save' button
202 pSaveButton = _Button::CreateButtonN();
204 SysTryCatch(NID_UI_CTRL, (r == E_SUCCESS), , r, "[%s] Propagating.", GetErrorMessage(r));
206 r = pSaveButton->SetActionId(DATETIME_EVENT_ID_SAVE);
207 SysTryCatch(NID_UI_CTRL, (r == E_SUCCESS), , r, "[%s] Propagating.", GetErrorMessage(r));
209 GET_STRING_CONFIG(IDS_COM_SK_SAVE, text);
211 r = pSaveButton->SetText(text);
212 SysTryCatch(NID_UI_CTRL, (r == E_SUCCESS), , r, "[%s] Propagating.", GetErrorMessage(r));
214 // Create 'Cancel' button
215 pCancelButton = _Button::CreateButtonN();
217 SysTryCatch(NID_UI_CTRL, (r == E_SUCCESS), , r, "[%s] Propagating.", GetErrorMessage(r));
219 r = pCancelButton->SetActionId(DATETIME_EVENT_ID_CANCEL);
220 SysTryCatch(NID_UI_CTRL, (r == E_SUCCESS), , r, "[%s] Propagating.", GetErrorMessage(r));
222 GET_STRING_CONFIG(IDS_COM_POP_CANCEL, text);
224 r = pCancelButton->SetText(text);
225 SysTryCatch(NID_UI_CTRL, (r == E_SUCCESS), , r, "[%s] Propagating.", GetErrorMessage(r));
227 r = pFooter->AddItem(pSaveButton);
228 SysTryCatch(NID_UI_CTRL, (r == E_SUCCESS), , r, "[%s] Propagating.", GetErrorMessage(r));
230 r = pFooter->AddItem(pCancelButton);
231 SysTryCatch(NID_UI_CTRL, (r == E_SUCCESS), , r, "[%s] Propagating.");
233 if (__pFooter != null)
235 DetachSystemChild(*__pFooter);
245 DetachSystemChild(*pFooter);
249 delete pCancelButton;
255 _DateTimePicker::DestroyFooter(void)
257 if (__pFooter != null)
259 DetachSystemChild(*__pFooter);
269 _DateTimePicker::CreateDisplayVisualElement(void)
271 result r = E_SUCCESS;
273 __pDisplayVisualElement = new (std::nothrow) _VisualElement();
274 SysTryReturnResult(NID_UI_CTRL, __pDisplayVisualElement, E_OUT_OF_MEMORY, "Memory allocation failed.");
276 r = __pDisplayVisualElement->Construct();
277 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
279 __pDisplayVisualElement->SetShowState(true);
280 __pDisplayVisualElement->SetImplicitAnimationEnabled(false);
282 r = GetVisualElement()->AttachChild(*__pDisplayVisualElement);
283 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
288 __pDisplayVisualElement->Destroy();
289 __pDisplayVisualElement = null;
295 _DateTimePicker::SetDisplayVisualElementBounds(FloatRectangle bounds)
297 if (__pDisplayVisualElement != null)
299 __pDisplayVisualElement->SetBounds(FloatRectangle(bounds.x, bounds.y, bounds.width, bounds.height));
306 _DateTimePicker::GetDisplayVisualElement(void)
308 return __pDisplayVisualElement;
312 _DateTimePicker::AddDateTimeChangeEventListener(const Controls::_IDateTimeChangeEventListener& listener)
314 SysTryReturnResult(NID_UI_CTRL, (__pDateTimeChangeEvent != null), E_SYSTEM,
315 "A system error has occurred. The _DateTimeChangeEvent instance is null.");
317 result r = __pDateTimeChangeEvent->AddListener(listener);
318 SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Propagating.");
324 _DateTimePicker::RemoveDateTimeChangeEventListener(const Controls::_IDateTimeChangeEventListener& listener)
326 SysTryReturnResult(NID_UI_CTRL, (__pDateTimeChangeEvent != null), E_SYSTEM,
327 "A system error has occurred. The _DateTimeChangeEvent instance is null.");
329 result r = __pDateTimeChangeEvent->RemoveListener(listener);
330 SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Propagating.");
336 _DateTimePicker::FireDateTimeChangeEvent(_DateTimeChangeStatus status, DateTime& dateTime)
338 SysTryReturnResult(NID_UI_CTRL, (__pDateTimeChangeEvent != null), E_SYSTEM,
339 "A system error has occurred. The _DateTimeChangeEvent instance is null");
341 SysTryReturnResult(NID_UI_CTRL, (status >= DATE_INTERNAL_CHANGE_SAVED && status <= TIME_INTERNAL_CHANGE_CANCELED), E_INVALID_ARG,
342 "Invalid argument(s) is used. The status provided is not present in the _DateTimeChangeStatus list.");
344 _DateTimeChangeEventArg* pDateTimeEventArg = new (std::nothrow) _DateTimeChangeEventArg(status);
345 SysTryReturnResult(NID_UI_CTRL, (pDateTimeEventArg != null), E_OUT_OF_MEMORY, "Memory allocation failed.");
347 pDateTimeEventArg->SetDateTime(dateTime);
348 pDateTimeEventArg->SetDate(dateTime.GetYear(), dateTime.GetMonth(), dateTime.GetDay());
349 pDateTimeEventArg->SetTime(dateTime.GetHour(), dateTime.GetMinute());
350 __pDateTimeChangeEvent->Fire(*pDateTimeEventArg);
356 _DateTimePicker::SetPropertyYear(const Variant& year)
358 int yearValue = year.ToInt();
360 SysTryReturnResult(NID_UI_CTRL, (yearValue >= DATETIME_YEAR_MIN && yearValue <= DATETIME_YEAR_MAX), E_INVALID_ARG,
361 "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);
366 _DateTimeUtils dateTimeUtils;
368 maxValue = dateTimeUtils.CalculateMaxDay(yearValue, GetMonth());
369 day = __pPresenter->GetDay();
373 __pPresenter->SetDay(maxValue);
376 return __pPresenter->SetYear(yearValue);
380 _DateTimePicker::SetYear(int year)
382 return SetProperty("year", Variant(year));
386 _DateTimePicker::GetPropertyYear(void) const
390 year = __pPresenter->GetYear();
392 return Variant(year);
396 _DateTimePicker::GetYear(void) const
398 Variant year = GetProperty("year");
404 _DateTimePicker::SetPropertyMonth(const Variant& month)
406 int monthValue = month.ToInt();
408 SysTryReturnResult(NID_UI_CTRL, (monthValue >= DATETIME_MONTH_MIN && monthValue <= DATETIME_MONTH_MAX), E_INVALID_ARG,
409 "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);
414 _DateTimeUtils dateTimeUtils;
416 maxValue = dateTimeUtils.CalculateMaxDay(GetYear(), monthValue);
417 day = __pPresenter->GetDay();
421 __pPresenter->SetDay(maxValue);
424 return __pPresenter->SetMonth(monthValue);
428 _DateTimePicker::SetMonth(int month)
430 return SetProperty("month", Variant(month));
434 _DateTimePicker::GetPropertyMonth(void) const
438 month = __pPresenter->GetMonth();
440 return Variant(month);
444 _DateTimePicker::GetMonth(void) const
446 Variant month = GetProperty("month");
448 return month.ToInt();
452 _DateTimePicker::SetPropertyDay(const Variant& day)
454 int dayValue = day.ToInt();
456 SysTryReturnResult(NID_UI_CTRL, (dayValue >= DATETIME_DAY_MIN && dayValue <= DATETIME_DAY_MAX), E_INVALID_ARG,
457 "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);
460 _DateTimeUtils dateTimeUtils;
461 maxValue = dateTimeUtils.CalculateMaxDay(GetYear(), GetMonth());
463 SysTryReturn(NID_UI_CTRL, (dayValue <= maxValue), E_INVALID_ARG, E_INVALID_ARG,
464 "[E_INVALID_ARG] Invalid argument is used. day (%d), month (%d)", dayValue, GetMonth());
466 return __pPresenter->SetDay(dayValue);
470 _DateTimePicker::SetDay(int day)
472 return SetProperty("day", Variant(day));
476 _DateTimePicker::GetPropertyDay(void) const
480 day = __pPresenter->GetDay();
486 _DateTimePicker::GetDay(void) const
488 Variant day = GetProperty("day");
494 _DateTimePicker::SetPropertyHour(const Variant& hour)
496 int hourValue = hour.ToInt();
498 SysTryReturnResult(NID_UI_CTRL, (hourValue >= DATETIME_HOUR_MIN && hourValue <= DATETIME_HOUR_MAX), E_INVALID_ARG,
499 "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);
501 return __pPresenter->SetHour(hourValue);
506 _DateTimePicker::SetHour(int hour)
508 return SetProperty("hour", Variant(hour));
512 _DateTimePicker::GetPropertyHour(void) const
516 hour = __pPresenter->GetHour();
518 return Variant(hour);
522 _DateTimePicker::GetHour(void) const
524 Variant hour = GetProperty("hour");
530 _DateTimePicker::SetPropertyMinute(const Variant& minute)
532 int minuteValue = minute.ToInt();
534 SysTryReturnResult(NID_UI_CTRL, (minuteValue >= DATETIME_MINUTE_MIN && minuteValue <= DATETIME_MINUTE_MAX), E_INVALID_ARG,
535 "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);
537 return __pPresenter->SetMinute(minuteValue);
542 _DateTimePicker::SetMinute(int minute)
544 return SetProperty("minute", Variant(minute));
548 _DateTimePicker::GetPropertyMinute(void) const
552 minute = __pPresenter->GetMinute();
554 return Variant(minute);
558 _DateTimePicker::GetMinute(void) const
560 Variant minute = GetProperty("minute");
562 return minute.ToInt();
566 _DateTimePicker::SetProperty24HourNotation(const Variant& enable)
568 bool enableValue = enable.ToBool();
570 __pPresenter->Set24HourNotationEnabled(enableValue);
576 _DateTimePicker::Set24HourNotationEnabled(bool enable)
578 SetProperty("24hourNotation", Variant(enable));
584 _DateTimePicker::GetProperty24HourNotation(void) const
586 bool is24HourNotation = false;
588 is24HourNotation = __pPresenter->Is24HourNotationEnabled();
590 return Variant(is24HourNotation);
594 _DateTimePicker::Is24HourNotationEnabled(void) const
596 Variant enable = GetProperty("24hourNotation");
598 return enable.ToBool();
602 _DateTimePicker::SetPropertyMinYearRange(const Variant& minYear)
604 int minYearValue = minYear.ToInt();
605 int currentMinYear = DATETIME_YEAR_MIN;
606 int currentMaxYear = DATETIME_YEAR_MAX;
608 SysTryReturnResult(NID_UI_CTRL, (minYearValue >= DATETIME_YEAR_MIN && minYearValue <= DATETIME_YEAR_MAX), E_INVALID_ARG,
609 "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);
611 __pPresenter->GetYearRange(currentMinYear, currentMaxYear);
613 SysTryReturnResult(NID_UI_CTRL, (currentMaxYear >= minYearValue), E_INVALID_ARG,
614 "Invalid argument(s) is used. The year (%d) must be less than or equal to (%d).", minYearValue, currentMaxYear);
616 return __pPresenter->SetYearRange(minYearValue, currentMaxYear);
620 _DateTimePicker::GetPropertyMinYearRange(void) const
622 int currentMinYear = DATETIME_YEAR_MIN;
623 int currentMaxYear = DATETIME_YEAR_MAX;
625 __pPresenter->GetYearRange(currentMinYear, currentMaxYear);
627 return Variant(currentMinYear);
631 _DateTimePicker::SetPropertyMaxYearRange(const Variant& maxYear)
633 int maxYearValue = maxYear.ToInt();
634 int currentMinYear = DATETIME_YEAR_MIN;
635 int currentMaxYear = DATETIME_YEAR_MAX;
637 SysTryReturnResult(NID_UI_CTRL, (maxYearValue >= DATETIME_YEAR_MIN && maxYearValue <= DATETIME_YEAR_MAX), E_INVALID_ARG,
638 "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);
640 __pPresenter->GetYearRange(currentMinYear, currentMaxYear);
642 SysTryReturnResult(NID_UI_CTRL, (maxYearValue >= currentMinYear), E_INVALID_ARG,
643 "Invalid argument(s) is used. The year (%d) must be greater than or equal to (%d).", maxYearValue, currentMinYear);
645 return __pPresenter->SetYearRange(currentMinYear, maxYearValue);
649 _DateTimePicker::GetPropertyMaxYearRange(void) const
651 int currentMinYear = DATETIME_YEAR_MIN;
652 int currentMaxYear = DATETIME_YEAR_MAX;
654 __pPresenter->GetYearRange(currentMinYear, currentMaxYear);
656 return Variant(currentMaxYear);
660 _DateTimePicker::SetYearRange(int minYear, int maxYear)
662 result r = E_SUCCESS;
664 SysTryReturnResult(NID_UI_CTRL, (minYear >= DATETIME_YEAR_MIN && minYear <= DATETIME_YEAR_MAX), E_INVALID_ARG,
665 "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);
666 SysTryReturnResult(NID_UI_CTRL, (maxYear >= DATETIME_YEAR_MIN && maxYear <= DATETIME_YEAR_MAX), E_INVALID_ARG,
667 "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);
668 SysTryReturnResult(NID_UI_CTRL, (maxYear >= minYear), E_INVALID_ARG,
669 "Invalid argument(s) is used. The maxYear (%d) must be greater than or equal to minYear (%d).", maxYear, minYear);
671 r = SetProperty("minYearRange", Variant(minYear));
677 r = SetProperty("maxYearRange", Variant(maxYear));
683 _DateTimePicker::GetYearRange(int& minYear, int& maxYear) const
685 Variant currentMinYear = GetProperty("minYearRange");
686 Variant currentMaxYear = GetProperty("maxYearRange");
688 minYear = currentMinYear.ToInt();
689 maxYear = currentMaxYear.ToInt();
695 _DateTimePicker::SetPropertyDateTime(const Variant& varDateTime)
697 DateTime dateTime = varDateTime.ToDateTime();
699 SysTryReturnResult(NID_UI_CTRL, (dateTime.GetYear() >= DATETIME_YEAR_MIN && dateTime.GetYear() <= DATETIME_YEAR_MAX), E_INVALID_ARG,
700 "[E_INVALID_ARG] Invalid argument is used. year (%d).", dateTime.GetYear());
705 GetYearRange(minYear, maxYear);
709 if (dateTime.GetYear() < minYear)
711 date.SetValue(minYear, dateTime.GetMonth(), dateTime.GetDay(), dateTime.GetHour(), dateTime.GetMinute(), dateTime.GetSecond());
713 else if (dateTime.GetYear() > maxYear)
715 date.SetValue(maxYear, dateTime.GetMonth(), dateTime.GetDay(), dateTime.GetHour(), dateTime.GetMinute(), dateTime.GetSecond());
719 date.SetValue(dateTime);
722 __pPresenter->SetDateTime(date);
728 _DateTimePicker::SetDateTime(const DateTime& dateTime)
730 SetProperty("dateTime", Variant(dateTime));
736 _DateTimePicker::GetPropertyDateTime(void) const
738 DateTime dateTime = DateTime();
740 dateTime = __pPresenter->GetDateTime();
742 return Variant(dateTime);
746 _DateTimePicker::GetDateTime(void) const
748 Variant dateTime = GetProperty("dateTime");
750 return dateTime.ToDateTime();
754 _DateTimePicker::SetCurrentDateTime(void)
756 __pPresenter->SetCurrentDateTime();
762 _DateTimePicker::SetFocusBoxId(int boxId)
764 __pPresenter->SetFocusBoxId(boxId);
770 _DateTimePicker::SetAccessibilityElementText(int index, const String& text, bool isAmPm)
772 _AccessibilityElement* pElement = null;
773 String hintAmPmText(L"Double tap to change to ");
775 if (__accessibilityElements.GetAt(index, pElement) == E_SUCCESS)
777 result r = GetLastResult();
778 SysTryReturnVoidResult(NID_UI_CTRL, (pElement != null), r, "[%s] Propagating.", GetErrorMessage(r));
780 pElement->SetLabel(text);
787 _DateTimeUtils dateTimeUtils;
788 dateTimeUtils.GetAmPm(amText, AM_TYPE);
789 dateTimeUtils.GetAmPm(pmText, PM_TYPE);
793 hintAmPmText.Append(pmText);
797 hintAmPmText.Append(amText);
800 pElement->SetHint(hintAmPmText);
804 SetLastResult(E_SUCCESS);
810 _DateTimePicker::OnTouchPressed(const _Control& source, const _TouchInfo& touchinfo)
812 return __pPresenter->OnTouchPressed(source, touchinfo);
816 _DateTimePicker::OnTouchMoved(const _Control& source, const _TouchInfo& touchinfo)
818 return __pPresenter->OnTouchMoved(source, touchinfo);
822 _DateTimePicker::OnTouchReleased(const _Control& source, const _TouchInfo& touchinfo)
824 return __pPresenter->OnTouchReleased(source, touchinfo);
828 _DateTimePicker::OnTouchCanceled(const _Control& source, const _TouchInfo& touchinfo)
830 return __pPresenter->OnTouchCanceled(source, touchinfo);
834 _DateTimePicker::OnAttachedToMainTree(void)
836 _AccessibilityContainer* pContainer = GetAccessibilityContainer();
837 if (pContainer != null)
839 float dateTimeDisplayBoxHeight = 0.0f;
840 float amPmDisplayBoxHeight = 0.0f;
841 float topMargin = 0.0f;
842 float leftMargin = 0.0f;
843 const _DateTimeDisplayBox* pBox = null;
844 const _DateTimeDisplayBox* pAmPmBox = null;
846 GET_SHAPE_CONFIG(DATETIMEPICKER::LEFT_MARGIN, GetOrientation(), leftMargin);
848 pContainer->AddListener(*this);
851 for (int index = 0; index < DATETIME_ID_MAX; index++)
853 pBox = __pPresenter->GetDisplayBox(index);
856 _AccessibilityElement* pElement = new (std::nothrow) _AccessibilityElement(true);
857 SysTryReturnResult(NID_UI_CTRL, (pElement != null), E_OUT_OF_MEMORY, "Memory allocation failed.");
859 FloatRectangle displayBoxBounds = pBox->GetDisplayBoxBounds();
860 int displayBoxId = pBox->GetDisplayBoxId();
862 String hintText(L"Double tap to edit");
864 switch (displayBoxId)
866 case DATETIME_ID_DAY:
867 pElement->SetTrait(ACCESSIBILITY_TRAITS_DAY);
868 pElement->SetHint(hintText);
870 case DATETIME_ID_MONTH:
871 pElement->SetTrait(ACCESSIBILITY_TRAITS_MONTH);
872 pElement->SetHint(hintText);
874 case DATETIME_ID_YEAR:
875 pElement->SetTrait(ACCESSIBILITY_TRAITS_YEAR);
876 pElement->SetHint(hintText);
878 case DATETIME_ID_HOUR:
879 pElement->SetTrait(ACCESSIBILITY_TRAITS_HOUR);
880 pElement->SetHint(hintText);
882 case DATETIME_ID_MINUTE:
883 pElement->SetTrait(ACCESSIBILITY_TRAITS_MINUTE);
884 pElement->SetHint(hintText);
888 GET_SHAPE_CONFIG(DATETIMEPICKER::DATETIME_DISPLAY_BOX_HEIGHT, GetOrientation(), dateTimeDisplayBoxHeight);
889 GET_SHAPE_CONFIG(DATETIMEPICKER::AMPM_DISPLAY_BOX_HEIGHT, GetOrientation(), amPmDisplayBoxHeight);
890 topMargin = (amPmDisplayBoxHeight - dateTimeDisplayBoxHeight) / 2.0f;
892 displayBoxBounds.x += leftMargin;
893 displayBoxBounds.y -= topMargin;
894 displayBoxBounds.height += 2 * topMargin;
896 if (__pDisplayVisualElement)
898 displayBoxBounds.y += __pDisplayVisualElement->GetBounds().y;
901 pElement->SetLabel(pBox->GetText());
902 pElement->SetBounds(displayBoxBounds);
903 pContainer->AddElement(*pElement);
908 String hintAmPmText(L"Double tap to change");
910 pAmPmBox = __pPresenter->GetAmPmBox();
911 if (pAmPmBox != null)
913 _AccessibilityElement* pElement = new (std::nothrow) _AccessibilityElement(true);
914 SysTryReturnResult(NID_UI_CTRL, (pElement != null), E_OUT_OF_MEMORY, "Memory allocation failed.");
916 FloatRectangle amPmBoxBounds = pAmPmBox->GetDisplayBoxBounds();
918 amPmBoxBounds.x += leftMargin;
920 if (__pDisplayVisualElement)
922 amPmBoxBounds.y += __pDisplayVisualElement->GetBounds().y;
925 pElement->SetLabel(pAmPmBox->GetText());
926 pElement->SetBounds(amPmBoxBounds);
927 pElement->SetTrait(ACCESSIBILITY_TRAITS_BUTTON);
928 pElement->SetHint(hintAmPmText);
929 pContainer->AddElement(*pElement);
932 pContainer->GetElements(__accessibilityElements);
933 _AccessibilityManager::GetInstance()->RequestAutoReading(_ACCESSIBILITY_AUTO_READING_MODE_FIRST_ITEM);
941 _DateTimePicker::OnDetachingFromMainTree(void)
943 RemoveAllAccessibilityElement();
945 return _Window::OnDetachingFromMainTree();
949 _DateTimePicker::OnChangeLayout(_ControlOrientation orientation)
951 result r = E_SUCCESS;
952 FloatDimension pickerSize(0.0f, 0.0f);
953 FloatDimension screenSize(0.0f, 0.0f);
955 screenSize = _ControlManager::GetInstance()->GetScreenSizeF();
956 pickerSize = screenSize;
957 if (orientation == _CONTROL_ORIENTATION_LANDSCAPE)
959 pickerSize.width = screenSize.height;
960 pickerSize.height = screenSize.width;
972 SysTryReturnVoidResult(NID_UI_CTRL, (r == E_SUCCESS), E_SYSTEM,
973 "[E_SYSTEM] A system error has occurred. Failed to destroy the footer for this control.");
976 SysTryReturnVoidResult(NID_UI_CTRL, (r == E_SUCCESS), E_SYSTEM,
977 "[E_SYSTEM] A system error has occurred. Failed to create the footer for this control.");
979 __pPresenter->OnChangeLayout(orientation);
981 const _DateTimeDisplayBox* pBox = null;
982 IEnumeratorT<_AccessibilityElement*>* pEnumerator = __accessibilityElements.GetEnumeratorN();
983 SysTryReturnVoidResult(NID_UI_CTRL, (pEnumerator != null), GetLastResult(),
984 "[%s] Propagating.", GetErrorMessage(GetLastResult()));
986 _AccessibilityElement* pElement = null;
988 while (pEnumerator->MoveNext() == E_SUCCESS)
990 if (pEnumerator->GetCurrent(pElement) == E_SUCCESS)
992 pBox = __pPresenter->GetDisplayBox(index);
995 FloatRectangle displayBoxBounds = pBox->GetDisplayBoxBounds();
997 if (__pDisplayVisualElement)
999 displayBoxBounds.y += __pDisplayVisualElement->GetBounds().y;
1002 pElement->SetBounds(displayBoxBounds);
1013 _DateTimePicker::OnDraw(void)
1015 __pPresenter->Draw();
1021 _DateTimePicker::OnActionPerformed(const _Control& source, int actionId)
1023 __pPresenter->OnActionPerformed(source, actionId);
1029 _DateTimePicker::OnAccessibilityActionPerformed(const _AccessibilityContainer& control, const _AccessibilityElement& element)
1031 String amString = L"";
1032 String pmString = L"";
1035 label = element.GetLabel();
1037 _DateTimeUtils dateTimeUtils;
1038 dateTimeUtils.GetAmPm(amString, AM_TYPE);
1039 dateTimeUtils.GetAmPm(pmString, PM_TYPE);
1041 if (label == amString || label == pmString)
1043 label.Append(L" Selected");
1044 _AccessibilityManager::GetInstance()->ReadContent(label);
1051 _DateTimePicker::OnFontChanged(Font* pFont)
1053 result r = E_SUCCESS;
1057 if (__pPresenter != null)
1059 r = __pPresenter->SetFont(pFont);
1060 SysTryReturnVoidResult(NID_UI_CTRL, (r == E_SUCCESS), r, "[%s] Propagating.");
1063 if (__pFooter != null)
1065 for (int i=0; i < __pFooter->GetItemCount(); i++)
1067 _Button* pButton = __pFooter->GetItem(i);
1069 if (pButton != null)
1071 r = pButton->SetFont(pFont->GetFaceName());
1072 SysTryReturnVoidResult(NID_UI_CTRL, (r == E_SUCCESS), r, "[%s] Propagating.", GetErrorMessage(r));
1084 _DateTimePicker::OnFontInfoRequested(unsigned long& style, float& size)
1086 style = FONT_STYLE_PLAIN;
1088 GET_SHAPE_CONFIG(DATETIMEPICKER::FONT_SIZE, GetOrientation(), size);
1094 _DateTimePicker::GetDateTimeFont(void)
1100 _DateTimePicker::InitializeFont(void)
1102 result r = E_SUCCESS;
1104 __pFont = GetFallbackFont();
1105 r = GetLastResult();
1106 SysTryReturnResult(NID_UI_CTRL, (__pFont != null), r, "[%s] Propagating.", GetErrorMessage(r));
1112 _DateTimePicker::RemoveAllAccessibilityElement(void)
1114 _AccessibilityContainer* pContainer = GetAccessibilityContainer();
1115 SysTryReturnVoidResult(NID_UI_CTRL, (pContainer != null), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1117 _AccessibilityElement* pAccessibilityElement = null;
1119 while (__accessibilityElements.GetCount() > 0)
1121 if ((__accessibilityElements.GetAt(0, pAccessibilityElement)) == E_SUCCESS)
1123 __accessibilityElements.RemoveAt(0);
1124 pContainer->RemoveElement(*pAccessibilityElement);
1128 __accessibilityElements.RemoveAt(0);
1133 }}} // Tizen::Ui::Controls