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