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_ResourceManager.h"
27 #include "FUiCtrl_DateTimeUtils.h"
28 #include "FUiCtrl_DateTimeBar.h"
29 #include "FUiCtrl_DateTimeBarPresenter.h"
31 using namespace Tizen::Graphics;
32 using namespace Tizen::Ui;
33 using namespace Tizen::Base;
34 using namespace Tizen::Base::Runtime;
35 using namespace Tizen::Graphics::_Text;
37 const int UPDATE_ITEM_COUNT = 3;
39 namespace Tizen { namespace Ui { namespace Controls
42 _DateTimeBarPresenter::_DateTimeBarPresenter(_DateTimeBar* pDateTimeBar)
43 : __pDateTimeBar(pDateTimeBar)
44 , __pDateTimeBarModel(null)
45 , __currentPoint(Point(0, 0))
46 , __isTouchMoved(false)
47 , __touchMoveHandled(false)
49 , __pFlickAnimationTimer(null)
52 , __bodyAreaBounds(Rectangle())
53 , __arrowAreaBounds(Rectangle())
54 , __windowAreaBounds(Rectangle())
55 , __pBgColorReplacementBitmap(null)
56 , __pArrowColorReplacementBitmap(null)
57 , __isInitialAnimation(false)
58 , __initialAnimationValue(0)
63 _DateTimeBarPresenter::~_DateTimeBarPresenter(void)
65 delete __pDateTimeBarModel;
66 __pDateTimeBarModel = 0;
68 delete __pBgColorReplacementBitmap;
69 __pBgColorReplacementBitmap = null;
71 delete __pArrowColorReplacementBitmap;
72 __pArrowColorReplacementBitmap = null;
74 delete __pFlickAnimationTimer;
75 __pFlickAnimationTimer = null;
81 _DateTimeBarPresenter*
82 _DateTimeBarPresenter::CreateInstanceN(_DateTimeBar& dateTimeBar)
86 _DateTimeBarPresenter* pDateTimeBarPresenter = new (std::nothrow) _DateTimeBarPresenter(&dateTimeBar);
87 SysTryReturn(NID_UI_CTRL, pDateTimeBarPresenter, null, E_OUT_OF_MEMORY,
88 "[E_OUT_OF_MEMORY] Memory allocation failed.");
90 pDateTimeBarPresenter->__pDateTimeBarModel = _DateTimeBarModel::CreateInstanceN();
92 SysTryCatch(NID_UI_CTRL, pDateTimeBarPresenter->__pDateTimeBarModel, , r,
93 "[%s] Propagating.", GetErrorMessage(r));
95 r = GET_SHAPE_CONFIG(DATETIMEBAR::ARROW_WIDTH, dateTimeBar.GetOrientation(), pDateTimeBarPresenter->__arrowAreaBounds.width);
96 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Failed to get arrow width from resource.", GetErrorMessage(r));
98 r = GET_SHAPE_CONFIG(DATETIMEBAR::ARROW_HEIGHT, dateTimeBar.GetOrientation(), pDateTimeBarPresenter->__arrowAreaBounds.height);
99 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Failed to get arrow height from resource.", GetErrorMessage(r));
101 r = pDateTimeBarPresenter->LoadResource();
102 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Failed to load the resources.", GetErrorMessage(r));
104 return pDateTimeBarPresenter;
107 delete pDateTimeBarPresenter;
113 _DateTimeBarPresenter::AddFlickAnimationInfo()
115 __flickAnimation.SetSensitivity(FLICK_ANIMATION_FPS_DATE_TIME_BAR, FLICK_ANIMATION_SENSITIVITY_DATE_TIME_BAR);
116 __flickAnimation.SetDirection(FD_HORIZONTAL);
120 _DateTimeBarPresenter::LoadResource(void)
122 result r = E_SUCCESS;
124 Bitmap* pBackgroundNormalBitmap = null;
126 r = GET_BITMAP_CONFIG_N(DATETIMEBAR::TIMEPICKERBAR_BG_NORMAL, BITMAP_PIXEL_FORMAT_ARGB8888, pBackgroundNormalBitmap);
127 SysTryReturn(NID_UI_CTRL, (r == E_SUCCESS), r, r, "[%s] Propagating.", GetErrorMessage(r));
129 GET_COLOR_CONFIG(DATETIMEBAR::BG_NORMAL, bgBitmapColor);
130 __pBgColorReplacementBitmap = _BitmapImpl::GetColorReplacedBitmapN(*pBackgroundNormalBitmap,
131 Color::GetColor(COLOR_ID_MAGENTA), bgBitmapColor);
132 SysTryCatch(NID_UI_CTRL, __pBgColorReplacementBitmap != null, r = GetLastResult(), GetLastResult(), "[%s] Propagating.",
133 GetErrorMessage(GetLastResult()));
135 r = LoadArrowBitmap();
136 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Failed to load resources.", GetErrorMessage(r));
138 delete pBackgroundNormalBitmap;
139 pBackgroundNormalBitmap = null;
141 AddFlickAnimationInfo();
147 delete pBackgroundNormalBitmap;
148 pBackgroundNormalBitmap = null;
150 delete __pBgColorReplacementBitmap;
151 __pBgColorReplacementBitmap = null;
157 _DateTimeBarPresenter::LoadArrowBitmap(void)
159 result r = E_SUCCESS;
161 Bitmap* pArrowNormalBitmap = null;
163 GET_COLOR_CONFIG(DATETIMEBAR::BG_NORMAL, arrowColor);
165 if (__pDateTimeBar->GetAlignment() == DATETIME_BAR_ALIGN_DOWN)
167 r = GET_BITMAP_CONFIG_N(DATETIMEBAR::TAIL_DOWN, BITMAP_PIXEL_FORMAT_ARGB8888, pArrowNormalBitmap);
168 SysTryReturn(NID_UI_CTRL, (r == E_SUCCESS), r, r, "[%s] Propagating.", GetErrorMessage(r));
172 r = GET_BITMAP_CONFIG_N(DATETIMEBAR::TAIL_UP, BITMAP_PIXEL_FORMAT_ARGB8888, pArrowNormalBitmap);
173 SysTryReturn(NID_UI_CTRL, (r == E_SUCCESS), r, r, "[%s] Propagating.", GetErrorMessage(r));
176 if (__pArrowColorReplacementBitmap != null)
178 delete __pArrowColorReplacementBitmap;
179 __pArrowColorReplacementBitmap = null;
182 __pArrowColorReplacementBitmap = _BitmapImpl::GetColorReplacedBitmapN(*pArrowNormalBitmap,
183 Color::GetColor(COLOR_ID_MAGENTA), arrowColor);
184 SysTryCatch(NID_UI_CTRL, __pArrowColorReplacementBitmap != null, r = GetLastResult(), GetLastResult(), "[%s] Propagating.",
185 GetErrorMessage(GetLastResult()));
187 delete pArrowNormalBitmap;
188 pArrowNormalBitmap = null;
194 delete pArrowNormalBitmap;
195 pArrowNormalBitmap = null;
197 delete __pArrowColorReplacementBitmap;
198 __pArrowColorReplacementBitmap = null;
204 _DateTimeBarPresenter::Draw(void)
206 result r = E_SUCCESS;
208 Canvas* pCanvas = __pDateTimeBar->GetCanvasN();
209 SysAssertf((pCanvas != null), "Failed to get canvas.");
211 pCanvas->SetBackgroundColor(Color(0, 0, 0, 0));
213 r = pCanvas->Clear();
214 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
216 r = DrawBackground(*pCanvas);
217 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
219 r = DrawArrow(*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));
234 _DateTimeBarPresenter::DrawItem(Canvas& canvas)
236 result r = E_SUCCESS;
238 Rectangle clientBounds = canvas.GetBounds();
240 _DateTimeBarItem* pDrawItem = null;
241 Rectangle itemBounds(0, 0, 0, 0);
244 Rectangle textAreaBounds(0, 0, 0, 0);
247 GET_COLOR_CONFIG(DATETIMEBAR::TEXT_NORMAL, textColor);
249 Color textPressedColor;
250 GET_COLOR_CONFIG(DATETIMEBAR::TEXT_PRESSED, textPressedColor);
252 _DateTimeBarItemStatus itemStatus = DATETIMEBAR_ITEM_STATUS_NORMAL;
254 int itemCount = GetItemCount();
256 RefreshAccessibilityElement();
258 for (int i = __pDateTimeBarModel->GetFirstDrawnItemIndex(); i < itemCount; i++)
260 pDrawItem = __pDateTimeBarModel->GetItemAt(i);
261 if (pDrawItem == null)
266 itemBounds = pDrawItem->GetBounds();
268 if (itemBounds.x + itemBounds.width <= 0)
273 textAreaBounds = Rectangle(itemBounds.x, itemBounds.y, itemBounds.width, itemBounds.height);
275 drawText = pDrawItem->GetText();
277 if (drawText.CompareTo(__selectedText) == 0)
279 pDrawItem->SetStatus(DATETIMEBAR_ITEM_STATUS_SELECTED);
282 itemStatus = pDrawItem->GetStatus();
284 int 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(textAreaBounds);
316 pTextObject->Draw(*_CanvasImpl::GetInstance(canvas));
320 if ((textAreaBounds.x + textAreaBounds.width + GetLeftRightMargin()) >= clientBounds.width)
330 _DateTimeBarPresenter::DrawBackground(Canvas& canvas)
332 result r = E_SUCCESS;
334 Rectangle bodyAreaBounds = GetBodyBounds();
336 if (__pBgColorReplacementBitmap != null)
338 if (__pBgColorReplacementBitmap->IsNinePatchedBitmap())
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 Rectangle arrowAreaBounds = GetArrowBounds();
365 if (__pArrowColorReplacementBitmap != null)
367 if (__pArrowColorReplacementBitmap->IsNinePatchedBitmap())
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 Point& point) const
398 Rectangle clientBounds = __pDateTimeBar->GetBounds();
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 Rectangle 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();
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);
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
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 int leftRightMargin = 0;
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(int distance)
628 _DateTimeBarItem* pItem = null;
629 pItem = __pDateTimeBarModel->GetItemAt(index);
631 while (pItem != null)
633 Rectangle 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 int startPosition = 0;
683 int itemWidth = GetItemWidth();
684 int itemMargin = GetItemMargin();
686 startPosition = (GetWindowBounds().width) / 2;
687 startPosition = startPosition + (itemWidth / 2) + 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 int itemWidth = GetItemWidth();
735 int 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 Rectangle windowAreaBounds = Rectangle(0, 0, 0, 0);
840 Rectangle bodyAreaBounds = Rectangle(0, 0, 0, 0);
841 Rectangle arrowAreaBounds = Rectangle(0, 0, 0, 0);
843 Rectangle parentWindowBounds = __pDateTimeBar->GetParentWindowBounds();
846 arrowAreaBounds = GetArrowBounds();
850 GET_SHAPE_CONFIG(DATETIMEBAR::ARROW_HEIGHT, orientation, arrowAreaBounds.height);
851 GET_SHAPE_CONFIG(DATETIMEBAR::ARROW_WIDTH, orientation, arrowAreaBounds.width);
853 GET_SHAPE_CONFIG(DATETIMEBAR::ITEM_HEIGHT, orientation, itemHeight);
855 bodyAreaBounds.width = parentWindowBounds.width;
856 bodyAreaBounds.height = itemHeight;
858 bodyAreaBounds.x = 0;
859 Point tempPoint = __pDateTimeBar->GetPosition();
860 windowAreaBounds.x = tempPoint.x;
862 if (__pDateTimeBar->GetAlignment() == DATETIME_BAR_ALIGN_DOWN)
864 bodyAreaBounds.y = arrowAreaBounds.height;
865 arrowAreaBounds.y = 0;
866 windowAreaBounds.y = tempPoint.y - arrowAreaBounds.height;
870 arrowAreaBounds.y = bodyAreaBounds.height;
871 bodyAreaBounds.y = 0;
872 windowAreaBounds.y = tempPoint.y;
875 windowAreaBounds.width = bodyAreaBounds.width;
876 windowAreaBounds.height = bodyAreaBounds.height + arrowAreaBounds.height;
878 SetBodyBounds(bodyAreaBounds);
879 SetArrowBounds(arrowAreaBounds);
880 SetWindowBounds(windowAreaBounds);
881 __pDateTimeBar->SetMovable(true);
882 __pDateTimeBar->SetResizable(true);
883 __pDateTimeBar->SetBounds(windowAreaBounds);
884 __pDateTimeBar->SetMovable(false);
885 __pDateTimeBar->SetResizable(false);
891 _DateTimeBarPresenter::SetBodyBounds(const Rectangle& bounds)
893 __bodyAreaBounds = bounds;
898 _DateTimeBarPresenter::GetBodyBounds(void) const
900 return __bodyAreaBounds;
904 _DateTimeBarPresenter::SetArrowBounds(const Rectangle& bounds)
906 __arrowAreaBounds = bounds;
911 _DateTimeBarPresenter::GetArrowBounds(void) const
913 return __arrowAreaBounds;
917 _DateTimeBarPresenter::SetWindowBounds(const Rectangle& bounds)
919 __windowAreaBounds = bounds;
924 _DateTimeBarPresenter::GetWindowBounds(void) const
926 return __windowAreaBounds;
930 _DateTimeBarPresenter::OnTouchPressed(const _Control& source, const _TouchInfo& touchinfo)
932 if (&source != __pDateTimeBar)
937 if (GetBodyBounds().Contains(touchinfo.GetCurrentPosition()) == false)
942 if (__isFlickEnabled)
944 ResetFlickAnimationTimer();
947 __touchMoveHandled = false;
949 __currentPoint = touchinfo.GetCurrentPosition();
951 int index = GetItemIndexFromPosition(touchinfo.GetCurrentPosition());
958 __pDateTimeBar->Draw();
964 _DateTimeBarPresenter::OnTouchReleased(const _Control& source, const _TouchInfo& touchinfo)
966 if (&source != __pDateTimeBar)
971 int index = GetItemIndexFromPosition(touchinfo.GetCurrentPosition());
972 bool isEventFire = true;
974 if (index != -1 && __isTouchMoved == false && __isFlickEnabled == false)
976 SetItemStatus(index, DATETIMEBAR_ITEM_STATUS_SELECTED);
977 __pDateTimeBarModel->SetFirstDrawnItemIndex(index);
984 __isTouchMoved = false;
987 __pDateTimeBar->Draw();
989 if (GetBodyBounds().Contains(touchinfo.GetCurrentPosition()) == false)
991 __pDateTimeBar->Close();
992 ResetFlickAnimationTimer();
996 if (isEventFire == true)
998 int index = GetFirstDrawnItemIndex();
1000 _DateTimeBarItem* pItem = null;
1004 pItem = GetItemAt(index);
1009 __pDateTimeBar->Close();
1011 __pDateTimeBar->FireActionEvent(pItem->GetActionId());
1013 if (__pDateTimeBar->GetSelectedBoxId() >= DATETIME_ID_YEAR && __pDateTimeBar->GetSelectedBoxId() <= DATETIME_ID_DAY)
1015 __pDateTimeBar->FireDateTimeChangeEvent(DATE_INTERNAL_CHANGE_SAVED);
1017 else if (__pDateTimeBar->GetSelectedBoxId() >= DATETIME_ID_HOUR && __pDateTimeBar->GetSelectedBoxId() <= DATETIME_ID_MINUTE)
1019 __pDateTimeBar->FireDateTimeChangeEvent(TIME_INTERNAL_CHANGE_SAVED);
1028 _DateTimeBarPresenter::OnTouchMoved(const _Control& source, const _TouchInfo& touchinfo)
1030 if (&source != __pDateTimeBar)
1035 if (GetBodyBounds().Contains(touchinfo.GetCurrentPosition()) == false || __touchMoveHandled == true)
1040 _ControlOrientation orientation = _ControlManager::GetInstance()->GetOrientation();
1042 __isTouchMoved = true;
1044 Dimension screen(0, 0);
1045 GET_DIMENSION_CONFIG(DATETIMEBAR::DEFAULT_SIZE, orientation, screen);
1047 const int _BOUNDARY_X_POSITION = screen.width * 2;
1048 int distance = (touchinfo.GetCurrentPosition()).x - __currentPoint.x;
1050 _DateTimeBarItem* pItem = null;
1052 Rectangle itemBounds;
1054 bool needItem = false;
1055 int updateItemCount = 1;
1059 pItem = __pDateTimeBarModel->GetItemAt(GetFirstDrawnItemIndex());
1066 itemBounds = pItem->GetBounds();
1068 __distance += distance;
1070 if (__distance > itemBounds.width / 2)
1073 if (__distance > itemBounds.width)
1075 updateItemCount = UPDATE_ITEM_COUNT;
1078 if (needItem == true)
1080 while (updateItemCount > 0)
1082 pItem = __pDateTimeBarModel->GetItemAt(GetFirstDrawnItemIndex());
1088 int actionId = pItem->GetActionId() - 1;
1090 if (__pDateTimeBarModel->GetMinimumValue() > actionId)
1092 actionId = __pDateTimeBarModel->GetMaximumValue();
1095 if (pItem->GetBounds().x > _BOUNDARY_X_POSITION * -1)
1097 if (InsertItem(0, actionId) == E_SUCCESS)
1099 SetFirstDrawnItemIndex(0);
1103 if (GetItemCount() >= __pDateTimeBarModel->GetMaxCachingSize())
1105 DeleteItem(GetItemCount() - 1);
1115 pItem = __pDateTimeBarModel->GetItemAt(GetItemCount() - 1);
1121 itemBounds = pItem->GetBounds();
1123 __distance += distance;
1125 if (__distance * -1 > itemBounds.width / 2)
1128 if (__distance * -1 > itemBounds.width)
1130 updateItemCount = UPDATE_ITEM_COUNT;
1135 if (needItem == true)
1137 while (updateItemCount > 0)
1139 pItem = __pDateTimeBarModel->GetItemAt(GetItemCount() - 1);
1145 int actionId = pItem->GetActionId() + 1;
1147 if (__pDateTimeBarModel->GetMaximumValue() < actionId)
1149 actionId = __pDateTimeBarModel->GetMinimumValue();
1152 if (pItem->GetBounds().x < _BOUNDARY_X_POSITION)
1157 if (GetItemCount() >= __pDateTimeBarModel->GetMaxCachingSize())
1160 SetFirstDrawnItemIndex(0);
1167 __currentPoint = touchinfo.GetCurrentPosition();
1169 AdjustItemPosition(distance);
1171 __pDateTimeBar->Draw();
1177 _DateTimeBarPresenter::OnTouchCanceled(const _Control& source, const _TouchInfo& touchinfo)
1179 if (&source != __pDateTimeBar)
1184 __isTouchMoved = false;
1187 __pDateTimeBar->Draw();
1193 _DateTimeBarPresenter::LoadItems()
1195 _ControlOrientation orientation = _ControlManager::GetInstance()->GetOrientation();
1197 Dimension screen(0, 0);
1198 GET_DIMENSION_CONFIG(DATETIMEBAR::DEFAULT_SIZE, orientation, screen);
1200 const int _BOUNDARY_X_POSITION = screen.width * 2;
1202 _DateTimeBarItem* pItem = null;
1204 Rectangle itemBounds;
1206 int updateItemCount = UPDATE_ITEM_COUNT;
1210 pItem = __pDateTimeBarModel->GetItemAt(GetFirstDrawnItemIndex());
1218 while (updateItemCount > 0)
1220 pItem = __pDateTimeBarModel->GetItemAt(GetFirstDrawnItemIndex());
1226 int actionId = pItem->GetActionId() - 1;
1228 if (__pDateTimeBarModel->GetMinimumValue() > actionId)
1230 actionId = __pDateTimeBarModel->GetMaximumValue();
1233 if (pItem->GetBounds().x > _BOUNDARY_X_POSITION * -1)
1235 if (InsertItem(0, actionId) == E_SUCCESS)
1237 SetFirstDrawnItemIndex(0);
1241 if (GetItemCount() >= __pDateTimeBarModel->GetMaxCachingSize())
1243 DeleteItem(GetItemCount() - 1);
1251 pItem = __pDateTimeBarModel->GetItemAt(GetItemCount() - 1);
1258 while (updateItemCount > 0)
1260 pItem = __pDateTimeBarModel->GetItemAt(GetItemCount() - 1);
1266 int actionId = pItem->GetActionId() + 1;
1268 if (__pDateTimeBarModel->GetMaximumValue() < actionId)
1270 actionId = __pDateTimeBarModel->GetMinimumValue();
1273 if (pItem->GetBounds().x < _BOUNDARY_X_POSITION)
1278 if (GetItemCount() >= __pDateTimeBarModel->GetMaxCachingSize())
1281 SetFirstDrawnItemIndex(0);
1291 _DateTimeBarPresenter::OnFlickGestureDetected(int distanceX,int distanceY,int duration)
1293 __isFlickEnabled = true;
1294 __isInitialAnimation = false;
1299 __flickAnimation.CalculateInitializeVelocity(distanceX, 0, duration, &velX, &velY);
1300 __flickAnimation.InitializeFlickAmount(velX);
1302 StartFlickAnimationTimer();
1307 _DateTimeBarPresenter::StartFlickAnimation(void)
1312 __flickAnimation.CalculateNextMove(&moveX, &moveY);
1317 StartFlickAnimationTimer();
1321 AdjustItemPosition(__distance);
1327 _DateTimeBarPresenter::StartAnimationEffect(void)
1329 __isInitialAnimation = true;
1332 if (__initialAnimationValue >= 0 )
1334 __initialAnimationValue = __initialAnimationValue + __distance;
1335 StartFlickAnimationTimer();
1338 AdjustItemPosition(__distance);
1343 __initialAnimationValue = 0;
1344 __isInitialAnimation = false;
1345 ResetFlickAnimationTimer();
1346 ValidateAndAdjustStartPosition();
1353 _DateTimeBarPresenter::StartFlickAnimationTimer(void)
1355 result r = E_SUCCESS;
1357 if (__pFlickAnimationTimer == null)
1359 __pFlickAnimationTimer = new (std::nothrow) Timer;
1360 SysTryReturn(NID_UI_CTRL, (__pFlickAnimationTimer != null), E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Unable to create timer.");
1362 r = __pFlickAnimationTimer->Construct(*this);
1363 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
1367 __pFlickAnimationTimer->Cancel();
1370 r = __pFlickAnimationTimer->Start(FLICK_ANIMATION_TIMER_PERIOD);
1371 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
1376 ResetFlickAnimationTimer();
1381 _DateTimeBarPresenter::ResetFlickAnimationTimer(void)
1383 if (__pFlickAnimationTimer)
1385 delete __pFlickAnimationTimer;
1386 __pFlickAnimationTimer = null;
1389 __isFlickEnabled = false;
1394 _DateTimeBarPresenter::OnTimerExpired(Timer& timer)
1396 if (&timer == __pFlickAnimationTimer)
1398 if (__isInitialAnimation)
1400 StartAnimationEffect();
1404 StartFlickAnimation();
1411 _DateTimeBarPresenter::ValidateAndAdjustStartPosition(void)
1414 int adjustPosition = 0;
1415 int leftMargin = GetLeftRightMargin();
1416 Rectangle bodyBounds = GetBodyBounds();
1418 index = GetItemIndexFromPosition(Point(GetLeftRightMargin() + GetItemMargin(), bodyBounds.y + (bodyBounds.height / 2)));
1425 _DateTimeBarItem* pDrawItem = null;
1426 pDrawItem = __pDateTimeBarModel->GetItemAt(index);
1428 if (pDrawItem == null)
1433 if (pDrawItem->GetBounds().x > 0 && pDrawItem->GetBounds().x < leftMargin)
1435 adjustPosition = leftMargin - pDrawItem->GetBounds().x;
1437 else if (pDrawItem->GetBounds().x < 0)
1439 pDrawItem = __pDateTimeBarModel->GetItemAt(index + 1);
1440 if (pDrawItem == null)
1444 adjustPosition = leftMargin - pDrawItem->GetBounds().x;
1446 else if (pDrawItem->GetBounds().x > leftMargin)
1448 adjustPosition = leftMargin - pDrawItem->GetBounds().x;
1451 AdjustItemPosition(adjustPosition);
1457 _DateTimeBarPresenter::SetInitialAnimationValue(int animationValue)
1459 __initialAnimationValue = animationValue;
1464 _DateTimeBarPresenter::SetFont(Font& pFont)
1469 __pFont = _FontImpl::CloneN(pFont);
1470 SysTryReturnVoidResult(NID_UI_CTRL, (__pFont != null), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1476 _DateTimeBarPresenter::OnAccessibilityFocusMovedNext(const _AccessibilityContainer& control, const _AccessibilityElement& element)
1478 __distance = (GetItemWidth() + GetItemMargin()) * (-1);
1480 if (element.GetBounds().x + element.GetBounds().width > GetWindowBounds().width)
1482 AdjustItemPosition(__distance);
1489 _DateTimeBarPresenter::OnAccessibilityFocusMovedPrevious(const _AccessibilityContainer& control, const _AccessibilityElement& element)
1491 __distance = (GetItemWidth() + GetItemMargin());
1493 if (element.GetBounds().x < GetWindowBounds().x)
1495 AdjustItemPosition(__distance);
1502 _DateTimeBarPresenter::OnTouchMoveHandled(const Tizen::Ui::_Control& control)
1504 __touchMoveHandled = true;
1506 __isTouchMoved = false;
1509 __pDateTimeBar->Draw();
1513 _DateTimeBarPresenter::RefreshAccessibilityElement(void)
1515 __pDateTimeBar->RemoveAllAccessibilityElement();
1517 for (int index = 0; index < __pDateTimeBarModel->GetItemCount(); index++)
1519 _DateTimeBarItem* pItem = __pDateTimeBarModel->GetItemAt(index);
1523 if (__pDateTimeBar->GetSelectedBoxId() == DATETIME_ID_MONTH)
1525 __pDateTimeBar->AddAccessibilityElement(pItem->GetBounds(), __pDateTimeBar->GetMonthValue(pItem->GetActionId()));
1529 __pDateTimeBar->AddAccessibilityElement(pItem->GetBounds(), pItem->GetText());
1537 }}} // Tizen::Ui::Controls