2 // Open Service Platform
3 // Copyright (c) 2012-2013 Samsung Electronics Co., Ltd.
5 // Licensed under the Flora License, Version 1.0 (the License);
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
9 // http://floralicense.org/license/
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an AS IS BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
19 * @file FUiCtrl_EditDatePresenter.cpp
20 * @brief This is the implementation file for the _EditDatePresenter class.
24 #include <FGrp_TextTextObject.h>
25 #include <FGrp_TextTextSimple.h>
26 #include <FGrp_CanvasImpl.h>
27 #include <FGrp_FontImpl.h>
28 #include "FUi_ResourceManager.h"
29 #include "FUiCtrl_EditDatePresenter.h"
30 #include "FUiCtrl_EditDate.h"
31 #include "FUiCtrl_DateTimeModel.h"
32 #include "FUiCtrl_DateTimeUtils.h"
33 #include "FUiControl.h"
34 #include "FUiAnim_VisualElement.h"
35 #include "FUiAnimVisualElementPropertyAnimation.h"
36 #include "FGrpColor.h"
37 #include "FUi_CoordinateSystemUtils.h"
39 using namespace Tizen::Graphics;
40 using namespace Tizen::Base;
41 using namespace Tizen::Graphics::_Text;
42 using namespace Tizen::Ui::Animations;
45 namespace Tizen { namespace Ui { namespace Controls
47 _EditDatePresenter::_EditDatePresenter(void)
48 : __pEditDateTimeModel(null)
50 , __dayBounds(FloatRectangle())
51 , __monthBounds(FloatRectangle())
52 , __yearBounds(FloatRectangle())
53 , __titleBounds(FloatRectangle())
54 , __datePickerEnabled(true)
55 , __selectedId(DATETIME_ID_NONE)
56 , __lastSelectedId(DATETIME_ID_NONE)
57 , __touchMoveHandled(false)
61 , __dividerLineWidth(0.0f)
62 , __dividerLineHeight(0.0f)
63 , __titleFontSize(0.0f)
64 , __dateFontSize(0.0f)
65 , __pContentProvider(null)
66 , __isAnimating(false)
67 , __isEditDateInitialized(false)
71 _EditDatePresenter::~_EditDatePresenter(void)
73 __titleObject.RemoveAll();
74 __textObject.RemoveAll();
76 delete __pEditDateTimeModel;
77 __pEditDateTimeModel = null;
81 _EditDatePresenter::CreateInstanceN(const _EditDate& editDate, const String& title)
83 _EditDatePresenter* pEditDatePresenter = new (std::nothrow) _EditDatePresenter;
84 SysTryReturn(NID_UI_CTRL, pEditDatePresenter, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
86 pEditDatePresenter->__pEditDate = const_cast <_EditDate*>(&editDate);
88 pEditDatePresenter->__pEditDateTimeModel = new (std::nothrow) _DateTimeModel;
89 SysTryCatch(NID_UI_CTRL, pEditDatePresenter->__pEditDateTimeModel, , E_OUT_OF_MEMORY,
90 "[E_OUT_OF_MEMORY] Memory allocation failed.");
91 pEditDatePresenter->SetTitle(title);
93 return pEditDatePresenter;
96 delete pEditDatePresenter;
101 _EditDatePresenter::SetTitle(const String& title)
106 _EditDatePresenter::Initialize(void)
108 result r = E_SUCCESS;
109 float editDateHeight = 0.0f;
110 float editDateWidth = 0.0f;
111 float leftMargin = 0.0f;
112 float titledateMargin = 0.0f;
113 float dateHeight = 0.0f;
114 FloatRectangle bounds(0.0f, 0.0f, 0.0f, 0.0f);
116 GET_SHAPE_CONFIG(EDITDATE::WIDTH, __pEditDate->GetOrientation(), editDateWidth);
117 GET_SHAPE_CONFIG(EDITDATE::HEIGHT, __pEditDate->GetOrientation(), editDateHeight);
118 GET_SHAPE_CONFIG(EDITDATE::DATE_TEXT_LEFT_MARGIN, __pEditDate->GetOrientation(), leftMargin);
119 GET_FIXED_VALUE_CONFIG(EDITDATE::ITEM_DIVIDER_WIDTH, __pEditDate->GetOrientation(), __dividerLineWidth);
120 GET_SHAPE_CONFIG(EDITDATE::ITEM_DIVIDER_HEIGHT, __pEditDate->GetOrientation(), __dividerLineHeight);
121 GET_SHAPE_CONFIG(EDITDATE::TEXT_FONT_SIZE, __pEditDate->GetOrientation(), __titleFontSize);
122 GET_SHAPE_CONFIG(EDITDATE::DATE_FONT_SIZE, __pEditDate->GetOrientation(), __dateFontSize);
123 GET_SHAPE_CONFIG(EDITDATE::TITLE_DATE_MARGIN, __pEditDate->GetOrientation(), titledateMargin);
124 GET_SHAPE_CONFIG(EDITDATE::DATE_HEIGHT, __pEditDate->GetOrientation(), dateHeight);
125 GET_SHAPE_CONFIG(EDITDATE::TITLE_HEIGHT, __pEditDate->GetOrientation(), __titleBounds.height);
127 if (__pEditDate->GetBoundsF().height > editDateHeight)
129 editDateHeight = __pEditDate->GetBoundsF().height;
132 __pFont = __pEditDate->GetFallbackFont();
134 SysTryReturn(NID_UI_CTRL, __pFont != null, r, r, "[%s] Propagating.", GetErrorMessage(r));
136 if (__title.IsEmpty() == false)
138 __titleBounds.x = leftMargin;
139 __titleBounds.y = (editDateHeight - (__titleBounds.height + titledateMargin + dateHeight)) / 2.0f;
140 __titleBounds.width = editDateWidth;
142 bounds.y = __titleBounds.y + __titleBounds.height + titledateMargin;
144 __dayBounds.height = dateHeight;
145 __monthBounds.height = dateHeight;
146 __yearBounds.height = dateHeight;
148 if (!__isEditDateInitialized)
150 r = InitializeTitleObject();
151 SysTryReturn(NID_UI_CTRL, (r == E_SUCCESS), r, r, "[%s] Propagating.", GetErrorMessage(r));
154 __titleObject.SetBounds(__titleBounds);
158 __dayBounds.height = editDateHeight;
159 __monthBounds.height = editDateHeight;
160 __yearBounds.height = editDateHeight;
163 float elementWidth = 0.0f;
164 GET_SHAPE_CONFIG(EDITDATE::TEXT_ELEMENT_WIDTH, __pEditDate->GetOrientation(), elementWidth);
166 __dayBounds.width = elementWidth;
167 __monthBounds.width = elementWidth;
168 __yearBounds.width = elementWidth;
170 __dayBounds.x = 0.0f;
171 __monthBounds.x = 0.0f;
172 __yearBounds.x = 0.0f;
174 __dayBounds.y = bounds.y;
175 __monthBounds.y = bounds.y;
176 __yearBounds.y = bounds.y;
178 if (!__isEditDateInitialized)
180 r = InitializeTextObject();
181 SysTryReturn(NID_UI_CTRL, (r == E_SUCCESS), r, r, "[%s] Propagating.", GetErrorMessage(r));
184 __isEditDateInitialized = true;
186 CalculateAreaBounds();
192 _EditDatePresenter::InitializeTitleObject(void)
194 result r = E_SUCCESS;
196 Color titleNormalColor;
198 GET_COLOR_CONFIG(EDITDATE::TITLE_TEXT_NORMAL, titleNormalColor);
200 r = __titleObject.Construct();
201 SysTryReturn(NID_UI_CTRL, (r == E_SUCCESS), r, r, "[%s] Propagating.", GetErrorMessage(r));
203 TextSimple* pSimpleText = null;
205 pSimpleText = new (std::nothrow)TextSimple((const_cast <wchar_t*>(__title.GetPointer())), __title.GetLength(), TEXT_ELEMENT_SOURCE_TYPE_EXTERNAL);
206 SysTryReturn(NID_UI_CTRL, (pSimpleText != null), E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
208 __titleObject.AppendElement(*pSimpleText);
210 __titleObject.SetForegroundColor(titleNormalColor, 0, __titleObject.GetTextLength());
211 __titleObject.SetFont(__pFont, 0, __titleObject.GetTextLength());
212 __titleObject.SetAlignment(TEXT_OBJECT_ALIGNMENT_LEFT | TEXT_OBJECT_ALIGNMENT_MIDDLE);
213 __titleObject.SetWrap(TEXT_OBJECT_WRAP_TYPE_NONE);
214 __titleObject.SetAction(TEXT_OBJECT_ACTION_TYPE_ABBREV);
220 _EditDatePresenter::InitializeTextObject(void)
222 result r = E_SUCCESS;
224 r = __textObject.Construct();
225 SysTryReturn(NID_UI_CTRL, (r == E_SUCCESS), r, r, "[%s] Propagating.", GetErrorMessage(r));
227 TextSimple* pSimpleText = null;
229 pSimpleText = new (std::nothrow)TextSimple(null, 0, TEXT_ELEMENT_SOURCE_TYPE_EXTERNAL);
230 SysTryReturn(NID_UI_CTRL, (pSimpleText != null), E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
232 __textObject.AppendElement(*pSimpleText);
234 __textObject.SetFont(__pFont, 0, __textObject.GetTextLength());
235 __textObject.SetAlignment(TEXT_OBJECT_ALIGNMENT_CENTER | TEXT_OBJECT_ALIGNMENT_MIDDLE);
236 __textObject.SetWrap(TEXT_OBJECT_WRAP_TYPE_NONE);
237 __textObject.SetAction(TEXT_OBJECT_ACTION_TYPE_ABBREV);
243 _EditDatePresenter::GetLocaleDateFormat(void) const
245 int localeDateFormat = -1;
246 int error = vconf_get_int(VCONFKEY_SETAPPL_DATE_FORMAT_INT, &localeDateFormat);
249 localeDateFormat = SETTING_DATE_FORMAT_DD_MM_YYYY;
252 return localeDateFormat;
256 _EditDatePresenter::GetDate(void) const
258 SysAssertf((__pEditDateTimeModel != null), "The _EditDateTimeModel instance is null.");
261 date.SetValue(GetYear(), GetMonth(), GetDay(), DATETIME_HOUR_MIN, DATETIME_MINUTE_MIN);
267 _EditDatePresenter::GetDay(void) const
269 SysAssertf((__pEditDateTimeModel != null), "The _EditDateTimeModel instance is null.");
271 return __pEditDateTimeModel->GetDay();
275 _EditDatePresenter::GetMonth(void) const
277 SysAssertf((__pEditDateTimeModel != null), "The _EditDateTimeModel instance is null.");
279 return __pEditDateTimeModel->GetMonth();
283 _EditDatePresenter::GetYear(void) const
285 SysAssertf((__pEditDateTimeModel != null), "The _EditDateTimeModel instance is null.");
287 return __pEditDateTimeModel->GetYear();
291 _EditDatePresenter::SetDate(const DateTime& date)
293 SysAssertf((__pEditDateTimeModel != null), "The _EditDateTimeModel instance is null.");
295 __pEditDateTimeModel->SetDateTime(date);
300 _EditDatePresenter::SetCurrentDate(void)
302 SysAssertf((__pEditDateTimeModel != null), "The _EditDateTimeModel instance is null.");
304 __pEditDateTimeModel->SetCurrentDateTime();
309 _EditDatePresenter::SetYear(int year)
311 SysAssertf((__pEditDateTimeModel != null), "The _EditDateTimeModel instance is null.");
313 return __pEditDateTimeModel->SetYear(year);
317 _EditDatePresenter::SetMonth(int month)
319 SysAssertf((__pEditDateTimeModel != null), "The _EditDateTimeModel instance is null.");
321 return __pEditDateTimeModel->SetMonth(month);
325 _EditDatePresenter::SetDay(int day)
327 SysAssertf((__pEditDateTimeModel != null), "The _EditDateTimeModel instance is null.");
329 return __pEditDateTimeModel->SetDay(day);
333 _EditDatePresenter::SetDatePickerEnabled(bool enable)
335 __datePickerEnabled = enable;
340 _EditDatePresenter::IsDatePickerEnabled(void) const
342 return __datePickerEnabled;
346 _EditDatePresenter::SetMinYear(int minYear)
348 return __pEditDateTimeModel->SetMinYear(minYear);
352 _EditDatePresenter::SetMaxYear(int maxYear)
354 return __pEditDateTimeModel->SetMaxYear(maxYear);
358 _EditDatePresenter::GetMinYear(void) const
363 __pEditDateTimeModel->GetYearRange(minYear, maxYear);
369 _EditDatePresenter::GetMaxYear(void) const
374 __pEditDateTimeModel->GetYearRange(minYear, maxYear);
380 _EditDatePresenter::Draw(void)
382 result r = E_SUCCESS;
389 Canvas* pCanvas = __pEditDate->GetCanvasN();
390 SysAssertf((pCanvas != null), "Failed to get canvas.");
392 pCanvas->SetBackgroundColor(Color(0, 0, 0, 0));
395 if (__title.IsEmpty() == false)
404 _DateTimeUtils dateTimeUtils;
405 monthString = dateTimeUtils.GetMonthString(GetMonth());
406 yearString.Format(10, L"%04d", GetYear());
407 dayString.Format(10, L"%02d", GetDay());
409 CalculateAreaBounds();
411 r = DrawText(*pCanvas, GetDateAreaBounds(DATETIME_ID_DAY), dayString);
412 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
413 r = DrawText(*pCanvas, GetDateAreaBounds(DATETIME_ID_MONTH), monthString);
414 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
415 r = DrawText(*pCanvas, GetDateAreaBounds(DATETIME_ID_YEAR), yearString);
416 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
418 r = DrawDividers(*pCanvas);
419 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
431 _EditDatePresenter::CalculateAreaBounds(void)
433 result r = E_SUCCESS;
435 if (GetLocaleDateFormat() == DATE_FORMAT_DDMMYYYY)
437 __monthBounds.x = __dayBounds.x + __dayBounds.width + __dividerLineWidth;
438 __yearBounds.x = __monthBounds.x + __monthBounds.width + __dividerLineWidth;
440 else if (GetLocaleDateFormat() == DATE_FORMAT_MMDDYYYY)
442 __dayBounds.x = __monthBounds.x + __monthBounds.width + __dividerLineWidth;
443 __yearBounds.x = __dayBounds.x + __dayBounds.width + __dividerLineWidth;
445 else if (GetLocaleDateFormat() == DATE_FORMAT_YYYYMMDD)
447 __monthBounds.x = __yearBounds.x + __yearBounds.width + __dividerLineWidth;
448 __dayBounds.x = __monthBounds.x + __monthBounds.width + __dividerLineWidth;
450 else if (GetLocaleDateFormat() == DATE_FORMAT_YYYYDDMM)
452 __dayBounds.x = __yearBounds.x + __yearBounds.width + __dividerLineWidth;
453 __monthBounds.x = __dayBounds.x + __dayBounds.width + __dividerLineWidth;
460 _EditDatePresenter::DrawTitle(Canvas& canvas)
462 if (!__pEditDate->IsEnabled())
464 Color titleDisabledColor;
465 GET_COLOR_CONFIG(EDITDATE::TITLE_TEXT_DISABLED, titleDisabledColor);
466 __titleObject.SetForegroundColor(titleDisabledColor, 0, __titleObject.GetTextLength());
469 (_FontImpl::GetInstance(*__pFont))->SetSize(__titleFontSize);
470 __titleObject.SetFont(__pFont, 0, __titleObject.GetTextLength());
471 __titleObject.Draw(*_CanvasImpl::GetInstance(canvas));
477 _EditDatePresenter::DrawText(Canvas& canvas, const FloatRectangle& bounds, const String& text)
481 if (!__pEditDate->IsEnabled())
483 GET_COLOR_CONFIG(EDITDATE::TEXT_DISABLED, textColor);
487 GET_COLOR_CONFIG(EDITDATE::TEXT_NORMAL, textColor);
490 _DateTimeId boxId = DATETIME_ID_NONE;
491 boxId = GetBoxIdFromPosition(FloatPoint(bounds.x, bounds.y));
493 if (boxId == __selectedId && boxId != DATETIME_ID_NONE)
495 GET_COLOR_CONFIG(EDITDATE::TEXT_PRESSED, textColor);
498 FloatRectangle drawAreaBounds(0.0f, 0.0f, 0.0f, 0.0f);
499 drawAreaBounds = bounds;
501 TextSimple* pSimpleText = null;
502 pSimpleText = new (std::nothrow)TextSimple((const_cast <wchar_t*>(text.GetPointer())), text.GetLength(), TEXT_ELEMENT_SOURCE_TYPE_EXTERNAL);
503 SysTryReturn(NID_UI_CTRL, (pSimpleText != null), E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
505 __textObject.RemoveAll();
507 (_FontImpl::GetInstance(*__pFont))->SetSize(__dateFontSize);
509 __textObject.AppendElement(*pSimpleText);
511 __textObject.SetFont(__pFont, 0, __textObject.GetTextLength());
512 __textObject.SetForegroundColor(textColor, 0, __textObject.GetTextLength());
513 __textObject.SetBounds(drawAreaBounds);
514 __textObject.Draw(*_CanvasImpl::GetInstance(canvas));
520 _EditDatePresenter::DrawDividers(Canvas& canvas)
522 result r = E_SUCCESS;
524 float elementWidth = 0.0f;
525 float editDateHeight = 0.0f;
526 float dateHeight = 0.0f;
528 GET_SHAPE_CONFIG(EDITDATE::TEXT_ELEMENT_WIDTH, __pEditDate->GetOrientation(), elementWidth);
529 GET_SHAPE_CONFIG(EDITDATE::DATE_HEIGHT, __pEditDate->GetOrientation(), dateHeight);
530 GET_SHAPE_CONFIG(EDITDATE::HEIGHT, __pEditDate->GetOrientation(), editDateHeight);
532 if (__pEditDate->GetBoundsF().height > editDateHeight)
534 editDateHeight = __pEditDate->GetBoundsF().height;
537 Color dividerHalfLeftColor;
538 Color dividerHalfRightColor;
540 GET_COLOR_CONFIG(EDITDATE::DIVIDER_LEFT_HALF, dividerHalfLeftColor);
541 GET_COLOR_CONFIG(EDITDATE::DIVIDER_RIGHT_HALF, dividerHalfRightColor);
543 FloatRectangle bounds(0.0f, 0.0f, 0.0f, 0.0f);
545 bounds.x = elementWidth;
547 if (__title.IsEmpty() == false)
549 bounds.y = __dayBounds.y + ((dateHeight - __dividerLineHeight) / 2.0f);
553 bounds.y = __dayBounds.y + ((editDateHeight - __dividerLineHeight) / 2.0f);
556 for (int divider = 0; divider < __dividerCount; divider++)
558 canvas.SetForegroundColor(dividerHalfLeftColor);
559 canvas.SetLineWidth(__dividerLineWidth / 2.0f);
561 r = canvas.DrawLine(FloatPoint(bounds.x, bounds.y), FloatPoint(bounds.x, bounds.y + __dividerLineHeight));
562 SysTryReturnResult(NID_UI_CTRL, (r == E_SUCCESS), r, "[%s] Propagating.", GetErrorMessage(r));
564 canvas.SetForegroundColor(dividerHalfRightColor);
565 canvas.SetLineWidth(__dividerLineWidth / 2.0f);
567 r = canvas.DrawLine(FloatPoint(bounds.x + 1.0f, bounds.y), FloatPoint(bounds.x + 1.0f, bounds.y + __dividerLineHeight));
568 SysTryReturnResult(NID_UI_CTRL, (r == E_SUCCESS), r, "[%s] Propagating.", GetErrorMessage(r));
570 bounds.x = bounds.x + elementWidth;
576 _EditDatePresenter::GetBoxIdFromPosition(const FloatPoint& point) const
578 _DateTimeId displayBoxId = DATETIME_ID_NONE;
580 if (point.y < __dayBounds.y || point.y > __dayBounds.y + __dayBounds.height)
585 if (__dayBounds.Contains(point) == true)
587 displayBoxId = DATETIME_ID_DAY;
589 else if (__monthBounds.Contains(point) == true)
591 displayBoxId = DATETIME_ID_MONTH;
593 else if (__yearBounds.Contains(point) == true)
595 displayBoxId = DATETIME_ID_YEAR;
602 _EditDatePresenter::GetDateAreaBounds(_DateTimeId id) const
604 if (id == DATETIME_ID_DAY)
608 else if (id == DATETIME_ID_MONTH)
610 return __monthBounds;
612 else if (id == DATETIME_ID_YEAR)
618 return FloatRectangle();
623 _EditDatePresenter::GetTitleBounds(void) const
625 return __titleBounds;
629 _EditDatePresenter::SetLastSelectedId(_DateTimeId boxId)
631 __lastSelectedId = boxId;
636 _EditDatePresenter::GetLastSelectedId(void) const
638 return __lastSelectedId;
642 _EditDatePresenter::OnFontChanged(Font* pFont)
646 if (__pEditDate->GetDateTimeBar() != null)
648 __pEditDate->GetDateTimeBar()->SetFont(*pFont);
655 _EditDatePresenter::OnFontInfoRequested(unsigned long& style, float& size)
657 style = FONT_STYLE_PLAIN;
658 size = __dateFontSize;
664 _EditDatePresenter::OnTouchPressed(const _Control& source, const _TouchInfo& touchinfo)
666 SysTryReturn(NID_UI_CTRL, IsDatePickerEnabled() == true, true, E_SYSTEM,
667 "[E_SYSTEM] A system error has occurred. EditDate instance is disabled.");
669 if (&source != __pEditDate)
674 __touchMoveHandled = false;
676 FloatPoint point = touchinfo.GetCurrentPosition();
678 _DateTimeId boxId = DATETIME_ID_NONE;
679 boxId = GetBoxIdFromPosition(point);
681 if (boxId < DATETIME_ID_YEAR || boxId > DATETIME_ID_DAY)
683 __selectedId = DATETIME_ID_NONE;
689 int displayValue = -1;
691 if (boxId == DATETIME_ID_DAY)
693 if (__pEditDate->GetDateTimeBar() != null)
695 _DateTimeUtils dateTimeUtils;
696 maxValue = dateTimeUtils.CalculateMaxDay(GetYear(), GetMonth());
697 minValue = DATETIME_DAY_MIN;
698 displayValue = GetDay();
701 else if (boxId == DATETIME_ID_MONTH)
703 minValue = DATETIME_MONTH_MIN;
704 maxValue = DATETIME_MONTH_MAX;
705 displayValue = GetMonth();
707 else if (boxId == DATETIME_ID_YEAR)
709 minValue = GetMinYear();
710 maxValue = GetMaxYear();
711 displayValue = GetYear();
714 if (__pEditDate->GetDateTimeBar() != null)
716 if (__pEditDate->GetDateTimeBar()->GetItemCount() > 0)
718 __pEditDate->GetDateTimeBar()->RemoveAllItems();
721 result r = __pEditDate->GetDateTimeBar()->SetInitialValue(minValue, maxValue, displayValue, boxId);
724 __selectedId = DATETIME_ID_NONE;
729 __selectedId = boxId;
731 __pEditDate->Invalidate();
737 _EditDatePresenter::OnTouchReleased(const _Control& source, const _TouchInfo& touchinfo)
739 SysTryReturn(NID_UI_CTRL, IsDatePickerEnabled() == true, true, E_SYSTEM,
740 "[E_SYSTEM] A system error has occurred. EditDate instance is disabled.");
742 if (&source != __pEditDate)
747 FloatPoint point = touchinfo.GetCurrentPosition();
749 _DateTimeId boxId = DATETIME_ID_NONE;
750 boxId = GetBoxIdFromPosition(point);
752 if (boxId != __selectedId)
754 __selectedId = DATETIME_ID_NONE;
757 SetLastSelectedId(__selectedId);
758 __selectedId = DATETIME_ID_NONE;
760 __lastSelectedValue = "";
761 _DateTimeUtils dateTimeUtils;
762 if (GetLastSelectedId() == DATETIME_ID_YEAR)
764 __lastSelectedValue.Format(10, L"%04d", GetYear());
765 PLAY_FEEDBACK(_RESOURCE_FEEDBACK_PATTERN_TAP);
767 else if (GetLastSelectedId() == DATETIME_ID_MONTH)
769 __lastSelectedValue = dateTimeUtils.GetMonthString(GetMonth());
770 PLAY_FEEDBACK(_RESOURCE_FEEDBACK_PATTERN_TAP);
772 else if (GetLastSelectedId() == DATETIME_ID_DAY)
774 __lastSelectedValue.Format(10, L"%02d", GetDay());
775 PLAY_FEEDBACK(_RESOURCE_FEEDBACK_PATTERN_TAP);
778 __pEditDate->Invalidate();
780 if (__pEditDate->GetDateTimeBar() != null && GetLastSelectedId() != DATETIME_ID_NONE)
782 FloatRectangle bounds(0.0f, 0.0f, 0.0f, 0.0f);
783 bounds = GetDateAreaBounds(GetLastSelectedId());
784 FloatRectangle absoluteBounds(0.0f, 0.0f, 0.0f, 0.0f);
785 absoluteBounds = __pEditDate->GetAbsoluteBoundsF();
786 bounds.x += absoluteBounds.x;
788 __pEditDate->GetDateTimeBar()->CalculateArrowBounds(bounds);
789 __pEditDate->GetDateTimeBar()->SetVisibleState(true);
790 __pEditDate->GetDateTimeBar()->Close();
791 __pEditDate->GetDateTimeBar()->Open();
798 _EditDatePresenter::OnTouchCanceled(const _Control& source, const _TouchInfo& touchinfo)
800 if (&source != __pEditDate)
805 __selectedId = DATETIME_ID_NONE;
807 __pEditDate->Invalidate();
813 _EditDatePresenter::OnTouchMoved(const _Control& source, const _TouchInfo& touchinfo)
815 if (&source != __pEditDate)
820 FloatPoint touchPoint = touchinfo.GetCurrentPosition();
822 if (GetBoxIdFromPosition(touchPoint) != __selectedId)
824 __selectedId = DATETIME_ID_NONE;
827 __pEditDate->Invalidate();
832 _EditDatePresenter::OnTouchMoveHandled(const _Control& control)
834 __touchMoveHandled = true;
835 __selectedId = DATETIME_ID_NONE;
836 __pEditDate->Invalidate();
841 _EditDatePresenter::Animate(void)
843 SysAssertf((__pFont != null), "Font instance must not be null.");
845 (_FontImpl::GetInstance(*__pFont))->SetSize(__dateFontSize);
847 result r = E_SUCCESS;
854 _DateTimeUtils dateTimeUtils;
855 monthString = dateTimeUtils.GetMonthString(GetMonth());
856 yearString.Format(10, L"%04d", GetYear());
857 dayString.Format(10, L"%02d", GetDay());
859 if (GetLastSelectedId() == DATETIME_ID_DAY)
861 SysTryReturnVoidResult(NID_UI_CTRL, (__lastSelectedValue.Equals(dayString) == false), E_SUCCESS, "Day string matched.");
863 newValue = dayString;
864 rect = GetDateAreaBounds(DATETIME_ID_DAY);
866 else if (GetLastSelectedId() == DATETIME_ID_MONTH)
868 SysTryReturnVoidResult(NID_UI_CTRL, (__lastSelectedValue.Equals(monthString) == false), E_SUCCESS, "Month string matched.");
870 newValue = monthString;
871 rect = GetDateAreaBounds(DATETIME_ID_MONTH);
873 else if (GetLastSelectedId() == DATETIME_ID_YEAR)
875 SysTryReturnVoidResult(NID_UI_CTRL, (__lastSelectedValue.Equals(yearString) == false), E_SUCCESS, "Year string matched.");
877 newValue = yearString;
878 rect = GetDateAreaBounds(DATETIME_ID_YEAR);
881 FloatDimension newTextDim;
882 FloatDimension oldTextDim;
883 FloatPoint textPoint;
884 VisualElement* pNewVisualElement = null;
885 VisualElement* pOldVisualElement = null;
886 VisualElement* pEditDateElement = null;
887 VisualElementPropertyAnimation* pNewBoundsAnimation = null;
888 VisualElementPropertyAnimation* pOldBoundsAnimation = null;
889 Canvas *pCanvas = null;
891 __pFont->GetTextExtent(newValue, newValue.GetLength(), newTextDim);
892 __pFont->GetTextExtent(__lastSelectedValue, __lastSelectedValue.GetLength(), oldTextDim);
894 if (newTextDim.width > oldTextDim.width)
896 textPoint.x = (rect.width - newTextDim.width) / 2.0f;
900 textPoint.x = (rect.width - oldTextDim.width) / 2.0f;
903 SysTryReturnVoidResult(NID_UI_CTRL, (rect.x + textPoint.x < __pEditDate->GetBoundsF().width), E_SUCCESS, "Rolling animation cann't be played.");
905 __isAnimating = true;
907 __pContentProvider = new (std::nothrow) VisualElement();
908 SysTryReturnVoidResult(NID_UI_CTRL, (__pContentProvider != null), E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
910 r = __pContentProvider->Construct();
911 SysTryCatch(NID_UI_CTRL, (r == E_SUCCESS), , r, "[%s] Propagating.", GetErrorMessage(r));
913 __pContentProvider->SetShowState(true);
914 __pContentProvider->SetClipChildrenEnabled(true);
915 __pContentProvider->SetImplicitAnimationEnabled(false);
917 pEditDateElement = __pEditDate->GetVisualElement();
919 SysTryCatch(NID_UI_CTRL, (pEditDateElement != null), , r, "[%s] Propagating.", GetErrorMessage(r));
921 pNewVisualElement = new (std::nothrow) VisualElement();
922 SysTryCatch(NID_UI_CTRL, (pNewVisualElement != null), , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
924 r = pNewVisualElement->Construct();
927 pNewVisualElement->Destroy();
929 SysTryCatch(NID_UI_CTRL, (r == E_SUCCESS), , r, "[%s] Propagating.", GetErrorMessage(r));
931 pOldVisualElement = new (std::nothrow) VisualElement();
932 if (pOldVisualElement == null)
934 pNewVisualElement->Destroy();
936 SysTryCatch(NID_UI_CTRL, (pOldVisualElement != null), , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
938 r = pOldVisualElement->Construct();
941 pNewVisualElement->Destroy();
942 pOldVisualElement->Destroy();
944 SysTryCatch(NID_UI_CTRL, (r == E_SUCCESS), , r, "[%s] Propagating.", GetErrorMessage(r));
946 pNewVisualElement->SetShowState(true);
947 pOldVisualElement->SetShowState(true);
949 if (newTextDim.width > oldTextDim.width)
951 textPoint.x = (rect.width - newTextDim.width) / 2.0f;
952 textPoint.y = (rect.height - newTextDim.height) / 2.0f;
953 __pContentProvider->SetBounds(FloatRectangle((rect.x + textPoint.x) * 1.0f, (rect.y + textPoint.y) * 1.0f, newTextDim.width * 1.0f, newTextDim.height * 1.0f));
954 pNewVisualElement->SetBounds(FloatRectangle(0.0f, newTextDim.height * 1.0f, newTextDim.width * 1.0f, newTextDim.height * 1.0f));
956 rect.x = static_cast<int>(__pContentProvider->GetBounds().x);
957 rect.y = static_cast<int>(__pContentProvider->GetBounds().y);
958 rect.width = static_cast<int>(__pContentProvider->GetBounds().width);
959 rect.height = static_cast<int>(__pContentProvider->GetBounds().height);
961 textPoint.x = (rect.width - oldTextDim.width) / 2.0f;
962 textPoint.y = (rect.height - oldTextDim.height) / 2.0f;
964 pOldVisualElement->SetBounds(FloatRectangle(textPoint.x * 1.0f, 0.0f, oldTextDim.width * 1.0f, oldTextDim.height * 1.0f));
968 textPoint.x = (rect.width - oldTextDim.width) / 2.0f;
969 textPoint.y = (rect.height - oldTextDim.height) / 2.0f;
970 __pContentProvider->SetBounds(FloatRectangle((rect.x + textPoint.x) * 1.0f, (rect.y + textPoint.y) * 1.0f, oldTextDim.width * 1.0f, oldTextDim.height * 1.0f));
971 pOldVisualElement->SetBounds(FloatRectangle(0.0f, 0.0f, oldTextDim.width * 1.0f, oldTextDim.height * 1.0f));
973 rect.x = static_cast<int>(__pContentProvider->GetBounds().x);
974 rect.y = static_cast<int>(__pContentProvider->GetBounds().y);
975 rect.width = static_cast<int>(__pContentProvider->GetBounds().width);
976 rect.height = static_cast<int>(__pContentProvider->GetBounds().height);
978 textPoint.x = (rect.width - newTextDim.width) / 2.0f;
979 textPoint.y = (rect.height - newTextDim.height) / 2.0f;
981 pNewVisualElement->SetBounds(FloatRectangle(textPoint.x * 1.0f, newTextDim.height * 1.0f, newTextDim.width * 1.0f, newTextDim.height * 1.0f));
985 pCanvas = pEditDateElement->GetCanvasN(rect);
986 pCanvas->SetBackgroundColor(Color(0, 0, 0, 0));
990 pEditDateElement->AttachChild(*__pContentProvider);
992 __pContentProvider->AttachChild(*pOldVisualElement);
993 __pContentProvider->AttachChild(*pNewVisualElement);
995 pNewBoundsAnimation = new (std::nothrow) VisualElementPropertyAnimation();
996 SysTryCatch(NID_UI_CTRL, (pNewBoundsAnimation != null), , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
998 pNewBoundsAnimation->SetDuration(300);
999 pNewBoundsAnimation->SetPropertyName("bounds.position");
1000 pNewBoundsAnimation->SetStartValue(Variant(FloatPoint(pNewVisualElement->GetBounds().x * 1.0f, newTextDim.height * 1.0f)));
1001 pNewBoundsAnimation->SetEndValue(Variant(FloatPoint(pNewVisualElement->GetBounds().x * 1.0f, 0.0f)));
1002 pNewBoundsAnimation->SetVisualElementAnimationStatusEventListener(this);
1004 pOldBoundsAnimation = new (std::nothrow) VisualElementPropertyAnimation();
1005 SysTryCatch(NID_UI_CTRL, (pOldBoundsAnimation != null), , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
1007 pOldBoundsAnimation->SetDuration(300);
1008 pOldBoundsAnimation->SetPropertyName("bounds.position");
1009 pOldBoundsAnimation->SetStartValue(Variant(FloatPoint(pOldVisualElement->GetBounds().x * 1.0f, 0.0f)));
1010 pOldBoundsAnimation->SetEndValue(Variant(FloatPoint(pOldVisualElement->GetBounds().x * 1.0f, oldTextDim.height * -1.0f)));
1011 pOldBoundsAnimation->SetVisualElementAnimationStatusEventListener(this);
1013 pCanvas = pOldVisualElement->GetCanvasN();
1014 r = GetLastResult();
1015 SysTryCatch(NID_UI_CTRL, (pCanvas != null), , r, "[%s] Propagating.", GetErrorMessage(r));
1017 pCanvas->SetBackgroundColor(Color(0, 0, 0, 0));
1019 pCanvas->SetFont(*__pFont);
1020 pCanvas->DrawText(FloatPoint(0.0f, 0.0f), __lastSelectedValue);
1025 pCanvas = pNewVisualElement->GetCanvasN();
1026 r = GetLastResult();
1027 SysTryCatch(NID_UI_CTRL, (pCanvas != null), , r, "[%s] Propagating.", GetErrorMessage(r));
1029 pCanvas->SetBackgroundColor(Color(0, 0, 0, 0));
1031 pCanvas->SetFont(*__pFont);
1032 pCanvas->DrawText(FloatPoint(0.0f, 0.0f), newValue);
1037 pOldVisualElement->SetImplicitAnimationEnabled(false);
1038 pOldVisualElement->AddAnimation(*pOldBoundsAnimation);
1040 pNewVisualElement->SetImplicitAnimationEnabled(false);
1041 pNewVisualElement->AddAnimation(*pNewBoundsAnimation);
1043 delete pOldBoundsAnimation;
1044 delete pNewBoundsAnimation;
1049 __isAnimating = false;
1050 __pContentProvider->Destroy();
1052 delete pNewBoundsAnimation;
1053 pNewBoundsAnimation = null;
1055 delete pOldBoundsAnimation;
1056 pOldBoundsAnimation = null;
1065 _EditDatePresenter::OnVisualElementAnimationFinished (const VisualElementAnimation &animation, const String &keyName, VisualElement &target, bool completedNormally)
1067 result r = E_SUCCESS;
1068 __isAnimating = false;
1070 VisualElement* pEditDateElement = __pEditDate->GetVisualElement();
1071 r = GetLastResult();
1072 SysTryReturnVoidResult(NID_UI_CTRL, (pEditDateElement != null), r, "[%s] Propagating.", GetErrorMessage(r));
1074 pEditDateElement->DetachChild(*__pContentProvider);
1075 __pContentProvider->Destroy();
1081 }}} // Tizen::Ui::Controls