2 * Copyright (c) 2020 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/object/base-object.h>
27 #include <dali/integration-api/adaptor-framework/adaptor.h>
28 #include <toolkit-adaptor-impl.h>
30 using AdaptorImpl = Dali::Internal::Adaptor::Adaptor;
37 /********************************************************************************
38 * Stub for Dali::Internal::Adaptor::Window
39 ********************************************************************************/
46 Window::Window( const PositionSize& positionSize )
47 : SceneHolder( positionSize ),
50 mRotationAngle(90), // dummy angle for test coverage
51 mVisibilityChangedSignal()
55 Window* Window::New(const PositionSize& positionSize, const std::string& name, const std::string& className, bool isTransparent)
57 return new Window( positionSize );
60 WindowPosition Window::GetPosition() const
62 PositionSize positionSize = mRenderSurface.GetPositionSize();
64 return WindowPosition(positionSize.x, positionSize.y);
67 PositionSize Window::GetPositionSize() const
69 return mRenderSurface.GetPositionSize();
72 Dali::Window::WindowSize Window::GetSize() const
74 PositionSize positionSize = mRenderSurface.GetPositionSize();
76 return Dali::Window::WindowSize(positionSize.width, positionSize.height);
79 void Window::SetPositionSize(PositionSize positionSize)
81 mRenderSurface.MoveResize(positionSize);
83 Uint16Pair newSize(positionSize.width, positionSize.height);
84 Dali::Window handle(this);
85 mResizeSignal.Emit(handle, newSize);
91 inline Internal::Adaptor::Window& GetImplementation(Dali::Window& window)
93 DALI_ASSERT_ALWAYS( window && "Window handle is empty" );
94 BaseObject& object = window.GetBaseObject();
95 return static_cast<Internal::Adaptor::Window&>(object);
98 inline const Internal::Adaptor::Window& GetImplementation(const Dali::Window& window)
100 DALI_ASSERT_ALWAYS( window && "Window handle is empty" );
101 const BaseObject& object = window.GetBaseObject();
102 return static_cast<const Internal::Adaptor::Window&>(object);
113 Window::Window( const Window& copy ) = default;
115 Window& Window::operator=( const Window& rhs ) = default;
117 Window::Window( Window&& rhs ) = default;
119 Window& Window::operator=( Window&& rhs ) = default;
121 Dali::Window Window::New( PositionSize windowPosition, const std::string& name, bool isTransparent )
123 return New( windowPosition, name, "", isTransparent );
126 Dali::Window Window::New(PositionSize windowPosition, const std::string& name, const std::string& className, bool isTransparent )
128 Internal::Adaptor::Window* window = Internal::Adaptor::Window::New( windowPosition, name, className, isTransparent );
130 Dali::Window result( window );
132 // This will also emit the window created signals
133 AdaptorImpl::GetImpl( AdaptorImpl::Get() ).AddWindow( window );
138 Window::Window( Internal::Adaptor::Window* window )
139 : BaseHandle( window )
143 Integration::Scene Window::GetScene()
145 return GetImplementation( *this ).GetScene();
148 Dali::RenderSurfaceInterface& Window::GetRenderSurface()
150 return GetImplementation( *this ).GetRenderSurface();
153 void Window::Add( Actor actor )
155 GetImplementation( *this ).Add( actor );
158 void Window::Remove( Actor actor )
160 GetImplementation( *this ).Remove( actor );
163 Dali::Layer Window::GetRootLayer() const
165 return GetImplementation( *this ).GetRootLayer();
168 void Window::SetBackgroundColor( const Vector4& color )
170 GetImplementation( *this ).SetBackgroundColor( color );
173 Vector4 Window::GetBackgroundColor() const
175 return GetImplementation( *this ).GetBackgroundColor();
180 GetImplementation( *this ).mFocusChangeSignal.Emit(*this, true);
185 GetImplementation( *this ).mVisibilityChangedSignal.Emit( *this, false );
188 FocusChangeSignalType& Window::FocusChangeSignal()
190 return GetImplementation( *this ).mFocusChangeSignal;
193 ResizeSignalType& Window::ResizeSignal()
195 return GetImplementation( *this ).mResizeSignal;
198 Window::KeyEventSignalType& Window::KeyEventSignal()
200 return GetImplementation( *this ).KeyEventSignal();
203 Window::TouchEventSignalType& Window::TouchedSignal()
205 return GetImplementation( *this ).TouchedSignal();
208 namespace DevelWindow
211 Window Get( Actor actor )
213 Internal::Adaptor::Window* windowImpl = nullptr;
215 if ( Dali::Adaptor::IsAvailable() )
217 windowImpl = static_cast<Internal::Adaptor::Window*>( AdaptorImpl::GetImpl( AdaptorImpl::Get() ).GetWindow( actor ) );
220 return Dali::Window( windowImpl );
223 Window DownCast( BaseHandle handle )
225 Internal::Adaptor::Window* windowImpl = nullptr;
226 if ( Dali::Adaptor::IsAvailable() )
228 windowImpl = dynamic_cast<Dali::Internal::Adaptor::Window*>( handle.GetObjectPtr());
230 return Dali::Window( windowImpl );
233 void SetPositionSize(Window window, PositionSize positionSize)
235 GetImplementation( window ).SetPositionSize(positionSize);
238 int GetPhysicalOrientation(Window window)
240 return GetImplementation( window ).mRotationAngle;
243 void AddFrameRenderedCallback( Window window, std::unique_ptr< CallbackBase > callback, int32_t frameId )
245 CallbackBase::Execute( *callback, frameId );
248 void AddFramePresentedCallback( Window window, std::unique_ptr< CallbackBase > callback, int32_t frameId )
250 CallbackBase::Execute( *callback, frameId );
253 EventProcessingFinishedSignalType& EventProcessingFinishedSignal( Window window )
255 return GetImplementation( window ).GetScene().EventProcessingFinishedSignal();
258 KeyEventGeneratedSignalType& KeyEventGeneratedSignal( Window window )
260 return GetImplementation( window ).KeyEventGeneratedSignal();
263 WheelEventSignalType& WheelEventSignal( Window window )
265 return GetImplementation( window ).WheelEventSignal();
268 VisibilityChangedSignalType& VisibilityChangedSignal( Window window )
270 return GetImplementation( window ).mVisibilityChangedSignal;
273 } // namespace DevelWindow