1 #ifndef __DALI_WINDOW_H__
2 #define __DALI_WINDOW_H__
5 * Copyright (c) 2017 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/object/base-handle.h>
27 #include <dali/public-api/object/any.h>
28 #include <dali/public-api/signals/dali-signal.h>
33 * @addtogroup dali_adaptor_framework
37 typedef Dali::Rect<int> PositionSize;
39 namespace Internal DALI_INTERNAL
47 class DragAndDropDetector;
51 * @brief The window class is used internally for drawing.
53 * A Window has an orientation and indicator properties.
54 * You can get a valid Window handle by calling Dali::Application::GetWindow().
57 class DALI_IMPORT_API Window : public BaseHandle
61 typedef Uint16Pair WindowSize; ///< Window size type @SINCE_1_2.60
62 typedef Uint16Pair WindowPosition; ///< Window position type @SINCE_1_2.60
64 typedef Signal< void (bool) > IndicatorSignalType; ///< Indicator state signal type @SINCE_1_0.0
65 typedef Signal< void (bool) > FocusSignalType; ///< Window focus signal type @SINCE_1_2.60
66 typedef Signal< void (WindowSize) > ResizedSignalType; ///< Window resized signal type @SINCE_1_2.60
73 * @brief Enumeration for orientation of the window is the way in which a rectangular page is oriented for normal viewing.
76 enum WindowOrientation
78 PORTRAIT = 0, ///< Portrait orientation. The height of the display area is greater than the width. @SINCE_1_0.0
79 LANDSCAPE = 90, ///< Landscape orientation. A wide view area is needed. @SINCE_1_0.0
80 PORTRAIT_INVERSE = 180, ///< Portrait inverse orientation @SINCE_1_0.0
81 LANDSCAPE_INVERSE = 270 ///< Landscape inverse orientation @SINCE_1_0.0
85 * @brief Enumeration for opacity of the indicator.
88 enum IndicatorBgOpacity
90 OPAQUE = 100, ///< Fully opaque indicator Bg @SINCE_1_0.0
91 TRANSLUCENT = 50, ///< Semi translucent indicator Bg @SINCE_1_0.0
92 TRANSPARENT = 0 ///< Fully transparent indicator Bg @SINCE_1_0.0
96 * @brief Enumeration for visible mode of the indicator.
99 enum IndicatorVisibleMode
101 INVISIBLE = 0, ///< Hide indicator @SINCE_1_0.0
102 VISIBLE = 1, ///< Show indicator @SINCE_1_0.0
103 AUTO = 2 ///< Hide in default, will show when necessary @SINCE_1_0.0
107 * @brief An enum of Window types.
112 NORMAL, ///< A default window type. Indicates a normal, top-level window. Almost every window will be created with this type. @SINCE_1_2.60
113 NOTIFICATION, ///< A notification window, like a warning about battery life or a new E-Mail received. @SINCE_1_2.60
114 UTILITY, ///< A persistent utility window, like a toolbox or palette. @SINCE_1_2.60
115 DIALOG ///< Used for simple dialog windows. @SINCE_1_2.60
119 * @brief An enum of screen mode.
122 struct NotificationLevel
125 * @brief An enum of screen mode.
130 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
131 BASE = 10, ///< Base notification level. @SINCE_1_2.60
132 MEDIUM = 20, ///< Higher notification level than base. @SINCE_1_2.60
133 HIGH = 30, ///< Higher notification level than medium. @SINCE_1_2.60
134 TOP = 40 ///< The highest notification level. @SINCE_1_2.60
139 * @brief An enum of screen mode.
145 * @brief An enum of screen mode.
150 TIMEOUT, ///< The mode which turns the screen off after a timeout. @SINCE_1_2.60
151 NEVER, ///< The mode which keeps the screen turned on. @SINCE_1_2.60
154 static constexpr Type DEFAULT { TIMEOUT }; ///< The default mode. @SINCE_1_2.60
160 * @brief Creates an initialized handle to a new Window.
162 * @param[in] windowPosition The position and size of the Window
163 * @param[in] name The Window title
164 * @param[in] isTransparent Whether Window is transparent
165 * @return A new window
167 static Window New(PositionSize windowPosition, const std::string& name, bool isTransparent = false);
170 * @brief Creates an initialized handle to a new Window.
172 * @param[in] windowPosition The position and size of the Window
173 * @param[in] name The Window title
174 * @param[in] className The Window class name
175 * @param[in] isTransparent Whether Window is transparent
176 * @return A new Window
178 static Window New(PositionSize windowPosition, const std::string& name, const std::string& className, bool isTransparent = false);
181 * @brief Creates an uninitialized handle.
183 * This can be initialized using Dali::Application::GetWindow() or
184 * Dali::Window::New().
192 * This is non-virtual since derived Handle types must not contain data or virtual methods.
198 * @brief This copy constructor is required for (smart) pointer semantics.
201 * @param[in] handle A reference to the copied handle
203 Window(const Window& handle);
206 * @brief This assignment operator is required for (smart) pointer semantics.
209 * @param[in] rhs A reference to the copied handle
210 * @return A reference to this
212 Window& operator=(const Window& rhs);
215 * @brief This sets whether the indicator bar should be shown or not.
217 * @param[in] visibleMode Visible mode for indicator bar, VISIBLE in default
219 void ShowIndicator( IndicatorVisibleMode visibleMode );
222 * @brief This sets the opacity mode of indicator bar.
224 * @param[in] opacity The opacity mode
226 void SetIndicatorBgOpacity( IndicatorBgOpacity opacity );
229 * @brief This sets the orientation of indicator bar.
231 * It does not implicitly show the indicator if it is currently hidden.
233 * @param[in] orientation The orientation
235 void RotateIndicator(WindowOrientation orientation);
238 * @brief Sets the window name and class string.
240 * @param[in] name The name of the window
241 * @param[in] klass The class of the window
243 void SetClass(std::string name, std::string klass);
246 * @brief Raises window to the top of Window stack.
252 * @brief Lowers window to the bottom of Window stack.
258 * @brief Activates window to the top of Window stack even it is iconified.
264 * @brief Adds an orientation to the list of available orientations.
266 * @param[in] orientation The available orientation to add
268 void AddAvailableOrientation( WindowOrientation orientation );
271 * @brief Removes an orientation from the list of available orientations.
273 * @param[in] orientation The available orientation to remove
275 void RemoveAvailableOrientation( WindowOrientation orientation );
278 * @brief Sets a preferred orientation.
280 * @param[in] orientation The preferred orientation
281 * @pre Orientation is in the list of available orientations.
283 void SetPreferredOrientation( WindowOrientation orientation );
286 * @brief Gets the preferred orientation.
288 * @return The preferred orientation if previously set, or none
290 WindowOrientation GetPreferredOrientation();
293 * @brief Returns the Drag & drop detector which can be used to receive drag & drop events.
294 * @note Not intended for application developers.
296 * @return A handle to the DragAndDropDetector
298 DragAndDropDetector GetDragAndDropDetector() const;
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( Type type );
423 * @brief Gets a window type.
425 * @return A window type.
427 Type GetType() const;
430 * @brief Sets a priority level for the specified notification window.
432 * @param[in] level The notification window level.
433 * @return True if no error occurred, false otherwise.
435 * @PRIVILEGE_WINDOW_PRIORITY
436 * @remarks This can be used for a notification type window only. The default level is NotificationLevel::NONE.
438 bool SetNotificationLevel( NotificationLevel::Type 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 NotificationLevel::Type 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::Window::ScreenOffMode::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 True if no error occurred, false otherwise.
479 bool SetScreenOffMode(ScreenOffMode::Type screenOffMode);
482 * @brief Gets a screen off mode of the window.
484 * @return The screen off mode.
486 ScreenOffMode::Type 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 True if no error occurred, false otherwise.
500 bool SetBrightness( int brightness );
503 * @brief Gets preffered brightness of the window.
505 * @return The preffered 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 );
551 * @brief The user should connect to this signal to get a timing when indicator was shown / hidden.
553 * @return The signal to connect to
555 IndicatorSignalType& IndicatorVisibilityChangedSignal();
558 * @brief The user should connect to this signal to get a timing when window gains focus or loses focus.
560 * A callback of the following type may be connected:
562 * void YourCallbackName( bool focusIn );
564 * The parameter is true if window gains focus, otherwise false.
567 * @return The signal to connect to
569 FocusSignalType& FocusChangedSignal();
572 * @brief This signal is emitted when the window is resized.
574 * A callback of the following type may be connected:
576 * void YourCallbackName( int width, int height );
578 * The parameters are the resized width and height.
581 * @return The signal to connect to
583 ResizedSignalType& ResizedSignal();
585 public: // Not intended for application developers
588 * @brief This constructor is used by Dali::Application::GetWindow().
590 * @param[in] window A pointer to the Window
592 explicit DALI_INTERNAL Window( Internal::Adaptor::Window* window );
601 #endif // __DALI_WINDOW_H__