Fork for IVI: mesa fixing
[profile/ivi/uifw.git] / src / ui / controls / FUiCtrlForm.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  * @file                FUiCtrlForm.cpp
19  * @brief               This is the implementation file for Form class.
20  */
21
22 // Includes
23 #include <unique_ptr.h>
24 #include <FUiCtrlForm.h>
25 #include <FBaseSysLog.h>
26 #include "FUi_UiBuilder.h"
27 #include "FUiCtrl_FormImpl.h"
28 #include "FUiCtrl_HeaderImpl.h"
29 #include "FUiCtrl_FooterImpl.h"
30 #include "FUiCtrl_TabImpl.h"
31
32 using namespace std;
33 using namespace Tizen::Ui;
34 using namespace Tizen::Graphics;
35 using namespace Tizen::Base;
36
37 namespace Tizen { namespace Ui { namespace Controls
38 {
39
40 Form::Form(void)
41 {
42 }
43
44 Form::~Form(void)
45 {
46 }
47
48 result
49 Form::Construct(unsigned long formStyle)
50 {
51         result r = E_SUCCESS;
52
53         SysAssertf(_FormImpl::GetInstance(*this) == null,
54                         "Already constructed. Calling Construct() twice or more on a same instance is not allowed for this class.");
55
56         _FormImpl* pImpl = _FormImpl::CreateFormImplN(this);
57         SysTryReturn(NID_UI_CTRL, pImpl, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
58
59         _pControlImpl = pImpl;
60
61         pImpl->SetFormStyle(formStyle);
62         r = GetLastResult();
63         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
64
65         return r;
66 }
67
68 result
69 Form::Construct(const Tizen::Base::String& resourceId)
70 {
71         ClearLastResult();
72
73         // Parse UiBuilder XML file
74         unique_ptr<_UiBuilder> pBuilder(new _UiBuilder());
75         SysTryReturn(NID_UI_CTRL, pBuilder, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory is insufficient.");
76         result r = pBuilder->Construct(resourceId, this);
77         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
78         r = pBuilder->Parse();
79         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
80
81         return r;
82 }
83
84 result
85 Form::Construct(const Layout& layout, unsigned long formStyle)
86 {
87         result r = E_SUCCESS;
88
89         SysAssertf(_FormImpl::GetInstance(*this) == null,
90                         "Already constructed. Calling Construct() twice or more on a same instance is not allowed for this class.");
91
92         r = Construct(layout, layout, formStyle);
93         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
94
95         return r;
96 }
97
98 result
99 Form::Construct(const Layout& portraitLayout, const Layout& landscapeLayout, unsigned long formStyle)
100 {
101         result r = E_SUCCESS;
102
103         SysAssertf(_FormImpl::GetInstance(*this) == null,
104                         "Already constructed. Calling Construct() twice or more on a same instance is not allowed for this class.");
105
106         Layout* pPortraitLayout = const_cast <Layout*>(&portraitLayout);
107         Layout* pLandscapeLayout = const_cast <Layout*>(&landscapeLayout);
108
109         _FormImpl* pImpl = _FormImpl::CreateFormImplN(this, pPortraitLayout, pLandscapeLayout);
110         SysTryReturn(NID_UI_CTRL, pImpl, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
111
112         _pControlImpl = pImpl;
113
114         pImpl->SetFormStyle(formStyle);
115         r = GetLastResult();
116         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
117
118         return r;
119 }
120
121 void
122 Form::AddOrientationEventListener(IOrientationEventListener& listener)
123 {
124         _FormImpl* pImpl = _FormImpl::GetInstance(*this);
125         SysAssertf(pImpl != null,
126                                 "Not yet constructed. Construct() should be called before use.");
127
128         pImpl->AddOrientationEventListener(listener);
129 }
130
131 void
132 Form::AddOptionkeyActionListener(IActionEventListener& listener)
133 {
134         _FormImpl* pImpl = _FormImpl::GetInstance(*this);
135         SysAssertf(pImpl != null,
136                                 "Not yet constructed. Construct() should be called before use.");
137
138         pImpl->AddOptionkeyActionListener(listener);
139 }
140
141 void
142 Form::AddSoftkeyActionListener(Softkey softkey, IActionEventListener& listener)
143 {
144         _FormImpl* pImpl = _FormImpl::GetInstance(*this);
145         SysAssertf(pImpl != null,
146                                 "Not yet constructed. Construct() should be called before use.");
147
148         pImpl->AddSoftkeyActionListener(softkey, listener);
149 }
150
151 void
152 Form::RemoveOptionkeyActionListener(IActionEventListener& listener)
153 {
154         _FormImpl* pImpl = _FormImpl::GetInstance(*this);
155         SysAssertf(pImpl != null,
156                                 "Not yet constructed. Construct() should be called before use.");
157
158         pImpl->RemoveOptionkeyActionListener(listener);
159 }
160
161 void
162 Form::RemoveOrientationEventListener(IOrientationEventListener& listener)
163 {
164         _FormImpl* pImpl = _FormImpl::GetInstance(*this);
165         SysAssertf(pImpl != null,
166                                 "Not yet constructed. Construct() should be called before use.");
167
168         pImpl->RemoveOrientationEventListener(listener);
169 }
170
171 void
172 Form::RemoveSoftkeyActionListener(Softkey softkey, IActionEventListener& listener)
173 {
174         _FormImpl* pImpl = _FormImpl::GetInstance(*this);
175         SysAssertf(pImpl != null,
176                                 "Not yet constructed. Construct() should be called before use.");
177
178         pImpl->RemoveSoftkeyActionListener(softkey, listener);
179 }
180
181 Color
182 Form::GetBackgroundColor(void) const
183 {
184         const _FormImpl* pImpl = _FormImpl::GetInstance(*this);
185         SysAssertf(pImpl != null,
186                                 "Not yet constructed. Construct() should be called before use.");
187
188         return pImpl->GetBackgroundColor();
189 }
190
191 Rectangle
192 Form::GetClientAreaBounds(void) const
193 {
194         const _FormImpl* pImpl = _FormImpl::GetInstance(*this);
195         SysAssertf(pImpl != null,
196                                 "Not yet constructed. Construct() should be called before use.");
197
198         return pImpl->GetClientBounds();
199 }
200
201 unsigned long
202 Form::GetFormStyle(void) const
203 {
204         const _FormImpl* pImpl = _FormImpl::GetInstance(*this);
205         SysAssertf(pImpl != null,
206                                 "Not yet constructed. Construct() should be called before use.");
207
208         return pImpl->GetFormStyle();
209 }
210
211 Orientation
212 Form::GetOrientation(void) const
213 {
214         const _FormImpl* pImpl = _FormImpl::GetInstance(*this);
215         SysAssertf(pImpl != null,
216                                 "Not yet constructed. Construct() should be called before use.");
217
218         return pImpl->GetOrientation();
219 }
220
221 OrientationStatus
222 Form::GetOrientationStatus(void) const
223 {
224         const _FormImpl* pImpl = _FormImpl::GetInstance(*this);
225         SysAssertf(pImpl != null,
226                                 "Not yet constructed. Construct() should be called before use.");
227
228         return pImpl->GetOrientationStatus();
229 }
230
231 int
232 Form::GetSoftkeyActionId(Softkey softkey) const
233 {
234         const _FormImpl* pImpl = _FormImpl::GetInstance(*this);
235         SysAssertf(pImpl != null,
236                                 "Not yet constructed. Construct() should be called before use.");
237
238         return pImpl->GetSoftkeyActionId(softkey);
239 }
240
241 String
242 Form::GetSoftkeyText(Softkey softkey) const
243 {
244         const _FormImpl* pImpl = _FormImpl::GetInstance(*this);
245         SysAssertf(pImpl != null,
246                                 "Not yet constructed. Construct() should be called before use.");
247
248         return pImpl->GetSoftkeyText(softkey);
249 }
250
251 Tab*
252 Form::GetTab(void) const
253 {
254         _FormImpl* pImpl = const_cast <_FormImpl*>(_FormImpl::GetInstance(*this));
255                 SysAssertf(pImpl != null,
256                                 "Not yet constructed. Construct() should be called before use.");
257
258         _TabImpl* pTabImpl = pImpl->GetTabImpl();
259         if (!pTabImpl)
260         {
261                 return null;
262         }
263
264         return pTabImpl->GetTab();
265 }
266
267
268 String
269 Form::GetTitleText(void) const
270 {
271         const _FormImpl* pImpl = _FormImpl::GetInstance(*this);
272         SysAssertf(pImpl != null,
273                                 "Not yet constructed. Construct() should be called before use.");
274
275         return pImpl->GetTitleText();
276 }
277
278 HorizontalAlignment
279 Form::GetTitleTextHorizontalAlignment(void) const
280 {
281         const _FormImpl* pImpl = _FormImpl::GetInstance(*this);
282         SysAssertf(pImpl != null,
283                                 "Not yet constructed. Construct() should be called before use.");
284
285         return pImpl->GetTitleTextHorizontalAlignment();
286 }
287
288 bool
289 Form::HasIndicator(void) const
290 {
291         const _FormImpl* pImpl = _FormImpl::GetInstance(*this);
292         SysAssertf(pImpl != null,
293                                 "Not yet constructed. Construct() should be called before use.");
294
295         return pImpl->HasIndicator();
296 }
297
298 bool
299 Form::HasOptionkey(void) const
300 {
301         const _FormImpl* pImpl = _FormImpl::GetInstance(*this);
302         SysAssertf(pImpl != null,
303                                 "Not yet constructed. Construct() should be called before use.");
304
305         return pImpl->HasOptionkey();
306 }
307
308 bool
309 Form::HasSoftkey(Softkey softkey) const
310 {
311         const _FormImpl* pImpl = _FormImpl::GetInstance(*this);
312         SysAssertf(pImpl != null,
313                                 "Not yet constructed. Construct() should be called before use.");
314
315         return pImpl->HasSoftkey(softkey);
316 }
317
318 bool
319 Form::HasTab(void) const
320 {
321         const _FormImpl* pImpl = _FormImpl::GetInstance(*this);
322         SysAssertf(pImpl != null,
323                                 "Not yet constructed. Construct() should be called before use.");
324
325         return pImpl->HasTab();
326 }
327
328 bool
329 Form::HasTitle(void) const
330 {
331         const _FormImpl* pImpl = _FormImpl::GetInstance(*this);
332         SysAssertf(pImpl != null,
333                                 "Not yet constructed. Construct() should be called before use.");
334
335         return pImpl->HasTitle();
336 }
337
338 bool
339 Form::IsSoftkeyEnabled(Softkey softkey) const
340 {
341         const _FormImpl* pImpl = _FormImpl::GetInstance(*this);
342         SysAssertf(pImpl != null,
343                                 "Not yet constructed. Construct() should be called before use.");
344
345         return pImpl->IsSoftkeyEnabled(softkey);
346 }
347
348 void
349 Form::SetBackgroundColor(const Color& color)
350 {
351         _FormImpl* pImpl = _FormImpl::GetInstance(*this);
352         SysAssertf(pImpl != null,
353                                 "Not yet constructed. Construct() should be called before use.");
354
355         pImpl->SetBackgroundColor(color);
356 }
357
358 void
359 Form::SetFormStyle(unsigned long formStyle)
360 {
361         _FormImpl* pImpl = _FormImpl::GetInstance(*this);
362         SysAssertf(pImpl != null,
363                                 "Not yet constructed. Construct() should be called before use.");
364
365         pImpl->SetFormStyle(formStyle);
366 }
367
368 void
369 Form::SetOptionkeyActionId(int actionId)
370 {
371         _FormImpl* pImpl = _FormImpl::GetInstance(*this);
372         SysAssertf(pImpl != null,
373                                 "Not yet constructed. Construct() should be called before use.");
374
375         pImpl->SetOptionkeyActionId(actionId);
376 }
377
378 void
379 Form::SetOrientation(Orientation orientation)
380 {
381         _FormImpl* pImpl = _FormImpl::GetInstance(*this);
382         SysAssertf(pImpl != null,
383                                 "Not yet constructed. Construct() should be called before use.");
384
385         pImpl->SetOrientation(orientation);
386 }
387
388 void
389 Form::SetSoftkeyActionId(Softkey softkey, int actionId)
390 {
391         _FormImpl* pImpl = _FormImpl::GetInstance(*this);
392         SysAssertf(pImpl != null,
393                                 "Not yet constructed. Construct() should be called before use.");
394
395         pImpl->SetSoftkeyActionId(softkey, actionId);
396 }
397
398 void
399 Form::SetSoftkeyEnabled(Softkey softkey, bool enable)
400 {
401         _FormImpl* pImpl = _FormImpl::GetInstance(*this);
402         SysAssertf(pImpl != null,
403                                 "Not yet constructed. Construct() should be called before use.");
404
405         pImpl->SetSoftkeyEnabled(softkey, enable);
406 }
407
408 result
409 Form::SetTitleIcon(const Bitmap* pTitleBitmap)
410 {
411         _FormImpl* pImpl = _FormImpl::GetInstance(*this);
412         SysAssertf(pImpl != null,
413                                 "Not yet constructed. Construct() should be called before use.");
414
415         return pImpl->SetTitleIcon(pTitleBitmap);
416 }
417
418 result
419 Form::SetTitleText(const String& title, HorizontalAlignment alignment)
420 {
421         _FormImpl* pImpl = _FormImpl::GetInstance(*this);
422         SysAssertf(pImpl != null,
423                                 "Not yet constructed. Construct() should be called before use.");
424
425         return pImpl->SetTitleText(title, alignment);
426 }
427
428 void
429 Form::SetSoftkeyIcon(Softkey softkey, const Bitmap& normalBitmap, const Bitmap* pPressedBitmap)
430 {
431         _FormImpl* pImpl = _FormImpl::GetInstance(*this);
432         SysAssertf(pImpl != null,
433                                 "Not yet constructed. Construct() should be called before use.");
434
435         pImpl->SetSoftkeyIcon(softkey, normalBitmap, pPressedBitmap);
436 }
437
438 void
439 Form::SetSoftkeyText(Softkey softkey, const String& text)
440 {
441         _FormImpl* pImpl = _FormImpl::GetInstance(*this);
442         SysAssertf(pImpl != null,
443                                 "Not yet constructed. Construct() should be called before use.");
444
445         pImpl->SetSoftkeyText(softkey, text);
446 }
447
448 Footer*
449 Form::GetFooter(void) const
450 {
451         const _FormImpl* pImpl = _FormImpl::GetInstance(*this);
452                 SysAssertf(pImpl != null,
453                                 "Not yet constructed. Construct() should be called before use.");
454
455         _FooterImpl* pFooterImpl = pImpl->GetFooter();
456         if (!pFooterImpl)
457         {
458                 return null;
459         }
460
461         return pFooterImpl->GetFooter();
462 }
463
464 Header*
465 Form::GetHeader(void) const
466 {
467         const _FormImpl* pImpl = _FormImpl::GetInstance(*this);
468                 SysAssertf(pImpl != null,
469                                 "Not yet constructed. Construct() should be called before use.");
470
471         _HeaderImpl* pHeaderImpl = pImpl->GetHeader();
472         if (!pHeaderImpl)
473         {
474                 return null;
475         }
476
477         return pHeaderImpl->GetHeader();
478 }
479
480 bool
481 Form::HasFooter(void) const
482 {
483         const _FormImpl* pImpl = _FormImpl::GetInstance(*this);
484         SysAssertf(pImpl != null,
485                                 "Not yet constructed. Construct() should be called before use.");
486
487         return pImpl->HasFooter();
488 }
489
490 bool
491 Form::HasHeader(void) const
492 {
493         const _FormImpl* pImpl = _FormImpl::GetInstance(*this);
494         SysAssertf(pImpl != null,
495                                 "Not yet constructed. Construct() should be called before use.");
496
497         return pImpl->HasHeader();
498 }
499
500 bool
501 Form::IsIndicatorVisible(void) const
502 {
503         const _FormImpl* pImpl = _FormImpl::GetInstance(*this);
504         SysAssertf(pImpl != null,
505                                 "Not yet constructed. Construct() should be called before use.");
506
507         return pImpl->IsIndicatorVisible();
508 }
509
510 bool
511 Form::IsHeaderVisible(void) const
512 {
513         const _FormImpl* pImpl = _FormImpl::GetInstance(*this);
514         SysAssertf(pImpl != null,
515                                 "Not yet constructed. Construct() should be called before use.");
516
517         return pImpl->IsHeaderVisible();
518 }
519
520 bool
521 Form::IsFooterVisible(void) const
522 {
523         const _FormImpl* pImpl = _FormImpl::GetInstance(*this);
524         SysAssertf(pImpl != null,
525                                 "Not yet constructed. Construct() should be called before use.");
526
527         return pImpl->IsFooterVisible();
528 }
529
530 bool
531 Form::IsIndicatorTranslucent(void) const
532 {
533         const _FormImpl* pImpl = _FormImpl::GetInstance(*this);
534         SysAssertf(pImpl != null,
535                                 "Not yet constructed. Construct() should be called before use.");
536
537         return pImpl->IsIndicatorTranslucent();
538 }
539
540 bool
541 Form::IsHeaderTranslucent(void) const
542 {
543         const _FormImpl* pImpl = _FormImpl::GetInstance(*this);
544         SysAssertf(pImpl != null,
545                                 "Not yet constructed. Construct() should be called before use.");
546
547         return pImpl->IsHeaderTranslucent();
548 }
549
550 bool
551 Form::IsFooterTranslucent(void) const
552 {
553         const _FormImpl* pImpl = _FormImpl::GetInstance(*this);
554         SysAssertf(pImpl != null,
555                                 "Not yet constructed. Construct() should be called before use.");
556
557         return pImpl->IsFooterTranslucent();
558 }
559
560 result
561 Form::SetActionBarsTranslucent(unsigned long actionBars, bool translucent)
562 {
563         _FormImpl* pImpl = _FormImpl::GetInstance(*this);
564         SysAssertf(pImpl != null,
565                                 "Not yet constructed. Construct() should be called before use.");
566
567         return pImpl->SetActionBarsTranslucent(actionBars, translucent);
568 }
569
570 result
571 Form::SetActionBarsVisible(unsigned long actionBars, bool visible)
572 {
573         _FormImpl* pImpl = _FormImpl::GetInstance(*this);
574         SysAssertf(pImpl != null,
575                                 "Not yet constructed. Construct() should be called before use.");
576
577         return pImpl->SetActionBarsVisible(actionBars, visible);
578 }
579
580 OverlayRegion*
581 Form::GetOverlayRegionN(const Rectangle& rect, OverlayRegionType regionType)
582 {
583         _FormImpl* pImpl = _FormImpl::GetInstance(*this);
584                 SysAssertf(pImpl != null,
585                                 "Not yet constructed. Construct() should be called before use.");
586
587         return pImpl->GetOverlayRegionN(rect, regionType);
588 }
589
590 Canvas*
591 Form::GetClientAreaCanvasN(void) const
592 {
593         const _FormImpl* pImpl = _FormImpl::GetInstance(*this);
594                 SysAssertf(pImpl != null,
595                                 "Not yet constructed. Construct() should be called before use.");
596
597         return pImpl->GetClientAreaCanvasN();
598 }
599
600 Point
601 Form::TranslateToClientAreaPosition(const Point& position) const
602 {
603         const _FormImpl* pImpl = _FormImpl::GetInstance(*this);
604         SysAssertf(pImpl != null,
605                                 "Not yet constructed. Construct() should be called before use.");
606
607         return pImpl->TranslateToClientAreaPosition(position);
608 }
609
610 Point
611 Form::TranslateFromClientAreaPosition(const Point& clientPosition) const
612 {
613         const _FormImpl* pImpl = _FormImpl::GetInstance(*this);
614         SysAssertf(pImpl != null,
615                                 "Not yet constructed. Construct() should be called before use.");
616
617         return pImpl->TranslateFromClientAreaPosition(clientPosition);
618 }
619
620 void
621 Form::SetFormBackEventListener(IFormBackEventListener* pFormBackEventListener)
622 {
623         _FormImpl* pImpl = _FormImpl::GetInstance(*this);
624         SysAssertf(pImpl != null,
625                                 "Not yet constructed. Construct() should be called before use.");
626
627         return pImpl->SetFormBackEventListener(pFormBackEventListener);
628 }
629
630 DataBindingContext*
631 Form::GetDataBindingContextN(void) const
632 {
633         const _FormImpl* pImpl = _FormImpl::GetInstance(*this);
634         SysAssertf(pImpl != null,
635                         "Not yet constructed. Construct() should be called before use.");
636
637         return pImpl->GetDataBindingContextN();
638 }
639
640 }}} // Tizen::Ui::Controls