[dali_1.9.27] Merge branch 'devel/master'
[platform/core/uifw/dali-adaptor.git] / dali / public-api / adaptor-framework / window.h
1 #ifndef DALI_WINDOW_H
2 #define DALI_WINDOW_H
3
4 /*
5  * Copyright (c) 2020 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 <string>
23 #include <dali/public-api/math/rect.h>
24 #include <dali/public-api/math/uint-16-pair.h>
25 #include <dali/public-api/math/vector2.h>
26 #include <dali/public-api/math/vector4.h>
27 #include <dali/public-api/object/base-handle.h>
28 #include <dali/public-api/object/any.h>
29 #include <dali/public-api/signals/dali-signal.h>
30
31 // INTERNAL INCLUDES
32 #include <dali/public-api/dali-adaptor-common.h>
33
34 #undef OPAQUE
35 #undef TRANSPARENT
36
37 namespace Dali
38 {
39 /**
40  * @addtogroup dali_adaptor_framework
41  * @{
42  */
43
44 typedef Dali::Rect<int> PositionSize;
45
46 namespace Internal DALI_INTERNAL
47 {
48 namespace Adaptor
49 {
50 class Window;
51 }
52 }
53
54 class DragAndDropDetector;
55 class Orientation;
56 class Actor;
57 class Layer;
58 class RenderTaskList;
59 class TouchEvent;
60 class KeyEvent;
61
62 /**
63  * @brief The window class is used internally for drawing.
64  *
65  * A Window has an orientation and indicator properties.
66  * You can get a valid Window handle by calling Dali::Application::GetWindow().
67  * @SINCE_1_0.0
68  */
69 class DALI_ADAPTOR_API Window : public BaseHandle
70 {
71 public:
72
73   using WindowSize = Uint16Pair ;     ///< Window size type @SINCE_1_2.60
74   using WindowPosition = Uint16Pair;  ///< Window position type @SINCE_1_2.60
75
76   using FocusChangeSignalType = Signal< void (Window,bool) >;  ///< Window focus signal type @SINCE_1_4.35
77   using ResizeSignalType = Signal< void (Window,WindowSize) >; ///< Window resized signal type @SINCE_1_4.35
78   using KeyEventSignalType = Signal< void (const KeyEvent&) >; ///< Key event signal type
79   using TouchSignalType = Signal< void (const TouchEvent&) >;   ///< Touch signal type
80
81 public:
82
83   // Enumerations
84
85   /**
86    * @brief Enumeration for orientation of the window is the way in which a rectangular page is oriented for normal viewing.
87    *
88    * This Enumeration is used the available orientation APIs and the preferred orientation.
89    *
90    * @SINCE_1_0.0
91    */
92   enum WindowOrientation
93   {
94     PORTRAIT = 0,  ///< Portrait orientation. The height of the display area is greater than the width. @SINCE_1_0.0
95     LANDSCAPE = 90,  ///< Landscape orientation. A wide view area is needed. @SINCE_1_0.0
96     PORTRAIT_INVERSE = 180,  ///< Portrait inverse orientation @SINCE_1_0.0
97     LANDSCAPE_INVERSE = 270,  ///< Landscape inverse orientation @SINCE_1_0.0
98     NO_ORIENTATION_PREFERENCE = -1 ///< No orientation. It is used to initialize or unset the preferred orientation.  @SINCE_1_4.51
99   };
100
101   /**
102    * @brief An enum of Window types.
103    * @SINCE_1_2.60
104    */
105   enum Type
106   {
107     NORMAL,           ///< A default window type. Indicates a normal, top-level window. Almost every window will be created with this type. @SINCE_1_2.60
108     NOTIFICATION,     ///< A notification window, like a warning about battery life or a new E-Mail received. @SINCE_1_2.60
109     UTILITY,          ///< A persistent utility window, like a toolbox or palette. @SINCE_1_2.60
110     DIALOG            ///< Used for simple dialog windows. @SINCE_1_2.60
111   };
112
113   /**
114    * @brief An enum of screen mode.
115    * @SINCE_1_2.60
116    */
117   struct NotificationLevel
118   {
119     /**
120      * @brief An enum of screen mode.
121      * @SINCE_1_2.60
122      */
123     enum Type
124     {
125       NONE   = -1,    ///< No notification level. Default level. This value makes the notification window place in the layer of the normal window. @SINCE_1_2.60
126       BASE   = 10,    ///< Base notification level. @SINCE_1_2.60
127       MEDIUM = 20,    ///< Higher notification level than base. @SINCE_1_2.60
128       HIGH   = 30,    ///< Higher notification level than medium. @SINCE_1_2.60
129       TOP    = 40     ///< The highest notification level. @SINCE_1_2.60
130     };
131   };
132
133   /**
134    * @brief An enum of screen mode.
135    * @SINCE_1_2.60
136    */
137   struct ScreenOffMode
138   {
139     /**
140      * @brief An enum of screen mode.
141      * @SINCE_1_2.60
142      */
143     enum Type
144     {
145       TIMEOUT,              ///< The mode which turns the screen off after a timeout. @SINCE_1_2.60
146       NEVER,                ///< The mode which keeps the screen turned on. @SINCE_1_2.60
147     };
148
149     static constexpr Type DEFAULT { TIMEOUT }; ///< The default mode. @SINCE_1_2.60
150   };
151
152   // Methods
153
154   /**
155    * @brief Creates an initialized handle to a new Window.
156    * @SINCE_1_0.0
157    * @param[in] windowPosition The position and size of the Window
158    * @param[in] name The Window title
159    * @param[in] isTransparent Whether Window is transparent
160    * @return A new window
161    * @note This creates an extra window in addition to the default main window
162    */
163   static Window New(PositionSize windowPosition, const std::string& name, bool isTransparent = false);
164
165   /**
166    * @brief Creates an initialized handle to a new Window.
167    * @SINCE_1_0.0
168    * @param[in] windowPosition The position and size of the Window
169    * @param[in] name The Window title
170    * @param[in] className The Window class name
171    * @param[in] isTransparent Whether Window is transparent
172    * @note This creates an extra window in addition to the default main window
173    * @return A new Window
174    */
175   static Window New(PositionSize windowPosition, const std::string& name, const std::string& className, bool isTransparent = false);
176
177   /**
178    * @brief Creates an uninitialized handle.
179    *
180    * This can be initialized using Dali::Application::GetWindow() or
181    * Dali::Window::New().
182    * @SINCE_1_0.0
183    */
184   Window();
185
186   /**
187    * @brief Destructor.
188    *
189    * This is non-virtual since derived Handle types must not contain data or virtual methods.
190    * @SINCE_1_0.0
191    */
192   ~Window();
193
194   /**
195    * @brief This copy constructor is required for (smart) pointer semantics.
196    *
197    * @SINCE_1_0.0
198    * @param[in] handle A reference to the copied handle
199    */
200   Window(const Window& handle);
201
202   /**
203    * @brief This assignment operator is required for (smart) pointer semantics.
204    *
205    * @SINCE_1_0.0
206    * @param[in] rhs A reference to the copied handle
207    * @return A reference to this
208    */
209   Window& operator=(const Window& rhs);
210
211   /**
212    * @brief Move constructor.
213    *
214    * @SINCE_1_9.24
215    * @param[in] rhs A reference to the moved handle
216    */
217   Window( Window&& rhs );
218
219   /**
220    * @brief Move assignment operator.
221    *
222    * @SINCE_1_9.24
223    * @param[in] rhs A reference to the moved handle
224    * @return A reference to this handle
225    */
226   Window& operator=( Window&& rhs );
227
228   /**
229    * @brief Adds a child Actor to the Window.
230    *
231    * The child will be referenced.
232    *
233    * @SINCE_1_4.19
234    * @param[in] actor The child
235    * @pre The actor has been initialized.
236    * @pre The actor does not have a parent.
237    */
238   void Add( Actor actor );
239
240   /**
241    * @brief Removes a child Actor from the Window.
242    *
243    * The child will be unreferenced.
244    *
245    * @SINCE_1_4.19
246    * @param[in] actor The child
247    * @pre The actor has been added to the stage.
248    */
249   void Remove( Actor actor );
250
251   /**
252    * @brief Sets the background color of the Window.
253    *
254    * @SINCE_1_4.19
255    * @param[in] color The new background color
256    */
257   void SetBackgroundColor( const Vector4& color );
258
259   /**
260    * @brief Gets the background color of the Window.
261    *
262    * @SINCE_1_4.19
263    * @return The background color
264    */
265   Vector4 GetBackgroundColor() const;
266
267   /**
268    * @brief Returns the root Layer of the Window.
269    *
270    * @SINCE_1_4.19
271    * @return The root layer
272    */
273   Layer GetRootLayer() const;
274
275   /**
276    * @brief Queries the number of on-scene layers in the Window.
277    *
278    * Note that a default layer is always provided (count >= 1).
279    *
280    * @SINCE_1_4.19
281    * @return The number of layers
282    */
283   uint32_t GetLayerCount() const;
284
285   /**
286    * @brief Retrieves the layer at a specified depth in the Window.
287    *
288    * @SINCE_1_4.19
289    * @param[in] depth The depth
290    * @return The layer found at the given depth
291    * @pre Depth is less than layer count; see GetLayerCount().
292    */
293   Layer GetLayer( uint32_t depth ) const;
294
295   /**
296    * @brief Retrieves the DPI of the window.
297    *
298    * @SINCE_1_9.21
299    * @return The DPI of the window
300    */
301   Uint16Pair GetDpi() const;
302
303   /**
304    * @brief Sets the window name and class string.
305    * @SINCE_1_0.0
306    * @param[in] name The name of the window
307    * @param[in] klass The class of the window
308    */
309   void SetClass(std::string name, std::string klass);
310
311   /**
312    * @brief Raises window to the top of Window stack.
313    * @SINCE_1_0.0
314    */
315   void Raise();
316
317   /**
318    * @brief Lowers window to the bottom of Window stack.
319    * @SINCE_1_0.0
320    */
321   void Lower();
322
323   /**
324    * @brief Activates window to the top of Window stack even it is iconified.
325    * @SINCE_1_0.0
326    */
327   void Activate();
328
329   /**
330    * @brief Adds an orientation to the list of available orientations.
331    * @SINCE_1_0.0
332    * @param[in] orientation The available orientation to add
333    */
334   void AddAvailableOrientation( WindowOrientation orientation );
335
336   /**
337    * @brief Removes an orientation from the list of available orientations.
338    * @SINCE_1_0.0
339    * @param[in] orientation The available orientation to remove
340    */
341   void RemoveAvailableOrientation( WindowOrientation orientation );
342
343   /**
344    * @brief Sets a preferred orientation.
345    * @SINCE_1_0.0
346    * @param[in] orientation The preferred orientation
347    * @pre Orientation is in the list of available orientations.
348    *
349    * @note To unset the preferred orientation, orientation should be set NO_ORIENTATION_PREFERENCE.
350    */
351   void SetPreferredOrientation( WindowOrientation orientation );
352
353   /**
354    * @brief Gets the preferred orientation.
355    * @SINCE_1_0.0
356    * @return The preferred orientation if previously set, or none
357    */
358   WindowOrientation GetPreferredOrientation();
359
360   /**
361    * @brief Gets the native handle of the window.
362    *
363    * When users call this function, it wraps the actual type used by the underlying window system.
364    * @SINCE_1_0.0
365    * @return The native handle of the Window or an empty handle
366    */
367   Any GetNativeHandle() const;
368
369   /**
370    * @brief Sets whether window accepts focus or not.
371    *
372    * @SINCE_1_2.60
373    * @param[in] accept If focus is accepted or not. Default is true.
374    */
375   void SetAcceptFocus( bool accept );
376
377   /**
378    * @brief Returns whether window accepts focus or not.
379    *
380    * @SINCE_1_2.60
381    * @return True if the window accept focus, false otherwise
382    */
383   bool IsFocusAcceptable() const;
384
385   /**
386    * @brief Shows the window if it is hidden.
387    * @SINCE_1_2.60
388    */
389   void Show();
390
391   /**
392    * @brief Hides the window if it is showing.
393    * @SINCE_1_2.60
394    */
395   void Hide();
396
397   /**
398    * @brief Returns whether the window is visible or not.
399    * @SINCE_1_2.60
400    * @return True if the window is visible, false otherwise.
401    */
402   bool IsVisible() const;
403
404   /**
405    * @brief Gets the count of supported auxiliary hints of the window.
406    * @SINCE_1_2.60
407    * @return The number of supported auxiliary hints.
408    *
409    * @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.
410    * If you want to set specific hint to your window, then you should check whether it exists in the supported auxiliary hints.
411    */
412   unsigned int GetSupportedAuxiliaryHintCount() const;
413
414   /**
415    * @brief Gets the supported auxiliary hint string of the window.
416    * @SINCE_1_2.60
417    * @param[in] index The index of the supported auxiliary hint lists
418    * @return The auxiliary hint string of the index.
419    *
420    * @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.
421    * If you want to set specific hint to your window, then you should check whether it exists in the supported auxiliary hints.
422    */
423   std::string GetSupportedAuxiliaryHint( unsigned int index ) const;
424
425   /**
426    * @brief Creates an auxiliary hint of the window.
427    * @SINCE_1_2.60
428    * @param[in] hint The auxiliary hint string.
429    * @param[in] value The value string.
430    * @return The ID of created auxiliary hint, or @c 0 on failure.
431    */
432   unsigned int AddAuxiliaryHint( const std::string& hint, const std::string& value );
433
434   /**
435    * @brief Removes an auxiliary hint of the window.
436    * @SINCE_1_2.60
437    * @param[in] id The ID of the auxiliary hint.
438    * @return True if no error occurred, false otherwise.
439    */
440   bool RemoveAuxiliaryHint( unsigned int id );
441
442   /**
443    * @brief Changes a value of the auxiliary hint.
444    * @SINCE_1_2.60
445    * @param[in] id The auxiliary hint ID.
446    * @param[in] value The value string to be set.
447    * @return True if no error occurred, false otherwise.
448    */
449   bool SetAuxiliaryHintValue( unsigned int id, const std::string& value );
450
451   /**
452    * @brief Gets a value of the auxiliary hint.
453    * @SINCE_1_2.60
454    * @param[in] id The auxiliary hint ID.
455    * @return The string value of the auxiliary hint ID, or an empty string if none exists.
456    */
457   std::string GetAuxiliaryHintValue( unsigned int id ) const;
458
459   /**
460    * @brief Gets a ID of the auxiliary hint string.
461    * @SINCE_1_2.60
462    * @param[in] hint The auxiliary hint string.
463    * @return The ID of the auxiliary hint string, or @c 0 if none exists.
464    */
465   unsigned int GetAuxiliaryHintId( const std::string& hint ) const;
466
467   /**
468    * @brief Sets a region to accept input events.
469    * @SINCE_1_2.60
470    * @param[in] inputRegion The region to accept input events.
471    */
472   void SetInputRegion( const Rect< int >& inputRegion );
473
474   /**
475    * @brief Sets a window type.
476    * @SINCE_1_2.60
477    * @param[in] type The window type.
478    * @remarks The default window type is NORMAL.
479    */
480   void SetType( Type type );
481
482   /**
483    * @brief Gets a window type.
484    * @SINCE_1_2.60
485    * @return A window type.
486    */
487   Type GetType() const;
488
489   /**
490    * @brief Sets a priority level for the specified notification window.
491    * @SINCE_1_2.60
492    * @param[in] level The notification window level.
493    * @return True if no error occurred, false otherwise.
494    * @PRIVLEVEL_PUBLIC
495    * @PRIVILEGE_WINDOW_PRIORITY
496    * @remarks This can be used for a notification type window only. The default level is NotificationLevel::NONE.
497    */
498   bool SetNotificationLevel( NotificationLevel::Type level );
499
500   /**
501    * @brief Gets a priority level for the specified notification window.
502    * @SINCE_1_2.60
503    * @return The notification window level.
504    * @remarks This can be used for a notification type window only.
505    */
506   NotificationLevel::Type GetNotificationLevel() const;
507
508   /**
509    * @brief Sets a transparent window's visual state to opaque.
510    * @details If a visual state of a transparent window is opaque,
511    * then the window manager could handle it as an opaque window when calculating visibility.
512    * @SINCE_1_2.60
513    * @param[in] opaque Whether the window's visual state is opaque.
514    * @remarks This will have no effect on an opaque window.
515    * It doesn't change transparent window to opaque window but lets the window manager know the visual state of the window.
516    */
517   void SetOpaqueState( bool opaque );
518
519   /**
520    * @brief Returns whether a transparent window's visual state is opaque or not.
521    * @SINCE_1_2.60
522    * @return True if the window's visual state is opaque, false otherwise.
523    * @remarks The return value has no meaning on an opaque window.
524    */
525   bool IsOpaqueState() const;
526
527   /**
528    * @brief Sets a window's screen off mode.
529    * @details This API is useful when the application needs to keep the display turned on.
530    * If the application sets the screen mode to #::Dali::Window::ScreenOffMode::NEVER to its window and the window is shown,
531    * the window manager requests the display system to keep the display on as long as the window is shown.
532    * If the window is no longer shown, then the window manager requests the display system to go back to normal operation.
533    * @SINCE_1_2.60
534    * @param[in] screenOffMode The screen mode.
535    * @return True if no error occurred, false otherwise.
536    * @PRIVLEVEL_PUBLIC
537    * @PRIVILEGE_DISPLAY
538    */
539   bool SetScreenOffMode(ScreenOffMode::Type screenOffMode);
540
541   /**
542    * @brief Gets a screen off mode of the window.
543    * @SINCE_1_2.60
544    * @return The screen off mode.
545    */
546   ScreenOffMode::Type GetScreenOffMode() const;
547
548   /**
549    * @brief Sets preferred brightness of the window.
550    * @details This API is useful when the application needs to change the brightness of the screen when it is appeared on the screen.
551    * If the brightness has been set and the window is shown, the window manager requests the display system to change the brightness to the provided value.
552    * If the window is no longer shown, then the window manager requests the display system to go back to default brightness.
553    * A value less than 0 results in default brightness and a value greater than 100 results in maximum brightness.
554    * @SINCE_1_2.60
555    * @param[in] brightness The preferred brightness (0 to 100).
556    * @return True if no error occurred, false otherwise.
557    * @PRIVLEVEL_PUBLIC
558    * @PRIVILEGE_DISPLAY
559    */
560   bool SetBrightness( int brightness );
561
562   /**
563    * @brief Gets preferred brightness of the window.
564    * @SINCE_1_2.60
565    * @return The preferred brightness.
566    */
567   int GetBrightness() const;
568
569   /**
570    * @brief Sets a size of the window.
571    *
572    * @SINCE_1_2.60
573    * @param[in] size The new window size
574    */
575   void SetSize( WindowSize size );
576
577   /**
578    * @brief Gets a size of the window.
579    *
580    * @SINCE_1_2.60
581    * @return The size of the window
582    */
583   WindowSize GetSize() const;
584
585   /**
586    * @brief Sets a position of the window.
587    *
588    * @SINCE_1_2.60
589    * @param[in] position The new window position
590    */
591   void SetPosition( WindowPosition position );
592
593   /**
594    * @brief Gets a position of the window.
595    *
596    * @SINCE_1_2.60
597    * @return The position of the window
598    */
599   WindowPosition GetPosition() const;
600
601   /**
602    * @brief Sets whether the window is transparent or not.
603    *
604    * @SINCE_1_2.60
605    * @param[in] transparent Whether the window is transparent
606    */
607   void SetTransparency( bool transparent );
608
609   /**
610    * @brief Retrieves the list of render-tasks in the window.
611    *
612    * @SINCE_1_9.21
613    * @return A valid handle to a RenderTaskList
614    */
615   RenderTaskList GetRenderTaskList();
616
617 public: // Signals
618
619   /**
620    * @brief The user should connect to this signal to get a timing when window gains focus or loses focus.
621    *
622    * A callback of the following type may be connected:
623    * @code
624    *   void YourCallbackName( Window window, bool focusIn );
625    * @endcode
626    * The parameter is true if window gains focus, otherwise false.
627    * and window means this signal was called from what window
628    *
629    * @SINCE_1_4.35
630    * @return The signal to connect to
631    */
632   FocusChangeSignalType& FocusChangeSignal();
633
634   /**
635    * @brief This signal is emitted when the window is resized.
636    *
637    * A callback of the following type may be connected:
638    * @code
639    *   void YourCallbackName( Window window, int width, int height );
640    * @endcode
641    * The parameters are the resized width and height.
642    * and window means this signal was called from what window
643    *
644    * @SINCE_1_4.35
645    * @return The signal to connect to
646    */
647   ResizeSignalType& ResizeSignal();
648
649   /**
650    * @brief This signal is emitted when key event is received.
651    *
652    * A callback of the following type may be connected:
653    * @code
654    *   void YourCallbackName(const KeyEvent& event);
655    * @endcode
656    *
657    * @SINCE_1_9.21
658    * @return The signal to connect to
659    */
660   KeyEventSignalType& KeyEventSignal();
661
662   /**
663    * @brief This signal is emitted when the screen is touched and when the touch ends
664    * (i.e. the down & up touch events only).
665    *
666    * If there are multiple touch points, then this will be emitted when the first touch occurs and
667    * then when the last finger is lifted.
668    * An interrupted event will also be emitted (if it occurs).
669    * A callback of the following type may be connected:
670    * @code
671    *   void YourCallbackName(const TouchEvent& event);
672    * @endcode
673    *
674    * @SINCE_1_9.21
675    * @return The touch signal to connect to
676    *
677    * @note Motion events are not emitted.
678    */
679   TouchSignalType& TouchSignal();
680
681 public: // Not intended for application developers
682   /// @cond internal
683   /**
684    * @brief This constructor is used by Dali::Application::GetWindow().
685    * @SINCE_1_0.0
686    * @param[in] window A pointer to the Window
687    */
688   explicit DALI_INTERNAL Window( Internal::Adaptor::Window* window );
689   /// @endcond
690 };
691
692 /**
693  * @}
694  */
695 } // namespace Dali
696
697 #endif // __DALI_WINDOW_H__