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 FUiContainer.cpp
20 * @brief This is the implementation file for Container class.
23 #include <FUiContainer.h>
24 #include <FBaseSysLog.h>
25 #include "FUi_ContainerImpl.h"
26 #include "FUi_ErrorMessages.h"
28 using namespace Tizen::Base;
29 using namespace Tizen::Base::Collection;
30 using namespace Tizen::Graphics;
31 using namespace Tizen::Base::Runtime;
32 using namespace Tizen::Ui;
34 namespace Tizen { namespace Ui {
36 Container::Container(void)
40 Container::~Container(void)
45 Container::Construct(void)
47 SysAssertf(_pControlImpl == null, "Already constructed. Calling Construct() twice or more on a same instance is not allowed for this class.");
49 _ContainerImpl* pImpl = _ContainerImpl::CreateContainerImplN(this);
50 result r = GetLastResult();
51 SysTryReturn(NID_UI, pImpl, r, r, "[%s] Propagating.", GetErrorMessage(r));
53 _pControlImpl = pImpl;
59 Container::Construct(const Rectangle& rect, bool resizable, bool movable)
62 SysAssertf(_pControlImpl == null, "Already constructed. Calling Construct() twice or more on a same instance is not allowed for this class.");
63 _ContainerImpl* pImpl = _ContainerImpl::CreateContainerImplN(this, rect, null, null, resizable, movable);
65 SysTryReturn(NID_UI, pImpl, r, r, "[%s] Propagating.", GetErrorMessage(r));
67 _pControlImpl = pImpl;
73 Container::Construct(const FloatRectangle& rect, bool resizable, bool movable)
76 SysAssertf(_pControlImpl == null, "Already constructed. Calling Construct() twice or more on a same instance is not allowed for this class.");
77 _ContainerImpl* pImpl = _ContainerImpl::CreateContainerImplN(this, rect, null, null, resizable, movable);
79 SysTryReturn(NID_UI, pImpl, r, r, "[%s] Propagating.", GetErrorMessage(r));
81 _pControlImpl = pImpl;
87 Container::Construct(const Layout& layout, const Rectangle& rect, bool resizable, bool movable)
89 return Construct(layout, layout, rect, resizable, movable);
93 Container::Construct(const Layout& layout, const FloatRectangle& rect, bool resizable, bool movable)
95 return Construct(layout, layout, rect, resizable, movable);
99 Container::Construct(const Layout& portraitLayout, const Layout& landscapeLayout,
100 const Rectangle& rect, bool resizable, bool movable)
102 result r = E_SUCCESS;
103 SysAssertf(_pControlImpl == null, "Already constructed. Calling Construct() twice or more on a same instance is not allowed for this class.");
105 _ContainerImpl* pImpl =
106 _ContainerImpl::CreateContainerImplN(this, rect, &portraitLayout, &landscapeLayout, resizable, movable);
109 SysTryReturn(NID_UI, pImpl, r, r, "[%s] Propagating.", GetErrorMessage(r));
112 _pControlImpl = pImpl;
118 Container::Construct(const Layout& portraitLayout, const Layout& landscapeLayout,
119 const FloatRectangle& rect, bool resizable, bool movable)
121 result r = E_SUCCESS;
122 SysAssertf(_pControlImpl == null, "Already constructed. Calling Construct() twice or more on a same instance is not allowed for this class.");
124 _ContainerImpl* pImpl =
125 _ContainerImpl::CreateContainerImplN(this, rect, &portraitLayout, &landscapeLayout, resizable, movable);
128 SysTryReturn(NID_UI, pImpl, r, r, "[%s] Propagating.", GetErrorMessage(r));
131 _pControlImpl = pImpl;
137 Container::AddControl(const Control& control)
139 return AddControl(const_cast< Control* >(&control));
143 Container::AddControl(Control* pControl)
145 SysTryReturnResult(NID_UI, pControl != null, E_INVALID_ARG, "pControl is null.");
146 _ContainerImpl* pImpl = _ContainerImpl::GetInstance(*this);
147 SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
149 result r = pImpl->AddChild(_ControlImpl::GetInstance(*pControl));
150 SysTryReturn(NID_UI, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
156 Container::RemoveAllControls(void)
158 _ContainerImpl* pImpl = _ContainerImpl::GetInstance(*this);
159 SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
161 pImpl->RemoveAllChildren(false);
165 Container::RemoveControl(const Control& control)
167 return RemoveControl(const_cast< Control* >(&control));
171 Container::RemoveControl(Control* pControl)
173 SysTryReturnResult(NID_UI, pControl != null, E_INVALID_ARG, "pControl is null.");
174 _ContainerImpl* pImpl = _ContainerImpl::GetInstance(*this);
175 SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
177 result r = pImpl->RemoveControl(const_cast <_ControlImpl*>(_ControlImpl::GetInstance(*pControl)));
178 SysTryReturn(NID_UI, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
184 Container::RemoveControl(int index)
186 _ContainerImpl* pImpl = _ContainerImpl::GetInstance(*this);
187 SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
189 result r = pImpl->RemoveControl(index);
190 SysTryReturn(NID_UI, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
196 Container::SetControlAt(const Control& control, int index)
198 return SetControlAt(const_cast< Control* >(&control), index);
202 Container::SetControlAt(Control* pControl, int index)
204 SysTryReturnResult(NID_UI, pControl != null, E_INVALID_ARG, "pControl is null.");
205 _ContainerImpl* pImpl = _ContainerImpl::GetInstance(*this);
206 SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
208 result r = pImpl->SetChildAt(_ControlImpl::GetInstance(*pControl), index);
209 SysTryReturn(NID_UI, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
215 Container::GetControlAt(const Control& control, int& index) const
217 return GetControlAt(&control, index);
221 Container::GetControlAt(const Control* pControl, int& index) const
223 SysTryReturnResult(NID_UI, pControl != null, E_INVALID_ARG, "pControl is null.");
224 const _ContainerImpl* pImpl = _ContainerImpl::GetInstance(*this);
225 SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
227 int childIndex = pImpl->GetChildIndex(const_cast <_ControlImpl*>(_ControlImpl::GetInstance(*pControl)));
228 result r = GetLastResult();
229 SysTryReturn(NID_UI, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
238 Container::GetControlCount(void) const
240 const _ContainerImpl* pImpl = _ContainerImpl::GetInstance(*this);
241 SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
243 return pImpl->GetChildCount();
247 Container::GetControl(int index) const
249 const _ContainerImpl* pImpl = _ContainerImpl::GetInstance(*this);
250 SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
252 _ControlImpl* pChildImpl = pImpl->GetChild(index);
253 result r = GetLastResult();
254 SysTryReturn(NID_UI, pChildImpl, null, r, "[%s] Propagating.", GetErrorMessage(r));
256 return &pChildImpl->GetPublic();
260 Container::GetControl(const Tizen::Base::String& name, bool recursive) const
262 const _ContainerImpl* pImpl = _ContainerImpl::GetInstance(*this);
263 SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
265 _ControlImpl* pChildImpl = pImpl->SearchControlByName(name, recursive);
266 if (pChildImpl == null)
271 return &pChildImpl->GetPublic();
275 Container::GetControls(void) const
277 const _ContainerImpl* pImpl = _ContainerImpl::GetInstance(*this);
278 SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
280 IList* pChildren = pImpl->GetChildrenPublic();
281 result r = GetLastResult();
282 SysTryReturn(NID_UI, r == E_SUCCESS, null, r, "[%s] Propagating.", GetErrorMessage(r));
288 Container::IsAncestorOf(const Control& control) const
290 return IsAncestorOf(&control);
294 Container::IsAncestorOf(const Control* pControl) const
296 SysTryReturnResult(NID_UI, pControl != null, E_INVALID_ARG, "pControl is null.");
297 const _ContainerImpl* pImpl = _ContainerImpl::GetInstance(*this);
298 SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
300 bool ancestorOf = pImpl->IsAncestorOf(_ControlImpl::GetInstance(*pControl));
301 result r = GetLastResult();
302 SysTryReturn(NID_UI, r == E_SUCCESS, false, r, "[%s] Propagating.", GetErrorMessage(r));
308 Container::OnClearBackground(void)
310 const _ContainerImpl* pImpl = _ContainerImpl::GetInstance(*this);
311 SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
312 if (pImpl->GetCore().IsCalledGetCanvasN())
314 Canvas* pCanvas = GetCanvasN();
317 pCanvas->SetBackgroundColor(pImpl->GetBackgroundColor());
325 Container::OnDraw(void)
327 _ContainerImpl* pImpl = _ContainerImpl::GetInstance(*this);
328 SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
335 Container::OnBoundsChanging(const Rectangle& oldRect, const Rectangle& newRect)
341 Container::OnBoundsChanging(const FloatRectangle& oldRect, const FloatRectangle& newRect)
347 Container::OnEvaluateSize(Dimension& evaluatedSize)
353 Container::OnEvaluateSize(FloatDimension& evaluatedSize)
359 Container::OnBoundsChanged(const Rectangle& oldRect, const Rectangle& newRect)
365 Container::OnBoundsChanged(const FloatRectangle& oldRect, const FloatRectangle& newRect)
371 Container::OnShowStateChanging(bool showState)
377 Container::OnShowStateChanged(bool showState)
383 Container::GetPortraitLayoutN(void) const
385 const _ContainerImpl* pImpl = _ContainerImpl::GetInstance(*this);
386 SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
388 Layout* pLayout = pImpl->GetPublicPortraitLayoutN();
389 result r = GetLastResult();
390 SysTryReturn(NID_UI, r == E_SUCCESS, null, r, "[%s] Propagating.", GetErrorMessage(r));
396 Container::GetLandscapeLayoutN(void) const
398 const _ContainerImpl* pImpl = _ContainerImpl::GetInstance(*this);
399 SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
401 Layout* pLayout = pImpl->GetPublicLandscapeLayoutN();
402 result r = GetLastResult();
403 SysTryReturn(NID_UI, r == E_SUCCESS, null, r, "[%s] Propagating.", GetErrorMessage(r));
409 Container::GetLayoutN(void) const
411 const _ContainerImpl* pImpl = _ContainerImpl::GetInstance(*this);
412 SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
414 Layout* pLayout = pImpl->GetPublicLayoutN();
415 result r = GetLastResult();
416 SysTryReturn(NID_UI, r == E_SUCCESS, null, r, "[%s] Propagating.", GetErrorMessage(r));
422 Container::SetControlAlwaysOnTop(Control& control, bool alwaysOnTop)
424 _ContainerImpl* pImpl = _ContainerImpl::GetInstance(*this);
425 SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
427 result r = pImpl->SetControlAlwaysOnTop(control, alwaysOnTop);
428 SysTryReturn(NID_UI, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
434 Container::SetControlAlwaysAtBottom(Control& control, bool alwaysAtBottom)
436 _ContainerImpl* pImpl = _ContainerImpl::GetInstance(*this);
437 SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
439 result r = pImpl->SetControlAlwaysAtBottom(control, alwaysAtBottom);
440 SysTryReturn(NID_UI, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
447 Container::IsControlAlwaysAtBottom(const Control& control) const
449 return IsControlAlwaysAtBottom(&control);
453 Container::IsControlAlwaysAtBottom(const Control* pControl) const
455 SysTryReturnResult(NID_UI, pControl != null, E_INVALID_ARG, "pControl is null.");
456 const _ContainerImpl* pImpl = _ContainerImpl::GetInstance(*this);
457 SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
459 return pImpl->IsControlAlwaysAtBottom(*pControl);
462 Container::IsControlAlwaysOnTop(const Control& control) const
464 return IsControlAlwaysOnTop(&control);
468 Container::IsControlAlwaysOnTop(const Control* pControl) const
470 SysTryReturnResult(NID_UI, pControl != null, E_INVALID_ARG, "pControl is null.");
471 const _ContainerImpl* pImpl = _ContainerImpl::GetInstance(*this);
472 SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
474 return pImpl->IsControlAlwaysOnTop(*pControl);