[dali_2.3.20] Merge branch 'devel/master'
[platform/core/uifw/dali-toolkit.git] / automated-tests / src / dali-toolkit / dali-toolkit-test-utils / toolkit-window.cpp
1 /*
2  * Copyright (c) 2024 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 #include <dali/public-api/render-tasks/render-task-list.h>
26
27 #define DALI_WINDOW_H
28 #include <dali/integration-api/adaptor-framework/adaptor.h>
29 #include <toolkit-adaptor-impl.h>
30
31 using AdaptorImpl = Dali::Internal::Adaptor::Adaptor;
32
33 namespace Dali
34 {
35 class Window;
36
37 /********************************************************************************
38  * Stub for Dali::Internal::Adaptor::Window
39  ********************************************************************************/
40
41 namespace Internal
42 {
43 namespace Adaptor
44 {
45 Window::Window(const PositionSize& positionSize)
46 : SceneHolder(positionSize),
47   mFocusChangeSignal(),
48   mResizeSignal(),
49   mRotationAngle(90), // dummy angle for test coverage
50   mVisible(true),
51   mVisibilityChangedSignal()
52 {
53 }
54
55 Window* Window::New(const PositionSize& positionSize, const std::string& name, const std::string& className, bool isTransparent)
56 {
57   return new Window(positionSize);
58 }
59
60 Dali::Window::WindowPosition Window::GetPosition() const
61 {
62   PositionSize positionSize = mRenderSurface.GetPositionSize();
63
64   return Dali::Window::WindowPosition(positionSize.x, positionSize.y);
65 }
66
67 PositionSize Window::GetPositionSize() const
68 {
69   return mRenderSurface.GetPositionSize();
70 }
71
72 Dali::Window::WindowSize Window::GetSize() const
73 {
74   PositionSize positionSize = mRenderSurface.GetPositionSize();
75
76   return Dali::Window::WindowSize(positionSize.width, positionSize.height);
77 }
78
79 void Window::SetPositionSize(PositionSize positionSize)
80 {
81   mRenderSurface.MoveResize(positionSize);
82
83   Uint16Pair   newSize(positionSize.width, positionSize.height);
84   Dali::Window handle(this);
85   mResizeSignal.Emit(handle, newSize);
86 }
87
88 } // namespace Adaptor
89 } // namespace Internal
90
91 inline Internal::Adaptor::Window& GetImplementation(Dali::Window& window)
92 {
93   DALI_ASSERT_ALWAYS(window && "Window handle is empty");
94   BaseObject& object = window.GetBaseObject();
95   return static_cast<Internal::Adaptor::Window&>(object);
96 }
97
98 inline const Internal::Adaptor::Window& GetImplementation(const Dali::Window& window)
99 {
100   DALI_ASSERT_ALWAYS(window && "Window handle is empty");
101   const BaseObject& object = window.GetBaseObject();
102   return static_cast<const Internal::Adaptor::Window&>(object);
103 }
104
105 Window::Window()
106 {
107 }
108
109 Window::~Window()
110 {
111 }
112
113 Window::Window(const Window& copy) = default;
114
115 Window& Window::operator=(const Window& rhs) = default;
116
117 Window::Window(Window&& rhs) = default;
118
119 Window& Window::operator=(Window&& rhs) = default;
120
121 Dali::Window Window::New(PositionSize windowPosition, const std::string& name, bool isTransparent)
122 {
123   return New(windowPosition, name, "", isTransparent);
124 }
125
126 Dali::Window Window::New(PositionSize windowPosition, const std::string& name, const std::string& className, bool isTransparent)
127 {
128   Internal::Adaptor::Window* window = Internal::Adaptor::Window::New(windowPosition, name, className, isTransparent);
129
130   Dali::Window result(window);
131
132   // This will also emit the window created signals
133   AdaptorImpl::GetImpl(AdaptorImpl::Get()).AddWindow(window);
134
135   return result;
136 }
137
138 Window Window::DownCast(BaseHandle handle)
139 {
140   Internal::Adaptor::Window* windowImpl = nullptr;
141   if(Dali::Adaptor::IsAvailable())
142   {
143     windowImpl = dynamic_cast<Dali::Internal::Adaptor::Window*>(handle.GetObjectPtr());
144   }
145   return Dali::Window(windowImpl);
146 }
147
148 Window::Window(Internal::Adaptor::Window* window)
149 : BaseHandle(window)
150 {
151 }
152
153 Integration::Scene Window::GetScene()
154 {
155   return GetImplementation(*this).GetScene();
156 }
157
158 Dali::RenderSurfaceInterface& Window::GetRenderSurface()
159 {
160   return GetImplementation(*this).GetRenderSurface();
161 }
162
163 void Window::Add(Actor actor)
164 {
165   GetImplementation(*this).Add(actor);
166 }
167
168 void Window::Remove(Actor actor)
169 {
170   GetImplementation(*this).Remove(actor);
171 }
172
173 Dali::Layer Window::GetRootLayer() const
174 {
175   return GetImplementation(*this).GetRootLayer();
176 }
177
178 void Window::SetBackgroundColor(const Vector4& color)
179 {
180   GetImplementation(*this).SetBackgroundColor(color);
181 }
182
183 Vector4 Window::GetBackgroundColor() const
184 {
185   return GetImplementation(*this).GetBackgroundColor();
186 }
187
188 void Window::Raise()
189 {
190   GetImplementation(*this).mFocusChangeSignal.Emit(*this, true);
191 }
192
193 void Window::Show()
194 {
195   GetImplementation(*this).mVisible = true;
196   GetImplementation(*this).mVisibilityChangedSignal.Emit(*this, true);
197 }
198
199 void Window::Hide()
200 {
201   GetImplementation(*this).mVisible = false;
202   GetImplementation(*this).mVisibilityChangedSignal.Emit(*this, false);
203 }
204
205 bool Window::IsVisible() const
206 {
207   return GetImplementation(*this).mVisible;
208 }
209
210 FocusChangeSignalType& Window::FocusChangeSignal()
211 {
212   return GetImplementation(*this).mFocusChangeSignal;
213 }
214
215 ResizeSignalType& Window::ResizeSignal()
216 {
217   return GetImplementation(*this).mResizeSignal;
218 }
219
220 Window::KeyEventSignalType& Window::KeyEventSignal()
221 {
222   return GetImplementation(*this).KeyEventSignal();
223 }
224
225 Window::TouchEventSignalType& Window::TouchedSignal()
226 {
227   return GetImplementation(*this).TouchedSignal();
228 }
229
230 Dali::RenderTaskList Window::GetRenderTaskList()
231 {
232   return GetImplementation(*this).GetRenderTaskList();
233 }
234
235 namespace DevelWindow
236 {
237 Window Get(Actor actor)
238 {
239   Internal::Adaptor::Window* windowImpl = nullptr;
240
241   if(Dali::Adaptor::IsAvailable())
242   {
243     windowImpl = static_cast<Internal::Adaptor::Window*>(AdaptorImpl::GetImpl(AdaptorImpl::Get()).GetWindow(actor));
244   }
245
246   return Dali::Window(windowImpl);
247 }
248
249 void SetPositionSize(Window window, PositionSize positionSize)
250 {
251   GetImplementation(window).SetPositionSize(positionSize);
252 }
253
254 int GetPhysicalOrientation(Window window)
255 {
256   return GetImplementation(window).mRotationAngle;
257 }
258
259 void AddFrameRenderedCallback(Window window, std::unique_ptr<CallbackBase> callback, int32_t frameId)
260 {
261   CallbackBase::Execute(*callback, frameId);
262 }
263
264 void AddFramePresentedCallback(Window window, std::unique_ptr<CallbackBase> callback, int32_t frameId)
265 {
266   CallbackBase::Execute(*callback, frameId);
267 }
268
269 EventProcessingFinishedSignalType& EventProcessingFinishedSignal(Window window)
270 {
271   return GetImplementation(window).GetScene().EventProcessingFinishedSignal();
272 }
273
274 KeyEventGeneratedSignalType& KeyEventGeneratedSignal(Window window)
275 {
276   return GetImplementation(window).KeyEventGeneratedSignal();
277 }
278
279 WheelEventSignalType& WheelEventSignal(Window window)
280 {
281   return GetImplementation(window).WheelEventSignal();
282 }
283
284 WheelEventGeneratedSignalType& WheelEventGeneratedSignal(Window window)
285 {
286   return GetImplementation(window).WheelEventGeneratedSignal();
287 }
288
289 VisibilityChangedSignalType& VisibilityChangedSignal(Window window)
290 {
291   return GetImplementation(window).mVisibilityChangedSignal;
292 }
293
294 } // namespace DevelWindow
295
296 } // namespace Dali