2 // Open Service Platform
3 // Copyright (c) 2012-2013 Samsung Electronics Co., Ltd.
5 // Licensed under the Flora License, Version 1.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://floralicense.org/license/
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_DateTimeBarPresenter.cpp
20 * @brief This is the implementation file for the _DateTimeBarPresenter class.
23 #include <FGrp_BitmapImpl.h>
24 #include <FGrp_FontImpl.h>
25 #include <FGrp_TextTextSimple.h>
26 #include "FUi_CoordinateSystemUtils.h"
27 #include "FUi_ResourceManager.h"
28 #include "FUiCtrl_DateTimeUtils.h"
29 #include "FUiCtrl_DateTimeBar.h"
30 #include "FUiCtrl_DateTimeBarPresenter.h"
32 using namespace Tizen::Graphics;
33 using namespace Tizen::Ui;
34 using namespace Tizen::Base;
35 using namespace Tizen::Base::Runtime;
36 using namespace Tizen::Graphics::_Text;
38 const int UPDATE_ITEM_COUNT = 3;
40 namespace Tizen { namespace Ui { namespace Controls
43 _DateTimeBarPresenter::_DateTimeBarPresenter(_DateTimeBar* pDateTimeBar)
44 : __pDateTimeBar(pDateTimeBar)
45 , __pDateTimeBarModel(null)
46 , __currentPoint(FloatPoint(0.0f, 0.0f))
47 , __isTouchMoved(false)
48 , __touchMoveHandled(false)
49 , __isFlickEnabled(true)
50 , __isFlickInProgress(false)
52 , __pFlickAnimationTimer(null)
55 , __bodyAreaBounds(FloatRectangle())
56 , __arrowAreaBounds(FloatRectangle())
57 , __windowAreaBounds(FloatRectangle())
58 , __pBgColorReplacementBitmap(null)
59 , __pArrowColorReplacementBitmap(null)
60 , __isInitialAnimation(false)
61 , __initialAnimationValue(0.0f)
66 _DateTimeBarPresenter::~_DateTimeBarPresenter(void)
68 delete __pDateTimeBarModel;
69 __pDateTimeBarModel = 0;
71 delete __pBgColorReplacementBitmap;
72 __pBgColorReplacementBitmap = null;
74 delete __pArrowColorReplacementBitmap;
75 __pArrowColorReplacementBitmap = null;
77 delete __pFlickAnimationTimer;
78 __pFlickAnimationTimer = null;
84 _DateTimeBarPresenter*
85 _DateTimeBarPresenter::CreateInstanceN(_DateTimeBar& dateTimeBar)
89 _DateTimeBarPresenter* pDateTimeBarPresenter = new (std::nothrow) _DateTimeBarPresenter(&dateTimeBar);
90 SysTryReturn(NID_UI_CTRL, pDateTimeBarPresenter, null, E_OUT_OF_MEMORY,
91 "[E_OUT_OF_MEMORY] Memory allocation failed.");
93 pDateTimeBarPresenter->__pDateTimeBarModel = _DateTimeBarModel::CreateInstanceN();
95 SysTryCatch(NID_UI_CTRL, pDateTimeBarPresenter->__pDateTimeBarModel, , r,
96 "[%s] Propagating.", GetErrorMessage(r));
98 r = GET_SHAPE_CONFIG(DATETIMEBAR::ARROW_WIDTH, dateTimeBar.GetOrientation(), pDateTimeBarPresenter->__arrowAreaBounds.width);
99 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Failed to get arrow width from resource.", GetErrorMessage(r));
101 r = GET_SHAPE_CONFIG(DATETIMEBAR::ARROW_HEIGHT, dateTimeBar.GetOrientation(), pDateTimeBarPresenter->__arrowAreaBounds.height);
102 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Failed to get arrow height from resource.", GetErrorMessage(r));
104 r = pDateTimeBarPresenter->LoadResource();
105 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Failed to load the resources.", GetErrorMessage(r));
107 return pDateTimeBarPresenter;
110 delete pDateTimeBarPresenter;
116 _DateTimeBarPresenter::AddFlickAnimationInfo()
118 __flickAnimation.SetSensitivity(FLICK_ANIMATION_FPS_DATE_TIME_BAR, FLICK_ANIMATION_SENSITIVITY_DATE_TIME_BAR);
119 __flickAnimation.SetDirection(FD_HORIZONTAL);
123 _DateTimeBarPresenter::LoadResource(void)
125 result r = E_SUCCESS;
127 Bitmap* pBackgroundNormalBitmap = null;
129 r = GET_BITMAP_CONFIG_N(DATETIMEBAR::TIMEPICKERBAR_BG_NORMAL, BITMAP_PIXEL_FORMAT_ARGB8888, pBackgroundNormalBitmap);
130 SysTryReturn(NID_UI_CTRL, (r == E_SUCCESS), r, r, "[%s] Propagating.", GetErrorMessage(r));
132 GET_COLOR_CONFIG(DATETIMEBAR::BG_NORMAL, bgBitmapColor);
133 __pBgColorReplacementBitmap = _BitmapImpl::GetColorReplacedBitmapN(*pBackgroundNormalBitmap,
134 Color::GetColor(COLOR_ID_MAGENTA), bgBitmapColor);
135 SysTryCatch(NID_UI_CTRL, __pBgColorReplacementBitmap != null, r = GetLastResult(), GetLastResult(), "[%s] Propagating.",
136 GetErrorMessage(GetLastResult()));
138 r = LoadArrowBitmap();
139 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Failed to load resources.", GetErrorMessage(r));
141 delete pBackgroundNormalBitmap;
142 pBackgroundNormalBitmap = null;
144 AddFlickAnimationInfo();
150 delete pBackgroundNormalBitmap;
151 pBackgroundNormalBitmap = null;
153 delete __pBgColorReplacementBitmap;
154 __pBgColorReplacementBitmap = null;
160 _DateTimeBarPresenter::LoadArrowBitmap(void)
162 result r = E_SUCCESS;
164 Bitmap* pArrowNormalBitmap = null;
166 GET_COLOR_CONFIG(DATETIMEBAR::BG_NORMAL, arrowColor);
168 if (__pDateTimeBar->GetAlignment() == DATETIME_BAR_ALIGN_DOWN)
170 r = GET_BITMAP_CONFIG_N(DATETIMEBAR::TAIL_DOWN, BITMAP_PIXEL_FORMAT_ARGB8888, pArrowNormalBitmap);
171 SysTryReturn(NID_UI_CTRL, (r == E_SUCCESS), r, r, "[%s] Propagating.", GetErrorMessage(r));
175 r = GET_BITMAP_CONFIG_N(DATETIMEBAR::TAIL_UP, BITMAP_PIXEL_FORMAT_ARGB8888, pArrowNormalBitmap);
176 SysTryReturn(NID_UI_CTRL, (r == E_SUCCESS), r, r, "[%s] Propagating.", GetErrorMessage(r));
179 if (__pArrowColorReplacementBitmap != null)
181 delete __pArrowColorReplacementBitmap;
182 __pArrowColorReplacementBitmap = null;
185 __pArrowColorReplacementBitmap = _BitmapImpl::GetColorReplacedBitmapN(*pArrowNormalBitmap,
186 Color::GetColor(COLOR_ID_MAGENTA), arrowColor);
187 SysTryCatch(NID_UI_CTRL, __pArrowColorReplacementBitmap != null, r = GetLastResult(), GetLastResult(), "[%s] Propagating.",
188 GetErrorMessage(GetLastResult()));
190 delete pArrowNormalBitmap;
191 pArrowNormalBitmap = null;
197 delete pArrowNormalBitmap;
198 pArrowNormalBitmap = null;
200 delete __pArrowColorReplacementBitmap;
201 __pArrowColorReplacementBitmap = null;
207 _DateTimeBarPresenter::Draw(void)
209 result r = E_SUCCESS;
211 Canvas* pCanvas = __pDateTimeBar->GetCanvasN();
212 SysAssertf((pCanvas != null), "Failed to get canvas.");
214 pCanvas->SetBackgroundColor(Color(0, 0, 0, 0));
216 r = pCanvas->Clear();
217 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
219 r = DrawBackground(*pCanvas);
220 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
222 r = DrawItem(*pCanvas);
223 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
225 r = DrawArrow(*pCanvas);
226 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
237 _DateTimeBarPresenter::DrawItem(Canvas& canvas)
239 result r = E_SUCCESS;
241 FloatRectangle clientBounds = canvas.GetBoundsF();
243 _DateTimeBarItem* pDrawItem = null;
244 FloatRectangle itemBounds(0.0f, 0.0f, 0.0f, 0.0f);
249 GET_COLOR_CONFIG(DATETIMEBAR::TEXT_NORMAL, textColor);
251 Color textPressedColor;
252 GET_COLOR_CONFIG(DATETIMEBAR::TEXT_PRESSED, textPressedColor);
254 _DateTimeBarItemStatus itemStatus = DATETIMEBAR_ITEM_STATUS_NORMAL;
256 int itemCount = GetItemCount();
258 RefreshAccessibilityElement();
260 for (int i = __pDateTimeBarModel->GetFirstDrawnItemIndex(); i < itemCount; i++)
262 pDrawItem = __pDateTimeBarModel->GetItemAt(i);
263 if (pDrawItem == null)
268 itemBounds = pDrawItem->GetBounds();
270 if (itemBounds.x + itemBounds.width <= 0)
275 drawText = pDrawItem->GetText();
277 if (drawText.CompareTo(__selectedText) == 0)
279 pDrawItem->SetStatus(DATETIMEBAR_ITEM_STATUS_SELECTED);
282 itemStatus = pDrawItem->GetStatus();
284 float fontSize = GetFontSize();
286 TextSimple* pSimpleText = null;
287 TextObject* pTextObject = new (std::nothrow) TextObject;
288 SysTryReturn(NID_UI_CTRL, (pTextObject != null), E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
290 pTextObject->Construct();
291 pSimpleText = new (std::nothrow)TextSimple((const_cast <wchar_t*>(drawText.GetPointer())), drawText.GetLength(), TEXT_ELEMENT_SOURCE_TYPE_EXTERNAL);
292 pTextObject->AppendElement(*pSimpleText);
294 pTextObject->SetAlignment(TEXT_OBJECT_ALIGNMENT_CENTER | TEXT_OBJECT_ALIGNMENT_MIDDLE);
295 pTextObject->SetWrap(TEXT_OBJECT_WRAP_TYPE_NONE);
296 pTextObject->SetAction(TEXT_OBJECT_ACTION_TYPE_ABBREV);
298 SysAssertf(__pFont != null, "Font instance is null");
300 if (itemStatus == DATETIMEBAR_ITEM_STATUS_SELECTED)
302 (_FontImpl::GetInstance(*__pFont))->SetSize(fontSize);
303 (_FontImpl::GetInstance(*__pFont))->SetStyle(FONT_STYLE_BOLD);
304 pTextObject->SetFont(__pFont, 0, pTextObject->GetTextLength());
305 pTextObject->SetForegroundColor(textPressedColor, 0, pTextObject->GetTextLength());
309 (_FontImpl::GetInstance(*__pFont))->SetSize(fontSize);
310 (_FontImpl::GetInstance(*__pFont))->SetStyle(FONT_STYLE_PLAIN);
311 pTextObject->SetFont(__pFont, 0, pTextObject->GetTextLength());
312 pTextObject->SetForegroundColor(textColor, 0, pTextObject->GetTextLength());
315 pTextObject->SetBounds(itemBounds);
316 pTextObject->Draw(*_CanvasImpl::GetInstance(canvas));
320 if ((itemBounds.x + itemBounds.width + GetLeftRightMargin()) >= clientBounds.width)
330 _DateTimeBarPresenter::DrawBackground(Canvas& canvas)
332 result r = E_SUCCESS;
334 FloatRectangle bodyAreaBounds = GetBodyBounds();
336 if (__pBgColorReplacementBitmap != null)
338 if (_BitmapImpl::CheckNinePatchedBitmapStrictly(*__pBgColorReplacementBitmap))
340 r = canvas.DrawNinePatchedBitmap(bodyAreaBounds, *__pBgColorReplacementBitmap);
341 SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Propagating.");
345 r = canvas.DrawBitmap(bodyAreaBounds, *__pBgColorReplacementBitmap);
346 SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Propagating.");
352 r = canvas.DrawRectangle(bodyAreaBounds);
353 SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Propagating.");
360 _DateTimeBarPresenter::DrawArrow(Canvas& canvas)
362 result r = E_SUCCESS;
363 FloatRectangle arrowAreaBounds = GetArrowBounds();
365 if (__pArrowColorReplacementBitmap != null)
367 if (_BitmapImpl::CheckNinePatchedBitmapStrictly(*__pArrowColorReplacementBitmap))
369 r = canvas.DrawNinePatchedBitmap(arrowAreaBounds, *__pArrowColorReplacementBitmap);
370 SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Propagating.");
374 r = canvas.DrawBitmap(arrowAreaBounds, *__pArrowColorReplacementBitmap);
375 SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Propagating.");
383 _DateTimeBarPresenter::SetItemSelected(int index)
385 __pDateTimeBarModel->SetSelectedItemIndex(index);
390 _DateTimeBarPresenter::GetSelectedItemIndex(void) const
392 return __pDateTimeBarModel->GetSelectedItemIndex();
396 _DateTimeBarPresenter::GetItemIndexFromPosition(const FloatPoint& point) const
398 FloatRectangle clientBounds = __pDateTimeBar->GetBoundsF();
400 if (point.x > clientBounds.width
401 || point.y > clientBounds.height)
406 int itemIndex = __pDateTimeBarModel->GetFirstDrawnItemIndex();
407 _DateTimeBarItem* pItem = __pDateTimeBarModel->GetItemAt(itemIndex);
409 float itemMargin = 0.0f;
410 itemMargin = GetItemMargin();
412 while (pItem != null)
414 FloatRectangle itemBounds = pItem->GetBounds();
416 if (itemBounds.x > clientBounds.x)
418 if (itemIndex == __pDateTimeBarModel->GetFirstDrawnItemIndex())
420 startX = itemBounds.x;
423 itemBounds.x -= startX;
426 itemBounds.x = itemBounds.x - (itemMargin / 2.0f);
427 itemBounds.width = itemBounds.width + itemMargin;
429 if (itemBounds.Contains(point) == true)
436 if (itemIndex == GetItemCount())
441 pItem = __pDateTimeBarModel->GetItemAt(itemIndex);
448 _DateTimeBarPresenter::SetItemStatus(int index, _DateTimeBarItemStatus status)
450 _DateTimeBarItem* pItem = __pDateTimeBarModel->GetItemAt(index);
451 SysTryReturn(NID_UI_CTRL, pItem, E_SYSTEM, E_SYSTEM,
452 "[E_SYSTEM] A system error has occurred. Failed to get _DateTimeBarItem at index (%d).", index);
454 if (status != DATETIMEBAR_ITEM_STATUS_NORMAL)
456 __pDateTimeBarModel->SetSelectedItemIndex(index);
458 pItem->SetStatus(status);
463 _DateTimeBarItemStatus
464 _DateTimeBarPresenter::GetItemStatus(int index) const
466 _DateTimeBarItem* pItem = __pDateTimeBarModel->GetItemAt(index);
467 SysTryReturn(NID_UI_CTRL, pItem, DATETIMEBAR_ITEM_STATUS_NORMAL, E_SYSTEM,
468 "[E_SYSTEM] A system error has occurred. Failed to get _DateTimeBarItem at index (%d).", index);
470 return pItem->GetStatus();
474 _DateTimeBarPresenter::GetFirstDrawnItemIndex(void) const
476 return __pDateTimeBarModel->GetFirstDrawnItemIndex();
480 _DateTimeBarPresenter::SetFirstDrawnItemIndex(int index)
482 __pDateTimeBarModel->SetFirstDrawnItemIndex(index);
487 _DateTimeBarPresenter::GetMinimumValue(void) const
489 return __pDateTimeBarModel->GetMinimumValue();
493 _DateTimeBarPresenter::SetMinimumValue(int minValue)
495 __pDateTimeBarModel->SetMinimumValue(minValue);
500 _DateTimeBarPresenter::GetMaximumValue(void) const
502 return __pDateTimeBarModel->GetMaximumValue();
506 _DateTimeBarPresenter::SetMaximumValue(int maxValue)
508 __pDateTimeBarModel->SetMaximumValue(maxValue);
513 _DateTimeBarPresenter::GetItemWidth(void) const
515 result r = E_SUCCESS;
517 _DateTimeId boxId = __pDateTimeBar->GetSelectedBoxId();
519 float itemWidth = 0.0f;
521 if (boxId == DATETIME_ID_YEAR)
523 GET_SHAPE_CONFIG(DATETIMEBAR::YEAR_ITEM_WIDTH, _ControlManager::GetInstance()->GetOrientation(), itemWidth);
525 else if (boxId == DATETIME_ID_DAY || boxId == DATETIME_ID_HOUR || boxId == DATETIME_ID_MINUTE)
527 GET_SHAPE_CONFIG(DATETIMEBAR::DAY_ITEM_WIDTH, _ControlManager::GetInstance()->GetOrientation(), itemWidth);
529 else if (boxId == DATETIME_ID_MONTH)
531 GET_SHAPE_CONFIG(DATETIMEBAR::MONTH_ITEM_WIDTH, _ControlManager::GetInstance()->GetOrientation(), itemWidth);
533 FloatDimension textArea;
536 GET_SHAPE_CONFIG(DATETIMEBAR::MONTH_FONT_SIZE, __pDateTimeBar->GetOrientation(), fontSize);
538 SysAssertf(__pFont != null, "Font instance is null");
540 (_FontImpl::GetInstance(*__pFont))->SetSize(fontSize);
541 (_FontImpl::GetInstance(*__pFont))->SetStyle(FONT_STYLE_PLAIN);
543 for (int i = DATETIME_MONTH_MIN; i <= DATETIME_MONTH_MAX; i++)
546 _DateTimeUtils dateTimeUtils;
547 string = dateTimeUtils.GetMonthString(i);
549 r = __pFont->GetTextExtent(string, string.GetLength(), textArea);
550 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
552 if (textArea.width > itemWidth)
554 itemWidth = textArea.width;
563 _DateTimeBarPresenter::GetFontSize(void) const
565 float fontSize = 0.0f;
566 _DateTimeId boxId = __pDateTimeBar->GetSelectedBoxId();
568 if (boxId == DATETIME_ID_YEAR)
570 GET_SHAPE_CONFIG(DATETIMEBAR::YEAR_FONT_SIZE, _ControlManager::GetInstance()->GetOrientation(), fontSize);
572 else if (boxId == DATETIME_ID_DAY || boxId == DATETIME_ID_HOUR || boxId == DATETIME_ID_MINUTE)
574 GET_SHAPE_CONFIG(DATETIMEBAR::DAY_FONT_SIZE, _ControlManager::GetInstance()->GetOrientation(), fontSize);
576 else if (boxId == DATETIME_ID_MONTH)
578 GET_SHAPE_CONFIG(DATETIMEBAR::MONTH_FONT_SIZE, _ControlManager::GetInstance()->GetOrientation(), fontSize);
585 _DateTimeBarPresenter::GetLeftRightMargin(void) const
587 float leftRightMargin = 0.0f;
588 _DateTimeId boxId = __pDateTimeBar->GetSelectedBoxId();
590 if (boxId == DATETIME_ID_YEAR)
592 GET_SHAPE_CONFIG(DATETIMEBAR::YEAR_LEFT_RIGHT_MARGIN, _ControlManager::GetInstance()->GetOrientation(), leftRightMargin);
594 else if (boxId == DATETIME_ID_DAY || boxId == DATETIME_ID_HOUR || boxId == DATETIME_ID_MINUTE)
596 GET_SHAPE_CONFIG(DATETIMEBAR::DAY_LEFT_RIGHT_MARGIN, _ControlManager::GetInstance()->GetOrientation(), leftRightMargin);
598 else if (boxId == DATETIME_ID_MONTH)
600 GET_SHAPE_CONFIG(DATETIMEBAR::MONTH_LEFT_RIGHT_MARGIN, _ControlManager::GetInstance()->GetOrientation(), leftRightMargin);
603 return leftRightMargin;
607 _DateTimeBarPresenter::GetItemMargin(void) const
610 _DateTimeId boxId = __pDateTimeBar->GetSelectedBoxId();
612 if (boxId == DATETIME_ID_YEAR)
614 GET_SHAPE_CONFIG(DATETIMEBAR::YEAR_ITEM_MARGIN, _ControlManager::GetInstance()->GetOrientation(), margin);
616 else if (boxId == DATETIME_ID_DAY || boxId == DATETIME_ID_HOUR || boxId == DATETIME_ID_MINUTE)
618 GET_SHAPE_CONFIG(DATETIMEBAR::DAY_ITEM_MARGIN, _ControlManager::GetInstance()->GetOrientation(), margin);
620 else if (boxId == DATETIME_ID_MONTH)
622 GET_SHAPE_CONFIG(DATETIMEBAR::MONTH_ITEM_MARGIN, _ControlManager::GetInstance()->GetOrientation(), margin);
629 _DateTimeBarPresenter::AdjustItemPosition(float distance)
633 _DateTimeBarItem* pItem = null;
634 pItem = __pDateTimeBarModel->GetItemAt(index);
636 while (pItem != null)
638 FloatRectangle bounds = pItem->GetBounds();
639 bounds.x += distance;
640 pItem->SetBounds(bounds);
643 if (index == GetItemCount())
648 pItem = __pDateTimeBarModel->GetItemAt(index);
655 _DateTimeBarPresenter::GetDisplayedText(int value) const
659 if (__pDateTimeBar->GetSelectedBoxId() == DATETIME_ID_MONTH)
662 _DateTimeUtils dateTimeUtils;
663 monthString = dateTimeUtils.GetMonthString(value);
664 string.Append(monthString);
666 else if (__pDateTimeBar->GetSelectedBoxId() == DATETIME_ID_YEAR)
668 string.Format(10, L"%04d", value);
672 string.Format(10, L"%02d", value);
679 _DateTimeBarPresenter::AddItems(int actionId)
681 result r = E_SUCCESS;
682 int cachingSize = __pDateTimeBarModel->GetMaxCachingSize() / 2;
684 int firstDrawItemIndex = cachingSize;
686 int value = actionId;
687 float startPosition = 0.0f;
688 float itemWidth = GetItemWidth();
689 float itemMargin = GetItemMargin();
691 startPosition = (GetWindowBounds().width) / 2.0f;
692 startPosition = startPosition + (itemWidth / 2.0f) + itemMargin;
693 __pDateTimeBarModel->SetItemStartPosition(startPosition);
695 while (cachingSize > 0)
699 string = GetDisplayedText(value);
701 r = __pDateTimeBarModel->AddItem(string, value, __pDateTimeBar->GetAlignment(), itemWidth, itemMargin);
702 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
708 if (__pDateTimeBarModel->GetMaximumValue() < value)
710 value = __pDateTimeBarModel->GetMinimumValue();
714 r = InsertItems(actionId -1);
715 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
717 _DateTimeBarItem* pItem = null;
718 pItem = GetItemAt(firstDrawItemIndex);
722 __selectedText.Clear();
723 __selectedText.Append(pItem->GetText().GetPointer());
726 SetItemStatus(firstDrawItemIndex, DATETIMEBAR_ITEM_STATUS_SELECTED);
732 _DateTimeBarPresenter::InsertItems(int actionId)
734 result r = E_SUCCESS;
736 int cachingSize = __pDateTimeBarModel->GetMaxCachingSize() / 2;
738 int value = actionId;
739 float itemWidth = GetItemWidth();
740 float itemMargin = GetItemMargin();
742 while (cachingSize > 0)
746 if (value < __pDateTimeBarModel->GetMinimumValue())
748 value = __pDateTimeBarModel->GetMaximumValue();
751 string = GetDisplayedText(value);
752 r = __pDateTimeBarModel->InsertItemAt(0, string, value, __pDateTimeBar->GetAlignment(), itemWidth, itemMargin);
753 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
764 _DateTimeBarPresenter::InsertItem(int index, int actionId)
766 result r = E_SUCCESS;
770 string = GetDisplayedText(actionId);
772 r = __pDateTimeBarModel->InsertItemAt(index, string, actionId, __pDateTimeBar->GetAlignment(), GetItemWidth(), GetItemMargin());
773 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
779 _DateTimeBarPresenter::AddItem(int actionId)
781 result r = E_SUCCESS;
785 string = GetDisplayedText(actionId);
787 r = __pDateTimeBarModel->AddItem(string, actionId, __pDateTimeBar->GetAlignment(), GetItemWidth(), GetItemMargin());
788 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
794 _DateTimeBarPresenter::DeleteItem(int index)
796 int itemCount = GetItemCount();
798 SysTryReturn(NID_UI_CTRL, itemCount > 0, E_INVALID_ARG, E_INVALID_ARG,
799 "[E_INVALID_ARG] Invalid argument is used. index = %d", index);
801 SysTryReturn(NID_UI_CTRL, index < itemCount, E_INVALID_ARG, E_INVALID_ARG,
802 "[E_INVALID_ARG] Invalid argument is used. index = %d", index);
804 SysTryReturn(NID_UI_CTRL, index >= 0, E_INVALID_ARG, E_INVALID_ARG,
805 "[E_INVALID_ARG] Invalid argument is used. index = %d", index);
807 result r = E_SUCCESS;
809 r = __pDateTimeBarModel->RemoveItemAt(index);
810 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
816 _DateTimeBarPresenter::RemoveAllItems(void)
818 SysTryReturn(NID_UI_CTRL, GetItemCount() > 0, E_INVALID_OPERATION, E_INVALID_OPERATION,
819 "[E_INVALID_OPERATION] Items count is zero.");
821 result r = E_SUCCESS;
823 __pDateTimeBarModel->RemoveAllItems();
829 _DateTimeBarPresenter::GetItemCount(void) const
831 return __pDateTimeBarModel->GetItemCount();
835 _DateTimeBarPresenter::GetItemAt(int index) const
837 return __pDateTimeBarModel->GetItemAt(index);
841 _DateTimeBarPresenter::CalculateWindowBounds(void)
843 _ControlOrientation orientation = _ControlManager::GetInstance()->GetOrientation();
844 FloatRectangle windowAreaBounds = FloatRectangle(0.0f, 0.0f, 0.0f, 0.0f);
845 FloatRectangle bodyAreaBounds = FloatRectangle(0.0f, 0.0f, 0.0f, 0.0f);
846 FloatRectangle arrowAreaBounds = FloatRectangle(0.0f, 0.0f, 0.0f, 0.0f);
848 FloatRectangle parentWindowBounds = __pDateTimeBar->GetParentWindowBounds();
850 arrowAreaBounds = GetArrowBounds();
854 GET_SHAPE_CONFIG(DATETIMEBAR::ARROW_HEIGHT, orientation, arrowAreaBounds.height);
855 GET_SHAPE_CONFIG(DATETIMEBAR::ARROW_WIDTH, orientation, arrowAreaBounds.width);
856 GET_SHAPE_CONFIG(DATETIMEBAR::ITEM_HEIGHT, orientation, bodyAreaBounds.height);
858 bodyAreaBounds.width = parentWindowBounds.width;
860 bodyAreaBounds.x = 0.0f;
861 FloatPoint tempPoint = __pDateTimeBar->GetPositionF();
862 windowAreaBounds.x = tempPoint.x;
864 if (__pDateTimeBar->GetAlignment() == DATETIME_BAR_ALIGN_DOWN)
866 bodyAreaBounds.y = arrowAreaBounds.height;
867 arrowAreaBounds.y = 0.0f;
868 windowAreaBounds.y = tempPoint.y - arrowAreaBounds.height;
872 arrowAreaBounds.y = bodyAreaBounds.height;
873 bodyAreaBounds.y = 0.0f;
874 windowAreaBounds.y = tempPoint.y;
877 windowAreaBounds.width = bodyAreaBounds.width;
878 windowAreaBounds.height = bodyAreaBounds.height + arrowAreaBounds.height;
880 SetBodyBounds(bodyAreaBounds);
881 SetArrowBounds(arrowAreaBounds);
882 SetWindowBounds(windowAreaBounds);
883 __pDateTimeBar->SetMovable(true);
884 __pDateTimeBar->SetResizable(true);
885 __pDateTimeBar->SetBounds(windowAreaBounds);
886 __pDateTimeBar->SetMovable(false);
887 __pDateTimeBar->SetResizable(false);
893 _DateTimeBarPresenter::SetBodyBounds(const FloatRectangle& bounds)
895 __bodyAreaBounds = bounds;
900 _DateTimeBarPresenter::GetBodyBounds(void) const
902 return __bodyAreaBounds;
906 _DateTimeBarPresenter::SetArrowBounds(const FloatRectangle& bounds)
908 __arrowAreaBounds = bounds;
913 _DateTimeBarPresenter::GetArrowBounds(void) const
915 return __arrowAreaBounds;
919 _DateTimeBarPresenter::SetWindowBounds(const FloatRectangle& bounds)
921 __windowAreaBounds = bounds;
926 _DateTimeBarPresenter::GetWindowBounds(void) const
928 return __windowAreaBounds;
932 _DateTimeBarPresenter::OnTouchPressed(const _Control& source, const _TouchInfo& touchinfo)
934 if (&source != __pDateTimeBar)
939 __isFlickEnabled = true;
941 if (GetBodyBounds().Contains(touchinfo.GetCurrentPosition()) == false)
943 __isFlickEnabled = false;
947 if (__isFlickInProgress)
949 ResetFlickAnimationTimer();
952 __touchMoveHandled = false;
954 __currentPoint = touchinfo.GetCurrentPosition();
956 int index = GetItemIndexFromPosition(touchinfo.GetCurrentPosition());
963 __pDateTimeBar->Invalidate();
969 _DateTimeBarPresenter::OnTouchReleased(const _Control& source, const _TouchInfo& touchinfo)
971 if (&source != __pDateTimeBar)
976 if (GetBodyBounds().Contains(touchinfo.GetCurrentPosition()) == false && !__isFlickInProgress && !__isTouchMoved)
978 __isTouchMoved = false;
979 PLAY_FEEDBACK(_RESOURCE_FEEDBACK_PATTERN_TAP);
980 __pDateTimeBar->SetVisibleState(false);
981 __pDateTimeBar->Close();
982 ResetFlickAnimationTimer();
983 __pDateTimeBar->FireDateTimeChangeEvent(DATE_INTERNAL_CHANGE_CANCELED);
987 int index = GetItemIndexFromPosition(touchinfo.GetCurrentPosition());
988 bool isEventFire = true;
990 if (index != -1 && __isTouchMoved == false && __isFlickInProgress == false)
992 PLAY_FEEDBACK(_RESOURCE_FEEDBACK_PATTERN_TAP);
993 SetItemStatus(index, DATETIMEBAR_ITEM_STATUS_SELECTED);
994 __pDateTimeBarModel->SetFirstDrawnItemIndex(index);
1001 __isTouchMoved = false;
1004 __pDateTimeBar->Invalidate();
1006 if (isEventFire == true)
1008 int index = GetFirstDrawnItemIndex();
1010 _DateTimeBarItem* pItem = null;
1014 pItem = GetItemAt(index);
1019 __pDateTimeBar->SetVisibleState(false);
1020 __pDateTimeBar->Close();
1022 __pDateTimeBar->FireActionEvent(pItem->GetActionId());
1024 if (__pDateTimeBar->GetSelectedBoxId() >= DATETIME_ID_YEAR && __pDateTimeBar->GetSelectedBoxId() <= DATETIME_ID_DAY)
1026 __pDateTimeBar->FireDateTimeChangeEvent(DATE_INTERNAL_CHANGE_SAVED);
1028 else if (__pDateTimeBar->GetSelectedBoxId() >= DATETIME_ID_HOUR && __pDateTimeBar->GetSelectedBoxId() <= DATETIME_ID_MINUTE)
1030 __pDateTimeBar->FireDateTimeChangeEvent(TIME_INTERNAL_CHANGE_SAVED);
1039 _DateTimeBarPresenter::OnTouchMoved(const _Control& source, const _TouchInfo& touchinfo)
1041 if (&source != __pDateTimeBar)
1046 if (GetBodyBounds().Contains(touchinfo.GetCurrentPosition()) == false || __touchMoveHandled == true)
1051 _ControlOrientation orientation = _ControlManager::GetInstance()->GetOrientation();
1053 __isTouchMoved = true;
1055 FloatDimension screen(0.0f, 0.0f);
1056 GET_DIMENSION_CONFIG(DATETIMEBAR::DEFAULT_SIZE, orientation, screen);
1058 const float _BOUNDARY_X_POSITION = screen.width * 2.0f;
1059 float distance = touchinfo.GetCurrentPosition().x - __currentPoint.x;
1061 _DateTimeBarItem* pItem = null;
1063 FloatRectangle itemBounds;
1065 bool needItem = false;
1066 int updateItemCount = 1;
1068 if (distance > 0.0f)
1070 pItem = __pDateTimeBarModel->GetItemAt(GetFirstDrawnItemIndex());
1077 itemBounds = pItem->GetBounds();
1079 __distance += distance;
1081 if (__distance > itemBounds.width / 2.0f)
1084 if (__distance > itemBounds.width)
1086 updateItemCount = UPDATE_ITEM_COUNT;
1089 if (needItem == true)
1091 while (updateItemCount > 0)
1093 pItem = __pDateTimeBarModel->GetItemAt(GetFirstDrawnItemIndex());
1099 int actionId = pItem->GetActionId() - 1;
1101 if (__pDateTimeBarModel->GetMinimumValue() > actionId)
1103 actionId = __pDateTimeBarModel->GetMaximumValue();
1106 if (pItem->GetBounds().x > _BOUNDARY_X_POSITION * -1.0f)
1108 if (InsertItem(0, actionId) == E_SUCCESS)
1110 SetFirstDrawnItemIndex(0);
1114 if (GetItemCount() >= __pDateTimeBarModel->GetMaxCachingSize())
1116 DeleteItem(GetItemCount() - 1);
1126 pItem = __pDateTimeBarModel->GetItemAt(GetItemCount() - 1);
1132 itemBounds = pItem->GetBounds();
1134 __distance += distance;
1136 if (__distance * -1.0f > itemBounds.width / 2.0f)
1139 if (__distance * -1.0f > itemBounds.width)
1141 updateItemCount = UPDATE_ITEM_COUNT;
1146 if (needItem == true)
1148 while (updateItemCount > 0)
1150 pItem = __pDateTimeBarModel->GetItemAt(GetItemCount() - 1);
1156 int actionId = pItem->GetActionId() + 1;
1158 if (__pDateTimeBarModel->GetMaximumValue() < actionId)
1160 actionId = __pDateTimeBarModel->GetMinimumValue();
1163 if (pItem->GetBounds().x < _BOUNDARY_X_POSITION)
1168 if (GetItemCount() >= __pDateTimeBarModel->GetMaxCachingSize())
1171 SetFirstDrawnItemIndex(0);
1178 __currentPoint = touchinfo.GetCurrentPosition();
1180 AdjustItemPosition(distance);
1182 __pDateTimeBar->Invalidate();
1188 _DateTimeBarPresenter::OnTouchCanceled(const _Control& source, const _TouchInfo& touchinfo)
1190 if (&source != __pDateTimeBar)
1195 __isTouchMoved = false;
1198 __pDateTimeBar->Invalidate();
1204 _DateTimeBarPresenter::LoadItems()
1206 _ControlOrientation orientation = _ControlManager::GetInstance()->GetOrientation();
1208 FloatDimension screen(0.0f, 0.0f);
1209 GET_DIMENSION_CONFIG(DATETIMEBAR::DEFAULT_SIZE, orientation, screen);
1211 const float _BOUNDARY_X_POSITION = screen.width * 2.0f;
1213 _DateTimeBarItem* pItem = null;
1215 Rectangle itemBounds;
1217 int updateItemCount = UPDATE_ITEM_COUNT;
1219 if (__distance > 0.0f)
1221 pItem = __pDateTimeBarModel->GetItemAt(GetFirstDrawnItemIndex());
1229 while (updateItemCount > 0)
1231 pItem = __pDateTimeBarModel->GetItemAt(GetFirstDrawnItemIndex());
1237 int actionId = pItem->GetActionId() - 1;
1239 if (__pDateTimeBarModel->GetMinimumValue() > actionId)
1241 actionId = __pDateTimeBarModel->GetMaximumValue();
1244 if (pItem->GetBounds().x > _BOUNDARY_X_POSITION * -1)
1246 if (InsertItem(0, actionId) == E_SUCCESS)
1248 SetFirstDrawnItemIndex(0);
1252 if (GetItemCount() >= __pDateTimeBarModel->GetMaxCachingSize())
1254 DeleteItem(GetItemCount() - 1);
1262 pItem = __pDateTimeBarModel->GetItemAt(GetItemCount() - 1);
1269 while (updateItemCount > 0)
1271 pItem = __pDateTimeBarModel->GetItemAt(GetItemCount() - 1);
1277 int actionId = pItem->GetActionId() + 1;
1279 if (__pDateTimeBarModel->GetMaximumValue() < actionId)
1281 actionId = __pDateTimeBarModel->GetMinimumValue();
1284 if (pItem->GetBounds().x < _BOUNDARY_X_POSITION)
1289 if (GetItemCount() >= __pDateTimeBarModel->GetMaxCachingSize())
1292 SetFirstDrawnItemIndex(0);
1302 _DateTimeBarPresenter::OnFlickGestureDetected(int distanceX,int distanceY,int duration)
1304 if (!__isFlickEnabled)
1309 __isFlickInProgress = true;
1310 __isInitialAnimation = false;
1315 __flickAnimation.CalculateInitializeVelocity(distanceX, 0, duration, &velX, &velY);
1316 __flickAnimation.InitializeFlickAmount(velX);
1318 StartFlickAnimationTimer();
1323 _DateTimeBarPresenter::StartFlickAnimation(void)
1328 __flickAnimation.CalculateNextMove(&moveX, &moveY);
1330 __distance = _CoordinateSystemUtils::ConvertToFloat(moveX);
1333 StartFlickAnimationTimer();
1337 AdjustItemPosition(__distance);
1343 _DateTimeBarPresenter::StartAnimationEffect(void)
1345 __isInitialAnimation = true;
1346 __distance = -10.0f;
1348 if (__initialAnimationValue >= 0.0f)
1350 __initialAnimationValue = __initialAnimationValue + __distance;
1351 StartFlickAnimationTimer();
1354 AdjustItemPosition(__distance);
1359 __initialAnimationValue = 0.0f;
1360 __isInitialAnimation = false;
1361 ResetFlickAnimationTimer();
1362 ValidateAndAdjustStartPosition();
1369 _DateTimeBarPresenter::StartFlickAnimationTimer(void)
1371 result r = E_SUCCESS;
1373 if (__pFlickAnimationTimer == null)
1375 __pFlickAnimationTimer = new (std::nothrow) Timer;
1376 SysTryReturn(NID_UI_CTRL, (__pFlickAnimationTimer != null), E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Unable to create timer.");
1378 r = __pFlickAnimationTimer->Construct(*this);
1379 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
1383 __pFlickAnimationTimer->Cancel();
1386 r = __pFlickAnimationTimer->Start(FLICK_ANIMATION_TIMER_PERIOD);
1387 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
1392 ResetFlickAnimationTimer();
1397 _DateTimeBarPresenter::ResetFlickAnimationTimer(void)
1399 if (__pFlickAnimationTimer)
1401 delete __pFlickAnimationTimer;
1402 __pFlickAnimationTimer = null;
1405 __isFlickInProgress = false;
1410 _DateTimeBarPresenter::OnTimerExpired(Timer& timer)
1412 __isFlickInProgress = false;
1413 if (&timer == __pFlickAnimationTimer)
1415 if (__isInitialAnimation)
1417 StartAnimationEffect();
1421 StartFlickAnimation();
1428 _DateTimeBarPresenter::ValidateAndAdjustStartPosition(void)
1431 float adjustPosition = 0.0f;
1432 float leftMargin = GetLeftRightMargin();
1433 FloatRectangle bodyBounds = GetBodyBounds();
1435 index = GetItemIndexFromPosition(FloatPoint(GetLeftRightMargin() + GetItemMargin(), bodyBounds.y + (bodyBounds.height / 2.0f)));
1442 _DateTimeBarItem* pDrawItem = null;
1443 pDrawItem = __pDateTimeBarModel->GetItemAt(index);
1445 if (pDrawItem == null)
1450 if (pDrawItem->GetBounds().x > 0.0f && pDrawItem->GetBounds().x < leftMargin)
1452 adjustPosition = leftMargin - pDrawItem->GetBounds().x;
1454 else if (pDrawItem->GetBounds().x < 0.0f)
1456 pDrawItem = __pDateTimeBarModel->GetItemAt(index + 1);
1457 if (pDrawItem == null)
1461 adjustPosition = leftMargin - pDrawItem->GetBounds().x;
1463 else if (pDrawItem->GetBounds().x > leftMargin)
1465 adjustPosition = leftMargin - pDrawItem->GetBounds().x;
1468 AdjustItemPosition(adjustPosition);
1474 _DateTimeBarPresenter::SetInitialAnimationValue(float animationValue)
1476 __initialAnimationValue = animationValue;
1481 _DateTimeBarPresenter::SetFont(Font& pFont)
1486 __pFont = _FontImpl::CloneN(pFont);
1487 SysTryReturnVoidResult(NID_UI_CTRL, (__pFont != null), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1493 _DateTimeBarPresenter::OnAccessibilityFocusMovedNext(const _AccessibilityContainer& control, const _AccessibilityElement& element)
1495 __distance = (GetItemWidth() + GetItemMargin()) * (-1.0f);
1497 if (element.GetBounds().x + element.GetBounds().width > GetWindowBounds().width)
1499 AdjustItemPosition(__distance);
1506 _DateTimeBarPresenter::OnAccessibilityFocusMovedPrevious(const _AccessibilityContainer& control, const _AccessibilityElement& element)
1508 __distance = (GetItemWidth() + GetItemMargin());
1510 if (element.GetBounds().x < GetWindowBounds().x)
1512 AdjustItemPosition(__distance);
1519 _DateTimeBarPresenter::OnTouchMoveHandled(const Tizen::Ui::_Control& control)
1521 __touchMoveHandled = true;
1523 __isTouchMoved = false;
1526 __pDateTimeBar->Invalidate();
1532 _DateTimeBarPresenter::RefreshAccessibilityElement(void)
1534 __pDateTimeBar->RemoveAllAccessibilityElement();
1536 for (int index = 0; index < __pDateTimeBarModel->GetItemCount(); index++)
1538 _DateTimeBarItem* pItem = __pDateTimeBarModel->GetItemAt(index);
1542 if (__pDateTimeBar->GetSelectedBoxId() == DATETIME_ID_MONTH)
1544 __pDateTimeBar->AddAccessibilityElement(pItem->GetBounds(), __pDateTimeBar->GetMonthValue(pItem->GetActionId()));
1548 __pDateTimeBar->AddAccessibilityElement(pItem->GetBounds(), pItem->GetText());
1556 }}} // Tizen::Ui::Controls