(Window) Set class-name before Map
[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
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: // Indicator::Observer interface
205
206   /**
207    * @copydoc Dali::Internal::Adaptor::Indicator::Observer::IndicatorTypeChanged()
208    */
209   virtual void IndicatorTypeChanged( Indicator::Type type );
210
211   /**
212    * @copydoc Dali::Internal::Adaptor::Indicator::Observer::IndicatorClosed()
213    */
214   virtual void IndicatorClosed(Indicator* indicator);
215
216   /**
217    * @copydoc Dali::Internal::Adaptor::Indicator::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    * The user should connect to this signal to get a timing when indicator was shown / hidden.
251    */
252   IndicatorSignalType& IndicatorVisibilityChangedSignal() { return mIndicatorVisibilityChangedSignal; }
253
254 private:
255
256   typedef std::vector<Indicator*> DiscardedIndicators;
257
258   RenderSurface*                   mSurface;
259   Dali::Window::IndicatorVisibleMode mIndicatorVisible; ///< public state
260   bool                             mIndicatorIsShown:1; ///< private state
261   bool                             mShowRotatedIndicatorOnClose:1;
262   bool                             mStarted:1;
263   bool                             mIsTransparent:1;
264   bool                             mWMRotationAppSet:1;
265   bool                             mEcoreEventHander:1;
266   Indicator*                       mIndicator;
267   Dali::Window::WindowOrientation  mIndicatorOrientation;
268   Dali::Window::WindowOrientation  mNextIndicatorOrientation;
269   Dali::Window::IndicatorBgOpacity mIndicatorOpacityMode;
270   Integration::SystemOverlay*      mOverlay;
271   Adaptor*                         mAdaptor;
272   Dali::DragAndDropDetector        mDragAndDropDetector;
273
274   struct EventHandler;
275   EventHandler*                    mEventHandler;
276
277   OrientationPtr                               mOrientation;
278   std::vector<Dali::Window::WindowOrientation> mAvailableOrientations;
279   Dali::Window::WindowOrientation              mPreferredOrientation;
280
281   // Signals
282   IndicatorSignalType mIndicatorVisibilityChangedSignal;
283 };
284
285 } // namespace Adaptor
286 } // namepsace Internal
287
288 // Helpers for public-api forwarding methods
289
290 inline Internal::Adaptor::Window& GetImplementation(Dali::Window& window)
291 {
292   DALI_ASSERT_ALWAYS( window && "Window handle is empty" );
293   BaseObject& object = window.GetBaseObject();
294   return static_cast<Internal::Adaptor::Window&>(object);
295 }
296
297 inline const Internal::Adaptor::Window& GetImplementation(const Dali::Window& window)
298 {
299   DALI_ASSERT_ALWAYS( window && "Window handle is empty" );
300   const BaseObject& object = window.GetBaseObject();
301   return static_cast<const Internal::Adaptor::Window&>(object);
302 }
303
304 } // namespace Dali
305
306
307 #endif // __DALI_INTERNAL_WINDOW_H__