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.
23 #include <FSysSettingInfo.h>
24 #include "FUi_AccessibilityContainer.h"
25 #include "FUi_AccessibilityElement.h"
26 #include "FUi_ResourceManager.h"
27 #include "FUiAnim_VisualElement.h"
28 #include "FUiCtrl_EditDate.h"
29 #include "FUiCtrl_EditDatePresenter.h"
30 #include "FUiCtrl_Form.h"
31 #include "FUiCtrl_Frame.h"
32 #include "FUiCtrl_DateTimeUtils.h"
33 #include "FUi_CoordinateSystemUtils.h"
35 using namespace Tizen::Graphics;
36 using namespace Tizen::Base;
37 using namespace Tizen::Base::Runtime;
38 using namespace Tizen::Ui;
39 using namespace Tizen::System;
41 namespace Tizen { namespace Ui { namespace Controls
44 IMPLEMENT_PROPERTY(_EditDate);
46 _EditDate::_EditDate(void)
47 : __pEditDatePresenter(null)
48 , __pDateChangeEvent(null)
49 , __pDateTimeBar(null)
50 , __absoluteBounds(FloatRectangle())
51 , __previousSize(0.0f, 0.0f)
53 , __pAccessibilityEditDateElement(null)
54 , __pAccessibilityYearElement(null)
55 , __pAccessibilityMonthElement(null)
56 , __pAccessibilityDayElement(null)
57 , __isCalledBoundsChanged(false)
58 , __isXmlBoundsExist(false)
62 _EditDate::~_EditDate(void)
64 SettingInfo::RemoveSettingEventListener(*this);
66 delete __pDateTimeBar;
67 __pDateTimeBar = null;
69 delete __pEditDatePresenter;
70 __pEditDatePresenter = null;
72 if (__pDateChangeEvent != null)
74 delete __pDateChangeEvent;
75 __pDateChangeEvent = null;
78 if (__pAccessibilityEditDateElement)
80 __pAccessibilityEditDateElement->Activate(false);
81 __pAccessibilityEditDateElement = null;
83 if (__pAccessibilityYearElement)
85 __pAccessibilityYearElement->Activate(false);
86 __pAccessibilityYearElement = null;
88 if (__pAccessibilityMonthElement)
90 __pAccessibilityMonthElement->Activate(false);
91 __pAccessibilityMonthElement = null;
93 if (__pAccessibilityDayElement)
95 __pAccessibilityDayElement->Activate(false);
96 __pAccessibilityDayElement = null;
101 _EditDate::CreateEditDateN(const String& title)
103 result r = E_SUCCESS;
105 _AccessibilityContainer* pContainer = null;
107 _EditDate* pEditDate = new (std::nothrow) _EditDate;
108 SysTryReturn(NID_UI_CTRL, pEditDate, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
110 pEditDate->GetVisualElement()->SetSurfaceOpaque(false);
112 pEditDate->__pEditDatePresenter = _EditDatePresenter::CreateInstanceN(*pEditDate, title);
114 r = pEditDate->CreateDateTimeBar();
115 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
117 pEditDate->__pEditDatePresenter->Initialize();
119 SysTryCatch(NID_UI_CTRL, pEditDate->__pEditDatePresenter, , r, "[%s] Propagating.", GetErrorMessage(r));
121 pEditDate->__pEditDatePresenter->SetCurrentDate();
123 if (title.IsEmpty() != true)
125 pEditDate->__title = title;
128 pContainer = pEditDate->GetAccessibilityContainer();
132 pContainer->Activate(true);
133 pEditDate->CreateAccessibilityElement();
136 pEditDate->AcquireHandle();
137 pEditDate->SetTouchPressThreshold(_TOUCH_PRESS_THRESHOLD_INSENSITIVE);
147 _EditDate::CreateDateTimeBar(void)
149 result r = E_SUCCESS;
151 __pDateTimeBar = _DateTimeBar::CreateDateTimeBarN(*this);
153 SysTryReturn(NID_UI_CTRL, (__pDateTimeBar != null), r, r, "[%s] Propagating.", GetErrorMessage(r));
155 r = __pDateTimeBar->AddActionEventListener(*this);
156 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
158 r = __pDateTimeBar->AddDateTimeChangeEventListener(*this);
159 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
161 r = SettingInfo::AddSettingEventListener(*this);
162 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
164 GET_SHAPE_CONFIG(EDITDATE::WIDTH, GetOrientation(), __previousSize.width);
165 GET_SHAPE_CONFIG(EDITDATE::HEIGHT, GetOrientation(), __previousSize.height);
170 delete __pDateTimeBar;
175 _EditDate::AddDateChangeEventListener(const _IDateTimeChangeEventListener& listener)
177 if (__pDateChangeEvent == null)
179 __pDateChangeEvent = new (std::nothrow) _DateTimeChangeEvent(*this);
180 SysTryReturn(NID_UI_CTRL, (__pDateChangeEvent != null), E_OUT_OF_MEMORY, E_OUT_OF_MEMORY,
181 "[E_OUT_OF_MEMORY] Memory allocation failed.");
184 result r = __pDateChangeEvent->AddListener(listener);
185 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
191 _EditDate::RemoveDateChangeEventListener(const _IDateTimeChangeEventListener& listener)
193 result r = E_OBJ_NOT_FOUND;
195 if (__pDateChangeEvent)
197 r = __pDateChangeEvent->RemoveListener(listener);
200 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
206 _EditDate::SetDate(const DateTime& date)
208 SetProperty("date", Variant(date));
213 _EditDate::SetPropertyDate(const Variant& date)
215 SysTryReturn(NID_UI_CTRL, (__pEditDatePresenter != null), E_SYSTEM, E_SYSTEM,
216 "[E_SYSTEM] A system error has occurred. The _EditDatePresenter instance is null.");
218 __pEditDatePresenter->SetDate(date.ToDateTime());
220 UpdateAccessibilityElement();
225 _EditDate::GetDate(void) const
227 Variant date = GetProperty("date");
229 return date.ToDateTime();
233 _EditDate::GetPropertyDate(void) const
237 SysTryReturn(NID_UI_CTRL, (__pEditDatePresenter != null), Variant(), E_SYSTEM,
238 "[E_SYSTEM] A system error has occurred. The _EditDatePresenter instance is null.");
240 date = __pEditDatePresenter->GetDate();
242 return Variant(date);
246 _EditDate::SetDay(int day)
248 result r = E_SUCCESS;
250 SetProperty("day", Variant(day));
258 _EditDate::SetPropertyDay(const Variant& day)
260 result r = E_SUCCESS;
262 SysTryReturn(NID_UI_CTRL, (__pEditDatePresenter != null), E_SYSTEM, E_SYSTEM,
263 "[E_SYSTEM] A system error has occurred. The _EditDatePresenter instance is null.");
265 r = __pEditDatePresenter->SetDay(day.ToInt());
269 UpdateAccessibilityElement();
276 _EditDate::GetDay(void) const
278 Variant day = GetProperty("day");
284 _EditDate::GetPropertyDay(void) const
288 SysTryReturn(NID_UI_CTRL, (__pEditDatePresenter != null), Variant(), E_SYSTEM,
289 "[E_SYSTEM] A system error has occurred. The _EditDatePresenter instance is null.");
291 day = __pEditDatePresenter->GetDay();
297 _EditDate::SetMonth(int month)
299 result r = E_SUCCESS;
301 SetProperty("month", Variant(month));
309 _EditDate::SetPropertyMonth(const Variant& month)
311 result r = E_SUCCESS;
313 SysTryReturn(NID_UI_CTRL, (__pEditDatePresenter != null), E_SYSTEM, E_SYSTEM,
314 "[E_SYSTEM] A system error has occurred. The _EditDatePresenter instance is null.");
319 _DateTimeUtils dateTimeUtils;
321 maxValue = dateTimeUtils.CalculateMaxDay(GetYear(), month.ToInt());
322 day = __pEditDatePresenter->GetDay();
326 __pEditDatePresenter->SetDay(maxValue);
329 r = __pEditDatePresenter->SetMonth(month.ToInt());
333 UpdateAccessibilityElement();
340 _EditDate::GetMonth(void) const
342 Variant month = GetProperty("month");
344 return month.ToInt();
348 _EditDate::GetPropertyMonth(void) const
352 SysTryReturn(NID_UI_CTRL, (__pEditDatePresenter != null), Variant(), E_SYSTEM,
353 "[E_SYSTEM] A system error has occurred. The _EditDatePresenter instance is null.");
355 month = __pEditDatePresenter->GetMonth();
357 return Variant(month);
361 _EditDate::SetYear(int year)
363 result r = E_SUCCESS;
365 SetProperty("year", Variant(year));
373 _EditDate::SetPropertyYear(const Variant& year)
375 result r = E_SUCCESS;
377 SysTryReturn(NID_UI_CTRL, (__pEditDatePresenter != null), E_SYSTEM, E_SYSTEM,
378 "[E_SYSTEM] A system error has occurred. The _EditDatePresenter instance is null.");
383 _DateTimeUtils dateTimeUtils;
385 maxValue = dateTimeUtils.CalculateMaxDay(year.ToInt(), GetMonth());
386 day = __pEditDatePresenter->GetDay();
390 __pEditDatePresenter->SetDay(maxValue);
393 r = __pEditDatePresenter->SetYear(year.ToInt());
397 UpdateAccessibilityElement();
404 _EditDate::GetYear(void) const
406 Variant year = GetProperty("year");
412 _EditDate::GetPropertyYear(void) const
416 SysTryReturn(NID_UI_CTRL, (__pEditDatePresenter != null), Variant(), E_SYSTEM,
417 "[E_SYSTEM] A system error has occurred. The _EditDatePresenter instance is null.");
419 year = __pEditDatePresenter->GetYear();
421 return Variant(year);
425 _EditDate::SetCurrentDate(void)
427 SysTryReturnVoidResult(NID_UI_CTRL, (__pEditDatePresenter != null), E_SYSTEM,
428 "[E_SYSTEM] A system error has occurred. The _EditDatePresenter instance is null.");
430 __pEditDatePresenter->SetCurrentDate();
432 UpdateAccessibilityElement();
438 _EditDate::SetDatePickerEnabled(bool enable)
440 SetProperty("datePickerEnabled", Variant(enable));
445 _EditDate::SetPropertyDatePickerEnabled(const Variant& enable)
447 SysTryReturn(NID_UI_CTRL, (__pEditDatePresenter != null), E_SYSTEM, E_SYSTEM,
448 "[E_SYSTEM] A system error has occurred. The _EditDatePresenter instance is null.");
450 __pEditDatePresenter->SetDatePickerEnabled(enable.ToBool());
456 _EditDate::IsDatePickerEnabled(void) const
458 Variant enable = GetProperty("datePickerEnabled");
460 return enable.ToBool();
464 _EditDate::GetPropertyDatePickerEnabled(void) const
468 SysTryReturn(NID_UI_CTRL, (__pEditDatePresenter != null), Variant(), E_SYSTEM,
469 "[E_SYSTEM] A system error has occurred. The _EditDatePresenter instance is null.");
471 enable = __pEditDatePresenter->IsDatePickerEnabled();
473 return Variant(enable);
477 _EditDate::SetYearRange(int minYear, int maxYear)
479 result r = E_SUCCESS;
481 SysTryReturn(NID_UI_CTRL, (maxYear >= DATETIME_YEAR_MIN && maxYear <= DATETIME_YEAR_MAX), E_INVALID_ARG, E_INVALID_ARG,
482 "[E_INVALID_ARG] maxYear(%d) must be greater than or equal to %d and less than or equal to %d.",
483 maxYear, DATETIME_YEAR_MIN, DATETIME_YEAR_MAX);
485 SysTryReturn(NID_UI_CTRL, (minYear >= DATETIME_YEAR_MIN && minYear <= DATETIME_YEAR_MAX), E_INVALID_ARG, E_INVALID_ARG,
486 "[E_INVALID_ARG] minYear(%d) must be greater than or equal to %d and less than or equal to %d.",
487 minYear, DATETIME_YEAR_MIN, DATETIME_YEAR_MAX);
489 SysTryReturn(NID_UI_CTRL, (maxYear >= minYear), E_INVALID_ARG, E_INVALID_ARG,
490 "[E_INVALID_ARG] maxYear(%d) must be greater than or equal to minYear(%d).", maxYear, minYear);
492 Variant oldMinYear = GetPropertyMinYearRange();
494 r = SetPropertyMinYearRange(Variant(minYear));
495 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, null, r, "[%s] Propagating.", GetErrorMessage(r));
497 r = SetPropertyMaxYearRange(Variant(maxYear));
501 SetPropertyMinYearRange(oldMinYear);
508 _EditDate::SetMinYearRange(int minYear)
510 result r = E_SUCCESS;
512 r = SetProperty("minYearRange", Variant(minYear));
518 _EditDate::SetMaxYearRange(int maxYear)
520 result r = E_SUCCESS;
522 r = SetProperty("maxYearRange", Variant(maxYear));
528 _EditDate::SetPropertyMinYearRange(const Variant& minYear)
530 SysTryReturn(NID_UI_CTRL, (__pEditDatePresenter != null), E_SYSTEM, E_SYSTEM,
531 "[E_SYSTEM] A system error has occurred. The _EditDatePresenter instance is null.");
533 return __pEditDatePresenter->SetMinYear(minYear.ToInt());
537 _EditDate::SetPropertyMaxYearRange(const Variant& maxYear)
539 SysTryReturn(NID_UI_CTRL, (__pEditDatePresenter != null), E_SYSTEM, E_SYSTEM,
540 "[E_SYSTEM] A system error has occurred. The _EditDatePresenter instance is null.");
542 return __pEditDatePresenter->SetMaxYear(maxYear.ToInt());
546 _EditDate::GetYearRange(int& minYear, int& maxYear) const
548 result r = E_SUCCESS;
550 minYear = GetMinYearRange();
551 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, null, r, "[%s] Propagating.", GetErrorMessage(r));
552 maxYear = GetMaxYearRange();
553 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, null, r, "[%s] Propagating.", GetErrorMessage(r));
559 _EditDate::GetMinYearRange(void) const
561 Variant minYear = GetProperty("minYearRange");
563 return minYear.ToInt();
567 _EditDate::GetMaxYearRange(void) const
569 Variant maxYear = GetProperty("maxYearRange");
571 return maxYear.ToInt();
575 _EditDate::GetPropertyMinYearRange(void) const
577 SysTryReturn(NID_UI_CTRL, (__pEditDatePresenter != null), Variant(), E_SYSTEM,
578 "[E_SYSTEM] A system error has occurred. The _EditDatePresenter instance is null.");
582 minYear = __pEditDatePresenter->GetMinYear();
584 return Variant(minYear);
588 _EditDate::GetPropertyMaxYearRange(void) const
590 SysTryReturn(NID_UI_CTRL, (__pEditDatePresenter != null), Variant(), E_SYSTEM,
591 "[E_SYSTEM] A system error has occurred. The _EditDatePresenter instance is null.");
595 maxYear = __pEditDatePresenter->GetMaxYear();
597 return Variant(maxYear);
601 _EditDate::CalculateDateTimeBarPosition(void)
603 result r = E_SUCCESS;
605 float dateTimeBarHeight = 0.0f;
606 float arrowHeight = 0.0f;
607 float dateHeight = 0.0f;
608 float dateBarMargin = 0.0f;
609 float textHeight = 0.0f;
610 float titleDateMargin = 0.0f;
611 float bottomPosition = 0.0f;
614 FloatRectangle absoluteBounds;
615 FloatRectangle frameBounds;
616 FloatRectangle parentWindowBounds;
617 FloatRectangle titleBounds;
619 _Frame* pFrame = dynamic_cast<_Frame*>(_ControlManager::GetInstance()->GetCurrentFrame());
620 SysTryReturn(NID_UI_CTRL, pFrame != null, E_SYSTEM, E_SYSTEM,
621 "[E_SYSTEM] A system error has occurred. Failed to get frame instance.");
623 absoluteBounds = GetAbsoluteBoundsF();
624 frameBounds = pFrame->GetAbsoluteBoundsF();
625 parentWindowBounds = GetParentWindowBounds();
626 titleBounds = __pEditDatePresenter->GetTitleBounds();
628 GET_SHAPE_CONFIG(DATETIMEBAR::ITEM_HEIGHT, GetOrientation(), dateTimeBarHeight);
629 GET_SHAPE_CONFIG(DATETIMEBAR::ARROW_HEIGHT, GetOrientation(), arrowHeight);
630 GET_SHAPE_CONFIG(EDITDATE::DATE_HEIGHT, GetOrientation(), dateHeight);
631 GET_SHAPE_CONFIG(EDITDATE::DATE_BAR_MARGIN, GetOrientation(), dateBarMargin);
632 GET_SHAPE_CONFIG(EDITDATE::TITLE_HEIGHT, GetOrientation(), textHeight);
633 GET_SHAPE_CONFIG(EDITDATE::TITLE_DATE_MARGIN, GetOrientation(), titleDateMargin);
635 if (!__title.IsEmpty()) //with title
637 dateY = titleBounds.y + textHeight + titleDateMargin ;
641 dateY = (absoluteBounds.height - dateHeight) / 2.0f ;
644 bottomPosition = absoluteBounds.y + dateY + dateHeight + dateBarMargin + arrowHeight + dateTimeBarHeight;
646 GetDateTimeBar()->SetParentWindowBounds(parentWindowBounds);
648 if (bottomPosition > frameBounds.y + parentWindowBounds.y + parentWindowBounds.height)
650 r = GetDateTimeBar()->SetPositionAndAlignment(FloatPoint(parentWindowBounds.x, absoluteBounds.y + dateY - dateBarMargin - arrowHeight), DATETIME_BAR_ALIGN_UP);
651 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
655 r = GetDateTimeBar()->SetPositionAndAlignment(FloatPoint(parentWindowBounds.x, absoluteBounds.y + dateY + dateHeight + dateBarMargin + arrowHeight), DATETIME_BAR_ALIGN_DOWN);
656 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
659 __absoluteBounds = absoluteBounds;
665 _EditDate::OnDraw(void)
667 if (GetDateTimeBar() != null)
669 FloatRectangle absoluteBounds = GetAbsoluteBoundsF();
671 if (absoluteBounds.y != __absoluteBounds.y || absoluteBounds.height != __absoluteBounds.height)
673 CalculateDateTimeBarPosition();
677 __pEditDatePresenter->Draw();
682 _EditDate::CreateAccessibilityElement(void)
684 _AccessibilityContainer* pContainer = GetAccessibilityContainer();
686 FloatRectangle dayBounds = __pEditDatePresenter->GetDateAreaBounds(DATETIME_ID_DAY);
687 FloatRectangle monthBounds = __pEditDatePresenter->GetDateAreaBounds(DATETIME_ID_MONTH);
688 FloatRectangle yearBounds = __pEditDatePresenter->GetDateAreaBounds(DATETIME_ID_YEAR);
690 if (__pAccessibilityEditDateElement == null)
692 __pAccessibilityEditDateElement = new _AccessibilityElement(true);
693 __pAccessibilityEditDateElement->SetBounds(GetClientBoundsF());
694 __pAccessibilityEditDateElement->SetTrait(ACCESSIBILITY_TRAITS_NONE);
695 __pAccessibilityEditDateElement->SetName("EditDateText");
696 pContainer->AddElement(*__pAccessibilityEditDateElement);
699 if (__pAccessibilityYearElement == null && __pAccessibilityMonthElement == null && __pAccessibilityDayElement == null)
701 String hintText(L"Double tap to edit");
703 __pAccessibilityYearElement = new _AccessibilityElement(true);
704 __pAccessibilityYearElement->SetBounds(yearBounds);
705 __pAccessibilityYearElement->SetTraitWithStringId("IDS_TPLATFORM_BODY_YEAR_LC");
706 __pAccessibilityYearElement->SetHint(hintText);
708 __pAccessibilityMonthElement = new _AccessibilityElement(true);
709 __pAccessibilityMonthElement->SetBounds(monthBounds);
710 __pAccessibilityMonthElement->SetTraitWithStringId("IDS_TPLATFORM_BODY_MONTH_LC");
711 __pAccessibilityMonthElement->SetHint(hintText);
713 __pAccessibilityDayElement = new _AccessibilityElement(true);
714 __pAccessibilityDayElement->SetBounds(dayBounds);
715 __pAccessibilityDayElement->SetTraitWithStringId("IDS_TPLATFORM_BODY_DAY_LC");
716 __pAccessibilityDayElement->SetHint(hintText);
718 _DateTimeUtils dateTimeUtils;
719 int localeDateFormat = dateTimeUtils.GetLocaleDateFormat();
721 switch (localeDateFormat)
723 case DATE_FORMAT_DDMMYYYY:
724 pContainer->AddElement(*__pAccessibilityDayElement);
725 pContainer->AddElement(*__pAccessibilityMonthElement);
726 pContainer->AddElement(*__pAccessibilityYearElement);
728 case DATE_FORMAT_MMDDYYYY:
729 pContainer->AddElement(*__pAccessibilityMonthElement);
730 pContainer->AddElement(*__pAccessibilityDayElement);
731 pContainer->AddElement(*__pAccessibilityYearElement);
733 case DATE_FORMAT_YYYYMMDD:
734 pContainer->AddElement(*__pAccessibilityYearElement);
735 pContainer->AddElement(*__pAccessibilityMonthElement);
736 pContainer->AddElement(*__pAccessibilityDayElement);
738 case DATE_FORMAT_YYYYDDMM:
739 pContainer->AddElement(*__pAccessibilityYearElement);
740 pContainer->AddElement(*__pAccessibilityDayElement);
741 pContainer->AddElement(*__pAccessibilityMonthElement);
746 UpdateAccessibilityElement();
751 _EditDate::OnBoundsChanged(void)
753 FloatDimension newSize = GetSizeF();
755 if (newSize.width != __previousSize.width || newSize.height != __previousSize.height)
757 __isCalledBoundsChanged = true;
760 __pEditDatePresenter->Initialize();
762 if (__pAccessibilityEditDateElement)
764 __pAccessibilityEditDateElement->SetBounds(GetClientBoundsF());
766 if (__pAccessibilityYearElement)
768 __pAccessibilityYearElement->SetBounds(__pEditDatePresenter->GetDateAreaBounds(DATETIME_ID_YEAR));
770 if (__pAccessibilityMonthElement)
772 __pAccessibilityMonthElement->SetBounds(__pEditDatePresenter->GetDateAreaBounds(DATETIME_ID_MONTH));
774 if (__pAccessibilityDayElement)
776 __pAccessibilityDayElement->SetBounds(__pEditDatePresenter->GetDateAreaBounds(DATETIME_ID_DAY));
783 _EditDate::OnChangeLayout(_ControlRotation rotation)
785 if (!__isCalledBoundsChanged && !__isXmlBoundsExist)
787 FloatRectangle bounds = GetBoundsF();
789 GET_SHAPE_CONFIG(EDITDATE::WIDTH, GetOrientation(), bounds.width);
790 GET_SHAPE_CONFIG(EDITDATE::HEIGHT, GetOrientation(), bounds.height);
792 SetBounds(bounds, false);
795 __pEditDatePresenter->Initialize();
796 __pEditDatePresenter->SetLastSelectedId(DATETIME_ID_NONE);
798 if (GetDateTimeBar() != null)
800 GetDateTimeBar()->SetVisibleState(false);
801 GetDateTimeBar()->Close();
808 _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();
955 UpdateAccessibilityElement();
964 _EditDate::OnKeyPressed(const _Control &source, const _KeyInfo &keyInfo)
966 _KeyCode keyCode = keyInfo.GetKeyCode();
973 FloatRectangle absoluteBounds = GetAbsoluteBoundsF();
975 if (absoluteBounds.y != __absoluteBounds.y || absoluteBounds.height != __absoluteBounds.height)
977 CalculateDateTimeBarPosition();
986 return __pEditDatePresenter->OnKeyPressed(source, keyInfo);
990 _EditDate::OnFocusGained(const _Control &source)
992 __pEditDatePresenter->SetFocusedElement();
997 _EditDate::OnFocusLost(const _Control &source)
999 __pEditDatePresenter->OnFocusLost(source);
1004 _EditDate::OnFocusModeStateChanged(void)
1006 __pEditDatePresenter->OnFocusModeStateChanged();
1011 _EditDate::OnDrawFocus(void)
1013 __pEditDatePresenter->SetFocusedElement();
1014 __pEditDatePresenter->SetFocusState(true);
1020 _EditDate::GetParentWindowBounds(void) const
1022 _Form* pForm = null;
1023 _Window* pwindow = null;
1024 _Control* pControlCore = GetParent();
1026 FloatDimension dateTimeBarSize(0.0f, 0.0f);
1027 GET_DIMENSION_CONFIG(DATETIMEBAR::DEFAULT_SIZE, GetOrientation(), dateTimeBarSize);
1028 FloatRectangle parentWindowBounds(0.0f, 0.0f, dateTimeBarSize.width, dateTimeBarSize.height);
1032 if (pControlCore == null)
1034 SysLog(NID_UI_CTRL,"[E_SYSTEM] Parent window not found.");
1036 return parentWindowBounds;
1039 // If the parent is a Frame, then return the Form's bounds.
1040 pForm = dynamic_cast<_Form*>(pControlCore);
1043 parentWindowBounds = pForm->GetBoundsF();
1047 pwindow = dynamic_cast<_Window*>(pControlCore);
1049 if (pwindow != null)
1051 parentWindowBounds = pwindow->GetBoundsF();
1055 pControlCore = pControlCore->GetParent();
1058 return parentWindowBounds;
1062 _EditDate::UpdateAccessibilityElement(void)
1069 if (__pAccessibilityEditDateElement == null)
1074 if (__title.IsEmpty() == false)
1076 string.Append(__title);
1077 string.Append(L", ");
1080 yearString.Append(GetYear());
1081 dayString.Append(GetDay());
1082 String monthString = GetDateTimeBar()->GetMonthValue(GetMonth()).GetPointer();
1084 _DateTimeUtils dateTimeUtils;
1085 int localeDateFormat = dateTimeUtils.GetLocaleDateFormat();
1087 switch (localeDateFormat)
1089 case DATE_FORMAT_DDMMYYYY:
1090 string.Append(dayString.GetPointer());
1091 string.Append(space.GetPointer());
1092 string.Append(monthString.GetPointer());
1093 string.Append(space.GetPointer());
1094 string.Append(yearString.GetPointer());
1096 case DATE_FORMAT_MMDDYYYY:
1097 string.Append(monthString.GetPointer());
1098 string.Append(space.GetPointer());
1099 string.Append(dayString.GetPointer());
1100 string.Append(space.GetPointer());
1101 string.Append(yearString.GetPointer());
1103 case DATE_FORMAT_YYYYMMDD:
1104 string.Append(yearString.GetPointer());
1105 string.Append(space.GetPointer());
1106 string.Append(monthString.GetPointer());
1107 string.Append(space.GetPointer());
1108 string.Append(dayString.GetPointer());
1110 case DATE_FORMAT_YYYYDDMM:
1111 string.Append(yearString.GetPointer());
1112 string.Append(space.GetPointer());
1113 string.Append(dayString.GetPointer());
1114 string.Append(space.GetPointer());
1115 string.Append(monthString.GetPointer());
1121 __pAccessibilityEditDateElement->SetLabel(string);
1122 __pAccessibilityDayElement->SetLabel(dayString);
1123 __pAccessibilityMonthElement->SetLabel(monthString);
1124 __pAccessibilityYearElement->SetLabel(yearString);
1126 FloatRectangle dayBounds = __pEditDatePresenter->GetDateAreaBounds(DATETIME_ID_DAY);
1127 FloatRectangle monthBounds = __pEditDatePresenter->GetDateAreaBounds(DATETIME_ID_MONTH);
1128 FloatRectangle yearBounds = __pEditDatePresenter->GetDateAreaBounds(DATETIME_ID_YEAR);
1130 __pAccessibilityDayElement->SetBounds(dayBounds);
1131 __pAccessibilityMonthElement->SetBounds(monthBounds);
1132 __pAccessibilityYearElement->SetBounds(yearBounds);
1138 _EditDate::SetXmlBoundsExist(bool isXmlBoundsExist)
1140 __isXmlBoundsExist = isXmlBoundsExist;
1144 _EditDate::OnVisibleStateChanged(void)
1146 if (__pEditDatePresenter->GetLastSelectedId() != DATETIME_ID_NONE)
1148 __pEditDatePresenter->SetLastSelectedId(DATETIME_ID_NONE);
1154 _EditDate::OnAncestorVisibleStateChanged(const _Control& control)
1156 if (GetDateTimeBar() != null && GetDateTimeBar()->IsActivated())
1158 GetDateTimeBar()->Close();
1159 __pEditDatePresenter->SetLastSelectedId(DATETIME_ID_NONE);
1165 _EditDate::OnAncestorEnableStateChanged(const _Control& control)
1169 if (GetDateTimeBar() != null && GetDateTimeBar()->IsActivated())
1171 GetDateTimeBar()->Close();
1172 __pEditDatePresenter->SetLastSelectedId(DATETIME_ID_NONE);
1178 }}} // Tizen::Ui::Controls