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