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