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_EditDate.cpp
20 * @brief This is the implementation file for the _EditDate class.
24 #include <FSysSettingInfo.h>
25 #include "FUi_AccessibilityContainer.h"
26 #include "FUi_AccessibilityElement.h"
27 #include "FUi_ResourceManager.h"
28 #include "FUiAnim_VisualElement.h"
29 #include "FUiCtrl_EditDate.h"
30 #include "FUiCtrl_EditDatePresenter.h"
31 #include "FUiCtrl_Form.h"
32 #include "FUiCtrl_Frame.h"
33 #include "FUiCtrl_DateTimeUtils.h"
34 #include "FUi_CoordinateSystemUtils.h"
36 using namespace Tizen::Graphics;
37 using namespace Tizen::Base;
38 using namespace Tizen::Base::Runtime;
39 using namespace Tizen::Ui;
40 using namespace Tizen::System;
42 namespace Tizen { namespace Ui { namespace Controls
45 IMPLEMENT_PROPERTY(_EditDate);
47 _EditDate::_EditDate(void)
48 : __pEditDatePresenter(null)
49 , __pDateChangeEvent(null)
50 , __pDateTimeBar(null)
51 , __absoluteBounds(FloatRectangle())
52 , __previousSize(0.0f, 0.0f)
54 , __pAccessibilityEditDateElement(null)
55 , __pAccessibilityYearElement(null)
56 , __pAccessibilityMonthElement(null)
57 , __pAccessibilityDayElement(null)
58 , __isCalledBoundsChanged(false)
59 , __isXmlBoundsExist(false)
63 _EditDate::~_EditDate(void)
65 SettingInfo::RemoveSettingEventListener(*this);
67 delete __pDateTimeBar;
68 __pDateTimeBar = null;
70 delete __pEditDatePresenter;
71 __pEditDatePresenter = null;
73 if (__pDateChangeEvent != null)
75 delete __pDateChangeEvent;
76 __pDateChangeEvent = null;
79 if (__pAccessibilityEditDateElement)
81 __pAccessibilityEditDateElement->Activate(false);
82 __pAccessibilityEditDateElement = null;
84 if (__pAccessibilityYearElement)
86 __pAccessibilityYearElement->Activate(false);
87 __pAccessibilityYearElement = null;
89 if (__pAccessibilityMonthElement)
91 __pAccessibilityMonthElement->Activate(false);
92 __pAccessibilityMonthElement = null;
94 if (__pAccessibilityDayElement)
96 __pAccessibilityDayElement->Activate(false);
97 __pAccessibilityDayElement = null;
102 _EditDate::CreateEditDateN(const String& title)
104 result r = E_SUCCESS;
106 _AccessibilityContainer* pContainer = null;
108 _EditDate* pEditDate = new (std::nothrow) _EditDate;
109 SysTryReturn(NID_UI_CTRL, pEditDate, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
111 pEditDate->GetVisualElement()->SetSurfaceOpaque(false);
113 pEditDate->__pEditDatePresenter = _EditDatePresenter::CreateInstanceN(*pEditDate, title);
115 r = pEditDate->CreateDateTimeBar();
116 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
118 pEditDate->__pEditDatePresenter->Initialize();
120 SysTryCatch(NID_UI_CTRL, pEditDate->__pEditDatePresenter, , r, "[%s] Propagating.", GetErrorMessage(r));
122 pEditDate->__pEditDatePresenter->SetCurrentDate();
124 if (title.IsEmpty() != true)
126 pEditDate->__title = title;
129 pContainer = pEditDate->GetAccessibilityContainer();
133 pContainer->Activate(true);
134 pEditDate->CreateAccessibilityElement();
137 pEditDate->AcquireHandle();
138 pEditDate->SetTouchPressThreshold(_TOUCH_PRESS_THRESHOLD_INSENSITIVE);
148 _EditDate::CreateDateTimeBar(void)
150 result r = E_SUCCESS;
152 __pDateTimeBar = _DateTimeBar::CreateDateTimeBarN(*this);
154 SysTryReturn(NID_UI_CTRL, (__pDateTimeBar != null), r, r, "[%s] Propagating.", GetErrorMessage(r));
156 r = __pDateTimeBar->AddActionEventListener(*this);
157 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
159 r = __pDateTimeBar->AddDateTimeChangeEventListener(*this);
160 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
162 r = SettingInfo::AddSettingEventListener(*this);
163 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
165 GET_SHAPE_CONFIG(EDITDATE::WIDTH, GetOrientation(), __previousSize.width);
166 GET_SHAPE_CONFIG(EDITDATE::HEIGHT, GetOrientation(), __previousSize.height);
171 delete __pDateTimeBar;
176 _EditDate::AddDateChangeEventListener(const _IDateTimeChangeEventListener& listener)
178 if (__pDateChangeEvent == null)
180 __pDateChangeEvent = new (std::nothrow) _DateTimeChangeEvent(*this);
181 SysTryReturn(NID_UI_CTRL, (__pDateChangeEvent != null), E_OUT_OF_MEMORY, E_OUT_OF_MEMORY,
182 "[E_OUT_OF_MEMORY] Memory allocation failed.");
185 result r = __pDateChangeEvent->AddListener(listener);
186 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
192 _EditDate::RemoveDateChangeEventListener(const _IDateTimeChangeEventListener& listener)
194 result r = E_OBJ_NOT_FOUND;
196 if (__pDateChangeEvent)
198 r = __pDateChangeEvent->RemoveListener(listener);
201 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
207 _EditDate::SetDate(const DateTime& date)
209 SetProperty("date", Variant(date));
214 _EditDate::SetPropertyDate(const Variant& date)
216 SysTryReturn(NID_UI_CTRL, (__pEditDatePresenter != null), E_SYSTEM, E_SYSTEM,
217 "[E_SYSTEM] A system error has occurred. The _EditDatePresenter instance is null.");
219 __pEditDatePresenter->SetDate(date.ToDateTime());
221 UpdateAccessibilityElement();
226 _EditDate::GetDate(void) const
228 Variant date = GetProperty("date");
230 return date.ToDateTime();
234 _EditDate::GetPropertyDate(void) const
238 SysTryReturn(NID_UI_CTRL, (__pEditDatePresenter != null), Variant(), E_SYSTEM,
239 "[E_SYSTEM] A system error has occurred. The _EditDatePresenter instance is null.");
241 date = __pEditDatePresenter->GetDate();
243 return Variant(date);
247 _EditDate::SetDay(int day)
249 result r = E_SUCCESS;
251 SetProperty("day", Variant(day));
259 _EditDate::SetPropertyDay(const Variant& day)
261 result r = E_SUCCESS;
263 SysTryReturn(NID_UI_CTRL, (__pEditDatePresenter != null), E_SYSTEM, E_SYSTEM,
264 "[E_SYSTEM] A system error has occurred. The _EditDatePresenter instance is null.");
266 r = __pEditDatePresenter->SetDay(day.ToInt());
270 UpdateAccessibilityElement();
277 _EditDate::GetDay(void) const
279 Variant day = GetProperty("day");
285 _EditDate::GetPropertyDay(void) const
289 SysTryReturn(NID_UI_CTRL, (__pEditDatePresenter != null), Variant(), E_SYSTEM,
290 "[E_SYSTEM] A system error has occurred. The _EditDatePresenter instance is null.");
292 day = __pEditDatePresenter->GetDay();
298 _EditDate::SetMonth(int month)
300 result r = E_SUCCESS;
302 SetProperty("month", Variant(month));
310 _EditDate::SetPropertyMonth(const Variant& month)
312 result r = E_SUCCESS;
314 SysTryReturn(NID_UI_CTRL, (__pEditDatePresenter != null), E_SYSTEM, E_SYSTEM,
315 "[E_SYSTEM] A system error has occurred. The _EditDatePresenter instance is null.");
320 _DateTimeUtils dateTimeUtils;
322 maxValue = dateTimeUtils.CalculateMaxDay(GetYear(), month.ToInt());
323 day = __pEditDatePresenter->GetDay();
327 __pEditDatePresenter->SetDay(maxValue);
330 r = __pEditDatePresenter->SetMonth(month.ToInt());
334 UpdateAccessibilityElement();
341 _EditDate::GetMonth(void) const
343 Variant month = GetProperty("month");
345 return month.ToInt();
349 _EditDate::GetPropertyMonth(void) const
353 SysTryReturn(NID_UI_CTRL, (__pEditDatePresenter != null), Variant(), E_SYSTEM,
354 "[E_SYSTEM] A system error has occurred. The _EditDatePresenter instance is null.");
356 month = __pEditDatePresenter->GetMonth();
358 return Variant(month);
362 _EditDate::SetYear(int year)
364 result r = E_SUCCESS;
366 SetProperty("year", Variant(year));
374 _EditDate::SetPropertyYear(const Variant& year)
376 result r = E_SUCCESS;
378 SysTryReturn(NID_UI_CTRL, (__pEditDatePresenter != null), E_SYSTEM, E_SYSTEM,
379 "[E_SYSTEM] A system error has occurred. The _EditDatePresenter instance is null.");
384 _DateTimeUtils dateTimeUtils;
386 maxValue = dateTimeUtils.CalculateMaxDay(year.ToInt(), GetMonth());
387 day = __pEditDatePresenter->GetDay();
391 __pEditDatePresenter->SetDay(maxValue);
394 r = __pEditDatePresenter->SetYear(year.ToInt());
398 UpdateAccessibilityElement();
405 _EditDate::GetYear(void) const
407 Variant year = GetProperty("year");
413 _EditDate::GetPropertyYear(void) const
417 SysTryReturn(NID_UI_CTRL, (__pEditDatePresenter != null), Variant(), E_SYSTEM,
418 "[E_SYSTEM] A system error has occurred. The _EditDatePresenter instance is null.");
420 year = __pEditDatePresenter->GetYear();
422 return Variant(year);
426 _EditDate::SetCurrentDate(void)
428 SysTryReturnVoidResult(NID_UI_CTRL, (__pEditDatePresenter != null), E_SYSTEM,
429 "[E_SYSTEM] A system error has occurred. The _EditDatePresenter instance is null.");
431 __pEditDatePresenter->SetCurrentDate();
433 UpdateAccessibilityElement();
439 _EditDate::SetDatePickerEnabled(bool enable)
441 SetProperty("datePickerEnabled", Variant(enable));
446 _EditDate::SetPropertyDatePickerEnabled(const Variant& enable)
448 SysTryReturn(NID_UI_CTRL, (__pEditDatePresenter != null), E_SYSTEM, E_SYSTEM,
449 "[E_SYSTEM] A system error has occurred. The _EditDatePresenter instance is null.");
451 __pEditDatePresenter->SetDatePickerEnabled(enable.ToBool());
457 _EditDate::IsDatePickerEnabled(void) const
459 Variant enable = GetProperty("datePickerEnabled");
461 return enable.ToBool();
465 _EditDate::GetPropertyDatePickerEnabled(void) const
469 SysTryReturn(NID_UI_CTRL, (__pEditDatePresenter != null), Variant(), E_SYSTEM,
470 "[E_SYSTEM] A system error has occurred. The _EditDatePresenter instance is null.");
472 enable = __pEditDatePresenter->IsDatePickerEnabled();
474 return Variant(enable);
478 _EditDate::SetYearRange(int minYear, int maxYear)
480 result r = E_SUCCESS;
482 SysTryReturn(NID_UI_CTRL, (maxYear >= DATETIME_YEAR_MIN && maxYear <= DATETIME_YEAR_MAX), E_INVALID_ARG, E_INVALID_ARG,
483 "[E_INVALID_ARG] maxYear(%d) must be greater than or equal to %d and less than or equal to %d.",
484 maxYear, DATETIME_YEAR_MIN, DATETIME_YEAR_MAX);
486 SysTryReturn(NID_UI_CTRL, (minYear >= DATETIME_YEAR_MIN && minYear <= DATETIME_YEAR_MAX), E_INVALID_ARG, E_INVALID_ARG,
487 "[E_INVALID_ARG] minYear(%d) must be greater than or equal to %d and less than or equal to %d.",
488 minYear, DATETIME_YEAR_MIN, DATETIME_YEAR_MAX);
490 SysTryReturn(NID_UI_CTRL, (maxYear >= minYear), E_INVALID_ARG, E_INVALID_ARG,
491 "[E_INVALID_ARG] maxYear(%d) must be greater than or equal to minYear(%d).", maxYear, minYear);
493 Variant oldMinYear = GetPropertyMinYearRange();
495 r = SetPropertyMinYearRange(Variant(minYear));
496 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, null, r, "[%s] Propagating.", GetErrorMessage(r));
498 r = SetPropertyMaxYearRange(Variant(maxYear));
502 SetPropertyMinYearRange(oldMinYear);
509 _EditDate::SetMinYearRange(int minYear)
511 result r = E_SUCCESS;
513 r = SetProperty("minYearRange", Variant(minYear));
519 _EditDate::SetMaxYearRange(int maxYear)
521 result r = E_SUCCESS;
523 r = SetProperty("maxYearRange", Variant(maxYear));
529 _EditDate::SetPropertyMinYearRange(const Variant& minYear)
531 SysTryReturn(NID_UI_CTRL, (__pEditDatePresenter != null), E_SYSTEM, E_SYSTEM,
532 "[E_SYSTEM] A system error has occurred. The _EditDatePresenter instance is null.");
534 return __pEditDatePresenter->SetMinYear(minYear.ToInt());
538 _EditDate::SetPropertyMaxYearRange(const Variant& maxYear)
540 SysTryReturn(NID_UI_CTRL, (__pEditDatePresenter != null), E_SYSTEM, E_SYSTEM,
541 "[E_SYSTEM] A system error has occurred. The _EditDatePresenter instance is null.");
543 return __pEditDatePresenter->SetMaxYear(maxYear.ToInt());
547 _EditDate::GetYearRange(int& minYear, int& maxYear) const
549 result r = E_SUCCESS;
551 minYear = GetMinYearRange();
552 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, null, r, "[%s] Propagating.", GetErrorMessage(r));
553 maxYear = GetMaxYearRange();
554 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, null, r, "[%s] Propagating.", GetErrorMessage(r));
560 _EditDate::GetMinYearRange(void) const
562 Variant minYear = GetProperty("minYearRange");
564 return minYear.ToInt();
568 _EditDate::GetMaxYearRange(void) const
570 Variant maxYear = GetProperty("maxYearRange");
572 return maxYear.ToInt();
576 _EditDate::GetPropertyMinYearRange(void) const
578 SysTryReturn(NID_UI_CTRL, (__pEditDatePresenter != null), Variant(), E_SYSTEM,
579 "[E_SYSTEM] A system error has occurred. The _EditDatePresenter instance is null.");
583 minYear = __pEditDatePresenter->GetMinYear();
585 return Variant(minYear);
589 _EditDate::GetPropertyMaxYearRange(void) const
591 SysTryReturn(NID_UI_CTRL, (__pEditDatePresenter != null), Variant(), E_SYSTEM,
592 "[E_SYSTEM] A system error has occurred. The _EditDatePresenter instance is null.");
596 maxYear = __pEditDatePresenter->GetMaxYear();
598 return Variant(maxYear);
602 _EditDate::CalculateDateTimeBarPosition(void)
604 result r = E_SUCCESS;
606 float dateTimeBarHeight = 0.0f;
607 float arrowHeight = 0.0f;
608 float dateHeight = 0.0f;
609 float dateBarMargin = 0.0f;
610 float textHeight = 0.0f;
611 float titleDateMargin = 0.0f;
612 float bottomPosition = 0.0f;
615 FloatRectangle absoluteBounds;
616 FloatRectangle frameBounds;
617 FloatRectangle parentWindowBounds;
618 FloatRectangle titleBounds;
620 _Frame* pFrame = dynamic_cast<_Frame*>(_ControlManager::GetInstance()->GetCurrentFrame());
621 SysTryReturn(NID_UI_CTRL, pFrame != null, E_SYSTEM, E_SYSTEM,
622 "[E_SYSTEM] A system error has occurred. Failed to get frame instance.");
624 absoluteBounds = GetAbsoluteBoundsF();
625 frameBounds = pFrame->GetAbsoluteBoundsF();
626 parentWindowBounds = GetParentWindowBounds();
627 titleBounds = __pEditDatePresenter->GetTitleBounds();
629 GET_SHAPE_CONFIG(DATETIMEBAR::ITEM_HEIGHT, GetOrientation(), dateTimeBarHeight);
630 GET_SHAPE_CONFIG(DATETIMEBAR::ARROW_HEIGHT, GetOrientation(), arrowHeight);
631 GET_SHAPE_CONFIG(EDITDATE::DATE_HEIGHT, GetOrientation(), dateHeight);
632 GET_SHAPE_CONFIG(EDITDATE::DATE_BAR_MARGIN, GetOrientation(), dateBarMargin);
633 GET_SHAPE_CONFIG(EDITDATE::TITLE_HEIGHT, GetOrientation(), textHeight);
634 GET_SHAPE_CONFIG(EDITDATE::TITLE_DATE_MARGIN, GetOrientation(), titleDateMargin);
636 if (!__title.IsEmpty()) //with title
638 dateY = titleBounds.y + textHeight + titleDateMargin ;
642 dateY = (absoluteBounds.height - dateHeight) / 2.0f ;
645 bottomPosition = absoluteBounds.y + dateY + dateHeight + dateBarMargin + arrowHeight + dateTimeBarHeight;
647 GetDateTimeBar()->SetParentWindowBounds(parentWindowBounds);
649 if (bottomPosition > frameBounds.y + parentWindowBounds.y + parentWindowBounds.height)
651 r = GetDateTimeBar()->SetPositionAndAlignment(FloatPoint(parentWindowBounds.x, absoluteBounds.y + dateY - dateBarMargin - arrowHeight), DATETIME_BAR_ALIGN_UP);
652 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
656 r = GetDateTimeBar()->SetPositionAndAlignment(FloatPoint(parentWindowBounds.x, absoluteBounds.y + dateY + dateHeight + dateBarMargin + arrowHeight), DATETIME_BAR_ALIGN_DOWN);
657 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
660 __absoluteBounds = absoluteBounds;
666 _EditDate::OnDraw(void)
668 if (GetDateTimeBar() != null)
670 FloatRectangle absoluteBounds = GetAbsoluteBoundsF();
672 if (absoluteBounds.y != __absoluteBounds.y || absoluteBounds.height != __absoluteBounds.height)
674 CalculateDateTimeBarPosition();
678 __pEditDatePresenter->Draw();
683 _EditDate::CreateAccessibilityElement(void)
685 _AccessibilityContainer* pContainer = GetAccessibilityContainer();
687 FloatRectangle dayBounds = __pEditDatePresenter->GetDateAreaBounds(DATETIME_ID_DAY);
688 FloatRectangle monthBounds = __pEditDatePresenter->GetDateAreaBounds(DATETIME_ID_MONTH);
689 FloatRectangle yearBounds = __pEditDatePresenter->GetDateAreaBounds(DATETIME_ID_YEAR);
691 if (__pAccessibilityEditDateElement == null)
693 __pAccessibilityEditDateElement = new _AccessibilityElement(true);
694 __pAccessibilityEditDateElement->SetBounds(GetClientBoundsF());
695 __pAccessibilityEditDateElement->SetTrait(ACCESSIBILITY_TRAITS_NONE);
696 __pAccessibilityEditDateElement->SetName("EditDateText");
697 pContainer->AddElement(*__pAccessibilityEditDateElement);
700 if (__pAccessibilityYearElement == null && __pAccessibilityMonthElement == null && __pAccessibilityDayElement == null)
702 String hintText(L"Double tap to edit");
704 __pAccessibilityYearElement = new _AccessibilityElement(true);
705 __pAccessibilityYearElement->SetBounds(yearBounds);
706 __pAccessibilityYearElement->SetTrait(ACCESSIBILITY_TRAITS_YEAR);
707 __pAccessibilityYearElement->SetHint(hintText);
709 __pAccessibilityMonthElement = new _AccessibilityElement(true);
710 __pAccessibilityMonthElement->SetBounds(monthBounds);
711 __pAccessibilityMonthElement->SetTrait(ACCESSIBILITY_TRAITS_MONTH);
712 __pAccessibilityMonthElement->SetHint(hintText);
714 __pAccessibilityDayElement = new _AccessibilityElement(true);
715 __pAccessibilityDayElement->SetBounds(dayBounds);
716 __pAccessibilityDayElement->SetTrait(ACCESSIBILITY_TRAITS_DAY);
717 __pAccessibilityDayElement->SetHint(hintText);
719 switch (__pEditDatePresenter->GetLocaleDateFormat())
721 case SETTING_DATE_FORMAT_DD_MM_YYYY:
722 pContainer->AddElement(*__pAccessibilityDayElement);
723 pContainer->AddElement(*__pAccessibilityMonthElement);
724 pContainer->AddElement(*__pAccessibilityYearElement);
726 case SETTING_DATE_FORMAT_MM_DD_YYYY:
727 pContainer->AddElement(*__pAccessibilityMonthElement);
728 pContainer->AddElement(*__pAccessibilityDayElement);
729 pContainer->AddElement(*__pAccessibilityYearElement);
731 case SETTING_DATE_FORMAT_YYYY_MM_DD:
732 pContainer->AddElement(*__pAccessibilityYearElement);
733 pContainer->AddElement(*__pAccessibilityMonthElement);
734 pContainer->AddElement(*__pAccessibilityDayElement);
736 case SETTING_DATE_FORMAT_YYYY_DD_MM:
737 pContainer->AddElement(*__pAccessibilityYearElement);
738 pContainer->AddElement(*__pAccessibilityDayElement);
739 pContainer->AddElement(*__pAccessibilityMonthElement);
744 UpdateAccessibilityElement();
749 _EditDate::OnBoundsChanged(void)
751 FloatDimension newSize = GetSizeF();
753 if (newSize.width != __previousSize.width || newSize.height != __previousSize.height)
755 __isCalledBoundsChanged = true;
758 __pEditDatePresenter->Initialize();
760 if (__pAccessibilityEditDateElement)
762 __pAccessibilityEditDateElement->SetBounds(GetClientBoundsF());
764 if (__pAccessibilityYearElement)
766 __pAccessibilityYearElement->SetBounds(__pEditDatePresenter->GetDateAreaBounds(DATETIME_ID_YEAR));
768 if (__pAccessibilityMonthElement)
770 __pAccessibilityMonthElement->SetBounds(__pEditDatePresenter->GetDateAreaBounds(DATETIME_ID_MONTH));
772 if (__pAccessibilityDayElement)
774 __pAccessibilityDayElement->SetBounds(__pEditDatePresenter->GetDateAreaBounds(DATETIME_ID_DAY));
781 _EditDate::OnChangeLayout(_ControlOrientation orientation)
783 if (!__isCalledBoundsChanged && !__isXmlBoundsExist)
785 FloatRectangle bounds = GetBoundsF();
787 GET_SHAPE_CONFIG(EDITDATE::WIDTH, GetOrientation(), bounds.width);
788 GET_SHAPE_CONFIG(EDITDATE::HEIGHT, GetOrientation(), bounds.height);
790 SetBounds(bounds, false);
793 __pEditDatePresenter->Initialize();
794 __pEditDatePresenter->SetLastSelectedId(DATETIME_ID_NONE);
796 if (GetDateTimeBar() != null)
798 GetDateTimeBar()->SetVisibleState(false);
799 GetDateTimeBar()->Close();
806 _EditDate::OnTouchPressed(const _Control& source, const _TouchInfo& touchinfo)
810 FloatRectangle absoluteBounds = GetAbsoluteBoundsF();
812 if (absoluteBounds.y != __absoluteBounds.y || absoluteBounds.height != __absoluteBounds.height)
814 CalculateDateTimeBarPosition();
817 return __pEditDatePresenter->OnTouchPressed(source, touchinfo);
821 _EditDate::OnTouchReleased(const _Control& source, const _TouchInfo& touchinfo)
823 return __pEditDatePresenter->OnTouchReleased(source, touchinfo);
827 _EditDate::OnTouchCanceled(const _Control& source, const _TouchInfo& touchinfo)
829 return __pEditDatePresenter->OnTouchCanceled(source, touchinfo);
833 _EditDate::OnTouchMoved(const _Control& source, const _TouchInfo& touchinfo)
835 return __pEditDatePresenter->OnTouchMoved(source, touchinfo);
839 _EditDate::OnTouchMoveHandled(const _Control& control)
841 __pEditDatePresenter->OnTouchMoveHandled(control);
846 _EditDate::FireDateChangeEvent(_DateTimeChangeStatus status)
848 SysTryReturn(NID_UI_CTRL, (__pDateChangeEvent != null), E_INVALID_STATE, E_INVALID_STATE,
849 "[E_INVALID_STATE] The _DateChangeEvent instance is null.");
851 _DateTimeChangeEventArg* pDateTimeEventArg = new (std::nothrow) _DateTimeChangeEventArg(status);
852 SysTryReturn(NID_UI_CTRL, pDateTimeEventArg, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
854 pDateTimeEventArg->SetDate(GetYear(), GetMonth(), GetDay());
856 __pDateChangeEvent->Fire(*pDateTimeEventArg);
862 _EditDate::OnDateTimeChanged(const _Control& source, int year, int month, int day, int hour, int minute)
864 __pEditDatePresenter->Animate();
865 __pEditDatePresenter->SetLastSelectedId(DATETIME_ID_NONE);
867 FireDateChangeEvent(DATE_INTERNAL_CHANGE_SAVED);
872 _EditDate::OnDateTimeChangeCanceled(const _Control& source)
874 __pEditDatePresenter->SetLastSelectedId(DATETIME_ID_NONE);
876 FireDateChangeEvent(DATE_INTERNAL_CHANGE_CANCELED);
881 _EditDate::OnActionPerformed(const Ui::_Control& source, int actionId)
883 _DateTimeId boxId = __pEditDatePresenter->GetLastSelectedId();
885 if (boxId == DATETIME_ID_YEAR)
888 AdjustDay(actionId, GetMonth());
890 else if (boxId == DATETIME_ID_MONTH)
893 AdjustDay(GetYear(), actionId);
895 else if (boxId == DATETIME_ID_DAY)
906 _EditDate::AdjustDay(int year, int month)
908 _DateTimeUtils dateTimeUtils;
909 int maxValue = dateTimeUtils.CalculateMaxDay(year, month);
911 if (GetDay() > maxValue)
920 _EditDate::GetDateTimeBar(void) const
922 return __pDateTimeBar;
926 _EditDate::OnFontChanged(Font* pFont)
928 __pEditDatePresenter->OnFontChanged(pFont);
934 _EditDate::OnFontInfoRequested(unsigned long& style, float& size)
936 __pEditDatePresenter->OnFontInfoRequested(style, size);
942 _EditDate::OnSettingChanged(String& key)
944 if (key.Equals(L"http://tizen.org/setting/locale.date.format", false))
946 __pEditDatePresenter->Initialize();
947 __pEditDatePresenter->SetLastSelectedId(DATETIME_ID_NONE);
949 if (GetDateTimeBar() != null)
951 GetDateTimeBar()->SetVisibleState(false);
952 GetDateTimeBar()->Close();
962 _EditDate::GetParentWindowBounds(void) const
965 _Window* pwindow = null;
966 _Control* pControlCore = GetParent();
968 FloatDimension dateTimeBarSize(0.0f, 0.0f);
969 GET_DIMENSION_CONFIG(DATETIMEBAR::DEFAULT_SIZE, GetOrientation(), dateTimeBarSize);
970 FloatRectangle parentWindowBounds(0.0f, 0.0f, dateTimeBarSize.width, dateTimeBarSize.height);
974 if (pControlCore == null)
976 SysLog(NID_UI_CTRL,"[E_SYSTEM] Parent window not found.");
978 return parentWindowBounds;
981 // If the parent is a Frame, then return the Form's bounds.
982 pForm = dynamic_cast<_Form*>(pControlCore);
985 parentWindowBounds = pForm->GetBoundsF();
989 pwindow = dynamic_cast<_Window*>(pControlCore);
993 parentWindowBounds = pwindow->GetBoundsF();
997 pControlCore = pControlCore->GetParent();
1000 return parentWindowBounds;
1004 _EditDate::UpdateAccessibilityElement(void)
1011 if (__pAccessibilityEditDateElement == null)
1016 if (__title.IsEmpty() == false)
1018 string.Append(__title);
1019 string.Append(L", ");
1022 yearString.Append(GetYear());
1023 dayString.Append(GetDay());
1024 String monthString = GetDateTimeBar()->GetMonthValue(GetMonth()).GetPointer();
1026 switch (__pEditDatePresenter->GetLocaleDateFormat())
1028 case SETTING_DATE_FORMAT_DD_MM_YYYY:
1029 string.Append(dayString.GetPointer());
1030 string.Append(space.GetPointer());
1031 string.Append(monthString.GetPointer());
1032 string.Append(space.GetPointer());
1033 string.Append(yearString.GetPointer());
1035 case SETTING_DATE_FORMAT_MM_DD_YYYY:
1036 string.Append(monthString.GetPointer());
1037 string.Append(space.GetPointer());
1038 string.Append(dayString.GetPointer());
1039 string.Append(space.GetPointer());
1040 string.Append(yearString.GetPointer());
1042 case SETTING_DATE_FORMAT_YYYY_MM_DD:
1043 string.Append(yearString.GetPointer());
1044 string.Append(space.GetPointer());
1045 string.Append(monthString.GetPointer());
1046 string.Append(space.GetPointer());
1047 string.Append(dayString.GetPointer());
1049 case SETTING_DATE_FORMAT_YYYY_DD_MM:
1050 string.Append(yearString.GetPointer());
1051 string.Append(space.GetPointer());
1052 string.Append(dayString.GetPointer());
1053 string.Append(space.GetPointer());
1054 string.Append(monthString.GetPointer());
1060 __pAccessibilityEditDateElement->SetLabel(string);
1061 __pAccessibilityDayElement->SetLabel(dayString);
1062 __pAccessibilityMonthElement->SetLabel(monthString);
1063 __pAccessibilityYearElement->SetLabel(yearString);
1068 _EditDate::SetXmlBoundsExist(bool isXmlBoundsExist)
1070 __isXmlBoundsExist = isXmlBoundsExist;
1073 }}} // Tizen::Ui::Controls