Revert "Adjust the position of the partial Frame"
[platform/framework/native/uifw.git] / src / ui / controls / FUiCtrl_FormImpl.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 #include <app.h>
19 #include <new>
20 #include <FUiControls.h>
21 #include <FBaseInteger.h>
22 #include <FBaseColLinkedListT.h>
23 #include <FUiCtrlHeader.h>
24 #include <FUiCtrlFooter.h>
25 #include <FUiCtrlTab.h>
26 #include <FUiLayout.h>
27 #include <FBaseSysLog.h>
28 #include <FApp_AppInfo.h>
29 #include <FGrpFloatRectangle.h>
30 #include "FUi_LayoutImpl.h"
31 #include "FUi_LayoutLayoutMaker.h"
32 #include "FUi_EcoreEvasMgr.h"
33 #include "FUi_EcoreEvas.h"
34 #include "FUi_ControlImplManager.h"
35 #include "FUi_OrientationAgent.h"
36 #include "FUi_UiBuilder.h"
37 #include "FUi_CoordinateSystemUtils.h"
38 #include "FUi_DataBindingContextImpl.h"
39 #include "FUi_ResourceSizeInfo.h"
40 #include "FUi_ResourceManager.h"
41 #include "FUiAnim_VisualElement.h"
42 #include "FUiCtrl_FormImpl.h"
43 #include "FUiCtrl_HeaderImpl.h"
44 #include "FUiCtrl_FooterImpl.h"
45 #include "FUiCtrl_Form.h"
46 #include "FUiCtrl_Frame.h"
47 #include "FUiCtrl_TabImpl.h"
48 #include "FUiCtrl_Indicator.h"
49
50 using namespace Tizen::App;
51 using namespace Tizen::Base;
52 using namespace Tizen::Base::Runtime;
53 using namespace Tizen::Base::Collection;
54 using namespace Tizen::Graphics;
55 using namespace Tizen::Ui;
56 using namespace Tizen::Ui::Animations;
57
58 #define OPTIONKEY       SOFTKEY_COUNT
59
60 namespace Tizen { namespace Ui { namespace Controls
61 {
62
63 const String _REQUEST_ORIENTATION_EVENT = L"RequestOrientationEvent";
64
65 Dimension
66 _FormImpl::FormSizeInfo::GetDefaultMinimumSize(_ControlOrientation orientation) const
67 {
68         result r = E_SUCCESS;
69         Dimension dimension(0, 0);
70         SetLastResult(r);
71
72         return dimension;
73 }
74
75 FloatDimension
76 _FormImpl::FormSizeInfo::GetDefaultMinimumSizeF(_ControlOrientation orientation) const
77 {
78         result r = E_SUCCESS;
79         FloatDimension dimension(0.0f, 0.0f);
80         SetLastResult(r);
81
82         return dimension;
83 }
84
85 const _FormImpl*
86 _FormImpl::GetInstance(const Form& form)
87 {
88         return static_cast<const _FormImpl*> (form._pControlImpl);
89 }
90
91 _FormImpl*
92 _FormImpl::GetInstance(Form& form)
93 {
94         return static_cast<_FormImpl*> (form._pControlImpl);
95 }
96
97 _FormImpl::_FormImpl(Form* pPublic, _Form* pCore, Layout* pPublicPortraitLayout, Layout* pPublicLandscapeLayout)
98         : _ContainerImpl(pPublic, pCore, pPublicPortraitLayout, pPublicLandscapeLayout)
99         , __pForm(null)
100         , __pFormBackEventListener(null)
101         , __pOriAgent(null)
102         , __pLeftSoftkeyActionEvent(null)
103         , __pRightSoftkeyActionEvent(null)
104         , __pOptionMenuActionEvent(null)
105 {
106         __pForm = pCore;
107
108         __pOriAgent = _OrientationAgent::CreateInstanceN(*pPublic);
109         SysTryReturnVoidResult(NID_UI_CTRL, __pOriAgent != null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
110 }
111
112 _FormImpl::~_FormImpl(void)
113 {
114         delete __pOriAgent;
115         __pOriAgent = null;
116
117         if (__pLeftSoftkeyActionEvent)
118         {
119                 delete __pLeftSoftkeyActionEvent;
120                 __pLeftSoftkeyActionEvent = null;
121         }
122
123         if (__pRightSoftkeyActionEvent)
124         {
125                 delete __pRightSoftkeyActionEvent;
126                 __pRightSoftkeyActionEvent = null;
127         }
128
129         if (__pOptionMenuActionEvent)
130         {
131                 delete __pOptionMenuActionEvent;
132                 __pOptionMenuActionEvent = null;
133         }
134
135         __leftSoftkeyActionList.RemoveAll(false);
136         __rightSoftkeyActionList.RemoveAll(false);
137
138         RemoveHeader();
139         RemoveFooter();
140         RemoveTabImpl();
141
142         __pForm = null;
143
144         ClearLastResult();
145 }
146
147 _FormImpl*
148 _FormImpl::CreateFormImplN(Form* pControl, Layout* pPublicPortraitLayout, Layout* pPublicLandscapeLayout)
149 {
150         result r = E_SUCCESS;
151         _VisualElement* pVisualElement = null;
152
153         _Form* pCore = _Form::CreateFormN();
154         r = GetLastResult();
155         SysTryReturn(NID_UI_CTRL, pCore, null, r, "[%s] Propagating.", GetErrorMessage(r)); // [ToDo] interpret last result.
156
157         _FormImpl* pImpl = new (std::nothrow) _FormImpl(pControl, pCore, pPublicPortraitLayout, pPublicLandscapeLayout);
158
159         r = _ControlImpl::CheckConstruction(pCore, pImpl);
160         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, null, r, "[%s] Propagating.", GetErrorMessage(r));
161
162         const FloatDimension portraitSize = _ControlManager::GetInstance()->_ControlManager::GetScreenSizeF();
163         const FloatDimension landscapeSize = FloatDimension(portraitSize.height, portraitSize.width);
164
165         _ControlOrientation orientation = pCore->GetOrientation();
166
167         if (orientation == _CONTROL_ORIENTATION_PORTRAIT)
168         {
169                 r = pImpl->InitializeBoundsPropertiesF(GET_SIZE_INFO(Form), portraitSize, orientation);
170         }
171         else
172         {
173                 r = pImpl->InitializeBoundsPropertiesF(GET_SIZE_INFO(Form), landscapeSize, orientation);
174         }
175         SysAssert(r == E_SUCCESS);
176
177         // Make surface opaque.
178         pVisualElement = pCore->GetVisualElement();
179         SysTryCatch(NID_UI_CTRL, pVisualElement, , GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
180         r = pVisualElement->SetSurfaceOpaque(true);
181         SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r)); // [ToDo] interpret last result.
182
183         SetLastResult(E_SUCCESS);
184
185         return pImpl;
186
187 CATCH:
188         delete pCore;
189         delete pImpl;
190
191         return null;
192 }
193
194 const char*
195 _FormImpl::GetPublicClassName(void) const
196 {
197         return "Tizen::Ui::Controls::Form";
198 }
199
200 const Form&
201 _FormImpl::GetPublic(void) const
202 {
203         return static_cast<const Form&>(_ControlImpl::GetPublic());
204 }
205
206 Form&
207 _FormImpl::GetPublic(void)
208 {
209         return static_cast<Form&>(_ControlImpl::GetPublic());
210 }
211
212 const _Form&
213 _FormImpl::GetCore(void) const
214 {
215         return static_cast<const _Form&>(_ControlImpl::GetCore());
216 }
217
218 _Form&
219 _FormImpl::GetCore(void)
220 {
221         return static_cast<_Form&>(_ControlImpl::GetCore());
222 }
223
224 _ControlImpl*
225 _FormImpl::GetFocusControl(void)
226 {
227         return null;
228 }
229
230 unsigned long
231 _FormImpl::GetFormStyle(void) const
232 {
233         return GetCore().GetFormStyle();
234 }
235
236 bool
237 _FormImpl::HasIndicator(void) const
238 {
239         return GetCore().HasIndicator();
240 }
241
242 void
243 _FormImpl::SetFormStyle(unsigned long formStyle)
244 {
245         result r = E_SUCCESS;
246
247         _HeaderImpl* pHeader = GetHeader();
248         _FooterImpl* pFooter = GetFooter();
249         _TabImpl* pTabImpl = GetTabImpl();
250
251         if (IsAttachedToMainTree())
252         {
253                 if (FORM_STYLE_INDICATOR & formStyle)
254                 {
255                         _Frame* pFrame = dynamic_cast<_Frame*>(GetCore().GetParent());
256                         SysTryReturnVoidResult(NID_UI_CTRL, pFrame != null, E_INVALID_ARG, "A Form which has FORM_STYLE_INDICATOR style cannot be added to a container except Frame.");
257                 }
258         }
259
260         // check formstyle
261         if (((formStyle & FORM_STYLE_TITLE) || (formStyle & FORM_STYLE_TEXT_TAB) || (formStyle & FORM_STYLE_ICON_TAB)) && (formStyle & FORM_STYLE_HEADER))
262         {
263                 SysLogException(NID_UI_CTRL, E_INVALID_ARG, "[E_INVALID_ARG] Invalid form style. FORM_STYLE_TITLE, FORM_STYLE_TEXT_TAB or FORM_STYLE_ICON_TAB and FORM_STYLE_HEADER can't use each other.");
264
265                 // remove Header
266                 if (pHeader)
267                 {
268                         RemoveHeader();
269                         r = GetLastResult();
270                         SysTryReturnVoidResult(NID_UI_CTRL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
271                 }
272
273                 return;
274         }
275
276         if (((formStyle & FORM_STYLE_SOFTKEY_0) || (formStyle & FORM_STYLE_SOFTKEY_1) || (formStyle & FORM_STYLE_OPTIONKEY)) && (formStyle & FORM_STYLE_FOOTER))
277         {
278                 SysLogException(NID_UI_CTRL, E_INVALID_ARG, "[E_INVALID_ARG] Invalid form style. FORM_STYLE_SOFTKEY0, FORM_STYLE_SOFTKEY_1 or FORM_STYLE_OPTIONKEY and FORM_STYLE_FOOTER can't use each other.");
279
280                 // remove Footer
281                 if (pFooter)
282                 {
283                         RemoveFooter();
284                         r = GetLastResult();
285                         SysTryReturnVoidResult(NID_UI_CTRL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
286                 }
287                 return;
288         }
289
290         _EcoreEvas* pEcoreEvas = GetEcoreEvasMgr()->GetEcoreEvas();
291         SysTryReturnVoidResult(NID_UI_CTRL, pEcoreEvas, E_SYSTEM, "[E_SYSTEM] Unable to get evas.");
292
293         GetCore().SetFormStyle(formStyle);
294
295         FloatRectangle indicatorBounds(0.0f, 0.0f, 0.0f, 0.0f);
296
297         if (FORM_STYLE_INDICATOR & formStyle)
298         {
299                 GetCore().SetIndicatorShowState(true);
300                 indicatorBounds = GetCore().GetIndicatorBoundsF();
301                 r = GetLastResult();
302                 SysTryReturnVoidResult(NID_UI_CTRL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
303
304         }
305         else if(FORM_STYLE_INDICATOR_AUTO_HIDE & formStyle)
306         {
307                 r = GetCore().SetIndicatorShowState(false, true);
308                 SysTryReturnVoidResult(NID_UI_CTRL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
309         }
310         else
311         {
312                 r = GetCore().SetIndicatorShowState(false);
313                 SysTryReturnVoidResult(NID_UI_CTRL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
314         }
315
316         if (formStyle & FORM_STYLE_HEADER)
317         {
318                 if (!pHeader)
319                 {
320                         pHeader = CreateHeaderN();
321                         SysTryReturnVoidResult(NID_UI_CTRL, pHeader != null, r, "[%s] Propagating.", GetErrorMessage(r));
322
323                         GetCore().SetHeader(&pHeader->GetCore());
324                         GetCore().AdjustClientBounds();
325
326                         FloatRectangle bounds(0.0f, indicatorBounds.height, GetClientBoundsF().width, GetCore().GetToolbarHeightF(true));
327                         GetCore().SetHeaderBounds(bounds);
328
329                         r = GetCore().AttachSystemChild(pHeader->GetCore());
330                         SysTryReturnVoidResult(NID_UI_CTRL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
331
332                         GetCore().SetFormBackEventListener(this);
333                 }
334         }
335         else if (formStyle & FORM_STYLE_TITLE)
336         {
337                 if (!pHeader)
338                 {
339                         pHeader = CreateHeaderN();
340                         SysTryReturnVoidResult(NID_UI_CTRL, pHeader != null, r, "[%s] Propagating.", GetErrorMessage(r));
341
342                         GetCore().SetHeader(&pHeader->GetCore());
343                         GetCore().AdjustClientBounds();
344
345                         FloatRectangle bounds(0.0f, indicatorBounds.height, GetClientBoundsF().width, GetCore().GetToolbarHeightF(true));
346                         GetCore().SetHeaderBounds(bounds);
347
348                         r = GetCore().AttachSystemChild(pHeader->GetCore());
349                         SysTryReturnVoidResult(NID_UI_CTRL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
350                 }
351         }
352         else
353         {
354                 // remove Header
355                 if (pHeader)
356                 {
357                         RemoveHeader();
358                         r = GetLastResult();
359                         SysTryReturnVoidResult(NID_UI_CTRL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
360                 }
361         }
362
363         _Indicator* pIndicator = GetCore().GetIndicator();
364         r = GetCore().AttachSystemChild(*pIndicator);
365         SysTryReturnVoidResult(NID_UI_CTRL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
366
367         if (formStyle & FORM_STYLE_TEXT_TAB)
368         {
369                 float titleHeight = 0.0f;
370
371                 if (formStyle & FORM_STYLE_TITLE)
372                 {
373                         if (pHeader)
374                         {
375                                 titleHeight = pHeader->GetBoundsF().height;
376                         }
377                 }
378
379                 if (!pTabImpl)
380                 {
381                         pTabImpl = CreateTabImplN();
382                         SysTryReturnVoidResult(NID_UI_CTRL, pTabImpl != null, r, "[%s] Propagating.", GetErrorMessage(r));
383
384                         float posY = indicatorBounds.height + titleHeight;
385
386                         GetCore().SetTab(&pTabImpl->GetCore());
387                         GetCore().AdjustClientBounds();
388
389                         FloatRectangle bounds(0.0f, posY, GetClientBoundsF().width, GetCore().GetTabHeightF());
390                         GetCore().SetTabBounds(bounds);
391
392                         r = GetCore().AttachSystemChild(pTabImpl->GetCore());
393                         SysTryReturnVoidResult(NID_UI_CTRL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
394                 }
395                 GetCore().SetTabStyle(_TAB_STYLE_TEXT);
396         }
397         else if (formStyle & FORM_STYLE_ICON_TAB)
398         {
399                 float titleHeight = 0.0f;
400
401                 if (formStyle & FORM_STYLE_TITLE)
402                 {
403                         if (pHeader)
404                         {
405                                 titleHeight = pHeader->GetBoundsF().height;
406                         }
407                 }
408
409                 if (!pTabImpl)
410                 {
411                         pTabImpl = CreateTabImplN();
412                         SysTryReturnVoidResult(NID_UI_CTRL, pTabImpl != null, r, "[%s] Propagating.", GetErrorMessage(r));
413
414                         float posY = indicatorBounds.height + titleHeight;
415
416                         GetCore().SetTab(&pTabImpl->GetCore());
417                         GetCore().AdjustClientBounds();
418
419                         FloatRectangle bounds(0.0f, posY, GetClientBoundsF().width, GetCore().GetTabHeightF());
420                         GetCore().SetTabBounds(bounds);
421
422                         r = GetCore().AttachSystemChild(pTabImpl->GetCore());
423                         SysTryReturnVoidResult(NID_UI_CTRL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
424                 }
425                 GetCore().SetTabStyle(_TAB_STYLE_ICON);
426         }
427         else
428         {
429                 if (pTabImpl)
430                 {
431                         RemoveTabImpl();
432                         r = GetLastResult();
433                         SysTryReturnVoidResult(NID_UI_CTRL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
434                 }
435         }
436
437         if (formStyle & FORM_STYLE_FOOTER)
438         {
439                 if (!pFooter)
440                 {
441                         pFooter = CreateFooterN();
442                         SysTryReturnVoidResult(NID_UI_CTRL, pFooter != null, r, "[%s] Propagating.", GetErrorMessage(r));
443
444                         GetCore().SetFooter(&pFooter->GetCore());
445                         GetCore().AdjustClientBounds();
446
447                         FloatRectangle clientbounds = GetClientBoundsF();
448                         FloatRectangle bounds(0.0f, clientbounds.y + clientbounds.height, clientbounds.width, GetCore().GetToolbarHeightF(false));
449
450                         GetCore().SetFooterBounds(bounds);
451
452                         r = GetCore().AttachSystemChild(pFooter->GetCore());
453                         SysTryReturnVoidResult(NID_UI_CTRL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
454                         //[ToDo]
455                         GetCore().SetFormBackEventListener(this);
456                 }
457         }
458         else if (formStyle & FORM_STYLE_SOFTKEY_0 || formStyle & FORM_STYLE_SOFTKEY_1 || formStyle & FORM_STYLE_OPTIONKEY)
459         {
460                 if (pFooter)
461                 {
462                         RemoveFooter();
463                         r = GetLastResult();
464                         SysTryReturnVoidResult(NID_UI_CTRL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
465                 }
466
467                 pFooter = GetFooter();
468
469                 if (!pFooter)
470                 {
471                         pFooter = CreateFooterN();
472                         SysTryReturnVoidResult(NID_UI_CTRL, pFooter != null, r, "[%s] Propagating.", GetErrorMessage(r));
473
474                         GetCore().SetFooter(&pFooter->GetCore());
475                         GetCore().AdjustClientBounds();
476
477                         FloatRectangle clientbounds = GetClientBoundsF();
478                         FloatRectangle bounds(0.0f, clientbounds.y + clientbounds.height - GetCore().GetToolbarHeightF(false), clientbounds.width, GetCore().GetToolbarHeightF(false));
479
480                         GetCore().SetFooterBounds(bounds);
481
482                         r = GetCore().AttachSystemChild(pFooter->GetCore());
483                         SysTryReturnVoidResult(NID_UI_CTRL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
484
485                         GetCore().CreateSoftkey(formStyle);
486
487                         pFooter->GetCore().AddActionEventListener(*this);
488                 }
489         }
490         else
491         {
492                 // remove Footer
493                 if (pFooter)
494                 {
495                         RemoveFooter();
496                         r = GetLastResult();
497                         SysTryReturnVoidResult(NID_UI_CTRL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
498                         GetCore().AdjustClientBounds();
499                 }
500         }
501
502         GetCore().AdjustClientBounds();
503
504         SetLastResult(E_SUCCESS);
505
506         return;
507 }
508
509 _FooterImpl*
510 _FormImpl::GetFooter(void) const
511 {
512         _Toolbar* pToolbar = __pForm->GetFooter();
513         if (pToolbar == null)
514         {
515                 return null;
516         }
517
518         _FooterImpl* pFooterImpl = static_cast<_FooterImpl*>(pToolbar->GetUserData());
519
520         return pFooterImpl;
521 }
522
523 _HeaderImpl*
524 _FormImpl::GetHeader(void) const
525 {
526         _Toolbar* pToolbar = __pForm->GetHeader();
527         if (pToolbar == null)
528         {
529                 return null;
530         }
531
532         _HeaderImpl* pHeaderImpl = static_cast<_HeaderImpl*>(pToolbar->GetUserData());
533
534         return pHeaderImpl;
535 }
536
537 // Ki-Dong,Hong.Temp
538 _TabImpl*
539 _FormImpl::GetTabImpl(void) const
540 {
541         _Tab* pTab = __pForm->GetTab();
542         if (pTab == null)
543         {
544                 return null;
545         }
546
547         _TabImpl* pTabImpl = static_cast<_TabImpl*>(pTab->GetUserData());
548
549         return pTabImpl;
550 }
551
552 String
553 _FormImpl::GetTitleText(void) const
554 {
555         return GetCore().GetTitleText();
556 }
557
558 HorizontalAlignment
559 _FormImpl::GetTitleTextHorizontalAlignment(void) const
560 {
561         return GetCore().GetTitleTextHorizontalAlignment();
562 }
563
564 bool
565 _FormImpl::HasFooter(void) const
566 {
567         return GetCore().HasFooter();
568 }
569
570 bool
571 _FormImpl::HasHeader(void) const
572 {
573         return GetCore().HasHeader();
574 }
575
576 bool
577 _FormImpl::HasTitle(void) const
578 {
579         return GetCore().HasTitle();
580 }
581
582 bool
583 _FormImpl::HasTab(void) const
584 {
585         return GetCore().HasTab();
586 }
587
588 bool
589 _FormImpl::IsIndicatorVisible(void) const
590 {
591         return GetCore().IsIndicatorVisible();
592 }
593
594 bool
595 _FormImpl::IsHeaderVisible(void) const
596 {
597         return GetCore().IsHeaderVisible();
598 }
599
600 bool
601 _FormImpl::IsFooterVisible(void) const
602 {
603         return GetCore().IsFooterVisible();
604 }
605
606 bool
607 _FormImpl::IsIndicatorTranslucent(void) const
608 {
609         return GetCore().IsIndicatorTranslucent();
610 }
611
612 bool
613 _FormImpl::IsHeaderTranslucent(void) const
614 {
615         return GetCore().IsHeaderTranslucent();
616 }
617
618 bool
619 _FormImpl::IsFooterTranslucent(void) const
620 {
621         return GetCore().IsFooterTranslucent();
622 }
623
624 // Ki-Dong,Hong.Temp
625 bool
626 _FormImpl::IsTabTranslucent(void) const
627 {
628         return GetCore().IsTabTranslucent();
629 }
630
631 result
632 _FormImpl::SetActionBarsTranslucent(unsigned long actionBars, bool translucent)
633 {
634         return GetCore().SetActionBarsTranslucent(actionBars, translucent);
635 }
636
637 result
638 _FormImpl::SetActionBarsVisible(unsigned long actionBars, bool visible)
639 {
640         return GetCore().SetActionBarsVisible(actionBars, visible);
641 }
642
643 result
644 _FormImpl::SetTitleIcon(const Bitmap* pTitleBitmap)
645 {
646         return GetCore().SetTitleIcon(pTitleBitmap);
647 }
648
649 result
650 _FormImpl::SetTitleText(const String& title, HorizontalAlignment alignment)
651 {
652         return GetCore().SetTitleText(title, alignment);
653 }
654
655 OverlayRegion*
656 _FormImpl::GetOverlayRegionN(const Rectangle& rect, OverlayRegionType regionType)
657 {
658         return GetCore().GetOverlayRegionN(rect, regionType);
659 }
660
661 OverlayRegion*
662 _FormImpl::GetOverlayRegionN(const FloatRectangle& rect, OverlayRegionType regionType)
663 {
664         return GetCore().GetOverlayRegionN(rect, regionType);
665 }
666
667 void
668 _FormImpl::OnDraw(void)
669 {
670         __pOriAgent->FireOrientationEvent();
671
672         _ContainerImpl::OnDraw();
673 }
674
675 bool
676 _FormImpl::OnKeyReleased(const _ControlImpl& source, _KeyCode keyCode)
677 {
678         switch (keyCode)
679         {
680         case _KEY_BACKSPACE:
681                 if (GetCore().GetFooter() || GetCore().GetHeader())
682                 {
683                         if (__pFormBackEventListener)
684                         {
685                                 Form* pForm = dynamic_cast <Form*>(&GetPublic());
686                                 if (pForm)
687                                 {
688                                         __pFormBackEventListener->OnFormBackRequested(*pForm);
689                                 }
690                         }
691                         else
692                         {
693                                 break;
694                         }
695                 }
696                 else
697                 {
698                         break;
699                 }
700                 break;
701
702         default:
703                 return false;
704         }
705
706         return true;
707 }
708
709 void
710 _FormImpl::OnActionPerformed(const _Control& source, int actionId)
711 {
712         if (GetFormStyle() & FORM_STYLE_SOFTKEY_0 || GetFormStyle() & FORM_STYLE_SOFTKEY_1 || GetFormStyle() & FORM_STYLE_OPTIONKEY)
713         {
714                 Tizen::Base::Runtime::IEventArg* tempArg = null;
715                 tempArg = _PublicActionEvent::CreateActionEventArgN(actionId);
716                 SysTryReturnVoidResult(NID_UI_CTRL, tempArg , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Unable to create Eventarg.");
717                 bool fired = true;
718
719                 _PublicActionEvent* pSoftkeyActionEvent = null;
720
721                 if (GetCore().GetFooter()->IsButtonSet(LEFT_BUTTON) && GetSoftkeyActionId(SOFTKEY_0) == actionId)
722                 {
723                         for (int i = 0; i < __leftSoftkeyActionList.GetCount(); i++)
724                         {
725                                 pSoftkeyActionEvent = dynamic_cast<_PublicActionEvent*>(__leftSoftkeyActionList.GetAt(i));
726
727                                 if (pSoftkeyActionEvent)
728                                 {
729                                         pSoftkeyActionEvent->Fire(*tempArg);
730                                         fired = false;
731                                 }
732                         }
733                 }
734
735                 if (GetCore().GetFooter()->IsButtonSet(RIGHT_BUTTON) && GetSoftkeyActionId(SOFTKEY_1) == actionId)
736                 {
737                         for (int i = 0; i < __rightSoftkeyActionList.GetCount(); i++)
738                         {
739                                 pSoftkeyActionEvent = dynamic_cast<_PublicActionEvent*>(__rightSoftkeyActionList.GetAt(i));
740
741                                 if (pSoftkeyActionEvent)
742                                 {
743                                         pSoftkeyActionEvent->Fire(*tempArg);
744                                         fired = false;
745                                 }
746                         }
747                 }
748
749                 if (GetCore().GetFooter()->IsButtonSet(MIDDLE_BUTTON) && GetOptionkeyActionId() == actionId)
750                 {
751                         if (__pOptionMenuActionEvent)
752                         {
753                                 __pOptionMenuActionEvent->Fire(*tempArg);
754                                 fired = false;
755                         }
756                 }
757                 if (fired)
758                 {
759                         delete tempArg;
760                 }
761         }
762 }
763
764 Canvas*
765 _FormImpl::GetClientAreaCanvasN(void) const
766 {
767         return GetCore().GetClientAreaCanvasN();
768 }
769
770 Point
771 _FormImpl::TranslateToClientAreaPosition(const Point& position) const
772 {
773         return GetCore().TranslateToClientAreaPosition(position);
774 }
775
776 FloatPoint
777 _FormImpl::TranslateToClientAreaPosition(const FloatPoint& position) const
778 {
779         return GetCore().TranslateToClientAreaPosition(position);
780 }
781
782 Point
783 _FormImpl::TranslateFromClientAreaPosition(const Point& clientPosition) const
784 {
785         return GetCore().TranslateFromClientAreaPosition(clientPosition);
786 }
787
788 FloatPoint
789 _FormImpl::TranslateFromClientAreaPosition(const FloatPoint& clientPosition) const
790 {
791         return GetCore().TranslateFromClientAreaPosition(clientPosition);
792 }
793
794 void
795 _FormImpl::SetFormBackEventListener(const IFormBackEventListener* pFormBackEventListener)
796 {
797         SysTryReturnVoidResult(NID_UI_CTRL, GetFooter() || GetHeader(), E_INVALID_STATE, "[E_INVALID_STATE] Footer isn't constructed.");
798         __pFormBackEventListener = const_cast <IFormBackEventListener*>(pFormBackEventListener);
799         GetCore().SetFormBackEventListener(this);
800         result r = GetLastResult();
801         SysTryReturnVoidResult(NID_UI_CTRL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
802 }
803
804 void
805 _FormImpl::AddOrientationEventListener(IOrientationEventListener& listener)
806 {
807         __pOriAgent->AddListener(listener);
808 }
809
810 void
811 _FormImpl::AddOptionkeyActionListener(const IActionEventListener& listener)
812 {
813         if (HasOptionkey() == false)
814         {
815                 return ;
816         }
817
818         __pOptionMenuActionEvent = _PublicActionEvent::CreateInstanceN(GetPublic());
819
820         SysTryReturnVoidResult(NID_UI_CTRL, __pOptionMenuActionEvent != null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
821
822         __pOptionMenuActionEvent->AddListener(listener);
823 }
824
825 void
826 _FormImpl::AddSoftkeyActionListener(Softkey softkey, const IActionEventListener& listener)
827 {
828         _Softkey _softkey = ConvertSoftkey(softkey);
829
830         if (GetCore().CheckSoftkey(_softkey) == false)
831         {
832                 return ;
833         }
834
835         if (softkey == SOFTKEY_0)
836         {
837                 __pLeftSoftkeyActionEvent = _PublicActionEvent::CreateInstanceN(GetPublic());
838
839                 SysTryReturnVoidResult(NID_UI_CTRL, __pLeftSoftkeyActionEvent != null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
840
841                 __pLeftSoftkeyActionEvent->AddListener(listener);
842
843                 __leftSoftkeyActionList.Add(*__pLeftSoftkeyActionEvent);
844         }
845         else if (softkey == SOFTKEY_1)
846         {
847                 __pRightSoftkeyActionEvent = _PublicActionEvent::CreateInstanceN(GetPublic());
848
849                 SysTryReturnVoidResult(NID_UI_CTRL, __pRightSoftkeyActionEvent != null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
850
851                 __pRightSoftkeyActionEvent->AddListener(listener);
852
853                 __rightSoftkeyActionList.Add(*__pRightSoftkeyActionEvent);
854         }
855 }
856
857 void
858 _FormImpl::RemoveOrientationEventListener(IOrientationEventListener& listener)
859 {
860         __pOriAgent->RemoveListener(listener);
861 }
862
863 void
864 _FormImpl::RemoveOptionkeyActionListener(const IActionEventListener& listener)
865 {
866         if (HasOptionkey() == false)
867         {
868                 return ;
869         }
870
871         if (__pOptionMenuActionEvent)
872         {
873                 __pOptionMenuActionEvent->RemoveListener(listener);
874         }
875 }
876
877 void
878 _FormImpl::RemoveSoftkeyActionListener(Softkey softkey, const IActionEventListener& listener)
879 {
880         _Softkey _softkey = ConvertSoftkey(softkey);
881
882         if (GetCore().CheckSoftkey(_softkey) == false)
883         {
884                 return ;
885         }
886
887         if (softkey == SOFTKEY_0)
888         {
889                 if (__pLeftSoftkeyActionEvent)
890                 {
891                         __pLeftSoftkeyActionEvent->RemoveListener(listener);
892                 }
893         }
894         else if (softkey == SOFTKEY_1)
895         {
896                 if (__pRightSoftkeyActionEvent)
897                 {
898                         __pRightSoftkeyActionEvent->RemoveListener(listener);
899                 }
900         }
901 }
902
903 void
904 _FormImpl::SetOrientation(Orientation orientation)
905 {
906         __pOriAgent->SetMode(orientation);
907 }
908
909 Orientation
910 _FormImpl::GetOrientation(void) const
911 {
912         return __pOriAgent->GetMode();
913 }
914
915 OrientationStatus
916 _FormImpl::GetOrientationStatus(void) const
917 {
918         return __pOriAgent->GetStatus();
919 }
920
921 void
922 _FormImpl::UpdateOrientationStatus(bool draw)
923 {
924         __pOriAgent->Update(draw);
925 }
926
927 #if defined(WINDOW_BASE_ROTATE)
928 void
929 _FormImpl::UpdateOrientation(void)
930 {
931         __pOriAgent->UpdateOrientation();
932 }
933 #endif
934
935 bool
936 _FormImpl::HasOptionkey(void) const
937 {
938         return GetCore().HasOptionkey();
939 }
940
941 bool
942 _FormImpl::HasSoftkey(Softkey softkey) const
943 {
944         _Softkey _softkey = ConvertSoftkey(softkey);
945
946         return GetCore().HasSoftkey(_softkey);
947 }
948
949 result
950 _FormImpl::SetSoftkeyEnabled(Softkey softkey, bool enable)
951 {
952         _Softkey _softkey = ConvertSoftkey(softkey);
953
954         result r = GetCore().SetSoftkeyEnabled(_softkey, enable);
955         SysTryLog(NID_UI_CTRL, r == E_SUCCESS, "[%s] Propagating.", GetErrorMessage(r));
956
957         return r;
958 }
959
960 bool
961 _FormImpl::IsSoftkeyEnabled(Softkey softkey) const
962 {
963         _Softkey _softkey = ConvertSoftkey(softkey);
964
965         return GetCore().IsSoftkeyEnabled(_softkey);
966 }
967
968 int
969 _FormImpl::GetSoftkeyActionId(Softkey softkey) const
970 {
971         _Softkey _softkey = ConvertSoftkey(softkey);
972
973         return GetCore().GetSoftkeyActionId(_softkey);
974 }
975
976 int
977 _FormImpl::GetOptionkeyActionId(void) const
978 {
979         return GetCore().GetOptionkeyActionId();
980 }
981
982 String
983 _FormImpl::GetSoftkeyText(Softkey softkey) const
984 {
985         _Softkey _softkey = ConvertSoftkey(softkey);
986
987         return GetCore().GetSoftkeyText(_softkey);
988 }
989
990 result
991 _FormImpl::SetOptionkeyActionId(int actionId)
992 {
993         result r = GetCore().SetOptionkeyActionId(actionId);
994         SysTryLog(NID_UI_CTRL, r == E_SUCCESS, "[%s] Propagating.", GetErrorMessage(r));
995
996         return r;
997 }
998
999 result
1000 _FormImpl::SetSoftkeyActionId(Softkey softkey, int actionId)
1001 {
1002         _Softkey _softkey = ConvertSoftkey(softkey);
1003
1004         result r = GetCore().SetSoftkeyActionId(_softkey, actionId);
1005         SysTryLog(NID_UI_CTRL, r == E_SUCCESS, "[%s] Propagating.", GetErrorMessage(r));
1006
1007         return r;
1008 }
1009
1010 result
1011 _FormImpl::SetSoftkeyText(Softkey softkey, const String& text)
1012 {
1013         _Softkey _softkey = ConvertSoftkey(softkey);
1014
1015         result r = GetCore().SetSoftkeyText(_softkey, text);
1016         SysTryLog(NID_UI_CTRL, r == E_SUCCESS, "[%s] Propagating.", GetErrorMessage(r));
1017
1018         return r;
1019 }
1020
1021 result
1022 _FormImpl::SetSoftkeyIcon(Softkey softkey, const Bitmap& pNormalBitmap, const Bitmap* ppPressedBitmap)
1023 {
1024         _Softkey _softkey = ConvertSoftkey(softkey);
1025
1026         result r = GetCore().SetSoftkeyIcon(_softkey, pNormalBitmap, ppPressedBitmap);
1027         SysTryLog(NID_UI_CTRL, r == E_SUCCESS, "[%s] Propagating.", GetErrorMessage(r));
1028
1029         return r;
1030 }
1031
1032 void
1033 _FormImpl::OnChangeLayout(_ControlOrientation orientation)
1034 {
1035         const FloatDimension portraitSize = _ControlManager::GetInstance()->_ControlManager::GetScreenSizeF();
1036         const FloatDimension landscapeSize = FloatDimension(portraitSize.height, portraitSize.width);
1037
1038         // Change layout.
1039         _ContainerImpl::OnChangeLayout(orientation);
1040         SysTryReturnVoidResult(NID_UI_CTRL, GetLastResult() == E_SUCCESS, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1041
1042         if (orientation == _CONTROL_ORIENTATION_PORTRAIT)
1043         {
1044                 SetSize(portraitSize);
1045         }
1046         else
1047         {
1048                 SetSize(landscapeSize);
1049         }
1050
1051         float indicatorheight = 0.0f;
1052
1053         GET_SHAPE_CONFIG(FORM::INDICATOR_HEIGHT, GetCore().GetOrientation(), indicatorheight);
1054         if (GetCore().HasIndicator())
1055         {
1056                 _Indicator* pIndicator = GetCore().GetIndicator();
1057                 if (pIndicator)
1058                 {
1059                         if (orientation == _CONTROL_ORIENTATION_PORTRAIT)
1060                         {
1061                                 pIndicator->SetBounds(FloatRectangle(0.0f, 0.0f, GetClientBoundsF().width, indicatorheight));
1062                         }
1063                         else
1064                         {
1065                                 GET_SHAPE_CONFIG(FORM::INDICATOR_MINIMIZE_HEIGHT, GetCore().GetOrientation(), indicatorheight);
1066                                 pIndicator->SetBounds(FloatRectangle(0.0f, 0.0f, GetClientBoundsF().width, indicatorheight));
1067                         }
1068                 }
1069                 GetCore().AdjustClientBounds();
1070         }
1071
1072
1073         float adjHeight = 0.0f;
1074
1075         if (GetCore().HasHeader())
1076         {
1077                 FloatRectangle indicatorBounds(0.0f, 0.0f, 0.0f, 0.0f);
1078                 if (GetCore().IsIndicatorVisible())
1079                 {
1080                         indicatorBounds = GetCore().GetIndicatorBoundsF();
1081                 }
1082
1083                 FloatRectangle bounds(0.0f, indicatorBounds.height, GetClientBoundsF().width, GetCore().GetToolbarHeightF(true));
1084                 GetCore().SetHeaderBounds(bounds);
1085         }
1086
1087         if (GetCore().HasTab())                         // Ki-Dong,Hong.Temp
1088         {
1089                 float titleHeight = 0.0f;
1090
1091                 if (GetCore().GetFormStyle() & FORM_STYLE_TITLE)
1092                 {
1093                         if (GetCore().HasHeader())
1094                         {
1095                                 _HeaderImpl* pHeaderImpl = GetHeader();
1096                                 if (pHeaderImpl)
1097                                 {
1098                                         titleHeight = pHeaderImpl->GetBoundsF().height;
1099                                 }
1100                         }
1101                 }
1102
1103                 FloatRectangle indicatorBounds(0.0f, 0.0f, 0.0f, 0.0f);
1104
1105                 if (GetCore().IsIndicatorVisible())
1106                 {
1107                         indicatorBounds = GetCore().GetIndicatorBoundsF();
1108                 }
1109
1110                 float posY = indicatorBounds.height + titleHeight;
1111
1112                 FloatRectangle bounds(0.0f, posY, GetClientBoundsF().width, GetCore().GetTabHeightF());
1113                 GetCore().SetTabBounds(bounds);
1114         }
1115
1116         if (GetCore().HasFooter())
1117         {
1118                 if (GetCore().GetFooter()->GetVisibleState() && !GetCore().IsFooterTranslucent())
1119                 {
1120                         adjHeight = 0.0f;
1121                 }
1122                 else
1123                 {
1124                         adjHeight = GetCore().GetToolbarHeightF(false);
1125                 }
1126
1127                 if (!(GetCore().GetFormStyle() & FORM_STYLE_FOOTER || GetCore().GetFormStyle() & FORM_STYLE_SOFTKEY_0 || GetCore().GetFormStyle() & FORM_STYLE_SOFTKEY_1
1128                                 || GetCore().GetFormStyle() & FORM_STYLE_OPTIONKEY))
1129                 {
1130                         adjHeight = GetCore().GetToolbarHeightF(false);
1131                 }
1132
1133                 FloatRectangle bounds(0.0f, GetClientBoundsF().y + GetClientBoundsF().height - adjHeight,
1134                                                                                 GetClientBoundsF().width, GetCore().GetToolbarHeightF(false));
1135                 GetCore().SetFooterBounds(bounds);
1136         }
1137 }
1138
1139 _HeaderImpl*
1140 _FormImpl::CreateHeaderN(void)
1141 {
1142         result r = E_SUCCESS;
1143
1144         Header* pHeader = new (std::nothrow) Header;
1145         SysTryReturn(NID_UI_CTRL, pHeader, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory is insufficient.");
1146
1147         r = pHeader->Construct();
1148         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, null, r, "[%s] Propagating.", GetErrorMessage(r));
1149
1150         _HeaderImpl* pHeaderImpl = _HeaderImpl::GetInstance(*pHeader);
1151
1152         SetLastResult(E_SUCCESS);
1153
1154         return pHeaderImpl;
1155 }
1156
1157 _FooterImpl*
1158 _FormImpl::CreateFooterN(void)
1159 {
1160         result r = E_SUCCESS;
1161
1162         Footer* pFooter = new (std::nothrow) Footer;
1163         SysTryReturn(NID_UI_CTRL, pFooter, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory is insufficient.");
1164
1165         r = pFooter->Construct();
1166         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, null, r, "[%s] Propagating.", GetErrorMessage(r));
1167
1168         _FooterImpl* pFooterImpl = _FooterImpl::GetInstance(*pFooter);
1169
1170         SetLastResult(E_SUCCESS);
1171
1172         return pFooterImpl;
1173 }
1174
1175 // Ki-Dong,Hong.Temp
1176 _TabImpl*
1177 _FormImpl::CreateTabImplN(void)
1178 {
1179         //result r = E_SUCCESS;
1180
1181         //Tab* pTab = new (std::nothrow) Tab;
1182         //SysTryReturn(NID_UI_CTRL, pTab, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory shortage.");
1183
1184         //r = pTab->Construct();
1185         //SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, null, E_SYSTEM, "[E_SYSTEM] Unable to consturct tab.");
1186
1187         //return pTab->GetTabImpl();
1188         Tab* pTab = _TabImpl::CreateTabN();
1189         SysTryReturn(NID_UI_CTRL, pTab, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1190
1191         _TabImpl* pTabImpl = _TabImpl::GetInstance(*pTab);
1192
1193         SetLastResult(E_SUCCESS);
1194
1195         return pTabImpl;
1196 }
1197
1198 bool
1199 _FormImpl::DeflateClientRectHeight(int height)
1200 {
1201         return GetCore().DeflateClientRectHeight(height);
1202 }
1203
1204 bool
1205 _FormImpl::DeflateClientRectHeight(float height)
1206 {
1207         return GetCore().DeflateClientRectHeight(height);
1208 }
1209
1210 bool
1211 _FormImpl::RemoveHeader(void)
1212 {
1213         _HeaderImpl* pHeaderImpl = GetHeader();
1214
1215         if (pHeaderImpl)
1216         {
1217                 __pForm->RemoveHeader();
1218                 result r = GetLastResult();
1219                 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, false, r, "[%s] Propagating.", GetErrorMessage(r));
1220                 Header* pHeader = pHeaderImpl->GetHeader();
1221
1222                 delete pHeader;
1223         }
1224         else
1225                 return false;
1226
1227         return true;
1228 }
1229
1230 bool
1231 _FormImpl::RemoveFooter(void)
1232 {
1233         _FooterImpl* pFooterImpl = GetFooter();
1234
1235         if (pFooterImpl)
1236         {
1237                 __pForm->RemoveFooter();
1238                 result r = GetLastResult();
1239                 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, false, r, "[%s] Propagating.", GetErrorMessage(r));
1240                 Footer* pFooter = pFooterImpl->GetFooter();
1241
1242                 delete pFooter;
1243         }
1244         else
1245         {
1246                 return false;
1247         }
1248
1249         return true;
1250 }
1251
1252 // Ki-Dong,Hong.Temp
1253 bool
1254 _FormImpl::RemoveTabImpl(void)
1255 {
1256         _TabImpl* pTabImpl = GetTabImpl();
1257
1258         if (pTabImpl)
1259         {
1260                 __pForm->RemoveTab();
1261                 result r = GetLastResult();
1262                 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, false, r, "[%s] Propagating.", GetErrorMessage(r));
1263                 Tab* pTab = pTabImpl->GetTab();
1264
1265                 pTabImpl->DeleteTab(pTab);
1266         }
1267         else
1268         {
1269                 return false;
1270         }
1271
1272         return true;
1273 }
1274
1275 DataBindingContext*
1276 _FormImpl::GetDataBindingContextN(void) const
1277 {
1278         return _DataBindingContextImpl::GetDataBindingContextN(*this);
1279 }
1280
1281 result
1282 _FormImpl::OnAttaching(const _Control* pParent)
1283 {
1284         result r = E_SUCCESS;
1285         _Frame* pFrame = dynamic_cast<_Frame*>(const_cast<_Control*>((pParent)));
1286         if (FORM_STYLE_INDICATOR & GetCore().GetFormStyle())
1287         {
1288                 SysTryReturnResult(NID_UI_CTRL, pFrame != null, E_INVALID_ARG, "A Form which has FORM_STYLE_INDICATOR style cannot be added to a container except Frame.");
1289         }
1290         r = _ControlImpl::OnAttaching(pParent);
1291         return r;
1292 }
1293
1294 result
1295 _FormImpl::OnAttachedToMainTree(void)
1296 {
1297         result r = E_SUCCESS;
1298   SetFocused();
1299
1300   r = GetCore().AttachedToMainTree();
1301   r = _ContainerImpl::OnAttachedToMainTree();
1302
1303         FloatRectangle indicatorBounds(0.0f, 0.0f, 0.0f, 0.0f);
1304
1305         if (FORM_STYLE_INDICATOR & GetCore().GetFormStyle())
1306         {
1307                 indicatorBounds = GetCore().GetIndicatorBoundsF();
1308                 r = GetLastResult();
1309                 SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
1310         }
1311
1312         _HeaderImpl* pHeader = GetHeader();
1313         _FooterImpl* pFooter = GetFooter();
1314         _TabImpl* pTabImpl = GetTabImpl();
1315
1316         if (pHeader)
1317         {
1318                 FloatRectangle bounds(0.0f, indicatorBounds.height, GetClientBoundsF().width, GetCore().GetToolbarHeightF(true));
1319                 GetCore().SetHeaderBounds(bounds);
1320         }
1321
1322         float titleHeight = 0.0f;
1323
1324         if (pHeader)
1325         {
1326                 titleHeight = pHeader->GetBoundsF().height;
1327         }
1328
1329         if (pTabImpl)
1330         {
1331                 float posY = indicatorBounds.height + titleHeight;
1332
1333                         FloatRectangle bounds(0.0f, posY, GetClientBoundsF().width, GetCore().GetTabHeightF());
1334                         GetCore().SetTabBounds(bounds);
1335         }
1336
1337         if (pFooter)
1338         {
1339                 float adjHeight = 0.0f;
1340
1341                 if (!(GetCore().GetFooter()->GetVisibleState()) || GetCore().IsFooterTranslucent())
1342                 {
1343                         adjHeight = GetCore().GetToolbarHeightF(false);
1344                 }
1345
1346                 if (!(GetCore().GetFormStyle() & FORM_STYLE_FOOTER || GetCore().GetFormStyle() & FORM_STYLE_SOFTKEY_0 || GetCore().GetFormStyle() & FORM_STYLE_SOFTKEY_1
1347                                 || GetCore().GetFormStyle() & FORM_STYLE_OPTIONKEY))
1348                 {
1349                         adjHeight = GetCore().GetToolbarHeightF(false);
1350                 }
1351
1352                 FloatRectangle clientbounds = GetClientBoundsF();
1353                 FloatRectangle bounds(0.0f, clientbounds.y + clientbounds.height - adjHeight, clientbounds.width, GetCore().GetToolbarHeightF(false));
1354
1355                 GetCore().SetFooterBounds(bounds);
1356         }
1357
1358         UpdateOrientationStatus();
1359
1360         __pOriAgent->RequestOrientationEvent();
1361
1362         return r;
1363 }
1364
1365 result
1366 _FormImpl::OnDetachingFromMainTree(void)
1367 {
1368         result r = E_SUCCESS;
1369         r = GetCore().DetachingFromMainTree();
1370         r = _ContainerImpl::OnDetachingFromMainTree();
1371
1372         return r;
1373 }
1374
1375 bool
1376 _FormImpl::OnNotifiedN(const _ControlImpl& source, IList* pArgs)
1377 {
1378         String* pString = dynamic_cast <Tizen::Base::String*>(pArgs->GetAt(0));
1379         if (pString)
1380         {
1381                 if (*pString == _REQUEST_ORIENTATION_EVENT)
1382                 {
1383                         __pOriAgent->FireOrientationEvent();
1384
1385                         pArgs->RemoveAll(true);
1386                         delete pArgs;
1387
1388                         return true;
1389                 }
1390         }
1391
1392         return false;
1393 }
1394
1395 void
1396 _FormImpl::OnFormBackRequested(Tizen::Ui::Controls::_Form& source)
1397 {
1398         if (__pFormBackEventListener)
1399         {
1400                 _FormImpl* pFormImpl = static_cast<_FormImpl*>(source.GetUserData());
1401                 Form* pForm = dynamic_cast <Form*>(&pFormImpl->GetPublic());
1402                 if (pForm)
1403                 {
1404                         __pFormBackEventListener->OnFormBackRequested(*pForm);
1405                 }
1406                 else
1407                 {
1408                         return;
1409                 }
1410         }
1411 }
1412
1413 bool
1414 _FormImpl::IsOpaque(void) const
1415 {
1416         //return true;
1417         return false;
1418 }
1419
1420 _Softkey
1421 _FormImpl::ConvertSoftkey(Softkey softkey) const
1422 {
1423         _Softkey _softkey;
1424
1425         if (softkey == SOFTKEY_0)
1426         {
1427                 _softkey = _SOFTKEY_0;
1428         }
1429         else if (softkey == SOFTKEY_1)
1430         {
1431                 _softkey = _SOFTKEY_1;
1432         }
1433         else
1434         {
1435                 _softkey = _SOFTKEY_COUNT;
1436         }
1437
1438         return _softkey;
1439 }
1440
1441 result
1442 _FormImpl::SetNotificationTrayOpenEnabled(bool enable)
1443 {
1444         return GetCore().SetNotificationTrayOpenEnabled(enable);
1445 }
1446
1447 bool
1448 _FormImpl::IsNotificationTrayOpenEnabled(void) const
1449 {
1450         return GetCore().IsNotificationTrayOpenEnabled();
1451 }
1452
1453 class _FormMaker
1454         : public _UiBuilderControlMaker
1455 {
1456 public:
1457         _FormMaker(_UiBuilder* uibuilder)
1458                 : _UiBuilderControlMaker(uibuilder){};
1459         virtual ~_FormMaker()
1460         {
1461         };
1462         static _UiBuilderControlMaker* GetInstance(_UiBuilder* uibuilder)
1463         {
1464                 _FormMaker* pFormMaker = new (std::nothrow) _FormMaker(uibuilder);
1465                 return pFormMaker;
1466         };
1467 protected:
1468         virtual Control* Make(_UiBuilderControl* pControl)
1469         {
1470                 _UiBuilderControlLayout* pControlProperty = null;
1471                 result r = E_SUCCESS;
1472                 int style = 0;
1473                 int opacity = 0;
1474                 Tizen::Base::String elementString;
1475                 bool isTitleAlign = false;
1476                 Color color;
1477
1478                 HorizontalAlignment align = ALIGNMENT_CENTER;
1479                 Form* pForm = (Form*) GetContainer();
1480
1481                 // Get control manager
1482                 _ControlManager* pControlManager = _ControlManager::GetInstance();
1483                 if (pControlManager == null)
1484                 {
1485                         SysLog(NID_UI_CTRL, "Unable to get the control manager.n");
1486                         return null;
1487                 }
1488                 FloatDimension screenSize = pControlManager->GetScreenSizeF();
1489
1490                 //Set rect
1491                 (pControl->GetAttribute(UIBUILDER_ATTRIBUTE_PORTRAIT))->SetRect(0.0f, 0.0f, screenSize.width, screenSize.height);
1492                 (pControl->GetAttribute(UIBUILDER_ATTRIBUTE_LANDSCAPE))->SetRect(0.0f, 0.0f, screenSize.height, screenSize.width);
1493
1494                 // Get device orientation
1495                 app_device_orientation_e deviceOrientation = app_get_device_orientation();
1496                 bool isHorizontal = (deviceOrientation == APP_DEVICE_ORIENTATION_90) || (deviceOrientation == APP_DEVICE_ORIENTATION_270);
1497
1498                 if (isHorizontal)
1499                 {
1500                         pControlProperty = pControl->GetAttribute(UIBUILDER_ATTRIBUTE_LANDSCAPE);
1501                 }
1502                 else
1503                 {
1504                         pControlProperty = pControl->GetAttribute(UIBUILDER_ATTRIBUTE_PORTRAIT);
1505                 }
1506
1507                 if (pControlProperty == null)
1508                 {
1509                         SysLogException(NID_UI_CTRL, E_SYSTEM, "[E_SYSTEM] Can't read attributes");
1510                         return null;
1511                 }
1512
1513                 pControlProperty = pControl->GetAttribute(UIBUILDER_ATTRIBUTE_PORTRAIT);
1514                 Tizen::Base::String styleString;
1515                 styleString = pControlProperty->GetStyle();
1516
1517                 if (styleString.Contains(L"FORM_STYLE_TITLE"))
1518                 {
1519                         style |= FORM_STYLE_TITLE;
1520                 }
1521                 if (styleString.Contains(L"FORM_STYLE_SOFTKEY_0"))
1522                 {
1523                         style |= FORM_STYLE_SOFTKEY_0;
1524                 }
1525                 if (styleString.Contains(L"FORM_STYLE_SOFTKEY_1"))
1526                 {
1527                         style |= FORM_STYLE_SOFTKEY_1;
1528                 }
1529                 if (styleString.Contains(L"FORM_STYLE_OPTIONKEY"))
1530                 {
1531                         style |= FORM_STYLE_OPTIONKEY;
1532                 }
1533                 if (styleString.Contains(L"FORM_STYLE_INDICATOR"))
1534                 {
1535                         style |= FORM_STYLE_INDICATOR;
1536                 }
1537                 if (styleString.Contains(L"FORM_STYLE_TEXT_TAB"))
1538                 {
1539                         style |= FORM_STYLE_TEXT_TAB;
1540                 }
1541                 if (styleString.Contains(L"FORM_STYLE_ICON_TAB"))
1542                 {
1543                         style |= FORM_STYLE_ICON_TAB;
1544                 }
1545                 if (styleString.Contains(L"FORM_STYLE_HEADER"))
1546                 {
1547                         style |= FORM_STYLE_HEADER;
1548                 }
1549                 if (styleString.Contains(L"FORM_STYLE_FOOTER"))
1550                 {
1551                         style |= FORM_STYLE_FOOTER;
1552                 }
1553
1554                 _UiBuilderLayoutType layoutType = UIBUILDER_LAYOUT_NONE;
1555                 __pLayoutMaker->GetLayoutType(pControlProperty, layoutType);
1556                 if (layoutType == UIBUILDER_LAYOUT_NONE)
1557                 {
1558                         // Construct
1559                         r = pForm->Construct(style);
1560                 }
1561                 else
1562                 {
1563                         Layout* pPortraitLayout = null;
1564                         Layout* pLandscapeLayout = null;
1565                         result tempResult = E_SUCCESS;
1566                         tempResult = __pLayoutMaker->GetLayoutN(pControl, pPortraitLayout, pLandscapeLayout);
1567                         if (E_SUCCESS == tempResult)
1568                         {
1569                                 r = pForm->Construct(*pPortraitLayout, *pLandscapeLayout, style);
1570                         }
1571                         else
1572                         {
1573                                 r = tempResult;
1574                         }
1575
1576                         _UiBuilderLayoutType layoutType = UIBUILDER_LAYOUT_NONE;
1577
1578                         if (__pLayoutMaker->GetLayoutType(pControlProperty, layoutType) == false)
1579                         {
1580                                 return null;
1581                         }
1582
1583                         if ( layoutType == UIBUILDER_LAYOUT_GRID)
1584                         {
1585                                 for (int i = 0; i < UIBUILDER_ATTRIBUTE_NUM; i++)
1586                                 {
1587                                         GridLayout* pGridLayout = null;
1588                                         pControlProperty = pControl->GetAttribute(i);
1589
1590                                         if ( i == UIBUILDER_ATTRIBUTE_PORTRAIT)
1591                                         {
1592                                                 pGridLayout = dynamic_cast<GridLayout*>(pPortraitLayout);
1593                                         }
1594                                         else
1595                                         {
1596                                                 pGridLayout = dynamic_cast<GridLayout*>(pLandscapeLayout);
1597                                         }
1598                                         __pLayoutMaker->SetGridLayoutContainerProperty(pGridLayout, pControlProperty);
1599                                 }
1600                         }
1601                         delete pPortraitLayout;
1602                         if (pPortraitLayout != pLandscapeLayout)
1603                         {
1604                                 delete pLandscapeLayout;
1605                         }
1606                 }
1607
1608                 if (r != E_SUCCESS)
1609                 {
1610                         SysLog(NID_UI_CTRL, "Failed to create Form.");
1611                         return null;
1612                 }
1613
1614                 // Set Property
1615                 if (pControl->GetElement(L"titleAlign", elementString))
1616                 {
1617                         if (elementString.Equals(L"ALIGN_CENTER", false))
1618                         {
1619                                 align = ALIGNMENT_CENTER;
1620                         }
1621                         else if (elementString.Equals(L"ALIGN_RIGHT", false))
1622                         {
1623                                 align = ALIGNMENT_RIGHT;
1624                         }
1625                         else
1626                         {
1627                                 align = ALIGNMENT_LEFT;
1628                         }
1629                         isTitleAlign = true;
1630                 }
1631
1632                 if (style & FORM_STYLE_TITLE)
1633                 {
1634                         if (pControl->GetElement(L"title", elementString))
1635                         {
1636                                 if (isTitleAlign)
1637                                 {
1638                                         pForm->SetTitleText(elementString, align);
1639                                 }
1640                                 else
1641                                 {
1642                                         pForm->SetTitleText(elementString);
1643                                 }
1644                         }
1645                         else
1646                         {
1647                                 if (isTitleAlign)
1648                                 {
1649                                         pForm->SetTitleText(L"", align);
1650                                 }
1651                                 else
1652                                 {
1653                                         pForm->SetTitleText(L"");
1654                                 }
1655                         }
1656                 }
1657
1658                 if (pControl->GetElement(L"titleIcon", elementString))
1659                 {
1660                         Bitmap* pBitmap = null;
1661                         pBitmap = LoadBitmapN(elementString);
1662                         if (pBitmap != null)
1663                         {
1664                                 r = pForm->SetTitleIcon(pBitmap);
1665                                 delete pBitmap;
1666                                 if (IsFailed(r))
1667                                 {
1668                                         SysLog(NID_UI_CTRL, "Failed to set TitleIcon.");
1669                                 }
1670                         }
1671                 }
1672
1673                 if (pControl->GetElement(L"softKey0Text", elementString))
1674                 {
1675                         pForm->SetSoftkeyText(SOFTKEY_0, elementString);
1676                 }
1677                 if (pControl->GetElement(L"softKey1Text", elementString))
1678                 {
1679                         pForm->SetSoftkeyText(SOFTKEY_1, elementString);
1680                 }
1681                 if (pControl->GetElement(L"backgroundColorOpacity", elementString) || pControl->GetElement(L"BGColorOpacity", elementString))
1682                 {
1683                         Base::Integer::Parse(elementString, opacity);
1684                 }
1685                 if (pControl->GetElement(L"backgroundColor", elementString) || pControl->GetElement(L"BGColor", elementString))
1686                 {
1687                         ConvertStringToColor32(elementString, opacity, color);
1688                         pForm->SetBackgroundColor(color);
1689                 }
1690                 else
1691                 {
1692                         Color color;
1693                         r = GET_COLOR_CONFIG(FORM::BG_NORMAL,color);
1694                         if (r == E_SUCCESS)
1695                         {
1696                                 pForm->SetBackgroundColor(color);
1697                         }
1698                         else
1699                         {
1700                                 pForm->SetBackgroundColor(0xff000000);
1701                         }
1702                 }
1703
1704                 if (pControl->GetElement(L"softKey0Icon", elementString) || pControl->GetElement(L"softKey0NormalIcon", elementString))
1705                 {
1706                         Bitmap* pNormalBitmap = null;
1707                         Bitmap* pPressedBitmap = null;
1708                         pNormalBitmap = LoadBitmapN(elementString); //__image->DecodeN(path,BITMAP_PIXEL_FORMAT_RGB565);
1709
1710                         if (pNormalBitmap != null)
1711                         {
1712                                 if (pControl->GetElement(L"softKey0PressedIcon", elementString))
1713                                 {
1714                                         pPressedBitmap = LoadBitmapN(elementString);
1715                                 }
1716
1717                                 if (pPressedBitmap != null)
1718                                 {
1719                                         pForm->SetSoftkeyIcon(SOFTKEY_0, *pNormalBitmap, pPressedBitmap);
1720                                         delete pNormalBitmap;
1721                                         delete pPressedBitmap;
1722                                 }
1723                                 else
1724                                 {
1725                                         pForm->SetSoftkeyIcon(SOFTKEY_0, *pNormalBitmap, null);
1726                                         delete pNormalBitmap;
1727                                 }
1728                         }
1729                 }
1730                 if (pControl->GetElement(L"softKey1Icon", elementString) || pControl->GetElement(L"softKey1NormalIcon", elementString))
1731                 {
1732                         Bitmap* pNormalBitmap = null;
1733                         Bitmap* pPressedBitmap = null;
1734                         pNormalBitmap = LoadBitmapN(elementString); //__image->DecodeN(path,BITMAP_PIXEL_FORMAT_RGB565);
1735
1736                         if (pNormalBitmap != null)
1737                         {
1738                                 if (pControl->GetElement(L"softKey1PressedIcon", elementString))
1739                                 {
1740                                         pPressedBitmap = LoadBitmapN(elementString); // __image->DecodeN(path,BITMAP_PIXEL_FORMAT_RGB565);
1741                                 }
1742
1743                                 if (pPressedBitmap != null)
1744                                 {
1745                                         pForm->SetSoftkeyIcon(SOFTKEY_1, *pNormalBitmap, pPressedBitmap);
1746                                         delete pNormalBitmap;
1747                                         delete pPressedBitmap;
1748                                 }
1749                                 else
1750                                 {
1751                                         pForm->SetSoftkeyIcon(SOFTKEY_1, *pNormalBitmap, null);
1752                                         delete pNormalBitmap;
1753                                 }
1754                         }
1755                 }
1756
1757                 if (pControl->GetElement(L"Orientation", elementString) || pControl->GetElement(L"orientation", elementString))
1758                 {
1759                         //ORIENTATION_NONE,
1760                         //ORIENTATION_PORTRAIT,
1761                         //ORIENTATION_LANDSACPE,
1762                         //ORIENTATION_PORTRAIT_REVERSE,
1763                         //ORIENTATION_LANDSACPE_REVERSE,
1764                         //ORIENTATION_AUTO = 6,
1765                         //ORIENTATION_AUTO_FOUR_DIRECTION = 8,
1766
1767                         if (elementString.Equals(L"Automatic:2Dir", false) || elementString.Equals(L"Automatic", false))
1768                         {
1769                                 pForm->SetOrientation(ORIENTATION_AUTOMATIC);
1770                         }
1771                         else if (elementString.Equals(L"Automatic:4Dir", false))
1772                         {
1773                                 pForm->SetOrientation(ORIENTATION_AUTOMATIC_FOUR_DIRECTION);
1774                         }
1775                         else if (elementString.Equals(L"Landscape", false))
1776                         {
1777                                 pForm->SetOrientation(ORIENTATION_LANDSCAPE);
1778                                 SetUiBuilderRotateState(UIBUIDER_SCREEN_HORIZONTAL);
1779                         }
1780                         else if (elementString.Equals(L"Landscape:Reverse", false))
1781                         {
1782                                 pForm->SetOrientation(ORIENTATION_LANDSCAPE_REVERSE);
1783                                 SetUiBuilderRotateState(UIBUIDER_SCREEN_HORIZONTAL);
1784                         }
1785                         else if (elementString.Equals(L"Portrait", false))
1786                         {
1787                                 pForm->SetOrientation(ORIENTATION_PORTRAIT);
1788                                 SetUiBuilderRotateState(UIBUIDER_SCREEN_VERTICAL);
1789                         }
1790                         else if (elementString.Equals(L"Portrait:Reverse", false))
1791                         {
1792                                 pForm->SetOrientation(ORIENTATION_PORTRAIT_REVERSE);
1793                                 SetUiBuilderRotateState(UIBUIDER_SCREEN_VERTICAL);
1794                         }
1795                 }
1796
1797                 if (style & FORM_STYLE_HEADER)
1798                 {
1799                         if (pControl->GetElement(L"translucentHeader", elementString))
1800                         {
1801                                 if (elementString.Equals(L"true", false))
1802                                 {
1803                                         pForm->SetActionBarsTranslucent(FORM_ACTION_BAR_HEADER, true);
1804                                 }
1805                         }
1806                 }
1807
1808                 if (style & FORM_STYLE_FOOTER)
1809                 {
1810                         if (pControl->GetElement(L"translucentFooter", elementString))
1811                         {
1812                                 if (elementString.Equals(L"true", false))
1813                                 {
1814                                         pForm->SetActionBarsTranslucent(FORM_ACTION_BAR_FOOTER, true);
1815                                 }
1816                         }
1817                 }
1818
1819                 if (style & FORM_STYLE_INDICATOR)
1820                 {
1821                         if (pControl->GetElement(L"translucentIndicator", elementString))
1822                         {
1823                                 if (elementString.Equals(L"true", false))
1824                                 {
1825                                         pForm->SetActionBarsTranslucent(FORM_ACTION_BAR_INDICATOR, true);
1826                                 }
1827                         }
1828                 }
1829
1830                 return pForm;
1831         }
1832
1833 };
1834
1835 _FormRegister::_FormRegister()
1836 {
1837         _UiBuilderControlTableManager* pUiBuilderControlTableManager = _UiBuilderControlTableManager::GetInstance();
1838         pUiBuilderControlTableManager->RegisterControl(L"Form", _FormMaker::GetInstance);
1839 }
1840 _FormRegister::~_FormRegister()
1841 {
1842         _UiBuilderControlTableManager* pUiBuilderControlTableManager = _UiBuilderControlTableManager::GetInstance();
1843         pUiBuilderControlTableManager->UnregisterControl(L"Form");
1844 }
1845 static _FormRegister FormRegisterToUiBuilder;
1846 }}} // Tizen::Ui::Controls