Tizen 2.1 base
[framework/osp/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 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 /**
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_UiBuilder.h"
29 #include "FUiCtrl_PanelImpl.h"
30 #include "FUiCtrl_Panel.h"
31
32 using namespace std;
33 using namespace Tizen::Graphics;
34
35 namespace Tizen { namespace Ui { namespace Controls
36 {
37
38 Panel::Panel(void)
39 {
40         // Nothing
41 }
42
43
44 Panel::~Panel(void)
45 {
46         // Nothing
47 }
48
49 result
50 Panel::Construct(const Rectangle& rect, GroupStyle groupStyle)
51 {
52         _PanelImpl* pImpl = _PanelImpl::GetInstance(*this);
53         SysAssertf(pImpl == null, "Already constructed! Calling Construct() twice or more on a same instance is not allowed for this class.");
54
55         pImpl = _PanelImpl::CreatePanelImplN(this, rect, groupStyle);
56         result r = GetLastResult();
57         SysTryCatch(NID_UI_CTRL, r != E_INVALID_ARG, , r, "[%s] A specified input parameter is invalid.", GetErrorMessage(r));
58         SysTryCatch(NID_UI_CTRL, r != E_OUT_OF_MEMORY, , r, "[%s] The memory is insufficient.", GetErrorMessage(r));
59         SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, r = E_SYSTEM, E_SYSTEM, "[%s] A system error has occurred.", GetErrorMessage(E_SYSTEM));
60
61         _pControlImpl = pImpl;
62
63         return r;
64
65 CATCH:
66         delete pImpl;
67
68         SetLastResult(r);
69         return r;
70
71 }
72
73 result
74 Panel::Construct(const Tizen::Base::String& resourceId)
75 {
76         ClearLastResult();
77
78         // Parse UiBuilder XML file
79         unique_ptr<_UiBuilder> pBuilder(new _UiBuilder());
80         SysTryReturn(NID_UI_CTRL, pBuilder, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory is insufficient.", GetErrorMessage(E_OUT_OF_MEMORY));
81         result r = pBuilder->Construct(resourceId, this);
82         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
83         r = pBuilder->Parse();
84         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
85
86         return r;
87 }
88
89 result
90 Panel::Construct(const Layout& layout, const Rectangle& rect, GroupStyle groupStyle)
91 {
92         return Construct(layout, layout, rect, groupStyle);
93 }
94
95 result
96 Panel::Construct(const Layout& portraitLayout, const Layout& landscapeLayout, const Rectangle& rect, GroupStyle groupStyle)
97 {
98         _PanelImpl* pImpl = _PanelImpl::GetInstance(*this);
99         SysAssertf(pImpl == null, "Already constructed! Calling Construct() twice or more on a same instance is not allowed for this class.");
100
101         pImpl = _PanelImpl::CreatePanelImplN(this, rect, groupStyle, &(const_cast <Layout&>(portraitLayout)), &(const_cast <Layout&>(landscapeLayout)));
102         result r = GetLastResult();
103         SysTryCatch(NID_UI_CTRL, r != E_INVALID_ARG, , r, "[%s] A specified input parameter is invalid.", GetErrorMessage(r));
104         SysTryCatch(NID_UI_CTRL, r != E_OUT_OF_MEMORY, , r, "[%s] The memory is insufficient.", GetErrorMessage(r));
105         SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, r = E_SYSTEM, E_SYSTEM, "[%s] A system error has occurred.", GetErrorMessage(E_SYSTEM));
106
107         _pControlImpl = pImpl;
108
109         return r;
110
111 CATCH:
112         delete pImpl;
113
114         SetLastResult(r);
115         return r;
116 }
117
118 Color
119 Panel::GetBackgroundColor(void) const
120 {
121         const _PanelImpl* pImpl = _PanelImpl::GetInstance(*this);
122         SysAssertf(pImpl != null, "Not-yet constructed! Construct() should be called before use.");
123
124         Color color = pImpl->GetBackgroundColor();
125         result r = GetLastResult();
126         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, Color(0, 0, 0, 0), E_SYSTEM, "[%s] A system error has occurred.", GetErrorMessage(E_SYSTEM));
127
128         return color;
129 }
130
131 void
132 Panel::SetBackgroundColor(const Color& color)
133 {
134         _PanelImpl* pImpl = _PanelImpl::GetInstance(*this);
135         SysAssertf(pImpl != null, "Not-yet constructed! Construct() should be called before use.");
136
137         pImpl->SetBackgroundColor(color);
138         result r = GetLastResult();
139         SysTryReturnVoidResult(NID_UI_CTRL, r == E_SUCCESS, E_SYSTEM, "[%s] A system error has occurred.", GetErrorMessage(E_SYSTEM));
140 }
141
142 result
143 Panel::SetCompositeEnabled(bool composite)
144 {
145         _PanelImpl* pImpl = _PanelImpl::GetInstance(*this);
146         SysAssertf(pImpl != null, "Not-yet constructed! Construct() should be called before use.");
147
148         result r = pImpl->SetCompositeEnabled(composite);
149         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, E_SYSTEM, E_SYSTEM, "[%s] A system error has occurred.", GetErrorMessage(E_SYSTEM));
150
151         return r;
152 }
153
154 bool
155 Panel::IsCompositeEnabled(void) const
156 {
157         const _PanelImpl* pImpl = _PanelImpl::GetInstance(*this);
158         SysAssertf(pImpl != null, "Not-yet constructed! Construct() should be called before use.");
159
160         return pImpl->IsCompositeEnabled();
161 }
162
163 DataBindingContext*
164 Panel::GetDataBindingContextN(void) const
165 {
166         const _PanelImpl* pImpl = _PanelImpl::GetInstance(*this);
167         if (pImpl == null)
168         {
169                 return null;
170         }
171         return pImpl->GetDataBindingContextN();
172 }
173
174
175 }}} //Tizen::Ui::Controls
176