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