Revision: 9349 https://osdn.net/projects/ttssh2/scm/svn/commits/9349 Author: zmatsuo Date: 2021-08-10 23:42:18 +0900 (Tue, 10 Aug 2021) Log Message: ----------- i18n系APIを調整 - GetI18nStrW() のバリエーションを追加 - GetI18nStrWW() - GetI18nStrWA() - i18n_static.c, common_static.lib に追加 - SetI18nDlgStrs() のバリエーションを追加 - SetI18nDlgStrsW() - SetI18nDlgStrsA() - i18n_static.c, common_static.lib に追加 - SetI18nMenuStrs() のバリエーションを追加 - SetI18nMenuStrsW() - SetI18nMenuStrsA() - i18n_static.c, common_static.lib に追加 - SetDlgTextsW() 追加 - ≒ SetI18nDlgStrsW() - SetDlgMenuTextsW() 追加 - ≒ SetI18nMenuStrsW() - GetI18nLogfont() のバリエーションを追加 - GetI18nLogfontAW() - GetI18nLogfontAA() - SetI18nListW() 追加 - TTMessageBoxW() 追加 - ttlib.c から ttlib_static_cpp.cpp へ移動 - GetNthString() - GetNthNum() - GetNthNum2() - RestoreNewLineW() Modified Paths: -------------- trunk/teraterm/common/i18n.c trunk/teraterm/common/i18n.h trunk/teraterm/common/i18n_static.c trunk/teraterm/common/ttlib.c trunk/teraterm/common/ttlib.h trunk/teraterm/common/ttlib_static.c trunk/teraterm/common/ttlib_static_cpp.cpp -------------- next part -------------- Modified: trunk/teraterm/common/i18n.c =================================================================== --- trunk/teraterm/common/i18n.c 2021-08-10 14:42:09 UTC (rev 9348) +++ trunk/teraterm/common/i18n.c 2021-08-10 14:42:18 UTC (rev 9349) @@ -41,32 +41,10 @@ DllExport size_t WINAPI GetI18nStrW(const char *section, const char *key, wchar_t *buf, int buf_len, const wchar_t *def, const char *iniFile) { - size_t size; - if (pGetPrivateProfileStringW != NULL) { - wchar_t sectionW[64]; - wchar_t keyW[128]; - wchar_t iniFileW[MAX_PATH]; - MultiByteToWideChar(CP_ACP, 0, section, -1, sectionW, _countof(sectionW)); - MultiByteToWideChar(CP_ACP, 0, key, -1, keyW, _countof(keyW)); - MultiByteToWideChar(CP_ACP, 0, iniFile, -1, iniFileW, _countof(iniFileW)); - // The return value is the number of characters copied to the buffer, - // not including the terminating null character. - size = pGetPrivateProfileStringW(sectionW, keyW, def, buf, buf_len, iniFileW); - if (size == 0 && def == NULL) { - buf[0] = 0; - } - } - else { - char tmp[MAX_UIMSG]; - char defA[MAX_UIMSG]; - WideCharToMultiByte(CP_ACP, 0, def, -1, defA, _countof(defA), NULL, NULL); - size = GetPrivateProfileStringA(section, key, defA, tmp, _countof(tmp), iniFile); - if (size == 0 && def == NULL) { - buf[0] = 0; - } - MultiByteToWideChar(CP_ACP, 0, tmp, -1, buf, buf_len); - } - size = RestoreNewLineW(buf); + wchar_t *str; + size_t size = GetI18nStrWA(section, key, def, iniFile, &str); + wcsncpy_s(buf, buf_len, str, _TRUNCATE); + free(str); return size; } @@ -79,44 +57,26 @@ */ DllExport void WINAPI GetI18nStr(const char *section, const char *key, PCHAR buf, int buf_len, const char *def, const char *iniFile) { - DWORD size = GetPrivateProfileStringA(section, key, def, buf, buf_len, iniFile); - if (size == 0 && def == NULL) { - // GetPrivateProfileStringA()\x82̖߂\xE8\x92l\x82\xCDbuf\x82ɃZ\x83b\x83g\x82\xB5\x82\xBD\x95\xB6\x8E\x9A\x90\x94(\x8FI\x92[\x8A܂܂\xB8) - // OS\x82̃o\x81[\x83W\x83\x87\x83\x93\x82ɂ\xE6\x82\xC1\x82Ă\xCDdef\x82\xAANULL\x82̎\x9E\x81Abuf\x82\xAA\x96\xA2\x90ݒ\xE8\x82ƂȂ邱\x82Ƃ\xAA\x82\xA0\x82\xE9 - buf[0] = 0; + wchar_t *strW; + wchar_t *defW = ToWcharA(def); + size_t size = GetI18nStrWA(section, key, defW, iniFile, &strW); + size_t lenA; + char *strA = _WideCharToMultiByte(strW, size, CP_ACP, &lenA); + if ((size_t)buf_len >= lenA) { + memcpy(buf, strA, lenA); + } else { + // \x83o\x83b\x83t\x83@\x95s\x91\xAB + memcpy(buf, strA, buf_len); + buf[buf_len - 1] = '\0'; } - RestoreNewLine(buf); + free(defW); + free(strA); + free(strW); } int WINAPI GetI18nLogfont(const char *section, const char *key, PLOGFONTA logfont, int ppi, const char *iniFile) { - char tmp[MAX_UIMSG]; - char font[LF_FACESIZE]; - int height, charset; - assert(iniFile[0] != '\0'); - memset(logfont, 0, sizeof(*logfont)); - - GetPrivateProfileStringA(section, key, "", tmp, MAX_UIMSG, iniFile); - if (tmp[0] == '\0') { - return FALSE; - } - - GetNthString(tmp, 1, LF_FACESIZE-1, font); - GetNthNum(tmp, 2, &height); - GetNthNum(tmp, 3, &charset); - - if (font[0] != '\0') { - strncpy_s(logfont->lfFaceName, sizeof(logfont->lfFaceName), font, _TRUNCATE); - } - logfont->lfCharSet = (BYTE)charset; - if (ppi != 0) { - logfont->lfHeight = MulDiv(height, -ppi, 72); - } else { - logfont->lfHeight = height; - } - logfont->lfWidth = 0; - - return TRUE; + return GetI18nLogfontAA(section, key, logfont, ppi, iniFile); } /* @@ -127,94 +87,15 @@ * */ int WINAPI SetI18nDlgStrs(const char *section, HWND hDlgWnd, - const DlgTextInfo *infos, size_t infoCount, const char *UILanguageFile) + const DlgTextInfo *infos, size_t infoCount, const char *UILanguageFile) { - size_t i; - int translatedCount = 0; - - assert(hDlgWnd != NULL); - assert(infoCount > 0); - for (i = 0 ; i < infoCount; i++) { - const char *key = infos[i].key; - BOOL r = FALSE; - if (pGetPrivateProfileStringW == NULL) { - // ANSI - char uimsg[MAX_UIMSG]; - GetI18nStr(section, key, uimsg, sizeof(uimsg), NULL, UILanguageFile); - if (uimsg[0] != '\0') { - const int nIDDlgItem = infos[i].nIDDlgItem; - if (nIDDlgItem == 0) { - r = SetWindowTextA(hDlgWnd, uimsg); - assert(r != 0); - } else { - r = SetDlgItemTextA(hDlgWnd, nIDDlgItem, uimsg); - assert(r != 0); - } - } - } - else { - // UNICODE - wchar_t uimsg[MAX_UIMSG]; - GetI18nStrW(section, key, uimsg, _countof(uimsg), NULL, UILanguageFile); - if (uimsg[0] != L'\0') { - const int nIDDlgItem = infos[i].nIDDlgItem; - if (nIDDlgItem == 0) { - r = pSetWindowTextW(hDlgWnd, uimsg); - assert(r != 0); - } else { - r = pSetDlgItemTextW(hDlgWnd, nIDDlgItem, uimsg); - assert(r != 0); - } - } - } - if (r) - translatedCount++; - } - - return (translatedCount); + return SetI18nDlgStrsA(hDlgWnd, section, infos, infoCount, UILanguageFile); } void WINAPI SetI18nMenuStrs(const char *section, HMENU hMenu, const DlgTextInfo *infos, size_t infoCount, - const char *UILanguageFile) + const char *UILanguageFile) { - const int id_position_threshold = 1000; - size_t i; - for (i = 0; i < infoCount; i++) { - const int nIDDlgItem = infos[i].nIDDlgItem; - const char *key = infos[i].key; - if (pGetPrivateProfileStringW == NULL) { - // ANSI - char uimsg[MAX_UIMSG]; - GetI18nStr(section, key, uimsg, sizeof(uimsg), NULL, UILanguageFile); - if (uimsg[0] != '\0') { - UINT uFlags = (nIDDlgItem < id_position_threshold) ? MF_BYPOSITION : MF_BYCOMMAND; - ModifyMenuA(hMenu, nIDDlgItem, uFlags, nIDDlgItem, uimsg); - } - else { - if (nIDDlgItem < id_position_threshold) { - // \x88\xEA\x93xModifyMenu()\x82\xB5\x82Ă\xA8\x82\xA9\x82Ȃ\xA2\x82ƃ\x81\x83j\x83\x85\x81[\x82̈ʒu\x82\xAA\x82\xB8\x82\xEA\x82\xE9 - GetMenuStringA(hMenu, nIDDlgItem, uimsg, _countof(uimsg), MF_BYPOSITION); - ModifyMenuA(hMenu, nIDDlgItem, MF_BYPOSITION, nIDDlgItem, uimsg); - } - } - } - else { - // UNICODE - wchar_t uimsg[MAX_UIMSG]; - GetI18nStrW(section, key, uimsg, _countof(uimsg), NULL, UILanguageFile); - if (uimsg[0] != '\0') { - UINT uFlags = (nIDDlgItem < id_position_threshold) ? MF_BYPOSITION : MF_BYCOMMAND; - pModifyMenuW(hMenu, nIDDlgItem, uFlags, nIDDlgItem, uimsg); - } - else { - if (nIDDlgItem < id_position_threshold) { - // \x88\xEA\x93xModifyMenu()\x82\xB5\x82Ă\xA8\x82\xA9\x82Ȃ\xA2\x82ƃ\x81\x83j\x83\x85\x81[\x82̈ʒu\x82\xAA\x82\xB8\x82\xEA\x82\xE9 - pGetMenuStringW(hMenu, nIDDlgItem, uimsg, _countof(uimsg), MF_BYPOSITION); - pModifyMenuW(hMenu, nIDDlgItem, MF_BYPOSITION, nIDDlgItem, uimsg); - } - } - } - } + SetI18nMenuStrsA(hMenu, section, infos, infoCount, UILanguageFile); } /* vim: set ts=4 sw=4 ff=dos : */ Modified: trunk/teraterm/common/i18n.h =================================================================== --- trunk/teraterm/common/i18n.h 2021-08-10 14:42:09 UTC (rev 9348) +++ trunk/teraterm/common/i18n.h 2021-08-10 14:42:18 UTC (rev 9349) @@ -60,9 +60,27 @@ const DlgTextInfo *infos, size_t infoCount, const char *UILanguageFile); // i18n_static.c +size_t GetI18nStrWW(const char *section, const char *key, const wchar_t *def, const wchar_t *iniFile, wchar_t **buf); +size_t GetI18nStrWA(const char *section, const char *key, const wchar_t *def, const char *iniFile, wchar_t **buf); +size_t GetI18nStrU8W(const char *section, const char *key, const char *def, const wchar_t *iniFile, char **buf); +size_t GetI18nStrU8A(const char *section, const char *key, const char *def, const char *iniFile, char **buf); + void GetI18nStrU8(const char *section, const char *key, char *buf, int buf_len, const char *def, const char *iniFile); + +int SetI18nDlgStrsW(HWND hDlgWnd, const char *section, const DlgTextInfo *infos, size_t infoCount, + const wchar_t *UILanguageFile); +int SetI18nDlgStrsA(HWND hDlgWnd, const char *section, const DlgTextInfo *infos, size_t infoCount, + const char *UILanguageFile); +void SetI18nMenuStrsW(HMENU hMenu, const char *section, const DlgTextInfo *infos, size_t infoCount, + const wchar_t *UILanguageFile); +void SetI18nMenuStrsA(HMENU hMenu, const char *section, const DlgTextInfo *infos, size_t infoCount, + const char *UILanguageFile); +void SetI18nListW(const char *section, HWND hDlg, int nIDDlgItem, const I18nTextInfo *infos, size_t infoCount, + const wchar_t *UILanguageFile, int nsel); void SetI18nList(const char *section, HWND hDlg, int nIDDlgItem, const I18nTextInfo *infos, size_t infoCount, const char *UILanguageFile, int nsel); +int GetI18nLogfontAW(const char *section, const char *key, PLOGFONTA logfont, int ppi, const wchar_t *iniFile); +int GetI18nLogfontAA(const char *section, const char *key, PLOGFONTA logfont, int ppi, const char *iniFile); #ifdef __cplusplus } Modified: trunk/teraterm/common/i18n_static.c =================================================================== --- trunk/teraterm/common/i18n_static.c 2021-08-10 14:42:09 UTC (rev 9348) +++ trunk/teraterm/common/i18n_static.c 2021-08-10 14:42:18 UTC (rev 9349) @@ -26,40 +26,76 @@ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ +#include <assert.h> + #include "i18n.h" #include "codeconv.h" #include "compat_win.h" +#include "win32helper.h" +#include "ttlib.h" -#include <assert.h> - -// TODO: \x83o\x83b\x83t\x83@\x95s\x91\xAB\x8E\x9E\x82̓\xAE\x8D\xEC -void GetI18nStrU8(const char *section, const char *key, char *buf, int buf_len, const char *def, const char *iniFile) +size_t GetI18nStrWW(const char *section, const char *key, const wchar_t *def, const wchar_t *iniFile, wchar_t **str) { - size_t r; - if (pGetPrivateProfileStringW != NULL) { - // unicode base - wchar_t tmp[MAX_UIMSG]; - wchar_t defW[MAX_UIMSG]; - r = UTF8ToWideChar(def, -1, defW, _countof(defW)); - assert(r != 0); - GetI18nStrW(section, key, tmp, _countof(tmp), defW, iniFile); - r = buf_len; - WideCharToUTF8(tmp, NULL, buf, &r); - assert(r != 0); + wchar_t sectionW[64]; + wchar_t keyW[128]; + DWORD error; + size_t size; + MultiByteToWideChar(CP_ACP, 0, section, -1, sectionW, _countof(sectionW)); + MultiByteToWideChar(CP_ACP, 0, key, -1, keyW, _countof(keyW)); + error = hGetPrivateProfileStringW(sectionW, keyW, def, iniFile, str); + if (error != NO_ERROR) { + *str = NULL; + return 0; } - else { - // ANSI -> Wide -> utf8 - char strA[MAX_UIMSG]; - wchar_t strW[MAX_UIMSG]; - GetI18nStr(section, key, strA, _countof(strA), def, iniFile); - r = MultiByteToWideChar(CP_ACP, 0, strA, -1, strW, _countof(strW)); - assert(r != 0); - r = buf_len; - WideCharToUTF8(strW, NULL, buf, &r); - assert(r != 0); + if (*str == NULL) { + return 0; } + size = RestoreNewLineW(*str); + return size; } +size_t GetI18nStrWA(const char *section, const char *key, const wchar_t *def, const char *iniFile, wchar_t **buf) +{ + wchar_t *iniFileW = ToWcharA(iniFile); + size_t size = GetI18nStrWW(section, key, def, iniFileW, buf); + free(iniFileW); + return size; +} + +wchar_t *TTGetLangStrW(const char *section, const char *key, const wchar_t *def, const char *UILanguageFile) +{ + wchar_t *str; + GetI18nStrWA(section, key, def, UILanguageFile, &str); + return str; +} + +size_t GetI18nStrU8W(const char *section, const char *key, const char *def, const wchar_t *iniFile, char **buf) +{ + wchar_t *defW = ToWcharU8(def); + wchar_t *strW; + size_t size = GetI18nStrWW(section, key, defW, iniFile, &strW); + *buf = ToU8W(strW); + free(defW); + free(strW); + return size; +} + +size_t GetI18nStrU8A(const char *section, const char *key, const char *def, const char *iniFile, char **buf) +{ + wchar_t *iniFileW = ToWcharA(iniFile); + size_t size = GetI18nStrU8W(section, key, def, iniFileW, buf); + free(iniFileW); + return size; +} + +void GetI18nStrU8(const char *section, const char *key, char *buf, int buf_len, const char *def, const char *iniFile) +{ + char *str; + GetI18nStrU8A(section, key, def, iniFile, &str); + strncpy_s(buf, buf_len, str, _TRUNCATE); + free(str); +} + /** * \x83\x8A\x83X\x83g\x82\xF0\x90ݒ肷\x82\xE9 * SetDropDownList() \x82̑\xBC\x8C\xBE\x8C\xEA\x94\xC5 @@ -74,8 +110,8 @@ * -1 \x96\xA2\x91I\x91\xF0 * 0\x81` \x91I\x91\xF0\x8D\x80\x96\xDA */ -void SetI18nList(const char *section, HWND hDlg, int nIDDlgItem, const I18nTextInfo *infos, size_t infoCount, - const char *UILanguageFile, int nsel) +void SetI18nListW(const char *section, HWND hDlg, int nIDDlgItem, const I18nTextInfo *infos, size_t infoCount, + const wchar_t *UILanguageFile, int nsel) { UINT ADDSTRING; UINT SETCURSEL; @@ -106,9 +142,10 @@ for (i = 0; i < infoCount; i++) { if (infos->key != NULL) { - wchar_t uimsg[MAX_UIMSG]; - GetI18nStrW(section, infos->key, uimsg, _countof(uimsg), infos->default_text, UILanguageFile); + wchar_t *uimsg; + GetI18nStrWW(section, infos->key, infos->default_text, UILanguageFile, &uimsg); SendDlgItemMessageW(hDlg, nIDDlgItem, ADDSTRING, 0, (LPARAM)uimsg); + free(uimsg); } else { SendDlgItemMessageW(hDlg, nIDDlgItem, ADDSTRING, 0, (LPARAM)infos->default_text); @@ -118,4 +155,137 @@ SendDlgItemMessageA(hDlg, nIDDlgItem, SETCURSEL, nsel, 0); } +void SetI18nList(const char *section, HWND hDlg, int nIDDlgItem, const I18nTextInfo *infos, size_t infoCount, + const char *UILanguageFile, int nsel) +{ + wchar_t *UILanguageFileW = ToWcharA(UILanguageFile); + SetI18nListW(section, hDlg, nIDDlgItem, infos, infoCount, UILanguageFileW, nsel); + free(UILanguageFileW); +} + +/** + * \x8C\xBE\x8C\xEA\x83t\x83@\x83C\x83\x8B\x82\xA9\x82\xE7Dialog\x82̃R\x83\x93\x83|\x81[\x83l\x83\x93\x83g\x82̕\xB6\x8E\x9A\x97\xF1\x82\xF0\x95ϊ\xB7\x82\xB7\x82\xE9 + * + * @return \x8C\xBE\x8C\xEA\x83t\x83@\x83C\x83\x8B\x82ŕϊ\xB7\x82ł\xAB\x82\xBD\x89\xF1\x90\x94(infoCount\x88ȉ\xBA\x82̐\x94\x82ɂȂ\xE9) + */ +int SetI18nDlgStrsW(HWND hDlgWnd, const char *section, const DlgTextInfo *infos, size_t infoCount, + const wchar_t *UILanguageFile) +{ + size_t i; + int translatedCount = 0; + + assert(hDlgWnd != NULL); + assert(infoCount > 0); + for (i = 0 ; i < infoCount; i++) { + wchar_t *uimsg; + GetI18nStrWW(section, infos[i].key, NULL, UILanguageFile, &uimsg); + if (uimsg != NULL) { + BOOL r = FALSE; + const int nIDDlgItem = infos[i].nIDDlgItem; + if (nIDDlgItem == 0) { + r = SetWindowTextW(hDlgWnd, uimsg); + assert(r != 0); + } else { + r = SetDlgItemTextW(hDlgWnd, nIDDlgItem, uimsg); + assert(r != 0); + } + free(uimsg); + if (r) + translatedCount++; + } + } + + return translatedCount; +} + +int SetI18nDlgStrsA(HWND hDlgWnd, const char *section, const DlgTextInfo *infos, size_t infoCount, + const char *UILanguageFile) +{ + wchar_t *UILanguageFileW = ToWcharA(UILanguageFile); + int r = SetI18nDlgStrsW(hDlgWnd, section, infos, infoCount, UILanguageFileW); + free(UILanguageFileW); + return r; +} + +void SetI18nMenuStrsW(HMENU hMenu, const char *section, const DlgTextInfo *infos, size_t infoCount, + const wchar_t *UILanguageFile) +{ + const int id_position_threshold = 1000; + size_t i; + for (i = 0; i < infoCount; i++) { + const int nIDDlgItem = infos[i].nIDDlgItem; + const char *key = infos[i].key; + // UNICODE + wchar_t *uimsg; + GetI18nStrWW(section, key, NULL, UILanguageFile, &uimsg); + if (uimsg != NULL) { + UINT uFlags = (nIDDlgItem < id_position_threshold) ? MF_BYPOSITION : MF_BYCOMMAND; + ModifyMenuW(hMenu, nIDDlgItem, uFlags, nIDDlgItem, uimsg); + free(uimsg); + } + else { + if (nIDDlgItem < id_position_threshold) { + // \x88\xEA\x93xModifyMenu()\x82\xB5\x82Ă\xA8\x82\xA9\x82Ȃ\xA2\x82ƃ\x81\x83j\x83\x85\x81[\x82̈ʒu\x82\xAA\x82\xB8\x82\xEA\x82\xE9 + wchar_t s[MAX_UIMSG]; + GetMenuStringW(hMenu, nIDDlgItem, s, _countof(s), MF_BYPOSITION); + ModifyMenuW(hMenu, nIDDlgItem, MF_BYPOSITION, nIDDlgItem, s); + } + } + } +} + +void SetI18nMenuStrsA(HMENU hMenu, const char *section, const DlgTextInfo *infos, size_t infoCount, + const char *UILanguageFile) +{ + wchar_t *UILanguageFileW = ToWcharA(UILanguageFile); + SetI18nMenuStrsW(hMenu, section, infos, infoCount, UILanguageFileW); + free(UILanguageFileW); +} + +int GetI18nLogfontAW(const char *section, const char *key, PLOGFONTA logfont, int ppi, const wchar_t *iniFile) +{ + wchar_t sectionW[64]; + wchar_t keyW[128]; + wchar_t tmpW[MAX_UIMSG]; + char *tmp; + char font[LF_FACESIZE]; + int height, charset; + assert(iniFile[0] != '\0'); + memset(logfont, 0, sizeof(*logfont)); + + MultiByteToWideChar(CP_ACP, 0, section, -1, sectionW, _countof(sectionW)); + MultiByteToWideChar(CP_ACP, 0, key, -1, keyW, _countof(keyW)); + GetPrivateProfileStringW(sectionW, keyW, L"", tmpW, MAX_UIMSG, iniFile); + if (tmpW[0] == L'\0') { + return FALSE; + } + tmp = ToCharW(tmpW); + + GetNthString(tmp, 1, LF_FACESIZE-1, font); + GetNthNum(tmp, 2, &height); + GetNthNum(tmp, 3, &charset); + + if (font[0] != '\0') { + strncpy_s(logfont->lfFaceName, sizeof(logfont->lfFaceName), font, _TRUNCATE); + } + logfont->lfCharSet = (BYTE)charset; + if (ppi != 0) { + logfont->lfHeight = MulDiv(height, -ppi, 72); + } else { + logfont->lfHeight = height; + } + logfont->lfWidth = 0; + + free(tmp); + return TRUE; +} + +int GetI18nLogfontAA(const char *section, const char *key, PLOGFONTA logfont, int ppi, const char *iniFile) +{ + wchar_t *iniFileW = ToWcharA(iniFile); + int r = GetI18nLogfontAW(section, key, logfont, ppi, iniFileW); + free(iniFileW); + return r; +} + /* vim: set ts=4 sw=4 ff=dos : */ Modified: trunk/teraterm/common/ttlib.c =================================================================== --- trunk/teraterm/common/ttlib.c 2021-08-10 14:42:09 UTC (rev 9348) +++ trunk/teraterm/common/ttlib.c 2021-08-10 14:42:18 UTC (rev 9349) @@ -821,101 +821,6 @@ memcpy(Text, buf, size); } -/** - * \x83G\x83X\x83P\x81[\x83v\x95\xB6\x8E\x9A\x82\xF0\x8F\x88\x97\x9D\x82\xB7\x82\xE9 - * \\,\n,\t,\0 \x82\xF0\x92u\x82\xAB\x8A\xB7\x82\xA6\x82\xE9 - * @return \x95\xB6\x8E\x9A\x90\x94\x81iL'\0'\x82\xF0\x8A܂\xDE) - */ -size_t RestoreNewLineW(wchar_t *Text) -{ - size_t i; - int j=0; - size_t size= wcslen(Text); - wchar_t *buf = (wchar_t *)_alloca((size+1) * sizeof(wchar_t)); - - memset(buf, 0, (size+1) * sizeof(wchar_t)); - for (i=0; i<size; i++) { - if (Text[i] == L'\\' && i<size ) { - switch (Text[i+1]) { - case L'\\': - buf[j] = L'\\'; - i++; - break; - case L'n': - buf[j] = L'\n'; - i++; - break; - case L't': - buf[j] = L'\t'; - i++; - break; - case L'0': - buf[j] = L'\0'; - i++; - break; - default: - buf[j] = L'\\'; - } - j++; - } - else { - buf[j] = Text[i]; - j++; - } - } - /* use memcpy to copy with '\0' */ - j++; // \x95\xB6\x8E\x9A\x97\xF1\x92\xB7 - memcpy(Text, buf, j * sizeof(wchar_t)); - return j; -} - -BOOL GetNthString(PCHAR Source, int Nth, int Size, PCHAR Dest) -{ - int i, j, k; - - i = 1; - j = 0; - k = 0; - - while (i<Nth && Source[j] != 0) { - if (Source[j++] == ',') { - i++; - } - } - - if (i == Nth) { - while (Source[j] != 0 && Source[j] != ',' && k<Size-1) { - Dest[k++] = Source[j++]; - } - } - - Dest[k] = 0; - return (i>=Nth); -} - -void GetNthNum(PCHAR Source, int Nth, int far *Num) -{ - char T[15]; - - GetNthString(Source,Nth,sizeof(T),T); - if (sscanf_s(T, "%d", Num) != 1) { - *Num = 0; - } -} - -int GetNthNum2(PCHAR Source, int Nth, int defval) -{ - char T[15]; - int v; - - GetNthString(Source, Nth, sizeof(T), T); - if (sscanf_s(T, "%d", &v) != 1) { - v = defval; - } - - return v; -} - void GetDownloadFolder(char *dest, int destlen) { HMODULE hDll; Modified: trunk/teraterm/common/ttlib.h =================================================================== --- trunk/teraterm/common/ttlib.h 2021-08-10 14:42:09 UTC (rev 9348) +++ trunk/teraterm/common/ttlib.h 2021-08-10 14:42:18 UTC (rev 9349) @@ -78,7 +78,7 @@ void RestoreNewLine(PCHAR Text); size_t RestoreNewLineW(wchar_t *Text); BOOL GetNthString(PCHAR Source, int Nth, int Size, PCHAR Dest); -void GetNthNum(PCHAR Source, int Nth, int far *Num); +void GetNthNum(PCHAR Source, int Nth, int *Num); int GetNthNum2(PCHAR Source, int Nth, int defval); void GetDownloadFolder(char *dest, int destlen); wchar_t *GetHomeDirW(HINSTANCE hInst); @@ -132,7 +132,9 @@ #define CheckFlag(var, flag) (((var) & (flag)) != 0) +int SetDlgTextsW(HWND hDlgWnd, const DlgTextInfo *infos, int infoCount, const wchar_t *UILanguageFileW); int SetDlgTexts(HWND hDlgWnd, const DlgTextInfo *infos, int infoCount, const char *UILanguageFile); +void SetDlgMenuTextsW(HMENU hMenu, const DlgTextInfo *infos, int infoCount, const wchar_t *UILanguageFile); void SetDlgMenuTexts(HMENU hMenu, const DlgTextInfo *infos, int infoCount, const char *UILanguageFile); int GetMonitorDpiFromWindow(HWND hWnd); Modified: trunk/teraterm/common/ttlib_static.c =================================================================== --- trunk/teraterm/common/ttlib_static.c 2021-08-10 14:42:09 UTC (rev 9348) +++ trunk/teraterm/common/ttlib_static.c 2021-08-10 14:42:18 UTC (rev 9349) @@ -110,11 +110,21 @@ return TRUE; } +int SetDlgTextsW(HWND hDlgWnd, const DlgTextInfo *infos, int infoCount, const wchar_t *UILanguageFile) +{ + return SetI18nDlgStrsW(hDlgWnd, "Tera Term", infos, infoCount, UILanguageFile); +} + int SetDlgTexts(HWND hDlgWnd, const DlgTextInfo *infos, int infoCount, const char *UILanguageFile) { - return SetI18nDlgStrs("Tera Term", hDlgWnd, infos, infoCount, UILanguageFile); + return SetI18nDlgStrsA(hDlgWnd, "Tera Term", infos, infoCount, UILanguageFile); } +void SetDlgMenuTextsW(HMENU hMenu, const DlgTextInfo *infos, int infoCount, const wchar_t *UILanguageFile) +{ + SetI18nMenuStrsW(hMenu, "Tera Term", infos, infoCount, UILanguageFile); +} + void SetDlgMenuTexts(HMENU hMenu, const DlgTextInfo *infos, int infoCount, const char *UILanguageFile) { SetI18nMenuStrs("Tera Term", hMenu, infos, infoCount, UILanguageFile); Modified: trunk/teraterm/common/ttlib_static_cpp.cpp =================================================================== --- trunk/teraterm/common/ttlib_static_cpp.cpp 2021-08-10 14:42:09 UTC (rev 9348) +++ trunk/teraterm/common/ttlib_static_cpp.cpp 2021-08-10 14:42:18 UTC (rev 9349) @@ -37,6 +37,7 @@ #include <assert.h> #include <wchar.h> #include <shlobj.h> +#include <malloc.h> #include "i18n.h" #include "asprintf.h" @@ -46,14 +47,54 @@ #include "ttlib.h" /** - * GetI18nStrW() \x82̓\xAE\x93I\x83o\x83b\x83t\x83@\x94\xC5 + * MessageBox\x82\xF0\x95\\x8E\xA6\x82\xB7\x82\xE9 + * + * @param[in] hWnd \x90e window + * @param[in] info \x83^\x83C\x83g\x83\x8B\x81A\x83\x81\x83b\x83Z\x81[\x83W + * @param[in] UILanguageFile lng\x83t\x83@\x83C\x83\x8B + * @param[in] ... \x83t\x83H\x81[\x83}\x83b\x83g\x88\xF8\x90\x94 + * + * info.message \x82\xF0\x8F\x91\x8E\xAE\x89\xBB\x95\xB6\x8E\x9A\x97\xF1\x82Ƃ\xB5\x82āA + * UILanguageFile\x82\xE6\x82\xE8\x8C\xE3\x82\xEB\x82̈\xF8\x90\x94\x82\xF0\x8Fo\x97͂\xB7\x82\xE9 + * + * info.message_key, info.message_default \x97\xBC\x95\xFB\x82Ƃ\xE0NULL\x82̏ꍇ + * \x89ψ\xF8\x90\x94\x82\xCC1\x82ڂ\xF0\x8F\x91\x8E\xAE\x89\xBB\x95\xB6\x8E\x9A\x97\xF1\x82Ƃ\xB5\x82Ďg\x97p\x82\xB7\x82\xE9 */ -wchar_t *TTGetLangStrW(const char *section, const char *key, const wchar_t *def, const char *UILanguageFile) +int TTMessageBoxW(HWND hWnd, const TTMessageBoxInfoW *info, const wchar_t *UILanguageFile, ...) { - wchar_t *buf = (wchar_t *)malloc(MAX_UIMSG * sizeof(wchar_t)); - size_t size = GetI18nStrW(section, key, buf, MAX_UIMSG, def, UILanguageFile); - buf = (wchar_t *)realloc(buf, size * sizeof(wchar_t)); - return buf; + const char *section = info->section; + const UINT uType = info->uType; + wchar_t *title; + if (info->title_key == NULL) { + title = _wcsdup(info->title_default); + } + else { + GetI18nStrWW(section, info->title_key, info->title_default, UILanguageFile, &title); + } + + wchar_t *message = NULL; + if (info->message_key == NULL && info->message_default == NULL) { + wchar_t *format; + va_list ap; + va_start(ap, UILanguageFile); + format = va_arg(ap, wchar_t *); + vaswprintf(&message, format, ap); + } + else { + wchar_t *format; + GetI18nStrWW(section, info->message_key, info->message_default, UILanguageFile, &format); + va_list ap; + va_start(ap, UILanguageFile); + vaswprintf(&message, format, ap); + free(format); + } + + int r = MessageBoxW(hWnd, message, title, uType); + + free(title); + free(message); + + return r; } /** @@ -927,3 +968,98 @@ wchar_t *buf = GetDefaultFNameW(home, ini); return buf; } + +/** + * \x83G\x83X\x83P\x81[\x83v\x95\xB6\x8E\x9A\x82\xF0\x8F\x88\x97\x9D\x82\xB7\x82\xE9 + * \\,\n,\t,\0 \x82\xF0\x92u\x82\xAB\x8A\xB7\x82\xA6\x82\xE9 + * @return \x95\xB6\x8E\x9A\x90\x94\x81iL'\0'\x82\xF0\x8A܂\xDE) + */ +size_t RestoreNewLineW(wchar_t *Text) +{ + size_t i; + int j=0; + size_t size= wcslen(Text); + wchar_t *buf = (wchar_t *)_alloca((size+1) * sizeof(wchar_t)); + + memset(buf, 0, (size+1) * sizeof(wchar_t)); + for (i=0; i<size; i++) { + if (Text[i] == L'\\' && i<size ) { + switch (Text[i+1]) { + case L'\\': + buf[j] = L'\\'; + i++; + break; + case L'n': + buf[j] = L'\n'; + i++; + break; + case L't': + buf[j] = L'\t'; + i++; + break; + case L'0': + buf[j] = L'\0'; + i++; + break; + default: + buf[j] = L'\\'; + } + j++; + } + else { + buf[j] = Text[i]; + j++; + } + } + /* use memcpy to copy with '\0' */ + j++; // \x95\xB6\x8E\x9A\x97\xF1\x92\xB7 + memcpy(Text, buf, j * sizeof(wchar_t)); + return j; +} + +BOOL GetNthString(PCHAR Source, int Nth, int Size, PCHAR Dest) +{ + int i, j, k; + + i = 1; + j = 0; + k = 0; + + while (i<Nth && Source[j] != 0) { + if (Source[j++] == ',') { + i++; + } + } + + if (i == Nth) { + while (Source[j] != 0 && Source[j] != ',' && k<Size-1) { + Dest[k++] = Source[j++]; + } + } + + Dest[k] = 0; + return (i>=Nth); +} + +void GetNthNum(PCHAR Source, int Nth, int far *Num) +{ + char T[15]; + + GetNthString(Source,Nth,sizeof(T),T); + if (sscanf_s(T, "%d", Num) != 1) { + *Num = 0; + } +} + +int GetNthNum2(PCHAR Source, int Nth, int defval) +{ + char T[15]; + int v; + + GetNthString(Source, Nth, sizeof(T), T); + if (sscanf_s(T, "%d", &v) != 1) { + v = defval; + } + + return v; +}