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 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 _ContainerImpl* pImpl = _ContainerImpl::GetInstance(*this);
146 SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
148 result r = pImpl->AddChild(_ControlImpl::GetInstance(*pControl));
149 SysTryReturn(NID_UI, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
155 Container::RemoveAllControls(void)
157 _ContainerImpl* pImpl = _ContainerImpl::GetInstance(*this);
158 SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
160 pImpl->RemoveAllChildren(false);
164 Container::RemoveControl(const Control& control)
166 return RemoveControl(const_cast< Control* >(&control));
170 Container::RemoveControl(Control* pControl)
172 _ContainerImpl* pImpl = _ContainerImpl::GetInstance(*this);
173 SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
175 result r = pImpl->RemoveChild(const_cast <_ControlImpl*>(_ControlImpl::GetInstance(*pControl)));
176 SysTryReturn(NID_UI, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
182 Container::RemoveControl(int index)
184 _ContainerImpl* pImpl = _ContainerImpl::GetInstance(*this);
185 SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
187 result r = pImpl->RemoveChild(index);
188 SysTryReturn(NID_UI, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
194 Container::SetControlAt(const Control& control, int index)
196 return SetControlAt(const_cast< Control* >(&control), index);
200 Container::SetControlAt(Control* pControl, int index)
202 _ContainerImpl* pImpl = _ContainerImpl::GetInstance(*this);
203 SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
205 result r = pImpl->SetChildAt(_ControlImpl::GetInstance(*pControl), index);
206 SysTryReturn(NID_UI, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
212 Container::GetControlAt(const Control& control, int& index) const
214 return GetControlAt(&control, index);
218 Container::GetControlAt(const Control* pControl, int& index) const
220 const _ContainerImpl* pImpl = _ContainerImpl::GetInstance(*this);
221 SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
223 int childIndex = pImpl->GetChildIndex(const_cast <_ControlImpl*>(_ControlImpl::GetInstance(*pControl)));
224 result r = GetLastResult();
225 SysTryReturn(NID_UI, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
234 Container::GetControlCount(void) const
236 const _ContainerImpl* pImpl = _ContainerImpl::GetInstance(*this);
237 SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
239 return pImpl->GetChildCount();
243 Container::GetControl(int index) const
245 const _ContainerImpl* pImpl = _ContainerImpl::GetInstance(*this);
246 SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
248 _ControlImpl* pChildImpl = pImpl->GetChild(index);
249 result r = GetLastResult();
250 SysTryReturn(NID_UI, pChildImpl, null, r, "[%s] Propagating.", GetErrorMessage(r));
252 return &pChildImpl->GetPublic();
256 Container::GetControl(const Tizen::Base::String& name, bool recursive) const
258 const _ContainerImpl* pImpl = _ContainerImpl::GetInstance(*this);
259 SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
261 _ControlImpl* pChildImpl = pImpl->SearchControlByName(name, recursive);
262 if (pChildImpl == null)
267 return &pChildImpl->GetPublic();
271 Container::GetControls(void) const
273 const _ContainerImpl* pImpl = _ContainerImpl::GetInstance(*this);
274 SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
276 IList* pChildren = pImpl->GetChildrenPublic();
277 result r = GetLastResult();
278 SysTryReturn(NID_UI, r == E_SUCCESS, null, r, "[%s] Propagating.", GetErrorMessage(r));
284 Container::IsAncestorOf(const Control& control) const
286 return IsAncestorOf(&control);
290 Container::IsAncestorOf(const Control* pControl) const
292 const _ContainerImpl* pImpl = _ContainerImpl::GetInstance(*this);
293 SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
295 bool ancestorOf = pImpl->IsAncestorOf(_ControlImpl::GetInstance(*pControl));
296 result r = GetLastResult();
297 SysTryReturn(NID_UI, r == E_SUCCESS, false, r, "[%s] Propagating.", GetErrorMessage(r));
303 Container::OnClearBackground(void)
305 const _ContainerImpl* pImpl = _ContainerImpl::GetInstance(*this);
306 SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
307 if (pImpl->GetCore().IsCalledGetCanvasN())
309 Canvas* pCanvas = GetCanvasN();
312 pCanvas->SetBackgroundColor(pImpl->GetBackgroundColor());
320 Container::OnDraw(void)
322 _ContainerImpl* pImpl = _ContainerImpl::GetInstance(*this);
323 SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
330 Container::OnBoundsChanging(const Rectangle& oldRect, const Rectangle& newRect)
336 Container::OnBoundsChanging(const FloatRectangle& oldRect, const FloatRectangle& newRect)
342 Container::OnEvaluateSize(Dimension& evaluatedSize)
348 Container::OnEvaluateSize(FloatDimension& evaluatedSize)
354 Container::OnBoundsChanged(const Rectangle& oldRect, const Rectangle& newRect)
360 Container::OnBoundsChanged(const FloatRectangle& oldRect, const FloatRectangle& newRect)
366 Container::OnShowStateChanging(bool showState)
372 Container::OnShowStateChanged(bool showState)
378 Container::GetPortraitLayoutN(void) const
380 const _ContainerImpl* pImpl = _ContainerImpl::GetInstance(*this);
381 SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
383 Layout* pLayout = pImpl->GetPublicPortraitLayoutN();
384 result r = GetLastResult();
385 SysTryReturn(NID_UI, r == E_SUCCESS, null, r, "[%s] Propagating.", GetErrorMessage(r));
391 Container::GetLandscapeLayoutN(void) const
393 const _ContainerImpl* pImpl = _ContainerImpl::GetInstance(*this);
394 SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
396 Layout* pLayout = pImpl->GetPublicLandscapeLayoutN();
397 result r = GetLastResult();
398 SysTryReturn(NID_UI, r == E_SUCCESS, null, r, "[%s] Propagating.", GetErrorMessage(r));
404 Container::GetLayoutN(void) const
406 const _ContainerImpl* pImpl = _ContainerImpl::GetInstance(*this);
407 SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
409 Layout* pLayout = pImpl->GetPublicLayoutN();
410 result r = GetLastResult();
411 SysTryReturn(NID_UI, r == E_SUCCESS, null, r, "[%s] Propagating.", GetErrorMessage(r));
417 Container::SetControlAlwaysOnTop(Control& control, bool alwaysOnTop)
419 _ContainerImpl* pImpl = _ContainerImpl::GetInstance(*this);
420 SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
422 result r = pImpl->SetControlAlwaysOnTop(control, alwaysOnTop);
423 SysTryReturn(NID_UI, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
429 Container::SetControlAlwaysAtBottom(Control& control, bool alwaysAtBottom)
431 _ContainerImpl* pImpl = _ContainerImpl::GetInstance(*this);
432 SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
434 result r = pImpl->SetControlAlwaysAtBottom(control, alwaysAtBottom);
435 SysTryReturn(NID_UI, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
442 Container::IsControlAlwaysAtBottom(const Control& control) const
444 return IsControlAlwaysAtBottom(&control);
448 Container::IsControlAlwaysAtBottom(const Control* pControl) const
450 const _ContainerImpl* pImpl = _ContainerImpl::GetInstance(*this);
451 SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
453 return pImpl->IsControlAlwaysAtBottom(*pControl);
456 Container::IsControlAlwaysOnTop(const Control& control) const
458 return IsControlAlwaysOnTop(&control);
462 Container::IsControlAlwaysOnTop(const Control* pControl) const
464 const _ContainerImpl* pImpl = _ContainerImpl::GetInstance(*this);
465 SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
467 return pImpl->IsControlAlwaysOnTop(*pControl);