[Ttssh2-commit] [8686] CListDlg, CMsgDlg を unicode化

Back to archive index
scmno****@osdn***** scmno****@osdn*****
2020年 4月 12日 (日) 00:53:38 JST


Revision: 8686
          https://osdn.net/projects/ttssh2/scm/svn/commits/8686
Author:   zmatsuo
Date:     2020-04-12 00:53:38 +0900 (Sun, 12 Apr 2020)
Log Message:
-----------
CListDlg, CMsgDlg を unicode化

- CalcTextExtentW()#ttmlib 追加

Modified Paths:
--------------
    trunk/teraterm/ttpmacro/ListDlg.cpp
    trunk/teraterm/ttpmacro/ListDlg.h
    trunk/teraterm/ttpmacro/msgdlg.cpp
    trunk/teraterm/ttpmacro/msgdlg.h
    trunk/teraterm/ttpmacro/ttl_gui.cpp
    trunk/teraterm/ttpmacro/ttmdlg.cpp
    trunk/teraterm/ttpmacro/ttmdlg.h
    trunk/teraterm/ttpmacro/ttmlib.c
    trunk/teraterm/ttpmacro/ttmlib.h

-------------- next part --------------
Modified: trunk/teraterm/ttpmacro/ListDlg.cpp
===================================================================
--- trunk/teraterm/ttpmacro/ListDlg.cpp	2020-04-11 15:53:28 UTC (rev 8685)
+++ trunk/teraterm/ttpmacro/ListDlg.cpp	2020-04-11 15:53:38 UTC (rev 8686)
@@ -44,7 +44,7 @@
 
 // CListDlg \x83_\x83C\x83A\x83\x8D\x83O
 
