Merge "(Visual) Support CORNER_RADIUS_POLICY" 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& handle)
84 : BaseHandle( handle )
85 {
86 }
87
88 Window& Window::operator=(const Window& rhs)
89 {
90   BaseHandle::operator=(rhs);
91   return *this;
92 }
93
94 Dali::Window Window::New( PositionSize windowPosition, const std::string& name, bool isTransparent )
95 {
96   return New( windowPosition, name, "", isTransparent );
97 }
98
99 Dali::Window Window::New(PositionSize windowPosition, const std::string& name, const std::string& className, bool isTransparent )
100 {
101   Internal::Adaptor::Window* window = Internal::Adaptor::Window::New( windowPosition, name, className, isTransparent );
102
103   Dali::Window result( window );
104
105   // This will also emit the window created signals
106   AdaptorImpl::GetImpl( AdaptorImpl::Get() ).AddWindow( window );
107
108   return result;
109 }
110
111 Window::Window( Internal::Adaptor::Window* window )
112 : BaseHandle( window )
113 {
114 }
115
116 Integration::Scene Window::GetScene()
117 {
118   return GetImplementation( *this ).GetScene();
119 }
120
121 Dali::RenderSurfaceInterface& Window::GetRenderSurface()
122 {
123   return GetImplementation( *this ).GetRenderSurface();
124 }
125
126 void Window::Add( Actor actor )
127 {
128   GetImplementation( *this ).Add( actor );
129 }
130
131 void Window::Remove( Actor actor )
132 {
133   GetImplementation( *this ).Remove( actor );
134 }
135
136 Dali::Layer Window::GetRootLayer() const
137 {
138   return GetImplementation( *this ).GetRootLayer();
139 }
140
141 void Window::SetBackgroundColor( const Vector4& color )
142 {
143   GetImplementation( *this ).SetBackgroundColor( color );
144 }
145
146 Vector4 Window::GetBackgroundColor() const
147 {
148   return GetImplementation( *this ).GetBackgroundColor();
149 }
150
151 void Window::Raise()
152 {
153   GetImplementation( *this ).mFocusChangeSignal.Emit(*this, true);
154 }
155
156 void Window::Hide()
157 {
158   GetImplementation( *this ).mVisibilityChangedSignal.Emit( *this, false );
159 }
160
161 FocusChangeSignalType& Window::FocusChangeSignal()
162 {
163   return GetImplementation( *this ).mFocusChangeSignal;
164 }
165
166 Window::KeyEventSignalType& Window::KeyEventSignal()
167 {
168   return GetImplementation( *this ).KeyEventSignal();
169 }
170
171 Window::TouchSignalType& Window::TouchSignal()
172 {
173   return GetImplementation( *this ).TouchSignal();
174 }
175
176 namespace DevelWindow
177 {
178
179 Window Get( Actor actor )
180 {
181   Internal::Adaptor::Window* windowImpl = nullptr;
182
183   if ( Dali::Adaptor::IsAvailable() )
184   {
185     windowImpl = static_cast<Internal::Adaptor::Window*>( AdaptorImpl::GetImpl( AdaptorImpl::Get() ).GetWindow( actor ) );
186   }
187
188   return Dali::Window( windowImpl );
189 }
190
191 Window DownCast( BaseHandle handle )
192 {
193   Internal::Adaptor::Window* windowImpl = nullptr;
194   if ( Dali::Adaptor::IsAvailable() )
195   {
196     windowImpl = dynamic_cast<Dali::Internal::Adaptor::Window*>( handle.GetObjectPtr());
197   }
198   return Dali::Window( windowImpl );
199 }
200
201 EventProcessingFinishedSignalType& EventProcessingFinishedSignal( Window window )
202 {
203   return GetImplementation( window ).GetScene().EventProcessingFinishedSignal();
204 }
205
206 KeyEventGeneratedSignalType& KeyEventGeneratedSignal( Window window )
207 {
208   return GetImplementation( window ).KeyEventGeneratedSignal();
209 }
210
211 WheelEventSignalType& WheelEventSignal( Window window )
212 {
213   return GetImplementation( window ).WheelEventSignal();
214 }
215
216 VisibilityChangedSignalType& VisibilityChangedSignal( Window window )
217 {
218   return GetImplementation( window ).mVisibilityChangedSignal;
219 }
220
221 } // namespace DevelWindow
222
223 } // Dali