Revision: 9393 https://osdn.net/projects/ttssh2/scm/svn/commits/9393 Author: zmatsuo Date: 2021-09-01 00:56:33 +0900 (Wed, 01 Sep 2021) Log Message: ----------- ファイルオープンダイアログ用フィルタ文字列作成関数のUnicode版を追加 - GetCommonDialogFilterWW() 追加 - GetCommonDialogFilterW() の入力文字列Unicode版 - GetCommonDialogFilterA() 削除 - 使用している個所がなくなったため Modified Paths: -------------- trunk/teraterm/common/dlglib.h trunk/teraterm/common/dlglib_cpp.cpp -------------- next part -------------- Modified: trunk/teraterm/common/dlglib.h =================================================================== --- trunk/teraterm/common/dlglib.h 2021-08-31 15:56:21 UTC (rev 9392) +++ trunk/teraterm/common/dlglib.h 2021-08-31 15:56:33 UTC (rev 9393) @@ -92,8 +92,8 @@ int GetFontPointFromPixel(HWND hWnd, int pixel); int GetFontPixelFromPoint(HWND hWnd, int point); void ExpandCBWidth(HWND dlg, int ID); +wchar_t *GetCommonDialogFilterWW(const char *user_filter_mask, const wchar_t *UILanguageFile); wchar_t *GetCommonDialogFilterW(const char *user_filter_mask, const char *UILanguageFile); -char *GetCommonDialogFilterA(const char *user_filter_mask, const char *UILanguageFile); #ifdef __cplusplus } Modified: trunk/teraterm/common/dlglib_cpp.cpp =================================================================== --- trunk/teraterm/common/dlglib_cpp.cpp 2021-08-31 15:56:21 UTC (rev 9392) +++ trunk/teraterm/common/dlglib_cpp.cpp 2021-08-31 15:56:33 UTC (rev 9393) @@ -39,6 +39,7 @@ #include "dlglib.h" #include "ttlib.h" #include "codeconv.h" +#include "asprintf.h" /** * EndDialog() \x8C݊\xB7\x8A\x94 @@ -226,18 +227,16 @@ * @retval "User define(*.txt)\0*.txt\0All(*.*)\0*.*\0" \x82Ȃ\xC7 * \x8FI\x92[\x82\xCD "\0\0" \x82ƂȂ\xE9 */ -wchar_t *GetCommonDialogFilterW(const char *user_filter_mask, const char *UILanguageFile, size_t *len) +wchar_t *GetCommonDialogFilterWW(const wchar_t *user_filter_mask, const wchar_t *UILanguageFile, size_t *len) { // "\x83\x86\x81[\x83U\x92\xE8\x8B`(*.txt)\0*.txt" wchar_t *user_filter_str = NULL; size_t user_filter_len = 0; if (user_filter_mask != NULL && user_filter_mask[0] != 0) { - wchar_t user_filter_name[MAX_UIMSG]; - GetI18nStrW("Tera Term", "FILEDLG_USER_FILTER_NAME", user_filter_name, sizeof(user_filter_name), L"User define", - UILanguageFile); + wchar_t *user_filter_name; + GetI18nStrWW("Tera Term", "FILEDLG_USER_FILTER_NAME", L"User define", UILanguageFile, &user_filter_name); size_t user_filter_name_len = wcslen(user_filter_name); - wchar_t *user_filter_maskW = ToWcharA(user_filter_mask); - size_t user_filter_mask_len = wcslen(user_filter_maskW); + size_t user_filter_mask_len = wcslen(user_filter_mask); user_filter_len = user_filter_name_len + 1 + user_filter_mask_len + 1 + 1 + user_filter_mask_len + 1; user_filter_str = (wchar_t *)malloc(user_filter_len * sizeof(wchar_t)); wchar_t *p = user_filter_str; @@ -244,32 +243,35 @@ wmemcpy(p, user_filter_name, user_filter_name_len); p += user_filter_name_len; *p++ = '('; - wmemcpy(p, user_filter_maskW, user_filter_mask_len); + wmemcpy(p, user_filter_mask, user_filter_mask_len); p += user_filter_mask_len; *p++ = ')'; *p++ = '\0'; - wmemcpy(p, user_filter_maskW, user_filter_mask_len); + wmemcpy(p, user_filter_mask, user_filter_mask_len); p += user_filter_mask_len; *p++ = '\0'; - free(user_filter_maskW); + free(user_filter_name); } // "\x82\xB7\x82ׂẴt\x83@\x83C\x83\x8B(*.*)\0*.*" - wchar_t all_filter_str[MAX_UIMSG]; - GetI18nStrW("Tera Term", "FILEDLG_ALL_FILTER", all_filter_str, _countof(all_filter_str), L"All(*.*)\\0*.*", UILanguageFile); + wchar_t *all_filter_str; size_t all_filter_len; + GetI18nStrWW("Tera Term", "FILEDLG_ALL_FILTER", L"All(*.*)\\0*.*", UILanguageFile, &all_filter_str); { - size_t all_filter_title_len = wcsnlen(all_filter_str, _countof(all_filter_str)); - if (all_filter_title_len == 0 || all_filter_title_len == _countof(all_filter_str)) { - all_filter_str[0] = 0; + // check all_filter_str + size_t all_filter_title_len = wcslen(all_filter_str); + if (all_filter_title_len == 0) { + free(all_filter_str); + all_filter_str = NULL; all_filter_len = 0; } else { - size_t all_filter_mask_max = _countof(all_filter_str) - all_filter_title_len - 1; - size_t all_filter_mask_len = wcsnlen(all_filter_str + all_filter_title_len + 1, all_filter_mask_max); - if (all_filter_mask_len == 0 || all_filter_mask_len == _countof(all_filter_str)) { - all_filter_str[0] = 0; + size_t all_filter_mask_len = wcslen(all_filter_str + all_filter_title_len + 1); + if (all_filter_mask_len == 0) { + free(all_filter_str); + all_filter_str = NULL; all_filter_len = 0; } else { + // ok all_filter_len = all_filter_title_len + 1 + all_filter_mask_len + 1; } } @@ -299,6 +301,9 @@ if (user_filter_len != 0) { free(user_filter_str); } + if (all_filter_len != 0) { + free(all_filter_str); + } if (len != NULL) { *len = filter_len; @@ -307,16 +312,17 @@ return filter_str; } -wchar_t *GetCommonDialogFilterW(const char *user_filter_mask, const char *UILanguageFile) +wchar_t *GetCommonDialogFilterWW(const wchar_t *user_filter_mask, const wchar_t *UILanguageFile) { - return GetCommonDialogFilterW(user_filter_mask, UILanguageFile, NULL); + return GetCommonDialogFilterWW(user_filter_mask, UILanguageFile, NULL); } -char *GetCommonDialogFilterA(const char *user_filter_mask, const char *UILanguageFile) +wchar_t *GetCommonDialogFilterW(const char *user_filter_mask, const char *UILanguageFile) { - size_t filterW_len; - wchar_t *filterW_ptr = GetCommonDialogFilterW(user_filter_mask, UILanguageFile, &filterW_len); - char *filterA_ptr = _WideCharToMultiByte(filterW_ptr, filterW_len, CP_ACP, NULL); - free(filterW_ptr); - return filterA_ptr; + wchar_t *UILanguageFileW = ToWcharA(UILanguageFile); + wchar_t * user_filter_maskW = ToWcharA(user_filter_mask); + wchar_t *ret = GetCommonDialogFilterWW(user_filter_maskW, UILanguageFileW); + free(user_filter_maskW); + free(UILanguageFileW); + return ret; }