Removed the deprecated Dali::Internal::Adaptor::Window::ResizedSignal().
[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   /**
346    * @copydoc Dali::DevelWindow::SetDamagedAreas()
347    */
348   void SetDamagedAreas(std::vector<Dali::Rect<int>>& areas);
349
350 public: // Dali::Internal::Adaptor::SceneHolder
351
352   /**
353    * @copydoc Dali::Internal::Adaptor::SceneHolder::GetNativeHandle
354    */
355   Dali::Any GetNativeHandle() const override;
356
357   /**
358    * @copydoc Dali::Internal::Adaptor::SceneHolder::IsVisible
359    */
360   bool IsVisible() const override;
361
362   /**
363    * @copydoc Dali::DevelWindow::GetNativeId()
364    */
365   int32_t GetNativeId() const;
366
367 private:
368
369   /**
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.
374    */
375   enum class OrientationMode
376   {
377     PORTRAIT = 0,
378     LANDSCAPE
379   };
380
381   /**
382    * Private constructor.
383    * @sa Window::New()
384    */
385   Window();
386
387   /**
388    * Destructor
389    */
390   virtual ~Window();
391
392   /**
393    * Second stage initialization
394    */
395   void Initialize(Any surface, const PositionSize& positionSize, const std::string& name, const std::string& className);
396
397   /**
398    * Called when the window becomes iconified or deiconified.
399    */
400   void OnIconifyChanged( bool iconified );
401
402   /**
403    * Called when the window focus is changed.
404    */
405   void OnFocusChanged( bool focusIn );
406
407   /**
408    * Called when the output is transformed.
409    */
410   void OnOutputTransformed();
411
412   /**
413    * Called when the window receives a delete request.
414    */
415   void OnDeleteRequest();
416
417   /**
418    * Called when the window receives a Transition effect-start/end event.
419    */
420   void OnTransitionEffectEvent( DevelWindow::EffectState state, DevelWindow::EffectType type );
421
422   /**
423    * @brief Called when window receives a keyboard repeat event.
424    */
425   void OnKeyboardRepeatSettingsChanged();
426
427   /**
428    * @brief Set available orientation to window base.
429    */
430   void SetAvailableAnlges( const std::vector< int >& angles );
431
432   /**
433    * @brief Convert from window orientation to angle using OrientationMode.
434    */
435   int ConvertToAngle( Dali::Window::WindowOrientation orientation );
436
437   /**
438    * @brief Convert from angle to window orientation using OrientationMode.
439    */
440   Dali::Window::WindowOrientation ConvertToOrientation( int angle ) const;
441
442   /**
443    * @brief Check available window orientation for Available orientation.
444    */
445   bool IsOrientationAvailable( Dali::Window::WindowOrientation orientation ) const;
446
447 private: // Dali::Internal::Adaptor::SceneHolder
448
449   /**
450    * @copydoc Dali::Internal::Adaptor::SceneHolder::OnAdaptorSet
451    */
452   void OnAdaptorSet( Dali::Adaptor& adaptor ) override;
453
454   /**
455    * @copydoc Dali::Internal::Adaptor::SceneHolder::OnSurfaceSet
456    */
457   void OnSurfaceSet( Dali::RenderSurfaceInterface* surface ) override;
458
459   /**
460    * @copydoc Dali::Internal::Adaptor::SceneHolder::OnPause
461    */
462   void OnPause() override;
463
464   /**
465    * @copydoc Dali::Internal::Adaptor::SceneHolder::OnResume
466    */
467   void OnResume() override;
468
469   /**
470    * @copydoc Dali::Internal::Adaptor::SceneHolder::RecalculateTouchPosition
471    */
472   void RecalculateTouchPosition( Integration::Point& point ) override;
473
474 private: // Dali::Internal::Adaptor::EventHandler::Observer
475
476   /**
477    * @copydoc Dali::Internal::Adaptor::EventHandler::Observer::OnTouchPoint
478    */
479   void OnTouchPoint( Dali::Integration::Point& point, int timeStamp ) override;
480
481   /**
482    * @copydoc Dali::Internal::Adaptor::EventHandler::Observer::OnWheelEvent
483    */
484   void OnWheelEvent( Dali::Integration::WheelEvent& wheelEvent ) override;
485
486   /**
487    * @copydoc Dali::Internal::Adaptor::EventHandler::Observer::OnKeyEvent
488    */
489   void OnKeyEvent( Dali::Integration::KeyEvent& keyEvent ) override;
490
491   /**
492    * @copydoc Dali::Internal::Adaptor::EventHandler::Observer::OnRotation
493    */
494   void OnRotation( const RotationEvent& rotation ) override;
495
496 public: // Signals
497
498   /**
499    * @copydoc Dali::Window::FocusChangeSignal()
500    */
501   FocusChangeSignalType& FocusChangeSignal() { return mFocusChangeSignal; }
502
503   /**
504    * @copydoc Dali::Window::ResizedSignal()
505    */
506   ResizeSignalType& ResizeSignal() { return mResizeSignal; }
507
508   /**
509    * This signal is emitted when the window is requesting to be deleted
510    */
511   SignalType& DeleteRequestSignal() { return mDeleteRequestSignal; }
512
513   /**
514    * @copydoc Dali::DevelWindow::VisibilityChangedSignal()
515    */
516   VisibilityChangedSignalType& VisibilityChangedSignal() { return mVisibilityChangedSignal; }
517
518   /**
519    * @copydoc Dali::Window::SignalEventProcessingFinished()
520    */
521   Dali::DevelWindow::EventProcessingFinishedSignalType& EventProcessingFinishedSignal() { return mScene.EventProcessingFinishedSignal(); }
522
523   /**
524    * @copydoc Dali::DevelWindow::TransitionEffectEventSignal()
525    */
526   TransitionEffectEventSignalType& TransitionEffectEventSignal() { return mTransitionEffectEventSignal; }
527
528   /**
529    * @copydoc Dali::DevelWindow::KeyboardRepeatSettingsChangedSignal()
530    */
531   KeyboardRepeatSettingsChangedSignalType& KeyboardRepeatSettingsChangedSignal() { return mKeyboardRepeatSettingsChangedSignal; }
532
533 private:
534
535   WindowRenderSurface*                  mWindowSurface;      ///< The window rendering surface
536   WindowBase*                           mWindowBase;
537   std::string                           mName;
538   std::string                           mClassName;
539   bool                                  mIsTransparent:1;
540   bool                                  mIsFocusAcceptable:1;
541   bool                                  mIconified:1;
542   bool                                  mOpaqueState:1;
543   bool                                  mResizeEnabled:1;
544   Dali::Window::Type                    mType;
545   Dali::Window                          mParentWindow;
546
547   OrientationPtr                        mOrientation;
548   std::vector< int >                    mAvailableAngles;
549   int                                   mPreferredAngle;
550
551   int                                   mRotationAngle;     ///< The angle of the rotation
552   int                                   mWindowWidth;       ///< The width of the window
553   int                                   mWindowHeight;      ///< The height of the window
554
555   EventHandlerPtr                       mEventHandler;      ///< The window events handler
556
557   OrientationMode                       mOrientationMode;
558
559   int                                   mNativeWindowId;          ///< The Native Window Id
560
561   // Signals
562   SignalType                              mDeleteRequestSignal;
563   FocusChangeSignalType                   mFocusChangeSignal;
564   ResizeSignalType                        mResizeSignal;
565   VisibilityChangedSignalType             mVisibilityChangedSignal;
566   TransitionEffectEventSignalType         mTransitionEffectEventSignal;
567   KeyboardRepeatSettingsChangedSignalType mKeyboardRepeatSettingsChangedSignal;
568 };
569
570 } // namespace Adaptor
571 } // namepsace Internal
572
573 // Helpers for public-api forwarding methods
574
575 inline Internal::Adaptor::Window& GetImplementation(Dali::Window& window)
576 {
577   DALI_ASSERT_ALWAYS( window && "Window handle is empty" );
578   BaseObject& object = window.GetBaseObject();
579   return static_cast<Internal::Adaptor::Window&>(object);
580 }
581
582 inline const Internal::Adaptor::Window& GetImplementation(const Dali::Window& window)
583 {
584   DALI_ASSERT_ALWAYS( window && "Window handle is empty" );
585   const BaseObject& object = window.GetBaseObject();
586   return static_cast<const Internal::Adaptor::Window&>(object);
587 }
588
589 } // namespace Dali
590
591 #endif // DALI_INTERNAL_WINDOWSYSTEM_COMMON_WINDOW_IMPL_H