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