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