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"
38 using namespace Tizen::Graphics;
39 using namespace Tizen::Base;
40 using namespace Tizen::Graphics::_Text;
41 using namespace Tizen::Ui::Animations;
44 namespace Tizen { namespace Ui { namespace Controls
46 _EditDatePresenter::_EditDatePresenter(void)
47 : __pEditDateTimeModel(null)
49 , __dayBounds(Rectangle())
50 , __monthBounds(Rectangle())
51 , __yearBounds(Rectangle())
52 , __titleBounds(Rectangle())
53 , __datePickerEnabled(true)
54 , __selectedId(DATETIME_ID_NONE)
55 , __lastSelectedId(DATETIME_ID_NONE)
56 , __touchMoveHandled(false)
60 , __dividerLineWidth(0)
61 , __dividerLineHeight(0)
64 , __pContentProvider(null)
65 , __isAnimating(false)
66 , __isEditDateInitialized(false)
70 _EditDatePresenter::~_EditDatePresenter(void)
72 __titleObject.RemoveAll();
73 __textObject.RemoveAll();
75 delete __pEditDateTimeModel;
76 __pEditDateTimeModel = null;
80 _EditDatePresenter::CreateInstanceN(const _EditDate& editDate, const String& title)
82 _EditDatePresenter* pEditDatePresenter = new (std::nothrow) _EditDatePresenter;
83 SysTryReturn(NID_UI_CTRL, pEditDatePresenter, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
85 pEditDatePresenter->__pEditDate = const_cast <_EditDate*>(&editDate);
87 pEditDatePresenter->__pEditDateTimeModel = new (std::nothrow) _DateTimeModel;
88 SysTryCatch(NID_UI_CTRL, pEditDatePresenter->__pEditDateTimeModel, , E_OUT_OF_MEMORY,
89 "[E_OUT_OF_MEMORY] Memory allocation failed.");
90 pEditDatePresenter->SetTitle(title);
92 return pEditDatePresenter;
95 delete pEditDatePresenter;
100 _EditDatePresenter::SetTitle(const String& title)
105 _EditDatePresenter::Initialize(void)
107 result r = E_SUCCESS;
108 int editDateHeight = 0;
109 int editDateWidth = 0;
111 int editDateFontSize = 0;
112 int titledateMargin = 0;
114 Rectangle bounds(0, 0, 0, 0);
116 GET_SHAPE_CONFIG(EDITDATE::WIDTH, __pEditDate->GetOrientation(), editDateWidth);
117 GET_SHAPE_CONFIG(EDITDATE::HEIGHT, __pEditDate->GetOrientation(), editDateHeight);
118 GET_SHAPE_CONFIG(EDITDATE::DATE_FONT_SIZE, __pEditDate->GetOrientation(), editDateFontSize);
119 GET_SHAPE_CONFIG(EDITDATE::DATE_TEXT_LEFT_MARGIN, __pEditDate->GetOrientation(), leftMargin);
120 GET_FIXED_VALUE_CONFIG(EDITDATE::ITEM_DIVIDER_WIDTH, __pEditDate->GetOrientation(), __dividerLineWidth);
121 GET_SHAPE_CONFIG(EDITDATE::ITEM_DIVIDER_HEIGHT, __pEditDate->GetOrientation(), __dividerLineHeight);
122 GET_SHAPE_CONFIG(EDITDATE::TEXT_FONT_SIZE, __pEditDate->GetOrientation(), __titleFontSize);
123 GET_SHAPE_CONFIG(EDITDATE::DATE_FONT_SIZE, __pEditDate->GetOrientation(), __dateFontSize);
124 GET_SHAPE_CONFIG(EDITDATE::TITLE_DATE_MARGIN, __pEditDate->GetOrientation(), titledateMargin);
125 GET_SHAPE_CONFIG(EDITDATE::DATE_HEIGHT, __pEditDate->GetOrientation(), dateHeight);
126 GET_SHAPE_CONFIG(EDITDATE::TEXT_HEIGHT, __pEditDate->GetOrientation(), __titleBounds.height);
128 if (__pEditDate->GetBounds().height > editDateHeight)
130 editDateHeight = __pEditDate->GetBounds().height;
133 __pFont = __pEditDate->GetFallbackFont();
135 SysTryReturn(NID_UI_CTRL, __pFont != null, r, r, "[%s] Propagating.", GetErrorMessage(r));
137 if (__title.IsEmpty() == false)
139 __titleBounds.x = leftMargin;
140 __titleBounds.y = (editDateHeight - (__titleBounds.height + titledateMargin + dateHeight)) / 2;
141 __titleBounds.width = editDateWidth;
143 bounds.y = __titleBounds.y + __titleBounds.height + titledateMargin;
145 __dayBounds.height = dateHeight;
146 __monthBounds.height = dateHeight;
147 __yearBounds.height = dateHeight;
149 if (!__isEditDateInitialized)
151 r = InitializeTitleObject();
152 SysTryReturn(NID_UI_CTRL, (r == E_SUCCESS), r, r, "[%s] Propagating.", GetErrorMessage(r));
155 __titleObject.SetBounds(__titleBounds);
159 __dayBounds.height = editDateHeight;
160 __monthBounds.height = editDateHeight;
161 __yearBounds.height = editDateHeight;
164 int elementWidth = 0;
165 GET_SHAPE_CONFIG(EDITDATE::TEXT_ELEMENT_WIDTH, __pEditDate->GetOrientation(), elementWidth);
167 __dayBounds.width = elementWidth;
168 __monthBounds.width = elementWidth;
169 __yearBounds.width = elementWidth;
175 __dayBounds.y = bounds.y;
176 __monthBounds.y = bounds.y;
177 __yearBounds.y = bounds.y;
179 if (!__isEditDateInitialized)
181 r = InitializeTextObject();
182 SysTryReturn(NID_UI_CTRL, (r == E_SUCCESS), r, r, "[%s] Propagating.", GetErrorMessage(r));
185 __isEditDateInitialized = true;
187 CalculateAreaBounds();
193 _EditDatePresenter::InitializeTitleObject(void)
195 result r = E_SUCCESS;
197 Color titleNormalColor;
199 GET_COLOR_CONFIG(EDITDATE::TITLE_TEXT_NORMAL, titleNormalColor);
201 r = __titleObject.Construct();
202 SysTryReturn(NID_UI_CTRL, (r == E_SUCCESS), r, r, "[%s] Propagating.", GetErrorMessage(r));
204 TextSimple* pSimpleText = null;
206 pSimpleText = new (std::nothrow)TextSimple((const_cast <wchar_t*>(__title.GetPointer())), __title.GetLength(), TEXT_ELEMENT_SOURCE_TYPE_EXTERNAL);
207 SysTryReturn(NID_UI_CTRL, (pSimpleText != null), E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
209 __titleObject.AppendElement(*pSimpleText);
211 __titleObject.SetForegroundColor(titleNormalColor, 0, __titleObject.GetTextLength());
212 __titleObject.SetFont(__pFont, 0, __titleObject.GetTextLength());
213 __titleObject.SetAlignment(TEXT_OBJECT_ALIGNMENT_LEFT | TEXT_OBJECT_ALIGNMENT_MIDDLE);
214 __titleObject.SetWrap(TEXT_OBJECT_WRAP_TYPE_NONE);
215 __titleObject.SetAction(TEXT_OBJECT_ACTION_TYPE_ABBREV);
221 _EditDatePresenter::InitializeTextObject(void)
223 result r = E_SUCCESS;
225 r = __textObject.Construct();
226 SysTryReturn(NID_UI_CTRL, (r == E_SUCCESS), r, r, "[%s] Propagating.", GetErrorMessage(r));
228 TextSimple* pSimpleText = null;
230 pSimpleText = new (std::nothrow)TextSimple(null, 0, TEXT_ELEMENT_SOURCE_TYPE_EXTERNAL);
231 SysTryReturn(NID_UI_CTRL, (pSimpleText != null), E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
233 __textObject.AppendElement(*pSimpleText);
235 __textObject.SetFont(__pFont, 0, __textObject.GetTextLength());
236 __textObject.SetAlignment(TEXT_OBJECT_ALIGNMENT_CENTER | TEXT_OBJECT_ALIGNMENT_MIDDLE);
237 __textObject.SetWrap(TEXT_OBJECT_WRAP_TYPE_NONE);
238 __textObject.SetAction(TEXT_OBJECT_ACTION_TYPE_ABBREV);
244 _EditDatePresenter::GetLocaleDateFormat(void) const
246 int localeDateFormat = -1;
247 int error = vconf_get_int(VCONFKEY_SETAPPL_DATE_FORMAT_INT, &localeDateFormat);
250 localeDateFormat = SETTING_DATE_FORMAT_DD_MM_YYYY;
253 return localeDateFormat;
257 _EditDatePresenter::GetDate(void) const
259 SysAssertf((__pEditDateTimeModel != null), "The _EditDateTimeModel instance is null.");
262 date.SetValue(GetYear(), GetMonth(), GetDay(), DATETIME_HOUR_MIN, DATETIME_MINUTE_MIN);
268 _EditDatePresenter::GetDay(void) const
270 SysAssertf((__pEditDateTimeModel != null), "The _EditDateTimeModel instance is null.");
272 return __pEditDateTimeModel->GetDay();
276 _EditDatePresenter::GetMonth(void) const
278 SysAssertf((__pEditDateTimeModel != null), "The _EditDateTimeModel instance is null.");
280 return __pEditDateTimeModel->GetMonth();
284 _EditDatePresenter::GetYear(void) const
286 SysAssertf((__pEditDateTimeModel != null), "The _EditDateTimeModel instance is null.");
288 return __pEditDateTimeModel->GetYear();
292 _EditDatePresenter::SetDate(const DateTime& date)
294 SysAssertf((__pEditDateTimeModel != null), "The _EditDateTimeModel instance is null.");
296 __pEditDateTimeModel->SetDateTime(date);
301 _EditDatePresenter::SetCurrentDate(void)
303 SysAssertf((__pEditDateTimeModel != null), "The _EditDateTimeModel instance is null.");
305 __pEditDateTimeModel->SetCurrentDateTime();
310 _EditDatePresenter::SetYear(int year)
312 SysAssertf((__pEditDateTimeModel != null), "The _EditDateTimeModel instance is null.");
314 return __pEditDateTimeModel->SetYear(year);
318 _EditDatePresenter::SetMonth(int month)
320 SysAssertf((__pEditDateTimeModel != null), "The _EditDateTimeModel instance is null.");
322 return __pEditDateTimeModel->SetMonth(month);
326 _EditDatePresenter::SetDay(int day)
328 SysAssertf((__pEditDateTimeModel != null), "The _EditDateTimeModel instance is null.");
330 return __pEditDateTimeModel->SetDay(day);
334 _EditDatePresenter::SetDatePickerEnabled(bool enable)
336 __datePickerEnabled = enable;
341 _EditDatePresenter::IsDatePickerEnabled(void) const
343 return __datePickerEnabled;
347 _EditDatePresenter::SetMinYear(int minYear)
349 return __pEditDateTimeModel->SetMinYear(minYear);
353 _EditDatePresenter::SetMaxYear(int maxYear)
355 return __pEditDateTimeModel->SetMaxYear(maxYear);
359 _EditDatePresenter::GetMinYear(void) const
364 __pEditDateTimeModel->GetYearRange(minYear, maxYear);
370 _EditDatePresenter::GetMaxYear(void) const
375 __pEditDateTimeModel->GetYearRange(minYear, maxYear);
381 _EditDatePresenter::Draw(void)
383 result r = E_SUCCESS;
390 Canvas* pCanvas = __pEditDate->GetCanvasN();
391 SysAssertf((pCanvas != null), "Failed to get canvas.");
393 pCanvas->SetBackgroundColor(Color(0, 0, 0, 0));
396 if (__title.IsEmpty() == false)
405 _DateTimeUtils dateTimeUtils;
406 monthString = dateTimeUtils.GetMonthString(GetMonth());
407 yearString.Format(10, L"%04d", GetYear());
408 dayString.Format(10, L"%02d", GetDay());
410 CalculateAreaBounds();
412 r = DrawText(*pCanvas, GetDateAreaBounds(DATETIME_ID_DAY), dayString);
413 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
414 r = DrawText(*pCanvas, GetDateAreaBounds(DATETIME_ID_MONTH), monthString);
415 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
416 r = DrawText(*pCanvas, GetDateAreaBounds(DATETIME_ID_YEAR), yearString);
417 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
419 r = DrawDividers(*pCanvas);
420 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
432 _EditDatePresenter::CalculateAreaBounds(void)
434 result r = E_SUCCESS;
436 if (GetLocaleDateFormat() == DATE_FORMAT_DDMMYYYY)
438 __monthBounds.x = __dayBounds.x + __dayBounds.width + __dividerLineWidth;
439 __yearBounds.x = __monthBounds.x + __monthBounds.width + __dividerLineWidth;
441 else if (GetLocaleDateFormat() == DATE_FORMAT_MMDDYYYY)
443 __dayBounds.x = __monthBounds.x + __monthBounds.width + __dividerLineWidth;
444 __yearBounds.x = __dayBounds.x + __dayBounds.width + __dividerLineWidth;
446 else if (GetLocaleDateFormat() == DATE_FORMAT_YYYYMMDD)
448 __monthBounds.x = __yearBounds.x + __yearBounds.width + __dividerLineWidth;
449 __dayBounds.x = __monthBounds.x + __monthBounds.width + __dividerLineWidth;
451 else if (GetLocaleDateFormat() == DATE_FORMAT_YYYYDDMM)
453 __dayBounds.x = __yearBounds.x + __yearBounds.width + __dividerLineWidth;
454 __monthBounds.x = __dayBounds.x + __dayBounds.width + __dividerLineWidth;
461 _EditDatePresenter::DrawTitle(Canvas& canvas)
463 if (!__pEditDate->IsEnabled())
465 Color titleDisabledColor;
466 GET_COLOR_CONFIG(EDITDATE::TITLE_TEXT_DISABLED, titleDisabledColor);
467 __titleObject.SetForegroundColor(titleDisabledColor, 0, __titleObject.GetTextLength());
470 (_FontImpl::GetInstance(*__pFont))->SetSize(__titleFontSize);
471 __titleObject.SetFont(__pFont, 0, __titleObject.GetTextLength());
472 __titleObject.Draw(*_CanvasImpl::GetInstance(canvas));
478 _EditDatePresenter::DrawText(Canvas& canvas, const Rectangle& bounds, const String& text)
482 if (!__pEditDate->IsEnabled())
484 GET_COLOR_CONFIG(EDITDATE::TEXT_DISABLED, textColor);
488 GET_COLOR_CONFIG(EDITDATE::TEXT_NORMAL, textColor);
491 _DateTimeId boxId = DATETIME_ID_NONE;
492 boxId = GetBoxIdFromPosition(Point(bounds.x, bounds.y));
494 if (boxId == __selectedId && boxId != DATETIME_ID_NONE)
496 GET_COLOR_CONFIG(EDITDATE::TEXT_PRESSED, textColor);
499 Rectangle drawAreaBounds(0, 0, 0, 0);
500 drawAreaBounds = bounds;
502 TextSimple* pSimpleText = null;
503 pSimpleText = new (std::nothrow)TextSimple((const_cast <wchar_t*>(text.GetPointer())), text.GetLength(), TEXT_ELEMENT_SOURCE_TYPE_EXTERNAL);
504 SysTryReturn(NID_UI_CTRL, (pSimpleText != null), E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
506 __textObject.RemoveAll();
508 (_FontImpl::GetInstance(*__pFont))->SetSize(__dateFontSize);
510 __textObject.AppendElement(*pSimpleText);
512 __textObject.SetFont(__pFont, 0, __textObject.GetTextLength());
513 __textObject.SetForegroundColor(textColor, 0, __textObject.GetTextLength());
514 __textObject.SetBounds(drawAreaBounds);
515 __textObject.Draw(*_CanvasImpl::GetInstance(canvas));
521 _EditDatePresenter::DrawDividers(Canvas& canvas)
523 result r = E_SUCCESS;
525 int elementWidth = 0;
526 int editDateHeight = 0;
529 GET_SHAPE_CONFIG(EDITDATE::TEXT_ELEMENT_WIDTH, __pEditDate->GetOrientation(), elementWidth);
530 GET_SHAPE_CONFIG(EDITDATE::DATE_HEIGHT, __pEditDate->GetOrientation(), dateHeight);
531 GET_SHAPE_CONFIG(EDITDATE::HEIGHT, __pEditDate->GetOrientation(), editDateHeight);
533 if (__pEditDate->GetBounds().height > editDateHeight)
535 editDateHeight = __pEditDate->GetBounds().height;
538 Color dividerHalfLeftColor;
539 Color dividerHalfRightColor;
541 GET_COLOR_CONFIG(EDITDATE::DIVIDER_HALF_LEFT, dividerHalfLeftColor);
542 GET_COLOR_CONFIG(EDITDATE::DIVIDER_HALF_RIGHT, dividerHalfRightColor);
544 Rectangle bounds(0, 0, 0, 0);
546 bounds.x = elementWidth;
548 if (__title.IsEmpty() == false)
550 bounds.y = __dayBounds.y + ((dateHeight - __dividerLineHeight) / 2);
554 bounds.y = __dayBounds.y + ((editDateHeight - __dividerLineHeight) / 2);
557 for (int divider = 0; divider < __dividerCount; divider++)
559 canvas.SetForegroundColor(dividerHalfLeftColor);
560 canvas.SetLineWidth(__dividerLineWidth / 2);
562 r = canvas.DrawLine(Point(bounds.x, bounds.y), Point(bounds.x, bounds.y + __dividerLineHeight));
563 SysTryReturnResult(NID_UI_CTRL, (r == E_SUCCESS), r, "[%s] Propagating.", GetErrorMessage(r));
565 canvas.SetForegroundColor(dividerHalfRightColor);
566 canvas.SetLineWidth(__dividerLineWidth / 2);
568 r = canvas.DrawLine(Point(bounds.x + 1, bounds.y), Point(bounds.x + 1, bounds.y + __dividerLineHeight));
569 SysTryReturnResult(NID_UI_CTRL, (r == E_SUCCESS), r, "[%s] Propagating.", GetErrorMessage(r));
571 bounds.x = bounds.x + elementWidth;
577 _EditDatePresenter::GetBoxIdFromPosition(const Point& point) const
579 _DateTimeId displayBoxId = DATETIME_ID_NONE;
581 if (point.y < __dayBounds.y || point.y > __dayBounds.y + __dayBounds.height)
586 if (__dayBounds.Contains(point) == true)
588 displayBoxId = DATETIME_ID_DAY;
590 else if (__monthBounds.Contains(point) == true)
592 displayBoxId = DATETIME_ID_MONTH;
594 else if (__yearBounds.Contains(point) == true)
596 displayBoxId = DATETIME_ID_YEAR;
603 _EditDatePresenter::GetDateAreaBounds(_DateTimeId id) const
605 if (id == DATETIME_ID_DAY)
609 else if (id == DATETIME_ID_MONTH)
611 return __monthBounds;
613 else if (id == DATETIME_ID_YEAR)
624 _EditDatePresenter::GetTitleBounds(void) const
626 return __titleBounds;
630 _EditDatePresenter::SetLastSelectedId(_DateTimeId boxId)
632 __lastSelectedId = boxId;
637 _EditDatePresenter::GetLastSelectedId(void) const
639 return __lastSelectedId;
643 _EditDatePresenter::OnFontChanged(Font* pFont)
647 if (__pEditDate->GetDateTimeBar() != null)
649 __pEditDate->GetDateTimeBar()->SetFont(*pFont);
656 _EditDatePresenter::OnFontInfoRequested(unsigned long& style, int& size)
658 style = FONT_STYLE_PLAIN;
659 size = __dateFontSize;
665 _EditDatePresenter::OnChangeLayout(_ControlOrientation orientation)
667 Dimension editDateSize;
669 result r = E_SUCCESS;
671 r = GET_DIMENSION_CONFIG(EDITDATE::DEFAULT_SIZE, orientation, editDateSize);
673 if (r == E_SUCCESS && editDateSize != __pEditDate->GetSize())
675 __pEditDate->SetResizable(true);
676 __pEditDate->SetSize(editDateSize);
677 __pEditDate->SetResizable(false);
681 SysTryReturnVoidResult(NID_UI_CTRL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
687 _EditDatePresenter::OnTouchPressed(const _Control& source, const _TouchInfo& touchinfo)
689 SysTryReturn(NID_UI_CTRL, IsDatePickerEnabled() == true, true, E_SYSTEM,
690 "[E_SYSTEM] A system error has occurred. EditDate instance is disabled.");
692 if (&source != __pEditDate)
697 __touchMoveHandled = false;
699 Point point = touchinfo.GetCurrentPosition();
701 _DateTimeId boxId = DATETIME_ID_NONE;
702 boxId = GetBoxIdFromPosition(point);
704 if (boxId < DATETIME_ID_YEAR || boxId > DATETIME_ID_DAY)
706 __selectedId = DATETIME_ID_NONE;
712 int displayValue = -1;
714 if (boxId == DATETIME_ID_DAY)
716 if (__pEditDate->GetDateTimeBar() != null)
718 _DateTimeUtils dateTimeUtils;
719 maxValue = dateTimeUtils.CalculateMaxDay(GetYear(), GetMonth());
720 minValue = DATETIME_DAY_MIN;
721 displayValue = GetDay();
724 else if (boxId == DATETIME_ID_MONTH)
726 minValue = DATETIME_MONTH_MIN;
727 maxValue = DATETIME_MONTH_MAX;
728 displayValue = GetMonth();
730 else if (boxId == DATETIME_ID_YEAR)
732 minValue = GetMinYear();
733 maxValue = GetMaxYear();
734 displayValue = GetYear();
737 if (__pEditDate->GetDateTimeBar() != null)
739 if (__pEditDate->GetDateTimeBar()->GetItemCount() > 0)
741 __pEditDate->GetDateTimeBar()->RemoveAllItems();
744 result r = __pEditDate->GetDateTimeBar()->SetInitialValue(minValue, maxValue, displayValue, boxId);
747 __selectedId = DATETIME_ID_NONE;
752 __selectedId = boxId;
754 __pEditDate->Invalidate();
760 _EditDatePresenter::OnTouchReleased(const _Control& source, const _TouchInfo& touchinfo)
762 SysTryReturn(NID_UI_CTRL, IsDatePickerEnabled() == true, true, E_SYSTEM,
763 "[E_SYSTEM] A system error has occurred. EditDate instance is disabled.");
765 if (&source != __pEditDate)
770 Point point = touchinfo.GetCurrentPosition();
772 _DateTimeId boxId = DATETIME_ID_NONE;
773 boxId = GetBoxIdFromPosition(point);
775 if (boxId != __selectedId)
777 __selectedId = DATETIME_ID_NONE;
780 SetLastSelectedId(__selectedId);
781 __selectedId = DATETIME_ID_NONE;
783 __lastSelectedValue = "";
784 _DateTimeUtils dateTimeUtils;
785 if (GetLastSelectedId() == DATETIME_ID_YEAR)
787 __lastSelectedValue.Format(10, L"%04d", GetYear());
789 else if (GetLastSelectedId() == DATETIME_ID_MONTH)
791 __lastSelectedValue = dateTimeUtils.GetMonthString(GetMonth());
793 else if (GetLastSelectedId() == DATETIME_ID_DAY)
795 __lastSelectedValue.Format(10, L"%02d", GetDay());
798 __pEditDate->Invalidate();
800 if (__pEditDate->GetDateTimeBar() != null && GetLastSelectedId() != DATETIME_ID_NONE)
802 Rectangle bounds(0, 0, 0, 0);
803 bounds = GetDateAreaBounds(GetLastSelectedId());
804 Rectangle absoluteBounds(0, 0, 0, 0);
805 absoluteBounds = __pEditDate->GetAbsoluteBounds();
806 bounds.x += absoluteBounds.x;
808 __pEditDate->GetDateTimeBar()->CalculateArrowBounds(bounds);
809 __pEditDate->GetDateTimeBar()->SetVisibleState(true);
810 __pEditDate->GetDateTimeBar()->Open();
817 _EditDatePresenter::OnTouchCanceled(const _Control& source, const _TouchInfo& touchinfo)
819 if (&source != __pEditDate)
824 __selectedId = DATETIME_ID_NONE;
826 __pEditDate->Invalidate();
832 _EditDatePresenter::OnTouchMoved(const _Control& source, const _TouchInfo& touchinfo)
834 if (&source != __pEditDate)
839 Point touchPoint = touchinfo.GetCurrentPosition();
841 if (GetBoxIdFromPosition(touchPoint) != __selectedId)
843 __selectedId = DATETIME_ID_NONE;
846 __pEditDate->Invalidate();
851 _EditDatePresenter::OnTouchMoveHandled(const _Control& control)
853 __touchMoveHandled = true;
854 __selectedId = DATETIME_ID_NONE;
855 __pEditDate->Invalidate();
860 _EditDatePresenter::Animate(void)
862 SysAssertf((__pFont != null), "Font instance must not be null.");
864 (_FontImpl::GetInstance(*__pFont))->SetSize(__dateFontSize);
866 result r = E_SUCCESS;
873 _DateTimeUtils dateTimeUtils;
874 monthString = dateTimeUtils.GetMonthString(GetMonth());
875 yearString.Format(10, L"%04d", GetYear());
876 dayString.Format(10, L"%02d", GetDay());
878 if (GetLastSelectedId() == DATETIME_ID_DAY)
880 SysTryReturnVoidResult(NID_UI_CTRL, (__lastSelectedValue.Equals(dayString) == false), E_SUCCESS, "Day string matched.");
882 newValue = dayString;
883 rect = GetDateAreaBounds(DATETIME_ID_DAY);
885 else if (GetLastSelectedId() == DATETIME_ID_MONTH)
887 SysTryReturnVoidResult(NID_UI_CTRL, (__lastSelectedValue.Equals(monthString) == false), E_SUCCESS, "Month string matched.");
889 newValue = monthString;
890 rect = GetDateAreaBounds(DATETIME_ID_MONTH);
892 else if (GetLastSelectedId() == DATETIME_ID_YEAR)
894 SysTryReturnVoidResult(NID_UI_CTRL, (__lastSelectedValue.Equals(yearString) == false), E_SUCCESS, "Year string matched.");
896 newValue = yearString;
897 rect = GetDateAreaBounds(DATETIME_ID_YEAR);
900 Dimension newTextDim;
901 Dimension oldTextDim;
903 VisualElement* pNewVisualElement = null;
904 VisualElement* pOldVisualElement = null;
905 VisualElement* pEditDateElement = null;
906 VisualElementPropertyAnimation* pNewBoundsAnimation = null;
907 VisualElementPropertyAnimation* pOldBoundsAnimation = null;
908 Canvas *pCanvas = null;
910 __pFont->GetTextExtent(newValue, newValue.GetLength(), newTextDim);
911 __pFont->GetTextExtent(__lastSelectedValue, __lastSelectedValue.GetLength(), oldTextDim);
913 if (newTextDim.width > oldTextDim.width)
915 textPoint.x = (rect.width - newTextDim.width) / 2;
919 textPoint.x = (rect.width - oldTextDim.width) / 2;
922 SysTryReturnVoidResult(NID_UI_CTRL, (rect.x + textPoint.x < __pEditDate->GetBounds().width), E_SUCCESS, "Rolling animation cann't be played.");
924 __isAnimating = true;
926 __pContentProvider = new (std::nothrow) VisualElement();
927 SysTryReturnVoidResult(NID_UI_CTRL, (__pContentProvider != null), E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
929 r = __pContentProvider->Construct();
930 SysTryCatch(NID_UI_CTRL, (r == E_SUCCESS), , r, "[%s] Propagating.", GetErrorMessage(r));
932 __pContentProvider->SetShowState(true);
933 __pContentProvider->SetClipChildrenEnabled(true);
934 __pContentProvider->SetImplicitAnimationEnabled(false);
936 pEditDateElement = __pEditDate->GetVisualElement();
938 SysTryCatch(NID_UI_CTRL, (pEditDateElement != null), , r, "[%s] Propagating.", GetErrorMessage(r));
940 pNewVisualElement = new (std::nothrow) VisualElement();
941 SysTryCatch(NID_UI_CTRL, (pNewVisualElement != null), , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
943 r = pNewVisualElement->Construct();
946 pNewVisualElement->Destroy();
948 SysTryCatch(NID_UI_CTRL, (r == E_SUCCESS), , r, "[%s] Propagating.", GetErrorMessage(r));
950 pOldVisualElement = new (std::nothrow) VisualElement();
951 if (pOldVisualElement == null)
953 pNewVisualElement->Destroy();
955 SysTryCatch(NID_UI_CTRL, (pOldVisualElement != null), , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
957 r = pOldVisualElement->Construct();
960 pNewVisualElement->Destroy();
961 pOldVisualElement->Destroy();
963 SysTryCatch(NID_UI_CTRL, (r == E_SUCCESS), , r, "[%s] Propagating.", GetErrorMessage(r));
965 pNewVisualElement->SetShowState(true);
966 pOldVisualElement->SetShowState(true);
968 if (newTextDim.width > oldTextDim.width)
970 textPoint.x = (rect.width - newTextDim.width) / 2;
971 textPoint.y = (rect.height - newTextDim.height) / 2;
972 __pContentProvider->SetBounds(FloatRectangle((rect.x + textPoint.x) * 1.0f, (rect.y + textPoint.y) * 1.0f, newTextDim.width * 1.0f, newTextDim.height * 1.0f));
973 pNewVisualElement->SetBounds(FloatRectangle(0.0f, newTextDim.height * 1.0f, newTextDim.width * 1.0f, newTextDim.height * 1.0f));
975 rect.x = static_cast<int>(__pContentProvider->GetBounds().x);
976 rect.y = static_cast<int>(__pContentProvider->GetBounds().y);
977 rect.width = static_cast<int>(__pContentProvider->GetBounds().width);
978 rect.height = static_cast<int>(__pContentProvider->GetBounds().height);
980 textPoint.x = (rect.width - oldTextDim.width) / 2;
981 textPoint.y = (rect.height - oldTextDim.height) / 2;
983 pOldVisualElement->SetBounds(FloatRectangle(textPoint.x * 1.0f, 0.0f, oldTextDim.width * 1.0f, oldTextDim.height * 1.0f));
987 textPoint.x = (rect.width - oldTextDim.width) / 2;
988 textPoint.y = (rect.height - oldTextDim.height) / 2;
989 __pContentProvider->SetBounds(FloatRectangle((rect.x + textPoint.x) * 1.0f, (rect.y + textPoint.y) * 1.0f, oldTextDim.width * 1.0f, oldTextDim.height * 1.0f));
990 pOldVisualElement->SetBounds(FloatRectangle(0.0f, 0.0f, oldTextDim.width * 1.0f, oldTextDim.height * 1.0f));
992 rect.x = static_cast<int>(__pContentProvider->GetBounds().x);
993 rect.y = static_cast<int>(__pContentProvider->GetBounds().y);
994 rect.width = static_cast<int>(__pContentProvider->GetBounds().width);
995 rect.height = static_cast<int>(__pContentProvider->GetBounds().height);
997 textPoint.x = (rect.width - newTextDim.width) / 2;
998 textPoint.y = (rect.height - newTextDim.height) / 2;
1000 pNewVisualElement->SetBounds(FloatRectangle(textPoint.x * 1.0f, newTextDim.height * 1.0f, newTextDim.width * 1.0f, newTextDim.height * 1.0f));
1004 pCanvas = pEditDateElement->GetCanvasN(rect);
1005 pCanvas->SetBackgroundColor(Color(0, 0, 0, 0));
1009 pEditDateElement->AttachChild(*__pContentProvider);
1011 __pContentProvider->AttachChild(*pOldVisualElement);
1012 __pContentProvider->AttachChild(*pNewVisualElement);
1014 pNewBoundsAnimation = new (std::nothrow) VisualElementPropertyAnimation();
1015 SysTryCatch(NID_UI_CTRL, (pNewBoundsAnimation != null), , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
1017 pNewBoundsAnimation->SetDuration(300);
1018 pNewBoundsAnimation->SetPropertyName("bounds.position");
1019 pNewBoundsAnimation->SetStartValue(Variant(FloatPoint(pNewVisualElement->GetBounds().x * 1.0f, newTextDim.height * 1.0f)));
1020 pNewBoundsAnimation->SetEndValue(Variant(FloatPoint(pNewVisualElement->GetBounds().x * 1.0f, 0.0f)));
1021 pNewBoundsAnimation->SetVisualElementAnimationStatusEventListener(this);
1023 pOldBoundsAnimation = new (std::nothrow) VisualElementPropertyAnimation();
1024 SysTryCatch(NID_UI_CTRL, (pOldBoundsAnimation != null), , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
1026 pOldBoundsAnimation->SetDuration(300);
1027 pOldBoundsAnimation->SetPropertyName("bounds.position");
1028 pOldBoundsAnimation->SetStartValue(Variant(FloatPoint(pOldVisualElement->GetBounds().x * 1.0f, 0.0f)));
1029 pOldBoundsAnimation->SetEndValue(Variant(FloatPoint(pOldVisualElement->GetBounds().x * 1.0f, oldTextDim.height * -1.0f)));
1030 pOldBoundsAnimation->SetVisualElementAnimationStatusEventListener(this);
1032 pCanvas = pOldVisualElement->GetCanvasN();
1033 r = GetLastResult();
1034 SysTryCatch(NID_UI_CTRL, (pCanvas != null), , r, "[%s] Propagating.", GetErrorMessage(r));
1036 pCanvas->SetBackgroundColor(Color(0, 0, 0, 0));
1038 pCanvas->SetFont(*__pFont);
1039 pCanvas->DrawText(Point(0,0),__lastSelectedValue);
1044 pCanvas = pNewVisualElement->GetCanvasN();
1045 r = GetLastResult();
1046 SysTryCatch(NID_UI_CTRL, (pCanvas != null), , r, "[%s] Propagating.", GetErrorMessage(r));
1048 pCanvas->SetBackgroundColor(Color(0, 0, 0, 0));
1050 pCanvas->SetFont(*__pFont);
1051 pCanvas->DrawText(Point(0,0),newValue);
1056 pOldVisualElement->SetImplicitAnimationEnabled(false);
1057 pOldVisualElement->AddAnimation(*pOldBoundsAnimation);
1059 pNewVisualElement->SetImplicitAnimationEnabled(false);
1060 pNewVisualElement->AddAnimation(*pNewBoundsAnimation);
1062 delete pOldBoundsAnimation;
1063 delete pNewBoundsAnimation;
1068 __isAnimating = false;
1069 __pContentProvider->Destroy();
1071 delete pNewBoundsAnimation;
1072 pNewBoundsAnimation = null;
1074 delete pOldBoundsAnimation;
1075 pOldBoundsAnimation = null;
1084 _EditDatePresenter::OnVisualElementAnimationFinished (const VisualElementAnimation &animation, const String &keyName, VisualElement &target, bool completedNormally)
1086 result r = E_SUCCESS;
1087 __isAnimating = false;
1089 VisualElement* pEditDateElement = __pEditDate->GetVisualElement();
1090 r = GetLastResult();
1091 SysTryReturnVoidResult(NID_UI_CTRL, (pEditDateElement != null), r, "[%s] Propagating.", GetErrorMessage(r));
1093 pEditDateElement->DetachChild(*__pContentProvider);
1094 __pContentProvider->Destroy();
1100 }}} // Tizen::Ui::Controls