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