comparison foosdk/sdk/foobar2000/SDK/popup_message.h @ 1:20d02a178406 default tip

*: check in everything else yay
author Paper <paper@tflc.us>
date Mon, 05 Jan 2026 02:15:46 -0500
parents
children
comparison
equal deleted inserted replaced
0:e9bb126753e7 1:20d02a178406
1 #pragma once
2
3 #include <climits> // UINT_MAX
4 #include <functional>
5 #include "completion_notify.h"
6
7 //! This interface allows you to show generic nonmodal noninteractive dialog with a text message. This should be used instead of MessageBox where possible.\n
8 //! Usage: use popup_message::g_show / popup_message::g_show_ex static helpers, or popup_message::get() to obtain an instance.\n
9 //! Thread safety: OK to call from worker threads (will delegate UI ops to main thread automatically). \n
10 //! Note that all strings are UTF-8.
11 class NOVTABLE popup_message : public service_base {
12 public:
13 enum t_icon {icon_information, icon_error, icon_query};
14 //! Activates the popup dialog; returns immediately (the dialog remains visible).
15 //! @param p_msg Message to show (UTF-8 encoded string).
16 //! @param p_msg_length Length limit of message string to show, in bytes (actual string may be shorter if null terminator is encountered before). Set this to infinite to use plain null-terminated strings.
17 //! @param p_title Title of dialog to show (UTF-8 encoded string).
18 //! @param p_title_length Length limit of the title string, in bytes (actual string may be shorter if null terminator is encountered before). Set this to infinite to use plain null-terminated strings.
19 //! @param p_icon Icon of the dialog - can be set to icon_information, icon_error or icon_query.
20 virtual void show_ex(const char * p_msg,size_t p_msg_length,const char * p_title,size_t p_title_length,t_icon p_icon = icon_information) = 0;
21
22 //! Activates the popup dialog; returns immediately (the dialog remains visible); helper function built around show_ex(), takes null terminated strings with no length limit parameters.
23 //! @param p_msg Message to show (UTF-8 encoded string).
24 //! @param p_title Title of dialog to show (UTF-8 encoded string).
25 //! @param p_icon Icon of the dialog - can be set to icon_information, icon_error or icon_query.
26 inline void show(const char * p_msg,const char * p_title,t_icon p_icon = icon_information) {show_ex(p_msg,UINT_MAX,p_title,UINT_MAX,p_icon);}
27
28 //! Static helper function instantiating the service and activating the message dialog. See show_ex() for description of parameters.
29 static void g_show_ex(const char * p_msg,size_t p_msg_length,const char * p_title,size_t p_title_length,t_icon p_icon = icon_information);
30 //! Static helper function instantiating the service and activating the message dialog. See show() for description of parameters.
31 static inline void g_show(const char * p_msg,const char * p_title,t_icon p_icon = icon_information) {g_show_ex(p_msg,UINT_MAX,p_title,UINT_MAX,p_icon);}
32
33 //! Shows generic box with a failure message
34 static void g_complain(const char * what);
35 //! <whatfailed>: <exception message>
36 static void g_complain(const char * p_whatFailed, const std::exception & p_exception);
37 //! <whatfailed>: <msg>
38 static void g_complain(const char * p_whatFailed, const char * msg);
39
40 static void g_showToast(const char * msg);
41 static void g_showToastLongDuration(const char * msg);
42
43 FB2K_MAKE_SERVICE_COREAPI(popup_message);
44 };
45
46 #define EXCEPTION_TO_POPUP_MESSAGE(CODE,LABEL) try { CODE; } catch(std::exception const & e) {popup_message::g_complain(LABEL,e);}
47
48 //! \since 1.1
49 //! Extendsion to popup_message API. \n
50 //! Thread safety: OK to call from worker threads (will delegate UI ops to main thread automatically). \n
51 //! Note that all strings are UTF-8.
52 class NOVTABLE popup_message_v2 : public service_base {
53 FB2K_MAKE_SERVICE_COREAPI(popup_message_v2);
54 public:
55 virtual void show(fb2k::hwnd_t parent, const char * msg, t_size msg_length, const char * title, t_size title_length) = 0;
56 void show(fb2k::hwnd_t parent, const char * msg, const char * title) {show(parent, msg, SIZE_MAX, title, SIZE_MAX);}
57
58 static void g_show(fb2k::hwnd_t parent, const char * msg, const char * title = "Information");
59 static void g_complain(fb2k::hwnd_t parent, const char * whatFailed, const char * msg);
60 static void g_complain(fb2k::hwnd_t parent, const char * whatFailed, const std::exception & e);
61 };
62
63 namespace fb2k {
64 //! \since 2.0
65 //! Not really implemented for Windows yet.
66 class popup_toast : public service_base {
67 FB2K_MAKE_SERVICE_COREAPI( popup_toast );
68 public:
69 struct arg_t {
70 bool longDuration = false;
71 };
72 virtual void show_toast(const char * msg, arg_t const & arg) = 0;
73 };
74 void showToast( const char * msg );
75 void showToastLongDuration( const char * msg );
76
77 class toastFormatter : public pfc::string_formatter {
78 public:
79 ~toastFormatter() noexcept {
80 try {
81 if ( this->length() > 0 ) showToast( c_str() );
82 } catch(...) {}
83 }
84 };
85 }
86
87 #define FB2K_Toast() ::fb2k::toastFormatter()._formatter()
88
89
90 //! \since 1.5
91 //! MessageBox-like dialog, only non-blocking and with dark mode support under foobar2000 v2.0. \n
92 //! Call from main thread only (contrary to popup_message / popup_message_v2) !!!
93 class NOVTABLE popup_message_v3 : public service_base {
94 FB2K_MAKE_SERVICE_COREAPI(popup_message_v3);
95 public:
96
97 //! show_query button codes. \n
98 //! Combine one or more of these to create a button mask to pass to show_query().
99 enum {
100 buttonOK = 1 << 0,
101 buttonCancel = 1 << 1,
102 buttonYes = 1 << 2,
103 buttonNo = 1 << 3,
104 buttonRetry = 1 << 4,
105 buttonAbort = 1 << 5,
106 buttonIgnore = 1 << 6,
107
108 flagDoNotAskAgain = 1 << 16,
109
110 iconNone = 0,
111 iconInformation,
112 iconQuestion,
113 iconWarning,
114 iconError,
115 };
116
117 struct query_t {
118 const char * title = nullptr;
119 const char * msg = nullptr;
120 uint32_t buttons = 0;
121 uint32_t defButton = 0;
122 uint32_t icon = iconNone;
123 completion_notify::ptr reply; // optional
124 fb2k::hwnd_t wndParent = NULL;
125 const char * msgDoNotAskAgain = nullptr;
126
127 void show();
128 };
129
130 //! Shows an interactive query presenting the user with multiple actions to choose from.
131 virtual void show_query(query_t const &) = 0;
132
133 //! Modal version of show_query. Reply part of the argument can be empty; the status code will be returned.
134 virtual uint32_t show_query_modal(query_t const &) = 0;
135
136 // Minimalist MessageBox() reimplementation wrapper
137 int messageBox(fb2k::hwnd_t, const char*, const char*, unsigned);
138 void messageBoxAsync(fb2k::hwnd_t, const char*, const char*, unsigned, std::function<void (int)> reply = nullptr);
139 static query_t setupMessageBox(fb2k::hwnd_t parent, const char* msg, const char* title, unsigned flags);
140 static int messageBoxReply(uint32_t);
141
142 //! Old method wrapper
143 void show_query( const char * title, const char * msg, unsigned buttons, completion_notify::ptr reply);
144 };