3620bf9a3d610ca9442f411bb7674abea21775ea
[platform/core/uifw/dali-toolkit.git] / automated-tests / src / dali-toolkit / dali-toolkit-test-utils / toolkit-window.cpp
1 /*
2  * Copyright (c) 2019 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/adaptors/adaptor.h>
29 #include <toolkit-adaptor-impl.h>
30
31 // INTERNAL INCLUDES
32 #include "test-render-surface.h"
33
34 using AdaptorImpl = Dali::Internal::Adaptor::Adaptor;
35
36 namespace Dali
37 {
38
39 class Window;
40
41 /********************************************************************************
42  * Stub for Dali::Internal::Adaptor::Window
43  ********************************************************************************/
44
45 namespace Internal
46 {
47 namespace Adaptor
48 {
49 class Window : public Dali::BaseObject
50 {
51 public:
52
53   Window( const PositionSize& positionSize )
54   : mRenderSurface( positionSize ),
55     mScene( Dali::Integration::Scene::New( mRenderSurface ) )
56   {
57   }
58
59   virtual ~Window() = default;
60
61   static Window* New(const PositionSize& positionSize, const std::string& name, const std::string& className, bool isTransparent)
62   {
63     return new Window( positionSize );
64   }
65
66   TestRenderSurface mRenderSurface;
67   Integration::Scene mScene;
68 };
69
70 } // Adaptor
71 } // Internal
72
73 inline Internal::Adaptor::Window& GetImplementation(Dali::Window& window)
74 {
75   DALI_ASSERT_ALWAYS( window && "Window handle is empty" );
76   BaseObject& object = window.GetBaseObject();
77   return static_cast<Internal::Adaptor::Window&>(object);
78 }
79
80 inline const Internal::Adaptor::Window& GetImplementation(const Dali::Window& window)
81 {
82   DALI_ASSERT_ALWAYS( window && "Window handle is empty" );
83   const BaseObject& object = window.GetBaseObject();
84   return static_cast<const Internal::Adaptor::Window&>(object);
85 }
86
87 Window::Window()
88 {
89 }
90
91 Window::~Window()
92 {
93 }
94
95 Window::Window(const Window& handle)
96 : BaseHandle( handle )
97 {
98 }
99
100 Window& Window::operator=(const Window& rhs)
101 {
102   BaseHandle::operator=(rhs);
103   return *this;
104 }
105
106 Dali::Window Window::New( PositionSize windowPosition, const std::string& name, bool isTransparent )
107 {
108   return New( windowPosition, name, "", isTransparent );
109 }
110
111 Dali::Window Window::New(PositionSize windowPosition, const std::string& name, const std::string& className, bool isTransparent )
112 {
113   Internal::Adaptor::Window* window = Internal::Adaptor::Window::New( windowPosition, name, className, isTransparent );
114   Dali::Window newWindow = Window( window );
115   Dali::Adaptor::WindowCreatedSignalType& windowCreatedSignal = AdaptorImpl::Get().WindowCreatedSignal();
116   windowCreatedSignal.Emit( newWindow );
117   return Window( window );
118 }
119
120 Window::Window( Internal::Adaptor::Window* window )
121 : BaseHandle( window )
122 {
123 }
124
125 Integration::Scene Window::GetScene()
126 {
127   return GetImplementation( *this ).mScene;
128 }
129
130 Integration::RenderSurface& Window::GetRenderSurface()
131 {
132   return GetImplementation( *this ).mRenderSurface;
133 }
134
135 void Window::Add( Actor actor )
136 {
137   GetImplementation( *this ).Add( actor );
138 }
139
140 void Window::Remove( Actor actor )
141 {
142   GetImplementation( *this ).Remove( actor );
143 }
144
145 Dali::Layer Window::GetRootLayer() const
146 {
147   return GetImplementation( *this ).GetRootLayer();
148 }
149
150 void Window::SetBackgroundColor( const Vector4& color )
151 {
152   GetImplementation( *this ).SetBackgroundColor( color );
153 }
154
155 Vector4 Window::GetBackgroundColor() const
156 {
157   return GetImplementation( *this ).GetBackgroundColor();
158 }
159
160 void Window::Raise()
161 {
162   GetImplementation( *this ).mFocusChangeSignal.Emit(*this, true);
163 }
164
165 FocusChangeSignalType& Window::FocusChangeSignal()
166 {
167   return GetImplementation( *this ).mFocusChangeSignal;
168 }
169
170 namespace DevelWindow
171 {
172
173 Window Get( Actor actor )
174 {
175   Internal::Adaptor::Window* windowImpl = nullptr;
176
177   if ( Dali::Adaptor::IsAvailable() )
178   {
179     windowImpl = static_cast<Internal::Adaptor::Window*>( AdaptorImpl::GetImpl( AdaptorImpl::Get() ).GetWindow( actor ) );
180   }
181
182   return Dali::Window( windowImpl );
183 }
184
185 Window DownCast( BaseHandle handle )
186 {
187   Internal::Adaptor::Window* windowImpl = nullptr;
188   if ( Dali::Adaptor::IsAvailable() )
189   {
190     windowImpl = dynamic_cast<Dali::Internal::Adaptor::Window*>( handle.GetObjectPtr());
191   }
192   return Dali::Window( windowImpl );
193 }
194
195 EventProcessingFinishedSignalType& EventProcessingFinishedSignal( Window window )
196 {
197   return GetImplementation( window ).mScene.EventProcessingFinishedSignal();
198 }
199
200 KeyEventSignalType& KeyEventSignal( Window window )
201 {
202   return GetImplementation( window ).mScene.KeyEventSignal();
203 }
204
205 KeyEventGeneratedSignalType& KeyEventGeneratedSignal( Window window )
206 {
207   return GetImplementation( window ).mScene.KeyEventGeneratedSignal();
208 }
209
210 TouchSignalType& TouchSignal( Window window )
211 {
212   return GetImplementation( window ).mScene.TouchSignal();
213 }
214
215 WheelEventSignalType& WheelEventSignal( Window window )
216 {
217   return GetImplementation( window ).mScene.WheelEventSignal();
218 }
219
220 } // namespace DevelWindow
221
222 } // Dali