Add Window Effect Start/End signal
[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::SetAvailableOrientations()
147    */
148   void SetAvailableOrientations(const std::vector<Dali::Window::WindowOrientation>& orientations);
149
150   /**
151    * @copydoc Dali::Window::GetAvailableOrientations()
152    */
153   const std::vector<Dali::Window::WindowOrientation>& GetAvailableOrientations();
154
155   /**
156    * @copydoc Dali::Window::SetPreferredOrientation()
157    */
158   void SetPreferredOrientation(Dali::Window::WindowOrientation orientation);
159
160   /**
161    * @copydoc Dali::Window::GetPreferredOrientation()
162    */
163   Dali::Window::WindowOrientation GetPreferredOrientation();
164
165   /**
166    * @copydoc Dali::Window::SetAcceptFocus()
167    */
168   void SetAcceptFocus( bool accept );
169
170   /**
171    * @copydoc Dali::Window::IsFocusAcceptable()
172    */
173   bool IsFocusAcceptable() const;
174
175   /**
176    * @copydoc Dali::Window::Show()
177    */
178   void Show();
179
180   /**
181    * @copydoc Dali::Window::Hide()
182    */
183   void Hide();
184
185   /**
186    * @copydoc Dali::Window::GetSupportedAuxiliaryHintCount()
187    */
188   unsigned int GetSupportedAuxiliaryHintCount() const;
189
190   /**
191    * @copydoc Dali::Window::GetSupportedAuxiliaryHint()
192    */
193   std::string GetSupportedAuxiliaryHint( unsigned int index ) const;
194
195   /**
196    * @copydoc Dali::Window::AddAuxiliaryHint()
197    */
198   unsigned int AddAuxiliaryHint( const std::string& hint, const std::string& value );
199
200   /**
201    * @copydoc Dali::Window::RemoveAuxiliaryHint()
202    */
203   bool RemoveAuxiliaryHint( unsigned int id );
204
205   /**
206    * @copydoc Dali::Window::SetAuxiliaryHintValue()
207    */
208   bool SetAuxiliaryHintValue( unsigned int id, const std::string& value );
209
210   /**
211    * @copydoc Dali::Window::GetAuxiliaryHintValue()
212    */
213   std::string GetAuxiliaryHintValue( unsigned int id ) const;
214
215   /**
216    * @copydoc Dali::Window::GetAuxiliaryHintId()
217    */
218   unsigned int GetAuxiliaryHintId( const std::string& hint ) const;
219
220   /**
221    * @copydoc Dali::Window::SetInputRegion()
222    */
223   void SetInputRegion( const Rect< int >& inputRegion );
224
225   /**
226    * @copydoc Dali::Window::SetType()
227    */
228   void SetType( Dali::Window::Type type );
229
230   /**
231    * @copydoc Dali::Window::GetType() const
232    */
233   Dali::Window::Type GetType() const;
234
235   /**
236    * @copydoc Dali::Window::SetNotificationLevel()
237    */
238   bool SetNotificationLevel( Dali::Window::NotificationLevel::Type level );
239
240   /**
241    * @copydoc Dali::Window::GetNotificationLevel()
242    */
243   Dali::Window::NotificationLevel::Type GetNotificationLevel() const;
244
245   /**
246    * @copydoc Dali::Window::SetOpaqueState()
247    */
248   void SetOpaqueState( bool opaque );
249
250   /**
251    * @copydoc Dali::Window::IsOpaqueState()
252    */
253   bool IsOpaqueState() const;
254
255   /**
256    * @copydoc Dali::Window::SetScreenOffMode()
257    */
258   bool SetScreenOffMode(Dali::Window::ScreenOffMode::Type screenOffMode);
259
260   /**
261    * @copydoc Dali::Window::GetScreenOffMode()
262    */
263   Dali::Window::ScreenOffMode::Type GetScreenOffMode() const;
264
265   /**
266    * @copydoc Dali::Window::SetBrightness()
267    */
268   bool SetBrightness( int brightness );
269
270   /**
271    * @copydoc Dali::Window::GetBrightness()
272    */
273   int GetBrightness() const;
274
275   /**
276    * @copydoc Dali::Window::SetSize()
277    */
278   void SetSize( Dali::Window::WindowSize size );
279
280   /**
281    * @copydoc Dali::Window::GetSize()
282    */
283   Dali::Window::WindowSize GetSize() const;
284
285   /**
286    * @copydoc Dali::Window::SetPosition()
287    */
288   void SetPosition( Dali::Window::WindowPosition position );
289
290   /**
291    * @copydoc Dali::Window::GetPosition()
292    */
293   Dali::Window::WindowPosition GetPosition() const;
294
295   /**
296    * @copydoc Dali::DevelWindow::SetPositionSize()
297    */
298   void SetPositionSize( PositionSize positionSize );
299
300   /**
301    * @copydoc Dali::Window::GetRootLayer()
302    */
303   Dali::Layer GetRootLayer() const;
304
305   /**
306    * @copydoc Dali::Window::SetTransparency()
307    */
308   void SetTransparency( bool transparent );
309
310   /**
311    * @copydoc Dali::KeyGrab::GrabKey()
312    */
313   bool GrabKey( Dali::KEY key, KeyGrab::KeyGrabMode grabMode );
314
315   /**
316    * @copydoc Dali::KeyGrab::UngrabKey()
317    */
318   bool UngrabKey( Dali::KEY key );
319
320   /**
321    * @copydoc Dali::KeyGrab::GrabKeyList()
322    */
323   bool GrabKeyList( const Dali::Vector< Dali::KEY >& key, const Dali::Vector< KeyGrab::KeyGrabMode >& grabMode, Dali::Vector< bool >& result );
324
325   /**
326    * @copydoc Dali::KeyGrab::UngrabKeyList()
327    */
328   bool UngrabKeyList( const Dali::Vector< Dali::KEY >& key, Dali::Vector< bool >& result );
329
330   /**
331    * @copydoc Dali::DevelWindow::Get()
332    */
333   static Dali::Window Get( Dali::Actor actor );
334
335   /**
336    * @copydoc Dali::DevelWindow::SetParent()
337    */
338   void SetParent( Dali::Window& parent );
339
340   /**
341    * @copydoc Dali::DevelWindow::Unparent()
342    */
343   void Unparent();
344
345   /**
346    * @copydoc Dali::DevelWindow::GetParent()
347    */
348   Dali::Window GetParent();
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 private:
363
364   /**
365    * Private constructor.
366    * @sa Window::New()
367    */
368   Window();
369
370   /**
371    * Destructor
372    */
373   virtual ~Window();
374
375   /**
376    * Second stage initialization
377    */
378   void Initialize(const PositionSize& positionSize, const std::string& name, const std::string& className);
379
380   /**
381    * Called when the window becomes iconified or deiconified.
382    */
383   void OnIconifyChanged( bool iconified );
384
385   /**
386    * Called when the window focus is changed.
387    */
388   void OnFocusChanged( bool focusIn );
389
390   /**
391    * Called when the output is transformed.
392    */
393   void OnOutputTransformed();
394
395   /**
396    * Called when the window receives a delete request.
397    */
398   void OnDeleteRequest();
399
400   /**
401    * Called when the window receives a Transition effect-start/end event.
402    */
403   void OnTransitionEffectEvent( DevelWindow::EffectState state, DevelWindow::EffectType type );
404
405 private: // Dali::Internal::Adaptor::SceneHolder
406
407   /**
408    * @copydoc Dali::Internal::Adaptor::SceneHolder::OnAdaptorSet
409    */
410   void OnAdaptorSet( Dali::Adaptor& adaptor ) override;
411
412   /**
413    * @copydoc Dali::Internal::Adaptor::SceneHolder::OnSurfaceSet
414    */
415   void OnSurfaceSet( Dali::RenderSurfaceInterface* surface ) override;
416
417   /**
418    * @copydoc Dali::Internal::Adaptor::SceneHolder::OnPause
419    */
420   void OnPause() override;
421
422   /**
423    * @copydoc Dali::Internal::Adaptor::SceneHolder::OnResume
424    */
425   void OnResume() override;
426
427   /**
428    * @copydoc Dali::Internal::Adaptor::SceneHolder::RecalculateTouchPosition
429    */
430   void RecalculateTouchPosition( Integration::Point& point ) override;
431
432 private: // Dali::Internal::Adaptor::EventHandler::Observer
433
434   /**
435    * @copydoc Dali::Internal::Adaptor::EventHandler::Observer::OnTouchPoint
436    */
437   void OnTouchPoint( Dali::Integration::Point& point, int timeStamp ) override;
438
439   /**
440    * @copydoc Dali::Internal::Adaptor::EventHandler::Observer::OnWheelEvent
441    */
442   void OnWheelEvent( Dali::Integration::WheelEvent& wheelEvent ) override;
443
444   /**
445    * @copydoc Dali::Internal::Adaptor::EventHandler::Observer::OnKeyEvent
446    */
447   void OnKeyEvent( Dali::Integration::KeyEvent& keyEvent ) override;
448
449   /**
450    * @copydoc Dali::Internal::Adaptor::EventHandler::Observer::OnRotation
451    */
452   void OnRotation( const RotationEvent& rotation ) override;
453
454 public: // Signals
455
456   /**
457    * The user should connect to this signal to get a timing when indicator was shown / hidden.
458    */
459   IndicatorSignalType& IndicatorVisibilityChangedSignal() { return mIndicatorVisibilityChangedSignal; }
460
461   /**
462    * @copydoc Dali::Window::FocusChangedSignal()
463    */
464   FocusSignalType& FocusChangedSignal() { return mFocusChangedSignal; }
465
466   /**
467    * @copydoc Dali::Window::WindowFocusChangedSignal()
468    */
469   FocusChangeSignalType& FocusChangeSignal() { return mFocusChangeSignal; }
470   /**
471    * @copydoc Dali::Window::ResizedSignal()
472    */
473   ResizedSignalType& ResizedSignal() { return mResizedSignal; }
474
475   /**
476    * @copydoc Dali::Window::ResizedSignal()
477    */
478   ResizeSignalType& ResizeSignal() { return mResizeSignal; }
479
480   /**
481    * This signal is emitted when the window is requesting to be deleted
482    */
483   SignalType& DeleteRequestSignal() { return mDeleteRequestSignal; }
484
485   /**
486    * @copydoc Dali::DevelWindow::VisibilityChangedSignal()
487    */
488   VisibilityChangedSignalType& VisibilityChangedSignal() { return mVisibilityChangedSignal; }
489
490   /**
491    * @copydoc Dali::Window::SignalEventProcessingFinished()
492    */
493   Dali::DevelWindow::EventProcessingFinishedSignalType& EventProcessingFinishedSignal() { return mScene.EventProcessingFinishedSignal(); }
494
495   /**
496    * @copydoc Dali::DevelWindow::TransitionEffectEventSignal()
497    */
498   TransitionEffectEventSignalType& TransitionEffectEventSignal() { return mTransitionEffectEventSignal; }
499
500 private:
501
502   WindowRenderSurface*                  mWindowSurface;      ///< The window rendering surface
503   WindowBase*                           mWindowBase;
504   std::string                           mName;
505   std::string                           mClassName;
506   bool                                  mIsTransparent:1;
507   bool                                  mIsFocusAcceptable:1;
508   bool                                  mIconified:1;
509   bool                                  mOpaqueState:1;
510   bool                                  mResizeEnabled:1;
511   Dali::Window::Type                    mType;
512   Dali::Window                          mParentWindow;
513
514   OrientationPtr                               mOrientation;
515   std::vector<Dali::Window::WindowOrientation> mAvailableOrientations;
516   Dali::Window::WindowOrientation              mPreferredOrientation;
517
518   int                                   mRotationAngle;     ///< The angle of the rotation
519   int                                   mWindowWidth;       ///< The width of the window
520   int                                   mWindowHeight;      ///< The height of the window
521
522   EventHandlerPtr                       mEventHandler;      ///< The window events handler
523
524   // Signals
525   IndicatorSignalType                   mIndicatorVisibilityChangedSignal;
526   FocusSignalType                       mFocusChangedSignal;
527   ResizedSignalType                     mResizedSignal;
528   SignalType                            mDeleteRequestSignal;
529   FocusChangeSignalType                 mFocusChangeSignal;
530   ResizeSignalType                      mResizeSignal;
531   VisibilityChangedSignalType           mVisibilityChangedSignal;
532   TransitionEffectEventSignalType       mTransitionEffectEventSignal;
533 };
534
535 } // namespace Adaptor
536 } // namepsace Internal
537
538 // Helpers for public-api forwarding methods
539
540 inline Internal::Adaptor::Window& GetImplementation(Dali::Window& window)
541 {
542   DALI_ASSERT_ALWAYS( window && "Window handle is empty" );
543   BaseObject& object = window.GetBaseObject();
544   return static_cast<Internal::Adaptor::Window&>(object);
545 }
546
547 inline const Internal::Adaptor::Window& GetImplementation(const Dali::Window& window)
548 {
549   DALI_ASSERT_ALWAYS( window && "Window handle is empty" );
550   const BaseObject& object = window.GetBaseObject();
551   return static_cast<const Internal::Adaptor::Window&>(object);
552 }
553
554 } // namespace Dali
555
556 #endif // DALI_INTERNAL_WINDOWSYSTEM_COMMON_WINDOW_IMPL_H