Split toUTF16() into a new file; other Windows text functions will also be there.

This commit is contained in:
Pietro Gagliardi 2015-04-09 09:23:44 -04:00
parent 723f2af8c6
commit 1f18d88f56
3 changed files with 19 additions and 17 deletions

18
new/text_windows.c Normal file
View File

@ -0,0 +1,18 @@
// 9 april 2015
#include "uipriv_windows.h"
#define MBTWC(str, wstr, bufsiz) MultiByteToWideChar(CP_UTF8, 0, str, -1, wstr, bufsiz)
WCHAR *toUTF16(const char *str)
{
WCHAR *wstr;
int n;
n = MBTWC(str, NULL, 0);
if (n == 0)
logLastError("error figuring out number of characters to convert to in toUTF16()");
wstr = (WCHAR *) uiAlloc(n * sizeof (WCHAR), "WCHAR[]");
if (MBTWC(str, wstr, n) != n)
logLastError("error converting from UTF-8 to UTF-16 in toUTF16()");
return wstr;
}

View File

@ -47,7 +47,7 @@ extern int nCmdShow;
extern HFONT hMessageFont;
extern HWND initialParent;
// util_windows.c
// text_windows.c
extern WCHAR *toUTF16(const char *);
// container_windows.c

View File

@ -1,22 +1,6 @@
// 6 april 2015
#include "uipriv_windows.h"
#define MBTWC(str, wstr, bufsiz) MultiByteToWideChar(CP_UTF8, 0, str, -1, wstr, bufsiz)
WCHAR *toUTF16(const char *str)
{
WCHAR *wstr;
int n;
n = MBTWC(str, NULL, 0);
if (n == 0)
logLastError("error figuring out number of characters to convert to in toUTF16()");
wstr = (WCHAR *) uiAlloc(n * sizeof (WCHAR), "WCHAR[]");
if (MBTWC(str, wstr, n) != n)
logLastError("error converting from UTF-8 to UTF-16 in toUTF16()");
return wstr;
}
intmax_t uiWindowsWindowTextWidth(HWND hwnd)
{
int len;