Skip to content
Permalink
Browse files

Common/MsgHandler: Make default message handler and translator's inte…

…rnally 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.
  • Loading branch information...
lioncash committed Jun 17, 2019
1 parent d1475f6 commit 76b675e9f02b9ae6d8c969298a24b846e322c649
Showing with 31 additions and 31 deletions.
  1. +31 −31 Source/Core/Common/MsgHandler.cpp
@@ -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;

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;
}

std::string DefaultStringTranslator(const char* text);
static StringTranslator str_translator = DefaultStringTranslator;
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;
}

0 comments on commit 76b675e

Please sign in to comment.
You can’t perform that action at this time.