[Ttssh2-commit] [8506] tipwin.cpp,h で TCHAR に依存しないようにした

scmno****@osdn***** scmno****@osdn*****
2020年 1月 27日 (月) 00:13:52 JST


Revision: 8506
          https://osdn.net/projects/ttssh2/scm/svn/commits/8506
Author:   zmatsuo
Date:     2020-01-27 00:13:52 +0900 (Mon, 27 Jan 2020)
Log Message:
-----------
tipwin.cpp,h で TCHAR に依存しないようにした

Modified Paths:
--------------
    trunk/teraterm/common/tipwin.cpp
    trunk/teraterm/common/tipwin.h
    trunk/teraterm/teraterm/sizetip.c
    trunk/teraterm/ttpdlg/ttdlg.c
    trunk/ttssh2/ttxssh/auth.c

-------------- next part --------------
Modified: trunk/teraterm/common/tipwin.cpp
===================================================================
--- trunk/teraterm/common/tipwin.cpp	2020-01-26 15:13:45 UTC (rev 8505)
+++ trunk/teraterm/common/tipwin.cpp	2020-01-26 15:13:52 UTC (rev 8506)
@@ -359,6 +359,16 @@
 	return (TipWin*)tipwin;
 }
 
+TipWin *TipWinCreateW(HINSTANCE hInstance, HWND src, int cx, int cy, const wchar_t *str)
+{
+	CTipWin* tipwin = new CTipWin(hInstance);
+	tipwin->Create(src);
+	tipwin->SetText(str);
+	tipwin->SetPos(cx, cy);
+	tipwin->SetVisible(TRUE);
+	return (TipWin*)tipwin;
+}
+
 /*
  * \x95\xB6\x8E\x9A\x97\xF1\x82\xF0\x83c\x81[\x83\x8B\x83`\x83b\x83v\x82ɕ`\x89悵\x82\xBD\x8E\x9E\x82̉\xA1\x82Əc\x82̃T\x83C\x83Y\x82\xF0\x8E擾\x82\xB7\x82\xE9\x81B
  *
@@ -369,7 +379,7 @@
  *   width
  *   height
  */
-void TipWinGetTextWidthHeight(HWND src, const TCHAR *str, int *width, int *height)
+void TipWinGetTextWidthHeight(HWND src, const char *str, int *width, int *height)
 {
 	LOGFONTA logfont;
 	HFONT tip_font;
@@ -379,7 +389,7 @@
 	size_t str_len;
 
 	/* \x95\xB6\x8E\x9A\x97\xF1\x82̒\xB7\x82\xB3\x82\xF0\x8Cv\x8EZ\x82\xB7\x82\xE9 */
-	str_len = _tcslen(str);
+	str_len = strlen(str);
 
 	/* DPI\x82\xF0\x8E擾\x82\xB7\x82\xE9 */
 	uDpi = GetMonitorDpiFromWindow(src);
@@ -404,6 +414,51 @@
 	DeleteObject(tip_font);
 }
 
