Tizen 2.1 base
[framework/osp/uifw.git] / src / ui / controls / FUiCtrlScrollPanel.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        FUiCtrlScrollPanel.cpp
20 * @brief        This is the implementation for the %ScrollPanel class.
21  *
22  */
23
24 #include <unique_ptr.h>
25 #include <FBaseSysLog.h>
26 #include <FUiCtrlScrollPanel.h>
27 #include "FUi_UiBuilder.h"
28 #include "FUiCtrl_ScrollPanelImpl.h"
29
30 using namespace std;
31 using namespace Tizen::Graphics;
32
33 namespace Tizen { namespace Ui { namespace Controls
34 {
35
36 ScrollPanel::ScrollPanel(void)
37 {
38         // Nothing
39 }
40
41
42 ScrollPanel::~ScrollPanel(void)
43 {
44         // Nothing
45 }
46
47 result
48 ScrollPanel::Construct(const Rectangle& rect)
49 {
50         result r = Construct(rect, SCROLL_PANEL_SCROLL_DIRECTION_VERTICAL, true);
51
52         return r;
53 }
54
55 result
56 ScrollPanel::Construct(const Rectangle& rect, ScrollPanelScrollDirection scrollDirection, bool autoResizingEnable)
57 {
58         _ScrollPanelImpl* pImpl = _ScrollPanelImpl::GetInstance(*this);
59         SysAssertf(pImpl == null, "Already constructed! Calling Construct() twice or more on a same instance is not allowed for this class.");
60
61         pImpl = _ScrollPanelImpl::CreateScrollPanelImplN(this, rect, scrollDirection, autoResizingEnable);
62         result r = GetLastResult();
63         SysTryCatch(NID_UI_CTRL, r != E_INVALID_ARG, , r, "[%s] The given width or height is less than 0.", GetErrorMessage(r));
64         SysTryCatch(NID_UI_CTRL, r != E_OUT_OF_MEMORY, , r, "[%s] The memory is insufficient.", GetErrorMessage(r));
65         SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, r = E_SYSTEM, E_SYSTEM, "[%s] A system error has occurred.", GetErrorMessage(E_SYSTEM));
66
67         _pControlImpl = pImpl;
68
69         return r;
70
71 CATCH:
72         delete pImpl;
73
74         SetLastResult(r);
75         return r;
76 }
77
78 result
79 ScrollPanel::Construct(const Tizen::Base::String& resourceId)
80 {
81         ClearLastResult();
82
83         // Parse UiBuilder XML file
84         unique_ptr<_UiBuilder> pBuilder(new _UiBuilder());
85         SysTryReturn(NID_UI_CTRL, pBuilder, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory is insufficient.", GetErrorMessage(E_OUT_OF_MEMORY));
86         result r = pBuilder->Construct(resourceId, this);
87         SysTryReturn(NID_UI_CTRL, r != E_OUT_OF_MEMORY, r, r, "[%s] The memory is insufficient.", GetErrorMessage(r));
88         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
89         r = pBuilder->Parse();
90         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
91
92         return r;
93 }
94
95 result
96 ScrollPanel::Construct(const Layout& layout, const Rectangle& rect)
97 {
98         result r = Construct(layout, layout, rect, SCROLL_PANEL_SCROLL_DIRECTION_VERTICAL, true);
99
100         return r;
101 }
102
103 result
104 ScrollPanel::Construct(const Layout& layout, const Rectangle& rect, ScrollPanelScrollDirection scrollDirection, bool autoResizingEnable)
105 {
106         result r = Construct(layout, layout, rect, scrollDirection, autoResizingEnable);
107
108         return r;
109 }
110
111 result
112 ScrollPanel::Construct(const Layout& portraitLayout, const Layout& landscapeLayout, const Rectangle& rect)
113 {
114         result r = Construct(portraitLayout, landscapeLayout, rect, SCROLL_PANEL_SCROLL_DIRECTION_VERTICAL, true);
115
116         return r;
117 }
118
119 result
120 ScrollPanel::Construct(const Layout& portraitLayout, const Layout& landscapeLayout, const Rectangle& rect, ScrollPanelScrollDirection scrollDirection, bool autoResizingEnable)
121 {
122         _ScrollPanelImpl* pImpl = _ScrollPanelImpl::GetInstance(*this);
123         SysAssertf(pImpl == null, "Already constructed! Calling Construct() twice or more on a same instance is not allowed for this class.");
124
125         pImpl = _ScrollPanelImpl::CreateScrollPanelImplN(this, rect, scrollDirection, autoResizingEnable, &(const_cast <Layout&>(portraitLayout)), &(const_cast <Layout&>(landscapeLayout)));
126         result r = GetLastResult();
127         SysTryCatch(NID_UI_CTRL, r != E_INVALID_ARG, , r, "[%s] portraitLayout or landscapeLayout is already bound to another container, or the given width or height is less than 0.", GetErrorMessage(r));
128         SysTryCatch(NID_UI_CTRL, r != E_OUT_OF_MEMORY, , r, "[%s] The memory is insufficient.", GetErrorMessage(r));
129         SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, r = E_SYSTEM, E_SYSTEM, "[%s] A system error has occurred.", GetErrorMessage(E_SYSTEM));
130
131         _pControlImpl = pImpl;
132
133         return r;
134
135 CATCH:
136         delete pImpl;
137
138         SetLastResult(r);
139         return r;
140 }
141
142 void
143 ScrollPanel::AddScrollEventListener(IScrollEventListener& listener)
144 {
145         _ScrollPanelImpl* pImpl = _ScrollPanelImpl::GetInstance(*this);
146         SysAssertf(pImpl != null, "Not-yet constructed! Construct() should be called before use.");
147
148         pImpl->AddScrollEventListener(listener);
149 }
150
151 void
152 ScrollPanel::RemoveScrollEventListener(IScrollEventListener& listener)
153 {
154         _ScrollPanelImpl* pImpl = _ScrollPanelImpl::GetInstance(*this);
155         SysAssertf(pImpl != null, "Not-yet constructed! Construct() should be called before use.");
156
157         pImpl->RemoveScrollEventListener(listener);
158 }
159
160 int
161 ScrollPanel::GetScrollPosition(void) const
162 {
163         const _ScrollPanelImpl* pImpl = _ScrollPanelImpl::GetInstance(*this);
164         SysAssertf(pImpl != null, "Not-yet constructed! Construct() should be called before use.");
165
166         return pImpl->GetScrollPosition();
167 }
168
169 void
170 ScrollPanel::SetScrollPosition(int position)
171 {
172         _ScrollPanelImpl* pImpl = _ScrollPanelImpl::GetInstance(*this);
173         SysAssertf(pImpl != null, "Not-yet constructed! Construct() should be called before use.");
174
175         pImpl->SetScrollPosition(position, false);
176 }
177
178 void
179 ScrollPanel::SetScrollPosition(int position, bool withAnimation)
180 {
181         _ScrollPanelImpl* pImpl = _ScrollPanelImpl::GetInstance(*this);
182         SysAssertf(pImpl != null, "Not-yet constructed! Construct() should be called before use.");
183
184         pImpl->SetScrollPosition(position, withAnimation);
185 }
186
187 void
188 ScrollPanel::ScrollToBottom(void) const
189 {
190         const _ScrollPanelImpl* pImpl = _ScrollPanelImpl::GetInstance(*this);
191         SysAssertf(pImpl != null, "Not-yet constructed! Construct() should be called before use.");
192
193         pImpl->ScrollToBottom();
194 }
195
196 void
197 ScrollPanel::ScrollToTop(void) const
198 {
199         const _ScrollPanelImpl* pImpl = _ScrollPanelImpl::GetInstance(*this);
200         SysAssertf(pImpl != null, "Not-yet constructed! Construct() should be called before use.");
201
202         pImpl->ScrollToTop();
203 }
204
205 result
206 ScrollPanel::CloseOverlayWindow(void)
207 {
208         _ScrollPanelImpl* pImpl = _ScrollPanelImpl::GetInstance(*this);
209         SysAssertf(pImpl != null, "Not-yet constructed! Construct() should be called before use.");
210
211         result r = pImpl->CloseOverlayWindow();
212         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, E_SYSTEM, E_SYSTEM, "[%s] A system error has occurred.", GetErrorMessage(E_SYSTEM));
213
214         return r;
215 }
216
217 Rectangle
218 ScrollPanel::GetClientAreaBounds(void) const
219 {
220         const _ScrollPanelImpl* pImpl = _ScrollPanelImpl::GetInstance(*this);
221         SysAssertf(pImpl != null, "Not-yet constructed! Construct() should be called before use.");
222
223         return pImpl->GetClientAreaBounds();
224 }
225
226 result
227 ScrollPanel::SetClientAreaWidth(int width)
228 {
229         _ScrollPanelImpl* pImpl = _ScrollPanelImpl::GetInstance(*this);
230         SysAssertf(pImpl != null, "Not-yet constructed! Construct() should be called before use.");
231
232         result r = pImpl->SetClientAreaWidth(width);
233         SysTryReturn(NID_UI_CTRL, r != E_INVALID_ARG, r, r, "[%s] width is less than the width of ScrollPanel.", GetErrorMessage(r));
234         SysTryReturn(NID_UI_CTRL, r != E_INVALID_OPERATION, r, r, "[%s] The width of the client area cannot be set when auto resizing of the client area is off, or the scroll direction is vertical.", GetErrorMessage(r));
235         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, E_SYSTEM, E_SYSTEM, "[%s] A system error has occurred.", GetErrorMessage(E_SYSTEM));
236
237         return r;
238 }
239
240 result
241 ScrollPanel::SetClientAreaHeight(int height)
242 {
243         _ScrollPanelImpl* pImpl = _ScrollPanelImpl::GetInstance(*this);
244         SysAssertf(pImpl != null, "Not-yet constructed! Construct() should be called before use.");
245
246         result r = pImpl->SetClientAreaHeight(height);
247         SysTryReturn(NID_UI_CTRL, r != E_INVALID_ARG, r, r, "[%s] height is less than the height of ScrollPanel.", GetErrorMessage(r));
248         SysTryReturn(NID_UI_CTRL, r != E_INVALID_OPERATION, r, r, "[%s] The height of the client area cannot be set when auto resizing of the client area is off, or the scroll direction is horizontal.", GetErrorMessage(r));
249         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, E_SYSTEM, E_SYSTEM, "[%s] A system error has occurred.", GetErrorMessage(E_SYSTEM));
250
251         return r;
252 }
253
254 ScrollPanelScrollDirection
255 ScrollPanel::GetScrollDirection(void) const
256 {
257         const _ScrollPanelImpl* pImpl = _ScrollPanelImpl::GetInstance(*this);
258         SysAssertf(pImpl != null, "Not-yet constructed! Construct() should be called before use.");
259
260         return pImpl->GetScrollDirection();
261 }
262
263 bool
264 ScrollPanel::IsScrollAreaAutoResizingEnabled(void) const
265 {
266         const _ScrollPanelImpl* pImpl = _ScrollPanelImpl::GetInstance(*this);
267         SysAssertf(pImpl != null, "Not-yet constructed! Construct() should be called before use.");
268
269         return pImpl->IsScrollAreaAutoResizingEnabled();
270 }
271
272 void
273 ScrollPanel::SetPageScrollEnabled(bool enable)
274 {
275         _ScrollPanelImpl* pImpl = _ScrollPanelImpl::GetInstance(*this);
276         SysAssertf(pImpl != null, "Not-yet constructed! Construct() should be called before use.");
277
278         pImpl->SetPageScrollEnabled(enable);
279 }
280
281 bool
282 ScrollPanel::IsPageScrollEnabled(void) const
283 {
284         const _ScrollPanelImpl* pImpl = _ScrollPanelImpl::GetInstance(*this);
285         SysAssertf(pImpl != null, "Not-yet constructed! Construct() should be called before use.");
286
287         return pImpl->IsPageScrollEnabled();
288 }
289
290 void
291 ScrollPanel::SetScrollBarVisible(bool visible)
292 {
293         _ScrollPanelImpl* pImpl = _ScrollPanelImpl::GetInstance(*this);
294         SysAssertf(pImpl != null, "Not-yet constructed! Construct() should be called before use.");
295
296         pImpl->SetScrollBarVisible(visible);
297 }
298
299 bool
300 ScrollPanel::IsScrollBarVisible(void) const
301 {
302         const _ScrollPanelImpl* pImpl = _ScrollPanelImpl::GetInstance(*this);
303         SysAssertf(pImpl != null, "Not-yet constructed! Construct() should be called before use.");
304
305         return pImpl->IsScrollBarVisible();
306 }
307
308 void
309 ScrollPanel::SetScrollInputMode(ScrollInputMode mode)
310 {
311         _ScrollPanelImpl* pImpl = _ScrollPanelImpl::GetInstance(*this);
312         SysAssertf(pImpl != null, "Not-yet constructed! Construct() should be called before use.");
313
314         pImpl->SetScrollInputMode(mode);
315 }
316
317 ScrollInputMode
318 ScrollPanel::GetScrollInputMode(void) const
319 {
320         const _ScrollPanelImpl* pImpl = _ScrollPanelImpl::GetInstance(*this);
321         SysAssertf(pImpl != null, "Not-yet constructed! Construct() should be called before use.");
322
323         return pImpl->GetScrollInputMode();
324 }
325
326 }}} // Tizen::Ui::Controls
327