Merge remote-tracking branch 'origin/tizen' into new_text
[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
38 namespace Integration
39 {
40 class SystemOverlay;
41 }
42
43 namespace Internal
44 {
45 namespace Adaptor
46 {
47 class RenderSurface;
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::SetIndicatorStyle()
86    */
87   void SetIndicatorStyle( Dali::Window::IndicatorStyle style );
88
89   /**
90    * @copydoc Dali::Window::ShowIndicator()
91    */
92   void ShowIndicator( Dali::Window::IndicatorVisibleMode visibleMode );
93
94   /**
95    * @copydoc Dali::Window::SetIndicatorBgOpacity()
96    */
97   void SetIndicatorBgOpacity( Dali::Window::IndicatorBgOpacity opacity );
98
99   /**
100    * @copydoc Dali::Window::RotateIndicator()
101    */
102   void RotateIndicator( Dali::Window::WindowOrientation orientation );
103
104   /**
105    * @copydoc Dali::Window::SetClass()
106    */
107   void SetClass( std::string name, std::string klass );
108
109   /**
110    * @copydoc Dali::Window::Raise()
111    */
112   void Raise();
113
114   /**
115    * @copydoc Dali::Window::Lower()
116    */
117   void Lower();
118
119   /**
120    * @copydoc Dali::Window::Activate()
121    */
122   void Activate();
123
124   /**
125    * @copydoc Dali::Window::GetOrientation()
126    */
127   OrientationPtr GetOrientation();
128
129   /**
130    * @copydoc Dali::Window::AddAvailableOrientation()
131    */
132   void AddAvailableOrientation(Dali::Window::WindowOrientation orientation);
133
134   /**
135    * @copydoc Dali::Window::RemoveAvailableOrientation()
136    */
137   void RemoveAvailableOrientation(Dali::Window::WindowOrientation orientation);
138
139   /**
140    * @copydoc Dali::Window::SetAvailableOrientations()
141    */
142   void SetAvailableOrientations(const std::vector<Dali::Window::WindowOrientation>& orientations);
143
144   /**
145    * @copydoc Dali::Window::GetAvailableOrientations()
146    */
147   const std::vector<Dali::Window::WindowOrientation>& GetAvailableOrientations();
148
149   /**
150    * @copydoc Dali::Window::SetPreferredOrientation()
151    */
152   void SetPreferredOrientation(Dali::Window::WindowOrientation orientation);
153
154   /**
155    * @copydoc Dali::Window::GetPreferredOrientation()
156    */
157   Dali::Window::WindowOrientation GetPreferredOrientation();
158
159   /**
160    * @copydoc Dali::Window::GetDragAndDropDetector() const
161    */
162   Dali::DragAndDropDetector GetDragAndDropDetector() const;
163
164   /**
165    * @copydoc Dali::Window::GetNativeHandle() const
166    */
167   Dali::Any GetNativeHandle() const;
168
169   /**
170    * Called from Orientation after the Change signal has been sent
171    */
172   void RotationDone( int orientation, int width, int height );
173
174 private:
175   /**
176    * Private constructor.
177    * @sa Window::New()
178    */
179   Window();
180
181   /**
182    * Destructor
183    */
184   virtual ~Window();
185
186   /**
187    * Second stage initialization
188    */
189   void Initialize(const PositionSize& posSize, const std::string& name);
190
191   /**
192    * Shows / hides the indicator bar.
193    * Handles close/open if rotation changes whilst hidden
194    */
195   void DoShowIndicator( Dali::Window::WindowOrientation lastOrientation );
196
197   /**
198    * Close current indicator and open a connection onto the new indicator service.
199    * Effect may not be synchronous if waiting for an indicator update on existing connection.
200    */
201   void DoRotateIndicator( Dali::Window::WindowOrientation orientation );
202
203   /**
204    * Change the indicator actor's rotation to match the current orientation
205    */
206   void SetIndicatorActorRotation();
207
208   /**
209    * Set the indicator properties on the window
210    */
211   void SetIndicatorProperties( bool isShown, Dali::Window::WindowOrientation lastOrientation );
212
213 private: // Indicator::Observer interface
214
215   /**
216    * @copydoc Dali::Internal::Adaptor::Indicator::Observer::IndicatorTypeChanged()
217    */
218   virtual void IndicatorTypeChanged( Indicator::Type type );
219
220   /**
221    * @copydoc Dali::Internal::Adaptor::Indicator::Observer::IndicatorClosed()
222    */
223   virtual void IndicatorClosed(Indicator* indicator);
224
225   /**
226    * @copydoc Dali::Internal::Adaptor::Indicator::Observer::IndicatorVisibilityChanged()
227    */
228   virtual void IndicatorVisibilityChanged( bool isVisible );
229
230 private: // Adaptor::Observer interface
231
232   /**
233    * @copydoc Dali::Internal::Adaptor::Adaptor::Observer::OnStart()
234    */
235   virtual void OnStart();
236
237   /**
238    * @copydoc Dali::Internal::Adaptor::Adaptor::Observer::OnPause()
239    */
240   virtual void OnPause();
241
242   /**
243    * @copydoc Dali::Internal::Adaptor::Adaptor::Observer::OnResume()
244    */
245   virtual void OnResume();
246
247   /**
248    * @copydoc Dali::Internal::Adaptor::Adaptor::Observer::OnStop()
249    */
250   virtual void OnStop();
251
252   /**
253    * @copydoc Dali::Internal::Adaptor::Adaptor::Observer::OnDestroy()
254    */
255   virtual void OnDestroy();
256
257 public: // Signals
258   /**
259    * The user should connect to this signal to get a timing when indicator was shown / hidden.
260    */
261   IndicatorSignalType& IndicatorVisibilityChangedSignal() { return mIndicatorVisibilityChangedSignal; }
262
263 private:
264
265   typedef std::vector<Indicator*> DiscardedIndicators;
266
267   RenderSurface*                   mSurface;
268   Dali::Window::IndicatorStyle     mIndicatorStyle;     ///< indicator style
269   Dali::Window::IndicatorVisibleMode mIndicatorVisible; ///< public state
270   bool                             mIndicatorIsShown:1; ///< private state
271   bool                             mShowRotatedIndicatorOnClose:1;
272   bool                             mStarted:1;
273   bool                             mIsTransparent:1;
274   bool                             mWMRotationAppSet:1;
275   Indicator*                       mIndicator;
276   Dali::Window::WindowOrientation  mIndicatorOrientation;
277   Dali::Window::WindowOrientation  mNextIndicatorOrientation;
278   Dali::Window::IndicatorBgOpacity mIndicatorOpacityMode;
279   Integration::SystemOverlay*      mOverlay;
280   Adaptor*                         mAdaptor;
281   Dali::DragAndDropDetector        mDragAndDropDetector;
282
283   struct EventHandler;
284   EventHandler*                    mEventHandler;
285
286   OrientationPtr                               mOrientation;
287   std::vector<Dali::Window::WindowOrientation> mAvailableOrientations;
288   Dali::Window::WindowOrientation              mPreferredOrientation;
289
290   // Signals
291   IndicatorSignalType mIndicatorVisibilityChangedSignal;
292 };
293
294 } // namespace Adaptor
295 } // namepsace Internal
296
297 // Helpers for public-api forwarding methods
298
299 inline Internal::Adaptor::Window& GetImplementation(Dali::Window& window)
300 {
301   DALI_ASSERT_ALWAYS( window && "Window handle is empty" );
302   BaseObject& object = window.GetBaseObject();
303   return static_cast<Internal::Adaptor::Window&>(object);
304 }
305
306 inline const Internal::Adaptor::Window& GetImplementation(const Dali::Window& window)
307 {
308   DALI_ASSERT_ALWAYS( window && "Window handle is empty" );
309   const BaseObject& object = window.GetBaseObject();
310   return static_cast<const Internal::Adaptor::Window&>(object);
311 }
312
313 } // namespace Dali
314
315
316 #endif // __DALI_INTERNAL_WINDOW_H__