modify license, permission and remove ^M char
[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 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
8 //
9 //     http://www.apache.org/licenses/LICENSE-2.0/
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         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.");
148
149         result r = pImpl->AddChild(_ControlImpl::GetInstance(*pControl));
150         SysTryReturn(NID_UI, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
151
152         return E_SUCCESS;
153 }
154
155 void
156 Container::RemoveAllControls(void)
157 {
158         _ContainerImpl* pImpl = _ContainerImpl::GetInstance(*this);
159         SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
160
161         pImpl->RemoveAllChildren(false);
162 }
163
164 result
165 Container::RemoveControl(const Control& control)
166 {
167         return RemoveControl(const_cast< Control* >(&control));
168 }
169
170 result
171 Container::RemoveControl(Control* pControl)
172 {
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.");
176
177         result r = pImpl->RemoveControl(const_cast <_ControlImpl*>(_ControlImpl::GetInstance(*pControl)));
178         SysTryReturn(NID_UI, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
179
180         return E_SUCCESS;
181 }
182
183 result
184 Container::RemoveControl(int index)
185 {
186         _ContainerImpl* pImpl = _ContainerImpl::GetInstance(*this);
187         SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
188
189         result r = pImpl->RemoveControl(index);
190         SysTryReturn(NID_UI, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
191
192         return E_SUCCESS;
193 }
194
195 result
196 Container::SetControlAt(const Control& control, int index)
197 {
198         return SetControlAt(const_cast< Control* >(&control), index);
199 }
200
201 result
202 Container::SetControlAt(Control* pControl, int index)
203 {
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.");
207
208         result r = pImpl->SetChildAt(_ControlImpl::GetInstance(*pControl), index);
209         SysTryReturn(NID_UI, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
210
211         return E_SUCCESS;
212 }
213
214 result
215 Container::GetControlAt(const Control& control, int& index) const
216 {
217         return GetControlAt(&control, index);
218 }
219
220 result
221 Container::GetControlAt(const Control* pControl, int& index) const
222 {
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.");
226
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));
230
231         index = childIndex;
232
233         return E_SUCCESS;
234 }
235
236
237 int
238 Container::GetControlCount(void) const
239 {
240         const _ContainerImpl* pImpl = _ContainerImpl::GetInstance(*this);
241         SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
242
243         return pImpl->GetChildCount();
244 }
245
246 Control*
247 Container::GetControl(int index) const
248 {
249         const _ContainerImpl* pImpl = _ContainerImpl::GetInstance(*this);
250         SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
251
252         _ControlImpl* pChildImpl = pImpl->GetChild(index);
253         result r = GetLastResult();
254         SysTryReturn(NID_UI, pChildImpl, null, r, "[%s] Propagating.", GetErrorMessage(r));
255
256         return &pChildImpl->GetPublic();
257 }
258
259 Control*
260 Container::GetControl(const Tizen::Base::String& name, bool recursive) const
261 {
262         const _ContainerImpl* pImpl = _ContainerImpl::GetInstance(*this);
263         SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
264
265         _ControlImpl* pChildImpl = pImpl->SearchControlByName(name, recursive);
266         if (pChildImpl == null)
267         {
268                 return null;
269         }
270
271         return &pChildImpl->GetPublic();
272 }
273
274 IList*
275 Container::GetControls(void) const
276 {
277         const _ContainerImpl* pImpl = _ContainerImpl::GetInstance(*this);
278         SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
279
280         IList* pChildren = pImpl->GetChildrenPublic();
281         result r = GetLastResult();
282         SysTryReturn(NID_UI, r == E_SUCCESS, null, r, "[%s] Propagating.", GetErrorMessage(r));
283
284         return pChildren;
285 }
286
287 bool
288 Container::IsAncestorOf(const Control& control) const
289 {
290         return IsAncestorOf(&control);
291 }
292
293 bool
294 Container::IsAncestorOf(const Control* pControl) const
295 {
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.");
299
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));
303
304         return ancestorOf;
305 }
306
307 void
308 Container::OnClearBackground(void)
309 {
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())
313         {
314                 Canvas* pCanvas = GetCanvasN();
315                 if (pCanvas)
316                 {
317                         pCanvas->SetBackgroundColor(pImpl->GetBackgroundColor());
318                         pCanvas->Clear();
319                         delete pCanvas;
320                 }
321         }
322 }
323
324 result
325 Container::OnDraw(void)
326 {
327         _ContainerImpl* pImpl = _ContainerImpl::GetInstance(*this);
328         SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
329
330         pImpl->CallOnDraw();
331         return E_SUCCESS;
332 }
333
334 result
335 Container::OnBoundsChanging(const Rectangle& oldRect, const Rectangle& newRect)
336 {
337         return E_SUCCESS;
338 }
339
340 result
341 Container::OnBoundsChanging(const FloatRectangle& oldRect, const FloatRectangle& newRect)
342 {
343         return E_SUCCESS;
344 }
345
346 void
347 Container::OnEvaluateSize(Dimension& evaluatedSize)
348 {
349
350 }
351
352 bool
353 Container::OnEvaluateSize(FloatDimension& evaluatedSize)
354 {
355         return false;
356 }
357
358 void
359 Container::OnBoundsChanged(const Rectangle& oldRect, const Rectangle& newRect)
360 {
361
362 }
363
364 void
365 Container::OnBoundsChanged(const FloatRectangle& oldRect, const FloatRectangle& newRect)
366 {
367
368 }
369
370 void
371 Container::OnShowStateChanging(bool showState)
372 {
373
374 }
375
376 void
377 Container::OnShowStateChanged(bool showState)
378 {
379
380 }
381
382 Layout*
383 Container::GetPortraitLayoutN(void) const
384 {
385         const _ContainerImpl* pImpl = _ContainerImpl::GetInstance(*this);
386         SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
387
388         Layout* pLayout = pImpl->GetPublicPortraitLayoutN();
389         result r = GetLastResult();
390         SysTryReturn(NID_UI, r == E_SUCCESS, null, r, "[%s] Propagating.", GetErrorMessage(r));
391
392         return pLayout;
393 }
394
395 Layout*
396 Container::GetLandscapeLayoutN(void) const
397 {
398         const _ContainerImpl* pImpl = _ContainerImpl::GetInstance(*this);
399         SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
400
401         Layout* pLayout = pImpl->GetPublicLandscapeLayoutN();
402         result r = GetLastResult();
403         SysTryReturn(NID_UI, r == E_SUCCESS, null, r, "[%s] Propagating.", GetErrorMessage(r));
404
405         return pLayout;
406 }
407
408 Layout*
409 Container::GetLayoutN(void) const
410 {
411         const _ContainerImpl* pImpl = _ContainerImpl::GetInstance(*this);
412         SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
413
414         Layout* pLayout = pImpl->GetPublicLayoutN();
415         result r = GetLastResult();
416         SysTryReturn(NID_UI, r == E_SUCCESS, null, r, "[%s] Propagating.", GetErrorMessage(r));
417
418         return pLayout;
419 }
420
421 result
422 Container::SetControlAlwaysOnTop(Control& control, bool alwaysOnTop)
423 {
424         _ContainerImpl* pImpl = _ContainerImpl::GetInstance(*this);
425         SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
426
427         result r = pImpl->SetControlAlwaysOnTop(control, alwaysOnTop);
428         SysTryReturn(NID_UI, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
429
430         return E_SUCCESS;
431 }
432
433 result
434 Container::SetControlAlwaysAtBottom(Control& control, bool alwaysAtBottom)
435 {
436         _ContainerImpl* pImpl = _ContainerImpl::GetInstance(*this);
437         SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
438
439         result r = pImpl->SetControlAlwaysAtBottom(control, alwaysAtBottom);
440         SysTryReturn(NID_UI, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
441
442         return E_SUCCESS;
443 }
444
445
446 bool
447 Container::IsControlAlwaysAtBottom(const Control& control) const
448 {
449         return IsControlAlwaysAtBottom(&control);
450 }
451
452 bool
453 Container::IsControlAlwaysAtBottom(const Control* pControl) const
454 {
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.");
458
459         return pImpl->IsControlAlwaysAtBottom(*pControl);
460 }
461 bool
462 Container::IsControlAlwaysOnTop(const Control& control) const
463 {
464         return IsControlAlwaysOnTop(&control);
465 }
466
467 bool
468 Container::IsControlAlwaysOnTop(const Control* pControl) const
469 {
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.");
473
474         return pImpl->IsControlAlwaysOnTop(*pControl);
475 }
476
477 }} //Tizen::Ui