Qt: Replace the toolbar extension icon.
[metze/wireshark/wip.git] / ui / simple_dialog.h
1 /* simple_dialog.h
2  * Definitions for alert box routines with toolkit-independent APIs but
3  * toolkit-dependent implementations.
4  *
5  * Wireshark - Network traffic analyzer
6  * By Gerald Combs <gerald@wireshark.org>
7  * Copyright 1998 Gerald Combs
8  *
9  * SPDX-License-Identifier: GPL-2.0-or-later*/
10
11 #ifndef __SIMPLE_DIALOG_UI_H__
12 #define __SIMPLE_DIALOG_UI_H__
13
14 #ifdef __cplusplus
15 extern "C" {
16 #endif /* __cplusplus */
17
18 /** @file
19  *  Simple dialog box.
20  *  @ingroup dialog_group
21  */
22
23
24 /** Dialog types. */
25 typedef enum {
26     ESD_TYPE_INFO,          /**< tells the user something they should know, but not requiring
27                                     any action; the only button should be "OK" */
28     ESD_TYPE_WARN,          /**< tells the user about a problem; the only button should be "OK" */
29     ESD_TYPE_CONFIRMATION,  /**< asks the user for confirmation; there should be more than
30                                     one button */
31     ESD_TYPE_ERROR,         /**< tells the user about a serious problem; the only button should be "OK" */
32     ESD_TYPE_STOP           /**< tells the user a stop action is in progress, there should be no button */
33 } ESD_TYPE_E;
34
35 /** display no buttons at all */
36 #define ESD_BTN_NONE   0x00
37 /** display an "Ok" button */
38 #define ESD_BTN_OK     0x01
39 /** display a "Cancel" button */
40 #define ESD_BTN_CANCEL 0x02
41 /** display a "Yes" button */
42 #define ESD_BTN_YES    0x04
43 /** display a "No" button */
44 #define ESD_BTN_NO     0x08
45 /** display a "Clear" button */
46 #define ESD_BTN_CLEAR  0x10
47 /** display a "Save" button */
48 #define ESD_BTN_SAVE   0x20
49 /** display a "Continue without Saving" button */
50 #define ESD_BTN_DONT_SAVE 0x40
51 /** display a "Quit without Saving" button */
52 #define ESD_BTN_QUIT_DONT_SAVE 0x80
53
54 /** Standard button combination "Ok" + "Cancel". */
55 #define ESD_BTNS_OK_CANCEL      (ESD_BTN_OK|ESD_BTN_CANCEL)
56 /** Standard button combination "Yes" + "No". */
57 #define ESD_BTNS_YES_NO         (ESD_BTN_YES|ESD_BTN_NO)
58 /** Standard button combination "Yes" + "No" + "Cancel". */
59 #define ESD_BTNS_YES_NO_CANCEL  (ESD_BTN_YES|ESD_BTN_NO|ESD_BTN_CANCEL)
60 /** Standard button combination "No" + "Cancel" + "Save". */
61 #define ESD_BTNS_SAVE_DONTSAVE  (ESD_BTN_SAVE|ESD_BTN_DONT_SAVE)
62 #define ESD_BTNS_SAVE_DONTSAVE_CANCEL (ESD_BTN_DONT_SAVE|ESD_BTN_CANCEL|ESD_BTN_SAVE)
63 /** Standard button combination "Quit without saving" + "Cancel" + "Save". */
64 #define ESD_BTNS_SAVE_QUIT_DONTSAVE_CANCEL (ESD_BTN_QUIT_DONT_SAVE|ESD_BTN_CANCEL|ESD_BTN_SAVE)
65 /** Standard button combination "Quit without saving" + "Cancel". */
66 #define ESD_BTNS_QUIT_DONTSAVE_CANCEL (ESD_BTN_QUIT_DONT_SAVE|ESD_BTN_CANCEL)
67
68 /** Create and show a simple dialog.
69  *
70  * @param type type of dialog, e.g. ESD_TYPE_WARN
71  * @param btn_mask The buttons to display, e.g. ESD_BTNS_OK_CANCEL
72  * @param msg_format Printf like message format. Text must be plain.
73  * @param ... Printf like parameters
74  * @return The newly created dialog
75  */
76 /*
77  * XXX This is a bit clunky. We typically pass in:
78  * - simple_dialog_primary_start
79  * - The primary message
80  * - simple_dialog_primary_end
81  * - Optionally, the secondary message.
82  *
83  * In the GTK+ UI primary_start and primary_end make up a <span> that adds
84  * text formatting. The whole string is then shoved into a GtkLabel.
85  *
86  * In the Qt UI we use primary_start and _end to split the primary and
87  * secondary messages. They are then added to a QMessageBox via setText and
88  * setInformativeText respectively. No formatting is applied.
89  *
90  * Callers are responsible for wrapping the primary message and formatting
91  * the message text.
92  *
93  * Explicitly passing in separate primary and secondary messages would let us
94  * get rid of primary_start and primary_end and reduce the amount of
95  * gymnastics we have to to in the Qt UI.
96  */
97 extern gpointer simple_dialog(ESD_TYPE_E type, gint btn_mask,
98     const gchar *msg_format, ...)
99     G_GNUC_PRINTF(3, 4);
100
101 /** Surround the primary dialog message text by
102  *  simple_dialog_primary_start() and simple_dialog_primary_end().
103  *  To highlight the first sentence (will take effect on GTK2 only).
104  */
105 extern const char *simple_dialog_primary_start(void);
106 /** Surround the primary dialog message text by
107  *  simple_dialog_primary_start() and simple_dialog_primary_end().
108  *  To highlight the first sentence (will take effect on GTK2 only).
109  */
110 extern const char *simple_dialog_primary_end(void);
111
112 /** Escape the message text, if it probably contains Pango escape sequences.
113  *  For example html like tags starting with a <.
114  *
115  * @param msg the string to escape
116  * @return the escaped message text, must be freed with g_free() later
117  */
118 extern char *simple_dialog_format_message(const char *msg);
119
120 /*
121  * Alert box, with optional "don't show this message again" variable
122  * and checkbox, and optional secondary text.
123  */
124 extern void simple_message_box(ESD_TYPE_E type, gboolean *notagain,
125                                const char *secondary_msg,
126                                const char *msg_format, ...) G_GNUC_PRINTF(4, 5);
127
128 /*
129  * Error alert box, taking a format and a va_list argument.
130  */
131 extern void vsimple_error_message_box(const char *msg_format, va_list ap);
132
133 /*
134  * Error alert box, taking a format and a list of arguments.
135  */
136 extern void simple_error_message_box(const char *msg_format, ...) G_GNUC_PRINTF(1, 2);
137
138 /*
139  * Warning alert box, taking a format and a va_list argument.
140  */
141 extern void vsimple_warning_message_box(const char *msg_format, va_list ap);
142
143 #ifdef __cplusplus
144 }
145 #endif /* __cplusplus */
146
147 #endif /* __SIMPLE_DIALOG_UI_H__ */
148
149 /*
150  * Editor modelines
151  *
152  * Local Variables:
153  * c-basic-offset: 4
154  * tab-width: 8
155  * indent-tabs-mode: nil
156  * End:
157  *
158  * ex: set shiftwidth=4 tabstop=8 expandtab:
159  * :indentSize=4:tabSize=8:noTabs=true:
160  */