comparison foosdk/sdk/foobar2000/SDK/popup_message.cpp @ 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 #include "foobar2000-sdk-pch.h"
2 #include "popup_message.h"
3 #include "messageBox.h"
4
5 void popup_message::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)
6 {
7 get()->show_ex(p_msg, p_msg_length, p_title, p_title_length, p_icon);
8 }
9
10
11 void popup_message::g_complain(const char * what) {
12 g_show(what, "Information", icon_error);
13 }
14
15 void popup_message::g_complain(const char * p_whatFailed, const std::exception & p_exception) {
16 g_complain(p_whatFailed,p_exception.what());
17 }
18 void popup_message::g_complain(const char * p_whatFailed, const char * msg) {
19 g_complain( pfc::format(p_whatFailed, ": ", msg));
20 }
21
22 void popup_message_v3::show_query( const char * title, const char * msg, unsigned buttons, completion_notify::ptr reply) {
23 query_t q;
24 q.title = title; q.msg = msg; q.buttons = buttons; q.reply = reply;
25 this->show_query( q );
26 }
27
28 void popup_message_v3::query_t::show() {
29 popup_message_v3::get()->show_query(*this);
30 }
31
32
33 void popup_message_v2::g_show(fb2k::hwnd_t parent, const char * msg, const char * title) {
34 service_enum_t< popup_message_v2 > e;
35 service_ptr_t< popup_message_v2 > m;
36 if (e.first( m )) {
37 m->show(parent, msg, title);
38 } else {
39 popup_message::g_show( msg, title );
40 }
41 }
42 void popup_message_v2::g_complain(fb2k::hwnd_t parent, const char * whatFailed, const char * msg) {
43 g_show(parent, pfc::format(whatFailed, ": ", msg));
44 }
45 void popup_message_v2::g_complain(fb2k::hwnd_t parent, const char * whatFailed, const std::exception & e) {
46 g_complain(parent, whatFailed, e.what());
47 }
48
49 void fb2k::showToast( const char * msg ) {
50 fb2k::popup_toast::arg_t arg;
51 fb2k::popup_toast::get()->show_toast(msg, arg);
52 }
53
54 void fb2k::showToastLongDuration( const char * msg ) {
55 fb2k::popup_toast::arg_t arg;
56 arg.longDuration = true;
57 fb2k::popup_toast::get()->show_toast(msg, arg);
58 }
59 void popup_message::g_showToast(const char * msg) {
60 fb2k::showToast( msg );
61 }
62 void popup_message::g_showToastLongDuration(const char * msg) {
63 fb2k::showToastLongDuration( msg );
64 }
65
66 int fb2k::messageBox(fb2k::hwnd_t parent, const char* msg, const char* title, unsigned flags) {
67 return popup_message_v3::get()->messageBox(parent, msg, title, flags);
68 }
69 void fb2k::messageBoxAsync(fb2k::hwnd_t parent, const char* msg, const char* title, unsigned flags, std::function<void(int)> reply) {
70 return popup_message_v3::get()->messageBoxAsync(parent, msg, title, flags, reply);
71 }
72 popup_message_v3::query_t popup_message_v3::setupMessageBox(fb2k::hwnd_t parent, const char* msg, const char* title, unsigned flags) {
73 query_t q = {};
74 q.title = title;
75 q.msg = msg;
76 q.wndParent = parent;
77
78 switch (flags & 0xF) {
79 default:
80 case MB_OK:
81 q.buttons = buttonOK;
82 q.defButton = buttonOK;
83 break;
84 case MB_OKCANCEL:
85 q.buttons = buttonOK | buttonCancel;
86 q.defButton = (flags & MB_DEFBUTTON2) ? buttonCancel : buttonOK;
87 break;
88 case MB_ABORTRETRYIGNORE:
89 q.buttons = buttonAbort | buttonRetry | buttonIgnore;
90 if (flags & MB_DEFBUTTON3) q.defButton = buttonIgnore;
91 else if (flags & MB_DEFBUTTON2) q.defButton = buttonRetry;
92 else q.defButton = buttonAbort;
93 break;
94 case MB_YESNOCANCEL:
95 q.buttons = buttonYes | buttonNo | buttonCancel;
96 if (flags & MB_DEFBUTTON3) q.defButton = buttonCancel;
97 else if (flags & MB_DEFBUTTON2) q.defButton = buttonNo;
98 else q.defButton = buttonYes;
99 break;
100 case MB_YESNO:
101 q.buttons = buttonYes | buttonNo;
102 q.defButton = (flags & MB_DEFBUTTON2) ? buttonNo : buttonYes;
103 break;
104 case MB_RETRYCANCEL:
105 q.buttons = buttonRetry | buttonCancel;
106 q.defButton = (flags & MB_DEFBUTTON2) ? buttonCancel : buttonRetry;
107 break;
108 }
109 switch (flags & 0xF0) {
110 case MB_ICONHAND:
111 q.icon = iconError;
112 break;
113 case MB_ICONQUESTION:
114 q.icon = iconQuestion;
115 break;
116 case MB_ICONEXCLAMATION:
117 q.icon = iconWarning;
118 break;
119 case MB_ICONASTERISK:
120 q.icon = iconInformation;
121 break;
122 }
123
124 return q;
125 }
126 int popup_message_v3::messageBoxReply(uint32_t status) {
127 if (status & buttonOK) return IDOK;
128 if (status & buttonCancel) return IDCANCEL;
129 if (status & buttonYes) return IDYES;
130 if (status & buttonNo) return IDNO;
131 if (status & buttonRetry) return IDRETRY;
132 if (status & buttonAbort) return IDABORT;
133 if (status & buttonIgnore) return IDIGNORE;
134
135 return -1;
136 }
137 void popup_message_v3::messageBoxAsync(fb2k::hwnd_t parent, const char* msg, const char* title, unsigned flags, std::function<void (int)> reply) {
138 PFC_ASSERT( core_api::is_main_thread() );
139 auto q = setupMessageBox(parent, msg, title, flags);
140 if (reply) {
141 q.reply = fb2k::makeCompletionNotify([reply](unsigned code) {
142 reply(messageBoxReply(code));
143 });
144 }
145 this->show_query(q);
146 }
147 int popup_message_v3::messageBox(fb2k::hwnd_t parent, const char* msg, const char* title, unsigned flags) {
148 PFC_ASSERT( core_api::is_main_thread() );
149 auto q = setupMessageBox(parent, msg, title, flags);
150 uint32_t status = this->show_query_modal(q);
151 return messageBoxReply(status);
152 }