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