Merge "OnFocusModeStateChanged implementation in Tab. Signed-off-by: syed khaja moinu...
[platform/framework/native/uifw.git] / src / ui / controls / FUiCtrl_Tab.cpp
1 //
2 // Open Service Platform
3 // Copyright (c) 2012-2013 Samsung Electronics Co., Ltd.
4 //
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
8 //
9 //     http://www.apache.org/licenses/LICENSE-2.0/
10 //
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.
16 //
17
18 /**
19  * @file                FUiCtrl_Tab.cpp
20  * @brief               This is the implementation file for the _Tab class.
21  */
22
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"
33
34 using namespace Tizen::Base;
35 using namespace Tizen::Graphics;
36 using namespace Tizen::Base::Runtime;
37
38 namespace Tizen { namespace Ui { namespace Controls {
39
40 _Tab::_Tab(void)
41         : __pTabPresenter(null)
42         , __style(_TAB_STYLE_TEXT)
43         , __currentHighlightedItemIndex(-1)
44         , __tabStatus(_TAB_STATUS_NORMAL)
45         , __pActionEvent(null)
46         , __pGestureLongPress(null)
47         , __pFlickGesture(null)
48         , __pBackgroundBitmap(null)
49         , __pDisabledBackgroundBitmap(null)
50         , __pPressedItemBackgroundBitmap(null)
51         , __pPressedItemBackgroundEffectBitmap(null)
52         , __pSelectedItemBackgroundBitmap(null)
53         , __pHighlightedItemBackgroundBitmap(null)
54         , __isInFocusMode(false)
55 {
56         ClearLastResult();
57         result r = E_SUCCESS;
58
59         __tabItems.Construct();
60
61         GET_COLOR_CONFIG(TAB::ITEM_BG_NORMAL, __itemBgColor[_TAB_STATUS_NORMAL]);
62         GET_COLOR_CONFIG(TAB::ITEM_BG_PRESSED, __itemBgColor[_TAB_STATUS_PRESSED]);
63         GET_COLOR_CONFIG(TAB::ITEM_BG_SELECTED, __itemBgColor[_TAB_STATUS_SELECTED]);
64         GET_COLOR_CONFIG(TAB::ITEM_BG_HIGHLIGHTED, __itemBgColor[_TAB_STATUS_HIGHLIGHTED]);
65         GET_COLOR_CONFIG(TAB::ITEM_BG_DISABLED, __itemBgColor[_TAB_STATUS_DISABLED]);
66
67         GET_COLOR_CONFIG(TAB::ITEM_TEXT_NORMAL, __itemTextColor[_TAB_STATUS_NORMAL]);
68         GET_COLOR_CONFIG(TAB::ITEM_TEXT_PRESSED, __itemTextColor[_TAB_STATUS_PRESSED]);
69         GET_COLOR_CONFIG(TAB::ITEM_TEXT_SELECTED, __itemTextColor[_TAB_STATUS_SELECTED]);
70         GET_COLOR_CONFIG(TAB::ITEM_TEXT_HIGHLIGHTED, __itemTextColor[_TAB_STATUS_HIGHLIGHTED]);
71         GET_COLOR_CONFIG(TAB::ITEM_TEXT_DISABLED, __itemTextColor[_TAB_STATUS_DISABLED]);
72
73         r = LoadBitmap();
74         SysTryReturnVoidResult(NID_UI_CTRL, r == E_SUCCESS, E_SYSTEM, "[E_SYSTEM] A system error has occurred. Failed to load bitmap.");
75
76         _Control::SetResizable(false);
77         _Control::SetMovable(false);
78
79         _TabPresenter* pPresenter = new (std::nothrow) _TabPresenter;
80         SysTryReturnVoidResult(NID_UI_CTRL, pPresenter, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
81
82         r = SetPresenter(*pPresenter);
83         SysTryReturnVoidResult(NID_UI_CTRL, r == E_SUCCESS, E_SYSTEM, "[E_SYSTEM] A system error has occurred. The _TabPresenter instance could not be set.");
84
85         r = pPresenter->Construct(*this);
86         SysTryReturnVoidResult(NID_UI_CTRL, r == E_SUCCESS, E_SYSTEM, "[E_SYSTEM] A system error has occurred. The _TabPresenter instance construct failed.");
87
88 }
89
90 _Tab::~_Tab(void)
91 {
92         delete __pTabPresenter;
93         __pTabPresenter = null;
94
95         if (__pActionEvent)
96         {
97                 delete __pActionEvent;
98                 __pActionEvent = null;
99         }
100
101         __tabItems.RemoveAll(true);
102
103         if (__pFlickGesture != null)
104         {
105                 __pFlickGesture->RemoveGestureListener(*this);
106                 RemoveGestureDetector(*__pFlickGesture);
107
108                 delete __pFlickGesture;
109                 __pFlickGesture = null;
110         }
111
112         if (__pGestureLongPress != null)
113         {
114                 __pGestureLongPress->RemoveGestureListener(*this);
115                 RemoveGestureDetector(*__pGestureLongPress);
116
117                 delete __pGestureLongPress;
118                 __pGestureLongPress = null;
119         }
120
121         if (__pBackgroundBitmap)
122         {
123                 delete __pBackgroundBitmap;
124                 __pBackgroundBitmap = null;
125         }
126
127         if (__pDisabledBackgroundBitmap)
128         {
129                 delete __pDisabledBackgroundBitmap;
130                 __pDisabledBackgroundBitmap = null;
131         }
132
133         if (__pPressedItemBackgroundBitmap)
134         {
135                 delete __pPressedItemBackgroundBitmap;
136                 __pPressedItemBackgroundBitmap = null;
137         }
138
139         if (__pPressedItemBackgroundEffectBitmap)
140         {
141                 delete __pPressedItemBackgroundEffectBitmap;
142                 __pPressedItemBackgroundEffectBitmap = null;
143         }
144
145         if (__pSelectedItemBackgroundBitmap)
146         {
147                 delete __pSelectedItemBackgroundBitmap;
148                 __pSelectedItemBackgroundBitmap = null;
149         }
150
151         if (__pHighlightedItemBackgroundBitmap)
152         {
153                 delete __pHighlightedItemBackgroundBitmap;
154                 __pHighlightedItemBackgroundBitmap = null;
155         }
156
157         RemoveAllAccessibilityElement();
158 }
159
160 _Tab*
161 _Tab::CreateTabN(void)
162 {
163         result r = E_SUCCESS;
164
165         _Tab* pTab = new (std::nothrow) _Tab;
166         SysTryReturn(NID_UI_CTRL, pTab, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
167
168         if (IsFailed(GetLastResult()))
169         {
170                 goto CATCH;
171         }
172
173         pTab->AcquireHandle();
174
175         pTab->__pGestureLongPress = new (std::nothrow) _TouchLongPressGestureDetector;
176         SysTryCatch(NID_UI_CTRL, pTab->__pGestureLongPress, , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
177
178         pTab->__pGestureLongPress->SetDuration(500);
179         pTab->AddGestureDetector(*(pTab->__pGestureLongPress));
180         r = pTab->__pGestureLongPress->AddGestureListener(*pTab);
181         SysTryCatch(NID_UI_CTRL, (r == E_SUCCESS), , r = E_SYSTEM, "[E_SYSTEM] A system error has occurred. The _ITouchGestureEventListener instance could not be set.");
182
183         pTab->__pFlickGesture = new (std::nothrow) _TouchFlickGestureDetector;
184         SysTryCatch(NID_UI_CTRL, pTab->__pFlickGesture, , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
185
186         r = pTab->AddGestureDetector(*(pTab->__pFlickGesture));
187         SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating", GetErrorMessage(r));
188
189         r = pTab->__pFlickGesture->AddGestureListener(*pTab);
190         SysTryCatch(NID_UI_CTRL, (r == E_SUCCESS), , r = E_SYSTEM, "[E_SYSTEM] A system error has occurred. The _ITouchGestureEventListener instance could not be set.");
191
192         return pTab;
193
194 CATCH:
195         if (pTab->__pGestureLongPress != null)
196         {
197                 pTab->__pGestureLongPress->RemoveGestureListener(*pTab);
198                 pTab->RemoveGestureDetector(*pTab->__pGestureLongPress);
199
200                 delete pTab->__pGestureLongPress;
201                 pTab->__pGestureLongPress = null;
202         }
203         if (pTab->__pFlickGesture != null)
204         {
205                 pTab->__pFlickGesture->RemoveGestureListener(*pTab);
206                 pTab->RemoveGestureDetector(*pTab->__pFlickGesture);
207
208                 delete pTab->__pFlickGesture;
209                 pTab->__pFlickGesture = null;
210         }
211
212         delete pTab;
213         return null;
214 }
215
216 result
217 _Tab::SetPresenter(const _TabPresenter& tabPresenter)
218 {
219         ClearLastResult();
220         __pTabPresenter = const_cast<_TabPresenter*>(&tabPresenter);
221
222         return E_SUCCESS;
223 }
224
225 result
226 _Tab::AddItem(const Bitmap& icon, const String& text, int actionId)
227 {
228         if (actionId < _TAB_ACTION_ID_MIN || actionId > _TAB_ACTION_ID_MAX)
229         {
230                 SysLog(NID_UI_CTRL, "[E_OUT_OF_RANGE] The actionId (%d) is out of range.", actionId);
231                 return E_OUT_OF_RANGE;
232         }
233
234         if (!((__style == _TAB_STYLE_TEXT) || (__style == _TAB_STYLE_ICON_TEXT)))
235         {
236                 return E_SYSTEM;
237         }
238
239         __style = _TAB_STYLE_ICON_TEXT;
240
241         bool isDuplicate = CheckDuplicatedActionId(actionId);
242         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);
243
244         int itemCount = __tabItems.GetCount();
245
246         SysTryReturnResult(NID_UI_CTRL, itemCount < _TAB_ITEM_MAXCOUNT, E_SYSTEM, "A system error has occurred. The tab has maximum number of items.");
247
248         _TabItem *pItem = new (std::nothrow) _TabItem;
249         SysTryReturnResult(NID_UI_CTRL, pItem != null, E_OUT_OF_MEMORY, "Memory allocation failed.");
250
251         pItem->SetIcon(icon);
252         pItem->SetText(text);
253         pItem->SetActionId(actionId);
254         pItem->SetUpdateState(true);
255
256         if (itemCount > 0)
257         {
258                 pItem->SetStatus(_TABITEM_STATUS_NORMAL);
259         }
260         else
261         {
262                 pItem->SetStatus(_TABITEM_STATUS_SELECTED);
263         }
264
265         __pTabPresenter->SetRecalculateItemBounds(true);
266
267         if (__pTabPresenter->GetItemStatus(__currentHighlightedItemIndex) == _TABITEM_STATUS_HIGHLIGHTED)
268         {
269                 __pTabPresenter->SetItemStatus(__currentHighlightedItemIndex, _TABITEM_STATUS_NORMAL);
270         }
271         __currentHighlightedItemIndex = 0;
272
273         AddAccessibilityElement(pItem->GetItemBounds(), pItem->GetText(), pItem->GetStatus());
274
275         return __tabItems.Add(*pItem);
276 }
277
278 result
279 _Tab::AddItem(const Bitmap& icon, int actionId)
280 {
281         if (actionId < _TAB_ACTION_ID_MIN || actionId > _TAB_ACTION_ID_MAX)
282         {
283                 SysLog(NID_UI_CTRL, "[E_OUT_OF_RANGE] The actionId (%d) is out of range.", actionId);
284                 return E_OUT_OF_RANGE;
285         }
286
287         if (__style != _TAB_STYLE_ICON)
288         {
289                 return E_SYSTEM;
290         }
291
292         bool isDuplicate = CheckDuplicatedActionId(actionId);
293         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);
294
295         int itemCount = __tabItems.GetCount();
296
297         SysTryReturnResult(NID_UI_CTRL, itemCount < _TAB_ITEM_MAXCOUNT, E_SYSTEM, "A system error has occurred. The tab has maximum number of items.");
298
299         _TabItem *pItem = new (std::nothrow) _TabItem;
300         SysTryReturnResult(NID_UI_CTRL, pItem != null, E_OUT_OF_MEMORY, "Memory allocation failed.");
301
302         pItem->SetIcon(icon);
303         pItem->SetActionId(actionId);
304         pItem->SetUpdateState(true);
305
306         if (itemCount > 0)
307         {
308                 pItem->SetStatus(_TABITEM_STATUS_NORMAL);
309         }
310         else
311         {
312                 pItem->SetStatus(_TABITEM_STATUS_SELECTED);
313         }
314
315         __pTabPresenter->SetRecalculateItemBounds(true);
316
317         if (__pTabPresenter->GetItemStatus(__currentHighlightedItemIndex) == _TABITEM_STATUS_HIGHLIGHTED)
318         {
319                 __pTabPresenter->SetItemStatus(__currentHighlightedItemIndex, _TABITEM_STATUS_NORMAL);
320         }
321         __currentHighlightedItemIndex = 0;
322
323         AddAccessibilityElement(pItem->GetItemBounds(), pItem->GetText(), pItem->GetStatus());
324
325         return __tabItems.Add(*pItem);
326 }
327
328 result
329 _Tab::AddItem(const String& text, int actionId)
330 {
331         if (actionId < _TAB_ACTION_ID_MIN || actionId > _TAB_ACTION_ID_MAX)
332         {
333                 SysLog(NID_UI_CTRL, "[E_OUT_OF_RANGE] The actionId (%d) is out of range.", actionId);
334                 return E_OUT_OF_RANGE;
335         }
336
337         if (!((__style == _TAB_STYLE_TEXT) || (__style == _TAB_STYLE_ICON_TEXT)))
338         {
339                 return E_SYSTEM;
340         }
341
342         bool isDuplicate = CheckDuplicatedActionId(actionId);
343         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);
344
345         int itemCount = __tabItems.GetCount();
346
347         SysTryReturnResult(NID_UI_CTRL, itemCount < _TAB_ITEM_MAXCOUNT, E_SYSTEM, "A system error has occurred. The tab has maximum number of items.");
348
349         _TabItem *pItem = new (std::nothrow) _TabItem;
350         SysTryReturnResult(NID_UI_CTRL, pItem != null, E_OUT_OF_MEMORY, "Memory allocation failed.");
351
352         pItem->SetText(text);
353         pItem->SetActionId(actionId);
354         pItem->SetUpdateState(true);
355
356         if (itemCount > 0)
357         {
358                 pItem->SetStatus(_TABITEM_STATUS_NORMAL);
359         }
360         else
361         {
362                 pItem->SetStatus(_TABITEM_STATUS_SELECTED);
363         }
364
365         __pTabPresenter->SetRecalculateItemBounds(true);
366
367         if (__pTabPresenter->GetItemStatus(__currentHighlightedItemIndex) == _TABITEM_STATUS_HIGHLIGHTED)
368         {
369                 __pTabPresenter->SetItemStatus(__currentHighlightedItemIndex, _TABITEM_STATUS_NORMAL);
370         }
371         __currentHighlightedItemIndex = 0;
372
373         AddAccessibilityElement(pItem->GetItemBounds(), pItem->GetText(), pItem->GetStatus());
374
375         return __tabItems.Add(*pItem);
376 }
377
378 result
379 _Tab::InsertItemAt(int index, const Bitmap& icon, const String& text, int actionId)
380 {
381         result r = E_SUCCESS;
382         bool isSelected = false;
383
384         if (actionId < _TAB_ACTION_ID_MIN || actionId > _TAB_ACTION_ID_MAX)
385         {
386                 SysLog(NID_UI_CTRL, "[E_OUT_OF_RANGE] The actionId (%d) is out of range.", actionId);
387                 return E_OUT_OF_RANGE;
388         }
389
390         if (!((__style == _TAB_STYLE_TEXT) || (__style == _TAB_STYLE_ICON_TEXT)))
391         {
392                 return E_SYSTEM;
393         }
394
395         __style = _TAB_STYLE_ICON_TEXT;
396
397         bool isDuplicate = CheckDuplicatedActionId(actionId);
398         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);
399
400         int itemCount = __tabItems.GetCount();
401
402         SysTryReturnResult(NID_UI_CTRL, itemCount < _TAB_ITEM_MAXCOUNT, E_SYSTEM, "A system error has occurred. The tab has maximum number of items.");
403
404         _TabItem *pItem = new (std::nothrow) _TabItem;
405         SysTryReturnResult(NID_UI_CTRL, pItem != null, E_OUT_OF_MEMORY, "Memory allocation failed.");
406
407         pItem->SetIcon(icon);
408         pItem->SetText(text);
409         pItem->SetActionId(actionId);
410         pItem->SetUpdateState(true);
411
412         int selectedIndex = GetSelectedItemIndex();
413
414         if (selectedIndex >= index)
415         {
416                 _TabItem *pSelectedItem = null;
417                 pSelectedItem = GetItemAt(selectedIndex);
418                 if (pSelectedItem != null)
419                 {
420                         isSelected = true;
421                         pSelectedItem->SetStatus(_TABITEM_STATUS_NORMAL);
422                 }
423         }
424         else
425         {
426                 pItem->SetStatus(_TABITEM_STATUS_NORMAL);
427         }
428
429         __pTabPresenter->SetRecalculateItemBounds(true);
430
431         r = __tabItems.InsertAt(*pItem, index);
432
433         if (isSelected)
434         {
435                 SetSelectedItemIndex(selectedIndex);
436         }
437
438         if (__pTabPresenter->GetItemStatus(__currentHighlightedItemIndex) == _TABITEM_STATUS_HIGHLIGHTED)
439         {
440                 __pTabPresenter->SetItemStatus(__currentHighlightedItemIndex, _TABITEM_STATUS_NORMAL);
441         }
442         __currentHighlightedItemIndex = 0;
443
444         InsertAccessibilityElementAt(index, pItem->GetItemBounds(), pItem->GetText(), pItem->GetStatus());
445
446         return r;
447 }
448
449 result
450 _Tab::InsertItemAt(int index, const Bitmap& icon, int actionId)
451 {
452         result r = E_SUCCESS;
453         bool isSelected = false;
454
455         if (actionId < _TAB_ACTION_ID_MIN || actionId > _TAB_ACTION_ID_MAX)
456         {
457                 SysLog(NID_UI_CTRL, "[E_OUT_OF_RANGE] The actionId (%d) is out of range.", actionId);
458                 return E_OUT_OF_RANGE;
459         }
460
461         if (__style != _TAB_STYLE_ICON)
462         {
463                 return E_SYSTEM;
464         }
465
466         bool isDuplicate = CheckDuplicatedActionId(actionId);
467         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);
468
469         int itemCount = __tabItems.GetCount();
470
471         SysTryReturnResult(NID_UI_CTRL, itemCount < _TAB_ITEM_MAXCOUNT, E_SYSTEM, "A system error has occurred. The tab has maximum number of items.");
472
473         _TabItem *pItem = new (std::nothrow) _TabItem;
474         SysTryReturnResult(NID_UI_CTRL, pItem != null, E_OUT_OF_MEMORY, "Memory allocation failed.");
475
476         pItem->SetIcon(icon);
477         pItem->SetActionId(actionId);
478         pItem->SetUpdateState(true);
479         int selectedIndex = GetSelectedItemIndex();
480
481         if (selectedIndex >= index)
482         {
483                 _TabItem *pSelectedItem = null;
484                 pSelectedItem = GetItemAt(selectedIndex);
485                 if (pSelectedItem != null)
486                 {
487                         isSelected = true;
488                         pSelectedItem->SetStatus(_TABITEM_STATUS_NORMAL);
489                 }
490         }
491         else
492         {
493                 pItem->SetStatus(_TABITEM_STATUS_NORMAL);
494         }
495
496         __pTabPresenter->SetRecalculateItemBounds(true);
497
498         r = __tabItems.InsertAt(*pItem, index);
499
500         if (isSelected)
501         {
502                 SetSelectedItemIndex(selectedIndex);
503         }
504
505         if (__pTabPresenter->GetItemStatus(__currentHighlightedItemIndex) == _TABITEM_STATUS_HIGHLIGHTED)
506         {
507                 __pTabPresenter->SetItemStatus(__currentHighlightedItemIndex, _TABITEM_STATUS_NORMAL);
508         }
509         __currentHighlightedItemIndex = 0;
510
511         InsertAccessibilityElementAt(index, pItem->GetItemBounds(), pItem->GetText(), pItem->GetStatus());
512
513         return r;
514 }
515
516 result
517 _Tab::InsertItemAt(int index, const String& text, int actionId)
518 {
519         result r = E_SUCCESS;
520         bool isSelected = false;
521
522         if (actionId < _TAB_ACTION_ID_MIN || actionId > _TAB_ACTION_ID_MAX)
523         {
524                 SysLog(NID_UI_CTRL, "[E_OUT_OF_RANGE] The actionId (%d) is out of range.", actionId);
525                 return E_OUT_OF_RANGE;
526         }
527
528         bool isDuplicate = CheckDuplicatedActionId(actionId);
529         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);
530
531         if (!((__style == _TAB_STYLE_TEXT) || (__style == _TAB_STYLE_ICON_TEXT)))
532         {
533                 return E_SYSTEM;
534         }
535
536         int itemCount = __tabItems.GetCount();
537
538         SysTryReturnResult(NID_UI_CTRL, itemCount < _TAB_ITEM_MAXCOUNT, E_SYSTEM, "A system error has occurred. The tab has maximum number of items.");
539
540         _TabItem *pItem = new (std::nothrow) _TabItem;
541         SysTryReturnResult(NID_UI_CTRL, pItem != null, E_OUT_OF_MEMORY, "Memory allocation failed.");
542
543         pItem->SetText(text);
544         pItem->SetActionId(actionId);
545         pItem->SetUpdateState(true);
546         int selectedIndex = GetSelectedItemIndex();
547
548         if (selectedIndex >= index)
549         {
550                 _TabItem *pSelectedItem = null;
551                 pSelectedItem = GetItemAt(selectedIndex);
552                 if (pSelectedItem != null)
553                 {
554                         isSelected = true;
555                         pSelectedItem->SetStatus(_TABITEM_STATUS_NORMAL);
556                 }
557         }
558         else
559         {
560                 pItem->SetStatus(_TABITEM_STATUS_NORMAL);
561         }
562
563         __pTabPresenter->SetRecalculateItemBounds(true);
564
565         r = __tabItems.InsertAt(*pItem, index);
566
567         if (isSelected)
568         {
569                 SetSelectedItemIndex(selectedIndex);
570         }
571
572         if (__pTabPresenter->GetItemStatus(__currentHighlightedItemIndex) == _TABITEM_STATUS_HIGHLIGHTED)
573         {
574                 __pTabPresenter->SetItemStatus(__currentHighlightedItemIndex, _TABITEM_STATUS_NORMAL);
575         }
576         __currentHighlightedItemIndex = 0;
577
578         InsertAccessibilityElementAt(index, pItem->GetItemBounds(), pItem->GetText(), pItem->GetStatus());
579
580         return r;
581 }
582
583 result
584 _Tab::SetItemAt(int index, const Bitmap& icon, const String& text, int actionId)
585 {
586         if (actionId < _TAB_ACTION_ID_MIN || actionId > _TAB_ACTION_ID_MAX)
587         {
588                 SysLog(NID_UI_CTRL, "[E_OUT_OF_RANGE] The actionId (%d) is out of range.", actionId);
589                 return E_OUT_OF_RANGE;
590         }
591
592         if (!((__style == _TAB_STYLE_TEXT) || (__style == _TAB_STYLE_ICON_TEXT)))
593         {
594                 return E_SYSTEM;
595         }
596
597         __style = _TAB_STYLE_ICON_TEXT;
598
599         int itemCount = __tabItems.GetCount();
600
601         if ((index < 0) || (index >= itemCount))
602         {
603                 return E_OUT_OF_RANGE;
604         }
605
606         SysTryReturnResult(NID_UI_CTRL, itemCount < _TAB_ITEM_MAXCOUNT, E_SYSTEM, "A system error has occurred. The tab has maximum number of items.");
607
608         if (GetItemIndex(actionId) != index)
609         {
610                 return E_SYSTEM;
611         }
612
613         _TabItem *pItem = static_cast<_TabItem*>(__tabItems.GetAt(index));
614         result r = GetLastResult();
615         SysTryReturnResult(NID_UI_CTRL, pItem != null, r, "[%s] Propagating.", GetErrorMessage(r));
616
617         pItem->SetIcon(icon);
618         pItem->SetText(text);
619         pItem->SetActionId(actionId);
620         pItem->SetUpdateState(true);
621
622         UpdateAccessibilityLabel(index, text);
623
624         return E_SUCCESS;
625 }
626
627 result
628 _Tab::SetItemAt(int index, const Bitmap& icon, int actionId)
629 {
630         if (actionId < _TAB_ACTION_ID_MIN || actionId > _TAB_ACTION_ID_MAX)
631         {
632                 SysLog(NID_UI_CTRL, "[E_OUT_OF_RANGE] The actionId (%d) is out of range.", actionId);
633                 return E_OUT_OF_RANGE;
634         }
635
636         if (__style != _TAB_STYLE_ICON)
637         {
638                 return E_SYSTEM;
639         }
640
641         int itemCount = __tabItems.GetCount();
642
643         if ((index < 0) || (index >= itemCount))
644         {
645                 return E_OUT_OF_RANGE;
646         }
647
648         SysTryReturnResult(NID_UI_CTRL, itemCount < _TAB_ITEM_MAXCOUNT, E_SYSTEM, "A system error has occurred. The tab has maximum number of items.");
649
650         if (GetItemIndex(actionId) != index)
651         {
652                 return E_SYSTEM;
653         }
654
655         _TabItem *pItem = static_cast<_TabItem*>(__tabItems.GetAt(index));
656         result r = GetLastResult();
657         SysTryReturnResult(NID_UI_CTRL, pItem != null, r, "[%s] Propagating.", GetErrorMessage(r));
658
659         pItem->SetIcon(icon);
660         pItem->SetActionId(actionId);
661         pItem->SetUpdateState(true);
662
663         return E_SUCCESS;
664 }
665
666 result
667 _Tab::SetItemAt(int index, const String& text, int actionId)
668 {
669         if (actionId < _TAB_ACTION_ID_MIN || actionId > _TAB_ACTION_ID_MAX)
670         {
671                 SysLog(NID_UI_CTRL, "[E_OUT_OF_RANGE] The actionId (%d) is out of range.", actionId);
672                 return E_OUT_OF_RANGE;
673         }
674
675         if (!((__style == _TAB_STYLE_TEXT) || (__style == _TAB_STYLE_ICON_TEXT)))
676         {
677                 return E_SYSTEM;
678         }
679
680         int itemCount = __tabItems.GetCount();
681
682         if ((index < 0) || (index >= itemCount))
683         {
684                 return E_OUT_OF_RANGE;
685         }
686
687         SysTryReturnResult(NID_UI_CTRL, itemCount < _TAB_ITEM_MAXCOUNT, E_SYSTEM, "A system error has occurred. The tab has maximum number of items.");
688
689         if (GetItemIndex(actionId) != index)
690         {
691                 return E_SYSTEM;
692         }
693
694         _TabItem *pItem = static_cast<_TabItem*>(__tabItems.GetAt(index));
695         result r = GetLastResult();
696         SysTryReturnResult(NID_UI_CTRL, pItem != null, r, "[%s] Propagating.", GetErrorMessage(r));
697
698         pItem->SetText(text);
699         pItem->SetActionId(actionId);
700         pItem->SetUpdateState(true);
701
702         UpdateAccessibilityLabel(index, text);
703
704         return E_SUCCESS;
705 }
706
707 result
708 _Tab::RemoveItemAt(int index)
709 {
710         result r = E_SUCCESS;
711         int selectedIndex = GetSelectedItemIndex();
712
713         if (selectedIndex >= index)
714         {
715                 _TabItem *pSelectedItem = null;
716                 pSelectedItem = GetItemAt(selectedIndex);
717                 if (pSelectedItem != null)
718                 {
719                         pSelectedItem->SetStatus(_TABITEM_STATUS_NORMAL);
720                 }
721         }
722         __pTabPresenter->SetRecalculateItemBounds(true);
723
724         r = __tabItems.RemoveAt(index, true);
725
726         SetSelectedItemIndex(0);
727
728         if (__pTabPresenter->GetItemStatus(__currentHighlightedItemIndex) == _TABITEM_STATUS_HIGHLIGHTED)
729         {
730                 __pTabPresenter->SetItemStatus(__currentHighlightedItemIndex, _TABITEM_STATUS_NORMAL);
731         }
732         if (GetItemCount() > 0)
733         {
734                 __currentHighlightedItemIndex = 0;
735         }
736         else
737         {
738                 __currentHighlightedItemIndex = -1;
739         }
740
741         RemoveAccessibilityElementAt(index);
742
743         return r;
744 }
745
746 result
747 _Tab::RemoveAllItems(void)
748 {
749         if (__pTabPresenter->GetItemStatus(__currentHighlightedItemIndex) == _TABITEM_STATUS_HIGHLIGHTED)
750         {
751                 __pTabPresenter->SetItemStatus(__currentHighlightedItemIndex, _TABITEM_STATUS_NORMAL);
752         }
753         __currentHighlightedItemIndex = -1;
754
755         __pTabPresenter->SetRecalculateItemBounds(true);
756         SetSelectedItemIndex(0);
757         SetFirstDrawnItemIndex(-1);
758
759         __tabItems.RemoveAll(true);
760
761         RemoveAllAccessibilityElement();
762
763         return E_SUCCESS;
764 }
765
766 bool
767 _Tab::ChangeItemAt(const int srcIndex, const int destIndex)
768 {
769         _TabItem* pItem = null;
770         pItem = GetItemAt(srcIndex);
771
772         __tabItems.InsertAt(*pItem, destIndex);
773
774         if (srcIndex > destIndex)
775         {
776                 __tabItems.RemoveAt((srcIndex + 1), false);
777         }
778         else
779         {
780                 __tabItems.RemoveAt(srcIndex, false);
781         }
782
783         return true;
784 }
785
786 int
787 _Tab::GetItemIndex(int actionId)
788 {
789         int itemCount = __tabItems.GetCount();
790
791         _TabItem* pItem = null;
792
793         for (int i = 0; i < itemCount; i++)
794         {
795                 pItem = GetItemAt(i);
796
797                 if ((pItem != null) && (actionId == pItem->GetActionId()))
798                 {
799                         return i;
800                 }
801         }
802
803         return -1;
804 }
805
806 bool
807 _Tab::CheckDuplicatedActionId(int actionId)
808 {
809         int itemIndex = GetItemIndex(actionId);
810
811         if (itemIndex >= 0)
812         {
813                 return true;
814         }
815
816         return false;
817 }
818
819 result
820 _Tab::LoadBitmap(void)
821 {
822         result r = E_SUCCESS;
823         Bitmap* pPressedItemBackgroundBitmap = null;
824         Bitmap* pItemBackgroundBitmap = null;
825         Bitmap* pDisabledBackgroundBitmap = null;
826         Bitmap* pSelectedItemBackgroundBitmap = null;
827         Bitmap* pPressedItemBackgroundEffectBitmap = null;
828         Bitmap* pHighlightedItemBackgroundBitmap = null;
829         Color pressedEffectColor;
830         GET_COLOR_CONFIG(TAB::ITEM_BG_EFFECT_PRESSED, pressedEffectColor);
831
832         r = GET_BITMAP_CONFIG_N(TAB::ITEM_BG_DISABLED, BITMAP_PIXEL_FORMAT_ARGB8888, pDisabledBackgroundBitmap);
833         SysTryLog(NID_UI_CTRL, r == E_SUCCESS, "Failed to locate disabled item background bitmap.");
834
835         if (pDisabledBackgroundBitmap)
836         {
837                 __pDisabledBackgroundBitmap = _BitmapImpl::GetColorReplacedBitmapN(*pDisabledBackgroundBitmap, Color::GetColor(COLOR_ID_MAGENTA), GetDisabledItemBackgroundColor());
838                 SysTryLog(NID_UI_CTRL, (__pDisabledBackgroundBitmap != null), "Failed to locate disabled item background bitmap.");
839
840                 delete pDisabledBackgroundBitmap;
841         }
842
843         r = GET_BITMAP_CONFIG_N(TAB::ITEM_BG_NORMAL, BITMAP_PIXEL_FORMAT_ARGB8888, pItemBackgroundBitmap);
844         SysTryLog(NID_UI_CTRL, r == E_SUCCESS, "Failed to locate item background bitmap.");
845
846         if (pItemBackgroundBitmap)
847         {
848                 __pBackgroundBitmap = _BitmapImpl::GetColorReplacedBitmapN(*pItemBackgroundBitmap, Color::GetColor(COLOR_ID_MAGENTA), GetItemBackgroundColor());
849                 SysTryLog(NID_UI_CTRL, (__pBackgroundBitmap != null), "Failed to locate item background bitmap.");
850
851                 delete pItemBackgroundBitmap;
852         }
853
854         r = GET_BITMAP_CONFIG_N(TAB::ITEM_BG_PRESSED, BITMAP_PIXEL_FORMAT_ARGB8888, pPressedItemBackgroundBitmap);
855         SysTryLog(NID_UI_CTRL, r == E_SUCCESS, "Failed to locate pressed item background bitmap.");
856
857         if (pPressedItemBackgroundBitmap)
858         {
859                 __pPressedItemBackgroundBitmap = _BitmapImpl::GetColorReplacedBitmapN(*pPressedItemBackgroundBitmap, Color::GetColor(COLOR_ID_MAGENTA), GetPressedItemBackgroundColor());
860                 SysTryLog(NID_UI_CTRL, (__pPressedItemBackgroundBitmap != null), "Failed to locate pressed item background bitmap.");
861
862                 delete pPressedItemBackgroundBitmap;
863         }
864
865         r = GET_BITMAP_CONFIG_N(TAB::ITEM_BG_SELECTED, BITMAP_PIXEL_FORMAT_ARGB8888, pSelectedItemBackgroundBitmap);
866         SysTryLog(NID_UI_CTRL, r == E_SUCCESS, "Failed to locate selected item background bitmap.");
867
868         if (pSelectedItemBackgroundBitmap)
869         {
870                 __pSelectedItemBackgroundBitmap = _BitmapImpl::GetColorReplacedBitmapN(*pSelectedItemBackgroundBitmap, Color::GetColor(COLOR_ID_MAGENTA), GetSelectedItemBackgroundColor());
871                 SysTryLog(NID_UI_CTRL, (__pSelectedItemBackgroundBitmap != null), "Failed to locate selected item background bitmap.");
872
873                 delete pSelectedItemBackgroundBitmap;
874         }
875
876         r = GET_BITMAP_CONFIG_N(TAB::ITEM_BG_EFFECT_PRESSED, BITMAP_PIXEL_FORMAT_ARGB8888, pPressedItemBackgroundEffectBitmap);
877         SysTryLog(NID_UI_CTRL, r == E_SUCCESS, "Failed to locate selected item background bitmap.");
878
879         if (pPressedItemBackgroundEffectBitmap)
880         {
881                 __pPressedItemBackgroundEffectBitmap = _BitmapImpl::GetColorReplacedBitmapN(*pPressedItemBackgroundEffectBitmap, Color::GetColor(COLOR_ID_MAGENTA), pressedEffectColor);
882                 SysTryLog(NID_UI_CTRL, (__pPressedItemBackgroundEffectBitmap != null), "Failed to locate selected item background bitmap.");
883
884                 delete pPressedItemBackgroundEffectBitmap;
885         }
886
887         r = GET_BITMAP_CONFIG_N(TAB::ITEM_BG_HIGHLIGHTED, BITMAP_PIXEL_FORMAT_ARGB8888, pHighlightedItemBackgroundBitmap);
888         SysTryLog(NID_UI_CTRL, r == E_SUCCESS, "Failed to locate highlighted item background bitmap.");
889
890         if (pHighlightedItemBackgroundBitmap)
891         {
892                 __pHighlightedItemBackgroundBitmap = _BitmapImpl::GetColorReplacedBitmapN(*pHighlightedItemBackgroundBitmap, Color::GetColor(COLOR_ID_MAGENTA), GetHighlightedItemBackgroundColor());
893                 SysTryLog(NID_UI_CTRL, (__pHighlightedItemBackgroundBitmap != null), "Failed to locate highlighted item background bitmap.");
894
895                 delete pHighlightedItemBackgroundBitmap;
896         }
897         return r;
898 }
899
900 result
901 _Tab::SetBadgeIcon(int actionId, const Bitmap* pBadgeIcon)
902 {
903         result r = E_SUCCESS;
904
905         if (actionId < _TAB_ACTION_ID_MIN || actionId > _TAB_ACTION_ID_MAX)
906         {
907                 SysLog(NID_UI_CTRL, "[E_OUT_OF_RANGE] The actionId (%d) is out of range.", actionId);
908                 return E_OUT_OF_RANGE;
909         }
910
911         int itemIndex = GetItemIndexFromActionId(actionId);
912
913         _TabItem *pItem = null;
914
915         if (itemIndex < 0)
916         {
917                 SysLog(NID_UI_CTRL, "[E_INVALID_ARG] Invalid argument(s) is used. The specified actionId is not found.");
918                 return E_INVALID_ARG;
919         }
920
921         pItem = dynamic_cast<_TabItem*>(__tabItems.GetAt(itemIndex));
922
923         if (pItem != null)
924         {
925                 pItem->SetBadgeIcon(*pBadgeIcon);
926
927                 r = __tabItems.SetAt(*pItem, itemIndex, false);
928         }
929
930         return r;
931 }
932
933 int
934 _Tab::GetItemCount(void) const
935 {
936         return __tabItems.GetCount();
937 }
938
939 int
940 _Tab::GetItemIndexFromActionId(int actionId) const
941 {
942         if (actionId < _TAB_ACTION_ID_MIN || actionId > _TAB_ACTION_ID_MAX)
943         {
944                 SysLog(NID_UI_CTRL, "[E_OUT_OF_RANGE] The actionId (%d) is out of range.", actionId);
945                 return -1;
946         }
947
948         int index = 0;
949         int itemCount = __tabItems.GetCount();
950
951         for (index = 0; index < itemCount; index++)
952         {
953                 const _TabItem *pItem = dynamic_cast<const _TabItem*>(__tabItems.GetAt(index));
954
955                 if (pItem != null)
956                 {
957                         if (pItem->GetActionId() == actionId)
958                         {
959                                 return index;
960                         }
961                 }
962         }
963
964         return -1;
965 }
966
967 int
968 _Tab::GetItemActionIdAt(int index) const
969 {
970         if (__tabItems.GetAt(index) == null )
971         {
972                 return -1;
973         }
974
975         const _TabItem *pItem = dynamic_cast<const _TabItem*>(__tabItems.GetAt(index));
976         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);
977
978         return pItem->GetActionId();
979 }
980
981 _TabItem*
982 _Tab::GetItemAt(int index)
983 {
984         if (__tabItems.GetAt(index) == null )
985         {
986                 return null;
987         }
988
989         _TabItem *pItem = static_cast<_TabItem*>(__tabItems.GetAt(index));
990         result r = GetLastResult();
991         SysTryReturn(NID_UI_CTRL, pItem != null, null, r, "[%s] Propagating.", GetErrorMessage(r));
992
993         return pItem;
994 }
995
996 void
997 _Tab::SetSelectedItemIndex(int index)
998 {
999         __pTabPresenter->SetSelectedItemIndex(index);
1000         return;
1001 }
1002
1003 int
1004 _Tab::GetSelectedItemIndex(void) const
1005 {
1006         return __pTabPresenter->GetSelectedItemIndex();
1007 }
1008
1009 void
1010 _Tab::SetFirstDrawnItemIndex(int index)
1011 {
1012         __pTabPresenter->SetFirstDrawnItemIndex(index);
1013         return;
1014 }
1015
1016 int
1017 _Tab::GetFirstDrawnItemIndex(void) const
1018 {
1019         return __pTabPresenter->GetFirstDrawnItemIndex();
1020 }
1021
1022 void
1023 _Tab::SetEditModeEnabled(bool isEnabled)
1024 {
1025         return __pTabPresenter->SetEditModeEnabled(isEnabled);
1026 }
1027
1028 bool
1029 _Tab::IsEditModeEnabled(void) const
1030 {
1031         return __pTabPresenter->IsEditModeEnabled();
1032 }
1033
1034 bool
1035 _Tab::IsInFocusMode(void) const
1036 {
1037         return __isInFocusMode;
1038 }
1039
1040 result
1041 _Tab::SetBackgroundBitmap(const Bitmap& bitmap)
1042 {
1043         ClearLastResult();
1044
1045         Tizen::Graphics::Bitmap* pBitmap = _BitmapImpl::CloneN(bitmap);
1046
1047         SysTryReturn(NID_UI_CTRL, (pBitmap), GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1048
1049         if (__pBackgroundBitmap)
1050         {
1051                 delete __pBackgroundBitmap;
1052                 __pBackgroundBitmap = null;
1053         }
1054
1055         __pBackgroundBitmap = pBitmap;
1056
1057         if (__pDisabledBackgroundBitmap)
1058         {
1059                 delete __pDisabledBackgroundBitmap;
1060                 __pDisabledBackgroundBitmap = null;
1061         }
1062
1063         return E_SUCCESS;
1064 }
1065
1066 Bitmap*
1067 _Tab::GetBackgroundBitmap(void) const
1068 {
1069         return __pBackgroundBitmap;
1070 }
1071
1072 Bitmap*
1073 _Tab::GetDisabledBackgroundBitmap(void) const
1074 {
1075         return __pDisabledBackgroundBitmap;
1076 }
1077
1078 Bitmap*
1079 _Tab::GetPressedItemBackgroundBitmap(void) const
1080 {
1081         return __pPressedItemBackgroundBitmap;
1082 }
1083
1084 Bitmap*
1085 _Tab::GetPressedItemBackgroundEffectBitmap(void) const
1086 {
1087         return __pPressedItemBackgroundEffectBitmap;
1088 }
1089
1090 result
1091 _Tab::SetSelectedItemBackgroundBitmap(const Bitmap& bitmap)
1092 {
1093         ClearLastResult();
1094
1095         Tizen::Graphics::Bitmap* pBitmap = _BitmapImpl::CloneN(bitmap);
1096
1097         SysTryReturn(NID_UI_CTRL, (pBitmap), GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1098
1099         if (__pSelectedItemBackgroundBitmap)
1100         {
1101                 delete __pSelectedItemBackgroundBitmap;
1102                 __pSelectedItemBackgroundBitmap = null;
1103         }
1104         __pSelectedItemBackgroundBitmap = pBitmap;
1105         __pTabPresenter->FreeHorizontalLineBitmap();
1106
1107         return E_SUCCESS;
1108 }
1109
1110
1111 Bitmap*
1112 _Tab::GetSelectedItemBackgroundBitmap(void) const
1113 {
1114         return __pSelectedItemBackgroundBitmap;
1115 }
1116
1117 result
1118 _Tab::SetHighlightedItemBackgroundBitmap(const Bitmap& bitmap)
1119 {
1120         ClearLastResult();
1121
1122         Tizen::Graphics::Bitmap* pBitmap = _BitmapImpl::CloneN(bitmap);
1123
1124         SysTryReturn(NID_UI_CTRL, (pBitmap), GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1125
1126         if (__pHighlightedItemBackgroundBitmap)
1127         {
1128                 delete __pHighlightedItemBackgroundBitmap;
1129                 __pHighlightedItemBackgroundBitmap = null;
1130         }
1131
1132         __pHighlightedItemBackgroundBitmap = pBitmap;
1133
1134         return E_SUCCESS;
1135 }
1136
1137 Bitmap*
1138 _Tab::GetHighlightedItemBackgroundBitmap(void) const
1139 {
1140         return __pHighlightedItemBackgroundBitmap;
1141 }
1142
1143 void
1144 _Tab::SetItemBackgroundColor(Color color)
1145 {
1146         __itemBgColor[_TAB_STATUS_NORMAL] = color;
1147         return;
1148 }
1149
1150 Color
1151 _Tab::GetItemBackgroundColor(void) const
1152 {
1153         return __itemBgColor[_TAB_STATUS_NORMAL];
1154 }
1155
1156 Color
1157 _Tab::GetPressedItemBackgroundColor(void) const
1158 {
1159         return __itemBgColor[_TAB_STATUS_PRESSED];
1160 }
1161
1162 void
1163 _Tab::SetSelectedItemBackgroundColor(Color color)
1164 {
1165         __itemBgColor[_TAB_STATUS_SELECTED] = color;
1166         return;
1167 }
1168
1169 Color
1170 _Tab::GetSelectedItemBackgroundColor(void) const
1171 {
1172         return __itemBgColor[_TAB_STATUS_SELECTED];
1173 }
1174
1175 void
1176 _Tab::SetHighlightedItemBackgroundColor(Color color)
1177 {
1178         __itemBgColor[_TAB_STATUS_HIGHLIGHTED] = color;
1179         return;
1180 }
1181
1182 Color
1183 _Tab::GetHighlightedItemBackgroundColor(void) const
1184 {
1185         return __itemBgColor[_TAB_STATUS_HIGHLIGHTED];
1186 }
1187
1188 Color
1189 _Tab::GetDisabledItemBackgroundColor(void) const
1190 {
1191         return __itemBgColor[_TAB_STATUS_DISABLED];
1192 }
1193
1194 void
1195 _Tab::SetTextColor(const Color& textColor)
1196 {
1197         __itemTextColor[_TAB_STATUS_NORMAL] = textColor;
1198         return;
1199 }
1200
1201 Color
1202 _Tab::GetTextColor(void) const
1203 {
1204         return  __itemTextColor[_TAB_STATUS_NORMAL];
1205 }
1206
1207 Color
1208 _Tab::GetDisabledTextColor(void) const
1209 {
1210         return  __itemTextColor[_TAB_STATUS_DISABLED];
1211 }
1212
1213 void
1214 _Tab::SetPressedTextColor(const Color& textColor)
1215 {
1216         __itemTextColor[_TAB_STATUS_PRESSED] = textColor;
1217         return;
1218 }
1219
1220 Color
1221 _Tab::GetPressedTextColor(void) const
1222 {
1223         return __itemTextColor[_TAB_STATUS_PRESSED];
1224 }
1225
1226 void
1227 _Tab::SetSelectedTextColor(const Color& textColor)
1228 {
1229         __itemTextColor[_TAB_STATUS_SELECTED] = textColor;
1230         return;
1231 }
1232
1233 Color
1234 _Tab::GetSelectedTextColor(void) const
1235 {
1236         return __itemTextColor[_TAB_STATUS_SELECTED];
1237 }
1238
1239 void
1240 _Tab::SetHighlightedTextColor(const Color& color)
1241 {
1242         __itemTextColor[_TAB_STATUS_HIGHLIGHTED] = color;
1243         return;
1244 }
1245
1246 Color
1247 _Tab::GetHighlightedTextColor(void) const
1248 {
1249         return __itemTextColor[_TAB_STATUS_HIGHLIGHTED];
1250 }
1251
1252 void
1253 _Tab::SetStyle(int style)
1254 {
1255         __style = style;
1256         return;
1257 }
1258
1259 _TabStyle
1260 _Tab::GetStyle(void) const
1261 {
1262         return _TabStyle(__style);
1263 }
1264
1265 int
1266 _Tab::GetCurrentHighlightedItemIndex(void) const
1267 {
1268         return __currentHighlightedItemIndex;
1269 }
1270
1271 void
1272 _Tab::AddActionEventListener(const _IActionEventListener& listener)
1273 {
1274         ClearLastResult();
1275
1276         if (__pActionEvent == null)
1277         {
1278                 __pActionEvent = _ActionEvent::CreateInstanceN(*this);
1279
1280                 if (__pActionEvent == null || IsFailed(GetLastResult()))
1281                 {
1282                         SetLastResult(E_SYSTEM);
1283                         delete __pActionEvent;
1284                         return;
1285                 }
1286         }
1287         __pActionEvent->AddListener(listener);
1288         return;
1289 }
1290
1291 void
1292 _Tab::RemoveActionEventListener(const _IActionEventListener& listener)
1293 {
1294         ClearLastResult();
1295
1296         __pActionEvent->RemoveListener(listener);
1297         return;
1298 }
1299
1300 bool
1301 _Tab::OnTouchPressed(const _Control& source, const _TouchInfo& touchinfo)
1302 {
1303         if (this != &source)
1304         {
1305                 return true;
1306         }
1307         return __pTabPresenter->OnTouchPressed(source, touchinfo);
1308 }
1309
1310 bool
1311 _Tab::OnTouchReleased(const _Control& source, const _TouchInfo& touchinfo)
1312 {
1313         if (this != &source)
1314         {
1315                 return true;
1316         }
1317
1318         __pTabPresenter->OnTouchReleased(source, touchinfo);
1319
1320         int index = __pTabPresenter->GetItemIndexFromPosition(touchinfo.GetCurrentPosition());
1321
1322         _TabItem* pItem = __pTabPresenter->GetItemAt(index);
1323
1324         if (pItem == null)
1325         {
1326                 return true;
1327         }
1328
1329         if (__pActionEvent)
1330         {
1331                 IEventArg* pEventArg = _ActionEvent::CreateActionEventArgN(pItem->GetActionId());
1332                 SysTryReturn(NID_UI_CTRL, pEventArg, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1333
1334                 __pActionEvent->Fire(*pEventArg);
1335         }
1336
1337         return true;
1338 }
1339
1340 bool
1341 _Tab::OnTouchMoved(const _Control& source, const _TouchInfo& touchinfo)
1342 {
1343         if (this != &source)
1344         {
1345                 return true;
1346         }
1347
1348         return __pTabPresenter->OnTouchMoved(source, touchinfo);
1349 }
1350
1351 bool
1352 _Tab::OnLongPressGestureDetected(_TouchLongPressGestureDetector& gesture)
1353 {
1354         return __pTabPresenter->OnLongPressGestureDetected();
1355 }
1356
1357 bool
1358 _Tab::OnLongPressGestureCanceled(_TouchLongPressGestureDetector& gesture)
1359 {
1360         return false;
1361 }
1362
1363 bool
1364 _Tab::OnFlickGestureDetected(_TouchFlickGestureDetector& gesture)
1365 {
1366
1367         return __pTabPresenter->OnFlickGestureDetected(gesture);
1368 }
1369
1370 bool
1371 _Tab::OnFlickGestureCanceled(_TouchFlickGestureDetector& gesture)
1372 {
1373         return false;
1374 }
1375
1376 void
1377 _Tab::OnDraw(void)
1378 {
1379         ClearLastResult();
1380         __pTabPresenter->Draw();
1381         return;
1382
1383 }
1384
1385 void
1386 _Tab::OnBoundsChanged(void)
1387 {
1388         __pTabPresenter->OnBoundsChanged();
1389 }
1390
1391 result
1392 _Tab::OnAttachedToMainTree(void)
1393 {
1394         _AccessibilityContainer* pContainer = null;
1395
1396         pContainer = GetAccessibilityContainer();
1397
1398         if (pContainer)
1399         {
1400                 pContainer->Activate(true);
1401                 pContainer->AddListener(*this);
1402         }
1403
1404         return E_SUCCESS;
1405 }
1406
1407 void
1408 _Tab::OnFontChanged(Font* pFont)
1409 {
1410     __pTabPresenter->OnFontChanged(pFont);
1411     return;
1412 }
1413
1414 void
1415 _Tab::OnFontInfoRequested(unsigned long& style, float& size)
1416 {
1417     __pTabPresenter->OnFontInfoRequested(style, size);
1418     return;
1419 }
1420
1421 bool
1422 _Tab::OnKeyPressed(const _Control& source, const _KeyInfo& keyInfo)
1423 {
1424         if (this != &source)
1425         {
1426                 return false;
1427         }
1428         _KeyCode keyCode = keyInfo.GetKeyCode();
1429         int itemCount = __pTabPresenter->GetItemCount();
1430         if (itemCount == 0 || __isInFocusMode == false)
1431         {
1432                 return false;
1433         }
1434
1435         if (keyCode == _KEY_RIGHT)
1436         {
1437                 if (__currentHighlightedItemIndex < (itemCount - 1))
1438                 {
1439                         if (__pTabPresenter->GetItemStatus(__currentHighlightedItemIndex) != _TABITEM_STATUS_SELECTED)
1440                         {
1441                                 __pTabPresenter->SetItemStatus(__currentHighlightedItemIndex, _TABITEM_STATUS_NORMAL);
1442                         }
1443
1444                         __currentHighlightedItemIndex++;
1445
1446                         if (__pTabPresenter->GetItemStatus(__currentHighlightedItemIndex) != _TABITEM_STATUS_SELECTED)
1447                         {
1448                                 __pTabPresenter->SetItemStatus(__currentHighlightedItemIndex, _TABITEM_STATUS_HIGHLIGHTED);
1449                         }
1450                         __pTabPresenter->ShiftToFocusedItem(__currentHighlightedItemIndex, _FOCUS_DIRECTION_MOVE_RIGHT);
1451                 }
1452                 return true;
1453         }
1454
1455         if (keyCode == _KEY_LEFT)
1456         {
1457                 if (__currentHighlightedItemIndex >= -1)
1458                 {
1459                         if (__pTabPresenter->GetItemStatus(__currentHighlightedItemIndex) != _TABITEM_STATUS_SELECTED)
1460                         {
1461                                 __pTabPresenter->SetItemStatus(__currentHighlightedItemIndex, _TABITEM_STATUS_NORMAL);
1462                         }
1463                         if (__currentHighlightedItemIndex == -1)
1464                         {
1465                                 __currentHighlightedItemIndex = 0;
1466                         }
1467                         if (__currentHighlightedItemIndex > 0)
1468                         {
1469                                 __currentHighlightedItemIndex--;
1470                         }
1471                         if (__pTabPresenter->GetItemStatus(__currentHighlightedItemIndex) != _TABITEM_STATUS_SELECTED)
1472                         {
1473                                 __pTabPresenter->SetItemStatus(__currentHighlightedItemIndex, _TABITEM_STATUS_HIGHLIGHTED);
1474                         }
1475                         __pTabPresenter->ShiftToFocusedItem(__currentHighlightedItemIndex, _FOCUS_DIRECTION_MOVE_LEFT);
1476                 }
1477                 return true;
1478         }
1479
1480         if (keyCode == _KEY_ENTER && __currentHighlightedItemIndex != -1)
1481         {
1482                 __pTabPresenter->SetItemStatus(__currentHighlightedItemIndex, _TABITEM_STATUS_SELECTED);
1483                 __pTabPresenter->SetSelectedItemIndex(__currentHighlightedItemIndex);
1484                 Invalidate();
1485                 return true;
1486         }
1487         return false;
1488 }
1489
1490 bool
1491 _Tab::OnKeyReleased(const _Control& source, const _KeyInfo& keyInfo)
1492 {
1493         return false;
1494 }
1495
1496 void
1497 _Tab::OnDrawFocus(void)
1498 {
1499         if (__pTabPresenter->GetItemCount() > 0)
1500         {
1501                 __currentHighlightedItemIndex = 0;
1502         }
1503         else
1504         {
1505                 __currentHighlightedItemIndex = -1;
1506         }
1507         if (__pTabPresenter->GetItemStatus(__currentHighlightedItemIndex) != _TABITEM_STATUS_SELECTED)
1508         {
1509                 __pTabPresenter->SetItemStatus(__currentHighlightedItemIndex, _TABITEM_STATUS_HIGHLIGHTED);
1510         }
1511         __pTabPresenter->ShiftToFocusedItem(__currentHighlightedItemIndex, _FOCUS_DIRECTION_MOVE_LEFT);
1512         __isInFocusMode = true;
1513         return;
1514 }
1515
1516 void
1517 _Tab::OnFocusModeStateChanged(void)
1518 {
1519         if (__pTabPresenter->GetItemStatus(__currentHighlightedItemIndex) == _TABITEM_STATUS_HIGHLIGHTED)
1520         {
1521                 __pTabPresenter->SetItemStatus(__currentHighlightedItemIndex, _TABITEM_STATUS_NORMAL);
1522         }
1523         __currentHighlightedItemIndex = -1;
1524         __isInFocusMode = false;
1525         Invalidate();
1526 }
1527
1528 void
1529 _Tab::AddAccessibilityElement(const FloatRectangle& itemBounds, const String& itemText, _TabItemStatus status)
1530 {
1531         _AccessibilityContainer* pContainer = GetAccessibilityContainer();
1532         SysTryReturnVoidResult(NID_UI_CTRL, (pContainer != null), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1533
1534         _AccessibilityElement* pAccessibilityElement = new (std::nothrow) _AccessibilityElement(true);
1535         SysTryReturnVoidResult(NID_UI_CTRL, pAccessibilityElement != null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
1536
1537         pAccessibilityElement->SetTrait(L"Tab");
1538         pAccessibilityElement->SetHint(L"Double tap to move to contents");
1539
1540         if (GetStyle() != _TAB_STYLE_ICON)
1541         {
1542                 pAccessibilityElement->SetLabel(itemText);
1543         }
1544
1545         if (status == _TABITEM_STATUS_SELECTED)
1546         {
1547                 pAccessibilityElement->SetStatus("Selected");
1548                 pAccessibilityElement->SetHintDisabled(true);
1549         }
1550         else
1551         {
1552                 pAccessibilityElement->SetStatus("");
1553                 pAccessibilityElement->SetHintDisabled(false);
1554         }
1555
1556         pContainer->AddElement(*pAccessibilityElement);
1557         __accessibilityElements.Add(pAccessibilityElement);
1558
1559         return;
1560 }
1561
1562 void
1563 _Tab::InsertAccessibilityElementAt(int index, const FloatRectangle& itemBounds, const String& itemText, _TabItemStatus status)
1564 {
1565         _AccessibilityContainer* pContainer = GetAccessibilityContainer();
1566         SysTryReturnVoidResult(NID_UI_CTRL, (pContainer != null), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1567
1568         _AccessibilityElement* pAccessibilityElement = new (std::nothrow) _AccessibilityElement(true);
1569         SysTryReturnVoidResult(NID_UI_CTRL, pAccessibilityElement != null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
1570
1571         pAccessibilityElement->SetTrait(L"Tab");
1572         pAccessibilityElement->SetHint(L"Double tap to move to contents");
1573
1574         if (GetStyle() != _TAB_STYLE_ICON)
1575         {
1576                 pAccessibilityElement->SetLabel(itemText);
1577         }
1578
1579         if (status == _TABITEM_STATUS_SELECTED)
1580         {
1581                 pAccessibilityElement->SetStatus("Selected");
1582                 pAccessibilityElement->SetHintDisabled(true);
1583         }
1584         else
1585         {
1586                 pAccessibilityElement->SetStatus("");
1587                 pAccessibilityElement->SetHintDisabled(false);
1588         }
1589
1590         pContainer->InsertElement(*pAccessibilityElement, index);
1591         __accessibilityElements.InsertAt(pAccessibilityElement, index);
1592
1593         return;
1594 }
1595
1596 void
1597 _Tab::RemoveAccessibilityElementAt(int index)
1598 {
1599         _AccessibilityElement* pAccessibilityElement = null;
1600         _AccessibilityContainer* pContainer = GetAccessibilityContainer();
1601         SysTryReturnVoidResult(NID_UI_CTRL, (pContainer != null), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1602
1603         if ((__accessibilityElements.GetAt(index, pAccessibilityElement)) == E_SUCCESS)
1604         {
1605                 __accessibilityElements.RemoveAt(index);
1606                 pContainer->RemoveElement(*pAccessibilityElement);
1607         }
1608
1609         return;
1610 }
1611
1612 void
1613 _Tab::RemoveAllAccessibilityElement(void)
1614 {
1615         _AccessibilityElement* pAccessibilityElement = null;
1616         _AccessibilityContainer* pContainer = GetAccessibilityContainer();
1617         SysTryReturnVoidResult(NID_UI_CTRL, (pContainer != null), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1618
1619         while (__accessibilityElements.GetCount() > 0)
1620         {
1621                 if ((__accessibilityElements.GetAt(0, pAccessibilityElement)) == E_SUCCESS)
1622                 {
1623                         __accessibilityElements.RemoveAt(0);
1624                         pContainer->RemoveElement(*pAccessibilityElement);
1625                 }
1626         }
1627
1628         return;
1629 }
1630
1631 void
1632 _Tab::UpdateAccessibilityElement(void)
1633 {
1634         _TabItemStatus itemStatus = _TABITEM_STATUS_NORMAL;
1635         _TabItem* pItem = null;
1636         _AccessibilityElement* pAccessibilityElement = null;
1637         _AccessibilityContainer* pContainer = GetAccessibilityContainer();
1638         SysTryReturnVoidResult(NID_UI_CTRL, (pContainer != null), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1639
1640         int count = __accessibilityElements.GetCount();
1641
1642         FloatRectangle bounds(0.0f, 0.0f, 0.0f, 0.0f);
1643
1644         for (int i = 0; i < count; i++)
1645         {
1646                 if ((__accessibilityElements.GetAt(i, pAccessibilityElement)) == E_SUCCESS)
1647                 {
1648                         pItem = GetItemAt(i);
1649                         if (pItem != null)
1650                         {
1651                                 bounds = pItem->GetItemBounds();
1652                                 itemStatus = pItem->GetStatus();
1653                         }
1654
1655                         if (pAccessibilityElement)
1656                         {
1657                                 pAccessibilityElement->SetBounds(bounds);
1658
1659                                 if (itemStatus == _TABITEM_STATUS_SELECTED)
1660                                 {
1661                                         pAccessibilityElement->SetStatus("Selected");
1662                                         pAccessibilityElement->SetHintDisabled(true);
1663                                 }
1664                                 else
1665                                 {
1666                                         pAccessibilityElement->SetStatus("");
1667                                         pAccessibilityElement->SetHintDisabled(false);
1668                                 }
1669                         }
1670                 }
1671         }
1672
1673         return;
1674 }
1675
1676 void
1677 _Tab::UpdateAccessibilityLabel(int index, const String& text)
1678 {
1679         _AccessibilityElement* pAccessibilityElement = null;
1680         _AccessibilityContainer* pContainer = GetAccessibilityContainer();
1681         SysTryReturnVoidResult(NID_UI_CTRL, (pContainer != null), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1682
1683         if ((__accessibilityElements.GetAt(index, pAccessibilityElement)) == E_SUCCESS)
1684         {
1685                 if (pAccessibilityElement)
1686                 {
1687                         pAccessibilityElement->SetLabel(text);
1688                 }
1689         }
1690
1691         return;
1692 }
1693
1694 void
1695 _Tab::OnChangeLayout(_ControlOrientation orientation)
1696 {
1697         __pTabPresenter->OnChangeLayout(orientation);
1698
1699         return;
1700 }
1701
1702 bool
1703 _Tab::OnAccessibilityFocusMovedNext(const _AccessibilityContainer& control, const _AccessibilityElement& element)
1704 {
1705         return false;
1706 }
1707
1708 bool
1709 _Tab::OnAccessibilityFocusMovedPrevious(const _AccessibilityContainer& control, const _AccessibilityElement& element)
1710 {
1711         return false;
1712 }
1713
1714 bool
1715 _Tab::OnAccessibilityReadingElement(const _AccessibilityContainer& control, const _AccessibilityElement& element)
1716 {
1717         return false;
1718 }
1719 bool
1720 _Tab::OnAccessibilityReadElement(const _AccessibilityContainer& control, const _AccessibilityElement& element)
1721 {
1722         return false;
1723 }
1724
1725 bool
1726 _Tab::OnAccessibilityFocusIn(const _AccessibilityContainer& control, const _AccessibilityElement& element)
1727 {
1728         FloatRectangle bounds = element.GetBounds();
1729
1730         if (bounds.x < 0)
1731         {
1732                 if (bounds.x == -bounds.width)
1733                 {
1734                         __pTabPresenter->MovePrevious();
1735                 }
1736                 else
1737                 {
1738                         __pTabPresenter->MoveToFirst();
1739                 }
1740         }
1741         else if (bounds.x + bounds.width > GetBounds().width)
1742         {
1743                 if (bounds.x  == GetBounds().width)
1744                 {
1745                         __pTabPresenter->MoveNext();
1746                 }
1747                 else
1748                 {
1749                         __pTabPresenter->MoveToLast(bounds.x);
1750                 }
1751         }
1752
1753         return true;
1754 }
1755
1756 bool
1757 _Tab::OnAccessibilityFocusOut(const _AccessibilityContainer& control, const _AccessibilityElement& element)
1758 {
1759         return false;
1760 }
1761
1762 bool
1763 _Tab::OnAccessibilityActionPerformed(const _AccessibilityContainer& control, const _AccessibilityElement& element)
1764 {
1765         return false;
1766 }
1767
1768 bool
1769 _Tab::OnAccessibilityValueIncreased(const _AccessibilityContainer& control, const _AccessibilityElement& element)
1770 {
1771         return false;
1772 }
1773
1774 bool
1775 _Tab::OnAccessibilityValueDecreased(const _AccessibilityContainer& control, const _AccessibilityElement& element)
1776 {
1777         return false;
1778 }
1779
1780 }}} // Tizen::Ui::Controls
1781