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_TabBarPresenter.cpp
19 * @brief This is the implementation file for the _TabBarPresenter class.
23 #include <FBaseErrorDefine.h>
24 #include <FBaseSysLog.h>
25 #include <FGrp_CanvasImpl.h>
26 #include <FGrp_BitmapImpl.h>
27 #include <FGrp_TextTextSimple.h>
28 #include "FUi_UiTouchEvent.h"
29 #include "FUi_ResourceManager.h"
30 #include "FUi_AccessibilityContainer.h"
31 #include "FUi_AccessibilityElement.h"
32 #include "FUiCtrl_TabBarPresenter.h"
35 using namespace Tizen::Ui;
36 using namespace Tizen::Base;
37 using namespace Tizen::Graphics;
38 using namespace Tizen::Graphics::_Text;
40 namespace Tizen { namespace Ui { namespace Controls
43 _TabBarPresenter::_TabBarPresenter(_TabBar& tabBar)
45 , __pTabBarModel(null)
48 , __highlightedItemIndex(-1)
50 , __touchBubblingBlocked(true)
51 , __pBgBitmapCached(null)
52 , __pLeftArrowBgBitmapCached(null)
53 , __pRightArrowBgBitmapCached(null)
54 , __pLeftArrowBitmapCached(null)
55 , __pRightArrowBitmapCached(null)
57 __startPosition = Point(0, 0);
58 for (int i = 0; i < ITEM_STATUS_MAX; i++)
60 __pItemBgBitmapCached[i] = null;
64 _TabBarPresenter::~_TabBarPresenter(void)
66 delete __pTabBarModel;
67 __pTabBarModel = null;
71 __pTextObject->RemoveAll();
76 delete __pBgBitmapCached;
77 __pBgBitmapCached = null;
79 for (int i = 0; i < ITEM_STATUS_MAX; i++)
81 delete __pItemBgBitmapCached[i];
82 __pItemBgBitmapCached[i] = null;
85 delete __pLeftArrowBgBitmapCached;
86 __pLeftArrowBgBitmapCached = null;
88 delete __pRightArrowBgBitmapCached;
89 __pRightArrowBgBitmapCached = null;
91 delete __pLeftArrowBitmapCached;
92 __pLeftArrowBitmapCached = null;
94 delete __pRightArrowBitmapCached;
95 __pRightArrowBitmapCached = null;
99 _TabBarPresenter::Construct()
101 __pTabBarModel = new (std::nothrow) _TabBarModel;
102 SysTryReturn(NID_UI_CTRL, __pTabBarModel != null, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
104 result r = E_SUCCESS;
107 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
112 delete __pTabBarModel;
113 __pTabBarModel = null;
119 _TabBarPresenter::InitializeFont(void)
121 result r = E_SUCCESS;
122 __pFont = __tabBar.GetFallbackFont();
123 SysTryCatch(NID_UI_CTRL, __pFont != null, r = E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
125 __pTextObject = new (std::nothrow) TextObject();
126 SysTryCatch(NID_UI_CTRL, __pTextObject != null, r = E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
127 __pTextObject->Construct();
128 __pTextObject->SetAlignment(TEXT_OBJECT_ALIGNMENT_CENTER | TEXT_OBJECT_ALIGNMENT_MIDDLE);
129 __pTextObject->SetFont(__pFont, 0, __pTextObject->GetTextLength());
134 delete __pTextObject;
135 __pTextObject = null;
141 _TabBarPresenter::OnFontChanged(Font* pFont)
147 _TabBarPresenter::OnFontInfoRequested(unsigned long& style, int& size)
150 GET_SHAPE_CONFIG(TABBAR::FONT_SIZE, __tabBar.GetOrientation(), fontSize);
152 style = FONT_STYLE_PLAIN;
157 _TabBarPresenter::LoadBitmap(void)
159 Bitmap* pBitmap = null;
162 GET_COLOR_CONFIG(TABBAR::ARROW_NORMAL, arrowColor);
164 if (__pBgBitmapCached != null)
166 delete __pBgBitmapCached;
167 __pBgBitmapCached = null;
170 if (__pLeftArrowBgBitmapCached != null)
172 delete __pLeftArrowBgBitmapCached;
173 __pLeftArrowBgBitmapCached = null;
176 if (__pLeftArrowBitmapCached != null)
178 delete __pLeftArrowBitmapCached;
179 __pLeftArrowBitmapCached = null;
182 if (__pRightArrowBgBitmapCached == null)
184 delete __pRightArrowBgBitmapCached;
185 __pRightArrowBgBitmapCached = null;
188 if (__pRightArrowBitmapCached == null)
190 delete __pRightArrowBitmapCached;
191 __pRightArrowBitmapCached = null;
194 for (int i = 0; i < ITEM_STATUS_MAX; i++)
196 if (__pItemBgBitmapCached[i] != null)
198 delete __pItemBgBitmapCached[i];
199 __pItemBgBitmapCached[i] = null;
204 r = GET_BITMAP_CONFIG_N(TABBAR::ARROW_BG_LEFT, BITMAP_PIXEL_FORMAT_ARGB8888, __pLeftArrowBgBitmapCached);
205 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "Failed to load bitmap.");
207 r = GET_BITMAP_CONFIG_N(TABBAR::ARROW_BG_RIGHT, BITMAP_PIXEL_FORMAT_ARGB8888, __pRightArrowBgBitmapCached);
208 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "Failed to load bitmap.");
210 r = GET_BITMAP_CONFIG_N(TABBAR::BG_NORMAL, BITMAP_PIXEL_FORMAT_ARGB8888, pBitmap);
211 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "Failed to load bitmap.");
212 __pBgBitmapCached = _BitmapImpl::GetColorReplacedBitmapN(*pBitmap, Color::GetColor(COLOR_ID_MAGENTA), __tabBar.GetColor());
216 r = GET_BITMAP_CONFIG_N(TABBAR::ARROW_LEFT, BITMAP_PIXEL_FORMAT_ARGB8888, pBitmap);
217 __pLeftArrowBitmapCached = _BitmapImpl::GetColorReplacedBitmapN(*pBitmap, Color::GetColor(COLOR_ID_MAGENTA), arrowColor);
218 SysTryCatch(NID_UI_CTRL, __pLeftArrowBitmapCached != null, , E_OUT_OF_MEMORY, "Failed to load bitmap.");
222 r = GET_BITMAP_CONFIG_N(TABBAR::ARROW_RIGHT, BITMAP_PIXEL_FORMAT_ARGB8888, pBitmap);
223 __pRightArrowBitmapCached = _BitmapImpl::GetColorReplacedBitmapN(*pBitmap, Color::GetColor(COLOR_ID_MAGENTA), arrowColor);
224 SysTryCatch(NID_UI_CTRL, __pRightArrowBitmapCached != null, , E_OUT_OF_MEMORY, "Failed to load bitmap.");
228 r = GET_BITMAP_CONFIG_N(TABBAR::ITEM_SELECTED, BITMAP_PIXEL_FORMAT_ARGB8888, pBitmap);
229 __pItemBgBitmapCached[ITEM_STATUS_SELECTED] = _BitmapImpl::GetColorReplacedBitmapN(*pBitmap, Color::GetColor(COLOR_ID_MAGENTA), __tabBar.GetItemColor(ITEM_STATUS_SELECTED));
230 SysTryCatch(NID_UI_CTRL, __pItemBgBitmapCached[ITEM_STATUS_SELECTED] != null, , E_OUT_OF_MEMORY, "Failed to load bitmap.");
234 r = GET_BITMAP_CONFIG_N(TABBAR::ITEM_PRESSED, BITMAP_PIXEL_FORMAT_ARGB8888, pBitmap);
235 __pItemBgBitmapCached[ITEM_STATUS_HIGHLIGHTED] = _BitmapImpl::GetColorReplacedBitmapN(*pBitmap, Color::GetColor(COLOR_ID_MAGENTA), __tabBar.GetItemColor(ITEM_STATUS_HIGHLIGHTED));
236 SysTryCatch(NID_UI_CTRL, __pItemBgBitmapCached[ITEM_STATUS_HIGHLIGHTED] != null, , E_OUT_OF_MEMORY, "Failed to load bitmap.");
245 delete __pBgBitmapCached;
246 __pBgBitmapCached = null;
248 delete __pLeftArrowBgBitmapCached;
249 __pLeftArrowBgBitmapCached = null;
251 delete __pLeftArrowBitmapCached;
252 __pLeftArrowBitmapCached = null;
254 delete __pRightArrowBgBitmapCached;
255 __pRightArrowBgBitmapCached = null;
257 delete __pRightArrowBitmapCached;
258 __pRightArrowBitmapCached = null;
260 for (int i = 0; i < ITEM_STATUS_MAX; i++)
262 delete __pItemBgBitmapCached[i];
263 __pItemBgBitmapCached[i] = null;
266 return E_OUT_OF_MEMORY;
270 _TabBarPresenter::AddItem(const Tizen::Base::String& text, int actionId)
272 return __pTabBarModel->AddItem(text, actionId, _CONTROL_ORIENTATION_PORTRAIT);
276 _TabBarPresenter::InsertItemAt(int index, const Tizen::Base::String& text, int actionId)
278 if (index <= __pTabBarModel->GetSelectedItemIndex())
280 if (__pTabBarModel->GetItemCount() != 0)
282 __pTabBarModel->SetSelectedItemIndex(GetSelectedItemIndex() + 1);
286 result r = __pTabBarModel->InsertItemAt(index, text, actionId, _CONTROL_ORIENTATION_PORTRAIT);
287 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
293 _TabBarPresenter::SetItemAt(int index, const Tizen::Base::String& text, int actionId)
295 return __pTabBarModel->SetItemAt(index, text, actionId, _CONTROL_ORIENTATION_PORTRAIT);
299 _TabBarPresenter::GetItemAt(int index) const
301 _TabBarItem* pItem = __pTabBarModel->GetItemAt(index);
306 _TabBarPresenter::RemoveItemAt(int index)
308 if (index <= GetSelectedItemIndex())
310 if (__pTabBarModel->GetItemCount() != 0 && GetSelectedItemIndex() != 0)
312 __pTabBarModel->SetSelectedItemIndex(GetSelectedItemIndex() - 1);
316 result r = __pTabBarModel->RemoveItemAt(index, _CONTROL_ORIENTATION_PORTRAIT);
317 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
319 if (GetItemCount() != 0)
321 r = SetItemSelected(0);
322 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
326 __pTabBarModel->SetSelectedItemIndex(0);
333 _TabBarPresenter::RemoveAllItems(void)
335 __pTabBarModel->RemoveAllItems();
340 _TabBarPresenter::SetItemSelected(int index)
343 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.");
345 int oldSelectedItemIndex = GetSelectedItemIndex();
346 if (index == oldSelectedItemIndex)
350 _TabBarItem* pItem = GetItemAt(oldSelectedItemIndex);
351 result r = GetLastResult();
352 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
353 pItem->SetStatus(ITEM_STATUS_NORMAL);
355 pItem = GetItemAt(index);
357 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
358 pItem->SetStatus(ITEM_STATUS_SELECTED);
360 __pTabBarModel->SetSelectedItemIndex(index);
365 _TabBarPresenter::GetSelectedItemIndex(void) const
367 return __pTabBarModel->GetSelectedItemIndex();
371 _TabBarPresenter::GetItemCount(void) const
373 return __pTabBarModel->GetItemCount();
377 _TabBarPresenter::GetItemIndexFromPosition(const Tizen::Graphics::Point& point) const
379 Rectangle clientBounds = __tabBar.GetBounds();
382 GET_SHAPE_CONFIG(TABBAR::TOP_MARGIN, _CONTROL_ORIENTATION_PORTRAIT, topMargin);
383 GET_SHAPE_CONFIG(TABBAR::SIDE_MARGIN, _CONTROL_ORIENTATION_PORTRAIT, sideMargin);
385 if (point.x < sideMargin
386 || point.x > clientBounds.width - sideMargin
387 || point.y < topMargin
388 || point.y > clientBounds.height - topMargin)
393 int itemIndex = __pTabBarModel->GetFirstDrawnItemIndex();
394 _TabBarItem* pItem = __pTabBarModel->GetItemAt(itemIndex);
396 while (pItem != null)
398 Rectangle itemBounds = pItem->GetBounds();
400 if (point.x - sideMargin > itemBounds.x
401 && point.x - sideMargin < itemBounds.x + itemBounds.width
402 && point.y - topMargin > itemBounds.y
403 && point.y - topMargin < itemBounds.y + itemBounds.height)
408 pItem = __pTabBarModel->GetItemAt(itemIndex);
414 _TabBarPresenter::GetItemFromPosition(const Tizen::Graphics::Point& position) const
416 SetLastResult(E_SUCCESS);
417 int index = GetItemIndexFromPosition(position);
418 SysTryReturn(NID_UI_CTRL, index != -1, null, E_SYSTEM, "[E_SYSTEM] Item not found.");
420 return __pTabBarModel->GetItemAt(index);
424 _TabBarPresenter::SetTopDrawnItemIndex(int index)
426 SysTryReturn(NID_UI_CTRL, index >= 0 && index < GetItemCount(),
427 E_OUT_OF_RANGE, E_OUT_OF_RANGE, "[E_OUT_OF_RANGE] The argument(%d) is out of range.", index);
429 _TabBarItem* pTopItem = GetItemAt(index);
430 result r = GetLastResult();
431 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
433 int distance = pTopItem->GetBounds().x;
435 _TabBarItem* pBottomItem = GetItemAt(GetItemCount() - 1);
436 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
438 Rectangle clientBounds = __tabBar.GetBounds();
440 GET_SHAPE_CONFIG(TABBAR::SIDE_MARGIN, _CONTROL_ORIENTATION_PORTRAIT, sideMargin);
442 if ((pBottomItem->GetBounds().x + pBottomItem->GetBounds().width - distance) < clientBounds.width - sideMargin * 2)
444 distance = (pBottomItem->GetBounds().x + pBottomItem->GetBounds().width) - (clientBounds.width - sideMargin * 2);
447 r = AdjustItemPositionX(-distance);
448 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
454 _TabBarPresenter::SetItemStatus(int index, _TabBarItemStatus status)
456 _TabBarItem* pItem = __pTabBarModel->GetItemAt(index);
457 SysTryReturn(NID_UI_CTRL, pItem, E_SYSTEM, E_SYSTEM, "[E_SYSTEM] Item(%d) not exists.", index);
459 pItem->SetStatus(status);
465 _TabBarPresenter::GetItemStatus(int index) const
467 _TabBarItem* pItem = __pTabBarModel->GetItemAt(index);
468 SysTryReturn(NID_UI_CTRL, pItem, ITEM_STATUS_NORMAL, E_SYSTEM, "[E_SYSTEM] Item(%d) not exists.", index);
470 _TabBarItemStatus status = pItem->GetStatus();
476 _TabBarPresenter::AdjustItemPositionX(int distance)
480 while (index < GetItemCount())
482 _TabBarItem* pItem = __pTabBarModel->GetItemAt(index);
483 SysTryReturn(NID_UI_CTRL, pItem, E_INVALID_STATE, E_INVALID_STATE, "[E_INVALID_STATE] Item(%d) not exists.", index);
484 Rectangle bounds = pItem->GetBounds();
485 bounds.x += distance;
486 pItem->SetBounds(bounds);
494 _TabBarPresenter::SetReplacementColor(const Tizen::Graphics::Color& color)
496 Bitmap* pBitmap = null;
497 Bitmap* pColorReplcedBitmap = null;
500 r = GET_BITMAP_CONFIG_N(TABBAR::BG_NORMAL, BITMAP_PIXEL_FORMAT_ARGB8888, pBitmap);
501 SysTryReturn(NID_UI_CTRL, pBitmap != null, E_SYSTEM, E_SYSTEM, "[E_SYSTEM] Image loading fail.");
503 pColorReplcedBitmap = _BitmapImpl::GetColorReplacedBitmapN(*pBitmap, Color::GetColor(COLOR_ID_MAGENTA), color);
506 if (__pBgBitmapCached != null)
508 delete __pBgBitmapCached;
510 __pBgBitmapCached = pColorReplcedBitmap;
516 _TabBarPresenter::SetItemReplacementColor(_TabBarItemStatus itemStatus, const Tizen::Graphics::Color& color)
518 Bitmap* pBitmap = null;
519 Bitmap* pColorReplcedBitmap = null;
522 if (itemStatus == ITEM_STATUS_SELECTED)
524 r = GET_BITMAP_CONFIG_N(TABBAR::ITEM_SELECTED, BITMAP_PIXEL_FORMAT_ARGB8888, pBitmap);
525 SysTryReturn(NID_UI_CTRL, pBitmap != null, E_SYSTEM, E_SYSTEM, "[E_SYSTEM] Image loading fail.");
527 else if (itemStatus == ITEM_STATUS_HIGHLIGHTED)
529 r = GET_BITMAP_CONFIG_N(TABBAR::ITEM_PRESSED, BITMAP_PIXEL_FORMAT_ARGB8888, pBitmap);
530 SysTryReturn(NID_UI_CTRL, pBitmap != null, E_SYSTEM, E_SYSTEM, "[E_SYSTEM] Image loading fail.");
537 pColorReplcedBitmap = _BitmapImpl::GetColorReplacedBitmapN(*pBitmap, Color::GetColor(COLOR_ID_MAGENTA), color);
540 if (__pItemBgBitmapCached[itemStatus] != null)
542 delete __pItemBgBitmapCached[itemStatus];
544 __pItemBgBitmapCached[itemStatus] = pColorReplcedBitmap;
550 _TabBarPresenter::Draw(void)
552 Canvas* pCanvas = __tabBar.GetCanvasN();
553 SysTryReturnVoidResult(NID_UI_CTRL, pCanvas != null, E_SYSTEM, "[E_SYSTEM] It can not get canvas.");
556 GET_SHAPE_CONFIG(TABBAR::SIDE_MARGIN, _CONTROL_ORIENTATION_PORTRAIT, sideMargin);
558 Rectangle clientBounds = __tabBar.GetBounds();
561 DrawBackground(pCanvas);
565 Rectangle rect(sideMargin, 0, clientBounds.width - sideMargin * 2, clientBounds.height);
566 Canvas* pSubCanvas = __tabBar.GetCanvasN(rect);
568 if (pSubCanvas != null)
570 DrawItem(pSubCanvas);
576 _TabBarPresenter::InitItemPositionX(void)
578 int itemCount = GetItemCount();
585 GET_SHAPE_CONFIG(TABBAR::SIDE_MARGIN, _CONTROL_ORIENTATION_PORTRAIT, sideMargin);
587 _TabBarItem* pFirstItem = __pTabBarModel->GetItemAt(0);
588 _TabBarItem* pLastItem = __pTabBarModel->GetItemAt(itemCount - 1);
589 SysTryReturnVoidResult(NID_UI_CTRL, pFirstItem != null && pLastItem != null, E_SYSTEM, "[E_SYSTEM] Item not found.");
591 Rectangle clientBounds = __tabBar.GetBounds();
592 Rectangle firstItemBounds = pFirstItem->GetBounds();
593 Rectangle lastItemBounds = pLastItem->GetBounds();
595 if (firstItemBounds.x != 0 && lastItemBounds.x + lastItemBounds.width - firstItemBounds.x < clientBounds.width - sideMargin * 2)
597 AdjustItemPositionX(-firstItemBounds.x);
604 _TabBarPresenter::OnBoundsChanged(void)
606 return InitItemPositionX();
610 _TabBarPresenter::DrawItem(Tizen::Graphics::Canvas* pCanvas)
612 SysTryReturnVoidResult(NID_UI_CTRL, __pTextObject != null, E_INVALID_STATE, "[E_INVALID_STATE] TextObject is not constructed.");
614 Rectangle clientBounds = pCanvas->GetBounds();
616 _TabBarItem* pDrawItem = null;
617 Rectangle itemBounds(0, 0, 0, 0);
619 String drawText(L"");
620 Rectangle textRect(0, 0, 0, 0);
621 TextSimple* pSimpleText = null;
623 _TabBarItemStatus itemStatus = ITEM_STATUS_NORMAL;
625 int itemCount = GetItemCount();
626 for (int i = 0; i < itemCount; i++)
628 pDrawItem = __pTabBarModel->GetItemAt(i);
629 if (pDrawItem == null)
634 itemBounds = pDrawItem->GetBounds();
636 if (itemBounds.x + itemBounds.width < 0)
641 if (itemBounds.x > clientBounds.width)
646 itemStatus = pDrawItem->GetStatus();
649 if (__pItemBgBitmapCached[itemStatus] != null)
651 pCanvas->DrawNinePatchedBitmap(itemBounds, *__pItemBgBitmapCached[itemStatus]);
655 textRect = Rectangle(itemBounds.x, itemBounds.y, itemBounds.width, itemBounds.height);
658 textRect.width += textRect.x;
662 if (textRect.x + textRect.width > clientBounds.width)
664 textRect.width = clientBounds.width - textRect.x;
667 drawText = pDrawItem->GetText();
668 __pTextObject->RemoveAll();
669 pSimpleText = new (std::nothrow)TextSimple(const_cast <wchar_t*>(drawText.GetPointer()), drawText.GetLength());
670 SysTryReturnVoidResult(NID_UI_CTRL, pSimpleText != null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] TextSimple is not constructed.");
672 __pFont = __tabBar.GetFallbackFont();
673 SysTryReturnVoidResult(NID_UI_CTRL, __pFont != null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
675 __pTextObject->AppendElement(*pSimpleText);
677 __pTextObject->SetForegroundColor(__tabBar.GetItemTextColor(itemStatus), 0, __pTextObject->GetTextLength());
678 __pTextObject->SetBounds(textRect);
679 __pTextObject->SetFont(__pFont, 0, __pTextObject->GetTextLength());
680 __pTextObject->SetWrap(TEXT_OBJECT_WRAP_TYPE_NONE);
681 __pTextObject->Draw(*_CanvasImpl::GetInstance(*pCanvas));
686 _TabBarPresenter::DrawBackground(Tizen::Graphics::Canvas* pCanvas)
688 Rectangle clientBounds = __tabBar.GetBounds();
690 if (__pBgBitmapCached != null)
692 pCanvas->DrawNinePatchedBitmap(Rectangle(0, 0, clientBounds.width, clientBounds.height), *__pBgBitmapCached);
697 _TabBarPresenter::DrawArrow(Tizen::Graphics::Canvas* pCanvas)
699 Rectangle clientBounds = __tabBar.GetBounds();
701 _TabBarItem* pFirstItem = __pTabBarModel->GetItemAt(0);
702 if (pFirstItem == null)
707 Rectangle firstItemBounds = pFirstItem->GetBounds();
710 GET_SHAPE_CONFIG(TABBAR::SIDE_MARGIN, _CONTROL_ORIENTATION_PORTRAIT, sideMargin);
711 GET_SHAPE_CONFIG(TABBAR::ARROW_MARGIN, _CONTROL_ORIENTATION_PORTRAIT, arrowMargin);
713 Rectangle drawRect(0, 0, 0, 0);
714 drawRect.width = sideMargin;
715 drawRect.height = clientBounds.height;
718 if (firstItemBounds.x < 0)
720 drawRect.width = __pLeftArrowBitmapCached->GetWidth();
721 drawRect.height = __pLeftArrowBitmapCached->GetHeight();
722 drawRect.x = (sideMargin - __pLeftArrowBitmapCached->GetWidth()) / 2;
723 drawRect.y = (clientBounds.height - __pLeftArrowBitmapCached->GetHeight()) / 2;
724 DrawBitmap(*pCanvas, drawRect, *__pLeftArrowBitmapCached);
727 int itemCount = __pTabBarModel->GetItemCount();
728 _TabBarItem* pLastItem = __pTabBarModel->GetItemAt(itemCount - 1);
729 if (pLastItem == null)
734 Rectangle lastItemBounds = pLastItem->GetBounds();
736 drawRect.SetBounds(0, 0, 0, 0);
737 drawRect.x = clientBounds.width - sideMargin;
738 drawRect.width = sideMargin;
739 drawRect.height = clientBounds.height;
742 if (lastItemBounds.x + lastItemBounds.width > clientBounds.width - sideMargin * 2)
744 drawRect.x += (sideMargin - __pRightArrowBitmapCached->GetWidth()) / 2;
745 drawRect.y = (clientBounds.height - __pRightArrowBitmapCached->GetHeight()) / 2;
746 drawRect.width = __pRightArrowBitmapCached->GetWidth();
747 drawRect.height = __pRightArrowBitmapCached->GetHeight();
748 DrawBitmap(*pCanvas, drawRect, *__pRightArrowBitmapCached);
753 _TabBarPresenter::OnTouchPressed(const _Control& source, const _TouchInfo& touchinfo)
755 __startPosition = touchinfo.GetCurrentPosition();
756 __touchBubblingBlocked = true;
758 int index = GetItemIndexFromPosition(touchinfo.GetCurrentPosition());
764 __highlightedItemIndex = index;
765 if (GetItemStatus(index) == ITEM_STATUS_SELECTED)
770 result r = SetItemStatus(index, ITEM_STATUS_HIGHLIGHTED);
771 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, true, r, "[%s] propagating.", GetErrorMessage(r));
779 _TabBarPresenter::OnTouchReleased(const _Control& source, const _TouchInfo& touchinfo)
781 int index = GetItemIndexFromPosition(touchinfo.GetCurrentPosition());
782 int selectedItemIndex = GetSelectedItemIndex();
783 bool eventFire = false;
784 result r = E_SUCCESS;
787 if (index != -1 && GetItemStatus(index) != ITEM_STATUS_NORMAL && __touchMoved == false)
789 if (GetItemStatus(index) == ITEM_STATUS_HIGHLIGHTED)
791 r = SetItemStatus(index, ITEM_STATUS_SELECTED);
792 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, false, r, "[%s] propagating.", GetErrorMessage(r));
793 SetItemSelected(index);
794 SetItemStatus(selectedItemIndex, ITEM_STATUS_NORMAL);
800 for (int i = 0; i < GetItemCount(); i++)
802 if (GetItemStatus(i) == ITEM_STATUS_HIGHLIGHTED)
804 r = SetItemStatus(i, ITEM_STATUS_NORMAL);
805 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, false, r, "[%s] propagating.", GetErrorMessage(r));
809 __highlightedItemIndex = -1;
810 __touchMoved = false;
818 _TabBarPresenter::OnTouchMoved(const _Control& source, const _TouchInfo& touchinfo)
820 if (&source != &__tabBar)
826 GET_SHAPE_CONFIG(TABBAR::SIDE_MARGIN, _CONTROL_ORIENTATION_PORTRAIT, sideMargin);
828 GET_SHAPE_CONFIG(TABBAR::ARROW_MARGIN, _CONTROL_ORIENTATION_PORTRAIT, arrowMargin);
830 Rectangle clientBounds = __tabBar.GetBounds();
831 if (__pTabBarModel->GetWidthOfAllItems() + (sideMargin * 2) <= clientBounds.width + arrowMargin * 2)
836 if (__touchMoved == false)
838 int distanceX = abs((touchinfo.GetCurrentPosition()).x - __startPosition.x);
839 int distanceY = abs((touchinfo.GetCurrentPosition()).y - __startPosition.y);
841 if (distanceY > distanceX)
843 __touchBubblingBlocked = false;
849 int distance = (touchinfo.GetCurrentPosition()).x - __startPosition.x;
851 __startPosition = touchinfo.GetCurrentPosition();
852 _TabBarItem* pItem = null;
853 Rectangle itemBounds;
854 int itemCount = GetItemCount();
856 if (distance > 0) // right move
858 pItem = __pTabBarModel->GetItemAt(0);
864 itemBounds = pItem->GetBounds();
866 if (itemBounds.x == arrowMargin)
871 if (itemBounds.x + distance >= arrowMargin)
873 distance = arrowMargin - itemBounds.x;
878 pItem = __pTabBarModel->GetItemAt(itemCount - 1);
884 itemBounds = pItem->GetBounds();
885 if (itemBounds.x + itemBounds.width + (arrowMargin * 2) == clientBounds.width - (sideMargin * 2))
890 if (itemBounds.x + itemBounds.width + distance + (arrowMargin * 2) <= clientBounds.width - (sideMargin * 2))
892 distance = (clientBounds.width - (sideMargin * 2)) - (itemBounds.x + itemBounds.width + (arrowMargin * 2));
896 AdjustItemPositionX(distance);
900 return __touchBubblingBlocked;
904 _TabBarPresenter::DrawBitmap(Tizen::Graphics::Canvas& canvas, const Tizen::Graphics::Rectangle& bounds, const Tizen::Graphics::Bitmap& bitmap)
906 result r = E_SUCCESS;
907 if (bitmap.IsNinePatchedBitmap())
909 r = canvas.DrawNinePatchedBitmap(bounds, bitmap);
910 SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Fail to draw ninepatched bitmap.")
914 r = canvas.DrawBitmap(bounds, bitmap);
915 SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Fail to draw bitmap.")
922 _TabBarPresenter::SetAllAccessibilityElement(void)
924 _AccessibilityContainer* pContainer = __tabBar.GetAccessibilityContainer();
926 GET_SHAPE_CONFIG(TABBAR::SIDE_MARGIN, _CONTROL_ORIENTATION_PORTRAIT, sideMargin);
928 if (pContainer != null)
930 int itemCount = __pTabBarModel->GetItemCount();
931 for (int i = 0; i < itemCount; i++)
933 _TabBarItem* pItem = __pTabBarModel->GetItemAt(i);
934 _AccessibilityElement* pElement = new (std::nothrow) _AccessibilityElement(true);
935 if (pItem != null && pElement != null)
937 pElement->SetLabel(pItem->GetText());
938 // pElement->SetTrait(ACCESSIBILITY_TRAITS_TABBAR);
939 pElement->SetTrait(ACCESSIBILITY_TRAITS_TAB); // not yet
940 Rectangle itemBounds = pItem->GetBounds();
941 itemBounds.x += sideMargin;
942 pElement->SetBounds(itemBounds);
946 pElement->SetHint(L"The first of TabBar");
948 else if(i == itemCount - 1)
950 pElement->SetHint(L"The last of TabBar");
952 pContainer->AddElement(*pElement);
953 __tabBar.AddAccessibilityElement(*pElement);
964 }}} // Tizen::Ui::Controls