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
175 private:
176   /**
177    * Private constructor.
178    * @sa Window::New()
179    */
180   Window();
181
182   /**
183    * Destructor
184    */
185   virtual ~Window();
186
187   /**
188    * Second stage initialization
189    */
190   void Initialize(const PositionSize& posSize, const std::string& name);
191
192   /**
193    * Shows / hides the indicator bar.
194    * Handles close/open if rotation changes whilst hidden
195    */
196   void DoShowIndicator( Dali::Window::WindowOrientation lastOrientation );
197
198   /**
199    * Close current indicator and open a connection onto the new indicator service.
200    * Effect may not be synchronous if waiting for an indicator update on existing connection.
201    */
202   void DoRotateIndicator( Dali::Window::WindowOrientation orientation );
203
204   /**
205    * Change the indicator actor's rotation to match the current orientation
206    */
207   void SetIndicatorActorRotation();
208
209   /**
210    * Set the indicator properties on the window
211    */
212   void SetIndicatorProperties( bool isShown, Dali::Window::WindowOrientation lastOrientation );
213
214 private: // Indicator::Observer interface
215
216   /**
217    * @copydoc Dali::Internal::Adaptor::Indicator::Observer::IndicatorTypeChanged()
218    */
219   virtual void IndicatorTypeChanged( Indicator::Type type );
220
221   /**
222    * @copydoc Dali::Internal::Adaptor::Indicator::Observer::IndicatorClosed()
223    */
224   virtual void IndicatorClosed(Indicator* indicator);
225
226   /**
227    * @copydoc Dali::Internal::Adaptor::Indicator::Observer::IndicatorVisibilityChanged()
228    */
229   virtual void IndicatorVisibilityChanged( bool isVisible );
230
231 private: // Adaptor::Observer interface
232
233   /**
234    * @copydoc Dali::Internal::Adaptor::Adaptor::Observer::OnStart()
235    */
236   virtual void OnStart();
237
238   /**
239    * @copydoc Dali::Internal::Adaptor::Adaptor::Observer::OnPause()
240    */
241   virtual void OnPause();
242
243   /**
244    * @copydoc Dali::Internal::Adaptor::Adaptor::Observer::OnResume()
245    */
246   virtual void OnResume();
247
248   /**
249    * @copydoc Dali::Internal::Adaptor::Adaptor::Observer::OnStop()
250    */
251   virtual void OnStop();
252
253   /**
254    * @copydoc Dali::Internal::Adaptor::Adaptor::Observer::OnDestroy()
255    */
256   virtual void OnDestroy();
257
258 public: // Signals
259   /**
260    * The user should connect to this signal to get a timing when indicator was shown / hidden.
261    */
262   IndicatorSignalType& IndicatorVisibilityChangedSignal() { return mIndicatorVisibilityChangedSignal; }
263
264 private:
265
266   typedef std::vector<Indicator*> DiscardedIndicators;
267
268   RenderSurface*                   mSurface;
269   Dali::Window::IndicatorStyle     mIndicatorStyle;     ///< indicator style
270   Dali::Window::IndicatorVisibleMode mIndicatorVisible; ///< public state
271   bool                             mIndicatorIsShown:1; ///< private state
272   bool                             mShowRotatedIndicatorOnClose:1;
273   bool                             mStarted:1;
274   bool                             mIsTransparent:1;
275   bool                             mWMRotationAppSet:1;
276   Indicator*                       mIndicator;
277   Dali::Window::WindowOrientation  mIndicatorOrientation;
278   Dali::Window::WindowOrientation  mNextIndicatorOrientation;
279   Dali::Window::IndicatorBgOpacity mIndicatorOpacityMode;
280   Integration::SystemOverlay*      mOverlay;
281   Adaptor*                         mAdaptor;
282   Dali::DragAndDropDetector        mDragAndDropDetector;
283
284   struct EventHandler;
285   EventHandler*                    mEventHandler;
286
287   OrientationPtr                               mOrientation;
288   std::vector<Dali::Window::WindowOrientation> mAvailableOrientations;
289   Dali::Window::WindowOrientation              mPreferredOrientation;
290
291   // Signals
292   IndicatorSignalType mIndicatorVisibilityChangedSignal;
293 };
294
295 } // namespace Adaptor
296 } // namepsace Internal
297
298 // Helpers for public-api forwarding methods
299
300 inline Internal::Adaptor::Window& GetImplementation(Dali::Window& window)
301 {
302   DALI_ASSERT_ALWAYS( window && "Window handle is empty" );
303   BaseObject& object = window.GetBaseObject();
304   return static_cast<Internal::Adaptor::Window&>(object);
305 }
306
307 inline const Internal::Adaptor::Window& GetImplementation(const Dali::Window& window)
308 {
309   DALI_ASSERT_ALWAYS( window && "Window handle is empty" );
310   const BaseObject& object = window.GetBaseObject();
311   return static_cast<const Internal::Adaptor::Window&>(object);
312 }
313
314 } // namespace Dali
315
316
317 #endif // __DALI_INTERNAL_WINDOW_H__