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 <FGrpColor.h>
25 #include <FUiControl.h>
26 #include <FUiAnimAnimationTransaction.h>
27 #include <FUiAnimVisualElementPropertyAnimation.h>
28 #include <FGrp_TextTextObject.h>
29 #include <FGrp_TextTextSimple.h>
30 #include <FGrp_CanvasImpl.h>
31 #include <FGrp_BitmapImpl.h>
32 #include <FGrp_FontImpl.h>
33 #include "FUi_ResourceManager.h"
34 #include "FUi_CoordinateSystemUtils.h"
35 #include "FUiAnim_VisualElement.h"
36 #include "FUiCtrl_EditDatePresenter.h"
37 #include "FUiCtrl_EditDate.h"
38 #include "FUiCtrl_DateTimeModel.h"
39 #include "FUiCtrl_DateTimeUtils.h"
41 using namespace Tizen::Graphics;
42 using namespace Tizen::Base;
43 using namespace Tizen::Graphics::_Text;
44 using namespace Tizen::Ui::Animations;
47 namespace Tizen { namespace Ui { namespace Controls
49 _EditDatePresenter::_EditDatePresenter(void)
50 : __pEditDateTimeModel(null)
52 , __dayBounds(FloatRectangle())
53 , __monthBounds(FloatRectangle())
54 , __yearBounds(FloatRectangle())
55 , __dayTouchBounds(FloatRectangle())
56 , __monthTouchBounds(FloatRectangle())
57 , __yearTouchBounds(FloatRectangle())
58 , __titleBounds(FloatRectangle())
59 , __pContentBgNormalColorReplacementBitmap(null)
60 , __pContentBgDisabledColorReplacementBitmap(null)
61 , __pContentBgPressedColorReplacementBitmap(null)
62 , __pContentBgHighlightedColorReplacementBitmap(null)
63 , __pContentBgEffectNormalBitmap(null)
64 , __pContentBgEffectPressedBitmap(null)
65 , __pContentBgEffectDisabledBitmap(null)
66 , __datePickerEnabled(true)
67 , __selectedId(DATETIME_ID_NONE)
68 , __lastSelectedId(DATETIME_ID_NONE)
69 , __focusId(DATETIME_ID_NONE)
70 , __touchMoveHandled(false)
74 , __elementMargin(0.0f)
75 , __dividerLineHeight(0.0f)
76 , __titleFontSize(0.0f)
77 , __dateFontSize(0.0f)
78 , __pContentProvider(null)
79 , __isAnimating(false)
80 , __isEditDateInitialized(false)
81 , __elementWidth(0.0f)
82 , __isEnterKeyPressed(false)
88 _EditDatePresenter::~_EditDatePresenter(void)
90 __titleObject.RemoveAll();
91 __textObject.RemoveAll();
93 delete __pEditDateTimeModel;
94 __pEditDateTimeModel = null;
96 delete __pContentBgNormalColorReplacementBitmap;
97 __pContentBgNormalColorReplacementBitmap = null;
99 delete __pContentBgDisabledColorReplacementBitmap;
100 __pContentBgDisabledColorReplacementBitmap = null;
102 delete __pContentBgPressedColorReplacementBitmap;
103 __pContentBgPressedColorReplacementBitmap = null;
105 delete __pContentBgHighlightedColorReplacementBitmap;
106 __pContentBgHighlightedColorReplacementBitmap = null;
108 delete __pContentBgEffectNormalBitmap;
109 __pContentBgEffectNormalBitmap = null;
111 delete __pContentBgEffectPressedBitmap;
112 __pContentBgEffectPressedBitmap = null;
114 delete __pContentBgEffectDisabledBitmap;
115 __pContentBgEffectDisabledBitmap = null;
117 if (__transactionId != 0)
119 AnimationTransaction::Stop(__transactionId);
122 if (__pContentProvider != null)
124 __pEditDate->GetVisualElement()->DetachChild(__pContentProvider);
125 __pContentProvider->Destroy();
126 __pContentProvider = null;
131 _EditDatePresenter::CreateInstanceN(const _EditDate& editDate, const String& title)
133 _EditDatePresenter* pEditDatePresenter = new (std::nothrow) _EditDatePresenter;
134 SysTryReturn(NID_UI_CTRL, pEditDatePresenter, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
136 pEditDatePresenter->__pEditDate = const_cast <_EditDate*>(&editDate);
138 pEditDatePresenter->__pEditDateTimeModel = new (std::nothrow) _DateTimeModel;
139 SysTryCatch(NID_UI_CTRL, pEditDatePresenter->__pEditDateTimeModel, , E_OUT_OF_MEMORY,
140 "[E_OUT_OF_MEMORY] Memory allocation failed.");
141 pEditDatePresenter->SetTitle(title);
143 return pEditDatePresenter;
146 delete pEditDatePresenter;
151 _EditDatePresenter::SetTitle(const String& title)
157 _EditDatePresenter::Initialize(void)
159 result r = E_SUCCESS;
160 float editDateHeight = 0.0f;
161 float dateLeftMargin = 0.0f;
162 float titleLeftMargin = 0.0f;
163 float titledateMargin = 0.0f;
164 float dateHeight = 0.0f;
165 float monthYearMinWidth = 0.0f;
166 float dayElementWidth = 0.0f;
167 float dayElementMinWidth = 0.0f;
168 FloatRectangle bounds(0.0f, 0.0f, 0.0f, 0.0f);
170 GET_SHAPE_CONFIG(EDITDATE::HEIGHT, __pEditDate->GetOrientation(), editDateHeight);
171 GET_SHAPE_CONFIG(EDITDATE::TITLE_TEXT_LEFT_MARGIN, __pEditDate->GetOrientation(), titleLeftMargin);
172 GET_SHAPE_CONFIG(EDITDATE::ITEM_DIVIDER_HEIGHT, __pEditDate->GetOrientation(), __dividerLineHeight);
173 GET_SHAPE_CONFIG(EDITDATE::TEXT_FONT_SIZE, __pEditDate->GetOrientation(), __titleFontSize);
174 GET_SHAPE_CONFIG(EDITDATE::DATE_FONT_SIZE, __pEditDate->GetOrientation(), __dateFontSize);
175 GET_SHAPE_CONFIG(EDITDATE::TITLE_DATE_MARGIN, __pEditDate->GetOrientation(), titledateMargin);
176 GET_SHAPE_CONFIG(EDITDATE::DATE_HEIGHT, __pEditDate->GetOrientation(), dateHeight);
177 GET_SHAPE_CONFIG(EDITDATE::TITLE_HEIGHT, __pEditDate->GetOrientation(), __titleBounds.height);
178 GET_SHAPE_CONFIG(EDITDATE::MONTH_YEAR_ELEMENT_WIDTH, __pEditDate->GetOrientation(), __elementWidth);
179 GET_SHAPE_CONFIG(EDITDATE::DAY_ELEMENT_WIDTH, __pEditDate->GetOrientation(), dayElementWidth);
180 GET_SHAPE_CONFIG(EDITDATE::ELEMENT_MARGIN, __pEditDate->GetOrientation(), __elementMargin);
181 GET_SHAPE_CONFIG(EDITDATE::DATE_TEXT_LEFT_MARGIN, __pEditDate->GetOrientation(), dateLeftMargin);
183 GET_SHAPE_CONFIG(EDITDATE::MONTH_YEAR_ELEMENT_MIN_WIDTH, __pEditDate->GetOrientation(), monthYearMinWidth);
184 GET_SHAPE_CONFIG(EDITDATE::DAY_ELEMENT_MIN_WIDTH, __pEditDate->GetOrientation(), dayElementMinWidth);
186 if (__pEditDate->GetBoundsF().height > editDateHeight)
188 editDateHeight = __pEditDate->GetBoundsF().height;
191 __pFont = __pEditDate->GetFallbackFont();
193 SysTryReturn(NID_UI_CTRL, __pFont != null, r, r, "[%s] Propagating.", GetErrorMessage(r));
195 if (!__title.IsEmpty())
197 __titleBounds.x = titleLeftMargin;
198 __titleBounds.y = (editDateHeight - (__titleBounds.height + titledateMargin + dateHeight)) / 2.0f;
199 __titleBounds.width = __pEditDate->GetBoundsF().width - __titleBounds.x;
201 bounds.y = __titleBounds.y + __titleBounds.height + titledateMargin;
203 if (!__isEditDateInitialized)
205 r = InitializeTitleObject();
206 SysTryReturn(NID_UI_CTRL, (r == E_SUCCESS), r, r, "[%s] Propagating.", GetErrorMessage(r));
209 __titleObject.SetBounds(__titleBounds);
213 bounds.y = (editDateHeight - dateHeight) / 2.0f;
217 dayElementWidth = GetElementWidth(dayElementMinWidth, dayElementWidth);
218 __elementWidth = GetElementWidth(monthYearMinWidth, __elementWidth);
220 __dayBounds.height = dateHeight;
221 __monthBounds.height = dateHeight;
222 __yearBounds.height = dateHeight;
224 __dayBounds.width = dayElementWidth;
225 __monthBounds.width = __elementWidth;
226 __yearBounds.width = __elementWidth;
228 __dayBounds.x = dateLeftMargin;
229 __monthBounds.x = dateLeftMargin;
230 __yearBounds.x = dateLeftMargin;
232 __dayBounds.y = bounds.y;
233 __monthBounds.y = bounds.y;
234 __yearBounds.y = bounds.y;
236 if (!__isEditDateInitialized)
239 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
241 r = InitializeTextObject();
242 SysTryReturn(NID_UI_CTRL, (r == E_SUCCESS), r, r, "[%s] Propagating.", GetErrorMessage(r));
245 __isEditDateInitialized = true;
247 CalculateAreaBounds();
252 _EditDatePresenter::InitializeTitleObject(void)
254 result r = E_SUCCESS;
256 Color titleNormalColor;
258 GET_COLOR_CONFIG(EDITDATE::TITLE_TEXT_NORMAL, titleNormalColor);
260 r = __titleObject.Construct();
261 SysTryReturn(NID_UI_CTRL, (r == E_SUCCESS), r, r, "[%s] Propagating.", GetErrorMessage(r));
263 TextSimple* pSimpleText = null;
265 pSimpleText = new (std::nothrow)TextSimple((const_cast <wchar_t*>(__title.GetPointer())), __title.GetLength(), TEXT_ELEMENT_SOURCE_TYPE_EXTERNAL);
266 SysTryReturn(NID_UI_CTRL, (pSimpleText != null), E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
268 __titleObject.AppendElement(*pSimpleText);
270 __titleObject.SetForegroundColor(titleNormalColor, 0, __titleObject.GetTextLength());
271 __titleObject.SetFont(__pFont, 0, __titleObject.GetTextLength());
272 __titleObject.SetAlignment(TEXT_OBJECT_ALIGNMENT_LEFT | TEXT_OBJECT_ALIGNMENT_MIDDLE);
273 __titleObject.SetWrap(TEXT_OBJECT_WRAP_TYPE_NONE);
274 __titleObject.SetAction(TEXT_OBJECT_ACTION_TYPE_ABBREV);
275 __titleObject.SetTextObjectEllipsisType(TEXT_OBJECT_ELLIPSIS_TYPE_TAIL);
281 _EditDatePresenter::InitializeTextObject(void)
283 result r = E_SUCCESS;
285 r = __textObject.Construct();
286 SysTryReturn(NID_UI_CTRL, (r == E_SUCCESS), r, r, "[%s] Propagating.", GetErrorMessage(r));
288 TextSimple* pSimpleText = null;
290 pSimpleText = new (std::nothrow)TextSimple(null, 0, TEXT_ELEMENT_SOURCE_TYPE_EXTERNAL);
291 SysTryReturn(NID_UI_CTRL, (pSimpleText != null), E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
293 pSimpleText->SetTextShadowEnabled(true);
294 pSimpleText->SetTextShadowOffset(FloatPoint(0.0f, -1.0f));
296 __textObject.AppendElement(*pSimpleText);
298 __textObject.SetFont(__pFont, 0, __textObject.GetTextLength());
299 __textObject.SetAlignment(TEXT_OBJECT_ALIGNMENT_CENTER | TEXT_OBJECT_ALIGNMENT_MIDDLE);
300 __textObject.SetWrap(TEXT_OBJECT_WRAP_TYPE_NONE);
301 __textObject.SetAction(TEXT_OBJECT_ACTION_TYPE_ABBREV);
307 _EditDatePresenter::GetElementWidth(const float minWidth, const float maxWidth) const
309 FloatRectangle bounds;
310 FloatDimension minSize;
311 bounds = __pEditDate->GetBoundsF();
313 float elementWidth = 0.0f;
314 float editDateWidth = 0.0f;
316 GET_SHAPE_CONFIG(EDITDATE::WIDTH, __pEditDate->GetOrientation(), editDateWidth);
317 GET_DIMENSION_CONFIG(EDITDATE::MIN_SIZE, __pEditDate->GetOrientation(), minSize);
319 if (bounds.width >= editDateWidth)
324 if (bounds.width <= minSize.width)
326 elementWidth = minWidth;
328 else if (bounds.width < editDateWidth && bounds.width > minSize.width)
330 elementWidth = maxWidth -
331 ((maxWidth - minWidth) / (editDateWidth - minSize.width)) * (editDateWidth - bounds.width);
338 _EditDatePresenter::LoadResource(void)
340 result r = E_SUCCESS;
342 Color contentNormalBgColor;
343 Color contentDisabledBgColor;
344 Color contentPressedColor;
345 Color contentHighlightedColor;
347 GET_COLOR_CONFIG(EDITDATE::CONTENT_BG_NORMAL, contentNormalBgColor);
348 GET_COLOR_CONFIG(EDITDATE::CONTENT_BG_DISABLED, contentDisabledBgColor);
349 GET_COLOR_CONFIG(EDITDATE::CONTENT_BG_PRESSED, contentPressedColor);
350 GET_COLOR_CONFIG(EDITDATE::CONTENT_BG_HIGHLIGHTED, contentHighlightedColor);
352 r = GET_REPLACED_BITMAP_CONFIG_N(EDITDATE::CONTENT_BG_NORMAL, BITMAP_PIXEL_FORMAT_ARGB8888, contentNormalBgColor, __pContentBgNormalColorReplacementBitmap);
353 SysTryCatch(NID_UI_CTRL, (r == E_SUCCESS), , r, "[%s] Propagating.", GetErrorMessage(r));
355 r = GET_REPLACED_BITMAP_CONFIG_N(EDITDATE::CONTENT_BG_PRESSED, BITMAP_PIXEL_FORMAT_ARGB8888, contentPressedColor, __pContentBgPressedColorReplacementBitmap);
356 SysTryCatch(NID_UI_CTRL, (r == E_SUCCESS), , r, "[%s] Propagating.", GetErrorMessage(r));
358 r = GET_REPLACED_BITMAP_CONFIG_N(EDITDATE::CONTENT_BG_DISABLED, BITMAP_PIXEL_FORMAT_ARGB8888, contentDisabledBgColor, __pContentBgDisabledColorReplacementBitmap);
359 SysTryCatch(NID_UI_CTRL, (r == E_SUCCESS), , r, "[%s] Propagating.", GetErrorMessage(r));
361 r = GET_REPLACED_BITMAP_CONFIG_N(EDITDATE::CONTENT_BG_HIGHLIGHTED, BITMAP_PIXEL_FORMAT_ARGB8888, contentHighlightedColor, __pContentBgHighlightedColorReplacementBitmap);
362 SysTryCatch(NID_UI_CTRL, (r == E_SUCCESS), , r, "[%s] Propagating.", GetErrorMessage(r));
364 r = GET_BITMAP_CONFIG_N(EDITDATE::CONTENT_BG_EFFECT_NORMAL, BITMAP_PIXEL_FORMAT_ARGB8888, __pContentBgEffectNormalBitmap);
365 SysTryCatch(NID_UI_CTRL, (r == E_SUCCESS), , r, "[%s] Propagating.", GetErrorMessage(r));
367 r = GET_BITMAP_CONFIG_N(EDITDATE::CONTENT_BG_EFFECT_PRESSED, BITMAP_PIXEL_FORMAT_ARGB8888, __pContentBgEffectPressedBitmap);
368 SysTryCatch(NID_UI_CTRL, (r == E_SUCCESS), , r, "[%s] Propagating.", GetErrorMessage(r));
370 r = GET_BITMAP_CONFIG_N(EDITDATE::CONTENT_BG_EFFECT_DISABLED, BITMAP_PIXEL_FORMAT_ARGB8888, __pContentBgEffectDisabledBitmap);
371 SysTryCatch(NID_UI_CTRL, (r == E_SUCCESS), , r, "[%s] Propagating.", GetErrorMessage(r));
377 delete __pContentBgNormalColorReplacementBitmap;
378 __pContentBgNormalColorReplacementBitmap = null;
380 delete __pContentBgPressedColorReplacementBitmap;
381 __pContentBgPressedColorReplacementBitmap = null;
383 delete __pContentBgDisabledColorReplacementBitmap;
384 __pContentBgDisabledColorReplacementBitmap = null;
386 delete __pContentBgHighlightedColorReplacementBitmap;
387 __pContentBgHighlightedColorReplacementBitmap = null;
389 delete __pContentBgEffectNormalBitmap;
390 __pContentBgEffectNormalBitmap = null;
392 delete __pContentBgEffectPressedBitmap;
393 __pContentBgEffectPressedBitmap = null;
395 delete __pContentBgEffectDisabledBitmap;
396 __pContentBgEffectDisabledBitmap = null;
402 _EditDatePresenter::GetDate(void) const
404 SysAssertf((__pEditDateTimeModel != null), "The _EditDateTimeModel instance is null.");
407 date.SetValue(GetYear(), GetMonth(), GetDay(), DATETIME_HOUR_MIN, DATETIME_MINUTE_MIN);
413 _EditDatePresenter::GetDay(void) const
415 SysAssertf((__pEditDateTimeModel != null), "The _EditDateTimeModel instance is null.");
417 return __pEditDateTimeModel->GetDay();
421 _EditDatePresenter::GetMonth(void) const
423 SysAssertf((__pEditDateTimeModel != null), "The _EditDateTimeModel instance is null.");
425 return __pEditDateTimeModel->GetMonth();
429 _EditDatePresenter::GetYear(void) const
431 SysAssertf((__pEditDateTimeModel != null), "The _EditDateTimeModel instance is null.");
433 return __pEditDateTimeModel->GetYear();
437 _EditDatePresenter::SetDate(const DateTime& date)
439 SysAssertf((__pEditDateTimeModel != null), "The _EditDateTimeModel instance is null.");
441 __pEditDateTimeModel->SetDateTime(date);
446 _EditDatePresenter::SetCurrentDate(void)
448 SysAssertf((__pEditDateTimeModel != null), "The _EditDateTimeModel instance is null.");
450 __pEditDateTimeModel->SetCurrentDateTime();
455 _EditDatePresenter::SetYear(int year)
457 SysAssertf((__pEditDateTimeModel != null), "The _EditDateTimeModel instance is null.");
459 return __pEditDateTimeModel->SetYear(year);
463 _EditDatePresenter::SetMonth(int month)
465 SysAssertf((__pEditDateTimeModel != null), "The _EditDateTimeModel instance is null.");
467 return __pEditDateTimeModel->SetMonth(month);
471 _EditDatePresenter::SetDay(int day)
473 SysAssertf((__pEditDateTimeModel != null), "The _EditDateTimeModel instance is null.");
475 return __pEditDateTimeModel->SetDay(day);
479 _EditDatePresenter::SetDatePickerEnabled(bool enable)
481 __datePickerEnabled = enable;
486 _EditDatePresenter::IsDatePickerEnabled(void) const
488 return __datePickerEnabled;
492 _EditDatePresenter::SetMinYear(int minYear)
494 return __pEditDateTimeModel->SetMinYear(minYear);
498 _EditDatePresenter::SetMaxYear(int maxYear)
500 return __pEditDateTimeModel->SetMaxYear(maxYear);
504 _EditDatePresenter::GetMinYear(void) const
509 __pEditDateTimeModel->GetYearRange(minYear, maxYear);
515 _EditDatePresenter::GetMaxYear(void) const
520 __pEditDateTimeModel->GetYearRange(minYear, maxYear);
526 _EditDatePresenter::Draw(void)
528 result r = E_SUCCESS;
534 Canvas* pCanvas = __pEditDate->GetCanvasN();
536 SysTryReturn(NID_UI_CTRL, (pCanvas != null), r, r, "[%s] Propagating. Failed to get canvas.", GetErrorMessage(r));
538 pCanvas->SetBackgroundColor(Color(0, 0, 0, 0));
541 if (!__title.IsEmpty())
550 _DateTimeUtils dateTimeUtils;
551 monthString = dateTimeUtils.GetMonthString(GetMonth());
552 yearString.Format(10, L"%04d", GetYear());
553 dayString.Format(10, L"%02d", GetDay());
555 CalculateAreaBounds();
557 r = DrawText(*pCanvas, GetDateAreaBounds(DATETIME_ID_DAY), dayString, DATETIME_ID_DAY);
558 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
559 r = DrawText(*pCanvas, GetDateAreaBounds(DATETIME_ID_MONTH), monthString, DATETIME_ID_MONTH);
560 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
561 r = DrawText(*pCanvas, GetDateAreaBounds(DATETIME_ID_YEAR), yearString, DATETIME_ID_YEAR);
562 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
571 _EditDatePresenter::DrawFocus(void)
573 FloatRectangle bounds(0.0f, 0.0f, 0.0f, 0.0f);
575 Canvas* pContentCanvas = null;
576 Canvas* pCanvas = __pEditDate->GetCanvasN();
577 SysTryReturnResult(NID_UI_CTRL, (pCanvas != null), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
579 if (__focusId == DATETIME_ID_DAY)
581 bounds = GetDateAreaBounds(DATETIME_ID_DAY);
583 else if (__focusId == DATETIME_ID_MONTH)
585 bounds = GetDateAreaBounds(DATETIME_ID_MONTH);
587 else if (__focusId == DATETIME_ID_YEAR)
589 bounds = GetDateAreaBounds(DATETIME_ID_YEAR);
592 result r = E_SUCCESS;
594 if (_BitmapImpl::CheckNinePatchedBitmapStrictly(*__pContentBgHighlightedColorReplacementBitmap))
596 r = pCanvas->DrawNinePatchedBitmap(bounds, *__pContentBgHighlightedColorReplacementBitmap);
597 SysTryCatch(NID_UI_CTRL, (r == E_SUCCESS), , r, "[%s] Propagating.", GetErrorMessage(r));
601 pContentCanvas = __pEditDate->GetCanvasN(bounds);
602 SysTryCatch(NID_UI_CTRL, (pContentCanvas != null), , GetLastResult(), "[%s]Propagating.", GetErrorMessage(GetLastResult()));
604 bounds.x = (bounds.width - __pContentBgHighlightedColorReplacementBitmap->GetWidthF()) / 2;
605 bounds.y = (bounds.height - __pContentBgHighlightedColorReplacementBitmap->GetHeightF()) / 2;
607 r = pContentCanvas->DrawBitmap(FloatPoint(bounds.x, bounds.y), *__pContentBgHighlightedColorReplacementBitmap);
608 SysTryCatch(NID_UI_CTRL, (r == E_SUCCESS), , r, "[%s] Propagating.", GetErrorMessage(r));
610 delete pContentCanvas;
618 delete pContentCanvas;
623 _EditDatePresenter::UpdateLastSelectedValue(_DateTimeId id, bool isTouchPressed)
626 SetLastSelectedId(id);
627 __lastSelectedValue = "";
628 _DateTimeUtils dateTimeUtils;
630 if (GetLastSelectedId() == DATETIME_ID_YEAR)
632 __lastSelectedValue.Format(10, L"%04d", GetYear());
635 PLAY_FEEDBACK(_RESOURCE_FEEDBACK_PATTERN_TAP, __pEditDate);
638 else if (GetLastSelectedId() == DATETIME_ID_MONTH)
640 __lastSelectedValue = dateTimeUtils.GetMonthString(GetMonth());
643 PLAY_FEEDBACK(_RESOURCE_FEEDBACK_PATTERN_TAP, __pEditDate);
646 else if (GetLastSelectedId() == DATETIME_ID_DAY)
648 __lastSelectedValue.Format(10, L"%02d", GetDay());
651 PLAY_FEEDBACK(_RESOURCE_FEEDBACK_PATTERN_TAP, __pEditDate);
655 __pEditDate->Invalidate();
660 _EditDatePresenter::CalculateAreaBounds(void)
662 result r = E_SUCCESS;
664 _DateTimeUtils dateTimeUtils;
665 int localeDateFormat = dateTimeUtils.GetLocaleDateFormat();
667 if (localeDateFormat == DATE_FORMAT_DDMMYYYY)
669 __monthBounds.x = __dayBounds.x + __dayBounds.width + __elementMargin;
670 __yearBounds.x = __monthBounds.x + __monthBounds.width + __elementMargin;
672 else if (localeDateFormat == DATE_FORMAT_MMDDYYYY)
674 __dayBounds.x = __monthBounds.x + __monthBounds.width + __elementMargin;
675 __yearBounds.x = __dayBounds.x + __dayBounds.width + __elementMargin;
677 else if (localeDateFormat == DATE_FORMAT_YYYYMMDD)
679 __monthBounds.x = __yearBounds.x + __yearBounds.width + __elementMargin;
680 __dayBounds.x = __monthBounds.x + __monthBounds.width + __elementMargin;
682 else if (localeDateFormat == DATE_FORMAT_YYYYDDMM)
684 __dayBounds.x = __yearBounds.x + __yearBounds.width + __elementMargin;
685 __monthBounds.x = __dayBounds.x + __dayBounds.width + __elementMargin;
692 _EditDatePresenter::DrawTitle(Canvas& canvas)
694 if (!__pEditDate->IsEnabled())
696 Color titleDisabledColor;
697 GET_COLOR_CONFIG(EDITDATE::TITLE_TEXT_DISABLED, titleDisabledColor);
698 __titleObject.SetForegroundColor(titleDisabledColor, 0, __titleObject.GetTextLength());
701 (_FontImpl::GetInstance(*__pFont))->SetSize(__titleFontSize);
702 (_FontImpl::GetInstance(*__pFont))->SetStyle(FONT_STYLE_BOLD);
703 __titleObject.SetFont(__pFont, 0, __titleObject.GetTextLength());
704 __titleObject.Draw(*_CanvasImpl::GetInstance(canvas));
710 _EditDatePresenter::DrawText(Canvas& canvas, const FloatRectangle& bounds, const String& text, _DateTimeId boxId)
713 float contentTextMargin;
715 GET_SHAPE_CONFIG(EDITDATE::CONTENT_TEXT_MARGIN, __pEditDate->GetOrientation(), contentTextMargin);
717 if (!__pEditDate->IsEnabled())
719 GET_COLOR_CONFIG(EDITDATE::TEXT_DISABLED, textColor);
723 GET_COLOR_CONFIG(EDITDATE::TEXT_NORMAL, textColor);
726 (_FontImpl::GetInstance(*__pFont))->SetStyle(FONT_STYLE_PLAIN);
728 if (boxId == GetLastSelectedId() && boxId != DATETIME_ID_NONE)
730 (_FontImpl::GetInstance(*__pFont))->SetStyle(FONT_STYLE_BOLD);
731 GET_COLOR_CONFIG(EDITDATE::TEXT_PRESSED, textColor);
734 DrawContentBitmap(canvas, bounds, boxId);
736 FloatRectangle drawAreaBounds(0.0f, 0.0f, 0.0f, 0.0f);
737 drawAreaBounds.x = bounds.x + contentTextMargin;
738 drawAreaBounds.y = bounds.y + contentTextMargin;
739 drawAreaBounds.width = bounds.width - (contentTextMargin * 2.0f);
740 drawAreaBounds.height = bounds.height - (contentTextMargin * 2.0f);
742 TextSimple* pSimpleText = null;
743 pSimpleText = new (std::nothrow)TextSimple((const_cast <wchar_t*>(text.GetPointer())), text.GetLength(), TEXT_ELEMENT_SOURCE_TYPE_EXTERNAL);
744 SysTryReturn(NID_UI_CTRL, (pSimpleText != null), E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
746 pSimpleText->SetTextShadowEnabled(true);
747 pSimpleText->SetTextShadowOffset(FloatPoint(0.0f, -1.0f));
749 __textObject.RemoveAll();
750 if (__isFocused && __focusId == boxId)
752 GET_COLOR_CONFIG(EDITDATE::TEXT_HIGHLIGHTED, textColor);
756 (_FontImpl::GetInstance(*__pFont))->SetSize(__dateFontSize);
757 __textObject.AppendElement(*pSimpleText);
759 __textObject.SetFont(__pFont, 0, __textObject.GetTextLength());
760 __textObject.SetForegroundColor(textColor, 0, __textObject.GetTextLength());
761 __textObject.SetBounds(drawAreaBounds);
762 __textObject.Draw(*_CanvasImpl::GetInstance(canvas));
768 _EditDatePresenter::DrawContentBitmap(Canvas& canvas, const FloatRectangle& bounds, _DateTimeId boxId)
770 result r = E_SUCCESS;
772 bool isCustomBitmap = false;
773 Bitmap* pReplacementBitmap = null;
774 Bitmap* pEffectBitmap = null;
776 if (!__pEditDate->IsEnabled())
778 isCustomBitmap = IS_CUSTOM_BITMAP(EDITTIME::CONTENT_BG_DISABLED);
779 pReplacementBitmap = __pContentBgDisabledColorReplacementBitmap;
780 pEffectBitmap = __pContentBgEffectDisabledBitmap;
782 else if (GetLastSelectedId() != boxId)
784 isCustomBitmap = IS_CUSTOM_BITMAP(EDITTIME::CONTENT_BG_NORMAL);
785 pReplacementBitmap = __pContentBgNormalColorReplacementBitmap;
786 pEffectBitmap = __pContentBgEffectNormalBitmap;
790 isCustomBitmap = IS_CUSTOM_BITMAP(EDITTIME::CONTENT_BG_PRESSED);
791 pReplacementBitmap = __pContentBgPressedColorReplacementBitmap;
792 pEffectBitmap = __pContentBgEffectPressedBitmap;
795 r = DrawResourceBitmap(canvas, bounds, pReplacementBitmap, isCustomBitmap);
796 SysTryReturn(NID_UI_CTRL, (r == E_SUCCESS), r, r, "[%s] Propagating.", GetErrorMessage(r));
800 r = DrawResourceBitmap(canvas, bounds, pEffectBitmap);
801 SysTryReturn(NID_UI_CTRL, (r == E_SUCCESS), r, r, "[%s] Propagating.", GetErrorMessage(r));
808 _EditDatePresenter::DrawResourceBitmap(Canvas& canvas, const FloatRectangle& bounds, Bitmap* pBitmap, bool isCustomBitmap)
810 result r = E_SUCCESS;
817 if (_BitmapImpl::CheckNinePatchedBitmapStrictly(*pBitmap))
819 r = canvas.DrawNinePatchedBitmap(bounds, *pBitmap);
820 SysTryReturn(NID_UI_CTRL, (r == E_SUCCESS), r, r, "[%s] Propagating.", GetErrorMessage(r));
826 Canvas *pContentCanvas = __pEditDate->GetCanvasN(bounds);
827 SysTryReturnResult(NID_UI_CTRL, (pContentCanvas != null), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
831 position.x = (bounds.width - pBitmap->GetWidthF()) / 2;
832 position.y = (bounds.height - pBitmap->GetHeightF()) / 2;
833 r = pContentCanvas->DrawBitmap(position, *pBitmap);
834 delete pContentCanvas;
838 r = canvas.DrawBitmap(FloatPoint(bounds.x, bounds.y), *pBitmap);
841 SysTryReturn(NID_UI_CTRL, (r == E_SUCCESS), r, r, "[%s] Propagating.", GetErrorMessage(r));
848 _EditDatePresenter::GetBoxIdFromPosition(const FloatPoint& point) const
850 _DateTimeId displayBoxId = DATETIME_ID_NONE;
852 if (point.y < __dayBounds.y || point.y > __dayBounds.y + __dayBounds.height)
857 if (__dayBounds.Contains(point))
859 displayBoxId = DATETIME_ID_DAY;
861 else if (__monthBounds.Contains(point))
863 displayBoxId = DATETIME_ID_MONTH;
865 else if (__yearBounds.Contains(point))
867 displayBoxId = DATETIME_ID_YEAR;
874 _EditDatePresenter::GetDateAreaBounds(_DateTimeId id) const
876 if (id == DATETIME_ID_DAY)
880 else if (id == DATETIME_ID_MONTH)
882 return __monthBounds;
884 else if (id == DATETIME_ID_YEAR)
890 return FloatRectangle();
895 _EditDatePresenter::GetTitleBounds(void) const
897 return __titleBounds;
901 _EditDatePresenter::SetLastSelectedId(_DateTimeId boxId)
903 __lastSelectedId = boxId;
908 _EditDatePresenter::GetLastSelectedId(void) const
910 return __lastSelectedId;
914 _EditDatePresenter::OnFontChanged(Font* pFont)
918 if (__pEditDate->GetDateTimeBar() != null)
920 __pEditDate->GetDateTimeBar()->SetFont(*pFont);
927 _EditDatePresenter::OnFontInfoRequested(unsigned long& style, float& size)
929 style = FONT_STYLE_PLAIN;
930 size = __dateFontSize;
936 _EditDatePresenter::SetFocusState(bool isFocused)
938 __isFocused = isFocused;
942 _EditDatePresenter::SetFocusedElement(void)
944 _DateTimeUtils dateTimeUtils;
945 if (__isEnterKeyPressed)
947 __isEnterKeyPressed = false;
949 if (__pEditDate->IsFocusModeStateEnabled())
954 int localeDateFormat = dateTimeUtils.GetLocaleDateFormat();
955 if (__focusId == DATETIME_ID_NONE)
957 if (localeDateFormat == DATE_FORMAT_DDMMYYYY)
959 __focusId = DATETIME_ID_DAY;
961 else if (localeDateFormat == DATE_FORMAT_MMDDYYYY)
963 __focusId = DATETIME_ID_MONTH;
965 else if (localeDateFormat == DATE_FORMAT_YYYYMMDD)
967 __focusId = DATETIME_ID_YEAR;
969 else if (localeDateFormat == DATE_FORMAT_YYYYDDMM)
971 __focusId = DATETIME_ID_YEAR;
978 _EditDatePresenter::OnFocusLost(const _Control &source)
980 if (!__isEnterKeyPressed)
982 __focusId = DATETIME_ID_NONE;
985 __pEditDate->Invalidate();
990 _EditDatePresenter::OnFocusModeStateChanged(void)
993 __isEnterKeyPressed = false;
994 __focusId = DATETIME_ID_NONE;
995 __pEditDate->Invalidate();
1000 _EditDatePresenter::OnKeyPressed(const _Control& source, const _KeyInfo& keyInfo)
1007 _KeyCode keyCode = keyInfo.GetKeyCode();
1008 _DateTimeUtils dateTimeUtils;
1009 int localeDateFormat = dateTimeUtils.GetLocaleDateFormat();
1015 if (__focusId == DATETIME_ID_DAY)
1017 if (localeDateFormat == DATE_FORMAT_DDMMYYYY || localeDateFormat == DATE_FORMAT_YYYYDDMM)
1019 __focusId = DATETIME_ID_MONTH;
1021 else if (localeDateFormat == DATE_FORMAT_MMDDYYYY)
1023 __focusId = DATETIME_ID_YEAR;
1030 else if (__focusId == DATETIME_ID_MONTH)
1032 if (localeDateFormat == DATE_FORMAT_DDMMYYYY)
1034 __focusId = DATETIME_ID_YEAR;
1036 else if (localeDateFormat == DATE_FORMAT_MMDDYYYY || localeDateFormat == DATE_FORMAT_YYYYMMDD)
1038 __focusId = DATETIME_ID_DAY;
1045 else if (__focusId == DATETIME_ID_YEAR)
1047 if (localeDateFormat == DATE_FORMAT_YYYYMMDD)
1049 __focusId = DATETIME_ID_MONTH;
1051 else if (localeDateFormat == DATE_FORMAT_YYYYDDMM)
1053 __focusId = DATETIME_ID_DAY;
1060 __pEditDate->Invalidate();
1065 if (__focusId == DATETIME_ID_DAY)
1067 if (localeDateFormat == DATE_FORMAT_YYYYDDMM)
1069 __focusId = DATETIME_ID_YEAR;
1071 else if (localeDateFormat == DATE_FORMAT_MMDDYYYY || localeDateFormat == DATE_FORMAT_YYYYMMDD)
1073 __focusId = DATETIME_ID_MONTH;
1080 else if (__focusId == DATETIME_ID_MONTH)
1082 if (localeDateFormat == DATE_FORMAT_YYYYMMDD)
1084 __focusId = DATETIME_ID_YEAR;
1086 else if (localeDateFormat == DATE_FORMAT_DDMMYYYY || localeDateFormat == DATE_FORMAT_YYYYDDMM)
1088 __focusId = DATETIME_ID_DAY;
1095 else if (__focusId == DATETIME_ID_YEAR)
1097 if (localeDateFormat == DATE_FORMAT_DDMMYYYY)
1099 __focusId = DATETIME_ID_MONTH;
1101 else if (localeDateFormat == DATE_FORMAT_MMDDYYYY)
1103 __focusId = DATETIME_ID_DAY;
1110 __pEditDate->Invalidate();
1122 _EditDatePresenter::OnKeyReleased(const _Control& source, const _KeyCode& keyCode)
1131 VisualElement *pEditDateElement = __pEditDate->GetVisualElement();
1132 result r = GetLastResult();
1133 SysTryReturn(NID_UI_CTRL, (pEditDateElement != null), false, r, "[%s] Propagating.", GetErrorMessage(r));
1134 pEditDateElement->RemoveAllAnimations();
1139 int displayValue = -1;
1141 _DateTimeId boxId = DATETIME_ID_NONE;
1147 __isEnterKeyPressed = true;
1148 if (__focusId == DATETIME_ID_DAY)
1150 _DateTimeUtils dateTimeUtils;
1151 maxValue = dateTimeUtils.CalculateMaxDay(GetYear(), GetMonth());
1152 minValue = DATETIME_DAY_MIN;
1153 displayValue = GetDay();
1154 boxId = DATETIME_ID_DAY;
1156 if (__pEditDate->GetDateTimeBar()->GetItemCount() > 0)
1158 __pEditDate->GetDateTimeBar()->RemoveAllItems();
1162 else if (__focusId == DATETIME_ID_MONTH)
1164 minValue = DATETIME_MONTH_MIN;
1165 maxValue = DATETIME_MONTH_MAX;
1166 displayValue = GetMonth();
1167 boxId = DATETIME_ID_MONTH;
1169 if (__pEditDate->GetDateTimeBar()->GetItemCount() > 0)
1171 __pEditDate->GetDateTimeBar()->RemoveAllItems();
1174 else if (__focusId == DATETIME_ID_YEAR)
1176 minValue = GetMinYear();
1177 maxValue = GetMaxYear();
1178 displayValue = GetYear();
1179 boxId = DATETIME_ID_YEAR;
1181 if (__pEditDate->GetDateTimeBar()->GetItemCount() > 0)
1183 __pEditDate->GetDateTimeBar()->RemoveAllItems();
1186 FloatRectangle absoluteBounds = __pEditDate->GetAbsoluteBoundsF();
1188 FloatRectangle bounds(0.0f, 0.0f, 0.0f, 0.0f);
1189 bounds = GetDateAreaBounds(boxId);
1190 bounds.x += absoluteBounds.x;
1191 __pEditDate->GetDateTimeBar()->CalculateArrowBounds(bounds);
1192 __pEditDate->GetDateTimeBar()->SetInitialValue(minValue, maxValue, displayValue, boxId);
1193 __pEditDate->GetDateTimeBar()->SetVisibleState(true);
1194 __pEditDate->GetDateTimeBar()->Open();
1196 UpdateLastSelectedValue(boxId, false);
1208 _EditDatePresenter::OnTouchPressed(const _Control& source, const _TouchInfo& touchinfo)
1210 SysTryReturn(NID_UI_CTRL, IsDatePickerEnabled() == true, true, E_SYSTEM,
1211 "[E_SYSTEM] A system error has occurred. EditDate instance is disabled.");
1213 if (&source != __pEditDate)
1218 __touchMoveHandled = false;
1220 FloatPoint point = touchinfo.GetCurrentPosition();
1222 _DateTimeId boxId = DATETIME_ID_NONE;
1223 boxId = GetBoxIdFromPosition(point);
1225 if (boxId < DATETIME_ID_YEAR || boxId > DATETIME_ID_DAY)
1227 __selectedId = DATETIME_ID_NONE;
1233 int displayValue = -1;
1235 if (boxId == DATETIME_ID_DAY)
1237 if (__pEditDate->GetDateTimeBar() != null)
1239 _DateTimeUtils dateTimeUtils;
1240 maxValue = dateTimeUtils.CalculateMaxDay(GetYear(), GetMonth());
1241 minValue = DATETIME_DAY_MIN;
1242 displayValue = GetDay();
1245 else if (boxId == DATETIME_ID_MONTH)
1247 minValue = DATETIME_MONTH_MIN;
1248 maxValue = DATETIME_MONTH_MAX;
1249 displayValue = GetMonth();
1251 else if (boxId == DATETIME_ID_YEAR)
1253 minValue = GetMinYear();
1254 maxValue = GetMaxYear();
1255 displayValue = GetYear();
1258 if (__pEditDate->GetDateTimeBar() != null)
1260 if (__pEditDate->GetDateTimeBar()->GetItemCount() > 0)
1262 __pEditDate->GetDateTimeBar()->RemoveAllItems();
1265 result r = __pEditDate->GetDateTimeBar()->SetInitialValue(minValue, maxValue, displayValue, boxId);
1268 __selectedId = DATETIME_ID_NONE;
1273 __selectedId = boxId;
1279 _EditDatePresenter::OnTouchReleased(const _Control& source, const _TouchInfo& touchinfo)
1281 SysTryReturn(NID_UI_CTRL, IsDatePickerEnabled() == true, true, E_SYSTEM,
1282 "[E_SYSTEM] A system error has occurred. EditDate instance is disabled.");
1284 if (&source != __pEditDate)
1289 FloatPoint point = touchinfo.GetCurrentPosition();
1291 _DateTimeId boxId = DATETIME_ID_NONE;
1292 boxId = GetBoxIdFromPosition(point);
1294 if (boxId == GetLastSelectedId() || boxId != __selectedId || boxId == DATETIME_ID_NONE)
1296 if (__pEditDate->GetDateTimeBar() != null && __pEditDate->GetDateTimeBar()->IsActivated())
1298 __pEditDate->GetDateTimeBar()->CloseDateTimeBar();
1301 __selectedId = DATETIME_ID_NONE;
1302 SetLastSelectedId(__selectedId);
1309 UpdateLastSelectedValue(__selectedId, true);
1311 if ((__pEditDate->GetDateTimeBar() != null) && (GetLastSelectedId() != DATETIME_ID_NONE))
1313 __pEditDate->SetFocused(true);
1314 FloatRectangle bounds(0.0f, 0.0f, 0.0f, 0.0f);
1315 bounds = GetDateAreaBounds(GetLastSelectedId());
1316 FloatRectangle absoluteBounds(0.0f, 0.0f, 0.0f, 0.0f);
1317 absoluteBounds = __pEditDate->GetAbsoluteBoundsF();
1318 bounds.x += absoluteBounds.x;
1320 __pEditDate->GetDateTimeBar()->CalculateArrowBounds(bounds);
1322 if (__pEditDate->GetDateTimeBar()->IsActivated())
1324 __pEditDate->GetDateTimeBar()->RemoveAllAnimations();
1325 __pEditDate->GetDateTimeBar()->Close();
1326 __pEditDate->GetDateTimeBar()->SetVisibleState(true);
1327 __pEditDate->GetDateTimeBar()->Open();
1331 __pEditDate->GetDateTimeBar()->SetVisibleState(true);
1332 __pEditDate->GetDateTimeBar()->Open();
1336 __selectedId = DATETIME_ID_NONE;
1341 _EditDatePresenter::OnTouchCanceled(const _Control& source, const _TouchInfo& touchinfo)
1343 if (&source != __pEditDate)
1348 __selectedId = DATETIME_ID_NONE;
1354 _EditDatePresenter::OnTouchMoved(const _Control& source, const _TouchInfo& touchinfo)
1356 if (&source != __pEditDate)
1361 if (__pEditDate->GetDateTimeBar() != null && __pEditDate->GetDateTimeBar()->IsActivated())
1370 _EditDatePresenter::OnTouchMoveHandled(const _Control& control)
1372 __touchMoveHandled = true;
1373 __selectedId = DATETIME_ID_NONE;
1379 _EditDatePresenter::Animate(void)
1381 SysTryReturnVoidResult(NID_UI_CTRL, !__isAnimating, E_SUCCESS, "Rolling animation is in progress.");
1382 SysAssertf((__pFont != null), "Font instance must not be null.");
1384 result r = E_SUCCESS;
1385 FloatRectangle rect;
1390 FloatPoint textPoint;
1391 TextSimple* pOldSimpleText = null;
1392 TextSimple* pNewSimpleText = null;
1393 bool isCustomBitmap = false;
1395 _DateTimeUtils dateTimeUtils;
1396 monthString = dateTimeUtils.GetMonthString(GetMonth());
1397 yearString.Format(10, L"%04d", GetYear());
1398 dayString.Format(10, L"%02d", GetDay());
1400 if (GetLastSelectedId() == DATETIME_ID_DAY)
1402 SysTryReturnVoidResult(NID_UI_CTRL, (__lastSelectedValue.Equals(dayString) == false), E_SUCCESS, "Day string matched.");
1404 newValue = dayString;
1405 rect = GetDateAreaBounds(DATETIME_ID_DAY);
1407 else if (GetLastSelectedId() == DATETIME_ID_MONTH)
1409 SysTryReturnVoidResult(NID_UI_CTRL, (__lastSelectedValue.Equals(monthString) == false), E_SUCCESS, "Month string matched.");
1411 newValue = monthString;
1412 rect = GetDateAreaBounds(DATETIME_ID_MONTH);
1414 else if (GetLastSelectedId() == DATETIME_ID_YEAR)
1416 SysTryReturnVoidResult(NID_UI_CTRL, (__lastSelectedValue.Equals(yearString) == false), E_SUCCESS, "Year string matched.");
1418 newValue = yearString;
1419 rect = GetDateAreaBounds(DATETIME_ID_YEAR);
1422 FloatDimension newTextDim;
1423 FloatDimension oldTextDim;
1424 VisualElement* pNewVisualElement = null;
1425 VisualElement* pOldVisualElement = null;
1426 VisualElement* pEditDateElement = null;
1427 VisualElementPropertyAnimation* pNewBoundsAnimation = null;
1428 VisualElementPropertyAnimation* pOldBoundsAnimation = null;
1429 Canvas *pCanvas = null;
1430 Canvas *pContentCanvas = null;
1431 Color contentBgColor;
1432 Color textPressedColor;
1433 float contentTextMargin;
1435 GET_COLOR_CONFIG(EDITTIME::CONTENT_BG_PRESSED, contentBgColor);
1436 GET_COLOR_CONFIG(EDITTIME::TEXT_PRESSED, textPressedColor);
1437 GET_SHAPE_CONFIG(EDITDATE::CONTENT_TEXT_MARGIN, __pEditDate->GetOrientation(), contentTextMargin);
1439 __pFont->GetTextExtent(newValue, newValue.GetLength(), newTextDim);
1440 __pFont->GetTextExtent(__lastSelectedValue, __lastSelectedValue.GetLength(), oldTextDim);
1442 if (newTextDim.width > oldTextDim.width)
1444 textPoint.x = (rect.width - newTextDim.width) / 2.0f;
1448 textPoint.x = (rect.width - oldTextDim.width) / 2.0f;
1451 SysTryReturnVoidResult(NID_UI_CTRL, (rect.x + textPoint.x < __pEditDate->GetBoundsF().width), E_SUCCESS, "Rolling animation can't be played.");
1453 __isAnimating = true;
1455 __pContentProvider = new (std::nothrow) VisualElement();
1456 SysTryReturnVoidResult(NID_UI_CTRL, (__pContentProvider != null), E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
1458 r = __pContentProvider->Construct();
1459 SysTryCatch(NID_UI_CTRL, (r == E_SUCCESS), , r, "[%s] Propagating.", GetErrorMessage(r));
1461 __pContentProvider->SetShowState(true);
1462 __pContentProvider->SetClipChildrenEnabled(true);
1463 __pContentProvider->SetImplicitAnimationEnabled(false);
1465 pEditDateElement = __pEditDate->GetVisualElement();
1466 r = GetLastResult();
1467 SysTryCatch(NID_UI_CTRL, (pEditDateElement != null), , r, "[%s] Propagating.", GetErrorMessage(r));
1469 pNewVisualElement = new (std::nothrow) VisualElement();
1470 SysTryCatch(NID_UI_CTRL, (pNewVisualElement != null), , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
1472 r = pNewVisualElement->Construct();
1475 pNewVisualElement->Destroy();
1476 pNewVisualElement = null;
1478 SysTryCatch(NID_UI_CTRL, (r == E_SUCCESS), , r, "[%s] Propagating.", GetErrorMessage(r));
1480 pOldVisualElement = new (std::nothrow) VisualElement();
1481 if (pOldVisualElement == null)
1483 pNewVisualElement->Destroy();
1484 pNewVisualElement = null;
1486 SysTryCatch(NID_UI_CTRL, (pOldVisualElement != null), , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
1488 r = pOldVisualElement->Construct();
1491 pNewVisualElement->Destroy();
1492 pOldVisualElement->Destroy();
1493 pNewVisualElement = null;
1494 pOldVisualElement = null;
1496 SysTryCatch(NID_UI_CTRL, (r == E_SUCCESS), , r, "[%s] Propagating.", GetErrorMessage(r));
1498 pNewVisualElement->SetShowState(true);
1499 pOldVisualElement->SetShowState(true);
1501 __pContentProvider->SetBounds(FloatRectangle((rect.x + contentTextMargin), (rect.y + (contentTextMargin * 2.0f)), (rect.width - (contentTextMargin * 2.0f)), (rect.height - (contentTextMargin * 4.0f))));
1503 pNewVisualElement->SetBounds(FloatRectangle(0, 0, __pContentProvider->GetBounds().width, __pContentProvider->GetBounds().height));
1504 pOldVisualElement->SetBounds(FloatRectangle(0, 0, __pContentProvider->GetBounds().width, __pContentProvider->GetBounds().height));
1506 pContentCanvas = pEditDateElement->GetCanvasN(__pContentProvider->GetBounds());
1507 r = GetLastResult();
1508 SysTryCatch(NID_UI_CTRL, (pContentCanvas != null), , r, "[%s] Propagating.", GetErrorMessage(r));
1510 pContentCanvas->SetBackgroundColor(Color(0, 0, 0, 0));
1511 pContentCanvas->Clear();
1513 pCanvas = pEditDateElement->GetCanvasN(rect);
1514 r = GetLastResult();
1515 SysTryCatch(NID_UI_CTRL, (pCanvas != null), , r, "[%s] Propagating.", GetErrorMessage(r));
1516 pCanvas->SetBackgroundColor(Color(0, 0, 0, 0));
1520 isCustomBitmap = IS_CUSTOM_BITMAP(EDITTIME::CONTENT_BG_PRESSED);
1521 r = DrawResourceBitmap(*pCanvas, rect, __pContentBgPressedColorReplacementBitmap, isCustomBitmap);
1523 if (!isCustomBitmap)
1525 result res = DrawResourceBitmap(*pCanvas, rect, __pContentBgEffectPressedBitmap);
1527 if (res != E_SUCCESS)
1529 SysLog(NID_UI_CTRL, "[%s] Propagating.", GetErrorMessage(res));
1538 pContentCanvas->SetBackgroundColor(contentBgColor);
1539 pContentCanvas->Clear();
1542 delete pContentCanvas;
1543 pContentCanvas = null;
1545 pEditDateElement->AttachChild(*__pContentProvider);
1546 __pContentProvider->AttachChild(*pOldVisualElement);
1547 __pContentProvider->AttachChild(*pNewVisualElement);
1549 pNewBoundsAnimation = new (std::nothrow) VisualElementPropertyAnimation();
1550 SysTryCatch(NID_UI_CTRL, (pNewBoundsAnimation != null), , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
1552 pNewBoundsAnimation->SetDuration(300);
1553 pNewBoundsAnimation->SetPropertyName("bounds.position");
1554 pNewBoundsAnimation->SetStartValue(Variant(FloatPoint(pNewVisualElement->GetBounds().x, oldTextDim.height)));
1555 pNewBoundsAnimation->SetEndValue(Variant(FloatPoint(pNewVisualElement->GetBounds().x, 0.0f)));
1557 pOldBoundsAnimation = new (std::nothrow) VisualElementPropertyAnimation();
1558 SysTryCatch(NID_UI_CTRL, (pOldBoundsAnimation != null), , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
1560 pOldBoundsAnimation->SetDuration(300);
1561 pOldBoundsAnimation->SetPropertyName("bounds.position");
1562 pOldBoundsAnimation->SetStartValue(Variant(FloatPoint(pOldVisualElement->GetBounds().x, 0.0f)));
1563 pOldBoundsAnimation->SetEndValue(Variant(FloatPoint(pOldVisualElement->GetBounds().x, oldTextDim.height * -1.0f)));
1565 pOldSimpleText = new (std::nothrow)TextSimple((const_cast <wchar_t*>(__lastSelectedValue.GetPointer())), __lastSelectedValue.GetLength(), TEXT_ELEMENT_SOURCE_TYPE_EXTERNAL);
1566 SysTryCatch(NID_UI_CTRL, (pOldSimpleText != null), , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
1568 pOldSimpleText->SetTextShadowEnabled(true);
1569 pOldSimpleText->SetTextShadowOffset(FloatPoint(0.0f, -1.0f));
1571 pCanvas = pOldVisualElement->GetCanvasN();
1572 r = GetLastResult();
1573 SysTryCatch(NID_UI_CTRL, (pCanvas != null), , r, "[%s] Propagating.", GetErrorMessage(r));
1575 pCanvas->SetBackgroundColor(Color(0, 0, 0, 0));
1577 pCanvas->SetForegroundColor(textPressedColor);
1579 (_FontImpl::GetInstance(*__pFont))->SetSize(__dateFontSize);
1580 (_FontImpl::GetInstance(*__pFont))->SetStyle(FONT_STYLE_PLAIN);
1581 __textObject.RemoveAll();
1582 __textObject.AppendElement(*pOldSimpleText);
1584 __textObject.SetFont(__pFont, 0, __textObject.GetTextLength());
1585 __textObject.SetForegroundColor(textPressedColor, 0, __textObject.GetTextLength());
1586 __textObject.SetBounds(FloatRectangle(0, 0, pCanvas->GetBounds().width, pCanvas->GetBounds().height));
1587 __textObject.Draw(*_CanvasImpl::GetInstance(*pCanvas));
1592 pNewSimpleText = new (std::nothrow)TextSimple((const_cast <wchar_t*>(newValue.GetPointer())), newValue.GetLength(), TEXT_ELEMENT_SOURCE_TYPE_EXTERNAL);
1593 SysTryCatch(NID_UI_CTRL, (pNewSimpleText != null), , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
1595 pNewSimpleText->SetTextShadowEnabled(true);
1596 pNewSimpleText->SetTextShadowOffset(FloatPoint(0.0f, -1.0f));
1598 pCanvas = pNewVisualElement->GetCanvasN();
1599 r = GetLastResult();
1600 SysTryCatch(NID_UI_CTRL, (pCanvas != null), , r, "[%s] Propagating.", GetErrorMessage(r));
1602 pCanvas->SetBackgroundColor(Color(0, 0, 0, 0));
1604 pCanvas->SetForegroundColor(textPressedColor);
1606 (_FontImpl::GetInstance(*__pFont))->SetSize(__dateFontSize);
1607 (_FontImpl::GetInstance(*__pFont))->SetStyle(FONT_STYLE_PLAIN);
1608 __textObject.RemoveAll();
1609 __textObject.AppendElement(*pNewSimpleText);
1611 __textObject.SetFont(__pFont, 0, __textObject.GetTextLength());
1612 __textObject.SetForegroundColor(textPressedColor, 0, __textObject.GetTextLength());
1613 __textObject.SetBounds(FloatRectangle(0, 0, pCanvas->GetBounds().width, pCanvas->GetBounds().height));
1614 __textObject.Draw(*_CanvasImpl::GetInstance(*pCanvas));
1619 pOldVisualElement->SetImplicitAnimationEnabled(false);
1620 pNewVisualElement->SetImplicitAnimationEnabled(false);
1622 AnimationTransaction::Begin(__transactionId);
1623 pOldVisualElement->AddAnimation(*pOldBoundsAnimation);
1624 pNewVisualElement->AddAnimation(*pNewBoundsAnimation);
1625 AnimationTransaction::SetCurrentTransactionEventListener(__pEditDate);
1626 AnimationTransaction::Commit();
1628 delete pOldBoundsAnimation;
1629 delete pNewBoundsAnimation;
1634 __isAnimating = false;
1635 __pContentProvider->Destroy();
1636 __pContentProvider = null;
1638 delete pNewBoundsAnimation;
1639 pNewBoundsAnimation = null;
1641 delete pOldBoundsAnimation;
1642 pOldBoundsAnimation = null;
1644 delete pOldSimpleText;
1645 pOldSimpleText = null;
1647 delete pNewSimpleText;
1648 pNewSimpleText = null;
1650 delete pContentCanvas;
1651 pContentCanvas = null;
1657 _EditDatePresenter::EndTransaction(void)
1659 result r = E_SUCCESS;
1661 __isAnimating = false;
1662 VisualElement* pEditDateElement = __pEditDate->GetVisualElement();
1663 r = GetLastResult();
1664 SysTryReturnVoidResult(NID_UI_CTRL, (pEditDateElement != null), r, "[%s] Propagating.", GetErrorMessage(r));
1666 //__pContentProvider will be destroyed in destructor when OnFormBackRequested() callback is received
1667 if (__pContentProvider != null)
1669 pEditDateElement->DetachChild(*__pContentProvider);
1670 __pContentProvider->Destroy();
1671 __pContentProvider = null;
1675 __transactionId = 0;
1678 }}} // Tizen::Ui::Controls