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