Tizen 2.1 base
[framework/osp/uifw.git] / src / ui / controls / FUiCtrlTabBarItem.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         FUiCtrlTabBarItem.cpp
19 * @brief        This file contains implementation of TabBarItem class
20 */
21
22 #include <FUiCtrlTabBarItem.h>
23 #include <FBaseErrors.h>
24 #include <FBaseResult.h>
25 #include <FBaseSysLog.h>
26 #include "FUiCtrl_TabBarItemImpl.h"
27
28 using namespace Tizen::Ui::Controls;
29
30 namespace Tizen { namespace Ui { namespace Controls
31 {
32
33 TabBarItem::TabBarItem(void)
34         : __pTabBarItemImpl(null)
35 {
36 }
37
38
39 TabBarItem::~TabBarItem(void)
40 {
41         delete __pTabBarItemImpl;
42         __pTabBarItemImpl = null;
43 }
44
45
46 result
47 TabBarItem::Construct(const Tizen::Base::String& text, int actionId)
48 {
49         if (__pTabBarItemImpl != null)
50         {
51                 SysLog(NID_UI_CTRL, "[E_INVALID_STATE] This instance is already allocated.");
52                 return E_INVALID_STATE;
53         }
54
55         if (actionId < 0)
56         {
57                 SysLog(NID_UI_CTRL, "[E_INVALID_ARG] The action ID of the item must be a positive integer.");
58                 return E_INVALID_ARG;
59         }
60
61         __pTabBarItemImpl = new (std::nothrow) _TabBarItemImpl();
62         if (__pTabBarItemImpl == null)
63         {
64                 SysLog(NID_UI_CTRL, "[E_OUT_OF_MEMORY] SeedItem of TabBarItem can not be allocated due to the memory shortage.");
65                 delete __pTabBarItemImpl;
66                 __pTabBarItemImpl = null;
67                 return E_OUT_OF_MEMORY;
68         }
69
70         __pTabBarItemImpl->SetText(text);
71         __pTabBarItemImpl->SetActionId(actionId);
72
73         return E_SUCCESS;
74 }
75
76 result
77 TabBarItem::SetActionId(int actionId)
78 {
79         if (__pTabBarItemImpl == null)
80         {
81                 SysLog(NID_UI_CTRL, "[E_INVALID_STATE] This instance isn't constructed.");
82                 return E_INVALID_STATE;
83         }
84
85         if (actionId < 0)
86         {
87                 SysLog(NID_UI_CTRL, "[E_INVALID_ARG] The action ID of the item must be a positive integer.");
88                 return E_INVALID_ARG;
89         }
90
91         __pTabBarItemImpl->SetActionId(actionId);
92         return E_SUCCESS;
93 }
94
95 int
96 TabBarItem::GetActionId(void) const
97 {
98         ClearLastResult();
99
100         if (__pTabBarItemImpl == null)
101         {
102                 SysLog(NID_UI_CTRL, "[E_INVALID_STATE] This instance isn't constructed.");
103                 SetLastResult(E_INVALID_STATE);
104                 return -1;
105         }
106
107         SetLastResult(E_SUCCESS);
108         return __pTabBarItemImpl->GetActionId();
109 }
110
111 Tizen::Base::String
112 TabBarItem::GetText(void) const
113 {
114         ClearLastResult();
115
116         if (__pTabBarItemImpl == null)
117         {
118                 SysLog(NID_UI_CTRL, "[E_INVALID_STATE] This instance isn't constructed.");
119                 SetLastResult(E_INVALID_STATE);
120                 return Tizen::Base::String();
121         }
122
123         SetLastResult(E_SUCCESS);
124         return __pTabBarItemImpl->GetText();
125 }
126
127 result
128 TabBarItem::SetText(const Tizen::Base::String& text)
129 {
130         if (__pTabBarItemImpl == null)
131         {
132                 SysLog(NID_UI_CTRL, "[E_INVALID_STATE] This instance isn't constructed.");
133                 return E_INVALID_STATE;
134         }
135
136         __pTabBarItemImpl->SetText(text);
137
138         return E_SUCCESS;
139 }
140
141 } } } // Tizen::Ui::Controls