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