Skip to content

Commit

Permalink
Fixed bug #139
Browse files Browse the repository at this point in the history
The text in SDL_WM_SetCaption() is in UTF-8 encoding.
  • Loading branch information
slouken committed Mar 13, 2006
1 parent 9120aff commit 844c388
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 14 deletions.
2 changes: 1 addition & 1 deletion include/SDL_video.h
Expand Up @@ -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);
Expand Down
8 changes: 2 additions & 6 deletions src/video/wincommon/SDL_sysevents.c
Expand Up @@ -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();
Expand Down
9 changes: 5 additions & 4 deletions src/video/wincommon/SDL_syswm.c
Expand Up @@ -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
}

Expand Down
17 changes: 14 additions & 3 deletions src/video/x11/SDL_x11wm.c
Expand Up @@ -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);
Expand All @@ -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);
Expand Down

0 comments on commit 844c388

Please sign in to comment.