2 // Open Service Platform
3 // Copyright (c) 2012-2013 Samsung Electronics Co., Ltd.
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
9 // http://floralicense.org/license/
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_UiBuilder.h"
28 #include "FUiCtrl_ScrollPanelImpl.h"
31 using namespace Tizen::Graphics;
33 namespace Tizen { namespace Ui { namespace Controls
36 ScrollPanel::ScrollPanel(void)
42 ScrollPanel::~ScrollPanel(void)
48 ScrollPanel::Construct(const Rectangle& rect)
50 result r = Construct(rect, SCROLL_PANEL_SCROLL_DIRECTION_VERTICAL, true);
56 ScrollPanel::Construct(const Rectangle& rect, ScrollPanelScrollDirection scrollDirection, bool autoResizingEnable)
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.");
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));
67 _pControlImpl = pImpl;
79 ScrollPanel::Construct(const Tizen::Base::String& resourceId)
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));
96 ScrollPanel::Construct(const Layout& layout, const Rectangle& rect)
98 result r = Construct(layout, layout, rect, SCROLL_PANEL_SCROLL_DIRECTION_VERTICAL, true);
104 ScrollPanel::Construct(const Layout& layout, const Rectangle& rect, ScrollPanelScrollDirection scrollDirection, bool autoResizingEnable)
106 result r = Construct(layout, layout, rect, scrollDirection, autoResizingEnable);
112 ScrollPanel::Construct(const Layout& portraitLayout, const Layout& landscapeLayout, const Rectangle& rect)
114 result r = Construct(portraitLayout, landscapeLayout, rect, SCROLL_PANEL_SCROLL_DIRECTION_VERTICAL, true);
120 ScrollPanel::Construct(const Layout& portraitLayout, const Layout& landscapeLayout, const Rectangle& rect, ScrollPanelScrollDirection scrollDirection, bool autoResizingEnable)
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.");
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));
131 _pControlImpl = pImpl;
143 ScrollPanel::AddScrollEventListener(IScrollEventListener& listener)
145 _ScrollPanelImpl* pImpl = _ScrollPanelImpl::GetInstance(*this);
146 SysAssertf(pImpl != null, "Not-yet constructed! Construct() should be called before use.");
148 pImpl->AddScrollEventListener(listener);
152 ScrollPanel::RemoveScrollEventListener(IScrollEventListener& listener)
154 _ScrollPanelImpl* pImpl = _ScrollPanelImpl::GetInstance(*this);
155 SysAssertf(pImpl != null, "Not-yet constructed! Construct() should be called before use.");
157 pImpl->RemoveScrollEventListener(listener);
161 ScrollPanel::GetScrollPosition(void) const
163 const _ScrollPanelImpl* pImpl = _ScrollPanelImpl::GetInstance(*this);
164 SysAssertf(pImpl != null, "Not-yet constructed! Construct() should be called before use.");
166 return pImpl->GetScrollPosition();
170 ScrollPanel::SetScrollPosition(int position)
172 _ScrollPanelImpl* pImpl = _ScrollPanelImpl::GetInstance(*this);
173 SysAssertf(pImpl != null, "Not-yet constructed! Construct() should be called before use.");
175 pImpl->SetScrollPosition(position, false);
179 ScrollPanel::SetScrollPosition(int position, bool withAnimation)
181 _ScrollPanelImpl* pImpl = _ScrollPanelImpl::GetInstance(*this);
182 SysAssertf(pImpl != null, "Not-yet constructed! Construct() should be called before use.");
184 pImpl->SetScrollPosition(position, withAnimation);
188 ScrollPanel::ScrollToBottom(void) const
190 const _ScrollPanelImpl* pImpl = _ScrollPanelImpl::GetInstance(*this);
191 SysAssertf(pImpl != null, "Not-yet constructed! Construct() should be called before use.");
193 pImpl->ScrollToBottom();
197 ScrollPanel::ScrollToTop(void) const
199 const _ScrollPanelImpl* pImpl = _ScrollPanelImpl::GetInstance(*this);
200 SysAssertf(pImpl != null, "Not-yet constructed! Construct() should be called before use.");
202 pImpl->ScrollToTop();
206 ScrollPanel::CloseOverlayWindow(void)
208 _ScrollPanelImpl* pImpl = _ScrollPanelImpl::GetInstance(*this);
209 SysAssertf(pImpl != null, "Not-yet constructed! Construct() should be called before use.");
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));
218 ScrollPanel::GetClientAreaBounds(void) const
220 const _ScrollPanelImpl* pImpl = _ScrollPanelImpl::GetInstance(*this);
221 SysAssertf(pImpl != null, "Not-yet constructed! Construct() should be called before use.");
223 return pImpl->GetClientAreaBounds();
227 ScrollPanel::SetClientAreaWidth(int width)
229 _ScrollPanelImpl* pImpl = _ScrollPanelImpl::GetInstance(*this);
230 SysAssertf(pImpl != null, "Not-yet constructed! Construct() should be called before use.");
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));
241 ScrollPanel::SetClientAreaHeight(int height)
243 _ScrollPanelImpl* pImpl = _ScrollPanelImpl::GetInstance(*this);
244 SysAssertf(pImpl != null, "Not-yet constructed! Construct() should be called before use.");
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));
254 ScrollPanelScrollDirection
255 ScrollPanel::GetScrollDirection(void) const
257 const _ScrollPanelImpl* pImpl = _ScrollPanelImpl::GetInstance(*this);
258 SysAssertf(pImpl != null, "Not-yet constructed! Construct() should be called before use.");
260 return pImpl->GetScrollDirection();
264 ScrollPanel::IsScrollAreaAutoResizingEnabled(void) const
266 const _ScrollPanelImpl* pImpl = _ScrollPanelImpl::GetInstance(*this);
267 SysAssertf(pImpl != null, "Not-yet constructed! Construct() should be called before use.");
269 return pImpl->IsScrollAreaAutoResizingEnabled();
273 ScrollPanel::SetPageScrollEnabled(bool enable)
275 _ScrollPanelImpl* pImpl = _ScrollPanelImpl::GetInstance(*this);
276 SysAssertf(pImpl != null, "Not-yet constructed! Construct() should be called before use.");
278 pImpl->SetPageScrollEnabled(enable);
282 ScrollPanel::IsPageScrollEnabled(void) const
284 const _ScrollPanelImpl* pImpl = _ScrollPanelImpl::GetInstance(*this);
285 SysAssertf(pImpl != null, "Not-yet constructed! Construct() should be called before use.");
287 return pImpl->IsPageScrollEnabled();
291 ScrollPanel::SetScrollBarVisible(bool visible)
293 _ScrollPanelImpl* pImpl = _ScrollPanelImpl::GetInstance(*this);
294 SysAssertf(pImpl != null, "Not-yet constructed! Construct() should be called before use.");
296 pImpl->SetScrollBarVisible(visible);
300 ScrollPanel::IsScrollBarVisible(void) const
302 const _ScrollPanelImpl* pImpl = _ScrollPanelImpl::GetInstance(*this);
303 SysAssertf(pImpl != null, "Not-yet constructed! Construct() should be called before use.");
305 return pImpl->IsScrollBarVisible();
309 ScrollPanel::SetScrollInputMode(ScrollInputMode mode)
311 _ScrollPanelImpl* pImpl = _ScrollPanelImpl::GetInstance(*this);
312 SysAssertf(pImpl != null, "Not-yet constructed! Construct() should be called before use.");
314 pImpl->SetScrollInputMode(mode);
318 ScrollPanel::GetScrollInputMode(void) const
320 const _ScrollPanelImpl* pImpl = _ScrollPanelImpl::GetInstance(*this);
321 SysAssertf(pImpl != null, "Not-yet constructed! Construct() should be called before use.");
323 return pImpl->GetScrollInputMode();
326 }}} // Tizen::Ui::Controls