summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobin Watts <Robin.Watts@artifex.com>2011-07-21 16:40:21 +0100
committerRobin Watts <Robin.Watts@artifex.com>2011-07-21 16:40:21 +0100
commit554ce829a9eb59da437541e2efbc646d9edc2805 (patch)
treee8e0363a2feeb9a7044ac71ee551c66659e987ae
parentc9a8f8b3b0327bb62fc79cfe93d6bd79f997a2b6 (diff)
Fix Bug 692355; gswin32 has garbage chars in window title bars.
Existing ghostscript includes windows.h without defining UNICODE, but calls the unicode versions of functions where appropriate. Here we move to defining UNICODE before including windows.h, but we keep to the practise of calling A or W specific variants as much as possible. Partly this is because of time before the release, but mostly a fear that this might lead to a Pandoras box of changes.
-rw-r--r--gs/psi/dwtext.c61
-rw-r--r--gs/psi/dwtext.h9
2 files changed, 46 insertions, 24 deletions
diff --git a/gs/psi/dwtext.c b/gs/psi/dwtext.c
index 21055a48e..b0cba1351 100644
--- a/gs/psi/dwtext.c
+++ b/gs/psi/dwtext.c
@@ -22,12 +22,10 @@
#define STRICT
#include <windowsx.h>
-#include "windows_.h"
+#include "dwtext.h"
#include <commdlg.h>
#include <shellapi.h>
-#include "dwtext.h"
-
#ifdef WINDOWS_NO_UNICODE
#define CHARSIZE 1
#else
@@ -173,7 +171,7 @@ void
text_font(TW *tw, const char *name, int size)
{
/* make a new font */
- LOGFONT lf;
+ LOGFONTA lf;
TEXTMETRIC tm;
LPSTR p;
HDC hdc;
@@ -185,8 +183,7 @@ text_font(TW *tw, const char *name, int size)
return;
/* set new name and size */
- if (tw->fontname)
- free(tw->fontname);
+ free(tw->fontname);
tw->fontname = (char *)malloc(strlen(name)+1);
if (tw->fontname == NULL)
return;
@@ -195,7 +192,7 @@ text_font(TW *tw, const char *name, int size)
/* if window not open, hwnd == 0 == HWND_DESKTOP */
hdc = GetDC(tw->hwnd);
- memset(&lf, 0, sizeof(LOGFONT));
+ memset(&lf, 0, sizeof(LOGFONTA));
strncpy(lf.lfFaceName,tw->fontname,LF_FACESIZE);
lf.lfHeight = -MulDiv(tw->fontsize, GetDeviceCaps(hdc, LOGPIXELSY), 72);
lf.lfPitchAndFamily = FIXED_PITCH;
@@ -211,7 +208,7 @@ text_font(TW *tw, const char *name, int size)
if (tw->hfont)
DeleteFont(tw->hfont);
- tw->hfont = CreateFontIndirect((LOGFONT FAR *)&lf);
+ tw->hfont = CreateFontIndirectA((LOGFONTA FAR *)&lf);
/* get text size */
SelectFont(hdc, tw->hfont);
@@ -234,11 +231,9 @@ void
text_drag(TW *tw, const char *pre, const char *post)
{
/* remove old strings */
- if (tw->DragPre)
- free((char *)tw->DragPre);
+ free((char *)tw->DragPre);
tw->DragPre = NULL;
- if (tw->DragPost)
- free((char *)tw->DragPost);
+ free((char *)tw->DragPost);
tw->DragPost = NULL;
/* add new strings */
@@ -315,25 +310,25 @@ text_destroy(TW *tw)
DeleteFont(tw->hfont);
tw->hfont = NULL;
- if (tw->KeyBuf)
- free((char *)tw->KeyBuf);
+ free((char *)tw->KeyBuf);
tw->KeyBuf = NULL;
- if (tw->ScreenBuffer)
- free((char *)tw->ScreenBuffer);
+ free((char *)tw->ScreenBuffer);
tw->ScreenBuffer = NULL;
- if (tw->DragPre)
- free((char *)tw->DragPre);
+ free((char *)tw->DragPre);
tw->DragPre = NULL;
- if (tw->DragPost)
- free((char *)tw->DragPost);
+ free((char *)tw->DragPost);
tw->DragPost = NULL;
- if (tw->fontname)
- free((char *)tw->fontname);
+ free((char *)tw->fontname);
tw->fontname = NULL;
+
+#ifndef WINDOWS_NO_UNICODE
+ free((char *)tw->TitleW);
+ tw->TitleW = NULL;
+#endif
}
/* register the window class */
@@ -371,6 +366,20 @@ int text_create(TW *tw, const char *app_name, int show_cmd)
{
HMENU sysmenu;
HINSTANCE hInstance = GetModuleHandle(NULL);
+#ifndef WINDOWS_NO_UNICODE
+ wchar_t *app_nameW, *d;
+ const char *s;
+
+ app_nameW = malloc(strlen(app_name)*2+2);
+ if (app_nameW == NULL) {
+ text_error("Out of memory");
+ return 1;
+ }
+ d = app_nameW;
+ s = app_name;
+ while ((*d++ = (wchar_t)(unsigned char)(*s++)) != 0);
+ tw->TitleW = app_nameW;
+#endif
tw->Title = app_name;
tw->nCmdShow = show_cmd;
@@ -408,7 +417,7 @@ int text_create(TW *tw, const char *app_name, int show_cmd)
tw->x, tw->y, tw->cx, tw->cy,
NULL, NULL, hInstance, tw);
#else
- tw->hwnd = CreateWindowW(TextWinClassName, (LPCWSTR)tw->Title,
+ tw->hwnd = CreateWindowW(TextWinClassName, app_nameW,
WS_OVERLAPPEDWINDOW | WS_VSCROLL | WS_HSCROLL,
tw->x, tw->y, tw->cx, tw->cy,
NULL, NULL, hInstance, tw);
@@ -1223,7 +1232,11 @@ WndTextProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
TCHAR title[256];
int count = GetWindowText(hwnd, title,
sizeof(title)/sizeof(TCHAR)-11);
- lstrcpy(title+count, " - closing");
+#ifdef WINDOWS_NO_UNICODE
+ lstrcpyA(title+count, " - closing");
+#else
+ lstrcpyW(title+count, L" - closing");
+#endif
SetWindowText(hwnd, title);
}
tw->quitnow = TRUE;
diff --git a/gs/psi/dwtext.h b/gs/psi/dwtext.h
index e8d23331d..5d6fa3419 100644
--- a/gs/psi/dwtext.h
+++ b/gs/psi/dwtext.h
@@ -21,10 +21,19 @@
#define _Windows
#endif
+#ifndef WINDOWS_NO_UNICODE
+#define UNICODE
+#endif
+
#include "windows_.h"
+#undef UNICODE
+
typedef struct TEXTWINDOW_S {
const char *Title; /* required */
+#ifndef WINDOWS_NO_UNICODE
+ wchar_t *TitleW; /* required */
+#endif
HICON hIcon; /* optional */
#ifdef WINDOWS_NO_UNICODE
BYTE *ScreenBuffer;