unicode in windowTitle
authorClaus Gittinger <cg@exept.de>
Wed, 29 Oct 2008 18:43:36 +0100
changeset 5067 e03d6ce6b5e7
parent 5066 c166f0bf72ed
child 5068 3b67e0696166
unicode in windowTitle
WinWorkstation.st
--- a/WinWorkstation.st	Wed Oct 29 17:32:29 2008 +0100
+++ b/WinWorkstation.st	Wed Oct 29 18:43:36 2008 +0100
@@ -744,8 +744,13 @@
 typedef struct createWindowInfo {
 	localWindowInfo *localWindowInfo;  /* in param */
 	HANDLE          newWinHandle;      /* out param */
+#ifdef PRE_27_OCT_2008
 	char            *windowName;       /* in params */
 	char            *className;
+#else
+	wchar_t         *windowName;       /* in params */
+	wchar_t         *className;
+#endif
 	int             winStyleBits;
 	int             winStyleBitsEx;
 	HANDLE          parentHandle;
@@ -2585,6 +2590,19 @@
 }
 #endif /* HANDLE_VIEWGRAVITY */
 
+static void
+ch2wch(char *in, wchar_t *out, int nMax)
+{
+    unsigned char *cp = (unsigned char *)in;
+    wchar_t *wcp = out;
+
+    while ((nMax > 1) && cp && *cp) {
+	*wcp++ = *cp++;
+	nMax--;
+    }
+    *wcp = 0;
+}
+
 static int
 winEventProcessing(hWnd, message, wParam, lParam, pDefault)
     HWND hWnd;                /* window handle                   */
@@ -2641,26 +2659,42 @@
 			HANDLE ev;
 			HANDLE hwnd;
 
