Merge "Changes after TouchedSignal changes" into devel/master
[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   mVisibilityChangedSignal()
50 {
51 }
52
53 Window* Window::New(const PositionSize& positionSize, const std::string& name, const std::string& className, bool isTransparent)
54 {
55   return new Window( positionSize );
56 }
57
58 } // Adaptor
59 } // Internal
60
61 inline Internal::Adaptor::Window& GetImplementation(Dali::Window& window)
62 {
63   DALI_ASSERT_ALWAYS( window && "Window handle is empty" );
64   BaseObject& object = window.GetBaseObject();
65   return static_cast<Internal::Adaptor::Window&>(object);
66 }
67
68 inline const Internal::Adaptor::Window& GetImplementation(const Dali::Window& window)
69 {
70   DALI_ASSERT_ALWAYS( window && "Window handle is empty" );
71   const BaseObject& object = window.GetBaseObject();
72   return static_cast<const Internal::Adaptor::Window&>(object);
73 }
74
75 Window::Window()
76 {
77 }
78
79 Window::~Window()
80 {
81 }
82
83 Window::Window( const Window& copy ) = default;
84
85 Window& Window::operator=( const Window& rhs ) = default;
86
87 Window::Window( Window&& rhs ) = default;
88
89 Window& Window::operator=( Window&& rhs ) = default;
90
91 Dali::Window Window::New( PositionSize windowPosition, const std::string& name, bool isTransparent )
92 {
93   return New( windowPosition, name, "", isTransparent );
94 }
95
96 Dali::Window Window::New(PositionSize windowPosition, const std::string& name, const std::string& className, bool isTransparent )
97 {
98   Internal::Adaptor::Window* window = Internal::Adaptor::Window::New( windowPosition, name, className, isTransparent );
99
100   Dali::Window result( window );
101
102   // This will also emit the window created signals
103   AdaptorImpl::GetImpl( AdaptorImpl::Get() ).AddWindow( window );
104
105   return result;
106 }
107
108 Window::Window( Internal::Adaptor::Window* window )
109 : BaseHandle( window )
110 {
111 }
112
113 Integration::Scene Window::GetScene()
114 {
115   return GetImplementation( *this ).GetScene();
116 }
117
118 Dali::RenderSurfaceInterface& Window::GetRenderSurface()
119 {
120   return GetImplementation( *this ).GetRenderSurface();
121 }
122
123 void Window::Add( Actor actor )
124 {
125   GetImplementation( *this ).Add( actor );
126 }
127
128 void Window::Remove( Actor actor )
129 {
130   GetImplementation( *this ).Remove( actor );
131 }
132
133 Dali::Layer Window::GetRootLayer() const
134 {
135   return GetImplementation( *this ).GetRootLayer();
136 }
137
138 void Window::SetBackgroundColor( const Vector4& color )
139 {
140   GetImplementation( *this ).SetBackgroundColor( color );
141 }
142
143 Vector4 Window::GetBackgroundColor() const
144 {
145   return GetImplementation( *this ).GetBackgroundColor();
146 }
147
148 void Window::Raise()
149 {
150   GetImplementation( *this ).mFocusChangeSignal.Emit(*this, true);
151 }
152
153 void Window::Hide()
154 {
155   GetImplementation( *this ).mVisibilityChangedSignal.Emit( *this, false );
156 }
157
158 FocusChangeSignalType& Window::FocusChangeSignal()
159 {
160   return GetImplementation( *this ).mFocusChangeSignal;
161 }
162
163 Window::KeyEventSignalType& Window::KeyEventSignal()
164 {
165   return GetImplementation( *this ).KeyEventSignal();
166 }
167
168 Window::TouchEventSignalType& Window::TouchedSignal()
169 {
170   return GetImplementation( *this ).TouchedSignal();
171 }
172
173 namespace DevelWindow
174 {
175
176 Window Get( Actor actor )
177 {
178   Internal::Adaptor::Window* windowImpl = nullptr;
179
180   if ( Dali::Adaptor::IsAvailable() )
181   {
182     windowImpl = static_cast<Internal::Adaptor::Window*>( AdaptorImpl::GetImpl( AdaptorImpl::Get() ).GetWindow( actor ) );
183   }
184
185   return Dali::Window( windowImpl );
186 }
187
188 Window DownCast( BaseHandle handle )
189 {
190   Internal::Adaptor::Window* windowImpl = nullptr;
191   if ( Dali::Adaptor::IsAvailable() )
192   {
193     windowImpl = dynamic_cast<Dali::Internal::Adaptor::Window*>( handle.GetObjectPtr());
194   }
195   return Dali::Window( windowImpl );
196 }
197
198 void AddFrameRenderedCallback( Window window, std::unique_ptr< CallbackBase > callback, int32_t frameId )
199 {
200   CallbackBase::Execute( *callback, frameId );
201 }
202
203 void AddFramePresentedCallback( Window window, std::unique_ptr< CallbackBase > callback, int32_t frameId )
204 {
205   CallbackBase::Execute( *callback, frameId );
206 }
207
208 EventProcessingFinishedSignalType& EventProcessingFinishedSignal( Window window )
209 {
210   return GetImplementation( window ).GetScene().EventProcessingFinishedSignal();
211 }
212
213 KeyEventGeneratedSignalType& KeyEventGeneratedSignal( Window window )
214 {
215   return GetImplementation( window ).KeyEventGeneratedSignal();
216 }
217
218 WheelEventSignalType& WheelEventSignal( Window window )
219 {
220   return GetImplementation( window ).WheelEventSignal();
221 }
222
223 VisibilityChangedSignalType& VisibilityChangedSignal( Window window )
224 {
225   return GetImplementation( window ).mVisibilityChangedSignal;
226 }
227
228 } // namespace DevelWindow
229
230 } // Dali