Tizen 2.1 base
[framework/osp/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 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
8 //
9 //     http://floralicense.org/license/
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  * @file                FUiCtrl_Tab.cpp
19  * @brief               This is the implementation file for the _Tab class.
20  */
21
22 #include <FBaseErrorDefine.h>
23 #include <FBaseSysLog.h>
24 #include <FGrp_BitmapImpl.h>
25 #include "FUi_ResourceManager.h"
26 #include "FUi_UiTouchEvent.h"
27 #include "FUi_AccessibilityContainer.h"
28 #include "FUi_AccessibilityElement.h"
29 #include "FUi_TouchLongPressGestureDetector.h"
30 #include "FUiCtrl_Tab.h"
31
32 using namespace Tizen::Base;
33 using namespace Tizen::Graphics;
34 using namespace Tizen::Base::Runtime;
35
36 namespace Tizen { namespace Ui { namespace Controls {
37
38 _Tab::_Tab(void)
39         : __pTabPresenter(null)
40         , __style(_TAB_STYLE_TEXT)
41         , __tabStatus(_TAB_STATUS_NORMAL)
42         , __pActionEvent(null)
43         , __pGestureLongPress(null)
44         , __pFlickGesture(null)
45         , __pBackgroundBitmap(null)
46         , __pPressedItemBackgroundBitmap(null)
47         , __pSelectedItemBackgroundBitmap(null)
48         , __pHighlightedItemBackgroundBitmap(null)
49 {
50         ClearLastResult();
51         result r = E_SUCCESS;
52
53         __tabItems.Construct();
54
55         GET_COLOR_CONFIG(TAB::ITEM_BG_NORMAL, __itemBgColor[_TAB_STATUS_NORMAL]);
56         GET_COLOR_CONFIG(TAB::ITEM_BG_PRESSED, __itemBgColor[_TAB_STATUS_PRESSED]);
57         GET_COLOR_CONFIG(TAB::ITEM_BG_SELECTED, __itemBgColor[_TAB_STATUS_SELECTED]);
58         GET_COLOR_CONFIG(TAB::ITEM_BG_HIGHLIGHTED, __itemBgColor[_TAB_STATUS_HIGHLIGHTED]);
59         GET_COLOR_CONFIG(TAB::ITEM_BG_DISABLED, __itemBgColor[_TAB_STATUS_DISABLED]);
60
61         GET_COLOR_CONFIG(TAB::ITEM_TEXT_NORMAL, __itemTextColor[_TAB_STATUS_NORMAL]);
62         GET_COLOR_CONFIG(TAB::ITEM_TEXT_PRESSED, __itemTextColor[_TAB_STATUS_PRESSED]);
63         GET_COLOR_CONFIG(TAB::ITEM_TEXT_SELECTED, __itemTextColor[_TAB_STATUS_SELECTED]);
64         GET_COLOR_CONFIG(TAB::ITEM_TEXT_HIGHLIGHTED, __itemTextColor[_TAB_STATUS_HIGHLIGHTED]);
65         GET_COLOR_CONFIG(TAB::ITEM_TEXT_DISABLED, __itemTextColor[_TAB_STATUS_DISABLED]);
66
67         r = LoadBitmap();
68         SysTryReturnVoidResult(NID_UI_CTRL, r == E_SUCCESS, E_SYSTEM, "[E_SYSTEM] A system error has occurred. Failed to load bitmap.");
69
70         _Control::SetResizable(false);
71         _Control::SetMovable(false);
72
73         _TabPresenter* pPresenter = new (std::nothrow) _TabPresenter;
74         SysTryReturnVoidResult(NID_UI_CTRL, pPresenter, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
75
76         r = SetPresenter(*pPresenter);
77         SysTryReturnVoidResult(NID_UI_CTRL, r == E_SUCCESS, E_SYSTEM, "[E_SYSTEM] A system error has occurred. The _TabPresenter instance could not be set.");
78
79         r = pPresenter->Construct(*this);
80         SysTryReturnVoidResult(NID_UI_CTRL, r == E_SUCCESS, E_SYSTEM, "[E_SYSTEM] A system error has occurred. The _TabPresenter instance construct failed.");
81
82 }
83
84 _Tab::~_Tab(void)
85 {
86         delete __pTabPresenter;
87         __pTabPresenter = null;
88
89         if (__pActionEvent)
90         {
91                 delete __pActionEvent;
92                 __pActionEvent = null;
93         }
94
95         __tabItems.RemoveAll(true);
96
97         if (__pFlickGesture != null)
98         {
99                 __pFlickGesture->RemoveGestureListener(*this);
100                 RemoveGestureDetector(*__pFlickGesture);
101
102                 delete __pFlickGesture;
103                 __pFlickGesture = null;
104         }
105
106         if (__pGestureLongPress != null)
107         {
108                 __pGestureLongPress->RemoveGestureListener(*this);
109                 RemoveGestureDetector(*__pGestureLongPress);
110
111                 delete __pGestureLongPress;
112                 __pGestureLongPress = null;
113         }
114
115         if (__pBackgroundBitmap)
116         {
117                 delete __pBackgroundBitmap;
118                 __pBackgroundBitmap = null;
119         }
120
121         if (__pPressedItemBackgroundBitmap)
122         {
123                 delete __pPressedItemBackgroundBitmap;
124                 __pPressedItemBackgroundBitmap = null;
125         }
126
127         if (__pSelectedItemBackgroundBitmap)
128         {
129                 delete __pSelectedItemBackgroundBitmap;
130                 __pSelectedItemBackgroundBitmap = null;
131         }
132
133         if (__pHighlightedItemBackgroundBitmap)
134         {
135                 delete __pHighlightedItemBackgroundBitmap;
136                 __pHighlightedItemBackgroundBitmap = null;
137         }
138
139         RemoveAllAccessibilityElement();
140 }
141
142 _Tab*
143 _Tab::CreateTabN(void)
144 {
145         result r = E_SUCCESS;
146
147         _Tab* pTab = new (std::nothrow) _Tab;
148         SysTryReturn(NID_UI_CTRL, pTab, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
149
150         if (IsFailed(GetLastResult()))
151         {
152                 goto CATCH;
153         }
154
155         pTab->AcquireHandle();
156
157         pTab->__pGestureLongPress = new (std::nothrow) _TouchLongPressGestureDetector;
158         SysTryCatch(NID_UI_CTRL, pTab->__pGestureLongPress, , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
159
160         pTab->__pGestureLongPress->SetDuration(300);
161         pTab->AddGestureDetector(*(pTab->__pGestureLongPress));
162         r = pTab->__pGestureLongPress->AddGestureListener(*pTab);
163         SysTryCatch(NID_UI_CTRL, (r == E_SUCCESS), , r = E_SYSTEM, "[E_SYSTEM] A system error has occurred. The _ITouchGestureEventListener instance could not be set.");
164
165         pTab->__pFlickGesture = new (std::nothrow) _TouchFlickGestureDetector;
166         SysTryCatch(NID_UI_CTRL, pTab->__pFlickGesture, , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
167
168         r = pTab->AddGestureDetector(*(pTab->__pFlickGesture));
169         SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating", GetErrorMessage(r));
170
171         r = pTab->__pFlickGesture->AddGestureListener(*pTab);
172         SysTryCatch(NID_UI_CTRL, (r == E_SUCCESS), , r = E_SYSTEM, "[E_SYSTEM] A system error has occurred. The _ITouchGestureEventListener instance could not be set.");
173
174         return pTab;
175
176 CATCH:
177         if (pTab->__pGestureLongPress != null)
178         {
179                 pTab->__pGestureLongPress->RemoveGestureListener(*pTab);
180                 pTab->RemoveGestureDetector(*pTab->__pGestureLongPress);
181
182                 delete pTab->__pGestureLongPress;
183                 pTab->__pGestureLongPress = null;
184         }
185         if (pTab->__pFlickGesture != null)
186         {
187                 pTab->__pFlickGesture->RemoveGestureListener(*pTab);
188                 pTab->RemoveGestureDetector(*pTab->__pFlickGesture);
189
190                 delete pTab->__pFlickGesture;
191                 pTab->__pFlickGesture = null;
192         }
193
194         delete pTab;
195         return null;
196 }
197
198 result
199 _Tab::SetPresenter(const _TabPresenter& tabPresenter)
200 {
201         ClearLastResult();
202         __pTabPresenter = const_cast<_TabPresenter*>(&tabPresenter);
203
204         return E_SUCCESS;
205 }
206
207 result
208 _Tab::AddItem(const Bitmap& icon, const String& text, int actionId)
209 {
210         if (actionId < _TAB_ACTION_ID_MIN || actionId > _TAB_ACTION_ID_MAX)
211         {
212                 SysLog(NID_UI_CTRL, "[E_OUT_OF_RANGE] The actionId (%d) is out of range.", actionId);
213                 return E_OUT_OF_RANGE;
214         }
215
216         if (!((__style == _TAB_STYLE_TEXT) || (__style == _TAB_STYLE_ICON_TEXT)))
217         {
218                 return E_SYSTEM;
219         }
220
221         __style = _TAB_STYLE_ICON_TEXT;
222
223         bool isDuplicate = CheckDuplicatedActionId(actionId);
224         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);
225
226         int itemCount = __tabItems.GetCount();
227
228         SysTryReturnResult(NID_UI_CTRL, itemCount < _TAB_ITEM_MAXCOUNT, E_SYSTEM, "A system error has occurred. The tab has maximum number of items.");
229
230         _TabItem *pItem = new (std::nothrow) _TabItem;
231         SysTryReturnResult(NID_UI_CTRL, pItem != null, E_OUT_OF_MEMORY, "Memory allocation failed.");
232
233         pItem->SetIcon(icon);
234         pItem->SetText(text);
235         pItem->SetActionId(actionId);
236         pItem->SetUpdateState(true);
237
238         if (itemCount > 0)
239         {
240                 pItem->SetStatus(_TABITEM_STATUS_NORMAL);
241         }
242         else
243         {
244                 pItem->SetStatus(_TABITEM_STATUS_SELECTED);
245         }
246
247         __pTabPresenter->SetReCalculateItemBounds(true);
248
249         return __tabItems.Add(*pItem);
250 }
251
252 result
253 _Tab::AddItem(const Bitmap& icon, int actionId)
254 {
255         if (actionId < _TAB_ACTION_ID_MIN || actionId > _TAB_ACTION_ID_MAX)
256         {
257                 SysLog(NID_UI_CTRL, "[E_OUT_OF_RANGE] The actionId (%d) is out of range.", actionId);
258                 return E_OUT_OF_RANGE;
259         }
260
261         if (__style != _TAB_STYLE_ICON)
262         {
263                 return E_SYSTEM;
264         }
265
266         bool isDuplicate = CheckDuplicatedActionId(actionId);
267         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);
268
269         int itemCount = __tabItems.GetCount();
270
271         SysTryReturnResult(NID_UI_CTRL, itemCount < _TAB_ITEM_MAXCOUNT, E_SYSTEM, "A system error has occurred. The tab has maximum number of items.");
272
273         _TabItem *pItem = new (std::nothrow) _TabItem;
274         SysTryReturnResult(NID_UI_CTRL, pItem != null, E_OUT_OF_MEMORY, "Memory allocation failed.");
275
276         pItem->SetIcon(icon);
277         pItem->SetActionId(actionId);
278         pItem->SetUpdateState(true);
279
280         if (itemCount > 0)
281         {
282                 pItem->SetStatus(_TABITEM_STATUS_NORMAL);
283         }
284         else
285         {
286                 pItem->SetStatus(_TABITEM_STATUS_SELECTED);
287         }
288
289         __pTabPresenter->SetReCalculateItemBounds(true);
290
291         return __tabItems.Add(*pItem);
292 }
293
294 result
295 _Tab::AddItem(const String& text, int actionId)
296 {
297         if (actionId < _TAB_ACTION_ID_MIN || actionId > _TAB_ACTION_ID_MAX)
298         {
299                 SysLog(NID_UI_CTRL, "[E_OUT_OF_RANGE] The actionId (%d) is out of range.", actionId);
300                 return E_OUT_OF_RANGE;
301         }
302
303         if (!((__style == _TAB_STYLE_TEXT) || (__style == _TAB_STYLE_ICON_TEXT)))
304         {
305                 return E_SYSTEM;
306         }
307
308         bool isDuplicate = CheckDuplicatedActionId(actionId);
309         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);
310
311         int itemCount = __tabItems.GetCount();
312
313         SysTryReturnResult(NID_UI_CTRL, itemCount < _TAB_ITEM_MAXCOUNT, E_SYSTEM, "A system error has occurred. The tab has maximum number of items.");
314
315         _TabItem *pItem = new (std::nothrow) _TabItem;
316         SysTryReturnResult(NID_UI_CTRL, pItem != null, E_OUT_OF_MEMORY, "Memory allocation failed.");
317
318         pItem->SetText(text);
319         pItem->SetActionId(actionId);
320         pItem->SetUpdateState(true);
321
322         if (itemCount > 0)
323         {
324                 pItem->SetStatus(_TABITEM_STATUS_NORMAL);
325         }
326         else
327         {
328                 pItem->SetStatus(_TABITEM_STATUS_SELECTED);
329         }
330
331         __pTabPresenter->SetReCalculateItemBounds(true);
332
333
334         return __tabItems.Add(*pItem);
335 }
336
337 result
338 _Tab::InsertItemAt(int index, const Bitmap& icon, const String& text, int actionId)
339 {
340         result r = E_SUCCESS;
341         bool selected = false;
342
343         if (actionId < _TAB_ACTION_ID_MIN || actionId > _TAB_ACTION_ID_MAX)
344         {
345                 SysLog(NID_UI_CTRL, "[E_OUT_OF_RANGE] The actionId (%d) is out of range.", actionId);
346                 return E_OUT_OF_RANGE;
347         }
348
349         if (!((__style == _TAB_STYLE_TEXT) || (__style == _TAB_STYLE_ICON_TEXT)))
350         {
351                 return E_SYSTEM;
352         }
353
354         __style = _TAB_STYLE_ICON_TEXT;
355
356         bool isDuplicate = CheckDuplicatedActionId(actionId);
357         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);
358
359         int itemCount = __tabItems.GetCount();
360
361         SysTryReturnResult(NID_UI_CTRL, itemCount < _TAB_ITEM_MAXCOUNT, E_SYSTEM, "A system error has occurred. The tab has maximum number of items.");
362
363         _TabItem *pItem = new (std::nothrow) _TabItem;
364         SysTryReturnResult(NID_UI_CTRL, pItem != null, E_OUT_OF_MEMORY, "Memory allocation failed.");
365
366         pItem->SetIcon(icon);
367         pItem->SetText(text);
368         pItem->SetActionId(actionId);
369         pItem->SetUpdateState(true);
370
371         int i = GetSelectedItemIndex();
372
373         if (i >= index)
374         {
375                 _TabItem *pSelectedItem = null;
376                 pSelectedItem = GetItemAt(i);
377                 if (pSelectedItem != null)
378                 {
379                         selected = true;
380                         pSelectedItem->SetStatus(_TABITEM_STATUS_NORMAL);
381                 }
382         }
383         else
384         {
385                 pItem->SetStatus(_TABITEM_STATUS_NORMAL);
386         }
387
388         __pTabPresenter->SetReCalculateItemBounds(true);
389
390         r = __tabItems.InsertAt(*pItem, index);
391
392         if (selected)
393         {
394                 SetSelectedItemIndex(i);
395         }
396
397         return r;
398 }
399
400 result
401 _Tab::InsertItemAt(int index, const Bitmap& icon, int actionId)
402 {
403         result r = E_SUCCESS;
404         bool selected = false;
405
406         if (actionId < _TAB_ACTION_ID_MIN || actionId > _TAB_ACTION_ID_MAX)
407         {
408                 SysLog(NID_UI_CTRL, "[E_OUT_OF_RANGE] The actionId (%d) is out of range.", actionId);
409                 return E_OUT_OF_RANGE;
410         }
411
412         if (__style != _TAB_STYLE_ICON)
413         {
414                 return E_SYSTEM;
415         }
416
417         bool isDuplicate = CheckDuplicatedActionId(actionId);
418         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);
419
420         int itemCount = __tabItems.GetCount();
421
422         SysTryReturnResult(NID_UI_CTRL, itemCount < _TAB_ITEM_MAXCOUNT, E_SYSTEM, "A system error has occurred. The tab has maximum number of items.");
423
424         _TabItem *pItem = new (std::nothrow) _TabItem;
425         SysTryReturnResult(NID_UI_CTRL, pItem != null, E_OUT_OF_MEMORY, "Memory allocation failed.");
426
427         pItem->SetIcon(icon);
428         pItem->SetActionId(actionId);
429         pItem->SetUpdateState(true);
430         int i = GetSelectedItemIndex();
431
432         if (i >= index)
433         {
434                 _TabItem *pSelectedItem = null;
435                 pSelectedItem = GetItemAt(i);
436                 if (pSelectedItem != null)
437                 {
438                         selected = true;
439                         pSelectedItem->SetStatus(_TABITEM_STATUS_NORMAL);
440                 }
441         }
442         else
443         {
444                 pItem->SetStatus(_TABITEM_STATUS_NORMAL);
445         }
446
447         __pTabPresenter->SetReCalculateItemBounds(true);
448
449         r = __tabItems.InsertAt(*pItem, index);
450
451         if (selected)
452         {
453                 SetSelectedItemIndex(i);
454         }
455
456         return r;
457 }
458
459 result
460 _Tab::InsertItemAt(int index, const String& text, int actionId)
461 {
462         result r = E_SUCCESS;
463         bool selected = false;
464
465         if (actionId < _TAB_ACTION_ID_MIN || actionId > _TAB_ACTION_ID_MAX)
466         {
467                 SysLog(NID_UI_CTRL, "[E_OUT_OF_RANGE] The actionId (%d) is out of range.", actionId);
468                 return E_OUT_OF_RANGE;
469         }
470
471         bool isDuplicate = CheckDuplicatedActionId(actionId);
472         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);
473
474         if (!((__style == _TAB_STYLE_TEXT) || (__style == _TAB_STYLE_ICON_TEXT)))
475         {
476                 return E_SYSTEM;
477         }
478
479         int itemCount = __tabItems.GetCount();
480
481         SysTryReturnResult(NID_UI_CTRL, itemCount < _TAB_ITEM_MAXCOUNT, E_SYSTEM, "A system error has occurred. The tab has maximum number of items.");
482
483         _TabItem *pItem = new (std::nothrow) _TabItem;
484         SysTryReturnResult(NID_UI_CTRL, pItem != null, E_OUT_OF_MEMORY, "Memory allocation failed.");
485
486         pItem->SetText(text);
487         pItem->SetActionId(actionId);
488         pItem->SetUpdateState(true);
489         int i = GetSelectedItemIndex();
490
491         if (i >= index)
492         {
493                 _TabItem *pSelectedItem = null;
494                 pSelectedItem = GetItemAt(i);
495                 if (pSelectedItem != null)
496                 {
497                         selected = true;
498                         pSelectedItem->SetStatus(_TABITEM_STATUS_NORMAL);
499                 }
500         }
501         else
502         {
503                 pItem->SetStatus(_TABITEM_STATUS_NORMAL);
504         }
505
506         __pTabPresenter->SetReCalculateItemBounds(true);
507
508         r = __tabItems.InsertAt(*pItem, index);
509
510         if (selected)
511         {
512                 SetSelectedItemIndex(i);
513         }
514
515         return r;
516 }
517
518 result
519 _Tab::SetItemAt(int index, const Bitmap& icon, const String& text, int actionId)
520 {
521         if (actionId < _TAB_ACTION_ID_MIN || actionId > _TAB_ACTION_ID_MAX)
522         {
523                 SysLog(NID_UI_CTRL, "[E_OUT_OF_RANGE] The actionId (%d) is out of range.", actionId);
524                 return E_OUT_OF_RANGE;
525         }
526
527         if (!((__style == _TAB_STYLE_TEXT) || (__style == _TAB_STYLE_ICON_TEXT)))
528         {
529                 return E_SYSTEM;
530         }
531
532         __style = _TAB_STYLE_ICON_TEXT;
533
534         int itemCount = __tabItems.GetCount();
535
536         if ((index < 0) || (index >= itemCount))
537         {
538                 return E_OUT_OF_RANGE;
539         }
540
541         SysTryReturnResult(NID_UI_CTRL, itemCount < _TAB_ITEM_MAXCOUNT, E_SYSTEM, "A system error has occurred. The tab has maximum number of items.");
542
543         if (GetItemIndex(actionId) != index)
544         {
545                 return E_SYSTEM;
546         }
547
548         _TabItem *pItem = static_cast<_TabItem*>(__tabItems.GetAt(index));
549         result r = GetLastResult();
550         SysTryReturnResult(NID_UI_CTRL, pItem != null, r, "[%s] Propagating.", GetErrorMessage(r));
551
552         pItem->SetIcon(icon);
553         pItem->SetText(text);
554         pItem->SetActionId(actionId);
555         pItem->SetUpdateState(true);
556
557         return E_SUCCESS;
558 }
559
560 result
561 _Tab::SetItemAt(int index, const Bitmap& icon, int actionId)
562 {
563         if (actionId < _TAB_ACTION_ID_MIN || actionId > _TAB_ACTION_ID_MAX)
564         {
565                 SysLog(NID_UI_CTRL, "[E_OUT_OF_RANGE] The actionId (%d) is out of range.", actionId);
566                 return E_OUT_OF_RANGE;
567         }
568
569         if (__style != _TAB_STYLE_ICON)
570         {
571                 return E_SYSTEM;
572         }
573
574         int itemCount = __tabItems.GetCount();
575
576         if ((index < 0) || (index >= itemCount))
577         {
578                 return E_OUT_OF_RANGE;
579         }
580
581         SysTryReturnResult(NID_UI_CTRL, itemCount < _TAB_ITEM_MAXCOUNT, E_SYSTEM, "A system error has occurred. The tab has maximum number of items.");
582
583         if (GetItemIndex(actionId) != index)
584         {
585                 return E_SYSTEM;
586         }
587
588         _TabItem *pItem = static_cast<_TabItem*>(__tabItems.GetAt(index));
589         result r = GetLastResult();
590         SysTryReturnResult(NID_UI_CTRL, pItem != null, r, "[%s] Propagating.", GetErrorMessage(r));
591
592         pItem->SetIcon(icon);
593         pItem->SetActionId(actionId);
594         pItem->SetUpdateState(true);
595
596         return E_SUCCESS;
597 }
598
599 result
600 _Tab::SetItemAt(int index, const String& text, int actionId)
601 {
602         if (actionId < _TAB_ACTION_ID_MIN || actionId > _TAB_ACTION_ID_MAX)
603         {
604                 SysLog(NID_UI_CTRL, "[E_OUT_OF_RANGE] The actionId (%d) is out of range.", actionId);
605                 return E_OUT_OF_RANGE;
606         }
607
608         if (!((__style == _TAB_STYLE_TEXT) || (__style == _TAB_STYLE_ICON_TEXT)))
609         {
610                 return E_SYSTEM;
611         }
612
613         int itemCount = __tabItems.GetCount();
614
615         if ((index < 0) || (index >= itemCount))
616         {
617                 return E_OUT_OF_RANGE;
618         }
619
620         SysTryReturnResult(NID_UI_CTRL, itemCount < _TAB_ITEM_MAXCOUNT, E_SYSTEM, "A system error has occurred. The tab has maximum number of items.");
621
622         if (GetItemIndex(actionId) != index)
623         {
624                 return E_SYSTEM;
625         }
626
627         _TabItem *pItem = static_cast<_TabItem*>(__tabItems.GetAt(index));
628         result r = GetLastResult();
629         SysTryReturnResult(NID_UI_CTRL, pItem != null, r, "[%s] Propagating.", GetErrorMessage(r));
630
631         pItem->SetText(text);
632         pItem->SetActionId(actionId);
633         pItem->SetUpdateState(true);
634
635         return E_SUCCESS;
636 }
637
638 result
639 _Tab::RemoveItemAt(int index)
640 {
641         result r = E_SUCCESS;
642         int i = GetSelectedItemIndex();
643
644         if (i >= index)
645         {
646                 _TabItem *pSelectedItem = null;
647                 pSelectedItem = GetItemAt(i);
648                 if (pSelectedItem != null)
649                 {
650                         pSelectedItem->SetStatus(_TABITEM_STATUS_NORMAL);
651                 }
652         }
653         __pTabPresenter->SetReCalculateItemBounds(true);
654
655         r = __tabItems.RemoveAt(index, true);
656
657         SetSelectedItemIndex(0);
658
659         return r;
660 }
661
662 result
663 _Tab::RemoveAllItems(void)
664 {
665         __pTabPresenter->SetReCalculateItemBounds(true);
666         SetSelectedItemIndex(0);
667         SetFirstDrawnItemIndex(-1);
668
669         __tabItems.RemoveAll(true);
670
671         return E_SUCCESS;
672 }
673
674 bool
675 _Tab::ChangeItemAt(const int srcIndex, const int destIndex)
676 {
677         _TabItem* pItem = null;
678         pItem = GetItemAt(srcIndex);
679
680         __tabItems.InsertAt(*pItem, destIndex);
681
682         if (srcIndex > destIndex)
683         {
684                 __tabItems.RemoveAt((srcIndex + 1), false);
685         }
686         else
687         {
688                 __tabItems.RemoveAt(srcIndex, false);
689         }
690
691         return true;
692 }
693
694 int
695 _Tab::GetItemIndex(int actionId)
696 {
697         int itemCount = __tabItems.GetCount();
698
699         _TabItem* pItem = null;
700
701         for (int i = 0; i < itemCount; i++)
702         {
703                 pItem = GetItemAt(i);
704
705                 if ((pItem != null) && (actionId == pItem->GetActionId()))
706                 {
707                         return i;
708                 }
709         }
710
711         return -1;
712 }
713
714 bool
715 _Tab::CheckDuplicatedActionId(int actionId)
716 {
717         int itemIndex = GetItemIndex(actionId);
718
719         if (itemIndex >= 0)
720         {
721                 return true;
722         }
723
724         return false;
725 }
726
727 result
728 _Tab::LoadBitmap(void)
729 {
730         result r = E_SUCCESS;
731
732         r = GET_BITMAP_CONFIG_N(TAB::ITEM_BG_EFFECT_PRESSED, BITMAP_PIXEL_FORMAT_ARGB8888, __pPressedItemBackgroundBitmap);
733         SysTryLog(NID_UI_CTRL, r == E_SUCCESS, "Failed to locate pressed item background bitmap.");
734
735         if (__pPressedItemBackgroundBitmap)
736         {
737                 __pPressedItemBackgroundBitmap = _BitmapImpl::GetColorReplacedBitmapN(*(__pPressedItemBackgroundBitmap), Color::GetColor(COLOR_ID_MAGENTA), GetPressedItemBackgroundColor());
738                 SysTryLog(NID_UI_CTRL, r == E_SUCCESS, "Failed to locate pressed item background bitmap.");
739         }
740
741         r = GET_BITMAP_CONFIG_N(TAB::ITEM_BG_EFFECT_HIGHLIGHTED, BITMAP_PIXEL_FORMAT_ARGB8888, __pHighlightedItemBackgroundBitmap);
742         SysTryLog(NID_UI_CTRL, r == E_SUCCESS, "Failed to locate highlighted item background bitmap.");
743
744         if (__pHighlightedItemBackgroundBitmap)
745         {
746                 __pHighlightedItemBackgroundBitmap = _BitmapImpl::GetColorReplacedBitmapN(*(__pHighlightedItemBackgroundBitmap), Color::GetColor(COLOR_ID_MAGENTA), GetHighlightedItemBackgroundColor());
747                 SysTryLog(NID_UI_CTRL, r == E_SUCCESS, "Failed to locate highlighted item background bitmap.");
748         }
749         return r;
750 }
751
752 result
753 _Tab::SetBadgeIcon(int actionId, const Bitmap* pBadgeIcon)
754 {
755         result r = E_SUCCESS;
756
757         if (actionId < _TAB_ACTION_ID_MIN || actionId > _TAB_ACTION_ID_MAX)
758         {
759                 SysLog(NID_UI_CTRL, "[E_OUT_OF_RANGE] The actionId (%d) is out of range.", actionId);
760                 return E_OUT_OF_RANGE;
761         }
762
763         int itemIndex = GetItemIndexFromActionId(actionId);
764
765         _TabItem *pItem = null;
766
767         if (itemIndex < 0)
768         {
769                 SysLog(NID_UI_CTRL, "[E_INVALID_ARG] Invalid argument(s) is used. The specified actionId is not found.");
770                 return E_INVALID_ARG;
771         }
772
773         pItem = dynamic_cast<_TabItem*>(__tabItems.GetAt(itemIndex));
774
775         if (pItem != null)
776         {
777                 pItem->SetBadgeIcon(*pBadgeIcon);
778
779                 r = __tabItems.SetAt(*pItem, itemIndex, false);
780         }
781
782         return r;
783 }
784
785 int
786 _Tab::GetItemCount(void) const
787 {
788         return __tabItems.GetCount();
789 }
790
791 int
792 _Tab::GetItemIndexFromActionId(int actionId) const
793 {
794         if (actionId < _TAB_ACTION_ID_MIN || actionId > _TAB_ACTION_ID_MAX)
795         {
796                 SysLog(NID_UI_CTRL, "[E_OUT_OF_RANGE] The actionId (%d) is out of range.", actionId);
797                 return -1;
798         }
799
800         int index = 0;
801         int itemCount = __tabItems.GetCount();
802
803         for (index = 0; index < itemCount; index++)
804         {
805                 const _TabItem *pItem = dynamic_cast<const _TabItem*>(__tabItems.GetAt(index));
806
807                 if (pItem != null)
808                 {
809                         if (pItem->GetActionId() == actionId)
810                         {
811                                 return index;
812                         }
813                 }
814         }
815
816         return -1;
817 }
818
819 int
820 _Tab::GetItemActionIdAt(int index) const
821 {
822         if (__tabItems.GetAt(index) == null )
823         {
824                 return -1;
825         }
826
827         const _TabItem *pItem = dynamic_cast<const _TabItem*>(__tabItems.GetAt(index));
828         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);
829
830         return pItem->GetActionId();
831 }
832
833 _TabItem*
834 _Tab::GetItemAt(int index)
835 {
836         if (__tabItems.GetAt(index) == null )
837         {
838                 return null;
839         }
840
841         _TabItem *pItem = static_cast<_TabItem*>(__tabItems.GetAt(index));
842         result r = GetLastResult();
843         SysTryReturn(NID_UI_CTRL, pItem != null, null, r, "[%s] Propagating.", GetErrorMessage(r));
844
845         return pItem;
846 }
847
848 void
849 _Tab::SetSelectedItemIndex(int index)
850 {
851         __pTabPresenter->SetSelectedItemIndex(index);
852         return;
853 }
854
855 int
856 _Tab::GetSelectedItemIndex(void) const
857 {
858         return __pTabPresenter->GetSelectedItemIndex();
859 }
860
861 void
862 _Tab::SetFirstDrawnItemIndex(int index)
863 {
864         __pTabPresenter->SetFirstDrawnItemIndex(index);
865         return;
866 }
867
868 int
869 _Tab::GetFirstDrawnItemIndex(void) const
870 {
871         return __pTabPresenter->GetFirstDrawnItemIndex();
872 }
873
874 void
875 _Tab::SetEditModeEnabled(bool enable)
876 {
877         return __pTabPresenter->SetEditModeEnabled(enable);
878 }
879
880 bool
881 _Tab::IsEditModeEnabled(void) const
882 {
883         return __pTabPresenter->IsEditModeEnabled();
884 }
885
886 result
887 _Tab::SetBackgroundBitmap(const Bitmap& bitmap)
888 {
889         ClearLastResult();
890
891         Tizen::Graphics::Bitmap* pBitmap = _BitmapImpl::CloneN(bitmap);
892
893         SysTryReturn(NID_UI_CTRL, (pBitmap), GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
894
895         if (__pBackgroundBitmap)
896         {
897                 delete __pBackgroundBitmap;
898                 __pBackgroundBitmap = null;
899         }
900
901         __pBackgroundBitmap = pBitmap;
902
903         return E_SUCCESS;
904 }
905
906 Bitmap*
907 _Tab::GetBackgroundBitmap(void) const
908 {
909         return __pBackgroundBitmap;
910 }
911
912
913 result
914 _Tab::SetPressedItemBackgroundBitmap(const Bitmap& bitmap)
915 {
916         ClearLastResult();
917
918         Tizen::Graphics::Bitmap* pBitmap = _BitmapImpl::CloneN(bitmap);
919
920         SysTryReturn(NID_UI_CTRL, (pBitmap), GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
921
922         if (__pPressedItemBackgroundBitmap)
923         {
924                 delete __pPressedItemBackgroundBitmap;
925                 __pPressedItemBackgroundBitmap = null;
926         }
927
928         __pPressedItemBackgroundBitmap = pBitmap;
929         return E_SUCCESS;
930 }
931
932 Bitmap*
933 _Tab::GetPressedItemBackgroundBitmap(void) const
934 {
935         return __pPressedItemBackgroundBitmap;
936 }
937
938 result
939 _Tab::SetSelectedItemBackgroundBitmap(const Bitmap& bitmap)
940 {
941         ClearLastResult();
942
943         Tizen::Graphics::Bitmap* pBitmap = _BitmapImpl::CloneN(bitmap);
944
945         SysTryReturn(NID_UI_CTRL, (pBitmap), GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
946
947         if (__pSelectedItemBackgroundBitmap)
948         {
949                 delete __pSelectedItemBackgroundBitmap;
950                 __pSelectedItemBackgroundBitmap = null;
951         }
952         __pSelectedItemBackgroundBitmap = pBitmap;
953         __pTabPresenter->FreeHorizontalLineBitmap();
954
955         return E_SUCCESS;
956 }
957
958
959 Bitmap*
960 _Tab::GetSelectedItemBackgroundBitmap(void) const
961 {
962         return __pSelectedItemBackgroundBitmap;
963 }
964
965 result
966 _Tab::SetHighlightedItemBackgroundBitmap(const Bitmap& bitmap)
967 {
968         ClearLastResult();
969
970         Tizen::Graphics::Bitmap* pBitmap = _BitmapImpl::CloneN(bitmap);
971
972         SysTryReturn(NID_UI_CTRL, (pBitmap), GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
973
974         if (__pHighlightedItemBackgroundBitmap)
975         {
976                 delete __pHighlightedItemBackgroundBitmap;
977                 __pHighlightedItemBackgroundBitmap = null;
978         }
979
980         __pHighlightedItemBackgroundBitmap = pBitmap;
981
982         return E_SUCCESS;
983 }
984
985 Bitmap*
986 _Tab::GetHighlightedItemBackgroundBitmap(void) const
987 {
988         return __pHighlightedItemBackgroundBitmap;
989 }
990
991 void
992 _Tab::SetItemBackgroundColor(Color color)
993 {
994         __itemBgColor[_TAB_STATUS_NORMAL] = color;
995         return;
996 }
997
998 Color
999 _Tab::GetItemBackgroundColor(void) const
1000 {
1001         return __itemBgColor[_TAB_STATUS_NORMAL];
1002 }
1003
1004 void
1005 _Tab::SetPressedItemBackgroundColor(Color color)
1006 {
1007         __itemBgColor[_TAB_STATUS_PRESSED] = color;
1008         return;
1009 }
1010
1011 Color
1012 _Tab::GetPressedItemBackgroundColor(void) const
1013 {
1014         return __itemBgColor[_TAB_STATUS_PRESSED];
1015 }
1016
1017 void
1018 _Tab::SetSelectedItemBackgroundColor(Color color)
1019 {
1020         __itemBgColor[_TAB_STATUS_SELECTED] = color;
1021         return;
1022 }
1023
1024 Color
1025 _Tab::GetSelectedItemBackgroundColor(void) const
1026 {
1027         return __itemBgColor[_TAB_STATUS_SELECTED];
1028 }
1029
1030 void
1031 _Tab::SetHighlightedItemBackgroundColor(Color color)
1032 {
1033         __itemBgColor[_TAB_STATUS_HIGHLIGHTED] = color;
1034         return;
1035 }
1036
1037 Color
1038 _Tab::GetHighlightedItemBackgroundColor(void) const
1039 {
1040         return __itemBgColor[_TAB_STATUS_HIGHLIGHTED];
1041 }
1042
1043 void
1044 _Tab::SetTextColor(const Color& textColor)
1045 {
1046         __itemTextColor[_TAB_STATUS_NORMAL] = textColor;
1047         return;
1048 }
1049
1050 Color
1051 _Tab::GetTextColor(void) const
1052 {
1053         return  __itemTextColor[_TAB_STATUS_NORMAL];
1054 }
1055
1056 void
1057 _Tab::SetPressedTextColor(const Color& textColor)
1058 {
1059         __itemTextColor[_TAB_STATUS_PRESSED] = textColor;
1060         return;
1061 }
1062
1063 Color
1064 _Tab::GetPressedTextColor(void) const
1065 {
1066         return __itemTextColor[_TAB_STATUS_PRESSED];
1067 }
1068
1069 void
1070 _Tab::SetSelectedTextColor(const Color& textColor)
1071 {
1072         __itemTextColor[_TAB_STATUS_SELECTED] = textColor;
1073         return;
1074 }
1075
1076 Color
1077 _Tab::GetSelectedTextColor(void) const
1078 {
1079         return __itemTextColor[_TAB_STATUS_SELECTED];
1080 }
1081
1082 void
1083 _Tab::SetHighlightedTextColor(const Color& color)
1084 {
1085         __itemTextColor[_TAB_STATUS_HIGHLIGHTED] = color;
1086         return;
1087 }
1088
1089 Color
1090 _Tab::GetHighlightedTextColor(void) const
1091 {
1092         return __itemTextColor[_TAB_STATUS_HIGHLIGHTED];
1093 }
1094
1095 void
1096 _Tab::SetStyle(int style)
1097 {
1098         __style = style;
1099         return;
1100 }
1101
1102 _TabStyle
1103 _Tab::GetStyle(void) const
1104 {
1105         return _TabStyle(__style);
1106 }
1107
1108 void
1109 _Tab::AddActionEventListener(const _IActionEventListener& listener)
1110 {
1111         ClearLastResult();
1112
1113         if (__pActionEvent == null)
1114         {
1115                 __pActionEvent = _ActionEvent::CreateInstanceN(*this);
1116
1117                 if (__pActionEvent == null || IsFailed(GetLastResult()))
1118                 {
1119                         SetLastResult(E_SYSTEM);
1120                         delete __pActionEvent;
1121                         return;
1122                 }
1123         }
1124         __pActionEvent->AddListener(listener);
1125         return;
1126 }
1127
1128 void
1129 _Tab::RemoveActionEventListener(const _IActionEventListener& listener)
1130 {
1131         ClearLastResult();
1132
1133         __pActionEvent->RemoveListener(listener);
1134         return;
1135 }
1136
1137 bool
1138 _Tab::OnTouchPressed(const _Control& source, const _TouchInfo& touchinfo)
1139 {
1140         if (this != &source)
1141         {
1142                 return true;
1143         }
1144
1145         return __pTabPresenter->OnTouchPressed(source, touchinfo);
1146 }
1147
1148 bool
1149 _Tab::OnTouchReleased(const _Control& source, const _TouchInfo& touchinfo)
1150 {
1151         if (this != &source)
1152         {
1153                 return true;
1154         }
1155
1156         __pTabPresenter->OnTouchReleased(source, touchinfo);
1157
1158         int index = __pTabPresenter->GetItemIndexFromPosition(touchinfo.GetCurrentPosition());
1159
1160         _TabItem* pItem = __pTabPresenter->GetItemAt(index);
1161
1162         if (pItem == null)
1163         {
1164                 return true;
1165         }
1166
1167         if (__pActionEvent)
1168         {
1169                 IEventArg* pEventArg = _ActionEvent::CreateActionEventArgN(pItem->GetActionId());
1170                 SysTryReturn(NID_UI_CTRL, pEventArg, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1171
1172                 __pActionEvent->Fire(*pEventArg);
1173         }
1174
1175         return true;
1176 }
1177
1178 bool
1179 _Tab::OnTouchMoved(const _Control& source, const _TouchInfo& touchinfo)
1180 {
1181         if (this != &source)
1182         {
1183                 return true;
1184         }
1185
1186         return __pTabPresenter->OnTouchMoved(source, touchinfo);
1187 }
1188
1189 bool
1190 _Tab::OnLongPressGestureDetected(_TouchLongPressGestureDetector& gesture)
1191 {
1192         return __pTabPresenter->OnLongPressGestureDetected();
1193 }
1194
1195 bool
1196 _Tab::OnLongPressGestureCanceled(_TouchLongPressGestureDetector& gesture)
1197 {
1198         return false;
1199 }
1200
1201 bool
1202 _Tab::OnFlickGestureDetected(_TouchFlickGestureDetector& gesture)
1203 {
1204
1205         return __pTabPresenter->OnFlickGestureDetected(gesture);
1206 }
1207
1208 bool
1209 _Tab::OnFlickGestureCanceled(_TouchFlickGestureDetector& gesture)
1210 {
1211         return false;
1212 }
1213
1214 void
1215 _Tab::OnDraw(void)
1216 {
1217         ClearLastResult();
1218         __pTabPresenter->Draw();
1219         return;
1220
1221 }
1222
1223 void
1224 _Tab::OnBoundsChanged(void)
1225 {
1226         __pTabPresenter->OnBoundsChanged();
1227 }
1228
1229 result
1230 _Tab::OnAttachedToMainTree(void)
1231 {
1232         _AccessibilityContainer* pContainer = null;
1233
1234         if (likely((_AccessibilityManager::IsActivated())))
1235         {
1236                 pContainer = GetAccessibilityContainer();
1237
1238                 if (pContainer)
1239                 {
1240                         pContainer->Activate(true);
1241                         pContainer->AddListener(*this);
1242                 }
1243         }
1244
1245         return E_SUCCESS;
1246 }
1247
1248 void
1249 _Tab::OnFontChanged(Font* pFont)
1250 {
1251     __pTabPresenter->OnFontChanged(pFont);
1252     return;
1253 }
1254
1255 void
1256 _Tab::OnFontInfoRequested(unsigned long& style, int& size)
1257 {
1258     __pTabPresenter->OnFontInfoRequested(style, size);
1259     return;
1260 }
1261
1262 void
1263 _Tab::AddAccessibilityElement(const Rectangle& itemBounds, const String& itemText, _TabItemStatus status)
1264 {
1265         if (likely(!(_AccessibilityManager::IsActivated())))
1266         {
1267                 return;
1268         }
1269
1270         _AccessibilityContainer* pContainer = GetAccessibilityContainer();
1271
1272         if (pContainer != null)
1273         {
1274                 _AccessibilityElement* pAccessibilityElement = new (std::nothrow) _AccessibilityElement(true);
1275                 SysTryReturnVoidResult(NID_UI_CTRL, pAccessibilityElement != null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
1276
1277                 pAccessibilityElement->SetTrait(ACCESSIBILITY_TRAITS_TAB);
1278                 pAccessibilityElement->SetHint(L"Double tap to move to contents");
1279                 pAccessibilityElement->SetBounds(itemBounds);
1280
1281                 if (GetStyle() != _TAB_STYLE_ICON)
1282                 {
1283                         pAccessibilityElement->SetLabel(itemText);
1284                 }
1285
1286                 if (status == _TABITEM_STATUS_SELECTED)
1287                 {
1288                         pAccessibilityElement->SetStatus("Selected");
1289                 }
1290                 else
1291                 {
1292                         pAccessibilityElement->SetStatus("");
1293                 }
1294
1295                 pContainer->AddElement(*pAccessibilityElement);
1296                 __accessibilityElements.Add(pAccessibilityElement);
1297         }
1298
1299         return;
1300 }
1301
1302 void
1303 _Tab::RemoveAllAccessibilityElement(void)
1304 {
1305         if (likely(!(_AccessibilityManager::IsActivated())))
1306         {
1307                 return;
1308         }
1309
1310         _AccessibilityContainer* pContainer = GetAccessibilityContainer();
1311
1312         if (pContainer == null)
1313         {
1314                 return;
1315         }
1316
1317         _AccessibilityElement* pAccessibilityElement = null;
1318
1319         while (__accessibilityElements.GetCount() > 0)
1320         {
1321                 if ((__accessibilityElements.GetAt(0, pAccessibilityElement)) == E_SUCCESS)
1322                 {
1323                         pContainer->RemoveElement(*pAccessibilityElement);
1324                         __accessibilityElements.RemoveAt(0);
1325                 }
1326                 else
1327                 {
1328                         __accessibilityElements.RemoveAt(0);
1329                 }
1330         }
1331
1332         return;
1333 }
1334
1335 bool
1336 _Tab::OnAccessibilityFocusMovedNext(const _AccessibilityContainer& control, const _AccessibilityElement& element)
1337 {
1338         ClearLastResult();
1339
1340         return __pTabPresenter->OnAccessibilityFocusMovedNext(control, element);
1341 }
1342
1343 bool
1344 _Tab::OnAccessibilityFocusMovedPrevious(const _AccessibilityContainer& control, const _AccessibilityElement& element)
1345 {
1346         ClearLastResult();
1347
1348         return __pTabPresenter->OnAccessibilityFocusMovedPrevious(control, element);
1349 }
1350
1351 bool
1352 _Tab::OnAccessibilityReadElement(const _AccessibilityContainer& control, const _AccessibilityElement& element)
1353 {
1354         return false;
1355 }
1356
1357 bool
1358 _Tab::OnAccessibilityFocusIn(const _AccessibilityContainer& control, const _AccessibilityElement& element)
1359 {
1360         return false;
1361 }
1362
1363 bool
1364 _Tab::OnAccessibilityFocusOut(const _AccessibilityContainer& control, const _AccessibilityElement& element)
1365 {
1366         return false;
1367 }
1368
1369 bool
1370 _Tab::OnAccessibilityActionPerformed(const _AccessibilityContainer& control, const _AccessibilityElement& element)
1371 {
1372         return false;
1373 }
1374
1375 bool
1376 _Tab::OnAccessibilityValueIncreased(const Tizen::Ui::_AccessibilityContainer&, const Tizen::Ui::_AccessibilityElement&)
1377 {
1378         return false;
1379 }
1380
1381 bool
1382 _Tab::OnAccessibilityValueDecreased(const Tizen::Ui::_AccessibilityContainer&, const Tizen::Ui::_AccessibilityElement&)
1383 {
1384         return false;
1385 }
1386
1387 }}} // Tizen::Ui::Controls
1388