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