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 void Window::SetPositionSize(PositionSize positionSize)
74 mRenderSurface.MoveResize(positionSize);
76 Uint16Pair newSize(positionSize.width, positionSize.height);
77 Dali::Window handle(this);
78 mResizeSignal.Emit(handle, newSize);
84 inline Internal::Adaptor::Window& GetImplementation(Dali::Window& window)
86 DALI_ASSERT_ALWAYS( window && "Window handle is empty" );
87 BaseObject& object = window.GetBaseObject();
88 return static_cast<Internal::Adaptor::Window&>(object);
91 inline const Internal::Adaptor::Window& GetImplementation(const Dali::Window& window)
93 DALI_ASSERT_ALWAYS( window && "Window handle is empty" );
94 const BaseObject& object = window.GetBaseObject();
95 return static_cast<const Internal::Adaptor::Window&>(object);
106 Window::Window( const Window& copy ) = default;
108 Window& Window::operator=( const Window& rhs ) = default;
110 Window::Window( Window&& rhs ) = default;
112 Window& Window::operator=( Window&& rhs ) = default;
114 Dali::Window Window::New( PositionSize windowPosition, const std::string& name, bool isTransparent )
116 return New( windowPosition, name, "", isTransparent );
119 Dali::Window Window::New(PositionSize windowPosition, const std::string& name, const std::string& className, bool isTransparent )
121 Internal::Adaptor::Window* window = Internal::Adaptor::Window::New( windowPosition, name, className, isTransparent );
123 Dali::Window result( window );
125 // This will also emit the window created signals
126 AdaptorImpl::GetImpl( AdaptorImpl::Get() ).AddWindow( window );
131 Window::Window( Internal::Adaptor::Window* window )
132 : BaseHandle( window )
136 Integration::Scene Window::GetScene()
138 return GetImplementation( *this ).GetScene();
141 Dali::RenderSurfaceInterface& Window::GetRenderSurface()
143 return GetImplementation( *this ).GetRenderSurface();
146 void Window::Add( Actor actor )
148 GetImplementation( *this ).Add( actor );
151 void Window::Remove( Actor actor )
153 GetImplementation( *this ).Remove( actor );
156 Dali::Layer Window::GetRootLayer() const
158 return GetImplementation( *this ).GetRootLayer();
161 void Window::SetBackgroundColor( const Vector4& color )
163 GetImplementation( *this ).SetBackgroundColor( color );
166 Vector4 Window::GetBackgroundColor() const
168 return GetImplementation( *this ).GetBackgroundColor();
173 GetImplementation( *this ).mFocusChangeSignal.Emit(*this, true);
178 GetImplementation( *this ).mVisibilityChangedSignal.Emit( *this, false );
181 FocusChangeSignalType& Window::FocusChangeSignal()
183 return GetImplementation( *this ).mFocusChangeSignal;
186 ResizeSignalType& Window::ResizeSignal()
188 return GetImplementation( *this ).mResizeSignal;
191 Window::KeyEventSignalType& Window::KeyEventSignal()
193 return GetImplementation( *this ).KeyEventSignal();
196 Window::TouchEventSignalType& Window::TouchedSignal()
198 return GetImplementation( *this ).TouchedSignal();
201 namespace DevelWindow
204 Window Get( Actor actor )
206 Internal::Adaptor::Window* windowImpl = nullptr;
208 if ( Dali::Adaptor::IsAvailable() )
210 windowImpl = static_cast<Internal::Adaptor::Window*>( AdaptorImpl::GetImpl( AdaptorImpl::Get() ).GetWindow( actor ) );
213 return Dali::Window( windowImpl );
216 Window DownCast( BaseHandle handle )
218 Internal::Adaptor::Window* windowImpl = nullptr;
219 if ( Dali::Adaptor::IsAvailable() )
221 windowImpl = dynamic_cast<Dali::Internal::Adaptor::Window*>( handle.GetObjectPtr());
223 return Dali::Window( windowImpl );
226 void SetPositionSize(Window window, PositionSize positionSize)
228 GetImplementation( window ).SetPositionSize(positionSize);
231 int GetPhysicalOrientation(Window window)
233 return GetImplementation( window ).mRotationAngle;
236 void AddFrameRenderedCallback( Window window, std::unique_ptr< CallbackBase > callback, int32_t frameId )
238 CallbackBase::Execute( *callback, frameId );
241 void AddFramePresentedCallback( Window window, std::unique_ptr< CallbackBase > callback, int32_t frameId )
243 CallbackBase::Execute( *callback, frameId );
246 EventProcessingFinishedSignalType& EventProcessingFinishedSignal( Window window )
248 return GetImplementation( window ).GetScene().EventProcessingFinishedSignal();
251 KeyEventGeneratedSignalType& KeyEventGeneratedSignal( Window window )
253 return GetImplementation( window ).KeyEventGeneratedSignal();
256 WheelEventSignalType& WheelEventSignal( Window window )
258 return GetImplementation( window ).WheelEventSignal();
261 VisibilityChangedSignalType& VisibilityChangedSignal( Window window )
263 return GetImplementation( window ).mVisibilityChangedSignal;
266 } // namespace DevelWindow