2 // Open Service Platform
3 // Copyright (c) 2012-2013 Samsung Electronics Co., Ltd.
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
9 // http://www.apache.org/licenses/LICENSE-2.0/
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.
19 * @file FUiCtrlScrollPanel.cpp
20 * @brief This is the implementation for the %ScrollPanel class.
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"
32 using namespace Tizen::Graphics;
34 namespace Tizen { namespace Ui { namespace Controls
37 ScrollPanel::ScrollPanel(void)
43 ScrollPanel::~ScrollPanel(void)
49 ScrollPanel::Construct(const Rectangle& rect)
51 result r = Construct(rect, SCROLL_PANEL_SCROLL_DIRECTION_VERTICAL, true);
57 ScrollPanel::Construct(const Tizen::Graphics::FloatRectangle& rect)
59 result r = Construct(rect, SCROLL_PANEL_SCROLL_DIRECTION_VERTICAL, true);
65 ScrollPanel::Construct(const Tizen::Base::String& resourceId)
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));
82 ScrollPanel::Construct(const Rectangle& rect, ScrollPanelScrollDirection scrollDirection, bool autoResizingEnable)
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.");
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));
94 _pControlImpl = pImpl;
106 ScrollPanel::Construct(const Tizen::Graphics::FloatRectangle& rect, ScrollPanelScrollDirection scrollDirection, bool autoResizingEnable)
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.");
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));
117 _pControlImpl = pImpl;
129 ScrollPanel::Construct(const Layout& layout, const Rectangle& rect)
131 result r = Construct(layout, layout, rect, SCROLL_PANEL_SCROLL_DIRECTION_VERTICAL, true);
137 ScrollPanel::Construct(const Tizen::Ui::Layout& layout, const Tizen::Graphics::FloatRectangle& rect)
139 result r = Construct(layout, layout, rect, SCROLL_PANEL_SCROLL_DIRECTION_VERTICAL, true);
145 ScrollPanel::Construct(const Layout& layout, const Rectangle& rect, ScrollPanelScrollDirection scrollDirection, bool autoResizingEnable)
147 result r = Construct(layout, layout, rect, scrollDirection, autoResizingEnable);
153 ScrollPanel::Construct(const Tizen::Ui::Layout& layout, const Tizen::Graphics::FloatRectangle& rect, ScrollPanelScrollDirection scrollDirection, bool autoResizingEnable)
155 result r = Construct(layout, layout, rect, scrollDirection, autoResizingEnable);
161 ScrollPanel::Construct(const Layout& portraitLayout, const Layout& landscapeLayout, const Rectangle& rect)
163 result r = Construct(portraitLayout, landscapeLayout, rect, SCROLL_PANEL_SCROLL_DIRECTION_VERTICAL, true);
169 ScrollPanel::Construct(const Tizen::Ui::Layout& portraitLayout, const Tizen::Ui::Layout& landscapeLayout, const Tizen::Graphics::FloatRectangle& rect)
171 result r = Construct(portraitLayout, landscapeLayout, rect, SCROLL_PANEL_SCROLL_DIRECTION_VERTICAL, true);
178 ScrollPanel::Construct(const Layout& portraitLayout, const Layout& landscapeLayout, const Rectangle& rect, ScrollPanelScrollDirection scrollDirection, bool autoResizingEnable)
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.");
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));
190 _pControlImpl = pImpl;
202 ScrollPanel::Construct(const Tizen::Ui::Layout& portraitLayout, const Tizen::Ui::Layout& landscapeLayout, const Tizen::Graphics::FloatRectangle& rect, ScrollPanelScrollDirection scrollDirection, bool autoResizingEnable)
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.");
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));
213 _pControlImpl = pImpl;
225 ScrollPanel::AddScrollEventListener(IScrollEventListener& listener)
227 _ScrollPanelImpl* pImpl = _ScrollPanelImpl::GetInstance(*this);
228 SysAssertf(pImpl != null, "Not-yet constructed! Construct() should be called before use.");
230 pImpl->AddScrollEventListener(listener);
234 ScrollPanel::AddScrollEventListener(IScrollEventListenerF& listener)
236 _ScrollPanelImpl* pImpl = _ScrollPanelImpl::GetInstance(*this);
237 SysAssertf(pImpl != null, "Not-yet constructed! Construct() should be called before use.");
239 pImpl->AddScrollEventListener(listener);
243 ScrollPanel::RemoveScrollEventListener(IScrollEventListener& listener)
245 _ScrollPanelImpl* pImpl = _ScrollPanelImpl::GetInstance(*this);
246 SysAssertf(pImpl != null, "Not-yet constructed! Construct() should be called before use.");
248 pImpl->RemoveScrollEventListener(listener);
252 ScrollPanel::RemoveScrollEventListener(IScrollEventListenerF& listener)
254 _ScrollPanelImpl* pImpl = _ScrollPanelImpl::GetInstance(*this);
255 SysAssertf(pImpl != null, "Not-yet constructed! Construct() should be called before use.");
257 pImpl->RemoveScrollEventListener(listener);
261 ScrollPanel::GetScrollPosition(void) const
263 const _ScrollPanelImpl* pImpl = _ScrollPanelImpl::GetInstance(*this);
264 SysAssertf(pImpl != null, "Not-yet constructed! Construct() should be called before use.");
266 float position = pImpl->GetScrollPosition();
267 return _CoordinateSystemUtils::ConvertToInteger(position);
271 ScrollPanel::GetScrollPositionF(void) const
273 const _ScrollPanelImpl* pImpl = _ScrollPanelImpl::GetInstance(*this);
274 SysAssertf(pImpl != null, "Not-yet constructed! Construct() should be called before use.");
276 return pImpl->GetScrollPosition();
280 ScrollPanel::SetScrollPosition(int position)
282 _ScrollPanelImpl* pImpl = _ScrollPanelImpl::GetInstance(*this);
283 SysAssertf(pImpl != null, "Not-yet constructed! Construct() should be called before use.");
285 float floatPosition = _CoordinateSystemUtils::ConvertToFloat(position);
286 pImpl->SetScrollPosition(floatPosition, false);
290 ScrollPanel::SetScrollPosition(int position, bool withAnimation)
292 _ScrollPanelImpl* pImpl = _ScrollPanelImpl::GetInstance(*this);
293 SysAssertf(pImpl != null, "Not-yet constructed! Construct() should be called before use.");
295 float floatPosition = _CoordinateSystemUtils::ConvertToFloat(position);
296 pImpl->SetScrollPosition(floatPosition, withAnimation);
300 ScrollPanel::SetScrollPosition(float position, bool withAnimation)
302 _ScrollPanelImpl* pImpl = _ScrollPanelImpl::GetInstance(*this);
303 SysAssertf(pImpl != null, "Not-yet constructed! Construct() should be called before use.");
305 pImpl->SetScrollPosition(position, withAnimation);
309 ScrollPanel::ScrollToBottom(void) const
311 const _ScrollPanelImpl* pImpl = _ScrollPanelImpl::GetInstance(*this);
312 SysAssertf(pImpl != null, "Not-yet constructed! Construct() should be called before use.");
314 pImpl->ScrollToBottom();
318 ScrollPanel::ScrollToTop(void) const
320 const _ScrollPanelImpl* pImpl = _ScrollPanelImpl::GetInstance(*this);
321 SysAssertf(pImpl != null, "Not-yet constructed! Construct() should be called before use.");
323 pImpl->ScrollToTop();
327 ScrollPanel::CloseOverlayWindow(void)
329 _ScrollPanelImpl* pImpl = _ScrollPanelImpl::GetInstance(*this);
330 SysAssertf(pImpl != null, "Not-yet constructed! Construct() should be called before use.");
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));
339 ScrollPanel::GetClientAreaBounds(void) const
341 const _ScrollPanelImpl* pImpl = _ScrollPanelImpl::GetInstance(*this);
342 SysAssertf(pImpl != null, "Not-yet constructed! Construct() should be called before use.");
344 FloatRectangle floatRect = pImpl->GetClientAreaBounds();
345 return _CoordinateSystemUtils::ConvertToInteger(floatRect);
349 ScrollPanel::GetClientAreaBoundsF(void) const
351 const _ScrollPanelImpl* pImpl = _ScrollPanelImpl::GetInstance(*this);
352 SysAssertf(pImpl != null, "Not-yet constructed! Construct() should be called before use.");
354 return pImpl->GetClientAreaBounds();
358 ScrollPanel::SetClientAreaWidth(int width)
360 _ScrollPanelImpl* pImpl = _ScrollPanelImpl::GetInstance(*this);
361 SysAssertf(pImpl != null, "Not-yet constructed! Construct() should be called before use.");
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));
373 ScrollPanel::SetClientAreaWidth(float width)
375 _ScrollPanelImpl* pImpl = _ScrollPanelImpl::GetInstance(*this);
376 SysAssertf(pImpl != null, "Not-yet constructed! Construct() should be called before use.");
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));
387 ScrollPanel::SetClientAreaHeight(int height)
389 _ScrollPanelImpl* pImpl = _ScrollPanelImpl::GetInstance(*this);
390 SysAssertf(pImpl != null, "Not-yet constructed! Construct() should be called before use.");
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));
402 ScrollPanel::SetClientAreaHeight(float height)
404 _ScrollPanelImpl* pImpl = _ScrollPanelImpl::GetInstance(*this);
405 SysAssertf(pImpl != null, "Not-yet constructed! Construct() should be called before use.");
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));
415 ScrollPanelScrollDirection
416 ScrollPanel::GetScrollDirection(void) const
418 const _ScrollPanelImpl* pImpl = _ScrollPanelImpl::GetInstance(*this);
419 SysAssertf(pImpl != null, "Not-yet constructed! Construct() should be called before use.");
421 return pImpl->GetScrollDirection();
425 ScrollPanel::IsScrollAreaAutoResizingEnabled(void) const
427 const _ScrollPanelImpl* pImpl = _ScrollPanelImpl::GetInstance(*this);
428 SysAssertf(pImpl != null, "Not-yet constructed! Construct() should be called before use.");
430 return pImpl->IsScrollAreaAutoResizingEnabled();
434 ScrollPanel::SetPageScrollEnabled(bool enable)
436 _ScrollPanelImpl* pImpl = _ScrollPanelImpl::GetInstance(*this);
437 SysAssertf(pImpl != null, "Not-yet constructed! Construct() should be called before use.");
439 pImpl->SetPageScrollEnabled(enable);
443 ScrollPanel::IsPageScrollEnabled(void) const
445 const _ScrollPanelImpl* pImpl = _ScrollPanelImpl::GetInstance(*this);
446 SysAssertf(pImpl != null, "Not-yet constructed! Construct() should be called before use.");
448 return pImpl->IsPageScrollEnabled();
452 ScrollPanel::SetScrollBarVisible(bool visible)
454 _ScrollPanelImpl* pImpl = _ScrollPanelImpl::GetInstance(*this);
455 SysAssertf(pImpl != null, "Not-yet constructed! Construct() should be called before use.");
457 pImpl->SetScrollBarVisible(visible);
461 ScrollPanel::IsScrollBarVisible(void) const
463 const _ScrollPanelImpl* pImpl = _ScrollPanelImpl::GetInstance(*this);
464 SysAssertf(pImpl != null, "Not-yet constructed! Construct() should be called before use.");
466 return pImpl->IsScrollBarVisible();
470 ScrollPanel::SetScrollInputMode(ScrollInputMode mode)
472 _ScrollPanelImpl* pImpl = _ScrollPanelImpl::GetInstance(*this);
473 SysAssertf(pImpl != null, "Not-yet constructed! Construct() should be called before use.");
475 pImpl->SetScrollInputMode(mode);
479 ScrollPanel::GetScrollInputMode(void) const
481 const _ScrollPanelImpl* pImpl = _ScrollPanelImpl::GetInstance(*this);
482 SysAssertf(pImpl != null, "Not-yet constructed! Construct() should be called before use.");
484 return pImpl->GetScrollInputMode();
487 }}} // Tizen::Ui::Controls