docs
Loading...
Searching...
No Matches
Dialogs.h
Go to the documentation of this file.
1///
2/// Copyright (C) 2026 Ultralight, Inc. All rights reserved.
3/// A license is required for commercial use. https://ultralig.ht
4///
5/// @file Dialogs.h
6///
7/// Native modal message boxes for alerts and confirmations.
8///
9/// `#include <AppCore/Dialogs.h>`
10///
11/// This header provides ShowMessageBox() to display modal dialogs from the host OS. The call blocks
12/// until the user responds and returns the selected button result.
13///
14/// You can prompt the user for confirmation before discarding unsaved edits:
15///
16/// ```
17/// bool ConfirmDiscard() {
18/// ButtonResult result = ShowMessageBox("Discard changes?",
19/// "Your unsaved edits will be lost.",
20/// DialogIcon::Question, ButtonType::YesNo);
21/// return result == ButtonResult::Yes;
22/// }
23/// ```
24///
25/// ## Main Thread and Linux Fallback
26///
27/// You must call ShowMessageBox() on the main thread.
28///
29/// On Linux, the library logs the message and returns the declining button (or ButtonResult::OK
30/// when it's the only button) whenever it can't display a dialog:
31///
32/// - **The call runs on a background thread.**
33/// - **The host system doesn't have GTK 3 installed.**
34///
35/// ## In-Window HTML Dialogs
36///
37/// To style dialogs with HTML and CSS instead of native OS chrome, create a floating panel through
38/// Foreground. Setting FocusPolicy::Grab on the panel ensures it takes keyboard focus whenever it's
39/// shown.
40///
41/// @see ShowMessageBox(), Foreground, FocusPolicy
42///
43
44#pragma once
45
46#include "Defines.h"
47#include <Ultralight/String.h>
48
49namespace ultralight {
50
51///
52/// Enum representing the icon to be displayed in a dialog.
53///
54enum class DialogIcon {
55 Info, ///< Information icon
56 Warning, ///< Warning icon
57 Error, ///< Error icon
58 Question ///< Question icon
59};
60
61///
62/// Enum representing the button types in a dialog.
63///
64enum class ButtonType {
65 OK, ///< Single "OK" button
66 OKCancel, ///< "OK" and "Cancel" buttons
67 YesNo ///< "Yes" and "No" buttons
68};
69
70///
71/// Enum representing the result of a dialog button press.
72///
73enum class ButtonResult {
74 OK, ///< "OK" button was pressed
75 Cancel, ///< "Cancel" button was pressed
76 Yes, ///< "Yes" button was pressed
77 No ///< "No" button was pressed
78};
79
80///
81/// Show a modal message box with the specified title, message, icon, and buttons.
82///
83/// @param title The title of the message box.
84///
85/// @param message The message to display in the message box.
86///
87/// @param icon The icon to display in the message box (default: DialogIcon::Info).
88///
89/// @param buttons The button type to display in the message box (default: ButtonType::OK).
90///
91/// @return Returns the result of the button press.
92///
93AExport ButtonResult ShowMessageBox(const String& title, const String& message,
95 ButtonType buttons = ButtonType::OK);
96
97} // namespace ultralight
#define AExport
Definition Defines.h:41
Unicode string container with conversions for UTF-8, UTF-16, and UTF-32.
Definition String.h:31
Root namespace for every public Ultralight type, function, and enumeration.
DialogIcon
Enum representing the icon to be displayed in a dialog.
Definition Dialogs.h:54
@ Warning
Warning icon.
Definition Dialogs.h:56
@ Info
Information icon.
Definition Dialogs.h:55
@ Error
Error icon.
Definition Dialogs.h:57
@ Question
Question icon.
Definition Dialogs.h:58
ButtonResult
Enum representing the result of a dialog button press.
Definition Dialogs.h:73
@ Yes
"Yes" button was pressed
Definition Dialogs.h:76
@ No
"No" button was pressed
Definition Dialogs.h:77
@ Cancel
"Cancel" button was pressed
Definition Dialogs.h:75
ButtonResult ShowMessageBox(const String &title, const String &message, DialogIcon icon=DialogIcon::Info, ButtonType buttons=ButtonType::OK)
Show a modal message box with the specified title, message, icon, and buttons.
ButtonType
Enum representing the button types in a dialog.
Definition Dialogs.h:64
@ OKCancel
"OK" and "Cancel" buttons
Definition Dialogs.h:66
@ YesNo
"Yes" and "No" buttons
Definition Dialogs.h:67
@ OK
Single "OK" button.
Definition Dialogs.h:65