+/*
+ * \x95\xB6\x8E\x9A\x97\xF1\x82\xF0\x83c\x81[\x83\x8B\x83`\x83b\x83v\x82ɕ`\x89悵\x82\xBD\x8E\x9E\x82̉\xA1\x82Əc\x82̃T\x83C\x83Y\x82\xF0\x8E擾\x82\xB7\x82\xE9\x81B
+ *
+ * [in]
+ *   src
+ *   str
+ * [out]
+ *   width
+ *   height
+ */
+void TipWinGetTextWidthHeightW(HWND src, const wchar_t *str, int *width, int *height)
+{
+	LOGFONTA logfont;
+	HFONT tip_font;
+	UINT uDpi;
+	HDC hdc;
+	RECT str_rect;
+	size_t str_len;
+
+	/* \x95\xB6\x8E\x9A\x97\xF1\x82̒\xB7\x82\xB3\x82\xF0\x8Cv\x8EZ\x82\xB7\x82\xE9 */
+	str_len = wcslen(str);
+
+	/* DPI\x82\xF0\x8E擾\x82\xB7\x82\xE9 */
+	uDpi = GetMonitorDpiFromWindow(src);
+
+	/* \x83t\x83H\x83\x93\x83g\x82𐶐\xAC\x82\xB7\x82\xE9 */
+	GetMessageboxFont(&logfont);
+	logfont.lfWidth = MulDiv(logfont.lfWidth, uDpi, 96);
+	logfont.lfHeight = MulDiv(logfont.lfHeight, uDpi, 96);
+	tip_font = CreateFontIndirect(&logfont);
+
+	/* \x95\xB6\x8E\x9A\x97\xF1\x82\xF0\x95`\x89悵\x82ăT\x83C\x83Y\x82\xF0\x8B\x81\x82߂\xE9 */
+	hdc = CreateCompatibleDC(NULL);
+	SelectObject(hdc, tip_font);
+	str_rect.top = 0;
+	str_rect.left = 0;
+	_DrawTextW(hdc, str, (int)str_len, &str_rect, DT_LEFT|DT_CALCRECT);
+	*width = str_rect.right - str_rect.left;
+	*height = str_rect.bottom - str_rect.top;
+	DeleteDC(hdc);
+
+	/* \x83t\x83H\x83\x93\x83g\x82\xF0\x94j\x8A\xFC\x82\xB7\x82\xE9 */
+	DeleteObject(tip_font);
+}
+
 void TipWinGetPos(TipWin *tWin, int *x, int *y)
 {
 	CTipWin* tipwin = (CTipWin*) tWin;

Modified: trunk/teraterm/common/tipwin.h
===================================================================
--- trunk/teraterm/common/tipwin.h	2020-01-26 15:13:45 UTC (rev 8505)
+++ trunk/teraterm/common/tipwin.h	2020-01-26 15:13:52 UTC (rev 8506)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2018-2019 TeraTerm Project
+ * Copyright (C) 2018-2020 TeraTerm Project
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -29,7 +29,6 @@
 #ifndef _H_TIPWIN
 #define _H_TIPWIN
 #include <windows.h>
-#include <tchar.h>
 
 #ifdef __cplusplus
 extern "C" {
@@ -45,7 +44,6 @@
 void TipWinSetTextA(TipWin *tWin, const char *text);
 void TipWinSetTextW(TipWin *tWin, const wchar_t *text);
 void TipWinDestroy(TipWin *tWin);
-void TipWinGetTextWidthHeight(HWND src, const TCHAR *str, int *width, int *height);
 void TipWinGetPos(TipWin *tWin, int *x, int *y);
 void TipWinSetPos(TipWin *tWin, int x, int y);
 void TipWinSetHideTimer(TipWin *tWin, int ms);
@@ -53,13 +51,8 @@
 int TipWinIsExists(TipWin *tWin);
 int TipWinIsVisible(TipWin *tWin);
 
-#if !defined(_UNICODE)
-#define	TipWinCreateT(p1, p2, p3, p4, p5)	TipWinCreateA(p1, p2, p3, p4, p5)
-#define TipWinSetText(p1, p2)				TipWinSetTextA(p1, p2)
-#else
-#define	TipWinCreateT(p1, p2, p3, p4, p5)	TipWinCreateW(p1, p2, p3, p4, p5)
-#define TipWinSetText(p1, p2)				TipWinSetTextW(p1, p2)
-#endif
+void TipWinGetTextWidthHeight(HWND src, const char *str, int *width, int *height);
+void TipWinGetTextWidthHeightW(HWND src, const wchar_t *str, int *width, int *height);
 
 #ifdef __cplusplus
 }

Modified: trunk/teraterm/teraterm/sizetip.c
===================================================================
--- trunk/teraterm/teraterm/sizetip.c	2020-01-26 15:13:45 UTC (rev 8505)
+++ trunk/teraterm/teraterm/sizetip.c	2020-01-26 15:13:52 UTC (rev 8506)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2008-2019 TeraTerm Project
+ * Copyright (C) 2008-2020 TeraTerm Project
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -35,7 +35,6 @@
 
 #include <windows.h>
 #include <stdio.h>
-#include <tchar.h>
 
 #include "tipwin.h"
 
@@ -111,7 +110,7 @@
  */
 void UpdateSizeTip(HWND src, int cx, int cy, UINT fwSide, int newX, int newY)
 {
-	TCHAR str[32];
+	char str[32];
 	int tooltip_movable = 0;
 
 	if (!tip_enabled)
@@ -118,7 +117,7 @@
 		return;
 
 	/* Generate the tip text */
-	_stprintf_s(str, _countof(str), _T("%dx%d"), cx, cy);
+	_snprintf_s(str, _countof(str), _TRUNCATE, "%dx%d", cx, cy);
 
 	// \x83E\x83B\x83\x93\x83h\x83E\x82̉E\x81A\x89E\x89\xBA\x81A\x89\xBA\x82\xF0\x92͂񂾏ꍇ\x82́A\x83c\x81[\x83\x8B\x83`\x83b\x83v\x82\xF0\x8D\xB6\x8F\xE3\x8B\xF7\x82ɔz\x92u\x82\xB7\x82\xE9\x81B
 	// \x82\xBB\x82\xEA\x82\xE7\x88ȊO\x82̓\x8A\x83T\x83C\x83Y\x8C\xE3\x82̍\xB6\x8F\xE3\x8B\xF7\x82ɔz\x92u\x82\xB7\x82\xE9\x81B
@@ -145,21 +144,14 @@
 		cx = point.x;
 		cy = point.y;
 
-		SizeTip = TipWinCreateT(NULL, src, cx, cy, str);
-
-		//OutputDebugPrintf("Created: (%d,%d)\n", cx, cy);
-
+		SizeTip = TipWinCreateA(NULL, src, cx, cy, str);
 	} else {
 		/* Tip already exists, just set the text */
-		TipWinSetText(SizeTip, str);
-		//SetWindowText(tip_wnd, str);
+		TipWinSetTextA(SizeTip, str);
 
-		//OutputDebugPrintf("Updated: (%d,%d)\n", cx, cy);
-
 		// \x83E\x83B\x83\x93\x83h\x83E\x82̍\xB6\x8Fオ\x88ړ\xAE\x82\xB7\x82\xE9\x8Fꍇ
 		if (tooltip_movable) {
 			TipWinSetPos(SizeTip, newX + TIP_WIN_FRAME_WIDTH*2, newY + TIP_WIN_FRAME_WIDTH*2);
-			//OutputDebugPrintf("Moved: (%d,%d)\n", newX, newY);
 		}
 	}
 }

