Changed indicator bg color.
[platform/framework/native/uifw.git] / src / ui / controls / FUiCtrlPanel.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         FUiCtrlPanel.cpp
20 * @brief        This is the implementation file for %Panel class.
21 *
22 */
23
24 #include <unique_ptr.h>
25 #include <FBaseErrors.h>
26 #include <FBaseSysLog.h>
27 #include <FUiCtrlPanel.h>
28 #include "FUi_CoordinateSystemUtils.h"
29 #include "FUi_UiBuilder.h"
30 #include "FUiCtrl_PanelImpl.h"
31 #include "FUiCtrl_Panel.h"
32
33 using namespace std;
34 using namespace Tizen::Graphics;
35
36 namespace Tizen { namespace Ui { namespace Controls
37 {
38
39 Panel::Panel(void)
40 {
41         // Nothing
42 }
43
44
45 Panel::~Panel(void)
46 {
47         // Nothing
48 }
49
50 result
51 Panel::Construct(const Rectangle& rect, GroupStyle groupStyle)
52 {
53         _PanelImpl* pImpl = _PanelImpl::GetInstance(*this);
54         SysAssertf(pImpl == null, "Already constructed! Calling Construct() twice or more on a same instance is not allowed for this class.");
55
56         FloatRectangle floatRect = _CoordinateSystemUtils::ConvertToFloat(rect);
57         pImpl = _PanelImpl::CreatePanelImplN(this, floatRect, groupStyle);
58         result r = GetLastResult();
59         SysTryCatch(NID_UI_CTRL, r != E_INVALID_ARG, , r, "[%s] A specified input parameter is invalid.", GetErrorMessage(r));
60         SysTryCatch(NID_UI_CTRL, r != E_OUT_OF_MEMORY, , r, "[%s] The memory is insufficient.", GetErrorMessage(r));
61         SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, r = E_SYSTEM, E_SYSTEM, "[%s] A system error has occurred.", GetErrorMessage(E_SYSTEM));
62
63         _pControlImpl = pImpl;
64
65         return r;
66
67 CATCH:
68         delete pImpl;
69
70         SetLastResult(r);
71         return r;
72
73 }
74
75 result
76 Panel::Construct(const FloatRectangle& rect, GroupStyle groupStyle)
77 {
78         _PanelImpl* pImpl = _PanelImpl::GetInstance(*this);
79         SysAssertf(pImpl == null, "Already constructed! Calling Construct() twice or more on a same instance is not allowed for this class.");
80
81         pImpl = _PanelImpl::CreatePanelImplN(this, rect, groupStyle);
82         result r = GetLastResult();
83         SysTryCatch(NID_UI_CTRL, r != E_INVALID_ARG, , r, "[%s] A specified input parameter is invalid.", GetErrorMessage(r));
84         SysTryCatch(NID_UI_CTRL, r != E_OUT_OF_MEMORY, , r, "[%s] The memory is insufficient.", GetErrorMessage(r));
85         SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, r = E_SYSTEM, E_SYSTEM, "[%s] A system error has occurred.", GetErrorMessage(E_SYSTEM));
86
87         _pControlImpl = pImpl;
88
89         return r;
90
91 CATCH:
92         delete pImpl;
93
94         SetLastResult(r);
95         return r;
96
97 }
98
99 result
100 Panel::Construct(const Tizen::Base::String& resourceId)
101 {
102         ClearLastResult();
103
104         // Parse UiBuilder XML file
105         unique_ptr<_UiBuilder> pBuilder(new _UiBuilder());
106         SysTryReturn(NID_UI_CTRL, pBuilder, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory is insufficient.", GetErrorMessage(E_OUT_OF_MEMORY));
107         result r = pBuilder->Construct(resourceId, this);
108         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
109         r = pBuilder->Parse();
110         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
111
112         return r;
113 }
114
115 result
116 Panel::Construct(const Layout& layout, const Rectangle& rect, GroupStyle groupStyle)
117 {
118         return Construct(layout, layout, rect, groupStyle);
119 }
120
121 result
122 Panel::Construct(const Layout& portraitLayout, const Layout& landscapeLayout, const Rectangle& rect, GroupStyle groupStyle)
123 {
124         _PanelImpl* pImpl = _PanelImpl::GetInstance(*this);
125         SysAssertf(pImpl == null, "Already constructed! Calling Construct() twice or more on a same instance is not allowed for this class.");
126
127         FloatRectangle floatRect = _CoordinateSystemUtils::ConvertToFloat(rect);
128         pImpl = _PanelImpl::CreatePanelImplN(this, floatRect, groupStyle, &(const_cast <Layout&>(portraitLayout)), &(const_cast <Layout&>(landscapeLayout)));
129         result r = GetLastResult();
130         SysTryCatch(NID_UI_CTRL, r != E_INVALID_ARG, , r, "[%s] A specified input parameter is invalid.", GetErrorMessage(r));
131         SysTryCatch(NID_UI_CTRL, r != E_OUT_OF_MEMORY, , r, "[%s] The memory is insufficient.", GetErrorMessage(r));
132         SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, r = E_SYSTEM, E_SYSTEM, "[%s] A system error has occurred.", GetErrorMessage(E_SYSTEM));
133
134         _pControlImpl = pImpl;
135
136         return r;
137
138 CATCH:
139         delete pImpl;
140
141         SetLastResult(r);
142         return r;
143 }
144
145 result
146 Panel::Construct(const Layout& layout, const FloatRectangle& rect, GroupStyle groupStyle)
147 {
148         return Construct(layout, layout, rect, groupStyle);
149 }
150
151 result
152 Panel::Construct(const Layout& portraitLayout, const Layout& landscapeLayout, const FloatRectangle& rect, GroupStyle groupStyle)
153 {
154         _PanelImpl* pImpl = _PanelImpl::GetInstance(*this);
155         SysAssertf(pImpl == null, "Already constructed! Calling Construct() twice or more on a same instance is not allowed for this class.");
156
157         pImpl = _PanelImpl::CreatePanelImplN(this, rect, groupStyle, &(const_cast <Layout&>(portraitLayout)), &(const_cast <Layout&>(landscapeLayout)));
158         result r = GetLastResult();
159         SysTryCatch(NID_UI_CTRL, r != E_INVALID_ARG, , r, "[%s] A specified input parameter is invalid.", GetErrorMessage(r));
160         SysTryCatch(NID_UI_CTRL, r != E_OUT_OF_MEMORY, , r, "[%s] The memory is insufficient.", GetErrorMessage(r));
161         SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, r = E_SYSTEM, E_SYSTEM, "[%s] A system error has occurred.", GetErrorMessage(E_SYSTEM));
162
163         _pControlImpl = pImpl;
164
165         return r;
166
167 CATCH:
168         delete pImpl;
169
170         SetLastResult(r);
171         return r;
172 }
173
174 Color
175 Panel::GetBackgroundColor(void) const
176 {
177         const _PanelImpl* pImpl = _PanelImpl::GetInstance(*this);
178         SysAssertf(pImpl != null, "Not-yet constructed! Construct() should be called before use.");
179
180         Color color = pImpl->GetBackgroundColor();
181         result r = GetLastResult();
182         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, Color(0, 0, 0, 0), E_SYSTEM, "[%s] A system error has occurred.", GetErrorMessage(E_SYSTEM));
183
184         return color;
185 }
186
187 void
188 Panel::SetBackgroundColor(const Color& color)
189 {
190         _PanelImpl* pImpl = _PanelImpl::GetInstance(*this);
191         SysAssertf(pImpl != null, "Not-yet constructed! Construct() should be called before use.");
192
193         pImpl->SetBackgroundColor(color);
194         result r = GetLastResult();
195         SysTryReturnVoidResult(NID_UI_CTRL, r == E_SUCCESS, E_SYSTEM, "[%s] A system error has occurred.", GetErrorMessage(E_SYSTEM));
196 }
197
198 result
199 Panel::SetCompositeEnabled(bool composite)
200 {
201         _PanelImpl* pImpl = _PanelImpl::GetInstance(*this);
202         SysAssertf(pImpl != null, "Not-yet constructed! Construct() should be called before use.");
203
204         result r = pImpl->SetCompositeEnabled(composite);
205         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, E_SYSTEM, E_SYSTEM, "[%s] A system error has occurred.", GetErrorMessage(E_SYSTEM));
206
207         return r;
208 }
209
210 bool
211 Panel::IsCompositeEnabled(void) const
212 {
213         const _PanelImpl* pImpl = _PanelImpl::GetInstance(*this);
214         SysAssertf(pImpl != null, "Not-yet constructed! Construct() should be called before use.");
215
216         return pImpl->IsCompositeEnabled();
217 }
218
219 DataBindingContext*
220 Panel::GetDataBindingContextN(void) const
221 {
222         const _PanelImpl* pImpl = _PanelImpl::GetInstance(*this);
223         SysAssertf(pImpl != null, "Not-yet constructed! Construct() should be called before use.");
224
225         return pImpl->GetDataBindingContextN();
226 }
227
228
229 }}} //Tizen::Ui::Controls
230