2 // Open Service Platform
3 // Copyright (c) 2012-2013 Samsung Electronics Co., Ltd.
5 // Licensed under the Apache License, Version 2.0 (the License);
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
9 // http://www.apache.org/licenses/LICENSE-2.0/
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
19 * @file FUiCtrl_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 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 drawText = pDrawItem->GetText();
275 if (drawText.CompareTo(__selectedText) == 0)
277 pDrawItem->SetStatus(DATETIMEBAR_ITEM_STATUS_SELECTED);
280 itemStatus = pDrawItem->GetStatus();
282 float fontSize = GetFontSize();
284 TextSimple* pSimpleText = null;
285 TextObject* pTextObject = new (std::nothrow) TextObject;
286 SysTryReturn(NID_UI_CTRL, (pTextObject != null), E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
288 pTextObject->Construct();
289 pSimpleText = new (std::nothrow)TextSimple((const_cast <wchar_t*>(drawText.GetPointer())), drawText.GetLength(), TEXT_ELEMENT_SOURCE_TYPE_EXTERNAL);
290 pTextObject->AppendElement(*pSimpleText);
292 pTextObject->SetAlignment(TEXT_OBJECT_ALIGNMENT_CENTER | TEXT_OBJECT_ALIGNMENT_MIDDLE);
293 pTextObject->SetWrap(TEXT_OBJECT_WRAP_TYPE_NONE);
294 pTextObject->SetAction(TEXT_OBJECT_ACTION_TYPE_ABBREV);
296 SysAssertf(__pFont != null, "Font instance is null");
298 if (itemStatus == DATETIMEBAR_ITEM_STATUS_SELECTED)
300 (_FontImpl::GetInstance(*__pFont))->SetSize(fontSize);
301 (_FontImpl::GetInstance(*__pFont))->SetStyle(FONT_STYLE_BOLD);
302 pTextObject->SetFont(__pFont, 0, pTextObject->GetTextLength());
303 pTextObject->SetForegroundColor(textPressedColor, 0, pTextObject->GetTextLength());
307 (_FontImpl::GetInstance(*__pFont))->SetSize(fontSize);
308 (_FontImpl::GetInstance(*__pFont))->SetStyle(FONT_STYLE_PLAIN);
309 pTextObject->SetFont(__pFont, 0, pTextObject->GetTextLength());
310 pTextObject->SetForegroundColor(textColor, 0, pTextObject->GetTextLength());
313 pTextObject->SetBounds(itemBounds);
314 pTextObject->Draw(*_CanvasImpl::GetInstance(canvas));
318 if ((itemBounds.x + itemBounds.width + GetLeftRightMargin()) >= clientBounds.width)
328 _DateTimeBarPresenter::DrawBackground(Canvas& canvas)
330 result r = E_SUCCESS;
332 FloatRectangle bodyAreaBounds = GetBodyBounds();
334 if (__pBgColorReplacementBitmap != null)
336 if (_BitmapImpl::CheckNinePatchedBitmapStrictly(*__pBgColorReplacementBitmap))
338 r = canvas.DrawNinePatchedBitmap(bodyAreaBounds, *__pBgColorReplacementBitmap);
339 SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Propagating.");
343 r = canvas.DrawBitmap(bodyAreaBounds, *__pBgColorReplacementBitmap);
344 SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Propagating.");
350 r = canvas.DrawRectangle(bodyAreaBounds);
351 SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Propagating.");
358 _DateTimeBarPresenter::DrawArrow(Canvas& canvas)
360 result r = E_SUCCESS;
361 FloatRectangle arrowAreaBounds = GetArrowBounds();
363 if (__pArrowColorReplacementBitmap != null)
365 if (_BitmapImpl::CheckNinePatchedBitmapStrictly(*__pArrowColorReplacementBitmap))
367 r = canvas.DrawNinePatchedBitmap(arrowAreaBounds, *__pArrowColorReplacementBitmap);
368 SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Propagating.");
372 r = canvas.DrawBitmap(arrowAreaBounds, *__pArrowColorReplacementBitmap);
373 SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Propagating.");
381 _DateTimeBarPresenter::SetItemSelected(int index)
383 __pDateTimeBarModel->SetSelectedItemIndex(index);
388 _DateTimeBarPresenter::GetSelectedItemIndex(void) const
390 return __pDateTimeBarModel->GetSelectedItemIndex();
394 _DateTimeBarPresenter::GetItemIndexFromPosition(const FloatPoint& point) const
396 FloatRectangle clientBounds = __pDateTimeBar->GetBoundsF();
398 if (point.x > clientBounds.width
399 || point.y > clientBounds.height)
404 int itemIndex = __pDateTimeBarModel->GetFirstDrawnItemIndex();
405 _DateTimeBarItem* pItem = __pDateTimeBarModel->GetItemAt(itemIndex);
407 float itemMargin = 0.0f;
408 itemMargin = GetItemMargin();
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 itemBounds.x = itemBounds.x - (itemMargin / 2.0f);
425 itemBounds.width = itemBounds.width + itemMargin;
427 if (itemBounds.Contains(point) == true)
434 if (itemIndex == GetItemCount())
439 pItem = __pDateTimeBarModel->GetItemAt(itemIndex);
446 _DateTimeBarPresenter::SetItemStatus(int index, _DateTimeBarItemStatus status)
448 _DateTimeBarItem* pItem = __pDateTimeBarModel->GetItemAt(index);
449 SysTryReturn(NID_UI_CTRL, pItem, E_SYSTEM, E_SYSTEM,
450 "[E_SYSTEM] A system error has occurred. Failed to get _DateTimeBarItem at index (%d).", index);
452 if (status != DATETIMEBAR_ITEM_STATUS_NORMAL)
454 __pDateTimeBarModel->SetSelectedItemIndex(index);
456 pItem->SetStatus(status);
461 _DateTimeBarItemStatus
462 _DateTimeBarPresenter::GetItemStatus(int index) const
464 _DateTimeBarItem* pItem = __pDateTimeBarModel->GetItemAt(index);
465 SysTryReturn(NID_UI_CTRL, pItem, DATETIMEBAR_ITEM_STATUS_NORMAL, E_SYSTEM,
466 "[E_SYSTEM] A system error has occurred. Failed to get _DateTimeBarItem at index (%d).", index);
468 return pItem->GetStatus();
472 _DateTimeBarPresenter::GetFirstDrawnItemIndex(void) const
474 return __pDateTimeBarModel->GetFirstDrawnItemIndex();
478 _DateTimeBarPresenter::SetFirstDrawnItemIndex(int index)
480 __pDateTimeBarModel->SetFirstDrawnItemIndex(index);
485 _DateTimeBarPresenter::GetMinimumValue(void) const
487 return __pDateTimeBarModel->GetMinimumValue();
491 _DateTimeBarPresenter::SetMinimumValue(int minValue)
493 __pDateTimeBarModel->SetMinimumValue(minValue);
498 _DateTimeBarPresenter::GetMaximumValue(void) const
500 return __pDateTimeBarModel->GetMaximumValue();
504 _DateTimeBarPresenter::SetMaximumValue(int maxValue)
506 __pDateTimeBarModel->SetMaximumValue(maxValue);
511 _DateTimeBarPresenter::GetItemWidth(void) const
513 result r = E_SUCCESS;
515 _DateTimeId boxId = __pDateTimeBar->GetSelectedBoxId();
517 float itemWidth = 0.0f;
519 if (boxId == DATETIME_ID_YEAR)
521 GET_SHAPE_CONFIG(DATETIMEBAR::YEAR_ITEM_WIDTH, _ControlManager::GetInstance()->GetOrientation(), itemWidth);
523 else if (boxId == DATETIME_ID_DAY || boxId == DATETIME_ID_HOUR || boxId == DATETIME_ID_MINUTE)
525 GET_SHAPE_CONFIG(DATETIMEBAR::DAY_ITEM_WIDTH, _ControlManager::GetInstance()->GetOrientation(), itemWidth);
527 else if (boxId == DATETIME_ID_MONTH)
529 GET_SHAPE_CONFIG(DATETIMEBAR::MONTH_ITEM_WIDTH, _ControlManager::GetInstance()->GetOrientation(), itemWidth);
531 FloatDimension textArea;
534 GET_SHAPE_CONFIG(DATETIMEBAR::MONTH_FONT_SIZE, __pDateTimeBar->GetOrientation(), fontSize);
536 SysAssertf(__pFont != null, "Font instance is null");
538 (_FontImpl::GetInstance(*__pFont))->SetSize(fontSize);
539 (_FontImpl::GetInstance(*__pFont))->SetStyle(FONT_STYLE_PLAIN);
541 for (int i = DATETIME_MONTH_MIN; i <= DATETIME_MONTH_MAX; i++)
544 _DateTimeUtils dateTimeUtils;
545 string = dateTimeUtils.GetMonthString(i);
547 r = __pFont->GetTextExtent(string, string.GetLength(), textArea);
548 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
550 if (textArea.width > itemWidth)
552 itemWidth = textArea.width;
561 _DateTimeBarPresenter::GetFontSize(void) const
563 float fontSize = 0.0f;
564 _DateTimeId boxId = __pDateTimeBar->GetSelectedBoxId();
566 if (boxId == DATETIME_ID_YEAR)
568 GET_SHAPE_CONFIG(DATETIMEBAR::YEAR_FONT_SIZE, _ControlManager::GetInstance()->GetOrientation(), fontSize);
570 else if (boxId == DATETIME_ID_DAY || boxId == DATETIME_ID_HOUR || boxId == DATETIME_ID_MINUTE)
572 GET_SHAPE_CONFIG(DATETIMEBAR::DAY_FONT_SIZE, _ControlManager::GetInstance()->GetOrientation(), fontSize);
574 else if (boxId == DATETIME_ID_MONTH)
576 GET_SHAPE_CONFIG(DATETIMEBAR::MONTH_FONT_SIZE, _ControlManager::GetInstance()->GetOrientation(), fontSize);
583 _DateTimeBarPresenter::GetLeftRightMargin(void) const
585 float leftRightMargin = 0.0f;
586 _DateTimeId boxId = __pDateTimeBar->GetSelectedBoxId();
588 if (boxId == DATETIME_ID_YEAR)
590 GET_SHAPE_CONFIG(DATETIMEBAR::YEAR_LEFT_RIGHT_MARGIN, _ControlManager::GetInstance()->GetOrientation(), leftRightMargin);
592 else if (boxId == DATETIME_ID_DAY || boxId == DATETIME_ID_HOUR || boxId == DATETIME_ID_MINUTE)
594 GET_SHAPE_CONFIG(DATETIMEBAR::DAY_LEFT_RIGHT_MARGIN, _ControlManager::GetInstance()->GetOrientation(), leftRightMargin);
596 else if (boxId == DATETIME_ID_MONTH)
598 GET_SHAPE_CONFIG(DATETIMEBAR::MONTH_LEFT_RIGHT_MARGIN, _ControlManager::GetInstance()->GetOrientation(), leftRightMargin);
601 return leftRightMargin;
605 _DateTimeBarPresenter::GetItemMargin(void) const
608 _DateTimeId boxId = __pDateTimeBar->GetSelectedBoxId();
610 if (boxId == DATETIME_ID_YEAR)
612 GET_SHAPE_CONFIG(DATETIMEBAR::YEAR_ITEM_MARGIN, _ControlManager::GetInstance()->GetOrientation(), margin);
614 else if (boxId == DATETIME_ID_DAY || boxId == DATETIME_ID_HOUR || boxId == DATETIME_ID_MINUTE)
616 GET_SHAPE_CONFIG(DATETIMEBAR::DAY_ITEM_MARGIN, _ControlManager::GetInstance()->GetOrientation(), margin);
618 else if (boxId == DATETIME_ID_MONTH)
620 GET_SHAPE_CONFIG(DATETIMEBAR::MONTH_ITEM_MARGIN, _ControlManager::GetInstance()->GetOrientation(), margin);
627 _DateTimeBarPresenter::AdjustItemPosition(float distance)
631 _DateTimeBarItem* pItem = null;
633 pItem = __pDateTimeBarModel->GetItemAt(index);
635 while (pItem != null)
637 FloatRectangle bounds = pItem->GetBounds();
638 bounds.x += distance;
639 pItem->SetBounds(bounds);
642 if (index == GetItemCount())
647 pItem = __pDateTimeBarModel->GetItemAt(index);
650 return AdjustAccessibilityElementPosition(distance);
654 _DateTimeBarPresenter::AdjustAccessibilityElementPosition(float distance)
656 _AccessibilityElement* pAccessibilityElement = null;
660 pAccessibilityElement = __pDateTimeBar->GetAccessibilityElementAt(index);
662 while (pAccessibilityElement != null)
664 FloatRectangle bounds = pAccessibilityElement->GetBounds();
665 bounds.x += distance;
666 pAccessibilityElement->SetBounds(bounds);
669 if (index == GetItemCount())
674 pAccessibilityElement = __pDateTimeBar->GetAccessibilityElementAt(index);
681 _DateTimeBarPresenter::GetDisplayedText(int value) const
685 if (__pDateTimeBar->GetSelectedBoxId() == DATETIME_ID_MONTH)
688 _DateTimeUtils dateTimeUtils;
689 monthString = dateTimeUtils.GetMonthString(value);
690 string.Append(monthString);
692 else if (__pDateTimeBar->GetSelectedBoxId() == DATETIME_ID_YEAR)
694 string.Format(10, L"%04d", value);
698 string.Format(10, L"%02d", value);
705 _DateTimeBarPresenter::AddItems(int actionId)
707 result r = E_SUCCESS;
708 int cachingSize = __pDateTimeBarModel->GetMaxCachingSize() / 2;
710 int firstDrawItemIndex = cachingSize;
712 int value = actionId;
713 float startPosition = 0.0f;
714 float itemWidth = GetItemWidth();
715 float itemMargin = GetItemMargin();
717 startPosition = (GetWindowBounds().width) / 2.0f;
718 startPosition = startPosition + (itemWidth / 2.0f) + itemMargin;
719 __pDateTimeBarModel->SetItemStartPosition(startPosition);
721 while (cachingSize > 0)
725 string = GetDisplayedText(value);
727 r = __pDateTimeBarModel->AddItem(string, value, __pDateTimeBar->GetAlignment(), itemWidth, itemMargin);
728 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
730 AddAccessibilityElement();
735 if (__pDateTimeBarModel->GetMaximumValue() < value)
737 value = __pDateTimeBarModel->GetMinimumValue();
741 r = InsertItems(actionId -1);
742 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
744 _DateTimeBarItem* pItem = null;
745 pItem = GetItemAt(firstDrawItemIndex);
749 __selectedText.Clear();
750 __selectedText.Append(pItem->GetText().GetPointer());
753 SetItemStatus(firstDrawItemIndex, DATETIMEBAR_ITEM_STATUS_SELECTED);
759 _DateTimeBarPresenter::InsertItems(int actionId)
761 result r = E_SUCCESS;
763 int cachingSize = __pDateTimeBarModel->GetMaxCachingSize() / 2;
765 int value = actionId;
766 float itemWidth = GetItemWidth();
767 float itemMargin = GetItemMargin();
769 while (cachingSize > 0)
773 if (value < __pDateTimeBarModel->GetMinimumValue())
775 value = __pDateTimeBarModel->GetMaximumValue();
778 string = GetDisplayedText(value);
779 r = __pDateTimeBarModel->InsertItemAt(0, string, value, __pDateTimeBar->GetAlignment(), itemWidth, itemMargin);
780 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
781 InsertAccessibilityElementAt(0);
791 _DateTimeBarPresenter::InsertItem(int index, int actionId)
793 result r = E_SUCCESS;
797 string = GetDisplayedText(actionId);
799 r = __pDateTimeBarModel->InsertItemAt(index, string, actionId, __pDateTimeBar->GetAlignment(), GetItemWidth(), GetItemMargin());
800 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
801 InsertAccessibilityElementAt(index);
806 _DateTimeBarPresenter::AddItem(int actionId)
808 result r = E_SUCCESS;
812 string = GetDisplayedText(actionId);
814 r = __pDateTimeBarModel->AddItem(string, actionId, __pDateTimeBar->GetAlignment(), GetItemWidth(), GetItemMargin());
815 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
817 AddAccessibilityElement();
822 _DateTimeBarPresenter::DeleteItem(int index)
824 int itemCount = GetItemCount();
826 SysTryReturn(NID_UI_CTRL, itemCount > 0, E_INVALID_ARG, E_INVALID_ARG,
827 "[E_INVALID_ARG] Invalid argument is used. index = %d", index);
829 SysTryReturn(NID_UI_CTRL, index < itemCount, E_INVALID_ARG, E_INVALID_ARG,
830 "[E_INVALID_ARG] Invalid argument is used. index = %d", index);
832 SysTryReturn(NID_UI_CTRL, index >= 0, E_INVALID_ARG, E_INVALID_ARG,
833 "[E_INVALID_ARG] Invalid argument is used. index = %d", index);
835 result r = E_SUCCESS;
837 r = __pDateTimeBarModel->RemoveItemAt(index);
838 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
840 __pDateTimeBar->RemoveAccessibilityElementAt(index);
846 _DateTimeBarPresenter::RemoveAllItems(void)
848 SysTryReturn(NID_UI_CTRL, GetItemCount() > 0, E_INVALID_OPERATION, E_INVALID_OPERATION,
849 "[E_INVALID_OPERATION] Items count is zero.");
851 result r = E_SUCCESS;
853 __pDateTimeBarModel->RemoveAllItems();
855 __pDateTimeBar->RemoveAllAccessibilityElement();
861 _DateTimeBarPresenter::GetItemCount(void) const
863 return __pDateTimeBarModel->GetItemCount();
867 _DateTimeBarPresenter::GetItemAt(int index) const
869 return __pDateTimeBarModel->GetItemAt(index);
873 _DateTimeBarPresenter::CalculateWindowBounds(void)
875 _ControlOrientation orientation = _ControlManager::GetInstance()->GetOrientation();
876 FloatRectangle windowAreaBounds = FloatRectangle(0.0f, 0.0f, 0.0f, 0.0f);
877 FloatRectangle bodyAreaBounds = FloatRectangle(0.0f, 0.0f, 0.0f, 0.0f);
878 FloatRectangle arrowAreaBounds = FloatRectangle(0.0f, 0.0f, 0.0f, 0.0f);
880 FloatRectangle parentWindowBounds = __pDateTimeBar->GetParentWindowBounds();
882 arrowAreaBounds = GetArrowBounds();
886 GET_SHAPE_CONFIG(DATETIMEBAR::ARROW_HEIGHT, orientation, arrowAreaBounds.height);
887 GET_SHAPE_CONFIG(DATETIMEBAR::ARROW_WIDTH, orientation, arrowAreaBounds.width);
888 GET_SHAPE_CONFIG(DATETIMEBAR::ITEM_HEIGHT, orientation, bodyAreaBounds.height);
890 bodyAreaBounds.width = parentWindowBounds.width;
892 bodyAreaBounds.x = 0.0f;
893 FloatPoint tempPoint = __pDateTimeBar->GetPositionF();
894 windowAreaBounds.x = tempPoint.x;
896 if (__pDateTimeBar->GetAlignment() == DATETIME_BAR_ALIGN_DOWN)
898 bodyAreaBounds.y = arrowAreaBounds.height;
899 arrowAreaBounds.y = 0.0f;
900 windowAreaBounds.y = tempPoint.y - arrowAreaBounds.height;
904 arrowAreaBounds.y = bodyAreaBounds.height;
905 bodyAreaBounds.y = 0.0f;
906 windowAreaBounds.y = tempPoint.y;
909 windowAreaBounds.width = bodyAreaBounds.width;
910 windowAreaBounds.height = bodyAreaBounds.height + arrowAreaBounds.height;
912 SetBodyBounds(bodyAreaBounds);
913 SetArrowBounds(arrowAreaBounds);
914 SetWindowBounds(windowAreaBounds);
915 __pDateTimeBar->SetMovable(true);
916 __pDateTimeBar->SetResizable(true);
917 __pDateTimeBar->SetBounds(windowAreaBounds);
918 __pDateTimeBar->SetMovable(false);
919 __pDateTimeBar->SetResizable(false);
925 _DateTimeBarPresenter::SetBodyBounds(const FloatRectangle& bounds)
927 __bodyAreaBounds = bounds;
932 _DateTimeBarPresenter::GetBodyBounds(void) const
934 return __bodyAreaBounds;
938 _DateTimeBarPresenter::SetArrowBounds(const FloatRectangle& bounds)
940 __arrowAreaBounds = bounds;
945 _DateTimeBarPresenter::GetArrowBounds(void) const
947 return __arrowAreaBounds;
951 _DateTimeBarPresenter::SetWindowBounds(const FloatRectangle& bounds)
953 __windowAreaBounds = bounds;
958 _DateTimeBarPresenter::GetWindowBounds(void) const
960 return __windowAreaBounds;
964 _DateTimeBarPresenter::OnTouchPressed(const _Control& source, const _TouchInfo& touchinfo)
966 if (&source != __pDateTimeBar)
971 __isFlickEnabled = true;
973 if (GetBodyBounds().Contains(touchinfo.GetCurrentPosition()) == false)
975 __isFlickEnabled = false;
979 if (__isFlickInProgress)
981 ResetFlickAnimationTimer();
984 __touchMoveHandled = false;
986 __currentPoint = touchinfo.GetCurrentPosition();
988 int index = GetItemIndexFromPosition(touchinfo.GetCurrentPosition());
995 __pDateTimeBar->Invalidate();
1001 _DateTimeBarPresenter::OnTouchReleased(const _Control& source, const _TouchInfo& touchinfo)
1003 if (&source != __pDateTimeBar)
1008 if (GetBodyBounds().Contains(touchinfo.GetCurrentPosition()) == false && !__isFlickInProgress && !__isTouchMoved)
1010 __isTouchMoved = false;
1011 PLAY_FEEDBACK(_RESOURCE_FEEDBACK_PATTERN_TAP);
1012 __pDateTimeBar->SetVisibleState(false);
1013 __pDateTimeBar->Close();
1014 ResetFlickAnimationTimer();
1015 __pDateTimeBar->FireDateTimeChangeEvent(DATE_INTERNAL_CHANGE_CANCELED);
1019 int index = GetItemIndexFromPosition(touchinfo.GetCurrentPosition());
1020 bool isEventFire = true;
1022 if (index != -1 && __isTouchMoved == false && __isFlickInProgress == false)
1024 PLAY_FEEDBACK(_RESOURCE_FEEDBACK_PATTERN_TAP);
1025 SetItemStatus(index, DATETIMEBAR_ITEM_STATUS_SELECTED);
1026 __pDateTimeBarModel->SetFirstDrawnItemIndex(index);
1030 isEventFire = false;
1033 __isTouchMoved = false;
1036 __pDateTimeBar->Invalidate();
1038 if (isEventFire == true)
1040 int index = GetFirstDrawnItemIndex();
1042 _DateTimeBarItem* pItem = null;
1046 pItem = GetItemAt(index);
1051 __pDateTimeBar->SetVisibleState(false);
1052 __pDateTimeBar->Close();
1054 __pDateTimeBar->FireActionEvent(pItem->GetActionId());
1056 if (__pDateTimeBar->GetSelectedBoxId() >= DATETIME_ID_YEAR && __pDateTimeBar->GetSelectedBoxId() <= DATETIME_ID_DAY)
1058 __pDateTimeBar->FireDateTimeChangeEvent(DATE_INTERNAL_CHANGE_SAVED);
1060 else if (__pDateTimeBar->GetSelectedBoxId() >= DATETIME_ID_HOUR && __pDateTimeBar->GetSelectedBoxId() <= DATETIME_ID_MINUTE)
1062 __pDateTimeBar->FireDateTimeChangeEvent(TIME_INTERNAL_CHANGE_SAVED);
1071 _DateTimeBarPresenter::OnTouchMoved(const _Control& source, const _TouchInfo& touchinfo)
1073 if (&source != __pDateTimeBar)
1078 if (GetBodyBounds().Contains(touchinfo.GetCurrentPosition()) == false || __touchMoveHandled == true)
1083 _ControlOrientation orientation = _ControlManager::GetInstance()->GetOrientation();
1085 __isTouchMoved = true;
1087 FloatDimension screen(0.0f, 0.0f);
1088 GET_DIMENSION_CONFIG(DATETIMEBAR::DEFAULT_SIZE, orientation, screen);
1090 const float _BOUNDARY_X_POSITION = screen.width * 2.0f;
1091 float distance = touchinfo.GetCurrentPosition().x - __currentPoint.x;
1093 _DateTimeBarItem* pItem = null;
1095 FloatRectangle itemBounds;
1097 bool needItem = false;
1098 int updateItemCount = 1;
1100 if (distance > 0.0f)
1102 pItem = __pDateTimeBarModel->GetItemAt(GetFirstDrawnItemIndex());
1109 itemBounds = pItem->GetBounds();
1111 __distance += distance;
1113 if (__distance > itemBounds.width / 2.0f)
1116 if (__distance > itemBounds.width)
1118 updateItemCount = UPDATE_ITEM_COUNT;
1121 if (needItem == true)
1123 while (updateItemCount > 0)
1125 pItem = __pDateTimeBarModel->GetItemAt(GetFirstDrawnItemIndex());
1131 int actionId = pItem->GetActionId() - 1;
1133 if (__pDateTimeBarModel->GetMinimumValue() > actionId)
1135 actionId = __pDateTimeBarModel->GetMaximumValue();
1138 if (pItem->GetBounds().x > _BOUNDARY_X_POSITION * -1.0f)
1140 if (InsertItem(0, actionId) == E_SUCCESS)
1142 SetFirstDrawnItemIndex(0);
1146 if (GetItemCount() >= __pDateTimeBarModel->GetMaxCachingSize())
1148 DeleteItem(GetItemCount() - 1);
1158 pItem = __pDateTimeBarModel->GetItemAt(GetItemCount() - 1);
1164 itemBounds = pItem->GetBounds();
1166 __distance += distance;
1168 if (__distance * -1.0f > itemBounds.width / 2.0f)
1171 if (__distance * -1.0f > itemBounds.width)
1173 updateItemCount = UPDATE_ITEM_COUNT;
1178 if (needItem == true)
1180 while (updateItemCount > 0)
1182 pItem = __pDateTimeBarModel->GetItemAt(GetItemCount() - 1);
1188 int actionId = pItem->GetActionId() + 1;
1190 if (__pDateTimeBarModel->GetMaximumValue() < actionId)
1192 actionId = __pDateTimeBarModel->GetMinimumValue();
1195 if (pItem->GetBounds().x < _BOUNDARY_X_POSITION)
1200 if (GetItemCount() >= __pDateTimeBarModel->GetMaxCachingSize())
1203 SetFirstDrawnItemIndex(0);
1210 __currentPoint = touchinfo.GetCurrentPosition();
1212 AdjustItemPosition(distance);
1214 __pDateTimeBar->Invalidate();
1220 _DateTimeBarPresenter::OnTouchCanceled(const _Control& source, const _TouchInfo& touchinfo)
1222 if (&source != __pDateTimeBar)
1227 __isTouchMoved = false;
1230 __pDateTimeBar->Invalidate();
1236 _DateTimeBarPresenter::LoadItems()
1238 _ControlOrientation orientation = _ControlManager::GetInstance()->GetOrientation();
1240 FloatDimension screen(0.0f, 0.0f);
1241 GET_DIMENSION_CONFIG(DATETIMEBAR::DEFAULT_SIZE, orientation, screen);
1243 const float _BOUNDARY_X_POSITION = screen.width * 2.0f;
1245 _DateTimeBarItem* pItem = null;
1247 int updateItemCount = UPDATE_ITEM_COUNT;
1249 if (__distance > 0.0f)
1251 pItem = __pDateTimeBarModel->GetItemAt(GetFirstDrawnItemIndex());
1259 while (updateItemCount > 0)
1261 pItem = __pDateTimeBarModel->GetItemAt(GetFirstDrawnItemIndex());
1267 int actionId = pItem->GetActionId() - 1;
1269 if (__pDateTimeBarModel->GetMinimumValue() > actionId)
1271 actionId = __pDateTimeBarModel->GetMaximumValue();
1274 if (pItem->GetBounds().x > _BOUNDARY_X_POSITION * -1)
1276 if (InsertItem(0, actionId) == E_SUCCESS)
1278 SetFirstDrawnItemIndex(0);
1282 if (GetItemCount() >= __pDateTimeBarModel->GetMaxCachingSize())
1284 DeleteItem(GetItemCount() - 1);
1292 pItem = __pDateTimeBarModel->GetItemAt(GetItemCount() - 1);
1299 while (updateItemCount > 0)
1301 pItem = __pDateTimeBarModel->GetItemAt(GetItemCount() - 1);
1307 int actionId = pItem->GetActionId() + 1;
1309 if (__pDateTimeBarModel->GetMaximumValue() < actionId)
1311 actionId = __pDateTimeBarModel->GetMinimumValue();
1314 if (pItem->GetBounds().x < _BOUNDARY_X_POSITION)
1319 if (GetItemCount() >= __pDateTimeBarModel->GetMaxCachingSize())
1322 SetFirstDrawnItemIndex(0);
1332 _DateTimeBarPresenter::OnFlickGestureDetected(int distanceX,int distanceY,int duration)
1334 if (!__isFlickEnabled)
1339 __isFlickInProgress = true;
1340 __isInitialAnimation = false;
1345 __flickAnimation.CalculateInitializeVelocity(distanceX, 0, duration, &velX, &velY);
1346 __flickAnimation.InitializeFlickAmount(velX * FLICK_ANIMATION_VELOCITY_FACTOR_DATE_TIME_BAR);
1348 StartFlickAnimationTimer();
1353 _DateTimeBarPresenter::StartFlickAnimation(void)
1358 __flickAnimation.CalculateNextMove(&moveX, &moveY);
1360 __distance = _CoordinateSystemUtils::ConvertToFloat(moveX);
1363 StartFlickAnimationTimer();
1367 AdjustItemPosition(__distance);
1373 _DateTimeBarPresenter::StartAnimationEffect(void)
1375 __isInitialAnimation = true;
1376 __distance = -10.0f;
1378 if (__initialAnimationValue >= 0.0f)
1380 __initialAnimationValue = __initialAnimationValue + __distance;
1381 StartFlickAnimationTimer();
1384 AdjustItemPosition(__distance);
1389 __initialAnimationValue = 0.0f;
1390 __isInitialAnimation = false;
1391 ResetFlickAnimationTimer();
1392 ValidateAndAdjustStartPosition();
1399 _DateTimeBarPresenter::StartFlickAnimationTimer(void)
1401 result r = E_SUCCESS;
1403 if (__pFlickAnimationTimer == null)
1405 __pFlickAnimationTimer = new (std::nothrow) Timer;
1406 SysTryReturn(NID_UI_CTRL, (__pFlickAnimationTimer != null), E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Unable to create timer.");
1408 r = __pFlickAnimationTimer->Construct(*this);
1409 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
1413 __pFlickAnimationTimer->Cancel();
1416 r = __pFlickAnimationTimer->Start(FLICK_ANIMATION_TIMER_PERIOD);
1417 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
1422 ResetFlickAnimationTimer();
1427 _DateTimeBarPresenter::ResetFlickAnimationTimer(void)
1429 if (__pFlickAnimationTimer)
1431 delete __pFlickAnimationTimer;
1432 __pFlickAnimationTimer = null;
1435 __isFlickInProgress = false;
1440 _DateTimeBarPresenter::OnTimerExpired(Timer& timer)
1442 __isFlickInProgress = false;
1443 if (&timer == __pFlickAnimationTimer)
1445 if (__isInitialAnimation)
1447 StartAnimationEffect();
1451 StartFlickAnimation();
1458 _DateTimeBarPresenter::ValidateAndAdjustStartPosition(void)
1461 float adjustPosition = 0.0f;
1462 float leftMargin = GetLeftRightMargin();
1463 FloatRectangle bodyBounds = GetBodyBounds();
1465 index = GetItemIndexFromPosition(FloatPoint(GetLeftRightMargin() + GetItemMargin(), bodyBounds.y + (bodyBounds.height / 2.0f)));
1472 _DateTimeBarItem* pDrawItem = null;
1473 pDrawItem = __pDateTimeBarModel->GetItemAt(index);
1475 if (pDrawItem == null)
1480 if (pDrawItem->GetBounds().x > 0.0f && pDrawItem->GetBounds().x < leftMargin)
1482 adjustPosition = leftMargin - pDrawItem->GetBounds().x;
1484 else if (pDrawItem->GetBounds().x < 0.0f)
1486 pDrawItem = __pDateTimeBarModel->GetItemAt(index + 1);
1487 if (pDrawItem == null)
1491 adjustPosition = leftMargin - pDrawItem->GetBounds().x;
1493 else if (pDrawItem->GetBounds().x > leftMargin)
1495 adjustPosition = leftMargin - pDrawItem->GetBounds().x;
1498 AdjustItemPosition(adjustPosition);
1504 _DateTimeBarPresenter::SetInitialAnimationValue(float animationValue)
1506 __initialAnimationValue = animationValue;
1511 _DateTimeBarPresenter::SetFont(Font& pFont)
1516 __pFont = _FontImpl::CloneN(pFont);
1517 SysTryReturnVoidResult(NID_UI_CTRL, (__pFont != null), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1523 _DateTimeBarPresenter::OnAccessibilityFocusMovedNext(const _AccessibilityContainer& control, const _AccessibilityElement& element)
1529 _DateTimeBarPresenter::OnAccessibilityFocusMovedPrevious(const _AccessibilityContainer& control, const _AccessibilityElement& element)
1535 _DateTimeBarPresenter::OnTouchMoveHandled(const Tizen::Ui::_Control& control)
1537 __touchMoveHandled = true;
1539 __isTouchMoved = false;
1542 __pDateTimeBar->Invalidate();
1548 _DateTimeBarPresenter::AddAccessibilityElement(void)
1550 _DateTimeBarItem* pItem = null;
1551 pItem = __pDateTimeBarModel->GetItemAt(__pDateTimeBarModel->GetItemCount() - 1);
1558 if (__pDateTimeBar->GetSelectedBoxId() == DATETIME_ID_MONTH)
1560 __pDateTimeBar->AddAccessibilityElement(pItem->GetBounds(), __pDateTimeBar->GetMonthValue(pItem->GetActionId()));
1564 __pDateTimeBar->AddAccessibilityElement(pItem->GetBounds(), pItem->GetText());
1571 _DateTimeBarPresenter::InsertAccessibilityElementAt(int index)
1573 _DateTimeBarItem* pItem = null;
1574 pItem = __pDateTimeBarModel->GetItemAt(index);
1581 if (__pDateTimeBar->GetSelectedBoxId() == DATETIME_ID_MONTH)
1583 __pDateTimeBar->InsertAccessibilityElementAt(index, pItem->GetBounds(), __pDateTimeBar->GetMonthValue(pItem->GetActionId()));
1587 __pDateTimeBar->InsertAccessibilityElementAt(index, pItem->GetBounds(), pItem->GetText());
1594 _DateTimeBarPresenter::MoveNext(void)
1596 __distance = (GetItemWidth() + GetItemMargin()) * (-1.0f);
1598 AdjustItemPosition(__distance);
1604 _DateTimeBarPresenter::MovePrevious(void)
1606 __distance = (GetItemWidth() + GetItemMargin());
1608 AdjustItemPosition(__distance);
1613 }}} // Tizen::Ui::Controls