• R/O
  • SSH
  • HTTPS

ttssh2: Commit


Commit MetaInfo

Revision8301 (tree)
Zeit2019-10-15 01:12:57
Autorzmatsuo

Log Message

TipWinのAPIをUnicodeを考慮して修正

- TipWinCreate() を TipWinCreateA() に改名
- 位置とテキストの指定が不要な TipWinCreate() を追加
- TipWinSetText() を TipWinSetTextA() に改名
- TipWinSetText() は TipWinSetTextA/W() に置き換えるようにした
- WM_NCDESTORY の処理は何も行っていなかったので削除
- WM_SETTEXT の処理を CTipWin::SetText() に移動

- Unicode版を考慮

- IsClassRegistered(), UnregisterClass() は削除

- exe,dllごとにウィンドウクラスの登録を行うようになったので不要

Ändern Zusammenfassung

Diff

--- trunk/teraterm/common/tipwin.cpp (revision 8300)
+++ trunk/teraterm/common/tipwin.cpp (revision 8301)
@@ -68,6 +68,8 @@
6868
6969 #include "tipwin.h"
7070
71+#define TipWinClassName _T("TeraTermTipWinClass")
72+
7173 typedef struct tagTipWinData {
7274 HFONT tip_font;
7375 COLORREF tip_bg;
@@ -79,7 +81,6 @@
7981 RECT rect;
8082 int px;
8183 int py;
82- TCHAR class_name[32];
8384 } TipWin;
8485
8586 VOID CTipWin::CalcStrRect(VOID)
@@ -150,33 +151,6 @@
150151
151152 case WM_NCHITTEST:
152153 return HTTRANSPARENT;
153- case WM_SETTEXT:
154- if(self) {
155- LPCTSTR str = (LPCTSTR) lParam;
156- const int str_width = self->tWin->str_rect.right - self->tWin->str_rect.left;
157- const int str_height = self->tWin->str_rect.bottom - self->tWin->str_rect.top;
158-
159- free((void *)(self->tWin->str));
160- self->tWin->str_len = _tcslen(str);
161- self->tWin->str = _tcsdup(str);
162- self->CalcStrRect();
163-
164- SetWindowPos(hWnd, NULL,
165- 0, 0,
166- str_width + TIP_WIN_FRAME_WIDTH * 2, str_height + TIP_WIN_FRAME_WIDTH * 2,
167- SWP_NOZORDER | SWP_NOMOVE | SWP_NOACTIVATE);
168- InvalidateRect(hWnd, NULL, FALSE);
169- }
170- break;
171- case WM_NCDESTROY:
172- /*
173- * use-after-freeによりTera Termの動作が不安定となる問題を修正した。
174- *
175- * WinMainで CVTWindow クラスのコンストラクタで、アロケートした
176- * TipWinメンバーを、ここのタイミングで解放していたため。
177- * 正しくは CVTWindow クラスのデストラクタで解放する。
178- */
179- break;
180154 case WM_TIMER:
181155 if(self) {
182156 if(self->timerid > 0)
@@ -213,15 +187,6 @@
213187 }
214188 }
215189
216-BOOL CTipWin::IsClassRegistered()
217-{
218- if (*class_name == NULL) {
219- _snprintf_s(class_name, sizeof(class_name), _TRUNCATE, _T("%s_%p"), TipWinClassName, hInstance);
220- }
221- WNDCLASS twc = { 0 };
222- return (GetClassInfo(hInstance, class_name, &twc) > 0);
223-}
224-
225190 ATOM CTipWin::RegisterClass()
226191 {
227192 WNDCLASS wc;
@@ -238,11 +203,6 @@
238203 return ::RegisterClass(&wc);
239204 }
240205
241-BOOL CTipWin::UnregisterClass()
242-{
243- return ::UnregisterClass(class_name, hInstance);
244-}
245-
246206 VOID CTipWin::Create(HWND pHwnd)
247207 {
248208 LOGFONTA logfont;
@@ -251,9 +211,10 @@
251211 if(hInstance == NULL) {
252212 hInstance = (HINSTANCE)GetWindowLongPtr(pHwnd, GWLP_HINSTANCE);
253213 }
254- if (! IsClassRegistered()) {
255- RegisterClass();
214+ if (class_name[0] == 0) {
215+ _snprintf_s(class_name, _countof(class_name), _TRUNCATE, _T("%s_%p"), TipWinClassName, hInstance);
256216 }
217+ RegisterClass();
257218 if (tWin == NULL) {
258219 return;
259220 }
@@ -268,14 +229,6 @@
268229 logfont.lfWidth = MulDiv(logfont.lfWidth, uDpi, 96);
269230 logfont.lfHeight = MulDiv(logfont.lfHeight, uDpi, 96);
270231 tWin->tip_font = CreateFontIndirect(&logfont);
271-
272- /*
273- * RegisterClass()が失敗した場合は、CreateWindowEx()が 87 (ERROR_INVALID_PARAMETER)で
274- * エラーとなるため、呼び出さないようにする。
275- *
276- * WindowsMe(9x)では、SSH認証ダイアログのツールチップ表示で RegisterClass() が
277- * 失敗する。原因不明。
278- */
279232 tWin->tip_wnd =
280233 CreateWindowEx(WS_EX_TOOLWINDOW | WS_EX_TOPMOST,
281234 class_name,
@@ -316,13 +269,25 @@
316269 }
317270 }
318271
319-VOID CTipWin::SetText(TCHAR *str)
272+VOID CTipWin::SetText(const TCHAR *str)
320273 {
321- if(IsExists()) {
322- SetWindowText(tWin->tip_wnd, str);
323- // ツールチップのテキストとウィンドウの描画順の関係でテキストを2度描画してツールチップウィンドウをリサイズする
324- SetWindowText(tWin->tip_wnd, str);
274+ if(!IsExists()) {
275+ return;
325276 }
277+
278+ TipWin* self = tWin;
279+ self->str_len = _tcslen(str);
280+ self->str = _tcsdup(str);
281+ CalcStrRect();
282+
283+ const int str_width = self->str_rect.right - self->str_rect.left;
284+ const int str_height = self->str_rect.bottom - self->str_rect.top;
285+ SetWindowText(tWin->tip_wnd, str);
286+ SetWindowPos(tWin->tip_wnd, NULL,
287+ 0, 0,
288+ str_width + TIP_WIN_FRAME_WIDTH * 2, str_height + TIP_WIN_FRAME_WIDTH * 2,
289+ SWP_NOZORDER | SWP_NOMOVE | SWP_NOACTIVATE);
290+ InvalidateRect(tWin->tip_wnd, NULL, FALSE);
326291 }
327292
328293 VOID CTipWin::SetHideTimer(int ms)
@@ -362,11 +327,18 @@
362327 return FALSE;
363328 }
364329
365-TipWin *TipWinCreate(HINSTANCE hInstance, HWND src, int cx, int cy, const TCHAR *str)
330+TipWin *TipWinCreate(HINSTANCE hInstance, HWND src)
366331 {
367332 CTipWin* tipwin = new CTipWin(hInstance);
368333 tipwin->Create(src);
369- tipwin->SetText((TCHAR*)str);
334+ return (TipWin*)tipwin;
335+}
336+
337+TipWin *TipWinCreateA(HINSTANCE hInstance, HWND src, int cx, int cy, const char *str)
338+{
339+ CTipWin* tipwin = new CTipWin(hInstance);
340+ tipwin->Create(src);
341+ tipwin->SetText(str);
370342 tipwin->SetPos(cx, cy);
371343 tipwin->SetVisible(TRUE);
372344 return (TipWin*)tipwin;
@@ -393,7 +365,7 @@
393365
394366 /* 文字列の長さを計算する */
395367 str_len = _tcslen(str);
396-
368+
397369 /* DPIを取得する */
398370 uDpi = GetMonitorDpiFromWindow(src);
399371
@@ -431,7 +403,7 @@
431403 tipwin->SetPos(x, y);
432404 }
433405
434-void TipWinSetText(TipWin* tWin, TCHAR *str)
406+void TipWinSetTextA(TipWin* tWin, const char *str)
435407 {
436408 CTipWin* tipwin = (CTipWin*) tWin;
437409 tipwin->SetText(str);
--- trunk/teraterm/common/tipwin.h (revision 8300)
+++ trunk/teraterm/common/tipwin.h (revision 8301)
@@ -37,12 +37,13 @@
3737
3838 #define TIP_WIN_FRAME_WIDTH 6
3939
40-#define TipWinClassName _T("TeraTermTipWinClass")
41-
4240 typedef struct tagTipWinData TipWin;
4341
44-TipWin *TipWinCreate(HINSTANCE hInstance, HWND src, int cx, int cy, const TCHAR *str);
45-void TipWinSetText(TipWin *tWin, TCHAR *text);
42+TipWin *TipWinCreate(HINSTANCE hInstance, HWND src);
43+TipWin *TipWinCreateA(HINSTANCE hInstance, HWND src, int cx, int cy, const char *str);
44+TipWin *TipWinCreateW(HINSTANCE hInstance, HWND src, int cx, int cy, const wchar_t *str);
45+void TipWinSetTextA(TipWin *tWin, const char *text);
46+void TipWinSetTextW(TipWin *tWin, const wchar_t *text);
4647 void TipWinDestroy(TipWin *tWin);
4748 void TipWinGetTextWidthHeight(HWND src, const TCHAR *str, int *width, int *height);
4849 void TipWinGetPos(TipWin *tWin, int *x, int *y);
@@ -52,6 +53,14 @@
5253 int TipWinIsExists(TipWin *tWin);
5354 int TipWinIsVisible(TipWin *tWin);
5455
56+#if !defined(_UNICODE)
57+#define TipWinCreateT(p1, p2, p3, p4, p5) TipWinCreateA(p1, p2, p3, p4, p5)
58+#define TipWinSetText(p1, p2) TipWinSetTextA(p1, p2)
59+#else
60+#define TipWinCreateT(p1, p2, p3, p4, p5) TipWinCreateW(p1, p2, p3, p4, p5)
61+#define TipWinSetText(p1, p2) TipWinSetTextW(p1, p2)
62+#endif
63+
5564 #ifdef __cplusplus
5665 }
5766 #endif
@@ -64,7 +73,8 @@
6473 ~CTipWin();
6574 VOID Create(HWND pHwnd);
6675 VOID Destroy();
67- VOID SetText(TCHAR *str);
76+ VOID SetText(const char *str);
77+ VOID SetText(const wchar_t *str);
6878 POINT GetPos();
6979 VOID SetPos(int x, int y);
7080 VOID SetHideTimer(int ms);
--- trunk/teraterm/teraterm/sizetip.c (revision 8300)
+++ trunk/teraterm/teraterm/sizetip.c (revision 8301)
@@ -144,7 +144,7 @@
144144 cx = point.x;
145145 cy = point.y;
146146
147- SizeTip = TipWinCreate(NULL, src, cx, cy, str);
147+ SizeTip = TipWinCreateT(NULL, src, cx, cy, str);
148148
149149 //OutputDebugPrintf("Created: (%d,%d)\n", cx, cy);
150150
--- trunk/teraterm/ttpdlg/ttdlg.c (revision 8300)
+++ trunk/teraterm/ttpdlg/ttdlg.c (revision 8301)
@@ -1300,18 +1300,16 @@
13001300
13011301 // ツールチップを表示する
13021302 if (g_SerialDlgSpeedTip == NULL) {
1303- g_SerialDlgSpeedTip = TipWinCreate(hInst, hWnd, cx, cy, str);
1303+ g_SerialDlgSpeedTip = TipWinCreate(hInst, hWnd);
13041304 TipWinSetHideTimer(g_SerialDlgSpeedTip, tooltip_timeout);
1305+ }
1306+ if (!TipWinIsVisible(g_SerialDlgSpeedTip))
1307+ TipWinSetVisible(g_SerialDlgSpeedTip, TRUE);
13051308
1306- } else {
1307- if (!TipWinIsVisible(g_SerialDlgSpeedTip))
1308- TipWinSetVisible(g_SerialDlgSpeedTip, TRUE);
1309+ TipWinSetText(g_SerialDlgSpeedTip, str);
1310+ TipWinSetPos(g_SerialDlgSpeedTip, cx, cy);
1311+ TipWinSetHideTimer(g_SerialDlgSpeedTip, tooltip_timeout);
13091312
1310- TipWinSetText(g_SerialDlgSpeedTip, str);
1311- TipWinSetPos(g_SerialDlgSpeedTip, cx, cy);
1312- TipWinSetHideTimer(g_SerialDlgSpeedTip, tooltip_timeout);
1313- }
1314-
13151313 break;
13161314 }
13171315 return CallWindowProc(g_defSerialDlgSpeedComboboxWndProc, hWnd, msg, wp, lp);
--- trunk/ttssh2/ttxssh/auth.c (revision 8300)
+++ trunk/ttssh2/ttxssh/auth.c (revision 8301)
@@ -122,7 +122,7 @@
122122 _tcscat_s(uimsg, _countof(uimsg), pvar->ts->UIMsg);
123123 }
124124 GetWindowRect(control, &rect);
125- data->tipwin = TipWinCreate(hInst, control, rect.left, rect.bottom, uimsg);
125+ data->tipwin = TipWinCreateT(hInst, control, rect.left, rect.bottom, uimsg);
126126 }
127127
128128 return 0;
Show on old repository browser