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