2 // Open Service Platform
3 // Copyright (c) 2012-2013 Samsung Electronics Co., Ltd.
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
9 // http://floralicense.org/license/
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.
18 * @file FUiCtrl_DateTimePicker.cpp
19 * @brief This is the implementation file for the _DateTimePicker class.
22 #include <FGrpDimension.h>
23 #include <FBaseColIEnumeratorT.h>
24 #include <FBaseSysLog.h>
25 #include <FGrp_BitmapImpl.h>
27 #include "FUiCtrl_DateTimePicker.h"
28 #include "FUiAnim_VisualElement.h"
29 #include "FUiCtrl_DateTimeDefine.h"
30 #include "FUiCtrl_DateTimePresenter.h"
31 #include "FUiCtrl_DateTimeDisplayBox.h"
32 #include "FUiCtrl_Form.h"
33 #include "FUiCtrl_Frame.h"
34 #include "FUiCtrl_Button.h"
35 #include "FUiCtrl_Toolbar.h"
36 #include "FUiCtrl_DateTimeChangeEvent.h"
37 #include "FUiCtrl_IDateTimeChangeEventListener.h"
38 #include "FUi_AccessibilityContainer.h"
39 #include "FUi_AccessibilityElement.h"
40 #include "FUi_AccessibilityManager.h"
41 #include "FUi_UiTouchEvent.h"
42 #include "FUi_ResourceManager.h"
44 using namespace Tizen::Base;
45 using namespace Tizen::Base::Collection;
46 using namespace Tizen::Graphics;
47 using namespace Tizen::Ui;
48 using namespace Tizen::Ui::Animations;
50 namespace Tizen { namespace Ui { namespace Controls
53 IMPLEMENT_PROPERTY(_DateTimePicker);
55 _DateTimePicker::_DateTimePicker(_DateTimePresenter* pPresenter, const String& title)
56 : __pPresenter(pPresenter)
60 , __pDateTimeChangeEvent(null)
62 , __pDisplayVisualElement(null)
64 GetAccessibilityContainer()->Activate(true);
67 _DateTimePicker::~_DateTimePicker(void)
69 if (__pDateTimeChangeEvent != null)
71 delete __pDateTimeChangeEvent;
72 __pDateTimeChangeEvent = null;
75 if (__pHeader != null)
77 DetachSystemChild(*__pHeader);
82 if (__pFooter != null)
84 DetachSystemChild(*__pFooter);
89 if (__pDisplayVisualElement != null)
91 __pDisplayVisualElement->Destroy();
92 __pDisplayVisualElement = null;
98 if (likely(_AccessibilityManager::IsActivated()))
100 _AccessibilityElement* pElement = null;
101 while (__accessibilityElements.GetCount() > 0)
103 if ((__accessibilityElements.GetAt(0, pElement)) == E_SUCCESS)
105 __accessibilityElements.RemoveAt(0);
106 pElement->GetParent()->RemoveElement(*pElement);
110 __accessibilityElements.RemoveAt(0);
117 _DateTimePicker::CreateDateTimePickerN(int style, const String& title)
119 result r = E_SUCCESS;
120 Dimension pickerSize(0, 0);
121 Dimension screenSize(0, 0);
122 _ControlOrientation orientation = _CONTROL_ORIENTATION_PORTRAIT;
124 SysTryReturn(NID_UI_CTRL, ((style & DATETIME_OUTPUT_STYLE_DATETIME) != DATETIME_OUTPUT_STYLE_INVALID), null, E_INVALID_ARG,
125 "[E_INVALID_ARG] Invalid argument(s) is used. The style provided is not present in the _DateTimeOutputStyle list.");
127 _DateTimePresenter* pPresenter = new (std::nothrow) _DateTimePresenter(style, title);
128 SysTryReturn(NID_UI_CTRL, (pPresenter != null), null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
130 _DateTimePicker* pView = new (std::nothrow) _DateTimePicker(pPresenter, title);
131 SysTryCatch(NID_UI_CTRL, (pView != null), , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
133 r = pView->InitializeFont();
134 SysTryCatch(NID_UI_CTRL, (r == E_SUCCESS), , E_SYSTEM, "[E_SYSTEM] A system error has occurred. Failed to set the Font.");
136 #if defined(MULTI_WINDOW)
137 r = pView->CreateRootVisualElement();
138 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
141 orientation = pView->GetOrientation();
142 screenSize = _ControlManager::GetInstance()->GetScreenSize();
143 pickerSize = screenSize;
144 if (orientation == _CONTROL_ORIENTATION_LANDSCAPE)
146 pickerSize.width = screenSize.height;
147 pickerSize.height = screenSize.width;
149 r = pView->SetSize(pickerSize);
150 SysTryCatch(NID_UI_CTRL, (r == E_SUCCESS), , E_SYSTEM,
151 "[E_SYSTEM] A system error has occurred. Failed to set the size for this control");
153 if (title.IsEmpty() == false && orientation == _CONTROL_ORIENTATION_PORTRAIT)
155 r = pView->CreateHeader();
156 SysTryCatch(NID_UI_CTRL, (r == E_SUCCESS), , E_SYSTEM,
157 "[E_SYSTEM] A system error has occurred. Failed to create the header for this control");
160 r = pView->CreateFooter();
161 SysTryCatch(NID_UI_CTRL, (r == E_SUCCESS), , E_SYSTEM,
162 "[E_SYSTEM] A system error has occurred. Failed to create the footer for this control");
164 r = pView->CreateDisplayVisualElement();
165 SysTryCatch(NID_UI_CTRL, (r == E_SUCCESS), , E_SYSTEM,
166 "[E_SYSTEM] A system error has occurred. Failed to create the display visual element for this control");
168 r = pPresenter->Construct(*pView);
169 SysTryCatch(NID_UI_CTRL, (r == E_SUCCESS), , E_SYSTEM,
170 "[E_SYSTEM] A system error has occurred. Failed to construct the presenter instance for this control");
172 pView->AcquireHandle();
174 pView->__pDateTimeChangeEvent = new (std::nothrow) _DateTimeChangeEvent(*pView);
175 SysTryCatch(NID_UI_CTRL, (pView->__pDateTimeChangeEvent != null), , E_OUT_OF_MEMORY,
176 "[E_OUT_OF_MEMORY] Memory allocation failed.");
178 if (likely(_AccessibilityManager::IsActivated()) && pView->GetAccessibilityContainer() != null)
180 pView->GetAccessibilityContainer()->Activate(true);
193 _DateTimePicker::CreateHeader(void)
195 Rectangle indicatorBounds(0, 0, 0, 0);
196 Rectangle headerBounds(0, 0, 0, 0);
197 _Frame* pFrame = dynamic_cast <_Frame*>(_ControlManager::GetInstance()->GetCurrentFrame());
198 SysTryReturnResult(NID_UI_CTRL, (pFrame != null), E_SYSTEM,
199 "A system error has occurred. Failed to get the instance of frame.");
201 _Form* pForm = pFrame->GetCurrentForm();
202 SysTryReturnResult(NID_UI_CTRL, (pForm != null), E_SYSTEM,
203 "A system error has occurred. Failed to get the instance of form.");
205 indicatorBounds = pForm->GetIndicatorBounds();
207 _Toolbar* pHeader = _Toolbar::CreateToolbarN(true);
208 result r = GetLastResult();
209 SysTryReturnResult(NID_UI_CTRL, (pHeader != null), r, "[%s] Propagating.", GetErrorMessage(r));
211 r = AttachSystemChild(*pHeader);
218 pHeader->SetStyle(TOOLBAR_TITLE);
219 pHeader->SetTitleText(__title);
220 pHeader->SetMovable(true);
221 pHeader->SetResizable(true);
222 headerBounds = pHeader->GetBounds();
223 headerBounds.y = indicatorBounds.height;
224 pHeader->SetBounds(headerBounds);
225 pHeader->SetMovable(false);
226 pHeader->SetResizable(false);
228 if (__pHeader != null)
230 DetachSystemChild(*__pHeader);
241 _DateTimePicker::DestroyHeader(void)
243 if (__pHeader != null)
245 DetachSystemChild(*__pHeader);
254 _DateTimePicker::CreateFooter(void)
256 result r = E_SUCCESS;
257 _Button* pSaveButton = null;
258 _Button* pCancelButton = null;
261 _ControlOrientation orientation = GetOrientation();
263 _Toolbar* pFooter = _Toolbar::CreateToolbarN(false);
265 SysTryReturnResult(NID_UI_CTRL, (pFooter != null), r, "[%s] Propagating.", GetErrorMessage(r));
267 r = AttachSystemChild(*pFooter);
268 SysTryCatch(NID_UI_CTRL, (r == E_SUCCESS), , r, "[%s] Propagating.", GetErrorMessage(r));
270 GET_SHAPE_CONFIG(DATETIMEPICKER::FOOTER_HEIGHT, orientation, bounds.height);
271 GET_SHAPE_CONFIG(DATETIMEPICKER::INPUTPAD_HEIGHT, orientation, bounds.y);
274 bounds.y = GetBounds().height - bounds.y - bounds.height;
275 bounds.width = GetBounds().width;
277 pFooter->SetMovable(true);
278 pFooter->SetResizable(true);
280 r = pFooter->SetBounds(bounds);
281 SysTryCatch(NID_UI_CTRL, (r == E_SUCCESS), , r, "[%s] Propagating.", GetErrorMessage(r));
283 pFooter->SetMovable(false);
284 pFooter->SetResizable(false);
286 pFooter->AddActionEventListener(*this);
288 r = pFooter->SetStyle(TOOLBAR_TEXT);
289 SysTryCatch(NID_UI_CTRL, (r == E_SUCCESS), , r, "[%s] Propagating.", GetErrorMessage(r));
291 // Create 'Save' button
292 pSaveButton = _Button::CreateButtonN();
294 SysTryCatch(NID_UI_CTRL, (r == E_SUCCESS), , r, "[%s] Propagating.", GetErrorMessage(r));
296 r = pSaveButton->SetActionId(DATETIME_EVENT_ID_SAVE);
297 SysTryCatch(NID_UI_CTRL, (r == E_SUCCESS), , r, "[%s] Propagating.", GetErrorMessage(r));
299 GET_STRING_CONFIG(IDS_COM_SK_SAVE, text);
301 r = pSaveButton->SetText(text);
302 SysTryCatch(NID_UI_CTRL, (r == E_SUCCESS), , r, "[%s] Propagating.", GetErrorMessage(r));
304 // Create 'Cancel' button
305 pCancelButton = _Button::CreateButtonN();
307 SysTryCatch(NID_UI_CTRL, (r == E_SUCCESS), , r, "[%s] Propagating.", GetErrorMessage(r));
309 r = pCancelButton->SetActionId(DATETIME_EVENT_ID_CANCEL);
310 SysTryCatch(NID_UI_CTRL, (r == E_SUCCESS), , r, "[%s] Propagating.", GetErrorMessage(r));
312 GET_STRING_CONFIG(IDS_COM_POP_CANCEL, text);
314 r = pCancelButton->SetText(text);
315 SysTryCatch(NID_UI_CTRL, (r == E_SUCCESS), , r, "[%s] Propagating.", GetErrorMessage(r));
317 r = pFooter->AddItem(pSaveButton);
318 SysTryCatch(NID_UI_CTRL, (r == E_SUCCESS), , r, "[%s] Propagating.", GetErrorMessage(r));
320 r = pFooter->AddItem(pCancelButton);
321 SysTryCatch(NID_UI_CTRL, (r == E_SUCCESS), , r, "[%s] Propagating.");
323 if (__pFooter != null)
325 DetachSystemChild(*__pFooter);
335 DetachSystemChild(*pFooter);
339 delete pCancelButton;
345 _DateTimePicker::DestroyFooter(void)
347 if (__pFooter != null)
349 DetachSystemChild(*__pFooter);
359 _DateTimePicker::GetHeaderBounds(void)
361 Rectangle headerBounds(0, 0, 0, 0);
363 if (__pHeader != null)
365 headerBounds = __pHeader->GetBounds();
369 _Frame* pFrame = dynamic_cast <_Frame*>(_ControlManager::GetInstance()->GetCurrentFrame());
370 SysTryReturn(NID_UI_CTRL, (pFrame != null), Rectangle(), E_SYSTEM,
371 "[E_SYSTEM] A system error has occurred. Failed to get the instance of frame.");
373 _Form* pForm = pFrame->GetCurrentForm();
374 SysTryReturn(NID_UI_CTRL, (pForm != null), Rectangle(), E_SYSTEM,
375 "[E_SYSTEM] A system error has occurred. Failed to get the instance of form.");
377 headerBounds = pForm->GetIndicatorBounds();
384 _DateTimePicker::CreateDisplayVisualElement(void)
386 result r = E_SUCCESS;
388 __pDisplayVisualElement = new (std::nothrow) _VisualElement();
389 SysTryReturnResult(NID_UI_CTRL, __pDisplayVisualElement, E_OUT_OF_MEMORY, "Memory allocation failed.");
391 r = __pDisplayVisualElement->Construct();
392 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
394 __pDisplayVisualElement->SetShowState(true);
395 __pDisplayVisualElement->SetImplicitAnimationEnabled(false);
397 r = GetVisualElement()->AttachChild(*__pDisplayVisualElement);
398 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
403 __pDisplayVisualElement->Destroy();
404 __pDisplayVisualElement = null;
410 _DateTimePicker::SetDisplayVisualElementBounds(Rectangle bounds)
412 if (__pDisplayVisualElement != null)
414 __pDisplayVisualElement->SetBounds(FloatRectangle(bounds.x, bounds.y, bounds.width, bounds.height));
421 _DateTimePicker::GetDisplayVisualElement(void)
423 return __pDisplayVisualElement;
427 _DateTimePicker::AddDateTimeChangeEventListener(const Controls::_IDateTimeChangeEventListener& listener)
429 SysTryReturnResult(NID_UI_CTRL, (__pDateTimeChangeEvent != null), E_SYSTEM,
430 "A system error has occurred. The _DateTimeChangeEvent instance is null.");
432 result r = __pDateTimeChangeEvent->AddListener(listener);
433 SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Propagating.");
439 _DateTimePicker::RemoveDateTimeChangeEventListener(const Controls::_IDateTimeChangeEventListener& listener)
441 SysTryReturnResult(NID_UI_CTRL, (__pDateTimeChangeEvent != null), E_SYSTEM,
442 "A system error has occurred. The _DateTimeChangeEvent instance is null.");
444 result r = __pDateTimeChangeEvent->RemoveListener(listener);
445 SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Propagating.");
451 _DateTimePicker::FireDateTimeChangeEvent(_DateTimeChangeStatus status, DateTime& dateTime)
453 SysTryReturnResult(NID_UI_CTRL, (__pDateTimeChangeEvent != null), E_SYSTEM,
454 "A system error has occurred. The _DateTimeChangeEvent instance is null");
456 SysTryReturnResult(NID_UI_CTRL, (status >= DATE_INTERNAL_CHANGE_SAVED && status <= TIME_INTERNAL_CHANGE_CANCELED), E_INVALID_ARG,
457 "Invalid argument(s) is used. The status provided is not present in the _DateTimeChangeStatus list.");
459 _DateTimeChangeEventArg* pDateTimeEventArg = new (std::nothrow) _DateTimeChangeEventArg(status);
460 SysTryReturnResult(NID_UI_CTRL, (pDateTimeEventArg != null), E_OUT_OF_MEMORY, "Memory allocation failed.");
462 pDateTimeEventArg->SetDateTime(dateTime);
463 pDateTimeEventArg->SetDate(dateTime.GetYear(), dateTime.GetMonth(), dateTime.GetDay());
464 pDateTimeEventArg->SetTime(dateTime.GetHour(), dateTime.GetMinute());
465 __pDateTimeChangeEvent->Fire(*pDateTimeEventArg);
471 _DateTimePicker::SetPropertyYear(const Variant& year)
473 int yearValue = year.ToInt();
475 SysTryReturnResult(NID_UI_CTRL, (yearValue >= DATETIME_YEAR_MIN && yearValue <= DATETIME_YEAR_MAX), E_INVALID_ARG,
476 "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);
478 return __pPresenter->SetYear(yearValue);
482 _DateTimePicker::SetYear(int year)
484 return SetProperty("year", Variant(year));
488 _DateTimePicker::GetPropertyYear(void) const
492 year = __pPresenter->GetYear();
494 return Variant(year);
498 _DateTimePicker::GetYear(void) const
500 Variant year = GetProperty("year");
506 _DateTimePicker::SetPropertyMonth(const Variant& month)
508 int monthValue = month.ToInt();
510 SysTryReturnResult(NID_UI_CTRL, (monthValue >= DATETIME_MONTH_MIN && monthValue <= DATETIME_MONTH_MAX), E_INVALID_ARG,
511 "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);
513 return __pPresenter->SetMonth(monthValue);
517 _DateTimePicker::SetMonth(int month)
519 return SetProperty("month", Variant(month));
523 _DateTimePicker::GetPropertyMonth(void) const
527 month = __pPresenter->GetMonth();
529 return Variant(month);
533 _DateTimePicker::GetMonth(void) const
535 Variant month = GetProperty("month");
537 return month.ToInt();
541 _DateTimePicker::SetPropertyDay(const Variant& day)
543 int dayValue = day.ToInt();
545 SysTryReturnResult(NID_UI_CTRL, (dayValue >= DATETIME_DAY_MIN && dayValue <= DATETIME_DAY_MAX), E_INVALID_ARG,
546 "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);
548 return __pPresenter->SetDay(dayValue);
553 _DateTimePicker::SetDay(int day)
555 return SetProperty("day", Variant(day));
559 _DateTimePicker::GetPropertyDay(void) const
563 day = __pPresenter->GetDay();
569 _DateTimePicker::GetDay(void) const
571 Variant day = GetProperty("day");
577 _DateTimePicker::SetPropertyHour(const Variant& hour)
579 int hourValue = hour.ToInt();
581 SysTryReturnResult(NID_UI_CTRL, (hourValue >= DATETIME_HOUR_MIN && hourValue <= DATETIME_HOUR_MAX), E_INVALID_ARG,
582 "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);
584 return __pPresenter->SetHour(hourValue);
589 _DateTimePicker::SetHour(int hour)
591 return SetProperty("hour", Variant(hour));
595 _DateTimePicker::GetPropertyHour(void) const
599 hour = __pPresenter->GetHour();
601 return Variant(hour);
605 _DateTimePicker::GetHour(void) const
607 Variant hour = GetProperty("hour");
613 _DateTimePicker::SetPropertyMinute(const Variant& minute)
615 int minuteValue = minute.ToInt();
617 SysTryReturnResult(NID_UI_CTRL, (minuteValue >= DATETIME_MINUTE_MIN && minuteValue <= DATETIME_MINUTE_MAX), E_INVALID_ARG,
618 "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);
620 return __pPresenter->SetMinute(minuteValue);
625 _DateTimePicker::SetMinute(int minute)
627 return SetProperty("minute", Variant(minute));
631 _DateTimePicker::GetPropertyMinute(void) const
635 minute = __pPresenter->GetMinute();
637 return Variant(minute);
641 _DateTimePicker::GetMinute(void) const
643 Variant minute = GetProperty("minute");
645 return minute.ToInt();
649 _DateTimePicker::SetProperty24HourNotation(const Variant& enable)
651 bool enableValue = enable.ToBool();
653 __pPresenter->Set24HourNotationEnabled(enableValue);
659 _DateTimePicker::Set24HourNotationEnabled(bool enable)
661 SetProperty("24hourNotation", Variant(enable));
667 _DateTimePicker::GetProperty24HourNotation(void) const
669 bool is24HourNotation = false;
671 is24HourNotation = __pPresenter->Is24HourNotationEnabled();
673 return Variant(is24HourNotation);
677 _DateTimePicker::Is24HourNotationEnabled(void) const
679 Variant enable = GetProperty("24hourNotation");
681 return enable.ToBool();
685 _DateTimePicker::SetPropertyMinYearRange(const Variant& minYear)
687 int minYearValue = minYear.ToInt();
688 int currentMinYear = DATETIME_YEAR_MIN;
689 int currentMaxYear = DATETIME_YEAR_MAX;
691 SysTryReturnResult(NID_UI_CTRL, (minYearValue >= DATETIME_YEAR_MIN && minYearValue <= DATETIME_YEAR_MAX), E_INVALID_ARG,
692 "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);
694 __pPresenter->GetYearRange(currentMinYear, currentMaxYear);
696 SysTryReturnResult(NID_UI_CTRL, (currentMaxYear >= minYearValue), E_INVALID_ARG,
697 "Invalid argument(s) is used. The year (%d) must be less than or equal to (%d).", minYearValue, currentMaxYear);
699 return __pPresenter->SetYearRange(minYearValue, currentMaxYear);
703 _DateTimePicker::GetPropertyMinYearRange(void) const
705 int currentMinYear = DATETIME_YEAR_MIN;
706 int currentMaxYear = DATETIME_YEAR_MAX;
708 __pPresenter->GetYearRange(currentMinYear, currentMaxYear);
710 return Variant(currentMinYear);
714 _DateTimePicker::SetPropertyMaxYearRange(const Variant& maxYear)
716 int maxYearValue = maxYear.ToInt();
717 int currentMinYear = DATETIME_YEAR_MIN;
718 int currentMaxYear = DATETIME_YEAR_MAX;
720 SysTryReturnResult(NID_UI_CTRL, (maxYearValue >= DATETIME_YEAR_MIN && maxYearValue <= DATETIME_YEAR_MAX), E_INVALID_ARG,
721 "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);
723 __pPresenter->GetYearRange(currentMinYear, currentMaxYear);
725 SysTryReturnResult(NID_UI_CTRL, (maxYearValue >= currentMinYear), E_INVALID_ARG,
726 "Invalid argument(s) is used. The year (%d) must be greater than or equal to (%d).", maxYearValue, currentMinYear);
728 return __pPresenter->SetYearRange(currentMinYear, maxYearValue);
732 _DateTimePicker::GetPropertyMaxYearRange(void) const
734 int currentMinYear = DATETIME_YEAR_MIN;
735 int currentMaxYear = DATETIME_YEAR_MAX;
737 __pPresenter->GetYearRange(currentMinYear, currentMaxYear);
739 return Variant(currentMaxYear);
743 _DateTimePicker::SetYearRange(int minYear, int maxYear)
745 result r = E_SUCCESS;
747 SysTryReturnResult(NID_UI_CTRL, (minYear >= DATETIME_YEAR_MIN && minYear <= DATETIME_YEAR_MAX), E_INVALID_ARG,
748 "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);
749 SysTryReturnResult(NID_UI_CTRL, (maxYear >= DATETIME_YEAR_MIN && maxYear <= DATETIME_YEAR_MAX), E_INVALID_ARG,
750 "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);
751 SysTryReturnResult(NID_UI_CTRL, (maxYear >= minYear), E_INVALID_ARG,
752 "Invalid argument(s) is used. The maxYear (%d) must be greater than or equal to minYear (%d).", maxYear, minYear);
754 r = SetProperty("minYearRange", Variant(minYear));
760 r = SetProperty("maxYearRange", Variant(maxYear));
766 _DateTimePicker::GetYearRange(int& minYear, int& maxYear) const
768 Variant currentMinYear = GetProperty("minYearRange");
769 Variant currentMaxYear = GetProperty("maxYearRange");
771 minYear = currentMinYear.ToInt();
772 maxYear = currentMaxYear.ToInt();
778 _DateTimePicker::SetPropertyDateTime(const Variant& varDateTime)
780 DateTime dateTime = varDateTime.ToDateTime();
782 __pPresenter->SetDateTime(dateTime);
788 _DateTimePicker::SetDateTime(const DateTime& dateTime)
790 SetProperty("dateTime", Variant(dateTime));
796 _DateTimePicker::GetPropertyDateTime(void) const
798 DateTime dateTime = DateTime();
800 dateTime = __pPresenter->GetDateTime();
802 return Variant(dateTime);
806 _DateTimePicker::GetDateTime(void) const
808 Variant dateTime = GetProperty("dateTime");
810 return dateTime.ToDateTime();
814 _DateTimePicker::SetCurrentDateTime(void)
816 __pPresenter->SetCurrentDateTime();
822 _DateTimePicker::SetFocusBoxId(int boxId)
824 __pPresenter->SetFocusBoxId(boxId);
830 _DateTimePicker::SetAccessibilityElementText(int index, const String& text, bool isAmPm)
832 _AccessibilityElement* pElement = null;
833 int elementIndex = __accessibilityElements.GetCount() - 1 - index;
834 String hintAmPmText(L"Double tap to change to ");
836 if (__accessibilityElements.GetAt(elementIndex, pElement) == E_SUCCESS)
838 result r = GetLastResult();
839 SysTryReturnVoidResult(NID_UI_CTRL, (pElement != null), r, "[%s] Propagating.", GetErrorMessage(r));
841 pElement->SetLabel(text);
846 GET_STRING_CONFIG(IDS_COM_BODY_AM, amText);
850 hintAmPmText.Append(L"PM");
854 hintAmPmText.Append(L"AM");
857 pElement->SetHint(hintAmPmText);
861 SetLastResult(E_SUCCESS);
867 _DateTimePicker::OnTouchPressed(const _Control& source, const _TouchInfo& touchinfo)
869 return __pPresenter->OnTouchPressed(source, touchinfo);
873 _DateTimePicker::OnTouchMoved(const _Control& source, const _TouchInfo& touchinfo)
875 return __pPresenter->OnTouchMoved(source, touchinfo);
879 _DateTimePicker::OnTouchReleased(const _Control& source, const _TouchInfo& touchinfo)
881 return __pPresenter->OnTouchReleased(source, touchinfo);
885 _DateTimePicker::OnTouchCanceled(const _Control& source, const _TouchInfo& touchinfo)
887 return __pPresenter->OnTouchCanceled(source, touchinfo);
891 _DateTimePicker::OnAttachedToMainTree(void)
893 if (likely(!(_AccessibilityManager::IsActivated())))
898 _AccessibilityContainer* pContainer = GetAccessibilityContainer();
899 if (pContainer != null)
901 pContainer->AddListener(*this);
903 const _DateTimeDisplayBox* pBox = null;
904 const _DateTimeDisplayBox* pAmPmBox = null;
906 for (int index = 0; index < DATETIME_ID_MAX; index++)
908 pBox = __pPresenter->GetDisplayBox(index);
911 _AccessibilityElement* pElement = new (std::nothrow) _AccessibilityElement(true);
912 SysTryReturnResult(NID_UI_CTRL, (pElement != null), E_OUT_OF_MEMORY, "Memory allocation failed.");
914 Rectangle displayBoxBounds = pBox->GetDisplayBoxBounds();
915 int displayBoxId = pBox->GetDisplayBoxId();
917 String hintText(L"Double tap to edit");
919 switch (displayBoxId)
921 case DATETIME_ID_DAY:
922 pElement->SetTrait(ACCESSIBILITY_TRAITS_DAY);
923 pElement->SetHint(hintText);
925 case DATETIME_ID_MONTH:
926 pElement->SetTrait(ACCESSIBILITY_TRAITS_MONTH);
927 pElement->SetHint(hintText);
929 case DATETIME_ID_YEAR:
930 pElement->SetTrait(ACCESSIBILITY_TRAITS_YEAR);
931 pElement->SetHint(hintText);
933 case DATETIME_ID_HOUR:
934 pElement->SetTrait(ACCESSIBILITY_TRAITS_HOUR);
935 pElement->SetHint(hintText);
937 case DATETIME_ID_MINUTE:
938 pElement->SetTrait(ACCESSIBILITY_TRAITS_MINUTE);
939 pElement->SetHint(hintText);
943 if (__pDisplayVisualElement)
945 displayBoxBounds.y += __pDisplayVisualElement->GetBounds().y;
948 pElement->SetLabel(pBox->GetText());
949 pElement->SetBounds(displayBoxBounds);
950 pContainer->AddElement(*pElement);
954 String hintAmPmText(L"Double tap to change");
956 pAmPmBox = __pPresenter->GetAmPmBox();
957 if (pAmPmBox != null)
959 _AccessibilityElement* pElement = new (std::nothrow) _AccessibilityElement(true);
960 SysTryReturnResult(NID_UI_CTRL, (pElement != null), E_OUT_OF_MEMORY, "Memory allocation failed.");
962 Rectangle amPmBoxBounds = pAmPmBox->GetDisplayBoxBounds();
964 if (__pDisplayVisualElement)
966 amPmBoxBounds.y += __pDisplayVisualElement->GetBounds().y;
969 pElement->SetLabel(pAmPmBox->GetText());
970 pElement->SetBounds(amPmBoxBounds);
971 pElement->SetTrait(ACCESSIBILITY_TRAITS_BUTTON);
972 pElement->SetHint(hintAmPmText);
973 pContainer->AddElement(*pElement);
979 pContainer->GetElements(__accessibilityElements);
986 _DateTimePicker::OnChangeLayout(_ControlOrientation orientation)
988 result r = E_SUCCESS;
989 Dimension pickerSize(0, 0);
990 Dimension screenSize(0, 0);
992 screenSize = _ControlManager::GetInstance()->GetScreenSize();
993 pickerSize = screenSize;
994 if (orientation == _CONTROL_ORIENTATION_LANDSCAPE)
996 pickerSize.width = screenSize.height;
997 pickerSize.height = screenSize.width;
1001 if (__pHeader != null)
1003 r = DestroyHeader();
1004 SysTryReturnVoidResult(NID_UI_CTRL, (r == E_SUCCESS), E_SYSTEM,
1005 "[E_SYSTEM] A system error has occurred. Failed to destroy the header for this control.");
1008 if (orientation == _CONTROL_ORIENTATION_PORTRAIT && __title.IsEmpty() == false)
1011 SysTryReturnVoidResult(NID_UI_CTRL, (r == E_SUCCESS), E_SYSTEM,
1012 "[E_SYSTEM] A system error has occurred. Failed to create the header for this control.");
1015 r = DestroyFooter();
1016 SysTryReturnVoidResult(NID_UI_CTRL, (r == E_SUCCESS), E_SYSTEM,
1017 "[E_SYSTEM] A system error has occurred. Failed to destroy the footer for this control.");
1020 SysTryReturnVoidResult(NID_UI_CTRL, (r == E_SUCCESS), E_SYSTEM,
1021 "[E_SYSTEM] A system error has occurred. Failed to create the footer for this control.");
1023 __pPresenter->OnChangeLayout(orientation);
1025 if (likely(_AccessibilityManager::IsActivated()))
1027 const _DateTimeDisplayBox* pBox = null;
1028 IEnumeratorT<_AccessibilityElement*>* pEnumerator = __accessibilityElements.GetEnumeratorN();
1029 _AccessibilityElement* pElement = null;
1031 while (pEnumerator->MoveNext() == E_SUCCESS)
1033 if (pEnumerator->GetCurrent(pElement) == E_SUCCESS)
1035 pBox = __pPresenter->GetDisplayBox(index);
1038 Rectangle displayBoxBounds = pBox->GetDisplayBoxBounds();
1040 if (__pDisplayVisualElement)
1042 displayBoxBounds.y += __pDisplayVisualElement->GetBounds().y;
1045 pElement->SetBounds(displayBoxBounds);
1057 _DateTimePicker::OnDraw(void)
1059 __pPresenter->Draw();
1065 _DateTimePicker::OnActionPerformed(const _Control& source, int actionId)
1067 __pPresenter->OnActionPerformed(source, actionId);
1073 _DateTimePicker::OnAccessibilityActionPerformed(const _AccessibilityContainer& control, const _AccessibilityElement& element)
1075 String amString = L"";
1076 String pmString = L"";
1079 label = element.GetLabel();
1081 GET_STRING_CONFIG(IDS_COM_BODY_AM, amString);
1082 GET_STRING_CONFIG(IDS_COM_POP_PM, pmString);
1084 if (label == amString || label == pmString)
1086 label.Append(L" Selected");
1087 _AccessibilityManager::GetInstance()->ReadContent(label);
1094 _DateTimePicker::OnFontChanged(Font* pFont)
1096 result r = E_SUCCESS;
1100 if (__pPresenter != null)
1102 r = __pPresenter->SetFont(pFont);
1103 SysTryReturnVoidResult(NID_UI_CTRL, (r == E_SUCCESS), r, "[%s] Propagating.");
1106 if (__pHeader != null)
1108 r = __pHeader->SetFont(pFont->GetFaceName());
1109 SysTryReturnVoidResult(NID_UI_CTRL, (r == E_SUCCESS), r, "[%s] Propagating.");
1112 if (__pFooter != null)
1114 for (int i=0; i < __pFooter->GetItemCount(); i++)
1116 _Button* pButton = __pFooter->GetItem(i);
1118 if (pButton != null)
1120 r = pButton->SetFont(pFont->GetFaceName());
1121 SysTryReturnVoidResult(NID_UI_CTRL, (r == E_SUCCESS), r, "[%s] Propagating.", GetErrorMessage(r));
1133 _DateTimePicker::OnFontInfoRequested(unsigned long& style, int& size)
1135 style = FONT_STYLE_PLAIN;
1137 GET_SHAPE_CONFIG(DATETIMEPICKER::FONT_SIZE, GetOrientation(), size);
1143 _DateTimePicker::GetDateTimeFont(void)
1149 _DateTimePicker::InitializeFont(void)
1151 result r = E_SUCCESS;
1153 __pFont = GetFallbackFont();
1154 r = GetLastResult();
1155 SysTryReturnResult(NID_UI_CTRL, (__pFont != null), r, "[%s] Propagating.", GetErrorMessage(r));
1160 }}} // Tizen::Ui::Controls