Revision: 7380 http://sourceforge.jp/projects/ttssh2/scm/svn/commits/7380 Author: zmatsuo Date: 2019-01-03 01:58:30 +0900 (Thu, 03 Jan 2019) Log Message: ----------- ダイアログフォント決定方法見直し#2 Ticket Links: ------------ http://sourceforge.jp/projects/ttssh2/tracker/detail/2 Modified Paths: -------------- branches/cmake/TTProxy/ProxyWSockHook.h branches/cmake/TTXSamples/TTXRecurringCommand/TTXRecurringCommand.c branches/cmake/teraterm/common/dlglib.c branches/cmake/teraterm/common/dlglib_tmpl.cpp branches/cmake/teraterm/common/i18n.c branches/cmake/teraterm/ttpdlg/ttdlg.c branches/cmake/ttssh2/ttxssh/ttxssh.c -------------- next part -------------- Modified: branches/cmake/TTProxy/ProxyWSockHook.h =================================================================== --- branches/cmake/TTProxy/ProxyWSockHook.h 2019-01-02 16:58:18 UTC (rev 7379) +++ branches/cmake/TTProxy/ProxyWSockHook.h 2019-01-02 16:58:30 UTC (rev 7380) @@ -32,6 +32,11 @@ GetI18nStrU8("TTProxy", key, buf, buf_len, def, UILanguageFile); } +void UTIL_set_dialog_font() +{ + SetDialogFont("TTProxy", UILanguageFile); +} + #if 0 int UTIL_get_lang_font(const char *key, HWND dlg, PLOGFONTA logfont, HFONT *font) { @@ -968,6 +973,7 @@ String ErrorMessage; int open(HWND owner) { + UTIL_set_dialog_font(); return Dialog::open(instance().resource_module, IDD_OPTION_SETTING, owner); } }; @@ -1250,6 +1256,7 @@ } int open(HWND owner) { + UTIL_set_dialog_font(); return Dialog::open(instance().resource_module, IDD_SETTING, owner); } }; @@ -1316,6 +1323,7 @@ } public : int open(HWND owner) { + UTIL_set_dialog_font(); return Dialog::open(instance().resource_module, IDD_ABOUTDIALOG, owner); } }; @@ -2425,7 +2433,8 @@ static bool setupDialog(HWND owner) { SettingDialog dlg; dlg.proxy = instance().defaultProxy; - if (dlg.open(owner) == IDOK) { + UTIL_set_dialog_font(); + if (dlg.open(owner) == IDOK) { instance().defaultProxy = dlg.proxy; return true; } @@ -2433,6 +2442,7 @@ } static bool aboutDialog(HWND owner) { AboutDialog dlg; + UTIL_set_dialog_font(); if (dlg.open(owner) == IDOK) { return true; } Modified: branches/cmake/TTXSamples/TTXRecurringCommand/TTXRecurringCommand.c =================================================================== --- branches/cmake/TTXSamples/TTXRecurringCommand/TTXRecurringCommand.c 2019-01-02 16:58:18 UTC (rev 7379) +++ branches/cmake/TTXSamples/TTXRecurringCommand/TTXRecurringCommand.c 2019-01-02 16:58:30 UTC (rev 7380) @@ -605,6 +605,7 @@ static int PASCAL TTXProcessCommand(HWND hWin, WORD cmd) { switch (cmd) { case ID_MENU_SETUP: + SetDialogFont("TTXRecurringCommand", pvar->ts->UILanguageFile); switch (DialogBoxParam(hInst, MAKEINTRESOURCE(IDD_SETUP_RECURRINGCOMMAND), hWin, RecurringCommandSetting, (LPARAM)NULL)) { case IDOK: Modified: branches/cmake/teraterm/common/dlglib.c =================================================================== --- branches/cmake/teraterm/common/dlglib.c 2019-01-02 16:58:18 UTC (rev 7379) +++ branches/cmake/teraterm/common/dlglib.c 2019-01-02 16:58:30 UTC (rev 7380) @@ -424,6 +424,7 @@ /** * 使用するCharSetを取得する */ +#if 0 DWORD GetCharSet() { DWORD codepage; @@ -450,10 +451,12 @@ return charset_info.ciCharset; } +#endif /** * 使用するダイアログフォントの候補 */ +#if 0 typedef struct { const TCHAR *face; LONG height; @@ -508,6 +511,7 @@ } } } +#endif /** * 使用するダイアログフォントを決定する @@ -514,8 +518,6 @@ */ void SetDialogFont(const char *section, const char *UILanguageFile) { - BYTE char_set = SYMBOL_CHARSET; // symbolを使うことはないだろう - // 明示的に指定されている場合はそれに従う { static const char *dlg_font_keys[] = { @@ -528,7 +530,7 @@ int i; if (section != NULL) { for (i = 0; i < _countof(dlg_font_keys); i++) { - result = GetI18nLogfont(section, "DLG_FONT", &logfont, 72, UILanguageFile); + result = GetI18nLogfont(section, dlg_font_keys[i], &logfont, 72, UILanguageFile); if (result == TRUE) { break; } @@ -536,7 +538,7 @@ } if (result == FALSE) { for (i = 0; i < _countof(dlg_font_keys); i++) { - result = GetI18nLogfont("Tera Term", "DLG_FONT", &logfont, 72, UILanguageFile); + result = GetI18nLogfont("Tera Term", dlg_font_keys[i], &logfont, 72, UILanguageFile); if (result == TRUE) { break; } @@ -556,31 +558,12 @@ return; } #endif - - // 使用したかったフォントのCharSetを取得 - char_set = logfont.lfCharSet; - // TODO フォントが見つからなかったときの処理 - // messagebox()出して下へ続くが妥当か? + // フォントが見つからなかったとき、 + // 文字化けで正しく表示されない事態となる + // messagebox()のフォントをとりあえず選択しておく } } - // 実際に存在するフォントを使用する - { - if (char_set == SYMBOL_CHARSET) { - // 未設定の場合 - char_set = GetCharSet(); - } - const DialogFontLists *list = GetDialogFontCandidate(char_set); - while(list->face != NULL) { - if (IsExistFont(list->face, char_set, TRUE)) { - // 候補内に存在するフォントが存在した - TTSetDlgFont(list->face, list->height, char_set); - return; - } - list++; - } - } - // messageboxのフォントを選択 { NONCLIENTMETRICS nci; Modified: branches/cmake/teraterm/common/dlglib_tmpl.cpp =================================================================== --- branches/cmake/teraterm/common/dlglib_tmpl.cpp 2019-01-02 16:58:18 UTC (rev 7379) +++ branches/cmake/teraterm/common/dlglib_tmpl.cpp 2019-01-02 16:58:30 UTC (rev 7380) @@ -392,7 +392,7 @@ new_size = prev_size; } else { // copy with replacing font - size_t size_namediff = + int size_namediff = wcslen(FontFaceName) - wcslen(logfont.lfFaceName); size_namediff *= sizeof(WCHAR); size_namediff += 3; // \x83e\x83L\x83X\x83g\x81A\x83t\x83H\x83\x93\x83g\x96\xBC\x92\xB7\x82\xC5align\x82\xAA\x95ω\xBB\x82\xB7\x82\xE9 Modified: branches/cmake/teraterm/common/i18n.c =================================================================== --- branches/cmake/teraterm/common/i18n.c 2019-01-02 16:58:18 UTC (rev 7379) +++ branches/cmake/teraterm/common/i18n.c 2019-01-02 16:58:30 UTC (rev 7380) @@ -82,12 +82,32 @@ #endif } +static void GetMessageBoxFontName(char *FontName) +{ + NONCLIENTMETRICSA nci; +#if(WINVER >= 0x0600) + int st_size = offsetof(NONCLIENTMETRICSA, iPaddedBorderWidth); +#else + int st_size = sizeof(NONCLIENTMETRICSA); +#endif + BOOL r; + const LOGFONTA *logfont; + memset(&nci, 0, sizeof(nci)); + nci.cbSize = st_size; + r = SystemParametersInfoA(SPI_GETNONCLIENTMETRICS, st_size, &nci, 0); + assert(r == TRUE); + logfont = &nci.lfStatusFont; + + strcpy(FontName, logfont->lfFaceName); +} + DllExport int GetI18nLogfont(const char *section, const char *key, PLOGFONTA logfont, int ppi, const char *iniFile) { static char tmp[MAX_UIMSG]; static char font[LF_FACESIZE]; int hight, charset; + assert(iniFile[0] != '\0'); GetPrivateProfileStringA(section, key, "", tmp, MAX_UIMSG, iniFile); if (tmp[0] == '\0') { return FALSE; @@ -97,7 +117,12 @@ GetNthNum(tmp, 2, &hight); GetNthNum(tmp, 3, &charset); - strncpy_s(logfont->lfFaceName, sizeof(logfont->lfFaceName), font, _TRUNCATE); + memset(logfont, 0, sizeof(*logfont)); + if (font[0] == '\0') { + GetMessageBoxFontName(logfont->lfFaceName); + } else { + strncpy_s(logfont->lfFaceName, sizeof(logfont->lfFaceName), font, _TRUNCATE); + } logfont->lfCharSet = (BYTE)charset; logfont->lfHeight = MulDiv(hight, -ppi, 72); logfont->lfWidth = 0; Modified: branches/cmake/teraterm/ttpdlg/ttdlg.c =================================================================== --- branches/cmake/teraterm/ttpdlg/ttdlg.c 2019-01-02 16:58:18 UTC (rev 7379) +++ branches/cmake/teraterm/ttpdlg/ttdlg.c 2019-01-02 16:58:30 UTC (rev 7380) @@ -2777,6 +2777,7 @@ i = IDD_TERMDLG; } + SetDialogFont(NULL, UILanguageFile); return (BOOL)DialogBoxParam(hInst, MAKEINTRESOURCE(i), @@ -2785,6 +2786,7 @@ DllExport BOOL WINAPI _SetupWin(HWND WndParent, PTTSet ts) { + SetDialogFont(NULL, UILanguageFile); return (BOOL)DialogBoxParam(hInst, MAKEINTRESOURCE(IDD_WINDLG), @@ -2793,6 +2795,7 @@ DllExport BOOL WINAPI _SetupKeyboard(HWND WndParent, PTTSet ts) { + SetDialogFont(NULL, UILanguageFile); return (BOOL)DialogBoxParam(hInst, MAKEINTRESOURCE(IDD_KEYBDLG), @@ -2801,6 +2804,7 @@ DllExport BOOL WINAPI _SetupSerialPort(HWND WndParent, PTTSet ts) { + SetDialogFont(NULL, UILanguageFile); return (BOOL)DialogBoxParam(hInst, MAKEINTRESOURCE(IDD_SERIALDLG), @@ -2809,6 +2813,7 @@ DllExport BOOL WINAPI _SetupTCPIP(HWND WndParent, PTTSet ts) { + SetDialogFont(NULL, UILanguageFile); return (BOOL)DialogBoxParam(hInst, MAKEINTRESOURCE(IDD_TCPIPDLG), @@ -2817,6 +2822,7 @@ DllExport BOOL WINAPI _GetHostName(HWND WndParent, PGetHNRec GetHNRec) { + SetDialogFont(NULL, UILanguageFile); return (BOOL)DialogBoxParam(hInst, MAKEINTRESOURCE(IDD_HOSTDLG), @@ -2825,6 +2831,7 @@ DllExport BOOL WINAPI _ChangeDirectory(HWND WndParent, PCHAR CurDir) { + SetDialogFont(NULL, UILanguageFile); return (BOOL)DialogBoxParam(hInst, MAKEINTRESOURCE(IDD_DIRDLG), @@ -2833,6 +2840,7 @@ DllExport BOOL WINAPI _AboutDialog(HWND WndParent) { + SetDialogFont(NULL, UILanguageFile); return (BOOL)DialogBox(hInst, MAKEINTRESOURCE(IDD_ABOUTDLG), @@ -2909,6 +2917,7 @@ DllExport BOOL WINAPI _SetupGeneral(HWND WndParent, PTTSet ts) { + SetDialogFont(NULL, UILanguageFile); return (BOOL)DialogBoxParam(hInst, MAKEINTRESOURCE(IDD_GENDLG), @@ -2917,6 +2926,7 @@ DllExport BOOL WINAPI _WindowWindow(HWND WndParent, PBOOL Close) { + SetDialogFont(NULL, UILanguageFile); *Close = FALSE; return (BOOL)DialogBoxParam(hInst, Modified: branches/cmake/ttssh2/ttxssh/ttxssh.c =================================================================== --- branches/cmake/ttssh2/ttxssh/ttxssh.c 2019-01-02 16:58:18 UTC (rev 7379) +++ branches/cmake/ttssh2/ttxssh/ttxssh.c 2019-01-02 16:58:30 UTC (rev 7380) @@ -217,7 +217,6 @@ pvar->err_msg = NULL; init_TTSSH(pvar); - SetDialogFont("TTSSH", ts->UILanguageFile); } static void normalize_generic_order(char *buf, char default_strings[], int default_strings_len) @@ -1714,8 +1713,14 @@ return FALSE; } +static void UTIL_SetDialogFont() +{ + SetDialogFont("TTSSH", pvar->ts->UILanguageFile); +} + static BOOL PASCAL TTXGetHostName(HWND parent, PGetHNRec rec) { + UTIL_SetDialogFont(); return (BOOL) DialogBoxParam(hInst, MAKEINTRESOURCE(IDD_HOSTDLG), parent, TTXHostDlg, (LPARAM)rec); } @@ -5321,6 +5326,7 @@ return 0; // SSH2\x82ŏ\x88\x97\x9D\x82\xB3\x82\xEA\x82Ȃ\xA9\x82\xC1\x82\xBD\x8Fꍇ\x82́A\x96{\x97\x88\x82̓\xAE\x8D\xEC\x82\xF0\x8Ds\x82\xA4\x82ׂ\xAD\x81A\x83[\x83\x8D\x82\xF0\x95Ԃ\xB7\x81B case ID_SSHSCPMENU: + UTIL_SetDialogFont(); if (DialogBoxParam(hInst, MAKEINTRESOURCE(IDD_SSHSCP), hWin, TTXScpDialog, (LPARAM) pvar) == -1) { UTIL_get_lang_msgT("MSG_CREATEWINDOW_SCP_ERROR", uimsg1, _countof(uimsg1), @@ -5332,6 +5338,7 @@ return 1; case ID_SSHKEYGENMENU: + UTIL_SetDialogFont(); if (DialogBoxParam(hInst, MAKEINTRESOURCE(IDD_SSHKEYGEN), hWin, TTXKeyGenerator, (LPARAM) pvar) == -1) { UTIL_get_lang_msgT("MSG_CREATEWINDOW_KEYGEN_ERROR", uimsg1, _countof(uimsg1), @@ -5343,6 +5350,7 @@ return 1; case ID_ABOUTMENU: + UTIL_SetDialogFont(); if (DialogBoxParam(hInst, MAKEINTRESOURCE(IDD_ABOUTDIALOG), hWin, TTXAboutDlg, (LPARAM) pvar) == -1) { UTIL_get_lang_msgT("MSG_CREATEWINDOW_ABOUT_ERROR", uimsg1, _countof(uimsg1), @@ -5353,9 +5361,11 @@ } return 1; case ID_SSHAUTH: + UTIL_SetDialogFont(); AUTH_do_cred_dialog(pvar); return 1; case ID_SSHSETUPMENU: + UTIL_SetDialogFont(); if (DialogBoxParam(hInst, MAKEINTRESOURCE(IDD_SSHSETUP), hWin, TTXSetupDlg, (LPARAM) pvar) == -1) { UTIL_get_lang_msgT("MSG_CREATEWINDOW_SETUP_ERROR", uimsg1, _countof(uimsg1), @@ -5366,15 +5376,19 @@ } return 1; case ID_SSHAUTHSETUPMENU: + UTIL_SetDialogFont(); AUTH_do_default_cred_dialog(pvar); return 1; case ID_SSHFWDSETUPMENU: + UTIL_SetDialogFont(); FWDUI_do_forwarding_dialog(pvar); return 1; case ID_SSHUNKNOWNHOST: + UTIL_SetDialogFont(); HOSTS_do_unknown_host_dialog(hWin, pvar); return 1; case ID_SSHDIFFERENTKEY: + UTIL_SetDialogFont(); HOSTS_do_different_key_dialog(hWin, pvar); return 1; case ID_SSHASYNCMESSAGEBOX: