Changed 'virtual' function override declarations to 'override'.
[platform/core/uifw/dali-adaptor.git] / dali / internal / window-system / common / window-impl.h
1 #ifndef DALI_INTERNAL_WINDOWSYSTEM_COMMON_WINDOW_IMPL_H
2 #define DALI_INTERNAL_WINDOWSYSTEM_COMMON_WINDOW_IMPL_H
3
4 /*
5  * Copyright (c) 2020 Samsung Electronics Co., Ltd.
6  *
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
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
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.
18  *
19  */
20
21 // EXTERNAL INCLUDES
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>
27
28 // INTERNAL INCLUDES
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>
35
36 namespace Dali
37 {
38 class Adaptor;
39 class Actor;
40 class RenderSurfaceInterface;
41
42 namespace Internal
43 {
44 namespace Adaptor
45 {
46 class Orientation;
47 class WindowRenderSurface;
48 class WindowBase;
49
50 class Window;
51 using WindowPtr = IntrusivePtr< Window >;
52 using OrientationPtr = IntrusivePtr< Orientation >;
53 using EventHandlerPtr = IntrusivePtr< EventHandler >;
54
55 /**
56  * Window provides a surface to render onto with orientation & indicator properties.
57  */
58 class Window : public Dali::Internal::Adaptor::SceneHolder, public EventHandler::Observer, public ConnectionTracker
59 {
60 public:
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;
67
68   /**
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
75    */
76   static Window* New(const PositionSize& positionSize, const std::string& name, const std::string& className, bool isTransparent = false);
77
78   /**
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
86    */
87   static Window* New(Any surface, const PositionSize& positionSize, const std::string& name, const std::string& className, bool isTransparent = false);
88
89   /**
90    * @copydoc Dali::Window::SetClass()
91    */
92   void SetClass( std::string name, std::string className );
93
94   /**
95    * @brief Gets the window class name.
96    * @return The class of the window
97    */
98   std::string GetClassName() const;
99
100   /**
101    * @copydoc Dali::Window::Raise()
102    */
103   void Raise();
104
105   /**
106    * @copydoc Dali::Window::Lower()
107    */
108   void Lower();
109
110   /**
111    * @copydoc Dali::Window::Activate()
112    */
113   void Activate();
114
115   /**
116    * @copydoc Dali::Window::GetLayerCount()
117    */
118   uint32_t GetLayerCount() const;
119
120   /**
121    * @copydoc Dali::Window::GetLayer()
122    */
123   Dali::Layer GetLayer( uint32_t depth ) const;
124
125   /**
126    * @copydoc Dali::DevelWindow::GetRenderTaskList()
127    */
128   Dali::RenderTaskList GetRenderTaskList() const;
129
130   /**
131    * @copydoc Dali::Window::AddAvailableOrientation()
132    */
133   void AddAvailableOrientation(Dali::Window::WindowOrientation orientation);
134
135   /**
136    * @copydoc Dali::Window::RemoveAvailableOrientation()
137    */
138   void RemoveAvailableOrientation(Dali::Window::WindowOrientation orientation);
139
140   /**
141    * @copydoc Dali::Window::SetPreferredOrientation()
142    */
143   void SetPreferredOrientation(Dali::Window::WindowOrientation orientation);
144
145   /**
146    * @copydoc Dali::Window::GetPreferredOrientation()
147    */
148   Dali::Window::WindowOrientation GetPreferredOrientation();
149
150   /**
151    * @copydoc Dali::Window::SetAcceptFocus()
152    */
153   void SetAcceptFocus( bool accept );
154
155   /**
156    * @copydoc Dali::Window::IsFocusAcceptable()
157    */
158   bool IsFocusAcceptable() const;
159
160   /**
161    * @copydoc Dali::Window::Show()
162    */
163   void Show();
164
165   /**
166    * @copydoc Dali::Window::Hide()
167    */
168   void Hide();
169
170   /**
171    * @copydoc Dali::Window::GetSupportedAuxiliaryHintCount()
172    */
173   unsigned int GetSupportedAuxiliaryHintCount() const;
174
175   /**
176    * @copydoc Dali::Window::GetSupportedAuxiliaryHint()
177    */
178   std::string GetSupportedAuxiliaryHint( unsigned int index ) const;
179
180   /**
181    * @copydoc Dali::Window::AddAuxiliaryHint()
182    */
183   unsigned int AddAuxiliaryHint( const std::string& hint, const std::string& value );
184
185   /**
186    * @copydoc Dali::Window::RemoveAuxiliaryHint()
187    */
188   bool RemoveAuxiliaryHint( unsigned int id );
189
190   /**
191    * @copydoc Dali::Window::SetAuxiliaryHintValue()
192    */
193   bool SetAuxiliaryHintValue( unsigned int id, const std::string& value );
194
195   /**
196    * @copydoc Dali::Window::GetAuxiliaryHintValue()
197    */
198   std::string GetAuxiliaryHintValue( unsigned int id ) const;
199
200   /**
201    * @copydoc Dali::Window::GetAuxiliaryHintId()
202    */
203   unsigned int GetAuxiliaryHintId( const std::string& hint ) const;
204
205   /**
206    * @copydoc Dali::Window::SetInputRegion()
207    */
208   void SetInputRegion( const Rect< int >& inputRegion );
209
210   /**
211    * @copydoc Dali::Window::SetType()
212    */
213   void SetType( Dali::Window::Type type );
214
215   /**
216    * @copydoc Dali::Window::GetType() const
217    */
218   Dali::Window::Type GetType() const;
219
220   /**
221    * @copydoc Dali::Window::SetNotificationLevel()
222    */
223   bool SetNotificationLevel( Dali::Window::NotificationLevel::Type level );
224
225   /**
226    * @copydoc Dali::Window::GetNotificationLevel()
227    */
228   Dali::Window::NotificationLevel::Type GetNotificationLevel() const;
229
230   /**
231    * @copydoc Dali::Window::SetOpaqueState()
232    */
233   void SetOpaqueState( bool opaque );
234
235   /**
236    * @copydoc Dali::Window::IsOpaqueState()
237    */
238   bool IsOpaqueState() const;
239
240   /**
241    * @copydoc Dali::Window::SetScreenOffMode()
242    */
243   bool SetScreenOffMode(Dali::Window::ScreenOffMode::Type screenOffMode);
244
245   /**
246    * @copydoc Dali::Window::GetScreenOffMode()
247    */
248   Dali::Window::ScreenOffMode::Type GetScreenOffMode() const;
249
250   /**
251    * @copydoc Dali::Window::SetBrightness()
252    */
253   bool SetBrightness( int brightness );
254
255   /**
256    * @copydoc Dali::Window::GetBrightness()
257    */
258   int GetBrightness() const;
259
260   /**
261    * @copydoc Dali::Window::SetSize()
262    */
263   void SetSize( Dali::Window::WindowSize size );
264
265   /**
266    * @copydoc Dali::Window::GetSize()
267    */
268   Dali::Window::WindowSize GetSize() const;
269
270   /**
271    * @copydoc Dali::Window::SetPosition()
272    */
273   void SetPosition( Dali::Window::WindowPosition position );
274
275   /**
276    * @copydoc Dali::Window::GetPosition()
277    */
278   Dali::Window::WindowPosition GetPosition() const;
279
280   /**
281    * @copydoc Dali::DevelWindow::SetPositionSize()
282    */
283   void SetPositionSize( PositionSize positionSize );
284
285   /**
286    * @copydoc Dali::Window::GetRootLayer()
287    */
288   Dali::Layer GetRootLayer() const;
289
290   /**
291    * @copydoc Dali::Window::SetTransparency()
292    */
293   void SetTransparency( bool transparent );
294
295   /**
296    * @copydoc Dali::KeyGrab::GrabKey()
297    */
298   bool GrabKey( Dali::KEY key, KeyGrab::KeyGrabMode grabMode );
299
300   /**
301    * @copydoc Dali::KeyGrab::UngrabKey()
302    */
303   bool UngrabKey( Dali::KEY key );
304
305   /**
306    * @copydoc Dali::KeyGrab::GrabKeyList()
307    */
308   bool GrabKeyList( const Dali::Vector< Dali::KEY >& key, const Dali::Vector< KeyGrab::KeyGrabMode >& grabMode, Dali::Vector< bool >& result );
309
310   /**
311    * @copydoc Dali::KeyGrab::UngrabKeyList()
312    */
313   bool UngrabKeyList( const Dali::Vector< Dali::KEY >& key, Dali::Vector< bool >& result );
314
315   /**
316    * @copydoc Dali::DevelWindow::Get()
317    */
318   static Dali::Window Get( Dali::Actor actor );
319
320   /**
321    * @copydoc Dali::DevelWindow::SetParent()
322    */
323   void SetParent( Dali::Window& parent );
324
325   /**
326    * @copydoc Dali::DevelWindow::Unparent()
327    */
328   void Unparent();
329
330   /**
331    * @copydoc Dali::DevelWindow::GetParent()
332    */
333   Dali::Window GetParent();
334
335   /**
336    * @copydoc Dali::DevelWindow::GetCurrentOrientation()
337    */
338   Dali::Window::WindowOrientation GetCurrentOrientation() const;
339
340   /**
341    * @copydoc Dali::DevelWindow::SetAvailableOrientations()
342    */
343   void SetAvailableOrientations( const Dali::Vector<Dali::Window::WindowOrientation>& orientations );
344
345 public: // Dali::Internal::Adaptor::SceneHolder
346
347   /**
348    * @copydoc Dali::Internal::Adaptor::SceneHolder::GetNativeHandle
349    */
350   Dali::Any GetNativeHandle() const override;
351
352   /**
353    * @copydoc Dali::Internal::Adaptor::SceneHolder::IsVisible
354    */
355   bool IsVisible() const override;
356
357   /**
358    * @copydoc Dali::DevelWindow::GetNativeId()
359    */
360   int32_t GetNativeId() const;
361
362 private:
363
364   /**
365    * @brief Enumeration for orietation mode.
366    * The Orientation Mode is related to screen size.
367    * If screen width is longer than height, the Orientation Mode will have LANDSCAPE.
368    * Otherwise screen width is shorter than height or same, the Orientation Mode will have PORTRAIT.
369    */
370   enum class OrientationMode
371   {
372     PORTRAIT = 0,
373     LANDSCAPE
374   };
375
376   /**
377    * Private constructor.
378    * @sa Window::New()
379    */
380   Window();
381
382   /**
383    * Destructor
384    */
385   ~Window() override;
386
387   /**
388    * Second stage initialization
389    */
390   void Initialize(Any surface, const PositionSize& positionSize, const std::string& name, const std::string& className);
391
392   /**
393    * Called when the window becomes iconified or deiconified.
394    */
395   void OnIconifyChanged( bool iconified );
396
397   /**
398    * Called when the window focus is changed.
399    */
400   void OnFocusChanged( bool focusIn );
401
402   /**
403    * Called when the output is transformed.
404    */
405   void OnOutputTransformed();
406
407   /**
408    * Called when the window receives a delete request.
409    */
410   void OnDeleteRequest();
411
412   /**
413    * Called when the window receives a Transition effect-start/end event.
414    */
415   void OnTransitionEffectEvent( DevelWindow::EffectState state, DevelWindow::EffectType type );
416
417   /**
418    * @brief Called when window receives a keyboard repeat event.
419    */
420   void OnKeyboardRepeatSettingsChanged();
421
422   /**
423    * @brief Set available orientation to window base.
424    */
425   void SetAvailableAnlges( const std::vector< int >& angles );
426
427   /**
428    * @brief Convert from window orientation to angle using OrientationMode.
429    */
430   int ConvertToAngle( Dali::Window::WindowOrientation orientation );
431
432   /**
433    * @brief Convert from angle to window orientation using OrientationMode.
434    */
435   Dali::Window::WindowOrientation ConvertToOrientation( int angle ) const;
436
437   /**
438    * @brief Check available window orientation for Available orientation.
439    */
440   bool IsOrientationAvailable( Dali::Window::WindowOrientation orientation ) const;
441
442 private: // Dali::Internal::Adaptor::SceneHolder
443
444   /**
445    * @copydoc Dali::Internal::Adaptor::SceneHolder::OnAdaptorSet
446    */
447   void OnAdaptorSet( Dali::Adaptor& adaptor ) override;
448
449   /**
450    * @copydoc Dali::Internal::Adaptor::SceneHolder::OnSurfaceSet
451    */
452   void OnSurfaceSet( Dali::RenderSurfaceInterface* surface ) override;
453
454   /**
455    * @copydoc Dali::Internal::Adaptor::SceneHolder::OnPause
456    */
457   void OnPause() override;
458
459   /**
460    * @copydoc Dali::Internal::Adaptor::SceneHolder::OnResume
461    */
462   void OnResume() override;
463
464   /**
465    * @copydoc Dali::Internal::Adaptor::SceneHolder::RecalculateTouchPosition
466    */
467   void RecalculateTouchPosition( Integration::Point& point ) override;
468
469 private: // Dali::Internal::Adaptor::EventHandler::Observer
470
471   /**
472    * @copydoc Dali::Internal::Adaptor::EventHandler::Observer::OnTouchPoint
473    */
474   void OnTouchPoint( Dali::Integration::Point& point, int timeStamp ) override;
475
476   /**
477    * @copydoc Dali::Internal::Adaptor::EventHandler::Observer::OnWheelEvent
478    */
479   void OnWheelEvent( Dali::Integration::WheelEvent& wheelEvent ) override;
480
481   /**
482    * @copydoc Dali::Internal::Adaptor::EventHandler::Observer::OnKeyEvent
483    */
484   void OnKeyEvent( Dali::Integration::KeyEvent& keyEvent ) override;
485
486   /**
487    * @copydoc Dali::Internal::Adaptor::EventHandler::Observer::OnRotation
488    */
489   void OnRotation( const RotationEvent& rotation ) override;
490
491 public: // Signals
492
493   /**
494    * @copydoc Dali::Window::FocusChangeSignal()
495    */
496   FocusChangeSignalType& FocusChangeSignal() { return mFocusChangeSignal; }
497
498   /**
499    * @copydoc Dali::Window::ResizedSignal()
500    */
501   ResizeSignalType& ResizeSignal() { return mResizeSignal; }
502
503   /**
504    * This signal is emitted when the window is requesting to be deleted
505    */
506   SignalType& DeleteRequestSignal() { return mDeleteRequestSignal; }
507
508   /**
509    * @copydoc Dali::DevelWindow::VisibilityChangedSignal()
510    */
511   VisibilityChangedSignalType& VisibilityChangedSignal() { return mVisibilityChangedSignal; }
512
513   /**
514    * @copydoc Dali::Window::SignalEventProcessingFinished()
515    */
516   Dali::DevelWindow::EventProcessingFinishedSignalType& EventProcessingFinishedSignal() { return mScene.EventProcessingFinishedSignal(); }
517
518   /**
519    * @copydoc Dali::DevelWindow::TransitionEffectEventSignal()
520    */
521   TransitionEffectEventSignalType& TransitionEffectEventSignal() { return mTransitionEffectEventSignal; }
522
523   /**
524    * @copydoc Dali::DevelWindow::KeyboardRepeatSettingsChangedSignal()
525    */
526   KeyboardRepeatSettingsChangedSignalType& KeyboardRepeatSettingsChangedSignal() { return mKeyboardRepeatSettingsChangedSignal; }
527
528 private:
529
530   WindowRenderSurface*                  mWindowSurface;      ///< The window rendering surface
531   WindowBase*                           mWindowBase;
532   std::string                           mName;
533   std::string                           mClassName;
534   bool                                  mIsTransparent:1;
535   bool                                  mIsFocusAcceptable:1;
536   bool                                  mIconified:1;
537   bool                                  mOpaqueState:1;
538   bool                                  mResizeEnabled:1;
539   Dali::Window::Type                    mType;
540   Dali::Window                          mParentWindow;
541
542   OrientationPtr                        mOrientation;
543   std::vector< int >                    mAvailableAngles;
544   int                                   mPreferredAngle;
545
546   int                                   mRotationAngle;     ///< The angle of the rotation
547   int                                   mWindowWidth;       ///< The width of the window
548   int                                   mWindowHeight;      ///< The height of the window
549
550   EventHandlerPtr                       mEventHandler;      ///< The window events handler
551
552   OrientationMode                       mOrientationMode;
553
554   int                                   mNativeWindowId;          ///< The Native Window Id
555
556   // Signals
557   SignalType                              mDeleteRequestSignal;
558   FocusChangeSignalType                   mFocusChangeSignal;
559   ResizeSignalType                        mResizeSignal;
560   VisibilityChangedSignalType             mVisibilityChangedSignal;
561   TransitionEffectEventSignalType         mTransitionEffectEventSignal;
562   KeyboardRepeatSettingsChangedSignalType mKeyboardRepeatSettingsChangedSignal;
563 };
564
565 } // namespace Adaptor
566 } // namepsace Internal
567
568 // Helpers for public-api forwarding methods
569
570 inline Internal::Adaptor::Window& GetImplementation(Dali::Window& window)
571 {
572   DALI_ASSERT_ALWAYS( window && "Window handle is empty" );
573   BaseObject& object = window.GetBaseObject();
574   return static_cast<Internal::Adaptor::Window&>(object);
575 }
576
577 inline const Internal::Adaptor::Window& GetImplementation(const Dali::Window& window)
578 {
579   DALI_ASSERT_ALWAYS( window && "Window handle is empty" );
580   const BaseObject& object = window.GetBaseObject();
581   return static_cast<const Internal::Adaptor::Window&>(object);
582 }
583
584 } // namespace Dali
585
586 #endif // DALI_INTERNAL_WINDOWSYSTEM_COMMON_WINDOW_IMPL_H