Merge "Modified to work properly for item set bounds" into tizen_2.1
[platform/framework/native/uifw.git] / src / ui / FUiContainer.cpp
1 //
2 // Open Service Platform
3 // Copyright (c) 2012-2013 Samsung Electronics Co., Ltd.
4 //
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
8 //
9 //     http://floralicense.org/license/
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                FUiContainer.cpp
20  * @brief               This is the implementation file for Container class.
21  */
22
23 #include <FUiContainer.h>
24 #include <FBaseSysLog.h>
25 #include "FUi_ContainerImpl.h"
26 #include "FUi_ErrorMessages.h"
27
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;
33
34 namespace Tizen { namespace Ui {
35
36 Container::Container(void)
37 {
38 }
39
40 Container::~Container(void)
41 {
42 }
43
44 result
45 Container::Construct(void)
46 {
47         SysAssertf(_pControlImpl == null, "Already constructed. Calling Construct() twice or more on a same instance is not allowed for this class.");
48
49         _ContainerImpl* pImpl = _ContainerImpl::CreateContainerImplN(this);
50         result r = GetLastResult();
51         SysTryReturn(NID_UI, pImpl, r, r, "[%s] Propagating.", GetErrorMessage(r));
52
53         _pControlImpl = pImpl;
54
55         return E_SUCCESS;
56 }
57
58 result
59 Container::Construct(const Rectangle& rect, bool resizable, bool movable)
60 {
61         result r = E_SUCCESS;
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);
64         r = GetLastResult();
65         SysTryReturn(NID_UI, pImpl, r, r, "[%s] Propagating.", GetErrorMessage(r));
66
67         _pControlImpl = pImpl;
68
69         return E_SUCCESS;
70 }
71
72 result
73 Container::Construct(const FloatRectangle& rect, bool resizable, bool movable)
74 {
75         result r = E_SUCCESS;
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);
78         r = GetLastResult();
79         SysTryReturn(NID_UI, pImpl, r, r, "[%s] Propagating.", GetErrorMessage(r));
80
81         _pControlImpl = pImpl;
82
83         return E_SUCCESS;
84 }
85
86 result
87 Container::Construct(const Layout& layout, const Rectangle& rect, bool resizable, bool movable)
88 {
89         return Construct(layout, layout, rect, resizable, movable);
90 }
91
92 result
93 Container::Construct(const Layout& layout, const FloatRectangle& rect, bool resizable, bool movable)
94 {
95         return Construct(layout, layout, rect, resizable, movable);
96 }
97
98 result
99 Container::Construct(const Layout& portraitLayout, const Layout& landscapeLayout,
100                                                          const Rectangle& rect, bool resizable, bool movable)
101 {
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.");
104
105         _ContainerImpl* pImpl =
106                 _ContainerImpl::CreateContainerImplN(this, rect, &portraitLayout, &landscapeLayout, resizable, movable);
107
108         r = GetLastResult();
109         SysTryReturn(NID_UI, pImpl, r, r, "[%s] Propagating.", GetErrorMessage(r));
110
111
112         _pControlImpl = pImpl;
113
114         return E_SUCCESS;
115 }
116
117 result
118 Container::Construct(const Layout& portraitLayout, const Layout& landscapeLayout,
119                                                          const FloatRectangle& rect, bool resizable, bool movable)
120 {
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.");
123
124         _ContainerImpl* pImpl =
125                 _ContainerImpl::CreateContainerImplN(this, rect, &portraitLayout, &landscapeLayout, resizable, movable);
126
127         r = GetLastResult();
128         SysTryReturn(NID_UI, pImpl, r, r, "[%s] Propagating.", GetErrorMessage(r));
129
130
131         _pControlImpl = pImpl;
132
133         return E_SUCCESS;
134 }
135
136 result
137 Container::AddControl(const Control& control)
138 {
139         return AddControl(const_cast< Control* >(&control));
140 }
141
142 result
143 Container::AddControl(Control* pControl)
144 {
145         _ContainerImpl* pImpl = _ContainerImpl::GetInstance(*this);
146         SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
147
148         result r = pImpl->AddChild(_ControlImpl::GetInstance(*pControl));
149         SysTryReturn(NID_UI, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
150
151         return E_SUCCESS;
152 }
153
154 void
155 Container::RemoveAllControls(void)
156 {
157         _ContainerImpl* pImpl = _ContainerImpl::GetInstance(*this);
158         SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
159
160         pImpl->RemoveAllChildren(false);
161 }
162
163 result
164 Container::RemoveControl(const Control& control)
165 {
166         return RemoveControl(const_cast< Control* >(&control));
167 }
168
169 result
170 Container::RemoveControl(Control* pControl)
171 {
172         _ContainerImpl* pImpl = _ContainerImpl::GetInstance(*this);
173         SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
174
175         result r = pImpl->RemoveControl(const_cast <_ControlImpl*>(_ControlImpl::GetInstance(*pControl)));
176         SysTryReturn(NID_UI, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
177
178         return E_SUCCESS;
179 }
180
181 result
182 Container::RemoveControl(int index)
183 {
184         _ContainerImpl* pImpl = _ContainerImpl::GetInstance(*this);
185         SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
186
187         result r = pImpl->RemoveControl(index);
188         SysTryReturn(NID_UI, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
189
190         return E_SUCCESS;
191 }
192
193 result
194 Container::SetControlAt(const Control& control, int index)
195 {
196         return SetControlAt(const_cast< Control* >(&control), index);
197 }
198
199 result
200 Container::SetControlAt(Control* pControl, int index)
201 {
202         _ContainerImpl* pImpl = _ContainerImpl::GetInstance(*this);
203         SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
204
205         result r = pImpl->SetChildAt(_ControlImpl::GetInstance(*pControl), index);
206         SysTryReturn(NID_UI, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
207
208         return E_SUCCESS;
209 }
210
211 result
212 Container::GetControlAt(const Control& control, int& index) const
213 {
214         return GetControlAt(&control, index);
215 }
216
217 result
218 Container::GetControlAt(const Control* pControl, int& index) const
219 {
220         const _ContainerImpl* pImpl = _ContainerImpl::GetInstance(*this);
221         SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
222
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));
226
227         index = childIndex;
228
229         return E_SUCCESS;
230 }
231
232
233 int
234 Container::GetControlCount(void) const
235 {
236         const _ContainerImpl* pImpl = _ContainerImpl::GetInstance(*this);
237         SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
238
239         return pImpl->GetChildCount();
240 }
241
242 Control*
243 Container::GetControl(int index) const
244 {
245         const _ContainerImpl* pImpl = _ContainerImpl::GetInstance(*this);
246         SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
247
248         _ControlImpl* pChildImpl = pImpl->GetChild(index);
249         result r = GetLastResult();
250         SysTryReturn(NID_UI, pChildImpl, null, r, "[%s] Propagating.", GetErrorMessage(r));
251
252         return &pChildImpl->GetPublic();
253 }
254
255 Control*
256 Container::GetControl(const Tizen::Base::String& name, bool recursive) const
257 {
258         const _ContainerImpl* pImpl = _ContainerImpl::GetInstance(*this);
259         SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
260
261         _ControlImpl* pChildImpl = pImpl->SearchControlByName(name, recursive);
262         if (pChildImpl == null)
263         {
264                 return null;
265         }
266
267         return &pChildImpl->GetPublic();
268 }
269
270 IList*
271 Container::GetControls(void) const
272 {
273         const _ContainerImpl* pImpl = _ContainerImpl::GetInstance(*this);
274         SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
275
276         IList* pChildren = pImpl->GetChildrenPublic();
277         result r = GetLastResult();
278         SysTryReturn(NID_UI, r == E_SUCCESS, null, r, "[%s] Propagating.", GetErrorMessage(r));
279
280         return pChildren;
281 }
282
283 bool
284 Container::IsAncestorOf(const Control& control) const
285 {
286         return IsAncestorOf(&control);
287 }
288
289 bool
290 Container::IsAncestorOf(const Control* pControl) const
291 {
292         const _ContainerImpl* pImpl = _ContainerImpl::GetInstance(*this);
293         SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
294
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));
298
299         return ancestorOf;
300 }
301
302 void
303 Container::OnClearBackground(void)
304 {
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())
308         {
309                 Canvas* pCanvas = GetCanvasN();
310                 if (pCanvas)
311                 {
312                         pCanvas->SetBackgroundColor(pImpl->GetBackgroundColor());
313                         pCanvas->Clear();
314                         delete pCanvas;
315                 }
316         }
317 }
318
319 result
320 Container::OnDraw(void)
321 {
322         _ContainerImpl* pImpl = _ContainerImpl::GetInstance(*this);
323         SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
324
325         pImpl->CallOnDraw();
326         return E_SUCCESS;
327 }
328
329 result
330 Container::OnBoundsChanging(const Rectangle& oldRect, const Rectangle& newRect)
331 {
332         return E_SUCCESS;
333 }
334
335 result
336 Container::OnBoundsChanging(const FloatRectangle& oldRect, const FloatRectangle& newRect)
337 {
338         return E_SUCCESS;
339 }
340
341 void
342 Container::OnEvaluateSize(Dimension& evaluatedSize)
343 {
344
345 }
346
347 bool
348 Container::OnEvaluateSize(FloatDimension& evaluatedSize)
349 {
350
351 }
352
353 void
354 Container::OnBoundsChanged(const Rectangle& oldRect, const Rectangle& newRect)
355 {
356
357 }
358
359 void
360 Container::OnBoundsChanged(const FloatRectangle& oldRect, const FloatRectangle& newRect)
361 {
362
363 }
364
365 void
366 Container::OnShowStateChanging(bool showState)
367 {
368
369 }
370
371 void
372 Container::OnShowStateChanged(bool showState)
373 {
374
375 }
376
377 Layout*
378 Container::GetPortraitLayoutN(void) const
379 {
380         const _ContainerImpl* pImpl = _ContainerImpl::GetInstance(*this);
381         SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
382
383         Layout* pLayout = pImpl->GetPublicPortraitLayoutN();
384         result r = GetLastResult();
385         SysTryReturn(NID_UI, r == E_SUCCESS, null, r, "[%s] Propagating.", GetErrorMessage(r));
386
387         return pLayout;
388 }
389
390 Layout*
391 Container::GetLandscapeLayoutN(void) const
392 {
393         const _ContainerImpl* pImpl = _ContainerImpl::GetInstance(*this);
394         SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
395
396         Layout* pLayout = pImpl->GetPublicLandscapeLayoutN();
397         result r = GetLastResult();
398         SysTryReturn(NID_UI, r == E_SUCCESS, null, r, "[%s] Propagating.", GetErrorMessage(r));
399
400         return pLayout;
401 }
402
403 Layout*
404 Container::GetLayoutN(void) const
405 {
406         const _ContainerImpl* pImpl = _ContainerImpl::GetInstance(*this);
407         SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
408
409         Layout* pLayout = pImpl->GetPublicLayoutN();
410         result r = GetLastResult();
411         SysTryReturn(NID_UI, r == E_SUCCESS, null, r, "[%s] Propagating.", GetErrorMessage(r));
412
413         return pLayout;
414 }
415
416 result
417 Container::SetControlAlwaysOnTop(Control& control, bool alwaysOnTop)
418 {
419         _ContainerImpl* pImpl = _ContainerImpl::GetInstance(*this);
420         SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
421
422         result r = pImpl->SetControlAlwaysOnTop(control, alwaysOnTop);
423         SysTryReturn(NID_UI, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
424
425         return E_SUCCESS;
426 }
427
428 result
429 Container::SetControlAlwaysAtBottom(Control& control, bool alwaysAtBottom)
430 {
431         _ContainerImpl* pImpl = _ContainerImpl::GetInstance(*this);
432         SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
433
434         result r = pImpl->SetControlAlwaysAtBottom(control, alwaysAtBottom);
435         SysTryReturn(NID_UI, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
436
437         return E_SUCCESS;
438 }
439
440
441 bool
442 Container::IsControlAlwaysAtBottom(const Control& control) const
443 {
444         return IsControlAlwaysAtBottom(&control);
445 }
446
447 bool
448 Container::IsControlAlwaysAtBottom(const Control* pControl) const
449 {
450         const _ContainerImpl* pImpl = _ContainerImpl::GetInstance(*this);
451         SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
452
453         return pImpl->IsControlAlwaysAtBottom(*pControl);
454 }
455 bool
456 Container::IsControlAlwaysOnTop(const Control& control) const
457 {
458         return IsControlAlwaysOnTop(&control);
459 }
460
461 bool
462 Container::IsControlAlwaysOnTop(const Control* pControl) const
463 {
464         const _ContainerImpl* pImpl = _ContainerImpl::GetInstance(*this);
465         SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
466
467         return pImpl->IsControlAlwaysOnTop(*pControl);
468 }
469
470 }} //Tizen::Ui