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