[dali_1.4.43] 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) 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
50 Window::Window( const PositionSize& positionSize )
51 : SceneHolder( positionSize ),
52   mFocusChangeSignal(),
53   mVisibilityChangedSignal()
54 {
55 }
56
57 Window* Window::New(const PositionSize& positionSize, const std::string& name, const std::string& className, bool isTransparent)
58 {
59   return new Window( positionSize );
60 }
61
62 } // Adaptor
63 } // Internal
64
65 inline Internal::Adaptor::Window& GetImplementation(Dali::Window& window)
66 {
67   DALI_ASSERT_ALWAYS( window && "Window handle is empty" );
68   BaseObject& object = window.GetBaseObject();
69   return static_cast<Internal::Adaptor::Window&>(object);
70 }
71
72 inline const Internal::Adaptor::Window& GetImplementation(const Dali::Window& window)
73 {
74   DALI_ASSERT_ALWAYS( window && "Window handle is empty" );
75   const BaseObject& object = window.GetBaseObject();
76   return static_cast<const Internal::Adaptor::Window&>(object);
77 }
78
79 Window::Window()
80 {
81 }
82
83 Window::~Window()
84 {
85 }
86
87 Window::Window(const Window& handle)
88 : BaseHandle( handle )
89 {
90 }
91
92 Window& Window::operator=(const Window& rhs)
93 {
94   BaseHandle::operator=(rhs);
95   return *this;
96 }
97
98 Dali::Window Window::New( PositionSize windowPosition, const std::string& name, bool isTransparent )
99 {
100   return New( windowPosition, name, "", isTransparent );
101 }
102
103 Dali::Window Window::New(PositionSize windowPosition, const std::string& name, const std::string& className, bool isTransparent )
104 {
105   Internal::Adaptor::Window* window = Internal::Adaptor::Window::New( windowPosition, name, className, isTransparent );
106
107   Dali::Window result( window );
108
109   // This will also emit the window created signals
110   AdaptorImpl::GetImpl( AdaptorImpl::Get() ).AddWindow( window );
111
112   return result;
113 }
114
115 Window::Window( Internal::Adaptor::Window* window )
116 : BaseHandle( window )
117 {
118 }
119
120 Integration::Scene Window::GetScene()
121 {
122   return GetImplementation( *this ).GetScene();
123 }
124
125 Integration::RenderSurface& Window::GetRenderSurface()
126 {
127   return GetImplementation( *this ).GetRenderSurface();
128 }
129
130 void Window::Add( Actor actor )
131 {
132   GetImplementation( *this ).Add( actor );
133 }
134
135 void Window::Remove( Actor actor )
136 {
137   GetImplementation( *this ).Remove( actor );
138 }
139
140 Dali::Layer Window::GetRootLayer() const
141 {
142   return GetImplementation( *this ).GetRootLayer();
143 }
144
145 void Window::SetBackgroundColor( const Vector4& color )
146 {
147   GetImplementation( *this ).SetBackgroundColor( color );
148 }
149
150 Vector4 Window::GetBackgroundColor() const
151 {
152   return GetImplementation( *this ).GetBackgroundColor();
153 }
154
155 void Window::Raise()
156 {
157   GetImplementation( *this ).mFocusChangeSignal.Emit(*this, true);
158 }
159
160 void Window::Hide()
161 {
162   GetImplementation( *this ).mVisibilityChangedSignal.Emit( *this, false );
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 ).GetScene().EventProcessingFinishedSignal();
198 }
199
200 KeyEventSignalType& KeyEventSignal( Window window )
201 {
202   return GetImplementation( window ).KeyEventSignal();
203 }
204
205 KeyEventGeneratedSignalType& KeyEventGeneratedSignal( Window window )
206 {
207   return GetImplementation( window ).KeyEventGeneratedSignal();
208 }
209
210 TouchSignalType& TouchSignal( Window window )
211 {
212   return GetImplementation( window ).TouchSignal();
213 }
214
215 WheelEventSignalType& WheelEventSignal( Window window )
216 {
217   return GetImplementation( window ).WheelEventSignal();
218 }
219
220 VisibilityChangedSignalType& VisibilityChangedSignal( Window window )
221 {
222   return GetImplementation( window ).mVisibilityChangedSignal;
223 }
224
225 } // namespace DevelWindow
226
227 } // Dali