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