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