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