Revision: 8307 https://osdn.net/projects/ttssh2/scm/svn/commits/8307 Author: zmatsuo Date: 2019-10-15 01:29:30 +0900 (Tue, 15 Oct 2019) Log Message: ----------- ツールチップをunicode対応 - VTWinで CTRLx2 で文字情報が表示されるようになった - tipwin.cpp,h - 仮に _DrawTextW() 追加 - DrawText(A)() -> _DrawTextW() - RegisterClass(A)() -> _RegisterClassW() - CreateWindowEx(A)() -> _CreateWindowExW() - SetWindowText(A)() -> _SetWindowTextW() - layer_for_unicode.cpp,h, compat_win.cpp,h - _CreateWindowExW(), _RegisterClassW() 追加 - compat_win.cpp,h - pCreateWindowExW, pRegisterClassW 追加 - ttxssh/CMakeLists.txt - tipwinで必要となった依存ファイル追加 - layer_for_unicode.cpp,h, compat_win.cpp,h, dllutil.cpp,h - codeconv.cpp,h - Comctl32 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/tipwin.cpp branches/unicode_buf/teraterm/common/tipwin.h branches/unicode_buf/ttssh2/ttxssh/CMakeLists.txt -------------- next part -------------- Modified: branches/unicode_buf/teraterm/common/compat_win.cpp =================================================================== --- branches/unicode_buf/teraterm/common/compat_win.cpp 2019-10-14 16:29:12 UTC (rev 8306) +++ branches/unicode_buf/teraterm/common/compat_win.cpp 2019-10-14 16:29:30 UTC (rev 8307) @@ -35,6 +35,10 @@ #include "dllutil.h" #include "ttlib.h" +ATOM (WINAPI *pRegisterClassW)(const WNDCLASSW *lpWndClass); +HWND(WINAPI *pCreateWindowExW) +(DWORD dwExStyle, LPCWSTR lpClassName, LPCWSTR lpWindowName, DWORD dwStyle, int X, int Y, int nWidth, int nHeight, + HWND hWndParent, HMENU hMenu, HINSTANCE hInstance, LPVOID lpParam); HPROPSHEETPAGE (WINAPI * pCreatePropertySheetPageW)(LPCPROPSHEETPAGEW constPropSheetPagePointer); INT_PTR (WINAPI *pPropertySheetW)(LPCPROPSHEETHEADERW constPropSheetHeaderPointer); LRESULT (WINAPI *pSendDlgItemMessageW)(HWND hDlg, int nIDDlgItem, UINT Msg, WPARAM wParam, LPARAM lParam); @@ -128,8 +132,10 @@ // 9x\x93\xC1\x95ʏ\x88\x97\x9D if (!IsWindowsNTKernel()) { - // GetPrivateProfileStringW() \x82\xAA Windows 95 \x82ɑ\xB6\x8D݂\xB5\x82Ă\xA2\x82\xE9(\x8A\xAB\x88ˑ\xB6?) + // Windows 9x \x82ɑ\xB6\x8D݂\xB5\x82Ă\xA2\x82\xE9API(\x8A\xAB\x88ˑ\xB6?) // \x90\xB3\x82\xB5\x82\xAD\x93\xAE\x8D삵\x82Ȃ\xA2\x82̂Ŗ\xB3\x8C\xF8\x82Ƃ\xB7\x82\xE9 pGetPrivateProfileStringW = NULL; + pSetWindowTextW = NULL; + pSetDlgItemTextW = NULL; } } Modified: branches/unicode_buf/teraterm/common/compat_win.h =================================================================== --- branches/unicode_buf/teraterm/common/compat_win.h 2019-10-14 16:29:12 UTC (rev 8306) +++ branches/unicode_buf/teraterm/common/compat_win.h 2019-10-14 16:29:30 UTC (rev 8307) @@ -67,6 +67,10 @@ #define OPENFILENAME_SIZE_VERSION_400A 76 #endif +extern ATOM (WINAPI *pRegisterClassW)(const WNDCLASSW *lpWndClass); +extern HWND(WINAPI *pCreateWindowExW)(DWORD dwExStyle, LPCWSTR lpClassName, LPCWSTR lpWindowName, DWORD dwStyle, int X, + int Y, int nWidth, int nHeight, HWND hWndParent, HMENU hMenu, HINSTANCE hInstance, + LPVOID lpParam); extern HPROPSHEETPAGE (WINAPI * pCreatePropertySheetPageW)(LPCPROPSHEETPAGEW constPropSheetPagePointer); extern INT_PTR (WINAPI *pPropertySheetW)(LPCPROPSHEETHEADERW constPropSheetHeaderPointer); extern LRESULT (WINAPI *pSendDlgItemMessageW)(HWND hDlg, int nIDDlgItem, UINT Msg, WPARAM wParam, LPARAM lParam); Modified: branches/unicode_buf/teraterm/common/layer_for_unicode.cpp =================================================================== --- branches/unicode_buf/teraterm/common/layer_for_unicode.cpp 2019-10-14 16:29:12 UTC (rev 8306) +++ branches/unicode_buf/teraterm/common/layer_for_unicode.cpp 2019-10-14 16:29:30 UTC (rev 8307) @@ -174,3 +174,65 @@ free(captionA); return retval; } + +HWND _CreateWindowExW(DWORD dwExStyle, LPCWSTR lpClassName, LPCWSTR lpWindowName, DWORD dwStyle, int X, int Y, + int nWidth, int nHeight, HWND hWndParent, HMENU hMenu, HINSTANCE hInstance, LPVOID lpParam) +{ + if (pCreateWindowExW != NULL) { + return pCreateWindowExW(dwExStyle, lpClassName, lpWindowName, dwStyle, X, Y, nWidth, nHeight, hWndParent, hMenu, + hInstance, lpParam); + } + + char *lpClassNameA = ToCharW(lpClassName); + char *lpWindowNameA = ToCharW(lpWindowName); + HWND hWnd = CreateWindowExA(dwExStyle, lpClassNameA, lpWindowNameA, dwStyle, X, Y, nWidth, nHeight, hWndParent, + hMenu, hInstance, lpParam); + free(lpClassNameA); + if (lpWindowNameA != NULL) { + free(lpWindowNameA); + } + return hWnd; +} + +ATOM _RegisterClassW(const WNDCLASSW *lpWndClass) +{ + if (pRegisterClassW != NULL) { + return pRegisterClassW(lpWndClass); + } + + char *menu_nameA = ToCharW(lpWndClass->lpszMenuName); + char *class_nameA = ToCharW(lpWndClass->lpszClassName); + + WNDCLASSA WndClassA; + WndClassA.style = lpWndClass->style; + WndClassA.lpfnWndProc = lpWndClass->lpfnWndProc; + WndClassA.cbClsExtra = lpWndClass->cbClsExtra; + WndClassA.cbWndExtra = lpWndClass->cbWndExtra; + WndClassA.hInstance = lpWndClass->hInstance; + WndClassA.hIcon = lpWndClass->hIcon; + WndClassA.hCursor = lpWndClass->hCursor; + WndClassA.hbrBackground = lpWndClass->hbrBackground; + WndClassA.lpszMenuName = menu_nameA; + WndClassA.lpszClassName = class_nameA; + ATOM atom = RegisterClassA(&WndClassA); + + if (menu_nameA != NULL) { + free(menu_nameA); + } + if (class_nameA != NULL) { + free(class_nameA); + } + return atom; +} + +BOOL _SetWindowTextW(HWND hWnd, LPCWSTR lpString) +{ + if (pSetWindowTextW != NULL) { + return pSetWindowTextW(hWnd, lpString); + } + + char *strA = ToCharW(lpString); + BOOL retval = SetWindowTextA(hWnd, strA); + free(strA); + return retval; +} Modified: branches/unicode_buf/teraterm/common/layer_for_unicode.h =================================================================== --- branches/unicode_buf/teraterm/common/layer_for_unicode.h 2019-10-14 16:29:12 UTC (rev 8306) +++ branches/unicode_buf/teraterm/common/layer_for_unicode.h 2019-10-14 16:29:30 UTC (rev 8307) @@ -40,6 +40,7 @@ extern "C" { #endif +BOOL _SetWindowTextW(HWND hWnd, LPCWSTR lpString); BOOL _SetDlgItemTextW(HWND hDlg, int nIDDlgItem, LPCWSTR lpString); DWORD _GetFileAttributesW(LPCWSTR lpFileName); UINT _DragQueryFileW(HDROP hDrop, UINT iFile, LPWSTR lpszFile, UINT cch); @@ -47,6 +48,10 @@ HPROPSHEETPAGE _CreatePropertySheetPageW(LPCPROPSHEETPAGEW_V1 constPropSheetPagePointer); INT_PTR _PropertySheetW(PROPSHEETHEADERW *constPropSheetHeaderPointer); //INT_PTR _PropertySheetW(PROPSHEETHEADERW_V1 *constPropSheetHeaderPointer); +HWND _CreateWindowExW(DWORD dwExStyle, LPCWSTR lpClassName, LPCWSTR lpWindowName, DWORD dwStyle, int X, int Y, + int nWidth, int nHeight, HWND hWndParent, HMENU hMenu, HINSTANCE hInstance, + LPVOID lpParam); +ATOM _RegisterClassW(const WNDCLASSW *lpWndClass); #ifdef __cplusplus } Modified: branches/unicode_buf/teraterm/common/tipwin.cpp =================================================================== --- branches/unicode_buf/teraterm/common/tipwin.cpp 2019-10-14 16:29:12 UTC (rev 8306) +++ branches/unicode_buf/teraterm/common/tipwin.cpp 2019-10-14 16:29:30 UTC (rev 8307) @@ -57,7 +57,7 @@ #include <windows.h> #include <stdio.h> -#include <tchar.h> +#include <wchar.h> #include <assert.h> #if !defined(_CRTDBG_MAP_ALLOC) #define _CRTDBG_MAP_ALLOC @@ -64,11 +64,13 @@ #endif #include <crtdbg.h> -#include "ttlib.h" // for GetMessageboxFont() +#include "ttlib.h" // for GetMessageboxFont(), IsWindowsNTKernel() +#include "codeconv.h" +#include "layer_for_unicode.h" #include "tipwin.h" -#define TipWinClassName _T("TeraTermTipWinClass") +#define TipWinClassName L"TeraTermTipWinClass" typedef struct tagTipWinData { HFONT tip_font; @@ -75,7 +77,7 @@ COLORREF tip_bg; COLORREF tip_text; HWND tip_wnd; - const TCHAR *str; + const wchar_t *str; size_t str_len; RECT str_rect; RECT rect; @@ -83,6 +85,24 @@ int py; } TipWin; +/** + * 9x\x8Cn\x82\xC5DrawTextW\x82\xAA\x8Eg\x82\xA6\x82邩\x82悭\x82킩\x82\xE7\x82Ȃ\xA2 + * \x82Ƃ肠\x82\xA6\x82\xB8\x82\xB1\x82̃t\x83@\x83C\x83\x8B\x82ł̂ݎg\x97p + * \x82\xBB\x82̂\xA4\x82\xBF layer_for_unicode.cpp \x82Ɉړ\xAE\x82\xB7\x82\xE9 + */ +static int _DrawTextW(HDC hdc, LPCWSTR lpchText, int cchText, LPRECT lprc, UINT format) +{ + if (IsWindowsNTKernel()) { + return DrawTextW(hdc, lpchText, cchText, lprc, format); + } + + char *strA = ToCharW(lpchText); + size_t strA_len = strlen(strA); + int result = DrawTextA(hdc, strA, strA_len, lprc, format); + free(strA); + return result; +} + VOID CTipWin::CalcStrRect(VOID) { HDC hdc = CreateCompatibleDC(NULL); @@ -89,8 +109,8 @@ SelectObject(hdc, tWin->tip_font); tWin->str_rect.top = 0; tWin->str_rect.left = 0; - DrawText(hdc, tWin->str, (int)tWin->str_len, - &tWin->str_rect, DT_LEFT|DT_CALCRECT); + _DrawTextW(hdc, tWin->str, (int)tWin->str_len, + &tWin->str_rect, DT_LEFT|DT_CALCRECT); DeleteDC(hdc); } @@ -139,7 +159,7 @@ rect.right = rect.right + TIP_WIN_FRAME_WIDTH; rect.top = rect.top + TIP_WIN_FRAME_WIDTH; rect.bottom = rect.bottom + TIP_WIN_FRAME_WIDTH; - DrawText(hdc, self->tWin->str, (int)self->tWin->str_len, &rect, DT_LEFT); + _DrawTextW(hdc, self->tWin->str, (int)self->tWin->str_len, &rect, DT_LEFT); } SelectObject(hdc, holdbr); @@ -189,7 +209,7 @@ ATOM CTipWin::RegisterClass() { - WNDCLASS wc; + WNDCLASSW wc; wc.style = CS_HREDRAW | CS_VREDRAW; wc.lpfnWndProc = WndProc; wc.cbClsExtra = 0; @@ -200,7 +220,7 @@ wc.hbrBackground = NULL; wc.lpszMenuName = NULL; wc.lpszClassName = class_name; - return ::RegisterClass(&wc); + return _RegisterClassW(&wc); } VOID CTipWin::Create(HWND pHwnd) @@ -212,7 +232,7 @@ hInstance = (HINSTANCE)GetWindowLongPtr(pHwnd, GWLP_HINSTANCE); } if (class_name[0] == 0) { - _snprintf_s(class_name, _countof(class_name), _TRUNCATE, _T("%s_%p"), TipWinClassName, hInstance); + _snwprintf_s(class_name, _countof(class_name), _TRUNCATE, L"%s_%p", TipWinClassName, hInstance); } RegisterClass(); if (tWin == NULL) { @@ -219,8 +239,8 @@ return; } tWin->str_len = 0; - tWin->str = (TCHAR*)malloc(sizeof(TCHAR)); - memset((void*)tWin->str, 0, sizeof(TCHAR)); + tWin->str = (wchar_t*)malloc(sizeof(wchar_t)); + memset((void*)tWin->str, 0, sizeof(wchar_t)); tWin->px = 0; tWin->py = 0; tWin->tip_bg = GetSysColor(COLOR_INFOBK); @@ -230,12 +250,12 @@ logfont.lfHeight = MulDiv(logfont.lfHeight, uDpi, 96); tWin->tip_font = CreateFontIndirect(&logfont); tWin->tip_wnd = - CreateWindowEx(WS_EX_TOOLWINDOW | WS_EX_TOPMOST, - class_name, - NULL, WS_POPUP, - 0, 0, - 0, 0, - pHwnd, NULL, hInstance, this); + _CreateWindowExW(WS_EX_TOOLWINDOW | WS_EX_TOPMOST, + class_name, + NULL, WS_POPUP, + 0, 0, + 0, 0, + pHwnd, NULL, hInstance, this); timerid = 0; } @@ -269,15 +289,22 @@ } } -VOID CTipWin::SetText(const TCHAR *str) +VOID CTipWin::SetText(const char *str) { + wchar_t *strW = ToWcharA(str); + SetText(strW); + free(strW); +} + +VOID CTipWin::SetText(const wchar_t *str) +{ if(!IsExists()) { return; } TipWin* self = tWin; - self->str_len = _tcslen(str); - self->str = _tcsdup(str); + self->str_len = wcslen(str); + self->str = _wcsdup(str); CalcStrRect(); // \x83E\x83B\x83\x93\x83h\x83E\x82̃T\x83C\x83Y\x82͕\xB6\x8E\x9A\x83T\x83C\x83Y+\x8D\xB6\x89E(\x8F㉺)\x82̃t\x83\x8C\x81[\x83\x80 @@ -412,10 +439,10 @@ tipwin->SetText(str); } -VOID TipWinSetTextW(TipWin* tWin, const wchar_t *str) +void TipWinSetTextW(TipWin* tWin, const wchar_t *str) { CTipWin* tipwin = (CTipWin*) tWin; - tipwin->SetText("not implimented"); + tipwin->SetText(str); } void TipWinSetHideTimer(TipWin *tWin, int ms) Modified: branches/unicode_buf/teraterm/common/tipwin.h =================================================================== --- branches/unicode_buf/teraterm/common/tipwin.h 2019-10-14 16:29:12 UTC (rev 8306) +++ branches/unicode_buf/teraterm/common/tipwin.h 2019-10-14 16:29:30 UTC (rev 8307) @@ -85,7 +85,7 @@ UINT_PTR timerid; TipWin* tWin; HINSTANCE hInstance; - TCHAR class_name[32]; + wchar_t class_name[32]; static LRESULT CALLBACK WndProc(HWND hWnd, UINT nMsg, WPARAM wParam, LPARAM lParam); VOID CalcStrRect(); ATOM RegisterClass(); Modified: branches/unicode_buf/ttssh2/ttxssh/CMakeLists.txt =================================================================== --- branches/unicode_buf/ttssh2/ttxssh/CMakeLists.txt 2019-10-14 16:29:12 UTC (rev 8306) +++ branches/unicode_buf/ttssh2/ttxssh/CMakeLists.txt 2019-10-14 16:29:30 UTC (rev 8307) @@ -98,6 +98,12 @@ ../../teraterm/common/codeconv.h ../../teraterm/common/tipwin.cpp ../../teraterm/common/tipwin.h + ../../teraterm/common/layer_for_unicode.cpp + ../../teraterm/common/layer_for_unicode.h + ../../teraterm/common/compat_win.cpp + ../../teraterm/common/compat_win.h + ../../teraterm/common/dllutil.cpp + ../../teraterm/common/dllutil.h ) source_group( @@ -149,6 +155,7 @@ gdi32 comdlg32 delayimp + Comctl32 ) ### create puttyversion.h