Fixed to decide the position of the mini App
[platform/framework/native/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                         __activated = true;
231                         OnFrameActivated();
232                 }
233                 else
234                 {
235                         __activated = false;
236                         OnFrameDeactivated();
237                 }
238
239                 pArgs->RemoveAll(true);
240                 delete pArgs;
241
242                 return true;
243         }
244         else if (*pType == _ACTIVATE_FRAME)
245         {
246                 _EcoreEvas* pEcoreEvas = GetEcoreEvasMgr()->GetEcoreEvas();
247                 if (pEcoreEvas)
248                 {
249                         pEcoreEvas->ActivateWindow(*this);
250                 }
251
252                 pArgs->RemoveAll(true);
253                 delete pArgs;
254
255                 return true;
256         }
257
258         return false;
259 }
260
261 void
262 _Frame::OnFrameActivated(void)
263 {
264         int childcount = GetChildCount();
265
266         for (int i = 0 ; i < childcount ; i++)
267         {
268                 _Control* pChild = GetChild(i);
269                 _Form* pForm = dynamic_cast<_Form*>(pChild);
270                 if (pForm)
271                 {
272                         pForm->MoveOverlayRegion(true);
273                 }
274         }
275
276         // Fire Event.
277         IEventArg* pArg = _FrameEvent::CreateFrameEventArgN(*this, _FRAME_STATUS_ACTIVATED);
278         __pFrameEvent->Fire(*pArg);
279
280         if (GetChildCount() < 1)
281         {
282                 _EcoreEvas* pEcoreEvas = GetEcoreEvasMgr()->GetEcoreEvas();
283                 SysTryReturnVoidResult(NID_UI_CTRL, pEcoreEvas, E_SYSTEM, "[E_SYSTEM] Unable to get evas");
284
285                 if (GetShowMode() == FRAME_SHOW_MODE_FULL_SCREEN)
286                 {
287                         pEcoreEvas->SetIndicatorShowState(*GetRootWindow(), false);
288                 }
289         }
290 }
291
292 void
293 _Frame::OnFrameDeactivated(void)
294 {
295         int childcount = GetChildCount();
296
297         for (int i = 0 ; i < childcount ; i++)
298         {
299                 _Control* pChild = GetChild(i);
300                 _Form* pForm = dynamic_cast<_Form*>(pChild);
301                 if (pForm)
302                 {
303                         pForm->MoveOverlayRegion(false);
304                 }
305         }
306
307         // Fire Event.
308         IEventArg* pArg = _FrameEvent::CreateFrameEventArgN(*this, _FRAME_STATUS_DEACTIVATED);
309         __pFrameEvent->Fire(*pArg);
310
311         _TouchManager* pTouchManager = _TouchManager::GetInstance();
312         if (pTouchManager)
313         {
314                 pTouchManager->SetTouchCanceled(null);
315         }
316 }
317
318 void
319 _Frame::OnFrameMinimized(void)
320 {
321         IEventArg* pArg = _FrameEvent::CreateFrameEventArgN(*this, _FRAME_STATUS_MINIMIZED);
322         __pFrameEvent->Fire(*pArg);
323 }
324
325 void
326 _Frame::OnFrameRestored(void)
327 {
328         __minimized = false;
329
330         IEventArg* pArg = _FrameEvent::CreateFrameEventArgN(*this, _FRAME_STATUS_RESTORED);
331         __pFrameEvent->Fire(*pArg);
332 }
333
334 void
335 _Frame::SetCurrentForm(const _Form* pForm)
336 {
337         result r = E_SUCCESS;
338
339         SysTryReturnVoidResult(NID_UI_CTRL, pForm != null, E_INVALID_ARG, "[E_INVALID_ARG] Form to become a new current form is null");
340         _Form* pNewForm = const_cast<_Form*>(pForm);
341
342         _Form* pCurrentForm = GetCurrentForm();
343         pNewForm->AddIndicatorObject();
344
345         if (pCurrentForm != null)
346         {
347                 if (pCurrentForm != pForm)
348                 {
349                         // Change order
350                         r = MoveChildToTop(*pForm);
351                         SysTryReturnVoidResult(NID_UI_CTRL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
352                         pNewForm->MoveOverlayRegion(true);
353
354                         pCurrentForm->SetVisibleState(false);
355                         pCurrentForm->MoveOverlayRegion(false);
356
357                         if (__pFormActivationChangeEventListener)
358                                 __pFormActivationChangeEventListener->OnFormDeactivated(*pCurrentForm);
359                 }
360         }
361
362         pNewForm->SetVisibleState(true);
363         _Control* pFocus = pNewForm->GetFocusControl();
364         if (pFocus)
365         {
366                 pFocus->SetFocused();
367         }
368         else
369         {
370                 pNewForm->SetFocused();
371         }
372
373         pNewForm->SetUpdateLayoutState(true);
374
375         if (__pFormActivationChangeEventListener)
376                 __pFormActivationChangeEventListener->OnFormActivated(*pNewForm);
377
378         SetLastResult(E_SUCCESS);
379
380         return;
381 }
382
383 _Form*
384 _Frame::GetCurrentForm(void) const
385 {
386         _Form* pCurrentForm = null;
387         int controlCount = GetChildCount();
388
389         if (controlCount > 0)
390         {
391                 for (int i = controlCount; i > 0; i--)
392                 {
393                         pCurrentForm = dynamic_cast<_Form*>(GetChild(i - 1));
394                         SysTryReturn(NID_UI_CTRL, pCurrentForm != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
395                         if (pCurrentForm->IsVisible())
396                         {
397                                 break;
398                         }
399                 }
400         }
401
402         return pCurrentForm;
403 }
404
405 bool
406 _Frame::IsOrientationRoot(void) const
407 {
408         return true;
409 }
410
411 void
412 _Frame::SetRotation(bool rotation)
413 {
414         __rotation = rotation;
415 }
416
417 void
418 _Frame::AddFrameEventListener(const _IFrameEventListener& listener)
419 {
420         __constructed = true;
421
422         result r = __pFrameEvent->AddListener(listener);
423         SysTryReturnVoidResult(NID_UI_CTRL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
424 }
425
426 void
427 _Frame::RemoveFrameEventListener(const _IFrameEventListener& listener)
428 {
429         result r = __pFrameEvent->RemoveListener(listener);
430         SysTryReturnVoidResult(NID_UI_CTRL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
431 }
432
433 void
434 _Frame::SetFormActivationChangeEventListener(const _IFormActivationChangeEventListener* plistener)
435 {
436         __pFormActivationChangeEventListener = const_cast<_IFormActivationChangeEventListener*>(plistener);
437 }
438
439
440 void
441 _Frame::SetFloatingBounds(const FloatRectangle& rect)
442 {
443         __floatingBounds = rect;
444 }
445
446 void
447 _Frame::SetFloatingBounds(const Rectangle& rect)
448 {
449         __floatingBounds = _CoordinateSystemUtils::ConvertToFloat(rect);
450 }
451
452 void
453 _Frame::SetFloatingOrientation(_ControlOrientation orientation)
454 {
455         if ((__showMode == FRAME_SHOW_MODE_PARTIAL_SCREEN) || (__showMode == FRAME_SHOW_MODE_PARTIAL_SCREEN_FLOATING))
456         {
457                 __floatingOrientation = orientation;
458         }
459 }
460
461 result
462 _Frame::SetShowMode(FrameShowMode showMode)
463 {
464         _EcoreEvas* pEcoreEvas = GetEcoreEvasMgr()->GetEcoreEvas();
465         SysTryReturnResult(NID_UI_CTRL, pEcoreEvas, E_SYSTEM, "The method cannot proceed due to a severe system error.");
466
467         if (showMode == FRAME_SHOW_MODE_MINIMIZED)
468         {
469                 if (__minimized == true)
470                 {
471                         return E_SUCCESS;
472                 }
473
474                 pEcoreEvas->MinimizeWindow(*GetRootWindow());
475                 __minimized = true;
476
477                 return E_SUCCESS;
478         }
479         else
480         {
481                 if (__minimized == true)
482                 {
483                         return E_SYSTEM;
484                 }
485         }
486
487         bool changeMode = true;
488
489         if ((showMode == FRAME_SHOW_MODE_PARTIAL_SCREEN) || (showMode == FRAME_SHOW_MODE_PARTIAL_SCREEN_FLOATING))
490         {
491                 _Form* pCurrentForm = GetCurrentForm();
492
493                 if (pCurrentForm)
494                 {
495                         if (pCurrentForm->GetFormStyle() & _FORM_STYLE_INDICATOR)
496                         {
497                                 changeMode = false;
498                         }
499                 }
500         }
501
502         SysTryReturnResult(NID_UI_CTRL, changeMode == true, E_SYSTEM, "The method cannot proceed due to a severe system error.");
503
504         int oldShowMode = __showMode;
505         __showMode = showMode;
506
507         if ((__showMode == FRAME_SHOW_MODE_PARTIAL_SCREEN) || (__showMode == FRAME_SHOW_MODE_PARTIAL_SCREEN_FLOATING))
508         {
509                 _ControlOrientation orientation = _CONTROL_ORIENTATION_PORTRAIT;
510                 _Form* pCurForm = GetCurrentForm();
511                 if (pCurForm)
512                 {
513                         orientation = pCurForm->GetOrientation();
514                 }
515                 else
516                 {
517                         orientation = GetOrientation();
518                 }
519
520                 if (orientation == _CONTROL_ORIENTATION_PORTRAIT)
521                 {
522                         if (__floatingOrientation == _CONTROL_ORIENTATION_LANDSCAPE)
523                         {
524                                 FloatDimension screenSize = _ControlManager::GetInstance()->_ControlManager::GetScreenSizeF();
525                                 FloatPoint prevPoint(__floatingBounds.x, __floatingBounds.y);
526                                 FloatPoint curPoint(prevPoint.x, prevPoint.y);
527                                 float ratio = screenSize.width / screenSize.height;
528
529                                 if (prevPoint.x > 0.0f)
530                                 {
531                                         curPoint.x = prevPoint.x * ratio;
532                                 }
533                         
534                                 if (prevPoint.y > 0.0f)
535                                 {
536                                         curPoint.y = prevPoint.y / ratio;
537                                 }
538
539                                 __floatingBounds.x = curPoint.x;
540                                 __floatingBounds.y = curPoint.y;
541                         }
542                 }
543                 else
544                 {
545                         if (__floatingOrientation == _CONTROL_ORIENTATION_PORTRAIT)
546                         {
547                                 FloatDimension screenSize = _ControlManager::GetInstance()->_ControlManager::GetScreenSizeF();
548                                 FloatPoint prevPoint(__floatingBounds.x, __floatingBounds.y);
549                                 FloatPoint curPoint(prevPoint.x, prevPoint.y);
550                                 float ratio = screenSize.width / screenSize.height;
551
552                                 if (prevPoint.x > 0.0f)
553                                 {
554                                         curPoint.x = prevPoint.x / ratio;
555                                 }
556                         
557                                 if (prevPoint.y > 0.0f)
558                                 {
559                                         curPoint.y = prevPoint.y * ratio;
560                                 }
561                         
562                                 __floatingBounds.x = curPoint.x;
563                                 __floatingBounds.y = curPoint.y;
564                         }
565                 }
566         }
567
568         result r = E_SUCCESS;
569
570         switch (__showMode)
571         {
572         case FRAME_SHOW_MODE_FULL_SCREEN:
573                 if (oldShowMode == FRAME_SHOW_MODE_PARTIAL_SCREEN_FLOATING)
574                 {
575                         r = pEcoreEvas->SetFloatingMode(*GetRootWindow(), false);
576                         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
577                 }
578
579                 if (oldShowMode != FRAME_SHOW_MODE_FULL_SCREEN)
580                 {
581                         FloatDimension screen = _ControlManager::GetInstance()->GetScreenSizeF();
582
583                         __restore = true;
584
585                         if (GetOrientation() == _CONTROL_ORIENTATION_PORTRAIT)
586                         {
587                                 SetBounds(FloatRectangle(0.0f, 0.0f, screen.width, screen.height));
588                         }
589                         else
590                         {
591                                 SetBounds(FloatRectangle(0.0f, 0.0f, screen.height, screen.width));
592                         }
593
594                         __restore = false;
595                 }
596
597                 break;
598         case FRAME_SHOW_MODE_PARTIAL_SCREEN:
599                 if (oldShowMode == FRAME_SHOW_MODE_PARTIAL_SCREEN_FLOATING)
600                 {
601                         r = pEcoreEvas->SetFloatingMode(*GetRootWindow(), false);
602                         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
603                 }
604
605                 if (oldShowMode == FRAME_SHOW_MODE_FULL_SCREEN)
606                 {
607                         SetBounds(__floatingBounds);
608                 }
609                 else if (oldShowMode == FRAME_SHOW_MODE_PARTIAL_SCREEN_FLOATING)
610                 {
611                         pEcoreEvas->SetWindowBounds(*GetRootWindow(), _CoordinateSystemUtils::ConvertToInteger(__floatingBounds));
612                 }
613
614                 break;
615         case FRAME_SHOW_MODE_PARTIAL_SCREEN_FLOATING:
616                 if (oldShowMode != FRAME_SHOW_MODE_PARTIAL_SCREEN_FLOATING)
617                 {
618                         r = pEcoreEvas->SetFloatingMode(*GetRootWindow(), true);
619                         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
620                 }
621
622                 if (oldShowMode == FRAME_SHOW_MODE_FULL_SCREEN)
623                 {
624                         SetBounds(__floatingBounds);
625                 }
626
627                 break;
628         default:
629                 break;
630         }
631
632         if ((__showMode == FRAME_SHOW_MODE_PARTIAL_SCREEN) || (__showMode == FRAME_SHOW_MODE_PARTIAL_SCREEN_FLOATING))
633         {
634                 _Form* pCurForm = GetCurrentForm();
635                 if (pCurForm)
636                 {
637                         __floatingOrientation = pCurForm->GetOrientation();
638                 }
639                 else
640                 {
641                         __floatingOrientation = GetOrientation();
642                 }
643         }
644
645         return E_SUCCESS;
646 }
647
648 FrameShowMode
649 _Frame::GetShowMode(bool minimize) const
650 {
651         if (minimize)
652         {
653                 if (__minimized == true)
654                 {
655                         return FRAME_SHOW_MODE_MINIMIZED;
656                 }
657                 else
658                 {
659                         return __showMode;
660                 }
661         }
662         else
663         {
664                 return __showMode;
665         }
666 }
667
668 bool
669 _Frame::IsActivated(void) const
670 {
671         return __activated;
672 }
673
674 void
675 _Frame::OnChildAttached(const _Control& child)
676 {
677         _Form* pCurrentForm = GetCurrentForm();
678
679         if (pCurrentForm == &child)
680         {
681                 int controlCount = GetChildCount();
682
683                 if (controlCount > 1)
684                 {
685                         _Control* pOldCurrentForm = GetChild(controlCount - 2);
686                         SysTryReturnVoidResult(NID_UI_CTRL, pOldCurrentForm != null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
687                         pOldCurrentForm->SetVisibleState(false);
688                 }
689         }
690 }
691
692 void
693 _Frame::OnChildDetached(const _Control& child)
694 {
695         int controlCount = GetChildCount();
696
697         if (controlCount > 0)
698         {
699                 _Control* pCurrentForm = GetChild(controlCount - 1);
700                 SysTryReturnVoidResult(NID_UI_CTRL, pCurrentForm, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
701                 pCurrentForm->SetVisibleState(true);
702         }
703         else
704         {
705                 _EcoreEvas* pEcoreEvas = GetEcoreEvasMgr()->GetEcoreEvas();
706                 SysTryReturnVoidResult(NID_UI_CTRL, pEcoreEvas, E_SYSTEM, "[E_SYSTEM] Unable to get evas");
707                 pEcoreEvas->SetIndicatorShowState(*GetRootWindow(), false);
708         }
709 }
710
711 result
712 _Frame::OnBoundsChanging(const FloatRectangle& bounds)
713 {
714         int appType = _AppInfo::GetAppType();
715         if (appType & _APP_TYPE_IME_APP)
716         {
717                 SysLog(NID_UI_CTRL, "[Ime Rotation]");
718                 return E_SUCCESS;
719         }
720
721         if (__restore == false)
722         {
723                 __floatingBounds = bounds;
724         }
725
726         if ((__showMode == FRAME_SHOW_MODE_FULL_SCREEN) && (__restore == false))
727         {
728                 if (__constructed == false)
729                 {
730                         return E_SUCCESS;
731                 }
732                 else
733                 {
734                         if (__rotation == true)
735                         {
736                                 return E_SUCCESS;
737                         }
738                         else
739                         {
740                                 return E_UNSUPPORTED_OPERATION;
741                         }
742                 }
743         }
744
745         if (__changingBoundsEnabled == false)
746         {
747                 return E_SUCCESS;
748         }
749
750         _EcoreEvas* pEcoreEvas = GetEcoreEvasMgr()->GetEcoreEvas();
751         SysTryReturn(NID_UI, pEcoreEvas, E_SYSTEM, E_SYSTEM, "[E_SYSTEM] A system error occurred.");
752
753         pEcoreEvas->SetWindowBounds(*GetRootWindow(), _CoordinateSystemUtils::ConvertToInteger(bounds));
754         result r = GetLastResult();
755         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
756
757         return r;
758 }
759
760
761 result
762 _Frame::OnAttached(void)
763 {
764         _EcoreEvas* pEcoreEvas = GetEcoreEvasMgr()->GetEcoreEvas();
765         SysAssert(pEcoreEvas);
766
767         pEcoreEvas->SetWindowVisibleState(*GetRootWindow(), true);
768
769         return E_SUCCESS;
770 }
771
772 void
773 _Frame::OnBackgroundColorChanged(Color& backgroundColor)
774 {
775         _RootVisualElement* pRootVE = GetRootVisualElement();
776         SysAssert(pRootVE);
777
778         _EflLayer* pLayer = static_cast<_EflLayer*>(pRootVE->GetNativeLayer());
779         SysAssert(pLayer);
780
781         byte alpha = backgroundColor.GetAlpha();
782         float opacity = static_cast<float>(alpha) / 255.0f;
783
784         pLayer->SetOpacity(opacity);
785
786         // Restore
787         FrameShowMode showMode = GetShowMode(false);
788         SetShowMode(FRAME_SHOW_MODE_FULL_SCREEN);
789
790         SetShowMode(showMode);
791
792         _EcoreEvas* pEcoreEvas = GetEcoreEvasMgr()->GetEcoreEvas();
793         if (!pEcoreEvas)
794         {
795                 return;
796         }
797
798         Orientation mode = ORIENTATION_PORTRAIT;
799
800         _Form* pCurrentForm = GetCurrentForm();
801         if (pCurrentForm)
802         {
803                 _FormImpl* pFormImpl = static_cast<_FormImpl*>(pCurrentForm->GetUserData());
804                 if (pFormImpl)
805                 {
806                         mode = pFormImpl->GetOrientation();
807                 }
808         }
809         else
810         {
811                 _FrameImpl* pFrameImpl = static_cast<_FrameImpl*>(GetUserData());
812                 if (pFrameImpl)
813                 {
814                         mode = pFrameImpl->GetOrientation();
815                 }
816         }
817
818         switch (mode)
819         {
820         case ORIENTATION_PORTRAIT:
821                 pEcoreEvas->SetWindowPreferredRotation(*this, 0, true);
822                 break;
823         case ORIENTATION_LANDSCAPE:
824                 pEcoreEvas->SetWindowPreferredRotation(*this, 270, true);
825                 break;
826         case ORIENTATION_PORTRAIT_REVERSE:
827                 pEcoreEvas->SetWindowPreferredRotation(*this, 180, true);
828                 break;
829         case ORIENTATION_LANDSCAPE_REVERSE:
830                 pEcoreEvas->SetWindowPreferredRotation(*this, 90, true);
831                 break;
832         case ORIENTATION_AUTOMATIC:
833                 {
834                         pEcoreEvas->SetWindowPreferredRotation(*this, -1);
835                         int autoRotation[3] = {0, 90, 270};
836                         pEcoreEvas->SetWindowAvailabledRotation(*this, autoRotation, 3, true);
837                 }
838                 break;
839         case ORIENTATION_AUTOMATIC_FOUR_DIRECTION:
840                 {
841                         pEcoreEvas->SetWindowPreferredRotation(*this, -1);
842                         int autoFourRotation[4] = {0, 90, 180, 270};
843                         pEcoreEvas->SetWindowAvailabledRotation(*this, autoFourRotation, 4, true);
844                 }
845                 break;
846         default:
847                 break;
848         }
849 }
850
851 void
852 _Frame::ResetFocusList(void)
853 {
854         Tizen::Ui::Controls::_Form* pCurrentForm = GetCurrentForm();
855         if (pCurrentForm)
856         {
857                 pCurrentForm->ResetFocusList();
858         }
859 }
860
861 _Control*
862 _Frame::GetFocusControl(const _Control* pControl) const
863 {
864         const _Form* pForm = null;
865         _Frame* pFrame = null;
866         const _Control* pTempControl = pControl;
867         while(pTempControl)
868         {
869                 pForm = dynamic_cast<_Form*>(const_cast<_Control*>(pTempControl));
870
871                 if (pForm)
872                 {
873                         pFrame = dynamic_cast<_Frame*>(pForm->GetParent());
874                         if (pFrame)
875                         {
876                                 break;
877                         }
878                         else
879                         {
880                                 pTempControl = pTempControl->GetParent();
881                         }
882                 }
883                 else
884                 {
885                         pTempControl = pTempControl->GetParent();
886                 }
887         }
888         if (pForm)
889         {
890                 return pForm->GetFocusControl();
891         }
892         return null;
893 }
894
895 _Control*
896 _Frame::GetCurrentFocusControl(void) const
897 {
898         _Form* pForm = GetCurrentForm();
899         if (pForm)
900         {
901                 return pForm->GetFocusControl();
902         }
903         return null;
904 }
905 void
906 _Frame::SetFocusControl(const _Control* pControl , bool on)
907 {
908         SysTryReturnVoidResult(NID_UI, pControl, E_SYSTEM, "[E_SYSTEM] The pControl cannot be NULL.");
909         _ControlManager* pControlMgr = _ControlManager::GetInstance();
910         SysAssert(pControlMgr);
911         _Form* pForm = null;
912         _Form* pCurrentForm = GetCurrentForm();
913         _Frame* pFrame = null;
914         const _Control* pTempControl = pControl;
915         bool isCurrentForm = false;
916
917         while(pTempControl)
918         {
919                 pForm = dynamic_cast<_Form*>(const_cast<_Control*>(pTempControl));
920
921                 if (pForm)
922                 {
923                         pFrame = dynamic_cast<_Frame*>(pForm->GetParent());
924                         if (pFrame)
925                         {
926                                 break;
927                         }
928                         else
929                         {
930                                 pTempControl = pTempControl->GetParent();
931                         }
932                 }
933                 else
934                 {
935                         pTempControl = pTempControl->GetParent();
936                 }
937         }
938
939         if (pForm == pCurrentForm)
940         {
941                 isCurrentForm = true;
942         }
943
944         if (pForm)
945         {
946                 if (on)
947                 {
948                         pForm->SetFocusControl(pControl);
949                         if (isCurrentForm)
950                         {
951                                 pControlMgr->SetFocusControl(*pControl);
952                         }
953                 }
954                 else
955                 {
956                         pControlMgr->SetFocusControl(*this, false);
957                         pForm->SetFocused();
958                 }
959         }
960 }
961
962 void
963 _Frame::SetChangingBoundsEnabled(bool enable)
964 {
965         __changingBoundsEnabled = enable;
966 }
967
968 Tizen::Base::Collection::IListT<_Control*>*
969 _Frame::GetFocusList(void) const
970 {
971         _Form* pForm = GetCurrentForm();
972         if (pForm)
973         {
974                 return pForm->GetFocusList();
975         }
976         return null;
977 }
978
979 _Control*
980 _Frame::GetFocusTraversalControl(_Control* pControl) const
981 {
982         _Form* pForm = null;
983         _Control* pTempControl = pControl;
984         _Frame* pFrame = null;
985         while(pTempControl)
986         {
987                 pForm = dynamic_cast<_Form*>(const_cast<_Control*>(pTempControl));
988
989                 if (pForm)
990                 {
991                         pFrame = dynamic_cast<_Frame*>(pForm->GetParent());
992                         if (pFrame)
993                         {
994                                 break;
995                         }
996                         else
997                         {
998                                 pTempControl = pTempControl->GetParent();
999                         }
1000                 }
1001                 else
1002                 {
1003                         pTempControl = pTempControl->GetParent();
1004                 }
1005         }
1006         
1007         if (pForm)
1008         {
1009                 return pForm->GetFocusTraversalControl();
1010         }
1011         return null;
1012 }
1013
1014 void
1015 _Frame::SetFocusTraversalControl(_Control* pControl)
1016 {
1017         _Form* pForm = null;
1018         _Control* pTempControl = pControl;
1019         _Frame* pFrame = null;
1020         while(pTempControl)
1021         {
1022                 pForm = dynamic_cast<_Form*>(const_cast<_Control*>(pTempControl));
1023
1024                 if (pForm)
1025                 {
1026                         pFrame = dynamic_cast<_Frame*>(pForm->GetParent());
1027                         if (pFrame)
1028                         {
1029                                 break;
1030                         }
1031                         else
1032                         {
1033                                 pTempControl = pTempControl->GetParent();
1034                         }
1035                 }
1036                 else
1037                 {
1038                         pTempControl = pTempControl->GetParent();
1039                 }
1040         }
1041
1042         if (pForm)
1043         {
1044                 pForm->SetFocusTraversalControl(pControl);
1045         }
1046 }
1047 }}} // Tizen::Ui::Controls