5 * Copyright (c) 2021 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/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/any.h>
28 #include <dali/public-api/object/base-handle.h>
29 #include <dali/public-api/signals/dali-signal.h>
33 #include <dali/public-api/dali-adaptor-common.h>
41 * @addtogroup dali_adaptor_framework
45 typedef Dali::Rect<int> PositionSize;
47 namespace Internal DALI_INTERNAL
53 } // namespace DALI_INTERNAL
55 class DragAndDropDetector;
64 * @brief The window class is used internally for drawing.
66 * A Window has an orientation and indicator properties.
67 * You can get a valid Window handle by calling Dali::Application::GetWindow().
70 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 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
85 * @brief Creates an initialized handle to a new Window.
87 * @param[in] windowPosition The position and size of the Window
88 * @param[in] name The Window title
89 * @param[in] isTransparent Whether Window is transparent
90 * @return A new window
91 * @note This creates an extra window in addition to the default main window
93 static Window New(PositionSize windowPosition, const std::string& name, bool isTransparent = false);
96 * @brief Creates an initialized handle to a new Window.
98 * @param[in] windowPosition The position and size of the Window
99 * @param[in] name The Window title
100 * @param[in] className The Window class name
101 * @param[in] isTransparent Whether Window is transparent
102 * @note This creates an extra window in addition to the default main window
103 * @return A new Window
105 static Window New(PositionSize windowPosition, const std::string& name, const std::string& className, bool isTransparent = false);
108 * @brief Creates an uninitialized handle.
110 * This can be initialized using Dali::Application::GetWindow() or
111 * Dali::Window::New().
119 * This is non-virtual since derived Handle types must not contain data or virtual methods.
125 * @brief This copy constructor is required for (smart) pointer semantics.
128 * @param[in] handle A reference to the copied handle
130 Window(const Window& handle);
133 * @brief This assignment operator is required for (smart) pointer semantics.
136 * @param[in] rhs A reference to the copied handle
137 * @return A reference to this
139 Window& operator=(const Window& rhs);
142 * @brief Move constructor.
145 * @param[in] rhs A reference to the moved handle
147 Window(Window&& rhs);
150 * @brief Move assignment operator.
153 * @param[in] rhs A reference to the moved handle
154 * @return A reference to this handle
156 Window& operator=(Window&& rhs);
159 * @brief Adds a child Actor to the Window.
161 * The child will be referenced.
164 * @param[in] actor The child
165 * @pre The actor has been initialized.
166 * @pre The actor does not have a parent.
168 void Add(Actor actor);
171 * @brief Removes a child Actor from the Window.
173 * The child will be unreferenced.
176 * @param[in] actor The child
177 * @pre The actor has been added to the stage.
179 void Remove(Actor actor);
182 * @brief Sets the background color of the Window.
185 * @param[in] color The new background color
187 void SetBackgroundColor(const Vector4& color);
190 * @brief Gets the background color of the Window.
193 * @return The background color
195 Vector4 GetBackgroundColor() const;
198 * @brief Returns the root Layer of the Window.
201 * @return The root layer
203 Layer GetRootLayer() const;
206 * @brief Queries the number of on-scene layers in the Window.
208 * Note that a default layer is always provided (count >= 1).
211 * @return The number of layers
213 uint32_t GetLayerCount() const;
216 * @brief Retrieves the layer at a specified depth in the Window.
219 * @param[in] depth The depth
220 * @return The layer found at the given depth
221 * @pre Depth is less than layer count; see GetLayerCount().
223 Layer GetLayer(uint32_t depth) const;
226 * @brief Retrieves the DPI of the window.
229 * @return The DPI of the window
231 Uint16Pair GetDpi() const;
234 * @brief Sets the window name and class string.
236 * @param[in] name The name of the window
237 * @param[in] klass The class of the window
239 void SetClass(std::string name, std::string klass);
242 * @brief Raises window to the top of Window stack.
248 * @brief Lowers window to the bottom of Window stack.
254 * @brief Activates window to the top of Window stack even it is iconified.
260 * @brief Adds an orientation to the list of available orientations.
262 * @param[in] orientation The available orientation to add
264 void AddAvailableOrientation(WindowOrientation orientation);
267 * @brief Removes an orientation from the list of available orientations.
269 * @param[in] orientation The available orientation to remove
271 void RemoveAvailableOrientation(WindowOrientation orientation);
274 * @brief Sets a preferred orientation.
276 * @param[in] orientation The preferred orientation
277 * @pre Orientation is in the list of available orientations.
279 * @note To unset the preferred orientation, orientation should be set NO_ORIENTATION_PREFERENCE.
281 void SetPreferredOrientation(WindowOrientation orientation);
284 * @brief Gets the preferred orientation.
286 * @return The preferred orientation if previously set, or none
288 WindowOrientation GetPreferredOrientation();
291 * @brief Gets the native handle of the window.
293 * When users call this function, it wraps the actual type used by the underlying window system.
295 * @return The native handle of the Window or an empty handle
297 Any GetNativeHandle() const;
300 * @brief Sets whether window accepts focus or not.
303 * @param[in] accept If focus is accepted or not. Default is true.
305 void SetAcceptFocus(bool accept);
308 * @brief Returns whether window accepts focus or not.
311 * @return True if the window accept focus, false otherwise
313 bool IsFocusAcceptable() const;
316 * @brief Shows the window if it is hidden.
322 * @brief Hides the window if it is showing.
328 * @brief Returns whether the window is visible or not.
330 * @return True if the window is visible, false otherwise.
332 bool IsVisible() const;
335 * @brief Gets the count of supported auxiliary hints of the window.
337 * @return The number of supported auxiliary hints.
339 * @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.
340 * If you want to set specific hint to your window, then you should check whether it exists in the supported auxiliary hints.
342 unsigned int GetSupportedAuxiliaryHintCount() const;
345 * @brief Gets the supported auxiliary hint string of the window.
347 * @param[in] index The index of the supported auxiliary hint lists
348 * @return The auxiliary hint string of the index.
350 * @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.
351 * If you want to set specific hint to your window, then you should check whether it exists in the supported auxiliary hints.
353 std::string GetSupportedAuxiliaryHint(unsigned int index) const;
356 * @brief Creates an auxiliary hint of the window.
358 * @param[in] hint The auxiliary hint string.
359 * @param[in] value The value string.
360 * @return The ID of created auxiliary hint, or @c 0 on failure.
362 unsigned int AddAuxiliaryHint(const std::string& hint, const std::string& value);
365 * @brief Removes an auxiliary hint of the window.
367 * @param[in] id The ID of the auxiliary hint.
368 * @return True if no error occurred, false otherwise.
370 bool RemoveAuxiliaryHint(unsigned int id);
373 * @brief Changes a value of the auxiliary hint.
375 * @param[in] id The auxiliary hint ID.
376 * @param[in] value The value string to be set.
377 * @return True if no error occurred, false otherwise.
379 bool SetAuxiliaryHintValue(unsigned int id, const std::string& value);
382 * @brief Gets a value of the auxiliary hint.
384 * @param[in] id The auxiliary hint ID.
385 * @return The string value of the auxiliary hint ID, or an empty string if none exists.
387 std::string GetAuxiliaryHintValue(unsigned int id) const;
390 * @brief Gets a ID of the auxiliary hint string.
392 * @param[in] hint The auxiliary hint string.
393 * @return The ID of the auxiliary hint string, or @c 0 if none exists.
395 unsigned int GetAuxiliaryHintId(const std::string& hint) const;
398 * @brief Sets a region to accept input events.
400 * @param[in] inputRegion The region to accept input events.
402 void SetInputRegion(const Rect<int>& inputRegion);
405 * @brief Sets a window type.
407 * @param[in] type The window type.
408 * @remarks The default window type is NORMAL.
410 void SetType(WindowType type);
413 * @brief Gets a window type.
415 * @return A window type.
417 WindowType GetType() const;
420 * @brief Sets a priority level for the specified notification window.
422 * @param[in] level The notification window level.
423 * @return True if no error occurred, false otherwise.
425 * @PRIVILEGE_WINDOW_PRIORITY
426 * @remarks This can be used for a notification type window only. The default level is NotificationLevel::NONE.
428 bool SetNotificationLevel(WindowNotificationLevel level);
431 * @brief Gets a priority level for the specified notification window.
433 * @return The notification window level.
434 * @remarks This can be used for a notification type window only.
436 WindowNotificationLevel GetNotificationLevel() const;
439 * @brief Sets a transparent window's visual state to opaque.
440 * @details If a visual state of a transparent window is opaque,
441 * then the window manager could handle it as an opaque window when calculating visibility.
443 * @param[in] opaque Whether the window's visual state is opaque.
444 * @remarks This will have no effect on an opaque window.
445 * It doesn't change transparent window to opaque window but lets the window manager know the visual state of the window.
447 void SetOpaqueState(bool opaque);
450 * @brief Returns whether a transparent window's visual state is opaque or not.
452 * @return True if the window's visual state is opaque, false otherwise.
453 * @remarks The return value has no meaning on an opaque window.
455 bool IsOpaqueState() const;
458 * @brief Sets a window's screen off mode.
459 * @details This API is useful when the application needs to keep the display turned on.
460 * If the application sets the screen mode to #::Dali::WindowScreenOffMode::NEVER to its window and the window is shown,
461 * the window manager requests the display system to keep the display on as long as the window is shown.
462 * If the window is no longer shown, then the window manager requests the display system to go back to normal operation.
464 * @param[in] screenOffMode The screen mode.
465 * @return True if no error occurred, false otherwise.
469 bool SetScreenOffMode(WindowScreenOffMode screenOffMode);
472 * @brief Gets a screen off mode of the window.
474 * @return The screen off mode.
476 WindowScreenOffMode GetScreenOffMode() const;
479 * @brief Sets preferred brightness of the window.
480 * @details This API is useful when the application needs to change the brightness of the screen when it is appeared on the screen.
481 * 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.
482 * If the window is no longer shown, then the window manager requests the display system to go back to default brightness.
483 * A value less than 0 results in default brightness and a value greater than 100 results in maximum brightness.
485 * @param[in] brightness The preferred brightness (0 to 100).
486 * @return True if no error occurred, false otherwise.
490 bool SetBrightness(int brightness);
493 * @brief Gets preferred brightness of the window.
495 * @return The preferred brightness.
497 int GetBrightness() const;
500 * @brief Sets a size of the window.
503 * @param[in] size The new window size
505 void SetSize(WindowSize size);
508 * @brief Gets a size of the window.
511 * @return The size of the window
513 WindowSize GetSize() const;
516 * @brief Sets a position of the window.
519 * @param[in] position The new window position
521 void SetPosition(WindowPosition position);
524 * @brief Gets a position of the window.
527 * @return The position of the window
529 WindowPosition GetPosition() const;
532 * @brief Sets whether the window is transparent or not.
535 * @param[in] transparent Whether the window is transparent
537 void SetTransparency(bool transparent);
540 * @brief Retrieves the list of render-tasks in the window.
543 * @return A valid handle to a RenderTaskList
545 RenderTaskList GetRenderTaskList();
549 * @brief The user should connect to this signal to get a timing when window gains focus or loses focus.
551 * A callback of the following type may be connected:
553 * void YourCallbackName( Window window, bool focusIn );
555 * The parameter is true if window gains focus, otherwise false.
556 * and window means this signal was called from what window
559 * @return The signal to connect to
561 FocusChangeSignalType& FocusChangeSignal();
564 * @brief This signal is emitted when the window is resized.
566 * A callback of the following type may be connected:
568 * void YourCallbackName( Window window, int width, int height );
570 * The parameters are the resized width and height.
571 * and window means this signal was called from what window
574 * @return The signal to connect to
576 ResizeSignalType& ResizeSignal();
579 * @brief This signal is emitted when key event is received.
581 * A callback of the following type may be connected:
583 * void YourCallbackName(const KeyEvent& event);
587 * @return The signal to connect to
589 KeyEventSignalType& KeyEventSignal();
592 * @brief This signal is emitted when the screen is touched and when the touch ends
593 * (i.e. the down & up touch events only).
595 * If there are multiple touch points, then this will be emitted when the first touch occurs and
596 * then when the last finger is lifted.
597 * An interrupted event will also be emitted (if it occurs).
598 * A callback of the following type may be connected:
600 * void YourCallbackName(const TouchEvent& event);
604 * @return The touch signal to connect to
606 * @note Motion events are not emitted.
608 TouchEventSignalType& TouchedSignal();
610 public: // Not intended for application developers
613 * @brief This constructor is used by Dali::Application::GetWindow().
615 * @param[in] window A pointer to the Window
617 explicit DALI_INTERNAL Window(Internal::Adaptor::Window* window);
626 #endif // __DALI_WINDOW_H__