5 * Copyright (c) 2022 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-enumerations.h>
23 #include <dali/public-api/math/int-pair.h>
24 #include <dali/public-api/math/rect.h>
25 #include <dali/public-api/math/uint-16-pair.h>
26 #include <dali/public-api/math/vector2.h>
27 #include <dali/public-api/math/vector4.h>
28 #include <dali/public-api/object/any.h>
29 #include <dali/public-api/object/base-handle.h>
30 #include <dali/public-api/signals/dali-signal.h>
34 #include <dali/public-api/dali-adaptor-common.h>
42 * @addtogroup dali_adaptor_framework
46 typedef Dali::Rect<int> PositionSize;
48 namespace Internal DALI_INTERNAL
54 } // namespace DALI_INTERNAL
56 class DragAndDropDetector;
65 * @brief The window class is used internally for drawing.
67 * A Window has an orientation and indicator properties.
68 * You can get a valid Window handle by calling Dali::Application::GetWindow().
71 class DALI_ADAPTOR_API Window : public BaseHandle
74 using WindowSize = Uint16Pair; ///< Window size type @SINCE_1_2.60
75 using WindowPosition = Int32Pair; ///< Window position type @SINCE_2_1.45
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 @SINCE_1_9.21
80 using TouchEventSignalType = Signal<void(const TouchEvent&)>; ///< Touch signal type @SINCE_1_9.28
86 * @brief Creates an initialized handle to a new Window.
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
94 static Window New(PositionSize windowPosition, const std::string& name, bool isTransparent = false);
97 * @brief Creates an initialized handle to a new Window.
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
106 static Window New(PositionSize windowPosition, const std::string& name, const std::string& className, bool isTransparent = false);
109 * @brief Creates an uninitialized handle.
111 * This can be initialized using Dali::Application::GetWindow() or
112 * Dali::Window::New().
120 * This is non-virtual since derived Handle types must not contain data or virtual methods.
126 * @brief This copy constructor is required for (smart) pointer semantics.
129 * @param[in] handle A reference to the copied handle
131 Window(const Window& handle);
134 * @brief This assignment operator is required for (smart) pointer semantics.
137 * @param[in] rhs A reference to the copied handle
138 * @return A reference to this
140 Window& operator=(const Window& rhs);
143 * @brief Move constructor.
146 * @param[in] rhs A reference to the moved handle
148 Window(Window&& rhs);
151 * @brief Move assignment operator.
154 * @param[in] rhs A reference to the moved handle
155 * @return A reference to this handle
157 Window& operator=(Window&& rhs);
160 * @brief Downcast sceneHolder to window
163 * @param[in] handle The handle need to downcast
164 * @return Whether it's a valid window or not
166 static Window DownCast(BaseHandle handle);
169 * @brief Adds a child Actor to the Window.
171 * The child will be referenced.
174 * @param[in] actor The child
175 * @pre The actor has been initialized.
176 * @pre The actor does not have a parent.
178 void Add(Actor actor);
181 * @brief Removes a child Actor from the Window.
183 * The child will be unreferenced.
186 * @param[in] actor The child
187 * @pre The actor has been added to the stage.
189 void Remove(Actor actor);
192 * @brief Sets the background color of the Window.
195 * @param[in] color The new background color
197 void SetBackgroundColor(const Vector4& color);
200 * @brief Gets the background color of the Window.
203 * @return The background color
205 Vector4 GetBackgroundColor() const;
208 * @brief Returns the root Layer of the Window.
211 * @return The root layer
213 Layer GetRootLayer() const;
216 * @brief Queries the number of on-scene layers in the Window.
218 * Note that a default layer is always provided (count >= 1).
221 * @return The number of layers
223 uint32_t GetLayerCount() const;
226 * @brief Retrieves the layer at a specified depth in the Window.
229 * @param[in] depth The depth
230 * @return The layer found at the given depth
231 * @pre Depth is less than layer count; see GetLayerCount().
233 Layer GetLayer(uint32_t depth) const;
236 * @brief Retrieves the DPI of the window.
239 * @return The DPI of the window
241 Uint16Pair GetDpi() const;
244 * @brief Sets the window name and class string.
246 * @param[in] name The name of the window
247 * @param[in] klass The class of the window
249 void SetClass(std::string name, std::string klass);
252 * @brief Raises window to the top of Window stack.
258 * @brief Lowers window to the bottom of Window stack.
264 * @brief Activates window to the top of Window stack even it is iconified.
270 * @brief Adds an orientation to the list of available orientations.
272 * @param[in] orientation The available orientation to add
274 void AddAvailableOrientation(WindowOrientation orientation);
277 * @brief Removes an orientation from the list of available orientations.
279 * @param[in] orientation The available orientation to remove
281 void RemoveAvailableOrientation(WindowOrientation orientation);
284 * @brief Sets a preferred orientation.
286 * @param[in] orientation The preferred orientation
287 * @pre Orientation is in the list of available orientations.
289 * @note To unset the preferred orientation, orientation should be set NO_ORIENTATION_PREFERENCE.
291 void SetPreferredOrientation(WindowOrientation orientation);
294 * @brief Gets the preferred orientation.
296 * @return The preferred orientation if previously set, or none
298 WindowOrientation GetPreferredOrientation();
301 * @brief Gets the native handle of the window.
303 * When users call this function, it wraps the actual type used by the underlying window system.
305 * @return The native handle of the Window or an empty handle
307 Any GetNativeHandle() const;
310 * @brief Sets whether window accepts focus or not.
313 * @param[in] accept If focus is accepted or not. Default is true.
315 void SetAcceptFocus(bool accept);
318 * @brief Returns whether window accepts focus or not.
321 * @return True if the window accept focus, false otherwise
323 bool IsFocusAcceptable() const;
326 * @brief Shows the window if it is hidden.
332 * @brief Hides the window if it is showing.
338 * @brief Returns whether the window is visible or not.
340 * @return True if the window is visible, false otherwise.
342 bool IsVisible() const;
345 * @brief Gets the count of supported auxiliary hints of the window.
347 * @return The number of supported auxiliary hints.
349 * @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.
350 * If you want to set specific hint to your window, then you should check whether it exists in the supported auxiliary hints.
352 unsigned int GetSupportedAuxiliaryHintCount() const;
355 * @brief Gets the supported auxiliary hint string of the window.
357 * @param[in] index The index of the supported auxiliary hint lists
358 * @return The auxiliary hint string of the index.
360 * @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.
361 * If you want to set specific hint to your window, then you should check whether it exists in the supported auxiliary hints.
363 std::string GetSupportedAuxiliaryHint(unsigned int index) const;
366 * @brief Creates an auxiliary hint of the window.
368 * @param[in] hint The auxiliary hint string.
369 * @param[in] value The value string.
370 * @return The ID of created auxiliary hint, or @c 0 on failure.
372 unsigned int AddAuxiliaryHint(const std::string& hint, const std::string& value);
375 * @brief Removes an auxiliary hint of the window.
377 * @param[in] id The ID of the auxiliary hint.
378 * @return True if no error occurred, false otherwise.
380 bool RemoveAuxiliaryHint(unsigned int id);
383 * @brief Changes a value of the auxiliary hint.
385 * @param[in] id The auxiliary hint ID.
386 * @param[in] value The value string to be set.
387 * @return True if no error occurred, false otherwise.
389 bool SetAuxiliaryHintValue(unsigned int id, const std::string& value);
392 * @brief Gets a value of the auxiliary hint.
394 * @param[in] id The auxiliary hint ID.
395 * @return The string value of the auxiliary hint ID, or an empty string if none exists.
397 std::string GetAuxiliaryHintValue(unsigned int id) const;
400 * @brief Gets a ID of the auxiliary hint string.
402 * @param[in] hint The auxiliary hint string.
403 * @return The ID of the auxiliary hint string, or @c 0 if none exists.
405 unsigned int GetAuxiliaryHintId(const std::string& hint) const;
408 * @brief Sets a region to accept input events.
410 * @param[in] inputRegion The region to accept input events.
412 void SetInputRegion(const Rect<int>& inputRegion);
415 * @brief Sets a window type.
417 * @param[in] type The window type.
418 * @remarks The default window type is NORMAL.
420 void SetType(WindowType type);
423 * @brief Gets a window type.
425 * @return A window type.
427 WindowType GetType() const;
430 * @brief Sets a priority level for the specified notification window.
432 * @param[in] level The notification window level.
433 * @return The result of the window operation.
435 * @PRIVILEGE_WINDOW_PRIORITY
436 * @remarks This can be used for a notification type window only. The default level is NotificationLevel::NONE.
438 WindowOperationResult SetNotificationLevel(WindowNotificationLevel level);
441 * @brief Gets a priority level for the specified notification window.
443 * @return The notification window level.
444 * @remarks This can be used for a notification type window only.
446 WindowNotificationLevel GetNotificationLevel() const;
449 * @brief Sets a transparent window's visual state to opaque.
450 * @details If a visual state of a transparent window is opaque,
451 * then the window manager could handle it as an opaque window when calculating visibility.
453 * @param[in] opaque Whether the window's visual state is opaque.
454 * @remarks This will have no effect on an opaque window.
455 * It doesn't change transparent window to opaque window but lets the window manager know the visual state of the window.
457 void SetOpaqueState(bool opaque);
460 * @brief Returns whether a transparent window's visual state is opaque or not.
462 * @return True if the window's visual state is opaque, false otherwise.
463 * @remarks The return value has no meaning on an opaque window.
465 bool IsOpaqueState() const;
468 * @brief Sets a window's screen off mode.
469 * @details This API is useful when the application needs to keep the display turned on.
470 * If the application sets the screen mode to #::Dali::WindowScreenOffMode::NEVER to its window and the window is shown,
471 * the window manager requests the display system to keep the display on as long as the window is shown.
472 * If the window is no longer shown, then the window manager requests the display system to go back to normal operation.
474 * @param[in] screenOffMode The screen mode.
475 * @return The result of the window operation.
479 WindowOperationResult SetScreenOffMode(WindowScreenOffMode screenOffMode);
482 * @brief Gets a screen off mode of the window.
484 * @return The screen off mode.
486 WindowScreenOffMode GetScreenOffMode() const;
489 * @brief Sets preferred brightness of the window.
490 * @details This API is useful when the application needs to change the brightness of the screen when it is appeared on the screen.
491 * 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.
492 * If the window is no longer shown, then the window manager requests the display system to go back to default brightness.
493 * A value less than 0 results in default brightness and a value greater than 100 results in maximum brightness.
495 * @param[in] brightness The preferred brightness (0 to 100).
496 * @return The result of the window operation.
500 WindowOperationResult SetBrightness(int brightness);
503 * @brief Gets preferred brightness of the window.
505 * @return The preferred brightness.
507 int GetBrightness() const;
510 * @brief Sets a size of the window.
513 * @param[in] size The new window size
515 void SetSize(WindowSize size);
518 * @brief Gets a size of the window.
521 * @return The size of the window
523 WindowSize GetSize() const;
526 * @brief Sets a position of the window.
529 * @param[in] position The new window position
531 void SetPosition(WindowPosition position);
534 * @brief Gets a position of the window.
537 * @return The position of the window
539 WindowPosition GetPosition() const;
542 * @brief Sets whether the window is transparent or not.
545 * @param[in] transparent Whether the window is transparent
547 void SetTransparency(bool transparent);
550 * @brief Retrieves the list of render-tasks in the window.
553 * @return A valid handle to a RenderTaskList
555 RenderTaskList GetRenderTaskList();
559 * @brief The user should connect to this signal to get a timing when window gains focus or loses focus.
561 * A callback of the following type may be connected:
563 * void YourCallbackName( Window window, bool focusIn );
565 * The parameter is true if window gains focus, otherwise false.
566 * and window means this signal was called from what window
569 * @return The signal to connect to
571 FocusChangeSignalType& FocusChangeSignal();
574 * @brief This signal is emitted when the window is resized.
576 * A callback of the following type may be connected:
578 * void YourCallbackName( Window window, int width, int height );
580 * The parameters are the resized width and height.
581 * and window means this signal was called from what window
584 * @return The signal to connect to
586 ResizeSignalType& ResizeSignal();
589 * @brief This signal is emitted when key event is received.
591 * A callback of the following type may be connected:
593 * void YourCallbackName(const KeyEvent& event);
597 * @return The signal to connect to
599 KeyEventSignalType& KeyEventSignal();
602 * @brief This signal is emitted when the screen is touched and when the touch ends
603 * (i.e. the down & up touch events only).
605 * If there are multiple touch points, then this will be emitted when the first touch occurs and
606 * then when the last finger is lifted.
607 * An interrupted event will also be emitted (if it occurs).
608 * A callback of the following type may be connected:
610 * void YourCallbackName(const TouchEvent& event);
614 * @return The touch signal to connect to
616 * @note Motion events are not emitted.
618 TouchEventSignalType& TouchedSignal();
620 public: // Not intended for application developers
623 * @brief This constructor is used by Dali::Application::GetWindow().
625 * @param[in] window A pointer to the Window
627 explicit DALI_INTERNAL Window(Internal::Adaptor::Window* window);
636 #endif // __DALI_WINDOW_H__