From 9c0c2c6b08f83d2cf7b61fc833a16c5f99ef6650 Mon Sep 17 00:00:00 2001 From: Camilla Berglund Date: Fri, 3 Feb 2012 20:34:24 +0100 Subject: [PATCH] Upgraded Win32 port to Unicode mode. --- readme.html | 1 + src/win32_init.c | 10 ++++---- src/win32_platform.h | 12 ++++++---- src/win32_window.c | 54 ++++++++++++++++++++++++++++++++++++++++---- 4 files changed, 63 insertions(+), 14 deletions(-) diff --git a/readme.html b/readme.html index f0a89585..b007952d 100644 --- a/readme.html +++ b/readme.html @@ -319,6 +319,7 @@ version of GLFW.

  • [X11] Bugfix: Some window properties required by the ICCCM were not set
  • [X11] Bugfix: Calling glXCreateContextAttribsARB with an unavailable OpenGL version caused the application to terminate with a BadMatch Xlib error
  • [X11] Bugfix: A synchronization point necessary for jitter-free locked cursor mode was incorrectly removed
  • +
  • [Win32] Changed port to use Unicode mode only
  • [Win32] Removed explicit support for versions of Windows older than Windows XP
  • [Win32] Bugfix: Window activation and iconification did not work as expected
  • [Win32] Bugfix: Software rasterizer pixel formats were not discarded by the WGL_ARB_pixel_format code path
  • diff --git a/src/win32_init.c b/src/win32_init.c index 0756b0f2..b23e7d57 100644 --- a/src/win32_init.c +++ b/src/win32_init.c @@ -47,7 +47,7 @@ static GLboolean initLibraries(void) #ifndef _GLFW_NO_DLOAD_GDI32 // gdi32.dll (OpenGL pixel format functions & SwapBuffers) - _glfwLibrary.Win32.gdi.instance = LoadLibrary("gdi32.dll"); + _glfwLibrary.Win32.gdi.instance = LoadLibrary(L"gdi32.dll"); if (!_glfwLibrary.Win32.gdi.instance) return GL_FALSE; @@ -81,12 +81,12 @@ static GLboolean initLibraries(void) #ifndef _GLFW_NO_DLOAD_WINMM // winmm.dll (for joystick and timer support) - _glfwLibrary.Win32.winmm.instance = LoadLibrary("winmm.dll"); + _glfwLibrary.Win32.winmm.instance = LoadLibrary(L"winmm.dll"); if (!_glfwLibrary.Win32.winmm.instance) return GL_FALSE; - _glfwLibrary.Win32.winmm.joyGetDevCapsA = (JOYGETDEVCAPSA_T) - GetProcAddress(_glfwLibrary.Win32.winmm.instance, "joyGetDevCapsA"); + _glfwLibrary.Win32.winmm.joyGetDevCaps = (JOYGETDEVCAPS_T) + GetProcAddress(_glfwLibrary.Win32.winmm.instance, "joyGetDevCapsW"); _glfwLibrary.Win32.winmm.joyGetPos = (JOYGETPOS_T) GetProcAddress(_glfwLibrary.Win32.winmm.instance, "joyGetPos"); _glfwLibrary.Win32.winmm.joyGetPosEx = (JOYGETPOSEX_T) @@ -94,7 +94,7 @@ static GLboolean initLibraries(void) _glfwLibrary.Win32.winmm.timeGetTime = (TIMEGETTIME_T) GetProcAddress(_glfwLibrary.Win32.winmm.instance, "timeGetTime"); - if (!_glfwLibrary.Win32.winmm.joyGetDevCapsA || + if (!_glfwLibrary.Win32.winmm.joyGetDevCaps || !_glfwLibrary.Win32.winmm.joyGetPos || !_glfwLibrary.Win32.winmm.joyGetPosEx || !_glfwLibrary.Win32.winmm.timeGetTime) diff --git a/src/win32_platform.h b/src/win32_platform.h index 074e28ba..0d63e09c 100644 --- a/src/win32_platform.h +++ b/src/win32_platform.h @@ -45,6 +45,8 @@ // thinks it is the only one that gets to do so #undef APIENTRY +#define UNICODE + #include #include @@ -162,7 +164,7 @@ typedef BOOL (WINAPI * SETDEVICEGAMMARAMP_T) (HDC,PVOID); // winmm.dll function pointer typedefs #ifndef _GLFW_NO_DLOAD_WINMM -typedef MMRESULT (WINAPI * JOYGETDEVCAPSA_T) (UINT,LPJOYCAPSA,UINT); +typedef MMRESULT (WINAPI * JOYGETDEVCAPS_T) (UINT,LPJOYCAPS,UINT); typedef MMRESULT (WINAPI * JOYGETPOS_T) (UINT,LPJOYINFO); typedef MMRESULT (WINAPI * JOYGETPOSEX_T) (UINT,LPJOYINFOEX); typedef DWORD (WINAPI * TIMEGETTIME_T) (void); @@ -190,12 +192,12 @@ typedef DWORD (WINAPI * TIMEGETTIME_T) (void); // winmm.dll shortcuts #ifndef _GLFW_NO_DLOAD_WINMM -#define _glfw_joyGetDevCaps _glfwLibrary.Win32.winmm.joyGetDevCapsA +#define _glfw_joyGetDevCaps _glfwLibrary.Win32.winmm.joyGetDevCaps #define _glfw_joyGetPos _glfwLibrary.Win32.winmm.joyGetPos #define _glfw_joyGetPosEx _glfwLibrary.Win32.winmm.joyGetPosEx #define _glfw_timeGetTime _glfwLibrary.Win32.winmm.timeGetTime #else -#define _glfw_joyGetDevCaps joyGetDevCapsA +#define _glfw_joyGetDevCaps joyGetDevCaps #define _glfw_joyGetPos joyGetPos #define _glfw_joyGetPosEx joyGetPosEx #define _glfw_timeGetTime timeGetTime @@ -204,7 +206,7 @@ typedef DWORD (WINAPI * TIMEGETTIME_T) (void); // We use versioned window class names in order not to cause conflicts // between applications using different versions of GLFW -#define _GLFW_WNDCLASSNAME "GLFW30" +#define _GLFW_WNDCLASSNAME L"GLFW30" #define _GLFW_PLATFORM_WINDOW_STATE _GLFWwindowWin32 Win32 @@ -309,7 +311,7 @@ typedef struct _GLFWlibraryWin32 // winmm.dll struct { HINSTANCE instance; - JOYGETDEVCAPSA_T joyGetDevCapsA; + JOYGETDEVCAPS_T joyGetDevCaps; JOYGETPOS_T joyGetPos; JOYGETPOSEX_T joyGetPosEx; TIMEGETTIME_T timeGetTime; diff --git a/src/win32_window.c b/src/win32_window.c index e2619acf..6ebe07b4 100644 --- a/src/win32_window.c +++ b/src/win32_window.c @@ -34,6 +34,31 @@ #include +//======================================================================== +// Convert the specified UTF-8 string to a wide string +//======================================================================== + +static WCHAR* createWideStringFromUTF8(const char* source) +{ + WCHAR* target; + int length; + + length = MultiByteToWideChar(CP_UTF8, 0, source, -1, NULL, 0); + if (!length) + return NULL; + + target = (WCHAR*) _glfwMalloc(sizeof(WCHAR) * (length + 1)); + + if (!MultiByteToWideChar(CP_UTF8, 0, source, -1, target, length + 1)) + { + _glfwFree(target); + return NULL; + } + + return target; +} + + //======================================================================== // Convert BPP to RGB bits based on "best guess" //======================================================================== @@ -1220,7 +1245,7 @@ static ATOM registerWindowClass(void) wc.lpszClassName = _GLFW_WNDCLASSNAME; // Set class name // Load user-provided icon if available - wc.hIcon = LoadIcon(_glfwLibrary.Win32.instance, "GLFW_ICON"); + wc.hIcon = LoadIcon(_glfwLibrary.Win32.instance, L"GLFW_ICON"); if (!wc.hIcon) { // Load default icon @@ -1280,9 +1305,10 @@ static int createWindow(_GLFWwindow* window, const _GLFWfbconfig* fbconfig) { DWORD dwStyle, dwExStyle; - int pixelFormat, fullWidth, fullHeight; + int length, pixelFormat, fullWidth, fullHeight; RECT wa; POINT pos; + WCHAR* wideTitle; // Set common window styles dwStyle = WS_CLIPSIBLINGS | WS_CLIPCHILDREN | WS_VISIBLE; @@ -1331,9 +1357,17 @@ static int createWindow(_GLFWwindow* window, else SystemParametersInfo(SPI_GETWORKAREA, 0, &wa, 0); + wideTitle = createWideStringFromUTF8(wndconfig->title); + if (!wideTitle) + { + _glfwSetError(GLFW_PLATFORM_ERROR, + "glfwOpenWindow: Failed to convert title to wide string"); + return; + } + window->Win32.handle = CreateWindowEx(window->Win32.dwExStyle, _GLFW_WNDCLASSNAME, - wndconfig->title, + wideTitle, window->Win32.dwStyle, wa.left, wa.top, // Window position fullWidth, // Decorated window width @@ -1349,6 +1383,8 @@ static int createWindow(_GLFWwindow* window, return GL_FALSE; } + _glfwFree(wideTitle); + window->WGL.DC = GetDC(window->Win32.handle); if (!window->WGL.DC) { @@ -1568,7 +1604,17 @@ void _glfwPlatformCloseWindow(_GLFWwindow* window) void _glfwPlatformSetWindowTitle(_GLFWwindow* window, const char* title) { - SetWindowText(window->Win32.handle, title); + WCHAR* wideTitle = createWideStringFromUTF8(title); + if (!wideTitle) + { + _glfwSetError(GLFW_PLATFORM_ERROR, + "glfwSetWindowTitle: Failed to convert title to wide string"); + return; + } + + SetWindowText(window->Win32.handle, wideTitle); + + _glfwFree(wideTitle); }