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