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_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 , __dayTouchBounds(FloatRectangle())
54 , __monthTouchBounds(FloatRectangle())
55 , __yearTouchBounds(FloatRectangle())
56 , __titleBounds(FloatRectangle())
57 , __datePickerEnabled(true)
58 , __selectedId(DATETIME_ID_NONE)
59 , __lastSelectedId(DATETIME_ID_NONE)
60 , __touchMoveHandled(false)
64 , __dividerLineWidth(0.0f)
65 , __dividerLineHeight(0.0f)
66 , __titleFontSize(0.0f)
67 , __dateFontSize(0.0f)
68 , __pContentProvider(null)
69 , __isAnimating(false)
70 , __isEditDateInitialized(false)
71 , __elementWidth(0.0f)
75 _EditDatePresenter::~_EditDatePresenter(void)
77 __titleObject.RemoveAll();
78 __textObject.RemoveAll();
80 delete __pEditDateTimeModel;
81 __pEditDateTimeModel = null;
85 _EditDatePresenter::CreateInstanceN(const _EditDate& editDate, const String& title)
87 _EditDatePresenter* pEditDatePresenter = new (std::nothrow) _EditDatePresenter;
88 SysTryReturn(NID_UI_CTRL, pEditDatePresenter, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
90 pEditDatePresenter->__pEditDate = const_cast <_EditDate*>(&editDate);
92 pEditDatePresenter->__pEditDateTimeModel = new (std::nothrow) _DateTimeModel;
93 SysTryCatch(NID_UI_CTRL, pEditDatePresenter->__pEditDateTimeModel, , E_OUT_OF_MEMORY,
94 "[E_OUT_OF_MEMORY] Memory allocation failed.");
95 pEditDatePresenter->SetTitle(title);
97 return pEditDatePresenter;
100 delete pEditDatePresenter;
105 _EditDatePresenter::SetTitle(const String& title)
110 _EditDatePresenter::Initialize(void)
112 result r = E_SUCCESS;
113 float editDateHeight = 0.0f;
114 float editDateWidth = 0.0f;
115 float leftMargin = 0.0f;
116 float titledateMargin = 0.0f;
117 float dateHeight = 0.0f;
118 FloatRectangle bounds(0.0f, 0.0f, 0.0f, 0.0f);
120 GET_SHAPE_CONFIG(EDITDATE::WIDTH, __pEditDate->GetOrientation(), editDateWidth);
121 GET_SHAPE_CONFIG(EDITDATE::HEIGHT, __pEditDate->GetOrientation(), editDateHeight);
122 GET_SHAPE_CONFIG(EDITDATE::DATE_TEXT_LEFT_MARGIN, __pEditDate->GetOrientation(), leftMargin);
123 GET_FIXED_VALUE_CONFIG(EDITDATE::ITEM_DIVIDER_WIDTH, __pEditDate->GetOrientation(), __dividerLineWidth);
124 GET_SHAPE_CONFIG(EDITDATE::ITEM_DIVIDER_HEIGHT, __pEditDate->GetOrientation(), __dividerLineHeight);
125 GET_SHAPE_CONFIG(EDITDATE::TEXT_FONT_SIZE, __pEditDate->GetOrientation(), __titleFontSize);
126 GET_SHAPE_CONFIG(EDITDATE::DATE_FONT_SIZE, __pEditDate->GetOrientation(), __dateFontSize);
127 GET_SHAPE_CONFIG(EDITDATE::TITLE_DATE_MARGIN, __pEditDate->GetOrientation(), titledateMargin);
128 GET_SHAPE_CONFIG(EDITDATE::DATE_HEIGHT, __pEditDate->GetOrientation(), dateHeight);
129 GET_SHAPE_CONFIG(EDITDATE::TITLE_HEIGHT, __pEditDate->GetOrientation(), __titleBounds.height);
131 CalculateElementWidth();
133 if (__pEditDate->GetBoundsF().height > editDateHeight)
135 editDateHeight = __pEditDate->GetBoundsF().height;
138 __pFont = __pEditDate->GetFallbackFont();
140 SysTryReturn(NID_UI_CTRL, __pFont != null, r, r, "[%s] Propagating.", GetErrorMessage(r));
142 if (__title.IsEmpty() == false)
144 __titleBounds.x = leftMargin;
145 __titleBounds.y = (editDateHeight - (__titleBounds.height + titledateMargin + dateHeight)) / 2.0f;
146 __titleBounds.width = editDateWidth;
148 bounds.y = __titleBounds.y + __titleBounds.height + titledateMargin;
150 __dayBounds.height = dateHeight;
151 __monthBounds.height = dateHeight;
152 __yearBounds.height = dateHeight;
154 if (!__isEditDateInitialized)
156 r = InitializeTitleObject();
157 SysTryReturn(NID_UI_CTRL, (r == E_SUCCESS), r, r, "[%s] Propagating.", GetErrorMessage(r));
160 __titleObject.SetBounds(__titleBounds);
164 __dayBounds.height = editDateHeight;
165 __monthBounds.height = editDateHeight;
166 __yearBounds.height = editDateHeight;
169 __dayBounds.width = __elementWidth;
170 __monthBounds.width = __elementWidth;
171 __yearBounds.width = __elementWidth;
173 __dayBounds.x = 0.0f;
174 __monthBounds.x = 0.0f;
175 __yearBounds.x = 0.0f;
177 __dayBounds.y = bounds.y;
178 __monthBounds.y = bounds.y;
179 __yearBounds.y = bounds.y;
181 if (!__isEditDateInitialized)
183 r = InitializeTextObject();
184 SysTryReturn(NID_UI_CTRL, (r == E_SUCCESS), r, r, "[%s] Propagating.", GetErrorMessage(r));
187 __isEditDateInitialized = true;
189 CalculateAreaBounds();
195 _EditDatePresenter::InitializeTitleObject(void)
197 result r = E_SUCCESS;
199 Color titleNormalColor;
201 GET_COLOR_CONFIG(EDITDATE::TITLE_TEXT_NORMAL, titleNormalColor);
203 r = __titleObject.Construct();
204 SysTryReturn(NID_UI_CTRL, (r == E_SUCCESS), r, r, "[%s] Propagating.", GetErrorMessage(r));
206 TextSimple* pSimpleText = null;
208 pSimpleText = new (std::nothrow)TextSimple((const_cast <wchar_t*>(__title.GetPointer())), __title.GetLength(), TEXT_ELEMENT_SOURCE_TYPE_EXTERNAL);
209 SysTryReturn(NID_UI_CTRL, (pSimpleText != null), E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
211 __titleObject.AppendElement(*pSimpleText);
213 __titleObject.SetForegroundColor(titleNormalColor, 0, __titleObject.GetTextLength());
214 __titleObject.SetFont(__pFont, 0, __titleObject.GetTextLength());
215 __titleObject.SetAlignment(TEXT_OBJECT_ALIGNMENT_LEFT | TEXT_OBJECT_ALIGNMENT_MIDDLE);
216 __titleObject.SetWrap(TEXT_OBJECT_WRAP_TYPE_NONE);
217 __titleObject.SetAction(TEXT_OBJECT_ACTION_TYPE_ABBREV);
223 _EditDatePresenter::InitializeTextObject(void)
225 result r = E_SUCCESS;
227 r = __textObject.Construct();
228 SysTryReturn(NID_UI_CTRL, (r == E_SUCCESS), r, r, "[%s] Propagating.", GetErrorMessage(r));
230 TextSimple* pSimpleText = null;
232 pSimpleText = new (std::nothrow)TextSimple(null, 0, TEXT_ELEMENT_SOURCE_TYPE_EXTERNAL);
233 SysTryReturn(NID_UI_CTRL, (pSimpleText != null), E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
235 __textObject.AppendElement(*pSimpleText);
237 __textObject.SetFont(__pFont, 0, __textObject.GetTextLength());
238 __textObject.SetAlignment(TEXT_OBJECT_ALIGNMENT_CENTER | TEXT_OBJECT_ALIGNMENT_MIDDLE);
239 __textObject.SetWrap(TEXT_OBJECT_WRAP_TYPE_NONE);
240 __textObject.SetAction(TEXT_OBJECT_ACTION_TYPE_ABBREV);
246 _EditDatePresenter::GetTextWidth(_DateTimeId boxId) const
248 result r = E_SUCCESS;
250 TextObject dateObject;
256 _DateTimeUtils dateTimeUtils;
257 monthString = dateTimeUtils.GetMonthString(GetMonth());
258 yearString.Format(10, L"%04d", GetYear());
259 dayString.Format(10, L"%02d", GetDay());
261 r = dateObject.Construct();
262 SysTryReturn(NID_UI_CTRL, (r == E_SUCCESS), r, r, "[%s] Propagating.", GetErrorMessage(r));
264 TextSimple* pSimpleText = null;
266 if (boxId == DATETIME_ID_DAY)
268 pSimpleText = new (std::nothrow)TextSimple((const_cast <wchar_t*>(dayString.GetPointer())), dayString.GetLength(), TEXT_ELEMENT_SOURCE_TYPE_EXTERNAL);
270 else if (boxId == DATETIME_ID_MONTH)
272 pSimpleText = new (std::nothrow)TextSimple((const_cast <wchar_t*>(monthString.GetPointer())), monthString.GetLength(), TEXT_ELEMENT_SOURCE_TYPE_EXTERNAL);
274 else if (boxId == DATETIME_ID_YEAR)
276 pSimpleText = new (std::nothrow)TextSimple((const_cast <wchar_t*>(yearString.GetPointer())), yearString.GetLength(), TEXT_ELEMENT_SOURCE_TYPE_EXTERNAL);
279 SysTryReturn(NID_UI_CTRL, (pSimpleText != null), dim.width, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
281 dateObject.AppendElement(*pSimpleText);
282 dateObject.SetFont(__pFont, 0, dateObject.GetTextLength());
283 dim = dateObject.GetTextExtentF(0, dateObject.GetTextLength());
285 dateObject.RemoveAll();
291 _EditDatePresenter::GetLocaleDateFormat(void) const
293 int localeDateFormat = -1;
294 int error = vconf_get_int(VCONFKEY_SETAPPL_DATE_FORMAT_INT, &localeDateFormat);
297 localeDateFormat = SETTING_DATE_FORMAT_DD_MM_YYYY;
300 return localeDateFormat;
304 _EditDatePresenter::GetDate(void) const
306 SysAssertf((__pEditDateTimeModel != null), "The _EditDateTimeModel instance is null.");
309 date.SetValue(GetYear(), GetMonth(), GetDay(), DATETIME_HOUR_MIN, DATETIME_MINUTE_MIN);
315 _EditDatePresenter::GetDay(void) const
317 SysAssertf((__pEditDateTimeModel != null), "The _EditDateTimeModel instance is null.");
319 return __pEditDateTimeModel->GetDay();
323 _EditDatePresenter::GetMonth(void) const
325 SysAssertf((__pEditDateTimeModel != null), "The _EditDateTimeModel instance is null.");
327 return __pEditDateTimeModel->GetMonth();
331 _EditDatePresenter::GetYear(void) const
333 SysAssertf((__pEditDateTimeModel != null), "The _EditDateTimeModel instance is null.");
335 return __pEditDateTimeModel->GetYear();
339 _EditDatePresenter::SetDate(const DateTime& date)
341 SysAssertf((__pEditDateTimeModel != null), "The _EditDateTimeModel instance is null.");
343 __pEditDateTimeModel->SetDateTime(date);
348 _EditDatePresenter::SetCurrentDate(void)
350 SysAssertf((__pEditDateTimeModel != null), "The _EditDateTimeModel instance is null.");
352 __pEditDateTimeModel->SetCurrentDateTime();
357 _EditDatePresenter::SetYear(int year)
359 SysAssertf((__pEditDateTimeModel != null), "The _EditDateTimeModel instance is null.");
361 return __pEditDateTimeModel->SetYear(year);
365 _EditDatePresenter::SetMonth(int month)
367 SysAssertf((__pEditDateTimeModel != null), "The _EditDateTimeModel instance is null.");
369 return __pEditDateTimeModel->SetMonth(month);
373 _EditDatePresenter::SetDay(int day)
375 SysAssertf((__pEditDateTimeModel != null), "The _EditDateTimeModel instance is null.");
377 return __pEditDateTimeModel->SetDay(day);
381 _EditDatePresenter::SetDatePickerEnabled(bool enable)
383 __datePickerEnabled = enable;
388 _EditDatePresenter::IsDatePickerEnabled(void) const
390 return __datePickerEnabled;
394 _EditDatePresenter::SetMinYear(int minYear)
396 return __pEditDateTimeModel->SetMinYear(minYear);
400 _EditDatePresenter::SetMaxYear(int maxYear)
402 return __pEditDateTimeModel->SetMaxYear(maxYear);
406 _EditDatePresenter::GetMinYear(void) const
411 __pEditDateTimeModel->GetYearRange(minYear, maxYear);
417 _EditDatePresenter::GetMaxYear(void) const
422 __pEditDateTimeModel->GetYearRange(minYear, maxYear);
428 _EditDatePresenter::Draw(void)
430 result r = E_SUCCESS;
437 Canvas* pCanvas = __pEditDate->GetCanvasN();
438 SysAssertf((pCanvas != null), "Failed to get canvas.");
440 pCanvas->SetBackgroundColor(Color(0, 0, 0, 0));
443 if (__title.IsEmpty() == false)
452 _DateTimeUtils dateTimeUtils;
453 monthString = dateTimeUtils.GetMonthString(GetMonth());
454 yearString.Format(10, L"%04d", GetYear());
455 dayString.Format(10, L"%02d", GetDay());
457 CalculateAreaBounds();
459 r = DrawText(*pCanvas, GetDateAreaBounds(DATETIME_ID_DAY), dayString, DATETIME_ID_DAY);
460 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
461 r = DrawText(*pCanvas, GetDateAreaBounds(DATETIME_ID_MONTH), monthString, DATETIME_ID_MONTH);
462 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
463 r = DrawText(*pCanvas, GetDateAreaBounds(DATETIME_ID_YEAR), yearString, DATETIME_ID_YEAR);
464 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
466 r = DrawDividers(*pCanvas);
467 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
469 CalculateTouchAreaBounds();
481 _EditDatePresenter::CalculateAreaBounds(void)
483 result r = E_SUCCESS;
485 if (GetLocaleDateFormat() == DATE_FORMAT_DDMMYYYY)
487 __monthBounds.x = __dayBounds.x + __dayBounds.width + __dividerLineWidth;
488 __yearBounds.x = __monthBounds.x + __monthBounds.width + __dividerLineWidth;
490 else if (GetLocaleDateFormat() == DATE_FORMAT_MMDDYYYY)
492 __dayBounds.x = __monthBounds.x + __monthBounds.width + __dividerLineWidth;
493 __yearBounds.x = __dayBounds.x + __dayBounds.width + __dividerLineWidth;
495 else if (GetLocaleDateFormat() == DATE_FORMAT_YYYYMMDD)
497 __monthBounds.x = __yearBounds.x + __yearBounds.width + __dividerLineWidth;
498 __dayBounds.x = __monthBounds.x + __monthBounds.width + __dividerLineWidth;
500 else if (GetLocaleDateFormat() == DATE_FORMAT_YYYYDDMM)
502 __dayBounds.x = __yearBounds.x + __yearBounds.width + __dividerLineWidth;
503 __monthBounds.x = __dayBounds.x + __dayBounds.width + __dividerLineWidth;
510 _EditDatePresenter::CalculateTouchAreaBounds(void)
512 __dayTouchBounds.width = GetTextWidth(DATETIME_ID_DAY);
513 __dayTouchBounds.x = __dayBounds.x + (__elementWidth - __dayTouchBounds.width) / 2.0f;
514 __dayTouchBounds.y = __dayBounds.y;
515 __dayTouchBounds.height = __dayBounds.height;
517 __monthTouchBounds.width = GetTextWidth(DATETIME_ID_MONTH);
518 __monthTouchBounds.x = __monthBounds.x + (__elementWidth - __monthTouchBounds.width) / 2.0f;
519 __monthTouchBounds.y = __monthBounds.y;
520 __monthTouchBounds.height = __monthBounds.height;
522 __yearTouchBounds.width = GetTextWidth(DATETIME_ID_YEAR);
523 __yearTouchBounds.x = __yearBounds.x + (__elementWidth - __yearTouchBounds.width) / 2.0f;
524 __yearTouchBounds.y = __yearBounds.y;
525 __yearTouchBounds.height = __yearBounds.height;
531 _EditDatePresenter::CalculateElementWidth(void)
533 FloatRectangle bounds;
534 FloatDimension minSize;
535 bounds = __pEditDate->GetBoundsF();
537 float elementMinWidth = 0.0f;
539 float minWidth = 0.0f;
541 GET_SHAPE_CONFIG(EDITDATE::TEXT_ELEMENT_WIDTH, __pEditDate->GetOrientation(), __elementWidth);
542 GET_SHAPE_CONFIG(EDITDATE::TEXT_ELEMENT_MIN_WIDTH, __pEditDate->GetOrientation(), elementMinWidth);
543 GET_SHAPE_CONFIG(EDITDATE::WIDTH, __pEditDate->GetOrientation(), width);
544 GET_DIMENSION_CONFIG(EDITDATE::MIN_SIZE, __pEditDate->GetOrientation(), minSize);
546 if (bounds.width >= width)
551 if (bounds.width <= minSize.width)
553 __elementWidth = elementMinWidth;
555 else if (bounds.width < width && bounds.width > minSize.width)
557 __elementWidth = __elementWidth - ((__elementWidth - elementMinWidth) / (width - minWidth)) * (width - bounds.width);
564 _EditDatePresenter::DrawTitle(Canvas& canvas)
566 if (!__pEditDate->IsEnabled())
568 Color titleDisabledColor;
569 GET_COLOR_CONFIG(EDITDATE::TITLE_TEXT_DISABLED, titleDisabledColor);
570 __titleObject.SetForegroundColor(titleDisabledColor, 0, __titleObject.GetTextLength());
573 (_FontImpl::GetInstance(*__pFont))->SetSize(__titleFontSize);
574 __titleObject.SetFont(__pFont, 0, __titleObject.GetTextLength());
575 __titleObject.Draw(*_CanvasImpl::GetInstance(canvas));
581 _EditDatePresenter::DrawText(Canvas& canvas, const FloatRectangle& bounds, const String& text, _DateTimeId boxId)
585 if (!__pEditDate->IsEnabled())
587 GET_COLOR_CONFIG(EDITDATE::TEXT_DISABLED, textColor);
591 GET_COLOR_CONFIG(EDITDATE::TEXT_NORMAL, textColor);
594 if (boxId == __selectedId && boxId != DATETIME_ID_NONE)
596 GET_COLOR_CONFIG(EDITDATE::TEXT_PRESSED, textColor);
599 FloatRectangle drawAreaBounds(0.0f, 0.0f, 0.0f, 0.0f);
600 drawAreaBounds = bounds;
602 TextSimple* pSimpleText = null;
603 pSimpleText = new (std::nothrow)TextSimple((const_cast <wchar_t*>(text.GetPointer())), text.GetLength(), TEXT_ELEMENT_SOURCE_TYPE_EXTERNAL);
604 SysTryReturn(NID_UI_CTRL, (pSimpleText != null), E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
606 __textObject.RemoveAll();
608 (_FontImpl::GetInstance(*__pFont))->SetSize(__dateFontSize);
610 __textObject.AppendElement(*pSimpleText);
612 __textObject.SetFont(__pFont, 0, __textObject.GetTextLength());
613 __textObject.SetForegroundColor(textColor, 0, __textObject.GetTextLength());
614 __textObject.SetBounds(drawAreaBounds);
615 __textObject.Draw(*_CanvasImpl::GetInstance(canvas));
621 _EditDatePresenter::DrawDividers(Canvas& canvas)
623 result r = E_SUCCESS;
625 float editDateHeight = 0.0f;
626 float dateHeight = 0.0f;
628 GET_SHAPE_CONFIG(EDITDATE::DATE_HEIGHT, __pEditDate->GetOrientation(), dateHeight);
629 GET_SHAPE_CONFIG(EDITDATE::HEIGHT, __pEditDate->GetOrientation(), editDateHeight);
631 if (__pEditDate->GetBoundsF().height > editDateHeight)
633 editDateHeight = __pEditDate->GetBoundsF().height;
636 Color dividerHalfLeftColor;
637 Color dividerHalfRightColor;
639 GET_COLOR_CONFIG(EDITDATE::DIVIDER_LEFT_HALF, dividerHalfLeftColor);
640 GET_COLOR_CONFIG(EDITDATE::DIVIDER_RIGHT_HALF, dividerHalfRightColor);
642 FloatRectangle bounds(0.0f, 0.0f, 0.0f, 0.0f);
644 bounds.x = __elementWidth;
646 if (__title.IsEmpty() == false)
648 bounds.y = __dayBounds.y + ((dateHeight - __dividerLineHeight) / 2.0f);
652 bounds.y = __dayBounds.y + ((editDateHeight - __dividerLineHeight) / 2.0f);
655 for (int divider = 0; divider < __dividerCount; divider++)
657 canvas.SetForegroundColor(dividerHalfLeftColor);
658 canvas.SetLineWidth(__dividerLineWidth / 2.0f);
660 r = canvas.DrawLine(FloatPoint(bounds.x, bounds.y), FloatPoint(bounds.x, bounds.y + __dividerLineHeight));
661 SysTryReturnResult(NID_UI_CTRL, (r == E_SUCCESS), r, "[%s] Propagating.", GetErrorMessage(r));
663 canvas.SetForegroundColor(dividerHalfRightColor);
664 canvas.SetLineWidth(__dividerLineWidth / 2.0f);
666 r = canvas.DrawLine(FloatPoint(bounds.x + 1.0f, bounds.y), FloatPoint(bounds.x + 1.0f, bounds.y + __dividerLineHeight));
667 SysTryReturnResult(NID_UI_CTRL, (r == E_SUCCESS), r, "[%s] Propagating.", GetErrorMessage(r));
669 bounds.x = bounds.x + __elementWidth;
675 _EditDatePresenter::GetBoxIdFromPosition(const FloatPoint& point) const
677 _DateTimeId displayBoxId = DATETIME_ID_NONE;
679 if (point.y < __dayTouchBounds.y || point.y > __dayTouchBounds.y + __dayTouchBounds.height)
684 if (__dayTouchBounds.Contains(point) == true)
686 displayBoxId = DATETIME_ID_DAY;
688 else if (__monthTouchBounds.Contains(point) == true)
690 displayBoxId = DATETIME_ID_MONTH;
692 else if (__yearTouchBounds.Contains(point) == true)
694 displayBoxId = DATETIME_ID_YEAR;
701 _EditDatePresenter::GetDateAreaBounds(_DateTimeId id) const
703 if (id == DATETIME_ID_DAY)
707 else if (id == DATETIME_ID_MONTH)
709 return __monthBounds;
711 else if (id == DATETIME_ID_YEAR)
717 return FloatRectangle();
722 _EditDatePresenter::GetTitleBounds(void) const
724 return __titleBounds;
728 _EditDatePresenter::SetLastSelectedId(_DateTimeId boxId)
730 __lastSelectedId = boxId;
735 _EditDatePresenter::GetLastSelectedId(void) const
737 return __lastSelectedId;
741 _EditDatePresenter::OnFontChanged(Font* pFont)
745 if (__pEditDate->GetDateTimeBar() != null)
747 __pEditDate->GetDateTimeBar()->SetFont(*pFont);
754 _EditDatePresenter::OnFontInfoRequested(unsigned long& style, float& size)
756 style = FONT_STYLE_PLAIN;
757 size = __dateFontSize;
763 _EditDatePresenter::OnTouchPressed(const _Control& source, const _TouchInfo& touchinfo)
765 SysTryReturn(NID_UI_CTRL, IsDatePickerEnabled() == true, true, E_SYSTEM,
766 "[E_SYSTEM] A system error has occurred. EditDate instance is disabled.");
768 if (&source != __pEditDate)
773 __touchMoveHandled = false;
775 FloatPoint point = touchinfo.GetCurrentPosition();
777 _DateTimeId boxId = DATETIME_ID_NONE;
778 boxId = GetBoxIdFromPosition(point);
780 if (boxId < DATETIME_ID_YEAR || boxId > DATETIME_ID_DAY)
782 __selectedId = DATETIME_ID_NONE;
788 int displayValue = -1;
790 if (boxId == DATETIME_ID_DAY)
792 if (__pEditDate->GetDateTimeBar() != null)
794 _DateTimeUtils dateTimeUtils;
795 maxValue = dateTimeUtils.CalculateMaxDay(GetYear(), GetMonth());
796 minValue = DATETIME_DAY_MIN;
797 displayValue = GetDay();
800 else if (boxId == DATETIME_ID_MONTH)
802 minValue = DATETIME_MONTH_MIN;
803 maxValue = DATETIME_MONTH_MAX;
804 displayValue = GetMonth();
806 else if (boxId == DATETIME_ID_YEAR)
808 minValue = GetMinYear();
809 maxValue = GetMaxYear();
810 displayValue = GetYear();
813 if (__pEditDate->GetDateTimeBar() != null)
815 if (__pEditDate->GetDateTimeBar()->GetItemCount() > 0)
817 __pEditDate->GetDateTimeBar()->RemoveAllItems();
820 result r = __pEditDate->GetDateTimeBar()->SetInitialValue(minValue, maxValue, displayValue, boxId);
823 __selectedId = DATETIME_ID_NONE;
828 __selectedId = boxId;
834 _EditDatePresenter::OnTouchReleased(const _Control& source, const _TouchInfo& touchinfo)
836 SysTryReturn(NID_UI_CTRL, IsDatePickerEnabled() == true, true, E_SYSTEM,
837 "[E_SYSTEM] A system error has occurred. EditDate instance is disabled.");
839 if (&source != __pEditDate)
844 FloatPoint point = touchinfo.GetCurrentPosition();
846 _DateTimeId boxId = DATETIME_ID_NONE;
847 boxId = GetBoxIdFromPosition(point);
849 if (boxId == GetLastSelectedId() || boxId != __selectedId || boxId == DATETIME_ID_NONE)
851 if (__pEditDate->GetDateTimeBar() != null && __pEditDate->GetDateTimeBar()->IsActivated())
853 __pEditDate->GetDateTimeBar()->SetVisibleState(false);
854 __pEditDate->GetDateTimeBar()->Close();
857 __selectedId = DATETIME_ID_NONE;
858 SetLastSelectedId(__selectedId);
865 SetLastSelectedId(__selectedId);
867 __lastSelectedValue = "";
868 _DateTimeUtils dateTimeUtils;
869 if (GetLastSelectedId() == DATETIME_ID_YEAR)
871 __lastSelectedValue.Format(10, L"%04d", GetYear());
872 PLAY_FEEDBACK(_RESOURCE_FEEDBACK_PATTERN_TAP);
874 else if (GetLastSelectedId() == DATETIME_ID_MONTH)
876 __lastSelectedValue = dateTimeUtils.GetMonthString(GetMonth());
877 PLAY_FEEDBACK(_RESOURCE_FEEDBACK_PATTERN_TAP);
879 else if (GetLastSelectedId() == DATETIME_ID_DAY)
881 __lastSelectedValue.Format(10, L"%02d", GetDay());
882 PLAY_FEEDBACK(_RESOURCE_FEEDBACK_PATTERN_TAP);
887 if ((__pEditDate->GetDateTimeBar() != null) && (GetLastSelectedId() != DATETIME_ID_NONE))
889 FloatRectangle bounds(0.0f, 0.0f, 0.0f, 0.0f);
890 bounds = GetDateAreaBounds(GetLastSelectedId());
891 FloatRectangle absoluteBounds(0.0f, 0.0f, 0.0f, 0.0f);
892 absoluteBounds = __pEditDate->GetAbsoluteBoundsF();
893 bounds.x += absoluteBounds.x;
895 __pEditDate->GetDateTimeBar()->CalculateArrowBounds(bounds);
897 if (__pEditDate->GetDateTimeBar()->IsActivated())
899 __pEditDate->GetDateTimeBar()->RefreshItems();
903 __pEditDate->GetDateTimeBar()->SetVisibleState(true);
904 __pEditDate->GetDateTimeBar()->Open();
908 __selectedId = DATETIME_ID_NONE;
913 _EditDatePresenter::OnTouchCanceled(const _Control& source, const _TouchInfo& touchinfo)
915 if (&source != __pEditDate)
920 __selectedId = DATETIME_ID_NONE;
926 _EditDatePresenter::OnTouchMoved(const _Control& source, const _TouchInfo& touchinfo)
928 if (&source != __pEditDate)
933 if (__pEditDate->GetDateTimeBar() != null && __pEditDate->GetDateTimeBar()->IsActivated())
942 _EditDatePresenter::OnTouchMoveHandled(const _Control& control)
944 __touchMoveHandled = true;
945 __selectedId = DATETIME_ID_NONE;
951 _EditDatePresenter::Animate(void)
953 SysAssertf((__pFont != null), "Font instance must not be null.");
955 (_FontImpl::GetInstance(*__pFont))->SetSize(__dateFontSize);
957 result r = E_SUCCESS;
964 _DateTimeUtils dateTimeUtils;
965 monthString = dateTimeUtils.GetMonthString(GetMonth());
966 yearString.Format(10, L"%04d", GetYear());
967 dayString.Format(10, L"%02d", GetDay());
969 if (GetLastSelectedId() == DATETIME_ID_DAY)
971 SysTryReturnVoidResult(NID_UI_CTRL, (__lastSelectedValue.Equals(dayString) == false), E_SUCCESS, "Day string matched.");
973 newValue = dayString;
974 rect = GetDateAreaBounds(DATETIME_ID_DAY);
976 else if (GetLastSelectedId() == DATETIME_ID_MONTH)
978 SysTryReturnVoidResult(NID_UI_CTRL, (__lastSelectedValue.Equals(monthString) == false), E_SUCCESS, "Month string matched.");
980 newValue = monthString;
981 rect = GetDateAreaBounds(DATETIME_ID_MONTH);
983 else if (GetLastSelectedId() == DATETIME_ID_YEAR)
985 SysTryReturnVoidResult(NID_UI_CTRL, (__lastSelectedValue.Equals(yearString) == false), E_SUCCESS, "Year string matched.");
987 newValue = yearString;
988 rect = GetDateAreaBounds(DATETIME_ID_YEAR);
991 FloatDimension newTextDim;
992 FloatDimension oldTextDim;
993 FloatPoint textPoint;
994 VisualElement* pNewVisualElement = null;
995 VisualElement* pOldVisualElement = null;
996 VisualElement* pEditDateElement = null;
997 VisualElementPropertyAnimation* pNewBoundsAnimation = null;
998 VisualElementPropertyAnimation* pOldBoundsAnimation = null;
999 Canvas *pCanvas = null;
1001 __pFont->GetTextExtent(newValue, newValue.GetLength(), newTextDim);
1002 __pFont->GetTextExtent(__lastSelectedValue, __lastSelectedValue.GetLength(), oldTextDim);
1004 if (newTextDim.width > oldTextDim.width)
1006 textPoint.x = (rect.width - newTextDim.width) / 2.0f;
1010 textPoint.x = (rect.width - oldTextDim.width) / 2.0f;
1013 SysTryReturnVoidResult(NID_UI_CTRL, (rect.x + textPoint.x < __pEditDate->GetBoundsF().width), E_SUCCESS, "Rolling animation cann't be played.");
1015 __isAnimating = true;
1017 __pContentProvider = new (std::nothrow) VisualElement();
1018 SysTryReturnVoidResult(NID_UI_CTRL, (__pContentProvider != null), E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
1020 r = __pContentProvider->Construct();
1021 SysTryCatch(NID_UI_CTRL, (r == E_SUCCESS), , r, "[%s] Propagating.", GetErrorMessage(r));
1023 __pContentProvider->SetShowState(true);
1024 __pContentProvider->SetClipChildrenEnabled(true);
1025 __pContentProvider->SetImplicitAnimationEnabled(false);
1027 pEditDateElement = __pEditDate->GetVisualElement();
1028 r = GetLastResult();
1029 SysTryCatch(NID_UI_CTRL, (pEditDateElement != null), , r, "[%s] Propagating.", GetErrorMessage(r));
1031 pNewVisualElement = new (std::nothrow) VisualElement();
1032 SysTryCatch(NID_UI_CTRL, (pNewVisualElement != null), , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
1034 r = pNewVisualElement->Construct();
1037 pNewVisualElement->Destroy();
1039 SysTryCatch(NID_UI_CTRL, (r == E_SUCCESS), , r, "[%s] Propagating.", GetErrorMessage(r));
1041 pOldVisualElement = new (std::nothrow) VisualElement();
1042 if (pOldVisualElement == null)
1044 pNewVisualElement->Destroy();
1046 SysTryCatch(NID_UI_CTRL, (pOldVisualElement != null), , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
1048 r = pOldVisualElement->Construct();
1051 pNewVisualElement->Destroy();
1052 pOldVisualElement->Destroy();
1054 SysTryCatch(NID_UI_CTRL, (r == E_SUCCESS), , r, "[%s] Propagating.", GetErrorMessage(r));
1056 pNewVisualElement->SetShowState(true);
1057 pOldVisualElement->SetShowState(true);
1059 if (newTextDim.width > oldTextDim.width)
1061 textPoint.x = (rect.width - newTextDim.width) / 2.0f;
1062 textPoint.y = (rect.height - newTextDim.height) / 2.0f;
1063 __pContentProvider->SetBounds(FloatRectangle((rect.x + textPoint.x) * 1.0f, (rect.y + textPoint.y) * 1.0f, newTextDim.width * 1.0f, newTextDim.height * 1.0f));
1064 pNewVisualElement->SetBounds(FloatRectangle(0.0f, newTextDim.height * 1.0f, newTextDim.width * 1.0f, newTextDim.height * 1.0f));
1066 rect.x = static_cast<int>(__pContentProvider->GetBounds().x);
1067 rect.y = static_cast<int>(__pContentProvider->GetBounds().y);
1068 rect.width = static_cast<int>(__pContentProvider->GetBounds().width);
1069 rect.height = static_cast<int>(__pContentProvider->GetBounds().height);
1071 textPoint.x = (rect.width - oldTextDim.width) / 2.0f;
1072 textPoint.y = (rect.height - oldTextDim.height) / 2.0f;
1074 pOldVisualElement->SetBounds(FloatRectangle(textPoint.x * 1.0f, 0.0f, oldTextDim.width * 1.0f, oldTextDim.height * 1.0f));
1078 textPoint.x = (rect.width - oldTextDim.width) / 2.0f;
1079 textPoint.y = (rect.height - oldTextDim.height) / 2.0f;
1080 __pContentProvider->SetBounds(FloatRectangle((rect.x + textPoint.x) * 1.0f, (rect.y + textPoint.y) * 1.0f, oldTextDim.width * 1.0f, oldTextDim.height * 1.0f));
1081 pOldVisualElement->SetBounds(FloatRectangle(0.0f, 0.0f, oldTextDim.width * 1.0f, oldTextDim.height * 1.0f));
1083 rect.x = static_cast<int>(__pContentProvider->GetBounds().x);
1084 rect.y = static_cast<int>(__pContentProvider->GetBounds().y);
1085 rect.width = static_cast<int>(__pContentProvider->GetBounds().width);
1086 rect.height = static_cast<int>(__pContentProvider->GetBounds().height);
1088 textPoint.x = (rect.width - newTextDim.width) / 2.0f;
1089 textPoint.y = (rect.height - newTextDim.height) / 2.0f;
1091 pNewVisualElement->SetBounds(FloatRectangle(textPoint.x * 1.0f, newTextDim.height * 1.0f, newTextDim.width * 1.0f, newTextDim.height * 1.0f));
1095 pCanvas = pEditDateElement->GetCanvasN(rect);
1096 pCanvas->SetBackgroundColor(Color(0, 0, 0, 0));
1100 pEditDateElement->AttachChild(*__pContentProvider);
1102 __pContentProvider->AttachChild(*pOldVisualElement);
1103 __pContentProvider->AttachChild(*pNewVisualElement);
1105 pNewBoundsAnimation = new (std::nothrow) VisualElementPropertyAnimation();
1106 SysTryCatch(NID_UI_CTRL, (pNewBoundsAnimation != null), , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
1108 pNewBoundsAnimation->SetDuration(300);
1109 pNewBoundsAnimation->SetPropertyName("bounds.position");
1110 pNewBoundsAnimation->SetStartValue(Variant(FloatPoint(pNewVisualElement->GetBounds().x * 1.0f, newTextDim.height * 1.0f)));
1111 pNewBoundsAnimation->SetEndValue(Variant(FloatPoint(pNewVisualElement->GetBounds().x * 1.0f, 0.0f)));
1112 pNewBoundsAnimation->SetVisualElementAnimationStatusEventListener(this);
1114 pOldBoundsAnimation = new (std::nothrow) VisualElementPropertyAnimation();
1115 SysTryCatch(NID_UI_CTRL, (pOldBoundsAnimation != null), , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
1117 pOldBoundsAnimation->SetDuration(300);
1118 pOldBoundsAnimation->SetPropertyName("bounds.position");
1119 pOldBoundsAnimation->SetStartValue(Variant(FloatPoint(pOldVisualElement->GetBounds().x * 1.0f, 0.0f)));
1120 pOldBoundsAnimation->SetEndValue(Variant(FloatPoint(pOldVisualElement->GetBounds().x * 1.0f, oldTextDim.height * -1.0f)));
1121 pOldBoundsAnimation->SetVisualElementAnimationStatusEventListener(this);
1123 pCanvas = pOldVisualElement->GetCanvasN();
1124 r = GetLastResult();
1125 SysTryCatch(NID_UI_CTRL, (pCanvas != null), , r, "[%s] Propagating.", GetErrorMessage(r));
1127 pCanvas->SetBackgroundColor(Color(0, 0, 0, 0));
1129 pCanvas->SetFont(*__pFont);
1130 pCanvas->DrawText(FloatPoint(0.0f, 0.0f), __lastSelectedValue);
1135 pCanvas = pNewVisualElement->GetCanvasN();
1136 r = GetLastResult();
1137 SysTryCatch(NID_UI_CTRL, (pCanvas != null), , r, "[%s] Propagating.", GetErrorMessage(r));
1139 pCanvas->SetBackgroundColor(Color(0, 0, 0, 0));
1141 pCanvas->SetFont(*__pFont);
1142 pCanvas->DrawText(FloatPoint(0.0f, 0.0f), newValue);
1147 pOldVisualElement->SetImplicitAnimationEnabled(false);
1148 pOldVisualElement->AddAnimation(*pOldBoundsAnimation);
1150 pNewVisualElement->SetImplicitAnimationEnabled(false);
1151 pNewVisualElement->AddAnimation(*pNewBoundsAnimation);
1153 delete pOldBoundsAnimation;
1154 delete pNewBoundsAnimation;
1159 __isAnimating = false;
1160 __pContentProvider->Destroy();
1162 delete pNewBoundsAnimation;
1163 pNewBoundsAnimation = null;
1165 delete pOldBoundsAnimation;
1166 pOldBoundsAnimation = null;
1175 _EditDatePresenter::OnVisualElementAnimationFinished (const VisualElementAnimation &animation, const String &keyName, VisualElement &target, bool completedNormally)
1177 result r = E_SUCCESS;
1178 __isAnimating = false;
1180 VisualElement* pEditDateElement = __pEditDate->GetVisualElement();
1181 r = GetLastResult();
1182 SysTryReturnVoidResult(NID_UI_CTRL, (pEditDateElement != null), r, "[%s] Propagating.", GetErrorMessage(r));
1184 pEditDateElement->DetachChild(*__pContentProvider);
1185 __pContentProvider->Destroy();
1191 }}} // Tizen::Ui::Controls