Develop and Download Open Source Software

Browse Subversion Repository

Contents of /branches/ttcomtester/teraterm/teraterm/coding_pp.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 10521 - (show annotations) (download) (as text)
Fri Jan 20 16:03:38 2023 UTC (13 months, 2 weeks ago) by zmatsuo
File MIME type: text/x-c++src
File size: 11713 byte(s)
add communication test tool
1 /*
2 * (C) 2020- TeraTerm Project
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * 3. The name of the author may not be used to endorse or promote products
15 * derived from this software without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS OR
18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 * IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY DIRECT, INDIRECT,
21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28
29 /* coding property page */
30
31 #include <stdio.h>
32 #define _CRTDBG_MAP_ALLOC
33 #include <stdlib.h>
34 #include <crtdbg.h>
35 #include <assert.h>
36
37 #include "tttypes.h"
38 #include "coding_pp_res.h"
39 #include "dlglib.h"
40 #include "compat_win.h"
41 #include "setting.h"
42 #include "helpid.h"
43 #include "ttlib_charset.h"
44
45 #include "coding_pp.h"
46
47 // �e���v���[�g�������������s��
48 #define REWRITE_TEMPLATE
49
50 static const char *KanjiInList[] = {"^[$@","^[$B",NULL};
51 static const char *KanjiOutList[] = {"^[(B","^[(J",NULL};
52 static const char *KanjiOutList2[] = {"^[(B","^[(J","^[(H",NULL};
53 static const char *CellWidthList[] = { "1 Cell", "2 Cell", NULL };
54
55 struct CodingPPData {
56 TTTSet *pts;
57 const char *UILanguageFile;
58 DLGTEMPLATE *dlg_templ;
59 };
60
61 static INT_PTR CALLBACK Proc(HWND hWnd, UINT msg, WPARAM wp, LPARAM lp)
62 {
63 static const DlgTextInfo TextInfos[] = {
64 {0, "DLG_GEN_TITLE"},
65 {IDC_GENLANGLABEL, "DLG_GEN_LANG"},
66 // { IDC_TERMKANJILABEL, "DLG_TERM_KANJI" },
67 {IDC_TERMKANJILABEL, "DLG_TERMK_KANJI"},
68 {IDC_TERMKANA, "DLG_TERM_KANA"},
69 {IDC_TERMKANJISENDLABEL, "DLG_TERMK_KANJISEND"},
70 // { IDC_TERMKANASEND, "DLG_TERM_KANASEND" },
71 {IDC_TERMKANASEND, "DLG_TERM_KANASEND"},
72 {IDC_TERMKINTEXT, "DLG_TERM_KIN"},
73 {IDC_TERMKOUTTEXT, "DLG_TERM_KOUT"},
74 };
75 CodingPPData *DlgData = (CodingPPData *)GetWindowLongPtr(hWnd, DWLP_USER);
76
77 switch (msg) {
78 case WM_INITDIALOG: {
79 DlgData = (CodingPPData *)(((PROPSHEETPAGEW_V1 *)lp)->lParam);
80 const TTTSet *ts = DlgData->pts;
81 SetWindowLongPtr(hWnd, DWLP_USER, (LONG_PTR)DlgData);
82 SetDlgTextsW(hWnd, TextInfos, _countof(TextInfos), DlgData->pts->UILanguageFileW);
83
84 int recv_index = 0;
85 int send_index = 0;
86 for (int i = 0;; i++) {
87 const TKanjiList *p = GetKanjiList(i);
88 if (p == NULL) {
89 break;
90 }
91 int id = p->lang * 100 + p->coding;
92 int index =
93 (int)SendDlgItemMessageA(hWnd, IDC_TERMKANJI, CB_ADDSTRING, 0, (LPARAM)p->CodeName);
94 SendDlgItemMessageA(hWnd, IDC_TERMKANJI, CB_SETITEMDATA, index, id);
95 if (ts->Language == p->lang && ts->KanjiCode == p->coding) {
96 recv_index = i;
97 }
98
99 index =
100 (int)SendDlgItemMessageA(hWnd, IDC_TERMKANJISEND, CB_ADDSTRING, 0, (LPARAM)p->CodeName);
101 SendDlgItemMessageA(hWnd, IDC_TERMKANJISEND, CB_SETITEMDATA, index, id);
102 if (ts->Language == p->lang && ts->KanjiCodeSend == p->coding) {
103 send_index = i;
104 }
105 }
106 ExpandCBWidth(hWnd, IDC_TERMKANJI);
107 ExpandCBWidth(hWnd, IDC_TERMKANJISEND);
108 SendDlgItemMessageA(hWnd, IDC_TERMKANJI, CB_SETCURSEL, recv_index, 0);
109 SendDlgItemMessageA(hWnd, IDC_TERMKANJISEND, CB_SETCURSEL, send_index, 0);
110
111 if (recv_index == send_index) {
112 CheckDlgButton(hWnd, IDC_USE_SAME_CODE, BST_CHECKED);
113 EnableWindow(GetDlgItem(hWnd, IDC_TERMKANJISEND), FALSE);
114 }
115
116 if (ts->KanjiCode != IdJIS) {
117 DisableDlgItem(hWnd, IDC_TERMKANA, IDC_TERMKANA);
118 }
119 if (ts->KanjiCodeSend != IdJIS) {
120 DisableDlgItem(hWnd, IDC_TERMKANASEND, IDC_TERMKOUT);
121 }
122
123 SetRB(hWnd, ts->JIS7Katakana, IDC_TERMKANA, IDC_TERMKANA);
124 SetRB(hWnd, ts->JIS7KatakanaSend, IDC_TERMKANASEND, IDC_TERMKANASEND);
125
126 {
127 const char **kanji_out_list;
128 int n;
129 n = ts->KanjiIn;
130 n = (n <= 0 || 2 < n) ? IdKanjiInB : n;
131 SetDropDownList(hWnd, IDC_TERMKIN, KanjiInList, n);
132
133 kanji_out_list = (ts->TermFlag & TF_ALLOWWRONGSEQUENCE) ? KanjiOutList2 : KanjiOutList;
134 n = ts->KanjiOut;
135 n = (n <= 0 || 3 < n) ? IdKanjiOutB : n;
136 SetDropDownList(hWnd, IDC_TERMKOUT, kanji_out_list, n);
137 }
138
139 // characters as wide
140 SetDropDownList(hWnd, IDC_AMBIGUOUS_WIDTH_COMBO, CellWidthList, ts->UnicodeAmbiguousWidth == 1 ? 1 : 2);
141 CheckDlgButton(hWnd, IDC_EMOJI_WIDTH_CHECK, ts->UnicodeEmojiOverride ? BST_CHECKED : BST_UNCHECKED);
142 SetDropDownList(hWnd, IDC_EMOJI_WIDTH_COMBO, CellWidthList, ts->UnicodeEmojiWidth == 1 ? 1 : 2);
143 EnableWindow(GetDlgItem(hWnd, IDC_EMOJI_WIDTH_COMBO), ts->UnicodeEmojiOverride);
144
145 return TRUE;
146 }
147 case WM_NOTIFY: {
148 NMHDR *nmhdr = (NMHDR *)lp;
149 switch (nmhdr->code) {
150 case PSN_APPLY: {
151 TTTSet *ts = DlgData->pts;
152
153 ts->JIS7KatakanaSend = 0;
154 ts->JIS7Katakana = 0;
155 ts->KanjiIn = 0;
156 ts->KanjiOut = 0;
157
158 // ���M�R�[�h
159 int curPos = (int)SendDlgItemMessageA(hWnd, IDC_TERMKANJI, CB_GETCURSEL, 0, 0);
160 int id = (int)SendDlgItemMessageA(hWnd, IDC_TERMKANJI, CB_GETITEMDATA, curPos, 0);
161 int lang = id / 100;
162 int coding = id % 100;
163 ts->Language = lang;
164 ts->KanjiCode = coding;
165 if (coding == IdUTF8 && (lang == IdJapanese || lang == IdKorean || lang == IdChinese || lang == IdUtf8)) {
166 ;
167 }
168 else if (lang == IdJapanese && (coding == IdSJIS || coding == IdEUC || coding == IdJIS)) {
169 if (coding == IdJIS) {
170 ts->JIS7Katakana = (IsDlgButtonChecked(hWnd, IDC_TERMKANA) == BST_CHECKED);
171 ts->JIS7KatakanaSend = (IsDlgButtonChecked(hWnd, IDC_TERMKANASEND) == BST_CHECKED);
172 WORD w = (WORD)GetCurSel(hWnd, IDC_TERMKIN);
173 if (w > 0) {
174 ts->KanjiIn = w;
175 }
176 w = (WORD)GetCurSel(hWnd, IDC_TERMKOUT);
177 if (w > 0) {
178 ts->KanjiOut = w;
179 }
180 }
181 }
182 else if (lang == IdRussian &&
183 (coding == IdWindows || coding == IdKOI8 || coding == Id866 || coding == IdISO)) {
184 }
185 else if (lang == IdKorean && coding == IdKoreanCP51949) {
186 ;
187 }
188 else if (lang == IdChinese && (coding == IdCnGB2312 || coding == IdCnBig5)) {
189 ;
190 }
191 else if (lang == IdEnglish) {
192 ;
193 }
194 else {
195 assert(FALSE);
196 }
197
198 // ���M�R�[�h
199 curPos = (int)SendDlgItemMessageA(hWnd, IDC_TERMKANJISEND, CB_GETCURSEL, 0, 0);
200 id = (int)SendDlgItemMessageA(hWnd, IDC_TERMKANJISEND, CB_GETITEMDATA, curPos, 0);
201 coding = id % 100;
202 ts->KanjiCodeSend = coding;
203
204 // characters as wide
205 ts->UnicodeAmbiguousWidth = (BYTE)GetCurSel(hWnd, IDC_AMBIGUOUS_WIDTH_COMBO);
206 ts->UnicodeEmojiOverride = (BYTE)IsDlgButtonChecked(hWnd, IDC_EMOJI_WIDTH_CHECK);
207 ts->UnicodeEmojiWidth = (BYTE)GetCurSel(hWnd, IDC_EMOJI_WIDTH_COMBO);
208
209 break;
210 }
211 case PSN_HELP: {
212 HWND vtwin = GetParent(hWnd);
213 vtwin = GetParent(vtwin);
214 PostMessage(vtwin, WM_USER_DLGHELP2, HlpMenuSetupAdditionalCoding, 0);
215 break;
216 }
217 default:
218 break;
219 }
220 break;
221 }
222 case WM_COMMAND: {
223 switch (wp) {
224 case IDC_TERMKANJI | (CBN_SELCHANGE << 16): {
225 // ���M�R�[�h
226 int curPos = (int)SendDlgItemMessageA(hWnd, IDC_TERMKANJI, CB_GETCURSEL, 0, 0);
227 int id = (int)SendDlgItemMessageA(hWnd, IDC_TERMKANJI, CB_GETITEMDATA, curPos, 0);
228 if (id == IdJapanese * 100 + IdJIS) {
229 EnableDlgItem(hWnd, IDC_TERMKANA, IDC_TERMKANA);
230 }
231 else {
232 DisableDlgItem(hWnd, IDC_TERMKANA, IDC_TERMKANA);
233 }
234 if ((id / 100) == IdChinese || (id / 100) == IdJapanese || (id / 100) == IdKorean) {
235 // CJK
236 SendDlgItemMessage(hWnd, IDC_AMBIGUOUS_WIDTH_COMBO, CB_SETCURSEL, 1, 0);
237 CheckDlgButton(hWnd, IDC_EMOJI_WIDTH_CHECK, BST_CHECKED);
238 EnableWindow(GetDlgItem(hWnd, IDC_EMOJI_WIDTH_COMBO), TRUE);
239 SendDlgItemMessage(hWnd, IDC_EMOJI_WIDTH_COMBO, CB_SETCURSEL, 1, 0);
240 }
241 else {
242 CheckDlgButton(hWnd, IDC_EMOJI_WIDTH_CHECK, BST_UNCHECKED);
243 SendDlgItemMessage(hWnd, IDC_AMBIGUOUS_WIDTH_COMBO, CB_SETCURSEL, 0, 0);
244 EnableWindow(GetDlgItem(hWnd, IDC_EMOJI_WIDTH_COMBO), FALSE);
245 }
246
247 if (IsDlgButtonChecked(hWnd, IDC_USE_SAME_CODE) == BST_CHECKED) {
248 // ���M�R�[�h�������l������
249 SendDlgItemMessageA(hWnd, IDC_TERMKANJISEND, CB_SETCURSEL, curPos, 0);
250 goto kanji_send_selchange;
251 }
252 break;
253 }
254 case IDC_TERMKANJISEND | (CBN_SELCHANGE << 16): {
255 kanji_send_selchange:
256 // ���M�R�[�h
257 int curPos = (int)SendDlgItemMessageA(hWnd, IDC_TERMKANJISEND, CB_GETCURSEL, 0, 0);
258 int id = (int)SendDlgItemMessageA(hWnd, IDC_TERMKANJISEND, CB_GETITEMDATA, curPos, 0);
259 if (id == IdJapanese * 100 + IdJIS) {
260 EnableDlgItem(hWnd, IDC_TERMKANASEND, IDC_TERMKOUT);
261 }
262 else {
263 DisableDlgItem(hWnd, IDC_TERMKANASEND, IDC_TERMKOUT);
264 }
265 break;
266 }
267 case IDC_USE_SAME_CODE | (BN_CLICKED << 16): {
268 BOOL enable = (IsDlgButtonChecked(hWnd, IDC_USE_SAME_CODE) == BST_CHECKED) ? FALSE : TRUE;
269 EnableWindow(GetDlgItem(hWnd, IDC_TERMKANJISEND), enable);
270 break;
271 }
272 case IDC_EMOJI_WIDTH_CHECK | (BN_CLICKED << 16): {
273 BOOL enable = (IsDlgButtonChecked(hWnd, IDC_EMOJI_WIDTH_CHECK) == BST_CHECKED) ? TRUE : FALSE;
274 EnableWindow(GetDlgItem(hWnd, IDC_EMOJI_WIDTH_COMBO), enable);
275 break;
276 }
277 default:
278 break;
279 }
280 break;
281 }
282 default:
283 return FALSE;
284 }
285 return FALSE;
286 }
287
288 static UINT CALLBACK CallBack(HWND hwnd, UINT uMsg, struct _PROPSHEETPAGEW *ppsp)
289 {
290 (void)hwnd;
291 UINT ret_val = 0;
292 switch (uMsg) {
293 case PSPCB_CREATE:
294 ret_val = 1;
295 break;
296 case PSPCB_RELEASE:
297 free((void *)ppsp->pResource);
298 ppsp->pResource = NULL;
299 free((void *)ppsp->lParam);
300 ppsp->lParam = NULL;
301 break;
302 default:
303 break;
304 }
305 return ret_val;
306 }
307
308 HPROPSHEETPAGE CodingPageCreate(HINSTANCE inst, TTTSet *pts)
309 {
310 // �� common/tt_res.h �� coding_pp_res.h ���l�����v����������
311 int id = IDD_TABSHEET_CODING;
312
313 CodingPPData *Param = (CodingPPData *)calloc(sizeof(CodingPPData), 1);
314 Param->UILanguageFile = pts->UILanguageFile;
315 Param->pts = pts;
316
317 PROPSHEETPAGEW_V1 psp = {};
318 psp.dwSize = sizeof(psp);
319 psp.dwFlags = PSP_DEFAULT | PSP_USECALLBACK | PSP_USETITLE | PSP_HASHELP;
320 psp.hInstance = inst;
321 psp.pfnCallback = CallBack;
322 psp.pszTitle = L"coding"; // TODO lng �t�@�C����������
323 psp.pszTemplate = MAKEINTRESOURCEW(id);
324 #if defined(REWRITE_TEMPLATE)
325 psp.dwFlags |= PSP_DLGINDIRECT;
326 Param->dlg_templ = TTGetDlgTemplate(inst, MAKEINTRESOURCEA(id));
327 psp.pResource = Param->dlg_templ;
328 #endif
329
330 psp.pfnDlgProc = Proc;
331 psp.lParam = (LPARAM)Param;
332
333 HPROPSHEETPAGE hpsp = CreatePropertySheetPageW((LPCPROPSHEETPAGEW)&psp);
334 return hpsp;
335 }

Back to OSDN">Back to OSDN
ViewVC Help
Powered by ViewVC 1.1.26