5 * Copyright (c) 2020 Samsung Electronics Co., Ltd.
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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.
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>
32 #include <dali/public-api/dali-adaptor-common.h>
40 * @addtogroup dali_adaptor_framework
44 typedef Dali::Rect<int> PositionSize;
46 namespace Internal DALI_INTERNAL
54 class DragAndDropDetector;
63 * @brief The window class is used internally for drawing.
65 * A Window has an orientation and indicator properties.
66 * You can get a valid Window handle by calling Dali::Application::GetWindow().
69 class DALI_ADAPTOR_API Window : public BaseHandle
73 using WindowSize = Uint16Pair ; ///< Window size type @SINCE_1_2.60
74 using WindowPosition = Uint16Pair; ///< Window position type @SINCE_1_2.60
76 using ResizedSignalType = Signal< void (WindowSize) >; ///< @DEPRECATED_1_4.35 @brief Window resized signal type @SINCE_1_2.60
77 using FocusChangeSignalType = Signal< void (Window,bool) >; ///< Window focus signal type @SINCE_1_4.35
78 using ResizeSignalType = Signal< void (Window,WindowSize) >; ///< Window resized signal type @SINCE_1_4.35
79 using KeyEventSignalType = Signal< void (const KeyEvent&) >; ///< Key event signal type
80 using TouchSignalType = Signal< void (const TouchData&) >; ///< Touch signal type
87 * @brief Enumeration for orientation of the window is the way in which a rectangular page is oriented for normal viewing.
89 * This Enumeration is used the available orientation APIs and the preferred orientation.
93 enum WindowOrientation
95 PORTRAIT = 0, ///< Portrait orientation. The height of the display area is greater than the width. @SINCE_1_0.0
96 LANDSCAPE = 90, ///< Landscape orientation. A wide view area is needed. @SINCE_1_0.0
97 PORTRAIT_INVERSE = 180, ///< Portrait inverse orientation @SINCE_1_0.0
98 LANDSCAPE_INVERSE = 270, ///< Landscape inverse orientation @SINCE_1_0.0
99 NO_ORIENTATION_PREFERENCE = -1 ///< No orientation. It is used to initialize or unset the preferred orientation. @SINCE_1_4.51
103 * @brief An enum of Window types.
108 NORMAL, ///< A default window type. Indicates a normal, top-level window. Almost every window will be created with this type. @SINCE_1_2.60
109 NOTIFICATION, ///< A notification window, like a warning about battery life or a new E-Mail received. @SINCE_1_2.60
110 UTILITY, ///< A persistent utility window, like a toolbox or palette. @SINCE_1_2.60
111 DIALOG ///< Used for simple dialog windows. @SINCE_1_2.60
115 * @brief An enum of screen mode.
118 struct NotificationLevel
121 * @brief An enum of screen mode.
126 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
127 BASE = 10, ///< Base notification level. @SINCE_1_2.60
128 MEDIUM = 20, ///< Higher notification level than base. @SINCE_1_2.60
129 HIGH = 30, ///< Higher notification level than medium. @SINCE_1_2.60
130 TOP = 40 ///< The highest notification level. @SINCE_1_2.60
135 * @brief An enum of screen mode.
141 * @brief An enum of screen mode.
146 TIMEOUT, ///< The mode which turns the screen off after a timeout. @SINCE_1_2.60
147 NEVER, ///< The mode which keeps the screen turned on. @SINCE_1_2.60
150 static constexpr Type DEFAULT { TIMEOUT }; ///< The default mode. @SINCE_1_2.60
156 * @brief Creates an initialized handle to a new Window.
158 * @param[in] windowPosition The position and size of the Window
159 * @param[in] name The Window title
160 * @param[in] isTransparent Whether Window is transparent
161 * @return A new window
162 * @note This creates an extra window in addition to the default main window
164 static Window New(PositionSize windowPosition, const std::string& name, bool isTransparent = false);
167 * @brief Creates an initialized handle to a new Window.
169 * @param[in] windowPosition The position and size of the Window
170 * @param[in] name The Window title
171 * @param[in] className The Window class name
172 * @param[in] isTransparent Whether Window is transparent
173 * @note This creates an extra window in addition to the default main window
174 * @return A new Window
176 static Window New(PositionSize windowPosition, const std::string& name, const std::string& className, bool isTransparent = false);
179 * @brief Creates an uninitialized handle.
181 * This can be initialized using Dali::Application::GetWindow() or
182 * Dali::Window::New().
190 * This is non-virtual since derived Handle types must not contain data or virtual methods.
196 * @brief This copy constructor is required for (smart) pointer semantics.
199 * @param[in] handle A reference to the copied handle
201 Window(const Window& handle);
204 * @brief This assignment operator is required for (smart) pointer semantics.
207 * @param[in] rhs A reference to the copied handle
208 * @return A reference to this
210 Window& operator=(const Window& rhs);
213 * @brief Adds a child Actor to the Window.
215 * The child will be referenced.
218 * @param[in] actor The child
219 * @pre The actor has been initialized.
220 * @pre The actor does not have a parent.
222 void Add( Actor actor );
225 * @brief Removes a child Actor from the Window.
227 * The child will be unreferenced.
230 * @param[in] actor The child
231 * @pre The actor has been added to the stage.
233 void Remove( Actor actor );
236 * @brief Sets the background color of the Window.
239 * @param[in] color The new background color
241 void SetBackgroundColor( const Vector4& color );
244 * @brief Gets the background color of the Window.
247 * @return The background color
249 Vector4 GetBackgroundColor() const;
252 * @brief Returns the root Layer of the Window.
255 * @return The root layer
257 Layer GetRootLayer() const;
260 * @brief Queries the number of on-scene layers in the Window.
262 * Note that a default layer is always provided (count >= 1).
265 * @return The number of layers
267 uint32_t GetLayerCount() const;
270 * @brief Retrieves the layer at a specified depth in the Window.
273 * @param[in] depth The depth
274 * @return The layer found at the given depth
275 * @pre Depth is less than layer count; see GetLayerCount().
277 Layer GetLayer( uint32_t depth ) const;
280 * @brief Retrieves the DPI of the window.
283 * @return The DPI of the window
285 Uint16Pair GetDpi() const;
288 * @brief Sets the window name and class string.
290 * @param[in] name The name of the window
291 * @param[in] klass The class of the window
293 void SetClass(std::string name, std::string klass);
296 * @brief Raises window to the top of Window stack.
302 * @brief Lowers window to the bottom of Window stack.
308 * @brief Activates window to the top of Window stack even it is iconified.
314 * @brief Adds an orientation to the list of available orientations.
316 * @param[in] orientation The available orientation to add
318 void AddAvailableOrientation( WindowOrientation orientation );
321 * @brief Removes an orientation from the list of available orientations.
323 * @param[in] orientation The available orientation to remove
325 void RemoveAvailableOrientation( WindowOrientation orientation );
328 * @brief Sets a preferred orientation.
330 * @param[in] orientation The preferred orientation
331 * @pre Orientation is in the list of available orientations.
333 * @note To unset the preferred orientation, orientation should be set NO_ORIENTATION_PREFERENCE.
335 void SetPreferredOrientation( WindowOrientation orientation );
338 * @brief Gets the preferred orientation.
340 * @return The preferred orientation if previously set, or none
342 WindowOrientation GetPreferredOrientation();
345 * @brief Gets the native handle of the window.
347 * When users call this function, it wraps the actual type used by the underlying window system.
349 * @return The native handle of the Window or an empty handle
351 Any GetNativeHandle() const;
354 * @brief Sets whether window accepts focus or not.
357 * @param[in] accept If focus is accepted or not. Default is true.
359 void SetAcceptFocus( bool accept );
362 * @brief Returns whether window accepts focus or not.
365 * @return True if the window accept focus, false otherwise
367 bool IsFocusAcceptable() const;
370 * @brief Shows the window if it is hidden.
376 * @brief Hides the window if it is showing.
382 * @brief Returns whether the window is visible or not.
384 * @return True if the window is visible, false otherwise.
386 bool IsVisible() const;
389 * @brief Gets the count of supported auxiliary hints of the window.
391 * @return The number of supported auxiliary hints.
393 * @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.
394 * If you want to set specific hint to your window, then you should check whether it exists in the supported auxiliary hints.
396 unsigned int GetSupportedAuxiliaryHintCount() const;
399 * @brief Gets the supported auxiliary hint string of the window.
401 * @param[in] index The index of the supported auxiliary hint lists
402 * @return The auxiliary hint string of the index.
404 * @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.
405 * If you want to set specific hint to your window, then you should check whether it exists in the supported auxiliary hints.
407 std::string GetSupportedAuxiliaryHint( unsigned int index ) const;
410 * @brief Creates an auxiliary hint of the window.
412 * @param[in] hint The auxiliary hint string.
413 * @param[in] value The value string.
414 * @return The ID of created auxiliary hint, or @c 0 on failure.
416 unsigned int AddAuxiliaryHint( const std::string& hint, const std::string& value );
419 * @brief Removes an auxiliary hint of the window.
421 * @param[in] id The ID of the auxiliary hint.
422 * @return True if no error occurred, false otherwise.
424 bool RemoveAuxiliaryHint( unsigned int id );
427 * @brief Changes a value of the auxiliary hint.
429 * @param[in] id The auxiliary hint ID.
430 * @param[in] value The value string to be set.
431 * @return True if no error occurred, false otherwise.
433 bool SetAuxiliaryHintValue( unsigned int id, const std::string& value );
436 * @brief Gets a value of the auxiliary hint.
438 * @param[in] id The auxiliary hint ID.
439 * @return The string value of the auxiliary hint ID, or an empty string if none exists.
441 std::string GetAuxiliaryHintValue( unsigned int id ) const;
444 * @brief Gets a ID of the auxiliary hint string.
446 * @param[in] hint The auxiliary hint string.
447 * @return The ID of the auxiliary hint string, or @c 0 if none exists.
449 unsigned int GetAuxiliaryHintId( const std::string& hint ) const;
452 * @brief Sets a region to accept input events.
454 * @param[in] inputRegion The region to accept input events.
456 void SetInputRegion( const Rect< int >& inputRegion );
459 * @brief Sets a window type.
461 * @param[in] type The window type.
462 * @remarks The default window type is NORMAL.
464 void SetType( Type type );
467 * @brief Gets a window type.
469 * @return A window type.
471 Type GetType() const;
474 * @brief Sets a priority level for the specified notification window.
476 * @param[in] level The notification window level.
477 * @return True if no error occurred, false otherwise.
479 * @PRIVILEGE_WINDOW_PRIORITY
480 * @remarks This can be used for a notification type window only. The default level is NotificationLevel::NONE.
482 bool SetNotificationLevel( NotificationLevel::Type level );
485 * @brief Gets a priority level for the specified notification window.
487 * @return The notification window level.
488 * @remarks This can be used for a notification type window only.
490 NotificationLevel::Type GetNotificationLevel() const;
493 * @brief Sets a transparent window's visual state to opaque.
494 * @details If a visual state of a transparent window is opaque,
495 * then the window manager could handle it as an opaque window when calculating visibility.
497 * @param[in] opaque Whether the window's visual state is opaque.
498 * @remarks This will have no effect on an opaque window.
499 * It doesn't change transparent window to opaque window but lets the window manager know the visual state of the window.
501 void SetOpaqueState( bool opaque );
504 * @brief Returns whether a transparent window's visual state is opaque or not.
506 * @return True if the window's visual state is opaque, false otherwise.
507 * @remarks The return value has no meaning on an opaque window.
509 bool IsOpaqueState() const;
512 * @brief Sets a window's screen off mode.
513 * @details This API is useful when the application needs to keep the display turned on.
514 * If the application sets the screen mode to #::Dali::Window::ScreenOffMode::NEVER to its window and the window is shown,
515 * the window manager requests the display system to keep the display on as long as the window is shown.
516 * If the window is no longer shown, then the window manager requests the display system to go back to normal operation.
518 * @param[in] screenOffMode The screen mode.
519 * @return True if no error occurred, false otherwise.
523 bool SetScreenOffMode(ScreenOffMode::Type screenOffMode);
526 * @brief Gets a screen off mode of the window.
528 * @return The screen off mode.
530 ScreenOffMode::Type GetScreenOffMode() const;
533 * @brief Sets preferred brightness of the window.
534 * @details This API is useful when the application needs to change the brightness of the screen when it is appeared on the screen.
535 * 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.
536 * If the window is no longer shown, then the window manager requests the display system to go back to default brightness.
537 * A value less than 0 results in default brightness and a value greater than 100 results in maximum brightness.
539 * @param[in] brightness The preferred brightness (0 to 100).
540 * @return True if no error occurred, false otherwise.
544 bool SetBrightness( int brightness );
547 * @brief Gets preferred brightness of the window.
549 * @return The preferred brightness.
551 int GetBrightness() const;
554 * @brief Sets a size of the window.
557 * @param[in] size The new window size
559 void SetSize( WindowSize size );
562 * @brief Gets a size of the window.
565 * @return The size of the window
567 WindowSize GetSize() const;
570 * @brief Sets a position of the window.
573 * @param[in] position The new window position
575 void SetPosition( WindowPosition position );
578 * @brief Gets a position of the window.
581 * @return The position of the window
583 WindowPosition GetPosition() const;
586 * @brief Sets whether the window is transparent or not.
589 * @param[in] transparent Whether the window is transparent
591 void SetTransparency( bool transparent );
594 * @brief Retrieves the list of render-tasks in the window.
597 * @return A valid handle to a RenderTaskList
599 RenderTaskList GetRenderTaskList();
604 * @brief This signal is emitted when the window is resized.
606 * A callback of the following type may be connected:
608 * void YourCallbackName( int width, int height );
610 * The parameters are the resized width and height.
613 * @return The signal to connect to
615 ResizedSignalType& ResizedSignal() DALI_DEPRECATED_API;
618 * @brief The user should connect to this signal to get a timing when window gains focus or loses focus.
620 * A callback of the following type may be connected:
622 * void YourCallbackName( Window window, bool focusIn );
624 * The parameter is true if window gains focus, otherwise false.
625 * and window means this signal was called from what window
628 * @return The signal to connect to
630 FocusChangeSignalType& FocusChangeSignal();
633 * @brief This signal is emitted when the window is resized.
635 * A callback of the following type may be connected:
637 * void YourCallbackName( Window window, int width, int height );
639 * The parameters are the resized width and height.
640 * and window means this signal was called from what window
643 * @return The signal to connect to
645 ResizeSignalType& ResizeSignal();
648 * @brief This signal is emitted when key event is received.
650 * A callback of the following type may be connected:
652 * void YourCallbackName(const KeyEvent& event);
656 * @return The signal to connect to
658 KeyEventSignalType& KeyEventSignal();
661 * @brief This signal is emitted when the screen is touched and when the touch ends
662 * (i.e. the down & up touch events only).
664 * If there are multiple touch points, then this will be emitted when the first touch occurs and
665 * then when the last finger is lifted.
666 * An interrupted event will also be emitted (if it occurs).
667 * A callback of the following type may be connected:
669 * void YourCallbackName(const TouchData& event);
673 * @return The touch signal to connect to
675 * @note Motion events are not emitted.
677 TouchSignalType& TouchSignal();
679 public: // Not intended for application developers
682 * @brief This constructor is used by Dali::Application::GetWindow().
684 * @param[in] window A pointer to the Window
686 explicit DALI_INTERNAL Window( Internal::Adaptor::Window* window );
695 #endif // __DALI_WINDOW_H__