BACKENDS: Use Common::U32String for OSystem::setWindowCaption

This commit is contained in:
Cameron Cawley 2020-11-01 21:15:34 +00:00 committed by Thierry Crozat
parent ce39fcbf8b
commit 01b4432825
23 changed files with 34 additions and 92 deletions

View file

@ -555,9 +555,7 @@ void OSystem_Android::quit() {
pthread_join(_timer_thread, 0); pthread_join(_timer_thread, 0);
} }
void OSystem_Android::setWindowCaption(const char *caption) { void OSystem_Android::setWindowCaption(const Common::U32String &caption) {
ENTER("%s", caption);
JNI::setWindowCaption(caption); JNI::setWindowCaption(caption);
} }

View file

@ -128,7 +128,7 @@ public:
virtual void quit() override; virtual void quit() override;
virtual void setWindowCaption(const char *caption) override; virtual void setWindowCaption(const Common::U32String &caption) override;
virtual Audio::Mixer *getMixer() override; virtual Audio::Mixer *getMixer() override;
virtual void getTimeAndDate(TimeDate &t) const override; virtual void getTimeAndDate(TimeDate &t) const override;

View file

@ -340,9 +340,9 @@ bool JNI::isConnectionLimited() {
return limited; return limited;
} }
void JNI::setWindowCaption(const Common::String &caption) { void JNI::setWindowCaption(const Common::U32String &caption) {
JNIEnv *env = JNI::getEnv(); JNIEnv *env = JNI::getEnv();
jstring java_caption = convertToJString(env, caption.decode(Common::kISO8859_1)); jstring java_caption = convertToJString(env, caption);
env->CallVoidMethod(_jobj, _MID_setWindowCaption, java_caption); env->CallVoidMethod(_jobj, _MID_setWindowCaption, java_caption);

View file

@ -58,7 +58,7 @@ public:
static void setReadyForEvents(bool ready); static void setReadyForEvents(bool ready);
static void setWindowCaption(const Common::String &caption); static void setWindowCaption(const Common::U32String &caption);
static void getDPI(float *values); static void getDPI(float *values);
static void displayMessageOnOSD(const Common::U32String &msg); static void displayMessageOnOSD(const Common::U32String &msg);
static bool openUrl(const Common::String &url); static bool openUrl(const Common::String &url);

View file

@ -490,9 +490,7 @@ void OSystem_Android::quit() {
dynamic_cast<AndroidGraphicsManager *>(_graphicsManager)->deinitSurface(); dynamic_cast<AndroidGraphicsManager *>(_graphicsManager)->deinitSurface();
} }
void OSystem_Android::setWindowCaption(const char *caption) { void OSystem_Android::setWindowCaption(const Common::U32String &caption) {
ENTER("%s", caption);
JNI::setWindowCaption(caption); JNI::setWindowCaption(caption);
} }

View file

@ -175,7 +175,7 @@ public:
virtual void quit(); virtual void quit();
virtual void setWindowCaption(const char *caption); virtual void setWindowCaption(const Common::U32String &caption);
virtual void showVirtualKeyboard(bool enable); virtual void showVirtualKeyboard(bool enable);
virtual Audio::Mixer *getMixer(); virtual Audio::Mixer *getMixer();

View file

@ -170,7 +170,7 @@ public:
// Set a window caption or any other comparable status display to the // Set a window caption or any other comparable status display to the
// given value. // given value.
void setWindowCaption(const char *caption); void setWindowCaption(const Common::U32String &caption);
// Modulatized backend // Modulatized backend
Audio::Mixer *getMixer() { return _mixer; } Audio::Mixer *getMixer() { return _mixer; }

View file

@ -37,7 +37,7 @@
Icon icon; Icon icon;
const char *gGameName; const char gGameName[32];
OSystem_Dreamcast::OSystem_Dreamcast() OSystem_Dreamcast::OSystem_Dreamcast()
@ -143,9 +143,9 @@ bool DCCDManager::isPlaying() const {
return getCdState() == 3; return getCdState() == 3;
} }
void OSystem_Dreamcast::setWindowCaption(const char *caption) void OSystem_Dreamcast::setWindowCaption(const Common::U32String &caption)
{ {
gGameName = caption; Common::strlcpy(gGameName, cap.encode(Common::kISO8859_1).c_str(), 32);
} }
void OSystem_Dreamcast::quit() { void OSystem_Dreamcast::quit() {

View file

@ -340,7 +340,7 @@ public:
void OutVMSave::finalize() void OutVMSave::finalize()
{ {
extern const char *gGameName; extern const char gGameName[32];
extern Icon icon; extern Icon icon;
if (committed >= _pos) if (committed >= _pos)

View file

@ -99,21 +99,8 @@ void OSystem_SDL_Maemo::setXWindowName(const char *caption) {
} }
} }
void OSystem_SDL_Maemo::setWindowCaption(const char *caption) { void OSystem_SDL_Maemo::setWindowCaption(const Common::U32String &caption) {
Common::String cap; Common::String cap = caption.encode();
byte c;
// The string caption is supposed to be in LATIN-1 encoding.
// SDL expects UTF-8. So we perform the conversion here.
while ((c = *(const byte *)caption++)) {
if (c < 0x80)
cap += c;
else {
cap += 0xC0 | (c >> 6);
cap += 0x80 | (c & 0x3F);
}
}
_window->setWindowCaption(cap); _window->setWindowCaption(cap);
Common::String cap2("ScummVM - "); // 2 lines in OS2008 task switcher, set first line Common::String cap2("ScummVM - "); // 2 lines in OS2008 task switcher, set first line

View file

@ -40,7 +40,7 @@ public:
virtual void initBackend() override; virtual void initBackend() override;
virtual void quit() override; virtual void quit() override;
virtual void fatalError() override; virtual void fatalError() override;
virtual void setWindowCaption(const char *caption) override; virtual void setWindowCaption(const Common::U32String &caption) override;
virtual Common::HardwareInputSet *getHardwareInputSet() override; virtual Common::HardwareInputSet *getHardwareInputSet() override;
virtual Common::KeymapArray getGlobalKeymaps() override; virtual Common::KeymapArray getGlobalKeymaps() override;
virtual Common::KeymapperDefaultBindings *getKeymapperDefaultBindings() override; virtual Common::KeymapperDefaultBindings *getKeymapperDefaultBindings() override;

View file

@ -470,21 +470,8 @@ void OSystem_SDL::addSysArchivesToSearchSet(Common::SearchSet &s, int priority)
} }
void OSystem_SDL::setWindowCaption(const char *caption) { void OSystem_SDL::setWindowCaption(const Common::U32String &caption) {
Common::String cap; Common::String cap = caption.encode();
byte c;
// The string caption is supposed to be in LATIN-1 encoding.
// SDL expects UTF-8. So we perform the conversion here.
while ((c = *(const byte *)caption++)) {
if (c < 0x80)
cap += c;
else {
cap += 0xC0 | (c >> 6);
cap += 0x80 | (c & 0x3F);
}
}
_window->setWindowCaption(cap); _window->setWindowCaption(cap);
} }

View file

@ -78,7 +78,7 @@ public:
virtual bool setTextInClipboard(const Common::U32String &text) override; virtual bool setTextInClipboard(const Common::U32String &text) override;
#endif #endif
virtual void setWindowCaption(const char *caption) override; virtual void setWindowCaption(const Common::U32String &caption) override;
virtual void addSysArchivesToSearchSet(Common::SearchSet &s, int priority = 0) override; virtual void addSysArchivesToSearchSet(Common::SearchSet &s, int priority = 0) override;
virtual uint32 getMillis(bool skipRecord = false) override; virtual uint32 getMillis(bool skipRecord = false) override;
virtual void delayMillis(uint msecs) override; virtual void delayMillis(uint msecs) override;

View file

@ -257,10 +257,6 @@ void OSystem_Wii::deleteMutex(MutexRef mutex) {
free(mutex); free(mutex);
} }
void OSystem_Wii::setWindowCaption(const char *caption) {
printf("window caption: %s\n", caption);
}
Audio::Mixer *OSystem_Wii::getMixer() { Audio::Mixer *OSystem_Wii::getMixer() {
assert(_mixer); assert(_mixer);
return _mixer; return _mixer;

View file

@ -206,8 +206,6 @@ public:
virtual void quit() override; virtual void quit() override;
virtual void setWindowCaption(const char *caption) override;
virtual Audio::Mixer *getMixer() override; virtual Audio::Mixer *getMixer() override;
virtual FilesystemFactory *getFilesystemFactory() override; virtual FilesystemFactory *getFilesystemFactory() override;
virtual void getTimeAndDate(TimeDate &t) const override; virtual void getTimeAndDate(TimeDate &t) const override;

View file

@ -237,7 +237,7 @@ static Common::Error runGame(const Plugin *plugin, OSystem &system, const Common
if (caption.empty()) if (caption.empty())
caption = target; caption = target;
if (!caption.empty()) { if (!caption.empty()) {
system.setWindowCaption(caption.c_str()); system.setWindowCaption(caption.decode());
} }
// //
@ -364,7 +364,7 @@ static void setupGraphics(OSystem &system) {
GUI::GuiManager::instance(); GUI::GuiManager::instance();
// Set initial window caption // Set initial window caption
system.setWindowCaption(gScummVMFullVersion); system.setWindowCaption(Common::U32String(gScummVMFullVersion));
// Clear the main screen // Clear the main screen
system.fillScreen(0); system.fillScreen(0);

View file

@ -1472,13 +1472,9 @@ public:
* Set a window caption or any other comparable status display to the * Set a window caption or any other comparable status display to the
* given value. * given value.
* *
* The caption must be a pure ISO LATIN 1 string. Passing a string * @param caption The window caption to use.
* with a different encoding may lead to unexpected behavior,
* even crashes.
*
* @param caption The window caption to use, as an ISO LATIN 1 string.
*/ */
virtual void setWindowCaption(const char *caption) {} virtual void setWindowCaption(const Common::U32String &caption) {}
/** /**
* Display a message in an 'on-screen display'. * Display a message in an 'on-screen display'.

View file

@ -417,7 +417,7 @@ void GUIErrorMessage(const Common::String &msg, const char *url) {
} }
void GUIErrorMessage(const Common::U32String &msg, const char *url) { void GUIErrorMessage(const Common::U32String &msg, const char *url) {
g_system->setWindowCaption("Error"); g_system->setWindowCaption(_("Error"));
g_system->beginGFXTransaction(); g_system->beginGFXTransaction();
initCommonGFX(); initCommonGFX();
g_system->initSize(320, 200); g_system->initSize(320, 200);

View file

@ -192,7 +192,7 @@ unsigned int _surface_manager::Init_direct_draw() {
// Debug info // Debug info
Zdebug("*SURFACE_MANAGER* Initalizing the SDL video interface"); Zdebug("*SURFACE_MANAGER* Initalizing the SDL video interface");
g_system->setWindowCaption("In Cold Blood (C)2000 Revolution Software Ltd"); g_system->setWindowCaption(Common::U32String("In Cold Blood (C)2000 Revolution Software Ltd"));
initGraphics(640, 480, nullptr); initGraphics(640, 480, nullptr);
_zb = new TinyGL::FrameBuffer(640, 480, g_system->getScreenFormat()); // TODO: delete _zb = new TinyGL::FrameBuffer(640, 480, g_system->getScreenFormat()); // TODO: delete

View file

@ -1721,18 +1721,12 @@ void ScummEngine_v100he::o100_setSystemMessage() {
switch (subOp) { switch (subOp) {
case 80: // Set Window Caption case 80: // Set Window Caption
// TODO: The 'name' string can contain non-ASCII data. This can lead to // TODO: The 'name' string can contain non-ASCII data. This can lead to
// problems, because (a) the encoding used for "name" is not clear, // problems, because the encoding used for "name" is not clear,
// (b) OSystem::setWindowCaption only supports ASCII. As a result, odd
// behavior can occur, from strange wrong titles, up to crashes (happens
// under Mac OS X).
// //
// Possible fixes/workarounds: // Possible fixes/workarounds:
// - Simply stop using this. It's a rather unimportant "feature" anyway. // - Simply stop using this. It's a rather unimportant "feature" anyway.
// - Try to translate the text to ASCII. // - Try to translate the text to UTF-32.
// - Refine OSystem to accept window captions that are non-ASCII, e.g. //_system->setWindowCaption(Common::U32String((const char *)name));
// by enhancing all backends to deal with UTF-8 data. Of course, then
// one still would have to convert 'name' to the correct encoding.
//_system->setWindowCaption((const char *)name);
break; break;
case 131: // Set Version case 131: // Set Version
debug(1,"o100_setSystemMessage: (%d) %s", subOp, name); debug(1,"o100_setSystemMessage: (%d) %s", subOp, name);

View file

@ -490,18 +490,12 @@ void ScummEngine_v70he::o70_setSystemMessage() {
break; break;
case 243: // Set Window Caption case 243: // Set Window Caption
// TODO: The 'name' string can contain non-ASCII data. This can lead to // TODO: The 'name' string can contain non-ASCII data. This can lead to
// problems, because (a) the encoding used for "name" is not clear, // problems, because the encoding used for "name" is not clear.
// (b) OSystem::setWindowCaption only supports ASCII. As a result, odd
// behavior can occur, from strange wrong titles, up to crashes (happens
// under Mac OS X).
// //
// Possible fixes/workarounds: // Possible fixes/workarounds:
// - Simply stop using this. It's a rather unimportant "feature" anyway. // - Simply stop using this. It's a rather unimportant "feature" anyway.
// - Try to translate the text to ASCII. // - Try to translate the text to UTF-32.
// - Refine OSystem to accept window captions that are non-ASCII, e.g. //_system->setWindowCaption(Common::U32String((const char *)name));
// by enhancing all backends to deal with UTF-8 data. Of course, then
// one still would have to convert 'name' to the correct encoding.
//_system->setWindowCaption((const char *)name);
break; break;
default: default:
error("o70_setSystemMessage: default case %d", subOp); error("o70_setSystemMessage: default case %d", subOp);

View file

@ -1993,18 +1993,12 @@ void ScummEngine_v72he::o72_setSystemMessage() {
break; break;
case 243: // Set Window Caption case 243: // Set Window Caption
// TODO: The 'name' string can contain non-ASCII data. This can lead to // TODO: The 'name' string can contain non-ASCII data. This can lead to
// problems, because (a) the encoding used for "name" is not clear, // problems, because the encoding used for "name" is not clear.
// (b) OSystem::setWindowCaption only supports ASCII. As a result, odd
// behavior can occur, from strange wrong titles, up to crashes (happens
// under Mac OS X).
// //
// Possible fixes/workarounds: // Possible fixes/workarounds:
// - Simply stop using this. It's a rather unimportant "feature" anyway. // - Simply stop using this. It's a rather unimportant "feature" anyway.
// - Try to translate the text to ASCII. // - Try to translate the text to UTF-32.
// - Refine OSystem to accept window captions that are non-ASCII, e.g. //_system->setWindowCaption(Common::U32String((const char *)name));
// by enhancing all backends to deal with UTF-8 data. Of course, then
// one still would have to convert 'name' to the correct encoding.
//_system->setWindowCaption((const char *)name);
break; break;
default: default:
error("o72_setSystemMessage: default case %d", subOp); error("o72_setSystemMessage: default case %d", subOp);

View file

@ -674,7 +674,7 @@ void Sword2Engine::initializeFontResourceFlags() {
else else
textLine = (char *)fetchTextLine(textFile, 54) + 2; textLine = (char *)fetchTextLine(textFile, 54) + 2;
_system->setWindowCaption(textLine); _system->setWindowCaption(Common::U32String(textLine));
_resman->closeResource(TEXT_RES); _resman->closeResource(TEXT_RES);
} }