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