2 // Open Service Platform
3 // Copyright (c) 2012-2013 Samsung Electronics Co., Ltd.
5 // Licensed under the Flora License, Version 1.0 (the License);
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
9 // http://floralicense.org/license/
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an AS IS BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
19 * @file FUiCtrl_Tab.cpp
20 * @brief This is the implementation file for the _Tab class.
23 #include <FBaseErrorDefine.h>
24 #include <FBaseSysLog.h>
25 #include <FGrp_BitmapImpl.h>
26 #include "FUi_ResourceManager.h"
27 #include "FUi_UiTouchEvent.h"
28 #include "FUi_AccessibilityContainer.h"
29 #include "FUi_AccessibilityElement.h"
30 #include "FUi_TouchLongPressGestureDetector.h"
31 #include "FUiCtrl_Tab.h"
32 #include "FUi_CoordinateSystemUtils.h"
34 using namespace Tizen::Base;
35 using namespace Tizen::Graphics;
36 using namespace Tizen::Base::Runtime;
38 namespace Tizen { namespace Ui { namespace Controls {
41 : __pTabPresenter(null)
42 , __style(_TAB_STYLE_TEXT)
43 , __tabStatus(_TAB_STATUS_NORMAL)
44 , __pActionEvent(null)
45 , __pGestureLongPress(null)
46 , __pFlickGesture(null)
47 , __pBackgroundBitmap(null)
48 , __pDisabledBackgroundBitmap(null)
49 , __pPressedItemBackgroundBitmap(null)
50 , __pPressedItemBackgroundEffectBitmap(null)
51 , __pSelectedItemBackgroundBitmap(null)
52 , __pHighlightedItemBackgroundBitmap(null)
57 __tabItems.Construct();
59 GET_COLOR_CONFIG(TAB::ITEM_BG_NORMAL, __itemBgColor[_TAB_STATUS_NORMAL]);
60 GET_COLOR_CONFIG(TAB::ITEM_BG_PRESSED, __itemBgColor[_TAB_STATUS_PRESSED]);
61 GET_COLOR_CONFIG(TAB::ITEM_BG_SELECTED, __itemBgColor[_TAB_STATUS_SELECTED]);
62 GET_COLOR_CONFIG(TAB::ITEM_BG_HIGHLIGHTED, __itemBgColor[_TAB_STATUS_HIGHLIGHTED]);
63 GET_COLOR_CONFIG(TAB::ITEM_BG_DISABLED, __itemBgColor[_TAB_STATUS_DISABLED]);
65 GET_COLOR_CONFIG(TAB::ITEM_TEXT_NORMAL, __itemTextColor[_TAB_STATUS_NORMAL]);
66 GET_COLOR_CONFIG(TAB::ITEM_TEXT_PRESSED, __itemTextColor[_TAB_STATUS_PRESSED]);
67 GET_COLOR_CONFIG(TAB::ITEM_TEXT_SELECTED, __itemTextColor[_TAB_STATUS_SELECTED]);
68 GET_COLOR_CONFIG(TAB::ITEM_TEXT_HIGHLIGHTED, __itemTextColor[_TAB_STATUS_HIGHLIGHTED]);
69 GET_COLOR_CONFIG(TAB::ITEM_TEXT_DISABLED, __itemTextColor[_TAB_STATUS_DISABLED]);
72 SysTryReturnVoidResult(NID_UI_CTRL, r == E_SUCCESS, E_SYSTEM, "[E_SYSTEM] A system error has occurred. Failed to load bitmap.");
74 _Control::SetResizable(false);
75 _Control::SetMovable(false);
77 _TabPresenter* pPresenter = new (std::nothrow) _TabPresenter;
78 SysTryReturnVoidResult(NID_UI_CTRL, pPresenter, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
80 r = SetPresenter(*pPresenter);
81 SysTryReturnVoidResult(NID_UI_CTRL, r == E_SUCCESS, E_SYSTEM, "[E_SYSTEM] A system error has occurred. The _TabPresenter instance could not be set.");
83 r = pPresenter->Construct(*this);
84 SysTryReturnVoidResult(NID_UI_CTRL, r == E_SUCCESS, E_SYSTEM, "[E_SYSTEM] A system error has occurred. The _TabPresenter instance construct failed.");
90 delete __pTabPresenter;
91 __pTabPresenter = null;
95 delete __pActionEvent;
96 __pActionEvent = null;
99 __tabItems.RemoveAll(true);
101 if (__pFlickGesture != null)
103 __pFlickGesture->RemoveGestureListener(*this);
104 RemoveGestureDetector(*__pFlickGesture);
106 delete __pFlickGesture;
107 __pFlickGesture = null;
110 if (__pGestureLongPress != null)
112 __pGestureLongPress->RemoveGestureListener(*this);
113 RemoveGestureDetector(*__pGestureLongPress);
115 delete __pGestureLongPress;
116 __pGestureLongPress = null;
119 if (__pBackgroundBitmap)
121 delete __pBackgroundBitmap;
122 __pBackgroundBitmap = null;
125 if (__pDisabledBackgroundBitmap)
127 delete __pDisabledBackgroundBitmap;
128 __pDisabledBackgroundBitmap = null;
131 if (__pPressedItemBackgroundBitmap)
133 delete __pPressedItemBackgroundBitmap;
134 __pPressedItemBackgroundBitmap = null;
137 if (__pPressedItemBackgroundEffectBitmap)
139 delete __pPressedItemBackgroundEffectBitmap;
140 __pPressedItemBackgroundEffectBitmap = null;
143 if (__pSelectedItemBackgroundBitmap)
145 delete __pSelectedItemBackgroundBitmap;
146 __pSelectedItemBackgroundBitmap = null;
149 if (__pHighlightedItemBackgroundBitmap)
151 delete __pHighlightedItemBackgroundBitmap;
152 __pHighlightedItemBackgroundBitmap = null;
155 RemoveAllAccessibilityElement();
159 _Tab::CreateTabN(void)
161 result r = E_SUCCESS;
163 _Tab* pTab = new (std::nothrow) _Tab;
164 SysTryReturn(NID_UI_CTRL, pTab, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
166 if (IsFailed(GetLastResult()))
171 pTab->AcquireHandle();
173 pTab->__pGestureLongPress = new (std::nothrow) _TouchLongPressGestureDetector;
174 SysTryCatch(NID_UI_CTRL, pTab->__pGestureLongPress, , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
176 pTab->__pGestureLongPress->SetDuration(500);
177 pTab->AddGestureDetector(*(pTab->__pGestureLongPress));
178 r = pTab->__pGestureLongPress->AddGestureListener(*pTab);
179 SysTryCatch(NID_UI_CTRL, (r == E_SUCCESS), , r = E_SYSTEM, "[E_SYSTEM] A system error has occurred. The _ITouchGestureEventListener instance could not be set.");
181 pTab->__pFlickGesture = new (std::nothrow) _TouchFlickGestureDetector;
182 SysTryCatch(NID_UI_CTRL, pTab->__pFlickGesture, , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
184 r = pTab->AddGestureDetector(*(pTab->__pFlickGesture));
185 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating", GetErrorMessage(r));
187 r = pTab->__pFlickGesture->AddGestureListener(*pTab);
188 SysTryCatch(NID_UI_CTRL, (r == E_SUCCESS), , r = E_SYSTEM, "[E_SYSTEM] A system error has occurred. The _ITouchGestureEventListener instance could not be set.");
193 if (pTab->__pGestureLongPress != null)
195 pTab->__pGestureLongPress->RemoveGestureListener(*pTab);
196 pTab->RemoveGestureDetector(*pTab->__pGestureLongPress);
198 delete pTab->__pGestureLongPress;
199 pTab->__pGestureLongPress = null;
201 if (pTab->__pFlickGesture != null)
203 pTab->__pFlickGesture->RemoveGestureListener(*pTab);
204 pTab->RemoveGestureDetector(*pTab->__pFlickGesture);
206 delete pTab->__pFlickGesture;
207 pTab->__pFlickGesture = null;
215 _Tab::SetPresenter(const _TabPresenter& tabPresenter)
218 __pTabPresenter = const_cast<_TabPresenter*>(&tabPresenter);
224 _Tab::AddItem(const Bitmap& icon, const String& text, int actionId)
226 if (actionId < _TAB_ACTION_ID_MIN || actionId > _TAB_ACTION_ID_MAX)
228 SysLog(NID_UI_CTRL, "[E_OUT_OF_RANGE] The actionId (%d) is out of range.", actionId);
229 return E_OUT_OF_RANGE;
232 if (!((__style == _TAB_STYLE_TEXT) || (__style == _TAB_STYLE_ICON_TEXT)))
237 __style = _TAB_STYLE_ICON_TEXT;
239 bool isDuplicate = CheckDuplicatedActionId(actionId);
240 SysTryReturnResult(NID_UI_CTRL, isDuplicate == false, E_SYSTEM, "A system error has occurred. The tab already has an item with same action id (%d).", actionId);
242 int itemCount = __tabItems.GetCount();
244 SysTryReturnResult(NID_UI_CTRL, itemCount < _TAB_ITEM_MAXCOUNT, E_SYSTEM, "A system error has occurred. The tab has maximum number of items.");
246 _TabItem *pItem = new (std::nothrow) _TabItem;
247 SysTryReturnResult(NID_UI_CTRL, pItem != null, E_OUT_OF_MEMORY, "Memory allocation failed.");
249 pItem->SetIcon(icon);
250 pItem->SetText(text);
251 pItem->SetActionId(actionId);
252 pItem->SetUpdateState(true);
256 pItem->SetStatus(_TABITEM_STATUS_NORMAL);
260 pItem->SetStatus(_TABITEM_STATUS_SELECTED);
263 __pTabPresenter->SetRecalculateItemBounds(true);
265 return __tabItems.Add(*pItem);
269 _Tab::AddItem(const Bitmap& icon, int actionId)
271 if (actionId < _TAB_ACTION_ID_MIN || actionId > _TAB_ACTION_ID_MAX)
273 SysLog(NID_UI_CTRL, "[E_OUT_OF_RANGE] The actionId (%d) is out of range.", actionId);
274 return E_OUT_OF_RANGE;
277 if (__style != _TAB_STYLE_ICON)
282 bool isDuplicate = CheckDuplicatedActionId(actionId);
283 SysTryReturnResult(NID_UI_CTRL, isDuplicate == false, E_SYSTEM, "A system error has occurred. The tab already has an item with same action id (%d).", actionId);
285 int itemCount = __tabItems.GetCount();
287 SysTryReturnResult(NID_UI_CTRL, itemCount < _TAB_ITEM_MAXCOUNT, E_SYSTEM, "A system error has occurred. The tab has maximum number of items.");
289 _TabItem *pItem = new (std::nothrow) _TabItem;
290 SysTryReturnResult(NID_UI_CTRL, pItem != null, E_OUT_OF_MEMORY, "Memory allocation failed.");
292 pItem->SetIcon(icon);
293 pItem->SetActionId(actionId);
294 pItem->SetUpdateState(true);
298 pItem->SetStatus(_TABITEM_STATUS_NORMAL);
302 pItem->SetStatus(_TABITEM_STATUS_SELECTED);
305 __pTabPresenter->SetRecalculateItemBounds(true);
307 return __tabItems.Add(*pItem);
311 _Tab::AddItem(const String& text, int actionId)
313 if (actionId < _TAB_ACTION_ID_MIN || actionId > _TAB_ACTION_ID_MAX)
315 SysLog(NID_UI_CTRL, "[E_OUT_OF_RANGE] The actionId (%d) is out of range.", actionId);
316 return E_OUT_OF_RANGE;
319 if (!((__style == _TAB_STYLE_TEXT) || (__style == _TAB_STYLE_ICON_TEXT)))
324 bool isDuplicate = CheckDuplicatedActionId(actionId);
325 SysTryReturnResult(NID_UI_CTRL, isDuplicate == false, E_SYSTEM, "A system error has occurred. The tab already has an item with same action id (%d).", actionId);
327 int itemCount = __tabItems.GetCount();
329 SysTryReturnResult(NID_UI_CTRL, itemCount < _TAB_ITEM_MAXCOUNT, E_SYSTEM, "A system error has occurred. The tab has maximum number of items.");
331 _TabItem *pItem = new (std::nothrow) _TabItem;
332 SysTryReturnResult(NID_UI_CTRL, pItem != null, E_OUT_OF_MEMORY, "Memory allocation failed.");
334 pItem->SetText(text);
335 pItem->SetActionId(actionId);
336 pItem->SetUpdateState(true);
340 pItem->SetStatus(_TABITEM_STATUS_NORMAL);
344 pItem->SetStatus(_TABITEM_STATUS_SELECTED);
347 __pTabPresenter->SetRecalculateItemBounds(true);
350 return __tabItems.Add(*pItem);
354 _Tab::InsertItemAt(int index, const Bitmap& icon, const String& text, int actionId)
356 result r = E_SUCCESS;
357 bool isSelected = false;
359 if (actionId < _TAB_ACTION_ID_MIN || actionId > _TAB_ACTION_ID_MAX)
361 SysLog(NID_UI_CTRL, "[E_OUT_OF_RANGE] The actionId (%d) is out of range.", actionId);
362 return E_OUT_OF_RANGE;
365 if (!((__style == _TAB_STYLE_TEXT) || (__style == _TAB_STYLE_ICON_TEXT)))
370 __style = _TAB_STYLE_ICON_TEXT;
372 bool isDuplicate = CheckDuplicatedActionId(actionId);
373 SysTryReturnResult(NID_UI_CTRL, isDuplicate == false, E_SYSTEM, "A system error has occurred.The tab already has an item with same action id (%d).", actionId);
375 int itemCount = __tabItems.GetCount();
377 SysTryReturnResult(NID_UI_CTRL, itemCount < _TAB_ITEM_MAXCOUNT, E_SYSTEM, "A system error has occurred. The tab has maximum number of items.");
379 _TabItem *pItem = new (std::nothrow) _TabItem;
380 SysTryReturnResult(NID_UI_CTRL, pItem != null, E_OUT_OF_MEMORY, "Memory allocation failed.");
382 pItem->SetIcon(icon);
383 pItem->SetText(text);
384 pItem->SetActionId(actionId);
385 pItem->SetUpdateState(true);
387 int selectedIndex = GetSelectedItemIndex();
389 if (selectedIndex >= index)
391 _TabItem *pSelectedItem = null;
392 pSelectedItem = GetItemAt(selectedIndex);
393 if (pSelectedItem != null)
396 pSelectedItem->SetStatus(_TABITEM_STATUS_NORMAL);
401 pItem->SetStatus(_TABITEM_STATUS_NORMAL);
404 __pTabPresenter->SetRecalculateItemBounds(true);
406 r = __tabItems.InsertAt(*pItem, index);
410 SetSelectedItemIndex(selectedIndex);
417 _Tab::InsertItemAt(int index, const Bitmap& icon, int actionId)
419 result r = E_SUCCESS;
420 bool isSelected = false;
422 if (actionId < _TAB_ACTION_ID_MIN || actionId > _TAB_ACTION_ID_MAX)
424 SysLog(NID_UI_CTRL, "[E_OUT_OF_RANGE] The actionId (%d) is out of range.", actionId);
425 return E_OUT_OF_RANGE;
428 if (__style != _TAB_STYLE_ICON)
433 bool isDuplicate = CheckDuplicatedActionId(actionId);
434 SysTryReturnResult(NID_UI_CTRL, isDuplicate == false, E_SYSTEM, "A system error has occurred.The tab already has an item with same action id (%d).", actionId);
436 int itemCount = __tabItems.GetCount();
438 SysTryReturnResult(NID_UI_CTRL, itemCount < _TAB_ITEM_MAXCOUNT, E_SYSTEM, "A system error has occurred. The tab has maximum number of items.");
440 _TabItem *pItem = new (std::nothrow) _TabItem;
441 SysTryReturnResult(NID_UI_CTRL, pItem != null, E_OUT_OF_MEMORY, "Memory allocation failed.");
443 pItem->SetIcon(icon);
444 pItem->SetActionId(actionId);
445 pItem->SetUpdateState(true);
446 int selectedIndex = GetSelectedItemIndex();
448 if (selectedIndex >= index)
450 _TabItem *pSelectedItem = null;
451 pSelectedItem = GetItemAt(selectedIndex);
452 if (pSelectedItem != null)
455 pSelectedItem->SetStatus(_TABITEM_STATUS_NORMAL);
460 pItem->SetStatus(_TABITEM_STATUS_NORMAL);
463 __pTabPresenter->SetRecalculateItemBounds(true);
465 r = __tabItems.InsertAt(*pItem, index);
469 SetSelectedItemIndex(selectedIndex);
476 _Tab::InsertItemAt(int index, const String& text, int actionId)
478 result r = E_SUCCESS;
479 bool isSelected = false;
481 if (actionId < _TAB_ACTION_ID_MIN || actionId > _TAB_ACTION_ID_MAX)
483 SysLog(NID_UI_CTRL, "[E_OUT_OF_RANGE] The actionId (%d) is out of range.", actionId);
484 return E_OUT_OF_RANGE;
487 bool isDuplicate = CheckDuplicatedActionId(actionId);
488 SysTryReturnResult(NID_UI_CTRL, isDuplicate == false, E_SYSTEM, "A system error has occurred.The tab already has an item with same action id (%d).", actionId);
490 if (!((__style == _TAB_STYLE_TEXT) || (__style == _TAB_STYLE_ICON_TEXT)))
495 int itemCount = __tabItems.GetCount();
497 SysTryReturnResult(NID_UI_CTRL, itemCount < _TAB_ITEM_MAXCOUNT, E_SYSTEM, "A system error has occurred. The tab has maximum number of items.");
499 _TabItem *pItem = new (std::nothrow) _TabItem;
500 SysTryReturnResult(NID_UI_CTRL, pItem != null, E_OUT_OF_MEMORY, "Memory allocation failed.");
502 pItem->SetText(text);
503 pItem->SetActionId(actionId);
504 pItem->SetUpdateState(true);
505 int selectedIndex = GetSelectedItemIndex();
507 if (selectedIndex >= index)
509 _TabItem *pSelectedItem = null;
510 pSelectedItem = GetItemAt(selectedIndex);
511 if (pSelectedItem != null)
514 pSelectedItem->SetStatus(_TABITEM_STATUS_NORMAL);
519 pItem->SetStatus(_TABITEM_STATUS_NORMAL);
522 __pTabPresenter->SetRecalculateItemBounds(true);
524 r = __tabItems.InsertAt(*pItem, index);
528 SetSelectedItemIndex(selectedIndex);
535 _Tab::SetItemAt(int index, const Bitmap& icon, const String& text, int actionId)
537 if (actionId < _TAB_ACTION_ID_MIN || actionId > _TAB_ACTION_ID_MAX)
539 SysLog(NID_UI_CTRL, "[E_OUT_OF_RANGE] The actionId (%d) is out of range.", actionId);
540 return E_OUT_OF_RANGE;
543 if (!((__style == _TAB_STYLE_TEXT) || (__style == _TAB_STYLE_ICON_TEXT)))
548 __style = _TAB_STYLE_ICON_TEXT;
550 int itemCount = __tabItems.GetCount();
552 if ((index < 0) || (index >= itemCount))
554 return E_OUT_OF_RANGE;
557 SysTryReturnResult(NID_UI_CTRL, itemCount < _TAB_ITEM_MAXCOUNT, E_SYSTEM, "A system error has occurred. The tab has maximum number of items.");
559 if (GetItemIndex(actionId) != index)
564 _TabItem *pItem = static_cast<_TabItem*>(__tabItems.GetAt(index));
565 result r = GetLastResult();
566 SysTryReturnResult(NID_UI_CTRL, pItem != null, r, "[%s] Propagating.", GetErrorMessage(r));
568 pItem->SetIcon(icon);
569 pItem->SetText(text);
570 pItem->SetActionId(actionId);
571 pItem->SetUpdateState(true);
577 _Tab::SetItemAt(int index, const Bitmap& icon, int actionId)
579 if (actionId < _TAB_ACTION_ID_MIN || actionId > _TAB_ACTION_ID_MAX)
581 SysLog(NID_UI_CTRL, "[E_OUT_OF_RANGE] The actionId (%d) is out of range.", actionId);
582 return E_OUT_OF_RANGE;
585 if (__style != _TAB_STYLE_ICON)
590 int itemCount = __tabItems.GetCount();
592 if ((index < 0) || (index >= itemCount))
594 return E_OUT_OF_RANGE;
597 SysTryReturnResult(NID_UI_CTRL, itemCount < _TAB_ITEM_MAXCOUNT, E_SYSTEM, "A system error has occurred. The tab has maximum number of items.");
599 if (GetItemIndex(actionId) != index)
604 _TabItem *pItem = static_cast<_TabItem*>(__tabItems.GetAt(index));
605 result r = GetLastResult();
606 SysTryReturnResult(NID_UI_CTRL, pItem != null, r, "[%s] Propagating.", GetErrorMessage(r));
608 pItem->SetIcon(icon);
609 pItem->SetActionId(actionId);
610 pItem->SetUpdateState(true);
616 _Tab::SetItemAt(int index, const String& text, int actionId)
618 if (actionId < _TAB_ACTION_ID_MIN || actionId > _TAB_ACTION_ID_MAX)
620 SysLog(NID_UI_CTRL, "[E_OUT_OF_RANGE] The actionId (%d) is out of range.", actionId);
621 return E_OUT_OF_RANGE;
624 if (!((__style == _TAB_STYLE_TEXT) || (__style == _TAB_STYLE_ICON_TEXT)))
629 int itemCount = __tabItems.GetCount();
631 if ((index < 0) || (index >= itemCount))
633 return E_OUT_OF_RANGE;
636 SysTryReturnResult(NID_UI_CTRL, itemCount < _TAB_ITEM_MAXCOUNT, E_SYSTEM, "A system error has occurred. The tab has maximum number of items.");
638 if (GetItemIndex(actionId) != index)
643 _TabItem *pItem = static_cast<_TabItem*>(__tabItems.GetAt(index));
644 result r = GetLastResult();
645 SysTryReturnResult(NID_UI_CTRL, pItem != null, r, "[%s] Propagating.", GetErrorMessage(r));
647 pItem->SetText(text);
648 pItem->SetActionId(actionId);
649 pItem->SetUpdateState(true);
655 _Tab::RemoveItemAt(int index)
657 result r = E_SUCCESS;
658 int selectedIndex = GetSelectedItemIndex();
660 if (selectedIndex >= index)
662 _TabItem *pSelectedItem = null;
663 pSelectedItem = GetItemAt(selectedIndex);
664 if (pSelectedItem != null)
666 pSelectedItem->SetStatus(_TABITEM_STATUS_NORMAL);
669 __pTabPresenter->SetRecalculateItemBounds(true);
671 r = __tabItems.RemoveAt(index, true);
673 SetSelectedItemIndex(0);
679 _Tab::RemoveAllItems(void)
681 __pTabPresenter->SetRecalculateItemBounds(true);
682 SetSelectedItemIndex(0);
683 SetFirstDrawnItemIndex(-1);
685 __tabItems.RemoveAll(true);
691 _Tab::ChangeItemAt(const int srcIndex, const int destIndex)
693 _TabItem* pItem = null;
694 pItem = GetItemAt(srcIndex);
696 __tabItems.InsertAt(*pItem, destIndex);
698 if (srcIndex > destIndex)
700 __tabItems.RemoveAt((srcIndex + 1), false);
704 __tabItems.RemoveAt(srcIndex, false);
711 _Tab::GetItemIndex(int actionId)
713 int itemCount = __tabItems.GetCount();
715 _TabItem* pItem = null;
717 for (int i = 0; i < itemCount; i++)
719 pItem = GetItemAt(i);
721 if ((pItem != null) && (actionId == pItem->GetActionId()))
731 _Tab::CheckDuplicatedActionId(int actionId)
733 int itemIndex = GetItemIndex(actionId);
744 _Tab::LoadBitmap(void)
746 result r = E_SUCCESS;
747 Bitmap* pPressedItemBackgroundBitmap = null;
748 Bitmap* pItemBackgroundBitmap = null;
749 Bitmap* pDisabledBackgroundBitmap = null;
750 Bitmap* pSelectedItemBackgroundBitmap = null;
751 Bitmap* pPressedItemBackgroundEffectBitmap = null;
752 Bitmap* pHighlightedItemBackgroundBitmap = null;
753 Color pressedEffectColor;
754 GET_COLOR_CONFIG(TAB::ITEM_BG_EFFECT_PRESSED, pressedEffectColor);
756 r = GET_BITMAP_CONFIG_N(TAB::ITEM_BG_DISABLED, BITMAP_PIXEL_FORMAT_ARGB8888, pDisabledBackgroundBitmap);
757 SysTryLog(NID_UI_CTRL, r == E_SUCCESS, "Failed to locate disabled item background bitmap.");
759 if (pDisabledBackgroundBitmap)
761 __pDisabledBackgroundBitmap = _BitmapImpl::GetColorReplacedBitmapN(*pDisabledBackgroundBitmap, Color::GetColor(COLOR_ID_MAGENTA), GetDisabledItemBackgroundColor());
762 SysTryLog(NID_UI_CTRL, (__pDisabledBackgroundBitmap != null), "Failed to locate disabled item background bitmap.");
764 delete pDisabledBackgroundBitmap;
767 r = GET_BITMAP_CONFIG_N(TAB::ITEM_BG_NORMAL, BITMAP_PIXEL_FORMAT_ARGB8888, pItemBackgroundBitmap);
768 SysTryLog(NID_UI_CTRL, r == E_SUCCESS, "Failed to locate item background bitmap.");
770 if (pItemBackgroundBitmap)
772 __pBackgroundBitmap = _BitmapImpl::GetColorReplacedBitmapN(*pItemBackgroundBitmap, Color::GetColor(COLOR_ID_MAGENTA), GetItemBackgroundColor());
773 SysTryLog(NID_UI_CTRL, (__pBackgroundBitmap != null), "Failed to locate item background bitmap.");
775 delete pItemBackgroundBitmap;
778 r = GET_BITMAP_CONFIG_N(TAB::ITEM_BG_PRESSED, BITMAP_PIXEL_FORMAT_ARGB8888, pPressedItemBackgroundBitmap);
779 SysTryLog(NID_UI_CTRL, r == E_SUCCESS, "Failed to locate pressed item background bitmap.");
781 if (pPressedItemBackgroundBitmap)
783 __pPressedItemBackgroundBitmap = _BitmapImpl::GetColorReplacedBitmapN(*pPressedItemBackgroundBitmap, Color::GetColor(COLOR_ID_MAGENTA), GetPressedItemBackgroundColor());
784 SysTryLog(NID_UI_CTRL, (__pPressedItemBackgroundBitmap != null), "Failed to locate pressed item background bitmap.");
786 delete pPressedItemBackgroundBitmap;
789 r = GET_BITMAP_CONFIG_N(TAB::ITEM_BG_SELECTED, BITMAP_PIXEL_FORMAT_ARGB8888, pSelectedItemBackgroundBitmap);
790 SysTryLog(NID_UI_CTRL, r == E_SUCCESS, "Failed to locate selected item background bitmap.");
792 if (pSelectedItemBackgroundBitmap)
794 __pSelectedItemBackgroundBitmap = _BitmapImpl::GetColorReplacedBitmapN(*pSelectedItemBackgroundBitmap, Color::GetColor(COLOR_ID_MAGENTA), GetSelectedItemBackgroundColor());
795 SysTryLog(NID_UI_CTRL, (__pSelectedItemBackgroundBitmap != null), "Failed to locate selected item background bitmap.");
797 delete pSelectedItemBackgroundBitmap;
800 r = GET_BITMAP_CONFIG_N(TAB::ITEM_BG_EFFECT_PRESSED, BITMAP_PIXEL_FORMAT_ARGB8888, pPressedItemBackgroundEffectBitmap);
801 SysTryLog(NID_UI_CTRL, r == E_SUCCESS, "Failed to locate selected item background bitmap.");
803 if (pPressedItemBackgroundEffectBitmap)
805 __pPressedItemBackgroundEffectBitmap = _BitmapImpl::GetColorReplacedBitmapN(*pPressedItemBackgroundEffectBitmap, Color::GetColor(COLOR_ID_MAGENTA), pressedEffectColor);
806 SysTryLog(NID_UI_CTRL, (__pPressedItemBackgroundEffectBitmap != null), "Failed to locate selected item background bitmap.");
808 delete pPressedItemBackgroundEffectBitmap;
811 r = GET_BITMAP_CONFIG_N(TAB::ITEM_BG_HIGHLIGHTED, BITMAP_PIXEL_FORMAT_ARGB8888, pHighlightedItemBackgroundBitmap);
812 SysTryLog(NID_UI_CTRL, r == E_SUCCESS, "Failed to locate highlighted item background bitmap.");
814 if (pHighlightedItemBackgroundBitmap)
816 __pHighlightedItemBackgroundBitmap = _BitmapImpl::GetColorReplacedBitmapN(*pHighlightedItemBackgroundBitmap, Color::GetColor(COLOR_ID_MAGENTA), GetHighlightedItemBackgroundColor());
817 SysTryLog(NID_UI_CTRL, (__pHighlightedItemBackgroundBitmap != null), "Failed to locate highlighted item background bitmap.");
819 delete pHighlightedItemBackgroundBitmap;
825 _Tab::SetBadgeIcon(int actionId, const Bitmap* pBadgeIcon)
827 result r = E_SUCCESS;
829 if (actionId < _TAB_ACTION_ID_MIN || actionId > _TAB_ACTION_ID_MAX)
831 SysLog(NID_UI_CTRL, "[E_OUT_OF_RANGE] The actionId (%d) is out of range.", actionId);
832 return E_OUT_OF_RANGE;
835 int itemIndex = GetItemIndexFromActionId(actionId);
837 _TabItem *pItem = null;
841 SysLog(NID_UI_CTRL, "[E_INVALID_ARG] Invalid argument(s) is used. The specified actionId is not found.");
842 return E_INVALID_ARG;
845 pItem = dynamic_cast<_TabItem*>(__tabItems.GetAt(itemIndex));
849 pItem->SetBadgeIcon(*pBadgeIcon);
851 r = __tabItems.SetAt(*pItem, itemIndex, false);
858 _Tab::GetItemCount(void) const
860 return __tabItems.GetCount();
864 _Tab::GetItemIndexFromActionId(int actionId) const
866 if (actionId < _TAB_ACTION_ID_MIN || actionId > _TAB_ACTION_ID_MAX)
868 SysLog(NID_UI_CTRL, "[E_OUT_OF_RANGE] The actionId (%d) is out of range.", actionId);
873 int itemCount = __tabItems.GetCount();
875 for (index = 0; index < itemCount; index++)
877 const _TabItem *pItem = dynamic_cast<const _TabItem*>(__tabItems.GetAt(index));
881 if (pItem->GetActionId() == actionId)
892 _Tab::GetItemActionIdAt(int index) const
894 if (__tabItems.GetAt(index) == null )
899 const _TabItem *pItem = dynamic_cast<const _TabItem*>(__tabItems.GetAt(index));
900 SysTryReturn(NID_UI_CTRL, pItem != null, E_SYSTEM, E_SYSTEM,"[E_SYSTEM] A system error has occurred. Failed to get an item at index (%d).", index);
902 return pItem->GetActionId();
906 _Tab::GetItemAt(int index)
908 if (__tabItems.GetAt(index) == null )
913 _TabItem *pItem = static_cast<_TabItem*>(__tabItems.GetAt(index));
914 result r = GetLastResult();
915 SysTryReturn(NID_UI_CTRL, pItem != null, null, r, "[%s] Propagating.", GetErrorMessage(r));
921 _Tab::SetSelectedItemIndex(int index)
923 __pTabPresenter->SetSelectedItemIndex(index);
928 _Tab::GetSelectedItemIndex(void) const
930 return __pTabPresenter->GetSelectedItemIndex();
934 _Tab::SetFirstDrawnItemIndex(int index)
936 __pTabPresenter->SetFirstDrawnItemIndex(index);
941 _Tab::GetFirstDrawnItemIndex(void) const
943 return __pTabPresenter->GetFirstDrawnItemIndex();
947 _Tab::SetEditModeEnabled(bool isEnabled)
949 return __pTabPresenter->SetEditModeEnabled(isEnabled);
953 _Tab::IsEditModeEnabled(void) const
955 return __pTabPresenter->IsEditModeEnabled();
959 _Tab::SetBackgroundBitmap(const Bitmap& bitmap)
963 Tizen::Graphics::Bitmap* pBitmap = _BitmapImpl::CloneN(bitmap);
965 SysTryReturn(NID_UI_CTRL, (pBitmap), GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
967 if (__pBackgroundBitmap)
969 delete __pBackgroundBitmap;
970 __pBackgroundBitmap = null;
973 __pBackgroundBitmap = pBitmap;
975 if (__pDisabledBackgroundBitmap)
977 delete __pDisabledBackgroundBitmap;
978 __pDisabledBackgroundBitmap = null;
985 _Tab::GetBackgroundBitmap(void) const
987 return __pBackgroundBitmap;
991 _Tab::GetDisabledBackgroundBitmap(void) const
993 return __pDisabledBackgroundBitmap;
997 _Tab::GetPressedItemBackgroundBitmap(void) const
999 return __pPressedItemBackgroundBitmap;
1003 _Tab::GetPressedItemBackgroundEffectBitmap(void) const
1005 return __pPressedItemBackgroundEffectBitmap;
1009 _Tab::SetSelectedItemBackgroundBitmap(const Bitmap& bitmap)
1013 Tizen::Graphics::Bitmap* pBitmap = _BitmapImpl::CloneN(bitmap);
1015 SysTryReturn(NID_UI_CTRL, (pBitmap), GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1017 if (__pSelectedItemBackgroundBitmap)
1019 delete __pSelectedItemBackgroundBitmap;
1020 __pSelectedItemBackgroundBitmap = null;
1022 __pSelectedItemBackgroundBitmap = pBitmap;
1023 __pTabPresenter->FreeHorizontalLineBitmap();
1030 _Tab::GetSelectedItemBackgroundBitmap(void) const
1032 return __pSelectedItemBackgroundBitmap;
1036 _Tab::SetHighlightedItemBackgroundBitmap(const Bitmap& bitmap)
1040 Tizen::Graphics::Bitmap* pBitmap = _BitmapImpl::CloneN(bitmap);
1042 SysTryReturn(NID_UI_CTRL, (pBitmap), GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1044 if (__pHighlightedItemBackgroundBitmap)
1046 delete __pHighlightedItemBackgroundBitmap;
1047 __pHighlightedItemBackgroundBitmap = null;
1050 __pHighlightedItemBackgroundBitmap = pBitmap;
1056 _Tab::GetHighlightedItemBackgroundBitmap(void) const
1058 return __pHighlightedItemBackgroundBitmap;
1062 _Tab::SetItemBackgroundColor(Color color)
1064 __itemBgColor[_TAB_STATUS_NORMAL] = color;
1069 _Tab::GetItemBackgroundColor(void) const
1071 return __itemBgColor[_TAB_STATUS_NORMAL];
1075 _Tab::GetPressedItemBackgroundColor(void) const
1077 return __itemBgColor[_TAB_STATUS_PRESSED];
1081 _Tab::SetSelectedItemBackgroundColor(Color color)
1083 __itemBgColor[_TAB_STATUS_SELECTED] = color;
1088 _Tab::GetSelectedItemBackgroundColor(void) const
1090 return __itemBgColor[_TAB_STATUS_SELECTED];
1094 _Tab::SetHighlightedItemBackgroundColor(Color color)
1096 __itemBgColor[_TAB_STATUS_HIGHLIGHTED] = color;
1101 _Tab::GetHighlightedItemBackgroundColor(void) const
1103 return __itemBgColor[_TAB_STATUS_HIGHLIGHTED];
1107 _Tab::GetDisabledItemBackgroundColor(void) const
1109 return __itemBgColor[_TAB_STATUS_DISABLED];
1113 _Tab::SetTextColor(const Color& textColor)
1115 __itemTextColor[_TAB_STATUS_NORMAL] = textColor;
1120 _Tab::GetTextColor(void) const
1122 return __itemTextColor[_TAB_STATUS_NORMAL];
1126 _Tab::GetDisabledTextColor(void) const
1128 return __itemTextColor[_TAB_STATUS_DISABLED];
1132 _Tab::SetPressedTextColor(const Color& textColor)
1134 __itemTextColor[_TAB_STATUS_PRESSED] = textColor;
1139 _Tab::GetPressedTextColor(void) const
1141 return __itemTextColor[_TAB_STATUS_PRESSED];
1145 _Tab::SetSelectedTextColor(const Color& textColor)
1147 __itemTextColor[_TAB_STATUS_SELECTED] = textColor;
1152 _Tab::GetSelectedTextColor(void) const
1154 return __itemTextColor[_TAB_STATUS_SELECTED];
1158 _Tab::SetHighlightedTextColor(const Color& color)
1160 __itemTextColor[_TAB_STATUS_HIGHLIGHTED] = color;
1165 _Tab::GetHighlightedTextColor(void) const
1167 return __itemTextColor[_TAB_STATUS_HIGHLIGHTED];
1171 _Tab::SetStyle(int style)
1178 _Tab::GetStyle(void) const
1180 return _TabStyle(__style);
1184 _Tab::AddActionEventListener(const _IActionEventListener& listener)
1188 if (__pActionEvent == null)
1190 __pActionEvent = _ActionEvent::CreateInstanceN(*this);
1192 if (__pActionEvent == null || IsFailed(GetLastResult()))
1194 SetLastResult(E_SYSTEM);
1195 delete __pActionEvent;
1199 __pActionEvent->AddListener(listener);
1204 _Tab::RemoveActionEventListener(const _IActionEventListener& listener)
1208 __pActionEvent->RemoveListener(listener);
1213 _Tab::OnTouchPressed(const _Control& source, const _TouchInfo& touchinfo)
1215 if (this != &source)
1220 return __pTabPresenter->OnTouchPressed(source, touchinfo);
1224 _Tab::OnTouchReleased(const _Control& source, const _TouchInfo& touchinfo)
1226 if (this != &source)
1231 __pTabPresenter->OnTouchReleased(source, touchinfo);
1233 int index = __pTabPresenter->GetItemIndexFromPosition(touchinfo.GetCurrentPosition());
1235 _TabItem* pItem = __pTabPresenter->GetItemAt(index);
1244 IEventArg* pEventArg = _ActionEvent::CreateActionEventArgN(pItem->GetActionId());
1245 SysTryReturn(NID_UI_CTRL, pEventArg, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1247 __pActionEvent->Fire(*pEventArg);
1254 _Tab::OnTouchMoved(const _Control& source, const _TouchInfo& touchinfo)
1256 if (this != &source)
1261 return __pTabPresenter->OnTouchMoved(source, touchinfo);
1265 _Tab::OnLongPressGestureDetected(_TouchLongPressGestureDetector& gesture)
1267 return __pTabPresenter->OnLongPressGestureDetected();
1271 _Tab::OnLongPressGestureCanceled(_TouchLongPressGestureDetector& gesture)
1277 _Tab::OnFlickGestureDetected(_TouchFlickGestureDetector& gesture)
1280 return __pTabPresenter->OnFlickGestureDetected(gesture);
1284 _Tab::OnFlickGestureCanceled(_TouchFlickGestureDetector& gesture)
1293 __pTabPresenter->Draw();
1299 _Tab::OnBoundsChanged(void)
1301 __pTabPresenter->OnBoundsChanged();
1305 _Tab::OnAttachedToMainTree(void)
1307 _AccessibilityContainer* pContainer = null;
1309 if (likely((_AccessibilityManager::IsActivated())))
1311 pContainer = GetAccessibilityContainer();
1315 pContainer->Activate(true);
1316 pContainer->AddListener(*this);
1324 _Tab::OnFontChanged(Font* pFont)
1326 __pTabPresenter->OnFontChanged(pFont);
1331 _Tab::OnFontInfoRequested(unsigned long& style, float& size)
1333 __pTabPresenter->OnFontInfoRequested(style, size);
1338 _Tab::AddAccessibilityElement(const FloatRectangle& itemBounds, const String& itemText, _TabItemStatus status)
1340 if (likely(!(_AccessibilityManager::IsActivated())))
1345 _AccessibilityContainer* pContainer = GetAccessibilityContainer();
1347 if (pContainer != null)
1349 _AccessibilityElement* pAccessibilityElement = new (std::nothrow) _AccessibilityElement(true);
1350 SysTryReturnVoidResult(NID_UI_CTRL, pAccessibilityElement != null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
1352 pAccessibilityElement->SetTrait(L"Tab");
1353 pAccessibilityElement->SetHint(L"Double tap to move to contents");
1354 pAccessibilityElement->SetBounds(itemBounds);
1356 if (GetStyle() != _TAB_STYLE_ICON)
1358 pAccessibilityElement->SetLabel(itemText);
1361 if (status == _TABITEM_STATUS_SELECTED)
1363 pAccessibilityElement->SetStatus("Selected");
1364 pAccessibilityElement->SetHintDisabled(true);
1368 pAccessibilityElement->SetStatus("");
1369 pAccessibilityElement->SetHintDisabled(false);
1372 pContainer->AddElement(*pAccessibilityElement);
1373 __accessibilityElements.Add(pAccessibilityElement);
1380 _Tab::RemoveAllAccessibilityElement(void)
1382 if (likely(!(_AccessibilityManager::IsActivated())))
1387 _AccessibilityContainer* pContainer = GetAccessibilityContainer();
1389 if (pContainer == null)
1394 _AccessibilityElement* pAccessibilityElement = null;
1396 while (__accessibilityElements.GetCount() > 0)
1398 if ((__accessibilityElements.GetAt(0, pAccessibilityElement)) == E_SUCCESS)
1400 pContainer->RemoveElement(*pAccessibilityElement);
1401 __accessibilityElements.RemoveAt(0);
1405 __accessibilityElements.RemoveAt(0);
1413 _Tab::OnChangeLayout(_ControlOrientation orientation)
1415 __pTabPresenter->OnChangeLayout(orientation);
1421 _Tab::OnAccessibilityFocusMovedNext(const _AccessibilityContainer& control, const _AccessibilityElement& element)
1425 return __pTabPresenter->OnAccessibilityFocusMovedNext(control, element);
1429 _Tab::OnAccessibilityFocusMovedPrevious(const _AccessibilityContainer& control, const _AccessibilityElement& element)
1433 return __pTabPresenter->OnAccessibilityFocusMovedPrevious(control, element);
1437 _Tab::OnAccessibilityReadingElement(const _AccessibilityContainer& control, const _AccessibilityElement& element)
1442 _Tab::OnAccessibilityReadedElement(const _AccessibilityContainer& control, const _AccessibilityElement& element)
1448 _Tab::OnAccessibilityFocusIn(const _AccessibilityContainer& control, const _AccessibilityElement& element)
1454 _Tab::OnAccessibilityFocusOut(const _AccessibilityContainer& control, const _AccessibilityElement& element)
1460 _Tab::OnAccessibilityActionPerformed(const _AccessibilityContainer& control, const _AccessibilityElement& element)
1466 _Tab::OnAccessibilityValueIncreased(const Tizen::Ui::_AccessibilityContainer&, const Tizen::Ui::_AccessibilityElement&)
1472 _Tab::OnAccessibilityValueDecreased(const Tizen::Ui::_AccessibilityContainer&, const Tizen::Ui::_AccessibilityElement&)
1477 }}} // Tizen::Ui::Controls