1 #ifndef DALI_INTERNAL_WINDOWSYSTEM_COMMON_WINDOW_IMPL_H
2 #define DALI_INTERNAL_WINDOWSYSTEM_COMMON_WINDOW_IMPL_H
5 * Copyright (c) 2020 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/object/ref-object.h>
23 #include <dali/public-api/object/base-object.h>
24 #include <dali/public-api/actors/layer.h>
25 #include <dali/public-api/render-tasks/render-task-list.h>
26 #include <dali/public-api/object/property-array.h>
29 #include <dali/public-api/adaptor-framework/window.h>
30 #include <dali/public-api/adaptor-framework/key-grab.h>
31 #include <dali/devel-api/adaptor-framework/window-devel.h>
32 #include <dali/integration-api/adaptor-framework/scene-holder-impl.h>
33 #include <dali/internal/adaptor/common/adaptor-impl.h>
34 #include <dali/internal/window-system/common/event-handler.h>
40 class RenderSurfaceInterface;
47 class WindowRenderSurface;
51 using WindowPtr = IntrusivePtr< Window >;
52 using OrientationPtr = IntrusivePtr< Orientation >;
53 using EventHandlerPtr = IntrusivePtr< EventHandler >;
56 * Window provides a surface to render onto with orientation & indicator properties.
58 class Window : public Dali::Internal::Adaptor::SceneHolder, public EventHandler::Observer, public ConnectionTracker
61 typedef Dali::Window::FocusChangeSignalType FocusChangeSignalType;
62 typedef Dali::Window::ResizeSignalType ResizeSignalType;
63 typedef Dali::DevelWindow::VisibilityChangedSignalType VisibilityChangedSignalType;
64 typedef Dali::DevelWindow::TransitionEffectEventSignalType TransitionEffectEventSignalType;
65 typedef Dali::DevelWindow::KeyboardRepeatSettingsChangedSignalType KeyboardRepeatSettingsChangedSignalType;
66 typedef Signal< void () > SignalType;
69 * @brief Create a new Window. This should only be called once by the Application class
70 * @param[in] positionSize The position and size of the window
71 * @param[in] name The window title
72 * @param[in] className The window class name
73 * @param[in] isTransparent Whether window is transparent
74 * @return A newly allocated Window
76 static Window* New(const PositionSize& positionSize, const std::string& name, const std::string& className, bool isTransparent = false);
79 * @brief Create a new Window. This should only be called once by the Application class
80 * @param[in] surface The surface used to render on.
81 * @param[in] positionSize The position and size of the window
82 * @param[in] name The window title
83 * @param[in] className The window class name
84 * @param[in] isTransparent Whether window is transparent
85 * @return A newly allocated Window
87 static Window* New(Any surface, const PositionSize& positionSize, const std::string& name, const std::string& className, bool isTransparent = false);
90 * @copydoc Dali::Window::SetClass()
92 void SetClass( std::string name, std::string className );
95 * @brief Gets the window class name.
96 * @return The class of the window
98 std::string GetClassName() const;
101 * @copydoc Dali::Window::Raise()
106 * @copydoc Dali::Window::Lower()
111 * @copydoc Dali::Window::Activate()
116 * @copydoc Dali::Window::GetLayerCount()
118 uint32_t GetLayerCount() const;
121 * @copydoc Dali::Window::GetLayer()
123 Dali::Layer GetLayer( uint32_t depth ) const;
126 * @copydoc Dali::DevelWindow::GetRenderTaskList()
128 Dali::RenderTaskList GetRenderTaskList() const;
131 * @copydoc Dali::Window::AddAvailableOrientation()
133 void AddAvailableOrientation(Dali::Window::WindowOrientation orientation);
136 * @copydoc Dali::Window::RemoveAvailableOrientation()
138 void RemoveAvailableOrientation(Dali::Window::WindowOrientation orientation);
141 * @copydoc Dali::Window::SetPreferredOrientation()
143 void SetPreferredOrientation(Dali::Window::WindowOrientation orientation);
146 * @copydoc Dali::Window::GetPreferredOrientation()
148 Dali::Window::WindowOrientation GetPreferredOrientation();
151 * @copydoc Dali::Window::SetAcceptFocus()
153 void SetAcceptFocus( bool accept );
156 * @copydoc Dali::Window::IsFocusAcceptable()
158 bool IsFocusAcceptable() const;
161 * @copydoc Dali::Window::Show()
166 * @copydoc Dali::Window::Hide()
171 * @copydoc Dali::Window::GetSupportedAuxiliaryHintCount()
173 unsigned int GetSupportedAuxiliaryHintCount() const;
176 * @copydoc Dali::Window::GetSupportedAuxiliaryHint()
178 std::string GetSupportedAuxiliaryHint( unsigned int index ) const;
181 * @copydoc Dali::Window::AddAuxiliaryHint()
183 unsigned int AddAuxiliaryHint( const std::string& hint, const std::string& value );
186 * @copydoc Dali::Window::RemoveAuxiliaryHint()
188 bool RemoveAuxiliaryHint( unsigned int id );
191 * @copydoc Dali::Window::SetAuxiliaryHintValue()
193 bool SetAuxiliaryHintValue( unsigned int id, const std::string& value );
196 * @copydoc Dali::Window::GetAuxiliaryHintValue()
198 std::string GetAuxiliaryHintValue( unsigned int id ) const;
201 * @copydoc Dali::Window::GetAuxiliaryHintId()
203 unsigned int GetAuxiliaryHintId( const std::string& hint ) const;
206 * @copydoc Dali::Window::SetInputRegion()
208 void SetInputRegion( const Rect< int >& inputRegion );
211 * @copydoc Dali::Window::SetType()
213 void SetType( Dali::Window::Type type );
216 * @copydoc Dali::Window::GetType() const
218 Dali::Window::Type GetType() const;
221 * @copydoc Dali::Window::SetNotificationLevel()
223 bool SetNotificationLevel( Dali::Window::NotificationLevel::Type level );
226 * @copydoc Dali::Window::GetNotificationLevel()
228 Dali::Window::NotificationLevel::Type GetNotificationLevel() const;
231 * @copydoc Dali::Window::SetOpaqueState()
233 void SetOpaqueState( bool opaque );
236 * @copydoc Dali::Window::IsOpaqueState()
238 bool IsOpaqueState() const;
241 * @copydoc Dali::Window::SetScreenOffMode()
243 bool SetScreenOffMode(Dali::Window::ScreenOffMode::Type screenOffMode);
246 * @copydoc Dali::Window::GetScreenOffMode()
248 Dali::Window::ScreenOffMode::Type GetScreenOffMode() const;
251 * @copydoc Dali::Window::SetBrightness()
253 bool SetBrightness( int brightness );
256 * @copydoc Dali::Window::GetBrightness()
258 int GetBrightness() const;
261 * @copydoc Dali::Window::SetSize()
263 void SetSize( Dali::Window::WindowSize size );
266 * @copydoc Dali::Window::GetSize()
268 Dali::Window::WindowSize GetSize() const;
271 * @copydoc Dali::Window::SetPosition()
273 void SetPosition( Dali::Window::WindowPosition position );
276 * @copydoc Dali::Window::GetPosition()
278 Dali::Window::WindowPosition GetPosition() const;
281 * @copydoc Dali::DevelWindow::SetPositionSize()
283 void SetPositionSize( PositionSize positionSize );
286 * @copydoc Dali::Window::GetRootLayer()
288 Dali::Layer GetRootLayer() const;
291 * @copydoc Dali::Window::SetTransparency()
293 void SetTransparency( bool transparent );
296 * @copydoc Dali::KeyGrab::GrabKey()
298 bool GrabKey( Dali::KEY key, KeyGrab::KeyGrabMode grabMode );
301 * @copydoc Dali::KeyGrab::UngrabKey()
303 bool UngrabKey( Dali::KEY key );
306 * @copydoc Dali::KeyGrab::GrabKeyList()
308 bool GrabKeyList( const Dali::Vector< Dali::KEY >& key, const Dali::Vector< KeyGrab::KeyGrabMode >& grabMode, Dali::Vector< bool >& result );
311 * @copydoc Dali::KeyGrab::UngrabKeyList()
313 bool UngrabKeyList( const Dali::Vector< Dali::KEY >& key, Dali::Vector< bool >& result );
316 * @copydoc Dali::DevelWindow::Get()
318 static Dali::Window Get( Dali::Actor actor );
321 * @copydoc Dali::DevelWindow::SetParent()
323 void SetParent( Dali::Window& parent );
326 * @copydoc Dali::DevelWindow::Unparent()
331 * @copydoc Dali::DevelWindow::GetParent()
333 Dali::Window GetParent();
336 * @copydoc Dali::DevelWindow::GetCurrentOrientation()
338 Dali::Window::WindowOrientation GetCurrentOrientation() const;
341 * @copydoc Dali::DevelWindow::SetAvailableOrientations()
343 void SetAvailableOrientations( const Dali::Vector<Dali::Window::WindowOrientation>& orientations );
346 * @copydoc Dali::DevelWindow::SetDamagedAreas()
348 void SetDamagedAreas(std::vector<Dali::Rect<int>>& areas);
350 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;
370 * @brief Enumeration for orietation mode.
371 * The Orientation Mode is related to screen size.
372 * If screen width is longer than height, the Orientation Mode will have LANDSCAPE.
373 * Otherwise screen width is shorter than height or same, the Orientation Mode will have PORTRAIT.
375 enum class OrientationMode
382 * Private constructor.
393 * Second stage initialization
395 void Initialize(Any surface, const PositionSize& positionSize, const std::string& name, const std::string& className);
398 * Called when the window becomes iconified or deiconified.
400 void OnIconifyChanged( bool iconified );
403 * Called when the window focus is changed.
405 void OnFocusChanged( bool focusIn );
408 * Called when the output is transformed.
410 void OnOutputTransformed();
413 * Called when the window receives a delete request.
415 void OnDeleteRequest();
418 * Called when the window receives a Transition effect-start/end event.
420 void OnTransitionEffectEvent( DevelWindow::EffectState state, DevelWindow::EffectType type );
423 * @brief Called when window receives a keyboard repeat event.
425 void OnKeyboardRepeatSettingsChanged();
428 * @brief Called when the window redraw is requested.
430 void OnWindowRedrawRequest();
433 * @brief Set available orientation to window base.
435 void SetAvailableAnlges( const std::vector< int >& angles );
438 * @brief Convert from window orientation to angle using OrientationMode.
440 int ConvertToAngle( Dali::Window::WindowOrientation orientation );
443 * @brief Convert from angle to window orientation using OrientationMode.
445 Dali::Window::WindowOrientation ConvertToOrientation( int angle ) const;
448 * @brief Check available window orientation for Available orientation.
450 bool IsOrientationAvailable( Dali::Window::WindowOrientation orientation ) const;
452 private: // Dali::Internal::Adaptor::SceneHolder
455 * @copydoc Dali::Internal::Adaptor::SceneHolder::OnAdaptorSet
457 void OnAdaptorSet( Dali::Adaptor& adaptor ) override;
460 * @copydoc Dali::Internal::Adaptor::SceneHolder::OnSurfaceSet
462 void OnSurfaceSet( Dali::RenderSurfaceInterface* surface ) override;
465 * @copydoc Dali::Internal::Adaptor::SceneHolder::OnPause
467 void OnPause() override;
470 * @copydoc Dali::Internal::Adaptor::SceneHolder::OnResume
472 void OnResume() override;
475 * @copydoc Dali::Internal::Adaptor::SceneHolder::RecalculateTouchPosition
477 void RecalculateTouchPosition( Integration::Point& point ) override;
479 private: // Dali::Internal::Adaptor::EventHandler::Observer
482 * @copydoc Dali::Internal::Adaptor::EventHandler::Observer::OnTouchPoint
484 void OnTouchPoint( Dali::Integration::Point& point, int timeStamp ) override;
487 * @copydoc Dali::Internal::Adaptor::EventHandler::Observer::OnWheelEvent
489 void OnWheelEvent( Dali::Integration::WheelEvent& wheelEvent ) override;
492 * @copydoc Dali::Internal::Adaptor::EventHandler::Observer::OnKeyEvent
494 void OnKeyEvent( Dali::Integration::KeyEvent& keyEvent ) override;
497 * @copydoc Dali::Internal::Adaptor::EventHandler::Observer::OnRotation
499 void OnRotation( const RotationEvent& rotation ) override;
504 * @copydoc Dali::Window::FocusChangeSignal()
506 FocusChangeSignalType& FocusChangeSignal() { return mFocusChangeSignal; }
509 * @copydoc Dali::Window::ResizedSignal()
511 ResizeSignalType& ResizeSignal() { return mResizeSignal; }
514 * This signal is emitted when the window is requesting to be deleted
516 SignalType& DeleteRequestSignal() { return mDeleteRequestSignal; }
519 * @copydoc Dali::DevelWindow::VisibilityChangedSignal()
521 VisibilityChangedSignalType& VisibilityChangedSignal() { return mVisibilityChangedSignal; }
524 * @copydoc Dali::Window::SignalEventProcessingFinished()
526 Dali::DevelWindow::EventProcessingFinishedSignalType& EventProcessingFinishedSignal() { return mScene.EventProcessingFinishedSignal(); }
529 * @copydoc Dali::DevelWindow::TransitionEffectEventSignal()
531 TransitionEffectEventSignalType& TransitionEffectEventSignal() { return mTransitionEffectEventSignal; }
534 * @copydoc Dali::DevelWindow::KeyboardRepeatSettingsChangedSignal()
536 KeyboardRepeatSettingsChangedSignalType& KeyboardRepeatSettingsChangedSignal() { return mKeyboardRepeatSettingsChangedSignal; }
540 WindowRenderSurface* mWindowSurface; ///< The window rendering surface
541 WindowBase* mWindowBase;
543 std::string mClassName;
544 bool mIsTransparent:1;
545 bool mIsFocusAcceptable:1;
548 bool mResizeEnabled:1;
549 Dali::Window::Type mType;
550 Dali::Window mParentWindow;
552 OrientationPtr mOrientation;
553 std::vector< int > mAvailableAngles;
556 int mRotationAngle; ///< The angle of the rotation
557 int mWindowWidth; ///< The width of the window
558 int mWindowHeight; ///< The height of the window
560 EventHandlerPtr mEventHandler; ///< The window events handler
562 OrientationMode mOrientationMode;
564 int mNativeWindowId; ///< The Native Window Id
567 SignalType mDeleteRequestSignal;
568 FocusChangeSignalType mFocusChangeSignal;
569 ResizeSignalType mResizeSignal;
570 VisibilityChangedSignalType mVisibilityChangedSignal;
571 TransitionEffectEventSignalType mTransitionEffectEventSignal;
572 KeyboardRepeatSettingsChangedSignalType mKeyboardRepeatSettingsChangedSignal;
575 } // namespace Adaptor
576 } // namepsace Internal
578 // Helpers for public-api forwarding methods
580 inline Internal::Adaptor::Window& GetImplementation(Dali::Window& window)
582 DALI_ASSERT_ALWAYS( window && "Window handle is empty" );
583 BaseObject& object = window.GetBaseObject();
584 return static_cast<Internal::Adaptor::Window&>(object);
587 inline const Internal::Adaptor::Window& GetImplementation(const Dali::Window& window)
589 DALI_ASSERT_ALWAYS( window && "Window handle is empty" );
590 const BaseObject& object = window.GetBaseObject();
591 return static_cast<const Internal::Adaptor::Window&>(object);
596 #endif // DALI_INTERNAL_WINDOWSYSTEM_COMMON_WINDOW_IMPL_H