Modified: trunk/teraterm/ttpdlg/ttdlg.c
===================================================================
--- trunk/teraterm/ttpdlg/ttdlg.c	2020-01-26 15:13:45 UTC (rev 8505)
+++ trunk/teraterm/ttpdlg/ttdlg.c	2020-01-26 15:13:52 UTC (rev 8506)
@@ -1310,7 +1310,7 @@
 			if (!TipWinIsVisible(g_SerialDlgSpeedTip))
 				TipWinSetVisible(g_SerialDlgSpeedTip, TRUE);
 
-			TipWinSetText(g_SerialDlgSpeedTip, str);
+			TipWinSetTextA(g_SerialDlgSpeedTip, str);
 			TipWinSetPos(g_SerialDlgSpeedTip, cx, cy);
 			TipWinSetHideTimer(g_SerialDlgSpeedTip, tooltip_timeout);
 

Modified: trunk/ttssh2/ttxssh/auth.c
===================================================================
--- trunk/ttssh2/ttxssh/auth.c	2020-01-26 15:13:45 UTC (rev 8505)
+++ trunk/ttssh2/ttxssh/auth.c	2020-01-26 15:13:52 UTC (rev 8506)
@@ -44,6 +44,7 @@
 #endif
 #include <stdlib.h>
 #include <crtdbg.h>
+#include <tchar.h>
 
 #include "resource.h"
 #include "keyfiles.h"
@@ -121,7 +122,7 @@
 					_tcscat_s(uimsg, _countof(uimsg), pvar->ts->UIMsg);
 				}
 				GetWindowRect(control, &rect);
-				data->tipwin = TipWinCreateT(hInst, control, rect.left, rect.bottom, uimsg);
+				data->tipwin = TipWinCreateA(hInst, control, rect.left, rect.bottom, uimsg);
 			}
 
 			return 0;


Ttssh2-commit メーリングリストの案内