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_BitmapImpl.h>
28 #include <FGrp_FontImpl.h>
29 #include "FUi_ResourceManager.h"
30 #include "FUiCtrl_EditDatePresenter.h"
31 #include "FUiCtrl_EditDate.h"
32 #include "FUiCtrl_DateTimeModel.h"
33 #include "FUiCtrl_DateTimeUtils.h"
34 #include "FUiControl.h"
35 #include "FUiAnim_VisualElement.h"
36 #include "FUiAnimVisualElementPropertyAnimation.h"
37 #include "FGrpColor.h"
38 #include "FUi_CoordinateSystemUtils.h"
40 using namespace Tizen::Graphics;
41 using namespace Tizen::Base;
42 using namespace Tizen::Graphics::_Text;
43 using namespace Tizen::Ui::Animations;
46 namespace Tizen { namespace Ui { namespace Controls
48 _EditDatePresenter::_EditDatePresenter(void)
49 : __pEditDateTimeModel(null)
51 , __dayBounds(FloatRectangle())
52 , __monthBounds(FloatRectangle())
53 , __yearBounds(FloatRectangle())
54 , __dayTouchBounds(FloatRectangle())
55 , __monthTouchBounds(FloatRectangle())
56 , __yearTouchBounds(FloatRectangle())
57 , __titleBounds(FloatRectangle())
58 , __pContentBgNormalColorReplacementBitmap(null)
59 , __pContentBgDisabledColorReplacementBitmap(null)
60 , __pContentBgPressedColorReplacementBitmap(null)
61 , __pContentBgHighlightedColorReplacementBitmap(null)
62 , __pContentBgEffectNormalBitmap(null)
63 , __pContentBgEffectPressedBitmap(null)
64 , __pContentBgEffectDisabledBitmap(null)
65 , __datePickerEnabled(true)
66 , __selectedId(DATETIME_ID_NONE)
67 , __lastSelectedId(DATETIME_ID_NONE)
68 , __touchMoveHandled(false)
72 , __elementMargin(0.0f)
73 , __dividerLineHeight(0.0f)
74 , __titleFontSize(0.0f)
75 , __dateFontSize(0.0f)
76 , __pContentProvider(null)
77 , __isAnimating(false)
78 , __isEditDateInitialized(false)
79 , __elementWidth(0.0f)
83 _EditDatePresenter::~_EditDatePresenter(void)
85 __titleObject.RemoveAll();
86 __textObject.RemoveAll();
88 delete __pEditDateTimeModel;
89 __pEditDateTimeModel = null;
91 delete __pContentBgNormalColorReplacementBitmap;
92 __pContentBgNormalColorReplacementBitmap = null;
94 delete __pContentBgDisabledColorReplacementBitmap;
95 __pContentBgDisabledColorReplacementBitmap = null;
97 delete __pContentBgPressedColorReplacementBitmap;
98 __pContentBgPressedColorReplacementBitmap = null;
100 delete __pContentBgHighlightedColorReplacementBitmap;
101 __pContentBgHighlightedColorReplacementBitmap = null;
103 delete __pContentBgEffectNormalBitmap;
104 __pContentBgEffectNormalBitmap = null;
106 delete __pContentBgEffectPressedBitmap;
107 __pContentBgEffectPressedBitmap = null;
109 delete __pContentBgEffectDisabledBitmap;
110 __pContentBgEffectDisabledBitmap = null;
114 _EditDatePresenter::CreateInstanceN(const _EditDate& editDate, const String& title)
116 _EditDatePresenter* pEditDatePresenter = new (std::nothrow) _EditDatePresenter;
117 SysTryReturn(NID_UI_CTRL, pEditDatePresenter, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
119 pEditDatePresenter->__pEditDate = const_cast <_EditDate*>(&editDate);
121 pEditDatePresenter->__pEditDateTimeModel = new (std::nothrow) _DateTimeModel;
122 SysTryCatch(NID_UI_CTRL, pEditDatePresenter->__pEditDateTimeModel, , E_OUT_OF_MEMORY,
123 "[E_OUT_OF_MEMORY] Memory allocation failed.");
124 pEditDatePresenter->SetTitle(title);
126 return pEditDatePresenter;
129 delete pEditDatePresenter;
134 _EditDatePresenter::SetTitle(const String& title)
140 _EditDatePresenter::Initialize(void)
142 result r = E_SUCCESS;
143 float editDateHeight = 0.0f;
144 float dateLeftMargin = 0.0f;
145 float titleLeftMargin = 0.0f;
146 float titledateMargin = 0.0f;
147 float dateHeight = 0.0f;
148 float monthYearMinWidth = 0.0f;
149 float dayElementWidth = 0.0f;
150 float dayElementMinWidth = 0.0f;
151 FloatRectangle bounds(0.0f, 0.0f, 0.0f, 0.0f);
153 GET_SHAPE_CONFIG(EDITDATE::HEIGHT, __pEditDate->GetOrientation(), editDateHeight);
154 GET_SHAPE_CONFIG(EDITDATE::TITLE_TEXT_LEFT_MARGIN, __pEditDate->GetOrientation(), titleLeftMargin);
155 GET_SHAPE_CONFIG(EDITDATE::ITEM_DIVIDER_HEIGHT, __pEditDate->GetOrientation(), __dividerLineHeight);
156 GET_SHAPE_CONFIG(EDITDATE::TEXT_FONT_SIZE, __pEditDate->GetOrientation(), __titleFontSize);
157 GET_SHAPE_CONFIG(EDITDATE::DATE_FONT_SIZE, __pEditDate->GetOrientation(), __dateFontSize);
158 GET_SHAPE_CONFIG(EDITDATE::TITLE_DATE_MARGIN, __pEditDate->GetOrientation(), titledateMargin);
159 GET_SHAPE_CONFIG(EDITDATE::DATE_HEIGHT, __pEditDate->GetOrientation(), dateHeight);
160 GET_SHAPE_CONFIG(EDITDATE::TITLE_HEIGHT, __pEditDate->GetOrientation(), __titleBounds.height);
161 GET_SHAPE_CONFIG(EDITDATE::MONTH_YEAR_ELEMENT_WIDTH, __pEditDate->GetOrientation(), __elementWidth);
162 GET_SHAPE_CONFIG(EDITDATE::DAY_ELEMENT_WIDTH, __pEditDate->GetOrientation(), dayElementWidth);
163 GET_SHAPE_CONFIG(EDITDATE::ELEMENT_MARGIN, __pEditDate->GetOrientation(), __elementMargin);
164 GET_SHAPE_CONFIG(EDITDATE::DATE_TEXT_LEFT_MARGIN, __pEditDate->GetOrientation(), dateLeftMargin);
166 GET_SHAPE_CONFIG(EDITDATE::MONTH_YEAR_ELEMENT_MIN_WIDTH, __pEditDate->GetOrientation(), monthYearMinWidth);
167 GET_SHAPE_CONFIG(EDITDATE::DAY_ELEMENT_MIN_WIDTH, __pEditDate->GetOrientation(), dayElementMinWidth);
169 if (__pEditDate->GetBoundsF().height > editDateHeight)
171 editDateHeight = __pEditDate->GetBoundsF().height;
174 __pFont = __pEditDate->GetFallbackFont();
176 SysTryReturn(NID_UI_CTRL, __pFont != null, r, r, "[%s] Propagating.", GetErrorMessage(r));
178 if (__title.IsEmpty() == false)
180 __titleBounds.x = titleLeftMargin;
181 __titleBounds.y = (editDateHeight - (__titleBounds.height + titledateMargin + dateHeight)) / 2.0f;
182 __titleBounds.width = __pEditDate->GetBoundsF().width - __titleBounds.x;
184 bounds.y = __titleBounds.y + __titleBounds.height + titledateMargin;
186 if (!__isEditDateInitialized)
188 r = InitializeTitleObject();
189 SysTryReturn(NID_UI_CTRL, (r == E_SUCCESS), r, r, "[%s] Propagating.", GetErrorMessage(r));
192 __titleObject.SetBounds(__titleBounds);
196 bounds.y = (editDateHeight - dateHeight) / 2.0f;
200 dayElementWidth = GetElementWidth(dayElementMinWidth, dayElementWidth);
201 __elementWidth = GetElementWidth(monthYearMinWidth, __elementWidth);
203 __dayBounds.height = dateHeight;
204 __monthBounds.height = dateHeight;
205 __yearBounds.height = dateHeight;
207 __dayBounds.width = dayElementWidth;
208 __monthBounds.width = __elementWidth;
209 __yearBounds.width = __elementWidth;
211 __dayBounds.x = dateLeftMargin;
212 __monthBounds.x = dateLeftMargin;
213 __yearBounds.x = dateLeftMargin;
215 __dayBounds.y = bounds.y;
216 __monthBounds.y = bounds.y;
217 __yearBounds.y = bounds.y;
219 if (!__isEditDateInitialized)
222 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
224 r = InitializeTextObject();
225 SysTryReturn(NID_UI_CTRL, (r == E_SUCCESS), r, r, "[%s] Propagating.", GetErrorMessage(r));
228 __isEditDateInitialized = true;
230 CalculateAreaBounds();
236 _EditDatePresenter::InitializeTitleObject(void)
238 result r = E_SUCCESS;
240 Color titleNormalColor;
242 GET_COLOR_CONFIG(EDITDATE::TITLE_TEXT_NORMAL, titleNormalColor);
244 r = __titleObject.Construct();
245 SysTryReturn(NID_UI_CTRL, (r == E_SUCCESS), r, r, "[%s] Propagating.", GetErrorMessage(r));
247 TextSimple* pSimpleText = null;
249 pSimpleText = new (std::nothrow)TextSimple((const_cast <wchar_t*>(__title.GetPointer())), __title.GetLength(), TEXT_ELEMENT_SOURCE_TYPE_EXTERNAL);
250 SysTryReturn(NID_UI_CTRL, (pSimpleText != null), E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
252 __titleObject.AppendElement(*pSimpleText);
254 __titleObject.SetForegroundColor(titleNormalColor, 0, __titleObject.GetTextLength());
255 __titleObject.SetFont(__pFont, 0, __titleObject.GetTextLength());
256 __titleObject.SetAlignment(TEXT_OBJECT_ALIGNMENT_LEFT | TEXT_OBJECT_ALIGNMENT_MIDDLE);
257 __titleObject.SetWrap(TEXT_OBJECT_WRAP_TYPE_NONE);
258 __titleObject.SetAction(TEXT_OBJECT_ACTION_TYPE_ABBREV);
259 __titleObject.SetTextObjectEllipsisType(TEXT_OBJECT_ELLIPSIS_TYPE_TAIL);
265 _EditDatePresenter::InitializeTextObject(void)
267 result r = E_SUCCESS;
269 r = __textObject.Construct();
270 SysTryReturn(NID_UI_CTRL, (r == E_SUCCESS), r, r, "[%s] Propagating.", GetErrorMessage(r));
272 TextSimple* pSimpleText = null;
274 pSimpleText = new (std::nothrow)TextSimple(null, 0, TEXT_ELEMENT_SOURCE_TYPE_EXTERNAL);
275 SysTryReturn(NID_UI_CTRL, (pSimpleText != null), E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
277 __textObject.AppendElement(*pSimpleText);
279 __textObject.SetFont(__pFont, 0, __textObject.GetTextLength());
280 __textObject.SetAlignment(TEXT_OBJECT_ALIGNMENT_CENTER | TEXT_OBJECT_ALIGNMENT_MIDDLE);
281 __textObject.SetWrap(TEXT_OBJECT_WRAP_TYPE_NONE);
282 __textObject.SetAction(TEXT_OBJECT_ACTION_TYPE_ABBREV);
288 _EditDatePresenter::GetElementWidth(const float minWidth, const float maxWidth) const
290 FloatRectangle bounds;
291 FloatDimension minSize;
292 bounds = __pEditDate->GetBoundsF();
294 float elementWidth = 0.0f;
295 float editDateWidth = 0.0f;
297 GET_SHAPE_CONFIG(EDITDATE::WIDTH, __pEditDate->GetOrientation(), editDateWidth);
298 GET_DIMENSION_CONFIG(EDITDATE::MIN_SIZE, __pEditDate->GetOrientation(), minSize);
300 if (bounds.width >= editDateWidth)
305 if (bounds.width <= minSize.width)
307 elementWidth = minWidth;
309 else if (bounds.width < editDateWidth && bounds.width > minSize.width)
311 elementWidth = maxWidth -
312 ((maxWidth - minWidth) / (editDateWidth - minSize.width)) * (editDateWidth - bounds.width);
319 _EditDatePresenter::LoadResource(void)
321 result r = E_SUCCESS;
323 Color contentNormalBgColor;
324 Color contentDisabledBgColor;
325 Color contentPressedColor;
326 Color contentHighlightedColor;
328 Bitmap* pTempBitmap = null;
330 GET_COLOR_CONFIG(EDITDATE::CONTENT_BG_NORMAL, contentNormalBgColor);
331 GET_COLOR_CONFIG(EDITDATE::CONTENT_BG_DISABLED, contentDisabledBgColor);
332 GET_COLOR_CONFIG(EDITDATE::CONTENT_BG_PRESSED, contentPressedColor);
333 GET_COLOR_CONFIG(EDITDATE::CONTENT_BG_HIGHLIGHTED, contentHighlightedColor);
335 r = GET_BITMAP_CONFIG_N(EDITDATE::CONTENT_BG_NORMAL, BITMAP_PIXEL_FORMAT_ARGB8888, pTempBitmap);
336 SysTryCatch(NID_UI_CTRL, (r == E_SUCCESS), , r, "[%s] Propagating.", GetErrorMessage(r));
338 __pContentBgNormalColorReplacementBitmap = _BitmapImpl::GetColorReplacedBitmapN(*pTempBitmap, Color::GetColor(COLOR_ID_MAGENTA), contentNormalBgColor);
339 SysTryCatch(NID_UI_CTRL, (__pContentBgNormalColorReplacementBitmap != null), r = GetLastResult(), GetLastResult(),
340 "[%s] Propagating.", GetErrorMessage(GetLastResult()));
345 r = GET_BITMAP_CONFIG_N(EDITDATE::CONTENT_BG_PRESSED, BITMAP_PIXEL_FORMAT_ARGB8888, pTempBitmap);
346 SysTryCatch(NID_UI_CTRL, (r == E_SUCCESS), , r, "[%s] Propagating.", GetErrorMessage(r));
348 __pContentBgPressedColorReplacementBitmap = _BitmapImpl::GetColorReplacedBitmapN(*pTempBitmap, Color::GetColor(COLOR_ID_MAGENTA), contentPressedColor);
349 SysTryCatch(NID_UI_CTRL, (__pContentBgPressedColorReplacementBitmap != null), r = GetLastResult(), GetLastResult(),
350 "[%s] Propagating.", GetErrorMessage(GetLastResult()));
355 r = GET_BITMAP_CONFIG_N(EDITDATE::CONTENT_BG_DISABLED, BITMAP_PIXEL_FORMAT_ARGB8888, pTempBitmap);
356 SysTryCatch(NID_UI_CTRL, (r == E_SUCCESS), , r, "[%s] Propagating.", GetErrorMessage(r));
358 __pContentBgDisabledColorReplacementBitmap = _BitmapImpl::GetColorReplacedBitmapN(*pTempBitmap, Color::GetColor(COLOR_ID_MAGENTA), contentDisabledBgColor);
359 SysTryCatch(NID_UI_CTRL, (__pContentBgDisabledColorReplacementBitmap != null), r = GetLastResult(), GetLastResult(),
360 "[%s] Propagating.", GetErrorMessage(GetLastResult()));
365 r = GET_BITMAP_CONFIG_N(EDITDATE::CONTENT_BG_HIGHLIGHTED, BITMAP_PIXEL_FORMAT_ARGB8888, pTempBitmap);
366 SysTryCatch(NID_UI_CTRL, (r == E_SUCCESS), , r, "[%s] Propagating.", GetErrorMessage(r));
368 __pContentBgHighlightedColorReplacementBitmap = _BitmapImpl::GetColorReplacedBitmapN(*pTempBitmap, Color::GetColor(COLOR_ID_MAGENTA), contentHighlightedColor);
369 SysTryCatch(NID_UI_CTRL, (__pContentBgHighlightedColorReplacementBitmap != null), r = GetLastResult(), GetLastResult(),
370 "[%s] Propagating.", GetErrorMessage(GetLastResult()));
372 r = GET_BITMAP_CONFIG_N(EDITDATE::CONTENT_BG_EFFECT_NORMAL, BITMAP_PIXEL_FORMAT_ARGB8888, __pContentBgEffectNormalBitmap);
373 SysTryCatch(NID_UI_CTRL, (r == E_SUCCESS), , r, "[%s] Propagating.", GetErrorMessage(r));
375 r = GET_BITMAP_CONFIG_N(EDITDATE::CONTENT_BG_EFFECT_PRESSED, BITMAP_PIXEL_FORMAT_ARGB8888, __pContentBgEffectPressedBitmap);
376 SysTryCatch(NID_UI_CTRL, (r == E_SUCCESS), , r, "[%s] Propagating.", GetErrorMessage(r));
378 r = GET_BITMAP_CONFIG_N(EDITDATE::CONTENT_BG_EFFECT_DISABLED, BITMAP_PIXEL_FORMAT_ARGB8888, __pContentBgEffectDisabledBitmap);
379 SysTryCatch(NID_UI_CTRL, (r == E_SUCCESS), , r, "[%s] Propagating.", GetErrorMessage(r));
391 delete __pContentBgNormalColorReplacementBitmap;
392 __pContentBgNormalColorReplacementBitmap = null;
394 delete __pContentBgPressedColorReplacementBitmap;
395 __pContentBgPressedColorReplacementBitmap = null;
397 delete __pContentBgDisabledColorReplacementBitmap;
398 __pContentBgDisabledColorReplacementBitmap = null;
400 delete __pContentBgHighlightedColorReplacementBitmap;
401 __pContentBgHighlightedColorReplacementBitmap = null;
403 delete __pContentBgEffectNormalBitmap;
404 __pContentBgEffectNormalBitmap = null;
406 delete __pContentBgEffectPressedBitmap;
407 __pContentBgEffectPressedBitmap = null;
409 delete __pContentBgEffectDisabledBitmap;
410 __pContentBgEffectDisabledBitmap = null;
416 _EditDatePresenter::GetLocaleDateFormat(void) const
418 int localeDateFormat = -1;
419 int error = vconf_get_int(VCONFKEY_SETAPPL_DATE_FORMAT_INT, &localeDateFormat);
422 localeDateFormat = SETTING_DATE_FORMAT_DD_MM_YYYY;
425 return localeDateFormat;
429 _EditDatePresenter::GetDate(void) const
431 SysAssertf((__pEditDateTimeModel != null), "The _EditDateTimeModel instance is null.");
434 date.SetValue(GetYear(), GetMonth(), GetDay(), DATETIME_HOUR_MIN, DATETIME_MINUTE_MIN);
440 _EditDatePresenter::GetDay(void) const
442 SysAssertf((__pEditDateTimeModel != null), "The _EditDateTimeModel instance is null.");
444 return __pEditDateTimeModel->GetDay();
448 _EditDatePresenter::GetMonth(void) const
450 SysAssertf((__pEditDateTimeModel != null), "The _EditDateTimeModel instance is null.");
452 return __pEditDateTimeModel->GetMonth();
456 _EditDatePresenter::GetYear(void) const
458 SysAssertf((__pEditDateTimeModel != null), "The _EditDateTimeModel instance is null.");
460 return __pEditDateTimeModel->GetYear();
464 _EditDatePresenter::SetDate(const DateTime& date)
466 SysAssertf((__pEditDateTimeModel != null), "The _EditDateTimeModel instance is null.");
468 __pEditDateTimeModel->SetDateTime(date);
473 _EditDatePresenter::SetCurrentDate(void)
475 SysAssertf((__pEditDateTimeModel != null), "The _EditDateTimeModel instance is null.");
477 __pEditDateTimeModel->SetCurrentDateTime();
482 _EditDatePresenter::SetYear(int year)
484 SysAssertf((__pEditDateTimeModel != null), "The _EditDateTimeModel instance is null.");
486 return __pEditDateTimeModel->SetYear(year);
490 _EditDatePresenter::SetMonth(int month)
492 SysAssertf((__pEditDateTimeModel != null), "The _EditDateTimeModel instance is null.");
494 return __pEditDateTimeModel->SetMonth(month);
498 _EditDatePresenter::SetDay(int day)
500 SysAssertf((__pEditDateTimeModel != null), "The _EditDateTimeModel instance is null.");
502 return __pEditDateTimeModel->SetDay(day);
506 _EditDatePresenter::SetDatePickerEnabled(bool enable)
508 __datePickerEnabled = enable;
513 _EditDatePresenter::IsDatePickerEnabled(void) const
515 return __datePickerEnabled;
519 _EditDatePresenter::SetMinYear(int minYear)
521 return __pEditDateTimeModel->SetMinYear(minYear);
525 _EditDatePresenter::SetMaxYear(int maxYear)
527 return __pEditDateTimeModel->SetMaxYear(maxYear);
531 _EditDatePresenter::GetMinYear(void) const
536 __pEditDateTimeModel->GetYearRange(minYear, maxYear);
542 _EditDatePresenter::GetMaxYear(void) const
547 __pEditDateTimeModel->GetYearRange(minYear, maxYear);
553 _EditDatePresenter::Draw(void)
555 result r = E_SUCCESS;
562 Canvas* pCanvas = __pEditDate->GetCanvasN();
563 SysAssertf((pCanvas != null), "Failed to get canvas.");
565 pCanvas->SetBackgroundColor(Color(0, 0, 0, 0));
568 if (__title.IsEmpty() == false)
577 _DateTimeUtils dateTimeUtils;
578 monthString = dateTimeUtils.GetMonthString(GetMonth());
579 yearString.Format(10, L"%04d", GetYear());
580 dayString.Format(10, L"%02d", GetDay());
582 CalculateAreaBounds();
584 r = DrawText(*pCanvas, GetDateAreaBounds(DATETIME_ID_DAY), dayString, DATETIME_ID_DAY);
585 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
586 r = DrawText(*pCanvas, GetDateAreaBounds(DATETIME_ID_MONTH), monthString, DATETIME_ID_MONTH);
587 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
588 r = DrawText(*pCanvas, GetDateAreaBounds(DATETIME_ID_YEAR), yearString, DATETIME_ID_YEAR);
589 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
601 _EditDatePresenter::CalculateAreaBounds(void)
603 result r = E_SUCCESS;
605 if (GetLocaleDateFormat() == DATE_FORMAT_DDMMYYYY)
607 __monthBounds.x = __dayBounds.x + __dayBounds.width + __elementMargin;
608 __yearBounds.x = __monthBounds.x + __monthBounds.width + __elementMargin;
610 else if (GetLocaleDateFormat() == DATE_FORMAT_MMDDYYYY)
612 __dayBounds.x = __monthBounds.x + __monthBounds.width + __elementMargin;
613 __yearBounds.x = __dayBounds.x + __dayBounds.width + __elementMargin;
615 else if (GetLocaleDateFormat() == DATE_FORMAT_YYYYMMDD)
617 __monthBounds.x = __yearBounds.x + __yearBounds.width + __elementMargin;
618 __dayBounds.x = __monthBounds.x + __monthBounds.width + __elementMargin;
620 else if (GetLocaleDateFormat() == DATE_FORMAT_YYYYDDMM)
622 __dayBounds.x = __yearBounds.x + __yearBounds.width + __elementMargin;
623 __monthBounds.x = __dayBounds.x + __dayBounds.width + __elementMargin;
630 _EditDatePresenter::DrawTitle(Canvas& canvas)
632 if (!__pEditDate->IsEnabled())
634 Color titleDisabledColor;
635 GET_COLOR_CONFIG(EDITDATE::TITLE_TEXT_DISABLED, titleDisabledColor);
636 __titleObject.SetForegroundColor(titleDisabledColor, 0, __titleObject.GetTextLength());
639 (_FontImpl::GetInstance(*__pFont))->SetSize(__titleFontSize);
640 (_FontImpl::GetInstance(*__pFont))->SetStyle(FONT_STYLE_BOLD);
641 __titleObject.SetFont(__pFont, 0, __titleObject.GetTextLength());
642 __titleObject.Draw(*_CanvasImpl::GetInstance(canvas));
648 _EditDatePresenter::DrawText(Canvas& canvas, const FloatRectangle& bounds, const String& text, _DateTimeId boxId)
652 if (!__pEditDate->IsEnabled())
654 GET_COLOR_CONFIG(EDITDATE::TEXT_DISABLED, textColor);
658 GET_COLOR_CONFIG(EDITDATE::TEXT_NORMAL, textColor);
661 (_FontImpl::GetInstance(*__pFont))->SetStyle(FONT_STYLE_PLAIN);
663 if (boxId == GetLastSelectedId() && boxId != DATETIME_ID_NONE)
665 (_FontImpl::GetInstance(*__pFont))->SetStyle(FONT_STYLE_BOLD);
666 GET_COLOR_CONFIG(EDITDATE::TEXT_PRESSED, textColor);
669 DrawContentBitmap(canvas, bounds, boxId);
671 FloatRectangle drawAreaBounds(0.0f, 0.0f, 0.0f, 0.0f);
672 drawAreaBounds = bounds;
674 TextSimple* pSimpleText = null;
675 pSimpleText = new (std::nothrow)TextSimple((const_cast <wchar_t*>(text.GetPointer())), text.GetLength(), TEXT_ELEMENT_SOURCE_TYPE_EXTERNAL);
676 SysTryReturn(NID_UI_CTRL, (pSimpleText != null), E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
678 __textObject.RemoveAll();
680 (_FontImpl::GetInstance(*__pFont))->SetSize(__dateFontSize);
681 __textObject.AppendElement(*pSimpleText);
683 __textObject.SetFont(__pFont, 0, __textObject.GetTextLength());
684 __textObject.SetForegroundColor(textColor, 0, __textObject.GetTextLength());
685 __textObject.SetBounds(drawAreaBounds);
686 __textObject.Draw(*_CanvasImpl::GetInstance(canvas));
692 _EditDatePresenter::DrawContentBitmap(Canvas& canvas, const FloatRectangle& bounds, _DateTimeId boxId)
694 result r = E_SUCCESS;
696 bool isCustomBitmap = false;
697 Bitmap* pReplacementBitmap = null;
698 Bitmap* pEffectBitmap = null;
700 if (!__pEditDate->IsEnabled())
702 isCustomBitmap = IS_CUSTOM_BITMAP(EDITTIME::CONTENT_BG_DISABLED);
703 pReplacementBitmap = __pContentBgDisabledColorReplacementBitmap;
704 pEffectBitmap = __pContentBgEffectDisabledBitmap;
706 else if (GetLastSelectedId() != boxId)
708 isCustomBitmap = IS_CUSTOM_BITMAP(EDITTIME::CONTENT_BG_NORMAL);
709 pReplacementBitmap = __pContentBgNormalColorReplacementBitmap;
710 pEffectBitmap = __pContentBgEffectNormalBitmap;
714 isCustomBitmap = IS_CUSTOM_BITMAP(EDITTIME::CONTENT_BG_PRESSED);
715 pReplacementBitmap = __pContentBgPressedColorReplacementBitmap;
716 pEffectBitmap = __pContentBgEffectPressedBitmap;
719 r = DrawResourceBitmap(canvas, bounds, pReplacementBitmap);
720 SysTryReturn(NID_UI_CTRL, (r == E_SUCCESS), r, r, "[%s] Propagating.", GetErrorMessage(r));
724 r = DrawResourceBitmap(canvas, bounds, pEffectBitmap);
725 SysTryReturn(NID_UI_CTRL, (r == E_SUCCESS), r, r, "[%s] Propagating.", GetErrorMessage(r));
732 _EditDatePresenter::DrawResourceBitmap(Canvas& canvas, const FloatRectangle& bounds, Bitmap* pBitmap)
734 result r = E_SUCCESS;
741 if (_BitmapImpl::CheckNinePatchedBitmapStrictly(*pBitmap))
743 r = canvas.DrawNinePatchedBitmap(bounds, *pBitmap);
744 SysTryReturn(NID_UI_CTRL, (r == E_SUCCESS), r, r, "[%s] Propagating.", GetErrorMessage(r));
748 r = canvas.DrawBitmap(bounds, *pBitmap);
749 SysTryReturn(NID_UI_CTRL, (r == E_SUCCESS), r, r, "[%s] Propagating.", GetErrorMessage(r));
756 _EditDatePresenter::GetBoxIdFromPosition(const FloatPoint& point) const
758 _DateTimeId displayBoxId = DATETIME_ID_NONE;
760 if (point.y < __dayBounds.y || point.y > __dayBounds.y + __dayBounds.height)
765 if (__dayBounds.Contains(point) == true)
767 displayBoxId = DATETIME_ID_DAY;
769 else if (__monthBounds.Contains(point) == true)
771 displayBoxId = DATETIME_ID_MONTH;
773 else if (__yearBounds.Contains(point) == true)
775 displayBoxId = DATETIME_ID_YEAR;
782 _EditDatePresenter::GetDateAreaBounds(_DateTimeId id) const
784 if (id == DATETIME_ID_DAY)
788 else if (id == DATETIME_ID_MONTH)
790 return __monthBounds;
792 else if (id == DATETIME_ID_YEAR)
798 return FloatRectangle();
803 _EditDatePresenter::GetTitleBounds(void) const
805 return __titleBounds;
809 _EditDatePresenter::SetLastSelectedId(_DateTimeId boxId)
811 __lastSelectedId = boxId;
816 _EditDatePresenter::GetLastSelectedId(void) const
818 return __lastSelectedId;
822 _EditDatePresenter::OnFontChanged(Font* pFont)
826 if (__pEditDate->GetDateTimeBar() != null)
828 __pEditDate->GetDateTimeBar()->SetFont(*pFont);
835 _EditDatePresenter::OnFontInfoRequested(unsigned long& style, float& size)
837 style = FONT_STYLE_PLAIN;
838 size = __dateFontSize;
844 _EditDatePresenter::OnTouchPressed(const _Control& source, const _TouchInfo& touchinfo)
846 SysTryReturn(NID_UI_CTRL, IsDatePickerEnabled() == true, true, E_SYSTEM,
847 "[E_SYSTEM] A system error has occurred. EditDate instance is disabled.");
849 if (&source != __pEditDate)
854 __touchMoveHandled = false;
856 FloatPoint point = touchinfo.GetCurrentPosition();
858 _DateTimeId boxId = DATETIME_ID_NONE;
859 boxId = GetBoxIdFromPosition(point);
861 if (boxId < DATETIME_ID_YEAR || boxId > DATETIME_ID_DAY)
863 __selectedId = DATETIME_ID_NONE;
869 int displayValue = -1;
871 if (boxId == DATETIME_ID_DAY)
873 if (__pEditDate->GetDateTimeBar() != null)
875 _DateTimeUtils dateTimeUtils;
876 maxValue = dateTimeUtils.CalculateMaxDay(GetYear(), GetMonth());
877 minValue = DATETIME_DAY_MIN;
878 displayValue = GetDay();
881 else if (boxId == DATETIME_ID_MONTH)
883 minValue = DATETIME_MONTH_MIN;
884 maxValue = DATETIME_MONTH_MAX;
885 displayValue = GetMonth();
887 else if (boxId == DATETIME_ID_YEAR)
889 minValue = GetMinYear();
890 maxValue = GetMaxYear();
891 displayValue = GetYear();
894 if (__pEditDate->GetDateTimeBar() != null)
896 if (__pEditDate->GetDateTimeBar()->GetItemCount() > 0)
898 __pEditDate->GetDateTimeBar()->RemoveAllItems();
901 result r = __pEditDate->GetDateTimeBar()->SetInitialValue(minValue, maxValue, displayValue, boxId);
904 __selectedId = DATETIME_ID_NONE;
909 __selectedId = boxId;
915 _EditDatePresenter::OnTouchReleased(const _Control& source, const _TouchInfo& touchinfo)
917 SysTryReturn(NID_UI_CTRL, IsDatePickerEnabled() == true, true, E_SYSTEM,
918 "[E_SYSTEM] A system error has occurred. EditDate instance is disabled.");
920 if (&source != __pEditDate)
925 FloatPoint point = touchinfo.GetCurrentPosition();
927 _DateTimeId boxId = DATETIME_ID_NONE;
928 boxId = GetBoxIdFromPosition(point);
930 if (boxId == GetLastSelectedId() || boxId != __selectedId || boxId == DATETIME_ID_NONE)
932 if (__pEditDate->GetDateTimeBar() != null && __pEditDate->GetDateTimeBar()->IsActivated())
934 __pEditDate->GetDateTimeBar()->SetVisibleState(false);
935 __pEditDate->GetDateTimeBar()->Close();
938 __selectedId = DATETIME_ID_NONE;
939 SetLastSelectedId(__selectedId);
946 SetLastSelectedId(__selectedId);
948 __lastSelectedValue = "";
949 _DateTimeUtils dateTimeUtils;
950 if (GetLastSelectedId() == DATETIME_ID_YEAR)
952 __lastSelectedValue.Format(10, L"%04d", GetYear());
953 PLAY_FEEDBACK(_RESOURCE_FEEDBACK_PATTERN_TAP);
955 else if (GetLastSelectedId() == DATETIME_ID_MONTH)
957 __lastSelectedValue = dateTimeUtils.GetMonthString(GetMonth());
958 PLAY_FEEDBACK(_RESOURCE_FEEDBACK_PATTERN_TAP);
960 else if (GetLastSelectedId() == DATETIME_ID_DAY)
962 __lastSelectedValue.Format(10, L"%02d", GetDay());
963 PLAY_FEEDBACK(_RESOURCE_FEEDBACK_PATTERN_TAP);
968 if ((__pEditDate->GetDateTimeBar() != null) && (GetLastSelectedId() != DATETIME_ID_NONE))
970 FloatRectangle bounds(0.0f, 0.0f, 0.0f, 0.0f);
971 bounds = GetDateAreaBounds(GetLastSelectedId());
972 FloatRectangle absoluteBounds(0.0f, 0.0f, 0.0f, 0.0f);
973 absoluteBounds = __pEditDate->GetAbsoluteBoundsF();
974 bounds.x += absoluteBounds.x;
976 __pEditDate->GetDateTimeBar()->CalculateArrowBounds(bounds);
978 if (__pEditDate->GetDateTimeBar()->IsActivated())
980 __pEditDate->GetDateTimeBar()->RefreshItems();
984 __pEditDate->GetDateTimeBar()->SetVisibleState(true);
985 __pEditDate->GetDateTimeBar()->Open();
989 __selectedId = DATETIME_ID_NONE;
994 _EditDatePresenter::OnTouchCanceled(const _Control& source, const _TouchInfo& touchinfo)
996 if (&source != __pEditDate)
1001 __selectedId = DATETIME_ID_NONE;
1007 _EditDatePresenter::OnTouchMoved(const _Control& source, const _TouchInfo& touchinfo)
1009 if (&source != __pEditDate)
1014 if (__pEditDate->GetDateTimeBar() != null && __pEditDate->GetDateTimeBar()->IsActivated())
1023 _EditDatePresenter::OnTouchMoveHandled(const _Control& control)
1025 __touchMoveHandled = true;
1026 __selectedId = DATETIME_ID_NONE;
1032 _EditDatePresenter::Animate(void)
1034 SysAssertf((__pFont != null), "Font instance must not be null.");
1036 (_FontImpl::GetInstance(*__pFont))->SetSize(__dateFontSize);
1038 result r = E_SUCCESS;
1039 FloatRectangle rect;
1045 _DateTimeUtils dateTimeUtils;
1046 monthString = dateTimeUtils.GetMonthString(GetMonth());
1047 yearString.Format(10, L"%04d", GetYear());
1048 dayString.Format(10, L"%02d", GetDay());
1050 if (GetLastSelectedId() == DATETIME_ID_DAY)
1052 SysTryReturnVoidResult(NID_UI_CTRL, (__lastSelectedValue.Equals(dayString) == false), E_SUCCESS, "Day string matched.");
1054 newValue = dayString;
1055 rect = GetDateAreaBounds(DATETIME_ID_DAY);
1057 else if (GetLastSelectedId() == DATETIME_ID_MONTH)
1059 SysTryReturnVoidResult(NID_UI_CTRL, (__lastSelectedValue.Equals(monthString) == false), E_SUCCESS, "Month string matched.");
1061 newValue = monthString;
1062 rect = GetDateAreaBounds(DATETIME_ID_MONTH);
1064 else if (GetLastSelectedId() == DATETIME_ID_YEAR)
1066 SysTryReturnVoidResult(NID_UI_CTRL, (__lastSelectedValue.Equals(yearString) == false), E_SUCCESS, "Year string matched.");
1068 newValue = yearString;
1069 rect = GetDateAreaBounds(DATETIME_ID_YEAR);
1072 FloatDimension newTextDim;
1073 FloatDimension oldTextDim;
1074 FloatPoint textPoint;
1075 VisualElement* pNewVisualElement = null;
1076 VisualElement* pOldVisualElement = null;
1077 VisualElement* pEditDateElement = null;
1078 VisualElementPropertyAnimation* pNewBoundsAnimation = null;
1079 VisualElementPropertyAnimation* pOldBoundsAnimation = null;
1080 Canvas *pCanvas = null;
1081 Color contentBgColor;
1082 Color textPressedColor;
1084 GET_COLOR_CONFIG(EDITTIME::CONTENT_BG_PRESSED, contentBgColor);
1085 GET_COLOR_CONFIG(EDITTIME::TEXT_PRESSED, textPressedColor);
1087 __pFont->GetTextExtent(newValue, newValue.GetLength(), newTextDim);
1088 __pFont->GetTextExtent(__lastSelectedValue, __lastSelectedValue.GetLength(), oldTextDim);
1090 if (newTextDim.width > oldTextDim.width)
1092 textPoint.x = (rect.width - newTextDim.width) / 2.0f;
1096 textPoint.x = (rect.width - oldTextDim.width) / 2.0f;
1099 SysTryReturnVoidResult(NID_UI_CTRL, (rect.x + textPoint.x < __pEditDate->GetBoundsF().width), E_SUCCESS, "Rolling animation cann't be played.");
1101 __isAnimating = true;
1103 __pContentProvider = new (std::nothrow) VisualElement();
1104 SysTryReturnVoidResult(NID_UI_CTRL, (__pContentProvider != null), E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
1106 r = __pContentProvider->Construct();
1107 SysTryCatch(NID_UI_CTRL, (r == E_SUCCESS), , r, "[%s] Propagating.", GetErrorMessage(r));
1109 __pContentProvider->SetShowState(true);
1110 __pContentProvider->SetClipChildrenEnabled(true);
1111 __pContentProvider->SetImplicitAnimationEnabled(false);
1113 pEditDateElement = __pEditDate->GetVisualElement();
1114 r = GetLastResult();
1115 SysTryCatch(NID_UI_CTRL, (pEditDateElement != null), , r, "[%s] Propagating.", GetErrorMessage(r));
1117 pNewVisualElement = new (std::nothrow) VisualElement();
1118 SysTryCatch(NID_UI_CTRL, (pNewVisualElement != null), , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
1120 r = pNewVisualElement->Construct();
1123 pNewVisualElement->Destroy();
1125 SysTryCatch(NID_UI_CTRL, (r == E_SUCCESS), , r, "[%s] Propagating.", GetErrorMessage(r));
1127 pOldVisualElement = new (std::nothrow) VisualElement();
1128 if (pOldVisualElement == null)
1130 pNewVisualElement->Destroy();
1132 SysTryCatch(NID_UI_CTRL, (pOldVisualElement != null), , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
1134 r = pOldVisualElement->Construct();
1137 pNewVisualElement->Destroy();
1138 pOldVisualElement->Destroy();
1140 SysTryCatch(NID_UI_CTRL, (r == E_SUCCESS), , r, "[%s] Propagating.", GetErrorMessage(r));
1142 pNewVisualElement->SetShowState(true);
1143 pOldVisualElement->SetShowState(true);
1145 if (newTextDim.width > oldTextDim.width)
1147 textPoint.x = (rect.width - newTextDim.width) / 2.0f;
1148 textPoint.y = (rect.height - newTextDim.height) / 2.0f;
1149 __pContentProvider->SetBounds(FloatRectangle((rect.x + textPoint.x) * 1.0f, (rect.y + textPoint.y) * 1.0f, newTextDim.width * 1.0f, newTextDim.height * 1.0f));
1150 pNewVisualElement->SetBounds(FloatRectangle(0.0f, newTextDim.height * 1.0f, newTextDim.width * 1.0f, newTextDim.height * 1.0f));
1152 rect.x = static_cast<int>(__pContentProvider->GetBounds().x);
1153 rect.y = static_cast<int>(__pContentProvider->GetBounds().y);
1154 rect.width = static_cast<int>(__pContentProvider->GetBounds().width);
1155 rect.height = static_cast<int>(__pContentProvider->GetBounds().height);
1157 textPoint.x = (rect.width - oldTextDim.width) / 2.0f;
1158 textPoint.y = (rect.height - oldTextDim.height) / 2.0f;
1160 pOldVisualElement->SetBounds(FloatRectangle(textPoint.x * 1.0f, 0.0f, oldTextDim.width * 1.0f, oldTextDim.height * 1.0f));
1164 textPoint.x = (rect.width - oldTextDim.width) / 2.0f;
1165 textPoint.y = (rect.height - oldTextDim.height) / 2.0f;
1166 __pContentProvider->SetBounds(FloatRectangle((rect.x + textPoint.x) * 1.0f, (rect.y + textPoint.y) * 1.0f, oldTextDim.width * 1.0f, oldTextDim.height * 1.0f));
1167 pOldVisualElement->SetBounds(FloatRectangle(0.0f, 0.0f, oldTextDim.width * 1.0f, oldTextDim.height * 1.0f));
1169 rect.x = static_cast<int>(__pContentProvider->GetBounds().x);
1170 rect.y = static_cast<int>(__pContentProvider->GetBounds().y);
1171 rect.width = static_cast<int>(__pContentProvider->GetBounds().width);
1172 rect.height = static_cast<int>(__pContentProvider->GetBounds().height);
1174 textPoint.x = (rect.width - newTextDim.width) / 2.0f;
1175 textPoint.y = (rect.height - newTextDim.height) / 2.0f;
1177 pNewVisualElement->SetBounds(FloatRectangle(textPoint.x * 1.0f, newTextDim.height * 1.0f, newTextDim.width * 1.0f, newTextDim.height * 1.0f));
1181 pCanvas = pEditDateElement->GetCanvasN(rect);
1182 pCanvas->SetBackgroundColor(contentBgColor);
1186 pEditDateElement->AttachChild(*__pContentProvider);
1188 __pContentProvider->AttachChild(*pOldVisualElement);
1189 __pContentProvider->AttachChild(*pNewVisualElement);
1191 pNewBoundsAnimation = new (std::nothrow) VisualElementPropertyAnimation();
1192 SysTryCatch(NID_UI_CTRL, (pNewBoundsAnimation != null), , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
1194 pNewBoundsAnimation->SetDuration(300);
1195 pNewBoundsAnimation->SetPropertyName("bounds.position");
1196 pNewBoundsAnimation->SetStartValue(Variant(FloatPoint(pNewVisualElement->GetBounds().x * 1.0f, newTextDim.height * 1.0f)));
1197 pNewBoundsAnimation->SetEndValue(Variant(FloatPoint(pNewVisualElement->GetBounds().x * 1.0f, 0.0f)));
1198 pNewBoundsAnimation->SetVisualElementAnimationStatusEventListener(this);
1200 pOldBoundsAnimation = new (std::nothrow) VisualElementPropertyAnimation();
1201 SysTryCatch(NID_UI_CTRL, (pOldBoundsAnimation != null), , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
1203 pOldBoundsAnimation->SetDuration(300);
1204 pOldBoundsAnimation->SetPropertyName("bounds.position");
1205 pOldBoundsAnimation->SetStartValue(Variant(FloatPoint(pOldVisualElement->GetBounds().x * 1.0f, 0.0f)));
1206 pOldBoundsAnimation->SetEndValue(Variant(FloatPoint(pOldVisualElement->GetBounds().x * 1.0f, oldTextDim.height * -1.0f)));
1207 pOldBoundsAnimation->SetVisualElementAnimationStatusEventListener(this);
1209 pCanvas = pOldVisualElement->GetCanvasN();
1210 r = GetLastResult();
1211 SysTryCatch(NID_UI_CTRL, (pCanvas != null), , r, "[%s] Propagating.", GetErrorMessage(r));
1213 pCanvas->SetBackgroundColor(Color(0, 0, 0, 0));
1215 pCanvas->SetForegroundColor(textPressedColor);
1216 (_FontImpl::GetInstance(*__pFont))->SetStyle(FONT_STYLE_BOLD);
1217 pCanvas->SetFont(*__pFont);
1218 pCanvas->DrawText(FloatPoint(0.0f, 0.0f), __lastSelectedValue);
1223 pCanvas = pNewVisualElement->GetCanvasN();
1224 r = GetLastResult();
1225 SysTryCatch(NID_UI_CTRL, (pCanvas != null), , r, "[%s] Propagating.", GetErrorMessage(r));
1227 pCanvas->SetBackgroundColor(Color(0, 0, 0, 0));
1229 pCanvas->SetForegroundColor(textPressedColor);
1230 (_FontImpl::GetInstance(*__pFont))->SetStyle(FONT_STYLE_BOLD);
1231 pCanvas->SetFont(*__pFont);
1232 pCanvas->DrawText(FloatPoint(0.0f, 0.0f), newValue);
1237 pOldVisualElement->SetImplicitAnimationEnabled(false);
1238 pOldVisualElement->AddAnimation(*pOldBoundsAnimation);
1240 pNewVisualElement->SetImplicitAnimationEnabled(false);
1241 pNewVisualElement->AddAnimation(*pNewBoundsAnimation);
1243 delete pOldBoundsAnimation;
1244 delete pNewBoundsAnimation;
1249 __isAnimating = false;
1250 __pContentProvider->Destroy();
1252 delete pNewBoundsAnimation;
1253 pNewBoundsAnimation = null;
1255 delete pOldBoundsAnimation;
1256 pOldBoundsAnimation = null;
1265 _EditDatePresenter::OnVisualElementAnimationFinished (const VisualElementAnimation &animation, const String &keyName, VisualElement &target, bool completedNormally)
1267 result r = E_SUCCESS;
1268 __isAnimating = false;
1270 VisualElement* pEditDateElement = __pEditDate->GetVisualElement();
1271 r = GetLastResult();
1272 SysTryReturnVoidResult(NID_UI_CTRL, (pEditDateElement != null), r, "[%s] Propagating.", GetErrorMessage(r));
1274 pEditDateElement->DetachChild(*__pContentProvider);
1275 __pContentProvider->Destroy();
1281 }}} // Tizen::Ui::Controls