Merge "Fix InputMethodContext to work well in multi-window env" 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) 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.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 Window::Window()
81 {
82 }
83
84 Window::~Window()
85 {
86 }
87
88 Window::Window(const Window& handle)
89 : BaseHandle( handle )
90 {
91 }
92
93 Window& Window::operator=(const Window& rhs)
94 {
95   BaseHandle::operator=(rhs);
96   return *this;
97 }
98
99 Dali::Window Window::New( PositionSize windowPosition, const std::string& name, bool isTransparent )
100 {
101   return New( windowPosition, name, "", isTransparent );
102 }
103
104 Dali::Window Window::New(PositionSize windowPosition, const std::string& name, const std::string& className, bool isTransparent )
105 {
106   Internal::Adaptor::Window* window = Internal::Adaptor::Window::New( windowPosition, name, className, isTransparent );
107   Dali::Window newWindow = Window( window );
108   Dali::Adaptor::WindowCreatedSignalType& windowCreatedSignal = AdaptorImpl::Get().WindowCreatedSignal();
109   windowCreatedSignal.Emit( newWindow );
110   return Window( window );
111 }
112
113 Dali::Layer Window::GetRootLayer() const
114 {
115   return Dali::Stage::GetCurrent().GetRootLayer();
116 }
117
118 Window::Window( Internal::Adaptor::Window* window )
119 : BaseHandle( window )
120 {
121 }
122
123 Integration::Scene Window::GetScene()
124 {
125   return GetImplementation( *this ).mScene;
126 }
127
128 Integration::RenderSurface& Window::GetRenderSurface()
129 {
130   return GetImplementation( *this ).mRenderSurface;
131 }
132
133 namespace DevelWindow
134 {
135
136 Window Get( Actor actor )
137 {
138   return Window();
139 }
140
141 EventProcessingFinishedSignalType& EventProcessingFinishedSignal( Window window )
142 {
143   return GetImplementation( window ).mScene.EventProcessingFinishedSignal();
144 }
145
146 KeyEventSignalType& KeyEventSignal( Window window )
147 {
148   return GetImplementation( window ).mScene.KeyEventSignal();
149 }
150
151 KeyEventGeneratedSignalType& KeyEventGeneratedSignal( Window window )
152 {
153   return GetImplementation( window ).mScene.KeyEventGeneratedSignal();
154 }
155
156 TouchSignalType& TouchSignal( Window window )
157 {
158   return GetImplementation( window ).mScene.TouchSignal();
159 }
160
161 WheelEventSignalType& WheelEventSignal( Window window )
162 {
163   return GetImplementation( window ).mScene.WheelEventSignal();
164 }
165 } // namespace DevelWindow
166
167 } // Dali