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 );
63 inline Internal::Adaptor::Window& GetImplementation(Dali::Window& window)
65 DALI_ASSERT_ALWAYS( window && "Window handle is empty" );
66 BaseObject& object = window.GetBaseObject();
67 return static_cast<Internal::Adaptor::Window&>(object);
70 inline const Internal::Adaptor::Window& GetImplementation(const Dali::Window& window)
72 DALI_ASSERT_ALWAYS( window && "Window handle is empty" );
73 const BaseObject& object = window.GetBaseObject();
74 return static_cast<const Internal::Adaptor::Window&>(object);
85 Window::Window( const Window& copy ) = default;
87 Window& Window::operator=( const Window& rhs ) = default;
89 Window::Window( Window&& rhs ) = default;
91 Window& Window::operator=( Window&& rhs ) = default;
93 Dali::Window Window::New( PositionSize windowPosition, const std::string& name, bool isTransparent )
95 return New( windowPosition, name, "", isTransparent );
98 Dali::Window Window::New(PositionSize windowPosition, const std::string& name, const std::string& className, bool isTransparent )
100 Internal::Adaptor::Window* window = Internal::Adaptor::Window::New( windowPosition, name, className, isTransparent );
102 Dali::Window result( window );
104 // This will also emit the window created signals
105 AdaptorImpl::GetImpl( AdaptorImpl::Get() ).AddWindow( window );
110 Window::Window( Internal::Adaptor::Window* window )
111 : BaseHandle( window )
115 Integration::Scene Window::GetScene()
117 return GetImplementation( *this ).GetScene();
120 Dali::RenderSurfaceInterface& Window::GetRenderSurface()
122 return GetImplementation( *this ).GetRenderSurface();
125 void Window::Add( Actor actor )
127 GetImplementation( *this ).Add( actor );
130 void Window::Remove( Actor actor )
132 GetImplementation( *this ).Remove( actor );
135 Dali::Layer Window::GetRootLayer() const
137 return GetImplementation( *this ).GetRootLayer();
140 void Window::SetBackgroundColor( const Vector4& color )
142 GetImplementation( *this ).SetBackgroundColor( color );
145 Vector4 Window::GetBackgroundColor() const
147 return GetImplementation( *this ).GetBackgroundColor();
152 GetImplementation( *this ).mFocusChangeSignal.Emit(*this, true);
157 GetImplementation( *this ).mVisibilityChangedSignal.Emit( *this, false );
160 FocusChangeSignalType& Window::FocusChangeSignal()
162 return GetImplementation( *this ).mFocusChangeSignal;
165 ResizeSignalType& Window::ResizeSignal()
167 return GetImplementation( *this ).mResizeSignal;
170 Window::KeyEventSignalType& Window::KeyEventSignal()
172 return GetImplementation( *this ).KeyEventSignal();
175 Window::TouchEventSignalType& Window::TouchedSignal()
177 return GetImplementation( *this ).TouchedSignal();
180 namespace DevelWindow
183 Window Get( Actor actor )
185 Internal::Adaptor::Window* windowImpl = nullptr;
187 if ( Dali::Adaptor::IsAvailable() )
189 windowImpl = static_cast<Internal::Adaptor::Window*>( AdaptorImpl::GetImpl( AdaptorImpl::Get() ).GetWindow( actor ) );
192 return Dali::Window( windowImpl );
195 Window DownCast( BaseHandle handle )
197 Internal::Adaptor::Window* windowImpl = nullptr;
198 if ( Dali::Adaptor::IsAvailable() )
200 windowImpl = dynamic_cast<Dali::Internal::Adaptor::Window*>( handle.GetObjectPtr());
202 return Dali::Window( windowImpl );
205 void SetPositionSize(Window window, PositionSize positionSize)
207 Uint16Pair newSize(positionSize.width, positionSize.height);
208 GetImplementation( window ).mResizeSignal.Emit(window,newSize);
211 int GetPhysicalOrientation(Window window)
213 return GetImplementation( window ).mRotationAngle;
216 void AddFrameRenderedCallback( Window window, std::unique_ptr< CallbackBase > callback, int32_t frameId )
218 CallbackBase::Execute( *callback, frameId );
221 void AddFramePresentedCallback( Window window, std::unique_ptr< CallbackBase > callback, int32_t frameId )
223 CallbackBase::Execute( *callback, frameId );
226 EventProcessingFinishedSignalType& EventProcessingFinishedSignal( Window window )
228 return GetImplementation( window ).GetScene().EventProcessingFinishedSignal();
231 KeyEventGeneratedSignalType& KeyEventGeneratedSignal( Window window )
233 return GetImplementation( window ).KeyEventGeneratedSignal();
236 WheelEventSignalType& WheelEventSignal( Window window )
238 return GetImplementation( window ).WheelEventSignal();
241 VisibilityChangedSignalType& VisibilityChangedSignal( Window window )
243 return GetImplementation( window ).mVisibilityChangedSignal;
246 } // namespace DevelWindow