ceed80aed9751e829492be26105124ebf3e574bd
[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   /**
199    * @brief Gets the count of supported auxiliary hints of the window.
200    * @return The number of supported auxiliary hints.
201    *
202    * @note The window auxiliary hint is the value which is used to decide which actions should be made available to the user by the window manager.
203    * If you want to set specific hint to your window, then you should check whether it exists in the supported auxiliary hints.
204    */
205    unsigned int GetSupportedAuxiliaryHintCount();
206
207   /**
208    * @brief Gets the supported auxiliary hint string of the window.
209    * @param[in] index The index of the supported auxiliary hint lists
210    * @return The auxiliary hint string of the index.
211    *
212    * @note The window auxiliary hint is the value which is used to decide which actions should be made available to the user by the window manager.
213    * If you want to set specific hint to your window, then you should check whether it exists in the supported auxiliary hints.
214    */
215   std::string GetSupportedAuxiliaryHint( unsigned int index );
216
217   /**
218    * @brief Creates an auxiliary hint of the window.
219    * @param[in] hint The auxiliary hint string.
220    * @param[in] value The value string.
221    * @return The ID of created auxiliary hint, or @c 0 on failure.
222    */
223   unsigned int AddAuxiliaryHint( const std::string& hint, const std::string& value );
224
225   /**
226    * @brief Removes an auxiliary hint of the window.
227    * @param[in] id The ID of the auxiliary hint.
228    * @return True if no error occurred, false otherwise.
229    */
230   bool RemoveAuxiliaryHint( unsigned int id );
231
232   /**
233    * @brief Changes a value of the auxiliary hint.
234    * @param[in] id The auxiliary hint ID.
235    * @param[in] value The value string to be set.
236    * @return True if no error occurred, false otherwise.
237    */
238   bool SetAuxiliaryHintValue( unsigned int id, const std::string& value );
239
240   /**
241    * @brief Gets a value of the auxiliary hint.
242    * @param[in] id The auxiliary hint ID.
243    * @return The string value of the auxiliary hint ID, or an empty string if none exists.
244    */
245   std::string GetAuxiliaryHintValue( unsigned int id ) const;
246
247   /**
248    * @brief Gets a ID of the auxiliary hint string.
249    * @param[in] hint The auxiliary hint string.
250    * @return The ID of the auxiliary hint string, or @c 0 if none exists.
251    */
252   unsigned int GetAuxiliaryHintId( const std::string& hint ) const;
253
254   /**
255    * @brief Sets a region to get input events.
256    * @param[in] inputRegion The rectangle region to get input events.
257    * @note To set an empty region, pass width and height as 0. An empty input region means the entire window will accept input events.
258    */
259   void SetInputRegion( const Rect< int >& inputRegion );
260
261 private:
262   /**
263    * Private constructor.
264    * @sa Window::New()
265    */
266   Window();
267
268   /**
269    * Destructor
270    */
271   virtual ~Window();
272
273   /**
274    * Second stage initialization
275    */
276   void Initialize(const PositionSize& posSize, const std::string& name, const std::string& className);
277
278   /**
279    * Shows / hides the indicator bar.
280    * Handles close/open if rotation changes whilst hidden
281    */
282   void DoShowIndicator( Dali::Window::WindowOrientation lastOrientation );
283
284   /**
285    * Close current indicator and open a connection onto the new indicator service.
286    * Effect may not be synchronous if waiting for an indicator update on existing connection.
287    */
288   void DoRotateIndicator( Dali::Window::WindowOrientation orientation );
289
290   /**
291    * Change the indicator actor's rotation to match the current orientation
292    */
293   void SetIndicatorActorRotation();
294
295   /**
296    * Set the indicator properties on the window
297    */
298   void SetIndicatorProperties( bool isShown, Dali::Window::WindowOrientation lastOrientation );
299
300 private: // IndicatorInterface::Observer interface
301
302   /**
303    * @copydoc Dali::Internal::Adaptor::IndicatorInterface::Observer::IndicatorTypeChanged()
304    */
305   virtual void IndicatorTypeChanged( IndicatorInterface::Type type );
306
307   /**
308    * @copydoc Dali::Internal::Adaptor::IndicatorInterface::Observer::IndicatorClosed()
309    */
310   virtual void IndicatorClosed( IndicatorInterface* indicator);
311
312   /**
313    * @copydoc Dali::Internal::Adaptor::IndicatorInterface::Observer::IndicatorVisibilityChanged()
314    */
315   virtual void IndicatorVisibilityChanged( bool isVisible );
316
317 private: // Adaptor::Observer interface
318
319   /**
320    * @copydoc Dali::Internal::Adaptor::Adaptor::Observer::OnStart()
321    */
322   virtual void OnStart();
323
324   /**
325    * @copydoc Dali::Internal::Adaptor::Adaptor::Observer::OnPause()
326    */
327   virtual void OnPause();
328
329   /**
330    * @copydoc Dali::Internal::Adaptor::Adaptor::Observer::OnResume()
331    */
332   virtual void OnResume();
333
334   /**
335    * @copydoc Dali::Internal::Adaptor::Adaptor::Observer::OnStop()
336    */
337   virtual void OnStop();
338
339   /**
340    * @copydoc Dali::Internal::Adaptor::Adaptor::Observer::OnDestroy()
341    */
342   virtual void OnDestroy();
343
344 public: // Signals
345
346   /**
347    * The user should connect to this signal to get a timing when indicator was shown / hidden.
348    */
349   IndicatorSignalType& IndicatorVisibilityChangedSignal() { return mIndicatorVisibilityChangedSignal; }
350
351   /**
352    * The user should connect to this signal to get a timing when window gains focus or loses focus.
353    */
354   FocusSignalType& FocusChangedSignal() { return mFocusChangedSignal; }
355
356   /**
357    * This signal is emitted when the window is requesting to be deleted
358    */
359   SignalType& DeleteRequestSignal() { return mDeleteRequestSignal; }
360
361 private:
362
363   typedef std::vector< std::pair< std::string, std::string > > AuxiliaryHints;
364
365   RenderSurface*                   mSurface;
366   Dali::Window::IndicatorVisibleMode mIndicatorVisible; ///< public state
367   bool                             mIndicatorIsShown:1; ///< private state
368   bool                             mShowRotatedIndicatorOnClose:1;
369   bool                             mStarted:1;
370   bool                             mIsTransparent:1;
371   bool                             mWMRotationAppSet:1;
372   bool                             mEcoreEventHander:1;
373   bool                             mIsFocusAcceptable:1;
374   bool                             mVisible:1;
375   IndicatorInterface*              mIndicator;
376   Dali::Window::WindowOrientation  mIndicatorOrientation;
377   Dali::Window::WindowOrientation  mNextIndicatorOrientation;
378   Dali::Window::IndicatorBgOpacity mIndicatorOpacityMode;
379   Integration::SystemOverlay*      mOverlay;
380   Adaptor*                         mAdaptor;
381   Dali::DragAndDropDetector        mDragAndDropDetector;
382
383   struct EventHandler;
384   EventHandler*                    mEventHandler;
385
386   OrientationPtr                               mOrientation;
387   std::vector<Dali::Window::WindowOrientation> mAvailableOrientations;
388   Dali::Window::WindowOrientation              mPreferredOrientation;
389
390   std::vector< std::string >        mSupportedAuxiliaryHints;
391   AuxiliaryHints                    mAuxiliaryHints;
392
393   // Signals
394   IndicatorSignalType mIndicatorVisibilityChangedSignal;
395   FocusSignalType     mFocusChangedSignal;
396   SignalType          mDeleteRequestSignal;
397 };
398
399 } // namespace Adaptor
400 } // namepsace Internal
401
402 // Helpers for public-api forwarding methods
403
404 inline Internal::Adaptor::Window& GetImplementation(Dali::Window& window)
405 {
406   DALI_ASSERT_ALWAYS( window && "Window handle is empty" );
407   BaseObject& object = window.GetBaseObject();
408   return static_cast<Internal::Adaptor::Window&>(object);
409 }
410
411 inline const Internal::Adaptor::Window& GetImplementation(const Dali::Window& window)
412 {
413   DALI_ASSERT_ALWAYS( window && "Window handle is empty" );
414   const BaseObject& object = window.GetBaseObject();
415   return static_cast<const Internal::Adaptor::Window&>(object);
416 }
417
418 } // namespace Dali
419
420
421 #endif // __DALI_INTERNAL_WINDOW_H__