Merge "Only make indicator visible when its actually needed" 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 #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   /**
63    * Create a new Window. This should only be called once by the Application class
64    * @param[in] windowPosition The position and size of the window
65    * @param[in] name The window title
66    * @param[in] isTransparent Whether window is transparent
67    * @return A newly allocated Window
68    */
69   static Window* New(const PositionSize& posSize, const std::string& name, bool isTransparent = false);
70
71   /**
72    * Pass the adaptor back to the overlay. This allows the window to access Core's overlay.
73    * @param[in] adaptor An initialized adaptor
74    */
75   void SetAdaptor(Dali::Adaptor& adaptor);
76
77   /**
78    * Get the window surface
79    * @return The render surface
80    */
81   RenderSurface* GetSurface();
82
83   /**
84    * @copydoc Dali::Window::SetIndicatorStyle()
85    */
86   void SetIndicatorStyle( Dali::Window::IndicatorStyle style );
87
88   /**
89    * @copydoc Dali::Window::ShowIndicator()
90    */
91   void ShowIndicator( Dali::Window::IndicatorVisibleMode visibleMode );
92
93   /**
94    * @copydoc Dali::Window::SetIndicatorBgOpacity()
95    */
96   void SetIndicatorBgOpacity( Dali::Window::IndicatorBgOpacity opacity );
97
98   /**
99    * @copydoc Dali::Window::RotateIndicator()
100    */
101   void RotateIndicator( Dali::Window::WindowOrientation orientation );
102
103   /**
104    * @copydoc Dali::Window::SetClass()
105    */
106   void SetClass( std::string name, std::string klass );
107
108   /**
109    * @copydoc Dali::Window::Raise()
110    */
111   void Raise();
112
113   /**
114    * @copydoc Dali::Window::Lower()
115    */
116   void Lower();
117
118   /**
119    * @copydoc Dali::Window::Activate()
120    */
121   void Activate();
122
123   /**
124    * @copydoc Dali::Window::GetOrientation()
125    */
126   OrientationPtr GetOrientation();
127
128   /**
129    * @copydoc Dali::Window::AddAvailableOrientation()
130    */
131   void AddAvailableOrientation(Dali::Window::WindowOrientation orientation);
132
133   /**
134    * @copydoc Dali::Window::RemoveAvailableOrientation()
135    */
136   void RemoveAvailableOrientation(Dali::Window::WindowOrientation orientation);
137
138   /**
139    * @copydoc Dali::Window::SetAvailableOrientations()
140    */
141   void SetAvailableOrientations(const std::vector<Dali::Window::WindowOrientation>& orientations);
142
143   /**
144    * @copydoc Dali::Window::GetAvailableOrientations()
145    */
146   const std::vector<Dali::Window::WindowOrientation>& GetAvailableOrientations();
147
148   /**
149    * @copydoc Dali::Window::SetPreferredOrientation()
150    */
151   void SetPreferredOrientation(Dali::Window::WindowOrientation orientation);
152
153   /**
154    * @copydoc Dali::Window::GetPreferredOrientation()
155    */
156   Dali::Window::WindowOrientation GetPreferredOrientation();
157
158   /**
159    * @copydoc Dali::Window::GetDragAndDropDetector() const
160    */
161   Dali::DragAndDropDetector GetDragAndDropDetector() const;
162
163   /**
164    * @copydoc Dali::Window::GetNativeHandle() const
165    */
166   Dali::Any GetNativeHandle() const;
167
168   /**
169    * Called from Orientation after the Change signal has been sent
170    */
171   void RotationDone( int orientation, int width, int height );
172
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 private: // Adaptor::Observer interface
226
227   /**
228    * @copydoc Dali::Internal::Adaptor::Adaptor::Observer::OnStart()
229    */
230   virtual void OnStart();
231
232   /**
233    * @copydoc Dali::Internal::Adaptor::Adaptor::Observer::OnPause()
234    */
235   virtual void OnPause();
236
237   /**
238    * @copydoc Dali::Internal::Adaptor::Adaptor::Observer::OnResume()
239    */
240   virtual void OnResume();
241
242   /**
243    * @copydoc Dali::Internal::Adaptor::Adaptor::Observer::OnStop()
244    */
245   virtual void OnStop();
246
247   /**
248    * @copydoc Dali::Internal::Adaptor::Adaptor::Observer::OnDestroy()
249    */
250   virtual void OnDestroy();
251
252 private:
253
254   typedef std::vector<Indicator*> DiscardedIndicators;
255
256   RenderSurface*                   mSurface;
257   Dali::Window::IndicatorStyle     mIndicatorStyle;     ///< indicator style
258   Dali::Window::IndicatorVisibleMode mIndicatorVisible; ///< public state
259   bool                             mIndicatorIsShown:1; ///< private state
260   bool                             mShowRotatedIndicatorOnClose:1;
261   bool                             mStarted:1;
262   bool                             mIsTransparent:1;
263   bool                             mWMRotationAppSet:1;
264   Indicator*                       mIndicator;
265   Dali::Window::WindowOrientation  mIndicatorOrientation;
266   Dali::Window::WindowOrientation  mNextIndicatorOrientation;
267   Dali::Window::IndicatorBgOpacity mIndicatorOpacityMode;
268   Integration::SystemOverlay*      mOverlay;
269   Adaptor*                         mAdaptor;
270   Dali::DragAndDropDetector        mDragAndDropDetector;
271
272   struct EventHandler;
273   EventHandler*                    mEventHandler;
274
275   OrientationPtr                               mOrientation;
276   std::vector<Dali::Window::WindowOrientation> mAvailableOrientations;
277   Dali::Window::WindowOrientation              mPreferredOrientation;
278 };
279
280 } // namespace Adaptor
281 } // namepsace Internal
282
283 // Helpers for public-api forwarding methods
284
285 inline Internal::Adaptor::Window& GetImplementation(Dali::Window& window)
286 {
287   DALI_ASSERT_ALWAYS( window && "Window handle is empty" );
288   BaseObject& object = window.GetBaseObject();
289   return static_cast<Internal::Adaptor::Window&>(object);
290 }
291
292 inline const Internal::Adaptor::Window& GetImplementation(const Dali::Window& window)
293 {
294   DALI_ASSERT_ALWAYS( window && "Window handle is empty" );
295   const BaseObject& object = window.GetBaseObject();
296   return static_cast<const Internal::Adaptor::Window&>(object);
297 }
298
299 } // namespace Dali
300
301
302 #endif // __DALI_INTERNAL_WINDOW_H__