d0a3e4f43c35162de99663519ac63f7c69427e0f
[platform/core/uifw/dali-toolkit.git] / automated-tests / src / dali-toolkit / dali-toolkit-test-utils / toolkit-window.cpp
1 /*
2  * Copyright (c) 2020 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
35 class Window;
36
37 /********************************************************************************
38  * Stub for Dali::Internal::Adaptor::Window
39  ********************************************************************************/
40
41 namespace Internal
42 {
43 namespace Adaptor
44 {
45
46 Window::Window( const PositionSize& positionSize )
47 : SceneHolder( positionSize ),
48   mFocusChangeSignal(),
49   mResizeSignal(),
50   mRotationAngle(90), // dummy angle for test coverage
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 WindowPosition Window::GetPosition() const
61 {
62   PositionSize positionSize = mRenderSurface.GetPositionSize();
63
64   return 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 } // Adaptor
89 } // 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( Internal::Adaptor::Window* window )
139 : BaseHandle( window )
140 {
141 }
142
143 Integration::Scene Window::GetScene()
144 {
145   return GetImplementation( *this ).GetScene();
146 }
147
148 Dali::RenderSurfaceInterface& Window::GetRenderSurface()
149 {
150   return GetImplementation( *this ).GetRenderSurface();
151 }
152
153 void Window::Add( Actor actor )
154 {
155   GetImplementation( *this ).Add( actor );
156 }
157
158 void Window::Remove( Actor actor )
159 {
160   GetImplementation( *this ).Remove( actor );
161 }
162
163 Dali::Layer Window::GetRootLayer() const
164 {
165   return GetImplementation( *this ).GetRootLayer();
166 }
167
168 void Window::SetBackgroundColor( const Vector4& color )
169 {
170   GetImplementation( *this ).SetBackgroundColor( color );
171 }
172
173 Vector4 Window::GetBackgroundColor() const
174 {
175   return GetImplementation( *this ).GetBackgroundColor();
176 }
177
178 void Window::Raise()
179 {
180   GetImplementation( *this ).mFocusChangeSignal.Emit(*this, true);
181 }
182
183 void Window::Hide()
184 {
185   GetImplementation( *this ).mVisibilityChangedSignal.Emit( *this, false );
186 }
187
188 FocusChangeSignalType& Window::FocusChangeSignal()
189 {
190   return GetImplementation( *this ).mFocusChangeSignal;
191 }
192
193 ResizeSignalType& Window::ResizeSignal()
194 {
195   return GetImplementation( *this ).mResizeSignal;
196 }
197
198 Window::KeyEventSignalType& Window::KeyEventSignal()
199 {
200   return GetImplementation( *this ).KeyEventSignal();
201 }
202
203 Window::TouchEventSignalType& Window::TouchedSignal()
204 {
205   return GetImplementation( *this ).TouchedSignal();
206 }
207
208 namespace DevelWindow
209 {
210
211 Window Get( Actor actor )
212 {
213   Internal::Adaptor::Window* windowImpl = nullptr;
214
215   if ( Dali::Adaptor::IsAvailable() )
216   {
217     windowImpl = static_cast<Internal::Adaptor::Window*>( AdaptorImpl::GetImpl( AdaptorImpl::Get() ).GetWindow( actor ) );
218   }
219
220   return Dali::Window( windowImpl );
221 }
222
223 Window DownCast( BaseHandle handle )
224 {
225   Internal::Adaptor::Window* windowImpl = nullptr;
226   if ( Dali::Adaptor::IsAvailable() )
227   {
228     windowImpl = dynamic_cast<Dali::Internal::Adaptor::Window*>( handle.GetObjectPtr());
229   }
230   return Dali::Window( windowImpl );
231 }
232
233 void SetPositionSize(Window window, PositionSize positionSize)
234 {
235   GetImplementation( window ).SetPositionSize(positionSize);
236 }
237
238 int GetPhysicalOrientation(Window window)
239 {
240   return GetImplementation( window ).mRotationAngle;
241 }
242
243 void AddFrameRenderedCallback( Window window, std::unique_ptr< CallbackBase > callback, int32_t frameId )
244 {
245   CallbackBase::Execute( *callback, frameId );
246 }
247
248 void AddFramePresentedCallback( Window window, std::unique_ptr< CallbackBase > callback, int32_t frameId )
249 {
250   CallbackBase::Execute( *callback, frameId );
251 }
252
253 EventProcessingFinishedSignalType& EventProcessingFinishedSignal( Window window )
254 {
255   return GetImplementation( window ).GetScene().EventProcessingFinishedSignal();
256 }
257
258 KeyEventGeneratedSignalType& KeyEventGeneratedSignal( Window window )
259 {
260   return GetImplementation( window ).KeyEventGeneratedSignal();
261 }
262
263 WheelEventSignalType& WheelEventSignal( Window window )
264 {
265   return GetImplementation( window ).WheelEventSignal();
266 }
267
268 VisibilityChangedSignalType& VisibilityChangedSignal( Window window )
269 {
270   return GetImplementation( window ).mVisibilityChangedSignal;
271 }
272
273 } // namespace DevelWindow
274
275 } // Dali