Tizen 2.1 base
[framework/osp/uifw.git] / src / ui / FUiWindow.cpp
1 //
2 // Open Service Platform
3 // Copyright (c) 2012-2013 Samsung Electronics Co., Ltd.
4 //
5 // Licensed under the Flora License, Version 1.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://floralicense.org/license/
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        FUiWindow.cpp
19  * @brief       This is the implementation file for Window class.
20  */
21
22 #include <FBaseSysLog.h>
23 #include <FUiWindow.h>
24 #include <FUiAnimDisplayContext.h>
25 #include <FSec_AccessController.h>
26 #include "FUi_WindowImpl.h"
27 #include "FUi_ErrorMessages.h"
28
29 using namespace Tizen::Graphics;
30 using namespace Tizen::Ui::Animations;
31 using namespace Tizen::Security;
32
33 namespace Tizen { namespace Ui {
34
35 Window::Window()
36 {
37 }
38
39 Window::~Window(void)
40 {
41 }
42
43 result
44 Window::Construct(const Rectangle& rect, bool resizable, bool movable)
45 {
46         result r = E_SUCCESS;
47         SysAssertf(_pControlImpl == null, "Already constructed. Calling Construct() twice or more on a same instance is not allowed for this class.");
48         _WindowImpl* pImpl = _WindowImpl::CreateWindowImplN(this, rect, null, null, resizable, movable);
49         r = GetLastResult();
50         SysTryReturn(NID_UI, pImpl, r, r, "[%s] Propagating.", GetErrorMessage(r));
51
52         _pControlImpl = pImpl;
53
54         return E_SUCCESS;
55 }
56
57 result
58 Window::Construct(const Layout& layout, const Rectangle& rect, bool resizable, bool movable)
59 {
60         return Construct(layout, layout, rect, resizable, movable);
61 }
62
63 result
64 Window::Construct(const Layout& portraitLayout, const Layout& landscapeLayout,
65                                                          const Rectangle& rect, bool resizable, bool movable)
66 {
67         result r = E_SUCCESS;
68         SysAssertf(_pControlImpl == null, "Already constructed. Calling Construct() twice or more on a same instance is not allowed for this class.");
69
70         _WindowImpl* pImpl =
71                 _WindowImpl::CreateWindowImplN(this, rect, &portraitLayout, &landscapeLayout, resizable, movable);
72
73         r = GetLastResult();
74         SysTryReturn(NID_UI, pImpl, r, r, "[%s] Propagating.", GetErrorMessage(r));
75
76
77         _pControlImpl = pImpl;
78
79         return E_SUCCESS;
80 }
81
82 result
83 Window::Show(void)
84 {
85         result r = E_SUCCESS;
86
87         _WindowImpl* pImpl = _WindowImpl::GetInstance(*this);
88         SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
89
90         r = pImpl->Open();
91
92         return r;
93 }
94
95 WindowState
96 Window::GetWindowState(void) const
97 {
98         const _WindowImpl* pImpl = _WindowImpl::GetInstance(*this);
99         SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
100
101         return pImpl->GetWindowState();
102 }
103
104 DisplayContext*
105 Window::GetDisplayContext(void) const
106 {
107         const _WindowImpl* pImpl = _WindowImpl::GetInstance(*this);
108         SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
109
110         return pImpl->GetDisplayContext();
111 }
112
113 result
114 Window::SetZOrderGroup(WindowZOrderGroup windowZOrderGroup)
115 {
116         result r = _AccessController::CheckUserPrivilege(_PRV_UIMANAGER);
117         SysTryReturnResult(NID_LOC, r == E_SUCCESS, E_PRIVILEGE_DENIED, "The application does not have the privilege to call this method.");
118
119         _WindowImpl* pImpl = _WindowImpl::GetInstance(*this);
120         SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
121
122         return pImpl->SetZOrderGroup(windowZOrderGroup);
123 }
124
125 void
126 Window::SetOwner(Tizen::Ui::Control *pControl)
127 {
128         _WindowImpl* pImpl = _WindowImpl::GetInstance(*this);
129         SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
130
131         pImpl->SetOwner(pControl);
132 }
133
134 void
135 Window::AddWindowEventListener(IWindowEventListener& listener)
136 {
137         _WindowImpl* pImpl = _WindowImpl::GetInstance(*this);
138         SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
139
140         pImpl->AddWindowEventListener(listener);
141         result r = GetLastResult();
142         SysTryReturnVoidResult(NID_UI, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
143 }
144
145 void
146 Window::RemoveWindowEventListener(IWindowEventListener& listener)
147 {
148         _WindowImpl* pImpl = _WindowImpl::GetInstance(*this);
149         SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
150
151         pImpl->RemoveWindowEventListener(listener);
152         result r = GetLastResult();
153         SysTryReturnVoidResult(NID_UI, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
154 }
155
156 }} // Tizen::Ui