fix win32 frontend to allow setting unicode titles

This commit is contained in:
Vincent Sanders 2019-12-01 11:27:21 +00:00
parent 9a02a41cd6
commit 03f72abdb3

View File

@ -59,7 +59,7 @@
static struct gui_window *window_list = NULL; static struct gui_window *window_list = NULL;
/** The main window class name */ /** The main window class name */
static const char windowclassname_main[] = "nswsmainwindow"; static const LPCWSTR windowclassname_main = L"nswsmainwindow";
/** width of the throbber element */ /** width of the throbber element */
#define NSWS_THROBBER_WIDTH 24 #define NSWS_THROBBER_WIDTH 24
@ -143,9 +143,9 @@ static HWND nsws_window_create(HINSTANCE hInstance, struct gui_window *gw)
NSLOG(netsurf, INFO, NSLOG(netsurf, INFO,
"creating hInstance %p GUI window %p", "creating hInstance %p GUI window %p",
hInstance, gw); hInstance, gw);
hwnd = CreateWindowEx(0, hwnd = CreateWindowExW(0,
windowclassname_main, windowclassname_main,
"NetSurf Browser", L"NetSurf Browser",
WS_OVERLAPPEDWINDOW | WS_OVERLAPPEDWINDOW |
WS_CLIPCHILDREN | WS_CLIPCHILDREN |
WS_CLIPSIBLINGS | WS_CLIPSIBLINGS |
@ -1345,7 +1345,7 @@ nsws_window_event_callback(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
*/ */
GetClientRect(hwnd, &rmain); GetClientRect(hwnd, &rmain);
PostMessage(hwnd, WM_SIZE, 0, MAKELPARAM(rmain.right, rmain.bottom)); PostMessage(hwnd, WM_SIZE, 0, MAKELPARAM(rmain.right, rmain.bottom));
return DefWindowProc(hwnd, msg, wparam, lparam); return DefWindowProcW(hwnd, msg, wparam, lparam);
} }
@ -1353,7 +1353,7 @@ nsws_window_event_callback(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
if (gw == NULL) { if (gw == NULL) {
NSLOG(netsurf, INFO, NSLOG(netsurf, INFO,
"Unable to find gui window structure for hwnd %p", hwnd); "Unable to find gui window structure for hwnd %p", hwnd);
return DefWindowProc(hwnd, msg, wparam, lparam); return DefWindowProcW(hwnd, msg, wparam, lparam);
} }
switch (msg) { switch (msg) {
@ -1386,7 +1386,7 @@ nsws_window_event_callback(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
} }
return DefWindowProc(hwnd, msg, wparam, lparam); return DefWindowProcW(hwnd, msg, wparam, lparam);
} }
@ -1529,6 +1529,8 @@ static void win32_window_update_extent(struct gui_window *gw)
static void win32_window_set_title(struct gui_window *w, const char *title) static void win32_window_set_title(struct gui_window *w, const char *title)
{ {
char *fulltitle; char *fulltitle;
int wlen;
LPWSTR enctitle;
if (w == NULL) { if (w == NULL) {
return; return;
@ -1537,14 +1539,32 @@ static void win32_window_set_title(struct gui_window *w, const char *title)
NSLOG(netsurf, INFO, "%p, title %s", w, title); NSLOG(netsurf, INFO, "%p, title %s", w, title);
fulltitle = malloc(strlen(title) + SLEN(" - NetSurf") + 1); fulltitle = malloc(strlen(title) + SLEN(" - NetSurf") + 1);
if (fulltitle == NULL) { if (fulltitle == NULL) {
win32_warning("NoMemory", 0); NSLOG(netsurf, ERROR, "%s",
messages_get_errorcode(NSERROR_NOMEM));
return; return;
} }
strcpy(fulltitle, title); strcpy(fulltitle, title);
strcat(fulltitle, " - NetSurf"); strcat(fulltitle, " - NetSurf");
SendMessage(w->main, WM_SETTEXT, 0, (LPARAM)fulltitle); wlen = MultiByteToWideChar(CP_UTF8, 0, fulltitle, -1, NULL, 0);
if (wlen == 0) {
NSLOG(netsurf, ERROR, "failed encoding \"%s\"", fulltitle);
free(fulltitle);
return;
}
enctitle = malloc(2 * (wlen + 1));
if (enctitle == NULL) {
NSLOG(netsurf, ERROR, "%s encoding \"%s\" len %d",
messages_get_errorcode(NSERROR_NOMEM), fulltitle, wlen);
free(fulltitle);
return;
}
MultiByteToWideChar(CP_UTF8, 0, fulltitle, -1, enctitle, wlen);
SetWindowTextW(w->main, enctitle);
free(enctitle);
free(fulltitle); free(fulltitle);
} }
@ -1908,7 +1928,7 @@ nserror
nsws_create_main_class(HINSTANCE hinstance) nsws_create_main_class(HINSTANCE hinstance)
{ {
nserror ret = NSERROR_OK; nserror ret = NSERROR_OK;
WNDCLASSEX wc; WNDCLASSEXW wc;
/* main window */ /* main window */
wc.cbSize = sizeof(WNDCLASSEX); wc.cbSize = sizeof(WNDCLASSEX);
@ -1924,7 +1944,7 @@ nsws_create_main_class(HINSTANCE hinstance)
wc.lpszClassName = windowclassname_main; wc.lpszClassName = windowclassname_main;
wc.hIconSm = LoadIcon(hinstance, MAKEINTRESOURCE(IDR_NETSURF_ICON)); wc.hIconSm = LoadIcon(hinstance, MAKEINTRESOURCE(IDR_NETSURF_ICON));
if (RegisterClassEx(&wc) == 0) { if (RegisterClassExW(&wc) == 0) {
win_perror("MainWindowClass"); win_perror("MainWindowClass");
ret = NSERROR_INIT_FAILED; ret = NSERROR_INIT_FAILED;
} }