1 #ifndef DALI_INTERNAL_WINDOWSYSTEM_COMMON_WINDOW_IMPL_H
2 #define DALI_INTERNAL_WINDOWSYSTEM_COMMON_WINDOW_IMPL_H
5 * Copyright (c) 2019 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::IndicatorSignalType IndicatorSignalType;
62 typedef Dali::Window::FocusSignalType FocusSignalType;
63 typedef Dali::Window::ResizedSignalType ResizedSignalType;
64 typedef Dali::Window::FocusChangeSignalType FocusChangeSignalType;
65 typedef Dali::Window::ResizeSignalType ResizeSignalType;
66 typedef Dali::DevelWindow::VisibilityChangedSignalType VisibilityChangedSignalType;
67 typedef Dali::DevelWindow::TransitionEffectEventSignalType TransitionEffectEventSignalType;
68 typedef Signal< void () > SignalType;
71 * @brief Create a new Window. This should only be called once by the Application class
72 * @param[in] positionSize The position and size of the window
73 * @param[in] name The window title
74 * @param[in] className The window class name
75 * @param[in] isTransparent Whether window is transparent
76 * @return A newly allocated Window
78 static Window* New(const PositionSize& positionSize, const std::string& name, const std::string& className, bool isTransparent = false);
81 * @brief Create a new Window. This should only be called once by the Application class
82 * @param[in] surface The surface used to render on.
83 * @param[in] positionSize The position and size of the window
84 * @param[in] name The window title
85 * @param[in] className The window class name
86 * @param[in] isTransparent Whether window is transparent
87 * @return A newly allocated Window
89 static Window* New(Any surface, const PositionSize& positionSize, const std::string& name, const std::string& className, bool isTransparent = false);
92 * @copydoc Dali::Window::ShowIndicator()
94 void ShowIndicator( Dali::Window::IndicatorVisibleMode visibleMode );
97 * @copydoc Dali::Window::SetIndicatorBgOpacity()
99 void SetIndicatorBgOpacity( Dali::Window::IndicatorBgOpacity opacity );
102 * @copydoc Dali::Window::RotateIndicator()
104 void RotateIndicator( Dali::Window::WindowOrientation orientation );
107 * @copydoc Dali::Window::SetClass()
109 void SetClass( std::string name, std::string className );
112 * @brief Gets the window class name.
113 * @return The class of the window
115 std::string GetClassName() const;
118 * @copydoc Dali::Window::Raise()
123 * @copydoc Dali::Window::Lower()
128 * @copydoc Dali::Window::Activate()
133 * @copydoc Dali::Window::GetLayerCount()
135 uint32_t GetLayerCount() const;
138 * @copydoc Dali::Window::GetLayer()
140 Dali::Layer GetLayer( uint32_t depth ) const;
143 * @copydoc Dali::DevelWindow::GetRenderTaskList()
145 Dali::RenderTaskList GetRenderTaskList() const;
148 * @copydoc Dali::Window::AddAvailableOrientation()
150 void AddAvailableOrientation(Dali::Window::WindowOrientation orientation);
153 * @copydoc Dali::Window::RemoveAvailableOrientation()
155 void RemoveAvailableOrientation(Dali::Window::WindowOrientation orientation);
158 * @copydoc Dali::Window::SetPreferredOrientation()
160 void SetPreferredOrientation(Dali::Window::WindowOrientation orientation);
163 * @copydoc Dali::Window::GetPreferredOrientation()
165 Dali::Window::WindowOrientation GetPreferredOrientation();
168 * @copydoc Dali::Window::SetAcceptFocus()
170 void SetAcceptFocus( bool accept );
173 * @copydoc Dali::Window::IsFocusAcceptable()
175 bool IsFocusAcceptable() const;
178 * @copydoc Dali::Window::Show()
183 * @copydoc Dali::Window::Hide()
188 * @copydoc Dali::Window::GetSupportedAuxiliaryHintCount()
190 unsigned int GetSupportedAuxiliaryHintCount() const;
193 * @copydoc Dali::Window::GetSupportedAuxiliaryHint()
195 std::string GetSupportedAuxiliaryHint( unsigned int index ) const;
198 * @copydoc Dali::Window::AddAuxiliaryHint()
200 unsigned int AddAuxiliaryHint( const std::string& hint, const std::string& value );
203 * @copydoc Dali::Window::RemoveAuxiliaryHint()
205 bool RemoveAuxiliaryHint( unsigned int id );
208 * @copydoc Dali::Window::SetAuxiliaryHintValue()
210 bool SetAuxiliaryHintValue( unsigned int id, const std::string& value );
213 * @copydoc Dali::Window::GetAuxiliaryHintValue()
215 std::string GetAuxiliaryHintValue( unsigned int id ) const;
218 * @copydoc Dali::Window::GetAuxiliaryHintId()
220 unsigned int GetAuxiliaryHintId( const std::string& hint ) const;
223 * @copydoc Dali::Window::SetInputRegion()
225 void SetInputRegion( const Rect< int >& inputRegion );
228 * @copydoc Dali::Window::SetType()
230 void SetType( Dali::Window::Type type );
233 * @copydoc Dali::Window::GetType() const
235 Dali::Window::Type GetType() const;
238 * @copydoc Dali::Window::SetNotificationLevel()
240 bool SetNotificationLevel( Dali::Window::NotificationLevel::Type level );
243 * @copydoc Dali::Window::GetNotificationLevel()
245 Dali::Window::NotificationLevel::Type GetNotificationLevel() const;
248 * @copydoc Dali::Window::SetOpaqueState()
250 void SetOpaqueState( bool opaque );
253 * @copydoc Dali::Window::IsOpaqueState()
255 bool IsOpaqueState() const;
258 * @copydoc Dali::Window::SetScreenOffMode()
260 bool SetScreenOffMode(Dali::Window::ScreenOffMode::Type screenOffMode);
263 * @copydoc Dali::Window::GetScreenOffMode()
265 Dali::Window::ScreenOffMode::Type GetScreenOffMode() const;
268 * @copydoc Dali::Window::SetBrightness()
270 bool SetBrightness( int brightness );
273 * @copydoc Dali::Window::GetBrightness()
275 int GetBrightness() const;
278 * @copydoc Dali::Window::SetSize()
280 void SetSize( Dali::Window::WindowSize size );
283 * @copydoc Dali::Window::GetSize()
285 Dali::Window::WindowSize GetSize() const;
288 * @copydoc Dali::Window::SetPosition()
290 void SetPosition( Dali::Window::WindowPosition position );
293 * @copydoc Dali::Window::GetPosition()
295 Dali::Window::WindowPosition GetPosition() const;
298 * @copydoc Dali::DevelWindow::SetPositionSize()
300 void SetPositionSize( PositionSize positionSize );
303 * @copydoc Dali::Window::GetRootLayer()
305 Dali::Layer GetRootLayer() const;
308 * @copydoc Dali::Window::SetTransparency()
310 void SetTransparency( bool transparent );
313 * @copydoc Dali::KeyGrab::GrabKey()
315 bool GrabKey( Dali::KEY key, KeyGrab::KeyGrabMode grabMode );
318 * @copydoc Dali::KeyGrab::UngrabKey()
320 bool UngrabKey( Dali::KEY key );
323 * @copydoc Dali::KeyGrab::GrabKeyList()
325 bool GrabKeyList( const Dali::Vector< Dali::KEY >& key, const Dali::Vector< KeyGrab::KeyGrabMode >& grabMode, Dali::Vector< bool >& result );
328 * @copydoc Dali::KeyGrab::UngrabKeyList()
330 bool UngrabKeyList( const Dali::Vector< Dali::KEY >& key, Dali::Vector< bool >& result );
333 * @copydoc Dali::DevelWindow::Get()
335 static Dali::Window Get( Dali::Actor actor );
338 * @copydoc Dali::DevelWindow::SetParent()
340 void SetParent( Dali::Window& parent );
343 * @copydoc Dali::DevelWindow::Unparent()
348 * @copydoc Dali::DevelWindow::GetParent()
350 Dali::Window GetParent();
353 * @copydoc Dali::DevelWindow::GetCurrentOrientation()
355 Dali::Window::WindowOrientation GetCurrentOrientation() const;
358 * @copydoc Dali::DevelWindow::SetAvailableOrientations()
360 void SetAvailableOrientations( const Dali::Vector<Dali::Window::WindowOrientation>& orientations );
362 public: // Dali::Internal::Adaptor::SceneHolder
365 * @copydoc Dali::Internal::Adaptor::SceneHolder::GetNativeHandle
367 Dali::Any GetNativeHandle() const override;
370 * @copydoc Dali::Internal::Adaptor::SceneHolder::IsVisible
372 bool IsVisible() const override;
377 * @brief Enumeration for orietation mode.
378 * The Orientation Mode is related to screen size.
379 * If screen width is longer than height, the Orientation Mode will have LANDSCAPE.
380 * Otherwise screen width is shorter than height or same, the Orientation Mode will have PORTRAIT.
382 enum class OrientationMode
389 * Private constructor.
400 * Second stage initialization
402 void Initialize(Any surface, const PositionSize& positionSize, const std::string& name, const std::string& className);
405 * Called when the window becomes iconified or deiconified.
407 void OnIconifyChanged( bool iconified );
410 * Called when the window focus is changed.
412 void OnFocusChanged( bool focusIn );
415 * Called when the output is transformed.
417 void OnOutputTransformed();
420 * Called when the window receives a delete request.
422 void OnDeleteRequest();
425 * Called when the window receives a Transition effect-start/end event.
427 void OnTransitionEffectEvent( DevelWindow::EffectState state, DevelWindow::EffectType type );
430 * @brief Set available orientation to window base.
432 void SetAvailableAnlges( const std::vector< int >& angles );
435 * @brief Convert from window orientation to angle using OrientationMode.
437 int ConvertToAngle( Dali::Window::WindowOrientation orientation );
440 * @brief Convert from angle to window orientation using OrientationMode.
442 Dali::Window::WindowOrientation ConvertToOrientation( int angle ) const;
445 * @brief Check available window orientation for Available orientation.
447 bool IsOrientationAvailable( Dali::Window::WindowOrientation orientation ) const;
449 private: // Dali::Internal::Adaptor::SceneHolder
452 * @copydoc Dali::Internal::Adaptor::SceneHolder::OnAdaptorSet
454 void OnAdaptorSet( Dali::Adaptor& adaptor ) override;
457 * @copydoc Dali::Internal::Adaptor::SceneHolder::OnSurfaceSet
459 void OnSurfaceSet( Dali::RenderSurfaceInterface* surface ) override;
462 * @copydoc Dali::Internal::Adaptor::SceneHolder::OnPause
464 void OnPause() override;
467 * @copydoc Dali::Internal::Adaptor::SceneHolder::OnResume
469 void OnResume() override;
472 * @copydoc Dali::Internal::Adaptor::SceneHolder::RecalculateTouchPosition
474 void RecalculateTouchPosition( Integration::Point& point ) override;
476 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;
501 * The user should connect to this signal to get a timing when indicator was shown / hidden.
503 IndicatorSignalType& IndicatorVisibilityChangedSignal() { return mIndicatorVisibilityChangedSignal; }
506 * @copydoc Dali::Window::FocusChangedSignal()
508 FocusSignalType& FocusChangedSignal() { return mFocusChangedSignal; }
511 * @copydoc Dali::Window::WindowFocusChangedSignal()
513 FocusChangeSignalType& FocusChangeSignal() { return mFocusChangeSignal; }
515 * @copydoc Dali::Window::ResizedSignal()
517 ResizedSignalType& ResizedSignal() { return mResizedSignal; }
520 * @copydoc Dali::Window::ResizedSignal()
522 ResizeSignalType& ResizeSignal() { return mResizeSignal; }
525 * This signal is emitted when the window is requesting to be deleted
527 SignalType& DeleteRequestSignal() { return mDeleteRequestSignal; }
530 * @copydoc Dali::DevelWindow::VisibilityChangedSignal()
532 VisibilityChangedSignalType& VisibilityChangedSignal() { return mVisibilityChangedSignal; }
535 * @copydoc Dali::Window::SignalEventProcessingFinished()
537 Dali::DevelWindow::EventProcessingFinishedSignalType& EventProcessingFinishedSignal() { return mScene.EventProcessingFinishedSignal(); }
540 * @copydoc Dali::DevelWindow::TransitionEffectEventSignal()
542 TransitionEffectEventSignalType& TransitionEffectEventSignal() { return mTransitionEffectEventSignal; }
546 WindowRenderSurface* mWindowSurface; ///< The window rendering surface
547 WindowBase* mWindowBase;
549 std::string mClassName;
550 bool mIsTransparent:1;
551 bool mIsFocusAcceptable:1;
554 bool mResizeEnabled:1;
555 Dali::Window::Type mType;
556 Dali::Window mParentWindow;
558 OrientationPtr mOrientation;
559 std::vector< int > mAvailableAngles;
562 int mRotationAngle; ///< The angle of the rotation
563 int mWindowWidth; ///< The width of the window
564 int mWindowHeight; ///< The height of the window
566 EventHandlerPtr mEventHandler; ///< The window events handler
568 OrientationMode mOrientationMode;
570 int mNativeWindowId; ///< The Native Window Id
573 IndicatorSignalType mIndicatorVisibilityChangedSignal;
574 FocusSignalType mFocusChangedSignal;
575 ResizedSignalType mResizedSignal;
576 SignalType mDeleteRequestSignal;
577 FocusChangeSignalType mFocusChangeSignal;
578 ResizeSignalType mResizeSignal;
579 VisibilityChangedSignalType mVisibilityChangedSignal;
580 TransitionEffectEventSignalType mTransitionEffectEventSignal;
583 } // namespace Adaptor
584 } // namepsace Internal
586 // Helpers for public-api forwarding methods
588 inline Internal::Adaptor::Window& GetImplementation(Dali::Window& window)
590 DALI_ASSERT_ALWAYS( window && "Window handle is empty" );
591 BaseObject& object = window.GetBaseObject();
592 return static_cast<Internal::Adaptor::Window&>(object);
595 inline const Internal::Adaptor::Window& GetImplementation(const Dali::Window& window)
597 DALI_ASSERT_ALWAYS( window && "Window handle is empty" );
598 const BaseObject& object = window.GetBaseObject();
599 return static_cast<const Internal::Adaptor::Window&>(object);
604 #endif // DALI_INTERNAL_WINDOWSYSTEM_COMMON_WINDOW_IMPL_H