-CListDlg::CListDlg(const TCHAR *Text, const TCHAR *Caption, TCHAR **Lists, int Selected, int x, int y)
+CListDlg::CListDlg(const wchar_t *Text, const wchar_t *Caption, wchar_t **Lists, int Selected, int x, int y)
 {
 	m_Text = Text;
 	m_Caption = Caption;
@@ -61,7 +61,7 @@
 
 void CListDlg::InitList(HWND HList)
 {
-	TCHAR **p;
+	wchar_t **p;
 	int ListMaxWidth = 0;
 	int ListCount = 0;
 	HDC DC = ::GetDC(HList);
@@ -72,7 +72,7 @@
 		SIZE size;
 		int ListWidth;
 		SendDlgItemMessage(IDC_LISTBOX, LB_ADDSTRING, 0, (LPARAM)(*p));
-		GetTextExtentPoint32(DC, *p, strlen(*p), &size);
+		GetTextExtentPoint32W(DC, *p, wcslen(*p), &size);
 		ListWidth = size.cx;
 		if (ListWidth > ListMaxWidth) {
 			ListMaxWidth = ListWidth;
@@ -106,10 +106,10 @@
 	InitList(HList);
 
 	// \x96{\x95\xB6\x82ƃ^\x83C\x83g\x83\x8B
-	SetDlgItemText(IDC_LISTTEXT, m_Text);
-	SetWindowText(m_Caption);
+	SetDlgItemTextW(IDC_LISTTEXT, m_Text);
+	SetWindowTextW(m_Caption);
 
-	CalcTextExtent(GetDlgItem(IDC_LISTTEXT), NULL, m_Text,&s);
+	CalcTextExtentW(GetDlgItem(IDC_LISTTEXT), NULL, m_Text,&s);
 	TW = s.cx + s.cx/10;
 	TH = s.cy;
 

Modified: trunk/teraterm/ttpmacro/ListDlg.h
===================================================================
--- trunk/teraterm/ttpmacro/ListDlg.h	2020-04-11 15:53:28 UTC (rev 8685)
+++ trunk/teraterm/ttpmacro/ListDlg.h	2020-04-11 15:53:38 UTC (rev 8686)
@@ -34,15 +34,15 @@
 class CListDlg : public CMacroDlgBase
 {
 public:
-	CListDlg(const TCHAR *Text, const TCHAR *Caption, TCHAR **Lists, int Selected, int x, int y);
+	CListDlg(const wchar_t *Text, const wchar_t *Caption, wchar_t **Lists, int Selected, int x, int y);
 	INT_PTR DoModal(HINSTANCE hInst, HWND hWndParent);
 	int m_SelectItem;
 
 private:
 	enum { IDD = IDD_LISTDLG };
-	const TCHAR *m_Text;
-	const TCHAR *m_Caption;
-	TCHAR **m_Lists;
+	const wchar_t *m_Text;
+	const wchar_t *m_Caption;
+	wchar_t **m_Lists;
 	int m_Selected;
 	int init_WW, TW, TH, BH, BW, LW, LH;
 	SIZE s;

Modified: trunk/teraterm/ttpmacro/msgdlg.cpp
===================================================================
--- trunk/teraterm/ttpmacro/msgdlg.cpp	2020-04-11 15:53:28 UTC (rev 8685)
+++ trunk/teraterm/ttpmacro/msgdlg.cpp	2020-04-11 15:53:38 UTC (rev 8686)
@@ -44,7 +44,7 @@
 
 // CMsgDlg dialog
 
-CMsgDlg::CMsgDlg(const TCHAR *Text, const TCHAR *Title, BOOL YesNo,
+CMsgDlg::CMsgDlg(const wchar_t *Text, const wchar_t *Title, BOOL YesNo,
                  int x, int y)
 {
 	TextStr = Text;
@@ -80,9 +80,9 @@
 		SetDlgTexts(m_hWnd, TextInfosOk, _countof(TextInfosOk), UILanguageFile);
 	}
 
-	SetWindowText(TitleStr);
-	SetDlgItemText(IDC_MSGTEXT,TextStr);
-	CalcTextExtent(GetDlgItem(IDC_MSGTEXT), NULL, TextStr, &s);
+	SetWindowTextW(TitleStr);
+	SetDlgItemTextW(IDC_MSGTEXT,TextStr);
+	CalcTextExtentW(GetDlgItem(IDC_MSGTEXT), NULL, TextStr, &s);
 	TW = s.cx + s.cx/10;
 	TH = s.cy;
 

Modified: trunk/teraterm/ttpmacro/msgdlg.h
===================================================================
--- trunk/teraterm/ttpmacro/msgdlg.h	2020-04-11 15:53:28 UTC (rev 8685)
+++ trunk/teraterm/ttpmacro/msgdlg.h	2020-04-11 15:53:38 UTC (rev 8686)
@@ -36,14 +36,14 @@
 class CMsgDlg : public CMacroDlgBase
 {
 public:
-	CMsgDlg(const TCHAR *Text, const TCHAR *Title, BOOL YesNo, int x, int y);
+	CMsgDlg(const wchar_t *Text, const wchar_t *Title, BOOL YesNo, int x, int y);
 	INT_PTR DoModal(HINSTANCE hInst, HWND hWndParent);
 
 private:
 	enum { IDD = IDD_MSGDLG };
 
-	const TCHAR *TextStr;
-	const TCHAR *TitleStr;
+	const wchar_t *TextStr;
+	const wchar_t *TitleStr;
 	BOOL YesNoFlag;
 	int  init_WW, TW, TH, BH, BW;
 	SIZE s;

Modified: trunk/teraterm/ttpmacro/ttl_gui.cpp
===================================================================
--- trunk/teraterm/ttpmacro/ttl_gui.cpp	2020-04-11 15:53:28 UTC (rev 8685)
+++ trunk/teraterm/ttpmacro/ttl_gui.cpp	2020-04-11 15:53:38 UTC (rev 8686)
@@ -480,7 +480,7 @@
 	}
 
 	if (BoxId==IdMsgBox) {
-		ret = OpenMsgDlg(tc::fromUtf8(Str1),tc::fromUtf8(Str2),FALSE);
+		ret = OpenMsgDlg(wc::fromUtf8(Str1),wc::fromUtf8(Str2),FALSE);
 		// \x83\x81\x83b\x83Z\x81[\x83W\x83{\x83b\x83N\x83X\x82\xF0\x83L\x83\x83\x83\x93\x83Z\x83\x8B\x82\xB7\x82\xE9\x82ƁA\x83}\x83N\x83\x8D\x82̏I\x97\xB9\x82Ƃ\xB7\x82\xE9\x81B
 		// (2008.8.5 yutaka)
 		if (ret == IDCANCEL) {
@@ -487,7 +487,7 @@
 			TTLStatus = IdTTLEnd;
 		}
 	} else if (BoxId==IdYesNoBox) {
-		ret = OpenMsgDlg(tc::fromUtf8(Str1),tc::fromUtf8(Str2),TRUE);
+		ret = OpenMsgDlg(wc::fromUtf8(Str1),wc::fromUtf8(Str2),TRUE);
 		// \x83\x81\x83b\x83Z\x81[\x83W\x83{\x83b\x83N\x83X\x82\xF0\x83L\x83\x83\x83\x93\x83Z\x83\x8B\x82\xB7\x82\xE9\x82ƁA\x83}\x83N\x83\x8D\x82̏I\x97\xB9\x82Ƃ\xB7\x82\xE9\x81B
 		// (2008.8.6 yutaka)
 		if (ret == IDCLOSE) {
@@ -514,7 +514,7 @@
 			sel = 0;
 		}
 
-		TCHAR **s = (TCHAR **)calloc(ary_size + 1, sizeof(TCHAR *));
+		wchar_t **s = (wchar_t **)calloc(ary_size + 1, sizeof(wchar_t *));
 		if (s == NULL) {
 			*Err = ErrFewMemory;
 			return -1;
@@ -523,7 +523,7 @@
 			TVarId VarId2;
 			VarId2 = GetStrVarFromArray(VarId, i, Err);
 			if (*Err!=0) return -1;
-			s[i] = ToTcharU8(StrVarPtr(VarId2));
+			s[i] = ToWcharU8(StrVarPtr(VarId2));
 		}
 		if (s[0] == NULL) {
 			*Err = ErrSyntax;
@@ -534,7 +534,7 @@
 		//   0\x88ȏ\xE3: \x91I\x91\xF0\x8D\x80\x96\xDA
 		//   -1: \x83L\x83\x83\x83\x93\x83Z\x83\x8B
 		//	 -2: close
-		ret = OpenListDlg(tc::fromUtf8(Str1), tc::fromUtf8(Str2), s, sel);
+		ret = OpenListDlg(wc::fromUtf8(Str1), wc::fromUtf8(Str2), s, sel);
 
 		for (i = 0 ; i < ary_size ; i++) {
 			free((void *)s[i]);

Modified: trunk/teraterm/ttpmacro/ttmdlg.cpp
===================================================================
--- trunk/teraterm/ttpmacro/ttmdlg.cpp	2020-04-11 15:53:28 UTC (rev 8685)
+++ trunk/teraterm/ttpmacro/ttmdlg.cpp	2020-04-11 15:53:38 UTC (rev 8686)
@@ -238,7 +238,7 @@
 	return ErrDlg.DoModal(hInst, hWndParent);
 }
 
-int OpenMsgDlg(const TCHAR *Text, const TCHAR *Caption, BOOL YesNo)
+int OpenMsgDlg(const wchar_t *Text, const wchar_t *Caption, BOOL YesNo)
 {
 	HINSTANCE hInst = GetInstance();
 	HWND hWndParent = GetHWND();
@@ -283,7 +283,7 @@
  * @retval -1		cancel\x83{\x83^\x83\x93
  * @retval -2		close\x83{\x83^\x83\x93
  */
-int OpenListDlg(const TCHAR *Text, const TCHAR *Caption, TCHAR **Lists, int Selected)
+int OpenListDlg(const wchar_t *Text, const wchar_t *Caption, wchar_t **Lists, int Selected)
 {
 	HINSTANCE hInst = GetInstance();
 	HWND hWndParent = GetHWND();

Modified: trunk/teraterm/ttpmacro/ttmdlg.h
===================================================================
--- trunk/teraterm/ttpmacro/ttmdlg.h	2020-04-11 15:53:28 UTC (rev 8685)
+++ trunk/teraterm/ttpmacro/ttmdlg.h	2020-04-11 15:53:38 UTC (rev 8686)
@@ -43,12 +43,12 @@
 void OpenInpDlg(TCHAR *Input, const TCHAR *Text, const TCHAR *Caption,
                 const TCHAR *Default, BOOL Paswd);
 int OpenErrDlg(const char *Msg, const char *Line, int lineno, int start, int end, const char *FileName);
-int OpenMsgDlg(const TCHAR *Text, const TCHAR *Caption, BOOL YesNo);
+int OpenMsgDlg(const wchar_t *Text, const wchar_t *Caption, BOOL YesNo);
 void OpenStatDlg(const TCHAR *Text, const TCHAR *Caption);
 void CloseStatDlg();
 void BringupStatDlg();
 
-int OpenListDlg(const TCHAR *Text, const TCHAR *Caption, TCHAR **Lists, int Selected);
+int OpenListDlg(const wchar_t *Text, const wchar_t *Caption, wchar_t **Lists, int Selected);
 
 extern char HomeDir[MAX_PATH];
 extern char FileName[MAX_PATH];

Modified: trunk/teraterm/ttpmacro/ttmlib.c
===================================================================
--- trunk/teraterm/ttpmacro/ttmlib.c	2020-04-11 15:53:28 UTC (rev 8685)
+++ trunk/teraterm/ttpmacro/ttmlib.c	2020-04-11 15:53:38 UTC (rev 8686)
@@ -101,7 +101,7 @@
 			Temp[0] = 0x20;
 			Temp[1] = 0;
 		}
-		dwExt = GetTabbedTextExtent(DC,Temp,strlen(Temp),0,NULL);
+		dwExt = GetTabbedTextExtent(DC,Temp, (int)strlen(Temp),0,NULL);
 		s->cx = LOWORD(dwExt);
 		s->cy = HIWORD(dwExt);
 		if (s->cx > W) W = s->cx;
@@ -123,6 +123,56 @@
 	ReleaseDC(hWnd, DC);
 }
 
+void CalcTextExtentW(HWND hWnd, HFONT hFont, const wchar_t *Text, LPSIZE s)
+{
+	HDC DC = GetDC(hWnd);
+	int W, H, i, i0;
+	wchar_t Temp[512];
+	DWORD dwExt;
+	HFONT prevFont;
+	if (hFont == NULL) {
+		hFont = (HFONT)SendMessage(hWnd, WM_GETFONT, 0, 0);
+	}
+	prevFont = (HFONT)SelectObject(DC, hFont);
+
+	W = 0;
+	H = 0;
+	i = 0;
+	do {
+		i0 = i;
+		while ((Text[i]!=0) &&
+			   (Text[i]!=0x0d) &&
+			   (Text[i]!=0x0a))
+			i++;
+		memcpy(Temp,&Text[i0],sizeof(wchar_t) * (i-i0));
+		Temp[i-i0] = 0;
+		if (Temp[0]==0)
+		{
+			Temp[0] = 0x20;
+			Temp[1] = 0;
+		}
+		dwExt = GetTabbedTextExtentW(DC,Temp,(int)wcslen(Temp),0,NULL);
+		s->cx = LOWORD(dwExt);
+		s->cy = HIWORD(dwExt);
+		if (s->cx > W) W = s->cx;
+		H = H + s->cy;
+		if (Text[i]!=0)
+		{
+			i++;
+			if ((Text[i]==0x0a) &&
+				(Text[i-1]==0x0d))
+				i++;
+		}
+	} while (Text[i]!=0);
+	if ((i-i0 == 0) && (H > s->cy)) H = H - s->cy;
+	s->cx = W;
+	s->cy = H;
+	if (prevFont != NULL) {
+		SelectObject(DC, prevFont);
+	}
+	ReleaseDC(hWnd, DC);
+}
+
 void TTMGetDir(PCHAR Dir, int destlen)
 {
   strncpy_s(Dir, destlen, CurrentDir, _TRUNCATE);

Modified: trunk/teraterm/ttpmacro/ttmlib.h
===================================================================
--- trunk/teraterm/ttpmacro/ttmlib.h	2020-04-11 15:53:28 UTC (rev 8685)
+++ trunk/teraterm/ttpmacro/ttmlib.h	2020-04-11 15:53:38 UTC (rev 8686)
@@ -40,6 +40,7 @@
 extern char UILanguageFile[MAX_PATH];
 
 void CalcTextExtent(HWND hWnd, HFONT Font, const char *Text, LPSIZE s);
+void CalcTextExtentW(HWND hWnd, HFONT Font, const wchar_t *Text, LPSIZE s);
 void TTMGetDir(PCHAR Dir, int destlen);
 void TTMSetDir(PCHAR Dir);
 int GetAbsPath(PCHAR FName, int destlen);


Ttssh2-commit メーリングリストの案内
Back to archive index