Changed indicator bg color.
[platform/framework/native/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 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        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_CoordinateSystemUtils.h"
28 #include "FUi_UiBuilder.h"
29 #include "FUiCtrl_ScrollPanelImpl.h"
30
31 using namespace std;
32 using namespace Tizen::Graphics;
33
34 namespace Tizen { namespace Ui { namespace Controls
35 {
36
37 ScrollPanel::ScrollPanel(void)
38 {
39         // Nothing
40 }
41
42
43 ScrollPanel::~ScrollPanel(void)
44 {
45         // Nothing
46 }
47
48 result
49 ScrollPanel::Construct(const Rectangle& rect)
50 {
51         result r = Construct(rect, SCROLL_PANEL_SCROLL_DIRECTION_VERTICAL, true);
52
53         return r;
54 }
55
56 result
57 ScrollPanel::Construct(const Tizen::Graphics::FloatRectangle& rect)
58 {
59         result r = Construct(rect, SCROLL_PANEL_SCROLL_DIRECTION_VERTICAL, true);
60
61         return r;
62 }
63
64 result
65 ScrollPanel::Construct(const Tizen::Base::String& resourceId)
66 {
67         ClearLastResult();
68
69         // Parse UiBuilder XML file
70         unique_ptr<_UiBuilder> pBuilder(new _UiBuilder());
71         SysTryReturn(NID_UI_CTRL, pBuilder, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory is insufficient.", GetErrorMessage(E_OUT_OF_MEMORY));
72         result r = pBuilder->Construct(resourceId, this);
73         SysTryReturn(NID_UI_CTRL, r != E_OUT_OF_MEMORY, r, r, "[%s] The memory is insufficient.", GetErrorMessage(r));
74         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
75         r = pBuilder->Parse();
76         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
77
78         return r;
79 }
80
81 result
82 ScrollPanel::Construct(const Rectangle& rect, ScrollPanelScrollDirection scrollDirection, bool autoResizingEnable)
83 {
84         _ScrollPanelImpl* pImpl = _ScrollPanelImpl::GetInstance(*this);
85         SysAssertf(pImpl == null, "Already constructed! Calling Construct() twice or more on a same instance is not allowed for this class.");
86
87         FloatRectangle floatRect = _CoordinateSystemUtils::ConvertToFloat(rect);
88         pImpl = _ScrollPanelImpl::CreateScrollPanelImplN(this, floatRect, scrollDirection, autoResizingEnable);
89         result r = GetLastResult();
90         SysTryCatch(NID_UI_CTRL, r != E_INVALID_ARG, , r, "[%s] The given width or height is less than 0.", GetErrorMessage(r));
91         SysTryCatch(NID_UI_CTRL, r != E_OUT_OF_MEMORY, , r, "[%s] The memory is insufficient.", GetErrorMessage(r));
92         SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, r = E_SYSTEM, E_SYSTEM, "[%s] A system error has occurred.", GetErrorMessage(E_SYSTEM));
93
94         _pControlImpl = pImpl;
95
96         return r;
97
98 CATCH:
99         delete pImpl;
100
101         SetLastResult(r);
102         return r;
103 }
104
105 result
106 ScrollPanel::Construct(const Tizen::Graphics::FloatRectangle& rect, ScrollPanelScrollDirection scrollDirection, bool autoResizingEnable)
107 {
108         _ScrollPanelImpl* pImpl = _ScrollPanelImpl::GetInstance(*this);
109         SysAssertf(pImpl == null, "Already constructed! Calling Construct() twice or more on a same instance is not allowed for this class.");
110
111         pImpl = _ScrollPanelImpl::CreateScrollPanelImplN(this, rect, scrollDirection, autoResizingEnable);
112         result r = GetLastResult();
113         SysTryCatch(NID_UI_CTRL, r != E_INVALID_ARG, , r, "[%s] The given width or height is less than 0.", GetErrorMessage(r));
114         SysTryCatch(NID_UI_CTRL, r != E_OUT_OF_MEMORY, , r, "[%s] The memory is insufficient.", GetErrorMessage(r));
115         SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, r = E_SYSTEM, E_SYSTEM, "[%s] A system error has occurred.", GetErrorMessage(E_SYSTEM));
116
117         _pControlImpl = pImpl;
118
119         return r;
120
121 CATCH:
122         delete pImpl;
123
124         SetLastResult(r);
125         return r;
126 }
127
128 result
129 ScrollPanel::Construct(const Layout& layout, const Rectangle& rect)
130 {
131         result r = Construct(layout, layout, rect, SCROLL_PANEL_SCROLL_DIRECTION_VERTICAL, true);
132
133         return r;
134 }
135
136 result
137 ScrollPanel::Construct(const Tizen::Ui::Layout& layout, const Tizen::Graphics::FloatRectangle& rect)
138 {
139         result r = Construct(layout, layout, rect, SCROLL_PANEL_SCROLL_DIRECTION_VERTICAL, true);
140
141         return r;
142 }
143
144 result
145 ScrollPanel::Construct(const Layout& layout, const Rectangle& rect, ScrollPanelScrollDirection scrollDirection, bool autoResizingEnable)
146 {
147         result r = Construct(layout, layout, rect, scrollDirection, autoResizingEnable);
148
149         return r;
150 }
151
152 result
153 ScrollPanel::Construct(const Tizen::Ui::Layout& layout, const Tizen::Graphics::FloatRectangle& rect, ScrollPanelScrollDirection scrollDirection, bool autoResizingEnable)
154 {
155         result r = Construct(layout, layout, rect, scrollDirection, autoResizingEnable);
156
157         return r;
158 }
159
160 result
161 ScrollPanel::Construct(const Layout& portraitLayout, const Layout& landscapeLayout, const Rectangle& rect)
162 {
163         result r = Construct(portraitLayout, landscapeLayout, rect, SCROLL_PANEL_SCROLL_DIRECTION_VERTICAL, true);
164
165         return r;
166 }
167
168 result
169 ScrollPanel::Construct(const Tizen::Ui::Layout& portraitLayout, const Tizen::Ui::Layout& landscapeLayout, const Tizen::Graphics::FloatRectangle& rect)
170 {
171         result r = Construct(portraitLayout, landscapeLayout, rect, SCROLL_PANEL_SCROLL_DIRECTION_VERTICAL, true);
172
173         return r;
174 }
175
176
177 result
178 ScrollPanel::Construct(const Layout& portraitLayout, const Layout& landscapeLayout, const Rectangle& rect, ScrollPanelScrollDirection scrollDirection, bool autoResizingEnable)
179 {
180         _ScrollPanelImpl* pImpl = _ScrollPanelImpl::GetInstance(*this);
181         SysAssertf(pImpl == null, "Already constructed! Calling Construct() twice or more on a same instance is not allowed for this class.");
182
183         FloatRectangle floatRect = _CoordinateSystemUtils::ConvertToFloat(rect);
184         pImpl = _ScrollPanelImpl::CreateScrollPanelImplN(this, floatRect, scrollDirection, autoResizingEnable, &(const_cast <Layout&>(portraitLayout)), &(const_cast <Layout&>(landscapeLayout)));
185         result r = GetLastResult();
186         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));
187         SysTryCatch(NID_UI_CTRL, r != E_OUT_OF_MEMORY, , r, "[%s] The memory is insufficient.", GetErrorMessage(r));
188         SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, r = E_SYSTEM, E_SYSTEM, "[%s] A system error has occurred.", GetErrorMessage(E_SYSTEM));
189
190         _pControlImpl = pImpl;
191
192         return r;
193
194 CATCH:
195         delete pImpl;
196
197         SetLastResult(r);
198         return r;
199 }
200
201 result
202 ScrollPanel::Construct(const Tizen::Ui::Layout& portraitLayout, const Tizen::Ui::Layout& landscapeLayout, const Tizen::Graphics::FloatRectangle& rect, ScrollPanelScrollDirection scrollDirection, bool autoResizingEnable)
203 {
204         _ScrollPanelImpl* pImpl = _ScrollPanelImpl::GetInstance(*this);
205         SysAssertf(pImpl == null, "Already constructed! Calling Construct() twice or more on a same instance is not allowed for this class.");
206
207         pImpl = _ScrollPanelImpl::CreateScrollPanelImplN(this, rect, scrollDirection, autoResizingEnable, &(const_cast <Layout&>(portraitLayout)), &(const_cast <Layout&>(landscapeLayout)));
208         result r = GetLastResult();
209         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));
210         SysTryCatch(NID_UI_CTRL, r != E_OUT_OF_MEMORY, , r, "[%s] The memory is insufficient.", GetErrorMessage(r));
211         SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, r = E_SYSTEM, E_SYSTEM, "[%s] A system error has occurred.", GetErrorMessage(E_SYSTEM));
212
213         _pControlImpl = pImpl;
214
215         return r;
216
217 CATCH:
218         delete pImpl;
219
220         SetLastResult(r);
221         return r;
222 }
223
224 void
225 ScrollPanel::AddScrollEventListener(IScrollEventListener& listener)
226 {
227         _ScrollPanelImpl* pImpl = _ScrollPanelImpl::GetInstance(*this);
228         SysAssertf(pImpl != null, "Not-yet constructed! Construct() should be called before use.");
229
230         pImpl->AddScrollEventListener(listener);
231 }
232
233 void
234 ScrollPanel::AddScrollEventListener(IScrollEventListenerF& listener)
235 {
236         _ScrollPanelImpl* pImpl = _ScrollPanelImpl::GetInstance(*this);
237         SysAssertf(pImpl != null, "Not-yet constructed! Construct() should be called before use.");
238
239         pImpl->AddScrollEventListener(listener);
240 }
241
242 void
243 ScrollPanel::RemoveScrollEventListener(IScrollEventListener& listener)
244 {
245         _ScrollPanelImpl* pImpl = _ScrollPanelImpl::GetInstance(*this);
246         SysAssertf(pImpl != null, "Not-yet constructed! Construct() should be called before use.");
247
248         pImpl->RemoveScrollEventListener(listener);
249 }
250
251 void
252 ScrollPanel::RemoveScrollEventListener(IScrollEventListenerF& listener)
253 {
254         _ScrollPanelImpl* pImpl = _ScrollPanelImpl::GetInstance(*this);
255         SysAssertf(pImpl != null, "Not-yet constructed! Construct() should be called before use.");
256
257         pImpl->RemoveScrollEventListener(listener);
258 }
259
260 int
261 ScrollPanel::GetScrollPosition(void) const
262 {
263         const _ScrollPanelImpl* pImpl = _ScrollPanelImpl::GetInstance(*this);
264         SysAssertf(pImpl != null, "Not-yet constructed! Construct() should be called before use.");
265
266         float position = pImpl->GetScrollPosition();
267         return _CoordinateSystemUtils::ConvertToInteger(position);
268 }
269
270 float
271 ScrollPanel::GetScrollPositionF(void) const
272 {
273         const _ScrollPanelImpl* pImpl = _ScrollPanelImpl::GetInstance(*this);
274         SysAssertf(pImpl != null, "Not-yet constructed! Construct() should be called before use.");
275
276         return pImpl->GetScrollPosition();
277 }
278
279 void
280 ScrollPanel::SetScrollPosition(int position)
281 {
282         _ScrollPanelImpl* pImpl = _ScrollPanelImpl::GetInstance(*this);
283         SysAssertf(pImpl != null, "Not-yet constructed! Construct() should be called before use.");
284
285         float floatPosition = _CoordinateSystemUtils::ConvertToFloat(position);
286         pImpl->SetScrollPosition(floatPosition, false);
287 }
288
289 void
290 ScrollPanel::SetScrollPosition(int position, bool withAnimation)
291 {
292         _ScrollPanelImpl* pImpl = _ScrollPanelImpl::GetInstance(*this);
293         SysAssertf(pImpl != null, "Not-yet constructed! Construct() should be called before use.");
294
295         float floatPosition = _CoordinateSystemUtils::ConvertToFloat(position);
296         pImpl->SetScrollPosition(floatPosition, withAnimation);
297 }
298
299 void
300 ScrollPanel::SetScrollPosition(float position, bool withAnimation)
301 {
302         _ScrollPanelImpl* pImpl = _ScrollPanelImpl::GetInstance(*this);
303         SysAssertf(pImpl != null, "Not-yet constructed! Construct() should be called before use.");
304
305         pImpl->SetScrollPosition(position, withAnimation);
306 }
307
308 void
309 ScrollPanel::ScrollToBottom(void) const
310 {
311         const _ScrollPanelImpl* pImpl = _ScrollPanelImpl::GetInstance(*this);
312         SysAssertf(pImpl != null, "Not-yet constructed! Construct() should be called before use.");
313
314         pImpl->ScrollToBottom();
315 }
316
317 void
318 ScrollPanel::ScrollToTop(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         pImpl->ScrollToTop();
324 }
325
326 result
327 ScrollPanel::CloseOverlayWindow(void)
328 {
329         _ScrollPanelImpl* pImpl = _ScrollPanelImpl::GetInstance(*this);
330         SysAssertf(pImpl != null, "Not-yet constructed! Construct() should be called before use.");
331
332         result r = pImpl->CloseOverlayWindow();
333         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, E_SYSTEM, E_SYSTEM, "[%s] A system error has occurred.", GetErrorMessage(E_SYSTEM));
334
335         return r;
336 }
337
338 Rectangle
339 ScrollPanel::GetClientAreaBounds(void) const
340 {
341         const _ScrollPanelImpl* pImpl = _ScrollPanelImpl::GetInstance(*this);
342         SysAssertf(pImpl != null, "Not-yet constructed! Construct() should be called before use.");
343
344         FloatRectangle floatRect = pImpl->GetClientAreaBounds();
345         return _CoordinateSystemUtils::ConvertToInteger(floatRect);
346 }
347
348 FloatRectangle
349 ScrollPanel::GetClientAreaBoundsF(void) const
350 {
351         const _ScrollPanelImpl* pImpl = _ScrollPanelImpl::GetInstance(*this);
352         SysAssertf(pImpl != null, "Not-yet constructed! Construct() should be called before use.");
353
354         return pImpl->GetClientAreaBounds();
355 }
356
357 result
358 ScrollPanel::SetClientAreaWidth(int width)
359 {
360         _ScrollPanelImpl* pImpl = _ScrollPanelImpl::GetInstance(*this);
361         SysAssertf(pImpl != null, "Not-yet constructed! Construct() should be called before use.");
362
363         float floatWidth = _CoordinateSystemUtils::ConvertToFloat(width);
364         result r = pImpl->SetClientAreaWidth(floatWidth);
365         SysTryReturn(NID_UI_CTRL, r != E_INVALID_ARG, r, r, "[%s] width is less than the width of ScrollPanel.", GetErrorMessage(r));
366         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 on, or the scroll direction is vertical.", GetErrorMessage(r));
367         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, E_SYSTEM, E_SYSTEM, "[%s] A system error has occurred.", GetErrorMessage(E_SYSTEM));
368
369         return r;
370 }
371
372 result
373 ScrollPanel::SetClientAreaWidth(float width)
374 {
375         _ScrollPanelImpl* pImpl = _ScrollPanelImpl::GetInstance(*this);
376         SysAssertf(pImpl != null, "Not-yet constructed! Construct() should be called before use.");
377
378         result r = pImpl->SetClientAreaWidth(width);
379         SysTryReturn(NID_UI_CTRL, r != E_INVALID_ARG, r, r, "[%s] width is less than the width of ScrollPanel.", GetErrorMessage(r));
380         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 on, or the scroll direction is vertical.", GetErrorMessage(r));
381         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, E_SYSTEM, E_SYSTEM, "[%s] A system error has occurred.", GetErrorMessage(E_SYSTEM));
382
383         return r;
384 }
385
386 result
387 ScrollPanel::SetClientAreaHeight(int height)
388 {
389         _ScrollPanelImpl* pImpl = _ScrollPanelImpl::GetInstance(*this);
390         SysAssertf(pImpl != null, "Not-yet constructed! Construct() should be called before use.");
391
392         float floatHeight = _CoordinateSystemUtils::ConvertToFloat(height);
393         result r = pImpl->SetClientAreaHeight(floatHeight);
394         SysTryReturn(NID_UI_CTRL, r != E_INVALID_ARG, r, r, "[%s] height is less than the height of ScrollPanel.", GetErrorMessage(r));
395         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 on, or the scroll direction is horizontal.", GetErrorMessage(r));
396         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, E_SYSTEM, E_SYSTEM, "[%s] A system error has occurred.", GetErrorMessage(E_SYSTEM));
397
398         return r;
399 }
400
401 result
402 ScrollPanel::SetClientAreaHeight(float height)
403 {
404         _ScrollPanelImpl* pImpl = _ScrollPanelImpl::GetInstance(*this);
405         SysAssertf(pImpl != null, "Not-yet constructed! Construct() should be called before use.");
406
407         result r = pImpl->SetClientAreaHeight(height);
408         SysTryReturn(NID_UI_CTRL, r != E_INVALID_ARG, r, r, "[%s] height is less than the height of ScrollPanel.", GetErrorMessage(r));
409         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 on, or the scroll direction is horizontal.", GetErrorMessage(r));
410         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, E_SYSTEM, E_SYSTEM, "[%s] A system error has occurred.", GetErrorMessage(E_SYSTEM));
411
412         return r;
413 }
414
415 ScrollPanelScrollDirection
416 ScrollPanel::GetScrollDirection(void) const
417 {
418         const _ScrollPanelImpl* pImpl = _ScrollPanelImpl::GetInstance(*this);
419         SysAssertf(pImpl != null, "Not-yet constructed! Construct() should be called before use.");
420
421         return pImpl->GetScrollDirection();
422 }
423
424 bool
425 ScrollPanel::IsScrollAreaAutoResizingEnabled(void) const
426 {
427         const _ScrollPanelImpl* pImpl = _ScrollPanelImpl::GetInstance(*this);
428         SysAssertf(pImpl != null, "Not-yet constructed! Construct() should be called before use.");
429
430         return pImpl->IsScrollAreaAutoResizingEnabled();
431 }
432
433 void
434 ScrollPanel::SetPageScrollEnabled(bool enable)
435 {
436         _ScrollPanelImpl* pImpl = _ScrollPanelImpl::GetInstance(*this);
437         SysAssertf(pImpl != null, "Not-yet constructed! Construct() should be called before use.");
438
439         pImpl->SetPageScrollEnabled(enable);
440 }
441
442 bool
443 ScrollPanel::IsPageScrollEnabled(void) const
444 {
445         const _ScrollPanelImpl* pImpl = _ScrollPanelImpl::GetInstance(*this);
446         SysAssertf(pImpl != null, "Not-yet constructed! Construct() should be called before use.");
447
448         return pImpl->IsPageScrollEnabled();
449 }
450
451 void
452 ScrollPanel::SetScrollBarVisible(bool visible)
453 {
454         _ScrollPanelImpl* pImpl = _ScrollPanelImpl::GetInstance(*this);
455         SysAssertf(pImpl != null, "Not-yet constructed! Construct() should be called before use.");
456
457         pImpl->SetScrollBarVisible(visible);
458 }
459
460 bool
461 ScrollPanel::IsScrollBarVisible(void) const
462 {
463         const _ScrollPanelImpl* pImpl = _ScrollPanelImpl::GetInstance(*this);
464         SysAssertf(pImpl != null, "Not-yet constructed! Construct() should be called before use.");
465
466         return pImpl->IsScrollBarVisible();
467 }
468
469 void
470 ScrollPanel::SetScrollInputMode(ScrollInputMode mode)
471 {
472         _ScrollPanelImpl* pImpl = _ScrollPanelImpl::GetInstance(*this);
473         SysAssertf(pImpl != null, "Not-yet constructed! Construct() should be called before use.");
474
475         pImpl->SetScrollInputMode(mode);
476 }
477
478 ScrollInputMode
479 ScrollPanel::GetScrollInputMode(void) const
480 {
481         const _ScrollPanelImpl* pImpl = _ScrollPanelImpl::GetInstance(*this);
482         SysAssertf(pImpl != null, "Not-yet constructed! Construct() should be called before use.");
483
484         return pImpl->GetScrollInputMode();
485 }
486
487 }}} // Tizen::Ui::Controls
488