2 * Copyright (c) 2019 Samsung Electronics Co., Ltd.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
19 #include "toolkit-window-impl.h"
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>
28 #include <dali/integration-api/adaptors/adaptor.h>
29 #include <toolkit-adaptor-impl.h>
32 #include "test-render-surface.h"
34 using AdaptorImpl = Dali::Internal::Adaptor::Adaptor;
41 /********************************************************************************
42 * Stub for Dali::Internal::Adaptor::Window
43 ********************************************************************************/
49 class Window : public Dali::BaseObject
53 Window( const PositionSize& positionSize )
54 : mRenderSurface( positionSize ),
55 mScene( Dali::Integration::Scene::New( mRenderSurface ) )
59 virtual ~Window() = default;
61 static Window* New(const PositionSize& positionSize, const std::string& name, const std::string& className, bool isTransparent)
63 return new Window( positionSize );
66 TestRenderSurface mRenderSurface;
67 Integration::Scene mScene;
73 inline Internal::Adaptor::Window& GetImplementation(Dali::Window& window)
75 DALI_ASSERT_ALWAYS( window && "Window handle is empty" );
76 BaseObject& object = window.GetBaseObject();
77 return static_cast<Internal::Adaptor::Window&>(object);
80 inline const Internal::Adaptor::Window& GetImplementation(const Dali::Window& window)
82 DALI_ASSERT_ALWAYS( window && "Window handle is empty" );
83 const BaseObject& object = window.GetBaseObject();
84 return static_cast<const Internal::Adaptor::Window&>(object);
95 Window::Window(const Window& handle)
96 : BaseHandle( handle )
100 Window& Window::operator=(const Window& rhs)
102 BaseHandle::operator=(rhs);
106 Dali::Window Window::New( PositionSize windowPosition, const std::string& name, bool isTransparent )
108 return New( windowPosition, name, "", isTransparent );
111 Dali::Window Window::New(PositionSize windowPosition, const std::string& name, const std::string& className, bool isTransparent )
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 );
120 Window::Window( Internal::Adaptor::Window* window )
121 : BaseHandle( window )
125 Integration::Scene Window::GetScene()
127 return GetImplementation( *this ).mScene;
130 Integration::RenderSurface& Window::GetRenderSurface()
132 return GetImplementation( *this ).mRenderSurface;
135 void Window::Add( Actor actor )
137 GetImplementation( *this ).Add( actor );
140 void Window::Remove( Actor actor )
142 GetImplementation( *this ).Remove( actor );
145 Dali::Layer Window::GetRootLayer() const
147 return GetImplementation( *this ).GetRootLayer();
150 void Window::SetBackgroundColor( const Vector4& color )
152 GetImplementation( *this ).SetBackgroundColor( color );
155 Vector4 Window::GetBackgroundColor() const
157 return GetImplementation( *this ).GetBackgroundColor();
162 GetImplementation( *this ).mFocusChangeSignal.Emit(*this, true);
165 FocusChangeSignalType& Window::FocusChangeSignal()
167 return GetImplementation( *this ).mFocusChangeSignal;
170 namespace DevelWindow
173 Window Get( Actor actor )
175 Internal::Adaptor::Window* windowImpl = nullptr;
177 if ( Dali::Adaptor::IsAvailable() )
179 windowImpl = static_cast<Internal::Adaptor::Window*>( AdaptorImpl::GetImpl( AdaptorImpl::Get() ).GetWindow( actor ) );
182 return Dali::Window( windowImpl );
185 Window DownCast( BaseHandle handle )
187 Internal::Adaptor::Window* windowImpl = nullptr;
188 if ( Dali::Adaptor::IsAvailable() )
190 windowImpl = dynamic_cast<Dali::Internal::Adaptor::Window*>( handle.GetObjectPtr());
192 return Dali::Window( windowImpl );
195 EventProcessingFinishedSignalType& EventProcessingFinishedSignal( Window window )
197 return GetImplementation( window ).mScene.EventProcessingFinishedSignal();
200 KeyEventSignalType& KeyEventSignal( Window window )
202 return GetImplementation( window ).mScene.KeyEventSignal();
205 KeyEventGeneratedSignalType& KeyEventGeneratedSignal( Window window )
207 return GetImplementation( window ).mScene.KeyEventGeneratedSignal();
210 TouchSignalType& TouchSignal( Window window )
212 return GetImplementation( window ).mScene.TouchSignal();
215 WheelEventSignalType& WheelEventSignal( Window window )
217 return GetImplementation( window ).mScene.WheelEventSignal();
220 } // namespace DevelWindow