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::ResizedSignalType ResizedSignalType;
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 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 Set available orientation to window base.
425 void SetAvailableAnlges( const std::vector< int >& angles );
428 * @brief Convert from window orientation to angle using OrientationMode.
430 int ConvertToAngle( Dali::Window::WindowOrientation orientation );
433 * @brief Convert from angle to window orientation using OrientationMode.
435 Dali::Window::WindowOrientation ConvertToOrientation( int angle ) const;
438 * @brief Check available window orientation for Available orientation.
440 bool IsOrientationAvailable( Dali::Window::WindowOrientation orientation ) const;
442 private: // Dali::Internal::Adaptor::SceneHolder
445 * @copydoc Dali::Internal::Adaptor::SceneHolder::OnAdaptorSet
447 void OnAdaptorSet( Dali::Adaptor& adaptor ) override;
450 * @copydoc Dali::Internal::Adaptor::SceneHolder::OnSurfaceSet
452 void OnSurfaceSet( Dali::RenderSurfaceInterface* surface ) override;
455 * @copydoc Dali::Internal::Adaptor::SceneHolder::OnPause
457 void OnPause() override;
460 * @copydoc Dali::Internal::Adaptor::SceneHolder::OnResume
462 void OnResume() override;
465 * @copydoc Dali::Internal::Adaptor::SceneHolder::RecalculateTouchPosition
467 void RecalculateTouchPosition( Integration::Point& point ) override;
469 private: // Dali::Internal::Adaptor::EventHandler::Observer
472 * @copydoc Dali::Internal::Adaptor::EventHandler::Observer::OnTouchPoint
474 void OnTouchPoint( Dali::Integration::Point& point, int timeStamp ) override;
477 * @copydoc Dali::Internal::Adaptor::EventHandler::Observer::OnWheelEvent
479 void OnWheelEvent( Dali::Integration::WheelEvent& wheelEvent ) override;
482 * @copydoc Dali::Internal::Adaptor::EventHandler::Observer::OnKeyEvent
484 void OnKeyEvent( Dali::Integration::KeyEvent& keyEvent ) override;
487 * @copydoc Dali::Internal::Adaptor::EventHandler::Observer::OnRotation
489 void OnRotation( const RotationEvent& rotation ) override;
494 * @copydoc Dali::Window::FocusChangeSignal()
496 FocusChangeSignalType& FocusChangeSignal() { return mFocusChangeSignal; }
498 * @copydoc Dali::Window::ResizedSignal()
500 ResizedSignalType& ResizedSignal() { return mResizedSignal; }
503 * @copydoc Dali::Window::ResizedSignal()
505 ResizeSignalType& ResizeSignal() { return mResizeSignal; }
508 * This signal is emitted when the window is requesting to be deleted
510 SignalType& DeleteRequestSignal() { return mDeleteRequestSignal; }
513 * @copydoc Dali::DevelWindow::VisibilityChangedSignal()
515 VisibilityChangedSignalType& VisibilityChangedSignal() { return mVisibilityChangedSignal; }
518 * @copydoc Dali::Window::SignalEventProcessingFinished()
520 Dali::DevelWindow::EventProcessingFinishedSignalType& EventProcessingFinishedSignal() { return mScene.EventProcessingFinishedSignal(); }
523 * @copydoc Dali::DevelWindow::TransitionEffectEventSignal()
525 TransitionEffectEventSignalType& TransitionEffectEventSignal() { return mTransitionEffectEventSignal; }
529 WindowRenderSurface* mWindowSurface; ///< The window rendering surface
530 WindowBase* mWindowBase;
532 std::string mClassName;
533 bool mIsTransparent:1;
534 bool mIsFocusAcceptable:1;
537 bool mResizeEnabled:1;
538 Dali::Window::Type mType;
539 Dali::Window mParentWindow;
541 OrientationPtr mOrientation;
542 std::vector< int > mAvailableAngles;
545 int mRotationAngle; ///< The angle of the rotation
546 int mWindowWidth; ///< The width of the window
547 int mWindowHeight; ///< The height of the window
549 EventHandlerPtr mEventHandler; ///< The window events handler
551 OrientationMode mOrientationMode;
553 int mNativeWindowId; ///< The Native Window Id
556 ResizedSignalType mResizedSignal;
557 SignalType mDeleteRequestSignal;
558 FocusChangeSignalType mFocusChangeSignal;
559 ResizeSignalType mResizeSignal;
560 VisibilityChangedSignalType mVisibilityChangedSignal;
561 TransitionEffectEventSignalType mTransitionEffectEventSignal;
564 } // namespace Adaptor
565 } // namepsace Internal
567 // Helpers for public-api forwarding methods
569 inline Internal::Adaptor::Window& GetImplementation(Dali::Window& window)
571 DALI_ASSERT_ALWAYS( window && "Window handle is empty" );
572 BaseObject& object = window.GetBaseObject();
573 return static_cast<Internal::Adaptor::Window&>(object);
576 inline const Internal::Adaptor::Window& GetImplementation(const Dali::Window& window)
578 DALI_ASSERT_ALWAYS( window && "Window handle is empty" );
579 const BaseObject& object = window.GetBaseObject();
580 return static_cast<const Internal::Adaptor::Window&>(object);
585 #endif // DALI_INTERNAL_WINDOWSYSTEM_COMMON_WINDOW_IMPL_H