• R/O
  • SSH
  • HTTPS

ttssh2: コミット


コミットメタ情報

リビジョン8625 (tree)
日時2020-03-27 00:39:27
作者zmatsuo

ログメッセージ

CListDlg, CMsgDlg を unicode化

- codeconvにwcクラスを追加
- CalcTextExtentW() 追加

変更サマリ

差分

--- branches/unicode_macro/teraterm/common/codeconv.cpp (revision 8624)
+++ branches/unicode_macro/teraterm/common/codeconv.cpp (revision 8625)
@@ -1,5 +1,5 @@
11 /*
2- * Copyright (C) 2018-2019 TeraTerm Project
2+ * Copyright (C) 2018-2020 TeraTerm Project
33 * All rights reserved.
44 *
55 * Redistribution and use in source and binary forms, with or without
@@ -1269,3 +1269,143 @@
12691269 obj.tstr_ = NULL;
12701270 }
12711271 }
1272+
1273+//////////////////////////////////////////////////////////////////////////////
1274+
1275+wc::wc()
1276+{
1277+ tstr_ = NULL;
1278+}
1279+
1280+#if 0
1281+tc::tc(const char *strA)
1282+{
1283+ tstr_ = NULL;
1284+ assign(strA, CP_ACP);
1285+}
1286+
1287+tc::tc(const char *strA, int code_page)
1288+{
1289+ tstr_ = NULL;
1290+ assign(strA, code_page);
1291+}
1292+#endif
1293+
1294+wc::wc(const wchar_t *strW)
1295+{
1296+ tstr_ = NULL;
1297+ assign(strW);
1298+}
1299+
1300+wc::wc(const wc &obj)
1301+{
1302+ tstr_ = NULL;
1303+ copy(obj);
1304+}
1305+
1306+#if defined(MOVE_CONSTRUCTOR_ENABLE)
1307+wc::wc(wc &&obj) noexcept
1308+{
1309+ tstr_ = NULL;
1310+ move(obj);
1311+}
1312+#endif
1313+
1314+
1315+wc::~wc()
1316+{
1317+ if (tstr_ != NULL) {
1318+ free(tstr_);
1319+ }
1320+}
1321+
1322+#if 0
1323+tc& tc::operator=(const char *strA)
1324+{
1325+ assign(strA, CP_ACP);
1326+ return *this;
1327+}
1328+
1329+tc& tc::operator=(const wchar_t *strW)
1330+{
1331+ assign(strW);
1332+ return *this;
1333+}
1334+
1335+tc &tc::operator=(const tc &obj)
1336+{
1337+ copy(obj);
1338+ return *this;
1339+}
1340+
1341+#if defined(MOVE_CONSTRUCTOR_ENABLE)
1342+tc& tc::operator=(tc &&obj) noexcept
1343+{
1344+ move(obj);
1345+ return *this;
1346+}
1347+#endif
1348+#endif
1349+
1350+wc wc::fromUtf8(const char *strU8)
1351+{
1352+ wchar_t *strW = _MultiByteToWideChar(strU8, 0, CP_UTF8, NULL);
1353+ wc _wc = strW;
1354+ free(strW);
1355+ return _wc;
1356+}
1357+
1358+// voidなしが一般的と思われるが、
1359+// VS2005でリンクエラーが出てしまうため void 追加
1360+wc::operator const wchar_t *(void) const
1361+{
1362+ return cstr();
1363+}
1364+
1365+const wchar_t *wc::cstr() const
1366+{
1367+ if (tstr_ == NULL) {
1368+ return L"";
1369+ }
1370+ return tstr_;
1371+}
1372+
1373+void wc::assign(const char *strA, int code_page)
1374+{
1375+ if (tstr_ != NULL) {
1376+ free(tstr_);
1377+ }
1378+ wchar_t *strW = _MultiByteToWideChar(strA, 0, code_page, NULL);
1379+ if (strW != NULL) {
1380+ tstr_ = strW;
1381+ } else {
1382+ tstr_ = NULL;
1383+ }
1384+}
1385+
1386+void wc::assign(const wchar_t *strW)
1387+{
1388+ if (tstr_ != NULL) {
1389+ free(tstr_);
1390+ }
1391+ tstr_ = _wcsdup(strW);
1392+}
1393+
1394+void wc::copy(const wc &obj)
1395+{
1396+ if (tstr_ != NULL) {
1397+ free(tstr_);
1398+ }
1399+ tstr_ = _wcsdup(obj.tstr_);
1400+}
1401+
1402+void wc::move(wc &obj)
1403+{
1404+ if (this != &obj) {
1405+ if (tstr_ != NULL) {
1406+ free(tstr_);
1407+ }
1408+ tstr_ = obj.tstr_;
1409+ obj.tstr_ = NULL;
1410+ }
1411+}
--- branches/unicode_macro/teraterm/common/codeconv.h (revision 8624)
+++ branches/unicode_macro/teraterm/common/codeconv.h (revision 8625)
@@ -150,4 +150,35 @@
150150 void copy(const tc &obj);
151151 void move(tc &obj);
152152 };
153+
154+class wc
155+{
156+public:
157+ wc();
158+ wc(const char *strA);
159+ wc(const char *strA, int code_page);
160+ wc(const wchar_t *strW);
161+ wc(const wc &obj);
162+#if defined(MOVE_CONSTRUCTOR_ENABLE)
163+ wc(wc &&obj) noexcept;
153164 #endif
165+ ~wc();
166+ wc& operator=(const char *strA);
167+ wc& operator=(const wchar_t *strW);
168+ wc& operator=(const wc &obj);
169+#if defined(MOVE_CONSTRUCTOR_ENABLE)
170+ wc& operator=(wc &&obj) noexcept;
171+#endif
172+ static wc fromUtf8(const char *strU8);
173+ operator const wchar_t *() const;
174+ const wchar_t *cstr() const;
175+ operator const char *() const;
176+// const char *cstr() const;
177+private:
178+ wchar_t *tstr_;
179+ void assign(const char *strA, int code_page);
180+ void assign(const wchar_t *strW);
181+ void copy(const wc &obj);
182+ void move(wc &obj);
183+};
184+#endif
--- branches/unicode_macro/teraterm/ttpmacro/ListDlg.cpp (revision 8624)
+++ branches/unicode_macro/teraterm/ttpmacro/ListDlg.cpp (revision 8625)
@@ -44,7 +44,7 @@
4444
4545 // CListDlg ダイアログ
4646
47-CListDlg::CListDlg(const TCHAR *Text, const TCHAR *Caption, TCHAR **Lists, int Selected, int x, int y)
47+CListDlg::CListDlg(const wchar_t *Text, const wchar_t *Caption, wchar_t **Lists, int Selected, int x, int y)
4848 {
4949 m_Text = Text;
5050 m_Caption = Caption;
@@ -61,7 +61,7 @@
6161
6262 void CListDlg::InitList(HWND HList)
6363 {
64- TCHAR **p;
64+ wchar_t **p;
6565 int ListMaxWidth = 0;
6666 int ListCount = 0;
6767 HDC DC = ::GetDC(HList);
@@ -72,7 +72,7 @@
7272 SIZE size;
7373 int ListWidth;
7474 SendDlgItemMessage(IDC_LISTBOX, LB_ADDSTRING, 0, (LPARAM)(*p));
75- GetTextExtentPoint32(DC, *p, strlen(*p), &size);
75+ GetTextExtentPoint32W(DC, *p, wcslen(*p), &size);
7676 ListWidth = size.cx;
7777 if (ListWidth > ListMaxWidth) {
7878 ListMaxWidth = ListWidth;
@@ -106,10 +106,10 @@
106106 InitList(HList);
107107
108108 // 本文とタイトル
109- SetDlgItemText(IDC_LISTTEXT, m_Text);
110- SetWindowText(m_Caption);
109+ SetDlgItemTextW(IDC_LISTTEXT, m_Text);
110+ SetWindowTextW(m_Caption);
111111
112- CalcTextExtent(GetDlgItem(IDC_LISTTEXT), NULL, m_Text,&s);
112+ CalcTextExtentW(GetDlgItem(IDC_LISTTEXT), NULL, m_Text,&s);
113113 TW = s.cx + s.cx/10;
114114 TH = s.cy;
115115
--- branches/unicode_macro/teraterm/ttpmacro/ListDlg.h (revision 8624)
+++ branches/unicode_macro/teraterm/ttpmacro/ListDlg.h (revision 8625)
@@ -34,15 +34,15 @@
3434 class CListDlg : public CMacroDlgBase
3535 {
3636 public:
37- CListDlg(const TCHAR *Text, const TCHAR *Caption, TCHAR **Lists, int Selected, int x, int y);
37+ CListDlg(const wchar_t *Text, const wchar_t *Caption, wchar_t **Lists, int Selected, int x, int y);
3838 INT_PTR DoModal(HINSTANCE hInst, HWND hWndParent);
3939 int m_SelectItem;
4040
4141 private:
4242 enum { IDD = IDD_LISTDLG };
43- const TCHAR *m_Text;
44- const TCHAR *m_Caption;
45- TCHAR **m_Lists;
43+ const wchar_t *m_Text;
44+ const wchar_t *m_Caption;
45+ wchar_t **m_Lists;
4646 int m_Selected;
4747 int init_WW, TW, TH, BH, BW, LW, LH;
4848 SIZE s;
--- branches/unicode_macro/teraterm/ttpmacro/msgdlg.cpp (revision 8624)
+++ branches/unicode_macro/teraterm/ttpmacro/msgdlg.cpp (revision 8625)
@@ -44,7 +44,7 @@
4444
4545 // CMsgDlg dialog
4646
47-CMsgDlg::CMsgDlg(const TCHAR *Text, const TCHAR *Title, BOOL YesNo,
47+CMsgDlg::CMsgDlg(const wchar_t *Text, const wchar_t *Title, BOOL YesNo,
4848 int x, int y)
4949 {
5050 TextStr = Text;
@@ -77,9 +77,9 @@
7777 SetDlgTexts(m_hWnd, TextInfosOk, _countof(TextInfosOk), UILanguageFile);
7878 }
7979
80- SetWindowText(TitleStr);
81- SetDlgItemText(IDC_MSGTEXT,TextStr);
82- CalcTextExtent(GetDlgItem(IDC_MSGTEXT), NULL, TextStr, &s);
80+ SetWindowTextW(TitleStr);
81+ SetDlgItemTextW(IDC_MSGTEXT,TextStr);
82+ CalcTextExtentW(GetDlgItem(IDC_MSGTEXT), NULL, TextStr, &s);
8383 TW = s.cx + s.cx/10;
8484 TH = s.cy;
8585
--- branches/unicode_macro/teraterm/ttpmacro/msgdlg.h (revision 8624)
+++ branches/unicode_macro/teraterm/ttpmacro/msgdlg.h (revision 8625)
@@ -36,14 +36,14 @@
3636 class CMsgDlg : public CMacroDlgBase
3737 {
3838 public:
39- CMsgDlg(const TCHAR *Text, const TCHAR *Title, BOOL YesNo, int x, int y);
39+ CMsgDlg(const wchar_t *Text, const wchar_t *Title, BOOL YesNo, int x, int y);
4040 INT_PTR DoModal(HINSTANCE hInst, HWND hWndParent);
4141
4242 private:
4343 enum { IDD = IDD_MSGDLG };
4444
45- const TCHAR *TextStr;
46- const TCHAR *TitleStr;
45+ const wchar_t *TextStr;
46+ const wchar_t *TitleStr;
4747 BOOL YesNoFlag;
4848 int init_WW, TW, TH, BH, BW;
4949 SIZE s;
--- branches/unicode_macro/teraterm/ttpmacro/ttl_gui.cpp (revision 8624)
+++ branches/unicode_macro/teraterm/ttpmacro/ttl_gui.cpp (revision 8625)
@@ -366,7 +366,7 @@
366366 }
367367
368368 if (BoxId==IdMsgBox) {
369- ret = OpenMsgDlg(tc::fromUtf8(Str1),tc::fromUtf8(Str2),FALSE);
369+ ret = OpenMsgDlg(wc::fromUtf8(Str1),wc::fromUtf8(Str2),FALSE);
370370 // メッセージボックスをキャンセルすると、マクロの終了とする。
371371 // (2008.8.5 yutaka)
372372 if (ret == IDCANCEL) {
@@ -373,7 +373,7 @@
373373 TTLStatus = IdTTLEnd;
374374 }
375375 } else if (BoxId==IdYesNoBox) {
376- ret = OpenMsgDlg(tc::fromUtf8(Str1),tc::fromUtf8(Str2),TRUE);
376+ ret = OpenMsgDlg(wc::fromUtf8(Str1),wc::fromUtf8(Str2),TRUE);
377377 // メッセージボックスをキャンセルすると、マクロの終了とする。
378378 // (2008.8.6 yutaka)
379379 if (ret == IDCLOSE) {
@@ -400,7 +400,7 @@
400400 sel = 0;
401401 }
402402
403- TCHAR **s = (TCHAR **)calloc(ary_size + 1, sizeof(TCHAR *));
403+ wchar_t **s = (wchar_t **)calloc(ary_size + 1, sizeof(wchar_t *));
404404 if (s == NULL) {
405405 *Err = ErrFewMemory;
406406 return -1;
@@ -409,7 +409,7 @@
409409 TVarId VarId2;
410410 VarId2 = GetStrVarFromArray(VarId, i, Err);
411411 if (*Err!=0) return -1;
412- s[i] = ToTcharU8(StrVarPtr(VarId2));
412+ s[i] = ToWcharU8(StrVarPtr(VarId2));
413413 }
414414 if (s[0] == NULL) {
415415 *Err = ErrSyntax;
@@ -420,7 +420,7 @@
420420 // 0以上: 選択項目
421421 // -1: キャンセル
422422 // -2: close
423- ret = OpenListDlg(tc::fromUtf8(Str1), tc::fromUtf8(Str2), s, sel);
423+ ret = OpenListDlg(wc::fromUtf8(Str1), wc::fromUtf8(Str2), s, sel);
424424
425425 for (i = 0 ; i < ary_size ; i++) {
426426 free((void *)s[i]);
--- branches/unicode_macro/teraterm/ttpmacro/ttmdlg.cpp (revision 8624)
+++ branches/unicode_macro/teraterm/ttpmacro/ttmdlg.cpp (revision 8625)
@@ -238,7 +238,7 @@
238238 return ErrDlg.DoModal(hInst, hWndParent);
239239 }
240240
241-int OpenMsgDlg(const TCHAR *Text, const TCHAR *Caption, BOOL YesNo)
241+int OpenMsgDlg(const wchar_t *Text, const wchar_t *Caption, BOOL YesNo)
242242 {
243243 HINSTANCE hInst = GetInstance();
244244 HWND hWndParent = GetHWND();
@@ -283,7 +283,7 @@
283283 * @retval -1 cancelボタン
284284 * @retval -2 closeボタン
285285 */
286-int OpenListDlg(const TCHAR *Text, const TCHAR *Caption, TCHAR **Lists, int Selected)
286+int OpenListDlg(const wchar_t *Text, const wchar_t *Caption, wchar_t **Lists, int Selected)
287287 {
288288 HINSTANCE hInst = GetInstance();
289289 HWND hWndParent = GetHWND();
--- branches/unicode_macro/teraterm/ttpmacro/ttmdlg.h (revision 8624)
+++ branches/unicode_macro/teraterm/ttpmacro/ttmdlg.h (revision 8625)
@@ -43,12 +43,12 @@
4343 void OpenInpDlg(TCHAR *Input, const TCHAR *Text, const TCHAR *Caption,
4444 const TCHAR *Default, BOOL Paswd);
4545 int OpenErrDlg(const char *Msg, const char *Line, int lineno, int start, int end, const char *FileName);
46-int OpenMsgDlg(const TCHAR *Text, const TCHAR *Caption, BOOL YesNo);
46+int OpenMsgDlg(const wchar_t *Text, const wchar_t *Caption, BOOL YesNo);
4747 void OpenStatDlg(const TCHAR *Text, const TCHAR *Caption);
4848 void CloseStatDlg();
4949 void BringupStatDlg();
5050
51-int OpenListDlg(const TCHAR *Text, const TCHAR *Caption, TCHAR **Lists, int Selected);
51+int OpenListDlg(const wchar_t *Text, const wchar_t *Caption, wchar_t **Lists, int Selected);
5252
5353 extern char HomeDir[MAX_PATH];
5454 extern char FileName[MAX_PATH];
--- branches/unicode_macro/teraterm/ttpmacro/ttmlib.c (revision 8624)
+++ branches/unicode_macro/teraterm/ttpmacro/ttmlib.c (revision 8625)
@@ -101,7 +101,7 @@
101101 Temp[0] = 0x20;
102102 Temp[1] = 0;
103103 }
104- dwExt = GetTabbedTextExtent(DC,Temp,strlen(Temp),0,NULL);
104+ dwExt = GetTabbedTextExtent(DC,Temp, (int)strlen(Temp),0,NULL);
105105 s->cx = LOWORD(dwExt);
106106 s->cy = HIWORD(dwExt);
107107 if (s->cx > W) W = s->cx;
@@ -123,6 +123,56 @@
123123 ReleaseDC(hWnd, DC);
124124 }
125125
126+void CalcTextExtentW(HWND hWnd, HFONT hFont, const wchar_t *Text, LPSIZE s)
127+{
128+ HDC DC = GetDC(hWnd);
129+ int W, H, i, i0;
130+ wchar_t Temp[512];
131+ DWORD dwExt;
132+ HFONT prevFont;
133+ if (hFont == NULL) {
134+ hFont = (HFONT)SendMessage(hWnd, WM_GETFONT, 0, 0);
135+ }
136+ prevFont = (HFONT)SelectObject(DC, hFont);
137+
138+ W = 0;
139+ H = 0;
140+ i = 0;
141+ do {
142+ i0 = i;
143+ while ((Text[i]!=0) &&
144+ (Text[i]!=0x0d) &&
145+ (Text[i]!=0x0a))
146+ i++;
147+ memcpy(Temp,&Text[i0],sizeof(wchar_t) * (i-i0));
148+ Temp[i-i0] = 0;
149+ if (Temp[0]==0)
150+ {
151+ Temp[0] = 0x20;
152+ Temp[1] = 0;
153+ }
154+ dwExt = GetTabbedTextExtentW(DC,Temp,(int)wcslen(Temp),0,NULL);
155+ s->cx = LOWORD(dwExt);
156+ s->cy = HIWORD(dwExt);
157+ if (s->cx > W) W = s->cx;
158+ H = H + s->cy;
159+ if (Text[i]!=0)
160+ {
161+ i++;
162+ if ((Text[i]==0x0a) &&
163+ (Text[i-1]==0x0d))
164+ i++;
165+ }
166+ } while (Text[i]!=0);
167+ if ((i-i0 == 0) && (H > s->cy)) H = H - s->cy;
168+ s->cx = W;
169+ s->cy = H;
170+ if (prevFont != NULL) {
171+ SelectObject(DC, prevFont);
172+ }
173+ ReleaseDC(hWnd, DC);
174+}
175+
126176 void TTMGetDir(PCHAR Dir, int destlen)
127177 {
128178 strncpy_s(Dir, destlen, CurrentDir, _TRUNCATE);
--- branches/unicode_macro/teraterm/ttpmacro/ttmlib.h (revision 8624)
+++ branches/unicode_macro/teraterm/ttpmacro/ttmlib.h (revision 8625)
@@ -40,6 +40,7 @@
4040 extern char UILanguageFile[MAX_PATH];
4141
4242 void CalcTextExtent(HWND hWnd, HFONT Font, const char *Text, LPSIZE s);
43+void CalcTextExtentW(HWND hWnd, HFONT Font, const wchar_t *Text, LPSIZE s);
4344 void TTMGetDir(PCHAR Dir, int destlen);
4445 void TTMSetDir(PCHAR Dir);
4546 int GetAbsPath(PCHAR FName, int destlen);
旧リポジトリブラウザで表示