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)
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);
410 while (pItem != null)
412 FloatRectangle itemBounds = pItem->GetBounds();
414 if (itemBounds.x > clientBounds.x)
416 if (itemIndex == __pDateTimeBarModel->GetFirstDrawnItemIndex())
418 startX = itemBounds.x;
421 itemBounds.x -= startX;
424 if (itemBounds.Contains(point) == true)
431 if (itemIndex == GetItemCount())
436 pItem = __pDateTimeBarModel->GetItemAt(itemIndex);
443 _DateTimeBarPresenter::SetItemStatus(int index, _DateTimeBarItemStatus status)
445 _DateTimeBarItem* pItem = __pDateTimeBarModel->GetItemAt(index);
446 SysTryReturn(NID_UI_CTRL, pItem, E_SYSTEM, E_SYSTEM,
447 "[E_SYSTEM] A system error has occurred. Failed to get _DateTimeBarItem at index (%d).", index);
449 if (status != DATETIMEBAR_ITEM_STATUS_NORMAL)
451 __pDateTimeBarModel->SetSelectedItemIndex(index);
453 pItem->SetStatus(status);
458 _DateTimeBarItemStatus
459 _DateTimeBarPresenter::GetItemStatus(int index) const
461 _DateTimeBarItem* pItem = __pDateTimeBarModel->GetItemAt(index);
462 SysTryReturn(NID_UI_CTRL, pItem, DATETIMEBAR_ITEM_STATUS_NORMAL, E_SYSTEM,
463 "[E_SYSTEM] A system error has occurred. Failed to get _DateTimeBarItem at index (%d).", index);
465 return pItem->GetStatus();
469 _DateTimeBarPresenter::GetFirstDrawnItemIndex(void) const
471 return __pDateTimeBarModel->GetFirstDrawnItemIndex();
475 _DateTimeBarPresenter::SetFirstDrawnItemIndex(int index)
477 __pDateTimeBarModel->SetFirstDrawnItemIndex(index);
482 _DateTimeBarPresenter::GetMinimumValue(void) const
484 return __pDateTimeBarModel->GetMinimumValue();
488 _DateTimeBarPresenter::SetMinimumValue(int minValue)
490 __pDateTimeBarModel->SetMinimumValue(minValue);
495 _DateTimeBarPresenter::GetMaximumValue(void) const
497 return __pDateTimeBarModel->GetMaximumValue();
501 _DateTimeBarPresenter::SetMaximumValue(int maxValue)
503 __pDateTimeBarModel->SetMaximumValue(maxValue);
508 _DateTimeBarPresenter::GetItemWidth(void) const
510 result r = E_SUCCESS;
512 _DateTimeId boxId = __pDateTimeBar->GetSelectedBoxId();
514 float itemWidth = 0.0f;
516 if (boxId == DATETIME_ID_YEAR)
518 GET_SHAPE_CONFIG(DATETIMEBAR::YEAR_ITEM_WIDTH, _ControlManager::GetInstance()->GetOrientation(), itemWidth);
520 else if (boxId == DATETIME_ID_DAY || boxId == DATETIME_ID_HOUR || boxId == DATETIME_ID_MINUTE)
522 GET_SHAPE_CONFIG(DATETIMEBAR::DAY_ITEM_WIDTH, _ControlManager::GetInstance()->GetOrientation(), itemWidth);
524 else if (boxId == DATETIME_ID_MONTH)
526 GET_SHAPE_CONFIG(DATETIMEBAR::MONTH_ITEM_WIDTH, _ControlManager::GetInstance()->GetOrientation(), itemWidth);
528 FloatDimension textArea;
531 GET_SHAPE_CONFIG(DATETIMEBAR::MONTH_FONT_SIZE, __pDateTimeBar->GetOrientation(), fontSize);
533 SysAssertf(__pFont != null, "Font instance is null");
535 (_FontImpl::GetInstance(*__pFont))->SetSize(fontSize);
536 (_FontImpl::GetInstance(*__pFont))->SetStyle(FONT_STYLE_PLAIN);
538 for (int i = DATETIME_MONTH_MIN; i <= DATETIME_MONTH_MAX; i++)
541 _DateTimeUtils dateTimeUtils;
542 string = dateTimeUtils.GetMonthString(i);
544 r = __pFont->GetTextExtent(string, string.GetLength(), textArea);
545 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
547 if (textArea.width > itemWidth)
549 itemWidth = textArea.width;
558 _DateTimeBarPresenter::GetFontSize(void) const
560 float fontSize = 0.0f;
561 _DateTimeId boxId = __pDateTimeBar->GetSelectedBoxId();
563 if (boxId == DATETIME_ID_YEAR)
565 GET_SHAPE_CONFIG(DATETIMEBAR::YEAR_FONT_SIZE, _ControlManager::GetInstance()->GetOrientation(), fontSize);
567 else if (boxId == DATETIME_ID_DAY || boxId == DATETIME_ID_HOUR || boxId == DATETIME_ID_MINUTE)
569 GET_SHAPE_CONFIG(DATETIMEBAR::DAY_FONT_SIZE, _ControlManager::GetInstance()->GetOrientation(), fontSize);
571 else if (boxId == DATETIME_ID_MONTH)
573 GET_SHAPE_CONFIG(DATETIMEBAR::MONTH_FONT_SIZE, _ControlManager::GetInstance()->GetOrientation(), fontSize);
580 _DateTimeBarPresenter::GetLeftRightMargin(void) const
582 float leftRightMargin = 0.0f;
583 _DateTimeId boxId = __pDateTimeBar->GetSelectedBoxId();
585 if (boxId == DATETIME_ID_YEAR)
587 GET_SHAPE_CONFIG(DATETIMEBAR::YEAR_LEFT_RIGHT_MARGIN, _ControlManager::GetInstance()->GetOrientation(), leftRightMargin);
589 else if (boxId == DATETIME_ID_DAY || boxId == DATETIME_ID_HOUR || boxId == DATETIME_ID_MINUTE)
591 GET_SHAPE_CONFIG(DATETIMEBAR::DAY_LEFT_RIGHT_MARGIN, _ControlManager::GetInstance()->GetOrientation(), leftRightMargin);
593 else if (boxId == DATETIME_ID_MONTH)
595 GET_SHAPE_CONFIG(DATETIMEBAR::MONTH_LEFT_RIGHT_MARGIN, _ControlManager::GetInstance()->GetOrientation(), leftRightMargin);
598 return leftRightMargin;
602 _DateTimeBarPresenter::GetItemMargin(void) const
605 _DateTimeId boxId = __pDateTimeBar->GetSelectedBoxId();
607 if (boxId == DATETIME_ID_YEAR)
609 GET_SHAPE_CONFIG(DATETIMEBAR::YEAR_ITEM_MARGIN, _ControlManager::GetInstance()->GetOrientation(), margin);
611 else if (boxId == DATETIME_ID_DAY || boxId == DATETIME_ID_HOUR || boxId == DATETIME_ID_MINUTE)
613 GET_SHAPE_CONFIG(DATETIMEBAR::DAY_ITEM_MARGIN, _ControlManager::GetInstance()->GetOrientation(), margin);
615 else if (boxId == DATETIME_ID_MONTH)
617 GET_SHAPE_CONFIG(DATETIMEBAR::MONTH_ITEM_MARGIN, _ControlManager::GetInstance()->GetOrientation(), margin);
624 _DateTimeBarPresenter::AdjustItemPosition(float distance)
628 _DateTimeBarItem* pItem = null;
629 pItem = __pDateTimeBarModel->GetItemAt(index);
631 while (pItem != null)
633 FloatRectangle bounds = pItem->GetBounds();
634 bounds.x += distance;
635 pItem->SetBounds(bounds);
638 if (index == GetItemCount())
643 pItem = __pDateTimeBarModel->GetItemAt(index);
650 _DateTimeBarPresenter::GetDisplayedText(int value) const
654 if (__pDateTimeBar->GetSelectedBoxId() == DATETIME_ID_MONTH)
657 _DateTimeUtils dateTimeUtils;
658 monthString = dateTimeUtils.GetMonthString(value);
659 string.Append(monthString);
661 else if (__pDateTimeBar->GetSelectedBoxId() == DATETIME_ID_YEAR)
663 string.Format(10, L"%04d", value);
667 string.Format(10, L"%02d", value);
674 _DateTimeBarPresenter::AddItems(int actionId)
676 result r = E_SUCCESS;
677 int cachingSize = __pDateTimeBarModel->GetMaxCachingSize() / 2;
679 int firstDrawItemIndex = cachingSize;
681 int value = actionId;
682 float startPosition = 0.0f;
683 float itemWidth = GetItemWidth();
684 float itemMargin = GetItemMargin();
686 startPosition = (GetWindowBounds().width) / 2.0f;
687 startPosition = startPosition + (itemWidth / 2.0f) + itemMargin;
688 __pDateTimeBarModel->SetItemStartPosition(startPosition);
690 while (cachingSize > 0)
694 string = GetDisplayedText(value);
696 r = __pDateTimeBarModel->AddItem(string, value, __pDateTimeBar->GetAlignment(), itemWidth, itemMargin);
697 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
703 if (__pDateTimeBarModel->GetMaximumValue() < value)
705 value = __pDateTimeBarModel->GetMinimumValue();
709 r = InsertItems(actionId -1);
710 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
712 _DateTimeBarItem* pItem = null;
713 pItem = GetItemAt(firstDrawItemIndex);
717 __selectedText.Clear();
718 __selectedText.Append(pItem->GetText().GetPointer());
721 SetItemStatus(firstDrawItemIndex, DATETIMEBAR_ITEM_STATUS_SELECTED);
727 _DateTimeBarPresenter::InsertItems(int actionId)
729 result r = E_SUCCESS;
731 int cachingSize = __pDateTimeBarModel->GetMaxCachingSize() / 2;
733 int value = actionId;
734 float itemWidth = GetItemWidth();
735 float itemMargin = GetItemMargin();
737 while (cachingSize > 0)
741 if (value < __pDateTimeBarModel->GetMinimumValue())
743 value = __pDateTimeBarModel->GetMaximumValue();
746 string = GetDisplayedText(value);
747 r = __pDateTimeBarModel->InsertItemAt(0, string, value, __pDateTimeBar->GetAlignment(), itemWidth, itemMargin);
748 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
759 _DateTimeBarPresenter::InsertItem(int index, int actionId)
761 result r = E_SUCCESS;
765 string = GetDisplayedText(actionId);
767 r = __pDateTimeBarModel->InsertItemAt(index, string, actionId, __pDateTimeBar->GetAlignment(), GetItemWidth(), GetItemMargin());
768 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
774 _DateTimeBarPresenter::AddItem(int actionId)
776 result r = E_SUCCESS;
780 string = GetDisplayedText(actionId);
782 r = __pDateTimeBarModel->AddItem(string, actionId, __pDateTimeBar->GetAlignment(), GetItemWidth(), GetItemMargin());
783 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
789 _DateTimeBarPresenter::DeleteItem(int index)
791 int itemCount = GetItemCount();
793 SysTryReturn(NID_UI_CTRL, itemCount > 0, E_INVALID_ARG, E_INVALID_ARG,
794 "[E_INVALID_ARG] Invalid argument is used. index = %d", index);
796 SysTryReturn(NID_UI_CTRL, index < itemCount, E_INVALID_ARG, E_INVALID_ARG,
797 "[E_INVALID_ARG] Invalid argument is used. index = %d", index);
799 SysTryReturn(NID_UI_CTRL, index >= 0, E_INVALID_ARG, E_INVALID_ARG,
800 "[E_INVALID_ARG] Invalid argument is used. index = %d", index);
802 result r = E_SUCCESS;
804 r = __pDateTimeBarModel->RemoveItemAt(index);
805 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
811 _DateTimeBarPresenter::RemoveAllItems(void)
813 SysTryReturn(NID_UI_CTRL, GetItemCount() > 0, E_INVALID_OPERATION, E_INVALID_OPERATION,
814 "[E_INVALID_OPERATION] Items count is zero.");
816 result r = E_SUCCESS;
818 __pDateTimeBarModel->RemoveAllItems();
824 _DateTimeBarPresenter::GetItemCount(void) const
826 return __pDateTimeBarModel->GetItemCount();
830 _DateTimeBarPresenter::GetItemAt(int index) const
832 return __pDateTimeBarModel->GetItemAt(index);
836 _DateTimeBarPresenter::CalculateWindowBounds(void)
838 _ControlOrientation orientation = _ControlManager::GetInstance()->GetOrientation();
839 FloatRectangle windowAreaBounds = FloatRectangle(0.0f, 0.0f, 0.0f, 0.0f);
840 FloatRectangle bodyAreaBounds = FloatRectangle(0.0f, 0.0f, 0.0f, 0.0f);
841 FloatRectangle arrowAreaBounds = FloatRectangle(0.0f, 0.0f, 0.0f, 0.0f);
843 FloatRectangle parentWindowBounds = __pDateTimeBar->GetParentWindowBounds();
845 arrowAreaBounds = GetArrowBounds();
849 GET_SHAPE_CONFIG(DATETIMEBAR::ARROW_HEIGHT, orientation, arrowAreaBounds.height);
850 GET_SHAPE_CONFIG(DATETIMEBAR::ARROW_WIDTH, orientation, arrowAreaBounds.width);
851 GET_SHAPE_CONFIG(DATETIMEBAR::ITEM_HEIGHT, orientation, bodyAreaBounds.height);
853 bodyAreaBounds.width = parentWindowBounds.width;
855 bodyAreaBounds.x = 0.0f;
856 FloatPoint tempPoint = __pDateTimeBar->GetPositionF();
857 windowAreaBounds.x = tempPoint.x;
859 if (__pDateTimeBar->GetAlignment() == DATETIME_BAR_ALIGN_DOWN)
861 bodyAreaBounds.y = arrowAreaBounds.height;
862 arrowAreaBounds.y = 0.0f;
863 windowAreaBounds.y = tempPoint.y - arrowAreaBounds.height;
867 arrowAreaBounds.y = bodyAreaBounds.height;
868 bodyAreaBounds.y = 0.0f;
869 windowAreaBounds.y = tempPoint.y;
872 windowAreaBounds.width = bodyAreaBounds.width;
873 windowAreaBounds.height = bodyAreaBounds.height + arrowAreaBounds.height;
875 SetBodyBounds(bodyAreaBounds);
876 SetArrowBounds(arrowAreaBounds);
877 SetWindowBounds(windowAreaBounds);
878 __pDateTimeBar->SetMovable(true);
879 __pDateTimeBar->SetResizable(true);
880 __pDateTimeBar->SetBounds(windowAreaBounds);
881 __pDateTimeBar->SetMovable(false);
882 __pDateTimeBar->SetResizable(false);
888 _DateTimeBarPresenter::SetBodyBounds(const FloatRectangle& bounds)
890 __bodyAreaBounds = bounds;
895 _DateTimeBarPresenter::GetBodyBounds(void) const
897 return __bodyAreaBounds;
901 _DateTimeBarPresenter::SetArrowBounds(const FloatRectangle& bounds)
903 __arrowAreaBounds = bounds;
908 _DateTimeBarPresenter::GetArrowBounds(void) const
910 return __arrowAreaBounds;
914 _DateTimeBarPresenter::SetWindowBounds(const FloatRectangle& bounds)
916 __windowAreaBounds = bounds;
921 _DateTimeBarPresenter::GetWindowBounds(void) const
923 return __windowAreaBounds;
927 _DateTimeBarPresenter::OnTouchPressed(const _Control& source, const _TouchInfo& touchinfo)
929 if (&source != __pDateTimeBar)
934 __isFlickEnabled = true;
936 if (GetBodyBounds().Contains(touchinfo.GetCurrentPosition()) == false)
938 __isFlickEnabled = false;
942 if (__isFlickInProgress)
944 ResetFlickAnimationTimer();
947 __touchMoveHandled = false;
949 __currentPoint = touchinfo.GetCurrentPosition();
951 int index = GetItemIndexFromPosition(touchinfo.GetCurrentPosition());
958 __pDateTimeBar->Invalidate();
964 _DateTimeBarPresenter::OnTouchReleased(const _Control& source, const _TouchInfo& touchinfo)
966 if (&source != __pDateTimeBar)
971 if (GetBodyBounds().Contains(touchinfo.GetCurrentPosition()) == false && !__isFlickInProgress && !__isTouchMoved)
973 __isTouchMoved = false;
974 PLAY_FEEDBACK(_RESOURCE_FEEDBACK_PATTERN_TAP);
975 __pDateTimeBar->SetVisibleState(false);
976 __pDateTimeBar->Close();
977 ResetFlickAnimationTimer();
981 int index = GetItemIndexFromPosition(touchinfo.GetCurrentPosition());
982 bool isEventFire = true;
984 if (index != -1 && __isTouchMoved == false && __isFlickInProgress == false)
986 PLAY_FEEDBACK(_RESOURCE_FEEDBACK_PATTERN_TAP);
987 SetItemStatus(index, DATETIMEBAR_ITEM_STATUS_SELECTED);
988 __pDateTimeBarModel->SetFirstDrawnItemIndex(index);
995 __isTouchMoved = false;
998 __pDateTimeBar->Invalidate();
1000 if (isEventFire == true)
1002 int index = GetFirstDrawnItemIndex();
1004 _DateTimeBarItem* pItem = null;
1008 pItem = GetItemAt(index);
1013 __pDateTimeBar->SetVisibleState(false);
1014 __pDateTimeBar->Close();
1016 __pDateTimeBar->FireActionEvent(pItem->GetActionId());
1018 if (__pDateTimeBar->GetSelectedBoxId() >= DATETIME_ID_YEAR && __pDateTimeBar->GetSelectedBoxId() <= DATETIME_ID_DAY)
1020 __pDateTimeBar->FireDateTimeChangeEvent(DATE_INTERNAL_CHANGE_SAVED);
1022 else if (__pDateTimeBar->GetSelectedBoxId() >= DATETIME_ID_HOUR && __pDateTimeBar->GetSelectedBoxId() <= DATETIME_ID_MINUTE)
1024 __pDateTimeBar->FireDateTimeChangeEvent(TIME_INTERNAL_CHANGE_SAVED);
1033 _DateTimeBarPresenter::OnTouchMoved(const _Control& source, const _TouchInfo& touchinfo)
1035 if (&source != __pDateTimeBar)
1040 if (GetBodyBounds().Contains(touchinfo.GetCurrentPosition()) == false || __touchMoveHandled == true)
1045 _ControlOrientation orientation = _ControlManager::GetInstance()->GetOrientation();
1047 __isTouchMoved = true;
1049 FloatDimension screen(0.0f, 0.0f);
1050 GET_DIMENSION_CONFIG(DATETIMEBAR::DEFAULT_SIZE, orientation, screen);
1052 const float _BOUNDARY_X_POSITION = screen.width * 2.0f;
1053 float distance = touchinfo.GetCurrentPosition().x - __currentPoint.x;
1055 _DateTimeBarItem* pItem = null;
1057 FloatRectangle itemBounds;
1059 bool needItem = false;
1060 int updateItemCount = 1;
1062 if (distance > 0.0f)
1064 pItem = __pDateTimeBarModel->GetItemAt(GetFirstDrawnItemIndex());
1071 itemBounds = pItem->GetBounds();
1073 __distance += distance;
1075 if (__distance > itemBounds.width / 2.0f)
1078 if (__distance > itemBounds.width)
1080 updateItemCount = UPDATE_ITEM_COUNT;
1083 if (needItem == true)
1085 while (updateItemCount > 0)
1087 pItem = __pDateTimeBarModel->GetItemAt(GetFirstDrawnItemIndex());
1093 int actionId = pItem->GetActionId() - 1;
1095 if (__pDateTimeBarModel->GetMinimumValue() > actionId)
1097 actionId = __pDateTimeBarModel->GetMaximumValue();
1100 if (pItem->GetBounds().x > _BOUNDARY_X_POSITION * -1.0f)
1102 if (InsertItem(0, actionId) == E_SUCCESS)
1104 SetFirstDrawnItemIndex(0);
1108 if (GetItemCount() >= __pDateTimeBarModel->GetMaxCachingSize())
1110 DeleteItem(GetItemCount() - 1);
1120 pItem = __pDateTimeBarModel->GetItemAt(GetItemCount() - 1);
1126 itemBounds = pItem->GetBounds();
1128 __distance += distance;
1130 if (__distance * -1.0f > itemBounds.width / 2.0f)
1133 if (__distance * -1.0f > itemBounds.width)
1135 updateItemCount = UPDATE_ITEM_COUNT;
1140 if (needItem == true)
1142 while (updateItemCount > 0)
1144 pItem = __pDateTimeBarModel->GetItemAt(GetItemCount() - 1);
1150 int actionId = pItem->GetActionId() + 1;
1152 if (__pDateTimeBarModel->GetMaximumValue() < actionId)
1154 actionId = __pDateTimeBarModel->GetMinimumValue();
1157 if (pItem->GetBounds().x < _BOUNDARY_X_POSITION)
1162 if (GetItemCount() >= __pDateTimeBarModel->GetMaxCachingSize())
1165 SetFirstDrawnItemIndex(0);
1172 __currentPoint = touchinfo.GetCurrentPosition();
1174 AdjustItemPosition(distance);
1176 __pDateTimeBar->Invalidate();
1182 _DateTimeBarPresenter::OnTouchCanceled(const _Control& source, const _TouchInfo& touchinfo)
1184 if (&source != __pDateTimeBar)
1189 __isTouchMoved = false;
1192 __pDateTimeBar->Invalidate();
1198 _DateTimeBarPresenter::LoadItems()
1200 _ControlOrientation orientation = _ControlManager::GetInstance()->GetOrientation();
1202 FloatDimension screen(0.0f, 0.0f);
1203 GET_DIMENSION_CONFIG(DATETIMEBAR::DEFAULT_SIZE, orientation, screen);
1205 const float _BOUNDARY_X_POSITION = screen.width * 2.0f;
1207 _DateTimeBarItem* pItem = null;
1209 Rectangle itemBounds;
1211 int updateItemCount = UPDATE_ITEM_COUNT;
1213 if (__distance > 0.0f)
1215 pItem = __pDateTimeBarModel->GetItemAt(GetFirstDrawnItemIndex());
1223 while (updateItemCount > 0)
1225 pItem = __pDateTimeBarModel->GetItemAt(GetFirstDrawnItemIndex());
1231 int actionId = pItem->GetActionId() - 1;
1233 if (__pDateTimeBarModel->GetMinimumValue() > actionId)
1235 actionId = __pDateTimeBarModel->GetMaximumValue();
1238 if (pItem->GetBounds().x > _BOUNDARY_X_POSITION * -1)
1240 if (InsertItem(0, actionId) == E_SUCCESS)
1242 SetFirstDrawnItemIndex(0);
1246 if (GetItemCount() >= __pDateTimeBarModel->GetMaxCachingSize())
1248 DeleteItem(GetItemCount() - 1);
1256 pItem = __pDateTimeBarModel->GetItemAt(GetItemCount() - 1);
1263 while (updateItemCount > 0)
1265 pItem = __pDateTimeBarModel->GetItemAt(GetItemCount() - 1);
1271 int actionId = pItem->GetActionId() + 1;
1273 if (__pDateTimeBarModel->GetMaximumValue() < actionId)
1275 actionId = __pDateTimeBarModel->GetMinimumValue();
1278 if (pItem->GetBounds().x < _BOUNDARY_X_POSITION)
1283 if (GetItemCount() >= __pDateTimeBarModel->GetMaxCachingSize())
1286 SetFirstDrawnItemIndex(0);
1296 _DateTimeBarPresenter::OnFlickGestureDetected(int distanceX,int distanceY,int duration)
1298 if (!__isFlickEnabled)
1303 __isFlickInProgress = true;
1304 __isInitialAnimation = false;
1309 __flickAnimation.CalculateInitializeVelocity(distanceX, 0, duration, &velX, &velY);
1310 __flickAnimation.InitializeFlickAmount(velX);
1312 StartFlickAnimationTimer();
1317 _DateTimeBarPresenter::StartFlickAnimation(void)
1322 __flickAnimation.CalculateNextMove(&moveX, &moveY);
1324 __distance = _CoordinateSystemUtils::ConvertToFloat(moveX);
1327 StartFlickAnimationTimer();
1331 AdjustItemPosition(__distance);
1337 _DateTimeBarPresenter::StartAnimationEffect(void)
1339 __isInitialAnimation = true;
1340 __distance = -10.0f;
1342 if (__initialAnimationValue >= 0 )
1344 __initialAnimationValue = __initialAnimationValue + _CoordinateSystemUtils::ConvertToInteger(__distance);
1345 StartFlickAnimationTimer();
1348 AdjustItemPosition(__distance);
1353 __initialAnimationValue = 0;
1354 __isInitialAnimation = false;
1355 ResetFlickAnimationTimer();
1356 ValidateAndAdjustStartPosition();
1363 _DateTimeBarPresenter::StartFlickAnimationTimer(void)
1365 result r = E_SUCCESS;
1367 if (__pFlickAnimationTimer == null)
1369 __pFlickAnimationTimer = new (std::nothrow) Timer;
1370 SysTryReturn(NID_UI_CTRL, (__pFlickAnimationTimer != null), E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Unable to create timer.");
1372 r = __pFlickAnimationTimer->Construct(*this);
1373 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
1377 __pFlickAnimationTimer->Cancel();
1380 r = __pFlickAnimationTimer->Start(FLICK_ANIMATION_TIMER_PERIOD);
1381 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
1386 ResetFlickAnimationTimer();
1391 _DateTimeBarPresenter::ResetFlickAnimationTimer(void)
1393 if (__pFlickAnimationTimer)
1395 delete __pFlickAnimationTimer;
1396 __pFlickAnimationTimer = null;
1399 __isFlickInProgress = false;
1404 _DateTimeBarPresenter::OnTimerExpired(Timer& timer)
1406 __isFlickInProgress = false;
1407 if (&timer == __pFlickAnimationTimer)
1409 if (__isInitialAnimation)
1411 StartAnimationEffect();
1415 StartFlickAnimation();
1422 _DateTimeBarPresenter::ValidateAndAdjustStartPosition(void)
1425 float adjustPosition = 0.0f;
1426 float leftMargin = GetLeftRightMargin();
1427 FloatRectangle bodyBounds = GetBodyBounds();
1429 index = GetItemIndexFromPosition(FloatPoint(GetLeftRightMargin() + GetItemMargin(), bodyBounds.y + (bodyBounds.height / 2.0f)));
1436 _DateTimeBarItem* pDrawItem = null;
1437 pDrawItem = __pDateTimeBarModel->GetItemAt(index);
1439 if (pDrawItem == null)
1444 if (pDrawItem->GetBounds().x > 0.0f && pDrawItem->GetBounds().x < leftMargin)
1446 adjustPosition = leftMargin - pDrawItem->GetBounds().x;
1448 else if (pDrawItem->GetBounds().x < 0.0f)
1450 pDrawItem = __pDateTimeBarModel->GetItemAt(index + 1);
1451 if (pDrawItem == null)
1455 adjustPosition = leftMargin - pDrawItem->GetBounds().x;
1457 else if (pDrawItem->GetBounds().x > leftMargin)
1459 adjustPosition = leftMargin - pDrawItem->GetBounds().x;
1462 AdjustItemPosition(adjustPosition);
1468 _DateTimeBarPresenter::SetInitialAnimationValue(int animationValue)
1470 __initialAnimationValue = animationValue;
1475 _DateTimeBarPresenter::SetFont(Font& pFont)
1480 __pFont = _FontImpl::CloneN(pFont);
1481 SysTryReturnVoidResult(NID_UI_CTRL, (__pFont != null), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1487 _DateTimeBarPresenter::OnAccessibilityFocusMovedNext(const _AccessibilityContainer& control, const _AccessibilityElement& element)
1489 __distance = (GetItemWidth() + GetItemMargin()) * (-1.0f);
1491 if (element.GetBounds().x + element.GetBounds().width > GetWindowBounds().width)
1493 AdjustItemPosition(__distance);
1500 _DateTimeBarPresenter::OnAccessibilityFocusMovedPrevious(const _AccessibilityContainer& control, const _AccessibilityElement& element)
1502 __distance = (GetItemWidth() + GetItemMargin());
1504 if (element.GetBounds().x < GetWindowBounds().x)
1506 AdjustItemPosition(__distance);
1513 _DateTimeBarPresenter::OnTouchMoveHandled(const Tizen::Ui::_Control& control)
1515 __touchMoveHandled = true;
1517 __isTouchMoved = false;
1520 __pDateTimeBar->Invalidate();
1526 _DateTimeBarPresenter::RefreshAccessibilityElement(void)
1528 __pDateTimeBar->RemoveAllAccessibilityElement();
1530 for (int index = 0; index < __pDateTimeBarModel->GetItemCount(); index++)
1532 _DateTimeBarItem* pItem = __pDateTimeBarModel->GetItemAt(index);
1536 if (__pDateTimeBar->GetSelectedBoxId() == DATETIME_ID_MONTH)
1538 __pDateTimeBar->AddAccessibilityElement(pItem->GetBounds(), __pDateTimeBar->GetMonthValue(pItem->GetActionId()));
1542 __pDateTimeBar->AddAccessibilityElement(pItem->GetBounds(), pItem->GetText());
1550 }}} // Tizen::Ui::Controls