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
52 mVisibilityChangedSignal()
56 Window* Window::New(const PositionSize& positionSize, const std::string& name, const std::string& className, bool isTransparent)
58 return new Window( positionSize );
61 WindowPosition Window::GetPosition() const
63 PositionSize positionSize = mRenderSurface.GetPositionSize();
65 return WindowPosition(positionSize.x, positionSize.y);
68 PositionSize Window::GetPositionSize() const
70 return mRenderSurface.GetPositionSize();
73 Dali::Window::WindowSize Window::GetSize() const
75 PositionSize positionSize = mRenderSurface.GetPositionSize();
77 return Dali::Window::WindowSize(positionSize.width, positionSize.height);
80 void Window::SetPositionSize(PositionSize positionSize)
82 mRenderSurface.MoveResize(positionSize);
84 Uint16Pair newSize(positionSize.width, positionSize.height);
85 Dali::Window handle(this);
86 mResizeSignal.Emit(handle, newSize);
92 inline Internal::Adaptor::Window& GetImplementation(Dali::Window& window)
94 DALI_ASSERT_ALWAYS( window && "Window handle is empty" );
95 BaseObject& object = window.GetBaseObject();
96 return static_cast<Internal::Adaptor::Window&>(object);
99 inline const Internal::Adaptor::Window& GetImplementation(const Dali::Window& window)
101 DALI_ASSERT_ALWAYS( window && "Window handle is empty" );
102 const BaseObject& object = window.GetBaseObject();
103 return static_cast<const Internal::Adaptor::Window&>(object);
114 Window::Window( const Window& copy ) = default;
116 Window& Window::operator=( const Window& rhs ) = default;
118 Window::Window( Window&& rhs ) = default;
120 Window& Window::operator=( Window&& rhs ) = default;
122 Dali::Window Window::New( PositionSize windowPosition, const std::string& name, bool isTransparent )
124 return New( windowPosition, name, "", isTransparent );
127 Dali::Window Window::New(PositionSize windowPosition, const std::string& name, const std::string& className, bool isTransparent )
129 Internal::Adaptor::Window* window = Internal::Adaptor::Window::New( windowPosition, name, className, isTransparent );
131 Dali::Window result( window );
133 // This will also emit the window created signals
134 AdaptorImpl::GetImpl( AdaptorImpl::Get() ).AddWindow( window );
139 Window::Window( Internal::Adaptor::Window* window )
140 : BaseHandle( window )
144 Integration::Scene Window::GetScene()
146 return GetImplementation( *this ).GetScene();
149 Dali::RenderSurfaceInterface& Window::GetRenderSurface()
151 return GetImplementation( *this ).GetRenderSurface();
154 void Window::Add( Actor actor )
156 GetImplementation( *this ).Add( actor );
159 void Window::Remove( Actor actor )
161 GetImplementation( *this ).Remove( actor );
164 Dali::Layer Window::GetRootLayer() const
166 return GetImplementation( *this ).GetRootLayer();
169 void Window::SetBackgroundColor( const Vector4& color )
171 GetImplementation( *this ).SetBackgroundColor( color );
174 Vector4 Window::GetBackgroundColor() const
176 return GetImplementation( *this ).GetBackgroundColor();
181 GetImplementation( *this ).mFocusChangeSignal.Emit(*this, true);
186 GetImplementation( *this ).mVisibilityChangedSignal.Emit( *this, false );
187 GetImplementation( *this ).mVisible = false;
190 bool Window::IsVisible() const
192 return GetImplementation( *this ).mVisible;
195 FocusChangeSignalType& Window::FocusChangeSignal()
197 return GetImplementation( *this ).mFocusChangeSignal;
200 ResizeSignalType& Window::ResizeSignal()
202 return GetImplementation( *this ).mResizeSignal;
205 Window::KeyEventSignalType& Window::KeyEventSignal()
207 return GetImplementation( *this ).KeyEventSignal();
210 Window::TouchEventSignalType& Window::TouchedSignal()
212 return GetImplementation( *this ).TouchedSignal();
215 namespace DevelWindow
218 Window Get( Actor actor )
220 Internal::Adaptor::Window* windowImpl = nullptr;
222 if ( Dali::Adaptor::IsAvailable() )
224 windowImpl = static_cast<Internal::Adaptor::Window*>( AdaptorImpl::GetImpl( AdaptorImpl::Get() ).GetWindow( actor ) );
227 return Dali::Window( windowImpl );
230 Window DownCast( BaseHandle handle )
232 Internal::Adaptor::Window* windowImpl = nullptr;
233 if ( Dali::Adaptor::IsAvailable() )
235 windowImpl = dynamic_cast<Dali::Internal::Adaptor::Window*>( handle.GetObjectPtr());
237 return Dali::Window( windowImpl );
240 void SetPositionSize(Window window, PositionSize positionSize)
242 GetImplementation( window ).SetPositionSize(positionSize);
245 int GetPhysicalOrientation(Window window)
247 return GetImplementation( window ).mRotationAngle;
250 void AddFrameRenderedCallback( Window window, std::unique_ptr< CallbackBase > callback, int32_t frameId )
252 CallbackBase::Execute( *callback, frameId );
255 void AddFramePresentedCallback( Window window, std::unique_ptr< CallbackBase > callback, int32_t frameId )
257 CallbackBase::Execute( *callback, frameId );
260 EventProcessingFinishedSignalType& EventProcessingFinishedSignal( Window window )
262 return GetImplementation( window ).GetScene().EventProcessingFinishedSignal();
265 KeyEventGeneratedSignalType& KeyEventGeneratedSignal( Window window )
267 return GetImplementation( window ).KeyEventGeneratedSignal();
270 WheelEventSignalType& WheelEventSignal( Window window )
272 return GetImplementation( window ).WheelEventSignal();
275 WheelEventGeneratedSignalType& WheelEventGeneratedSignal( Window window )
277 return GetImplementation( window ).WheelEventGeneratedSignal();
280 VisibilityChangedSignalType& VisibilityChangedSignal( Window window )
282 return GetImplementation( window ).mVisibilityChangedSignal;
285 } // namespace DevelWindow