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