Changed indicator bg color.
[platform/framework/native/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 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  * @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 FloatRectangle
202 Form::GetClientAreaBoundsF(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->GetClientBoundsF();
209 }
210
211 unsigned long
212 Form::GetFormStyle(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->GetFormStyle();
219 }
220
221 Orientation
222 Form::GetOrientation(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->GetOrientation();
229 }
230
231 OrientationStatus
232 Form::GetOrientationStatus(void) 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->GetOrientationStatus();
239 }
240
241 int
242 Form::GetSoftkeyActionId(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->GetSoftkeyActionId(softkey);
249 }
250
251 String
252 Form::GetSoftkeyText(Softkey softkey) const
253 {
254         const _FormImpl* pImpl = _FormImpl::GetInstance(*this);
255         SysAssertf(pImpl != null,
256                                 "Not yet constructed. Construct() should be called before use.");
257
258         return pImpl->GetSoftkeyText(softkey);
259 }
260
261 Tab*
262 Form::GetTab(void) const
263 {
264         _FormImpl* pImpl = const_cast <_FormImpl*>(_FormImpl::GetInstance(*this));
265                 SysAssertf(pImpl != null,
266                                 "Not yet constructed. Construct() should be called before use.");
267
268         _TabImpl* pTabImpl = pImpl->GetTabImpl();
269         if (!pTabImpl)
270         {
271                 return null;
272         }
273
274         return pTabImpl->GetTab();
275 }
276
277
278 String
279 Form::GetTitleText(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->GetTitleText();
286 }
287
288 HorizontalAlignment
289 Form::GetTitleTextHorizontalAlignment(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->GetTitleTextHorizontalAlignment();
296 }
297
298 bool
299 Form::HasIndicator(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->HasIndicator();
306 }
307
308 bool
309 Form::HasOptionkey(void) 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->HasOptionkey();
316 }
317
318 bool
319 Form::HasSoftkey(Softkey softkey) 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->HasSoftkey(softkey);
326 }
327
328 bool
329 Form::HasTab(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->HasTab();
336 }
337
338 bool
339 Form::HasTitle(void) 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->HasTitle();
346 }
347
348 bool
349 Form::IsSoftkeyEnabled(Softkey softkey) const
350 {
351         const _FormImpl* pImpl = _FormImpl::GetInstance(*this);
352         SysAssertf(pImpl != null,
353                                 "Not yet constructed. Construct() should be called before use.");
354
355         return pImpl->IsSoftkeyEnabled(softkey);
356 }
357
358 void
359 Form::SetBackgroundColor(const Color& color)
360 {
361         _FormImpl* pImpl = _FormImpl::GetInstance(*this);
362         SysAssertf(pImpl != null,
363                                 "Not yet constructed. Construct() should be called before use.");
364
365         pImpl->SetBackgroundColor(color);
366 }
367
368 void
369 Form::SetFormStyle(unsigned long formStyle)
370 {
371         _FormImpl* pImpl = _FormImpl::GetInstance(*this);
372         SysAssertf(pImpl != null,
373                                 "Not yet constructed. Construct() should be called before use.");
374
375         pImpl->SetFormStyle(formStyle);
376 }
377
378 void
379 Form::SetOptionkeyActionId(int actionId)
380 {
381         _FormImpl* pImpl = _FormImpl::GetInstance(*this);
382         SysAssertf(pImpl != null,
383                                 "Not yet constructed. Construct() should be called before use.");
384
385         pImpl->SetOptionkeyActionId(actionId);
386 }
387
388 void
389 Form::SetOrientation(Orientation orientation)
390 {
391         _FormImpl* pImpl = _FormImpl::GetInstance(*this);
392         SysAssertf(pImpl != null,
393                                 "Not yet constructed. Construct() should be called before use.");
394
395         pImpl->SetOrientation(orientation);
396 }
397
398 void
399 Form::SetSoftkeyActionId(Softkey softkey, int actionId)
400 {
401         _FormImpl* pImpl = _FormImpl::GetInstance(*this);
402         SysAssertf(pImpl != null,
403                                 "Not yet constructed. Construct() should be called before use.");
404
405         pImpl->SetSoftkeyActionId(softkey, actionId);
406 }
407
408 void
409 Form::SetSoftkeyEnabled(Softkey softkey, bool enable)
410 {
411         _FormImpl* pImpl = _FormImpl::GetInstance(*this);
412         SysAssertf(pImpl != null,
413                                 "Not yet constructed. Construct() should be called before use.");
414
415         pImpl->SetSoftkeyEnabled(softkey, enable);
416 }
417
418 result
419 Form::SetTitleIcon(const Bitmap* pTitleBitmap)
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->SetTitleIcon(pTitleBitmap);
426 }
427
428 result
429 Form::SetTitleText(const String& title, HorizontalAlignment alignment)
430 {
431         _FormImpl* pImpl = _FormImpl::GetInstance(*this);
432         SysAssertf(pImpl != null,
433                                 "Not yet constructed. Construct() should be called before use.");
434
435         return pImpl->SetTitleText(title, alignment);
436 }
437
438 void
439 Form::SetSoftkeyIcon(Softkey softkey, const Bitmap& normalBitmap, const Bitmap* pPressedBitmap)
440 {
441         _FormImpl* pImpl = _FormImpl::GetInstance(*this);
442         SysAssertf(pImpl != null,
443                                 "Not yet constructed. Construct() should be called before use.");
444
445         pImpl->SetSoftkeyIcon(softkey, normalBitmap, pPressedBitmap);
446 }
447
448 void
449 Form::SetSoftkeyText(Softkey softkey, const String& text)
450 {
451         _FormImpl* pImpl = _FormImpl::GetInstance(*this);
452         SysAssertf(pImpl != null,
453                                 "Not yet constructed. Construct() should be called before use.");
454
455         pImpl->SetSoftkeyText(softkey, text);
456 }
457
458 Footer*
459 Form::GetFooter(void) const
460 {
461         const _FormImpl* pImpl = _FormImpl::GetInstance(*this);
462                 SysAssertf(pImpl != null,
463                                 "Not yet constructed. Construct() should be called before use.");
464
465         _FooterImpl* pFooterImpl = pImpl->GetFooter();
466         if (!pFooterImpl)
467         {
468                 return null;
469         }
470
471         return pFooterImpl->GetFooter();
472 }
473
474 Header*
475 Form::GetHeader(void) const
476 {
477         const _FormImpl* pImpl = _FormImpl::GetInstance(*this);
478                 SysAssertf(pImpl != null,
479                                 "Not yet constructed. Construct() should be called before use.");
480
481         _HeaderImpl* pHeaderImpl = pImpl->GetHeader();
482         if (!pHeaderImpl)
483         {
484                 return null;
485         }
486
487         return pHeaderImpl->GetHeader();
488 }
489
490 bool
491 Form::HasFooter(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->HasFooter();
498 }
499
500 bool
501 Form::HasHeader(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->HasHeader();
508 }
509
510 bool
511 Form::IsIndicatorVisible(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->IsIndicatorVisible();
518 }
519
520 bool
521 Form::IsHeaderVisible(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->IsHeaderVisible();
528 }
529
530 bool
531 Form::IsFooterVisible(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->IsFooterVisible();
538 }
539
540 bool
541 Form::IsIndicatorTranslucent(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->IsIndicatorTranslucent();
548 }
549
550 bool
551 Form::IsHeaderTranslucent(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->IsHeaderTranslucent();
558 }
559
560 bool
561 Form::IsFooterTranslucent(void) const
562 {
563         const _FormImpl* pImpl = _FormImpl::GetInstance(*this);
564         SysAssertf(pImpl != null,
565                                 "Not yet constructed. Construct() should be called before use.");
566
567         return pImpl->IsFooterTranslucent();
568 }
569
570 result
571 Form::SetActionBarsTranslucent(unsigned long actionBars, bool translucent)
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->SetActionBarsTranslucent(actionBars, translucent);
578 }
579
580 result
581 Form::SetActionBarsVisible(unsigned long actionBars, bool visible)
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->SetActionBarsVisible(actionBars, visible);
588 }
589
590 OverlayRegion*
591 Form::GetOverlayRegionN(const Rectangle& rect, OverlayRegionType regionType)
592 {
593         _FormImpl* pImpl = _FormImpl::GetInstance(*this);
594                 SysAssertf(pImpl != null,
595                                 "Not yet constructed. Construct() should be called before use.");
596
597         return pImpl->GetOverlayRegionN(rect, regionType);
598 }
599
600 OverlayRegion*
601 Form::GetOverlayRegionN(const FloatRectangle& rect, OverlayRegionType regionType)
602 {
603         _FormImpl* pImpl = _FormImpl::GetInstance(*this);
604                 SysAssertf(pImpl != null,
605                                 "Not yet constructed. Construct() should be called before use.");
606
607         return pImpl->GetOverlayRegionN(rect, regionType);
608 }
609
610 Canvas*
611 Form::GetClientAreaCanvasN(void) 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->GetClientAreaCanvasN();
618 }
619
620 Point
621 Form::TranslateToClientAreaPosition(const Point& position) const
622 {
623         const _FormImpl* pImpl = _FormImpl::GetInstance(*this);
624         SysAssertf(pImpl != null,
625                                 "Not yet constructed. Construct() should be called before use.");
626
627         return pImpl->TranslateToClientAreaPosition(position);
628 }
629
630 FloatPoint
631 Form::TranslateToClientAreaPosition(const FloatPoint& position) 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->TranslateToClientAreaPosition(position);
638 }
639
640
641 Point
642 Form::TranslateFromClientAreaPosition(const Point& clientPosition) const
643 {
644         const _FormImpl* pImpl = _FormImpl::GetInstance(*this);
645         SysAssertf(pImpl != null,
646                                 "Not yet constructed. Construct() should be called before use.");
647
648         return pImpl->TranslateFromClientAreaPosition(clientPosition);
649 }
650
651 FloatPoint
652 Form::TranslateFromClientAreaPosition(const FloatPoint& clientPosition) const
653 {
654         const _FormImpl* pImpl = _FormImpl::GetInstance(*this);
655         SysAssertf(pImpl != null,
656                                 "Not yet constructed. Construct() should be called before use.");
657
658         return pImpl->TranslateFromClientAreaPosition(clientPosition);
659 }
660
661 void
662 Form::SetFormBackEventListener(IFormBackEventListener* pFormBackEventListener)
663 {
664         _FormImpl* pImpl = _FormImpl::GetInstance(*this);
665         SysAssertf(pImpl != null,
666                                 "Not yet constructed. Construct() should be called before use.");
667
668         return pImpl->SetFormBackEventListener(pFormBackEventListener);
669 }
670
671 void
672 Form::SetFormMenuEventListener(IFormMenuEventListener* pFormMenuEventListener)
673 {
674         _FormImpl* pImpl = _FormImpl::GetInstance(*this);
675         SysAssertf(pImpl != null,
676                                 "Not yet constructed. Construct() should be called before use.");
677
678         return pImpl->SetFormMenuEventListener(pFormMenuEventListener);
679 }
680
681 DataBindingContext*
682 Form::GetDataBindingContextN(void) const
683 {
684         const _FormImpl* pImpl = _FormImpl::GetInstance(*this);
685         SysAssertf(pImpl != null,
686                         "Not yet constructed. Construct() should be called before use.");
687
688         return pImpl->GetDataBindingContextN();
689 }
690
691 result
692 Form::SetNotificationTrayOpenEnabled(bool enable)
693 {
694         _FormImpl* pImpl = _FormImpl::GetInstance(*this);
695         SysAssertf(pImpl != null,
696                                 "Not yet constructed. Construct() should be called before use.");
697
698         return pImpl->SetNotificationTrayOpenEnabled(enable);
699 }
700
701 bool
702 Form::IsNotificationTrayOpenEnabled(void) const
703 {
704         const _FormImpl* pImpl = _FormImpl::GetInstance(*this);
705         SysAssertf(pImpl != null,
706                         "Not yet constructed. Construct() should be called before use.");
707
708         return pImpl->IsNotificationTrayOpenEnabled();
709 }
710
711
712 }}} // Tizen::Ui::Controls