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 editDateWidth = 0.0f;
145 float dateLeftMargin = 0.0f;
146 float titleLeftMargin = 0.0f;
147 float titledateMargin = 0.0f;
148 float dateHeight = 0.0f;
149 float monthYearMinWidth = 0.0f;
150 float dayElementWidth = 0.0f;
151 float dayElementMinWidth = 0.0f;
152 FloatRectangle bounds(0.0f, 0.0f, 0.0f, 0.0f);
154 GET_SHAPE_CONFIG(EDITDATE::WIDTH, __pEditDate->GetOrientation(), editDateWidth);
155 GET_SHAPE_CONFIG(EDITDATE::HEIGHT, __pEditDate->GetOrientation(), editDateHeight);
156 GET_SHAPE_CONFIG(EDITDATE::TITLE_TEXT_LEFT_MARGIN, __pEditDate->GetOrientation(), titleLeftMargin);
157 GET_SHAPE_CONFIG(EDITDATE::ITEM_DIVIDER_HEIGHT, __pEditDate->GetOrientation(), __dividerLineHeight);
158 GET_SHAPE_CONFIG(EDITDATE::TEXT_FONT_SIZE, __pEditDate->GetOrientation(), __titleFontSize);
159 GET_SHAPE_CONFIG(EDITDATE::DATE_FONT_SIZE, __pEditDate->GetOrientation(), __dateFontSize);
160 GET_SHAPE_CONFIG(EDITDATE::TITLE_DATE_MARGIN, __pEditDate->GetOrientation(), titledateMargin);
161 GET_SHAPE_CONFIG(EDITDATE::DATE_HEIGHT, __pEditDate->GetOrientation(), dateHeight);
162 GET_SHAPE_CONFIG(EDITDATE::TITLE_HEIGHT, __pEditDate->GetOrientation(), __titleBounds.height);
163 GET_SHAPE_CONFIG(EDITDATE::MONTH_YEAR_ELEMENT_WIDTH, __pEditDate->GetOrientation(), __elementWidth);
164 GET_SHAPE_CONFIG(EDITDATE::DAY_ELEMENT_WIDTH, __pEditDate->GetOrientation(), dayElementWidth);
165 GET_SHAPE_CONFIG(EDITDATE::ELEMENT_MARGIN, __pEditDate->GetOrientation(), __elementMargin);
166 GET_SHAPE_CONFIG(EDITDATE::DATE_TEXT_LEFT_MARGIN, __pEditDate->GetOrientation(), dateLeftMargin);
168 GET_SHAPE_CONFIG(EDITDATE::MONTH_YEAR_ELEMENT_MIN_WIDTH, __pEditDate->GetOrientation(), monthYearMinWidth);
169 GET_SHAPE_CONFIG(EDITDATE::DAY_ELEMENT_MIN_WIDTH, __pEditDate->GetOrientation(), dayElementMinWidth);
171 if (__pEditDate->GetBoundsF().height > editDateHeight)
173 editDateHeight = __pEditDate->GetBoundsF().height;
176 __pFont = __pEditDate->GetFallbackFont();
178 SysTryReturn(NID_UI_CTRL, __pFont != null, r, r, "[%s] Propagating.", GetErrorMessage(r));
180 if (__title.IsEmpty() == false)
182 __titleBounds.x = titleLeftMargin;
183 __titleBounds.y = (editDateHeight - (__titleBounds.height + titledateMargin + dateHeight)) / 2.0f;
184 __titleBounds.width = editDateWidth - __titleBounds.x;
186 bounds.y = __titleBounds.y + __titleBounds.height + titledateMargin;
188 if (!__isEditDateInitialized)
190 r = InitializeTitleObject();
191 SysTryReturn(NID_UI_CTRL, (r == E_SUCCESS), r, r, "[%s] Propagating.", GetErrorMessage(r));
194 __titleObject.SetBounds(__titleBounds);
198 bounds.y = (editDateHeight - dateHeight) / 2.0f;
202 dayElementWidth = GetElementWidth(dayElementMinWidth, dayElementWidth);
203 __elementWidth = GetElementWidth(monthYearMinWidth, __elementWidth);
205 __dayBounds.height = dateHeight;
206 __monthBounds.height = dateHeight;
207 __yearBounds.height = dateHeight;
209 __dayBounds.width = dayElementWidth;
210 __monthBounds.width = __elementWidth;
211 __yearBounds.width = __elementWidth;
213 __dayBounds.x = dateLeftMargin;
214 __monthBounds.x = dateLeftMargin;
215 __yearBounds.x = dateLeftMargin;
217 __dayBounds.y = bounds.y;
218 __monthBounds.y = bounds.y;
219 __yearBounds.y = bounds.y;
221 if (!__isEditDateInitialized)
224 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
226 r = InitializeTextObject();
227 SysTryReturn(NID_UI_CTRL, (r == E_SUCCESS), r, r, "[%s] Propagating.", GetErrorMessage(r));
230 __isEditDateInitialized = true;
232 CalculateAreaBounds();
238 _EditDatePresenter::InitializeTitleObject(void)
240 result r = E_SUCCESS;
242 Color titleNormalColor;
244 GET_COLOR_CONFIG(EDITDATE::TITLE_TEXT_NORMAL, titleNormalColor);
246 r = __titleObject.Construct();
247 SysTryReturn(NID_UI_CTRL, (r == E_SUCCESS), r, r, "[%s] Propagating.", GetErrorMessage(r));
249 TextSimple* pSimpleText = null;
251 pSimpleText = new (std::nothrow)TextSimple((const_cast <wchar_t*>(__title.GetPointer())), __title.GetLength(), TEXT_ELEMENT_SOURCE_TYPE_EXTERNAL);
252 SysTryReturn(NID_UI_CTRL, (pSimpleText != null), E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
254 __titleObject.AppendElement(*pSimpleText);
256 __titleObject.SetForegroundColor(titleNormalColor, 0, __titleObject.GetTextLength());
257 __titleObject.SetFont(__pFont, 0, __titleObject.GetTextLength());
258 __titleObject.SetAlignment(TEXT_OBJECT_ALIGNMENT_LEFT | TEXT_OBJECT_ALIGNMENT_MIDDLE);
259 __titleObject.SetWrap(TEXT_OBJECT_WRAP_TYPE_NONE);
260 __titleObject.SetAction(TEXT_OBJECT_ACTION_TYPE_ABBREV);
266 _EditDatePresenter::InitializeTextObject(void)
268 result r = E_SUCCESS;
270 r = __textObject.Construct();
271 SysTryReturn(NID_UI_CTRL, (r == E_SUCCESS), r, r, "[%s] Propagating.", GetErrorMessage(r));
273 TextSimple* pSimpleText = null;
275 pSimpleText = new (std::nothrow)TextSimple(null, 0, TEXT_ELEMENT_SOURCE_TYPE_EXTERNAL);
276 SysTryReturn(NID_UI_CTRL, (pSimpleText != null), E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
278 __textObject.AppendElement(*pSimpleText);
280 __textObject.SetFont(__pFont, 0, __textObject.GetTextLength());
281 __textObject.SetAlignment(TEXT_OBJECT_ALIGNMENT_CENTER | TEXT_OBJECT_ALIGNMENT_MIDDLE);
282 __textObject.SetWrap(TEXT_OBJECT_WRAP_TYPE_NONE);
283 __textObject.SetAction(TEXT_OBJECT_ACTION_TYPE_ABBREV);
289 _EditDatePresenter::GetElementWidth(const float minWidth, const float maxWidth) const
291 FloatRectangle bounds;
292 FloatDimension minSize;
293 bounds = __pEditDate->GetBoundsF();
295 float elementWidth = 0.0f;
296 float editDateWidth = 0.0f;
298 GET_SHAPE_CONFIG(EDITDATE::WIDTH, __pEditDate->GetOrientation(), editDateWidth);
299 GET_DIMENSION_CONFIG(EDITDATE::MIN_SIZE, __pEditDate->GetOrientation(), minSize);
301 if (bounds.width >= editDateWidth)
306 if (bounds.width <= minSize.width)
308 elementWidth = minWidth;
310 else if (bounds.width < editDateWidth && bounds.width > minSize.width)
312 elementWidth = maxWidth -
313 ((maxWidth - minWidth) / (editDateWidth - minSize.width)) * (editDateWidth - bounds.width);
320 _EditDatePresenter::LoadResource(void)
322 result r = E_SUCCESS;
324 Color contentNormalBgColor;
325 Color contentDisabledBgColor;
326 Color contentPressedColor;
327 Color contentHighlightedColor;
329 Bitmap* pTempBitmap = null;
331 GET_COLOR_CONFIG(EDITDATE::CONTENT_BG_NORMAL, contentNormalBgColor);
332 GET_COLOR_CONFIG(EDITDATE::CONTENT_BG_DISABLED, contentDisabledBgColor);
333 GET_COLOR_CONFIG(EDITDATE::CONTENT_BG_PRESSED, contentPressedColor);
334 GET_COLOR_CONFIG(EDITDATE::CONTENT_BG_HIGHLIGHTED, contentHighlightedColor);
336 r = GET_BITMAP_CONFIG_N(EDITDATE::CONTENT_BG_NORMAL, BITMAP_PIXEL_FORMAT_ARGB8888, pTempBitmap);
337 SysTryCatch(NID_UI_CTRL, (r == E_SUCCESS), , r, "[%s] Propagating.", GetErrorMessage(r));
339 __pContentBgNormalColorReplacementBitmap = _BitmapImpl::GetColorReplacedBitmapN(*pTempBitmap, Color::GetColor(COLOR_ID_MAGENTA), contentNormalBgColor);
340 SysTryCatch(NID_UI_CTRL, (__pContentBgNormalColorReplacementBitmap != null), r = GetLastResult(), GetLastResult(),
341 "[%s] Propagating.", GetErrorMessage(GetLastResult()));
346 r = GET_BITMAP_CONFIG_N(EDITDATE::CONTENT_BG_PRESSED, BITMAP_PIXEL_FORMAT_ARGB8888, pTempBitmap);
347 SysTryCatch(NID_UI_CTRL, (r == E_SUCCESS), , r, "[%s] Propagating.", GetErrorMessage(r));
349 __pContentBgPressedColorReplacementBitmap = _BitmapImpl::GetColorReplacedBitmapN(*pTempBitmap, Color::GetColor(COLOR_ID_MAGENTA), contentPressedColor);
350 SysTryCatch(NID_UI_CTRL, (__pContentBgPressedColorReplacementBitmap != null), r = GetLastResult(), GetLastResult(),
351 "[%s] Propagating.", GetErrorMessage(GetLastResult()));
356 r = GET_BITMAP_CONFIG_N(EDITDATE::CONTENT_BG_DISABLED, BITMAP_PIXEL_FORMAT_ARGB8888, pTempBitmap);
357 SysTryCatch(NID_UI_CTRL, (r == E_SUCCESS), , r, "[%s] Propagating.", GetErrorMessage(r));
359 __pContentBgDisabledColorReplacementBitmap = _BitmapImpl::GetColorReplacedBitmapN(*pTempBitmap, Color::GetColor(COLOR_ID_MAGENTA), contentDisabledBgColor);
360 SysTryCatch(NID_UI_CTRL, (__pContentBgDisabledColorReplacementBitmap != null), r = GetLastResult(), GetLastResult(),
361 "[%s] Propagating.", GetErrorMessage(GetLastResult()));
366 r = GET_BITMAP_CONFIG_N(EDITDATE::CONTENT_BG_HIGHLIGHTED, BITMAP_PIXEL_FORMAT_ARGB8888, pTempBitmap);
367 SysTryCatch(NID_UI_CTRL, (r == E_SUCCESS), , r, "[%s] Propagating.", GetErrorMessage(r));
369 __pContentBgHighlightedColorReplacementBitmap = _BitmapImpl::GetColorReplacedBitmapN(*pTempBitmap, Color::GetColor(COLOR_ID_MAGENTA), contentHighlightedColor);
370 SysTryCatch(NID_UI_CTRL, (__pContentBgHighlightedColorReplacementBitmap != null), r = GetLastResult(), GetLastResult(),
371 "[%s] Propagating.", GetErrorMessage(GetLastResult()));
373 r = GET_BITMAP_CONFIG_N(EDITDATE::CONTENT_BG_EFFECT_NORMAL, BITMAP_PIXEL_FORMAT_ARGB8888, __pContentBgEffectNormalBitmap);
374 SysTryCatch(NID_UI_CTRL, (r == E_SUCCESS), , r, "[%s] Propagating.", GetErrorMessage(r));
376 r = GET_BITMAP_CONFIG_N(EDITDATE::CONTENT_BG_EFFECT_PRESSED, BITMAP_PIXEL_FORMAT_ARGB8888, __pContentBgEffectPressedBitmap);
377 SysTryCatch(NID_UI_CTRL, (r == E_SUCCESS), , r, "[%s] Propagating.", GetErrorMessage(r));
379 r = GET_BITMAP_CONFIG_N(EDITDATE::CONTENT_BG_EFFECT_DISABLED, BITMAP_PIXEL_FORMAT_ARGB8888, __pContentBgEffectDisabledBitmap);
380 SysTryCatch(NID_UI_CTRL, (r == E_SUCCESS), , r, "[%s] Propagating.", GetErrorMessage(r));
392 delete __pContentBgNormalColorReplacementBitmap;
393 __pContentBgNormalColorReplacementBitmap = null;
395 delete __pContentBgPressedColorReplacementBitmap;
396 __pContentBgPressedColorReplacementBitmap = null;
398 delete __pContentBgDisabledColorReplacementBitmap;
399 __pContentBgDisabledColorReplacementBitmap = null;
401 delete __pContentBgHighlightedColorReplacementBitmap;
402 __pContentBgHighlightedColorReplacementBitmap = null;
404 delete __pContentBgEffectNormalBitmap;
405 __pContentBgEffectNormalBitmap = null;
407 delete __pContentBgEffectPressedBitmap;
408 __pContentBgEffectPressedBitmap = null;
410 delete __pContentBgEffectDisabledBitmap;
411 __pContentBgEffectDisabledBitmap = null;
417 _EditDatePresenter::GetLocaleDateFormat(void) const
419 int localeDateFormat = -1;
420 int error = vconf_get_int(VCONFKEY_SETAPPL_DATE_FORMAT_INT, &localeDateFormat);
423 localeDateFormat = SETTING_DATE_FORMAT_DD_MM_YYYY;
426 return localeDateFormat;
430 _EditDatePresenter::GetDate(void) const
432 SysAssertf((__pEditDateTimeModel != null), "The _EditDateTimeModel instance is null.");
435 date.SetValue(GetYear(), GetMonth(), GetDay(), DATETIME_HOUR_MIN, DATETIME_MINUTE_MIN);
441 _EditDatePresenter::GetDay(void) const
443 SysAssertf((__pEditDateTimeModel != null), "The _EditDateTimeModel instance is null.");
445 return __pEditDateTimeModel->GetDay();
449 _EditDatePresenter::GetMonth(void) const
451 SysAssertf((__pEditDateTimeModel != null), "The _EditDateTimeModel instance is null.");
453 return __pEditDateTimeModel->GetMonth();
457 _EditDatePresenter::GetYear(void) const
459 SysAssertf((__pEditDateTimeModel != null), "The _EditDateTimeModel instance is null.");
461 return __pEditDateTimeModel->GetYear();
465 _EditDatePresenter::SetDate(const DateTime& date)
467 SysAssertf((__pEditDateTimeModel != null), "The _EditDateTimeModel instance is null.");
469 __pEditDateTimeModel->SetDateTime(date);
474 _EditDatePresenter::SetCurrentDate(void)
476 SysAssertf((__pEditDateTimeModel != null), "The _EditDateTimeModel instance is null.");
478 __pEditDateTimeModel->SetCurrentDateTime();
483 _EditDatePresenter::SetYear(int year)
485 SysAssertf((__pEditDateTimeModel != null), "The _EditDateTimeModel instance is null.");
487 return __pEditDateTimeModel->SetYear(year);
491 _EditDatePresenter::SetMonth(int month)
493 SysAssertf((__pEditDateTimeModel != null), "The _EditDateTimeModel instance is null.");
495 return __pEditDateTimeModel->SetMonth(month);
499 _EditDatePresenter::SetDay(int day)
501 SysAssertf((__pEditDateTimeModel != null), "The _EditDateTimeModel instance is null.");
503 return __pEditDateTimeModel->SetDay(day);
507 _EditDatePresenter::SetDatePickerEnabled(bool enable)
509 __datePickerEnabled = enable;
514 _EditDatePresenter::IsDatePickerEnabled(void) const
516 return __datePickerEnabled;
520 _EditDatePresenter::SetMinYear(int minYear)
522 return __pEditDateTimeModel->SetMinYear(minYear);
526 _EditDatePresenter::SetMaxYear(int maxYear)
528 return __pEditDateTimeModel->SetMaxYear(maxYear);
532 _EditDatePresenter::GetMinYear(void) const
537 __pEditDateTimeModel->GetYearRange(minYear, maxYear);
543 _EditDatePresenter::GetMaxYear(void) const
548 __pEditDateTimeModel->GetYearRange(minYear, maxYear);
554 _EditDatePresenter::Draw(void)
556 result r = E_SUCCESS;
563 Canvas* pCanvas = __pEditDate->GetCanvasN();
564 SysAssertf((pCanvas != null), "Failed to get canvas.");
566 pCanvas->SetBackgroundColor(Color(0, 0, 0, 0));
569 if (__title.IsEmpty() == false)
578 _DateTimeUtils dateTimeUtils;
579 monthString = dateTimeUtils.GetMonthString(GetMonth());
580 yearString.Format(10, L"%04d", GetYear());
581 dayString.Format(10, L"%02d", GetDay());
583 CalculateAreaBounds();
585 r = DrawText(*pCanvas, GetDateAreaBounds(DATETIME_ID_DAY), dayString, DATETIME_ID_DAY);
586 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
587 r = DrawText(*pCanvas, GetDateAreaBounds(DATETIME_ID_MONTH), monthString, DATETIME_ID_MONTH);
588 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
589 r = DrawText(*pCanvas, GetDateAreaBounds(DATETIME_ID_YEAR), yearString, DATETIME_ID_YEAR);
590 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
602 _EditDatePresenter::CalculateAreaBounds(void)
604 result r = E_SUCCESS;
606 if (GetLocaleDateFormat() == DATE_FORMAT_DDMMYYYY)
608 __monthBounds.x = __dayBounds.x + __dayBounds.width + __elementMargin;
609 __yearBounds.x = __monthBounds.x + __monthBounds.width + __elementMargin;
611 else if (GetLocaleDateFormat() == DATE_FORMAT_MMDDYYYY)
613 __dayBounds.x = __monthBounds.x + __monthBounds.width + __elementMargin;
614 __yearBounds.x = __dayBounds.x + __dayBounds.width + __elementMargin;
616 else if (GetLocaleDateFormat() == DATE_FORMAT_YYYYMMDD)
618 __monthBounds.x = __yearBounds.x + __yearBounds.width + __elementMargin;
619 __dayBounds.x = __monthBounds.x + __monthBounds.width + __elementMargin;
621 else if (GetLocaleDateFormat() == DATE_FORMAT_YYYYDDMM)
623 __dayBounds.x = __yearBounds.x + __yearBounds.width + __elementMargin;
624 __monthBounds.x = __dayBounds.x + __dayBounds.width + __elementMargin;
631 _EditDatePresenter::DrawTitle(Canvas& canvas)
633 if (!__pEditDate->IsEnabled())
635 Color titleDisabledColor;
636 GET_COLOR_CONFIG(EDITDATE::TITLE_TEXT_DISABLED, titleDisabledColor);
637 __titleObject.SetForegroundColor(titleDisabledColor, 0, __titleObject.GetTextLength());
640 (_FontImpl::GetInstance(*__pFont))->SetSize(__titleFontSize);
641 (_FontImpl::GetInstance(*__pFont))->SetStyle(FONT_STYLE_BOLD);
642 __titleObject.SetFont(__pFont, 0, __titleObject.GetTextLength());
643 __titleObject.Draw(*_CanvasImpl::GetInstance(canvas));
649 _EditDatePresenter::DrawText(Canvas& canvas, const FloatRectangle& bounds, const String& text, _DateTimeId boxId)
653 if (!__pEditDate->IsEnabled())
655 GET_COLOR_CONFIG(EDITDATE::TEXT_DISABLED, textColor);
659 GET_COLOR_CONFIG(EDITDATE::TEXT_NORMAL, textColor);
662 (_FontImpl::GetInstance(*__pFont))->SetStyle(FONT_STYLE_PLAIN);
664 if (boxId == __selectedId && boxId != DATETIME_ID_NONE)
666 (_FontImpl::GetInstance(*__pFont))->SetStyle(FONT_STYLE_BOLD);
667 GET_COLOR_CONFIG(EDITDATE::TEXT_PRESSED, textColor);
670 DrawContentBitmap(canvas, bounds, boxId);
672 FloatRectangle drawAreaBounds(0.0f, 0.0f, 0.0f, 0.0f);
673 drawAreaBounds = bounds;
675 TextSimple* pSimpleText = null;
676 pSimpleText = new (std::nothrow)TextSimple((const_cast <wchar_t*>(text.GetPointer())), text.GetLength(), TEXT_ELEMENT_SOURCE_TYPE_EXTERNAL);
677 SysTryReturn(NID_UI_CTRL, (pSimpleText != null), E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
679 __textObject.RemoveAll();
681 (_FontImpl::GetInstance(*__pFont))->SetSize(__dateFontSize);
682 __textObject.AppendElement(*pSimpleText);
684 __textObject.SetFont(__pFont, 0, __textObject.GetTextLength());
685 __textObject.SetForegroundColor(textColor, 0, __textObject.GetTextLength());
686 __textObject.SetBounds(drawAreaBounds);
687 __textObject.Draw(*_CanvasImpl::GetInstance(canvas));
693 _EditDatePresenter::DrawContentBitmap(Canvas& canvas, const FloatRectangle& bounds, _DateTimeId boxId)
695 result r = E_SUCCESS;
697 bool isCustomBitmap = false;
698 Bitmap* pReplacementBitmap = null;
699 Bitmap* pEffectBitmap = null;
701 if (!__pEditDate->IsEnabled())
703 isCustomBitmap = IS_CUSTOM_BITMAP(EDITTIME::CONTENT_BG_DISABLED);
704 pReplacementBitmap = __pContentBgDisabledColorReplacementBitmap;
705 pEffectBitmap = __pContentBgEffectDisabledBitmap;
707 else if (__selectedId != boxId)
709 isCustomBitmap = IS_CUSTOM_BITMAP(EDITTIME::CONTENT_BG_NORMAL);
710 pReplacementBitmap = __pContentBgNormalColorReplacementBitmap;
711 pEffectBitmap = __pContentBgEffectNormalBitmap;
715 isCustomBitmap = IS_CUSTOM_BITMAP(EDITTIME::CONTENT_BG_PRESSED);
716 pReplacementBitmap = __pContentBgPressedColorReplacementBitmap;
717 pEffectBitmap = __pContentBgEffectPressedBitmap;
720 r = DrawResourceBitmap(canvas, bounds, pReplacementBitmap);
721 SysTryReturn(NID_UI_CTRL, (r == E_SUCCESS), r, r, "[%s] Propagating.", GetErrorMessage(r));
725 r = DrawResourceBitmap(canvas, bounds, pEffectBitmap);
726 SysTryReturn(NID_UI_CTRL, (r == E_SUCCESS), r, r, "[%s] Propagating.", GetErrorMessage(r));
733 _EditDatePresenter::DrawResourceBitmap(Canvas& canvas, const FloatRectangle& bounds, Bitmap* pBitmap)
735 result r = E_SUCCESS;
742 if (_BitmapImpl::CheckNinePatchedBitmapStrictly(*pBitmap))
744 r = canvas.DrawNinePatchedBitmap(bounds, *pBitmap);
745 SysTryReturn(NID_UI_CTRL, (r == E_SUCCESS), r, r, "[%s] Propagating.", GetErrorMessage(r));
749 r = canvas.DrawBitmap(bounds, *pBitmap);
750 SysTryReturn(NID_UI_CTRL, (r == E_SUCCESS), r, r, "[%s] Propagating.", GetErrorMessage(r));
757 _EditDatePresenter::GetBoxIdFromPosition(const FloatPoint& point) const
759 _DateTimeId displayBoxId = DATETIME_ID_NONE;
761 if (point.y < __dayBounds.y || point.y > __dayBounds.y + __dayBounds.height)
766 if (__dayBounds.Contains(point) == true)
768 displayBoxId = DATETIME_ID_DAY;
770 else if (__monthBounds.Contains(point) == true)
772 displayBoxId = DATETIME_ID_MONTH;
774 else if (__yearBounds.Contains(point) == true)
776 displayBoxId = DATETIME_ID_YEAR;
783 _EditDatePresenter::GetDateAreaBounds(_DateTimeId id) const
785 if (id == DATETIME_ID_DAY)
789 else if (id == DATETIME_ID_MONTH)
791 return __monthBounds;
793 else if (id == DATETIME_ID_YEAR)
799 return FloatRectangle();
804 _EditDatePresenter::GetTitleBounds(void) const
806 return __titleBounds;
810 _EditDatePresenter::SetLastSelectedId(_DateTimeId boxId)
812 __lastSelectedId = boxId;
817 _EditDatePresenter::GetLastSelectedId(void) const
819 return __lastSelectedId;
823 _EditDatePresenter::OnFontChanged(Font* pFont)
827 if (__pEditDate->GetDateTimeBar() != null)
829 __pEditDate->GetDateTimeBar()->SetFont(*pFont);
836 _EditDatePresenter::OnFontInfoRequested(unsigned long& style, float& size)
838 style = FONT_STYLE_PLAIN;
839 size = __dateFontSize;
845 _EditDatePresenter::OnTouchPressed(const _Control& source, const _TouchInfo& touchinfo)
847 SysTryReturn(NID_UI_CTRL, IsDatePickerEnabled() == true, true, E_SYSTEM,
848 "[E_SYSTEM] A system error has occurred. EditDate instance is disabled.");
850 if (&source != __pEditDate)
855 __touchMoveHandled = false;
857 FloatPoint point = touchinfo.GetCurrentPosition();
859 _DateTimeId boxId = DATETIME_ID_NONE;
860 boxId = GetBoxIdFromPosition(point);
862 if (boxId < DATETIME_ID_YEAR || boxId > DATETIME_ID_DAY)
864 __selectedId = DATETIME_ID_NONE;
870 int displayValue = -1;
872 if (boxId == DATETIME_ID_DAY)
874 if (__pEditDate->GetDateTimeBar() != null)
876 _DateTimeUtils dateTimeUtils;
877 maxValue = dateTimeUtils.CalculateMaxDay(GetYear(), GetMonth());
878 minValue = DATETIME_DAY_MIN;
879 displayValue = GetDay();
882 else if (boxId == DATETIME_ID_MONTH)
884 minValue = DATETIME_MONTH_MIN;
885 maxValue = DATETIME_MONTH_MAX;
886 displayValue = GetMonth();
888 else if (boxId == DATETIME_ID_YEAR)
890 minValue = GetMinYear();
891 maxValue = GetMaxYear();
892 displayValue = GetYear();
895 if (__pEditDate->GetDateTimeBar() != null)
897 if (__pEditDate->GetDateTimeBar()->GetItemCount() > 0)
899 __pEditDate->GetDateTimeBar()->RemoveAllItems();
902 result r = __pEditDate->GetDateTimeBar()->SetInitialValue(minValue, maxValue, displayValue, boxId);
905 __selectedId = DATETIME_ID_NONE;
910 __selectedId = boxId;
916 _EditDatePresenter::OnTouchReleased(const _Control& source, const _TouchInfo& touchinfo)
918 SysTryReturn(NID_UI_CTRL, IsDatePickerEnabled() == true, true, E_SYSTEM,
919 "[E_SYSTEM] A system error has occurred. EditDate instance is disabled.");
921 if (&source != __pEditDate)
926 FloatPoint point = touchinfo.GetCurrentPosition();
928 _DateTimeId boxId = DATETIME_ID_NONE;
929 boxId = GetBoxIdFromPosition(point);
931 if (boxId == GetLastSelectedId() || boxId != __selectedId || boxId == DATETIME_ID_NONE)
933 if (__pEditDate->GetDateTimeBar() != null && __pEditDate->GetDateTimeBar()->IsActivated())
935 __pEditDate->GetDateTimeBar()->SetVisibleState(false);
936 __pEditDate->GetDateTimeBar()->Close();
939 __selectedId = DATETIME_ID_NONE;
940 SetLastSelectedId(__selectedId);
947 SetLastSelectedId(__selectedId);
949 __lastSelectedValue = "";
950 _DateTimeUtils dateTimeUtils;
951 if (GetLastSelectedId() == DATETIME_ID_YEAR)
953 __lastSelectedValue.Format(10, L"%04d", GetYear());
954 PLAY_FEEDBACK(_RESOURCE_FEEDBACK_PATTERN_TAP);
956 else if (GetLastSelectedId() == DATETIME_ID_MONTH)
958 __lastSelectedValue = dateTimeUtils.GetMonthString(GetMonth());
959 PLAY_FEEDBACK(_RESOURCE_FEEDBACK_PATTERN_TAP);
961 else if (GetLastSelectedId() == DATETIME_ID_DAY)
963 __lastSelectedValue.Format(10, L"%02d", GetDay());
964 PLAY_FEEDBACK(_RESOURCE_FEEDBACK_PATTERN_TAP);
969 if ((__pEditDate->GetDateTimeBar() != null) && (GetLastSelectedId() != DATETIME_ID_NONE))
971 FloatRectangle bounds(0.0f, 0.0f, 0.0f, 0.0f);
972 bounds = GetDateAreaBounds(GetLastSelectedId());
973 FloatRectangle absoluteBounds(0.0f, 0.0f, 0.0f, 0.0f);
974 absoluteBounds = __pEditDate->GetAbsoluteBoundsF();
975 bounds.x += absoluteBounds.x;
977 __pEditDate->GetDateTimeBar()->CalculateArrowBounds(bounds);
979 if (__pEditDate->GetDateTimeBar()->IsActivated())
981 __pEditDate->GetDateTimeBar()->RefreshItems();
985 __pEditDate->GetDateTimeBar()->SetVisibleState(true);
986 __pEditDate->GetDateTimeBar()->Open();
990 __selectedId = DATETIME_ID_NONE;
995 _EditDatePresenter::OnTouchCanceled(const _Control& source, const _TouchInfo& touchinfo)
997 if (&source != __pEditDate)
1002 __selectedId = DATETIME_ID_NONE;
1008 _EditDatePresenter::OnTouchMoved(const _Control& source, const _TouchInfo& touchinfo)
1010 if (&source != __pEditDate)
1015 if (__pEditDate->GetDateTimeBar() != null && __pEditDate->GetDateTimeBar()->IsActivated())
1024 _EditDatePresenter::OnTouchMoveHandled(const _Control& control)
1026 __touchMoveHandled = true;
1027 __selectedId = DATETIME_ID_NONE;
1033 _EditDatePresenter::Animate(void)
1035 SysAssertf((__pFont != null), "Font instance must not be null.");
1037 (_FontImpl::GetInstance(*__pFont))->SetSize(__dateFontSize);
1039 result r = E_SUCCESS;
1040 FloatRectangle rect;
1046 _DateTimeUtils dateTimeUtils;
1047 monthString = dateTimeUtils.GetMonthString(GetMonth());
1048 yearString.Format(10, L"%04d", GetYear());
1049 dayString.Format(10, L"%02d", GetDay());
1051 if (GetLastSelectedId() == DATETIME_ID_DAY)
1053 SysTryReturnVoidResult(NID_UI_CTRL, (__lastSelectedValue.Equals(dayString) == false), E_SUCCESS, "Day string matched.");
1055 newValue = dayString;
1056 rect = GetDateAreaBounds(DATETIME_ID_DAY);
1058 else if (GetLastSelectedId() == DATETIME_ID_MONTH)
1060 SysTryReturnVoidResult(NID_UI_CTRL, (__lastSelectedValue.Equals(monthString) == false), E_SUCCESS, "Month string matched.");
1062 newValue = monthString;
1063 rect = GetDateAreaBounds(DATETIME_ID_MONTH);
1065 else if (GetLastSelectedId() == DATETIME_ID_YEAR)
1067 SysTryReturnVoidResult(NID_UI_CTRL, (__lastSelectedValue.Equals(yearString) == false), E_SUCCESS, "Year string matched.");
1069 newValue = yearString;
1070 rect = GetDateAreaBounds(DATETIME_ID_YEAR);
1073 FloatDimension newTextDim;
1074 FloatDimension oldTextDim;
1075 FloatPoint textPoint;
1076 VisualElement* pNewVisualElement = null;
1077 VisualElement* pOldVisualElement = null;
1078 VisualElement* pEditDateElement = null;
1079 VisualElementPropertyAnimation* pNewBoundsAnimation = null;
1080 VisualElementPropertyAnimation* pOldBoundsAnimation = null;
1081 Canvas *pCanvas = null;
1082 Color contentBgColor;
1083 Color textPressedColor;
1085 GET_COLOR_CONFIG(EDITTIME::CONTENT_BG_PRESSED, contentBgColor);
1086 GET_COLOR_CONFIG(EDITTIME::TEXT_PRESSED, textPressedColor);
1088 __pFont->GetTextExtent(newValue, newValue.GetLength(), newTextDim);
1089 __pFont->GetTextExtent(__lastSelectedValue, __lastSelectedValue.GetLength(), oldTextDim);
1091 if (newTextDim.width > oldTextDim.width)
1093 textPoint.x = (rect.width - newTextDim.width) / 2.0f;
1097 textPoint.x = (rect.width - oldTextDim.width) / 2.0f;
1100 SysTryReturnVoidResult(NID_UI_CTRL, (rect.x + textPoint.x < __pEditDate->GetBoundsF().width), E_SUCCESS, "Rolling animation cann't be played.");
1102 __isAnimating = true;
1104 __pContentProvider = new (std::nothrow) VisualElement();
1105 SysTryReturnVoidResult(NID_UI_CTRL, (__pContentProvider != null), E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
1107 r = __pContentProvider->Construct();
1108 SysTryCatch(NID_UI_CTRL, (r == E_SUCCESS), , r, "[%s] Propagating.", GetErrorMessage(r));
1110 __pContentProvider->SetShowState(true);
1111 __pContentProvider->SetClipChildrenEnabled(true);
1112 __pContentProvider->SetImplicitAnimationEnabled(false);
1114 pEditDateElement = __pEditDate->GetVisualElement();
1115 r = GetLastResult();
1116 SysTryCatch(NID_UI_CTRL, (pEditDateElement != null), , r, "[%s] Propagating.", GetErrorMessage(r));
1118 pNewVisualElement = new (std::nothrow) VisualElement();
1119 SysTryCatch(NID_UI_CTRL, (pNewVisualElement != null), , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
1121 r = pNewVisualElement->Construct();
1124 pNewVisualElement->Destroy();
1126 SysTryCatch(NID_UI_CTRL, (r == E_SUCCESS), , r, "[%s] Propagating.", GetErrorMessage(r));
1128 pOldVisualElement = new (std::nothrow) VisualElement();
1129 if (pOldVisualElement == null)
1131 pNewVisualElement->Destroy();
1133 SysTryCatch(NID_UI_CTRL, (pOldVisualElement != null), , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
1135 r = pOldVisualElement->Construct();
1138 pNewVisualElement->Destroy();
1139 pOldVisualElement->Destroy();
1141 SysTryCatch(NID_UI_CTRL, (r == E_SUCCESS), , r, "[%s] Propagating.", GetErrorMessage(r));
1143 pNewVisualElement->SetShowState(true);
1144 pOldVisualElement->SetShowState(true);
1146 if (newTextDim.width > oldTextDim.width)
1148 textPoint.x = (rect.width - newTextDim.width) / 2.0f;
1149 textPoint.y = (rect.height - newTextDim.height) / 2.0f;
1150 __pContentProvider->SetBounds(FloatRectangle((rect.x + textPoint.x) * 1.0f, (rect.y + textPoint.y) * 1.0f, newTextDim.width * 1.0f, newTextDim.height * 1.0f));
1151 pNewVisualElement->SetBounds(FloatRectangle(0.0f, newTextDim.height * 1.0f, newTextDim.width * 1.0f, newTextDim.height * 1.0f));
1153 rect.x = static_cast<int>(__pContentProvider->GetBounds().x);
1154 rect.y = static_cast<int>(__pContentProvider->GetBounds().y);
1155 rect.width = static_cast<int>(__pContentProvider->GetBounds().width);
1156 rect.height = static_cast<int>(__pContentProvider->GetBounds().height);
1158 textPoint.x = (rect.width - oldTextDim.width) / 2.0f;
1159 textPoint.y = (rect.height - oldTextDim.height) / 2.0f;
1161 pOldVisualElement->SetBounds(FloatRectangle(textPoint.x * 1.0f, 0.0f, oldTextDim.width * 1.0f, oldTextDim.height * 1.0f));
1165 textPoint.x = (rect.width - oldTextDim.width) / 2.0f;
1166 textPoint.y = (rect.height - oldTextDim.height) / 2.0f;
1167 __pContentProvider->SetBounds(FloatRectangle((rect.x + textPoint.x) * 1.0f, (rect.y + textPoint.y) * 1.0f, oldTextDim.width * 1.0f, oldTextDim.height * 1.0f));
1168 pOldVisualElement->SetBounds(FloatRectangle(0.0f, 0.0f, oldTextDim.width * 1.0f, oldTextDim.height * 1.0f));
1170 rect.x = static_cast<int>(__pContentProvider->GetBounds().x);
1171 rect.y = static_cast<int>(__pContentProvider->GetBounds().y);
1172 rect.width = static_cast<int>(__pContentProvider->GetBounds().width);
1173 rect.height = static_cast<int>(__pContentProvider->GetBounds().height);
1175 textPoint.x = (rect.width - newTextDim.width) / 2.0f;
1176 textPoint.y = (rect.height - newTextDim.height) / 2.0f;
1178 pNewVisualElement->SetBounds(FloatRectangle(textPoint.x * 1.0f, newTextDim.height * 1.0f, newTextDim.width * 1.0f, newTextDim.height * 1.0f));
1182 pCanvas = pEditDateElement->GetCanvasN(rect);
1183 pCanvas->SetBackgroundColor(contentBgColor);
1187 pEditDateElement->AttachChild(*__pContentProvider);
1189 __pContentProvider->AttachChild(*pOldVisualElement);
1190 __pContentProvider->AttachChild(*pNewVisualElement);
1192 pNewBoundsAnimation = new (std::nothrow) VisualElementPropertyAnimation();
1193 SysTryCatch(NID_UI_CTRL, (pNewBoundsAnimation != null), , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
1195 pNewBoundsAnimation->SetDuration(300);
1196 pNewBoundsAnimation->SetPropertyName("bounds.position");
1197 pNewBoundsAnimation->SetStartValue(Variant(FloatPoint(pNewVisualElement->GetBounds().x * 1.0f, newTextDim.height * 1.0f)));
1198 pNewBoundsAnimation->SetEndValue(Variant(FloatPoint(pNewVisualElement->GetBounds().x * 1.0f, 0.0f)));
1199 pNewBoundsAnimation->SetVisualElementAnimationStatusEventListener(this);
1201 pOldBoundsAnimation = new (std::nothrow) VisualElementPropertyAnimation();
1202 SysTryCatch(NID_UI_CTRL, (pOldBoundsAnimation != null), , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
1204 pOldBoundsAnimation->SetDuration(300);
1205 pOldBoundsAnimation->SetPropertyName("bounds.position");
1206 pOldBoundsAnimation->SetStartValue(Variant(FloatPoint(pOldVisualElement->GetBounds().x * 1.0f, 0.0f)));
1207 pOldBoundsAnimation->SetEndValue(Variant(FloatPoint(pOldVisualElement->GetBounds().x * 1.0f, oldTextDim.height * -1.0f)));
1208 pOldBoundsAnimation->SetVisualElementAnimationStatusEventListener(this);
1210 pCanvas = pOldVisualElement->GetCanvasN();
1211 r = GetLastResult();
1212 SysTryCatch(NID_UI_CTRL, (pCanvas != null), , r, "[%s] Propagating.", GetErrorMessage(r));
1214 pCanvas->SetBackgroundColor(Color(0, 0, 0, 0));
1216 pCanvas->SetForegroundColor(textPressedColor);
1217 (_FontImpl::GetInstance(*__pFont))->SetStyle(FONT_STYLE_BOLD);
1218 pCanvas->SetFont(*__pFont);
1219 pCanvas->DrawText(FloatPoint(0.0f, 0.0f), __lastSelectedValue);
1224 pCanvas = pNewVisualElement->GetCanvasN();
1225 r = GetLastResult();
1226 SysTryCatch(NID_UI_CTRL, (pCanvas != null), , r, "[%s] Propagating.", GetErrorMessage(r));
1228 pCanvas->SetBackgroundColor(Color(0, 0, 0, 0));
1230 pCanvas->SetForegroundColor(textPressedColor);
1231 (_FontImpl::GetInstance(*__pFont))->SetStyle(FONT_STYLE_BOLD);
1232 pCanvas->SetFont(*__pFont);
1233 pCanvas->DrawText(FloatPoint(0.0f, 0.0f), newValue);
1238 pOldVisualElement->SetImplicitAnimationEnabled(false);
1239 pOldVisualElement->AddAnimation(*pOldBoundsAnimation);
1241 pNewVisualElement->SetImplicitAnimationEnabled(false);
1242 pNewVisualElement->AddAnimation(*pNewBoundsAnimation);
1244 delete pOldBoundsAnimation;
1245 delete pNewBoundsAnimation;
1250 __isAnimating = false;
1251 __pContentProvider->Destroy();
1253 delete pNewBoundsAnimation;
1254 pNewBoundsAnimation = null;
1256 delete pOldBoundsAnimation;
1257 pOldBoundsAnimation = null;
1266 _EditDatePresenter::OnVisualElementAnimationFinished (const VisualElementAnimation &animation, const String &keyName, VisualElement &target, bool completedNormally)
1268 result r = E_SUCCESS;
1269 __isAnimating = false;
1271 VisualElement* pEditDateElement = __pEditDate->GetVisualElement();
1272 r = GetLastResult();
1273 SysTryReturnVoidResult(NID_UI_CTRL, (pEditDateElement != null), r, "[%s] Propagating.", GetErrorMessage(r));
1275 pEditDateElement->DetachChild(*__pContentProvider);
1276 __pContentProvider->Destroy();
1282 }}} // Tizen::Ui::Controls