Merge "The advance of the letters is too narrow. So, remove the floor." into devel...
[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) 2019 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 <dali/public-api/actors/layer.h>
25 #include <dali/public-api/render-tasks/render-task-list.h>
26 #include <dali/public-api/object/property-array.h>
27
28 // INTERNAL INCLUDES
29 #include <dali/public-api/adaptor-framework/window.h>
30 #include <dali/public-api/adaptor-framework/key-grab.h>
31 #include <dali/devel-api/adaptor-framework/window-devel.h>
32 #include <dali/integration-api/adaptor-framework/scene-holder-impl.h>
33 #include <dali/internal/adaptor/common/adaptor-impl.h>
34 #include <dali/internal/window-system/common/event-handler.h>
35
36 namespace Dali
37 {
38 class Adaptor;
39 class Actor;
40 class RenderSurfaceInterface;
41
42 namespace Internal
43 {
44 namespace Adaptor
45 {
46 class Orientation;
47 class WindowRenderSurface;
48 class WindowBase;
49
50 class Window;
51 using WindowPtr = IntrusivePtr< Window >;
52 using OrientationPtr = IntrusivePtr< Orientation >;
53 using EventHandlerPtr = IntrusivePtr< EventHandler >;
54
55 /**
56  * Window provides a surface to render onto with orientation & indicator properties.
57  */
58 class Window : public Dali::Internal::Adaptor::SceneHolder, public EventHandler::Observer, public ConnectionTracker
59 {
60 public:
61   typedef Dali::Window::IndicatorSignalType IndicatorSignalType;
62   typedef Dali::Window::FocusSignalType FocusSignalType;
63   typedef Dali::Window::ResizedSignalType ResizedSignalType;
64   typedef Dali::Window::FocusChangeSignalType FocusChangeSignalType;
65   typedef Dali::Window::ResizeSignalType ResizeSignalType;
66   typedef Dali::DevelWindow::VisibilityChangedSignalType VisibilityChangedSignalType;
67   typedef Dali::DevelWindow::TransitionEffectEventSignalType TransitionEffectEventSignalType;
68   typedef Signal< void () > SignalType;
69
70   /**
71    * @brief Create a new Window. This should only be called once by the Application class
72    * @param[in] positionSize The position and size of the window
73    * @param[in] name The window title
74    * @param[in] className The window class name
75    * @param[in] isTransparent Whether window is transparent
76    * @return A newly allocated Window
77    */
78   static Window* New(const PositionSize& positionSize, const std::string& name, const std::string& className, bool isTransparent = false);
79
80   /**
81    * @brief Create a new Window. This should only be called once by the Application class
82    * @param[in] surface The surface used to render on.
83    * @param[in] positionSize The position and size of the window
84    * @param[in] name The window title
85    * @param[in] className The window class name
86    * @param[in] isTransparent Whether window is transparent
87    * @return A newly allocated Window
88    */
89   static Window* New(Any surface, const PositionSize& positionSize, const std::string& name, const std::string& className, bool isTransparent = false);
90
91   /**
92    * @copydoc Dali::Window::ShowIndicator()
93    */
94   void ShowIndicator( Dali::Window::IndicatorVisibleMode visibleMode );
95
96   /**
97    * @copydoc Dali::Window::SetIndicatorBgOpacity()
98    */
99   void SetIndicatorBgOpacity( Dali::Window::IndicatorBgOpacity opacity );
100
101   /**
102    * @copydoc Dali::Window::RotateIndicator()
103    */
104   void RotateIndicator( Dali::Window::WindowOrientation orientation );
105
106   /**
107    * @copydoc Dali::Window::SetClass()
108    */
109   void SetClass( std::string name, std::string className );
110
111   /**
112    * @brief Gets the window class name.
113    * @return The class of the window
114    */
115   std::string GetClassName() const;
116
117   /**
118    * @copydoc Dali::Window::Raise()
119    */
120   void Raise();
121
122   /**
123    * @copydoc Dali::Window::Lower()
124    */
125   void Lower();
126
127   /**
128    * @copydoc Dali::Window::Activate()
129    */
130   void Activate();
131
132   /**
133    * @copydoc Dali::Window::GetLayerCount()
134    */
135   uint32_t GetLayerCount() const;
136
137   /**
138    * @copydoc Dali::Window::GetLayer()
139    */
140   Dali::Layer GetLayer( uint32_t depth ) const;
141
142   /**
143    * @copydoc Dali::DevelWindow::GetRenderTaskList()
144    */
145   Dali::RenderTaskList GetRenderTaskList() const;
146
147   /**
148    * @copydoc Dali::Window::AddAvailableOrientation()
149    */
150   void AddAvailableOrientation(Dali::Window::WindowOrientation orientation);
151
152   /**
153    * @copydoc Dali::Window::RemoveAvailableOrientation()
154    */
155   void RemoveAvailableOrientation(Dali::Window::WindowOrientation orientation);
156
157   /**
158    * @copydoc Dali::Window::SetPreferredOrientation()
159    */
160   void SetPreferredOrientation(Dali::Window::WindowOrientation orientation);
161
162   /**
163    * @copydoc Dali::Window::GetPreferredOrientation()
164    */
165   Dali::Window::WindowOrientation GetPreferredOrientation();
166
167   /**
168    * @copydoc Dali::Window::SetAcceptFocus()
169    */
170   void SetAcceptFocus( bool accept );
171
172   /**
173    * @copydoc Dali::Window::IsFocusAcceptable()
174    */
175   bool IsFocusAcceptable() const;
176
177   /**
178    * @copydoc Dali::Window::Show()
179    */
180   void Show();
181
182   /**
183    * @copydoc Dali::Window::Hide()
184    */
185   void Hide();
186
187   /**
188    * @copydoc Dali::Window::GetSupportedAuxiliaryHintCount()
189    */
190   unsigned int GetSupportedAuxiliaryHintCount() const;
191
192   /**
193    * @copydoc Dali::Window::GetSupportedAuxiliaryHint()
194    */
195   std::string GetSupportedAuxiliaryHint( unsigned int index ) const;
196
197   /**
198    * @copydoc Dali::Window::AddAuxiliaryHint()
199    */
200   unsigned int AddAuxiliaryHint( const std::string& hint, const std::string& value );
201
202   /**
203    * @copydoc Dali::Window::RemoveAuxiliaryHint()
204    */
205   bool RemoveAuxiliaryHint( unsigned int id );
206
207   /**
208    * @copydoc Dali::Window::SetAuxiliaryHintValue()
209    */
210   bool SetAuxiliaryHintValue( unsigned int id, const std::string& value );
211
212   /**
213    * @copydoc Dali::Window::GetAuxiliaryHintValue()
214    */
215   std::string GetAuxiliaryHintValue( unsigned int id ) const;
216
217   /**
218    * @copydoc Dali::Window::GetAuxiliaryHintId()
219    */
220   unsigned int GetAuxiliaryHintId( const std::string& hint ) const;
221
222   /**
223    * @copydoc Dali::Window::SetInputRegion()
224    */
225   void SetInputRegion( const Rect< int >& inputRegion );
226
227   /**
228    * @copydoc Dali::Window::SetType()
229    */
230   void SetType( Dali::Window::Type type );
231
232   /**
233    * @copydoc Dali::Window::GetType() const
234    */
235   Dali::Window::Type GetType() const;
236
237   /**
238    * @copydoc Dali::Window::SetNotificationLevel()
239    */
240   bool SetNotificationLevel( Dali::Window::NotificationLevel::Type level );
241
242   /**
243    * @copydoc Dali::Window::GetNotificationLevel()
244    */
245   Dali::Window::NotificationLevel::Type GetNotificationLevel() const;
246
247   /**
248    * @copydoc Dali::Window::SetOpaqueState()
249    */
250   void SetOpaqueState( bool opaque );
251
252   /**
253    * @copydoc Dali::Window::IsOpaqueState()
254    */
255   bool IsOpaqueState() const;
256
257   /**
258    * @copydoc Dali::Window::SetScreenOffMode()
259    */
260   bool SetScreenOffMode(Dali::Window::ScreenOffMode::Type screenOffMode);
261
262   /**
263    * @copydoc Dali::Window::GetScreenOffMode()
264    */
265   Dali::Window::ScreenOffMode::Type GetScreenOffMode() const;
266
267   /**
268    * @copydoc Dali::Window::SetBrightness()
269    */
270   bool SetBrightness( int brightness );
271
272   /**
273    * @copydoc Dali::Window::GetBrightness()
274    */
275   int GetBrightness() const;
276
277   /**
278    * @copydoc Dali::Window::SetSize()
279    */
280   void SetSize( Dali::Window::WindowSize size );
281
282   /**
283    * @copydoc Dali::Window::GetSize()
284    */
285   Dali::Window::WindowSize GetSize() const;
286
287   /**
288    * @copydoc Dali::Window::SetPosition()
289    */
290   void SetPosition( Dali::Window::WindowPosition position );
291
292   /**
293    * @copydoc Dali::Window::GetPosition()
294    */
295   Dali::Window::WindowPosition GetPosition() const;
296
297   /**
298    * @copydoc Dali::DevelWindow::SetPositionSize()
299    */
300   void SetPositionSize( PositionSize positionSize );
301
302   /**
303    * @copydoc Dali::Window::GetRootLayer()
304    */
305   Dali::Layer GetRootLayer() const;
306
307   /**
308    * @copydoc Dali::Window::SetTransparency()
309    */
310   void SetTransparency( bool transparent );
311
312   /**
313    * @copydoc Dali::KeyGrab::GrabKey()
314    */
315   bool GrabKey( Dali::KEY key, KeyGrab::KeyGrabMode grabMode );
316
317   /**
318    * @copydoc Dali::KeyGrab::UngrabKey()
319    */
320   bool UngrabKey( Dali::KEY key );
321
322   /**
323    * @copydoc Dali::KeyGrab::GrabKeyList()
324    */
325   bool GrabKeyList( const Dali::Vector< Dali::KEY >& key, const Dali::Vector< KeyGrab::KeyGrabMode >& grabMode, Dali::Vector< bool >& result );
326
327   /**
328    * @copydoc Dali::KeyGrab::UngrabKeyList()
329    */
330   bool UngrabKeyList( const Dali::Vector< Dali::KEY >& key, Dali::Vector< bool >& result );
331
332   /**
333    * @copydoc Dali::DevelWindow::Get()
334    */
335   static Dali::Window Get( Dali::Actor actor );
336
337   /**
338    * @copydoc Dali::DevelWindow::SetParent()
339    */
340   void SetParent( Dali::Window& parent );
341
342   /**
343    * @copydoc Dali::DevelWindow::Unparent()
344    */
345   void Unparent();
346
347   /**
348    * @copydoc Dali::DevelWindow::GetParent()
349    */
350   Dali::Window GetParent();
351
352   /**
353    * @copydoc Dali::DevelWindow::GetCurrentOrientation()
354    */
355   Dali::Window::WindowOrientation GetCurrentOrientation() const;
356
357   /**
358    * @copydoc Dali::DevelWindow::SetAvailableOrientations()
359    */
360   void SetAvailableOrientations( const Dali::Vector<Dali::Window::WindowOrientation>& orientations );
361
362   /**
363    * @copydoc Dali::DevelWindow::SetDamagedAreas()
364    */
365   void SetDamagedAreas(std::vector<Dali::Rect<int>>& areas);
366
367 public: // Dali::Internal::Adaptor::SceneHolder
368
369   /**
370    * @copydoc Dali::Internal::Adaptor::SceneHolder::GetNativeHandle
371    */
372   Dali::Any GetNativeHandle() const override;
373
374   /**
375    * @copydoc Dali::Internal::Adaptor::SceneHolder::IsVisible
376    */
377   bool IsVisible() const override;
378
379   /**
380    * @copydoc Dali::DevelWindow::GetNativeId()
381    */
382   int32_t GetNativeId() const;
383
384 private:
385
386   /**
387    * @brief Enumeration for orietation mode.
388    * The Orientation Mode is related to screen size.
389    * If screen width is longer than height, the Orientation Mode will have LANDSCAPE.
390    * Otherwise screen width is shorter than height or same, the Orientation Mode will have PORTRAIT.
391    */
392   enum class OrientationMode
393   {
394     PORTRAIT = 0,
395     LANDSCAPE
396   };
397
398   /**
399    * Private constructor.
400    * @sa Window::New()
401    */
402   Window();
403
404   /**
405    * Destructor
406    */
407   virtual ~Window();
408
409   /**
410    * Second stage initialization
411    */
412   void Initialize(Any surface, const PositionSize& positionSize, const std::string& name, const std::string& className);
413
414   /**
415    * Called when the window becomes iconified or deiconified.
416    */
417   void OnIconifyChanged( bool iconified );
418
419   /**
420    * Called when the window focus is changed.
421    */
422   void OnFocusChanged( bool focusIn );
423
424   /**
425    * Called when the output is transformed.
426    */
427   void OnOutputTransformed();
428
429   /**
430    * Called when the window receives a delete request.
431    */
432   void OnDeleteRequest();
433
434   /**
435    * Called when the window receives a Transition effect-start/end event.
436    */
437   void OnTransitionEffectEvent( DevelWindow::EffectState state, DevelWindow::EffectType type );
438
439   /**
440    * @brief Set available orientation to window base.
441    */
442   void SetAvailableAnlges( const std::vector< int >& angles );
443
444   /**
445    * @brief Convert from window orientation to angle using OrientationMode.
446    */
447   int ConvertToAngle( Dali::Window::WindowOrientation orientation );
448
449   /**
450    * @brief Convert from angle to window orientation using OrientationMode.
451    */
452   Dali::Window::WindowOrientation ConvertToOrientation( int angle ) const;
453
454   /**
455    * @brief Check available window orientation for Available orientation.
456    */
457   bool IsOrientationAvailable( Dali::Window::WindowOrientation orientation ) const;
458
459 private: // Dali::Internal::Adaptor::SceneHolder
460
461   /**
462    * @copydoc Dali::Internal::Adaptor::SceneHolder::OnAdaptorSet
463    */
464   void OnAdaptorSet( Dali::Adaptor& adaptor ) override;
465
466   /**
467    * @copydoc Dali::Internal::Adaptor::SceneHolder::OnSurfaceSet
468    */
469   void OnSurfaceSet( Dali::RenderSurfaceInterface* surface ) override;
470
471   /**
472    * @copydoc Dali::Internal::Adaptor::SceneHolder::OnPause
473    */
474   void OnPause() override;
475
476   /**
477    * @copydoc Dali::Internal::Adaptor::SceneHolder::OnResume
478    */
479   void OnResume() override;
480
481   /**
482    * @copydoc Dali::Internal::Adaptor::SceneHolder::RecalculateTouchPosition
483    */
484   void RecalculateTouchPosition( Integration::Point& point ) override;
485
486 private: // Dali::Internal::Adaptor::EventHandler::Observer
487
488   /**
489    * @copydoc Dali::Internal::Adaptor::EventHandler::Observer::OnTouchPoint
490    */
491   void OnTouchPoint( Dali::Integration::Point& point, int timeStamp ) override;
492
493   /**
494    * @copydoc Dali::Internal::Adaptor::EventHandler::Observer::OnWheelEvent
495    */
496   void OnWheelEvent( Dali::Integration::WheelEvent& wheelEvent ) override;
497
498   /**
499    * @copydoc Dali::Internal::Adaptor::EventHandler::Observer::OnKeyEvent
500    */
501   void OnKeyEvent( Dali::Integration::KeyEvent& keyEvent ) override;
502
503   /**
504    * @copydoc Dali::Internal::Adaptor::EventHandler::Observer::OnRotation
505    */
506   void OnRotation( const RotationEvent& rotation ) override;
507
508 public: // Signals
509
510   /**
511    * The user should connect to this signal to get a timing when indicator was shown / hidden.
512    */
513   IndicatorSignalType& IndicatorVisibilityChangedSignal() { return mIndicatorVisibilityChangedSignal; }
514
515   /**
516    * @copydoc Dali::Window::FocusChangedSignal()
517    */
518   FocusSignalType& FocusChangedSignal() { return mFocusChangedSignal; }
519
520   /**
521    * @copydoc Dali::Window::WindowFocusChangedSignal()
522    */
523   FocusChangeSignalType& FocusChangeSignal() { return mFocusChangeSignal; }
524   /**
525    * @copydoc Dali::Window::ResizedSignal()
526    */
527   ResizedSignalType& ResizedSignal() { return mResizedSignal; }
528
529   /**
530    * @copydoc Dali::Window::ResizedSignal()
531    */
532   ResizeSignalType& ResizeSignal() { return mResizeSignal; }
533
534   /**
535    * This signal is emitted when the window is requesting to be deleted
536    */
537   SignalType& DeleteRequestSignal() { return mDeleteRequestSignal; }
538
539   /**
540    * @copydoc Dali::DevelWindow::VisibilityChangedSignal()
541    */
542   VisibilityChangedSignalType& VisibilityChangedSignal() { return mVisibilityChangedSignal; }
543
544   /**
545    * @copydoc Dali::Window::SignalEventProcessingFinished()
546    */
547   Dali::DevelWindow::EventProcessingFinishedSignalType& EventProcessingFinishedSignal() { return mScene.EventProcessingFinishedSignal(); }
548
549   /**
550    * @copydoc Dali::DevelWindow::TransitionEffectEventSignal()
551    */
552   TransitionEffectEventSignalType& TransitionEffectEventSignal() { return mTransitionEffectEventSignal; }
553
554 private:
555
556   WindowRenderSurface*                  mWindowSurface;      ///< The window rendering surface
557   WindowBase*                           mWindowBase;
558   std::string                           mName;
559   std::string                           mClassName;
560   bool                                  mIsTransparent:1;
561   bool                                  mIsFocusAcceptable:1;
562   bool                                  mIconified:1;
563   bool                                  mOpaqueState:1;
564   bool                                  mResizeEnabled:1;
565   Dali::Window::Type                    mType;
566   Dali::Window                          mParentWindow;
567
568   OrientationPtr                        mOrientation;
569   std::vector< int >                    mAvailableAngles;
570   int                                   mPreferredAngle;
571
572   int                                   mRotationAngle;     ///< The angle of the rotation
573   int                                   mWindowWidth;       ///< The width of the window
574   int                                   mWindowHeight;      ///< The height of the window
575
576   EventHandlerPtr                       mEventHandler;      ///< The window events handler
577
578   OrientationMode                       mOrientationMode;
579
580   int                                   mNativeWindowId;          ///< The Native Window Id
581
582   // Signals
583   IndicatorSignalType                   mIndicatorVisibilityChangedSignal;
584   FocusSignalType                       mFocusChangedSignal;
585   ResizedSignalType                     mResizedSignal;
586   SignalType                            mDeleteRequestSignal;
587   FocusChangeSignalType                 mFocusChangeSignal;
588   ResizeSignalType                      mResizeSignal;
589   VisibilityChangedSignalType           mVisibilityChangedSignal;
590   TransitionEffectEventSignalType       mTransitionEffectEventSignal;
591 };
592
593 } // namespace Adaptor
594 } // namepsace Internal
595
596 // Helpers for public-api forwarding methods
597
598 inline Internal::Adaptor::Window& GetImplementation(Dali::Window& window)
599 {
600   DALI_ASSERT_ALWAYS( window && "Window handle is empty" );
601   BaseObject& object = window.GetBaseObject();
602   return static_cast<Internal::Adaptor::Window&>(object);
603 }
604
605 inline const Internal::Adaptor::Window& GetImplementation(const Dali::Window& window)
606 {
607   DALI_ASSERT_ALWAYS( window && "Window handle is empty" );
608   const BaseObject& object = window.GetBaseObject();
609   return static_cast<const Internal::Adaptor::Window&>(object);
610 }
611
612 } // namespace Dali
613
614 #endif // DALI_INTERNAL_WINDOWSYSTEM_COMMON_WINDOW_IMPL_H