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