+#ifdef PRE_27_OCT_2008
 			cwi->newWinHandle = hwnd = CreateWindowEx(
-						cwi->winStyleBitsEx,
-						cwi->className,
-						cwi->windowName,
-						cwi->winStyleBits,
-						cwi->x, cwi->y,
-						cwi->dx, cwi->dy,
-						cwi->parentHandle,
-						NULL,           /* menu */
-						(HANDLE) __getHInstance(),
-						cwi->localWindowInfo
-					       );
-
+					    cwi->winStyleBitsEx,
+					    cwi->className,
+					    cwi->windowName,
+					    cwi->winStyleBits,
+					    cwi->x, cwi->y,
+					    cwi->dx, cwi->dy,
+					    cwi->parentHandle,
+					    NULL,           /* menu */
+					    (HANDLE) __getHInstance(),
+					    cwi->localWindowInfo
+					   );
+#else
+			cwi->newWinHandle = hwnd = CreateWindowExW(
+					    cwi->winStyleBitsEx,
+					    cwi->className,
+					    cwi->windowName,
+					    cwi->winStyleBits,
+					    cwi->x, cwi->y,
+					    cwi->dx, cwi->dy,
+					    cwi->parentHandle,
+					    NULL,           /* menu */
+					    (HANDLE) __getHInstance(),
+					    cwi->localWindowInfo
+					   );
+#endif
 			if (hwnd == NULL) {
 			    cwi->errCode = GetLastError();
 			    console_fprintf(stderr, "WinWorkstation [info]: CreateWindow failed: %d (0x%x) [%d]\n",
 						cwi->errCode, cwi->errCode, __LINE__);
 			} else {
 #ifndef PRE_27_OCT_2008
+# if 0
 			    SetWindowLongW(hwnd, GWL_WNDPROC, GetWindowLong(hwnd, GWL_WNDPROC));
+# endif
 #endif
 			    SETLOCALWINDOWINFOPTR(hwnd, cwi->localWindowInfo);
 #ifdef DEBUG /* PARANOIA */
@@ -4739,31 +4773,12 @@
 			cwi->infoWasRead = 1;
 			if (cwi->newWinHandle == NULL) {
 			    HANDLE ev;
-			    wchar_t wClassName[256];
-			    wchar_t wWindowName[256];
-
-#ifndef PRE_27_OCT_2008
-			    {
-				char *cp = cwi->className;
-				wchar_t *wcp = wClassName;
-				while (cp && *cp) {
-				    *wcp++ = *cp++;
-				}
-				*wcp = 0;
-			    }
-			    {
-				char *cp = cwi->windowName;
-				wchar_t *wcp = wWindowName;
-				while (cp && *cp) {
-				    *wcp++ = *cp++;
-				}
-				*wcp = 0;
-			    }
-#endif
-			    cwi->newWinHandle = CreateWindowExW(
+
+#ifdef PRE_27_OCT_2008
+			    cwi->newWinHandle = CreateWindowEx(
 						    cwi->winStyleBitsEx,
-						    wClassName /* cwi->className */,
-						    wWindowName /* cwi->windowName */,
+						    cwi->className,
+						    cwi->windowName,
 						    cwi->winStyleBits,
 						    cwi->x, cwi->y,
 						    cwi->dx, cwi->dy,
@@ -4772,7 +4787,20 @@
 						    (HANDLE) __getHInstance(),
 						    cwi->localWindowInfo
 						   );
-
+#else
+			    cwi->newWinHandle = CreateWindowExW(
+						cwi->winStyleBitsEx,
+						cwi->className,
+						cwi->windowName,
+						cwi->winStyleBits,
+						cwi->x, cwi->y,
+						cwi->dx, cwi->dy,
+						cwi->parentHandle,
+						NULL,           /* menu */
+						(HANDLE) __getHInstance(),
+						cwi->localWindowInfo
+					       );
+#endif
 			    if (cwi->newWinHandle == NULL) {
 				cwi->errCode = GetLastError();
 				console_fprintf(stderr, "WinWorkstation [info]: CreateWindow %s failed: %d (0x%x) [%d]\n",
@@ -7973,8 +8001,16 @@
     HICON          xIcon = (HICON)0;
     ICONINFO       iconInfo;
     char *className;
-    static char classNameBuffer[256];
-    static char windowNameBuffer[256];
+
+#   define MAX_LABEL_SIZE       256
+#   define MAX_CLASSNAME_SIZE   256
+#ifdef PRE_27_OCT_2008
+    static char classNameBuffer[MAX_CLASSNAME_SIZE];
+    static char windowNameBuffer[MAX_LABEL_SIZE];
+#else
+    static wchar_t classNameBuffer[MAX_CLASSNAME_SIZE];
+    static wchar_t windowNameBuffer[MAX_LABEL_SIZE];
+#endif
     unsigned char fastBits[10000];
 
     xpos = __ArrayInstPtr(moreArgs)->a_element[0];
@@ -8116,13 +8152,10 @@
     }
 
     className = app_name;
-
-#if 1
     if (__isString(windowClass) || __isSymbol(windowClass)) {
 	className = __stringVal(windowClass);
 	NDPRINTF(("className: %s\n", className));
     }
-#endif
 
     if (__isString(windowClass) || __isSymbol(windowClass)) {
 	if (__isInteger(wStyle)) {
@@ -8367,26 +8400,30 @@
 	lI->flag |= LI_NATIVEWIN;
     }
 
-#if 0
-    /*
-     * this leads to leftOver pixel-garbage (views)
-     * under win95 ...
-     */
-    if (winStyleBits & WS_POPUP)
-#else
-    if (wStyle == @symbol(popUp))
-#endif
-    {
+#ifdef PRE_27_OCT_2008
+    if (wStyle == @symbol(popUp)) {
 	cwi.className = app_namePopup;
     } else {
 	if (wStyle == @symbol(dialog)) {
 	    cwi.className = app_nameDialog;
 	} else {
 	    strncpy(classNameBuffer, className, sizeof(classNameBuffer));
-	    classNameBuffer[sizeof(classNameBuffer)-1] = 0;
-	    cwi.className = &classNameBuffer;
-	}
-    }
+	    classNameBuffer[ MAX_CLASSNAME_SIZE-1 ] = 0;
+	    cwi.className = classNameBuffer;
+	}
+    }
+#else
+    if (wStyle == @symbol(popUp)) {
+	cwi.className = wapp_namePopup;
+    } else {
+	if (wStyle == @symbol(dialog)) {
+	    cwi.className = wapp_nameDialog;
+	} else {
+	    ch2wch(className, classNameBuffer, MAX_CLASSNAME_SIZE);
+	    cwi.className = classNameBuffer;
+	}
+    }
+#endif
 
     cwi.winStyleBits = winStyleBits;
     cwi.parentHandle = parentHandle;
@@ -8440,11 +8477,25 @@
 
     if (isTopWindow | isMDIChild) {
 	if (__isString(wlabel) || __isSymbol(wlabel)) {
-	    strncpy(windowNameBuffer, (char *) __stringVal(wlabel), sizeof(windowNameBuffer));
-	    windowNameBuffer[ sizeof(windowNameBuffer)-1 ] = 0;
+#ifdef PRE_27_OCT_2008
+	    strncpy(windowNameBuffer, (char *) __stringVal(wlabel), MAX_LABEL_SIZE);
+	    windowNameBuffer[ MAX_LABEL_SIZE-1 ] = 0;
+	    DPRINTF(("title = %s\n", windowNameBuffer));
+#else
+	    ch2wch((char *)__stringVal(wlabel), windowNameBuffer, MAX_LABEL_SIZE);
+#endif
 	    cwi.windowName = windowNameBuffer;
-	    DPRINTF(("title = %s\n", cwi.windowName));
-	}
+	}
+#ifndef PRE_27_OCT_2008
+	else if (__isUnicode16String(wlabel)) {
+	    int l = __unicode16StringSize(wlabel);
+
+	    if (l >= MAX_LABEL_SIZE) l = MAX_LABEL_SIZE-1;
+	    memmove(windowNameBuffer, __unicode16StringVal(wlabel), l*sizeof(wchar_t));
+	    windowNameBuffer[ l ] = 0;
+	    cwi.windowName = windowNameBuffer;
+	}
+#endif
     }
 
     cwi.infoWasRead = 0;
@@ -17911,14 +17962,28 @@
 
 %{  /* NOCONTEXT */
 
-    if (__isExternalAddress(aWindowId)
-     && (__isString(aString) || __isSymbol(aString))) {
+    if (__isExternalAddress(aWindowId)) {
 	HWND win = _HWNDVal(aWindowId);
-
-	SetWindowText(win, __stringVal(aString));
-	RETURN (self);
-    }
-%}
+	wchar_t nameBuffer[ MAX_LABEL_SIZE ];
+
+	if (__isString(aString) || __isSymbol(aString)) {
+	    ch2wch((char *)__stringVal(aString), nameBuffer, MAX_LABEL_SIZE);
+	    SetWindowTextW(win, nameBuffer);
+	    RETURN (self);
+	}
+	if (__isUnicode16String(aString)) {
+	    int l = __unicode16StringSize(aString);
+	    if (l >= MAX_LABEL_SIZE) l = MAX_LABEL_SIZE-1;
+	    memmove(nameBuffer, __unicode16StringVal(aString), l*sizeof(wchar_t));
+	    nameBuffer[ l ] = 0;
+	    SetWindowTextW(win, nameBuffer);
+	    RETURN (self);
+	}
+    }
+%}
+    "
+     (StandardSystemView new label:'äöü') open
+    "
 !
 
 setWindowShapeEllipticalX:x Y:y width:w height:h in:aWindowId
@@ -18157,7 +18222,7 @@
 !WinWorkstation class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libview/WinWorkstation.st,v 1.372 2008-10-28 10:04:22 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libview/WinWorkstation.st,v 1.373 2008-10-29 17:43:36 cg Exp $'
 ! !
 
 WinWorkstation initialize!