Merge "libuv support for dali-adaptor for running in Node.JS" 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) 2014 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 <adaptor-impl.h>
28 #include <indicator-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 Indicator;
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 Indicator::Observer, public LifeCycleObserver
59 {
60 public:
61   typedef Dali::Window::IndicatorSignalType IndicatorSignalType;
62
63   /**
64    * Create a new Window. This should only be called once by the Application class
65    * @param[in] windowPosition The position and size of the window
66    * @param[in] name The window title
67    * @param[in] isTransparent Whether window is transparent
68    * @return A newly allocated Window
69    */
70   static Window* New(const PositionSize& posSize, const std::string& name, bool isTransparent = false);
71
72   /**
73    * Pass the adaptor back to the overlay. This allows the window to access Core's overlay.
74    * @param[in] adaptor An initialized adaptor
75    */
76   void SetAdaptor(Dali::Adaptor& adaptor);
77
78   /**
79    * Get the window surface
80    * @return The render surface
81    */
82   RenderSurface* GetSurface();
83
84   /**
85    * @copydoc Dali::Window::ShowIndicator()
86    */
87   void ShowIndicator( Dali::Window::IndicatorVisibleMode visibleMode );
88
89   /**
90    * @copydoc Dali::Window::SetIndicatorBgOpacity()
91    */
92   void SetIndicatorBgOpacity( Dali::Window::IndicatorBgOpacity opacity );
93
94   /**
95    * @copydoc Dali::Window::RotateIndicator()
96    */
97   void RotateIndicator( Dali::Window::WindowOrientation orientation );
98
99   /**
100    * @copydoc Dali::Window::SetClass()
101    */
102   void SetClass( std::string name, std::string klass );
103
104   /**
105    * @copydoc Dali::Window::Raise()
106    */
107   void Raise();
108
109   /**
110    * @copydoc Dali::Window::Lower()
111    */
112   void Lower();
113
114   /**
115    * @copydoc Dali::Window::Activate()
116    */
117   void Activate();
118
119   /**
120    * @copydoc Dali::Window::AddAvailableOrientation()
121    */
122   void AddAvailableOrientation(Dali::Window::WindowOrientation orientation);
123
124   /**
125    * @copydoc Dali::Window::RemoveAvailableOrientation()
126    */
127   void RemoveAvailableOrientation(Dali::Window::WindowOrientation orientation);
128
129   /**
130    * @copydoc Dali::Window::SetAvailableOrientations()
131    */
132   void SetAvailableOrientations(const std::vector<Dali::Window::WindowOrientation>& orientations);
133
134   /**
135    * @copydoc Dali::Window::GetAvailableOrientations()
136    */
137   const std::vector<Dali::Window::WindowOrientation>& GetAvailableOrientations();
138
139   /**
140    * @copydoc Dali::Window::SetPreferredOrientation()
141    */
142   void SetPreferredOrientation(Dali::Window::WindowOrientation orientation);
143
144   /**
145    * @copydoc Dali::Window::GetPreferredOrientation()
146    */
147   Dali::Window::WindowOrientation GetPreferredOrientation();
148
149   /**
150    * @copydoc Dali::Window::GetDragAndDropDetector() const
151    */
152   Dali::DragAndDropDetector GetDragAndDropDetector() const;
153
154   /**
155    * @copydoc Dali::Window::GetNativeHandle() const
156    */
157   Dali::Any GetNativeHandle() const;
158
159   /**
160    * Called from Orientation after the Change signal has been sent
161    */
162   void RotationDone( int orientation, int width, int height );
163
164 private:
165   /**
166    * Private constructor.
167    * @sa Window::New()
168    */
169   Window();
170
171   /**
172    * Destructor
173    */
174   virtual ~Window();
175
176   /**
177    * Second stage initialization
178    */
179   void Initialize(const PositionSize& posSize, const std::string& name);
180
181   /**
182    * Shows / hides the indicator bar.
183    * Handles close/open if rotation changes whilst hidden
184    */
185   void DoShowIndicator( Dali::Window::WindowOrientation lastOrientation );
186
187   /**
188    * Close current indicator and open a connection onto the new indicator service.
189    * Effect may not be synchronous if waiting for an indicator update on existing connection.
190    */
191   void DoRotateIndicator( Dali::Window::WindowOrientation orientation );
192
193   /**
194    * Change the indicator actor's rotation to match the current orientation
195    */
196   void SetIndicatorActorRotation();
197
198   /**
199    * Set the indicator properties on the window
200    */
201   void SetIndicatorProperties( bool isShown, Dali::Window::WindowOrientation lastOrientation );
202
203 private: // Indicator::Observer interface
204
205   /**
206    * @copydoc Dali::Internal::Adaptor::Indicator::Observer::IndicatorTypeChanged()
207    */
208   virtual void IndicatorTypeChanged( Indicator::Type type );
209
210   /**
211    * @copydoc Dali::Internal::Adaptor::Indicator::Observer::IndicatorClosed()
212    */
213   virtual void IndicatorClosed(Indicator* indicator);
214
215   /**
216    * @copydoc Dali::Internal::Adaptor::Indicator::Observer::IndicatorVisibilityChanged()
217    */
218   virtual void IndicatorVisibilityChanged( bool isVisible );
219
220 private: // Adaptor::Observer interface
221
222   /**
223    * @copydoc Dali::Internal::Adaptor::Adaptor::Observer::OnStart()
224    */
225   virtual void OnStart();
226
227   /**
228    * @copydoc Dali::Internal::Adaptor::Adaptor::Observer::OnPause()
229    */
230   virtual void OnPause();
231
232   /**
233    * @copydoc Dali::Internal::Adaptor::Adaptor::Observer::OnResume()
234    */
235   virtual void OnResume();
236
237   /**
238    * @copydoc Dali::Internal::Adaptor::Adaptor::Observer::OnStop()
239    */
240   virtual void OnStop();
241
242   /**
243    * @copydoc Dali::Internal::Adaptor::Adaptor::Observer::OnDestroy()
244    */
245   virtual void OnDestroy();
246
247 public: // Signals
248   /**
249    * The user should connect to this signal to get a timing when indicator was shown / hidden.
250    */
251   IndicatorSignalType& IndicatorVisibilityChangedSignal() { return mIndicatorVisibilityChangedSignal; }
252
253 private:
254
255   typedef std::vector<Indicator*> DiscardedIndicators;
256
257   RenderSurface*                   mSurface;
258   Dali::Window::IndicatorVisibleMode mIndicatorVisible; ///< public state
259   bool                             mIndicatorIsShown:1; ///< private state
260   bool                             mShowRotatedIndicatorOnClose:1;
261   bool                             mStarted:1;
262   bool                             mIsTransparent:1;
263   bool                             mWMRotationAppSet:1;
264   bool                             mEcoreEventHander:1;
265   Indicator*                       mIndicator;
266   Dali::Window::WindowOrientation  mIndicatorOrientation;
267   Dali::Window::WindowOrientation  mNextIndicatorOrientation;
268   Dali::Window::IndicatorBgOpacity mIndicatorOpacityMode;
269   Integration::SystemOverlay*      mOverlay;
270   Adaptor*                         mAdaptor;
271   Dali::DragAndDropDetector        mDragAndDropDetector;
272
273   struct EventHandler;
274   EventHandler*                    mEventHandler;
275
276   OrientationPtr                               mOrientation;
277   std::vector<Dali::Window::WindowOrientation> mAvailableOrientations;
278   Dali::Window::WindowOrientation              mPreferredOrientation;
279
280   // Signals
281   IndicatorSignalType mIndicatorVisibilityChangedSignal;
282 };
283
284 } // namespace Adaptor
285 } // namepsace Internal
286
287 // Helpers for public-api forwarding methods
288
289 inline Internal::Adaptor::Window& GetImplementation(Dali::Window& window)
290 {
291   DALI_ASSERT_ALWAYS( window && "Window handle is empty" );
292   BaseObject& object = window.GetBaseObject();
293   return static_cast<Internal::Adaptor::Window&>(object);
294 }
295
296 inline const Internal::Adaptor::Window& GetImplementation(const Dali::Window& window)
297 {
298   DALI_ASSERT_ALWAYS( window && "Window handle is empty" );
299   const BaseObject& object = window.GetBaseObject();
300   return static_cast<const Internal::Adaptor::Window&>(object);
301 }
302
303 } // namespace Dali
304
305
306 #endif // __DALI_INTERNAL_WINDOW_H__