Revision: 8343 https://osdn.net/projects/ttssh2/scm/svn/commits/8343 Author: zmatsuo Date: 2019-10-29 22:04:49 +0900 (Tue, 29 Oct 2019) Log Message: ----------- clipboarddlg から layer_for_unicode を使用するようにした - layer_for_unicodeに SendDlgItemMessageW(WM_GETTEXTLENGTH), GetDlgItemTextW() を実装した Modified Paths: -------------- branches/unicode_buf/teraterm/common/compat_win.cpp branches/unicode_buf/teraterm/common/compat_win.h branches/unicode_buf/teraterm/common/layer_for_unicode.cpp branches/unicode_buf/teraterm/common/layer_for_unicode.h branches/unicode_buf/teraterm/common/tmfc.cpp branches/unicode_buf/teraterm/teraterm/clipboarddlg.cpp -------------- next part -------------- Modified: branches/unicode_buf/teraterm/common/compat_win.cpp =================================================================== --- branches/unicode_buf/teraterm/common/compat_win.cpp 2019-10-29 13:04:33 UTC (rev 8342) +++ branches/unicode_buf/teraterm/common/compat_win.cpp 2019-10-29 13:04:49 UTC (rev 8343) @@ -49,6 +49,7 @@ UINT (WINAPI *pDragQueryFileW)(HDROP hDrop, UINT iFile, LPWSTR lpszFile, UINT cch); DWORD (WINAPI *pGetFileAttributesW)(LPCWSTR lpFileName); BOOL (WINAPI *pSetDlgItemTextW)(HWND hDlg, int nIDDlgItem, LPCWSTR lpString); +BOOL (WINAPI *pGetDlgItemTextW)(HWND hDlg, int nIDDlgItem, LPWSTR lpString, int cchMax); BOOL (WINAPI *pAlphaBlend)(HDC,int,int,int,int,HDC,int,int,int,int,BLENDFUNCTION); BOOL (WINAPI *pEnumDisplayMonitors)(HDC,LPCRECT,MONITORENUMPROC,LPARAM); DPI_AWARENESS_CONTEXT (WINAPI *pSetThreadDpiAwarenessContext)(DPI_AWARENESS_CONTEXT dpiContext); @@ -71,6 +72,7 @@ { "MonitorFromRect", (void **)&pMonitorFromRect }, { "AdjustWindowRectExForDpi", (void **)&pAdjustWindowRectExForDpi }, { "SetDlgItemTextW", (void **)&pSetDlgItemTextW }, + { "GetDlgItemTextW", (void **)&pGetDlgItemTextW }, { "SetWindowTextW", (void **)&pSetWindowTextW }, { "ModifyMenuW", (void **)&pModifyMenuW }, { "GetMenuStringW", (void **)&pGetMenuStringW }, @@ -139,5 +141,7 @@ pGetPrivateProfileStringW = NULL; pSetWindowTextW = NULL; pSetDlgItemTextW = NULL; + pGetDlgItemTextW = NULL; } } + Modified: branches/unicode_buf/teraterm/common/compat_win.h =================================================================== --- branches/unicode_buf/teraterm/common/compat_win.h 2019-10-29 13:04:33 UTC (rev 8342) +++ branches/unicode_buf/teraterm/common/compat_win.h 2019-10-29 13:04:49 UTC (rev 8343) @@ -82,6 +82,7 @@ extern UINT(WINAPI *pDragQueryFileW)(HDROP hDrop, UINT iFile, LPWSTR lpszFile, UINT cch); extern DWORD (WINAPI *pGetFileAttributesW)(LPCWSTR lpFileName); extern BOOL (WINAPI *pSetDlgItemTextW)(HWND hDlg, int nIDDlgItem, LPCWSTR lpString); +extern BOOL (WINAPI *pGetDlgItemTextW)(HWND hDlg, int nIDDlgItem, LPWSTR lpString, int cchMax); extern BOOL (WINAPI *pAlphaBlend)(HDC,int,int,int,int,HDC,int,int,int,int,BLENDFUNCTION); extern BOOL (WINAPI *pEnumDisplayMonitors)(HDC,LPCRECT,MONITORENUMPROC,LPARAM); extern HMONITOR (WINAPI *pMonitorFromRect)(LPCRECT lprc, DWORD dwFlags); Modified: branches/unicode_buf/teraterm/common/layer_for_unicode.cpp =================================================================== --- branches/unicode_buf/teraterm/common/layer_for_unicode.cpp 2019-10-29 13:04:33 UTC (rev 8342) +++ branches/unicode_buf/teraterm/common/layer_for_unicode.cpp 2019-10-29 13:04:49 UTC (rev 8343) @@ -109,12 +109,34 @@ } LRESULT retval; - if (Msg == CB_ADDSTRING || Msg == LB_ADDSTRING) { + switch(Msg) { + case CB_ADDSTRING: + case LB_ADDSTRING: { char *strA = ToCharW((wchar_t *)lParam); retval = SendDlgItemMessageA(hDlg, nIDDlgItem, Msg, wParam, (LPARAM)strA); free(strA); - } else { + break; + } + case WM_GETTEXTLENGTH: { + retval = 0; + LRESULT len = SendDlgItemMessageA(hDlg, nIDDlgItem, WM_GETTEXTLENGTH, 0, 0); + len++; // for '\0' + char *strA = (char *)malloc(sizeof(char) * len); + if (strA != NULL) { + GetDlgItemTextA(hDlg, nIDDlgItem, strA, (int)len); + strA[len-1] = '\0'; + wchar_t *strW = ToWcharA(strA); + if (strW != NULL) { + retval = (LRESULT)wcslen(strW);// '\0'\x82\xF0\x8A܂܂Ȃ\xA2\x92\xB7\x82\xB3\x82\xF0\x95Ԃ\xB7 + free(strW); + } + free(strA); + } + break; + } + default: retval = SendDlgItemMessageA(hDlg, nIDDlgItem, Msg, wParam, lParam); + break; } return retval; } @@ -236,3 +258,30 @@ free(strA); return retval; } + +UINT _GetDlgItemTextW(HWND hDlg, int nIDDlgItem, LPWSTR lpString, int cchMax) +{ + if (pGetDlgItemTextW != NULL) { + return pGetDlgItemTextW(hDlg, nIDDlgItem, lpString, cchMax); + } + + // \x82\xB1\x82̕\xB6\x8E\x9A\x97\xCD ANSI + size_t len = SendDlgItemMessageA(hDlg, nIDDlgItem, WM_GETTEXTLENGTH, 0, 0); + len++; // for '\0' + char *strA = (char *)malloc(sizeof(char) * len); + if (strA != NULL) { + GetDlgItemTextA(hDlg, nIDDlgItem, strA, (int)len); + strA[len - 1] = '\0'; + wchar_t *strW = ToWcharA(strA); + if (strW != NULL) { + wcscpy_s(lpString, cchMax, strW); + UINT len = (UINT)wcslen(strW); // '\0' \x82\xF0\x8A܂܂Ȃ\xA2\x92\xB7\x82\xB3\x82\xF0\x95Ԃ\xB7 + free(strW); + return len; + } + } + + if (cchMax > 0) + lpString[0] = 0; + return 0; +} Modified: branches/unicode_buf/teraterm/common/layer_for_unicode.h =================================================================== --- branches/unicode_buf/teraterm/common/layer_for_unicode.h 2019-10-29 13:04:33 UTC (rev 8342) +++ branches/unicode_buf/teraterm/common/layer_for_unicode.h 2019-10-29 13:04:49 UTC (rev 8343) @@ -42,6 +42,7 @@ BOOL _SetWindowTextW(HWND hWnd, LPCWSTR lpString); BOOL _SetDlgItemTextW(HWND hDlg, int nIDDlgItem, LPCWSTR lpString); +UINT _GetDlgItemTextW(HWND hDlg, int nIDDlgItem, LPWSTR lpString, int cchMax); DWORD _GetFileAttributesW(LPCWSTR lpFileName); UINT _DragQueryFileW(HDROP hDrop, UINT iFile, LPWSTR lpszFile, UINT cch); LRESULT _SendDlgItemMessageW(HWND hDlg, int nIDDlgItem, UINT Msg, WPARAM wParam, LPARAM lParam); Modified: branches/unicode_buf/teraterm/common/tmfc.cpp =================================================================== --- branches/unicode_buf/teraterm/common/tmfc.cpp 2019-10-29 13:04:33 UTC (rev 8342) +++ branches/unicode_buf/teraterm/common/tmfc.cpp 2019-10-29 13:04:49 UTC (rev 8343) @@ -84,12 +84,10 @@ ::GetDlgItemText(m_hWnd, id, buf, (int)size); } -#if defined(UNICODE) void TTCWnd::GetDlgItemTextW(int id, wchar_t *buf, size_t size) { - ::GetDlgItemTextW(m_hWnd, id, buf, (int)size); + _GetDlgItemTextW(m_hWnd, id, buf, (int)size); } -#endif void TTCWnd::GetDlgItemTextA(int id, char *buf, size_t size) { @@ -103,7 +101,7 @@ void TTCWnd::SetDlgItemTextW(int id, const wchar_t *str) { - ::SetDlgItemTextW(m_hWnd, id, str); + _SetDlgItemTextW(m_hWnd, id, str); } void TTCWnd::SetDlgItemTextA(int id, const char *str) @@ -183,7 +181,7 @@ void TTCWnd::SetWindowTextW(const wchar_t *str) { - ::SetWindowTextW(m_hWnd, str); + _SetWindowTextW(m_hWnd, str); } void TTCWnd::SetWindowTextA(const char *str) Modified: branches/unicode_buf/teraterm/teraterm/clipboarddlg.cpp =================================================================== --- branches/unicode_buf/teraterm/teraterm/clipboarddlg.cpp 2019-10-29 13:04:33 UTC (rev 8342) +++ branches/unicode_buf/teraterm/teraterm/clipboarddlg.cpp 2019-10-29 13:04:49 UTC (rev 8343) @@ -26,7 +26,6 @@ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -/* TERATERM.EXE, Clipboard routines */ #include "teraterm.h" #include "tttypes.h" #include "vtdisp.h" @@ -37,16 +36,13 @@ #include <commctrl.h> #define _CRTDBG_MAP_ALLOC #include <crtdbg.h> -#include <wchar.h> #include "ttwinman.h" #include "ttcommon.h" #include "ttlib.h" #include "dlglib.h" - +#include "layer_for_unicode.h" #include "tt_res.h" -#include "sendmem.h" - #include "clipboarddlg.h" static INT_PTR CALLBACK OnClipboardDlgProc(HWND hDlgWnd, UINT msg, WPARAM wp, LPARAM lp) @@ -73,7 +69,7 @@ SetDlgTexts(hDlgWnd, TextInfos, _countof(TextInfos), data->UILanguageFile); if (data->strW_ptr != NULL) { - SetDlgItemTextW(hDlgWnd, IDC_EDIT, data->strW_ptr); + _SetDlgItemTextW(hDlgWnd, IDC_EDIT, data->strW_ptr); } else { SetDlgItemTextA(hDlgWnd, IDC_EDIT, data->strA_ptr); } @@ -180,11 +176,12 @@ { INT_PTR result = IDCANCEL; - size_t len = SendDlgItemMessage(hDlgWnd, IDC_EDIT, WM_GETTEXTLENGTH, 0, 0); + size_t len = _SendDlgItemMessageW(hDlgWnd, IDC_EDIT, WM_GETTEXTLENGTH, 0, 0); len++; // for '\0' wchar_t *strW = (wchar_t *)malloc(sizeof(wchar_t) * len); if (strW != NULL) { - GetDlgItemTextW(hDlgWnd, IDC_EDIT, strW, (int)len); + _GetDlgItemTextW(hDlgWnd, IDC_EDIT, strW, (int)len); + strW[len - 1] = '\0'; result = IDOK; } data->strW_edited_ptr = strW;