Changes required after Window::DownCast addition
[platform/core/uifw/dali-toolkit.git] / automated-tests / src / dali-toolkit / dali-toolkit-test-utils / toolkit-window.cpp
1 /*
2  * Copyright (c) 2022 Samsung Electronics Co., Ltd.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  */
17
18 // CLASS HEADER
19 #include "toolkit-window-impl.h"
20
21 // EXTERNAL INCLUDES
22 #include <dali/public-api/actors/actor.h>
23 #include <dali/public-api/actors/layer.h>
24 #include <dali/public-api/object/base-object.h>
25
26 #define DALI_WINDOW_H
27 #include <dali/integration-api/adaptor-framework/adaptor.h>
28 #include <toolkit-adaptor-impl.h>
29
30 using AdaptorImpl = Dali::Internal::Adaptor::Adaptor;
31
32 namespace Dali
33 {
34 class Window;
35
36 /********************************************************************************
37  * Stub for Dali::Internal::Adaptor::Window
38  ********************************************************************************/
39
40 namespace Internal
41 {
42 namespace Adaptor
43 {
44 Window::Window(const PositionSize& positionSize)
45 : SceneHolder(positionSize),
46   mFocusChangeSignal(),
47   mResizeSignal(),
48   mRotationAngle(90), // dummy angle for test coverage
49   mVisible(true),
50   mVisibilityChangedSignal()
51 {
52 }
53
54 Window* Window::New(const PositionSize& positionSize, const std::string& name, const std::string& className, bool isTransparent)
55 {
56   return new Window(positionSize);
57 }
58
59 Dali::Window::WindowPosition Window::GetPosition() const
60 {
61   PositionSize positionSize = mRenderSurface.GetPositionSize();
62
63   return Dali::Window::WindowPosition(positionSize.x, positionSize.y);
64 }
65
66 PositionSize Window::GetPositionSize() const
67 {
68   return mRenderSurface.GetPositionSize();
69 }
70
71 Dali::Window::WindowSize Window::GetSize() const
72 {
73   PositionSize positionSize = mRenderSurface.GetPositionSize();
74
75   return Dali::Window::WindowSize(positionSize.width, positionSize.height);
76 }
77
78 void Window::SetPositionSize(PositionSize positionSize)
79 {
80   mRenderSurface.MoveResize(positionSize);
81
82   Uint16Pair   newSize(positionSize.width, positionSize.height);
83   Dali::Window handle(this);
84   mResizeSignal.Emit(handle, newSize);
85 }
86
87 } // namespace Adaptor
88 } // namespace Internal
89
90 inline Internal::Adaptor::Window& GetImplementation(Dali::Window& window)
91 {
92   DALI_ASSERT_ALWAYS(window && "Window handle is empty");
93   BaseObject& object = window.GetBaseObject();
94   return static_cast<Internal::Adaptor::Window&>(object);
95 }
96
97 inline const Internal::Adaptor::Window& GetImplementation(const Dali::Window& window)
98 {
99   DALI_ASSERT_ALWAYS(window && "Window handle is empty");
100   const BaseObject& object = window.GetBaseObject();
101   return static_cast<const Internal::Adaptor::Window&>(object);
102 }
103
104 Window::Window()
105 {
106 }
107
108 Window::~Window()
109 {
110 }
111
112 Window::Window(const Window& copy) = default;
113
114 Window& Window::operator=(const Window& rhs) = default;
115
116 Window::Window(Window&& rhs) = default;
117
118 Window& Window::operator=(Window&& rhs) = default;
119
120 Dali::Window Window::New(PositionSize windowPosition, const std::string& name, bool isTransparent)
121 {
122   return New(windowPosition, name, "", isTransparent);
123 }
124
125 Dali::Window Window::New(PositionSize windowPosition, const std::string& name, const std::string& className, bool isTransparent)
126 {
127   Internal::Adaptor::Window* window = Internal::Adaptor::Window::New(windowPosition, name, className, isTransparent);
128
129   Dali::Window result(window);
130
131   // This will also emit the window created signals
132   AdaptorImpl::GetImpl(AdaptorImpl::Get()).AddWindow(window);
133
134   return result;
135 }
136
137 Window Window::DownCast(BaseHandle handle)
138 {
139   Internal::Adaptor::Window* windowImpl = nullptr;
140   if(Dali::Adaptor::IsAvailable())
141   {
142     windowImpl = dynamic_cast<Dali::Internal::Adaptor::Window*>(handle.GetObjectPtr());
143   }
144   return Dali::Window(windowImpl);
145 }
146
147 Window::Window(Internal::Adaptor::Window* window)
148 : BaseHandle(window)
149 {
150 }
151
152 Integration::Scene Window::GetScene()
153 {
154   return GetImplementation(*this).GetScene();
155 }
156
157 Dali::RenderSurfaceInterface& Window::GetRenderSurface()
158 {
159   return GetImplementation(*this).GetRenderSurface();
160 }
161
162 void Window::Add(Actor actor)
163 {
164   GetImplementation(*this).Add(actor);
165 }
166
167 void Window::Remove(Actor actor)
168 {
169   GetImplementation(*this).Remove(actor);
170 }
171
172 Dali::Layer Window::GetRootLayer() const
173 {
174   return GetImplementation(*this).GetRootLayer();
175 }
176
177 void Window::SetBackgroundColor(const Vector4& color)
178 {
179   GetImplementation(*this).SetBackgroundColor(color);
180 }
181
182 Vector4 Window::GetBackgroundColor() const
183 {
184   return GetImplementation(*this).GetBackgroundColor();
185 }
186
187 void Window::Raise()
188 {
189   GetImplementation(*this).mFocusChangeSignal.Emit(*this, true);
190 }
191
192 void Window::Hide()
193 {
194   GetImplementation(*this).mVisibilityChangedSignal.Emit(*this, false);
195   GetImplementation(*this).mVisible = false;
196 }
197
198 bool Window::IsVisible() const
199 {
200   return GetImplementation(*this).mVisible;
201 }
202
203 FocusChangeSignalType& Window::FocusChangeSignal()
204 {
205   return GetImplementation(*this).mFocusChangeSignal;
206 }
207
208 ResizeSignalType& Window::ResizeSignal()
209 {
210   return GetImplementation(*this).mResizeSignal;
211 }
212
213 Window::KeyEventSignalType& Window::KeyEventSignal()
214 {
215   return GetImplementation(*this).KeyEventSignal();
216 }
217
218 Window::TouchEventSignalType& Window::TouchedSignal()
219 {
220   return GetImplementation(*this).TouchedSignal();
221 }
222
223 namespace DevelWindow
224 {
225 Window Get(Actor actor)
226 {
227   Internal::Adaptor::Window* windowImpl = nullptr;
228
229   if(Dali::Adaptor::IsAvailable())
230   {
231     windowImpl = static_cast<Internal::Adaptor::Window*>(AdaptorImpl::GetImpl(AdaptorImpl::Get()).GetWindow(actor));
232   }
233
234   return Dali::Window(windowImpl);
235 }
236
237 void SetPositionSize(Window window, PositionSize positionSize)
238 {
239   GetImplementation(window).SetPositionSize(positionSize);
240 }
241
242 int GetPhysicalOrientation(Window window)
243 {
244   return GetImplementation(window).mRotationAngle;
245 }
246
247 void AddFrameRenderedCallback(Window window, std::unique_ptr<CallbackBase> callback, int32_t frameId)
248 {
249   CallbackBase::Execute(*callback, frameId);
250 }
251
252 void AddFramePresentedCallback(Window window, std::unique_ptr<CallbackBase> callback, int32_t frameId)
253 {
254   CallbackBase::Execute(*callback, frameId);
255 }
256
257 EventProcessingFinishedSignalType& EventProcessingFinishedSignal(Window window)
258 {
259   return GetImplementation(window).GetScene().EventProcessingFinishedSignal();
260 }
261
262 KeyEventGeneratedSignalType& KeyEventGeneratedSignal(Window window)
263 {
264   return GetImplementation(window).KeyEventGeneratedSignal();
265 }
266
267 WheelEventSignalType& WheelEventSignal(Window window)
268 {
269   return GetImplementation(window).WheelEventSignal();
270 }
271
272 WheelEventGeneratedSignalType& WheelEventGeneratedSignal(Window window)
273 {
274   return GetImplementation(window).WheelEventGeneratedSignal();
275 }
276
277 VisibilityChangedSignalType& VisibilityChangedSignal(Window window)
278 {
279   return GetImplementation(window).mVisibilityChangedSignal;
280 }
281
282 } // namespace DevelWindow
283
284 } // namespace Dali