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)
70 _DateTimePicker::~_DateTimePicker(void)
72 SettingInfo::RemoveSettingEventListener(*this);
74 if (__pDateTimeChangeEvent != null)
76 delete __pDateTimeChangeEvent;
77 __pDateTimeChangeEvent = null;
80 if (__pFooter != null)
82 DetachSystemChild(*__pFooter);
87 if (__pDisplayVisualElement != null)
89 __pDisplayVisualElement->Destroy();
90 __pDisplayVisualElement = null;
98 _DateTimePicker::CreateDateTimePickerN(int style, const String& title)
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;
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.");
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.");
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.");
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.");
119 r = pView->CreateRootVisualElement();
120 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
122 orientation = pView->GetOrientation();
123 screenSize = _ControlManager::GetInstance()->GetScreenSizeF();
124 pickerSize = screenSize;
125 if (orientation == _CONTROL_ORIENTATION_LANDSCAPE)
127 pickerSize.width = screenSize.height;
128 pickerSize.height = screenSize.width;
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");
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");
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");
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");
147 pView->AcquireHandle();
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.");
153 if (pView->GetAccessibilityContainer() != null)
155 pView->GetAccessibilityContainer()->Activate(true);
158 r = SettingInfo::AddSettingEventListener(*pView);
159 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
171 _DateTimePicker::CreateFooter(void)
173 result r = E_SUCCESS;
174 _Button* pSaveButton = null;
175 _Button* pCancelButton = null;
176 FloatRectangle bounds;
178 _ControlOrientation orientation = GetOrientation();
180 _Toolbar* pFooter = _Toolbar::CreateToolbarN(false);
182 SysTryReturnResult(NID_UI_CTRL, (pFooter != null), r, "[%s] Propagating.", GetErrorMessage(r));
184 r = AttachSystemChild(*pFooter);
185 SysTryCatch(NID_UI_CTRL, (r == E_SUCCESS), , r, "[%s] Propagating.", GetErrorMessage(r));
187 GET_SHAPE_CONFIG(DATETIMEPICKER::FOOTER_HEIGHT, orientation, bounds.height);
188 GET_SHAPE_CONFIG(DATETIMEPICKER::INPUTPAD_HEIGHT, orientation, bounds.y);
191 bounds.y = GetBoundsF().height - bounds.y - bounds.height;
192 bounds.width = GetBoundsF().width;
194 pFooter->SetMovable(true);
195 pFooter->SetResizable(true);
197 r = pFooter->SetBounds(bounds);
198 SysTryCatch(NID_UI_CTRL, (r == E_SUCCESS), , r, "[%s] Propagating.", GetErrorMessage(r));
200 pFooter->SetMovable(false);
201 pFooter->SetResizable(false);
203 pFooter->AddActionEventListener(*this);
205 r = pFooter->SetStyle(TOOLBAR_TEXT);
206 SysTryCatch(NID_UI_CTRL, (r == E_SUCCESS), , r, "[%s] Propagating.", GetErrorMessage(r));
208 // Create 'Save' button
209 pSaveButton = _Button::CreateButtonN();
211 SysTryCatch(NID_UI_CTRL, (r == E_SUCCESS), , r, "[%s] Propagating.", GetErrorMessage(r));
213 r = pSaveButton->SetActionId(DATETIME_EVENT_ID_SAVE);
214 SysTryCatch(NID_UI_CTRL, (r == E_SUCCESS), , r, "[%s] Propagating.", GetErrorMessage(r));
216 GET_STRING_CONFIG(IDS_TPLATFORM_BUTTON_SAVE, text);
218 r = pSaveButton->SetText(text);
219 SysTryCatch(NID_UI_CTRL, (r == E_SUCCESS), , r, "[%s] Propagating.", GetErrorMessage(r));
221 // Create 'Cancel' button
222 pCancelButton = _Button::CreateButtonN();
224 SysTryCatch(NID_UI_CTRL, (r == E_SUCCESS), , r, "[%s] Propagating.", GetErrorMessage(r));
226 r = pCancelButton->SetActionId(DATETIME_EVENT_ID_CANCEL);
227 SysTryCatch(NID_UI_CTRL, (r == E_SUCCESS), , r, "[%s] Propagating.", GetErrorMessage(r));
229 GET_STRING_CONFIG(IDS_TPLATFORM_BUTTON_CANCEL_ABB, text);
231 r = pCancelButton->SetText(text);
232 SysTryCatch(NID_UI_CTRL, (r == E_SUCCESS), , r, "[%s] Propagating.", GetErrorMessage(r));
234 r = pFooter->AddItem(pSaveButton);
235 SysTryCatch(NID_UI_CTRL, (r == E_SUCCESS), , r, "[%s] Propagating.", GetErrorMessage(r));
237 r = pFooter->AddItem(pCancelButton);
238 SysTryCatch(NID_UI_CTRL, (r == E_SUCCESS), , r, "[%s] Propagating.");
240 if (__pFooter != null)
242 DetachSystemChild(*__pFooter);
252 DetachSystemChild(*pFooter);
256 delete pCancelButton;
262 _DateTimePicker::DestroyFooter(void)
264 if (__pFooter != null)
266 DetachSystemChild(*__pFooter);
276 _DateTimePicker::CreateDisplayVisualElement(void)
278 result r = E_SUCCESS;
280 __pDisplayVisualElement = new (std::nothrow) _VisualElement();
281 SysTryReturnResult(NID_UI_CTRL, __pDisplayVisualElement, E_OUT_OF_MEMORY, "Memory allocation failed.");
283 r = __pDisplayVisualElement->Construct();
284 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
286 __pDisplayVisualElement->SetShowState(true);
287 __pDisplayVisualElement->SetImplicitAnimationEnabled(false);
289 r = GetVisualElement()->AttachChild(*__pDisplayVisualElement);
290 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
295 __pDisplayVisualElement->Destroy();
296 __pDisplayVisualElement = null;
302 _DateTimePicker::SetDisplayVisualElementBounds(FloatRectangle bounds)
304 if (__pDisplayVisualElement != null)
306 __pDisplayVisualElement->SetBounds(FloatRectangle(bounds.x, bounds.y, bounds.width, bounds.height));
313 _DateTimePicker::GetDisplayVisualElement(void)
315 return __pDisplayVisualElement;
319 _DateTimePicker::AddDateTimeChangeEventListener(const Controls::_IDateTimeChangeEventListener& listener)
321 SysTryReturnResult(NID_UI_CTRL, (__pDateTimeChangeEvent != null), E_SYSTEM,
322 "A system error has occurred. The _DateTimeChangeEvent instance is null.");
324 result r = __pDateTimeChangeEvent->AddListener(listener);
325 SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Propagating.");
331 _DateTimePicker::RemoveDateTimeChangeEventListener(const Controls::_IDateTimeChangeEventListener& listener)
333 SysTryReturnResult(NID_UI_CTRL, (__pDateTimeChangeEvent != null), E_SYSTEM,
334 "A system error has occurred. The _DateTimeChangeEvent instance is null.");
336 result r = __pDateTimeChangeEvent->RemoveListener(listener);
337 SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Propagating.");
343 _DateTimePicker::FireDateTimeChangeEvent(_DateTimeChangeStatus status, DateTime& dateTime)
345 SysTryReturnResult(NID_UI_CTRL, (__pDateTimeChangeEvent != null), E_SYSTEM,
346 "A system error has occurred. The _DateTimeChangeEvent instance is null");
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.");
351 _DateTimeChangeEventArg* pDateTimeEventArg = new (std::nothrow) _DateTimeChangeEventArg(status);
352 SysTryReturnResult(NID_UI_CTRL, (pDateTimeEventArg != null), E_OUT_OF_MEMORY, "Memory allocation failed.");
354 pDateTimeEventArg->SetDateTime(dateTime);
355 pDateTimeEventArg->SetDate(dateTime.GetYear(), dateTime.GetMonth(), dateTime.GetDay());
356 pDateTimeEventArg->SetTime(dateTime.GetHour(), dateTime.GetMinute());
357 __pDateTimeChangeEvent->Fire(*pDateTimeEventArg);
363 _DateTimePicker::SetPropertyYear(const Variant& year)
365 int yearValue = year.ToInt();
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);
373 _DateTimeUtils dateTimeUtils;
375 maxValue = dateTimeUtils.CalculateMaxDay(yearValue, GetMonth());
376 day = __pPresenter->GetDay();
380 __pPresenter->SetDay(maxValue);
383 return __pPresenter->SetYear(yearValue);
387 _DateTimePicker::SetYear(int year)
389 return SetProperty("year", Variant(year));
393 _DateTimePicker::GetPropertyYear(void) const
397 year = __pPresenter->GetYear();
399 return Variant(year);
403 _DateTimePicker::GetYear(void) const
405 Variant year = GetProperty("year");
411 _DateTimePicker::SetPropertyMonth(const Variant& month)
413 int monthValue = month.ToInt();
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);
421 _DateTimeUtils dateTimeUtils;
423 maxValue = dateTimeUtils.CalculateMaxDay(GetYear(), monthValue);
424 day = __pPresenter->GetDay();
428 __pPresenter->SetDay(maxValue);
431 return __pPresenter->SetMonth(monthValue);
435 _DateTimePicker::SetMonth(int month)
437 return SetProperty("month", Variant(month));
441 _DateTimePicker::GetPropertyMonth(void) const
445 month = __pPresenter->GetMonth();
447 return Variant(month);
451 _DateTimePicker::GetMonth(void) const
453 Variant month = GetProperty("month");
455 return month.ToInt();
459 _DateTimePicker::SetPropertyDay(const Variant& day)
461 int dayValue = day.ToInt();
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);
467 _DateTimeUtils dateTimeUtils;
468 maxValue = dateTimeUtils.CalculateMaxDay(GetYear(), GetMonth());
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());
473 return __pPresenter->SetDay(dayValue);
477 _DateTimePicker::SetDay(int day)
479 return SetProperty("day", Variant(day));
483 _DateTimePicker::GetPropertyDay(void) const
487 day = __pPresenter->GetDay();
493 _DateTimePicker::GetDay(void) const
495 Variant day = GetProperty("day");
501 _DateTimePicker::SetPropertyHour(const Variant& hour)
503 int hourValue = hour.ToInt();
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);
508 return __pPresenter->SetHour(hourValue);
513 _DateTimePicker::SetHour(int hour)
515 return SetProperty("hour", Variant(hour));
519 _DateTimePicker::GetPropertyHour(void) const
523 hour = __pPresenter->GetHour();
525 return Variant(hour);
529 _DateTimePicker::GetHour(void) const
531 Variant hour = GetProperty("hour");
537 _DateTimePicker::SetPropertyMinute(const Variant& minute)
539 int minuteValue = minute.ToInt();
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);
544 return __pPresenter->SetMinute(minuteValue);
549 _DateTimePicker::SetMinute(int minute)
551 return SetProperty("minute", Variant(minute));
555 _DateTimePicker::GetPropertyMinute(void) const
559 minute = __pPresenter->GetMinute();
561 return Variant(minute);
565 _DateTimePicker::GetMinute(void) const
567 Variant minute = GetProperty("minute");
569 return minute.ToInt();
573 _DateTimePicker::SetProperty24HourNotation(const Variant& enable)
575 bool enableValue = enable.ToBool();
577 __pPresenter->Set24HourNotationEnabled(enableValue);
583 _DateTimePicker::Set24HourNotationEnabled(bool enable)
585 SetProperty("24hourNotation", Variant(enable));
591 _DateTimePicker::GetProperty24HourNotation(void) const
593 bool is24HourNotation = false;
595 is24HourNotation = __pPresenter->Is24HourNotationEnabled();
597 return Variant(is24HourNotation);
601 _DateTimePicker::Is24HourNotationEnabled(void) const
603 Variant enable = GetProperty("24hourNotation");
605 return enable.ToBool();
609 _DateTimePicker::SetPropertyMinYearRange(const Variant& minYear)
611 int minYearValue = minYear.ToInt();
612 int currentMinYear = DATETIME_YEAR_MIN;
613 int currentMaxYear = DATETIME_YEAR_MAX;
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);
618 __pPresenter->GetYearRange(currentMinYear, currentMaxYear);
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);
623 return __pPresenter->SetYearRange(minYearValue, currentMaxYear);
627 _DateTimePicker::GetPropertyMinYearRange(void) const
629 int currentMinYear = DATETIME_YEAR_MIN;
630 int currentMaxYear = DATETIME_YEAR_MAX;
632 __pPresenter->GetYearRange(currentMinYear, currentMaxYear);
634 return Variant(currentMinYear);
638 _DateTimePicker::SetPropertyMaxYearRange(const Variant& maxYear)
640 int maxYearValue = maxYear.ToInt();
641 int currentMinYear = DATETIME_YEAR_MIN;
642 int currentMaxYear = DATETIME_YEAR_MAX;
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);
647 __pPresenter->GetYearRange(currentMinYear, currentMaxYear);
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);
652 return __pPresenter->SetYearRange(currentMinYear, maxYearValue);
656 _DateTimePicker::GetPropertyMaxYearRange(void) const
658 int currentMinYear = DATETIME_YEAR_MIN;
659 int currentMaxYear = DATETIME_YEAR_MAX;
661 __pPresenter->GetYearRange(currentMinYear, currentMaxYear);
663 return Variant(currentMaxYear);
667 _DateTimePicker::SetYearRange(int minYear, int maxYear)
669 result r = E_SUCCESS;
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);
678 r = SetProperty("minYearRange", Variant(minYear));
684 r = SetProperty("maxYearRange", Variant(maxYear));
690 _DateTimePicker::GetYearRange(int& minYear, int& maxYear) const
692 Variant currentMinYear = GetProperty("minYearRange");
693 Variant currentMaxYear = GetProperty("maxYearRange");
695 minYear = currentMinYear.ToInt();
696 maxYear = currentMaxYear.ToInt();
702 _DateTimePicker::SetPropertyDateTime(const Variant& varDateTime)
704 DateTime dateTime = varDateTime.ToDateTime();
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());
712 GetYearRange(minYear, maxYear);
716 if (dateTime.GetYear() < minYear)
718 date.SetValue(minYear, dateTime.GetMonth(), dateTime.GetDay(), dateTime.GetHour(), dateTime.GetMinute(), dateTime.GetSecond());
720 else if (dateTime.GetYear() > maxYear)
722 date.SetValue(maxYear, dateTime.GetMonth(), dateTime.GetDay(), dateTime.GetHour(), dateTime.GetMinute(), dateTime.GetSecond());
726 date.SetValue(dateTime);
729 __pPresenter->SetDateTime(date);
735 _DateTimePicker::SetDateTime(const DateTime& dateTime)
737 SetProperty("dateTime", Variant(dateTime));
743 _DateTimePicker::GetPropertyDateTime(void) const
745 DateTime dateTime = DateTime();
747 dateTime = __pPresenter->GetDateTime();
749 return Variant(dateTime);
753 _DateTimePicker::GetDateTime(void) const
755 Variant dateTime = GetProperty("dateTime");
757 return dateTime.ToDateTime();
761 _DateTimePicker::SetCurrentDateTime(void)
763 __pPresenter->SetCurrentDateTime();
769 _DateTimePicker::SetFocusBoxId(int boxId)
771 __pPresenter->SetFocusBoxId(boxId);
777 _DateTimePicker::SetAccessibilityElementText(int index, const String& text, bool isAmPm)
779 _AccessibilityElement* pElement = null;
781 if (__accessibilityElements.GetAt(index, pElement) == E_SUCCESS)
783 result r = GetLastResult();
784 SysTryReturnVoidResult(NID_UI_CTRL, (pElement != null), r, "[%s] Propagating.", GetErrorMessage(r));
786 pElement->SetLabel(text);
793 _DateTimeUtils dateTimeUtils;
794 dateTimeUtils.GetAmPm(amText, AM_TYPE);
795 dateTimeUtils.GetAmPm(pmText, PM_TYPE);
797 pElement->SetHintWithStringId("IDS_TPLATFORM_BODY_DOUBLE_TAP_TO_CHANGE_T_TTS");
801 SetLastResult(E_SUCCESS);
807 _DateTimePicker::OnTouchPressed(const _Control& source, const _TouchInfo& touchinfo)
809 return __pPresenter->OnTouchPressed(source, touchinfo);
813 _DateTimePicker::OnTouchMoved(const _Control& source, const _TouchInfo& touchinfo)
815 return __pPresenter->OnTouchMoved(source, touchinfo);
819 _DateTimePicker::OnTouchReleased(const _Control& source, const _TouchInfo& touchinfo)
821 return __pPresenter->OnTouchReleased(source, touchinfo);
825 _DateTimePicker::OnTouchCanceled(const _Control& source, const _TouchInfo& touchinfo)
827 return __pPresenter->OnTouchCanceled(source, touchinfo);
831 _DateTimePicker::OnAttachedToMainTree(void)
833 return CreateAllAccessibilityElements();
837 _DateTimePicker::OnDetachingFromMainTree(void)
839 RemoveAllAccessibilityElements();
841 return _Window::OnDetachingFromMainTree();
845 _DateTimePicker::OnChangeLayout(_ControlOrientation orientation)
847 result r = E_SUCCESS;
848 FloatDimension pickerSize(0.0f, 0.0f);
849 FloatDimension screenSize(0.0f, 0.0f);
851 screenSize = _ControlManager::GetInstance()->GetScreenSizeF();
852 pickerSize = screenSize;
853 if (orientation == _CONTROL_ORIENTATION_LANDSCAPE)
855 pickerSize.width = screenSize.height;
856 pickerSize.height = screenSize.width;
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.");
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.");
875 __pPresenter->OnChangeLayout(orientation);
877 const _DateTimeDisplayBox* pBox = null;
878 IEnumeratorT<_AccessibilityElement*>* pEnumerator = __accessibilityElements.GetEnumeratorN();
879 SysTryReturnVoidResult(NID_UI_CTRL, (pEnumerator != null), GetLastResult(),
880 "[%s] Propagating.", GetErrorMessage(GetLastResult()));
882 _AccessibilityElement* pElement = null;
884 while (pEnumerator->MoveNext() == E_SUCCESS)
886 if (pEnumerator->GetCurrent(pElement) == E_SUCCESS)
888 pBox = __pPresenter->GetDisplayBox(index);
891 FloatRectangle displayBoxBounds = pBox->GetDisplayBoxBounds();
893 if (__pDisplayVisualElement)
895 displayBoxBounds.y += __pDisplayVisualElement->GetBounds().y;
898 pElement->SetBounds(displayBoxBounds);
909 _DateTimePicker::OnDraw(void)
911 __pPresenter->Draw();
917 _DateTimePicker::OnActionPerformed(const _Control& source, int actionId)
919 __pPresenter->OnActionPerformed(source, actionId);
925 _DateTimePicker::OnAccessibilityActionPerformed(const _AccessibilityContainer& control, const _AccessibilityElement& element)
927 String amString = L"";
928 String pmString = L"";
931 label = element.GetLabel();
933 _DateTimeUtils dateTimeUtils;
934 dateTimeUtils.GetAmPm(amString, AM_TYPE);
935 dateTimeUtils.GetAmPm(pmString, PM_TYPE);
937 if (label == amString || label == pmString)
939 label.Append(L" Selected");
940 _AccessibilityManager::GetInstance()->ReadContent(label);
947 _DateTimePicker::OnFontChanged(Font* pFont)
949 result r = E_SUCCESS;
953 if (__pPresenter != null)
955 r = __pPresenter->SetFont(pFont);
956 SysTryReturnVoidResult(NID_UI_CTRL, (r == E_SUCCESS), r, "[%s] Propagating.");
959 if (__pFooter != null)
961 for (int i=0; i < __pFooter->GetItemCount(); i++)
963 _Button* pButton = __pFooter->GetItem(i);
967 r = pButton->SetFont(pFont->GetFaceName());
968 SysTryReturnVoidResult(NID_UI_CTRL, (r == E_SUCCESS), r, "[%s] Propagating.", GetErrorMessage(r));
980 _DateTimePicker::OnFontInfoRequested(unsigned long& style, float& size)
982 style = FONT_STYLE_PLAIN;
984 GET_SHAPE_CONFIG(DATETIMEPICKER::FONT_SIZE, GetOrientation(), size);
990 _DateTimePicker::OnKeyPressed(const _Control& source, const _KeyInfo& keyInfo)
997 return __pPresenter->OnKeyPressed(source, keyInfo);
1001 _DateTimePicker::OnKeyReleased(const _Control& source, const _KeyInfo& keyInfo)
1003 if (&source != this)
1008 return __pPresenter->OnKeyReleased(source, keyInfo);
1012 _DateTimePicker::OnDrawFocus(void)
1014 __pPresenter->DrawFocus();
1019 _DateTimePicker::OnFocusGained(const _Control& source)
1021 return _Control::OnFocusGained(source);
1025 _DateTimePicker::OnFocusLost(const _Control& source)
1027 result r = __pPresenter->ReleaseFocus();
1028 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, false, r, "[%s] Propagating.", GetErrorMessage(r));
1030 _Control::OnFocusLost(source);
1035 _DateTimePicker::OnFocusModeStateChanged(void)
1037 __pPresenter->ReleaseFocus();
1042 _DateTimePicker::OnSettingChanged(Tizen::Base::String& key)
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))
1047 __pPresenter->UpdateLocaleDateTimeFormat();
1049 RemoveAllAccessibilityElements();
1050 CreateAllAccessibilityElements();
1057 _DateTimePicker::GetDateTimeFont(void)
1063 _DateTimePicker::InitializeFont(void)
1065 result r = E_SUCCESS;
1067 __pFont = GetFallbackFont();
1068 r = GetLastResult();
1069 SysTryReturnResult(NID_UI_CTRL, (__pFont != null), r, "[%s] Propagating.", GetErrorMessage(r));
1075 _DateTimePicker::CreateAllAccessibilityElements(void)
1077 _AccessibilityContainer* pContainer = GetAccessibilityContainer();
1078 if (pContainer != null)
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;
1087 GET_SHAPE_CONFIG(DATETIMEPICKER::LEFT_MARGIN, GetOrientation(), leftMargin);
1089 pContainer->AddListener(*this);
1092 for (int index = 0; index < DATETIME_ID_MAX; index++)
1094 pBox = __pPresenter->GetDisplayBox(index);
1097 _AccessibilityElement* pElement = new (std::nothrow) _AccessibilityElement(true);
1098 SysTryReturnResult(NID_UI_CTRL, (pElement != null), E_OUT_OF_MEMORY, "Memory allocation failed.");
1100 FloatRectangle displayBoxBounds = pBox->GetDisplayBoxBounds();
1101 int displayBoxId = pBox->GetDisplayBoxId();
1103 String hintText(L"Double tap to edit");
1105 switch (displayBoxId)
1107 case DATETIME_ID_DAY:
1108 pElement->SetTraitWithStringId("IDS_TPLATFORM_BODY_DAY_LC");
1109 pElement->SetHint(hintText);
1111 case DATETIME_ID_MONTH:
1112 pElement->SetTraitWithStringId("IDS_TPLATFORM_BODY_MONTH_LC");
1113 pElement->SetHint(hintText);
1115 case DATETIME_ID_YEAR:
1116 pElement->SetTraitWithStringId("IDS_TPLATFORM_BODY_YEAR_LC");
1117 pElement->SetHint(hintText);
1119 case DATETIME_ID_HOUR:
1120 pElement->SetTraitWithStringId("IDS_TPLATFORM_BODY_HOUR_LC");
1121 pElement->SetHint(hintText);
1123 case DATETIME_ID_MINUTE:
1124 pElement->SetTraitWithStringId("IDS_TPLATFORM_BODY_MINUTE_LC");
1125 pElement->SetHint(hintText);
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;
1133 displayBoxBounds.x += leftMargin;
1134 displayBoxBounds.y -= topMargin;
1135 displayBoxBounds.height += 2 * topMargin;
1137 if (__pDisplayVisualElement)
1139 displayBoxBounds.y += __pDisplayVisualElement->GetBounds().y;
1142 pElement->SetLabel(pBox->GetText());
1143 pElement->SetBounds(displayBoxBounds);
1144 pContainer->AddElement(*pElement);
1148 pAmPmBox = __pPresenter->GetAmPmBox();
1149 if (pAmPmBox != null)
1151 _AccessibilityElement* pElement = new (std::nothrow) _AccessibilityElement(true);
1152 SysTryReturnResult(NID_UI_CTRL, (pElement != null), E_OUT_OF_MEMORY, "Memory allocation failed.");
1154 FloatRectangle amPmBoxBounds = pAmPmBox->GetDisplayBoxBounds();
1156 amPmBoxBounds.x += leftMargin;
1158 if (__pDisplayVisualElement)
1160 amPmBoxBounds.y += __pDisplayVisualElement->GetBounds().y;
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);
1170 pContainer->GetElements(__accessibilityElements);
1171 _AccessibilityManager::GetInstance()->RequestAutoReading(_ACCESSIBILITY_AUTO_READING_MODE_FIRST_ITEM);
1179 _DateTimePicker::RemoveAllAccessibilityElements(void)
1181 _AccessibilityContainer* pContainer = GetAccessibilityContainer();
1182 SysTryReturnVoidResult(NID_UI_CTRL, (pContainer != null), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1184 _AccessibilityElement* pAccessibilityElement = null;
1186 pContainer->RemoveListener(*this);
1188 while (__accessibilityElements.GetCount() > 0)
1190 if ((__accessibilityElements.GetAt(0, pAccessibilityElement)) == E_SUCCESS)
1192 __accessibilityElements.RemoveAt(0);
1193 pContainer->RemoveElement(*pAccessibilityElement);
1197 __accessibilityElements.RemoveAt(0);
1202 }}} // Tizen::Ui::Controls