c1a53f0b7433b1beca595e4b5eb91354e8506aed
[platform/framework/native/uifw.git] / src / ui / FUi_Window.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 /**
19  * @file                FUi_Window.cpp
20  * @brief               This is the implementation file for the _Window class.
21  */
22
23 #include <FBaseSysLog.h>
24 #include <FUiAnimDisplayContext.h>
25 #include <FUiWindow.h>
26 #include <FBase_Log.h>
27 #include <FBaseColArrayListT.h>
28 #include <FApp_AppInfo.h>
29 #include "FUi_Window.h"
30 #include "FUi_ControlManager.h"
31 #include "FUi_TouchManager.h"
32 #include "FUiAnim_DisplayContextImpl.h"
33 #include "FUiAnim_RootVisualElement.h"
34 #include "FUiAnim_VisualElement.h"
35 #include "FUi_EcoreEvasMgr.h"
36 #include "FUi_EcoreEvas.h"
37 #include "FUiAnim_DisplayManager.h"
38 #include "FUiAnim_EflLayer.h"
39 #include "FUiCtrl_Form.h"
40 #include "FUiCtrl_FormImpl.h"
41 #include "FUiCtrl_FrameImpl.h"
42 #include "FUi_AccessibilityManager.h"
43
44 using namespace Tizen::App;
45 using namespace Tizen::Base;
46 using namespace Tizen::Base::Collection;
47 using namespace Tizen::Graphics;
48 using namespace Tizen::Ui::Animations;
49 using namespace Tizen::Ui::Controls;
50
51 namespace Tizen { namespace Ui
52 {
53
54 _Window*
55 _Window::CreateWindowN(void)
56 {
57         _Window* pWindow = new (std::nothrow) _Window;
58         SysTryReturn(NID_UI, pWindow, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory shortage.");
59
60         result r = E_SUCCESS;
61
62         if (IsFailed(GetLastResult()))
63         {
64                 goto CATCH;
65         }
66
67         r = pWindow->CreateRootVisualElement();
68         SysTryCatch(NID_UI, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
69
70         pWindow->AcquireHandle();
71
72         return pWindow;
73
74 CATCH:
75         delete pWindow;
76         return null;
77 }
78
79 _Window::~_Window(void)
80 {
81         __destroying = true;
82         Close();
83         SetOwner(null);
84
85         if (__pDisplayContext)
86         {
87                 _DisplayContextImpl::DestroyPublicInstance(*__pDisplayContext);
88                 __pDisplayContext = null;
89         }
90
91         if(__pLayer)
92         {
93                 //_EflLayer* pLayer = static_cast<_EflLayer*>(__pLayer);
94                 //Ecore_X_Window win = (Ecore_X_Window) ecore_evas_window_get(pLayer->GetEcoreEvas());
95                 //SysLog(NID_UI, "[Multi_Window] destroy x window(0x%x)", win);
96
97                 if(__pRootVisualElement)
98                 {
99                         if (GetVisualElement())
100                         {
101                                 __pRootVisualElement->DetachChild(*GetVisualElement());
102                         }
103                 }
104                 delete __pLayer;
105                 __pLayer = NULL;
106         }
107
108         delete __pDimmingLayer;
109         __pDimmingLayer = null;
110
111         __pRootVisualElement =NULL;
112
113         _ControlManager::GetInstance()->DetachAllWindow(*this);
114 }
115
116 _IWindowDelegate&
117 _Window::GetWindowDelegate(void) const
118 {
119         if (__destroying)
120         {
121                 return const_cast<_Window&>(*this);
122         }
123
124         SysAssert(__pWindowDelegate);
125         return *__pWindowDelegate;
126 }
127
128 String
129 _Window::GetDescription(void) const
130 {
131         String description = _Control::GetDescription();
132         String descriptionTemp(L"");
133
134         descriptionTemp.Format(LOG_LEN_MAX, L"_Window: xid(0x%x) owner(0x%x) delegate(0x%x) activated(%d) destroying(%d) displayContext(0x%x)",
135                 GetNativeHandle(), __pOwner, __pWindowDelegate, __activated, __destroying, __pDisplayContext);
136
137         description.Append(descriptionTemp);
138
139         return description;
140 }
141
142 void
143 _Window::SetRootVisualElement(const Tizen::Ui::Animations::_RootVisualElement& rootVisualElement)
144 {
145         _RootVisualElement* pRootVE = const_cast<_RootVisualElement*>(&rootVisualElement);
146
147         __pRootVisualElement = pRootVE;
148 }
149
150 void
151 _Window::SetLayer(const Tizen::Ui::Animations::_NativeLayer& layer)
152 {
153         _NativeLayer* pLayer = const_cast<_NativeLayer*>(&layer);
154
155         __pLayer = pLayer;
156 }
157
158 bool
159 _Window::IsActivatedOnOpen(void) const
160 {
161         return true;
162 }
163
164 bool
165 _Window::IsActivated(void) const
166 {
167         return __activated;
168 }
169
170 void
171 _Window::SetWindowDelegate(_IWindowDelegate& delegate)
172 {
173         ClearLastResult();
174         __pWindowDelegate = &delegate;
175 }
176
177 void
178 _Window::ResetWindowDelegate(void)
179 {
180         ClearLastResult();
181         __pWindowDelegate = this;
182 }
183
184 bool
185 _Window::IsAttached(void) const
186 {
187         return _ControlManager::GetInstance()->IsWindowAttached(*this);
188 }
189
190 result
191 _Window::Open(bool drawAndShow)
192 {
193         bool visibleState = GetVisibleState();
194         if (!__isOpened && visibleState)
195         {
196                 __isOpened = true;
197                 __isInitialized = true;
198                 result r = _ControlManager::GetInstance()->OpenWindow(*this, drawAndShow);
199
200                 if (__type != _WINDOW_TYPE_VE)
201                 {
202                         _EcoreEvas* pEcoreEvas = GetEcoreEvasMgr()->GetEcoreEvas();
203                         SysTryReturn(NID_UI, pEcoreEvas, E_SYSTEM, E_SYSTEM, "[E_SYSTEM] A system error occurred.");
204                         pEcoreEvas->SetWindowVisibleState(*GetRootWindow(), visibleState);
205                 }
206
207                 return r;
208         }
209
210         return E_SUCCESS;
211 }
212
213 void
214 _Window::Close(void)
215 {
216         if (__isOpened)
217         {
218                 if (__type != _WINDOW_TYPE_VE)
219                 {
220                         bool visibleState = GetVisibleState();
221                         _EcoreEvas* pEcoreEvas = GetEcoreEvasMgr()->GetEcoreEvas();
222                         SysTryReturnVoidResult(NID_UI, pEcoreEvas, E_SYSTEM, "[E_SYSTEM] A system error occurred.");
223                         pEcoreEvas->SetWindowVisibleState(*GetRootWindow(), visibleState);
224                 }
225
226                 _ControlManager::GetInstance()->CloseWindow(*this);
227                 __isOpened = false;
228         }
229 }
230
231 _Control*
232 _Window::GetOwner(void) const
233 {
234         ClearLastResult();
235         return __pOwner;
236 }
237
238 void
239 _Window::SetOwner(_Control* pOwner)
240 {
241         ClearLastResult();
242
243         if (pOwner)
244         {
245                 if (__type != _WINDOW_TYPE_VE)
246                 {
247                         _EcoreEvas* pEcoreEvas = GetEcoreEvasMgr()->GetEcoreEvas();
248                         if (pEcoreEvas)
249                         {
250                                 if (__transient == true)
251                                 {
252                                         pEcoreEvas->SetOwner(*this, *pOwner);
253                                 }
254
255                                 __transient = true;
256                         }
257                 }
258         }
259
260         if (pOwner == __pOwner)
261         {
262                 return;
263         }
264
265         _VisualElement* pVE = GetVisualElement();
266
267         if (__pOwner)
268         {
269                 __pOwner->DetachOwnee(*this);
270
271                 if (__type == _WINDOW_TYPE_VE)
272                 {
273                         _Window* pRootWindow = __pOwner->GetRootWindow();
274                         if (pRootWindow)
275                         {
276                                 _RootVisualElement* pRootVE = pRootWindow->GetRootVisualElement();
277                                 if (pRootVE && pVE)
278                                 {
279                                         pRootVE->DetachChild(*pVE);
280                                 }
281                         }
282                 }
283         }
284
285         if (pOwner)
286         {
287                 pOwner->AttachOwnee(*this);
288
289                 if (__type == _WINDOW_TYPE_VE)
290                 {
291                         _Window* pRootWindow = pOwner->GetRootWindow();
292                         if (pRootWindow)
293                         {
294                                 _RootVisualElement* pRootVE = pRootWindow->GetRootVisualElement();
295                                 if (pRootVE && pVE)
296                                 {
297                                         pRootVE->AttachChild(*pVE);
298                                 }
299                         }
300                 }
301         }
302
303         _Control* pOldOwner = __pOwner;
304         __pOwner = pOwner;
305         GetWindowDelegate().OnOwnerChanged(pOldOwner);
306 }
307
308 result
309 _Window::CreateRootVisualElement(_WindowType windowType)
310 {
311         __type = windowType;
312
313         if (__type == _WINDOW_TYPE_VE)
314         {
315                 return E_SUCCESS;
316         }
317
318         result r = CreateLayer();
319         SysTryReturn(NID_UI, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
320
321         _EcoreEvas* pEcoreEvas = GetEcoreEvasMgr()->GetEcoreEvas();
322         SysAssert(pEcoreEvas);
323         __rotation = pEcoreEvas->GetWindowRotation(*this);
324         pEcoreEvas->RegisterWindowStateCallback(*this);
325
326         // Get visual element.
327         _VisualElement* pVisualElement = GetVisualElement();
328         SysAssert(pVisualElement);
329
330         pVisualElement->SetName(L"Window");
331         pVisualElement->SetClipChildrenEnabled(false);
332         pVisualElement->SetRenderOperation(_VisualElement::RENDER_OPERATION_COPY);
333
334         // Attach visual element to root visual element.
335         __pRootVisualElement->AttachChild(*GetVisualElement());
336
337         if (__type == _WINDOW_TYPE_MAIN)
338         {
339                 SysLog(NID_UI, "[WM ROTATION][WIN 0x%x, BASIC] Create.", GetNativeHandle());
340         }
341         else
342         {
343                 pEcoreEvas->SetWindowType(*this, _WINDOW_TYPE_SUB);
344                 SysLog(NID_UI, "[WM ROTATION][WIN 0x%x, UTILITY] Create.", GetNativeHandle());
345         }
346
347         return E_SUCCESS;
348 }
349
350 result
351 _Window::CreateLayer(void)
352 {
353         _DisplayManager* pDisplayManager = _DisplayManager::GetInstance();
354         SysAssert(pDisplayManager);
355
356         if (__type == _WINDOW_TYPE_MAIN)
357         {
358                 __pLayer = _NativeLayer::CreateInstanceN();
359         }
360         else
361         {
362                 __pLayer = _NativeLayer::CreateInstanceN(false);
363         }
364
365         SysAssert(__pLayer);
366         __pRootVisualElement = __pLayer->GetRootVisualElement();
367
368         _EflLayer* pLayer = static_cast<_EflLayer*>(__pLayer);
369         SysAssert(pLayer);
370
371         int rootWindowW = 0;
372         int rootWindowH = 0;
373         ecore_x_window_size_get(ecore_x_window_root_get((Ecore_X_Window)ecore_evas_window_get(pLayer->GetEcoreEvas())), &rootWindowW, &rootWindowH);
374
375         pLayer->SetBounds(FloatRectangle(0.0f, 0.0f, (float)rootWindowW, (float)rootWindowH));
376         pLayer->SetOpacity(0);
377
378         __pRootVisualElement->SetName(L"Root");
379
380         _EcoreEvas* pEcoreEvas = GetEcoreEvasMgr()->GetEcoreEvas();
381         if (pEcoreEvas)
382         {
383                 String osp(L"OSP_");
384                 String appName = _AppInfo::GetAppName();
385                 osp.Append(appName);
386
387                 pEcoreEvas->SetWindowName(*this, osp);
388         }
389
390         return E_SUCCESS;
391 }
392
393 void
394 _Window::SetActivationEnabled(bool enable)
395 {
396         if (__type == _WINDOW_TYPE_VE)
397         {
398                 SetFocusable(enable);
399                 return;
400         }
401
402         _EcoreEvas* pEcoreEvas = GetEcoreEvasMgr()->GetEcoreEvas();
403         SysTryReturnVoidResult(NID_UI, pEcoreEvas, E_SYSTEM, "[E_SYSTEM] A system error occurred.");
404
405         pEcoreEvas->SetWindowActivationEnabled(*GetRootWindow(), enable);
406
407         SetLastResult(E_SUCCESS);
408 }
409
410 bool
411 _Window::IsActivationEnabled(void)
412 {
413         if (__type == _WINDOW_TYPE_VE)
414         {
415                 return IsFocusable();
416         }
417
418         _EcoreEvas* pEcoreEvas = GetEcoreEvasMgr()->GetEcoreEvas();
419         SysTryReturn(NID_UI, pEcoreEvas, true, E_SYSTEM, "[E_SYSTEM] A system error occurred.");
420
421         bool enable = pEcoreEvas->IsWindowActivationEnabled(*GetRootWindow());
422
423         SetLastResult(E_SUCCESS);
424
425         return enable;
426 }
427
428 void
429 _Window::SetNativeWindowActivated(bool activated)
430 {
431         __nativeWindowActivated = activated;
432 }
433
434 bool
435 _Window::GetNativeWindowActivated(void)
436 {
437         return __nativeWindowActivated;
438 }
439
440 _RootVisualElement*
441 _Window::GetRootVisualElement(void) const
442 {
443         return __pRootVisualElement;
444 }
445
446 NativeWindowHandle
447 _Window::GetNativeHandle(void) const
448 {
449         if (__type == _WINDOW_TYPE_VE)
450         {
451                 return 0;
452         }
453
454         _RootVisualElement* pRootVE = GetRootVisualElement();
455         SysAssert(pRootVE);
456
457         _EflLayer* pLayer = static_cast<_EflLayer*>(pRootVE->GetNativeLayer());
458         SysAssert(pLayer);
459
460         Ecore_Evas* pEcoreEvas = pLayer->GetEcoreEvas();
461         Ecore_X_Window win = (Ecore_X_Window) ecore_evas_window_get(pEcoreEvas);
462
463         return win;
464 }
465
466 void
467 _Window::OnActivated(void)
468 {
469         bool isFrameActivated = _ControlManager::GetInstance()->IsFrameActivated();
470         SysLog(NID_UI, "frameActivated(%d)", isFrameActivated);
471
472         _Control* focusedControl = GetCurrentFocusControl();
473
474         if (focusedControl)
475         {
476                 focusedControl->SetFocused();
477         }
478
479         else
480         {
481                 SetFocused();
482         }
483
484         if (!isFrameActivated)
485         {
486                 return;
487         }
488
489         _TouchManager* pTouchMgr = _TouchManager::GetInstance();
490         if (pTouchMgr)
491         {
492                 pTouchMgr->SetTouchCanceled(null);
493         }
494 }
495
496 void
497 _Window::OnNativeWindowActivated(void)
498 {
499
500 }
501
502 void
503 _Window::OnFocusableStateChanged(bool focusalbeState)
504 {
505         if (__type == _WINDOW_TYPE_VE)
506         {
507                 return;
508         }
509
510         SetActivationEnabled(focusalbeState);
511 }
512
513 bool
514 _Window::OnNotifiedN(const _Control& source, IList* pArgs)
515 {
516         SysTryReturn(NID_UI_CTRL, pArgs, false, E_SYSTEM, "[E_SYSTEM] pArgs is null.")
517
518         String* pType = dynamic_cast <String*>(pArgs->GetAt(0));
519         SysTryReturn(NID_UI_CTRL, pType, false, E_SYSTEM, "[E_SYSTEM] pType is null.")
520
521         if (*pType == L"VisibilityEvent")
522         {
523                 int obscured = 0;
524
525                 Integer* pObscured = dynamic_cast<Integer*>(pArgs->GetAt(1));
526                 if (pObscured == null)
527                 {
528                         pArgs->RemoveAll(true);
529                         delete pArgs;
530
531                         return true;
532                 }
533
534                 obscured = pObscured->ToInt();
535                 if (obscured == 0)
536                 {
537                         SetNativeWindowActivated(true);
538                         GetWindowDelegate().OnNativeWindowActivated();
539                 }
540                 else
541                 {
542                         SetNativeWindowActivated(false);
543                 }
544
545                 pArgs->RemoveAll(true);
546                 delete pArgs;
547
548                 return true;
549         }
550
551         return false;
552 }
553
554 void
555 _Window::OnDeactivated(void)
556 {
557         bool isFrameActivated = _ControlManager::GetInstance()->IsFrameActivated();
558         SysLog(NID_UI, "frameActivated(%d)", isFrameActivated);
559 }
560
561 void
562 _Window::OnOwnerChanged(_Control* pOldOwner)
563 {
564
565 }
566
567 result
568 _Window::OnBoundsChanging(const FloatRectangle& bounds)
569 {
570         if (__type == _WINDOW_TYPE_VE)
571         {
572                 return E_SUCCESS;
573         }
574
575         _EcoreEvas* pEcoreEvas = GetEcoreEvasMgr()->GetEcoreEvas();
576         SysTryReturn(NID_UI, pEcoreEvas, E_SYSTEM, E_SYSTEM, "[E_SYSTEM] A system error occurred.");
577
578         pEcoreEvas->SetWindowBounds(*GetRootWindow(), bounds);
579         result r = GetLastResult();
580         SysTryReturn(NID_UI, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
581
582         return r;
583 }
584
585 void
586 _Window::OnVisibleStateChanged(void)
587 {
588         ClearLastResult();
589
590         bool visibleState = GetVisibleState();
591         if (visibleState == false)
592         {
593                 Close();
594                 if(unlikely((_AccessibilityManager::IsActivated())))
595                 {
596                         _AccessibilityManager::GetInstance()->RequestAutoReading(_ACCESSIBILITY_AUTO_READING_MODE_FIRST_ITEM);
597                 }
598         }
599
600         result r = GetLastResult();
601         SysTryReturnVoidResult(NID_UI, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
602
603         SetLastResult(E_SUCCESS);
604 }
605
606 result
607 _Window::OnAttachingToMainTree(const _Control* pParent)
608 {
609         if (__type == _WINDOW_TYPE_VE)
610         {
611                 return E_SUCCESS;
612         }
613
614         _EflLayer* pLayer = static_cast<_EflLayer*>(__pRootVisualElement->GetNativeLayer());
615         SysAssert(pLayer);
616         SetVisibleState(true);
617         pLayer->SetShowState(true);
618
619         return E_SUCCESS;
620 }
621
622 result
623 _Window::OnDetachingFromMainTree(void)
624 {
625         if (__type == _WINDOW_TYPE_VE)
626         {
627                 return E_SUCCESS;
628         }
629
630         _EflLayer* pLayer = static_cast<_EflLayer*>(__pRootVisualElement->GetNativeLayer());
631         SysAssert(pLayer);
632         pLayer->SetShowState(false);
633
634         return E_SUCCESS;
635 }
636
637 void
638 _Window::OnWindowStateChanged(void)
639 {
640         // <0>
641         // Update rotation
642         // <1>
643         // Find current form
644         // Call UpdateOrientation
645         // <2>
646         // Find current frame
647         // Call UpdateOrientation
648         // <3>
649         // Find window
650         // Change layout
651         // Rotate window
652
653         SetOrientationCallbackModeEnabled(true);
654         _EcoreEvas* pEcoreEvas = GetEcoreEvasMgr()->GetEcoreEvas();
655         if (!pEcoreEvas)
656         {
657                 return;
658         }
659
660         int rotation = pEcoreEvas->GetWindowRotation(*this);
661
662         Rectangle winBounds = GetBounds();
663         SysLog(NID_UI, "[WM ROTATION][WIN 0x%x, %d, %d, %d, %d] OnWindowStateChanged : prev ROT %d, cur ROT %d", GetNativeHandle(), winBounds.x, winBounds.y, winBounds.width, winBounds.height, __rotation, rotation);
664
665         if (rotation == __rotation)
666         {
667                 return;
668         }
669
670         __rotation = rotation;
671
672         // <1>
673         int childCount = GetChildCount();
674         for (int i = childCount; i > 0; i--)
675         {
676                 _Control* pChild = GetChild(i - 1);
677
678                 _Form* pForm = dynamic_cast<_Form*>(pChild);
679                 if (pForm)
680                 {
681                         if (pForm->IsVisible())
682                         {
683                                 // Current Form
684                                 _FormImpl* pFormImpl = static_cast<_FormImpl*>(pForm->GetUserData());
685                                 if (pFormImpl)
686                                 {
687                                         pFormImpl->UpdateOrientation();
688                                 }
689
690                                 return;
691                         }
692                 }
693         }
694
695         // <2>
696         if (IsOrientationRoot())
697         {
698                 _FrameImpl* pFrameImpl = static_cast<_FrameImpl*>(GetUserData());
699                 if (pFrameImpl)
700                 {
701                         pFrameImpl->UpdateOrientation();
702                 }
703
704                 return;
705         }
706
707         // <3>
708         SysLog(NID_UI, "[WM ROTATION] ---------- Update Ownee Window : START ----------");
709
710         _ControlOrientation controlOrientation = (rotation == 0 || rotation == 180) ? _CONTROL_ORIENTATION_PORTRAIT : _CONTROL_ORIENTATION_LANDSCAPE;
711         ChangeLayout(controlOrientation, false);
712
713         _ControlRotation controlRotation = _CONTROL_ROTATION_0;
714         switch (rotation)
715         {
716                 case 0:
717                         controlRotation = _CONTROL_ROTATION_0;
718                         break;
719                 case 90:
720                         controlRotation = _CONTROL_ROTATION_90;
721                         break;
722                 case 180:
723                         controlRotation = _CONTROL_ROTATION_180;
724                         break;
725                 case 270:
726                         controlRotation = _CONTROL_ROTATION_270;
727                         break;
728                 default:
729                         break;
730         }
731         ChangeLayout(controlRotation);
732
733         pEcoreEvas->RotateWindow(*this, __rotation, false);
734
735         Invalidate(true);
736
737         SysLog(NID_UI, "[WM ROTATION] ---------- Update Ownee Window : END ----------");
738         SetOrientationCallbackModeEnabled(false);
739 }
740
741 void
742 _Window::OnTouchCaptureGained(void)
743 {
744
745 }
746
747 void
748 _Window::OnTouchCaptureLost(void)
749 {
750 }
751
752 void
753 _Window::SetPreferredRotation(bool enable)
754 {
755         __preferredRotation = enable;
756 }
757
758 bool
759 _Window::GetPreferredRotation(void) const
760 {
761         return __preferredRotation;
762 }
763
764 bool
765 _Window::IsRotationSynchronized(void) const
766 {
767         return false;
768 }
769
770 bool
771 _Window::IsLayoutChangable(void) const
772 {
773         if (__type == _WINDOW_TYPE_VE)
774         {
775                 return true;
776         }
777
778         return false;
779 }
780
781 void
782 _Window::SetRotation(int rotation)
783 {
784         __rotation = rotation;
785 }
786
787 _WindowType
788 _Window::GetWindowType(void)
789 {
790         return __type;
791 }
792
793 void
794 _Window::OnChangeLayout(_ControlOrientation orientation)
795 {
796         _DimmingLayer *pLayer = GetDimmingLayer();
797         if (pLayer)
798         {
799                 result r = GetDimmingLayer()->Rearrange();
800                 SysTryReturnVoidResult(NID_UI_CTRL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
801         }
802
803         // if window, change its size specially for full-screen(Form, Frame, etc.).
804         _Control::OnChangeLayout(orientation); // if called, layout will be changed.
805 }
806
807 WindowState
808 _Window::GetWindowState(void) const
809 {
810         ClearLastResult();
811         return __windowState;
812 }
813
814 void
815 _Window::SetWindowState(WindowState windowState)
816 {
817         __windowState = windowState;
818 }
819
820 DisplayContext*
821 _Window::GetDisplayContext(void) const
822 {
823         if (!__pDisplayContext)
824         {
825                 SysTryReturn(NID_UI, __pLayer, null, E_SYSTEM, "[E_SYSTEM] Cannot gain the DisplayContext. This window is not completed.");
826
827                 __pDisplayContext = _DisplayContextImpl::CreatePublicInstance(*__pLayer);
828         }
829
830         result r = GetLastResult();
831         SysTryReturn(NID_UI, __pDisplayContext, null, r, "[%s] Propagating.", GetErrorMessage(r));
832
833         return __pDisplayContext;
834 }
835
836 result
837 _Window::SetZOrderGroup(int windowZOrderGroup)
838 {
839         if (__type == _WINDOW_TYPE_VE)
840         {
841                 return E_SUCCESS;
842         }
843
844         _EcoreEvas* pEcoreEvas = GetEcoreEvasMgr()->GetEcoreEvas();
845
846         if (windowZOrderGroup == WINDOW_Z_ORDER_GROUP_HIGHEST)
847         {
848                 pEcoreEvas->SetWindowLevel(*this, _WINDOW_LEVEL_NOTIFICATION_HIGH);
849         }
850         else if (windowZOrderGroup == WINDOW_Z_ORDER_GROUP_HIGH)
851         {
852                 pEcoreEvas->SetWindowLevel(*this, _WINDOW_LEVEL_NOTIFICATION_MIDDLE);
853         }
854         else if (windowZOrderGroup == WINDOW_Z_ORDER_GROUP_NORMAL)
855         {
856                 pEcoreEvas->SetWindowLevel(*this, _WINDOW_LEVEL_NORMAL);
857         }
858
859         __transient = false;
860
861         bool visible = pEcoreEvas->IsWindowVisible(*this);
862         bool activationEnabled = pEcoreEvas->IsWindowActivationEnabled(*this);
863
864         if ((visible == true) && (activationEnabled == true))
865         {
866                 pEcoreEvas->ActivateWindow(*this);
867         }
868
869         return E_SUCCESS;
870 }
871
872 _Window::_Window()
873         : __type(_WINDOW_TYPE_MAIN)
874         , __windowState(WINDOW_STATE_INITIALIZED)
875         , __pOwner(null)
876         , __pWindowDelegate(null)
877         , __activated(false)
878         , __destroying(false)
879         , __pRootVisualElement(null)
880         , __pLayer(null)
881         , __pDimmingLayer(null)
882         , __pDisplayContext(null)
883         , __systemWindow(false)
884         , __isOpened(false)
885         , __isInitialized(false)
886         , __pFocusControl(null)
887         , __pFocusTraversalControl(null)
888         , __transient(true)
889         , __dimmingEnabled(false)
890         , __rotation(-1)
891         , __preferredRotation(false)
892         , __orientationCallbackMode(false)
893         , __nativeWindowActivated(false)
894 {
895         SetControlDelegate(*this);
896         SetWindowDelegate(*this);
897         SetClipToParent(false); // [ToDo] exception check.
898 }
899
900 void
901 _Window::Activate(void)
902 {
903         if (__activated)
904         {
905                 return;
906         }
907
908         __activated = true;
909         GetWindowDelegate().OnActivated();
910 }
911
912 void
913 _Window::Deactivate(void)
914 {
915         __activated = false;
916
917         if (__destroying == false)
918         {
919                 GetWindowDelegate().OnDeactivated();
920         }
921 }
922
923 void
924 _Window::SetSystemWindow(bool systemWindow)
925 {
926         __systemWindow = systemWindow;
927 }
928
929 bool
930 _Window::IsSystemWindow(void) const
931 {
932         return __systemWindow;
933 }
934
935 IListT<_Control*>*
936 _Window::GetFocusList(void) const
937 {
938         if(!__pFocusControlList)
939         {
940                 __pFocusControlList.reset(GetFocusListN());
941                 __pFocusControlList->InsertAt(const_cast<_Window*>(this), 0);
942         }
943         return __pFocusControlList.get();
944 }
945
946 void
947 _Window::ResetFocusList(void)
948 {
949         if(__pFocusControlList)
950         {
951                 __pFocusControlList.reset();
952         }
953 }
954
955 result
956 _Window::SetDimmingEnabled(bool enabled)
957 {
958         __dimmingEnabled = enabled;
959
960         return E_SUCCESS;
961 }
962
963 bool
964 _Window::IsDimmingEnabled(void) const
965 {
966         return __dimmingEnabled;
967 }
968
969 void
970 _Window::SetDimmingLayer(_DimmingLayer* pLayer)
971 {
972         __pDimmingLayer = pLayer;
973 }
974
975 _DimmingLayer*
976 _Window::GetDimmingLayer(void)
977 {
978         return __pDimmingLayer;
979 }
980
981 void
982 _Window::SetOrientationCallbackModeEnabled(bool enable)
983 {
984         __orientationCallbackMode = enable;
985 }
986
987 bool
988 _Window::IsOrientationCallbackModeEnabled(void) const
989 {
990         return __orientationCallbackMode;
991 }
992
993 _Control*
994 _Window::GetFocusTraversalControl(_Control* pControl) const
995 {
996         return __pFocusTraversalControl;
997 }
998
999 void
1000 _Window::SetFocusTraversalControl(_Control* pControl, bool on)
1001 {
1002         if (on)
1003         {
1004                 __pFocusTraversalControl = pControl;
1005         }
1006         else
1007         {
1008                 __pFocusTraversalControl = this;
1009         }
1010 }
1011
1012 void
1013 _Window:: SetFocusControl(const _Control* pControl, bool on)
1014 {
1015         SysTryReturnVoidResult(NID_UI, pControl, E_SYSTEM, "[E_SYSTEM] The pControl cannot be NULL.");
1016
1017         __pFocusControl = const_cast<_Control*>(pControl);
1018
1019         _ControlManager* pControlMgr = _ControlManager::GetInstance();
1020         SysAssert(pControlMgr);
1021
1022         if (on)
1023         {
1024                 if (IsActivated())
1025                 {
1026                         pControlMgr->SetFocusControl(*pControl);
1027                 }
1028         }
1029         else
1030         {
1031                 pControlMgr->SetFocusControl(*this, false);
1032                 SetFocused();
1033         }
1034 }
1035
1036 _Control*
1037 _Window::GetFocusControl(const _Control* pControl) const
1038 {
1039         return __pFocusControl;
1040 }
1041 _Control*
1042 _Window::GetCurrentFocusControl(void) const
1043 {
1044         return __pFocusControl;
1045 }
1046 }} // Tizen::Ui