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_TabBar.cpp
19 * @brief This is the implementation file for the _TabBar class.
23 #include <FBaseErrorDefine.h>
24 #include <FBaseSysLog.h>
25 #include "FUi_UiTouchEvent.h"
26 #include "FUi_ResourceManager.h"
27 #include "FUi_AccessibilityContainer.h"
28 #include "FUi_AccessibilityElement.h"
29 #include "FUiCtrl_TabBar.h"
31 using namespace Tizen::Base;
32 using namespace Tizen::Graphics;
33 using namespace Tizen::Base::Runtime;
35 namespace Tizen { namespace Ui { namespace Controls
38 IMPLEMENT_PROPERTY(_TabBar);
41 : __pTabBarPresenter(null)
42 , __pActionEvent(null)
44 GET_COLOR_CONFIG(TABBAR::BG_NORMAL, __color);
46 GET_COLOR_CONFIG(TABBAR::ITEM_BG_NORMAL, __itemColor[ITEM_STATUS_NORMAL]);
47 GET_COLOR_CONFIG(TABBAR::ITEM_BG_PRESSED, __itemColor[ITEM_STATUS_SELECTED]);
48 GET_COLOR_CONFIG(TABBAR::ITEM_BG_HIGHLIGHTED, __itemColor[ITEM_STATUS_HIGHLIGHTED]);
50 GET_COLOR_CONFIG(TABBAR::ITEM_TEXT_NORMAL, __itemTextColor[ITEM_STATUS_NORMAL]);
51 GET_COLOR_CONFIG(TABBAR::ITEM_TEXT_PRESSED, __itemTextColor[ITEM_STATUS_SELECTED]);
52 GET_COLOR_CONFIG(TABBAR::ITEM_TEXT_HIGHLIGHTED, __itemTextColor[ITEM_STATUS_HIGHLIGHTED]);
55 _TabBar::~_TabBar(void)
57 delete __pTabBarPresenter;
58 __pTabBarPresenter = null;
62 delete __pActionEvent;
63 __pActionEvent = null;
66 RemoveAllAccessibilityElement();
70 _TabBar::CreateTabBarN(void)
72 _TabBar* pTabBar = new (std::nothrow) _TabBar();
73 SysTryReturn(NID_UI_CTRL, pTabBar != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
75 result r = pTabBar->Initialize();
76 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Failed to Initialize.", GetErrorMessage(r));
78 pTabBar->AcquireHandle();
79 pTabBar->SetTouchMoveAllowance(TOUCH_MOVE_ALLOWANCE_NORMAL);
81 if (pTabBar->GetAccessibilityContainer() != null)
83 pTabBar->GetAccessibilityContainer()->Activate(true);
95 _TabBar::Initialize(void)
99 _TabBarPresenter* pTabBarPresenter = new (std::nothrow) _TabBarPresenter(*this);
100 SysTryReturn(NID_UI_CTRL, pTabBarPresenter != null, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
102 r = pTabBarPresenter->Construct();
103 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
105 r = SetPresenter(*pTabBarPresenter);
106 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
108 r = pTabBarPresenter->InitializeFont();
109 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
114 __pTabBarPresenter = null;
116 delete pTabBarPresenter;
122 _TabBar::SetPresenter(const _TabBarPresenter& tabBarPresenter)
124 __pTabBarPresenter = const_cast<_TabBarPresenter*>(&tabBarPresenter);
130 _TabBar::AddItem(const Tizen::Base::String& text, int actionId)
132 return __pTabBarPresenter->AddItem(text, actionId);
136 _TabBar::InsertItemAt(int index, const Tizen::Base::String& text, int actionId)
138 return __pTabBarPresenter->InsertItemAt(index, text, actionId);
142 _TabBar::SetItemAt(int index, const Tizen::Base::String& text, int actionId)
144 return __pTabBarPresenter->SetItemAt(index, text, actionId);
148 _TabBar::RemoveItemAt(int index)
150 return __pTabBarPresenter->RemoveItemAt(index);
154 _TabBar::RemoveAllItems(void)
156 return __pTabBarPresenter->RemoveAllItems();
160 _TabBar::SetPropertyColor(const Variant& color)
162 result r = E_SUCCESS;
164 r = __pTabBarPresenter->SetReplacementColor(color.ToColor());
168 __color = color.ToColor();
175 _TabBar::GetPropertyColor(void) const
177 return Tizen::Ui::Variant(__color);
181 _TabBar::SetColor(Tizen::Graphics::Color color)
183 return SetProperty("color", Variant(color));
186 Tizen::Graphics::Color
187 _TabBar::GetColor(void) const
189 Variant color = GetProperty("color");
191 return color.ToColor();
195 _TabBar::SetPropertyNormalItemColor(const Variant& color)
197 result r = E_SUCCESS;
199 r = __pTabBarPresenter->SetItemReplacementColor(ITEM_STATUS_NORMAL, color.ToColor());
202 __itemColor[ITEM_STATUS_NORMAL] = color.ToColor();
209 _TabBar::GetPropertyNormalItemColor(void) const
211 return Tizen::Ui::Variant(__itemColor[ITEM_STATUS_NORMAL]);
215 _TabBar::SetPropertySelectedItemColor(const Variant& color)
217 result r = E_SUCCESS;
219 r = __pTabBarPresenter->SetItemReplacementColor(ITEM_STATUS_SELECTED, color.ToColor());
222 __itemColor[ITEM_STATUS_SELECTED] = color.ToColor();
229 _TabBar::GetPropertySelectedItemColor(void) const
231 return Tizen::Ui::Variant(__itemColor[ITEM_STATUS_SELECTED]);
235 _TabBar::SetPropertyHighlightedItemColor(const Variant& color)
237 result r = E_SUCCESS;
239 r = __pTabBarPresenter->SetItemReplacementColor(ITEM_STATUS_HIGHLIGHTED, color.ToColor());
242 __itemColor[ITEM_STATUS_HIGHLIGHTED] = color.ToColor();
249 _TabBar::GetPropertyHighlightedItemColor(void) const
251 return Tizen::Ui::Variant(__itemColor[ITEM_STATUS_HIGHLIGHTED]);
255 _TabBar::SetItemColor(_TabBarItemStatus itemStatus, Tizen::Graphics::Color color)
257 result r = E_SUCCESS;
259 if (itemStatus == ITEM_STATUS_NORMAL)
261 r = SetProperty("normalItemColor", Variant(color));
263 else if (itemStatus == ITEM_STATUS_SELECTED)
265 r = SetProperty("selectedItemColor", Variant(color));
269 r = SetProperty("highlightedItemColor", Variant(color));
275 Tizen::Graphics::Color
276 _TabBar::GetItemColor(_TabBarItemStatus itemStatus) const
280 if (itemStatus == ITEM_STATUS_NORMAL)
282 Variant color = GetProperty("normalItemColor");
283 itemColor = color.ToColor();
285 else if (itemStatus == ITEM_STATUS_SELECTED)
287 Variant color = GetProperty("selectedItemColor");
288 itemColor = color.ToColor();
292 Variant color = GetProperty("highlightedItemColor");
293 itemColor = color.ToColor();
300 _TabBar::SetPropertyNormalItemTextColor(const Variant & color)
302 __itemTextColor[ITEM_STATUS_NORMAL] = color.ToColor();
308 _TabBar::GetPropertyNormalItemTextColor(void) const
310 return Tizen::Ui::Variant(__itemTextColor[ITEM_STATUS_NORMAL]);
314 _TabBar::SetPropertySelectedItemTextColor(const Variant & color)
316 __itemTextColor[ITEM_STATUS_SELECTED] = color.ToColor();
322 _TabBar::GetPropertySelectedItemTextColor(void) const
324 return Tizen::Ui::Variant(__itemTextColor[ITEM_STATUS_SELECTED]);
328 _TabBar::SetPropertyHighlightedItemTextColor(const Variant & color)
330 __itemTextColor[ITEM_STATUS_HIGHLIGHTED] = color.ToColor();
336 _TabBar::GetPropertyHighlightedItemTextColor(void) const
338 return Tizen::Ui::Variant(__itemTextColor[ITEM_STATUS_HIGHLIGHTED]);
343 _TabBar::SetItemTextColor(_TabBarItemStatus status, Tizen::Graphics::Color color)
346 result r = E_SUCCESS;
348 if (status == ITEM_STATUS_NORMAL)
350 r = SetProperty("normalItemTextColor", Variant(color));
352 else if (status == ITEM_STATUS_SELECTED)
354 r = SetProperty("selectedItemTextColor", Variant(color));
358 r = SetProperty("highlightedItemTextColor", Variant(color));
363 SysLogException(NID_UI_CTRL, E_INVALID_STATE, "Color is invalid.");
368 Tizen::Graphics::Color
369 _TabBar::GetItemTextColor(_TabBarItemStatus status) const
373 if (status == ITEM_STATUS_NORMAL)
375 Variant color = GetProperty("normalItemTextColor");
376 itemTextColor = color.ToColor();
378 else if (status == ITEM_STATUS_SELECTED)
380 Variant color = GetProperty("selectedItemTextColor");
381 itemTextColor = color.ToColor();
385 Variant color = GetProperty("highlightedItemTextColor");
386 itemTextColor = color.ToColor();
389 return itemTextColor;
393 _TabBar::SetItemSelected(int index)
395 return __pTabBarPresenter->SetItemSelected(index);
399 _TabBar::GetSelectedItemIndex(void) const
401 return __pTabBarPresenter->GetSelectedItemIndex();
405 _TabBar::GetItemCount(void) const
407 return __pTabBarPresenter->GetItemCount();
411 _TabBar::GetItemFromPosition(const Tizen::Graphics::Point& position) const
413 return __pTabBarPresenter->GetItemFromPosition(position);
417 _TabBar::SetTopDrawnItemIndex(int index)
419 return __pTabBarPresenter->SetTopDrawnItemIndex(index);
423 _TabBar::SetWidth(int width)
428 GET_SHAPE_CONFIG(TABBAR::HEIGHT, _CONTROL_ORIENTATION_PORTRAIT, height);
429 r = SetSize(Dimension(width, height));
430 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
431 __pTabBarPresenter->InitItemPositionX();
437 _TabBar::AddActionEventListener(const Tizen::Ui::Controls::_IActionEventListener& listener)
441 if (__pActionEvent == null)
443 __pActionEvent = _ActionEvent::CreateInstanceN(*this);
445 if (__pActionEvent == null || IsFailed(GetLastResult()))
447 SysLog(NID_UI_CTRL, "[E_INVALID_STATE] System error occured.");
448 SetLastResult(E_INVALID_STATE);
449 delete __pActionEvent;
454 SetLastResult(E_SUCCESS);
455 __pActionEvent->AddListener(listener);
459 _TabBar::RemoveActionEventListener(const Tizen::Ui::Controls::_IActionEventListener& listener)
461 SysTryReturnVoidResult(NID_UI_CTRL, __pActionEvent != null, E_INVALID_STATE, "[E_INVALID_STATE] This instance isn't constructed.")
462 // Todo : check fail case of RemoveListener
463 __pActionEvent->RemoveListener(listener);
467 _TabBar::OnTouchPressed(const _Control& source, const _TouchInfo& touchinfo)
469 return __pTabBarPresenter->OnTouchPressed(source, touchinfo);
473 _TabBar::OnTouchReleased(const _Control& source, const _TouchInfo& touchinfo)
475 bool eventFire = __pTabBarPresenter->OnTouchReleased(source, touchinfo);
476 if (eventFire == true)
478 int index = __pTabBarPresenter->GetItemIndexFromPosition(touchinfo.GetCurrentPosition());
479 _TabBarItem* pItem = __pTabBarPresenter->GetItemAt(index);
484 IEventArg* pEventArg = _ActionEvent::CreateActionEventArgN(pItem->GetActionId());
485 SysTryReturn(NID_UI_CTRL, pEventArg != null, E_INVALID_STATE, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
487 __pActionEvent->Fire(*pEventArg);
496 _TabBar::OnTouchMoved(const _Control& source, const _TouchInfo& touchinfo)
498 return __pTabBarPresenter->OnTouchMoved(source, touchinfo);
502 _TabBar::OnFontChanged(Font * pFont)
504 __pTabBarPresenter->OnFontChanged(pFont);
508 _TabBar::OnFontInfoRequested(unsigned long& style, int& size)
510 __pTabBarPresenter->OnFontInfoRequested(style, size);
514 _TabBar::OnDraw(void)
516 __pTabBarPresenter->Draw();
518 SetAllAccessibilityElement();
522 _TabBar::OnBoundsChanged(void)
524 __pTabBarPresenter->OnBoundsChanged();
527 _AccessibilityElement*
528 _TabBar::GetAccessibilityElement(const int mainIndex) const
530 _AccessibilityElement* pElement = null;
531 result r = __accessibilityElements.GetAt(mainIndex, pElement);
532 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Failed at AccessibiltyElement.", GetErrorMessage(r));
543 _TabBar::AddAccessibilityElement(const _AccessibilityElement& element)
545 __accessibilityElements.Add(const_cast<_AccessibilityElement*>(&element));
549 _TabBar::SetAllAccessibilityElement(void)
551 RemoveAllAccessibilityElement();
552 __pTabBarPresenter->SetAllAccessibilityElement();
556 _TabBar::RemoveAllAccessibilityElement(void)
558 while (__accessibilityElements.GetCount() > 0)
560 _AccessibilityElement* pElement = null;
561 if (__accessibilityElements.GetAt(0, pElement) == E_SUCCESS)
563 pElement->GetParent()->RemoveElement(*pElement);
564 __accessibilityElements.RemoveAt(0);
569 }}} // Tizen::Ui::Controls