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