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