Changed indicator bg color.
[platform/framework/native/uifw.git] / src / ui / controls / FUiCtrl_TabImpl.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_TabImpl.cpp
20  * @brief               This is the implementation file for the _TabImpl class.
21  */
22
23
24 #include <FUiControl.h>
25 #include "FUi_ResourceManager.h"
26 #include "FUiCtrl_TabImpl.h"
27
28 using namespace Tizen::Base;
29 using namespace Tizen::Ui;
30 using namespace Tizen::Graphics;
31
32 namespace Tizen { namespace Ui { namespace Controls {
33
34 _TabImpl::_TabImpl(Tab* pPublic, _Tab* pCore)
35         : _ControlImpl(pPublic, pCore)
36         , __pActionEvent(null)
37 {
38 }
39
40 _TabImpl::~_TabImpl(void)
41 {
42         if (__pActionEvent)
43         {
44                 delete __pActionEvent;
45                 __pActionEvent = null;
46         }
47 }
48
49 _TabImpl*
50 _TabImpl::CreateTabImplN(Tab* pPublic)
51 {
52         ClearLastResult();
53         result r = E_SUCCESS;
54
55         Rectangle rect(0, 0, 0, 0);
56
57         _Tab* pCore = null;
58         pCore = _Tab::CreateTabN();
59         r = GetLastResult();
60
61         _TabImpl* pTabImpl = new (std::nothrow) _TabImpl(pPublic, pCore);
62         SysTryCatch(NID_UI_CTRL, pTabImpl, , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
63
64         return pTabImpl;
65
66 CATCH:
67         delete pCore;
68         return null;
69 }
70
71
72 Tab*
73 _TabImpl::GetTab(void)
74 {
75         return dynamic_cast<Tab*>(&(_ControlImpl::GetPublic()));
76 }
77
78
79 const char*
80 _TabImpl::GetPublicClassName(void) const
81 {
82         return "Controls::Tab";
83 }
84
85
86 const Tab&
87 _TabImpl::GetPublic(void) const
88 {
89         return static_cast<const Tab&>(_ControlImpl::GetPublic());
90 }
91
92
93 Tab&
94 _TabImpl::GetPublic(void)
95 {
96         return static_cast<Tab&>(_ControlImpl::GetPublic());
97 }
98
99
100 const _Tab&
101 _TabImpl::GetCore(void) const
102 {
103         return static_cast<const _Tab&>(_ControlImpl::GetCore());
104 }
105
106
107 _Tab&
108 _TabImpl::GetCore(void)
109 {
110         return static_cast<_Tab&>(_ControlImpl::GetCore());
111 }
112
113
114 _TabImpl*
115 _TabImpl::GetInstance(Tab& pTab)
116 {
117         return static_cast<_TabImpl*>(pTab._pControlImpl);
118 }
119
120
121 const _TabImpl*
122 _TabImpl::GetInstance(const Tab& pTab)
123 {
124         return static_cast<const _TabImpl*>(pTab._pControlImpl);
125 }
126
127
128 Tab*
129 _TabImpl::CreateTabN(void)
130 {
131         result r = E_SUCCESS;
132
133         Tab* pTab = new (std::nothrow) Tab;
134         SysTryReturn(NID_UI_CTRL, (pTab != null), null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
135
136         r = pTab->Construct();
137         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, null, E_SYSTEM, "[E_SYSTEM] A system error has occurred. Failed to construct Tab instance.");
138
139         return pTab;
140 }
141
142 void
143 _TabImpl::DeleteTab(Tab* pTab)
144 {
145         if (pTab != null)
146         {
147                 delete pTab;
148                 pTab = null;
149         }
150 }
151
152
153 bool
154 _TabImpl::IsMovable(void) const
155 {
156         return false;
157 }
158
159 bool
160 _TabImpl::IsResizable(void)     const
161 {
162         return false;
163 }
164
165
166 result
167 _TabImpl::AddItem(const Bitmap& icon, const String& text, int actionId)
168 {
169         ClearLastResult();
170
171         result r = GetCore().AddItem(icon, text, actionId);
172
173         if (r == E_SYSTEM)
174         {
175                 SysLog(NID_UI_CTRL, "[E_SYSTEM] A system error has occurred. Failed to add item to tab.");
176                 return E_SYSTEM;
177         }
178
179         return r;
180 }
181
182
183 result
184 _TabImpl::AddItem(const Bitmap& icon, int actionId)
185 {
186         ClearLastResult();
187
188         result r = GetCore().AddItem(icon, actionId);
189
190         if (r == E_SYSTEM)
191         {
192                 SysLog(NID_UI_CTRL, "[E_SYSTEM] A system error has occurred. Failed to add item to tab.");
193                 return E_SYSTEM;
194         }
195
196         return r;
197 }
198
199 result
200 _TabImpl::AddItem(const String& text, int actionId)
201 {
202         ClearLastResult();
203
204         result r = GetCore().AddItem(text, actionId);
205
206         if (r == E_SYSTEM)
207         {
208                 SysLog(NID_UI_CTRL, "[E_SYSTEM] A system error has occurred. Failed to add item to tab.");
209                 return E_SYSTEM;
210         }
211
212         return r;
213 }
214
215
216 result
217 _TabImpl::InsertItemAt(int index, const Bitmap& icon, const String& text, int actionId)
218 {
219         ClearLastResult();
220
221         result r = GetCore().InsertItemAt(index, icon, text, actionId);
222
223         if (r == E_SYSTEM)
224         {
225                 SysLog(NID_UI_CTRL, "[E_SYSTEM] A system error has occurred. Failed to insert item to tab.");
226                 return E_SYSTEM;
227         }
228
229         return r;
230 }
231
232
233 result
234 _TabImpl::InsertItemAt(int index, const Bitmap& icon, int actionId)
235 {
236         ClearLastResult();
237
238         result r = GetCore().InsertItemAt(index, icon, actionId);
239
240         if (r == E_SYSTEM)
241         {
242                 SysLog(NID_UI_CTRL, "[E_SYSTEM] A system error has occurred. Failed to insert item to tab.");
243                 return E_SYSTEM;
244         }
245
246         return r;
247 }
248
249
250 result
251 _TabImpl::InsertItemAt(int index, const String& text, int actionId)
252 {
253         ClearLastResult();
254
255         result r = GetCore().InsertItemAt(index, text, actionId);
256
257         if (r == E_SYSTEM)
258         {
259                 SysLog(NID_UI_CTRL, "[E_SYSTEM] A system error has occurred. Failed to insert item to tab.");
260                 return E_SYSTEM;
261         }
262
263         return r;
264 }
265
266
267 result
268 _TabImpl::SetItemAt(int index, const Bitmap& icon, const String& text, int actionId)
269 {
270         ClearLastResult();
271
272         result r = GetCore().SetItemAt(index, icon, text, actionId);
273
274         if (r == E_SYSTEM)
275         {
276                 SysLog(NID_UI_CTRL, "[E_SYSTEM] A system error has occurred. Failed to set item to tab.");
277                 return E_SYSTEM;
278         }
279
280         return r;
281 }
282
283
284 result
285 _TabImpl::SetItemAt(int index, const Bitmap& icon, int actionId)
286 {
287         ClearLastResult();
288
289         result r = GetCore().SetItemAt(index, icon, actionId);
290
291         if (r == E_SYSTEM)
292         {
293                 SysLog(NID_UI_CTRL, "[E_SYSTEM] A system error has occurred. Failed to set item to tab.");
294                 return E_SYSTEM;
295         }
296
297         return r;
298 }
299
300
301 result
302 _TabImpl::SetItemAt(int index, const String& text, int actionId)
303 {
304         ClearLastResult();
305
306         result r = GetCore().SetItemAt(index, text, actionId);
307
308         if (r == E_SYSTEM)
309         {
310                 SysLog(NID_UI_CTRL, "[E_SYSTEM] A system error has occurred. Failed to set item to tab.");
311                 return E_SYSTEM;
312         }
313
314         return r;
315 }
316
317
318 result
319 _TabImpl::RemoveItemAt(int index)
320 {
321         ClearLastResult();
322
323         return GetCore().RemoveItemAt(index);
324 }
325
326
327 result
328 _TabImpl::RemoveAllItems(void)
329 {
330         ClearLastResult();
331
332         return GetCore().RemoveAllItems();
333 }
334
335
336 result
337 _TabImpl::SetBadgeIcon(int actionId, const Bitmap* pBadgeIcon)
338 {
339         ClearLastResult();
340
341         return GetCore().SetBadgeIcon(actionId, pBadgeIcon);
342 }
343
344
345 int
346 _TabImpl::GetItemCount(void) const
347 {
348         ClearLastResult();
349
350         return GetCore().GetItemCount();
351 }
352
353
354 int
355 _TabImpl::GetItemIndexFromActionId(int actionId) const
356 {
357         ClearLastResult();
358
359         return GetCore().GetItemIndexFromActionId(actionId);
360 }
361
362
363 int
364 _TabImpl::GetItemActionIdAt(int index) const
365 {
366         ClearLastResult();
367
368         return GetCore().GetItemActionIdAt(index);
369 }
370
371
372 void
373 _TabImpl::SetSelectedItem(int index)
374 {
375         ClearLastResult();
376
377         GetCore().SetSelectedItemIndex(index);
378 }
379
380
381 int
382 _TabImpl::GetSelectedItemIndex(void) const
383 {
384         ClearLastResult();
385
386         return GetCore().GetSelectedItemIndex();
387 }
388
389
390 void
391 _TabImpl::SetEditModeEnabled(bool enable)
392 {
393         ClearLastResult();
394
395         GetCore().SetEditModeEnabled(enable);
396 }
397
398
399 bool
400 _TabImpl::IsEditModeEnabled(void) const
401 {
402         ClearLastResult();
403
404         return GetCore().IsEditModeEnabled();
405 }
406
407
408 result
409 _TabImpl::SetBackgroundBitmap(const Bitmap& bitmap)
410 {
411         ClearLastResult();
412
413         return GetCore().SetBackgroundBitmap(bitmap);
414 }
415
416
417 result
418 _TabImpl::SetFocusedItemBackgroundBitmap(const Bitmap& bitmap)
419 {
420         ClearLastResult();
421
422         return GetCore().SetSelectedItemBackgroundBitmap(bitmap);
423 }
424
425
426 void
427 _TabImpl::SetTextColor(const Color& textColor)
428 {
429         ClearLastResult();
430
431         GetCore().SetTextColor(textColor);
432 }
433
434
435 Color
436 _TabImpl::GetTextColor(void) const
437 {
438         ClearLastResult();
439
440         return GetCore().GetTextColor();
441 }
442
443
444 void
445 _TabImpl::SetSelectedTextColor(const Color& textColor)
446 {
447         ClearLastResult();
448
449         GetCore().SetSelectedTextColor(textColor);
450 }
451
452
453 Color
454 _TabImpl::GetSelectedTextColor(void) const
455 {
456         ClearLastResult();
457
458         return GetCore().GetSelectedTextColor();
459 }
460
461
462 result
463 _TabImpl::SetHighlightedItemBackgroundBitmap(const Bitmap& bitmap)
464 {
465         ClearLastResult();
466
467         return GetCore().SetHighlightedItemBackgroundBitmap(bitmap);
468 }
469
470
471 void
472 _TabImpl::SetHighlightedTextColor(const Color& color)
473 {
474         ClearLastResult();
475
476         GetCore().SetHighlightedTextColor(color);
477 }
478
479
480 Color
481 _TabImpl::GetHighlightedTextColor(void) const
482 {
483         ClearLastResult();
484
485         return GetCore().GetHighlightedTextColor();
486 }
487
488
489 void
490 _TabImpl::AddActionEventListener(IActionEventListener& listener)
491 {
492         ClearLastResult();
493
494         if (__pActionEvent == null)
495         {
496                 __pActionEvent = _PublicActionEvent::CreateInstanceN(GetPublic());
497
498                 if (__pActionEvent == null || IsFailed(GetLastResult()))
499                 {
500                         SysLog(NID_UI_CTRL, "[E_SYSTEM] A system error has occurred. Failed to construct a _PublicActionEvent instance.");
501                         SetLastResult(E_SYSTEM);
502                         delete __pActionEvent;
503                         return;
504                 }
505         }
506
507         __pActionEvent->AddListener(listener);
508
509         GetCore().AddActionEventListener(*this);
510 }
511
512
513 void
514 _TabImpl::RemoveActionEventListener(IActionEventListener& listener)
515 {
516         __pActionEvent->RemoveListener(listener);
517
518         GetCore().RemoveActionEventListener(*this);
519 }
520
521
522 void
523 _TabImpl::OnActionPerformed(const _Control& source, int actionId)
524 {
525         if (__pActionEvent != null)
526         {
527                 __pActionEvent->Fire(*_PublicActionEvent::CreateActionEventArgN(actionId));
528         }
529 }
530
531
532 }}} // Tizen::Ui::Controls