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;
734 _EditDatePresenter::OnTouchReleased(const _Control& source, const _TouchInfo& touchinfo)
736 SysTryReturn(NID_UI_CTRL, IsDatePickerEnabled() == true, true, E_SYSTEM,
737 "[E_SYSTEM] A system error has occurred. EditDate instance is disabled.");
739 if (&source != __pEditDate)
744 FloatPoint point = touchinfo.GetCurrentPosition();
746 _DateTimeId boxId = DATETIME_ID_NONE;
747 boxId = GetBoxIdFromPosition(point);
748 if (boxId != __selectedId || boxId == DATETIME_ID_NONE)
750 if (__pEditDate->GetDateTimeBar() != null && __pEditDate->GetDateTimeBar()->IsActivated())
752 __pEditDate->GetDateTimeBar()->SetVisibleState(false);
753 __pEditDate->GetDateTimeBar()->Close();
757 __selectedId = DATETIME_ID_NONE;
758 SetLastSelectedId(__selectedId);
763 SetLastSelectedId(__selectedId);
765 __lastSelectedValue = "";
766 _DateTimeUtils dateTimeUtils;
767 if (GetLastSelectedId() == DATETIME_ID_YEAR)
769 __lastSelectedValue.Format(10, L"%04d", GetYear());
770 PLAY_FEEDBACK(_RESOURCE_FEEDBACK_PATTERN_TAP);
772 else if (GetLastSelectedId() == DATETIME_ID_MONTH)
774 __lastSelectedValue = dateTimeUtils.GetMonthString(GetMonth());
775 PLAY_FEEDBACK(_RESOURCE_FEEDBACK_PATTERN_TAP);
777 else if (GetLastSelectedId() == DATETIME_ID_DAY)
779 __lastSelectedValue.Format(10, L"%02d", GetDay());
780 PLAY_FEEDBACK(_RESOURCE_FEEDBACK_PATTERN_TAP);
785 if ((__pEditDate->GetDateTimeBar() != null) && (GetLastSelectedId() != DATETIME_ID_NONE))
787 FloatRectangle bounds(0.0f, 0.0f, 0.0f, 0.0f);
788 bounds = GetDateAreaBounds(GetLastSelectedId());
789 FloatRectangle absoluteBounds(0.0f, 0.0f, 0.0f, 0.0f);
790 absoluteBounds = __pEditDate->GetAbsoluteBoundsF();
791 bounds.x += absoluteBounds.x;
793 __pEditDate->GetDateTimeBar()->CalculateArrowBounds(bounds);
795 if (__pEditDate->GetDateTimeBar()->IsActivated())
797 __pEditDate->GetDateTimeBar()->RefreshItems();
801 __pEditDate->GetDateTimeBar()->SetVisibleState(true);
802 __pEditDate->GetDateTimeBar()->Open();
806 __selectedId = DATETIME_ID_NONE;
811 _EditDatePresenter::OnTouchCanceled(const _Control& source, const _TouchInfo& touchinfo)
813 if (&source != __pEditDate)
818 __selectedId = DATETIME_ID_NONE;
824 _EditDatePresenter::OnTouchMoved(const _Control& source, const _TouchInfo& touchinfo)
826 if (&source != __pEditDate)
831 FloatPoint touchPoint = touchinfo.GetCurrentPosition();
833 if (GetBoxIdFromPosition(touchPoint) != __selectedId)
835 __selectedId = DATETIME_ID_NONE;
842 _EditDatePresenter::OnTouchMoveHandled(const _Control& control)
844 __touchMoveHandled = true;
845 __selectedId = DATETIME_ID_NONE;
851 _EditDatePresenter::Animate(void)
853 SysAssertf((__pFont != null), "Font instance must not be null.");
855 (_FontImpl::GetInstance(*__pFont))->SetSize(__dateFontSize);
857 result r = E_SUCCESS;
864 _DateTimeUtils dateTimeUtils;
865 monthString = dateTimeUtils.GetMonthString(GetMonth());
866 yearString.Format(10, L"%04d", GetYear());
867 dayString.Format(10, L"%02d", GetDay());
869 if (GetLastSelectedId() == DATETIME_ID_DAY)
871 SysTryReturnVoidResult(NID_UI_CTRL, (__lastSelectedValue.Equals(dayString) == false), E_SUCCESS, "Day string matched.");
873 newValue = dayString;
874 rect = GetDateAreaBounds(DATETIME_ID_DAY);
876 else if (GetLastSelectedId() == DATETIME_ID_MONTH)
878 SysTryReturnVoidResult(NID_UI_CTRL, (__lastSelectedValue.Equals(monthString) == false), E_SUCCESS, "Month string matched.");
880 newValue = monthString;
881 rect = GetDateAreaBounds(DATETIME_ID_MONTH);
883 else if (GetLastSelectedId() == DATETIME_ID_YEAR)
885 SysTryReturnVoidResult(NID_UI_CTRL, (__lastSelectedValue.Equals(yearString) == false), E_SUCCESS, "Year string matched.");
887 newValue = yearString;
888 rect = GetDateAreaBounds(DATETIME_ID_YEAR);
891 FloatDimension newTextDim;
892 FloatDimension oldTextDim;
893 FloatPoint textPoint;
894 VisualElement* pNewVisualElement = null;
895 VisualElement* pOldVisualElement = null;
896 VisualElement* pEditDateElement = null;
897 VisualElementPropertyAnimation* pNewBoundsAnimation = null;
898 VisualElementPropertyAnimation* pOldBoundsAnimation = null;
899 Canvas *pCanvas = null;
901 __pFont->GetTextExtent(newValue, newValue.GetLength(), newTextDim);
902 __pFont->GetTextExtent(__lastSelectedValue, __lastSelectedValue.GetLength(), oldTextDim);
904 if (newTextDim.width > oldTextDim.width)
906 textPoint.x = (rect.width - newTextDim.width) / 2.0f;
910 textPoint.x = (rect.width - oldTextDim.width) / 2.0f;
913 SysTryReturnVoidResult(NID_UI_CTRL, (rect.x + textPoint.x < __pEditDate->GetBoundsF().width), E_SUCCESS, "Rolling animation cann't be played.");
915 __isAnimating = true;
917 __pContentProvider = new (std::nothrow) VisualElement();
918 SysTryReturnVoidResult(NID_UI_CTRL, (__pContentProvider != null), E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
920 r = __pContentProvider->Construct();
921 SysTryCatch(NID_UI_CTRL, (r == E_SUCCESS), , r, "[%s] Propagating.", GetErrorMessage(r));
923 __pContentProvider->SetShowState(true);
924 __pContentProvider->SetClipChildrenEnabled(true);
925 __pContentProvider->SetImplicitAnimationEnabled(false);
927 pEditDateElement = __pEditDate->GetVisualElement();
929 SysTryCatch(NID_UI_CTRL, (pEditDateElement != null), , r, "[%s] Propagating.", GetErrorMessage(r));
931 pNewVisualElement = new (std::nothrow) VisualElement();
932 SysTryCatch(NID_UI_CTRL, (pNewVisualElement != null), , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
934 r = pNewVisualElement->Construct();
937 pNewVisualElement->Destroy();
939 SysTryCatch(NID_UI_CTRL, (r == E_SUCCESS), , r, "[%s] Propagating.", GetErrorMessage(r));
941 pOldVisualElement = new (std::nothrow) VisualElement();
942 if (pOldVisualElement == null)
944 pNewVisualElement->Destroy();
946 SysTryCatch(NID_UI_CTRL, (pOldVisualElement != null), , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
948 r = pOldVisualElement->Construct();
951 pNewVisualElement->Destroy();
952 pOldVisualElement->Destroy();
954 SysTryCatch(NID_UI_CTRL, (r == E_SUCCESS), , r, "[%s] Propagating.", GetErrorMessage(r));
956 pNewVisualElement->SetShowState(true);
957 pOldVisualElement->SetShowState(true);
959 if (newTextDim.width > oldTextDim.width)
961 textPoint.x = (rect.width - newTextDim.width) / 2.0f;
962 textPoint.y = (rect.height - newTextDim.height) / 2.0f;
963 __pContentProvider->SetBounds(FloatRectangle((rect.x + textPoint.x) * 1.0f, (rect.y + textPoint.y) * 1.0f, newTextDim.width * 1.0f, newTextDim.height * 1.0f));
964 pNewVisualElement->SetBounds(FloatRectangle(0.0f, newTextDim.height * 1.0f, newTextDim.width * 1.0f, newTextDim.height * 1.0f));
966 rect.x = static_cast<int>(__pContentProvider->GetBounds().x);
967 rect.y = static_cast<int>(__pContentProvider->GetBounds().y);
968 rect.width = static_cast<int>(__pContentProvider->GetBounds().width);
969 rect.height = static_cast<int>(__pContentProvider->GetBounds().height);
971 textPoint.x = (rect.width - oldTextDim.width) / 2.0f;
972 textPoint.y = (rect.height - oldTextDim.height) / 2.0f;
974 pOldVisualElement->SetBounds(FloatRectangle(textPoint.x * 1.0f, 0.0f, oldTextDim.width * 1.0f, oldTextDim.height * 1.0f));
978 textPoint.x = (rect.width - oldTextDim.width) / 2.0f;
979 textPoint.y = (rect.height - oldTextDim.height) / 2.0f;
980 __pContentProvider->SetBounds(FloatRectangle((rect.x + textPoint.x) * 1.0f, (rect.y + textPoint.y) * 1.0f, oldTextDim.width * 1.0f, oldTextDim.height * 1.0f));
981 pOldVisualElement->SetBounds(FloatRectangle(0.0f, 0.0f, oldTextDim.width * 1.0f, oldTextDim.height * 1.0f));
983 rect.x = static_cast<int>(__pContentProvider->GetBounds().x);
984 rect.y = static_cast<int>(__pContentProvider->GetBounds().y);
985 rect.width = static_cast<int>(__pContentProvider->GetBounds().width);
986 rect.height = static_cast<int>(__pContentProvider->GetBounds().height);
988 textPoint.x = (rect.width - newTextDim.width) / 2.0f;
989 textPoint.y = (rect.height - newTextDim.height) / 2.0f;
991 pNewVisualElement->SetBounds(FloatRectangle(textPoint.x * 1.0f, newTextDim.height * 1.0f, newTextDim.width * 1.0f, newTextDim.height * 1.0f));
995 pCanvas = pEditDateElement->GetCanvasN(rect);
996 pCanvas->SetBackgroundColor(Color(0, 0, 0, 0));
1000 pEditDateElement->AttachChild(*__pContentProvider);
1002 __pContentProvider->AttachChild(*pOldVisualElement);
1003 __pContentProvider->AttachChild(*pNewVisualElement);
1005 pNewBoundsAnimation = new (std::nothrow) VisualElementPropertyAnimation();
1006 SysTryCatch(NID_UI_CTRL, (pNewBoundsAnimation != null), , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
1008 pNewBoundsAnimation->SetDuration(300);
1009 pNewBoundsAnimation->SetPropertyName("bounds.position");
1010 pNewBoundsAnimation->SetStartValue(Variant(FloatPoint(pNewVisualElement->GetBounds().x * 1.0f, newTextDim.height * 1.0f)));
1011 pNewBoundsAnimation->SetEndValue(Variant(FloatPoint(pNewVisualElement->GetBounds().x * 1.0f, 0.0f)));
1012 pNewBoundsAnimation->SetVisualElementAnimationStatusEventListener(this);
1014 pOldBoundsAnimation = new (std::nothrow) VisualElementPropertyAnimation();
1015 SysTryCatch(NID_UI_CTRL, (pOldBoundsAnimation != null), , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
1017 pOldBoundsAnimation->SetDuration(300);
1018 pOldBoundsAnimation->SetPropertyName("bounds.position");
1019 pOldBoundsAnimation->SetStartValue(Variant(FloatPoint(pOldVisualElement->GetBounds().x * 1.0f, 0.0f)));
1020 pOldBoundsAnimation->SetEndValue(Variant(FloatPoint(pOldVisualElement->GetBounds().x * 1.0f, oldTextDim.height * -1.0f)));
1021 pOldBoundsAnimation->SetVisualElementAnimationStatusEventListener(this);
1023 pCanvas = pOldVisualElement->GetCanvasN();
1024 r = GetLastResult();
1025 SysTryCatch(NID_UI_CTRL, (pCanvas != null), , r, "[%s] Propagating.", GetErrorMessage(r));
1027 pCanvas->SetBackgroundColor(Color(0, 0, 0, 0));
1029 pCanvas->SetFont(*__pFont);
1030 pCanvas->DrawText(FloatPoint(0.0f, 0.0f), __lastSelectedValue);
1035 pCanvas = pNewVisualElement->GetCanvasN();
1036 r = GetLastResult();
1037 SysTryCatch(NID_UI_CTRL, (pCanvas != null), , r, "[%s] Propagating.", GetErrorMessage(r));
1039 pCanvas->SetBackgroundColor(Color(0, 0, 0, 0));
1041 pCanvas->SetFont(*__pFont);
1042 pCanvas->DrawText(FloatPoint(0.0f, 0.0f), newValue);
1047 pOldVisualElement->SetImplicitAnimationEnabled(false);
1048 pOldVisualElement->AddAnimation(*pOldBoundsAnimation);
1050 pNewVisualElement->SetImplicitAnimationEnabled(false);
1051 pNewVisualElement->AddAnimation(*pNewBoundsAnimation);
1053 delete pOldBoundsAnimation;
1054 delete pNewBoundsAnimation;
1059 __isAnimating = false;
1060 __pContentProvider->Destroy();
1062 delete pNewBoundsAnimation;
1063 pNewBoundsAnimation = null;
1065 delete pOldBoundsAnimation;
1066 pOldBoundsAnimation = null;
1075 _EditDatePresenter::OnVisualElementAnimationFinished (const VisualElementAnimation &animation, const String &keyName, VisualElement &target, bool completedNormally)
1077 result r = E_SUCCESS;
1078 __isAnimating = false;
1080 VisualElement* pEditDateElement = __pEditDate->GetVisualElement();
1081 r = GetLastResult();
1082 SysTryReturnVoidResult(NID_UI_CTRL, (pEditDateElement != null), r, "[%s] Propagating.", GetErrorMessage(r));
1084 pEditDateElement->DetachChild(*__pContentProvider);
1085 __pContentProvider->Destroy();
1091 }}} // Tizen::Ui::Controls