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