3656ba7d4272a70c290dcb8c34a2c036726ecad7
[framework/osp/uifw.git] / src / ui / controls / FUiCtrl_Frame.cpp
1 //
2 // Open Service Platform
3 // Copyright (c) 2012-2013 Samsung Electronics Co., Ltd.
4 //
5 // Licensed under the Apache License, Version 2.0 (the License);
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
8 //
9 //     http://www.apache.org/licenses/LICENSE-2.0/
10 //
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
16 //
17 /**
18  * @file                FUiCtrl_Frame.cpp
19  * @brief               This is the implementation file for the _Frame class.
20  */
21
22 #include <new>
23 #include <FBaseErrorDefine.h>
24 #include <FBaseInteger.h>
25 #include <FBaseSysLog.h>
26 #include <FApp_AppInfo.h>
27 #include "FUi_UiNotificationEvent.h"
28 #include "FUi_UiEventManager.h"
29 #include "FUi_ControlManager.h"
30 #include "FUi_EcoreEvasMgr.h"
31 #include "FUi_EcoreEvas.h"
32 #include "FUi_TouchManager.h"
33 #include "FUi_CoordinateSystemUtils.h"
34 #include "FUiCtrl_Frame.h"
35 #include "FUiCtrl_FramePresenter.h"
36 #include "FUiCtrl_FrameEvent.h"
37 #include "FUiCtrl_IFrameEventListener.h"
38 #include "FUiCtrl_IFormActivationChangeEventListener.h"
39 #include "FUiCtrl_Form.h"
40 #include "FUiCtrl_FormImpl.h"
41 #include "FUiCtrl_FrameImpl.h"
42 #include "FUiAnim_VisualElement.h"
43 #include "FUiAnim_RootVisualElement.h"
44 #include "FUiAnim_EflLayer.h"
45 #include "FUi_AccessibilityManager.h"
46
47 using namespace Tizen::App;
48 using namespace Tizen::Ui::Animations;
49 using namespace Tizen::Ui;
50 using namespace Tizen::Ui::Controls;
51 using namespace Tizen::Base;
52 using namespace Tizen::Base::Collection;
53 using namespace Tizen::Base::Runtime;
54 using namespace Tizen::Graphics;
55
56 namespace Tizen { namespace Ui { namespace Controls {
57
58 const String _ACTIVATE_FRAME = L"ActivateFrame";
59
60 _Frame::_Frame(void)
61         : __pFramePresenter(null)
62         , __pFrameEvent(null)
63         , __floatingBounds(0.0f, 0.0f, 0.0f, 0.0f)
64         , __floatingOrientation(_CONTROL_ORIENTATION_PORTRAIT)
65         , __showMode(FRAME_SHOW_MODE_FULL_SCREEN)
66         , __restore(false)
67         , __minimized(false)
68         , __activated(false)
69         , __constructed(false)
70         , __rotation(false)
71         , __changingBoundsEnabled(true)
72         , __pFormActivationChangeEventListener(null)
73 {
74         _FramePresenter* pPresenter = new (std::nothrow) _FramePresenter(*this);
75         SysTryReturnVoidResult(NID_UI_CTRL, pPresenter, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory is insufficient.");
76
77         FloatDimension screen = _ControlManager::GetInstance()->GetScreenSizeF();
78         __floatingBounds.width = screen.width;
79         __floatingBounds.height = screen.height;
80
81         __pFrameEvent = _FrameEvent::CreateInstanceN(*this);
82         SysTryCatch(NID_UI_CTRL, __pFrameEvent, , GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
83
84         SetPresenter(*pPresenter);
85         SetClipChildrenEnabled(false);
86
87         ClearLastResult();
88
89         return;
90
91 CATCH:
92         delete pPresenter;
93         pPresenter = null;
94 }
95
96 _Frame::~_Frame(void)
97 {
98         if (__pFrameEvent)
99         {
100                 delete __pFrameEvent;
101                 __pFrameEvent = null;
102         }
103
104         delete __pFramePresenter;
105         __pFramePresenter = null;
106
107         ClearLastResult();
108 }
109
110 _Frame*
111 _Frame::CreateFrameN(void)
112 {
113         result r = E_SUCCESS;
114         _RootVisualElement* pRootVE = null;
115         _EflLayer* pLayer = null;
116         int appType = _AppInfo::GetAppType();
117
118         _Frame* pFrame = new (std::nothrow) _Frame;
119         SysTryCatch(NID_UI_CTRL, pFrame, , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory shortage.");
120         SysTryCatch(NID_UI_CTRL, GetLastResult() == E_SUCCESS, , E_SYSTEM, "[E_SYSTEM] A system error occurred.");
121
122         if (appType & _APP_TYPE_IME_APP)
123         {
124                 SysLog(NID_UI_CTRL, "[Ime Rotation]");
125                 r = pFrame->CreateRootVisualElement(_WINDOW_TYPE_SUB);
126                 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
127         }
128         else
129         {
130                 r = pFrame->CreateRootVisualElement();
131                 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
132         }
133
134         pRootVE = pFrame->GetRootVisualElement();
135         SysAssert(pRootVE);
136
137         pLayer = static_cast<_EflLayer*>(pRootVE->GetNativeLayer());
138         SysAssert(pLayer);
139
140         if (!(appType & _APP_TYPE_IME_APP))
141         {
142                 pLayer->SetOpacity(1);
143         }
144
145         pFrame->AcquireHandle();
146
147         SetLastResult(E_SUCCESS);
148
149         return pFrame;
150
151 CATCH:
152         delete pFrame;
153
154         return null;
155 }
156
157 result
158 _Frame::SetPresenter(const _FramePresenter& framePresenter)
159 {
160         __pFramePresenter = const_cast <_FramePresenter*>(&framePresenter);
161
162         return E_SUCCESS;
163 }
164
165 void
166 _Frame::OnDraw(void)
167 {
168         if (__pFramePresenter)
169         {
170                 __pFramePresenter->Draw();
171         }
172 }
173
174 void
175 _Frame::OnActivated(void)
176 {
177         SysLog(NID_UI, "activated(%d)", __activated);
178
179         if (!__activated)
180         {
181                 return;
182         }
183
184         _Window::OnActivated();
185
186         _Form* pCurrentForm = GetCurrentForm();
187         if (pCurrentForm == null)
188         {
189                 return;
190         }
191
192         pCurrentForm->AddIndicatorObject();
193
194         _Control* pFocusControl = pCurrentForm->GetFocusControl();
195         if (pFocusControl)
196         {
197                 pFocusControl->SetFocused();
198         }
199         else
200         {
201                 pCurrentForm->SetFocused();
202         }
203         _AccessibilityManager::GetInstance()->RequestAutoReading(_ACCESSIBILITY_AUTO_READING_MODE_FIRST_ITEM);
204 }
205
206 bool
207 _Frame::OnNotifiedN(const _Control& source, IList* pArgs)
208 {
209         SysTryReturn(NID_UI_CTRL, pArgs, false, E_SYSTEM, "[E_SYSTEM] pArgs is null.")
210
211         String* pType = dynamic_cast <String*>(pArgs->GetAt(0));
212         SysTryReturn(NID_UI_CTRL, pType, false, E_SYSTEM, "[E_SYSTEM] pType is null.")
213
214         if (*pType == L"VisibilityEvent")
215         {
216                 int obscured = 0;
217
218                 Integer* pObscured = dynamic_cast<Integer*>(pArgs->GetAt(1));
219                 if (pObscured == null)
220                 {
221                         pArgs->RemoveAll(true);
222                         delete pArgs;
223
224                         return true;
225                 }
226
227                 obscured = pObscured->ToInt();
228                 if (obscured == 0)
229                 {
230                         SetNativeWindowActivated(true);
231                         __activated = true;
232                         OnFrameActivated();
233                 }
234                 else
235                 {
236                         SetNativeWindowActivated(false);
237                         __activated = false;
238                         OnFrameDeactivated();
239                 }
240
241                 pArgs->RemoveAll(true);
242                 delete pArgs;
243
244                 return true;
245         }
246         else if (*pType == _ACTIVATE_FRAME)
247         {
248                 _EcoreEvas* pEcoreEvas = GetEcoreEvasMgr()->GetEcoreEvas();
249                 if (pEcoreEvas)
250                 {
251                         pEcoreEvas->ActivateWindow(*this);
252                 }
253
254                 pArgs->RemoveAll(true);
255                 delete pArgs;
256
257                 return true;
258         }
259
260         return false;
261 }
262
263 void
264 _Frame::OnFrameActivated(void)
265 {
266         int childcount = GetChildCount();
267
268         for (int i = 0 ; i < childcount ; i++)
269         {
270                 _Control* pChild = GetChild(i);
271                 _Form* pForm = dynamic_cast<_Form*>(pChild);
272                 if (pForm)
273                 {
274                         pForm->MoveOverlayRegion(true);
275                 }
276         }
277
278         // Fire Event.
279         IEventArg* pArg = _FrameEvent::CreateFrameEventArgN(*this, _FRAME_STATUS_ACTIVATED);
280         __pFrameEvent->Fire(*pArg);
281
282         if (GetChildCount() < 1)
283         {
284                 _EcoreEvas* pEcoreEvas = GetEcoreEvasMgr()->GetEcoreEvas();
285                 SysTryReturnVoidResult(NID_UI_CTRL, pEcoreEvas, E_SYSTEM, "[E_SYSTEM] Unable to get evas");
286
287                 if (GetShowMode() == FRAME_SHOW_MODE_FULL_SCREEN)
288                 {
289                         pEcoreEvas->SetIndicatorShowState(*GetRootWindow(), false);
290                 }
291         }
292 }
293
294 void
295 _Frame::OnFrameDeactivated(void)
296 {
297         int childcount = GetChildCount();
298
299         for (int i = 0 ; i < childcount ; i++)
300         {
301                 _Control* pChild = GetChild(i);
302                 _Form* pForm = dynamic_cast<_Form*>(pChild);
303                 if (pForm)
304                 {
305                         pForm->MoveOverlayRegion(false);
306                 }
307         }
308
309         // Fire Event.
310         IEventArg* pArg = _FrameEvent::CreateFrameEventArgN(*this, _FRAME_STATUS_DEACTIVATED);
311         __pFrameEvent->Fire(*pArg);
312
313         _TouchManager* pTouchManager = _TouchManager::GetInstance();
314         if (pTouchManager)
315         {
316                 pTouchManager->SetTouchCanceled(null);
317         }
318 }
319
320 void
321 _Frame::OnFrameMinimized(void)
322 {
323         IEventArg* pArg = _FrameEvent::CreateFrameEventArgN(*this, _FRAME_STATUS_MINIMIZED);
324         __pFrameEvent->Fire(*pArg);
325 }
326
327 void
328 _Frame::OnFrameRestored(void)
329 {
330         __minimized = false;
331
332         IEventArg* pArg = _FrameEvent::CreateFrameEventArgN(*this, _FRAME_STATUS_RESTORED);
333         __pFrameEvent->Fire(*pArg);
334 }
335
336 void
337 _Frame::SetCurrentForm(const _Form* pForm)
338 {
339         result r = E_SUCCESS;
340
341         SysTryReturnVoidResult(NID_UI_CTRL, pForm != null, E_INVALID_ARG, "[E_INVALID_ARG] Form to become a new current form is null");
342         _Form* pNewForm = const_cast<_Form*>(pForm);
343
344         _Form* pCurrentForm = GetCurrentForm();
345         pNewForm->AddIndicatorObject();
346
347         if (pCurrentForm != null)
348         {
349                 if (pCurrentForm != pForm)
350                 {
351                         // Change order
352                         r = MoveChildToTop(*pForm);
353                         SysTryReturnVoidResult(NID_UI_CTRL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
354                         pNewForm->MoveOverlayRegion(true);
355
356                         pCurrentForm->SetVisibleState(false);
357                         pCurrentForm->MoveOverlayRegion(false);
358
359                         if (__pFormActivationChangeEventListener)
360                                 __pFormActivationChangeEventListener->OnFormDeactivated(*pCurrentForm);
361                 }
362         }
363
364         pNewForm->SetVisibleState(true);
365         _Control* pFocus = pNewForm->GetFocusControl();
366         if (pFocus)
367         {
368                 pFocus->SetFocused();
369         }
370         else
371         {
372                 pNewForm->SetFocused();
373         }
374
375         pNewForm->SetUpdateLayoutState(true);
376
377         if (__pFormActivationChangeEventListener)
378                 __pFormActivationChangeEventListener->OnFormActivated(*pNewForm);
379
380         SetLastResult(E_SUCCESS);
381
382         return;
383 }
384
385 _Form*
386 _Frame::GetCurrentForm(void) const
387 {
388         _Form* pCurrentForm = null;
389         int controlCount = GetChildCount();
390
391         if (controlCount > 0)
392         {
393                 for (int i = controlCount; i > 0; i--)
394                 {
395                         pCurrentForm = dynamic_cast<_Form*>(GetChild(i - 1));
396                         SysTryReturn(NID_UI_CTRL, pCurrentForm != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
397                         if (pCurrentForm->IsVisible())
398                         {
399                                 break;
400                         }
401                 }
402         }
403
404         return pCurrentForm;
405 }
406
407 bool
408 _Frame::IsOrientationRoot(void) const
409 {
410         return true;
411 }
412
413 void
414 _Frame::SetRotation(bool rotation)
415 {
416         __rotation = rotation;
417 }
418
419 void
420 _Frame::AddFrameEventListener(const _IFrameEventListener& listener)
421 {
422         __constructed = true;
423
424         result r = __pFrameEvent->AddListener(listener);
425         SysTryReturnVoidResult(NID_UI_CTRL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
426 }
427
428 void
429 _Frame::RemoveFrameEventListener(const _IFrameEventListener& listener)
430 {
431         result r = __pFrameEvent->RemoveListener(listener);
432         SysTryReturnVoidResult(NID_UI_CTRL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
433 }
434
435 void
436 _Frame::SetFormActivationChangeEventListener(const _IFormActivationChangeEventListener* plistener)
437 {
438         __pFormActivationChangeEventListener = const_cast<_IFormActivationChangeEventListener*>(plistener);
439 }
440
441
442 void
443 _Frame::SetFloatingBounds(const FloatRectangle& rect)
444 {
445         __floatingBounds = rect;
446 }
447
448 void
449 _Frame::SetFloatingBounds(const Rectangle& rect)
450 {
451         __floatingBounds = _CoordinateSystemUtils::ConvertToFloat(rect);
452 }
453
454 void
455 _Frame::SetFloatingOrientation(_ControlOrientation orientation)
456 {
457         if ((__showMode == FRAME_SHOW_MODE_PARTIAL_SCREEN) || (__showMode == FRAME_SHOW_MODE_PARTIAL_SCREEN_FLOATING))
458         {
459                 __floatingOrientation = orientation;
460         }
461 }
462
463 result
464 _Frame::SetShowMode(FrameShowMode showMode)
465 {
466         _EcoreEvas* pEcoreEvas = GetEcoreEvasMgr()->GetEcoreEvas();
467         SysTryReturnResult(NID_UI_CTRL, pEcoreEvas, E_SYSTEM, "The method cannot proceed due to a severe system error.");
468
469         if (showMode == FRAME_SHOW_MODE_MINIMIZED)
470         {
471                 if (__minimized == true)
472                 {
473                         return E_SUCCESS;
474                 }
475
476                 pEcoreEvas->MinimizeWindow(*GetRootWindow());
477                 __minimized = true;
478
479                 return E_SUCCESS;
480         }
481         else
482         {
483                 if (__minimized == true)
484                 {
485                         return E_SYSTEM;
486                 }
487         }
488
489         bool changeMode = true;
490
491         if ((showMode == FRAME_SHOW_MODE_PARTIAL_SCREEN) || (showMode == FRAME_SHOW_MODE_PARTIAL_SCREEN_FLOATING))
492         {
493                 _Form* pCurrentForm = GetCurrentForm();
494
495                 if (pCurrentForm)
496                 {
497                         if (pCurrentForm->GetFormStyle() & _FORM_STYLE_INDICATOR)
498                         {
499                                 changeMode = false;
500                         }
501                 }
502         }
503
504         SysTryReturnResult(NID_UI_CTRL, changeMode == true, E_SYSTEM, "The method cannot proceed due to a severe system error.");
505
506         int oldShowMode = __showMode;
507         __showMode = showMode;
508
509         if ((__showMode == FRAME_SHOW_MODE_PARTIAL_SCREEN) || (__showMode == FRAME_SHOW_MODE_PARTIAL_SCREEN_FLOATING))
510         {
511                 _ControlOrientation orientation = _CONTROL_ORIENTATION_PORTRAIT;
512                 _Form* pCurForm = GetCurrentForm();
513                 if (pCurForm)
514                 {
515                         orientation = pCurForm->GetOrientation();
516                 }
517                 else
518                 {
519                         orientation = GetOrientation();
520                 }
521
522                 if (orientation == _CONTROL_ORIENTATION_PORTRAIT)
523                 {
524                         if (__floatingOrientation == _CONTROL_ORIENTATION_LANDSCAPE)
525                         {
526                                 FloatDimension screenSize = _ControlManager::GetInstance()->_ControlManager::GetScreenSizeF();
527                                 FloatPoint prevPoint(__floatingBounds.x, __floatingBounds.y);
528                                 FloatPoint curPoint(prevPoint.x, prevPoint.y);
529                                 float ratio = screenSize.width / screenSize.height;
530
531                                 if (prevPoint.x > 0.0f)
532                                 {
533                                         curPoint.x = prevPoint.x * ratio;
534                                 }
535                         
536                                 if (prevPoint.y > 0.0f)
537                                 {
538                                         curPoint.y = prevPoint.y / ratio;
539                                 }
540
541                                 __floatingBounds.x = curPoint.x;
542                                 __floatingBounds.y = curPoint.y;
543                         }
544                 }
545                 else
546                 {
547                         if (__floatingOrientation == _CONTROL_ORIENTATION_PORTRAIT)
548                         {
549                                 FloatDimension screenSize = _ControlManager::GetInstance()->_ControlManager::GetScreenSizeF();
550                                 FloatPoint prevPoint(__floatingBounds.x, __floatingBounds.y);
551                                 FloatPoint curPoint(prevPoint.x, prevPoint.y);
552                                 float ratio = screenSize.width / screenSize.height;
553
554                                 if (prevPoint.x > 0.0f)
555                                 {
556                                         curPoint.x = prevPoint.x / ratio;
557                                 }
558                         
559                                 if (prevPoint.y > 0.0f)
560                                 {
561                                         curPoint.y = prevPoint.y * ratio;
562                                 }
563                         
564                                 __floatingBounds.x = curPoint.x;
565                                 __floatingBounds.y = curPoint.y;
566                         }
567                 }
568         }
569
570         result r = E_SUCCESS;
571
572         switch (__showMode)
573         {
574         case FRAME_SHOW_MODE_FULL_SCREEN:
575                 if (oldShowMode == FRAME_SHOW_MODE_PARTIAL_SCREEN_FLOATING)
576                 {
577                         r = pEcoreEvas->SetFloatingMode(*GetRootWindow(), false);
578                         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
579                 }
580
581                 if (oldShowMode != FRAME_SHOW_MODE_FULL_SCREEN)
582                 {
583                         FloatDimension screen = _ControlManager::GetInstance()->GetScreenSizeF();
584
585                         __restore = true;
586
587                         if (GetOrientation() == _CONTROL_ORIENTATION_PORTRAIT)
588                         {
589                                 SetBounds(FloatRectangle(0.0f, 0.0f, screen.width, screen.height));
590                         }
591                         else
592                         {
593                                 SetBounds(FloatRectangle(0.0f, 0.0f, screen.height, screen.width));
594                         }
595
596                         __restore = false;
597                 }
598
599                 break;
600         case FRAME_SHOW_MODE_PARTIAL_SCREEN:
601                 if (oldShowMode == FRAME_SHOW_MODE_PARTIAL_SCREEN_FLOATING)
602                 {
603                         r = pEcoreEvas->SetFloatingMode(*GetRootWindow(), false);
604                         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
605                 }
606
607                 if (oldShowMode == FRAME_SHOW_MODE_FULL_SCREEN)
608                 {
609                         SetBounds(__floatingBounds);
610                 }
611                 else if (oldShowMode == FRAME_SHOW_MODE_PARTIAL_SCREEN_FLOATING)
612                 {
613                         pEcoreEvas->SetWindowBounds(*GetRootWindow(), _CoordinateSystemUtils::ConvertToInteger(__floatingBounds));
614                 }
615
616                 break;
617         case FRAME_SHOW_MODE_PARTIAL_SCREEN_FLOATING:
618                 if (oldShowMode != FRAME_SHOW_MODE_PARTIAL_SCREEN_FLOATING)
619                 {
620                         r = pEcoreEvas->SetFloatingMode(*GetRootWindow(), true);
621                         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
622                 }
623
624                 if (oldShowMode == FRAME_SHOW_MODE_FULL_SCREEN)
625                 {
626                         SetBounds(__floatingBounds);
627                 }
628
629                 break;
630         default:
631                 break;
632         }
633
634         if ((__showMode == FRAME_SHOW_MODE_PARTIAL_SCREEN) || (__showMode == FRAME_SHOW_MODE_PARTIAL_SCREEN_FLOATING))
635         {
636                 _Form* pCurForm = GetCurrentForm();
637                 if (pCurForm)
638                 {
639                         __floatingOrientation = pCurForm->GetOrientation();
640                 }
641                 else
642                 {
643                         __floatingOrientation = GetOrientation();
644                 }
645         }
646
647         return E_SUCCESS;
648 }
649
650 FrameShowMode
651 _Frame::GetShowMode(bool minimize) const
652 {
653         if (minimize)
654         {
655                 if (__minimized == true)
656                 {
657                         return FRAME_SHOW_MODE_MINIMIZED;
658                 }
659                 else
660                 {
661                         return __showMode;
662                 }
663         }
664         else
665         {
666                 return __showMode;
667         }
668 }
669
670 bool
671 _Frame::IsFrameActivated(void) const
672 {
673         return __activated;
674 }
675
676 void
677 _Frame::OnChildAttached(const _Control& child)
678 {
679         _Form* pCurrentForm = GetCurrentForm();
680
681         if (pCurrentForm == &child)
682         {
683                 int controlCount = GetChildCount();
684
685                 if (controlCount > 1)
686                 {
687                         _Control* pOldCurrentForm = GetChild(controlCount - 2);
688                         SysTryReturnVoidResult(NID_UI_CTRL, pOldCurrentForm != null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
689                         pOldCurrentForm->SetVisibleState(false);
690                 }
691         }
692 }
693
694 void
695 _Frame::OnChildDetached(const _Control& child)
696 {
697         int controlCount = GetChildCount();
698
699         if (controlCount > 0)
700         {
701                 _Control* pCurrentForm = GetChild(controlCount - 1);
702                 SysTryReturnVoidResult(NID_UI_CTRL, pCurrentForm, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
703                 pCurrentForm->SetVisibleState(true);
704         }
705         else
706         {
707                 _EcoreEvas* pEcoreEvas = GetEcoreEvasMgr()->GetEcoreEvas();
708                 SysTryReturnVoidResult(NID_UI_CTRL, pEcoreEvas, E_SYSTEM, "[E_SYSTEM] Unable to get evas");
709                 pEcoreEvas->SetIndicatorShowState(*GetRootWindow(), false);
710         }
711 }
712
713 result
714 _Frame::OnBoundsChanging(const FloatRectangle& bounds)
715 {
716         int appType = _AppInfo::GetAppType();
717         if (appType & _APP_TYPE_IME_APP)
718         {
719                 SysLog(NID_UI_CTRL, "[Ime Rotation]");
720                 return E_SUCCESS;
721         }
722
723         if (__restore == false)
724         {
725                 __floatingBounds = bounds;
726         }
727
728         if ((__showMode == FRAME_SHOW_MODE_FULL_SCREEN) && (__restore == false))
729         {
730                 if (__constructed == false)
731                 {
732                         return E_SUCCESS;
733                 }
734                 else
735                 {
736                         if (__rotation == true)
737                         {
738                                 return E_SUCCESS;
739                         }
740                         else
741                         {
742                                 return E_UNSUPPORTED_OPERATION;
743                         }
744                 }
745         }
746
747         if (__changingBoundsEnabled == false)
748         {
749                 return E_SUCCESS;
750         }
751
752         _EcoreEvas* pEcoreEvas = GetEcoreEvasMgr()->GetEcoreEvas();
753         SysTryReturn(NID_UI, pEcoreEvas, E_SYSTEM, E_SYSTEM, "[E_SYSTEM] A system error occurred.");
754
755         pEcoreEvas->SetWindowBounds(*GetRootWindow(), _CoordinateSystemUtils::ConvertToInteger(bounds));
756         result r = GetLastResult();
757         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
758
759         return r;
760 }
761
762
763 result
764 _Frame::OnAttached(void)
765 {
766         _EcoreEvas* pEcoreEvas = GetEcoreEvasMgr()->GetEcoreEvas();
767         SysAssert(pEcoreEvas);
768
769         pEcoreEvas->SetWindowVisibleState(*GetRootWindow(), true);
770
771         return E_SUCCESS;
772 }
773
774 void
775 _Frame::OnBackgroundColorChanged(Color& backgroundColor)
776 {
777         _RootVisualElement* pRootVE = GetRootVisualElement();
778         SysAssert(pRootVE);
779
780         _EflLayer* pLayer = static_cast<_EflLayer*>(pRootVE->GetNativeLayer());
781         SysAssert(pLayer);
782
783         byte alpha = backgroundColor.GetAlpha();
784         float opacity = static_cast<float>(alpha) / 255.0f;
785
786         pLayer->SetOpacity(opacity);
787
788         // Restore
789         FrameShowMode showMode = GetShowMode(false);
790         SetShowMode(FRAME_SHOW_MODE_FULL_SCREEN);
791
792         SetShowMode(showMode);
793
794         _EcoreEvas* pEcoreEvas = GetEcoreEvasMgr()->GetEcoreEvas();
795         if (!pEcoreEvas)
796         {
797                 return;
798         }
799
800         Orientation mode = ORIENTATION_PORTRAIT;
801
802         _Form* pCurrentForm = GetCurrentForm();
803         if (pCurrentForm)
804         {
805                 _FormImpl* pFormImpl = static_cast<_FormImpl*>(pCurrentForm->GetUserData());
806                 if (pFormImpl)
807                 {
808                         mode = pFormImpl->GetOrientation();
809                 }
810         }
811         else
812         {
813                 _FrameImpl* pFrameImpl = static_cast<_FrameImpl*>(GetUserData());
814                 if (pFrameImpl)
815                 {
816                         mode = pFrameImpl->GetOrientation();
817                 }
818         }
819
820         switch (mode)
821         {
822         case ORIENTATION_PORTRAIT:
823                 pEcoreEvas->SetWindowPreferredRotation(*this, 0, true);
824                 break;
825         case ORIENTATION_LANDSCAPE:
826                 pEcoreEvas->SetWindowPreferredRotation(*this, 270, true);
827                 break;
828         case ORIENTATION_PORTRAIT_REVERSE:
829                 pEcoreEvas->SetWindowPreferredRotation(*this, 180, true);
830                 break;
831         case ORIENTATION_LANDSCAPE_REVERSE:
832                 pEcoreEvas->SetWindowPreferredRotation(*this, 90, true);
833                 break;
834         case ORIENTATION_AUTOMATIC:
835                 {
836                         pEcoreEvas->SetWindowPreferredRotation(*this, -1);
837                         int autoRotation[3] = {0, 90, 270};
838                         pEcoreEvas->SetWindowAvailabledRotation(*this, autoRotation, 3, true);
839                 }
840                 break;
841         case ORIENTATION_AUTOMATIC_FOUR_DIRECTION:
842                 {
843                         pEcoreEvas->SetWindowPreferredRotation(*this, -1);
844                         int autoFourRotation[4] = {0, 90, 180, 270};
845                         pEcoreEvas->SetWindowAvailabledRotation(*this, autoFourRotation, 4, true);
846                 }
847                 break;
848         default:
849                 break;
850         }
851 }
852
853 void
854 _Frame::ResetFocusList(void)
855 {
856         Tizen::Ui::Controls::_Form* pCurrentForm = GetCurrentForm();
857         if (pCurrentForm)
858         {
859                 pCurrentForm->ResetFocusList();
860         }
861 }
862
863 _Control*
864 _Frame::GetFocusControl(const _Control* pControl) const
865 {
866         const _Form* pForm = null;
867         _Frame* pFrame = null;
868         const _Control* pTempControl = pControl;
869         while(pTempControl)
870         {
871                 pForm = dynamic_cast<_Form*>(const_cast<_Control*>(pTempControl));
872
873                 if (pForm)
874                 {
875                         pFrame = dynamic_cast<_Frame*>(pForm->GetParent());
876                         if (pFrame)
877                         {
878                                 break;
879                         }
880                         else
881                         {
882                                 pTempControl = pTempControl->GetParent();
883                         }
884                 }
885                 else
886                 {
887                         pTempControl = pTempControl->GetParent();
888                 }
889         }
890         if (pForm)
891         {
892                 return pForm->GetFocusControl();
893         }
894         return null;
895 }
896
897 _Control*
898 _Frame::GetCurrentFocusControl(void) const
899 {
900         _Form* pForm = GetCurrentForm();
901         if (pForm)
902         {
903                 return pForm->GetFocusControl();
904         }
905         return null;
906 }
907 void
908 _Frame::SetFocusControl(const _Control* pControl , bool on)
909 {
910         SysTryReturnVoidResult(NID_UI, pControl, E_SYSTEM, "[E_SYSTEM] The pControl cannot be NULL.");
911         _ControlManager* pControlMgr = _ControlManager::GetInstance();
912         SysAssert(pControlMgr);
913         _Form* pForm = null;
914         _Form* pCurrentForm = GetCurrentForm();
915         _Frame* pFrame = null;
916         const _Control* pTempControl = pControl;
917         bool isCurrentForm = false;
918
919         while(pTempControl)
920         {
921                 pForm = dynamic_cast<_Form*>(const_cast<_Control*>(pTempControl));
922
923                 if (pForm)
924                 {
925                         pFrame = dynamic_cast<_Frame*>(pForm->GetParent());
926                         if (pFrame)
927                         {
928                                 break;
929                         }
930                         else
931                         {
932                                 pTempControl = pTempControl->GetParent();
933                         }
934                 }
935                 else
936                 {
937                         pTempControl = pTempControl->GetParent();
938                 }
939         }
940
941         if (pForm == pCurrentForm)
942         {
943                 isCurrentForm = true;
944         }
945
946         if (pForm)
947         {
948                 if (on)
949                 {
950                         pForm->SetFocusControl(pControl);
951                         if (isCurrentForm && pFrame->IsActivated())
952                         {
953                                 pControlMgr->SetFocusControl(*pControl);
954                         }
955                 }
956                 else
957                 {
958                         pControlMgr->SetFocusControl(*this, false);
959                         pForm->SetFocused();
960                 }
961         }
962 }
963
964 void
965 _Frame::SetChangingBoundsEnabled(bool enable)
966 {
967         __changingBoundsEnabled = enable;
968 }
969
970 Tizen::Base::Collection::IListT<_Control*>*
971 _Frame::GetFocusList(void) const
972 {
973         _Form* pForm = GetCurrentForm();
974         if (pForm)
975         {
976                 return pForm->GetFocusList();
977         }
978         return null;
979 }
980
981 _Control*
982 _Frame::GetFocusTraversalControl(_Control* pControl) const
983 {
984         _Form* pForm = null;
985         _Control* pTempControl = pControl;
986         _Frame* pFrame = null;
987         while(pTempControl)
988         {
989                 pForm = dynamic_cast<_Form*>(const_cast<_Control*>(pTempControl));
990
991                 if (pForm)
992                 {
993                         pFrame = dynamic_cast<_Frame*>(pForm->GetParent());
994                         if (pFrame)
995                         {
996                                 break;
997                         }
998                         else
999                         {
1000                                 pTempControl = pTempControl->GetParent();
1001                         }
1002                 }
1003                 else
1004                 {
1005                         pTempControl = pTempControl->GetParent();
1006                 }
1007         }
1008         
1009         if (pForm)
1010         {
1011                 return pForm->GetFocusTraversalControl();
1012         }
1013         return null;
1014 }
1015
1016 void
1017 _Frame::SetFocusTraversalControl(_Control* pControl, bool on)
1018 {
1019         _Form* pForm = null;
1020         _Control* pTempControl = pControl;
1021         _Frame* pFrame = null;
1022         while(pTempControl)
1023         {
1024                 pForm = dynamic_cast<_Form*>(const_cast<_Control*>(pTempControl));
1025
1026                 if (pForm)
1027                 {
1028                         pFrame = dynamic_cast<_Frame*>(pForm->GetParent());
1029                         if (pFrame)
1030                         {
1031                                 break;
1032                         }
1033                         else
1034                         {
1035                                 pTempControl = pTempControl->GetParent();
1036                         }
1037                 }
1038                 else
1039                 {
1040                         pTempControl = pTempControl->GetParent();
1041                 }
1042         }
1043
1044         if (pForm)
1045         {
1046                 if (on)
1047                 {
1048                         pForm->SetFocusTraversalControl(pControl);
1049                 }
1050                 else
1051                 {
1052                         pForm->SetFocusTraversalControl(pForm);
1053                 }
1054         }
1055 }
1056 }}} // Tizen::Ui::Controls