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>
27 #include <FSysSettingInfo.h>
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"
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;
55 namespace Tizen { namespace Ui { namespace Controls
58 IMPLEMENT_PROPERTY(_DateTimePicker);
60 _DateTimePicker::_DateTimePicker(_DateTimePresenter* pPresenter, const String& title)
61 : __pPresenter(pPresenter)
64 , __pDateTimeChangeEvent(null)
66 , __pDisplayVisualElement(null)
67 , __isInFocusMode(false)
71 _DateTimePicker::~_DateTimePicker(void)
73 SettingInfo::RemoveSettingEventListener(*this);
75 delete __pDateTimeChangeEvent;
76 __pDateTimeChangeEvent = null;
78 if (__pFooter != null)
80 DetachSystemChild(*__pFooter);
85 if (__pDisplayVisualElement != null)
87 __pDisplayVisualElement->Destroy();
88 __pDisplayVisualElement = null;
96 _DateTimePicker::CreateDateTimePickerN(int style, const String& title)
99 FloatDimension pickerSize(0.0f, 0.0f);
100 FloatDimension screenSize(0.0f, 0.0f);
101 _ControlOrientation orientation = _CONTROL_ORIENTATION_PORTRAIT;
102 _DateTimePresenter* pPresenter = null;
103 _DateTimePicker* pView = null;
105 SysTryReturn(NID_UI_CTRL, ((style & DATETIME_OUTPUT_STYLE_DATETIME) != DATETIME_OUTPUT_STYLE_INVALID), null, E_INVALID_ARG,
106 "[E_INVALID_ARG] Invalid argument(s) is used. The style provided is not present in the _DateTimeOutputStyle list.");
108 pPresenter = new (std::nothrow) _DateTimePresenter(style, title);
109 SysTryReturn(NID_UI_CTRL, (pPresenter != null), null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
111 pView = new (std::nothrow) _DateTimePicker(pPresenter, title);
112 SysTryCatch(NID_UI_CTRL, (pView != null), , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
114 r = pView->InitializeFont();
115 SysTryCatch(NID_UI_CTRL, (r == E_SUCCESS), , E_SYSTEM, "[E_SYSTEM] A system error has occurred. Failed to set the Font.");
117 r = pView->CreateRootVisualElement();
118 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
120 orientation = pView->GetOrientation();
121 screenSize = _ControlManager::GetInstance()->GetScreenSizeF();
122 pickerSize = screenSize;
123 if (orientation == _CONTROL_ORIENTATION_LANDSCAPE)
125 pickerSize.width = screenSize.height;
126 pickerSize.height = screenSize.width;
129 r = pView->SetSize(pickerSize);
130 SysTryCatch(NID_UI_CTRL, (r == E_SUCCESS), , E_SYSTEM,
131 "[E_SYSTEM] A system error has occurred. Failed to set the size for this control");
133 r = pView->CreateFooter();
134 SysTryCatch(NID_UI_CTRL, (r == E_SUCCESS), , E_SYSTEM,
135 "[E_SYSTEM] A system error has occurred. Failed to create the footer for this control");
137 r = pView->CreateDisplayVisualElement();
138 SysTryCatch(NID_UI_CTRL, (r == E_SUCCESS), , E_SYSTEM,
139 "[E_SYSTEM] A system error has occurred. Failed to create the display visual element for this control");
141 r = pPresenter->Construct(*pView);
142 SysTryCatch(NID_UI_CTRL, (r == E_SUCCESS), , E_SYSTEM,
143 "[E_SYSTEM] A system error has occurred. Failed to construct the presenter instance for this control");
145 pView->AcquireHandle();
147 pView->__pDateTimeChangeEvent = new (std::nothrow) _DateTimeChangeEvent(*pView);
148 SysTryCatch(NID_UI_CTRL, (pView->__pDateTimeChangeEvent != null), , E_OUT_OF_MEMORY,
149 "[E_OUT_OF_MEMORY] Memory allocation failed.");
151 if (pView->GetAccessibilityContainer() != null)
153 pView->GetAccessibilityContainer()->Activate(true);
156 r = SettingInfo::AddSettingEventListener(*pView);
157 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
169 _DateTimePicker::CreateFooter(void)
171 result r = E_SUCCESS;
172 _Button* pSaveButton = null;
173 _Button* pCancelButton = null;
174 FloatRectangle bounds;
176 _ControlOrientation orientation = GetOrientation();
178 _Toolbar* pFooter = _Toolbar::CreateToolbarN(false);
180 SysTryReturnResult(NID_UI_CTRL, (pFooter != null), r, "[%s] Propagating.", GetErrorMessage(r));
182 r = AttachSystemChild(*pFooter);
183 SysTryCatch(NID_UI_CTRL, (r == E_SUCCESS), , r, "[%s] Propagating.", GetErrorMessage(r));
185 GET_SHAPE_CONFIG(DATETIMEPICKER::FOOTER_HEIGHT, orientation, bounds.height);
186 GET_SHAPE_CONFIG(DATETIMEPICKER::INPUTPAD_HEIGHT, orientation, bounds.y);
189 bounds.y = GetBoundsF().height - bounds.y - bounds.height;
190 bounds.width = GetBoundsF().width;
192 pFooter->SetMovable(true);
193 pFooter->SetResizable(true);
195 r = pFooter->SetBounds(bounds);
196 SysTryCatch(NID_UI_CTRL, (r == E_SUCCESS), , r, "[%s] Propagating.", GetErrorMessage(r));
198 pFooter->SetMovable(false);
199 pFooter->SetResizable(false);
201 pFooter->AddActionEventListener(*this);
203 r = pFooter->SetStyle(TOOLBAR_TEXT);
204 SysTryCatch(NID_UI_CTRL, (r == E_SUCCESS), , r, "[%s] Propagating.", GetErrorMessage(r));
206 // Create 'Save' button
207 pSaveButton = _Button::CreateButtonN();
209 SysTryCatch(NID_UI_CTRL, (r == E_SUCCESS), , r, "[%s] Propagating.", GetErrorMessage(r));
211 r = pSaveButton->SetActionId(DATETIME_EVENT_ID_SAVE);
212 SysTryCatch(NID_UI_CTRL, (r == E_SUCCESS), , r, "[%s] Propagating.", GetErrorMessage(r));
214 GET_STRING_CONFIG(IDS_TPLATFORM_BUTTON_SAVE, text);
216 r = pSaveButton->SetText(text);
217 SysTryCatch(NID_UI_CTRL, (r == E_SUCCESS), , r, "[%s] Propagating.", GetErrorMessage(r));
219 // Create 'Cancel' button
220 pCancelButton = _Button::CreateButtonN();
222 SysTryCatch(NID_UI_CTRL, (r == E_SUCCESS), , r, "[%s] Propagating.", GetErrorMessage(r));
224 r = pCancelButton->SetActionId(DATETIME_EVENT_ID_CANCEL);
225 SysTryCatch(NID_UI_CTRL, (r == E_SUCCESS), , r, "[%s] Propagating.", GetErrorMessage(r));
227 GET_STRING_CONFIG(IDS_TPLATFORM_BUTTON_CANCEL_ABB, text);
229 r = pCancelButton->SetText(text);
230 SysTryCatch(NID_UI_CTRL, (r == E_SUCCESS), , r, "[%s] Propagating.", GetErrorMessage(r));
232 r = pFooter->AddItem(pCancelButton);
233 SysTryCatch(NID_UI_CTRL, (r == E_SUCCESS), , r, "[%s] Propagating.");
235 r = pFooter->AddItem(pSaveButton);
236 SysTryCatch(NID_UI_CTRL, (r == E_SUCCESS), , r, "[%s] Propagating.", GetErrorMessage(r));
238 if (__pFooter != null)
240 DetachSystemChild(*__pFooter);
250 DetachSystemChild(*pFooter);
254 delete pCancelButton;
260 _DateTimePicker::DestroyFooter(void)
262 if (__pFooter != null)
264 DetachSystemChild(*__pFooter);
274 _DateTimePicker::CreateDisplayVisualElement(void)
276 result r = E_SUCCESS;
278 __pDisplayVisualElement = new (std::nothrow) _VisualElement();
279 SysTryReturnResult(NID_UI_CTRL, __pDisplayVisualElement, E_OUT_OF_MEMORY, "Memory allocation failed.");
281 r = __pDisplayVisualElement->Construct();
282 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
284 __pDisplayVisualElement->SetShowState(true);
285 __pDisplayVisualElement->SetImplicitAnimationEnabled(false);
287 r = GetVisualElement()->AttachChild(*__pDisplayVisualElement);
288 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
293 __pDisplayVisualElement->Destroy();
294 __pDisplayVisualElement = null;
300 _DateTimePicker::SetDisplayVisualElementBounds(FloatRectangle bounds)
302 if (__pDisplayVisualElement != null)
304 __pDisplayVisualElement->SetBounds(FloatRectangle(bounds.x, bounds.y, bounds.width, bounds.height));
311 _DateTimePicker::GetDisplayVisualElement(void)
313 return __pDisplayVisualElement;
317 _DateTimePicker::AddDateTimeChangeEventListener(const Controls::_IDateTimeChangeEventListener& listener)
319 SysTryReturnResult(NID_UI_CTRL, (__pDateTimeChangeEvent != null), E_SYSTEM,
320 "A system error has occurred. The _DateTimeChangeEvent instance is null.");
322 result r = __pDateTimeChangeEvent->AddListener(listener);
323 SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Propagating.");
329 _DateTimePicker::RemoveDateTimeChangeEventListener(const Controls::_IDateTimeChangeEventListener& listener)
331 SysTryReturnResult(NID_UI_CTRL, (__pDateTimeChangeEvent != null), E_SYSTEM,
332 "A system error has occurred. The _DateTimeChangeEvent instance is null.");
334 result r = __pDateTimeChangeEvent->RemoveListener(listener);
335 SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Propagating.");
341 _DateTimePicker::FireDateTimeChangeEvent(_DateTimeChangeStatus status, DateTime& dateTime)
343 SysTryReturnResult(NID_UI_CTRL, (__pDateTimeChangeEvent != null), E_SYSTEM,
344 "A system error has occurred. The _DateTimeChangeEvent instance is null");
346 SysTryReturnResult(NID_UI_CTRL, (status >= DATE_INTERNAL_CHANGE_SAVED && status <= TIME_INTERNAL_CHANGE_CANCELED), E_INVALID_ARG,
347 "Invalid argument(s) is used. The status provided is not present in the _DateTimeChangeStatus list.");
349 _DateTimeChangeEventArg* pDateTimeEventArg = new (std::nothrow) _DateTimeChangeEventArg(status);
350 SysTryReturnResult(NID_UI_CTRL, (pDateTimeEventArg != null), E_OUT_OF_MEMORY, "Memory allocation failed.");
352 pDateTimeEventArg->SetDateTime(dateTime);
353 pDateTimeEventArg->SetDate(dateTime.GetYear(), dateTime.GetMonth(), dateTime.GetDay());
354 pDateTimeEventArg->SetTime(dateTime.GetHour(), dateTime.GetMinute());
355 __pDateTimeChangeEvent->Fire(*pDateTimeEventArg);
361 _DateTimePicker::SetPropertyYear(const Variant& year)
363 int yearValue = year.ToInt();
365 SysTryReturnResult(NID_UI_CTRL, (yearValue >= DATETIME_YEAR_MIN && yearValue <= DATETIME_YEAR_MAX), E_INVALID_ARG,
366 "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);
371 _DateTimeUtils dateTimeUtils;
373 maxValue = dateTimeUtils.CalculateMaxDay(yearValue, GetMonth());
374 day = __pPresenter->GetDay();
378 __pPresenter->SetDay(maxValue);
381 return __pPresenter->SetYear(yearValue);
385 _DateTimePicker::SetYear(int year)
387 return SetProperty("year", Variant(year));
391 _DateTimePicker::GetPropertyYear(void) const
395 year = __pPresenter->GetYear();
397 return Variant(year);
401 _DateTimePicker::GetYear(void) const
403 Variant year = GetProperty("year");
409 _DateTimePicker::SetPropertyMonth(const Variant& month)
411 int monthValue = month.ToInt();
413 SysTryReturnResult(NID_UI_CTRL, (monthValue >= DATETIME_MONTH_MIN && monthValue <= DATETIME_MONTH_MAX), E_INVALID_ARG,
414 "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);
419 _DateTimeUtils dateTimeUtils;
421 maxValue = dateTimeUtils.CalculateMaxDay(GetYear(), monthValue);
422 day = __pPresenter->GetDay();
426 __pPresenter->SetDay(maxValue);
429 return __pPresenter->SetMonth(monthValue);
433 _DateTimePicker::SetMonth(int month)
435 return SetProperty("month", Variant(month));
439 _DateTimePicker::GetPropertyMonth(void) const
443 month = __pPresenter->GetMonth();
445 return Variant(month);
449 _DateTimePicker::GetMonth(void) const
451 Variant month = GetProperty("month");
453 return month.ToInt();
457 _DateTimePicker::SetPropertyDay(const Variant& day)
459 int dayValue = day.ToInt();
461 SysTryReturnResult(NID_UI_CTRL, (dayValue >= DATETIME_DAY_MIN && dayValue <= DATETIME_DAY_MAX), E_INVALID_ARG,
462 "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 _DateTimeUtils dateTimeUtils;
466 maxValue = dateTimeUtils.CalculateMaxDay(GetYear(), GetMonth());
468 SysTryReturn(NID_UI_CTRL, (dayValue <= maxValue), E_INVALID_ARG, E_INVALID_ARG,
469 "[E_INVALID_ARG] Invalid argument is used. day (%d), month (%d)", dayValue, GetMonth());
471 return __pPresenter->SetDay(dayValue);
475 _DateTimePicker::SetDay(int day)
477 return SetProperty("day", Variant(day));
481 _DateTimePicker::GetPropertyDay(void) const
485 day = __pPresenter->GetDay();
491 _DateTimePicker::GetDay(void) const
493 Variant day = GetProperty("day");
499 _DateTimePicker::SetPropertyHour(const Variant& hour)
501 int hourValue = hour.ToInt();
503 SysTryReturnResult(NID_UI_CTRL, (hourValue >= DATETIME_HOUR_MIN && hourValue <= DATETIME_HOUR_MAX), E_INVALID_ARG,
504 "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);
506 return __pPresenter->SetHour(hourValue);
511 _DateTimePicker::SetHour(int hour)
513 return SetProperty("hour", Variant(hour));
517 _DateTimePicker::GetPropertyHour(void) const
521 hour = __pPresenter->GetHour();
523 return Variant(hour);
527 _DateTimePicker::GetHour(void) const
529 Variant hour = GetProperty("hour");
535 _DateTimePicker::SetPropertyMinute(const Variant& minute)
537 int minuteValue = minute.ToInt();
539 SysTryReturnResult(NID_UI_CTRL, (minuteValue >= DATETIME_MINUTE_MIN && minuteValue <= DATETIME_MINUTE_MAX), E_INVALID_ARG,
540 "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);
542 return __pPresenter->SetMinute(minuteValue);
547 _DateTimePicker::SetMinute(int minute)
549 return SetProperty("minute", Variant(minute));
553 _DateTimePicker::GetPropertyMinute(void) const
557 minute = __pPresenter->GetMinute();
559 return Variant(minute);
563 _DateTimePicker::GetMinute(void) const
565 Variant minute = GetProperty("minute");
567 return minute.ToInt();
571 _DateTimePicker::SetProperty24HourNotation(const Variant& enable)
573 bool enableValue = enable.ToBool();
575 __pPresenter->Set24HourNotationEnabled(enableValue);
581 _DateTimePicker::Set24HourNotationEnabled(bool enable)
583 SetProperty("24hourNotation", Variant(enable));
589 _DateTimePicker::GetProperty24HourNotation(void) const
591 bool is24HourNotation = false;
593 is24HourNotation = __pPresenter->Is24HourNotationEnabled();
595 return Variant(is24HourNotation);
599 _DateTimePicker::Is24HourNotationEnabled(void) const
601 Variant enable = GetProperty("24hourNotation");
603 return enable.ToBool();
607 _DateTimePicker::SetPropertyMinYearRange(const Variant& minYear)
609 int minYearValue = minYear.ToInt();
610 int currentMinYear = DATETIME_YEAR_MIN;
611 int currentMaxYear = DATETIME_YEAR_MAX;
613 SysTryReturnResult(NID_UI_CTRL, (minYearValue >= DATETIME_YEAR_MIN && minYearValue <= DATETIME_YEAR_MAX), E_INVALID_ARG,
614 "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);
616 __pPresenter->GetYearRange(currentMinYear, currentMaxYear);
618 SysTryReturnResult(NID_UI_CTRL, (currentMaxYear >= minYearValue), E_INVALID_ARG,
619 "Invalid argument(s) is used. The year (%d) must be less than or equal to (%d).", minYearValue, currentMaxYear);
621 return __pPresenter->SetYearRange(minYearValue, currentMaxYear);
625 _DateTimePicker::GetPropertyMinYearRange(void) const
627 int currentMinYear = DATETIME_YEAR_MIN;
628 int currentMaxYear = DATETIME_YEAR_MAX;
630 __pPresenter->GetYearRange(currentMinYear, currentMaxYear);
632 return Variant(currentMinYear);
636 _DateTimePicker::SetPropertyMaxYearRange(const Variant& maxYear)
638 int maxYearValue = maxYear.ToInt();
639 int currentMinYear = DATETIME_YEAR_MIN;
640 int currentMaxYear = DATETIME_YEAR_MAX;
642 SysTryReturnResult(NID_UI_CTRL, (maxYearValue >= DATETIME_YEAR_MIN && maxYearValue <= DATETIME_YEAR_MAX), E_INVALID_ARG,
643 "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);
645 __pPresenter->GetYearRange(currentMinYear, currentMaxYear);
647 SysTryReturnResult(NID_UI_CTRL, (maxYearValue >= currentMinYear), E_INVALID_ARG,
648 "Invalid argument(s) is used. The year (%d) must be greater than or equal to (%d).", maxYearValue, currentMinYear);
650 return __pPresenter->SetYearRange(currentMinYear, maxYearValue);
654 _DateTimePicker::GetPropertyMaxYearRange(void) const
656 int currentMinYear = DATETIME_YEAR_MIN;
657 int currentMaxYear = DATETIME_YEAR_MAX;
659 __pPresenter->GetYearRange(currentMinYear, currentMaxYear);
661 return Variant(currentMaxYear);
665 _DateTimePicker::SetYearRange(int minYear, int maxYear)
667 result r = E_SUCCESS;
669 SysTryReturnResult(NID_UI_CTRL, (minYear >= DATETIME_YEAR_MIN && minYear <= DATETIME_YEAR_MAX), E_INVALID_ARG,
670 "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);
671 SysTryReturnResult(NID_UI_CTRL, (maxYear >= DATETIME_YEAR_MIN && maxYear <= DATETIME_YEAR_MAX), E_INVALID_ARG,
672 "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);
673 SysTryReturnResult(NID_UI_CTRL, (maxYear >= minYear), E_INVALID_ARG,
674 "Invalid argument(s) is used. The maxYear (%d) must be greater than or equal to minYear (%d).", maxYear, minYear);
676 r = SetProperty("minYearRange", Variant(minYear));
682 r = SetProperty("maxYearRange", Variant(maxYear));
688 _DateTimePicker::GetYearRange(int& minYear, int& maxYear) const
690 Variant currentMinYear = GetProperty("minYearRange");
691 Variant currentMaxYear = GetProperty("maxYearRange");
693 minYear = currentMinYear.ToInt();
694 maxYear = currentMaxYear.ToInt();
700 _DateTimePicker::SetPropertyDateTime(const Variant& varDateTime)
702 DateTime dateTime = varDateTime.ToDateTime();
704 SysTryReturnResult(NID_UI_CTRL, (dateTime.GetYear() >= DATETIME_YEAR_MIN && dateTime.GetYear() <= DATETIME_YEAR_MAX), E_INVALID_ARG,
705 "[E_INVALID_ARG] Invalid argument is used. year (%d).", dateTime.GetYear());
710 GetYearRange(minYear, maxYear);
714 if (dateTime.GetYear() < minYear)
716 date.SetValue(minYear, dateTime.GetMonth(), dateTime.GetDay(), dateTime.GetHour(), dateTime.GetMinute(), dateTime.GetSecond());
718 else if (dateTime.GetYear() > maxYear)
720 date.SetValue(maxYear, dateTime.GetMonth(), dateTime.GetDay(), dateTime.GetHour(), dateTime.GetMinute(), dateTime.GetSecond());
724 date.SetValue(dateTime);
727 __pPresenter->SetDateTime(date);
733 _DateTimePicker::SetDateTime(const DateTime& dateTime)
735 SetProperty("dateTime", Variant(dateTime));
741 _DateTimePicker::GetPropertyDateTime(void) const
743 DateTime dateTime = DateTime();
745 dateTime = __pPresenter->GetDateTime();
747 return Variant(dateTime);
751 _DateTimePicker::GetDateTime(void) const
753 Variant dateTime = GetProperty("dateTime");
755 return dateTime.ToDateTime();
759 _DateTimePicker::SetCurrentDateTime(void)
761 __pPresenter->SetCurrentDateTime();
767 _DateTimePicker::SetFocusBoxId(int boxId)
769 __pPresenter->SetFocusBoxId(boxId);
775 _DateTimePicker::SetAccessibilityElementText(int index, const String& text, bool isAmPm)
777 _AccessibilityElement* pElement = null;
779 if (__accessibilityElements.GetAt(index, pElement) == E_SUCCESS)
781 result r = GetLastResult();
782 SysTryReturnVoidResult(NID_UI_CTRL, (pElement != null), r, "[%s] Propagating.", GetErrorMessage(r));
784 pElement->SetLabel(text);
791 _DateTimeUtils dateTimeUtils;
792 dateTimeUtils.GetAmPm(amText, AM_TYPE);
793 dateTimeUtils.GetAmPm(pmText, PM_TYPE);
795 pElement->SetHintWithStringId("IDS_TPLATFORM_BODY_DOUBLE_TAP_TO_CHANGE_T_TTS");
799 SetLastResult(E_SUCCESS);
805 _DateTimePicker::OnTouchPressed(const _Control& source, const _TouchInfo& touchinfo)
807 return __pPresenter->OnTouchPressed(source, touchinfo);
811 _DateTimePicker::OnTouchMoved(const _Control& source, const _TouchInfo& touchinfo)
813 return __pPresenter->OnTouchMoved(source, touchinfo);
817 _DateTimePicker::OnTouchReleased(const _Control& source, const _TouchInfo& touchinfo)
819 return __pPresenter->OnTouchReleased(source, touchinfo);
823 _DateTimePicker::OnTouchCanceled(const _Control& source, const _TouchInfo& touchinfo)
825 return __pPresenter->OnTouchCanceled(source, touchinfo);
829 _DateTimePicker::OnAttachedToMainTree(void)
831 return CreateAllAccessibilityElements();
835 _DateTimePicker::OnDetachingFromMainTree(void)
837 RemoveAllAccessibilityElements();
839 return _Window::OnDetachingFromMainTree();
843 _DateTimePicker::OnChangeLayout(_ControlOrientation orientation)
845 result r = E_SUCCESS;
846 FloatDimension pickerSize(0.0f, 0.0f);
847 FloatDimension screenSize(0.0f, 0.0f);
849 screenSize = _ControlManager::GetInstance()->GetScreenSizeF();
850 pickerSize = screenSize;
851 if (orientation == _CONTROL_ORIENTATION_LANDSCAPE)
853 pickerSize.width = screenSize.height;
854 pickerSize.height = screenSize.width;
866 SysTryReturnVoidResult(NID_UI_CTRL, (r == E_SUCCESS), E_SYSTEM,
867 "[E_SYSTEM] A system error has occurred. Failed to destroy the footer for this control.");
870 SysTryReturnVoidResult(NID_UI_CTRL, (r == E_SUCCESS), E_SYSTEM,
871 "[E_SYSTEM] A system error has occurred. Failed to create the footer for this control.");
873 __pPresenter->OnChangeLayout(orientation);
875 const _DateTimeDisplayBox* pBox = null;
876 IEnumeratorT<_AccessibilityElement*>* pEnumerator = __accessibilityElements.GetEnumeratorN();
877 SysTryReturnVoidResult(NID_UI_CTRL, (pEnumerator != null), GetLastResult(),
878 "[%s] Propagating.", GetErrorMessage(GetLastResult()));
880 _AccessibilityElement* pElement = null;
882 while (pEnumerator->MoveNext() == E_SUCCESS)
884 if (pEnumerator->GetCurrent(pElement) == E_SUCCESS)
886 pBox = __pPresenter->GetDisplayBox(index);
889 FloatRectangle displayBoxBounds = pBox->GetDisplayBoxBounds();
891 if (__pDisplayVisualElement != null)
893 displayBoxBounds.y += __pDisplayVisualElement->GetBounds().y;
896 pElement->SetBounds(displayBoxBounds);
907 _DateTimePicker::OnDraw(void)
909 __pPresenter->Draw();
915 _DateTimePicker::OnActionPerformed(const _Control& source, int actionId)
917 __pPresenter->OnActionPerformed(source, actionId);
923 _DateTimePicker::OnAccessibilityActionPerformed(const _AccessibilityContainer& control, const _AccessibilityElement& element)
925 String amString = L"";
926 String pmString = L"";
929 label = element.GetLabel();
931 _DateTimeUtils dateTimeUtils;
932 dateTimeUtils.GetAmPm(amString, AM_TYPE);
933 dateTimeUtils.GetAmPm(pmString, PM_TYPE);
935 if (label == amString || label == pmString)
937 label.Append(L" Selected");
938 _AccessibilityManager::GetInstance()->ReadContent(label);
945 _DateTimePicker::OnFontChanged(Font* pFont)
947 result r = E_SUCCESS;
951 if (__pPresenter != null)
953 r = __pPresenter->SetFont(pFont);
954 SysTryReturnVoidResult(NID_UI_CTRL, (r == E_SUCCESS), r, "[%s] Propagating.");
957 if (__pFooter != null)
959 for (int i=0; i < __pFooter->GetItemCount(); i++)
961 _Button* pButton = __pFooter->GetItem(i);
965 r = pButton->SetFont(pFont->GetFaceName());
966 SysTryReturnVoidResult(NID_UI_CTRL, (r == E_SUCCESS), r, "[%s] Propagating.", GetErrorMessage(r));
978 _DateTimePicker::OnFontInfoRequested(unsigned long& style, float& size)
980 style = FONT_STYLE_PLAIN;
982 GET_SHAPE_CONFIG(DATETIMEPICKER::FONT_SIZE, GetOrientation(), size);
988 _DateTimePicker::OnKeyPressed(const _Control& source, const _KeyInfo& keyInfo)
990 if (&source != this && &source != __pFooter)
995 return __pPresenter->OnKeyPressed(source, keyInfo);
999 _DateTimePicker::OnKeyReleased(const _Control& source, const _KeyInfo& keyInfo)
1001 if (&source != this && &source != __pFooter)
1006 return __pPresenter->OnKeyReleased(source, keyInfo);
1010 _DateTimePicker::OnDrawFocus(void)
1012 __pPresenter->DrawFocus();
1013 __isInFocusMode = true;
1018 _DateTimePicker::OnFocusGained(const _Control& source)
1020 return _Control::OnFocusGained(source);
1024 _DateTimePicker::OnFocusLost(const _Control& source)
1026 result r = __pPresenter->ReleaseFocus();
1027 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, false, r, "[%s] Propagating.", GetErrorMessage(r));
1029 _Control::OnFocusLost(source);
1030 __isInFocusMode = false;
1035 _DateTimePicker::OnFocusModeStateChanged(void)
1037 if (__isInFocusMode)
1039 __pPresenter->ReleaseFocus();
1040 __isInFocusMode = false;
1047 _DateTimePicker::OnSettingChanged(Tizen::Base::String& key)
1049 if (key.Equals(L"http://tizen.org/setting/locale.date.format", false)
1050 || key.Equals(L"http://tizen.org/setting/locale.time.format.24hour", false))
1052 __pPresenter->UpdateLocaleDateTimeFormat();
1054 RemoveAllAccessibilityElements();
1055 CreateAllAccessibilityElements();
1062 _DateTimePicker::GetDateTimeFont(void)
1068 _DateTimePicker::InitializeFont(void)
1070 result r = E_SUCCESS;
1072 __pFont = GetFallbackFont();
1073 r = GetLastResult();
1074 SysTryReturnResult(NID_UI_CTRL, (__pFont != null), r, "[%s] Propagating.", GetErrorMessage(r));
1080 _DateTimePicker::CreateAllAccessibilityElements(void)
1082 _AccessibilityContainer* pContainer = GetAccessibilityContainer();
1083 if (pContainer != null)
1085 float dateTimeDisplayBoxHeight = 0.0f;
1086 float amPmDisplayBoxHeight = 0.0f;
1087 float topMargin = 0.0f;
1088 float leftMargin = 0.0f;
1089 const _DateTimeDisplayBox* pBox = null;
1090 const _DateTimeDisplayBox* pAmPmBox = null;
1092 GET_SHAPE_CONFIG(DATETIMEPICKER::LEFT_MARGIN, GetOrientation(), leftMargin);
1094 pContainer->AddListener(*this);
1097 for (int index = 0; index < DATETIME_ID_MAX; index++)
1099 pBox = __pPresenter->GetDisplayBox(index);
1102 _AccessibilityElement* pElement = new (std::nothrow) _AccessibilityElement(true);
1103 SysTryReturnResult(NID_UI_CTRL, (pElement != null), E_OUT_OF_MEMORY, "Memory allocation failed.");
1105 FloatRectangle displayBoxBounds = pBox->GetDisplayBoxBounds();
1106 int displayBoxId = pBox->GetDisplayBoxId();
1108 String hintText(L"Double tap to edit");
1110 switch (displayBoxId)
1112 case DATETIME_ID_DAY:
1113 pElement->SetTraitWithStringId("IDS_TPLATFORM_BODY_DAY_LC");
1114 pElement->SetHint(hintText);
1116 case DATETIME_ID_MONTH:
1117 pElement->SetTraitWithStringId("IDS_TPLATFORM_BODY_MONTH_LC");
1118 pElement->SetHint(hintText);
1120 case DATETIME_ID_YEAR:
1121 pElement->SetTraitWithStringId("IDS_TPLATFORM_BODY_YEAR_LC");
1122 pElement->SetHint(hintText);
1124 case DATETIME_ID_HOUR:
1125 pElement->SetTraitWithStringId("IDS_TPLATFORM_BODY_HOUR_LC");
1126 pElement->SetHint(hintText);
1128 case DATETIME_ID_MINUTE:
1129 pElement->SetTraitWithStringId("IDS_TPLATFORM_BODY_MINUTE_LC");
1130 pElement->SetHint(hintText);
1134 GET_SHAPE_CONFIG(DATETIMEPICKER::DATETIME_DISPLAY_BOX_HEIGHT, GetOrientation(), dateTimeDisplayBoxHeight);
1135 GET_SHAPE_CONFIG(DATETIMEPICKER::AMPM_DISPLAY_BOX_HEIGHT, GetOrientation(), amPmDisplayBoxHeight);
1136 topMargin = (amPmDisplayBoxHeight - dateTimeDisplayBoxHeight) / 2.0f;
1138 displayBoxBounds.x += leftMargin;
1139 displayBoxBounds.y -= topMargin;
1140 displayBoxBounds.height += 2 * topMargin;
1142 if (__pDisplayVisualElement != null)
1144 displayBoxBounds.y += __pDisplayVisualElement->GetBounds().y;
1147 pElement->SetLabel(pBox->GetText());
1148 pElement->SetBounds(displayBoxBounds);
1149 pContainer->AddElement(*pElement);
1153 pAmPmBox = __pPresenter->GetAmPmBox();
1154 if (pAmPmBox != null)
1156 _AccessibilityElement* pElement = new (std::nothrow) _AccessibilityElement(true);
1157 SysTryReturnResult(NID_UI_CTRL, (pElement != null), E_OUT_OF_MEMORY, "Memory allocation failed.");
1159 FloatRectangle amPmBoxBounds = pAmPmBox->GetDisplayBoxBounds();
1161 amPmBoxBounds.x += leftMargin;
1163 if (__pDisplayVisualElement != null)
1165 amPmBoxBounds.y += __pDisplayVisualElement->GetBounds().y;
1168 pElement->SetLabel(pAmPmBox->GetText());
1169 pElement->SetBounds(amPmBoxBounds);
1170 pElement->SetTraitWithStringId("IDS_TPLATFORM_BODY_BUTTON_T_TTS");
1171 pElement->SetHintWithStringId("IDS_TPLATFORM_BODY_DOUBLE_TAP_TO_CHANGE_T_TTS");
1172 pContainer->AddElement(*pElement);
1175 pContainer->GetElements(__accessibilityElements);
1176 _AccessibilityManager::GetInstance()->RequestAutoReading(_ACCESSIBILITY_AUTO_READING_MODE_FIRST_ITEM);
1184 _DateTimePicker::RemoveAllAccessibilityElements(void)
1186 _AccessibilityContainer* pContainer = GetAccessibilityContainer();
1187 SysTryReturnVoidResult(NID_UI_CTRL, (pContainer != null), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1189 _AccessibilityElement* pAccessibilityElement = null;
1191 pContainer->RemoveListener(*this);
1193 while (__accessibilityElements.GetCount() > 0)
1195 if ((__accessibilityElements.GetAt(0, pAccessibilityElement)) == E_SUCCESS)
1197 __accessibilityElements.RemoveAt(0);
1198 pContainer->RemoveElement(*pAccessibilityElement);
1202 __accessibilityElements.RemoveAt(0);
1207 }}} // Tizen::Ui::Controls