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.
18 * @file FUiCtrl_TabPresenter.cpp
19 * @brief This is the implementation file for the _TabPresenter class.
22 #include <FBaseErrorDefine.h>
23 #include <FBaseRtITimerEventListener.h>
24 #include <FBaseRtTimer.h>
27 #include <FBaseSysLog.h>
28 #include <FUiAnimVisualElementPropertyAnimation.h>
29 #include <FGrp_FontImpl.h>
30 #include <FGrp_TextTextObject.h>
31 #include <FGrp_BitmapImpl.h>
32 #include <FGrp_TextTextSimple.h>
33 #include "FUi_AccessibilityElement.h"
34 #include "FUi_IAccessibilityListener.h"
35 #include "FUi_AccessibilityContainer.h"
36 #include "FUiAnim_VisualElement.h"
37 #include "FUi_UiTouchEvent.h"
38 #include "FUi_ResourceManager.h"
39 #include "FUiCtrl_TabPresenter.h"
41 using namespace Tizen::Base;
42 using namespace Tizen::Graphics;
43 using namespace Tizen::Graphics::_Text;
44 using namespace Tizen::Base::Runtime;
45 using namespace Tizen::Ui::Animations;
47 namespace Tizen { namespace Ui { namespace Controls {
49 struct ReorderAnimationInfo{
64 _TabPresenter::_TabPresenter(void)
72 , __pVerticalLineBitmap(null)
73 , __pHorizontalLineBitmap(null)
74 , __pFrontScrollingEffectBitmap(null)
75 , __pRearScrollingEffectBitmap(null)
76 , __pScrollingEffectBitmap(null)
77 , __pScrollingEffectVe(null)
78 , __pFlickAnimationTimer(null)
79 , __pScrollAnimationTimer(null)
85 , __isFlickEnabled(false)
90 , __isRightScrolable(false)
91 , __isLeftScrolable(false)
92 , __isDirectionRight(true)
93 , __isTimerCanceled(false)
100 , __selectedLineLeftMargin(0)
101 , __selectedLineRightMargin(0)
102 , __isScrollEffectEnded(false)
103 , __isScrollEffectStarted(false)
105 , __isTouchMove(false)
107 , __tabMinimumSize(0)
110 __currentTouchPosition = Point(0, 0);
111 __dividerLine = Rectangle(0, 0, 0, 0);
112 __selectedLine = Rectangle(0, 0, 0, 0);
114 for (int i = 0; i < (_TIMER_COUNT); i++)
116 __pTimerInfo[i] = null;
119 for (int i = 0; i < _TAB_ITEM_MAXCOUNT; i++)
121 __pAnimInfo[i] = null;
126 _TabPresenter::~_TabPresenter(void)
136 delete __pTextObject;
137 __pTextObject = null;
140 if (__pVerticalLineBitmap)
142 delete __pVerticalLineBitmap;
143 __pVerticalLineBitmap = null;
146 if (__pHorizontalLineBitmap)
148 delete __pHorizontalLineBitmap;
149 __pHorizontalLineBitmap = null;
152 if (__pFlickAnimationTimer)
154 delete __pFlickAnimationTimer;
155 __pFlickAnimationTimer = null;
158 for (int i = 0; i < (_TIMER_COUNT); i++)
162 if (__pTimerInfo[i]->pReorderTimer)
164 delete __pTimerInfo[i]->pReorderTimer;
165 __pTimerInfo[i]->pReorderTimer = null;
167 delete __pTimerInfo[i];
168 __pTimerInfo[i] = null;
172 for (int i = 0; i < _TAB_ITEM_MAXCOUNT; i++)
176 delete __pAnimInfo[i];
177 __pAnimInfo[i] = null;
181 if (__pScrollAnimationTimer)
183 delete __pScrollAnimationTimer;
184 __pScrollAnimationTimer = null;
187 if (__pFrontScrollingEffectBitmap)
189 delete __pFrontScrollingEffectBitmap;
190 __pFrontScrollingEffectBitmap = null;
193 if (__pRearScrollingEffectBitmap)
195 delete __pRearScrollingEffectBitmap;
196 __pRearScrollingEffectBitmap = null;
199 if (__pScrollingEffectBitmap)
201 __pScrollingEffectBitmap = null;
204 if (__pScrollingEffectVe)
206 __pScrollingEffectVe->RemoveAllAnimations();
207 __pScrollingEffectVe->Destroy();
208 __pScrollingEffectVe = null;
213 _TabPresenter::Construct(const _Tab& tab)
215 result r = E_SUCCESS;
217 __pTab = const_cast<_Tab*>(&tab);
219 __pFont = __pTab->GetFallbackFont();
220 SysTryReturn(NID_UI_CTRL, __pFont, E_SYSTEM , E_SYSTEM, "[E_SYSTEM] A system error has occurred. Failed to retrive Font.");
222 _TabModel* pModel = new (std::nothrow) _TabModel;
223 SysTryReturn(NID_UI_CTRL, pModel, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
225 r = SetModel(*pModel);
226 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , E_SYSTEM, "[E_SYSTEM] A system error has occurred. Failed to set _TabModel instance.");
228 r = pModel->Construct();
229 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , E_SYSTEM, "[E_SYSTEM] A system error has occurred. Failed to construct _TabModel instance.");
231 __pTextObject = new (std::nothrow) TextObject;
232 SysTryCatch(NID_UI_CTRL, __pTextObject, r = E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
234 __pTextObject->Construct();
235 __pTextObject->SetAlignment(TEXT_OBJECT_ALIGNMENT_CENTER | TEXT_OBJECT_ALIGNMENT_MIDDLE);
236 __pTextObject->SetFont(__pFont, 0, __pTextObject->GetTextLength());
239 SysTryLog(NID_UI_CTRL, r == E_SUCCESS, "Failed to locate bitmap.");
241 GET_FIXED_VALUE_CONFIG(TAB::ITEM_MAX_COUNT, __pTab->GetOrientation(), __itemMaxCount);
242 GET_SHAPE_CONFIG(TAB::SCREEN_WIDTH, __pTab->GetOrientation(), __width);
243 GET_SHAPE_CONFIG(TAB::SCREEN_HEIGHT, __pTab->GetOrientation(), __height);
245 GET_SHAPE_CONFIG(TAB::DIVIDER_WIDTH, __pTab->GetOrientation(), __dividerLine.width);
246 GET_SHAPE_CONFIG(TAB::DIVIDER_HEIGHT, __pTab->GetOrientation(), __dividerLine.height);
248 GET_SHAPE_CONFIG(TAB::TAB_MINIMUM_SIZE, __pTab->GetOrientation(), __tabMinimumSize);
250 GET_SHAPE_CONFIG(TAB::SELECTED_LINE_LEFT_MARGIN, __pTab->GetOrientation(), __selectedLineLeftMargin);
251 GET_SHAPE_CONFIG(TAB::SELECTED_LINE_RIGHT_MARGIN, __pTab->GetOrientation(), __selectedLineRightMargin);
252 GET_SHAPE_CONFIG(TAB::SELECTED_LINE_HEIGHT, __pTab->GetOrientation(), __selectedLine.height);
254 __flickAnimation.SetSizeInformation(__width, __height, DEVICE_SIZE_HORIZONTAL, DEVICE_SIZE_VERTICAL);
255 __flickAnimation.SetSensitivity(FLICK_ANIMATION_FPS_TAB, FLICK_ANIMATION_SENSITIVITY_TAB);
256 __flickAnimation.SetDirection(FD_HORIZONTAL);
258 for (int i = 0; i < _TIMER_COUNT; i++)
260 __pTimerInfo[i] = new (std::nothrow) TimerInfo();
261 SysTryCatch(NID_UI_CTRL, __pTimerInfo[i], , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
263 __pTimerInfo[i]->index = -1;
264 __pTimerInfo[i]->pReorderTimer = null;
273 delete __pTextObject;
274 __pTextObject = null;
280 _TabPresenter::LoadBitmap(void)
282 result r = E_SUCCESS;
283 Tizen::Graphics::Bitmap* pBitmap = null;
284 r = GET_BITMAP_CONFIG_N(TAB::VERTICAL_DIVIDER_NORMAL, BITMAP_PIXEL_FORMAT_ARGB8888, __pVerticalLineBitmap);
285 SysTryLog(NID_UI_CTRL, r == E_SUCCESS, "Failed to locate divider line bitmap.");
287 r = GET_BITMAP_CONFIG_N(TAB::ITEM_SELECTED, BITMAP_PIXEL_FORMAT_ARGB8888, pBitmap);
288 SysTryLog(NID_UI_CTRL, r == E_SUCCESS, "Failed to locate horizontal line bitmap.");
292 __pHorizontalLineBitmap = _BitmapImpl::GetColorReplacedBitmapN(*(pBitmap), Color::GetColor(COLOR_ID_MAGENTA), __pTab->GetPressedTextColor());
293 SysTryLog(NID_UI_CTRL, r == E_SUCCESS, "Failed to locate focus item line bitmap.");
295 r = GET_BITMAP_CONFIG_N(TAB::TAB_BOUNCE_EFFECT_LEFT, BITMAP_PIXEL_FORMAT_ARGB8888, __pFrontScrollingEffectBitmap);
296 SysTryLog(NID_UI_CTRL, r == E_SUCCESS, "Failed to locate overscrolling left bitmap.");
298 r = GET_BITMAP_CONFIG_N(TAB::TAB_BOUNCE_EFFECT_RIGHT, BITMAP_PIXEL_FORMAT_ARGB8888, __pRearScrollingEffectBitmap);
299 SysTryLog(NID_UI_CTRL, r == E_SUCCESS, "Failed to locate overscrolling right bitmap.");
306 _TabPresenter::DrawResourceBitmap(Canvas& canvas, const Rectangle& bounds, Bitmap* pBitmap)
308 result r = E_SUCCESS;
315 if (pBitmap->IsNinePatchedBitmap())
317 r = canvas.DrawNinePatchedBitmap(bounds, *pBitmap);
318 SysTryReturnVoidResult(NID_UI_CTRL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
322 r = canvas.DrawBitmap(bounds, *pBitmap);
323 SysTryReturnVoidResult(NID_UI_CTRL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
330 _TabPresenter::SetModel(const _TabModel& tabModel)
332 __pTabModel = const_cast<_TabModel*>(&tabModel);
338 _TabPresenter::SetSelectedItemIndex(int index)
340 int i = GetSelectedItemIndex();
341 SetItemStatus(i, _TABITEM_STATUS_NORMAL);
342 __pTabModel->SetSelectedItemIndex(index);
343 SetItemStatus(index, _TABITEM_STATUS_SELECTED);
348 _TabPresenter::GetSelectedItemIndex(void) const
350 return __pTabModel->GetSelectedItemIndex();
354 _TabPresenter::SetPressedItemIndex(int index)
356 __pTabModel->SetPressedItemIndex(index);
361 _TabPresenter::GetPressedItemIndex(void) const
363 return __pTabModel->GetPressedItemIndex();
367 _TabPresenter::SetFirstDrawnItemIndex(int index)
369 __pTabModel->SetFirstDrawnItemIndex(index);
374 _TabPresenter::GetFirstDrawnItemIndex(void) const
377 return __pTabModel->GetFirstDrawnItemIndex();
381 _TabPresenter::SetEditModeEnabled(bool enable)
384 return __pTabModel->SetEditModeEnabled(enable);
388 _TabPresenter::IsEditModeEnabled(void) const
390 return __pTabModel->IsEditModeEnabled();
394 _TabPresenter::GetItemCount(void) const
397 return __pTab->GetItemCount();
401 _TabPresenter::GetItemAt(int index)
403 return __pTab->GetItemAt(index);
407 _TabPresenter::SetItemStatus(int index, _TabItemStatus status)
409 _TabItem *pItem = GetItemAt(index);
410 SysTryReturn(NID_UI_CTRL, pItem, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
412 pItem->SetUpdateState(true);
413 pItem->SetStatus(status);
419 _TabPresenter::GetItemStatus(int index) const
422 _TabItem *pItem = __pTab->GetItemAt(index);
426 return _TABITEM_STATUS_NORMAL;
429 return pItem->GetStatus();
433 _TabPresenter::GetItemIndexFromPosition(const Point& point) const
436 Rectangle itemBounds(0, 0, 0, 0);
438 int itemIndex = GetFirstDrawnItemIndex();
440 if ((point.x < 0) || (point.x > __pTab->GetBounds().width)
441 || (point.y < 0 ) || (point.y > __pTab->GetBounds().height))
446 _TabItem* pItem = __pTab->GetItemAt(itemIndex);
452 while (pItem != null)
454 itemBounds = pItem->GetItemBounds();
456 if ((point.x > itemBounds.x) && (point.x < itemBounds.x + itemBounds.width)
457 && (point.y > itemBounds.y) && (point.y < itemBounds.y + itemBounds.height))
463 pItem = __pTab->GetItemAt(itemIndex);
474 _TabPresenter::Draw(void)
478 SysTryReturnVoidResult(NID_UI_CTRL, __pTab, E_SYSTEM, "[E_SYSTEM] A system error has occurred. The _Tab instance is null.");
479 GET_COLOR_CONFIG(TAB::ITEM_BG_NORMAL, backgroundColor);
485 else if (__isFlickEnabled )
489 Canvas* pCanvas = __pTab->GetCanvasN();
490 SysTryReturnVoidResult(NID_UI_CTRL, pCanvas, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
492 pCanvas->SetBackgroundColor(backgroundColor);
495 if (__pTab->GetStyle() == _TAB_STYLE_TEXT)
497 DrawTextItem(pCanvas);
499 else if (__pTab->GetStyle() == _TAB_STYLE_ICON)
501 DrawIconItem(pCanvas);
503 else // _TAB_STYLE_ICON_TEXT
508 RefreshAccessibilityElement();
515 _TabPresenter::SetReCalculateItemBounds(bool reCalculationRequired)
517 __recalc = reCalculationRequired;
522 _TabPresenter::DrawTextItem(Canvas* pCanvas)
525 TextSimple* pSimpleText = null;
526 Rectangle bounds = __pTab->GetBounds();
528 _TabItem* pDrawItem = null;
529 String itemText(L"");
530 Rectangle itemDrawRect(0, 0, 0, 0);
532 const int itemCount = GetItemCount();
534 _TabItemStatus itemStatus = _TABITEM_STATUS_NORMAL;
536 bool multiline = false;
537 int fontChangeItemCount = 0;
538 GET_FIXED_VALUE_CONFIG(TAB::FONT_CHANGE_ITEM_COUNT, __pTab->GetOrientation(), fontChangeItemCount);
541 int bottomMargin = 0;
544 GET_SHAPE_CONFIG(TAB::TOP_MARGIN, __pTab->GetOrientation(), topMargin);
545 GET_SHAPE_CONFIG(TAB::BOTTOM_MARGIN, __pTab->GetOrientation(), bottomMargin);
546 GET_SHAPE_CONFIG(TAB::ITEM_LEFT_MARGIN, __pTab->GetOrientation(), leftMargin);
547 GET_SHAPE_CONFIG(TAB::ITEM_RIGHT_MARGIN, __pTab->GetOrientation(), rightMargin);
549 for (int i = 0; i < itemCount; i++)
551 pDrawItem = GetItemAt(i);
553 SysTryReturnVoidResult(NID_UI_CTRL, pDrawItem, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
555 SetFirstDrawnItemIndex(0);
558 itemDrawRect = pDrawItem->GetItemBounds();
559 __dividerLine.x = itemDrawRect.x + (itemDrawRect.width - (__dividerLine.width)/2);
560 __dividerLine.y = ((itemDrawRect.height - __dividerLine.height)/2);
563 itemStatus = pDrawItem->GetStatus();
566 if (itemStatus == _TABITEM_STATUS_SELECTED)
568 DrawSelectedItemBackground(pCanvas, itemDrawRect);
569 __selectedLine.width = __itemWidth - __selectedLineLeftMargin - __selectedLineRightMargin;
570 __selectedLine.x = itemDrawRect.x + __selectedLineLeftMargin;
572 else if (itemStatus == _TABITEM_STATUS_PRESSED)
574 DrawFocusItemBackground(pCanvas, itemDrawRect);
578 DrawItemBackground(pCanvas, itemDrawRect);
582 itemText = pDrawItem->GetText();
584 __pTextObject->RemoveAll();
585 pSimpleText = new (std::nothrow)TextSimple(const_cast <mchar*>(itemText.GetPointer()), itemText.GetLength());
586 SysTryReturnVoidResult(NID_UI_CTRL, pSimpleText, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
588 __pTextObject->AppendElement(*pSimpleText);
589 __pTextObject->SetWrap(TEXT_OBJECT_WRAP_TYPE_WORD);
590 __pTextObject->SetAction(TEXT_OBJECT_ACTION_TYPE_ABBREV);
592 // Margin - Item Rect.
593 itemDrawRect.x = itemDrawRect.x + leftMargin;
594 itemDrawRect.y = itemDrawRect.y + topMargin;
595 itemDrawRect.width = itemDrawRect.width - leftMargin - rightMargin;
596 itemDrawRect.height = itemDrawRect.height - topMargin - bottomMargin;
598 __pTextObject->SetBounds(itemDrawRect);
599 __pTextObject->Compose();
601 const int textRowCount = __pTextObject->GetTotalLineCount();
606 if (textRowCount >= 2)
612 if (__pFont != null )
616 if (__showItemCount < fontChangeItemCount)
618 if (multiline == false)
620 GET_SHAPE_CONFIG(TAB::FONT_SIZE_01, __pTab->GetOrientation(), fontSize);
624 GET_SHAPE_CONFIG(TAB::MULTILINE_FONT_SIZE_01, __pTab->GetOrientation(), fontSize);
627 else if (__showItemCount == fontChangeItemCount)
629 if (multiline == false)
631 GET_SHAPE_CONFIG(TAB::FONT_SIZE_02, __pTab->GetOrientation(), fontSize);
635 GET_SHAPE_CONFIG(TAB::MULTILINE_FONT_SIZE_02, __pTab->GetOrientation(), fontSize);
640 if (multiline == false)
642 GET_SHAPE_CONFIG(TAB::FONT_SIZE_03, __pTab->GetOrientation(), fontSize);
646 GET_SHAPE_CONFIG(TAB::MULTILINE_FONT_SIZE_03, __pTab->GetOrientation(), fontSize);
650 (_FontImpl::GetInstance(*__pFont))->SetSize(fontSize);
653 __pTextObject->SetFont(__pFont, 0, __pTextObject->GetTextLength());
655 if (itemStatus == _TABITEM_STATUS_SELECTED)
657 __pTextObject->SetForegroundColor(__pTab->GetSelectedTextColor(), 0, __pTextObject->GetTextLength());
658 __selectedLine.y = itemDrawRect.y + itemDrawRect.height;
659 if (__pTab->GetSelectedItemBackgroundBitmap() == null)
661 DrawResourceBitmap(*pCanvas, __selectedLine, __pHorizontalLineBitmap);
665 else if (itemStatus == _TABITEM_STATUS_PRESSED)
667 __pTextObject->SetForegroundColor(__pTab->GetPressedTextColor(), 0, __pTextObject->GetTextLength());
669 else if (itemStatus == _TABITEM_STATUS_HIGHLIGHTED)
671 __pTextObject->SetForegroundColor(__pTab->GetHighlightedTextColor(), 0, __pTextObject->GetTextLength());
675 __pTextObject->SetForegroundColor(__pTab->GetTextColor(), 0, __pTextObject->GetTextLength());
678 __pTextObject->SetBounds(itemDrawRect);
679 __pTextObject->Draw(*_CanvasImpl::GetInstance(*pCanvas));
680 if (i < (itemCount - 1))
682 DrawItemDivisionVerticalLine(pCanvas, __dividerLine);
685 DrawBadgeIcon(pDrawItem, pCanvas);
692 _TabPresenter::DrawItemBackground(Canvas* pCanvas, Rectangle& itemRect)
694 Bitmap* pBackgroundBitmap = __pTab->GetBackgroundBitmap();
696 DrawResourceBitmap(*pCanvas, itemRect, pBackgroundBitmap);
702 _TabPresenter::DrawFocusItemBackground(Canvas* pCanvas, Rectangle& itemRect)
704 Bitmap* pBackgroundBitmap = __pTab->GetPressedItemBackgroundBitmap();
706 DrawResourceBitmap(*pCanvas, itemRect, pBackgroundBitmap);
712 _TabPresenter::DrawSelectedItemBackground(Canvas* pCanvas, Rectangle& itemRect)
714 Bitmap* pBackgroundBitmap = __pTab->GetSelectedItemBackgroundBitmap();
716 DrawResourceBitmap(*pCanvas, itemRect, pBackgroundBitmap);
722 _TabPresenter::DrawIconItem(Canvas* pCanvas)
725 Rectangle bounds = __pTab->GetBounds();
727 _TabItem* pDrawItem = null;
728 String itemText(L"");
729 Rectangle itemDrawRect(0, 0, 0, 0);
730 const int itemCount = GetItemCount();
732 _TabItemStatus itemStatus = _TABITEM_STATUS_NORMAL;
736 int bottomMargin = 0;
738 GET_SHAPE_CONFIG(TAB::ICON_WIDTH, __pTab->GetOrientation(), iconWidth);
739 GET_SHAPE_CONFIG(TAB::ICON_HEIGHT, __pTab->GetOrientation(), iconHeight);
740 GET_SHAPE_CONFIG(TAB::BOTTOM_MARGIN, __pTab->GetOrientation(), bottomMargin);
742 for (int i = 0; i < itemCount; i++)
744 pDrawItem = GetItemAt(i);
745 SysTryReturnVoidResult(NID_UI_CTRL, pDrawItem, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
747 SetFirstDrawnItemIndex(0);
750 itemDrawRect = pDrawItem->GetItemBounds();
751 __dividerLine.x = itemDrawRect.x + (itemDrawRect.width - (__dividerLine.width)/2);
752 __dividerLine.y = ((itemDrawRect.height - __dividerLine.height)/2);
755 itemStatus = pDrawItem->GetStatus();
758 if (itemStatus == _TABITEM_STATUS_SELECTED)
760 DrawSelectedItemBackground(pCanvas, itemDrawRect);
761 __selectedLine.width = __itemWidth - __selectedLineLeftMargin - __selectedLineRightMargin;
762 __selectedLine.x = itemDrawRect.x + __selectedLineLeftMargin;
763 __selectedLine.y = itemDrawRect.height - (bottomMargin/2);
765 if (__pTab->GetSelectedItemBackgroundBitmap() == null)
767 DrawResourceBitmap(*pCanvas, __selectedLine, __pHorizontalLineBitmap);
770 else if (itemStatus == _TABITEM_STATUS_PRESSED)
772 DrawFocusItemBackground(pCanvas, itemDrawRect);
776 DrawItemBackground(pCanvas, itemDrawRect);
780 // Margin - Item Rect.
781 itemDrawRect.x = itemDrawRect.x + ((itemDrawRect.width - iconWidth) / 2);
782 itemDrawRect.y = itemDrawRect.y + ((itemDrawRect.height - iconHeight) / 2);
783 itemDrawRect.width = iconWidth;
784 itemDrawRect.height = iconHeight;
786 Bitmap* pIconBitmap = pDrawItem->GetIcon();
788 DrawResourceBitmap(*pCanvas, itemDrawRect, pIconBitmap);
790 if (i < itemCount - 1)
792 DrawItemDivisionVerticalLine(pCanvas, __dividerLine);
794 DrawBadgeIcon(pDrawItem, pCanvas);
801 _TabPresenter::DrawItem(Canvas* pCanvas)
805 Rectangle bounds = __pTab->GetBounds();
807 TextSimple* pSimpleText = null;
808 _TabItem* pDrawItem = null;
809 Rectangle buttonBounds(0, 0, 0, 0);
810 String itemText(L"");
811 Rectangle itemDrawRect(0, 0, 0, 0);
812 Rectangle itemDrawIconRect(0, 0, 0, 0);
813 Rectangle itemDrawTextRect(0, 0, 0, 0);
815 const int itemCount = GetItemCount();
817 _TabItemStatus itemStatus = _TABITEM_STATUS_NORMAL;
819 bool multiline = false;
820 int fontChangeItemCount = 0;
821 GET_FIXED_VALUE_CONFIG(TAB::FONT_CHANGE_ITEM_COUNT, __pTab->GetOrientation(), fontChangeItemCount);
822 GET_FIXED_VALUE_CONFIG(TAB::ICON_TEXT_GAP, __pTab->GetOrientation(), iconTextGap);
825 int bottomMargin = 0;
828 int topMarginTextOnly = 0;
830 int bottomMarginTextOnly = 0;
831 GET_SHAPE_CONFIG(TAB::TOP_MARGIN, __pTab->GetOrientation(), topMarginTextOnly);
832 GET_SHAPE_CONFIG(TAB::BOTTOM_MARGIN, __pTab->GetOrientation(), bottomMarginTextOnly);
834 GET_SHAPE_CONFIG(TAB::ICON_TEXT_TOP_MARGIN, __pTab->GetOrientation(), topMargin);
835 GET_SHAPE_CONFIG(TAB::ICON_TEXT_BOTTOM_MARGIN, __pTab->GetOrientation(), bottomMargin);
836 GET_SHAPE_CONFIG(TAB::ITEM_LEFT_MARGIN, __pTab->GetOrientation(), leftMargin);
837 GET_SHAPE_CONFIG(TAB::ITEM_RIGHT_MARGIN, __pTab->GetOrientation(), rightMargin);
840 GET_SHAPE_CONFIG(TAB::ICON_TEXT_ICON_WIDTH, __pTab->GetOrientation(), iconWidth);
841 GET_SHAPE_CONFIG(TAB::ICON_TEXT_ICON_HEIGHT, __pTab->GetOrientation(), iconHeight);
843 GET_FIXED_VALUE_CONFIG(TAB::ICON_TEXT_GAP, __pTab->GetOrientation(), iconGap);
845 for (int i = 0; i < itemCount; i++)
847 pDrawItem = GetItemAt(i);
848 SysTryReturnVoidResult(NID_UI_CTRL, pDrawItem, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
850 SetFirstDrawnItemIndex(0);
852 itemDrawRect = pDrawItem->GetItemBounds();
853 __dividerLine.x = itemDrawRect.x + (itemDrawRect.width - (__dividerLine.width)/2);
854 __dividerLine.y = ((itemDrawRect.height - __dividerLine.height)/2);
856 itemStatus = pDrawItem->GetStatus();
858 if (itemStatus == _TABITEM_STATUS_SELECTED)
860 DrawSelectedItemBackground(pCanvas, itemDrawRect);
861 __selectedLine.width = __itemWidth - __selectedLineLeftMargin - __selectedLineRightMargin;
862 __selectedLine.x = itemDrawRect.x + __selectedLineLeftMargin;
864 else if (itemStatus == _TABITEM_STATUS_PRESSED)
866 DrawFocusItemBackground(pCanvas, itemDrawRect);
870 DrawItemBackground(pCanvas, itemDrawRect);
874 itemText = pDrawItem->GetText();
876 __pTextObject->RemoveAll();
877 pSimpleText = new (std::nothrow)TextSimple(const_cast <mchar*>(itemText.GetPointer()), itemText.GetLength());
878 SysTryReturnVoidResult(NID_UI_CTRL, pSimpleText, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
880 __pTextObject->AppendElement(*pSimpleText);
882 __pTextObject->SetWrap(TEXT_OBJECT_WRAP_TYPE_WORD);
883 __pTextObject->SetAction(TEXT_OBJECT_ACTION_TYPE_ABBREV);
884 __pTextObject->SetAlignment(TEXT_OBJECT_ALIGNMENT_CENTER | TEXT_OBJECT_ALIGNMENT_MIDDLE);
885 textLength = __pTextObject->GetTextLength();
887 if ((pDrawItem->GetIcon()) == null)
889 topMargin = topMarginTextOnly;
890 bottomMargin = bottomMarginTextOnly;
892 Dimension textDim(0,0);
895 if (__pFont != null )
899 if (__showItemCount < fontChangeItemCount)
901 if (multiline == false)
903 GET_SHAPE_CONFIG(TAB::ICON_TEXT_FONT_SIZE_01, __pTab->GetOrientation(), fontSize);
907 GET_SHAPE_CONFIG(TAB::ICON_TEXT_FONT_SIZE_02, __pTab->GetOrientation(), fontSize);
910 else if (__showItemCount == fontChangeItemCount)
912 if (multiline == false)
914 GET_SHAPE_CONFIG(TAB::ICON_TEXT_FONT_SIZE_02, __pTab->GetOrientation(), fontSize);
918 GET_SHAPE_CONFIG(TAB::ICON_TEXT_FONT_SIZE_02, __pTab->GetOrientation(), fontSize);
923 if (multiline == false)
925 GET_SHAPE_CONFIG(TAB::ICON_TEXT_FONT_SIZE_03, __pTab->GetOrientation(), fontSize);
929 GET_SHAPE_CONFIG(TAB::ICON_TEXT_FONT_SIZE_03, __pTab->GetOrientation(), fontSize);
933 (_FontImpl::GetInstance(*__pFont))->SetSize(fontSize);
935 __pTextObject->SetFont(__pFont, 0, __pTextObject->GetTextLength());
937 __pFont->GetTextExtent(itemText, itemText.GetLength(), textDim);
940 itemDrawTextRect = itemDrawRect;
941 itemDrawTextRect.x = itemDrawRect.x + leftMargin;
943 if (textDim.width > (__itemWidth/2))
946 textDim.width = (__itemWidth/2);
947 textDim.height = textDim.height * 2;
949 itemDrawTextRect.width = textDim.width;
950 itemDrawTextRect.x = itemDrawRect.x + leftMargin;
951 itemDrawTextRect.x = itemDrawTextRect.x + ((itemDrawRect.width - leftMargin - rightMargin) - (iconWidth + iconGap + itemDrawTextRect.width))/2;
952 itemDrawTextRect.height = textDim.height;
953 itemDrawIconRect = itemDrawTextRect;
954 itemDrawTextRect.x = itemDrawIconRect.x + iconWidth + iconGap;
956 if ((pDrawItem->GetIcon()) != null)
958 itemDrawIconRect.height = itemDrawRect.height - topMargin - bottomMargin;
959 itemDrawIconRect.y = itemDrawIconRect.y +topMargin+ (itemDrawIconRect.height - iconHeight)/2;
961 itemDrawIconRect.width = iconWidth;
962 itemDrawIconRect.height = iconHeight;
963 Bitmap* pIconBitmap = pDrawItem->GetIcon();
965 DrawResourceBitmap(*pCanvas, itemDrawIconRect, pIconBitmap);
970 itemDrawTextRect.x = itemDrawRect.x + leftMargin + (itemDrawRect.width - leftMargin - rightMargin - itemDrawTextRect.width)/2;
974 if (multiline == false)
976 itemDrawTextRect.y = itemDrawRect.y + topMargin + (itemDrawRect.height - topMargin - bottomMargin - itemDrawTextRect.height)/2;
980 itemDrawTextRect.y = itemDrawRect.y + topMargin + (itemDrawRect.height - topMargin - bottomMargin - itemDrawTextRect.height)/2;
982 __pTextObject->SetBounds(itemDrawTextRect);
983 __pTextObject->Compose();
984 if (itemStatus == _TABITEM_STATUS_SELECTED)
986 __pTextObject->SetForegroundColor(__pTab->GetSelectedTextColor(), 0, __pTextObject->GetTextLength());
987 __selectedLine.y = itemDrawRect.height - bottomMargin;
988 if (__pTab->GetSelectedItemBackgroundBitmap() == null)
990 DrawResourceBitmap(*pCanvas, __selectedLine, __pHorizontalLineBitmap);
993 else if (itemStatus == _TABITEM_STATUS_PRESSED)
995 __pTextObject->SetForegroundColor(__pTab->GetPressedTextColor(), 0, __pTextObject->GetTextLength());
997 else if (itemStatus == _TABITEM_STATUS_HIGHLIGHTED)
999 __pTextObject->SetForegroundColor(__pTab->GetHighlightedTextColor(), 0, __pTextObject->GetTextLength());
1003 __pTextObject->SetForegroundColor(__pTab->GetTextColor(), 0, __pTextObject->GetTextLength());
1006 __pTextObject->SetBounds(itemDrawTextRect);
1008 __pTextObject->Draw(*_CanvasImpl::GetInstance(*pCanvas));
1010 if (i < itemCount - 1)
1012 DrawItemDivisionVerticalLine(pCanvas, __dividerLine);
1014 DrawBadgeIcon(pDrawItem, pCanvas);
1021 _TabPresenter::DrawEditItem(const Point& point)
1024 _TabItem *pTabItem = null;
1025 Rectangle editRect(0, 0, 0, 0);
1026 pTabItem = GetItemAt(__editItemIndex);
1027 SysTryReturnVoidResult(NID_UI_CTRL, pTabItem, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1029 editRect = pTabItem->GetItemBounds();
1031 editRect.x = point.x - (__itemWidth / 2);
1032 pTabItem->SetItemBounds(editRect);
1039 _TabPresenter::DrawItemDivisionVerticalLine(Canvas* pCanvas, Rectangle& lineRect)
1041 DrawResourceBitmap(*pCanvas, lineRect, __pVerticalLineBitmap);
1047 _TabPresenter::DrawHorizontal()
1051 int itemCount = GetItemCount();
1052 int boundItemIndex = 0;
1053 if (__moveDistance == 0)
1059 SysLog(NID_UI_CTRL, "itemCount is 0.");
1062 //Bound beyond which the item shouldnt move when flicked
1063 boundItemIndex = itemCount - __itemMaxCount;
1065 _TabItem* pItem = null;
1066 pItem = GetItemAt(boundItemIndex);
1067 SysTryReturnVoidResult(NID_UI_CTRL, pItem, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1069 Rectangle bounds = pItem->GetItemBounds();
1070 Rectangle itemBounds(0, 0, 0, 0);
1071 if ((bounds.x + __moveDistance) < 0)
1073 __moveDistance = -bounds.x;
1074 ResetFlickAnimationTimer();
1077 pItem = GetItemAt(0);
1078 SysTryReturnVoidResult(NID_UI_CTRL, pItem, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1080 bounds = pItem->GetItemBounds();
1082 if ((bounds.x + __moveDistance) > 0)
1085 ResetFlickAnimationTimer();
1089 for (int i = 0; i < itemCount; i++)
1091 pItem = GetItemAt(i);
1092 SysTryReturnVoidResult(NID_UI_CTRL, pItem, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1094 itemBounds = pItem->GetItemBounds();
1096 itemBounds.x = itemBounds.x + __moveDistance;
1097 pItem->SetItemBounds(itemBounds);
1103 _TabPresenter::DrawBadgeIcon(_TabItem* pDrawItem, Canvas* pCanvas)
1105 Bitmap* pBadgeIcon = null;
1106 int badgeMargin = 0;
1107 GET_SHAPE_CONFIG(TAB::BADGE_ICON_MARGIN, __pTab->GetOrientation(), badgeMargin);
1109 pBadgeIcon = pDrawItem->GetBadgeIcon();
1111 if (pBadgeIcon != null)
1113 Rectangle badgeRect = pDrawItem->GetItemBounds();
1115 badgeRect.x = (badgeRect.x + badgeRect.width) - pBadgeIcon->GetWidth() - badgeMargin;
1116 badgeRect.y = badgeMargin;
1117 badgeRect.width = pBadgeIcon->GetWidth();
1118 badgeRect.height = pBadgeIcon->GetHeight();
1120 DrawResourceBitmap(*pCanvas, badgeRect, pBadgeIcon);
1128 _TabPresenter::CalcItemBounds(void)
1132 const int itemCount = GetItemCount();
1139 CalcTabBounds(true);
1141 Rectangle bounds = __pTab->GetBounds();
1143 _TabItem* pItem = null;
1144 Rectangle itemBounds(0, 0, 0, 0);
1146 if (__itemMaxCount > itemCount)
1148 __showItemCount = itemCount;
1152 __showItemCount = __itemMaxCount;
1155 itemBounds.width = bounds.width / __showItemCount;
1156 itemBounds.height = bounds.height;
1157 __itemWidth = itemBounds.width;
1158 __itemHeight = bounds.height;
1161 for (int i = 0; i < itemCount; i++)
1163 pItem = GetItemAt(i);
1164 SysTryReturnVoidResult(NID_UI_CTRL, pItem, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1166 __pAnimInfo[i]->xPosition = itemBounds.x;
1167 __pAnimInfo[i]->totalDistance = __itemWidth;
1168 pItem->SetItemBounds(itemBounds);
1169 itemBounds.x = itemBounds.x + itemBounds.width;
1175 _TabPresenter::CalcTabBounds(bool bReset)
1177 Rectangle bounds = __pTab->GetBounds();
1179 bool movable = __pTab->IsMovable();
1180 bool resizable = __pTab->IsResizable();
1183 int tabLeftMargin = 0;
1184 int tabRightMargin = 0;
1185 GET_SHAPE_CONFIG(TAB::LEFT_MARGIN, __pTab->GetOrientation(), tabLeftMargin);
1186 GET_SHAPE_CONFIG(TAB::RIGHT_MARGIN, __pTab->GetOrientation(), tabRightMargin);
1188 if (__pTab->GetStyle() == _TAB_STYLE_ICON_TEXT)
1190 GET_SHAPE_CONFIG(TAB::ICON_TEXT_HEIGHT, __pTab->GetOrientation(), lineHeight);
1194 GET_SHAPE_CONFIG(TAB::HEIGHT, __pTab->GetOrientation(), lineHeight);
1196 __lastItemIndex = (__pTab->GetItemCount() - 1);
1198 bounds.height = lineHeight;
1200 for (int i = 0; i < (__pTab->GetItemCount()); i++)
1202 if (__pAnimInfo[i] == null)
1204 __pAnimInfo[i] = new (std::nothrow) ReorderAnimationInfo();
1205 SysTryReturnVoidResult(NID_UI_CTRL, __pAnimInfo[i], E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
1207 __pAnimInfo[i]->totalDistance = 0;
1208 __pAnimInfo[i]->move = 0;
1209 __pAnimInfo[i]->reorderValue = 0;
1213 __pTab->SetMovable(true);
1214 __pTab->SetResizable(true);
1216 __pTab->SetBounds(bounds);
1218 __pTab->SetMovable(movable);
1219 __pTab->SetResizable(resizable);
1226 _TabPresenter::OnTouchPressed(const _Control& source, const _TouchInfo& touchinfo)
1228 if (GetItemCount() == 0)
1232 __currentTouchPosition = touchinfo.GetCurrentPosition();
1233 SetFirstLoadedItemIndex();
1234 SetLastLoadedItemIndex();
1236 ResetScrollAnimationTimer();
1237 SetReCalculateItemBounds(false);
1238 ResetFlickAnimationTimer();
1240 Point point = touchinfo.GetCurrentPosition();
1242 const int index = GetItemIndexFromPosition(touchinfo.GetCurrentPosition());
1247 if (GetItemStatus(index) != _TABITEM_STATUS_SELECTED)
1249 SetItemStatus(index, _TABITEM_STATUS_PRESSED);
1250 SetPressedItemIndex(index);
1253 __pTab->Invalidate();
1259 _TabPresenter::OnTouchReleased(const _Control& source, const _TouchInfo& touchinfo)
1261 if (GetItemCount() == 0)
1265 Point point = touchinfo.GetCurrentPosition();
1267 CancelReorderTimer();
1268 ResetScrollAnimationTimer();
1269 Rectangle itemBounds(0, 0, 0, 0);
1270 _TabItem* pItem = null;
1271 int index = GetItemIndexFromPosition(touchinfo.GetCurrentPosition());
1272 if (__pScrollingEffectVe)
1274 __pScrollingEffectVe->RemoveAllAnimations();
1275 __pTab->GetVisualElement()->DetachChild(*__pScrollingEffectVe);
1276 __pScrollingEffectVe->Destroy();
1277 __pScrollingEffectVe = null;
1278 __isScrollEffectEnded = false;
1279 __isScrollEffectStarted = false;
1281 int pressedIndex = GetPressedItemIndex();
1282 __isRightScrolable = false;
1283 if (index == -1 && !__isFlickEnabled)
1285 SetFirstLoadedItemIndex();
1286 if (GetItemStatus(pressedIndex) == _TABITEM_STATUS_PRESSED)
1288 SetItemStatus(pressedIndex, _TABITEM_STATUS_NORMAL);
1291 __moveDistance = -(GetItemAt(__firstLoadedItemIndex)->GetItemBounds().x);
1293 __pTab->Invalidate();
1298 if (__editMode && __editItemIndex == __rearIndex)
1300 Rectangle bounds(0,0,0,0);
1301 if(__editItemIndex > 0)
1303 pItem = GetItemAt((__editItemIndex - 1));
1304 SysTryReturn(NID_UI_CTRL, pItem, false, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1306 bounds = pItem->GetItemBounds();
1307 bounds.x = bounds.x + __itemWidth;
1308 GetItemAt(__editItemIndex)->SetItemBounds(bounds);
1316 // Edit Mode - Item Insert
1317 if (__editMode && (__editItemIndex != __rearIndex))
1319 index = __rearIndex;
1320 int i = GetSelectedItemIndex();
1321 SetItemStatus(i, _TABITEM_STATUS_NORMAL);
1323 if (__isDirectionRight)
1328 __pTab->ChangeItemAt(__editItemIndex, (index));
1329 if (__editItemIndex < index)
1331 SetItemStatus((index-1), _TABITEM_STATUS_SELECTED);
1332 SetSelectedItemIndex((index-1));
1334 else if (__editItemIndex > index)
1336 SetItemStatus(index, _TABITEM_STATUS_SELECTED);
1337 SetSelectedItemIndex(index);
1340 SetFirstLoadedItemIndex();
1341 SetLastLoadedItemIndex();
1345 __moveDistance = -(__firstLoadedItemIndex * __itemWidth);
1350 // Pressed -> Selected or Normal
1351 if (GetItemStatus(index) == _TABITEM_STATUS_PRESSED && !__isFlickEnabled && !__isTouchMove)
1353 int i = GetSelectedItemIndex();
1354 SetItemStatus(i, _TABITEM_STATUS_NORMAL);
1356 SetItemStatus(index, _TABITEM_STATUS_SELECTED);
1357 SetSelectedItemIndex(index);
1361 int i = GetPressedItemIndex();
1362 if (GetItemStatus(i) == _TABITEM_STATUS_PRESSED)
1364 SetItemStatus(i, _TABITEM_STATUS_NORMAL);
1370 __pTab->Invalidate();
1371 __isTouchMove = false;
1373 __editItemIndex = -1;
1376 if (__firstItemIndex > 0)
1381 if (__lastItemIndex < (__pTab->GetItemCount() - 1))
1390 _TabPresenter::OnTouchMoved(const _Control& source, const _TouchInfo& touchinfo)
1392 if (GetItemCount() == 0)
1396 _TabItem *pTabItem = null;
1397 _TabItem *pNextItem = null;
1398 _TabItem *pPrevItem = null;
1399 Point movedPosition = touchinfo.GetCurrentPosition();
1401 int index = GetNextItemIndexFromPosition(movedPosition, __editItemIndex);
1402 SetFirstLoadedItemIndex();
1403 SetLastLoadedItemIndex();
1404 //Remove the Pressed Bitmap during Touch Move
1405 int i = GetPressedItemIndex();
1408 if (GetItemStatus(i) == _TABITEM_STATUS_PRESSED)
1410 SetItemStatus(i, _TABITEM_STATUS_NORMAL);
1416 distance = movedPosition.x - __currentTouchPosition.x;
1417 __currentTouchPosition.x = movedPosition.x;
1418 if (!__editMode && distance > 0) //Move right i.e Bounce at leftEnd
1420 __isTouchMove = true;
1421 if (!__isDirectionRight)
1423 if (__pScrollingEffectVe)
1425 __pScrollingEffectVe->RemoveAllAnimations();
1426 __pTab->GetVisualElement()->DetachChild(*__pScrollingEffectVe);
1427 __pScrollingEffectVe->Destroy();
1428 __pScrollingEffectVe = null;
1430 __isScrollEffectEnded = false;
1431 __isScrollEffectStarted = false;
1433 __isDirectionRight = true;
1434 SetFirstLoadedItemIndex();
1435 if ( GetItemAt(0)->GetItemBounds().x >= 0)
1437 if (!__isScrollEffectStarted)
1439 __pScrollingEffectBitmap = __pFrontScrollingEffectBitmap;
1440 SetOpacityVisualElement(0);
1441 StartScrollingEffect();
1443 __isScrollEffectStarted = true;
1445 __moveDistance = distance;
1453 if (!__editMode && distance < 0)//Move left i.e Bounce at RightEnd
1455 __isTouchMove = true;
1456 if (__isDirectionRight)
1458 if (__pScrollingEffectVe)
1460 __pScrollingEffectVe->RemoveAllAnimations();
1461 __pTab->GetVisualElement()->DetachChild(*__pScrollingEffectVe);
1462 __pScrollingEffectVe->Destroy();
1463 __pScrollingEffectVe = null;
1465 __isScrollEffectEnded = false;
1466 __isScrollEffectStarted = false;
1468 __isDirectionRight = false;
1469 SetLastLoadedItemIndex();
1471 if ( __lastLoadedItemIndex == (GetItemCount() - 1) && ((GetItemAt(__lastLoadedItemIndex)->GetItemBounds().x + __itemWidth) <= (__width)))
1473 if (!__isScrollEffectStarted)
1475 int index = (GetItemCount() - 1);
1476 int xPosition = (GetItemAt(index)->GetItemBounds().x + (__itemWidth/2));
1477 __pScrollingEffectBitmap = __pRearScrollingEffectBitmap;
1478 SetOpacityVisualElement(xPosition);
1479 StartScrollingEffect();
1482 __isScrollEffectStarted = true;
1484 __moveDistance = distance;
1498 if (!__isDirectionRight)
1500 __isTimerCanceled = true;
1501 __isRightScrolable = false;
1502 __isLeftScrolable = false;
1503 CancelReorderTimer();
1505 __isDirectionRight = true;
1509 if (__isDirectionRight)
1511 __isTimerCanceled = true;
1512 __isLeftScrolable = false;
1513 __isRightScrolable = false;
1514 CancelReorderTimer();
1516 __isDirectionRight = false;
1518 pTabItem = GetItemAt(__editItemIndex);
1519 SysTryReturn(NID_UI_CTRL, pTabItem, false, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1521 Rectangle bounds = pTabItem->GetItemBounds();
1524 if (__isDirectionRight)
1526 pNextItem = GetItemAt(index);
1527 SysTryReturn(NID_UI_CTRL, pNextItem, false, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1529 Rectangle boundsNext = pNextItem->GetItemBounds();
1530 if ((bounds.x + (__itemWidth / 2) ) > (boundsNext.x) && ((bounds.x + __itemWidth) < (boundsNext.x + boundsNext.width)))
1532 __pTimerInfo[__timerCount]->index = index;
1533 StartReorderTimer(__timerCount);
1535 if (__timerCount >= (__itemMaxCount - 1))
1539 __isTimerCanceled = false;
1540 __rearIndex = index;
1546 pPrevItem = GetItemAt(index);
1547 SysTryReturn(NID_UI_CTRL, pPrevItem, false, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1549 Rectangle boundsPrev = pPrevItem->GetItemBounds();
1550 if ((bounds.x + 100) > (boundsPrev.x + 100) && ((bounds.x + 100) < (boundsPrev.x + boundsPrev.width)))
1552 __pTimerInfo[__timerCount]->index = index;
1553 StartReorderTimer(__timerCount);
1555 if (__timerCount >= (__itemMaxCount - 1))
1559 __isTimerCanceled = false;
1560 __rearIndex = index;
1565 else //Scroll the entire tab when item moves beyond boundary
1567 if ((bounds.x + __itemWidth) > (__width - (__itemWidth / 2)))
1569 if (__isDirectionRight)
1571 _TabItem *pLastItem = GetItemAt(__lastItemIndex);
1572 SysTryReturn(NID_UI_CTRL, pLastItem, false, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1574 if ((pLastItem->GetItemBounds().x + pLastItem->GetItemBounds().width) > __width)
1576 __isRightScrolable = true;
1577 StartScrollAnimationTimer();
1584 if (!__isDirectionRight)
1586 if (GetItemAt(__firstItemIndex)->GetItemBounds().x < __itemWidth)
1588 __isLeftScrolable = true;
1589 StartScrollAnimationTimer();
1595 DrawEditItem(movedPosition);
1596 __pTab->Invalidate();
1602 _TabPresenter::ShiftItems(void)
1604 Point pt = Point(0,0);
1605 int itemCount = GetItemCount();
1606 int fitDistance = 0;
1607 _TabItem* pTabItem = null;
1608 Rectangle bounds(0,0,0,0);
1609 pTabItem = GetItemAt(0);
1610 SysTryReturnVoidResult(NID_UI_CTRL, pTabItem, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1612 bounds = pTabItem->GetItemBounds();
1614 for (int i = 0; i < itemCount; i++)
1616 if (i == __editItemIndex)
1620 if (__isRightScrolable)
1623 if (i == __rearIndex + 1)
1625 fitDistance = -(2 * __itemWidth);
1630 fitDistance = -__itemWidth;
1635 if (i == __rearIndex - 1)
1637 fitDistance = (2 * __itemWidth);
1642 fitDistance = __itemWidth;
1646 pTabItem = GetItemAt(i);
1647 SysTryReturnVoidResult(NID_UI_CTRL, pTabItem, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1649 bounds = pTabItem->GetItemBounds();
1650 bounds.x = bounds.x + fitDistance;
1651 if ( i == __firstItemIndex && ( bounds.x ) >= (2 * __itemWidth))
1655 pTabItem->SetItemBounds(bounds);
1659 if (__isRightScrolable)
1664 if (__isLeftScrolable)
1673 _TabPresenter::OnLongPressGestureDetected(void)
1675 if (!__pTabModel->IsEditModeEnabled())
1679 const int index = GetItemIndexFromPosition(__currentTouchPosition);
1686 if (GetItemStatus(index) == _TABITEM_STATUS_PRESSED && GetSelectedItemIndex() != index)
1688 SetItemStatus(index, _TABITEM_STATUS_NORMAL);
1692 __editItemIndex = index;
1693 if (__editItemIndex == __firstItemIndex)
1695 __firstItemIndex = __firstItemIndex + 1;
1698 if (__editItemIndex == __lastItemIndex)
1700 __lastItemIndex = __lastItemIndex - 1;
1703 __rearIndex = index;
1704 __pTab->Invalidate();
1710 _TabPresenter::OnFlickGestureDetected(_TouchFlickGestureDetector& gesture)
1712 if (GetItemCount() == 0)
1721 if (gesture.GetDirection() != _FLICK_DIRECTION_RIGHT && gesture.GetDirection() != _FLICK_DIRECTION_LEFT)
1727 gesture.GetDistance(distanceX, distanceY);
1728 SetFirstLoadedItemIndex();
1729 SetLastLoadedItemIndex();
1731 int itemsBeyondScreen = 0;
1732 int itemCount = GetItemCount();
1733 if (distanceX < 0) //left
1735 itemsBeyondScreen = (itemCount - 1) - __lastLoadedItemIndex;
1736 xPosition = GetItemAt(__lastLoadedItemIndex)->GetItemBounds().x;
1737 if (xPosition < (3 * __itemWidth))
1739 __flickDistance = xPosition - (4 * __itemWidth);
1744 itemsBeyondScreen = __firstLoadedItemIndex;
1745 xPosition = GetItemAt(__firstLoadedItemIndex)->GetItemBounds().x;
1748 __flickDistance = -xPosition;
1752 if (itemsBeyondScreen >= (__itemMaxCount - 1))
1754 __flickDistance = (3 * __itemWidth);
1758 __flickDistance = (itemsBeyondScreen * __itemWidth);
1760 if (distanceX < 0) //Left flick
1762 __flickMove = 0.006;
1765 else if (distanceX > 0) //Right flick
1767 __flickMove = 0.006;
1768 __flickDistance = -(__flickDistance);
1774 __flickDistance = 0;
1778 __isFlickEnabled = true;
1780 StartFlickAnimationTimer();
1786 _TabPresenter::StartFlickAnimation(void)
1789 float distance = CalculateProgress(__flickMove);
1790 __moveDistance = -(__flickDistance * distance);
1792 __flickDistance = (__flickDistance + __moveDistance);
1793 __flickMove = __flickMove + 0.006;
1795 if (__flickFlag <= 400)
1797 StartFlickAnimationTimer();
1801 ResetFlickAnimationTimer();
1809 _TabPresenter::StartFlickAnimationTimer(void)
1811 result r = E_SUCCESS;
1813 if (__pFlickAnimationTimer == null)
1815 __pFlickAnimationTimer = new (std::nothrow) Timer;
1816 SysTryReturn(NID_UI_CTRL, (__pFlickAnimationTimer != null), E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
1818 r = __pFlickAnimationTimer->Construct(*this);
1819 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
1823 __pFlickAnimationTimer->Cancel();
1826 r = __pFlickAnimationTimer->Start(FLICK_ANIMATION_TIMER_PERIOD);
1827 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
1832 ResetFlickAnimationTimer();
1837 _TabPresenter::StartScrollAnimationTimer(void)
1839 result r = E_SUCCESS;
1840 ResetReorderTimer();
1841 if (__pScrollAnimationTimer == null)
1843 __pScrollAnimationTimer = new (std::nothrow) Timer;
1844 SysTryReturn(NID_UI_CTRL, (__pScrollAnimationTimer != null), E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
1846 r = __pScrollAnimationTimer->Construct(*this);
1847 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
1851 __pScrollAnimationTimer->Cancel();
1854 r = __pScrollAnimationTimer->Start(SCROLL_ANIMATION_TIMER_PERIOD);
1855 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
1860 ResetScrollAnimationTimer();
1865 _TabPresenter::ResetScrollAnimationTimer(void)
1867 if (__pScrollAnimationTimer)
1869 delete __pScrollAnimationTimer;
1870 __pScrollAnimationTimer = null;
1876 _TabPresenter::ResetFlickAnimationTimer(void)
1878 if (__pFlickAnimationTimer)
1880 delete __pFlickAnimationTimer;
1881 __pFlickAnimationTimer = null;
1884 __isFlickEnabled = false;
1890 _TabPresenter::SetItemFit(int index)
1892 Point pt = Point(0,0);
1893 int itemCount = GetItemCount();
1894 int fitDistance = 0;
1895 _TabItem* pTabItem = null;
1896 Rectangle bounds(0,0,0,0);
1897 pTabItem = GetItemAt(index);
1898 SysTryReturnVoidResult(NID_UI_CTRL, pTabItem, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1900 bounds = pTabItem->GetItemBounds();
1901 fitDistance = -bounds.x;
1902 for (int i = 0; i < itemCount; i++)
1904 pTabItem = GetItemAt(i);
1905 SysTryReturnVoidResult(NID_UI_CTRL, pTabItem, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1907 bounds = pTabItem->GetItemBounds();
1908 bounds.x = bounds.x + fitDistance;
1909 pTabItem->SetItemBounds(bounds);
1915 _TabPresenter::SetItemFitToLeft(void)
1917 SetItemFit(__firstLoadedItemIndex);
1922 _TabPresenter::SetItemFitToRight(void)
1924 SetItemFit(__lastLoadedItemIndex);
1929 _TabPresenter::OnTimerExpired(Timer& timer)
1931 if (&timer == __pFlickAnimationTimer)
1933 StartFlickAnimation();
1935 for (int i = 0; i < _TIMER_COUNT; i++)
1938 if (!__isTimerCanceled)
1940 if (&timer == __pTimerInfo[i]->pReorderTimer)
1942 StartReorderAnimation(__pTimerInfo[i]->index, i);
1946 if (&timer == __pScrollAnimationTimer)
1948 _TabItem* pLastItem = GetItemAt(__lastItemIndex);
1949 SysTryReturnVoidResult(NID_UI_CTRL, pLastItem, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1951 if ((GetItemAt(__firstItemIndex)->GetItemBounds().x >= __itemWidth))
1953 __isRightScrolable = false;
1954 __isLeftScrolable = false;
1956 if ((pLastItem->GetItemBounds().x + pLastItem->GetItemBounds().width) <= __width && __isDirectionRight)
1958 __isRightScrolable = false;
1959 __isLeftScrolable = false;
1961 if (__isRightScrolable || __isLeftScrolable)
1963 if ((__rearIndex - 1) == __editItemIndex && !__isDirectionRight)
1965 if (__isLeftScrolable)
1970 if ((__rearIndex + 1) == __editItemIndex && __isDirectionRight)
1972 if (__isRightScrolable)
1978 StartScrollAnimationTimer();
1983 ResetScrollAnimationTimer();
1990 _TabPresenter::CalculateProgress(float timeProgress) const
1992 const float segments[3][3] = {{0.0f, 0.01f, 0.45f}, {0.45f, 0.80f, 0.908f}, {0.908f, 0.9999f, 1.0f}};
1993 float loc_5 = timeProgress / 1;
1994 int loc_6 = 3; //Length of the segments array
1995 int loc_9 = (int)floor(loc_6 * loc_5);
2000 float loc_7 = (loc_5 - loc_9 * (1.0 / loc_6)) * loc_6;
2002 for (int i = 0; i < 3; i++)
2004 loc_8[i] = segments[loc_9][i];
2006 float ret = 0 + 1 * (loc_8[0] + loc_7 * (2 * (1 - loc_7) * (loc_8[1] - loc_8[0]) + loc_7 * (loc_8[2] - loc_8[0])));
2011 _TabPresenter::StartReorderTimer(int index)
2014 result r = E_SUCCESS;
2015 if (__pTimerInfo[index]->pReorderTimer == null)
2017 __pTimerInfo[index]->pReorderTimer = new (std::nothrow) Timer;
2018 SysTryReturn(NID_UI_CTRL, (__pTimerInfo[index]->pReorderTimer != null), E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
2020 r = __pTimerInfo[index]->pReorderTimer->Construct(*this);
2021 SysTryCatch(NID_UI, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
2025 __pTimerInfo[index]->pReorderTimer->Cancel();
2028 r = __pTimerInfo[index]->pReorderTimer->Start(REORDER_TIMER_PERIOD);
2029 SysTryCatch(NID_UI, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
2034 ResetReorderTimer();
2039 _TabPresenter::FreeHorizontalLineBitmap()
2041 if (__pHorizontalLineBitmap != null)
2043 delete __pHorizontalLineBitmap;
2044 __pHorizontalLineBitmap = null;
2051 _TabPresenter::CancelReorderTimer()
2054 for (int index = 0; index < (__pTab->GetItemCount()); index++)
2056 if (index < _TIMER_COUNT && __pTimerInfo[index])
2058 if (__pTimerInfo[index]->pReorderTimer)
2060 __pTimerInfo[index]->pReorderTimer->Cancel();
2064 __pAnimInfo[index]->totalDistance = __itemWidth;
2065 __pAnimInfo[index]->move = 0.5;
2066 __pAnimInfo[index]->reorderValue =0;
2072 _TabPresenter::ResetReorderTimer(int index)
2074 __pAnimInfo[index]->totalDistance = __itemWidth;
2075 __pAnimInfo[index]->move = 0.5;
2076 __pAnimInfo[index]->reorderValue =0;
2078 for (int i = 0; i <_TIMER_COUNT; i++)
2080 if (__pTimerInfo[i])
2082 if (__pTimerInfo[i]->pReorderTimer)
2084 __pTimerInfo[i]->pReorderTimer->Cancel();
2092 _TabPresenter::StopReorderTimer()
2094 for (int i = 0 ; i < _TIMER_COUNT; i++)
2096 if (__pTimerInfo[i])
2098 delete __pTimerInfo[i]->pReorderTimer;
2099 __pTimerInfo[i]->pReorderTimer = null;
2107 _TabPresenter::StartReorderAnimation(int index, int timerIndex)
2110 float dist = CalculateProgress(__pAnimInfo[index]->move);
2111 __reorderDist = -(__pAnimInfo[index]->totalDistance * dist);
2113 __pAnimInfo[index]->move = __pAnimInfo[index]->move + 0.5;
2114 __pAnimInfo[index]->totalDistance = (__pAnimInfo[index]->totalDistance + __reorderDist);
2116 if (!__isDirectionRight)
2118 __reorderDist = -__reorderDist;
2120 __pAnimInfo[index]->reorderValue++;
2122 if (__pAnimInfo[index]->reorderValue <= 50)
2124 SwapItems(index, __reorderDist);
2125 StartReorderTimer(timerIndex);
2130 ResetReorderTimer(index);
2140 _TabPresenter::SwapItems(int indexDest, int distance)
2143 Rectangle itemBounds(0,0,0,0);
2144 pItem = GetItemAt(indexDest);
2145 SysTryReturnVoidResult(NID_UI_CTRL, pItem, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
2147 itemBounds = pItem->GetItemBounds();
2148 itemBounds.x = itemBounds.x + distance;
2149 SetFirstLoadedItemIndex();
2150 SetLastLoadedItemIndex();
2153 index = GetNextItemIndexFromPosition(Point(itemBounds.x,itemBounds.y), __editItemIndex);
2154 if (distance < 0) //Moving Left
2156 animIndex = indexDest - __lastLoadedItemIndex;
2157 if (__pTab->GetItemCount() >= __itemMaxCount)
2159 animIndex = animIndex + (__itemMaxCount - 1);
2163 animIndex = animIndex + (__pTab->GetItemCount() - 1);
2165 if ((__lastLoadedItemIndex > __editItemIndex) && (indexDest < __editItemIndex))
2169 if ((itemBounds.x <= __pAnimInfo[animIndex]->xPosition) && (itemBounds.x >= __pAnimInfo[animIndex-1]->xPosition))
2171 if (index == -1 || index == indexDest) //to avoid overlaping of items on each other
2173 pItem->SetItemBounds(itemBounds);
2179 animIndex = indexDest - __firstLoadedItemIndex;
2180 if ((__firstLoadedItemIndex < __editItemIndex) && (indexDest > __editItemIndex))
2184 if ((itemBounds.x >= __pAnimInfo[animIndex]->xPosition) && (itemBounds.x <= __pAnimInfo[animIndex+1]->xPosition))
2186 if (index == -1 || index == indexDest)
2188 pItem->SetItemBounds(itemBounds);
2198 _TabPresenter::GetNextItemIndexFromPosition(const Point& point, int curIndex) const
2201 Rectangle itemBounds(0, 0, 0, 0);
2203 int itemIndex = GetFirstDrawnItemIndex();
2205 if ((point.x < 0) || (point.x > __pTab->GetBounds().width))
2210 _TabItem* pItem = __pTab->GetItemAt(itemIndex);
2216 while (pItem != null)
2218 itemBounds = pItem->GetItemBounds();
2220 if ((point.x > itemBounds.x) && (point.x < itemBounds.x + itemBounds.width))
2222 if (curIndex != itemIndex)
2227 pItem = __pTab->GetItemAt(itemIndex);
2238 _TabPresenter::SetFirstLoadedItemIndex()
2240 for (int i = 0; i < __pTab->GetItemCount(); i++)
2242 if (__editItemIndex == i)
2246 if ((GetItemAt(i)->GetItemBounds().x + 50) <= __itemWidth)
2248 __firstLoadedItemIndex = i;
2255 _TabPresenter::SetLastLoadedItemIndex()
2257 for (int i = 0; i < __pTab->GetItemCount(); i++)
2259 int X = GetItemAt(i)->GetItemBounds().x;
2260 if (__editItemIndex == i)
2264 if ((X + 50) < __width)
2266 __lastLoadedItemIndex = i;
2273 _TabPresenter::RefreshAccessibilityElement(void)
2275 if (likely(!(_AccessibilityManager::IsActivated())))
2280 __pTab->RemoveAllAccessibilityElement();
2282 for (int index = 0; index < GetItemCount(); index++)
2284 _TabItem* pItem = GetItemAt(index);
2288 __pTab->AddAccessibilityElement(pItem->GetItemBounds(), pItem->GetText(), pItem->GetStatus());
2297 _TabPresenter::OnFontChanged(Font* pFont)
2304 _TabPresenter::OnFontInfoRequested(unsigned long& style, int& size)
2306 style = FONT_STYLE_BOLD;
2307 GET_SHAPE_CONFIG(TAB::FONT_SIZE_01, __pTab->GetOrientation(), size);
2312 _TabPresenter::OnBoundsChanged()
2314 Rectangle bounds = __pTab->GetBounds();
2315 if (bounds.width <= __tabMinimumSize)
2317 bounds.width = __tabMinimumSize;
2319 __pTab->SetBounds(bounds);
2320 SetReCalculateItemBounds(true);
2326 _TabPresenter::OnAccessibilityFocusMovedNext(const _AccessibilityContainer& control, const _AccessibilityElement& element)
2328 if (element.GetBounds().x < 0)
2330 SetReCalculateItemBounds(true);
2334 if ((element.GetBounds().x + element.GetBounds().width) > __pTab->GetBounds().width)
2336 __moveDistance = (element.GetBounds().width) * (-1);
2345 _TabPresenter::OnAccessibilityFocusMovedPrevious(const _AccessibilityContainer& control, const _AccessibilityElement& element)
2347 if (element.GetBounds().x > (__pTab->GetBounds().x + __pTab->GetBounds().width))
2349 int noOfItems = GetItemCount();
2350 __moveDistance = (noOfItems - __itemMaxCount) * element.GetBounds().width * (-1);
2355 if (element.GetBounds().x < 0)
2357 __moveDistance = element.GetBounds().width;
2366 _TabPresenter::SetOpacityVisualElement(int xPosition)
2368 Canvas * pCanvas = null;
2369 int bounceWidth = (__itemWidth / 2);
2370 if (__pScrollingEffectVe == null)
2372 __pScrollingEffectVe = new (std::nothrow) _VisualElement();
2373 SysTryReturnVoidResult(NID_UI_CTRL, __pScrollingEffectVe, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
2375 __pScrollingEffectVe->Construct();
2376 __pScrollingEffectVe->SetName(L"Opacity");
2378 __pScrollingEffectVe->SetBounds(FloatRectangle(xPosition, 0, bounceWidth, __itemHeight));
2379 __pScrollingEffectVe->SetShowState(true);
2380 __pScrollingEffectVe->SetImplicitAnimationEnabled(true);
2381 __pTab->GetVisualElement()->AttachChild(*__pScrollingEffectVe);
2382 pCanvas = __pScrollingEffectVe->GetCanvasN();
2385 __pScrollingEffectVe->Destroy();
2386 __pScrollingEffectVe = null;
2388 SysLog(NID_UI_CTRL, "[%s] Propagating.", GetErrorMessage(GetLastResult()));
2391 Color backgroundColor(0,0,0,0);
2392 pCanvas->SetBackgroundColor(backgroundColor);
2394 Rectangle rect(0, 0, bounceWidth, __itemHeight);
2396 DrawResourceBitmap(*pCanvas, rect, __pScrollingEffectBitmap);
2403 _TabPresenter::StartScrollingEffect(void)
2405 float __startOpacity = 0.0f;
2406 float __endOpacity = 1.0f;
2407 VisualElementPropertyAnimation* pAnimation = new (std::nothrow) VisualElementPropertyAnimation();
2408 SysTryReturnVoidResult(NID_UI_CTRL, pAnimation, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
2410 pAnimation->SetPropertyName(L"opacity");
2411 pAnimation->SetStartValue(Variant(__startOpacity));
2412 pAnimation->SetEndValue(Variant(__endOpacity));
2413 pAnimation->SetDuration(500);
2414 pAnimation->SetVisualElementAnimationStatusEventListener(this);
2416 String animationName3(L"opacity");
2417 __pScrollingEffectVe->AddAnimation(animationName3, *pAnimation);
2420 __isScrollEffectStarted = true;
2426 _TabPresenter::OnVisualElementAnimationStarted(const VisualElementAnimation& animation, const String& keyName, VisualElement& target)
2432 _TabPresenter::OnVisualElementAnimationRepeated(const VisualElementAnimation& animation, const String& keyName, VisualElement& target, long currentRepeatCount)
2438 _TabPresenter::OnVisualElementAnimationFinished(const VisualElementAnimation& animation, const String& keyName, VisualElement& target, bool completedNormally)
2444 }}} // Tizen::Ui::Controls