From 76295cecf345ade3c240ce22085f7f4d67df8ba2 Mon Sep 17 00:00:00 2001 From: Ozkan Sezer Date: Tue, 5 Jan 2021 15:50:10 +0300 Subject: [PATCH] video/windows: ANSI/UNICODE updates (cf. bug 5435): - explicitly use UNICODE versions of DrawText, EnumDisplaySettings, EnumDisplayDevices, and CreateDC: the underlying structures have WCHAR strings. - change WIN_UpdateDisplayMode and WIN_GetDisplayMode() to accept LPCWSTR instead of LPCTSTR for the same reason. - change WIN_StringToUTF8 and WIN_UTF8ToString to the explicit 'W' versions where appropriate. --- src/video/windows/SDL_windowskeyboard.c | 4 ++-- src/video/windows/SDL_windowsmessagebox.c | 12 ++++++------ src/video/windows/SDL_windowsmodes.c | 20 ++++++++++---------- src/video/windows/SDL_windowsvideo.c | 10 +++++----- src/video/windows/SDL_windowswindow.c | 4 ++-- 5 files changed, 25 insertions(+), 25 deletions(-) diff --git a/src/video/windows/SDL_windowskeyboard.c b/src/video/windows/SDL_windowskeyboard.c index 964d61c41..157ec2a59 100644 --- a/src/video/windows/SDL_windowskeyboard.c +++ b/src/video/windows/SDL_windowskeyboard.c @@ -749,7 +749,7 @@ static void IME_SendInputEvent(SDL_VideoData *videodata) { char *s = 0; - s = WIN_StringToUTF8(videodata->ime_composition); + s = WIN_StringToUTF8W(videodata->ime_composition); SDL_SendKeyboardText(s); SDL_free(s); @@ -774,7 +774,7 @@ IME_SendEditingEvent(SDL_VideoData *videodata) else { SDL_wcslcpy(buffer, videodata->ime_composition, size); } - s = WIN_StringToUTF8(buffer); + s = WIN_StringToUTF8W(buffer); SDL_SendEditingText(s, videodata->ime_cursor + (int)SDL_wcslen(videodata->ime_readingstring), 0); SDL_free(s); } diff --git a/src/video/windows/SDL_windowsmessagebox.c b/src/video/windows/SDL_windowsmessagebox.c index 78b81fdfe..5e5fda808 100644 --- a/src/video/windows/SDL_windowsmessagebox.c +++ b/src/video/windows/SDL_windowsmessagebox.c @@ -260,7 +260,7 @@ static SDL_bool AddDialogString(WIN_DialogData *dialog, const char *string) string = ""; } - wstring = WIN_UTF8ToString(string); + wstring = WIN_UTF8ToStringW(string); if (!wstring) { return SDL_FALSE; } @@ -645,9 +645,9 @@ WIN_ShowOldMessageBox(const SDL_MessageBoxData *messageboxdata, int *buttonid) } /* Measure the *pixel* size of the string. */ - wmessage = WIN_UTF8ToString(messageboxdata->message); + wmessage = WIN_UTF8ToStringW(messageboxdata->message); SDL_zero(TextSize); - DrawText(FontDC, wmessage, -1, &TextSize, DT_CALCRECT | DT_LEFT | DT_NOPREFIX | DT_EDITCONTROL); + DrawTextW(FontDC, wmessage, -1, &TextSize, DT_CALCRECT | DT_LEFT | DT_NOPREFIX | DT_EDITCONTROL); /* Add margins and some padding for hangs, etc. */ TextSize.left += TextMargin; @@ -822,8 +822,8 @@ WIN_ShowMessageBox(const SDL_MessageBoxData *messageboxdata, int *buttonid) ParentWindow = ((SDL_WindowData *) messageboxdata->window->driverdata)->hwnd; } - wmessage = WIN_UTF8ToString(messageboxdata->message); - wtitle = WIN_UTF8ToString(messageboxdata->title); + wmessage = WIN_UTF8ToStringW(messageboxdata->message); + wtitle = WIN_UTF8ToStringW(messageboxdata->title); SDL_zero(TaskConfig); TaskConfig.cbSize = sizeof (TASKDIALOGCONFIG); @@ -872,7 +872,7 @@ WIN_ShowMessageBox(const SDL_MessageBoxData *messageboxdata, int *buttonid) SDL_free(pButtons); return -1; } - pButton->pszButtonText = WIN_UTF8ToString(buttontext); + pButton->pszButtonText = WIN_UTF8ToStringW(buttontext); if (messageboxdata->buttons[i].flags & SDL_MESSAGEBOX_BUTTON_RETURNKEY_DEFAULT) { TaskConfig.nDefaultButton = pButton->nButtonID; } diff --git a/src/video/windows/SDL_windowsmodes.c b/src/video/windows/SDL_windowsmodes.c index 93eb84d65..e8b1fc151 100644 --- a/src/video/windows/SDL_windowsmodes.c +++ b/src/video/windows/SDL_windowsmodes.c @@ -32,7 +32,7 @@ /* #define DEBUG_MODES */ static void -WIN_UpdateDisplayMode(_THIS, LPCTSTR deviceName, DWORD index, SDL_DisplayMode * mode) +WIN_UpdateDisplayMode(_THIS, LPCWSTR deviceName, DWORD index, SDL_DisplayMode * mode) { SDL_DisplayModeData *data = (SDL_DisplayModeData *) mode->driverdata; HDC hdc; @@ -109,14 +109,14 @@ WIN_UpdateDisplayMode(_THIS, LPCTSTR deviceName, DWORD index, SDL_DisplayMode * } static SDL_bool -WIN_GetDisplayMode(_THIS, LPCTSTR deviceName, DWORD index, SDL_DisplayMode * mode) +WIN_GetDisplayMode(_THIS, LPCWSTR deviceName, DWORD index, SDL_DisplayMode * mode) { SDL_DisplayModeData *data; DEVMODE devmode; devmode.dmSize = sizeof(devmode); devmode.dmDriverExtra = 0; - if (!EnumDisplaySettings(deviceName, index, &devmode)) { + if (!EnumDisplaySettingsW(deviceName, index, &devmode)) { return SDL_FALSE; } @@ -145,10 +145,10 @@ WIN_AddDisplay(_THIS, HMONITOR hMonitor, const MONITORINFOEXW *info, SDL_bool se SDL_VideoDisplay display; SDL_DisplayData *displaydata; SDL_DisplayMode mode; - DISPLAY_DEVICE device; + DISPLAY_DEVICEW device; #ifdef DEBUG_MODES - SDL_Log("Display: %s\n", WIN_StringToUTF8(info->szDevice)); + SDL_Log("Display: %s\n", WIN_StringToUTF8W(info->szDevice)); #endif if (!WIN_GetDisplayMode(_this, info->szDevice, ENUM_CURRENT_SETTINGS, &mode)) { @@ -178,8 +178,8 @@ WIN_AddDisplay(_THIS, HMONITOR hMonitor, const MONITORINFOEXW *info, SDL_bool se SDL_zero(display); device.cb = sizeof(device); - if (EnumDisplayDevices(info->szDevice, 0, &device, 0)) { - display.name = WIN_StringToUTF8(device.DeviceString); + if (EnumDisplayDevicesW(info->szDevice, 0, &device, 0)) { + display.name = WIN_StringToUTF8W(device.DeviceString); } display.desktop_mode = mode; display.current_mode = mode; @@ -383,9 +383,9 @@ WIN_SetDisplayMode(_THIS, SDL_VideoDisplay * display, SDL_DisplayMode * mode) LONG status; if (mode->driverdata == display->desktop_mode.driverdata) { - status = ChangeDisplaySettingsEx(displaydata->DeviceName, NULL, NULL, CDS_FULLSCREEN, NULL); + status = ChangeDisplaySettingsExW(displaydata->DeviceName, NULL, NULL, CDS_FULLSCREEN, NULL); } else { - status = ChangeDisplaySettingsEx(displaydata->DeviceName, &data->DeviceMode, NULL, CDS_FULLSCREEN, NULL); + status = ChangeDisplaySettingsExW(displaydata->DeviceName, &data->DeviceMode, NULL, CDS_FULLSCREEN, NULL); } if (status != DISP_CHANGE_SUCCESSFUL) { const char *reason = "Unknown reason"; @@ -405,7 +405,7 @@ WIN_SetDisplayMode(_THIS, SDL_VideoDisplay * display, SDL_DisplayMode * mode) } return SDL_SetError("ChangeDisplaySettingsEx() failed: %s", reason); } - EnumDisplaySettings(displaydata->DeviceName, ENUM_CURRENT_SETTINGS, &data->DeviceMode); + EnumDisplaySettingsW(displaydata->DeviceName, ENUM_CURRENT_SETTINGS, &data->DeviceMode); WIN_UpdateDisplayMode(_this, displaydata->DeviceName, ENUM_CURRENT_SETTINGS, mode); return 0; } diff --git a/src/video/windows/SDL_windowsvideo.c b/src/video/windows/SDL_windowsvideo.c index f0a5da976..9ef93605f 100644 --- a/src/video/windows/SDL_windowsvideo.c +++ b/src/video/windows/SDL_windowsvideo.c @@ -184,7 +184,7 @@ WIN_CreateDevice(int devindex) device->GL_GetSwapInterval = WIN_GL_GetSwapInterval; device->GL_SwapWindow = WIN_GL_SwapWindow; device->GL_DeleteContext = WIN_GL_DeleteContext; -#elif SDL_VIDEO_OPENGL_EGL +#elif SDL_VIDEO_OPENGL_EGL /* Use EGL based functions */ device->GL_LoadLibrary = WIN_GLES_LoadLibrary; device->GL_GetProcAddress = WIN_GLES_GetProcAddress; @@ -249,7 +249,7 @@ WIN_VideoQuit(_THIS) #define D3D_DEBUG_INFO #include -SDL_bool +SDL_bool D3D_LoadDLL(void **pD3DDLL, IDirect3D9 **pDirect3D9Interface) { *pD3DDLL = SDL_LoadObject("D3D9.DLL"); @@ -308,7 +308,7 @@ SDL_Direct3D9GetAdapterIndex(int displayIndex) SDL_SetError("Invalid display index"); adapterIndex = -1; /* make sure we return something invalid */ } else { - char *displayName = WIN_StringToUTF8(pData->DeviceName); + char *displayName = WIN_StringToUTF8W(pData->DeviceName); unsigned int count = IDirect3D9_GetAdapterCount(pD3D); unsigned int i; for (i=0; iDeviceName); + displayName = WIN_StringToUTF8W(pData->DeviceName); nAdapter = 0; while (*adapterIndex == -1 && SUCCEEDED(IDXGIFactory_EnumAdapters(pDXGIFactory, nAdapter, &pDXGIAdapter))) { nOutput = 0; while (*adapterIndex == -1 && SUCCEEDED(IDXGIAdapter_EnumOutputs(pDXGIAdapter, nOutput, &pDXGIOutput))) { DXGI_OUTPUT_DESC outputDesc; if (SUCCEEDED(IDXGIOutput_GetDesc(pDXGIOutput, &outputDesc))) { - char *outputName = WIN_StringToUTF8(outputDesc.DeviceName); + char *outputName = WIN_StringToUTF8W(outputDesc.DeviceName); if (SDL_strcmp(outputName, displayName) == 0) { *adapterIndex = nAdapter; *outputIndex = nOutput; diff --git a/src/video/windows/SDL_windowswindow.c b/src/video/windows/SDL_windowswindow.c index e39ed08aa..2a54eb2ab 100644 --- a/src/video/windows/SDL_windowswindow.c +++ b/src/video/windows/SDL_windowswindow.c @@ -708,7 +708,7 @@ WIN_SetWindowGammaRamp(_THIS, SDL_Window * window, const Uint16 * ramp) HDC hdc; BOOL succeeded = FALSE; - hdc = CreateDC(data->DeviceName, NULL, NULL, NULL); + hdc = CreateDCW(data->DeviceName, NULL, NULL, NULL); if (hdc) { succeeded = SetDeviceGammaRamp(hdc, (LPVOID)ramp); if (!succeeded) { @@ -727,7 +727,7 @@ WIN_GetWindowGammaRamp(_THIS, SDL_Window * window, Uint16 * ramp) HDC hdc; BOOL succeeded = FALSE; - hdc = CreateDC(data->DeviceName, NULL, NULL, NULL); + hdc = CreateDCW(data->DeviceName, NULL, NULL, NULL); if (hdc) { succeeded = GetDeviceGammaRamp(hdc, (LPVOID)ramp); if (!succeeded) {