76fb76fb4523d539a28c482ff7b86ee78be2b9f1
[platform/core/uifw/dali-adaptor.git] / dali / internal / window-system / common / window-impl.h
1 #ifndef DALI_INTERNAL_WINDOWSYSTEM_COMMON_WINDOW_IMPL_H
2 #define DALI_INTERNAL_WINDOWSYSTEM_COMMON_WINDOW_IMPL_H
3
4 /*
5  * Copyright (c) 2018 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 <dali/internal/adaptor/common/lifecycle-observer.h>
27 #include <dali/internal/adaptor/common/adaptor-impl.h>
28 #include <dali/public-api/adaptor-framework/window.h>
29 #include <dali/public-api/adaptor-framework/key-grab.h>
30 #include <dali/devel-api/adaptor-framework/drag-and-drop-detector.h>
31
32 namespace Dali
33 {
34 class Adaptor;
35
36 namespace Internal
37 {
38 namespace Adaptor
39 {
40 class Orientation;
41 class WindowRenderSurface;
42 class WindowBase;
43
44 class Window;
45 typedef IntrusivePtr<Window> WindowPtr;
46 typedef IntrusivePtr<Orientation> OrientationPtr;
47
48 /**
49  * Window provides a surface to render onto with orientation & indicator properties.
50  */
51 class Window : public Dali::BaseObject, public LifeCycleObserver, public ConnectionTracker
52 {
53 public:
54   typedef Dali::Window::IndicatorSignalType IndicatorSignalType;
55   typedef Dali::Window::FocusSignalType FocusSignalType;
56   typedef Dali::Window::ResizedSignalType ResizedSignalType;
57   typedef Signal< void () > SignalType;
58
59   /**
60    * Create a new Window. This should only be called once by the Application class
61    * @param[in] positionSize The position and size of the window
62    * @param[in] name The window title
63    * @param[in] className The window class name
64    * @param[in] isTransparent Whether window is transparent
65    * @return A newly allocated Window
66    */
67   static Window* New(const PositionSize& positionSize, const std::string& name, const std::string& className, bool isTransparent = false);
68
69   /**
70    * Pass the adaptor back to the overlay. This allows the window to access Core's overlay.
71    * @param[in] adaptor An initialized adaptor
72    */
73   void SetAdaptor(Dali::Adaptor& adaptor);
74
75   /**
76    * Get the window surface
77    * @return The render surface
78    */
79   WindowRenderSurface* GetSurface();
80
81   /**
82    * @copydoc Dali::Window::ShowIndicator()
83    */
84   void ShowIndicator( Dali::Window::IndicatorVisibleMode visibleMode );
85
86   /**
87    * @copydoc Dali::Window::SetIndicatorBgOpacity()
88    */
89   void SetIndicatorBgOpacity( Dali::Window::IndicatorBgOpacity opacity );
90
91   /**
92    * @copydoc Dali::Window::RotateIndicator()
93    */
94   void RotateIndicator( Dali::Window::WindowOrientation orientation );
95
96   /**
97    * @copydoc Dali::Window::SetClass()
98    */
99   void SetClass( std::string name, std::string className );
100
101   /**
102    * @copydoc Dali::Window::Raise()
103    */
104   void Raise();
105
106   /**
107    * @copydoc Dali::Window::Lower()
108    */
109   void Lower();
110
111   /**
112    * @copydoc Dali::Window::Activate()
113    */
114   void Activate();
115
116   /**
117    * @copydoc Dali::Window::AddAvailableOrientation()
118    */
119   void AddAvailableOrientation(Dali::Window::WindowOrientation orientation);
120
121   /**
122    * @copydoc Dali::Window::RemoveAvailableOrientation()
123    */
124   void RemoveAvailableOrientation(Dali::Window::WindowOrientation orientation);
125
126   /**
127    * @copydoc Dali::Window::SetAvailableOrientations()
128    */
129   void SetAvailableOrientations(const std::vector<Dali::Window::WindowOrientation>& orientations);
130
131   /**
132    * @copydoc Dali::Window::GetAvailableOrientations()
133    */
134   const std::vector<Dali::Window::WindowOrientation>& GetAvailableOrientations();
135
136   /**
137    * @copydoc Dali::Window::SetPreferredOrientation()
138    */
139   void SetPreferredOrientation(Dali::Window::WindowOrientation orientation);
140
141   /**
142    * @copydoc Dali::Window::GetPreferredOrientation()
143    */
144   Dali::Window::WindowOrientation GetPreferredOrientation();
145
146   /**
147    * @copydoc Dali::Window::GetDragAndDropDetector() const
148    */
149   Dali::DragAndDropDetector GetDragAndDropDetector() const;
150
151   /**
152    * @copydoc Dali::Window::GetNativeHandle() const
153    */
154   Dali::Any GetNativeHandle() const;
155
156   /**
157    * @copydoc Dali::Window::SetAcceptFocus()
158    */
159   void SetAcceptFocus( bool accept );
160
161   /**
162    * @copydoc Dali::Window::IsFocusAcceptable()
163    */
164   bool IsFocusAcceptable() const;
165
166   /**
167    * @copydoc Dali::Window::Show()
168    */
169   void Show();
170
171   /**
172    * @copydoc Dali::Window::Hide()
173    */
174   void Hide();
175
176   /**
177    * @copydoc Dali::Window::IsVisible() const
178    */
179   bool IsVisible() const;
180
181   /**
182    * @copydoc Dali::Window::GetSupportedAuxiliaryHintCount()
183    */
184   unsigned int GetSupportedAuxiliaryHintCount() const;
185
186   /**
187    * @copydoc Dali::Window::GetSupportedAuxiliaryHint()
188    */
189   std::string GetSupportedAuxiliaryHint( unsigned int index ) const;
190
191   /**
192    * @copydoc Dali::Window::AddAuxiliaryHint()
193    */
194   unsigned int AddAuxiliaryHint( const std::string& hint, const std::string& value );
195
196   /**
197    * @copydoc Dali::Window::RemoveAuxiliaryHint()
198    */
199   bool RemoveAuxiliaryHint( unsigned int id );
200
201   /**
202    * @copydoc Dali::Window::SetAuxiliaryHintValue()
203    */
204   bool SetAuxiliaryHintValue( unsigned int id, const std::string& value );
205
206   /**
207    * @copydoc Dali::Window::GetAuxiliaryHintValue()
208    */
209   std::string GetAuxiliaryHintValue( unsigned int id ) const;
210
211   /**
212    * @copydoc Dali::Window::GetAuxiliaryHintId()
213    */
214   unsigned int GetAuxiliaryHintId( const std::string& hint ) const;
215
216   /**
217    * @copydoc Dali::Window::SetInputRegion()
218    */
219   void SetInputRegion( const Rect< int >& inputRegion );
220
221   /**
222    * @copydoc Dali::Window::SetType()
223    */
224   void SetType( Dali::Window::Type type );
225
226   /**
227    * @copydoc Dali::Window::GetType() const
228    */
229   Dali::Window::Type GetType() const;
230
231   /**
232    * @copydoc Dali::Window::SetNotificationLevel()
233    */
234   bool SetNotificationLevel( Dali::Window::NotificationLevel::Type level );
235
236   /**
237    * @copydoc Dali::Window::GetNotificationLevel()
238    */
239   Dali::Window::NotificationLevel::Type GetNotificationLevel() const;
240
241   /**
242    * @copydoc Dali::Window::SetOpaqueState()
243    */
244   void SetOpaqueState( bool opaque );
245
246   /**
247    * @copydoc Dali::Window::IsOpaqueState()
248    */
249   bool IsOpaqueState() const;
250
251   /**
252    * @copydoc Dali::Window::SetScreenOffMode()
253    */
254   bool SetScreenOffMode(Dali::Window::ScreenOffMode::Type screenOffMode);
255
256   /**
257    * @copydoc Dali::Window::GetScreenOffMode()
258    */
259   Dali::Window::ScreenOffMode::Type GetScreenOffMode() const;
260
261   /**
262    * @copydoc Dali::Window::SetBrightness()
263    */
264   bool SetBrightness( int brightness );
265
266   /**
267    * @copydoc Dali::Window::GetBrightness()
268    */
269   int GetBrightness() const;
270
271   /**
272    * @copydoc Dali::Window::SetSize()
273    */
274   void SetSize( Dali::Window::WindowSize size );
275
276   /**
277    * @copydoc Dali::Window::GetSize()
278    */
279   Dali::Window::WindowSize GetSize() const;
280
281   /**
282    * @copydoc Dali::Window::SetPosition()
283    */
284   void SetPosition( Dali::Window::WindowPosition position );
285
286   /**
287    * @copydoc Dali::Window::GetPosition()
288    */
289   Dali::Window::WindowPosition GetPosition() const;
290
291   /**
292    * @copydoc Dali::DevelWindow::SetPositionSize()
293    */
294   void SetPositionSize( PositionSize positionSize );
295
296   /**
297    * @copydoc Dali::Window::SetTransparency()
298    */
299   void SetTransparency( bool transparent );
300
301   /**
302    * @copydoc Dali::KeyGrab::GrabKey()
303    */
304   bool GrabKey( Dali::KEY key, KeyGrab::KeyGrabMode grabMode );
305
306   /**
307    * @copydoc Dali::KeyGrab::UngrabKey()
308    */
309   bool UngrabKey( Dali::KEY key );
310
311   /**
312    * @copydoc Dali::KeyGrab::GrabKeyList()
313    */
314   bool GrabKeyList( const Dali::Vector< Dali::KEY >& key, const Dali::Vector< KeyGrab::KeyGrabMode >& grabMode, Dali::Vector< bool >& result );
315
316   /**
317    * @copydoc Dali::KeyGrab::UngrabKeyList()
318    */
319   bool UngrabKeyList( const Dali::Vector< Dali::KEY >& key, Dali::Vector< bool >& result );
320
321   /**
322    * Called from Orientation after the Change signal has been sent
323    */
324   void RotationDone( int orientation, int width, int height );
325
326 private:
327
328   /**
329    * Private constructor.
330    * @sa Window::New()
331    */
332   Window();
333
334   /**
335    * Destructor
336    */
337   virtual ~Window();
338
339   /**
340    * Second stage initialization
341    */
342   void Initialize(const PositionSize& positionSize, const std::string& name, const std::string& className);
343
344   /**
345    * Called when the window becomes iconified or deiconified.
346    */
347   void OnIconifyChanged( bool iconified );
348
349   /**
350    * Called when the window focus is changed.
351    */
352   void OnFocusChanged( bool focusIn );
353
354   /**
355    * Called when the output is transformed.
356    */
357   void OnOutputTransformed();
358
359   /**
360    * Called when the window receives a delete request.
361    */
362   void OnDeleteRequest();
363
364 private: // Adaptor::Observer interface
365
366   /**
367    * @copydoc Dali::Internal::Adaptor::Adaptor::Observer::OnStart()
368    */
369   virtual void OnStart();
370
371   /**
372    * @copydoc Dali::Internal::Adaptor::Adaptor::Observer::OnPause()
373    */
374   virtual void OnPause();
375
376   /**
377    * @copydoc Dali::Internal::Adaptor::Adaptor::Observer::OnResume()
378    */
379   virtual void OnResume();
380
381   /**
382    * @copydoc Dali::Internal::Adaptor::Adaptor::Observer::OnStop()
383    */
384   virtual void OnStop();
385
386   /**
387    * @copydoc Dali::Internal::Adaptor::Adaptor::Observer::OnDestroy()
388    */
389   virtual void OnDestroy();
390
391 public: // Signals
392
393   /**
394    * The user should connect to this signal to get a timing when indicator was shown / hidden.
395    */
396   IndicatorSignalType& IndicatorVisibilityChangedSignal() { return mIndicatorVisibilityChangedSignal; }
397
398   /**
399    * @copydoc Dali::Window::FocusChangedSignal()
400    */
401   FocusSignalType& FocusChangedSignal() { return mFocusChangedSignal; }
402
403   /**
404    * @copydoc Dali::Window::ResizedSignal()
405    */
406   ResizedSignalType& ResizedSignal() { return mResizedSignal; }
407
408   /**
409    * This signal is emitted when the window is requesting to be deleted
410    */
411   SignalType& DeleteRequestSignal() { return mDeleteRequestSignal; }
412
413 private:
414
415   WindowRenderSurface*                  mSurface;
416   WindowBase*                           mWindowBase;
417   bool                                  mStarted:1;
418   bool                                  mIsTransparent:1;
419   bool                                  mIsFocusAcceptable:1;
420   bool                                  mVisible:1;
421   bool                                  mIconified:1;
422   bool                                  mOpaqueState:1;
423   bool                                  mResizeEnabled:1;
424   Adaptor*                              mAdaptor;
425   Dali::DragAndDropDetector             mDragAndDropDetector;
426   Dali::Window::Type                    mType;
427
428   OrientationPtr                               mOrientation;
429   std::vector<Dali::Window::WindowOrientation> mAvailableOrientations;
430   Dali::Window::WindowOrientation              mPreferredOrientation;
431
432   // Signals
433   IndicatorSignalType mIndicatorVisibilityChangedSignal;
434   FocusSignalType     mFocusChangedSignal;
435   ResizedSignalType   mResizedSignal;
436   SignalType          mDeleteRequestSignal;
437 };
438
439 } // namespace Adaptor
440 } // namepsace Internal
441
442 // Helpers for public-api forwarding methods
443
444 inline Internal::Adaptor::Window& GetImplementation(Dali::Window& window)
445 {
446   DALI_ASSERT_ALWAYS( window && "Window handle is empty" );
447   BaseObject& object = window.GetBaseObject();
448   return static_cast<Internal::Adaptor::Window&>(object);
449 }
450
451 inline const Internal::Adaptor::Window& GetImplementation(const Dali::Window& window)
452 {
453   DALI_ASSERT_ALWAYS( window && "Window handle is empty" );
454   const BaseObject& object = window.GetBaseObject();
455   return static_cast<const Internal::Adaptor::Window&>(object);
456 }
457
458 } // namespace Dali
459
460 #endif // DALI_INTERNAL_WINDOWSYSTEM_COMMON_WINDOW_IMPL_H