[Tizen] Support Ecore-Wayland2
[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) 2018 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
25 // INTERNAL INCLUDES
26 #include <dali/internal/adaptor/common/lifecycle-observer.h>
27 #include <dali/internal/window-system/common/indicator-interface.h>
28 #include <dali/internal/adaptor/common/adaptor-impl.h>
29 #include <dali/public-api/adaptor-framework/window.h>
30 #include <dali/public-api/adaptor-framework/key-grab.h>
31 #include <dali/devel-api/adaptor-framework/drag-and-drop-detector.h>
32
33 namespace Dali
34 {
35 class Adaptor;
36
37 namespace Integration
38 {
39 class SystemOverlay;
40 }
41
42 namespace Internal
43 {
44 namespace Adaptor
45 {
46 class Orientation;
47 class WindowBase;
48 class WindowRenderSurface;
49
50 class Window;
51 typedef IntrusivePtr<Window> WindowPtr;
52 typedef IntrusivePtr<Orientation> OrientationPtr;
53
54 /**
55  * Window provides a surface to render onto with orientation & indicator properties.
56  */
57 class Window : public Dali::BaseObject, public IndicatorInterface::Observer, public LifeCycleObserver
58 {
59 public:
60   typedef Dali::Window::IndicatorSignalType IndicatorSignalType;
61   typedef Dali::Window::FocusSignalType FocusSignalType;
62   typedef Dali::Window::ResizedSignalType ResizedSignalType;
63   typedef Signal< void () > SignalType;
64
65   /**
66    * Create a new Window. This should only be called once by the Application class
67    * @param[in] positionSize The position and size of the window
68    * @param[in] name The window title
69    * @param[in] className The window class name
70    * @param[in] isTransparent Whether window is transparent
71    * @return A newly allocated Window
72    */
73   static Window* New(const PositionSize& positionSize, const std::string& name, const std::string& className, bool isTransparent = false);
74
75   /**
76    * Pass the adaptor back to the overlay. This allows the window to access Core's overlay.
77    * @param[in] adaptor An initialized adaptor
78    */
79   void SetAdaptor(Dali::Adaptor& adaptor);
80
81   /**
82    * Get the window surface
83    * @return The render surface
84    */
85   WindowRenderSurface* GetSurface();
86
87   /**
88    * @copydoc Dali::Window::ShowIndicator()
89    */
90   void ShowIndicator( Dali::Window::IndicatorVisibleMode visibleMode );
91
92   /**
93    * @copydoc Dali::Window::SetIndicatorBgOpacity()
94    */
95   void SetIndicatorBgOpacity( Dali::Window::IndicatorBgOpacity opacity );
96
97   /**
98    * Set the indicator visible mode
99    */
100   void SetIndicatorVisibleMode( Dali::Window::IndicatorVisibleMode mode );
101
102   /**
103    * @copydoc Dali::Window::RotateIndicator()
104    */
105   void RotateIndicator( Dali::Window::WindowOrientation orientation );
106
107   /**
108    * @copydoc Dali::Window::SetClass()
109    */
110   void SetClass( std::string name, std::string className );
111
112   /**
113    * @copydoc Dali::Window::Raise()
114    */
115   void Raise();
116
117   /**
118    * @copydoc Dali::Window::Lower()
119    */
120   void Lower();
121
122   /**
123    * @copydoc Dali::Window::Activate()
124    */
125   void Activate();
126
127   /**
128    * @copydoc Dali::Window::AddAvailableOrientation()
129    */
130   void AddAvailableOrientation(Dali::Window::WindowOrientation orientation);
131
132   /**
133    * @copydoc Dali::Window::RemoveAvailableOrientation()
134    */
135   void RemoveAvailableOrientation(Dali::Window::WindowOrientation orientation);
136
137   /**
138    * @copydoc Dali::Window::SetAvailableOrientations()
139    */
140   void SetAvailableOrientations(const std::vector<Dali::Window::WindowOrientation>& orientations);
141
142   /**
143    * @copydoc Dali::Window::GetAvailableOrientations()
144    */
145   const std::vector<Dali::Window::WindowOrientation>& GetAvailableOrientations();
146
147   /**
148    * @copydoc Dali::Window::SetPreferredOrientation()
149    */
150   void SetPreferredOrientation(Dali::Window::WindowOrientation orientation);
151
152   /**
153    * @copydoc Dali::Window::GetPreferredOrientation()
154    */
155   Dali::Window::WindowOrientation GetPreferredOrientation();
156
157   /**
158    * @copydoc Dali::Window::GetDragAndDropDetector() const
159    */
160   Dali::DragAndDropDetector GetDragAndDropDetector() const;
161
162   /**
163    * @copydoc Dali::Window::GetNativeHandle() const
164    */
165   Dali::Any GetNativeHandle() const;
166
167   /**
168    * @copydoc Dali::Window::SetAcceptFocus()
169    */
170   void SetAcceptFocus( bool accept );
171
172   /**
173    * @copydoc Dali::Window::IsFocusAcceptable()
174    */
175   bool IsFocusAcceptable() const;
176
177   /**
178    * @copydoc Dali::Window::Show()
179    */
180   void Show();
181
182   /**
183    * @copydoc Dali::Window::Hide()
184    */
185   void Hide();
186
187   /**
188    * @copydoc Dali::Window::IsVisible() const
189    */
190   bool IsVisible() const;
191
192   /**
193    * @copydoc Dali::Window::GetSupportedAuxiliaryHintCount()
194    */
195   unsigned int GetSupportedAuxiliaryHintCount() const;
196
197   /**
198    * @copydoc Dali::Window::GetSupportedAuxiliaryHint()
199    */
200   std::string GetSupportedAuxiliaryHint( unsigned int index ) const;
201
202   /**
203    * @copydoc Dali::Window::AddAuxiliaryHint()
204    */
205   unsigned int AddAuxiliaryHint( const std::string& hint, const std::string& value );
206
207   /**
208    * @copydoc Dali::Window::RemoveAuxiliaryHint()
209    */
210   bool RemoveAuxiliaryHint( unsigned int id );
211
212   /**
213    * @copydoc Dali::Window::SetAuxiliaryHintValue()
214    */
215   bool SetAuxiliaryHintValue( unsigned int id, const std::string& value );
216
217   /**
218    * @copydoc Dali::Window::GetAuxiliaryHintValue()
219    */
220   std::string GetAuxiliaryHintValue( unsigned int id ) const;
221
222   /**
223    * @copydoc Dali::Window::GetAuxiliaryHintId()
224    */
225   unsigned int GetAuxiliaryHintId( const std::string& hint ) const;
226
227   /**
228    * @copydoc Dali::Window::SetInputRegion()
229    */
230   void SetInputRegion( const Rect< int >& inputRegion );
231
232   /**
233    * @copydoc Dali::Window::SetType()
234    */
235   void SetType( Dali::Window::Type type );
236
237   /**
238    * @copydoc Dali::Window::GetType() const
239    */
240   Dali::Window::Type GetType() const;
241
242   /**
243    * @copydoc Dali::Window::SetNotificationLevel()
244    */
245   bool SetNotificationLevel( Dali::Window::NotificationLevel::Type level );
246
247   /**
248    * @copydoc Dali::Window::GetNotificationLevel()
249    */
250   Dali::Window::NotificationLevel::Type GetNotificationLevel() const;
251
252   /**
253    * @copydoc Dali::Window::SetOpaqueState()
254    */
255   void SetOpaqueState( bool opaque );
256
257   /**
258    * @copydoc Dali::Window::IsOpaqueState()
259    */
260   bool IsOpaqueState() const;
261
262   /**
263    * @copydoc Dali::Window::SetScreenOffMode()
264    */
265   bool SetScreenOffMode(Dali::Window::ScreenOffMode::Type screenOffMode);
266
267   /**
268    * @copydoc Dali::Window::GetScreenOffMode()
269    */
270   Dali::Window::ScreenOffMode::Type GetScreenOffMode() const;
271
272   /**
273    * @copydoc Dali::Window::SetBrightness()
274    */
275   bool SetBrightness( int brightness );
276
277   /**
278    * @copydoc Dali::Window::GetBrightness()
279    */
280   int GetBrightness() const;
281
282   /**
283    * @copydoc Dali::Window::SetSize()
284    */
285   void SetSize( Dali::Window::WindowSize size );
286
287   /**
288    * @copydoc Dali::Window::GetSize()
289    */
290   Dali::Window::WindowSize GetSize() const;
291
292   /**
293    * @copydoc Dali::Window::SetPosition()
294    */
295   void SetPosition( Dali::Window::WindowPosition position );
296
297   /**
298    * @copydoc Dali::Window::GetPosition()
299    */
300   Dali::Window::WindowPosition GetPosition() const;
301
302   /**
303    * @copydoc Dali::Window::SetTransparency()
304    */
305   void SetTransparency( bool transparent );
306
307   /**
308    * @copydoc Dali::KeyGrab::GrabKey()
309    */
310   bool GrabKey( Dali::KEY key, KeyGrab::KeyGrabMode grabMode );
311
312   /**
313    * @copydoc Dali::KeyGrab::UngrabKey()
314    */
315   bool UngrabKey( Dali::KEY key );
316
317   /**
318    * @copydoc Dali::KeyGrab::GrabKeyList()
319    */
320   bool GrabKeyList( const Dali::Vector< Dali::KEY >& key, const Dali::Vector< KeyGrab::KeyGrabMode >& grabMode, Dali::Vector< bool >& result );
321
322   /**
323    * @copydoc Dali::KeyGrab::UngrabKeyList()
324    */
325   bool UngrabKeyList( const Dali::Vector< Dali::KEY >& key, Dali::Vector< bool >& result );
326
327   /**
328    * Called from Orientation after the Change signal has been sent
329    */
330   void RotationDone( int orientation, int width, int height );
331
332   /**
333    * Called when the window becomes iconified or deiconified.
334    */
335   void OnIconifyChanged( bool iconified );
336
337   /**
338    * Called when the window focus is changed.
339    */
340   void OnFocusChanged( bool focusIn );
341
342   /**
343    * Called when the output is transformed.
344    */
345   void OnOutputTransformed();
346
347   /**
348    * Called when the window receives a delete request
349    */
350   void OnDeleteRequest();
351
352 private:
353   /**
354    * Private constructor.
355    * @sa Window::New()
356    */
357   Window();
358
359   /**
360    * Destructor
361    */
362   virtual ~Window();
363
364   /**
365    * Second stage initialization
366    */
367   void Initialize(const PositionSize& positionSize, const std::string& name, const std::string& className);
368
369   /**
370    * Shows / hides the indicator bar.
371    * Handles close/open if rotation changes whilst hidden
372    */
373   void DoShowIndicator( Dali::Window::WindowOrientation lastOrientation );
374
375   /**
376    * Close current indicator and open a connection onto the new indicator service.
377    * Effect may not be synchronous if waiting for an indicator update on existing connection.
378    */
379   void DoRotateIndicator( Dali::Window::WindowOrientation orientation );
380
381   /**
382    * Change the indicator actor's rotation to match the current orientation
383    */
384   void SetIndicatorActorRotation();
385
386   /**
387    * Set the indicator properties on the window
388    */
389   void SetIndicatorProperties( bool isShow, Dali::Window::WindowOrientation lastOrientation );
390
391 private: // IndicatorInterface::Observer interface
392
393   /**
394    * @copydoc Dali::Internal::Adaptor::IndicatorInterface::Observer::IndicatorTypeChanged()
395    */
396   virtual void IndicatorTypeChanged( IndicatorInterface::Type type );
397
398   /**
399    * @copydoc Dali::Internal::Adaptor::IndicatorInterface::Observer::IndicatorClosed()
400    */
401   virtual void IndicatorClosed( IndicatorInterface* indicator);
402
403   /**
404    * @copydoc Dali::Internal::Adaptor::IndicatorInterface::Observer::IndicatorVisibilityChanged()
405    */
406   virtual void IndicatorVisibilityChanged( bool isVisible );
407
408 private: // Adaptor::Observer interface
409
410   /**
411    * @copydoc Dali::Internal::Adaptor::Adaptor::Observer::OnStart()
412    */
413   virtual void OnStart();
414
415   /**
416    * @copydoc Dali::Internal::Adaptor::Adaptor::Observer::OnPause()
417    */
418   virtual void OnPause();
419
420   /**
421    * @copydoc Dali::Internal::Adaptor::Adaptor::Observer::OnResume()
422    */
423   virtual void OnResume();
424
425   /**
426    * @copydoc Dali::Internal::Adaptor::Adaptor::Observer::OnStop()
427    */
428   virtual void OnStop();
429
430   /**
431    * @copydoc Dali::Internal::Adaptor::Adaptor::Observer::OnDestroy()
432    */
433   virtual void OnDestroy();
434
435 public: // Signals
436
437   /**
438    * The user should connect to this signal to get a timing when indicator was shown / hidden.
439    */
440   IndicatorSignalType& IndicatorVisibilityChangedSignal() { return mIndicatorVisibilityChangedSignal; }
441
442   /**
443    * @copydoc Dali::Window::FocusChangedSignal()
444    */
445   FocusSignalType& FocusChangedSignal() { return mFocusChangedSignal; }
446
447   /**
448    * @copydoc Dali::Window::ResizedSignal()
449    */
450   ResizedSignalType& ResizedSignal() { return mResizedSignal; }
451
452   /**
453    * This signal is emitted when the window is requesting to be deleted
454    */
455   SignalType& DeleteRequestSignal() { return mDeleteRequestSignal; }
456
457 private:
458
459   WindowRenderSurface*                  mSurface;
460   std::unique_ptr< WindowBase >         mWindowBase;
461   Dali::Window::IndicatorVisibleMode    mIndicatorVisible; ///< public state
462   bool                                  mIndicatorIsShown:1; ///< private state
463   bool                                  mShowRotatedIndicatorOnClose:1;
464   bool                                  mStarted:1;
465   bool                                  mIsTransparent:1;
466   bool                                  mIsFocusAcceptable:1;
467   bool                                  mVisible:1;
468   bool                                  mIconified:1;
469   bool                                  mOpaqueState:1;
470   bool                                  mResizeEnabled:1;
471   std::unique_ptr< IndicatorInterface > mIndicator;
472   Dali::Window::WindowOrientation       mIndicatorOrientation;
473   Dali::Window::WindowOrientation       mNextIndicatorOrientation;
474   Dali::Window::IndicatorBgOpacity      mIndicatorOpacityMode;
475   Integration::SystemOverlay*           mOverlay;
476   Adaptor*                              mAdaptor;
477   Dali::DragAndDropDetector             mDragAndDropDetector;
478   Dali::Window::Type                    mType;
479
480   OrientationPtr                               mOrientation;
481   std::vector<Dali::Window::WindowOrientation> mAvailableOrientations;
482   Dali::Window::WindowOrientation              mPreferredOrientation;
483
484   // Signals
485   IndicatorSignalType mIndicatorVisibilityChangedSignal;
486   FocusSignalType     mFocusChangedSignal;
487   ResizedSignalType   mResizedSignal;
488   SignalType          mDeleteRequestSignal;
489 };
490
491 } // namespace Adaptor
492 } // namepsace Internal
493
494 // Helpers for public-api forwarding methods
495
496 inline Internal::Adaptor::Window& GetImplementation(Dali::Window& window)
497 {
498   DALI_ASSERT_ALWAYS( window && "Window handle is empty" );
499   BaseObject& object = window.GetBaseObject();
500   return static_cast<Internal::Adaptor::Window&>(object);
501 }
502
503 inline const Internal::Adaptor::Window& GetImplementation(const Dali::Window& window)
504 {
505   DALI_ASSERT_ALWAYS( window && "Window handle is empty" );
506   const BaseObject& object = window.GetBaseObject();
507   return static_cast<const Internal::Adaptor::Window&>(object);
508 }
509
510 } // namespace Dali
511
512 #endif // DALI_INTERNAL_WINDOWSYSTEM_COMMON_WINDOW_IMPL_H