Update toolkit-window to add/remove actors in the correct Scene
[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 {
53 }
54
55 Window* Window::New(const PositionSize& positionSize, const std::string& name, const std::string& className, bool isTransparent)
56 {
57   return new Window( positionSize );
58 }
59
60 } // Adaptor
61 } // Internal
62
63 inline Internal::Adaptor::Window& GetImplementation(Dali::Window& window)
64 {
65   DALI_ASSERT_ALWAYS( window && "Window handle is empty" );
66   BaseObject& object = window.GetBaseObject();
67   return static_cast<Internal::Adaptor::Window&>(object);
68 }
69
70 inline const Internal::Adaptor::Window& GetImplementation(const Dali::Window& window)
71 {
72   DALI_ASSERT_ALWAYS( window && "Window handle is empty" );
73   const BaseObject& object = window.GetBaseObject();
74   return static_cast<const Internal::Adaptor::Window&>(object);
75 }
76
77 Window::Window()
78 {
79 }
80
81 Window::~Window()
82 {
83 }
84
85 Window::Window(const Window& handle)
86 : BaseHandle( handle )
87 {
88 }
89
90 Window& Window::operator=(const Window& rhs)
91 {
92   BaseHandle::operator=(rhs);
93   return *this;
94 }
95
96 Dali::Window Window::New( PositionSize windowPosition, const std::string& name, bool isTransparent )
97 {
98   return New( windowPosition, name, "", isTransparent );
99 }
100
101 Dali::Window Window::New(PositionSize windowPosition, const std::string& name, const std::string& className, bool isTransparent )
102 {
103   Internal::Adaptor::Window* window = Internal::Adaptor::Window::New( windowPosition, name, className, isTransparent );
104
105   Dali::Window result( window );
106
107   // This will also emit the window created signals
108   AdaptorImpl::GetImpl( AdaptorImpl::Get() ).AddWindow( window );
109
110   return result;
111 }
112
113 Window::Window( Internal::Adaptor::Window* window )
114 : BaseHandle( window )
115 {
116 }
117
118 Integration::Scene Window::GetScene()
119 {
120   return GetImplementation( *this ).GetScene();
121 }
122
123 Integration::RenderSurface& Window::GetRenderSurface()
124 {
125   return GetImplementation( *this ).GetRenderSurface();
126 }
127
128 namespace DevelWindow
129 {
130
131 Window Get( Actor actor )
132 {
133   Internal::Adaptor::Window* windowImpl = nullptr;
134
135   if ( Dali::Adaptor::IsAvailable() )
136   {
137     windowImpl = static_cast<Internal::Adaptor::Window*>( AdaptorImpl::GetImpl( AdaptorImpl::Get() ).GetWindow( actor ) );
138   }
139
140   return Dali::Window( windowImpl );
141 }
142
143 EventProcessingFinishedSignalType& EventProcessingFinishedSignal( Window window )
144 {
145   return GetImplementation( window ).GetScene().EventProcessingFinishedSignal();
146 }
147
148 KeyEventSignalType& KeyEventSignal( Window window )
149 {
150   return GetImplementation( window ).KeyEventSignal();
151 }
152
153 KeyEventGeneratedSignalType& KeyEventGeneratedSignal( Window window )
154 {
155   return GetImplementation( window ).KeyEventGeneratedSignal();
156 }
157
158 TouchSignalType& TouchSignal( Window window )
159 {
160   return GetImplementation( window ).TouchSignal();
161 }
162
163 WheelEventSignalType& WheelEventSignal( Window window )
164 {
165   return GetImplementation( window ).WheelEventSignal();
166 }
167 } // namespace DevelWindow
168
169 } // Dali