2 * Copyright (c) 2022 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;
36 /********************************************************************************
37 * Stub for Dali::Internal::Adaptor::Window
38 ********************************************************************************/
44 Window::Window(const PositionSize& positionSize)
45 : SceneHolder(positionSize),
48 mRotationAngle(90), // dummy angle for test coverage
50 mVisibilityChangedSignal()
54 Window* Window::New(const PositionSize& positionSize, const std::string& name, const std::string& className, bool isTransparent)
56 return new Window(positionSize);
59 Dali::Window::WindowPosition Window::GetPosition() const
61 PositionSize positionSize = mRenderSurface.GetPositionSize();
63 return Dali::Window::WindowPosition(positionSize.x, positionSize.y);
66 PositionSize Window::GetPositionSize() const
68 return mRenderSurface.GetPositionSize();
71 Dali::Window::WindowSize Window::GetSize() const
73 PositionSize positionSize = mRenderSurface.GetPositionSize();
75 return Dali::Window::WindowSize(positionSize.width, positionSize.height);
78 void Window::SetPositionSize(PositionSize positionSize)
80 mRenderSurface.MoveResize(positionSize);
82 Uint16Pair newSize(positionSize.width, positionSize.height);
83 Dali::Window handle(this);
84 mResizeSignal.Emit(handle, newSize);
87 } // namespace Adaptor
88 } // namespace Internal
90 inline Internal::Adaptor::Window& GetImplementation(Dali::Window& window)
92 DALI_ASSERT_ALWAYS(window && "Window handle is empty");
93 BaseObject& object = window.GetBaseObject();
94 return static_cast<Internal::Adaptor::Window&>(object);
97 inline const Internal::Adaptor::Window& GetImplementation(const Dali::Window& window)
99 DALI_ASSERT_ALWAYS(window && "Window handle is empty");
100 const BaseObject& object = window.GetBaseObject();
101 return static_cast<const Internal::Adaptor::Window&>(object);
112 Window::Window(const Window& copy) = default;
114 Window& Window::operator=(const Window& rhs) = default;
116 Window::Window(Window&& rhs) = default;
118 Window& Window::operator=(Window&& rhs) = default;
120 Dali::Window Window::New(PositionSize windowPosition, const std::string& name, bool isTransparent)
122 return New(windowPosition, name, "", isTransparent);
125 Dali::Window Window::New(PositionSize windowPosition, const std::string& name, const std::string& className, bool isTransparent)
127 Internal::Adaptor::Window* window = Internal::Adaptor::Window::New(windowPosition, name, className, isTransparent);
129 Dali::Window result(window);
131 // This will also emit the window created signals
132 AdaptorImpl::GetImpl(AdaptorImpl::Get()).AddWindow(window);
137 Window Window::DownCast(BaseHandle handle)
139 Internal::Adaptor::Window* windowImpl = nullptr;
140 if(Dali::Adaptor::IsAvailable())
142 windowImpl = dynamic_cast<Dali::Internal::Adaptor::Window*>(handle.GetObjectPtr());
144 return Dali::Window(windowImpl);
147 Window::Window(Internal::Adaptor::Window* window)
152 Integration::Scene Window::GetScene()
154 return GetImplementation(*this).GetScene();
157 Dali::RenderSurfaceInterface& Window::GetRenderSurface()
159 return GetImplementation(*this).GetRenderSurface();
162 void Window::Add(Actor actor)
164 GetImplementation(*this).Add(actor);
167 void Window::Remove(Actor actor)
169 GetImplementation(*this).Remove(actor);
172 Dali::Layer Window::GetRootLayer() const
174 return GetImplementation(*this).GetRootLayer();
177 void Window::SetBackgroundColor(const Vector4& color)
179 GetImplementation(*this).SetBackgroundColor(color);
182 Vector4 Window::GetBackgroundColor() const
184 return GetImplementation(*this).GetBackgroundColor();
189 GetImplementation(*this).mFocusChangeSignal.Emit(*this, true);
194 GetImplementation(*this).mVisibilityChangedSignal.Emit(*this, false);
195 GetImplementation(*this).mVisible = false;
198 bool Window::IsVisible() const
200 return GetImplementation(*this).mVisible;
203 FocusChangeSignalType& Window::FocusChangeSignal()
205 return GetImplementation(*this).mFocusChangeSignal;
208 ResizeSignalType& Window::ResizeSignal()
210 return GetImplementation(*this).mResizeSignal;
213 Window::KeyEventSignalType& Window::KeyEventSignal()
215 return GetImplementation(*this).KeyEventSignal();
218 Window::TouchEventSignalType& Window::TouchedSignal()
220 return GetImplementation(*this).TouchedSignal();
223 namespace DevelWindow
225 Window Get(Actor actor)
227 Internal::Adaptor::Window* windowImpl = nullptr;
229 if(Dali::Adaptor::IsAvailable())
231 windowImpl = static_cast<Internal::Adaptor::Window*>(AdaptorImpl::GetImpl(AdaptorImpl::Get()).GetWindow(actor));
234 return Dali::Window(windowImpl);
237 void SetPositionSize(Window window, PositionSize positionSize)
239 GetImplementation(window).SetPositionSize(positionSize);
242 int GetPhysicalOrientation(Window window)
244 return GetImplementation(window).mRotationAngle;
247 void AddFrameRenderedCallback(Window window, std::unique_ptr<CallbackBase> callback, int32_t frameId)
249 CallbackBase::Execute(*callback, frameId);
252 void AddFramePresentedCallback(Window window, std::unique_ptr<CallbackBase> callback, int32_t frameId)
254 CallbackBase::Execute(*callback, frameId);
257 EventProcessingFinishedSignalType& EventProcessingFinishedSignal(Window window)
259 return GetImplementation(window).GetScene().EventProcessingFinishedSignal();
262 KeyEventGeneratedSignalType& KeyEventGeneratedSignal(Window window)
264 return GetImplementation(window).KeyEventGeneratedSignal();
267 WheelEventSignalType& WheelEventSignal(Window window)
269 return GetImplementation(window).WheelEventSignal();
272 WheelEventGeneratedSignalType& WheelEventGeneratedSignal(Window window)
274 return GetImplementation(window).WheelEventGeneratedSignal();
277 VisibilityChangedSignalType& VisibilityChangedSignal(Window window)
279 return GetImplementation(window).mVisibilityChangedSignal;
282 } // namespace DevelWindow