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