5#include <simgear/simgear_config.h>
17#include <osgViewer/Viewer>
19#include <simgear/structure/commands.hxx>
24#include <osgViewer/GraphicsWindow>
25#include <osgViewer/api/Win32/GraphicsWindowWin32>
32cocoaFatalMessage(
const std::string& msg,
const std::string& text);
35cocoaMessageBox(
const std::string& msg,
const std::string& text);
43using namespace simgear::strutils;
47static bool static_isHeadless =
false;
49bool isCanvasImplementationRegistered()
55 SGCommandMgr* cmd =
globals->get_commands();
56 return (cmd->getCommand(
"canvas-message-box") != NULL);
59#if defined(SG_WINDOWS)
63 osgViewer::Viewer::Windows windows;
68 globals->get_renderer()->getViewerBase()->getWindows(windows);
69 osgViewer::Viewer::Windows::const_iterator it = windows.begin();
70 for(; it != windows.end(); ++it) {
71 if (strcmp((*it)->className(),
"GraphicsWindowWin32")) {
75 osgViewer::GraphicsWindowWin32* platformWin =
76 static_cast<osgViewer::GraphicsWindowWin32*
>(*it);
77 return platformWin->getHWND();
84win32MessageBox(
const std::string& caption,
85 const std::string& msg,
86 const std::string& moreText)
91 std::string fullMsg(msg);
92 if (!moreText.empty()) {
93 fullMsg +=
"\n\n" + moreText;
97 std::wstring wMsg(convertUtf8ToWString(fullMsg)),
98 wCap(convertUtf8ToWString(caption));
100 ::MessageBoxExW(ownerWindow, wMsg.c_str(), wCap.c_str(),
115 static_isHeadless = headless;
120 return static_isHeadless;
124 const std::string& msg,
125 const std::string& moreText)
128 if (static_isHeadless) {
129 SG_LOG(SG_HEADLESS, SG_ALERT,
"ModalMessageBox Caption: \"" << caption <<
"\"");
130 SG_LOG(SG_HEADLESS, SG_ALERT,
"ModalMessageBox Message: \"" << msg <<
"\"");
131 if (!moreText.empty())
132 SG_LOG(SG_HEADLESS, SG_ALERT,
"ModalMessageBox More text: \"" << moreText <<
"\"");
137 if (isCanvasImplementationRegistered()) {
138 SGPropertyNode_ptr args(
new SGPropertyNode);
139 args->setStringValue(
"caption", caption);
140 args->setStringValue(
"message", msg);
141 args->setStringValue(
"more", moreText);
142 globals->get_commands()->execute(
"canvas-message-box", args,
nullptr);
149#if defined(SG_WINDOWS)
150 return win32MessageBox(caption, msg, moreText);
152 return cocoaMessageBox(msg, moreText);
153#elif defined(HAVE_QT)
156 std::string s = caption +
": "+ msg;
157 if (!moreText.empty()) {
158 s +=
"\n( " + moreText +
")";
162 if (!gui || (
fgGetBool(
"/sim/rendering/initialized",
false) ==
false)) {
163 SG_LOG(SG_GENERAL, SG_POPUP, s);
165 SGPropertyNode_ptr dlg = gui->getDialogProperties(
"popup");
166 dlg->setStringValue(
"text/label", s );
167 gui->showDialog(
"popup");
174 const std::string& msg,
175 const std::string& moreText,
178 if (reportToSentry) {
183 if (static_isHeadless) {
184 SG_LOG(SG_HEADLESS, SG_ALERT,
"Fatal Error: \"" << caption <<
"\"");
185 SG_LOG(SG_HEADLESS, SG_ALERT,
"Error Message: \"" << msg <<
"\"");
186 if (!moreText.empty())
187 SG_LOG(SG_HEADLESS, SG_ALERT,
"\tMore text: \"" << moreText <<
"\"");
191#if defined(SG_WINDOWS)
192 return win32MessageBox(caption, msg, moreText);
194 return cocoaFatalMessage(msg, moreText);
195#elif defined(HAVE_QT)
198 std::string s =
"FATAL: "+ msg;
199 if (!moreText.empty()) {
200 s +=
"\n( " + moreText +
")";
202 if (
fgGetBool(
"/sim/rendering/initialized",
false) ==
false) {
203 std::cerr << s << std::endl;
207 dlg->setStringValue(
"text/label", s );
208 _gui->showDialog(
"popup");
215 const std::string& caption,
216 const std::string& msg,
217 const std::string& moreText,
221 SG_LOG(SG_GENERAL, SG_ALERT, msg);
flightgear::MessageBoxResult QtMessageBox(const std::string &caption, const std::string &msg, const std::string &moreText, bool fatal)
XML-configured GUI subsystem.
virtual SGPropertyNode_ptr getDialogProperties(const std::string &name)
Get dialog property tree's root node.
FlightPlan.hxx - defines a full flight-plan object, including departure, cruise, arrival information ...
MessageBoxResult modalMessageBox(const std::string &caption, const std::string &msg, const std::string &moreText)
MessageBoxResult fatalMessageBoxWithoutExit(const std::string &caption, const std::string &msg, const std::string &moreText, bool reportToSentry)
void fatalMessageBoxThenExit(const std::string &caption, const std::string &msg, const std::string &moreText, int exitStatus, bool reportToSentry)
void sentryReportFatalError(const std::string &, const std::string &)
void setHeadlessMode(bool headless)
bool fgGetBool(char const *name, bool def)
Get a bool value for a property.