From 844c38838501d727259ec0c8600c1e99cfc26b67 Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Mon, 13 Mar 2006 01:33:58 +0000 Subject: [PATCH] Fixed bug #139 The text in SDL_WM_SetCaption() is in UTF-8 encoding. --- include/SDL_video.h | 2 +- src/video/wincommon/SDL_sysevents.c | 8 ++------ src/video/wincommon/SDL_syswm.c | 9 +++++---- src/video/x11/SDL_x11wm.c | 17 ++++++++++++++--- 4 files changed, 22 insertions(+), 14 deletions(-) diff --git a/include/SDL_video.h b/include/SDL_video.h index 6753b290d..d70330e1a 100644 --- a/include/SDL_video.h +++ b/include/SDL_video.h @@ -818,7 +818,7 @@ extern DECLSPEC void SDLCALL SDL_GL_Unlock(void); /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ /* - * Sets/Gets the title and icon text of the display window + * Sets/Gets the title and icon text of the display window (UTF-8 encoded) */ extern DECLSPEC void SDLCALL SDL_WM_SetCaption(const char *title, const char *icon); extern DECLSPEC void SDLCALL SDL_WM_GetCaption(char **title, char **icon); diff --git a/src/video/wincommon/SDL_sysevents.c b/src/video/wincommon/SDL_sysevents.c index 977f128af..00bd8b1b7 100644 --- a/src/video/wincommon/SDL_sysevents.c +++ b/src/video/wincommon/SDL_sysevents.c @@ -762,13 +762,9 @@ int SDL_RegisterApp(char *name, Uint32 style, void *hInst) if ( name ) { #ifdef _WIN32_WCE /* WinCE uses the UNICODE version */ - size_t nLen = SDL_strlen(name)+1; - SDL_Appname = SDL_malloc(nLen*2); - MultiByteToWideChar(CP_ACP, 0, name, -1, SDL_Appname, nLen); + SDL_Appname = SDL_iconv_utf8_ucs2(name); #else - size_t nLen = SDL_strlen(name)+1; - SDL_Appname = SDL_malloc(nLen); - SDL_strlcpy(SDL_Appname, name, nLen); + SDL_Appname = SDL_iconv_utf8_latin1(name); #endif /* _WIN32_WCE */ SDL_Appstyle = style; SDL_Instance = hInst ? hInst : SDL_GetModuleHandle(); diff --git a/src/video/wincommon/SDL_syswm.c b/src/video/wincommon/SDL_syswm.c index 9610ec23a..d6db2fb92 100644 --- a/src/video/wincommon/SDL_syswm.c +++ b/src/video/wincommon/SDL_syswm.c @@ -230,12 +230,13 @@ void WIN_SetWMCaption(_THIS, const char *title, const char *icon) { #ifdef _WIN32_WCE /* WinCE uses the UNICODE version */ - int nLen = SDL_strlen(title)+1; - LPWSTR lpszW = alloca(nLen*2); - MultiByteToWideChar(CP_ACP, 0, title, -1, lpszW, nLen); + LPWSTR lpszW = SDL_iconv_utf8_ucs2(title); SetWindowText(SDL_Window, lpszW); + SDL_free(lpszW); #else - SetWindowText(SDL_Window, title); + char *lpsz = SDL_iconv_utf8_latin1(title); + SetWindowText(SDL_Window, lpsz); + SDL_free(lpsz); #endif } diff --git a/src/video/x11/SDL_x11wm.c b/src/video/x11/SDL_x11wm.c index eec866125..c1161023a 100644 --- a/src/video/x11/SDL_x11wm.c +++ b/src/video/x11/SDL_x11wm.c @@ -255,8 +255,13 @@ void X11_SetCaption(_THIS, const char *title, const char *icon) &titleprop); #endif if ( error != Success ) { - pXStringListToTextProperty((char **)&title, 1, - &titleprop); + char *title_latin1 = SDL_iconv_utf8_latin1((char *)title); + if ( !title_latin1 ) { + SDL_OutOfMemory(); + return; + } + pXStringListToTextProperty(&title_latin1, 1, &titleprop); + SDL_free(title_latin1); } pXSetWMName(SDL_Display, WMwindow, &titleprop); pXFree(titleprop.value); @@ -268,7 +273,13 @@ void X11_SetCaption(_THIS, const char *title, const char *icon) (char **)&icon, 1, XUTF8StringStyle, &iconprop); #endif if ( error != Success ) { - pXStringListToTextProperty((char **)&icon, 1, &iconprop); + char *icon_latin1 = SDL_iconv_utf8_latin1((char *)title); + if ( !icon_latin1 ) { + SDL_OutOfMemory(); + return; + } + pXStringListToTextProperty(&icon_latin1, 1, &iconprop); + SDL_free(icon_latin1); } pXSetWMIconName(SDL_Display, WMwindow, &iconprop); pXFree(iconprop.value);