[dali_1.2.60] 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 private:
308   /**
309    * Private constructor.
310    * @sa Window::New()
311    */
312   Window();
313
314   /**
315    * Destructor
316    */
317   virtual ~Window();
318
319   /**
320    * Second stage initialization
321    */
322   void Initialize(const PositionSize& positionSize, const std::string& name, const std::string& className);
323
324   /**
325    * Shows / hides the indicator bar.
326    * Handles close/open if rotation changes whilst hidden
327    */
328   void DoShowIndicator( Dali::Window::WindowOrientation lastOrientation );
329
330   /**
331    * Close current indicator and open a connection onto the new indicator service.
332    * Effect may not be synchronous if waiting for an indicator update on existing connection.
333    */
334   void DoRotateIndicator( Dali::Window::WindowOrientation orientation );
335
336   /**
337    * Change the indicator actor's rotation to match the current orientation
338    */
339   void SetIndicatorActorRotation();
340
341   /**
342    * Set the indicator properties on the window
343    */
344   void SetIndicatorProperties( bool isShown, Dali::Window::WindowOrientation lastOrientation );
345
346 private: // IndicatorInterface::Observer interface
347
348   /**
349    * @copydoc Dali::Internal::Adaptor::IndicatorInterface::Observer::IndicatorTypeChanged()
350    */
351   virtual void IndicatorTypeChanged( IndicatorInterface::Type type );
352
353   /**
354    * @copydoc Dali::Internal::Adaptor::IndicatorInterface::Observer::IndicatorClosed()
355    */
356   virtual void IndicatorClosed( IndicatorInterface* indicator);
357
358   /**
359    * @copydoc Dali::Internal::Adaptor::IndicatorInterface::Observer::IndicatorVisibilityChanged()
360    */
361   virtual void IndicatorVisibilityChanged( bool isVisible );
362
363 private: // Adaptor::Observer interface
364
365   /**
366    * @copydoc Dali::Internal::Adaptor::Adaptor::Observer::OnStart()
367    */
368   virtual void OnStart();
369
370   /**
371    * @copydoc Dali::Internal::Adaptor::Adaptor::Observer::OnPause()
372    */
373   virtual void OnPause();
374
375   /**
376    * @copydoc Dali::Internal::Adaptor::Adaptor::Observer::OnResume()
377    */
378   virtual void OnResume();
379
380   /**
381    * @copydoc Dali::Internal::Adaptor::Adaptor::Observer::OnStop()
382    */
383   virtual void OnStop();
384
385   /**
386    * @copydoc Dali::Internal::Adaptor::Adaptor::Observer::OnDestroy()
387    */
388   virtual void OnDestroy();
389
390 public: // Signals
391
392   /**
393    * The user should connect to this signal to get a timing when indicator was shown / hidden.
394    */
395   IndicatorSignalType& IndicatorVisibilityChangedSignal() { return mIndicatorVisibilityChangedSignal; }
396
397   /**
398    * @copydoc Dali::Window::FocusChangedSignal()
399    */
400   FocusSignalType& FocusChangedSignal() { return mFocusChangedSignal; }
401
402   /**
403    * @copydoc Dali::Window::ResizedSignal()
404    */
405   ResizedSignalType& ResizedSignal() { return mResizedSignal; }
406
407   /**
408    * This signal is emitted when the window is requesting to be deleted
409    */
410   SignalType& DeleteRequestSignal() { return mDeleteRequestSignal; }
411
412 private:
413
414   typedef std::vector< std::pair< std::string, std::string > > AuxiliaryHints;
415
416   RenderSurface*                   mSurface;
417   Dali::Window::IndicatorVisibleMode mIndicatorVisible; ///< public state
418   bool                             mIndicatorIsShown:1; ///< private state
419   bool                             mShowRotatedIndicatorOnClose:1;
420   bool                             mStarted:1;
421   bool                             mIsTransparent:1;
422   bool                             mWMRotationAppSet:1;
423   bool                             mEcoreEventHander:1;
424   bool                             mIsFocusAcceptable:1;
425   bool                             mVisible:1;
426   bool                             mOpaqueState:1;
427   bool                             mResizeEnabled:1;
428   IndicatorInterface*              mIndicator;
429   Dali::Window::WindowOrientation  mIndicatorOrientation;
430   Dali::Window::WindowOrientation  mNextIndicatorOrientation;
431   Dali::Window::IndicatorBgOpacity mIndicatorOpacityMode;
432   Integration::SystemOverlay*      mOverlay;
433   Adaptor*                         mAdaptor;
434   Dali::DragAndDropDetector        mDragAndDropDetector;
435   Dali::Window::Type          mType;
436
437   struct EventHandler;
438   EventHandler*                    mEventHandler;
439
440   OrientationPtr                               mOrientation;
441   std::vector<Dali::Window::WindowOrientation> mAvailableOrientations;
442   Dali::Window::WindowOrientation              mPreferredOrientation;
443
444   std::vector< std::string >        mSupportedAuxiliaryHints;
445   AuxiliaryHints                    mAuxiliaryHints;
446
447   // Signals
448   IndicatorSignalType mIndicatorVisibilityChangedSignal;
449   FocusSignalType     mFocusChangedSignal;
450   ResizedSignalType   mResizedSignal;
451   SignalType          mDeleteRequestSignal;
452 };
453
454 } // namespace Adaptor
455 } // namepsace Internal
456
457 // Helpers for public-api forwarding methods
458
459 inline Internal::Adaptor::Window& GetImplementation(Dali::Window& window)
460 {
461   DALI_ASSERT_ALWAYS( window && "Window handle is empty" );
462   BaseObject& object = window.GetBaseObject();
463   return static_cast<Internal::Adaptor::Window&>(object);
464 }
465
466 inline const Internal::Adaptor::Window& GetImplementation(const Dali::Window& window)
467 {
468   DALI_ASSERT_ALWAYS( window && "Window handle is empty" );
469   const BaseObject& object = window.GetBaseObject();
470   return static_cast<const Internal::Adaptor::Window&>(object);
471 }
472
473 } // namespace Dali
474
475
476 #endif // __DALI_INTERNAL_WINDOW_H__