5 * Copyright (c) 2023 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.
22 #include <dali/public-api/adaptor-framework/window-data.h>
23 #include <dali/public-api/adaptor-framework/window-enumerations.h>
24 #include <dali/public-api/math/int-pair.h>
25 #include <dali/public-api/math/rect.h>
26 #include <dali/public-api/math/uint-16-pair.h>
27 #include <dali/public-api/math/vector2.h>
28 #include <dali/public-api/math/vector4.h>
29 #include <dali/public-api/object/any.h>
30 #include <dali/public-api/object/base-handle.h>
31 #include <dali/public-api/signals/dali-signal.h>
35 #include <dali/public-api/dali-adaptor-common.h>
43 * @addtogroup dali_adaptor_framework
47 typedef Dali::Rect<int> PositionSize;
49 namespace Internal DALI_INTERNAL
55 } // namespace DALI_INTERNAL
57 class DragAndDropDetector;
66 * @brief The window class is used internally for drawing.
68 * A Window has an orientation and indicator properties.
69 * You can get a valid Window handle by calling Dali::Application::GetWindow().
72 class DALI_ADAPTOR_API Window : public BaseHandle
75 using WindowSize = Uint16Pair; ///< Window size type @SINCE_1_2.60
76 using WindowPosition = Int32Pair; ///< Window position type @SINCE_2_1.45
78 using FocusChangeSignalType = Signal<void(Window, bool)>; ///< Window focus signal type @SINCE_1_4.35
79 using ResizeSignalType = Signal<void(Window, WindowSize)>; ///< Window resized signal type @SINCE_1_4.35
80 using KeyEventSignalType = Signal<void(const KeyEvent&)>; ///< Key event signal type @SINCE_1_9.21
81 using TouchEventSignalType = Signal<void(const TouchEvent&)>; ///< Touch signal type @SINCE_1_9.28
87 * @brief Creates an initialized handle to a new Window.
89 * @param[in] windowPosition The position and size of the Window
90 * @param[in] name The Window title
91 * @param[in] isTransparent Whether Window is transparent
92 * @return A new window
93 * @note This creates an extra window in addition to the default main window
95 static Window New(PositionSize windowPosition, const std::string& name, bool isTransparent = false);
98 * @brief Creates an initialized handle to a new Window.
100 * @param[in] windowPosition The position and size of the Window
101 * @param[in] name The Window title
102 * @param[in] className The Window class name
103 * @param[in] isTransparent Whether Window is transparent
104 * @note This creates an extra window in addition to the default main window
105 * @return A new Window
107 static Window New(PositionSize windowPosition, const std::string& name, const std::string& className, bool isTransparent = false);
110 * @brief Creates an initialized handle to a new Window.
112 * @param[in] name The Window title
113 * @param[in] className The Window class name
114 * @param[in] windowData The window data
115 * @note This creates an extra window in addition to the default main window
116 * @return A new Window
118 static Window New(const std::string& name, const std::string& className, const WindowData& windowData);
121 * @brief Creates an uninitialized handle.
123 * This can be initialized using Dali::Application::GetWindow() or
124 * Dali::Window::New().
132 * This is non-virtual since derived Handle types must not contain data or virtual methods.
138 * @brief This copy constructor is required for (smart) pointer semantics.
141 * @param[in] handle A reference to the copied handle
143 Window(const Window& handle);
146 * @brief This assignment operator is required for (smart) pointer semantics.
149 * @param[in] rhs A reference to the copied handle
150 * @return A reference to this
152 Window& operator=(const Window& rhs);
155 * @brief Move constructor.
158 * @param[in] rhs A reference to the moved handle
160 Window(Window&& rhs) noexcept;
163 * @brief Move assignment operator.
166 * @param[in] rhs A reference to the moved handle
167 * @return A reference to this handle
169 Window& operator=(Window&& rhs) noexcept;
172 * @brief Downcast sceneHolder to window
175 * @param[in] handle The handle need to downcast
176 * @return Whether it's a valid window or not
178 static Window DownCast(BaseHandle handle);
181 * @brief Adds a child Actor to the Window.
183 * The child will be referenced.
186 * @param[in] actor The child
187 * @pre The actor has been initialized.
188 * @pre The actor does not have a parent.
190 void Add(Actor actor);
193 * @brief Removes a child Actor from the Window.
195 * The child will be unreferenced.
198 * @param[in] actor The child
199 * @pre The actor has been added to the stage.
201 void Remove(Actor actor);
204 * @brief Sets the background color of the Window.
207 * @param[in] color The new background color
209 void SetBackgroundColor(const Vector4& color);
212 * @brief Gets the background color of the Window.
215 * @return The background color
217 Vector4 GetBackgroundColor() const;
220 * @brief Returns the root Layer of the Window.
223 * @return The root layer
225 Layer GetRootLayer() const;
228 * @brief Returns the overlay Layer of the Window.
229 * If there isn't overlay layer yet, this method create overlay layer and
230 * exclusive render task internally.
233 * @return The root layer
235 Layer GetOverlayLayer();
238 * @brief Queries the number of on-scene layers in the Window.
240 * Note that a default layer is always provided (count >= 1).
243 * @return The number of layers
245 uint32_t GetLayerCount() const;
248 * @brief Retrieves the layer at a specified depth in the Window.
251 * @param[in] depth The depth
252 * @return The layer found at the given depth
253 * @pre Depth is less than layer count; see GetLayerCount().
255 Layer GetLayer(uint32_t depth) const;
258 * @brief Retrieves the DPI of the window.
261 * @return The DPI of the window
263 Uint16Pair GetDpi() const;
266 * @brief Sets the window name and class string.
268 * @param[in] name The name of the window
269 * @param[in] klass The class of the window
271 void SetClass(std::string name, std::string klass);
274 * @brief Raises window to the top of Window stack.
280 * @brief Lowers window to the bottom of Window stack.
286 * @brief Activates window to the top of Window stack even it is iconified.
292 * @brief Adds an orientation to the list of available orientations.
294 * @param[in] orientation The available orientation to add
296 void AddAvailableOrientation(WindowOrientation orientation);
299 * @brief Removes an orientation from the list of available orientations.
301 * @param[in] orientation The available orientation to remove
303 void RemoveAvailableOrientation(WindowOrientation orientation);
306 * @brief Sets a preferred orientation.
308 * @param[in] orientation The preferred orientation
309 * @pre Orientation is in the list of available orientations.
311 * @note To unset the preferred orientation, orientation should be set NO_ORIENTATION_PREFERENCE.
313 void SetPreferredOrientation(WindowOrientation orientation);
316 * @brief Gets the preferred orientation.
318 * @return The preferred orientation if previously set, or none
320 WindowOrientation GetPreferredOrientation();
323 * @brief Gets the native handle of the window.
325 * When users call this function, it wraps the actual type used by the underlying window system.
327 * @return The native handle of the Window or an empty handle
329 Any GetNativeHandle() const;
332 * @brief Sets whether window accepts focus or not.
335 * @param[in] accept If focus is accepted or not. Default is true.
337 void SetAcceptFocus(bool accept);
340 * @brief Returns whether window accepts focus or not.
343 * @return True if the window accept focus, false otherwise
345 bool IsFocusAcceptable() const;
348 * @brief Shows the window if it is hidden.
354 * @brief Hides the window if it is showing.
360 * @brief Returns whether the window is visible or not.
362 * @return True if the window is visible, false otherwise.
364 bool IsVisible() const;
367 * @brief Gets the count of supported auxiliary hints of the window.
369 * @return The number of supported auxiliary hints.
371 * @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.
372 * If you want to set specific hint to your window, then you should check whether it exists in the supported auxiliary hints.
374 unsigned int GetSupportedAuxiliaryHintCount() const;
377 * @brief Gets the supported auxiliary hint string of the window.
379 * @param[in] index The index of the supported auxiliary hint lists
380 * @return The auxiliary hint string of the index.
382 * @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.
383 * If you want to set specific hint to your window, then you should check whether it exists in the supported auxiliary hints.
385 std::string GetSupportedAuxiliaryHint(unsigned int index) const;
388 * @brief Creates an auxiliary hint of the window.
390 * @param[in] hint The auxiliary hint string.
391 * @param[in] value The value string.
392 * @return The ID of created auxiliary hint, or @c 0 on failure.
394 unsigned int AddAuxiliaryHint(const std::string& hint, const std::string& value);
397 * @brief Removes an auxiliary hint of the window.
399 * @param[in] id The ID of the auxiliary hint.
400 * @return True if no error occurred, false otherwise.
402 bool RemoveAuxiliaryHint(unsigned int id);
405 * @brief Changes a value of the auxiliary hint.
407 * @param[in] id The auxiliary hint ID.
408 * @param[in] value The value string to be set.
409 * @return True if no error occurred, false otherwise.
411 bool SetAuxiliaryHintValue(unsigned int id, const std::string& value);
414 * @brief Gets a value of the auxiliary hint.
416 * @param[in] id The auxiliary hint ID.
417 * @return The string value of the auxiliary hint ID, or an empty string if none exists.
419 std::string GetAuxiliaryHintValue(unsigned int id) const;
422 * @brief Gets a ID of the auxiliary hint string.
424 * @param[in] hint The auxiliary hint string.
425 * @return The ID of the auxiliary hint string, or @c 0 if none exists.
427 unsigned int GetAuxiliaryHintId(const std::string& hint) const;
430 * @brief Sets a region to accept input events.
432 * @param[in] inputRegion The region to accept input events.
434 void SetInputRegion(const Rect<int>& inputRegion);
437 * @brief Sets a window type.
439 * @param[in] type The window type.
440 * @remarks The default window type is NORMAL.
442 void SetType(WindowType type);
445 * @brief Gets a window type.
447 * @return A window type.
449 WindowType GetType() const;
452 * @brief Sets a priority level for the specified notification window.
454 * @param[in] level The notification window level.
455 * @return The result of the window operation.
457 * @PRIVILEGE_WINDOW_PRIORITY
458 * @remarks This can be used for a notification type window only. The default level is NotificationLevel::NONE.
460 WindowOperationResult SetNotificationLevel(WindowNotificationLevel level);
463 * @brief Gets a priority level for the specified notification window.
465 * @return The notification window level.
466 * @remarks This can be used for a notification type window only.
468 WindowNotificationLevel GetNotificationLevel() const;
471 * @brief Sets a transparent window's visual state to opaque.
472 * @details If a visual state of a transparent window is opaque,
473 * then the window manager could handle it as an opaque window when calculating visibility.
475 * @param[in] opaque Whether the window's visual state is opaque.
476 * @remarks This will have no effect on an opaque window.
477 * It doesn't change transparent window to opaque window but lets the window manager know the visual state of the window.
479 void SetOpaqueState(bool opaque);
482 * @brief Returns whether a transparent window's visual state is opaque or not.
484 * @return True if the window's visual state is opaque, false otherwise.
485 * @remarks The return value has no meaning on an opaque window.
487 bool IsOpaqueState() const;
490 * @brief Sets a window's screen off mode.
491 * @details This API is useful when the application needs to keep the display turned on.
492 * If the application sets the screen mode to #::Dali::WindowScreenOffMode::NEVER to its window and the window is shown,
493 * the window manager requests the display system to keep the display on as long as the window is shown.
494 * If the window is no longer shown, then the window manager requests the display system to go back to normal operation.
496 * @param[in] screenOffMode The screen mode.
497 * @return The result of the window operation.
501 WindowOperationResult SetScreenOffMode(WindowScreenOffMode screenOffMode);
504 * @brief Gets a screen off mode of the window.
506 * @return The screen off mode.
508 WindowScreenOffMode GetScreenOffMode() const;
511 * @brief Sets preferred brightness of the window.
512 * @details This API is useful when the application needs to change the brightness of the screen when it is appeared on the screen.
513 * 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.
514 * If the window is no longer shown, then the window manager requests the display system to go back to default brightness.
515 * A value less than 0 results in default brightness and a value greater than 100 results in maximum brightness.
517 * @param[in] brightness The preferred brightness (0 to 100).
518 * @return The result of the window operation.
522 WindowOperationResult SetBrightness(int brightness);
525 * @brief Gets preferred brightness of the window.
527 * @return The preferred brightness.
529 int GetBrightness() const;
532 * @brief Sets a size of the window.
535 * @param[in] size The new window size
537 void SetSize(WindowSize size);
540 * @brief Gets a size of the window.
543 * @return The size of the window
545 WindowSize GetSize() const;
548 * @brief Sets a position of the window.
551 * @param[in] position The new window position
553 void SetPosition(WindowPosition position);
556 * @brief Gets a position of the window.
559 * @return The position of the window
561 WindowPosition GetPosition() const;
564 * @brief Sets the layout of the window.
566 * This method sets the layout of the window based on the specified number of columns and rows,
567 * as well as the position and size of the window within that layout.
569 * @param numCols The number of columns in the layout.
570 * @param numRows The number of rows in the layout.
571 * @param column The column number of the window within the layout.
572 * @param row The row number of the window within the layout.
573 * @param colSpan The number of columns the window should span within the layout.
574 * @param rowSpan The number of rows the window should span within the layout.
577 void SetLayout(unsigned int numCols, unsigned int numRows, unsigned int column, unsigned int row, unsigned int colSpan, unsigned int rowSpan);
580 * @brief Sets whether the window is transparent or not.
583 * @param[in] transparent Whether the window is transparent
585 void SetTransparency(bool transparent);
588 * @brief Retrieves the list of render-tasks in the window.
591 * @return A valid handle to a RenderTaskList
593 RenderTaskList GetRenderTaskList();
596 * @brief Keeps rendering for at least the given amount of time.
598 * By default, Dali will stop rendering when no Actor positions are being set, and when no animations are running etc.
599 * This method is useful to force screen refreshes.
602 * @param[in] durationSeconds Time to keep rendering, 0 means render at least one more frame
604 void KeepRendering(float durationSeconds);
607 * @brief Sets whether the window will update partial area or full area.
610 * @param[in] enabled True if the window should update partial area
611 * @note This doesn't change the global value which is set by the environment variable.
612 * This works when partial update is enabled by the environment variable. If the partial update is disabled by the environment variable, it changes nothing.
614 void SetPartialUpdateEnabled(bool enabled);
617 * @brief Queries whether the window will update partial area.
620 * @return True if the window should update partial area
622 bool IsPartialUpdateEnabled() const;
626 * @brief The user should connect to this signal to get a timing when window gains focus or loses focus.
628 * A callback of the following type may be connected:
630 * void YourCallbackName( Window window, bool focusIn );
632 * The parameter is true if window gains focus, otherwise false.
633 * and window means this signal was called from what window
636 * @return The signal to connect to
638 FocusChangeSignalType& FocusChangeSignal();
641 * @brief This signal is emitted when the window is resized.
643 * A callback of the following type may be connected:
645 * void YourCallbackName( Window window, int width, int height );
647 * The parameters are the resized width and height.
648 * and window means this signal was called from what window
651 * @return The signal to connect to
653 ResizeSignalType& ResizeSignal();
656 * @brief This signal is emitted when key event is received.
658 * A callback of the following type may be connected:
660 * void YourCallbackName(const KeyEvent& event);
664 * @return The signal to connect to
666 KeyEventSignalType& KeyEventSignal();
669 * @brief This signal is emitted when the screen is touched and when the touch ends
670 * (i.e. the down & up touch events only).
672 * If there are multiple touch points, then this will be emitted when the first touch occurs and
673 * then when the last finger is lifted.
674 * An interrupted event will also be emitted (if it occurs).
675 * A callback of the following type may be connected:
677 * void YourCallbackName(const TouchEvent& event);
681 * @return The touch signal to connect to
683 * @note Motion events are not emitted.
685 TouchEventSignalType& TouchedSignal();
687 public: // Not intended for application developers
690 * @brief This constructor is used by Dali::Application::GetWindow().
692 * @param[in] window A pointer to the Window
694 explicit DALI_INTERNAL Window(Internal::Adaptor::Window* window);
703 #endif // __DALI_WINDOW_H__