1 #ifndef DALI_INTERNAL_WINDOWSYSTEM_COMMON_WINDOW_IMPL_H
2 #define DALI_INTERNAL_WINDOWSYSTEM_COMMON_WINDOW_IMPL_H
5 * Copyright (c) 2021 Samsung Electronics Co., Ltd.
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
22 #include <dali/public-api/actors/layer.h>
23 #include <dali/public-api/adaptor-framework/window-enumerations.h>
24 #include <dali/public-api/object/base-object.h>
25 #include <dali/public-api/object/property-array.h>
26 #include <dali/public-api/object/ref-object.h>
27 #include <dali/public-api/render-tasks/render-task-list.h>
30 #include <dali/devel-api/adaptor-framework/window-devel.h>
31 #include <dali/integration-api/adaptor-framework/scene-holder-impl.h>
32 #include <dali/internal/adaptor/common/adaptor-impl.h>
33 #include <dali/internal/window-system/common/event-handler.h>
34 #include <dali/public-api/adaptor-framework/key-grab.h>
35 #include <dali/public-api/adaptor-framework/window.h>
41 class RenderSurfaceInterface;
48 class WindowRenderSurface;
52 using WindowPtr = IntrusivePtr<Window>;
53 using OrientationPtr = IntrusivePtr<Orientation>;
54 using EventHandlerPtr = IntrusivePtr<EventHandler>;
57 * Window provides a surface to render onto with orientation & indicator properties.
59 class Window : public Dali::Internal::Adaptor::SceneHolder, public EventHandler::Observer, public ConnectionTracker
62 typedef Dali::Window::FocusChangeSignalType FocusChangeSignalType;
63 typedef Dali::Window::ResizeSignalType ResizeSignalType;
64 typedef Dali::DevelWindow::VisibilityChangedSignalType VisibilityChangedSignalType;
65 typedef Dali::DevelWindow::TransitionEffectEventSignalType TransitionEffectEventSignalType;
66 typedef Dali::DevelWindow::KeyboardRepeatSettingsChangedSignalType KeyboardRepeatSettingsChangedSignalType;
67 typedef Signal<void()> SignalType;
70 * @brief Create a new Window. This should only be called once by the Application class
71 * @param[in] positionSize The position and size of the window
72 * @param[in] name The window title
73 * @param[in] className The window class name
74 * @param[in] isTransparent Whether window is transparent
75 * @return A newly allocated Window
77 static Window* New(const PositionSize& positionSize, const std::string& name, const std::string& className, bool isTransparent = false);
80 * @brief Create a new Window. This should only be called once by the Application class
81 * @param[in] surface The surface used to render on.
82 * @param[in] positionSize The position and size of the window
83 * @param[in] name The window title
84 * @param[in] className The window class name
85 * @param[in] isTransparent Whether window is transparent
86 * @return A newly allocated Window
88 static Window* New(Any surface, const PositionSize& positionSize, const std::string& name, const std::string& className, bool isTransparent = false);
91 * @copydoc Dali::Window::SetClass()
93 void SetClass(std::string name, std::string className);
96 * @brief Gets the window class name.
97 * @return The class of the window
99 std::string GetClassName() const;
102 * @copydoc Dali::Window::Raise()
107 * @copydoc Dali::Window::Lower()
112 * @copydoc Dali::Window::Activate()
117 * @copydoc Dali::Window::GetLayerCount()
119 uint32_t GetLayerCount() const;
122 * @copydoc Dali::Window::GetLayer()
124 Dali::Layer GetLayer(uint32_t depth) const;
127 * @copydoc Dali::DevelWindow::GetRenderTaskList()
129 Dali::RenderTaskList GetRenderTaskList() const;
132 * @copydoc Dali::Window::AddAvailableOrientation()
134 void AddAvailableOrientation(WindowOrientation orientation);
137 * @copydoc Dali::Window::RemoveAvailableOrientation()
139 void RemoveAvailableOrientation(WindowOrientation orientation);
142 * @copydoc Dali::Window::SetPreferredOrientation()
144 void SetPreferredOrientation(WindowOrientation orientation);
147 * @copydoc Dali::Window::GetPreferredOrientation()
149 WindowOrientation GetPreferredOrientation();
152 * @copydoc Dali::Window::SetAcceptFocus()
154 void SetAcceptFocus(bool accept);
157 * @copydoc Dali::Window::IsFocusAcceptable()
159 bool IsFocusAcceptable() const;
162 * @copydoc Dali::Window::Show()
167 * @copydoc Dali::Window::Hide()
172 * @copydoc Dali::Window::GetSupportedAuxiliaryHintCount()
174 unsigned int GetSupportedAuxiliaryHintCount() const;
177 * @copydoc Dali::Window::GetSupportedAuxiliaryHint()
179 std::string GetSupportedAuxiliaryHint(unsigned int index) const;
182 * @copydoc Dali::Window::AddAuxiliaryHint()
184 unsigned int AddAuxiliaryHint(const std::string& hint, const std::string& value);
187 * @copydoc Dali::Window::RemoveAuxiliaryHint()
189 bool RemoveAuxiliaryHint(unsigned int id);
192 * @copydoc Dali::Window::SetAuxiliaryHintValue()
194 bool SetAuxiliaryHintValue(unsigned int id, const std::string& value);
197 * @copydoc Dali::Window::GetAuxiliaryHintValue()
199 std::string GetAuxiliaryHintValue(unsigned int id) const;
202 * @copydoc Dali::Window::GetAuxiliaryHintId()
204 unsigned int GetAuxiliaryHintId(const std::string& hint) const;
207 * @copydoc Dali::Window::SetInputRegion()
209 void SetInputRegion(const Rect<int>& inputRegion);
212 * @copydoc Dali::Window::SetType()
214 void SetType(WindowType type);
217 * @copydoc Dali::Window::GetType() const
219 WindowType GetType() const;
222 * @copydoc Dali::Window::SetNotificationLevel()
224 bool SetNotificationLevel(WindowNotificationLevel level);
227 * @copydoc Dali::Window::GetNotificationLevel()
229 WindowNotificationLevel GetNotificationLevel() const;
232 * @copydoc Dali::Window::SetOpaqueState()
234 void SetOpaqueState(bool opaque);
237 * @copydoc Dali::Window::IsOpaqueState()
239 bool IsOpaqueState() const;
242 * @copydoc Dali::Window::SetScreenOffMode()
244 bool SetScreenOffMode(WindowScreenOffMode screenOffMode);
247 * @copydoc Dali::Window::GetScreenOffMode()
249 WindowScreenOffMode GetScreenOffMode() const;
252 * @copydoc Dali::Window::SetBrightness()
254 bool SetBrightness(int brightness);
257 * @copydoc Dali::Window::GetBrightness()
259 int GetBrightness() const;
262 * @copydoc Dali::Window::SetSize()
264 void SetSize(Dali::Window::WindowSize size);
267 * @copydoc Dali::Window::GetSize()
269 Dali::Window::WindowSize GetSize() const;
272 * @copydoc Dali::Window::SetPosition()
274 void SetPosition(Dali::Window::WindowPosition position);
277 * @copydoc Dali::Window::GetPosition()
279 Dali::Window::WindowPosition GetPosition() const;
282 * @copydoc Dali::DevelWindow::SetPositionSize()
284 void SetPositionSize(PositionSize positionSize);
287 * @copydoc Dali::Window::GetRootLayer()
289 Dali::Layer GetRootLayer() const;
292 * @copydoc Dali::Window::SetTransparency()
294 void SetTransparency(bool transparent);
297 * @copydoc Dali::KeyGrab::GrabKey()
299 bool GrabKey(Dali::KEY key, KeyGrab::KeyGrabMode grabMode);
302 * @copydoc Dali::KeyGrab::UngrabKey()
304 bool UngrabKey(Dali::KEY key);
307 * @copydoc Dali::KeyGrab::GrabKeyList()
309 bool GrabKeyList(const Dali::Vector<Dali::KEY>& key, const Dali::Vector<KeyGrab::KeyGrabMode>& grabMode, Dali::Vector<bool>& result);
312 * @copydoc Dali::KeyGrab::UngrabKeyList()
314 bool UngrabKeyList(const Dali::Vector<Dali::KEY>& key, Dali::Vector<bool>& result);
317 * @copydoc Dali::DevelWindow::Get()
319 static Dali::Window Get(Dali::Actor actor);
322 * @copydoc Dali::DevelWindow::SetParent()
324 void SetParent(Dali::Window& parent);
327 * @copydoc Dali::DevelWindow::Unparent()
332 * @copydoc Dali::DevelWindow::GetParent()
334 Dali::Window GetParent();
337 * @copydoc Dali::DevelWindow::GetCurrentOrientation()
339 WindowOrientation GetCurrentOrientation() const;
342 * @copydoc Dali::DevelWindow::GetPhysicalOrientation()
344 int GetPhysicalOrientation() const;
347 * @copydoc Dali::DevelWindow::SetAvailableOrientations()
349 void SetAvailableOrientations(const Dali::Vector<WindowOrientation>& orientations);
351 public: // Dali::Internal::Adaptor::SceneHolder
353 * @copydoc Dali::Internal::Adaptor::SceneHolder::GetNativeHandle
355 Dali::Any GetNativeHandle() const override;
358 * @copydoc Dali::Internal::Adaptor::SceneHolder::IsVisible
360 bool IsVisible() const override;
363 * @copydoc Dali::DevelWindow::GetNativeId()
365 int32_t GetNativeId() const;
369 * @brief Enumeration for orietation mode.
370 * The Orientation Mode is related to screen size.
371 * If screen width is longer than height, the Orientation Mode will have LANDSCAPE.
372 * Otherwise screen width is shorter than height or same, the Orientation Mode will have PORTRAIT.
374 enum class OrientationMode
381 * Private constructor.
392 * Second stage initialization
394 void Initialize(Any surface, const PositionSize& positionSize, const std::string& name, const std::string& className);
397 * Called when the window becomes iconified or deiconified.
399 void OnIconifyChanged(bool iconified);
402 * Called when the window focus is changed.
404 void OnFocusChanged(bool focusIn);
407 * Called when the output is transformed.
409 void OnOutputTransformed();
412 * Called when the window receives a delete request.
414 void OnDeleteRequest();
417 * Called when the window receives a Transition effect-start/end event.
419 void OnTransitionEffectEvent(WindowEffectState state, WindowEffectType type);
422 * @brief Called when window receives a keyboard repeat event.
424 void OnKeyboardRepeatSettingsChanged();
427 * @brief Called when the window redraw is requested.
429 void OnWindowRedrawRequest();
432 * @brief Set available orientation to window base.
434 void SetAvailableAnlges(const std::vector<int>& angles);
437 * @brief Convert from window orientation to angle using OrientationMode.
439 int ConvertToAngle(WindowOrientation orientation);
442 * @brief Convert from angle to window orientation using OrientationMode.
444 WindowOrientation ConvertToOrientation(int angle) const;
447 * @brief Check available window orientation for Available orientation.
449 bool IsOrientationAvailable(WindowOrientation orientation) const;
451 private: // Dali::Internal::Adaptor::SceneHolder
453 * @copydoc Dali::Internal::Adaptor::SceneHolder::OnAdaptorSet
455 void OnAdaptorSet(Dali::Adaptor& adaptor) override;
458 * @copydoc Dali::Internal::Adaptor::SceneHolder::OnSurfaceSet
460 void OnSurfaceSet(Dali::RenderSurfaceInterface* surface) override;
463 * @copydoc Dali::Internal::Adaptor::SceneHolder::OnPause
465 void OnPause() override;
468 * @copydoc Dali::Internal::Adaptor::SceneHolder::OnResume
470 void OnResume() override;
473 * @copydoc Dali::Internal::Adaptor::SceneHolder::RecalculateTouchPosition
475 void RecalculateTouchPosition(Integration::Point& point) override;
477 private: // Dali::Internal::Adaptor::EventHandler::Observer
479 * @copydoc Dali::Internal::Adaptor::EventHandler::Observer::OnTouchPoint
481 void OnTouchPoint(Dali::Integration::Point& point, int timeStamp) override;
484 * @copydoc Dali::Internal::Adaptor::EventHandler::Observer::OnWheelEvent
486 void OnWheelEvent(Dali::Integration::WheelEvent& wheelEvent) override;
489 * @copydoc Dali::Internal::Adaptor::EventHandler::Observer::OnKeyEvent
491 void OnKeyEvent(Dali::Integration::KeyEvent& keyEvent) override;
494 * @copydoc Dali::Internal::Adaptor::EventHandler::Observer::OnRotation
496 void OnRotation(const RotationEvent& rotation) override;
500 * @copydoc Dali::Window::FocusChangeSignal()
502 FocusChangeSignalType& FocusChangeSignal()
504 return mFocusChangeSignal;
508 * @copydoc Dali::Window::ResizedSignal()
510 ResizeSignalType& ResizeSignal()
512 return mResizeSignal;
516 * This signal is emitted when the window is requesting to be deleted
518 SignalType& DeleteRequestSignal()
520 return mDeleteRequestSignal;
524 * @copydoc Dali::DevelWindow::VisibilityChangedSignal()
526 VisibilityChangedSignalType& VisibilityChangedSignal()
528 return mVisibilityChangedSignal;
532 * @copydoc Dali::Window::SignalEventProcessingFinished()
534 Dali::DevelWindow::EventProcessingFinishedSignalType& EventProcessingFinishedSignal()
536 return mScene.EventProcessingFinishedSignal();
540 * @copydoc Dali::DevelWindow::TransitionEffectEventSignal()
542 TransitionEffectEventSignalType& TransitionEffectEventSignal()
544 return mTransitionEffectEventSignal;
548 * @copydoc Dali::DevelWindow::KeyboardRepeatSettingsChangedSignal()
550 KeyboardRepeatSettingsChangedSignalType& KeyboardRepeatSettingsChangedSignal()
552 return mKeyboardRepeatSettingsChangedSignal;
556 WindowRenderSurface* mWindowSurface; ///< The window rendering surface
557 WindowBase* mWindowBase;
559 std::string mClassName;
560 bool mIsTransparent : 1;
561 bool mIsFocusAcceptable : 1;
563 bool mOpaqueState : 1;
564 bool mResizeEnabled : 1;
566 Dali::Window mParentWindow;
568 OrientationPtr mOrientation;
569 std::vector<int> mAvailableAngles;
572 int mRotationAngle; ///< The angle of the rotation
573 int mWindowWidth; ///< The width of the window
574 int mWindowHeight; ///< The height of the window
576 EventHandlerPtr mEventHandler; ///< The window events handler
578 OrientationMode mOrientationMode;
580 int mNativeWindowId; ///< The Native Window Id
583 SignalType mDeleteRequestSignal;
584 FocusChangeSignalType mFocusChangeSignal;
585 ResizeSignalType mResizeSignal;
586 VisibilityChangedSignalType mVisibilityChangedSignal;
587 TransitionEffectEventSignalType mTransitionEffectEventSignal;
588 KeyboardRepeatSettingsChangedSignalType mKeyboardRepeatSettingsChangedSignal;
591 } // namespace Adaptor
592 } // namespace Internal
594 // Helpers for public-api forwarding methods
596 inline Internal::Adaptor::Window& GetImplementation(Dali::Window& window)
598 DALI_ASSERT_ALWAYS(window && "Window handle is empty");
599 BaseObject& object = window.GetBaseObject();
600 return static_cast<Internal::Adaptor::Window&>(object);
603 inline const Internal::Adaptor::Window& GetImplementation(const Dali::Window& window)
605 DALI_ASSERT_ALWAYS(window && "Window handle is empty");
606 const BaseObject& object = window.GetBaseObject();
607 return static_cast<const Internal::Adaptor::Window&>(object);
612 #endif // DALI_INTERNAL_WINDOWSYSTEM_COMMON_WINDOW_IMPL_H