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.
18 * @file FUiCtrl_TabBarPresenter.cpp
19 * @brief This is the implementation file for the _TabBarPresenter class.
23 #include <FBaseErrorDefine.h>
24 #include <FBaseSysLog.h>
25 #include <FGrp_BitmapImpl.h>
26 #include <FGrp_CanvasImpl.h>
27 #include <FGrp_TextTextSimple.h>
28 #include "FUi_AccessibilityContainer.h"
29 #include "FUi_AccessibilityElement.h"
30 #include "FUi_CoordinateSystemUtils.h"
32 #include "FUi_ResourceManager.h"
33 #include "FUi_UiTouchEvent.h"
35 #include "FUiCtrl_TabBarPresenter.h"
38 using namespace Tizen::Ui;
39 using namespace Tizen::Base;
40 using namespace Tizen::Graphics;
41 using namespace Tizen::Graphics::_Text;
43 namespace Tizen { namespace Ui { namespace Controls
46 _TabBarPresenter::_TabBarPresenter(_TabBar& tabBar)
48 , __pTabBarModel(null)
51 , __startPosition(FloatPoint(0.0f, 0.0f))
52 , __pressedItemIndex(-1)
54 , __touchBubblingBlocked(true)
59 , __itemMaxWidth(0.0f)
60 , __pBgBitmapCached(null)
61 , __pBgEffectBitmapCached(null)
62 , __pLeftArrowBitmapCached(null)
63 , __pRightArrowBitmapCached(null)
65 for (int i = 0; i < ITEM_STATUS_MAX; i++)
67 __pItemBgBitmapCached[i] = null;
70 GET_SHAPE_CONFIG(TABBAR::TOP_MARGIN, _CONTROL_ORIENTATION_PORTRAIT, __topMargin);
71 GET_SHAPE_CONFIG(TABBAR::SIDE_MARGIN, _CONTROL_ORIENTATION_PORTRAIT, __sideMargin);
72 GET_SHAPE_CONFIG(TABBAR::ITEM_MARGIN, _CONTROL_ORIENTATION_PORTRAIT, __itemMargin);
73 GET_SHAPE_CONFIG(TABBAR::ARROW_MARGIN, _CONTROL_ORIENTATION_PORTRAIT, __arrowMargin);
74 GET_SHAPE_CONFIG(TABBAR::ITEM_MAX_WIDTH, _CONTROL_ORIENTATION_PORTRAIT, __itemMaxWidth);
77 _TabBarPresenter::~_TabBarPresenter(void)
79 delete __pTabBarModel;
80 __pTabBarModel = null;
84 __pTextObject->RemoveAll();
89 delete __pBgBitmapCached;
90 __pBgBitmapCached = null;
92 delete __pBgEffectBitmapCached;
93 __pBgEffectBitmapCached = null;
95 for (int i = 0; i < ITEM_STATUS_MAX; i++)
97 delete __pItemBgBitmapCached[i];
98 __pItemBgBitmapCached[i] = null;
101 delete __pLeftArrowBitmapCached;
102 __pLeftArrowBitmapCached = null;
104 delete __pRightArrowBitmapCached;
105 __pRightArrowBitmapCached = null;
109 _TabBarPresenter::Construct(void)
111 __pTabBarModel = new (std::nothrow) _TabBarModel;
112 SysTryReturn(NID_UI_CTRL, __pTabBarModel != null, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
114 result r = E_SUCCESS;
117 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
122 delete __pTabBarModel;
123 __pTabBarModel = null;
129 _TabBarPresenter::InitializeFont(void)
131 result r = E_SUCCESS;
132 __pFont = __tabBar.GetFallbackFont();
133 SysTryCatch(NID_UI_CTRL, __pFont != null, r = E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
135 __pTextObject = new (std::nothrow) TextObject();
136 SysTryCatch(NID_UI_CTRL, __pTextObject != null, r = E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
138 __pTextObject->Construct();
139 __pTextObject->SetAlignment(TEXT_OBJECT_ALIGNMENT_CENTER | TEXT_OBJECT_ALIGNMENT_MIDDLE);
140 __pTextObject->SetFont(__pFont, 0, __pTextObject->GetTextLength());
145 delete __pTextObject;
146 __pTextObject = null;
152 _TabBarPresenter::OnFontChanged(Font* pFont)
158 _TabBarPresenter::OnFontInfoRequested(unsigned long& style, float& size)
160 float fontSize = 0.0f;
161 GET_SHAPE_CONFIG(TABBAR::FONT_SIZE, __tabBar.GetOrientation(), fontSize);
163 style = FONT_STYLE_PLAIN;
168 _TabBarPresenter::LoadBitmap(void)
170 Bitmap* pBitmap = null;
173 GET_COLOR_CONFIG(TABBAR::ARROW_BG_NORMAL, arrowColor);
175 if (__pBgBitmapCached != null)
177 delete __pBgBitmapCached;
178 __pBgBitmapCached = null;
181 if (__pBgEffectBitmapCached != null)
183 delete __pBgEffectBitmapCached;
184 __pBgEffectBitmapCached = null;
187 if (__pLeftArrowBitmapCached != null)
189 delete __pLeftArrowBitmapCached;
190 __pLeftArrowBitmapCached = null;
193 if (__pRightArrowBitmapCached == null)
195 delete __pRightArrowBitmapCached;
196 __pRightArrowBitmapCached = null;
199 for (int i = 0; i < ITEM_STATUS_MAX; i++)
201 if (__pItemBgBitmapCached[i] != null)
203 delete __pItemBgBitmapCached[i];
204 __pItemBgBitmapCached[i] = null;
209 r = GET_BITMAP_CONFIG_N(TABBAR::BG_NORMAL, BITMAP_PIXEL_FORMAT_ARGB8888, pBitmap);
210 SysTryCatch(NID_UI_CTRL, (r == E_SUCCESS), , r, "[%s] Propagating.", GetErrorMessage(r));
211 __pBgBitmapCached = _BitmapImpl::GetColorReplacedBitmapN(*pBitmap, Color::GetColor(COLOR_ID_MAGENTA), __tabBar.GetColor());
215 r = GET_BITMAP_CONFIG_N(TABBAR::BG_OUTLINE_EFFECT_NORMAL, BITMAP_PIXEL_FORMAT_ARGB8888, __pBgEffectBitmapCached);
216 SysTryCatch(NID_UI_CTRL, (r == E_SUCCESS), , r, "[%s] Propagating.", GetErrorMessage(r));
218 r = GET_BITMAP_CONFIG_N(TABBAR::LEFT_ARROW_NORMAL, BITMAP_PIXEL_FORMAT_ARGB8888, pBitmap);
219 __pLeftArrowBitmapCached = _BitmapImpl::GetColorReplacedBitmapN(*pBitmap, Color::GetColor(COLOR_ID_MAGENTA), arrowColor);
220 SysTryCatch(NID_UI_CTRL, (r == E_SUCCESS), , r, "[%s] Propagating.", GetErrorMessage(r));
224 r = GET_BITMAP_CONFIG_N(TABBAR::RIGHT_ARROW_NORMAL, BITMAP_PIXEL_FORMAT_ARGB8888, pBitmap);
225 __pRightArrowBitmapCached = _BitmapImpl::GetColorReplacedBitmapN(*pBitmap, Color::GetColor(COLOR_ID_MAGENTA), arrowColor);
226 SysTryCatch(NID_UI_CTRL, (r == E_SUCCESS), , r, "[%s] Propagating.", GetErrorMessage(r));
230 r = GET_BITMAP_CONFIG_N(TABBAR::ITEM_BG_SELECTED, BITMAP_PIXEL_FORMAT_ARGB8888, pBitmap);
231 __pItemBgBitmapCached[ITEM_STATUS_SELECTED] = _BitmapImpl::GetColorReplacedBitmapN(*pBitmap, Color::GetColor(COLOR_ID_MAGENTA), __tabBar.GetItemColor(ITEM_STATUS_SELECTED));
232 SysTryCatch(NID_UI_CTRL, (r == E_SUCCESS), , r, "[%s] Propagating.", GetErrorMessage(r));
236 r = GET_BITMAP_CONFIG_N(TABBAR::ITEM_BG_PRESSED, BITMAP_PIXEL_FORMAT_ARGB8888, pBitmap);
237 __pItemBgBitmapCached[ITEM_STATUS_PRESSED] = _BitmapImpl::GetColorReplacedBitmapN(*pBitmap, Color::GetColor(COLOR_ID_MAGENTA), __tabBar.GetItemColor(ITEM_STATUS_PRESSED));
238 SysTryCatch(NID_UI_CTRL, (r == E_SUCCESS), , r, "[%s] Propagating.", GetErrorMessage(r));
242 r = GET_BITMAP_CONFIG_N(TABBAR::ITEM_BG_DISABLED, BITMAP_PIXEL_FORMAT_ARGB8888, pBitmap);
243 __pItemBgBitmapCached[ITEM_STATUS_DISABLED] = _BitmapImpl::GetColorReplacedBitmapN(*pBitmap, Color::GetColor(COLOR_ID_MAGENTA), __tabBar.GetItemColor(ITEM_STATUS_DISABLED));
244 SysTryCatch(NID_UI_CTRL, (r == E_SUCCESS), , r, "[%s] Propagating.", GetErrorMessage(r));
253 delete __pBgBitmapCached;
254 __pBgBitmapCached = null;
256 delete __pLeftArrowBitmapCached;
257 __pLeftArrowBitmapCached = null;
259 delete __pRightArrowBitmapCached;
260 __pRightArrowBitmapCached = null;
262 for (int i = 0; i < ITEM_STATUS_MAX; i++)
264 delete __pItemBgBitmapCached[i];
265 __pItemBgBitmapCached[i] = null;
268 return E_OUT_OF_MEMORY;
272 _TabBarPresenter::AddItem(const Tizen::Base::String& text, int actionId)
274 return __pTabBarModel->AddItem(text, actionId, _CONTROL_ORIENTATION_PORTRAIT);
278 _TabBarPresenter::InsertItemAt(int index, const Tizen::Base::String& text, int actionId)
280 if (index <= __pTabBarModel->GetSelectedItemIndex())
282 if (__pTabBarModel->GetItemCount() != 0)
284 __pTabBarModel->SetSelectedItemIndex(GetSelectedItemIndex() + 1);
288 result r = __pTabBarModel->InsertItemAt(index, text, actionId, _CONTROL_ORIENTATION_PORTRAIT);
289 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
295 _TabBarPresenter::SetItemAt(int index, const Tizen::Base::String& text, int actionId)
297 return __pTabBarModel->SetItemAt(index, text, actionId, _CONTROL_ORIENTATION_PORTRAIT);
301 _TabBarPresenter::GetItemAt(int index) const
303 _TabBarItem* pItem = __pTabBarModel->GetItemAt(index);
308 _TabBarPresenter::RemoveItemAt(int index)
310 if (index <= GetSelectedItemIndex())
312 if (__pTabBarModel->GetItemCount() != 0 && GetSelectedItemIndex() != 0)
314 __pTabBarModel->SetSelectedItemIndex(GetSelectedItemIndex() - 1);
318 result r = __pTabBarModel->RemoveItemAt(index, _CONTROL_ORIENTATION_PORTRAIT);
319 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
321 if (GetItemCount() != 0)
323 r = SetItemSelected(0);
324 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
328 __pTabBarModel->SetSelectedItemIndex(0);
335 _TabBarPresenter::RemoveAllItems(void)
337 __pTabBarModel->RemoveAllItems();
342 _TabBarPresenter::SetItemSelected(int index)
345 SysTryReturn(NID_UI_CTRL, index >= 0 && index < GetItemCount(), E_OUT_OF_RANGE, E_OUT_OF_RANGE, "[E_OUT_OF_RANGE] The argument is out of range.");
347 int oldSelectedItemIndex = GetSelectedItemIndex();
348 if (index == oldSelectedItemIndex)
352 _TabBarItem* pItem = GetItemAt(oldSelectedItemIndex);
353 result r = GetLastResult();
354 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
355 pItem->SetStatus(ITEM_STATUS_NORMAL);
356 _AccessibilityElement* pElement = pItem->GetAccessibilityElement();
359 pElement->SetStatus(L"");
360 pElement->SetHintDisabled(false);
363 pItem = GetItemAt(index);
365 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
366 pItem->SetStatus(ITEM_STATUS_SELECTED);
367 pElement = pItem->GetAccessibilityElement();
370 pElement->SetStatusWithStringId("IDS_TPLATFORM_BODY_SELECTED_T_TTS");
371 pElement->SetHintDisabled(true);
374 __pTabBarModel->SetSelectedItemIndex(index);
380 _TabBarPresenter::GetSelectedItemIndex(void) const
382 return __pTabBarModel->GetSelectedItemIndex();
386 _TabBarPresenter::GetItemCount(void) const
388 return __pTabBarModel->GetItemCount();
392 _TabBarPresenter::GetItemIndexFromPosition(const Tizen::Graphics::FloatPoint& point) const
394 FloatRectangle clientBounds = __tabBar.GetBoundsF();
396 if (point.x < __sideMargin
397 || point.x > clientBounds.width - __sideMargin
398 || point.y < __topMargin
399 || point.y > clientBounds.height - __topMargin)
404 int itemIndex = __pTabBarModel->GetFirstDrawnItemIndex();
405 _TabBarItem* pItem = __pTabBarModel->GetItemAt(itemIndex);
407 while (pItem != null)
409 FloatRectangle itemBounds = pItem->GetBounds();
411 if (point.x - __sideMargin > itemBounds.x
412 && point.x - __sideMargin < itemBounds.x + itemBounds.width
413 && point.y - __topMargin > itemBounds.y
414 && point.y - __topMargin < itemBounds.y + itemBounds.height)
419 pItem = __pTabBarModel->GetItemAt(itemIndex);
426 _TabBarPresenter::GetItemIndexFromAbsPosition(const Tizen::Graphics::FloatPoint& point) const
428 FloatRectangle clientBounds = __tabBar.GetBoundsF();
431 _TabBarItem* pItem = __pTabBarModel->GetItemAt(itemIndex);
433 while (pItem != null)
435 FloatRectangle itemBounds = pItem->GetBounds();
437 if (point.x - __sideMargin > itemBounds.x
438 && point.x - __sideMargin < itemBounds.x + itemBounds.width
439 && point.y - __topMargin > itemBounds.y
440 && point.y - __topMargin < itemBounds.y + itemBounds.height)
445 pItem = __pTabBarModel->GetItemAt(itemIndex);
452 _TabBarPresenter::GetItemFromPosition(const Tizen::Graphics::FloatPoint& position) const
454 SetLastResult(E_SUCCESS);
455 int index = GetItemIndexFromPosition(position);
456 SysTryReturn(NID_UI_CTRL, index != -1, null, E_SYSTEM, "[E_SYSTEM] Item not found.");
458 return __pTabBarModel->GetItemAt(index);
462 _TabBarPresenter::SetTopDrawnItemIndex(int index)
464 SysTryReturn(NID_UI_CTRL, index >= 0 && index < GetItemCount(),
465 E_OUT_OF_RANGE, E_OUT_OF_RANGE, "[E_OUT_OF_RANGE] The argument(%d) is out of range.", index);
467 _TabBarItem* pTopItem = GetItemAt(index);
468 result r = GetLastResult();
469 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
471 float distance = pTopItem->GetBounds().x;
473 _TabBarItem* pLastItem = GetItemAt(GetItemCount() - 1);
474 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
476 FloatRectangle clientBounds = __tabBar.GetBoundsF();
477 float movableDistance = (pLastItem->GetBounds().x + pLastItem->GetBounds().width) - (clientBounds.width - __sideMargin * 2.0f - __arrowMargin * 2.0f);
478 if (movableDistance < distance)
480 distance = movableDistance;
483 r = AdjustItemPositionX(-distance);
484 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
490 _TabBarPresenter::SetItemStatus(int index, _TabBarItemStatus status)
492 _TabBarItem* pItem = __pTabBarModel->GetItemAt(index);
493 SysTryReturn(NID_UI_CTRL, pItem, E_SYSTEM, E_SYSTEM, "[E_SYSTEM] Item(%d) not exists.", index);
495 pItem->SetStatus(status);
501 _TabBarPresenter::GetItemStatus(int index) const
503 _TabBarItem* pItem = __pTabBarModel->GetItemAt(index);
504 SysTryReturn(NID_UI_CTRL, pItem, ITEM_STATUS_NORMAL, E_SYSTEM, "[E_SYSTEM] Item(%d) not exists.", index);
506 _TabBarItemStatus status = pItem->GetStatus();
512 _TabBarPresenter::AdjustItemPositionX(float distance)
516 while (index < GetItemCount())
518 _TabBarItem* pItem = __pTabBarModel->GetItemAt(index);
519 SysTryReturn(NID_UI_CTRL, pItem, E_INVALID_STATE, E_INVALID_STATE, "[E_INVALID_STATE] Item(%d) not exists.", index);
520 FloatRectangle bounds = pItem->GetBounds();
521 bounds.x += distance;
522 pItem->SetBounds(bounds);
526 SetAllAccessibilityElement();
532 _TabBarPresenter::SetReplacementColor(const Tizen::Graphics::Color& color)
534 Bitmap* pBitmap = null;
535 Bitmap* pColorReplcedBitmap = null;
538 r = GET_BITMAP_CONFIG_N(TABBAR::BG_NORMAL, BITMAP_PIXEL_FORMAT_ARGB8888, pBitmap);
539 SysTryReturn(NID_UI_CTRL, pBitmap != null, E_SYSTEM, E_SYSTEM, "[E_SYSTEM] Image loading fail.");
541 pColorReplcedBitmap = _BitmapImpl::GetColorReplacedBitmapN(*pBitmap, Color::GetColor(COLOR_ID_MAGENTA), color);
544 if (__pBgBitmapCached != null)
546 delete __pBgBitmapCached;
548 __pBgBitmapCached = pColorReplcedBitmap;
554 _TabBarPresenter::SetItemReplacementColor(_TabBarItemStatus itemStatus, const Tizen::Graphics::Color& color)
556 Bitmap* pBitmap = null;
557 Bitmap* pColorReplcedBitmap = null;
560 if (itemStatus == ITEM_STATUS_SELECTED)
562 r = GET_BITMAP_CONFIG_N(TABBAR::ITEM_BG_SELECTED, BITMAP_PIXEL_FORMAT_ARGB8888, pBitmap);
563 SysTryReturn(NID_UI_CTRL, pBitmap != null, E_SYSTEM, E_SYSTEM, "[E_SYSTEM] Image loading fail.");
565 else if (itemStatus == ITEM_STATUS_PRESSED)
567 r = GET_BITMAP_CONFIG_N(TABBAR::ITEM_BG_PRESSED, BITMAP_PIXEL_FORMAT_ARGB8888, pBitmap);
568 SysTryReturn(NID_UI_CTRL, pBitmap != null, E_SYSTEM, E_SYSTEM, "[E_SYSTEM] Image loading fail.");
575 pColorReplcedBitmap = _BitmapImpl::GetColorReplacedBitmapN(*pBitmap, Color::GetColor(COLOR_ID_MAGENTA), color);
578 if (__pItemBgBitmapCached[itemStatus] != null)
580 delete __pItemBgBitmapCached[itemStatus];
582 __pItemBgBitmapCached[itemStatus] = pColorReplcedBitmap;
588 _TabBarPresenter::Draw(void)
590 Canvas* pCanvas = __tabBar.GetCanvasN();
591 SysTryReturnVoidResult(NID_UI_CTRL, pCanvas != null, E_SYSTEM, "[E_SYSTEM] It can not get canvas.");
593 FloatRectangle clientBounds = __tabBar.GetBoundsF();
596 DrawBackground(pCanvas);
600 FloatRectangle rect(__sideMargin, 0.0f, clientBounds.width - __sideMargin * 2.0f, clientBounds.height);
601 Canvas* pSubCanvas = __tabBar.GetCanvasN(rect);
603 if (pSubCanvas != null)
605 DrawItem(pSubCanvas);
611 _TabBarPresenter::ShiftToFocusedItem(int itemIndex, _FocusDirectionMove direction)
613 int firstDrawnItemIndex = __pTabBarModel->GetFirstDrawnItemIndex();
614 int lastDrawnItemIndex = __pTabBarModel->GetLastDrawnItemIndex();
616 result r = E_SUCCESS;
618 if (direction == _FOCUS_DIRECTION_MOVE_LEFT)
620 index = itemIndex - 1;
622 else if (direction == _FOCUS_DIRECTION_MOVE_RIGHT)
624 index = itemIndex + 1;
627 _TabBarItem* pItem = GetItemAt(itemIndex);
628 SysTryReturn(NID_UI_CTRL, pItem != null, E_SYSTEM, E_SYSTEM, "[E_SYSTEM] Item loading fail.");
630 FloatRectangle itemBounds = pItem->GetBounds();
631 FloatRectangle clientBounds = __tabBar.GetBoundsF();
632 if (itemBounds.x < 0.0f || clientBounds.width - __sideMargin * 2.0f < itemBounds.x + (itemBounds.width))
634 if(index <= firstDrawnItemIndex)
636 r = SetTopDrawnItemIndex(itemIndex);
640 r = SetTopDrawnItemIndex(firstDrawnItemIndex + 1);
642 pItem = GetItemAt(itemIndex);
643 SysTryReturn(NID_UI_CTRL, pItem != null, E_SYSTEM, E_SYSTEM, "[E_SYSTEM] Item loading fail.");
645 itemBounds = pItem->GetBounds();
646 AdjustItemPositionX((clientBounds.width - (__sideMargin * 2.0f)) - (itemBounds.x + itemBounds.width));
649 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
652 if(itemIndex == 0) //when touchedCOM
657 __tabBar.Invalidate();
663 _TabBarPresenter::ResetItemPositionX(void)
665 int itemCount = GetItemCount();
671 _TabBarItem* pFirstItem = __pTabBarModel->GetItemAt(0);
672 _TabBarItem* pLastItem = __pTabBarModel->GetItemAt(itemCount - 1);
673 SysTryReturnVoidResult(NID_UI_CTRL, pFirstItem != null && pLastItem != null, E_SYSTEM, "[E_SYSTEM] Item not found.");
675 FloatRectangle clientBounds = __tabBar.GetBoundsF();
676 FloatRectangle firstItemBounds = pFirstItem->GetBounds();
677 FloatRectangle lastItemBounds = pLastItem->GetBounds();
679 if (!_FloatCompare(firstItemBounds.x, 0.0f) && lastItemBounds.x + lastItemBounds.width - firstItemBounds.x < clientBounds.width - __sideMargin * 2.0f)
681 AdjustItemPositionX(-firstItemBounds.x);
683 else if (!_FloatCompare(firstItemBounds.x, 0.0f) && lastItemBounds.x + lastItemBounds.width < clientBounds.width - __sideMargin * 2.0f)
685 AdjustItemPositionX(clientBounds.width - (__sideMargin + __arrowMargin) * 2.0f - (lastItemBounds.x + lastItemBounds.width));
690 _TabBarPresenter::OnBoundsChanged(void)
692 return ResetItemPositionX();
696 _TabBarPresenter::DrawItem(Tizen::Graphics::Canvas* pCanvas)
698 SysTryReturnVoidResult(NID_UI_CTRL, __pTextObject != null, E_INVALID_STATE, "[E_INVALID_STATE] TextObject is not constructed.");
700 FloatRectangle clientBounds = pCanvas->GetBoundsF();
702 _TabBarItem* pDrawItem = null;
703 FloatRectangle itemBounds(0.0f, 0.0f, 0.0f, 0.0f);
705 String drawText(L"");
706 FloatRectangle textRect(0.0f, 0.0f, 0.0f, 0.0f);
707 TextSimple* pSimpleText = null;
710 _TabBarItemStatus itemStatus = ITEM_STATUS_NORMAL;
712 __pTabBarModel->SetFirstDrawnItemIndex(-1);
713 __pTabBarModel->SetLastDrawnItemIndex(-1);
714 int itemCount = GetItemCount();
715 for (int i = 0; i < itemCount; i++)
717 pDrawItem = __pTabBarModel->GetItemAt(i);
718 if (pDrawItem == null)
723 itemBounds = pDrawItem->GetBounds();
725 if (itemBounds.x + itemBounds.width < 0.0f)
730 if (itemBounds.x > clientBounds.width)
735 if (__pTabBarModel->GetFirstDrawnItemIndex() == -1)
737 __pTabBarModel->SetFirstDrawnItemIndex(i);
740 __pTabBarModel->SetLastDrawnItemIndex(i);
742 itemStatus = pDrawItem->GetStatus();
744 if (!__tabBar.IsEnabled())
746 textColor = __tabBar.GetItemTextColor(ITEM_STATUS_DISABLED);
747 if (__pItemBgBitmapCached[ITEM_STATUS_DISABLED] != null)
749 pCanvas->DrawNinePatchedBitmap(itemBounds, *__pItemBgBitmapCached[ITEM_STATUS_DISABLED]);
754 textColor = __tabBar.GetItemTextColor(itemStatus);
755 if (__pItemBgBitmapCached[itemStatus] != null)
757 pCanvas->DrawNinePatchedBitmap(itemBounds, *__pItemBgBitmapCached[itemStatus]);
762 textRect = FloatRectangle(itemBounds.x, itemBounds.y, itemBounds.width, itemBounds.height);
763 if (textRect.x < 0.0f)
765 textRect.width += textRect.x;
769 if (textRect.x + textRect.width > clientBounds.width)
771 textRect.width = clientBounds.width - textRect.x;
774 drawText = pDrawItem->GetText();
775 __pTextObject->RemoveAll();
776 pSimpleText = new (std::nothrow)TextSimple(const_cast <wchar_t*>(drawText.GetPointer()), drawText.GetLength());
777 SysTryReturnVoidResult(NID_UI_CTRL, pSimpleText != null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] TextSimple is not constructed.");
779 __pFont = __tabBar.GetFallbackFont();
780 SysTryReturnVoidResult(NID_UI_CTRL, __pFont != null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
782 __pTextObject->AppendElement(*pSimpleText);
784 __pTextObject->SetForegroundColor(textColor, 0, __pTextObject->GetTextLength());
785 __pTextObject->SetBounds(textRect);
786 __pTextObject->SetFont(__pFont, 0, __pTextObject->GetTextLength());
787 __pTextObject->SetWrap(TEXT_OBJECT_WRAP_TYPE_NONE);
788 if (itemBounds.width < __itemMaxWidth)
790 __pTextObject->SetAction(TEXT_OBJECT_ACTION_TYPE_NONE);
794 __pTextObject->SetAction(TEXT_OBJECT_ACTION_TYPE_ABBREV);
795 __pTextObject->SetTextObjectEllipsisType(TEXT_OBJECT_ELLIPSIS_TYPE_TAIL);
797 __pTextObject->Draw(*_CanvasImpl::GetInstance(*pCanvas));
802 _TabBarPresenter::DrawBackground(Tizen::Graphics::Canvas* pCanvas)
804 result r = E_SUCCESS;
805 FloatRectangle clientBounds = __tabBar.GetBoundsF();
807 if (__pBgBitmapCached != null)
809 r = DrawBitmap(*pCanvas, FloatRectangle(0.0f, 0.0f, clientBounds.width, clientBounds.height), *__pBgBitmapCached);
810 SysTryReturnVoidResult(NID_UI_CTRL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
813 bool isCustomBitmap = IS_CUSTOM_BITMAP(TABBAR::BG_NORMAL);
814 if (__pBgEffectBitmapCached != null && !isCustomBitmap)
816 r = DrawBitmap(*pCanvas, FloatRectangle(0.0f, 0.0f, clientBounds.width, clientBounds.height), *__pBgEffectBitmapCached);
817 SysTryReturnVoidResult(NID_UI_CTRL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
822 _TabBarPresenter::DrawArrow(Tizen::Graphics::Canvas* pCanvas)
824 FloatRectangle clientBounds = __tabBar.GetBoundsF();
826 _TabBarItem* pFirstItem = __pTabBarModel->GetItemAt(0);
827 if (pFirstItem == null)
832 FloatRectangle firstItemBounds = pFirstItem->GetBounds();
833 FloatRectangle drawRect(0.0f, 0.0f, 0.0f, 0.0f);
834 drawRect.width = __sideMargin;
835 drawRect.height = clientBounds.height;
838 if (firstItemBounds.x < 0.0f)
840 drawRect.width = __pLeftArrowBitmapCached->GetWidth();
841 drawRect.height = __pLeftArrowBitmapCached->GetHeight();
842 drawRect.x = (__sideMargin - __pLeftArrowBitmapCached->GetWidth()) / 2.0f;
843 drawRect.y = (clientBounds.height - __pLeftArrowBitmapCached->GetHeight()) / 2.0f;
844 DrawBitmap(*pCanvas, drawRect, *__pLeftArrowBitmapCached);
847 int itemCount = __pTabBarModel->GetItemCount();
848 _TabBarItem* pLastItem = __pTabBarModel->GetItemAt(itemCount - 1);
849 if (pLastItem == null)
854 FloatRectangle lastItemBounds = pLastItem->GetBounds();
856 drawRect.SetBounds(0.0f, 0.0f, 0.0f, 0.0f);
857 drawRect.x = clientBounds.width - __sideMargin;
858 drawRect.width = __sideMargin;
859 drawRect.height = clientBounds.height;
862 if (lastItemBounds.x + lastItemBounds.width > clientBounds.width - __sideMargin * 2.0f)
864 drawRect.x += (__sideMargin - __pRightArrowBitmapCached->GetWidth()) / 2.0f;
865 drawRect.y = (clientBounds.height - __pRightArrowBitmapCached->GetHeight()) / 2.0f;
866 drawRect.width = __pRightArrowBitmapCached->GetWidth();
867 drawRect.height = __pRightArrowBitmapCached->GetHeight();
868 DrawBitmap(*pCanvas, drawRect, *__pRightArrowBitmapCached);
873 _TabBarPresenter::OnTouchPressed(const _Control& source, const _TouchInfo& touchinfo)
875 FloatPoint touchPosition = touchinfo.GetCurrentPosition();
876 __startPosition = touchPosition;
877 __touchBubblingBlocked = true;
879 int index = GetItemIndexFromPosition(touchPosition);
885 __pressedItemIndex = index;
886 if (GetItemStatus(index) == ITEM_STATUS_SELECTED)
891 result r = SetItemStatus(index, ITEM_STATUS_PRESSED);
892 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, true, r, "[%s] propagating.", GetErrorMessage(r));
900 _TabBarPresenter::OnTouchReleased(const _Control& source, const _TouchInfo& touchinfo)
902 FloatPoint touchPosition = touchinfo.GetCurrentPosition();
903 int index = GetItemIndexFromPosition(touchPosition);
904 int selectedItemIndex = GetSelectedItemIndex();
905 bool eventFire = false;
906 result r = E_SUCCESS;
908 if (index != -1 && GetItemStatus(index) != ITEM_STATUS_NORMAL && __touchMoved == false)
910 if (GetItemStatus(index) == ITEM_STATUS_PRESSED)
912 r = SetItemStatus(index, ITEM_STATUS_SELECTED);
913 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, false, r, "[%s] propagating.", GetErrorMessage(r));
914 SetItemSelected(index);
915 SetItemStatus(selectedItemIndex, ITEM_STATUS_NORMAL);
920 for (int i = 0; i < GetItemCount(); i++)
922 if (GetItemStatus(i) == ITEM_STATUS_PRESSED)
924 r = SetItemStatus(i, ITEM_STATUS_NORMAL);
925 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, false, r, "[%s] propagating.", GetErrorMessage(r));
929 __pressedItemIndex = -1;
930 __touchMoved = false;
938 _TabBarPresenter::OnTouchCanceled(const _Control& source, const _TouchInfo& touchinfo)
940 result r = E_SUCCESS;
942 for (int i = 0; i < GetItemCount(); i++)
944 if (GetItemStatus(i) == ITEM_STATUS_PRESSED)
946 r = SetItemStatus(i, ITEM_STATUS_NORMAL);
947 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, false, r, "[%s] propagating.", GetErrorMessage(r));
951 __pressedItemIndex = -1;
959 _TabBarPresenter::OnTouchMoved(const _Control& source, const _TouchInfo& touchinfo)
962 if (&source != &__tabBar)
967 FloatRectangle clientBounds = __tabBar.GetBoundsF();
968 if (__pTabBarModel->GetWidthOfAllItems() + (__sideMargin * 2.0f) <= clientBounds.width + __arrowMargin * 2.0f)
973 FloatPoint touchPosition = touchinfo.GetCurrentPosition();
975 if (__touchMoved == false)
977 float distanceX = _Abs((touchPosition).x - __startPosition.x);
978 float distanceY = _Abs((touchPosition).y - __startPosition.y);
980 if (distanceY > distanceX)
982 __touchBubblingBlocked = false;
988 float distance = touchPosition.x - __startPosition.x;
990 __startPosition = touchPosition;
991 _TabBarItem* pItem = null;
992 FloatRectangle itemBounds;
993 int itemCount = GetItemCount();
995 if (distance > 0) // right move
997 pItem = __pTabBarModel->GetItemAt(0);
1003 itemBounds = pItem->GetBounds();
1005 if (itemBounds.x == __arrowMargin)
1010 if (itemBounds.x + distance >= __arrowMargin)
1012 distance = __arrowMargin - itemBounds.x;
1017 pItem = __pTabBarModel->GetItemAt(itemCount - 1);
1023 itemBounds = pItem->GetBounds();
1024 if (_FloatCompare(itemBounds.x + itemBounds.width + (__arrowMargin * 2.0f), clientBounds.width - (__sideMargin * 2.0f)))
1029 if (itemBounds.x + itemBounds.width + distance + (__arrowMargin * 2.0f) <= clientBounds.width - (__sideMargin * 2.0f))
1031 distance = (clientBounds.width - (__sideMargin * 2.0f)) - (itemBounds.x + itemBounds.width + (__arrowMargin * 2.0f));
1035 AdjustItemPositionX(distance);
1039 return __touchBubblingBlocked;
1043 _TabBarPresenter::DrawBitmap(Tizen::Graphics::Canvas& canvas, const Tizen::Graphics::FloatRectangle& bounds, const Tizen::Graphics::Bitmap& bitmap)
1045 result r = E_SUCCESS;
1046 if (_BitmapImpl::CheckNinePatchedBitmapStrictly(bitmap))
1048 r = canvas.DrawNinePatchedBitmap(bounds, bitmap);
1049 SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Fail to draw ninepatched bitmap.")
1053 r = canvas.DrawBitmap(bounds, bitmap);
1054 SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Fail to draw bitmap.")
1061 _TabBarPresenter::SetAllAccessibilityElement(void)
1063 _AccessibilityContainer* pContainer = __tabBar.GetAccessibilityContainer();
1064 if (pContainer != null)
1066 int itemCount = __pTabBarModel->GetItemCount();
1067 for (int i = 0; i < itemCount; i++)
1069 _TabBarItem* pItem = __pTabBarModel->GetItemAt(i);
1072 result r = GetLastResult();
1073 SysLogException(NID_UI_CTRL, r, "[%s] The current value of pItem is null", GetErrorMessage(r));
1078 _AccessibilityElement* pElement = pItem->GetAccessibilityElement();
1079 if (pElement == null)
1081 pElement = new (std::nothrow) _AccessibilityElement(true);
1082 pElement->Construct(L"", FloatRectangle(0.0f, 0.0f, 0.0f, 0.0f));
1083 pElement->SetName(L"Category" + Integer::ToString(i + 1));
1084 pElement->SetLabel(pItem->GetText());
1085 pElement->SetTraitWithStringId("IDS_TPLATFORM_BODY_CATEGORY");
1086 FloatRectangle itemBounds = pItem->GetBounds();
1087 itemBounds.x += __sideMargin;
1088 pElement->SetBounds(itemBounds);
1089 pItem->SetAccessibilityElement(pElement);
1090 pContainer->AddElement(*pElement);
1094 pElement->SetName(L"Category" + Integer::ToString(i + 1));
1095 pElement->SetLabel(pItem->GetText());
1096 pElement->SetTraitWithStringId("IDS_TPLATFORM_BODY_CATEGORY");
1097 FloatRectangle itemBounds = pItem->GetBounds();
1098 itemBounds.x += __sideMargin;
1099 pElement->SetBounds(itemBounds);
1102 if (pItem->GetStatus() != ITEM_STATUS_SELECTED)
1104 pElement->SetHintWithStringId("IDS_TPLATFORM_BODY_DOUBLE_TAP_TO_MOVE_TO_CONTENT_T_TTS");
1111 _TabBarPresenter::OnAccessibilityFocusMovedNext(const _AccessibilityContainer& control, const _AccessibilityElement& element)
1117 _TabBarPresenter::OnAccessibilityFocusMovedPrevious(const _AccessibilityContainer& control, const _AccessibilityElement& element)
1123 _TabBarPresenter::OnAccessibilityReadElement(const _AccessibilityContainer& control, const _AccessibilityElement& element)
1129 _TabBarPresenter::OnAccessibilityReadingElement(const _AccessibilityContainer& control, const _AccessibilityElement& element)
1136 _TabBarPresenter::OnAccessibilityFocusIn(const _AccessibilityContainer& control, const _AccessibilityElement& element)
1142 _TabBarPresenter::OnAccessibilityFocusOut(const _AccessibilityContainer& control, const _AccessibilityElement& element)
1148 _TabBarPresenter::OnAccessibilityActionPerformed(const _AccessibilityContainer& control, const _AccessibilityElement& element)
1154 _TabBarPresenter::OnAccessibilityValueIncreased(const _AccessibilityContainer& control, const _AccessibilityElement& element)
1160 _TabBarPresenter::OnAccessibilityValueDecreased(const _AccessibilityContainer& control, const _AccessibilityElement& element)
1166 _TabBarPresenter::OnAccessibilityItemRefreshed(const _AccessibilityContainer& control, const _AccessibilityElement& element, _AccessibilityFocusDirection direction)
1168 FloatRectangle r = element.GetBounds();
1169 int itemIndex = GetItemIndexFromAbsPosition(FloatPoint(r.x + r.width / 2.0f, r.y + r.height / 2.0f));
1171 if (itemIndex < __pTabBarModel->GetFirstDrawnItemIndex() || __pTabBarModel->GetLastDrawnItemIndex() < itemIndex)
1173 SetTopDrawnItemIndex(itemIndex);
1180 }}} // Tizen::Ui::Controls