1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
|
/*
* Reporting.cpp
* -------------
* Purpose: A class for showing notifications, prompts, etc...
* Notes : (currently none)
* Authors: OpenMPT Devs
* The OpenMPT source code is released under the BSD license. Read LICENSE for more details.
*/
#include "stdafx.h"
#include "Reporting.h"
#include "../mptrack/Mainfrm.h"
#include "../mptrack/InputHandler.h"
OPENMPT_NAMESPACE_BEGIN
static inline UINT LogLevelToFlags(LogLevel level)
{
switch(level)
{
case LogDebug: return MB_OK; break;
case LogNotification: return MB_OK; break;
case LogInformation: return MB_OK | MB_ICONINFORMATION; break;
case LogWarning: return MB_OK | MB_ICONWARNING; break;
case LogError: return MB_OK | MB_ICONERROR; break;
}
return MB_OK;
}
static CString GetTitle()
{
return MAINFRAME_TITLE;
}
static CString FillEmptyCaption(const CString &caption, LogLevel level)
{
CString result = caption;
if(result.IsEmpty())
{
result = GetTitle() + _T(" - ");
switch(level)
{
case LogDebug: result += _T("Debug"); break;
case LogNotification: result += _T("Notification"); break;
case LogInformation: result += _T("Information"); break;
case LogWarning: result += _T("Warning"); break;
case LogError: result += _T("Error"); break;
}
}
return result;
}
static CString FillEmptyCaption(const CString &caption)
{
CString result = caption;
if(result.IsEmpty())
{
result = GetTitle();
}
return result;
}
static UINT ShowNotificationImpl(const CString &text, const CString &caption, UINT flags, const CWnd *parent)
{
if(parent == nullptr)
{
parent = CMainFrame::GetActiveWindow();
}
BypassInputHandler bih;
UINT result = ::MessageBox(parent->GetSafeHwnd(), text, caption.IsEmpty() ? CString(MAINFRAME_TITLE) : caption, flags);
return result;
}
UINT Reporting::CustomNotification(const AnyStringLocale &text, const AnyStringLocale &caption, UINT flags, const CWnd *parent)
{
return ShowNotificationImpl(mpt::ToCString(text), FillEmptyCaption(mpt::ToCString(caption)), flags, parent);
}
void Reporting::Notification(const AnyStringLocale &text, const CWnd *parent)
{
ShowNotificationImpl(mpt::ToCString(text), FillEmptyCaption(CString(), LogNotification), LogLevelToFlags(LogNotification), parent);
}
void Reporting::Notification(const AnyStringLocale &text, const AnyStringLocale &caption, const CWnd *parent)
{
ShowNotificationImpl(mpt::ToCString(text), FillEmptyCaption(mpt::ToCString(caption), LogNotification), LogLevelToFlags(LogNotification), parent);
}
void Reporting::Information(const AnyStringLocale &text, const CWnd *parent)
{
ShowNotificationImpl(mpt::ToCString(text), FillEmptyCaption(CString(), LogInformation), LogLevelToFlags(LogInformation), parent);
}
void Reporting::Information(const AnyStringLocale &text, const AnyStringLocale &caption, const CWnd *parent)
{
ShowNotificationImpl(mpt::ToCString(text), FillEmptyCaption(mpt::ToCString(caption), LogInformation), LogLevelToFlags(LogInformation), parent);
}
void Reporting::Warning(const AnyStringLocale &text, const CWnd *parent)
{
ShowNotificationImpl(mpt::ToCString(text), FillEmptyCaption(CString(), LogWarning), LogLevelToFlags(LogWarning), parent);
}
void Reporting::Warning(const AnyStringLocale &text, const AnyStringLocale &caption, const CWnd *parent)
{
ShowNotificationImpl(mpt::ToCString(text), FillEmptyCaption(mpt::ToCString(caption), LogWarning), LogLevelToFlags(LogWarning), parent);
}
void Reporting::Error(const AnyStringLocale &text, const CWnd *parent)
{
ShowNotificationImpl(mpt::ToCString(text), FillEmptyCaption(CString(), LogError), LogLevelToFlags(LogError), parent);
}
void Reporting::Error(const AnyStringLocale &text, const AnyStringLocale &caption, const CWnd *parent)
{
ShowNotificationImpl(mpt::ToCString(text), FillEmptyCaption(mpt::ToCString(caption), LogError), LogLevelToFlags(LogError), parent);
}
void Reporting::Message(LogLevel level, const AnyStringLocale &text, const CWnd *parent)
{
ShowNotificationImpl(mpt::ToCString(text), FillEmptyCaption(CString(), level), LogLevelToFlags(level), parent);
}
void Reporting::Message(LogLevel level, const AnyStringLocale &text, const AnyStringLocale &caption, const CWnd *parent)
{
ShowNotificationImpl(mpt::ToCString(text), FillEmptyCaption(mpt::ToCString(caption), level), LogLevelToFlags(level), parent);
}
ConfirmAnswer Reporting::Confirm(const AnyStringLocale &text, bool showCancel, bool defaultNo, const CWnd *parent)
{
return Confirm(mpt::ToCString(text), GetTitle() + _T(" - Confirmation"), showCancel, defaultNo, parent);
}
ConfirmAnswer Reporting::Confirm(const AnyStringLocale &text, const AnyStringLocale &caption, bool showCancel, bool defaultNo, const CWnd *parent)
{
UINT result = ShowNotificationImpl(mpt::ToCString(text), FillEmptyCaption(mpt::ToCString(caption)), (showCancel ? MB_YESNOCANCEL : MB_YESNO) | MB_ICONQUESTION | (defaultNo ? MB_DEFBUTTON2 : 0), parent);
switch(result)
{
case IDYES:
return cnfYes;
case IDNO:
return cnfNo;
default:
case IDCANCEL:
return cnfCancel;
}
}
RetryAnswer Reporting::RetryCancel(const AnyStringLocale &text, const CWnd *parent)
{
return RetryCancel(mpt::ToCString(text), GetTitle(), parent);
}
RetryAnswer Reporting::RetryCancel(const AnyStringLocale &text, const AnyStringLocale &caption, const CWnd *parent)
{
UINT result = ShowNotificationImpl(mpt::ToCString(text), FillEmptyCaption(mpt::ToCString(caption)), MB_RETRYCANCEL, parent);
switch(result)
{
case IDRETRY:
return rtyRetry;
default:
case IDCANCEL:
return rtyCancel;
}
}
OPENMPT_NAMESPACE_END
|