Tizen 2.1 base
[framework/osp/uifw.git] / src / ui / controls / FUiCtrlPopup.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                FUiCtrlPopup.cpp
20  * @brief       This is the implementation file for Popup class.
21  */
22
23 #include <unique_ptr.h>
24 #include <FUiCtrlPopup.h>
25 #include <FBaseSysLog.h>
26 #include "FUi_UiBuilder.h"
27 #include "FUiCtrl_PopupImpl.h"
28
29 using namespace std;
30
31 namespace Tizen { namespace Ui { namespace Controls
32 {
33
34
35 Popup::Popup(void)
36 {
37         //empty statement
38 }
39
40 Popup::~Popup(void)
41 {
42         //empty statement
43 }
44
45 result
46 Popup::Construct(bool hasTitle, const Tizen::Graphics::Dimension& dim)
47 {
48         result r = E_SUCCESS;
49
50         _PopupImpl* pPopupImpl = _PopupImpl::GetInstance(*this);
51         SysAssertf(pPopupImpl == null, "Already constructed. Calling Construct() twice or more on a same instance is not allowed for this class.");
52
53         pPopupImpl = _PopupImpl::CreatePopupImplN(this, dim);
54         r = GetLastResult();
55         SysTryReturn(NID_UI_CTRL, pPopupImpl != null, r, r, "[%s] Propagating.", GetErrorMessage(r));
56
57         // Set _PopupImpl
58         _pControlImpl = pPopupImpl;
59
60         r = pPopupImpl->Initialize(hasTitle, dim);
61         SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
62
63         return r;
64
65 CATCH:
66         delete pPopupImpl;
67
68         _pControlImpl = null;
69
70         return r;
71 }
72
73 result
74 Popup::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, "[E_OUT_OF_MEMORY] Memory is insufficient.");
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 Popup::Construct(const Tizen::Ui::Layout& layout, bool hasTitle, const Tizen::Graphics::Dimension& dim)
91 {
92         return Construct(layout, layout, hasTitle, dim);
93 }
94
95 result
96 Popup::Construct(const Tizen::Ui::Layout& portraitLayout, const Tizen::Ui::Layout& landscapeLayout,
97                                         bool hasTitle, const Tizen::Graphics::Dimension& dim)
98 {
99         result r = E_SUCCESS;
100
101         _PopupImpl* pPopupImpl = _PopupImpl::GetInstance(*this);
102         SysAssertf(pPopupImpl == null, "Already constructed. Calling Construct() twice or more on a same instance is not allowed for this class.");
103
104         pPopupImpl = _PopupImpl::CreatePopupImplN(this, dim,
105                                                                                                                  &(const_cast <Tizen::Ui::Layout&>(portraitLayout)),
106                                                                                                                  &(const_cast <Tizen::Ui::Layout&>(landscapeLayout)));
107
108         r = GetLastResult();
109         SysTryReturn(NID_UI_CTRL, pPopupImpl != null, r, r, "[%s] Propagating.", GetErrorMessage(r));
110
111         // Set _PopupImpl
112         _pControlImpl = pPopupImpl;
113
114         r = pPopupImpl->Initialize(hasTitle, dim);
115         SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
116
117         return r;
118
119 CATCH:
120         delete pPopupImpl;
121
122         return r;
123 }
124
125 result
126 Popup::DoModal(int& modalResult)
127 {
128         _PopupImpl* pPopupImpl = _PopupImpl::GetInstance(*this);
129         SysAssertf(pPopupImpl != null, "Not-yet constructed. Construct() should be called before use.");
130
131         return pPopupImpl->DoModal(modalResult);
132 }
133
134 result
135 Popup::EndModal(int modalResult)
136 {
137         _PopupImpl* pPopupImpl = _PopupImpl::GetInstance(*this);
138         SysAssertf(pPopupImpl != null, "Not-yet constructed. Construct() should be called before use.");
139
140         return pPopupImpl->EndModal(modalResult);
141 }
142
143 Tizen::Graphics::Rectangle
144 Popup::GetClientAreaBounds(void) const
145 {
146         const _PopupImpl* pPopupImpl = _PopupImpl::GetInstance(*this);
147         SysAssertf(pPopupImpl != null, "Not-yet constructed. Construct() should be called before use.");
148
149         return pPopupImpl->GetClientAreaBounds();
150 }
151
152 Tizen::Graphics::Canvas*
153 Popup::GetClientAreaCanvasN(void) const
154 {
155         const _PopupImpl* pPopupImpl = _PopupImpl::GetInstance(*this);
156         SysAssertf(pPopupImpl != null, "Not-yet constructed. Construct() should be called before use.");
157
158         return pPopupImpl->GetClientAreaCanvasN();
159 }
160
161 Tizen::Graphics::Point
162 Popup::TranslateToClientAreaPosition(const Tizen::Graphics::Point& position) const
163 {
164         const _PopupImpl* pPopupImpl = _PopupImpl::GetInstance(*this);
165         SysAssertf(pPopupImpl != null, "Not-yet constructed. Construct() should be called before use.");
166
167         return pPopupImpl->TranslateToClientAreaPosition(position);
168 }
169
170 Tizen::Graphics::Point
171 Popup::TranslateFromClientAreaPosition(const Tizen::Graphics::Point& clientPosition) const
172 {
173         const _PopupImpl* pPopupImpl = _PopupImpl::GetInstance(*this);
174         SysAssertf(pPopupImpl != null, "Not-yet constructed. Construct() should be called before use.");
175
176         return pPopupImpl->TranslateFromClientAreaPosition(clientPosition);
177 }
178
179 Tizen::Graphics::Color
180 Popup::GetColor(void) const
181 {
182         const _PopupImpl* pPopupImpl = _PopupImpl::GetInstance(*this);
183         SysAssertf(pPopupImpl != null, "Not-yet constructed. Construct() should be called before use.");
184
185         return pPopupImpl->GetColor();
186 }
187
188 result
189 Popup::SetColor(const Tizen::Graphics::Color& color)
190 {
191         _PopupImpl* pPopupImpl = _PopupImpl::GetInstance(*this);
192         SysAssertf(pPopupImpl != null, "Not-yet constructed. Construct() should be called before use.");
193
194         return pPopupImpl->SetColor(color);
195 }
196
197 Tizen::Base::String
198 Popup::GetTitleText(void) const
199 {
200         const _PopupImpl* pPopupImpl = _PopupImpl::GetInstance(*this);
201         SysAssertf(pPopupImpl != null, "Not-yet constructed. Construct() should be called before use.");
202
203         return pPopupImpl->GetTitleText();
204 }
205
206 result
207 Popup::SetTitleText(const Tizen::Base::String& title)
208 {
209         _PopupImpl* pPopupImpl = _PopupImpl::GetInstance(*this);
210         SysAssertf(pPopupImpl != null, "Not-yet constructed. Construct() should be called before use.");
211
212         result r = pPopupImpl->SetTitleText(title);
213         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[E_SYSTEM] A system error occurred.");
214
215         return E_SUCCESS;
216 }
217
218 Tizen::Graphics::Color
219 Popup::GetTitleTextColor(void) const
220 {
221         const _PopupImpl* pPopupImpl = _PopupImpl::GetInstance(*this);
222         SysAssertf(pPopupImpl != null, "Not-yet constructed. Construct() should be called before use.");
223
224         return pPopupImpl->GetTitleTextColor();
225 }
226
227 result
228 Popup::SetTitleTextColor(const Tizen::Graphics::Color& color)
229 {
230         _PopupImpl* pPopupImpl = _PopupImpl::GetInstance(*this);
231         SysAssertf(pPopupImpl != null, "Not-yet constructed. Construct() should be called before use.");
232
233         return pPopupImpl->SetTitleTextColor(color);
234 }
235
236 DataBindingContext*
237 Popup::GetDataBindingContextN(void) const
238 {
239         const _PopupImpl* pPopupImpl = _PopupImpl::GetInstance(*this);
240         SysAssertf(pPopupImpl != null, "Not-yet constructed. Construct() should be called before use.");
241
242         return pPopupImpl->GetDataBindingContextN();
243 }
244
245
246 }}} // Tizen::Ui::Controls