Common/MsgHandler: Make default message handler and translator's internally linked

Previously these functions were declared without the static specifier,
giving them external linkage, which isn't really ideal.

Instead, we can place these functions up by the relevant file-scope
variables and place them inside an anonymous namespace with said variables,
giving them internal linkage.
This commit is contained in:
Lioncash 2019-06-16 23:30:46 -04:00
parent d1475f6d59
commit 76b675e9f0
1 changed files with 31 additions and 31 deletions

View File

@ -19,12 +19,38 @@
#include "Common/Logging/Log.h"
#include "Common/StringUtil.h"
bool DefaultMsgHandler(const char* caption, const char* text, bool yes_no, MsgType style);
static MsgAlertHandler msg_handler = DefaultMsgHandler;
static bool AlertEnabled = true;
namespace
{
// Default non library dependent panic alert
bool DefaultMsgHandler(const char* caption, const char* text, bool yes_no, MsgType style)
{
#ifdef _WIN32
int window_style = MB_ICONINFORMATION;
if (style == MsgType::Question)
window_style = MB_ICONQUESTION;
if (style == MsgType::Warning)
window_style = MB_ICONWARNING;
std::string DefaultStringTranslator(const char* text);
static StringTranslator str_translator = DefaultStringTranslator;
return IDYES == MessageBox(0, UTF8ToTStr(text).c_str(), UTF8ToTStr(caption).c_str(),
window_style | (yes_no ? MB_YESNO : MB_OK));
#else
fmt::print(stderr, "{}\n", text);
// Return no to any question (which will in general crash the emulator)
return false;
#endif
}
// Default (non) translator
std::string DefaultStringTranslator(const char* text)
{
return text;
}
MsgAlertHandler msg_handler = DefaultMsgHandler;
StringTranslator str_translator = DefaultStringTranslator;
bool AlertEnabled = true;
} // Anonymous namespace
// Select which of these functions that are used for message boxes. If
// Qt is enabled we will use QtMsgAlertHandler() that is defined in Main.cpp
@ -100,29 +126,3 @@ bool MsgAlert(bool yes_no, MsgType style, const char* format, ...)
return true;
}
// Default non library dependent panic alert
bool DefaultMsgHandler(const char* caption, const char* text, bool yes_no, MsgType style)
{
#ifdef _WIN32
int window_style = MB_ICONINFORMATION;
if (style == MsgType::Question)
window_style = MB_ICONQUESTION;
if (style == MsgType::Warning)
window_style = MB_ICONWARNING;
return IDYES == MessageBox(0, UTF8ToTStr(text).c_str(), UTF8ToTStr(caption).c_str(),
window_style | (yes_no ? MB_YESNO : MB_OK));
#else
fmt::print(stderr, "{}\n", text);
// Return no to any question (which will in general crash the emulator)
return false;
#endif
}
// Default (non) translator
std::string DefaultStringTranslator(const char* text)
{
return text;
}