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 __textObject.AppendElement(*pSimpleText);
295 __textObject.SetFont(__pFont, 0, __textObject.GetTextLength());
296 __textObject.SetAlignment(TEXT_OBJECT_ALIGNMENT_CENTER | TEXT_OBJECT_ALIGNMENT_MIDDLE);
297 __textObject.SetWrap(TEXT_OBJECT_WRAP_TYPE_NONE);
298 __textObject.SetAction(TEXT_OBJECT_ACTION_TYPE_ABBREV);
304 _EditDatePresenter::GetElementWidth(const float minWidth, const float maxWidth) const
306 FloatRectangle bounds;
307 FloatDimension minSize;
308 bounds = __pEditDate->GetBoundsF();
310 float elementWidth = 0.0f;
311 float editDateWidth = 0.0f;
313 GET_SHAPE_CONFIG(EDITDATE::WIDTH, __pEditDate->GetOrientation(), editDateWidth);
314 GET_DIMENSION_CONFIG(EDITDATE::MIN_SIZE, __pEditDate->GetOrientation(), minSize);
316 if (bounds.width >= editDateWidth)
321 if (bounds.width <= minSize.width)
323 elementWidth = minWidth;
325 else if (bounds.width < editDateWidth && bounds.width > minSize.width)
327 elementWidth = maxWidth -
328 ((maxWidth - minWidth) / (editDateWidth - minSize.width)) * (editDateWidth - bounds.width);
335 _EditDatePresenter::LoadResource(void)
337 result r = E_SUCCESS;
339 Color contentNormalBgColor;
340 Color contentDisabledBgColor;
341 Color contentPressedColor;
342 Color contentHighlightedColor;
344 GET_COLOR_CONFIG(EDITDATE::CONTENT_BG_NORMAL, contentNormalBgColor);
345 GET_COLOR_CONFIG(EDITDATE::CONTENT_BG_DISABLED, contentDisabledBgColor);
346 GET_COLOR_CONFIG(EDITDATE::CONTENT_BG_PRESSED, contentPressedColor);
347 GET_COLOR_CONFIG(EDITDATE::CONTENT_BG_HIGHLIGHTED, contentHighlightedColor);
349 r = GET_REPLACED_BITMAP_CONFIG_N(EDITDATE::CONTENT_BG_NORMAL, BITMAP_PIXEL_FORMAT_ARGB8888, contentNormalBgColor, __pContentBgNormalColorReplacementBitmap);
350 SysTryCatch(NID_UI_CTRL, (r == E_SUCCESS), , r, "[%s] Propagating.", GetErrorMessage(r));
352 r = GET_REPLACED_BITMAP_CONFIG_N(EDITDATE::CONTENT_BG_PRESSED, BITMAP_PIXEL_FORMAT_ARGB8888, contentPressedColor, __pContentBgPressedColorReplacementBitmap);
353 SysTryCatch(NID_UI_CTRL, (r == E_SUCCESS), , r, "[%s] Propagating.", GetErrorMessage(r));
355 r = GET_REPLACED_BITMAP_CONFIG_N(EDITDATE::CONTENT_BG_DISABLED, BITMAP_PIXEL_FORMAT_ARGB8888, contentDisabledBgColor, __pContentBgDisabledColorReplacementBitmap);
356 SysTryCatch(NID_UI_CTRL, (r == E_SUCCESS), , r, "[%s] Propagating.", GetErrorMessage(r));
358 r = GET_REPLACED_BITMAP_CONFIG_N(EDITDATE::CONTENT_BG_HIGHLIGHTED, BITMAP_PIXEL_FORMAT_ARGB8888, contentHighlightedColor, __pContentBgHighlightedColorReplacementBitmap);
359 SysTryCatch(NID_UI_CTRL, (r == E_SUCCESS), , r, "[%s] Propagating.", GetErrorMessage(r));
361 r = GET_BITMAP_CONFIG_N(EDITDATE::CONTENT_BG_EFFECT_NORMAL, BITMAP_PIXEL_FORMAT_ARGB8888, __pContentBgEffectNormalBitmap);
362 SysTryCatch(NID_UI_CTRL, (r == E_SUCCESS), , r, "[%s] Propagating.", GetErrorMessage(r));
364 r = GET_BITMAP_CONFIG_N(EDITDATE::CONTENT_BG_EFFECT_PRESSED, BITMAP_PIXEL_FORMAT_ARGB8888, __pContentBgEffectPressedBitmap);
365 SysTryCatch(NID_UI_CTRL, (r == E_SUCCESS), , r, "[%s] Propagating.", GetErrorMessage(r));
367 r = GET_BITMAP_CONFIG_N(EDITDATE::CONTENT_BG_EFFECT_DISABLED, BITMAP_PIXEL_FORMAT_ARGB8888, __pContentBgEffectDisabledBitmap);
368 SysTryCatch(NID_UI_CTRL, (r == E_SUCCESS), , r, "[%s] Propagating.", GetErrorMessage(r));
374 delete __pContentBgNormalColorReplacementBitmap;
375 __pContentBgNormalColorReplacementBitmap = null;
377 delete __pContentBgPressedColorReplacementBitmap;
378 __pContentBgPressedColorReplacementBitmap = null;
380 delete __pContentBgDisabledColorReplacementBitmap;
381 __pContentBgDisabledColorReplacementBitmap = null;
383 delete __pContentBgHighlightedColorReplacementBitmap;
384 __pContentBgHighlightedColorReplacementBitmap = null;
386 delete __pContentBgEffectNormalBitmap;
387 __pContentBgEffectNormalBitmap = null;
389 delete __pContentBgEffectPressedBitmap;
390 __pContentBgEffectPressedBitmap = null;
392 delete __pContentBgEffectDisabledBitmap;
393 __pContentBgEffectDisabledBitmap = null;
399 _EditDatePresenter::GetDate(void) const
401 SysAssertf((__pEditDateTimeModel != null), "The _EditDateTimeModel instance is null.");
404 date.SetValue(GetYear(), GetMonth(), GetDay(), DATETIME_HOUR_MIN, DATETIME_MINUTE_MIN);
410 _EditDatePresenter::GetDay(void) const
412 SysAssertf((__pEditDateTimeModel != null), "The _EditDateTimeModel instance is null.");
414 return __pEditDateTimeModel->GetDay();
418 _EditDatePresenter::GetMonth(void) const
420 SysAssertf((__pEditDateTimeModel != null), "The _EditDateTimeModel instance is null.");
422 return __pEditDateTimeModel->GetMonth();
426 _EditDatePresenter::GetYear(void) const
428 SysAssertf((__pEditDateTimeModel != null), "The _EditDateTimeModel instance is null.");
430 return __pEditDateTimeModel->GetYear();
434 _EditDatePresenter::SetDate(const DateTime& date)
436 SysAssertf((__pEditDateTimeModel != null), "The _EditDateTimeModel instance is null.");
438 __pEditDateTimeModel->SetDateTime(date);
443 _EditDatePresenter::SetCurrentDate(void)
445 SysAssertf((__pEditDateTimeModel != null), "The _EditDateTimeModel instance is null.");
447 __pEditDateTimeModel->SetCurrentDateTime();
452 _EditDatePresenter::SetYear(int year)
454 SysAssertf((__pEditDateTimeModel != null), "The _EditDateTimeModel instance is null.");
456 return __pEditDateTimeModel->SetYear(year);
460 _EditDatePresenter::SetMonth(int month)
462 SysAssertf((__pEditDateTimeModel != null), "The _EditDateTimeModel instance is null.");
464 return __pEditDateTimeModel->SetMonth(month);
468 _EditDatePresenter::SetDay(int day)
470 SysAssertf((__pEditDateTimeModel != null), "The _EditDateTimeModel instance is null.");
472 return __pEditDateTimeModel->SetDay(day);
476 _EditDatePresenter::SetDatePickerEnabled(bool enable)
478 __datePickerEnabled = enable;
483 _EditDatePresenter::IsDatePickerEnabled(void) const
485 return __datePickerEnabled;
489 _EditDatePresenter::SetMinYear(int minYear)
491 return __pEditDateTimeModel->SetMinYear(minYear);
495 _EditDatePresenter::SetMaxYear(int maxYear)
497 return __pEditDateTimeModel->SetMaxYear(maxYear);
501 _EditDatePresenter::GetMinYear(void) const
506 __pEditDateTimeModel->GetYearRange(minYear, maxYear);
512 _EditDatePresenter::GetMaxYear(void) const
517 __pEditDateTimeModel->GetYearRange(minYear, maxYear);
523 _EditDatePresenter::Draw(void)
525 result r = E_SUCCESS;
531 Canvas* pCanvas = __pEditDate->GetCanvasN();
533 SysTryReturn(NID_UI_CTRL, (pCanvas != null), r, r, "[%s] Propagating. Failed to get canvas.", GetErrorMessage(r));
535 pCanvas->SetBackgroundColor(Color(0, 0, 0, 0));
538 if (!__title.IsEmpty())
547 _DateTimeUtils dateTimeUtils;
548 monthString = dateTimeUtils.GetMonthString(GetMonth());
549 yearString.Format(10, L"%04d", GetYear());
550 dayString.Format(10, L"%02d", GetDay());
552 CalculateAreaBounds();
554 r = DrawText(*pCanvas, GetDateAreaBounds(DATETIME_ID_DAY), dayString, DATETIME_ID_DAY);
555 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
556 r = DrawText(*pCanvas, GetDateAreaBounds(DATETIME_ID_MONTH), monthString, DATETIME_ID_MONTH);
557 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
558 r = DrawText(*pCanvas, GetDateAreaBounds(DATETIME_ID_YEAR), yearString, DATETIME_ID_YEAR);
559 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
568 _EditDatePresenter::DrawFocus(void)
570 FloatRectangle bounds(0.0f, 0.0f, 0.0f, 0.0f);
572 Canvas* pCanvas = __pEditDate->GetCanvasN();
573 SysTryReturnResult(NID_UI_CTRL, (pCanvas != null), E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Unable to create canvas.");
575 if (__focusId == DATETIME_ID_DAY)
577 bounds = GetDateAreaBounds(DATETIME_ID_DAY);
579 else if (__focusId == DATETIME_ID_MONTH)
581 bounds = GetDateAreaBounds(DATETIME_ID_MONTH);
583 else if (__focusId == DATETIME_ID_YEAR)
585 bounds = GetDateAreaBounds(DATETIME_ID_YEAR);
588 result r = E_SUCCESS;
590 if (_BitmapImpl::CheckNinePatchedBitmapStrictly(*__pContentBgHighlightedColorReplacementBitmap))
592 r = pCanvas->DrawNinePatchedBitmap(bounds, *__pContentBgHighlightedColorReplacementBitmap);
593 SysTryCatch(NID_UI_CTRL, (r == E_SUCCESS), , r, "[%s] Propagating.", GetErrorMessage(r));
597 r = pCanvas->DrawBitmap(bounds, *__pContentBgHighlightedColorReplacementBitmap);
598 SysTryCatch(NID_UI_CTRL, (r == E_SUCCESS), , r, "[%s] Propagating.", GetErrorMessage(r));
611 _EditDatePresenter::UpdateLastSelectedValue(_DateTimeId id, bool isTouchPressed)
614 SetLastSelectedId(id);
615 __lastSelectedValue = "";
616 _DateTimeUtils dateTimeUtils;
618 if (GetLastSelectedId() == DATETIME_ID_YEAR)
620 __lastSelectedValue.Format(10, L"%04d", GetYear());
623 PLAY_FEEDBACK(_RESOURCE_FEEDBACK_PATTERN_TAP, __pEditDate);
626 else if (GetLastSelectedId() == DATETIME_ID_MONTH)
628 __lastSelectedValue = dateTimeUtils.GetMonthString(GetMonth());
631 PLAY_FEEDBACK(_RESOURCE_FEEDBACK_PATTERN_TAP, __pEditDate);
634 else if (GetLastSelectedId() == DATETIME_ID_DAY)
636 __lastSelectedValue.Format(10, L"%02d", GetDay());
639 PLAY_FEEDBACK(_RESOURCE_FEEDBACK_PATTERN_TAP, __pEditDate);
643 __pEditDate->Invalidate();
648 _EditDatePresenter::CalculateAreaBounds(void)
650 result r = E_SUCCESS;
652 _DateTimeUtils dateTimeUtils;
653 int localeDateFormat = dateTimeUtils.GetLocaleDateFormat();
655 if (localeDateFormat == DATE_FORMAT_DDMMYYYY)
657 __monthBounds.x = __dayBounds.x + __dayBounds.width + __elementMargin;
658 __yearBounds.x = __monthBounds.x + __monthBounds.width + __elementMargin;
660 else if (localeDateFormat == DATE_FORMAT_MMDDYYYY)
662 __dayBounds.x = __monthBounds.x + __monthBounds.width + __elementMargin;
663 __yearBounds.x = __dayBounds.x + __dayBounds.width + __elementMargin;
665 else if (localeDateFormat == DATE_FORMAT_YYYYMMDD)
667 __monthBounds.x = __yearBounds.x + __yearBounds.width + __elementMargin;
668 __dayBounds.x = __monthBounds.x + __monthBounds.width + __elementMargin;
670 else if (localeDateFormat == DATE_FORMAT_YYYYDDMM)
672 __dayBounds.x = __yearBounds.x + __yearBounds.width + __elementMargin;
673 __monthBounds.x = __dayBounds.x + __dayBounds.width + __elementMargin;
680 _EditDatePresenter::DrawTitle(Canvas& canvas)
682 if (!__pEditDate->IsEnabled())
684 Color titleDisabledColor;
685 GET_COLOR_CONFIG(EDITDATE::TITLE_TEXT_DISABLED, titleDisabledColor);
686 __titleObject.SetForegroundColor(titleDisabledColor, 0, __titleObject.GetTextLength());
689 (_FontImpl::GetInstance(*__pFont))->SetSize(__titleFontSize);
690 (_FontImpl::GetInstance(*__pFont))->SetStyle(FONT_STYLE_BOLD);
691 __titleObject.SetFont(__pFont, 0, __titleObject.GetTextLength());
692 __titleObject.Draw(*_CanvasImpl::GetInstance(canvas));
698 _EditDatePresenter::DrawText(Canvas& canvas, const FloatRectangle& bounds, const String& text, _DateTimeId boxId)
701 float contentTextMargin;
703 GET_SHAPE_CONFIG(EDITDATE::CONTENT_TEXT_MARGIN, __pEditDate->GetOrientation(), contentTextMargin);
705 if (!__pEditDate->IsEnabled())
707 GET_COLOR_CONFIG(EDITDATE::TEXT_DISABLED, textColor);
711 GET_COLOR_CONFIG(EDITDATE::TEXT_NORMAL, textColor);
714 (_FontImpl::GetInstance(*__pFont))->SetStyle(FONT_STYLE_PLAIN);
716 if (boxId == GetLastSelectedId() && boxId != DATETIME_ID_NONE)
718 (_FontImpl::GetInstance(*__pFont))->SetStyle(FONT_STYLE_BOLD);
719 GET_COLOR_CONFIG(EDITDATE::TEXT_PRESSED, textColor);
722 DrawContentBitmap(canvas, bounds, boxId);
724 FloatRectangle drawAreaBounds(0.0f, 0.0f, 0.0f, 0.0f);
725 drawAreaBounds.x = bounds.x + contentTextMargin;
726 drawAreaBounds.y = bounds.y + contentTextMargin;
727 drawAreaBounds.width = bounds.width - (contentTextMargin * 2.0f);
728 drawAreaBounds.height = bounds.height - (contentTextMargin * 2.0f);
730 TextSimple* pSimpleText = null;
731 pSimpleText = new (std::nothrow)TextSimple((const_cast <wchar_t*>(text.GetPointer())), text.GetLength(), TEXT_ELEMENT_SOURCE_TYPE_EXTERNAL);
732 SysTryReturn(NID_UI_CTRL, (pSimpleText != null), E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
734 __textObject.RemoveAll();
735 if (__isFocused && __focusId == boxId)
737 GET_COLOR_CONFIG(EDITDATE::TEXT_HIGHLIGHTED, textColor);
741 (_FontImpl::GetInstance(*__pFont))->SetSize(__dateFontSize);
742 __textObject.AppendElement(*pSimpleText);
744 __textObject.SetFont(__pFont, 0, __textObject.GetTextLength());
745 __textObject.SetForegroundColor(textColor, 0, __textObject.GetTextLength());
746 __textObject.SetBounds(drawAreaBounds);
747 __textObject.Draw(*_CanvasImpl::GetInstance(canvas));
753 _EditDatePresenter::DrawContentBitmap(Canvas& canvas, const FloatRectangle& bounds, _DateTimeId boxId)
755 result r = E_SUCCESS;
757 bool isCustomBitmap = false;
758 Bitmap* pReplacementBitmap = null;
759 Bitmap* pEffectBitmap = null;
761 if (!__pEditDate->IsEnabled())
763 isCustomBitmap = IS_CUSTOM_BITMAP(EDITTIME::CONTENT_BG_DISABLED);
764 pReplacementBitmap = __pContentBgDisabledColorReplacementBitmap;
765 pEffectBitmap = __pContentBgEffectDisabledBitmap;
767 else if (GetLastSelectedId() != boxId)
769 isCustomBitmap = IS_CUSTOM_BITMAP(EDITTIME::CONTENT_BG_NORMAL);
770 pReplacementBitmap = __pContentBgNormalColorReplacementBitmap;
771 pEffectBitmap = __pContentBgEffectNormalBitmap;
775 isCustomBitmap = IS_CUSTOM_BITMAP(EDITTIME::CONTENT_BG_PRESSED);
776 pReplacementBitmap = __pContentBgPressedColorReplacementBitmap;
777 pEffectBitmap = __pContentBgEffectPressedBitmap;
780 r = DrawResourceBitmap(canvas, bounds, pReplacementBitmap);
781 SysTryReturn(NID_UI_CTRL, (r == E_SUCCESS), r, r, "[%s] Propagating.", GetErrorMessage(r));
785 r = DrawResourceBitmap(canvas, bounds, pEffectBitmap);
786 SysTryReturn(NID_UI_CTRL, (r == E_SUCCESS), r, r, "[%s] Propagating.", GetErrorMessage(r));
793 _EditDatePresenter::DrawResourceBitmap(Canvas& canvas, const FloatRectangle& bounds, Bitmap* pBitmap)
795 result r = E_SUCCESS;
802 if (_BitmapImpl::CheckNinePatchedBitmapStrictly(*pBitmap))
804 r = canvas.DrawNinePatchedBitmap(bounds, *pBitmap);
805 SysTryReturn(NID_UI_CTRL, (r == E_SUCCESS), r, r, "[%s] Propagating.", GetErrorMessage(r));
809 r = canvas.DrawBitmap(bounds, *pBitmap);
810 SysTryReturn(NID_UI_CTRL, (r == E_SUCCESS), r, r, "[%s] Propagating.", GetErrorMessage(r));
817 _EditDatePresenter::GetBoxIdFromPosition(const FloatPoint& point) const
819 _DateTimeId displayBoxId = DATETIME_ID_NONE;
821 if (point.y < __dayBounds.y || point.y > __dayBounds.y + __dayBounds.height)
826 if (__dayBounds.Contains(point))
828 displayBoxId = DATETIME_ID_DAY;
830 else if (__monthBounds.Contains(point))
832 displayBoxId = DATETIME_ID_MONTH;
834 else if (__yearBounds.Contains(point))
836 displayBoxId = DATETIME_ID_YEAR;
843 _EditDatePresenter::GetDateAreaBounds(_DateTimeId id) const
845 if (id == DATETIME_ID_DAY)
849 else if (id == DATETIME_ID_MONTH)
851 return __monthBounds;
853 else if (id == DATETIME_ID_YEAR)
859 return FloatRectangle();
864 _EditDatePresenter::GetTitleBounds(void) const
866 return __titleBounds;
870 _EditDatePresenter::SetLastSelectedId(_DateTimeId boxId)
872 __lastSelectedId = boxId;
877 _EditDatePresenter::GetLastSelectedId(void) const
879 return __lastSelectedId;
883 _EditDatePresenter::OnFontChanged(Font* pFont)
887 if (__pEditDate->GetDateTimeBar() != null)
889 __pEditDate->GetDateTimeBar()->SetFont(*pFont);
896 _EditDatePresenter::OnFontInfoRequested(unsigned long& style, float& size)
898 style = FONT_STYLE_PLAIN;
899 size = __dateFontSize;
905 _EditDatePresenter::SetFocusState(bool isFocused)
907 __isFocused = isFocused;
911 _EditDatePresenter::SetFocusedElement(void)
913 _DateTimeUtils dateTimeUtils;
914 if (__isEnterKeyPressed)
916 __isEnterKeyPressed = false;
919 int localeDateFormat = dateTimeUtils.GetLocaleDateFormat();
920 if (__focusId == DATETIME_ID_NONE)
922 if (localeDateFormat == DATE_FORMAT_DDMMYYYY)
924 __focusId = DATETIME_ID_DAY;
926 else if (localeDateFormat == DATE_FORMAT_MMDDYYYY)
928 __focusId = DATETIME_ID_MONTH;
930 else if (localeDateFormat == DATE_FORMAT_YYYYMMDD)
932 __focusId = DATETIME_ID_YEAR;
934 else if (localeDateFormat == DATE_FORMAT_YYYYDDMM)
936 __focusId = DATETIME_ID_YEAR;
943 _EditDatePresenter::OnFocusLost(const _Control &source)
945 if (!__isEnterKeyPressed)
947 __focusId = DATETIME_ID_NONE;
950 __pEditDate->Invalidate();
955 _EditDatePresenter::OnFocusModeStateChanged(void)
958 __focusId = DATETIME_ID_NONE;
959 __pEditDate->Invalidate();
964 _EditDatePresenter::OnKeyPressed(const _Control& source, const _KeyInfo& keyInfo)
971 _KeyCode keyCode = keyInfo.GetKeyCode();
972 _DateTimeUtils dateTimeUtils;
973 int localeDateFormat = dateTimeUtils.GetLocaleDateFormat();
979 if (__focusId == DATETIME_ID_DAY)
981 if (localeDateFormat == DATE_FORMAT_DDMMYYYY || localeDateFormat == DATE_FORMAT_YYYYDDMM)
983 __focusId = DATETIME_ID_MONTH;
985 else if (localeDateFormat == DATE_FORMAT_MMDDYYYY)
987 __focusId = DATETIME_ID_YEAR;
994 else if (__focusId == DATETIME_ID_MONTH)
996 if (localeDateFormat == DATE_FORMAT_DDMMYYYY)
998 __focusId = DATETIME_ID_YEAR;
1000 else if (localeDateFormat == DATE_FORMAT_MMDDYYYY || localeDateFormat == DATE_FORMAT_YYYYMMDD)
1002 __focusId = DATETIME_ID_DAY;
1009 else if (__focusId == DATETIME_ID_YEAR)
1011 if (localeDateFormat == DATE_FORMAT_YYYYMMDD)
1013 __focusId = DATETIME_ID_MONTH;
1015 else if (localeDateFormat == DATE_FORMAT_YYYYDDMM)
1017 __focusId = DATETIME_ID_DAY;
1024 __pEditDate->Invalidate();
1029 if (__focusId == DATETIME_ID_DAY)
1031 if (localeDateFormat == DATE_FORMAT_YYYYDDMM)
1033 __focusId = DATETIME_ID_YEAR;
1035 else if (localeDateFormat == DATE_FORMAT_MMDDYYYY || localeDateFormat == DATE_FORMAT_YYYYMMDD)
1037 __focusId = DATETIME_ID_MONTH;
1044 else if (__focusId == DATETIME_ID_MONTH)
1046 if (localeDateFormat == DATE_FORMAT_YYYYMMDD)
1048 __focusId = DATETIME_ID_YEAR;
1050 else if (localeDateFormat == DATE_FORMAT_DDMMYYYY || localeDateFormat == DATE_FORMAT_YYYYDDMM)
1052 __focusId = DATETIME_ID_DAY;
1059 else if (__focusId == DATETIME_ID_YEAR)
1061 if (localeDateFormat == DATE_FORMAT_DDMMYYYY)
1063 __focusId = DATETIME_ID_MONTH;
1065 else if (localeDateFormat == DATE_FORMAT_MMDDYYYY)
1067 __focusId = DATETIME_ID_DAY;
1074 __pEditDate->Invalidate();
1086 _EditDatePresenter::OnKeyReleased(const _Control& source, const _KeyCode& keyCode)
1095 VisualElement *pEditDateElement = __pEditDate->GetVisualElement();
1096 result r = GetLastResult();
1097 SysTryReturn(NID_UI_CTRL, (pEditDateElement != null), false, r, "[%s] Propagating.", GetErrorMessage(r));
1098 pEditDateElement->RemoveAllAnimations();
1103 int displayValue = -1;
1105 _DateTimeId boxId = DATETIME_ID_NONE;
1111 __isEnterKeyPressed = true;
1112 if (__focusId == DATETIME_ID_DAY)
1114 _DateTimeUtils dateTimeUtils;
1115 maxValue = dateTimeUtils.CalculateMaxDay(GetYear(), GetMonth());
1116 minValue = DATETIME_DAY_MIN;
1117 displayValue = GetDay();
1118 boxId = DATETIME_ID_DAY;
1120 if (__pEditDate->GetDateTimeBar()->GetItemCount() > 0)
1122 __pEditDate->GetDateTimeBar()->RemoveAllItems();
1126 else if (__focusId == DATETIME_ID_MONTH)
1128 minValue = DATETIME_MONTH_MIN;
1129 maxValue = DATETIME_MONTH_MAX;
1130 displayValue = GetMonth();
1131 boxId = DATETIME_ID_MONTH;
1133 if (__pEditDate->GetDateTimeBar()->GetItemCount() > 0)
1135 __pEditDate->GetDateTimeBar()->RemoveAllItems();
1138 else if (__focusId == DATETIME_ID_YEAR)
1140 minValue = GetMinYear();
1141 maxValue = GetMaxYear();
1142 displayValue = GetYear();
1143 boxId = DATETIME_ID_YEAR;
1145 if (__pEditDate->GetDateTimeBar()->GetItemCount() > 0)
1147 __pEditDate->GetDateTimeBar()->RemoveAllItems();
1150 FloatRectangle absoluteBounds = __pEditDate->GetAbsoluteBoundsF();
1152 FloatRectangle bounds(0.0f, 0.0f, 0.0f, 0.0f);
1153 bounds = GetDateAreaBounds(boxId);
1154 bounds.x += absoluteBounds.x;
1155 __pEditDate->GetDateTimeBar()->CalculateArrowBounds(bounds);
1156 __pEditDate->GetDateTimeBar()->SetInitialValue(minValue, maxValue, displayValue, boxId);
1157 __pEditDate->GetDateTimeBar()->SetVisibleState(true);
1158 __pEditDate->GetDateTimeBar()->Open();
1160 UpdateLastSelectedValue(boxId, false);
1172 _EditDatePresenter::OnTouchPressed(const _Control& source, const _TouchInfo& touchinfo)
1174 SysTryReturn(NID_UI_CTRL, IsDatePickerEnabled() == true, true, E_SYSTEM,
1175 "[E_SYSTEM] A system error has occurred. EditDate instance is disabled.");
1177 if (&source != __pEditDate)
1182 __touchMoveHandled = false;
1184 FloatPoint point = touchinfo.GetCurrentPosition();
1186 _DateTimeId boxId = DATETIME_ID_NONE;
1187 boxId = GetBoxIdFromPosition(point);
1189 if (boxId < DATETIME_ID_YEAR || boxId > DATETIME_ID_DAY)
1191 __selectedId = DATETIME_ID_NONE;
1197 int displayValue = -1;
1199 if (boxId == DATETIME_ID_DAY)
1201 if (__pEditDate->GetDateTimeBar() != null)
1203 _DateTimeUtils dateTimeUtils;
1204 maxValue = dateTimeUtils.CalculateMaxDay(GetYear(), GetMonth());
1205 minValue = DATETIME_DAY_MIN;
1206 displayValue = GetDay();
1209 else if (boxId == DATETIME_ID_MONTH)
1211 minValue = DATETIME_MONTH_MIN;
1212 maxValue = DATETIME_MONTH_MAX;
1213 displayValue = GetMonth();
1215 else if (boxId == DATETIME_ID_YEAR)
1217 minValue = GetMinYear();
1218 maxValue = GetMaxYear();
1219 displayValue = GetYear();
1222 if (__pEditDate->GetDateTimeBar() != null)
1224 if (__pEditDate->GetDateTimeBar()->GetItemCount() > 0)
1226 __pEditDate->GetDateTimeBar()->RemoveAllItems();
1229 result r = __pEditDate->GetDateTimeBar()->SetInitialValue(minValue, maxValue, displayValue, boxId);
1232 __selectedId = DATETIME_ID_NONE;
1237 __selectedId = boxId;
1243 _EditDatePresenter::OnTouchReleased(const _Control& source, const _TouchInfo& touchinfo)
1245 SysTryReturn(NID_UI_CTRL, IsDatePickerEnabled() == true, true, E_SYSTEM,
1246 "[E_SYSTEM] A system error has occurred. EditDate instance is disabled.");
1248 if (&source != __pEditDate)
1253 FloatPoint point = touchinfo.GetCurrentPosition();
1255 _DateTimeId boxId = DATETIME_ID_NONE;
1256 boxId = GetBoxIdFromPosition(point);
1258 if (boxId == GetLastSelectedId() || boxId != __selectedId || boxId == DATETIME_ID_NONE)
1260 if (__pEditDate->GetDateTimeBar() != null && __pEditDate->GetDateTimeBar()->IsActivated())
1262 __pEditDate->GetDateTimeBar()->CloseDateTimeBar();
1265 __selectedId = DATETIME_ID_NONE;
1266 SetLastSelectedId(__selectedId);
1273 UpdateLastSelectedValue(__selectedId, true);
1275 if ((__pEditDate->GetDateTimeBar() != null) && (GetLastSelectedId() != DATETIME_ID_NONE))
1277 __pEditDate->SetFocused(true);
1278 FloatRectangle bounds(0.0f, 0.0f, 0.0f, 0.0f);
1279 bounds = GetDateAreaBounds(GetLastSelectedId());
1280 FloatRectangle absoluteBounds(0.0f, 0.0f, 0.0f, 0.0f);
1281 absoluteBounds = __pEditDate->GetAbsoluteBoundsF();
1282 bounds.x += absoluteBounds.x;
1284 __pEditDate->GetDateTimeBar()->CalculateArrowBounds(bounds);
1286 if (__pEditDate->GetDateTimeBar()->IsActivated())
1288 __pEditDate->GetDateTimeBar()->RemoveAllAnimations();
1289 __pEditDate->GetDateTimeBar()->Close();
1290 __pEditDate->GetDateTimeBar()->SetVisibleState(true);
1291 __pEditDate->GetDateTimeBar()->Open();
1295 __pEditDate->GetDateTimeBar()->SetVisibleState(true);
1296 __pEditDate->GetDateTimeBar()->Open();
1300 __selectedId = DATETIME_ID_NONE;
1305 _EditDatePresenter::OnTouchCanceled(const _Control& source, const _TouchInfo& touchinfo)
1307 if (&source != __pEditDate)
1312 __selectedId = DATETIME_ID_NONE;
1318 _EditDatePresenter::OnTouchMoved(const _Control& source, const _TouchInfo& touchinfo)
1320 if (&source != __pEditDate)
1325 if (__pEditDate->GetDateTimeBar() != null && __pEditDate->GetDateTimeBar()->IsActivated())
1334 _EditDatePresenter::OnTouchMoveHandled(const _Control& control)
1336 __touchMoveHandled = true;
1337 __selectedId = DATETIME_ID_NONE;
1343 _EditDatePresenter::Animate(void)
1345 SysTryReturnVoidResult(NID_UI_CTRL, !__isAnimating, E_SUCCESS, "Rolling animation is in progress.");
1346 SysAssertf((__pFont != null), "Font instance must not be null.");
1348 result r = E_SUCCESS;
1349 FloatRectangle rect;
1354 FloatPoint textPoint;
1355 TextSimple* pOldSimpleText = null;
1356 TextSimple* pNewSimpleText = null;
1357 bool isCustomBitmap = false;
1359 _DateTimeUtils dateTimeUtils;
1360 monthString = dateTimeUtils.GetMonthString(GetMonth());
1361 yearString.Format(10, L"%04d", GetYear());
1362 dayString.Format(10, L"%02d", GetDay());
1364 if (GetLastSelectedId() == DATETIME_ID_DAY)
1366 SysTryReturnVoidResult(NID_UI_CTRL, (__lastSelectedValue.Equals(dayString) == false), E_SUCCESS, "Day string matched.");
1368 newValue = dayString;
1369 rect = GetDateAreaBounds(DATETIME_ID_DAY);
1371 else if (GetLastSelectedId() == DATETIME_ID_MONTH)
1373 SysTryReturnVoidResult(NID_UI_CTRL, (__lastSelectedValue.Equals(monthString) == false), E_SUCCESS, "Month string matched.");
1375 newValue = monthString;
1376 rect = GetDateAreaBounds(DATETIME_ID_MONTH);
1378 else if (GetLastSelectedId() == DATETIME_ID_YEAR)
1380 SysTryReturnVoidResult(NID_UI_CTRL, (__lastSelectedValue.Equals(yearString) == false), E_SUCCESS, "Year string matched.");
1382 newValue = yearString;
1383 rect = GetDateAreaBounds(DATETIME_ID_YEAR);
1386 FloatDimension newTextDim;
1387 FloatDimension oldTextDim;
1388 VisualElement* pNewVisualElement = null;
1389 VisualElement* pOldVisualElement = null;
1390 VisualElement* pEditDateElement = null;
1391 VisualElementPropertyAnimation* pNewBoundsAnimation = null;
1392 VisualElementPropertyAnimation* pOldBoundsAnimation = null;
1393 Canvas *pCanvas = null;
1394 Canvas *pContentCanvas = null;
1395 Color contentBgColor;
1396 Color textPressedColor;
1397 float contentTextMargin;
1399 GET_COLOR_CONFIG(EDITTIME::CONTENT_BG_PRESSED, contentBgColor);
1400 GET_COLOR_CONFIG(EDITTIME::TEXT_PRESSED, textPressedColor);
1401 GET_SHAPE_CONFIG(EDITDATE::CONTENT_TEXT_MARGIN, __pEditDate->GetOrientation(), contentTextMargin);
1403 __pFont->GetTextExtent(newValue, newValue.GetLength(), newTextDim);
1404 __pFont->GetTextExtent(__lastSelectedValue, __lastSelectedValue.GetLength(), oldTextDim);
1406 if (newTextDim.width > oldTextDim.width)
1408 textPoint.x = (rect.width - newTextDim.width) / 2.0f;
1412 textPoint.x = (rect.width - oldTextDim.width) / 2.0f;
1415 SysTryReturnVoidResult(NID_UI_CTRL, (rect.x + textPoint.x < __pEditDate->GetBoundsF().width), E_SUCCESS, "Rolling animation can't be played.");
1417 __isAnimating = true;
1419 __pContentProvider = new (std::nothrow) VisualElement();
1420 SysTryReturnVoidResult(NID_UI_CTRL, (__pContentProvider != null), E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
1422 r = __pContentProvider->Construct();
1423 SysTryCatch(NID_UI_CTRL, (r == E_SUCCESS), , r, "[%s] Propagating.", GetErrorMessage(r));
1425 __pContentProvider->SetShowState(true);
1426 __pContentProvider->SetClipChildrenEnabled(true);
1427 __pContentProvider->SetImplicitAnimationEnabled(false);
1429 pEditDateElement = __pEditDate->GetVisualElement();
1430 r = GetLastResult();
1431 SysTryCatch(NID_UI_CTRL, (pEditDateElement != null), , r, "[%s] Propagating.", GetErrorMessage(r));
1433 pNewVisualElement = new (std::nothrow) VisualElement();
1434 SysTryCatch(NID_UI_CTRL, (pNewVisualElement != null), , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
1436 r = pNewVisualElement->Construct();
1439 pNewVisualElement->Destroy();
1440 pNewVisualElement = null;
1442 SysTryCatch(NID_UI_CTRL, (r == E_SUCCESS), , r, "[%s] Propagating.", GetErrorMessage(r));
1444 pOldVisualElement = new (std::nothrow) VisualElement();
1445 if (pOldVisualElement == null)
1447 pNewVisualElement->Destroy();
1448 pNewVisualElement = null;
1450 SysTryCatch(NID_UI_CTRL, (pOldVisualElement != null), , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
1452 r = pOldVisualElement->Construct();
1455 pNewVisualElement->Destroy();
1456 pOldVisualElement->Destroy();
1457 pNewVisualElement = null;
1458 pOldVisualElement = null;
1460 SysTryCatch(NID_UI_CTRL, (r == E_SUCCESS), , r, "[%s] Propagating.", GetErrorMessage(r));
1462 pNewVisualElement->SetShowState(true);
1463 pOldVisualElement->SetShowState(true);
1465 __pContentProvider->SetBounds(FloatRectangle((rect.x + contentTextMargin), (rect.y + (contentTextMargin * 2.0f)), (rect.width - (contentTextMargin * 2.0f)), (rect.height - (contentTextMargin * 4.0f))));
1467 pNewVisualElement->SetBounds(FloatRectangle(0, 0, __pContentProvider->GetBounds().width, __pContentProvider->GetBounds().height));
1468 pOldVisualElement->SetBounds(FloatRectangle(0, 0, __pContentProvider->GetBounds().width, __pContentProvider->GetBounds().height));
1470 pContentCanvas = pEditDateElement->GetCanvasN(__pContentProvider->GetBounds());
1471 r = GetLastResult();
1472 SysTryCatch(NID_UI_CTRL, (pContentCanvas != null), , r, "[%s] Propagating.", GetErrorMessage(r));
1474 pContentCanvas->SetBackgroundColor(Color(0, 0, 0, 0));
1475 pContentCanvas->Clear();
1477 pCanvas = pEditDateElement->GetCanvasN(rect);
1478 r = GetLastResult();
1479 SysTryCatch(NID_UI_CTRL, (pCanvas != null), , r, "[%s] Propagating.", GetErrorMessage(r));
1480 pCanvas->SetBackgroundColor(Color(0, 0, 0, 0));
1484 r = DrawResourceBitmap(*pCanvas, rect, __pContentBgPressedColorReplacementBitmap);
1485 isCustomBitmap = IS_CUSTOM_BITMAP(EDITTIME::CONTENT_BG_PRESSED);
1487 if (!isCustomBitmap)
1489 result res = DrawResourceBitmap(*pCanvas, rect, __pContentBgEffectPressedBitmap);
1491 if (res != E_SUCCESS)
1493 SysLog(NID_UI_CTRL, "[%s] Propagating.", GetErrorMessage(res));
1502 pContentCanvas->SetBackgroundColor(contentBgColor);
1503 pContentCanvas->Clear();
1506 delete pContentCanvas;
1507 pContentCanvas = null;
1509 pEditDateElement->AttachChild(*__pContentProvider);
1510 __pContentProvider->AttachChild(*pOldVisualElement);
1511 __pContentProvider->AttachChild(*pNewVisualElement);
1513 pNewBoundsAnimation = new (std::nothrow) VisualElementPropertyAnimation();
1514 SysTryCatch(NID_UI_CTRL, (pNewBoundsAnimation != null), , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
1516 pNewBoundsAnimation->SetDuration(300);
1517 pNewBoundsAnimation->SetPropertyName("bounds.position");
1518 pNewBoundsAnimation->SetStartValue(Variant(FloatPoint(pNewVisualElement->GetBounds().x, oldTextDim.height)));
1519 pNewBoundsAnimation->SetEndValue(Variant(FloatPoint(pNewVisualElement->GetBounds().x, 0.0f)));
1521 pOldBoundsAnimation = new (std::nothrow) VisualElementPropertyAnimation();
1522 SysTryCatch(NID_UI_CTRL, (pOldBoundsAnimation != null), , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
1524 pOldBoundsAnimation->SetDuration(300);
1525 pOldBoundsAnimation->SetPropertyName("bounds.position");
1526 pOldBoundsAnimation->SetStartValue(Variant(FloatPoint(pOldVisualElement->GetBounds().x, 0.0f)));
1527 pOldBoundsAnimation->SetEndValue(Variant(FloatPoint(pOldVisualElement->GetBounds().x, oldTextDim.height * -1.0f)));
1529 pOldSimpleText = new (std::nothrow)TextSimple((const_cast <wchar_t*>(__lastSelectedValue.GetPointer())), __lastSelectedValue.GetLength(), TEXT_ELEMENT_SOURCE_TYPE_EXTERNAL);
1530 SysTryCatch(NID_UI_CTRL, (pOldSimpleText != null), , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
1532 pCanvas = pOldVisualElement->GetCanvasN();
1533 r = GetLastResult();
1534 SysTryCatch(NID_UI_CTRL, (pCanvas != null), , r, "[%s] Propagating.", GetErrorMessage(r));
1536 pCanvas->SetBackgroundColor(Color(0, 0, 0, 0));
1538 pCanvas->SetForegroundColor(textPressedColor);
1540 (_FontImpl::GetInstance(*__pFont))->SetSize(__dateFontSize);
1541 (_FontImpl::GetInstance(*__pFont))->SetStyle(FONT_STYLE_PLAIN);
1542 __textObject.RemoveAll();
1543 __textObject.AppendElement(*pOldSimpleText);
1545 __textObject.SetFont(__pFont, 0, __textObject.GetTextLength());
1546 __textObject.SetForegroundColor(textPressedColor, 0, __textObject.GetTextLength());
1547 __textObject.SetBounds(FloatRectangle(0, 0, pCanvas->GetBounds().width, pCanvas->GetBounds().height));
1548 __textObject.Draw(*_CanvasImpl::GetInstance(*pCanvas));
1553 pNewSimpleText = new (std::nothrow)TextSimple((const_cast <wchar_t*>(newValue.GetPointer())), newValue.GetLength(), TEXT_ELEMENT_SOURCE_TYPE_EXTERNAL);
1554 SysTryCatch(NID_UI_CTRL, (pNewSimpleText != null), , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
1556 pCanvas = pNewVisualElement->GetCanvasN();
1557 r = GetLastResult();
1558 SysTryCatch(NID_UI_CTRL, (pCanvas != null), , r, "[%s] Propagating.", GetErrorMessage(r));
1560 pCanvas->SetBackgroundColor(Color(0, 0, 0, 0));
1562 pCanvas->SetForegroundColor(textPressedColor);
1564 (_FontImpl::GetInstance(*__pFont))->SetSize(__dateFontSize);
1565 (_FontImpl::GetInstance(*__pFont))->SetStyle(FONT_STYLE_PLAIN);
1566 __textObject.RemoveAll();
1567 __textObject.AppendElement(*pNewSimpleText);
1569 __textObject.SetFont(__pFont, 0, __textObject.GetTextLength());
1570 __textObject.SetForegroundColor(textPressedColor, 0, __textObject.GetTextLength());
1571 __textObject.SetBounds(FloatRectangle(0, 0, pCanvas->GetBounds().width, pCanvas->GetBounds().height));
1572 __textObject.Draw(*_CanvasImpl::GetInstance(*pCanvas));
1577 pOldVisualElement->SetImplicitAnimationEnabled(false);
1578 pNewVisualElement->SetImplicitAnimationEnabled(false);
1580 AnimationTransaction::Begin(__transactionId);
1581 pOldVisualElement->AddAnimation(*pOldBoundsAnimation);
1582 pNewVisualElement->AddAnimation(*pNewBoundsAnimation);
1583 AnimationTransaction::SetCurrentTransactionEventListener(__pEditDate);
1584 AnimationTransaction::Commit();
1586 delete pOldBoundsAnimation;
1587 delete pNewBoundsAnimation;
1592 __isAnimating = false;
1593 __pContentProvider->Destroy();
1594 __pContentProvider = null;
1596 delete pNewBoundsAnimation;
1597 pNewBoundsAnimation = null;
1599 delete pOldBoundsAnimation;
1600 pOldBoundsAnimation = null;
1602 delete pOldSimpleText;
1603 pOldSimpleText = null;
1605 delete pNewSimpleText;
1606 pNewSimpleText = null;
1608 delete pContentCanvas;
1609 pContentCanvas = null;
1615 _EditDatePresenter::EndTransaction(void)
1617 result r = E_SUCCESS;
1619 __isAnimating = false;
1620 VisualElement* pEditDateElement = __pEditDate->GetVisualElement();
1621 r = GetLastResult();
1622 SysTryReturnVoidResult(NID_UI_CTRL, (pEditDateElement != null), r, "[%s] Propagating.", GetErrorMessage(r));
1624 //__pContentProvider will be destroyed in destructor when OnFormBackRequested() callback is received
1625 if (__pContentProvider != null)
1627 pEditDateElement->DetachChild(*__pContentProvider);
1628 __pContentProvider->Destroy();
1629 __pContentProvider = null;
1633 __transactionId = 0;
1636 }}} // Tizen::Ui::Controls