mirror of https://github.com/OpenTTD/OpenTTD
Remove: [Win32] Last pretenses of being able to build for Windows 95
parent
4bc69fec62
commit
beeb9e0a1b
|
@ -340,7 +340,7 @@ std::string FioFindDirectory(Subdirectory subdir)
|
||||||
|
|
||||||
static FILE *FioFOpenFileSp(const std::string &filename, const char *mode, Searchpath sp, Subdirectory subdir, size_t *filesize)
|
static FILE *FioFOpenFileSp(const std::string &filename, const char *mode, Searchpath sp, Subdirectory subdir, size_t *filesize)
|
||||||
{
|
{
|
||||||
#if defined(_WIN32) && defined(UNICODE)
|
#if defined(_WIN32)
|
||||||
/* fopen is implemented as a define with ellipses for
|
/* fopen is implemented as a define with ellipses for
|
||||||
* Unicode support (prepend an L). As we are not sending
|
* Unicode support (prepend an L). As we are not sending
|
||||||
* a string, but a variable, it 'renames' the variable,
|
* a string, but a variable, it 'renames' the variable,
|
||||||
|
|
|
@ -1103,7 +1103,6 @@ const char *MusicDriver_DMusic::Start(const StringList &parm)
|
||||||
DEBUG(driver, 1, "Detected DirectMusic ports:");
|
DEBUG(driver, 1, "Detected DirectMusic ports:");
|
||||||
for (int i = 0; _music->EnumPort(i, &caps) == S_OK; i++) {
|
for (int i = 0; _music->EnumPort(i, &caps) == S_OK; i++) {
|
||||||
if (caps.dwClass == DMUS_PC_OUTPUTCLASS) {
|
if (caps.dwClass == DMUS_PC_OUTPUTCLASS) {
|
||||||
/* Description is UNICODE even for ANSI build. */
|
|
||||||
DEBUG(driver, 1, " %d: %s%s", i, convert_from_fs(caps.wszDescription, desc, lengthof(desc)), i == pIdx ? " (selected)" : "");
|
DEBUG(driver, 1, " %d: %s%s", i, convert_from_fs(caps.wszDescription, desc, lengthof(desc)), i == pIdx ? " (selected)" : "");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -49,14 +49,9 @@ extern FT_Library _library;
|
||||||
static const char *GetShortPath(const TCHAR *long_path)
|
static const char *GetShortPath(const TCHAR *long_path)
|
||||||
{
|
{
|
||||||
static char short_path[MAX_PATH];
|
static char short_path[MAX_PATH];
|
||||||
#ifdef UNICODE
|
|
||||||
WCHAR short_path_w[MAX_PATH];
|
WCHAR short_path_w[MAX_PATH];
|
||||||
GetShortPathName(long_path, short_path_w, lengthof(short_path_w));
|
GetShortPathName(long_path, short_path_w, lengthof(short_path_w));
|
||||||
WideCharToMultiByte(CP_ACP, 0, short_path_w, -1, short_path, lengthof(short_path), nullptr, nullptr);
|
WideCharToMultiByte(CP_ACP, 0, short_path_w, -1, short_path, lengthof(short_path), nullptr, nullptr);
|
||||||
#else
|
|
||||||
/* Technically not needed, but do it for consistency. */
|
|
||||||
GetShortPathName(long_path, short_path, lengthof(short_path));
|
|
||||||
#endif
|
|
||||||
return short_path;
|
return short_path;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -68,8 +63,7 @@ static const char *GetShortPath(const TCHAR *long_path)
|
||||||
* kept in memory then until the font is no longer needed. This could mean
|
* kept in memory then until the font is no longer needed. This could mean
|
||||||
* an additional memory usage of 30MB (just for fonts!) when using an eastern
|
* an additional memory usage of 30MB (just for fonts!) when using an eastern
|
||||||
* font for all font sizes */
|
* font for all font sizes */
|
||||||
#define FONT_DIR_NT "SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Fonts"
|
static const wchar_t *FONT_DIR_NT = L"SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Fonts";
|
||||||
#define FONT_DIR_9X "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Fonts"
|
|
||||||
FT_Error GetFontByFaceName(const char *font_name, FT_Face *face)
|
FT_Error GetFontByFaceName(const char *font_name, FT_Face *face)
|
||||||
{
|
{
|
||||||
FT_Error err = FT_Err_Cannot_Open_Resource;
|
FT_Error err = FT_Err_Cannot_Open_Resource;
|
||||||
|
@ -81,14 +75,10 @@ FT_Error GetFontByFaceName(const char *font_name, FT_Face *face)
|
||||||
uint index;
|
uint index;
|
||||||
size_t path_len;
|
size_t path_len;
|
||||||
|
|
||||||
/* On windows NT (2000, NT3.5, XP, etc.) the fonts are stored in the
|
ret = RegOpenKeyEx(HKEY_LOCAL_MACHINE, FONT_DIR_NT, 0, KEY_READ, &hKey);
|
||||||
* "Windows NT" key, on Windows 9x in the Windows key. To save us having
|
|
||||||
* to retrieve the windows version, we'll just query both */
|
|
||||||
ret = RegOpenKeyEx(HKEY_LOCAL_MACHINE, _T(FONT_DIR_NT), 0, KEY_READ, &hKey);
|
|
||||||
if (ret != ERROR_SUCCESS) ret = RegOpenKeyEx(HKEY_LOCAL_MACHINE, _T(FONT_DIR_9X), 0, KEY_READ, &hKey);
|
|
||||||
|
|
||||||
if (ret != ERROR_SUCCESS) {
|
if (ret != ERROR_SUCCESS) {
|
||||||
DEBUG(freetype, 0, "Cannot open registry key HKLM\\SOFTWARE\\Microsoft\\Windows (NT)\\CurrentVersion\\Fonts");
|
DEBUG(freetype, 0, "Cannot open registry key HKLM\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Fonts");
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -122,7 +112,7 @@ FT_Error GetFontByFaceName(const char *font_name, FT_Face *face)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!SUCCEEDED(OTTDSHGetFolderPath(nullptr, CSIDL_FONTS, nullptr, SHGFP_TYPE_CURRENT, vbuffer))) {
|
if (!SUCCEEDED(SHGetFolderPath(nullptr, CSIDL_FONTS, nullptr, SHGFP_TYPE_CURRENT, vbuffer))) {
|
||||||
DEBUG(freetype, 0, "SHGetFolderPath cannot return fonts directory");
|
DEBUG(freetype, 0, "SHGetFolderPath cannot return fonts directory");
|
||||||
goto folder_error;
|
goto folder_error;
|
||||||
}
|
}
|
||||||
|
@ -629,11 +619,7 @@ void LoadWin32Font(FontSize fs)
|
||||||
/* Try a nice little undocumented function first for getting the internal font name.
|
/* Try a nice little undocumented function first for getting the internal font name.
|
||||||
* Some documentation is found at: http://www.undocprint.org/winspool/getfontresourceinfo */
|
* Some documentation is found at: http://www.undocprint.org/winspool/getfontresourceinfo */
|
||||||
typedef BOOL(WINAPI *PFNGETFONTRESOURCEINFO)(LPCTSTR, LPDWORD, LPVOID, DWORD);
|
typedef BOOL(WINAPI *PFNGETFONTRESOURCEINFO)(LPCTSTR, LPDWORD, LPVOID, DWORD);
|
||||||
#ifdef UNICODE
|
|
||||||
static PFNGETFONTRESOURCEINFO GetFontResourceInfo = (PFNGETFONTRESOURCEINFO)GetProcAddress(GetModuleHandle(_T("Gdi32")), "GetFontResourceInfoW");
|
static PFNGETFONTRESOURCEINFO GetFontResourceInfo = (PFNGETFONTRESOURCEINFO)GetProcAddress(GetModuleHandle(_T("Gdi32")), "GetFontResourceInfoW");
|
||||||
#else
|
|
||||||
static PFNGETFONTRESOURCEINFO GetFontResourceInfo = (PFNGETFONTRESOURCEINFO)GetProcAddress(GetModuleHandle(_T("Gdi32")), "GetFontResourceInfoA");
|
|
||||||
#endif
|
|
||||||
|
|
||||||
if (GetFontResourceInfo != nullptr) {
|
if (GetFontResourceInfo != nullptr) {
|
||||||
/* Try to query an array of LOGFONTs that describe the file. */
|
/* Try to query an array of LOGFONTs that describe the file. */
|
||||||
|
|
|
@ -52,8 +52,6 @@ bool MyShowCursor(bool show, bool toggle)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Helper function needed by dynamically loading libraries
|
* Helper function needed by dynamically loading libraries
|
||||||
* XXX: Hurray for MS only having an ANSI GetProcAddress function
|
|
||||||
* on normal windows and no Wide version except for in Windows Mobile/CE
|
|
||||||
*/
|
*/
|
||||||
bool LoadLibraryList(Function proc[], const char *dll)
|
bool LoadLibraryList(Function proc[], const char *dll)
|
||||||
{
|
{
|
||||||
|
@ -419,11 +417,6 @@ int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLi
|
||||||
|
|
||||||
CrashLog::InitialiseCrashLog();
|
CrashLog::InitialiseCrashLog();
|
||||||
|
|
||||||
#if defined(UNICODE)
|
|
||||||
/* Check if a win9x user started the win32 version */
|
|
||||||
if (HasBit(GetVersion(), 31)) usererror("This version of OpenTTD doesn't run on windows 95/98/ME.\nPlease download the win9x binary and try again.");
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* Convert the command line to UTF-8. We need a dedicated buffer
|
/* Convert the command line to UTF-8. We need a dedicated buffer
|
||||||
* for this because argv[] points into this buffer and this needs to
|
* for this because argv[] points into this buffer and this needs to
|
||||||
* be available between subsequent calls to FS2OTTD(). */
|
* be available between subsequent calls to FS2OTTD(). */
|
||||||
|
@ -468,7 +461,7 @@ void DetermineBasePaths(const char *exe)
|
||||||
|
|
||||||
TCHAR path[MAX_PATH];
|
TCHAR path[MAX_PATH];
|
||||||
#ifdef WITH_PERSONAL_DIR
|
#ifdef WITH_PERSONAL_DIR
|
||||||
if (SUCCEEDED(OTTDSHGetFolderPath(nullptr, CSIDL_PERSONAL, nullptr, SHGFP_TYPE_CURRENT, path))) {
|
if (SUCCEEDED(SHGetFolderPath(nullptr, CSIDL_PERSONAL, nullptr, SHGFP_TYPE_CURRENT, path))) {
|
||||||
std::string tmp(FS2OTTD(path));
|
std::string tmp(FS2OTTD(path));
|
||||||
AppendPathSeparator(tmp);
|
AppendPathSeparator(tmp);
|
||||||
tmp += PERSONAL_DIR;
|
tmp += PERSONAL_DIR;
|
||||||
|
@ -482,7 +475,7 @@ void DetermineBasePaths(const char *exe)
|
||||||
_searchpaths[SP_PERSONAL_DIR].clear();
|
_searchpaths[SP_PERSONAL_DIR].clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (SUCCEEDED(OTTDSHGetFolderPath(nullptr, CSIDL_COMMON_DOCUMENTS, nullptr, SHGFP_TYPE_CURRENT, path))) {
|
if (SUCCEEDED(SHGetFolderPath(nullptr, CSIDL_COMMON_DOCUMENTS, nullptr, SHGFP_TYPE_CURRENT, path))) {
|
||||||
std::string tmp(FS2OTTD(path));
|
std::string tmp(FS2OTTD(path));
|
||||||
AppendPathSeparator(tmp);
|
AppendPathSeparator(tmp);
|
||||||
tmp += PERSONAL_DIR;
|
tmp += PERSONAL_DIR;
|
||||||
|
@ -556,17 +549,6 @@ bool GetClipboardContents(char *buffer, const char *last)
|
||||||
CloseClipboard();
|
CloseClipboard();
|
||||||
|
|
||||||
if (out_len == 0) return false;
|
if (out_len == 0) return false;
|
||||||
#if !defined(UNICODE)
|
|
||||||
} else if (IsClipboardFormatAvailable(CF_TEXT)) {
|
|
||||||
OpenClipboard(nullptr);
|
|
||||||
cbuf = GetClipboardData(CF_TEXT);
|
|
||||||
|
|
||||||
ptr = (const char*)GlobalLock(cbuf);
|
|
||||||
strecpy(buffer, FS2OTTD(ptr), last);
|
|
||||||
|
|
||||||
GlobalUnlock(cbuf);
|
|
||||||
CloseClipboard();
|
|
||||||
#endif /* UNICODE */
|
|
||||||
} else {
|
} else {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -576,10 +558,7 @@ bool GetClipboardContents(char *buffer, const char *last)
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Convert to OpenTTD's encoding from that of the local environment.
|
* Convert to OpenTTD's encoding from wide characters.
|
||||||
* When the project is built in UNICODE, the system codepage is irrelevant and
|
|
||||||
* the input string is wide. In ANSI mode, the string is in the
|
|
||||||
* local codepage which we'll convert to wide-char, and then to UTF-8.
|
|
||||||
* OpenTTD internal encoding is UTF8.
|
* OpenTTD internal encoding is UTF8.
|
||||||
* The returned value's contents can only be guaranteed until the next call to
|
* The returned value's contents can only be guaranteed until the next call to
|
||||||
* this function. So if the value is needed for anything else, use convert_from_fs
|
* this function. So if the value is needed for anything else, use convert_from_fs
|
||||||
|
@ -595,10 +574,7 @@ const char *FS2OTTD(const TCHAR *name)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Convert from OpenTTD's encoding to that of the local environment.
|
* Convert from OpenTTD's encoding to wide characters.
|
||||||
* When the project is built in UNICODE the system codepage is irrelevant and
|
|
||||||
* the converted string is wide. In ANSI mode, the UTF8 string is converted
|
|
||||||
* to multi-byte.
|
|
||||||
* OpenTTD internal encoding is UTF8.
|
* OpenTTD internal encoding is UTF8.
|
||||||
* The returned value's contents can only be guaranteed until the next call to
|
* The returned value's contents can only be guaranteed until the next call to
|
||||||
* this function. So if the value is needed for anything else, use convert_from_fs
|
* this function. So if the value is needed for anything else, use convert_from_fs
|
||||||
|
@ -615,7 +591,7 @@ const TCHAR *OTTD2FS(const char *name, bool console_cp)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Convert to OpenTTD's encoding from that of the environment in
|
* Convert to OpenTTD's encoding from that of the environment in
|
||||||
* UNICODE. OpenTTD encoding is UTF8, local is wide
|
* UNICODE. OpenTTD encoding is UTF8, local is wide.
|
||||||
* @param name pointer to a valid string that will be converted
|
* @param name pointer to a valid string that will be converted
|
||||||
* @param utf8_buf pointer to a valid buffer that will receive the converted string
|
* @param utf8_buf pointer to a valid buffer that will receive the converted string
|
||||||
* @param buflen length in characters of the receiving buffer
|
* @param buflen length in characters of the receiving buffer
|
||||||
|
@ -623,19 +599,7 @@ const TCHAR *OTTD2FS(const char *name, bool console_cp)
|
||||||
*/
|
*/
|
||||||
char *convert_from_fs(const TCHAR *name, char *utf8_buf, size_t buflen)
|
char *convert_from_fs(const TCHAR *name, char *utf8_buf, size_t buflen)
|
||||||
{
|
{
|
||||||
#if defined(UNICODE)
|
|
||||||
const WCHAR *wide_buf = name;
|
const WCHAR *wide_buf = name;
|
||||||
#else
|
|
||||||
/* Convert string from the local codepage to UTF-16. */
|
|
||||||
int wide_len = MultiByteToWideChar(CP_ACP, 0, name, -1, nullptr, 0);
|
|
||||||
if (wide_len == 0) {
|
|
||||||
utf8_buf[0] = '\0';
|
|
||||||
return utf8_buf;
|
|
||||||
}
|
|
||||||
|
|
||||||
WCHAR *wide_buf = AllocaM(WCHAR, wide_len);
|
|
||||||
MultiByteToWideChar(CP_ACP, 0, name, -1, wide_buf, wide_len);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* Convert UTF-16 string to UTF-8. */
|
/* Convert UTF-16 string to UTF-8. */
|
||||||
int len = WideCharToMultiByte(CP_UTF8, 0, wide_buf, -1, utf8_buf, (int)buflen, nullptr, nullptr);
|
int len = WideCharToMultiByte(CP_UTF8, 0, wide_buf, -1, utf8_buf, (int)buflen, nullptr, nullptr);
|
||||||
|
@ -647,7 +611,7 @@ char *convert_from_fs(const TCHAR *name, char *utf8_buf, size_t buflen)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Convert from OpenTTD's encoding to that of the environment in
|
* Convert from OpenTTD's encoding to that of the environment in
|
||||||
* UNICODE. OpenTTD encoding is UTF8, local is wide
|
* UNICODE. OpenTTD encoding is UTF8, local is wide.
|
||||||
* @param name pointer to a valid string that will be converted
|
* @param name pointer to a valid string that will be converted
|
||||||
* @param system_buf pointer to a valid wide-char buffer that will receive the
|
* @param system_buf pointer to a valid wide-char buffer that will receive the
|
||||||
* converted string
|
* converted string
|
||||||
|
@ -657,91 +621,12 @@ char *convert_from_fs(const TCHAR *name, char *utf8_buf, size_t buflen)
|
||||||
*/
|
*/
|
||||||
TCHAR *convert_to_fs(const char *name, TCHAR *system_buf, size_t buflen, bool console_cp)
|
TCHAR *convert_to_fs(const char *name, TCHAR *system_buf, size_t buflen, bool console_cp)
|
||||||
{
|
{
|
||||||
#if defined(UNICODE)
|
|
||||||
int len = MultiByteToWideChar(CP_UTF8, 0, name, -1, system_buf, (int)buflen);
|
int len = MultiByteToWideChar(CP_UTF8, 0, name, -1, system_buf, (int)buflen);
|
||||||
if (len == 0) system_buf[0] = '\0';
|
if (len == 0) system_buf[0] = '\0';
|
||||||
#else
|
|
||||||
int len = MultiByteToWideChar(CP_UTF8, 0, name, -1, nullptr, 0);
|
|
||||||
if (len == 0) {
|
|
||||||
system_buf[0] = '\0';
|
|
||||||
return system_buf;
|
|
||||||
}
|
|
||||||
|
|
||||||
WCHAR *wide_buf = AllocaM(WCHAR, len);
|
|
||||||
MultiByteToWideChar(CP_UTF8, 0, name, -1, wide_buf, len);
|
|
||||||
|
|
||||||
len = WideCharToMultiByte(console_cp ? CP_OEMCP : CP_ACP, 0, wide_buf, len, system_buf, (int)buflen, nullptr, nullptr);
|
|
||||||
if (len == 0) system_buf[0] = '\0';
|
|
||||||
#endif
|
|
||||||
|
|
||||||
return system_buf;
|
return system_buf;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Our very own SHGetFolderPath function for support of windows operating
|
|
||||||
* systems that don't have this function (eg Win9x, etc.). We try using the
|
|
||||||
* native function, and if that doesn't exist we will try a more crude approach
|
|
||||||
* of environment variables and hope for the best
|
|
||||||
*/
|
|
||||||
HRESULT OTTDSHGetFolderPath(HWND hwnd, int csidl, HANDLE hToken, DWORD dwFlags, LPTSTR pszPath)
|
|
||||||
{
|
|
||||||
static HRESULT (WINAPI *SHGetFolderPath)(HWND, int, HANDLE, DWORD, LPTSTR) = nullptr;
|
|
||||||
static bool first_time = true;
|
|
||||||
|
|
||||||
/* We only try to load the library one time; if it fails, it fails */
|
|
||||||
if (first_time) {
|
|
||||||
#if defined(UNICODE)
|
|
||||||
# define W(x) x "W"
|
|
||||||
#else
|
|
||||||
# define W(x) x "A"
|
|
||||||
#endif
|
|
||||||
/* The function lives in shell32.dll for all current Windows versions, but it first started to appear in SHFolder.dll. */
|
|
||||||
if (!LoadLibraryList((Function*)&SHGetFolderPath, "shell32.dll\0" W("SHGetFolderPath") "\0\0")) {
|
|
||||||
if (!LoadLibraryList((Function*)&SHGetFolderPath, "SHFolder.dll\0" W("SHGetFolderPath") "\0\0")) {
|
|
||||||
DEBUG(misc, 0, "Unable to load " W("SHGetFolderPath") "from either shell32.dll or SHFolder.dll");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#undef W
|
|
||||||
first_time = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (SHGetFolderPath != nullptr) return SHGetFolderPath(hwnd, csidl, hToken, dwFlags, pszPath);
|
|
||||||
|
|
||||||
/* SHGetFolderPath doesn't exist, try a more conservative approach,
|
|
||||||
* eg environment variables. This is only included for legacy modes
|
|
||||||
* MSDN says: that 'pszPath' is a "Pointer to a null-terminated string of
|
|
||||||
* length MAX_PATH which will receive the path" so let's assume that
|
|
||||||
* Windows 95 with Internet Explorer 5.0, Windows 98 with Internet Explorer 5.0,
|
|
||||||
* Windows 98 Second Edition (SE), Windows NT 4.0 with Internet Explorer 5.0,
|
|
||||||
* Windows NT 4.0 with Service Pack 4 (SP4) */
|
|
||||||
{
|
|
||||||
DWORD ret;
|
|
||||||
switch (csidl) {
|
|
||||||
case CSIDL_FONTS: // Get the system font path, eg %WINDIR%\Fonts
|
|
||||||
ret = GetEnvironmentVariable(_T("WINDIR"), pszPath, MAX_PATH);
|
|
||||||
if (ret == 0) break;
|
|
||||||
_tcsncat(pszPath, _T("\\Fonts"), MAX_PATH);
|
|
||||||
|
|
||||||
return (HRESULT)0;
|
|
||||||
|
|
||||||
case CSIDL_PERSONAL:
|
|
||||||
case CSIDL_COMMON_DOCUMENTS: {
|
|
||||||
HKEY key;
|
|
||||||
if (RegOpenKeyEx(csidl == CSIDL_PERSONAL ? HKEY_CURRENT_USER : HKEY_LOCAL_MACHINE, REGSTR_PATH_SPECIAL_FOLDERS, 0, KEY_READ, &key) != ERROR_SUCCESS) break;
|
|
||||||
DWORD len = MAX_PATH;
|
|
||||||
ret = RegQueryValueEx(key, csidl == CSIDL_PERSONAL ? _T("Personal") : _T("Common Documents"), nullptr, nullptr, (LPBYTE)pszPath, &len);
|
|
||||||
RegCloseKey(key);
|
|
||||||
if (ret == ERROR_SUCCESS) return (HRESULT)0;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* XXX - other types to go here when needed... */
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return E_INVALIDARG;
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Determine the current user's locale. */
|
/** Determine the current user's locale. */
|
||||||
const char *GetCurrentLocale(const char *)
|
const char *GetCurrentLocale(const char *)
|
||||||
{
|
{
|
||||||
|
|
|
@ -19,19 +19,10 @@ bool LoadLibraryList(Function proc[], const char *dll);
|
||||||
char *convert_from_fs(const TCHAR *name, char *utf8_buf, size_t buflen);
|
char *convert_from_fs(const TCHAR *name, char *utf8_buf, size_t buflen);
|
||||||
TCHAR *convert_to_fs(const char *name, TCHAR *utf16_buf, size_t buflen, bool console_cp = false);
|
TCHAR *convert_to_fs(const char *name, TCHAR *utf16_buf, size_t buflen, bool console_cp = false);
|
||||||
|
|
||||||
/* Function shortcuts for UTF-8 <> UNICODE conversion. When unicode is not
|
/* Function shortcuts for UTF-8 <> UNICODE conversion. These functions use an
|
||||||
* defined these macros return the string passed to them, with UNICODE
|
|
||||||
* they return a pointer to the converted string. These functions use an
|
|
||||||
* internal buffer of max 512 characters. */
|
* internal buffer of max 512 characters. */
|
||||||
#if defined(UNICODE)
|
|
||||||
# define MB_TO_WIDE(str) OTTD2FS(str)
|
# define MB_TO_WIDE(str) OTTD2FS(str)
|
||||||
# define WIDE_TO_MB(str) FS2OTTD(str)
|
# define WIDE_TO_MB(str) FS2OTTD(str)
|
||||||
#else
|
|
||||||
# define MB_TO_WIDE(str) (str)
|
|
||||||
# define WIDE_TO_MB(str) (str)
|
|
||||||
#endif
|
|
||||||
|
|
||||||
HRESULT OTTDSHGetFolderPath(HWND, int, HANDLE, DWORD, LPTSTR);
|
|
||||||
|
|
||||||
#if defined(__MINGW32__) && !defined(__MINGW64__)
|
#if defined(__MINGW32__) && !defined(__MINGW64__)
|
||||||
#define SHGFP_TYPE_CURRENT 0
|
#define SHGFP_TYPE_CURRENT 0
|
||||||
|
|
|
@ -234,41 +234,6 @@ bool VideoDriver_Win32Base::MakeWindow(bool full_screen)
|
||||||
/** Forward key presses to the window system. */
|
/** Forward key presses to the window system. */
|
||||||
static LRESULT HandleCharMsg(uint keycode, WChar charcode)
|
static LRESULT HandleCharMsg(uint keycode, WChar charcode)
|
||||||
{
|
{
|
||||||
#if !defined(UNICODE)
|
|
||||||
static char prev_char = 0;
|
|
||||||
|
|
||||||
char input[2] = {(char)charcode, 0};
|
|
||||||
int input_len = 1;
|
|
||||||
|
|
||||||
if (prev_char != 0) {
|
|
||||||
/* We stored a lead byte previously, combine it with this byte. */
|
|
||||||
input[0] = prev_char;
|
|
||||||
input[1] = (char)charcode;
|
|
||||||
input_len = 2;
|
|
||||||
} else if (IsDBCSLeadByte(charcode)) {
|
|
||||||
/* We got a lead byte, store and exit. */
|
|
||||||
prev_char = charcode;
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
prev_char = 0;
|
|
||||||
|
|
||||||
wchar_t w[2]; // Can get up to two code points as a result.
|
|
||||||
int len = MultiByteToWideChar(CP_ACP, 0, input, input_len, w, 2);
|
|
||||||
switch (len) {
|
|
||||||
case 1: // Normal unicode character.
|
|
||||||
charcode = w[0];
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 2: // Got an UTF-16 surrogate pair back.
|
|
||||||
charcode = Utf16DecodeSurrogate(w[0], w[1]);
|
|
||||||
break;
|
|
||||||
|
|
||||||
default: // Some kind of error.
|
|
||||||
DEBUG(driver, 1, "Invalid DBCS character sequence encountered, dropping input");
|
|
||||||
charcode = 0;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
#else
|
|
||||||
static WChar prev_char = 0;
|
static WChar prev_char = 0;
|
||||||
|
|
||||||
/* Did we get a lead surrogate? If yes, store and exit. */
|
/* Did we get a lead surrogate? If yes, store and exit. */
|
||||||
|
@ -287,7 +252,6 @@ static LRESULT HandleCharMsg(uint keycode, WChar charcode)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
prev_char = 0;
|
prev_char = 0;
|
||||||
#endif /* UNICODE */
|
|
||||||
|
|
||||||
HandleKeypress(keycode, charcode);
|
HandleKeypress(keycode, charcode);
|
||||||
|
|
||||||
|
@ -396,11 +360,7 @@ static LRESULT HandleIMEComposition(HWND hwnd, WPARAM wParam, LPARAM lParam)
|
||||||
const char *caret = utf8_buf;
|
const char *caret = utf8_buf;
|
||||||
for (const TCHAR *c = str; *c != '\0' && *caret != '\0' && caret_bytes > 0; c++, caret_bytes--) {
|
for (const TCHAR *c = str; *c != '\0' && *caret != '\0' && caret_bytes > 0; c++, caret_bytes--) {
|
||||||
/* Skip DBCS lead bytes or leading surrogates. */
|
/* Skip DBCS lead bytes or leading surrogates. */
|
||||||
#ifdef UNICODE
|
|
||||||
if (Utf16IsLeadSurrogate(*c)) {
|
if (Utf16IsLeadSurrogate(*c)) {
|
||||||
#else
|
|
||||||
if (IsDBCSLeadByte(*c)) {
|
|
||||||
#endif
|
|
||||||
c++;
|
c++;
|
||||||
caret_bytes--;
|
caret_bytes--;
|
||||||
}
|
}
|
||||||
|
@ -569,16 +529,6 @@ LRESULT CALLBACK WndProcGdi(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
|
||||||
if (wParam == IMN_OPENCANDIDATE) SetCandidatePos(hwnd);
|
if (wParam == IMN_OPENCANDIDATE) SetCandidatePos(hwnd);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
#if !defined(UNICODE)
|
|
||||||
case WM_IME_CHAR:
|
|
||||||
if (GB(wParam, 8, 8) != 0) {
|
|
||||||
/* DBCS character, send lead byte first. */
|
|
||||||
HandleCharMsg(0, GB(wParam, 8, 8));
|
|
||||||
}
|
|
||||||
HandleCharMsg(0, GB(wParam, 0, 8));
|
|
||||||
return 0;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
case WM_DEADCHAR:
|
case WM_DEADCHAR:
|
||||||
console = GB(lParam, 16, 8) == 41;
|
console = GB(lParam, 16, 8) == 41;
|
||||||
return 0;
|
return 0;
|
||||||
|
|
Loading…
Reference in New Issue