[Tizen] Add KeyEventGeneratedSignal for Get KeyEvent normally
[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
27 #ifdef DALI_ADAPTOR_COMPILATION
28 #include <dali/integration-api/scene-holder-impl.h>
29 #else
30 #include <dali/integration-api/adaptors/scene-holder-impl.h>
31 #endif
32
33 // INTERNAL INCLUDES
34 #include <dali/internal/adaptor/common/adaptor-impl.h>
35 #include <dali/public-api/adaptor-framework/window.h>
36 #include <dali/public-api/adaptor-framework/key-grab.h>
37 #include <dali/devel-api/adaptor-framework/window-devel.h>
38 #include <dali/internal/window-system/common/event-handler.h>
39
40 namespace Dali
41 {
42 class Adaptor;
43 class Actor;
44 class RenderSurfaceInterface;
45
46 namespace Internal
47 {
48 namespace Adaptor
49 {
50 class Orientation;
51 class WindowRenderSurface;
52 class WindowBase;
53
54 class Window;
55 using WindowPtr = IntrusivePtr< Window >;
56 using OrientationPtr = IntrusivePtr< Orientation >;
57 using EventHandlerPtr = IntrusivePtr< EventHandler >;
58
59 /**
60  * Window provides a surface to render onto with orientation & indicator properties.
61  */
62 class Window : public Dali::Internal::Adaptor::SceneHolder, public EventHandler::Observer, public ConnectionTracker
63 {
64 public:
65   typedef Dali::Window::IndicatorSignalType IndicatorSignalType;
66   typedef Dali::Window::FocusSignalType FocusSignalType;
67   typedef Dali::Window::ResizedSignalType ResizedSignalType;
68   typedef Signal< void () > SignalType;
69
70   /**
71    * 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    * @copydoc Dali::Window::ShowIndicator()
82    */
83   void ShowIndicator( Dali::Window::IndicatorVisibleMode visibleMode );
84
85   /**
86    * @copydoc Dali::Window::SetIndicatorBgOpacity()
87    */
88   void SetIndicatorBgOpacity( Dali::Window::IndicatorBgOpacity opacity );
89
90   /**
91    * @copydoc Dali::Window::RotateIndicator()
92    */
93   void RotateIndicator( Dali::Window::WindowOrientation orientation );
94
95   /**
96    * @copydoc Dali::Window::SetClass()
97    */
98   void SetClass( std::string name, std::string className );
99
100   /**
101    * @brief Gets the window class name.
102    * @return The class of the window
103    */
104   std::string GetClassName() const;
105
106   /**
107    * @copydoc Dali::Window::Raise()
108    */
109   void Raise();
110
111   /**
112    * @copydoc Dali::Window::Lower()
113    */
114   void Lower();
115
116   /**
117    * @copydoc Dali::Window::Activate()
118    */
119   void Activate();
120
121   /**
122    * @copydoc Dali::Window::GetLayerCount()
123    */
124   uint32_t GetLayerCount() const;
125
126   /**
127    * @copydoc Dali::Window::GetLayer()
128    */
129   Dali::Layer GetLayer( uint32_t depth ) const;
130
131   /**
132    * @copydoc Dali::DevelWindow::GetRenderTaskList()
133    */
134   Dali::RenderTaskList GetRenderTaskList() const;
135
136   /**
137    * @copydoc Dali::Window::AddAvailableOrientation()
138    */
139   void AddAvailableOrientation(Dali::Window::WindowOrientation orientation);
140
141   /**
142    * @copydoc Dali::Window::RemoveAvailableOrientation()
143    */
144   void RemoveAvailableOrientation(Dali::Window::WindowOrientation orientation);
145
146   /**
147    * @copydoc Dali::Window::SetAvailableOrientations()
148    */
149   void SetAvailableOrientations(const std::vector<Dali::Window::WindowOrientation>& orientations);
150
151   /**
152    * @copydoc Dali::Window::GetAvailableOrientations()
153    */
154   const std::vector<Dali::Window::WindowOrientation>& GetAvailableOrientations();
155
156   /**
157    * @copydoc Dali::Window::SetPreferredOrientation()
158    */
159   void SetPreferredOrientation(Dali::Window::WindowOrientation orientation);
160
161   /**
162    * @copydoc Dali::Window::GetPreferredOrientation()
163    */
164   Dali::Window::WindowOrientation GetPreferredOrientation();
165
166   /**
167    * @copydoc Dali::Window::SetAcceptFocus()
168    */
169   void SetAcceptFocus( bool accept );
170
171   /**
172    * @copydoc Dali::Window::IsFocusAcceptable()
173    */
174   bool IsFocusAcceptable() const;
175
176   /**
177    * @copydoc Dali::Window::Show()
178    */
179   void Show();
180
181   /**
182    * @copydoc Dali::Window::Hide()
183    */
184   void Hide();
185
186   /**
187    * @copydoc Dali::Window::GetSupportedAuxiliaryHintCount()
188    */
189   unsigned int GetSupportedAuxiliaryHintCount() const;
190
191   /**
192    * @copydoc Dali::Window::GetSupportedAuxiliaryHint()
193    */
194   std::string GetSupportedAuxiliaryHint( unsigned int index ) const;
195
196   /**
197    * @copydoc Dali::Window::AddAuxiliaryHint()
198    */
199   unsigned int AddAuxiliaryHint( const std::string& hint, const std::string& value );
200
201   /**
202    * @copydoc Dali::Window::RemoveAuxiliaryHint()
203    */
204   bool RemoveAuxiliaryHint( unsigned int id );
205
206   /**
207    * @copydoc Dali::Window::SetAuxiliaryHintValue()
208    */
209   bool SetAuxiliaryHintValue( unsigned int id, const std::string& value );
210
211   /**
212    * @copydoc Dali::Window::GetAuxiliaryHintValue()
213    */
214   std::string GetAuxiliaryHintValue( unsigned int id ) const;
215
216   /**
217    * @copydoc Dali::Window::GetAuxiliaryHintId()
218    */
219   unsigned int GetAuxiliaryHintId( const std::string& hint ) const;
220
221   /**
222    * @copydoc Dali::Window::SetInputRegion()
223    */
224   void SetInputRegion( const Rect< int >& inputRegion );
225
226   /**
227    * @copydoc Dali::Window::SetType()
228    */
229   void SetType( Dali::Window::Type type );
230
231   /**
232    * @copydoc Dali::Window::GetType() const
233    */
234   Dali::Window::Type GetType() const;
235
236   /**
237    * @copydoc Dali::Window::SetNotificationLevel()
238    */
239   bool SetNotificationLevel( Dali::Window::NotificationLevel::Type level );
240
241   /**
242    * @copydoc Dali::Window::GetNotificationLevel()
243    */
244   Dali::Window::NotificationLevel::Type GetNotificationLevel() const;
245
246   /**
247    * @copydoc Dali::Window::SetOpaqueState()
248    */
249   void SetOpaqueState( bool opaque );
250
251   /**
252    * @copydoc Dali::Window::IsOpaqueState()
253    */
254   bool IsOpaqueState() const;
255
256   /**
257    * @copydoc Dali::Window::SetScreenOffMode()
258    */
259   bool SetScreenOffMode(Dali::Window::ScreenOffMode::Type screenOffMode);
260
261   /**
262    * @copydoc Dali::Window::GetScreenOffMode()
263    */
264   Dali::Window::ScreenOffMode::Type GetScreenOffMode() const;
265
266   /**
267    * @copydoc Dali::Window::SetBrightness()
268    */
269   bool SetBrightness( int brightness );
270
271   /**
272    * @copydoc Dali::Window::GetBrightness()
273    */
274   int GetBrightness() const;
275
276   /**
277    * @copydoc Dali::Window::SetSize()
278    */
279   void SetSize( Dali::Window::WindowSize size );
280
281   /**
282    * @copydoc Dali::Window::GetSize()
283    */
284   Dali::Window::WindowSize GetSize() const;
285
286   /**
287    * @copydoc Dali::Window::SetPosition()
288    */
289   void SetPosition( Dali::Window::WindowPosition position );
290
291   /**
292    * @copydoc Dali::Window::GetPosition()
293    */
294   Dali::Window::WindowPosition GetPosition() const;
295
296   /**
297    * @copydoc Dali::DevelWindow::SetPositionSize()
298    */
299   void SetPositionSize( PositionSize positionSize );
300
301   /**
302    * @copydoc Dali::Window::GetRootLayer()
303    */
304   Dali::Layer GetRootLayer() const;
305
306   /**
307    * @copydoc Dali::Window::SetTransparency()
308    */
309   void SetTransparency( bool transparent );
310
311   /**
312    * @copydoc Dali::KeyGrab::GrabKey()
313    */
314   bool GrabKey( Dali::KEY key, KeyGrab::KeyGrabMode grabMode );
315
316   /**
317    * @copydoc Dali::KeyGrab::UngrabKey()
318    */
319   bool UngrabKey( Dali::KEY key );
320
321   /**
322    * @copydoc Dali::KeyGrab::GrabKeyList()
323    */
324   bool GrabKeyList( const Dali::Vector< Dali::KEY >& key, const Dali::Vector< KeyGrab::KeyGrabMode >& grabMode, Dali::Vector< bool >& result );
325
326   /**
327    * @copydoc Dali::KeyGrab::UngrabKeyList()
328    */
329   bool UngrabKeyList( const Dali::Vector< Dali::KEY >& key, Dali::Vector< bool >& result );
330
331   /**
332    * @copydoc Dali::DevelWindow::Get()
333    */
334   static Dali::Window Get( Dali::Actor actor );
335
336 public: // Dali::Internal::Adaptor::SceneHolder
337
338   /**
339    * @copydoc Dali::Internal::Adaptor::SceneHolder::GetNativeHandle
340    */
341   Dali::Any GetNativeHandle() const override;
342
343   /**
344    * @copydoc Dali::Internal::Adaptor::SceneHolder::IsVisible
345    */
346   bool IsVisible() const override;
347
348 private:
349
350   /**
351    * Private constructor.
352    * @sa Window::New()
353    */
354   Window();
355
356   /**
357    * Destructor
358    */
359   virtual ~Window();
360
361   /**
362    * Second stage initialization
363    */
364   void Initialize(const PositionSize& positionSize, const std::string& name, const std::string& className);
365
366   /**
367    * Called when the window becomes iconified or deiconified.
368    */
369   void OnIconifyChanged( bool iconified );
370
371   /**
372    * Called when the window focus is changed.
373    */
374   void OnFocusChanged( bool focusIn );
375
376   /**
377    * Called when the output is transformed.
378    */
379   void OnOutputTransformed();
380
381   /**
382    * Called when the window receives a delete request.
383    */
384   void OnDeleteRequest();
385
386 private: // Dali::Internal::Adaptor::SceneHolder
387
388   /**
389    * @copydoc Dali::Internal::Adaptor::SceneHolder::OnAdaptorSet
390    */
391   void OnAdaptorSet( Dali::Adaptor& adaptor ) override;
392
393   /**
394    * @copydoc Dali::Internal::Adaptor::SceneHolder::OnSurfaceSet
395    */
396   void OnSurfaceSet( Dali::RenderSurfaceInterface* surface ) override;
397
398   /**
399    * @copydoc Dali::Internal::Adaptor::SceneHolder::OnPause
400    */
401   void OnPause() override;
402
403   /**
404    * @copydoc Dali::Internal::Adaptor::SceneHolder::OnResume
405    */
406   void OnResume() override;
407
408   /**
409    * @copydoc Dali::Internal::Adaptor::SceneHolder::RecalculateTouchPosition
410    */
411   void RecalculateTouchPosition( Integration::Point& point ) override;
412
413 private: // Dali::Internal::Adaptor::EventHandler::Observer
414
415   /**
416    * @copydoc Dali::Internal::Adaptor::EventHandler::Observer::OnTouchPoint
417    */
418   void OnTouchPoint( Dali::Integration::Point& point, int timeStamp ) override;
419
420   /**
421    * @copydoc Dali::Internal::Adaptor::EventHandler::Observer::OnWheelEvent
422    */
423   void OnWheelEvent( Dali::Integration::WheelEvent& wheelEvent ) override;
424
425   /**
426    * @copydoc Dali::Internal::Adaptor::EventHandler::Observer::OnKeyEvent
427    */
428   void OnKeyEvent( Dali::Integration::KeyEvent& keyEvent ) override;
429
430   /**
431    * @copydoc Dali::Internal::Adaptor::EventHandler::Observer::OnRotation
432    */
433   void OnRotation( const RotationEvent& rotation ) override;
434
435 public: // Signals
436
437   /**
438    * The user should connect to this signal to get a timing when indicator was shown / hidden.
439    */
440   IndicatorSignalType& IndicatorVisibilityChangedSignal() { return mIndicatorVisibilityChangedSignal; }
441
442   /**
443    * @copydoc Dali::Window::FocusChangedSignal()
444    */
445   FocusSignalType& FocusChangedSignal() { return mFocusChangedSignal; }
446
447   /**
448    * @copydoc Dali::Window::ResizedSignal()
449    */
450   ResizedSignalType& ResizedSignal() { return mResizedSignal; }
451
452   /**
453    * This signal is emitted when the window is requesting to be deleted
454    */
455   SignalType& DeleteRequestSignal() { return mDeleteRequestSignal; }
456
457   /**
458    * @copydoc Dali::Window::SignalEventProcessingFinished()
459    */
460   Dali::DevelWindow::EventProcessingFinishedSignalType& EventProcessingFinishedSignal() { return mScene.EventProcessingFinishedSignal(); };
461
462   /**
463    * @copydoc Dali::Window::KeyEventSignal()
464    */
465   Dali::DevelWindow::KeyEventSignalType& KeyEventSignal() { return mScene.KeyEventSignal(); };
466
467     /**
468    * @copydoc Dali::Window::KeyEventGeneratedSignal()
469    */
470   Dali::DevelWindow::KeyEventGeneratedSignalType& KeyEventGeneratedSignal() { return mScene.KeyEventGeneratedSignal(); };
471
472   /**
473     * @copydoc Dali::Window::TouchSignal()
474     */
475   Dali::DevelWindow::TouchSignalType& TouchSignal() { return mScene.TouchSignal(); };
476
477   /**
478    * @copydoc Dali::Window::WheelEventSignal()
479    */
480   Dali::DevelWindow::WheelEventSignalType& WheelEventSignal() { return mScene.WheelEventSignal(); };
481
482 private:
483
484   WindowRenderSurface*                  mWindowSurface;      ///< The window rendering surface
485   WindowBase*                           mWindowBase;
486   std::string                           mName;
487   std::string                           mClassName;
488   bool                                  mIsTransparent:1;
489   bool                                  mIsFocusAcceptable:1;
490   bool                                  mIconified:1;
491   bool                                  mOpaqueState:1;
492   bool                                  mResizeEnabled:1;
493   Dali::Window::Type                    mType;
494
495   OrientationPtr                               mOrientation;
496   std::vector<Dali::Window::WindowOrientation> mAvailableOrientations;
497   Dali::Window::WindowOrientation              mPreferredOrientation;
498
499   int                                   mRotationAngle;     ///< The angle of the rotation
500   int                                   mWindowWidth;       ///< The width of the window
501   int                                   mWindowHeight;      ///< The height of the window
502
503   EventHandlerPtr                       mEventHandler;      ///< The window events handler
504
505   // Signals
506   IndicatorSignalType                   mIndicatorVisibilityChangedSignal;
507   FocusSignalType                       mFocusChangedSignal;
508   ResizedSignalType                     mResizedSignal;
509   SignalType                            mDeleteRequestSignal;
510
511
512 };
513
514 } // namespace Adaptor
515 } // namepsace Internal
516
517 // Helpers for public-api forwarding methods
518
519 inline Internal::Adaptor::Window& GetImplementation(Dali::Window& window)
520 {
521   DALI_ASSERT_ALWAYS( window && "Window handle is empty" );
522   BaseObject& object = window.GetBaseObject();
523   return static_cast<Internal::Adaptor::Window&>(object);
524 }
525
526 inline const Internal::Adaptor::Window& GetImplementation(const Dali::Window& window)
527 {
528   DALI_ASSERT_ALWAYS( window && "Window handle is empty" );
529   const BaseObject& object = window.GetBaseObject();
530   return static_cast<const Internal::Adaptor::Window&>(object);
531 }
532
533 } // namespace Dali
534
535 #endif // DALI_INTERNAL_WINDOWSYSTEM_COMMON_WINDOW_IMPL_H