changeset 1505:4d005dfbb7f5

Fixed bug #139 The text in SDL_WM_SetCaption() is in UTF-8 encoding.
author Sam Lantinga <slouken@libsdl.org>
date Mon, 13 Mar 2006 01:33:58 +0000
parents 7b4b31075f67
children dc057a602e98
files include/SDL_video.h src/video/wincommon/SDL_sysevents.c src/video/wincommon/SDL_syswm.c src/video/x11/SDL_x11wm.c
diffstat 4 files changed, 22 insertions(+), 14 deletions(-) [+]
line wrap: on
line diff
--- a/include/SDL_video.h	Mon Mar 13 01:20:05 2006 +0000
+++ b/include/SDL_video.h	Mon Mar 13 01:33:58 2006 +0000
@@ -818,7 +818,7 @@
 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
 
 /*
- * 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);
--- a/src/video/wincommon/SDL_sysevents.c	Mon Mar 13 01:20:05 2006 +0000
+++ b/src/video/wincommon/SDL_sysevents.c	Mon Mar 13 01:33:58 2006 +0000
@@ -762,13 +762,9 @@
 	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();
--- a/src/video/wincommon/SDL_syswm.c	Mon Mar 13 01:20:05 2006 +0000
+++ b/src/video/wincommon/SDL_syswm.c	Mon Mar 13 01:33:58 2006 +0000
@@ -230,12 +230,13 @@
 {
 #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
 }
 
--- a/src/video/x11/SDL_x11wm.c	Mon Mar 13 01:20:05 2006 +0000
+++ b/src/video/x11/SDL_x11wm.c	Mon Mar 13 01:33:58 2006 +0000
@@ -255,8 +255,13 @@
 				&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 @@
 				(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);