Develop and Download Open Source Software

Browse Subversion Repository

Annotation of /trunk/teraterm/teraterm/coding_pp.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 10805 - (hide annotations) (download) (as text)
Sun Jul 23 07:07:29 2023 UTC (8 months, 2 weeks ago) by zmatsuo
File MIME type: text/x-c++src
File size: 13014 byte(s)
DEC特殊文字をUnicodeへマッピングできるようにした

- DEC特殊文字をUnicodeで置き換えるコードを追加
- codingタブにDEC特殊文字に関する設定を追加
1 zmatsuo 8767 /*
2 nmaya 9048 * (C) 2020- TeraTerm Project
3 zmatsuo 8767 * 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 zmatsuo 8800 #include "helpid.h"
43 zmatsuo 9499 #include "ttlib_charset.h"
44 zmatsuo 8767
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 zmatsuo 8798 static const char *CellWidthList[] = { "1 Cell", "2 Cell", NULL };
54 zmatsuo 8767
55     struct CodingPPData {
56     TTTSet *pts;
57 zmatsuo 10614 const wchar_t *UILanguageFileW;
58 zmatsuo 8769 DLGTEMPLATE *dlg_templ;
59 zmatsuo 8767 };
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 zmatsuo 8798 {IDC_TERMKANASEND, "DLG_TERM_KANASEND"},
72 zmatsuo 8767 {IDC_TERMKINTEXT, "DLG_TERM_KIN"},
73     {IDC_TERMKOUTTEXT, "DLG_TERM_KOUT"},
74 zmatsuo 10805 { IDC_UNICODE2DEC, "DLG_CODING_UNICODE_TO_DEC" },
75     { IDC_DEC2UNICODE, "DLG_CODING_DEC_TO_UNICODE" },
76     { IDC_DEC2UNICODE_BOXDRAWING, "DLG_CODING_UNICODE_TO_DEC_BOXDRAWING" },
77     { IDC_DEC2UNICODE_PUNCTUATION, "DLG_CODING_UNICODE_TO_DEC_PUNCTUATION" },
78     { IDC_DEC2UNICODE_MIDDLEDOT, "DLG_CODING_UNICODE_TO_DEC_MIDDLEDOT" },
79 zmatsuo 8767 };
80     CodingPPData *DlgData = (CodingPPData *)GetWindowLongPtr(hWnd, DWLP_USER);
81    
82     switch (msg) {
83     case WM_INITDIALOG: {
84     DlgData = (CodingPPData *)(((PROPSHEETPAGEW_V1 *)lp)->lParam);
85 zmatsuo 8769 const TTTSet *ts = DlgData->pts;
86 zmatsuo 8767 SetWindowLongPtr(hWnd, DWLP_USER, (LONG_PTR)DlgData);
87 zmatsuo 9359 SetDlgTextsW(hWnd, TextInfos, _countof(TextInfos), DlgData->pts->UILanguageFileW);
88 zmatsuo 8767
89     int recv_index = 0;
90     int send_index = 0;
91 zmatsuo 9499 for (int i = 0;; i++) {
92     const TKanjiList *p = GetKanjiList(i);
93     if (p == NULL) {
94     break;
95     }
96     int id = p->lang * 100 + p->coding;
97 zmatsuo 8767 int index =
98 zmatsuo 9499 (int)SendDlgItemMessageA(hWnd, IDC_TERMKANJI, CB_ADDSTRING, 0, (LPARAM)p->CodeName);
99 zmatsuo 8767 SendDlgItemMessageA(hWnd, IDC_TERMKANJI, CB_SETITEMDATA, index, id);
100 zmatsuo 9499 if (ts->Language == p->lang && ts->KanjiCode == p->coding) {
101 zmatsuo 8767 recv_index = i;
102     }
103    
104     index =
105 zmatsuo 9499 (int)SendDlgItemMessageA(hWnd, IDC_TERMKANJISEND, CB_ADDSTRING, 0, (LPARAM)p->CodeName);
106 zmatsuo 8767 SendDlgItemMessageA(hWnd, IDC_TERMKANJISEND, CB_SETITEMDATA, index, id);
107 zmatsuo 9499 if (ts->Language == p->lang && ts->KanjiCodeSend == p->coding) {
108 zmatsuo 8767 send_index = i;
109     }
110     }
111     ExpandCBWidth(hWnd, IDC_TERMKANJI);
112     ExpandCBWidth(hWnd, IDC_TERMKANJISEND);
113     SendDlgItemMessageA(hWnd, IDC_TERMKANJI, CB_SETCURSEL, recv_index, 0);
114     SendDlgItemMessageA(hWnd, IDC_TERMKANJISEND, CB_SETCURSEL, send_index, 0);
115    
116     if (recv_index == send_index) {
117     CheckDlgButton(hWnd, IDC_USE_SAME_CODE, BST_CHECKED);
118     EnableWindow(GetDlgItem(hWnd, IDC_TERMKANJISEND), FALSE);
119     }
120    
121     if (ts->KanjiCode != IdJIS) {
122     DisableDlgItem(hWnd, IDC_TERMKANA, IDC_TERMKANA);
123     }
124     if (ts->KanjiCodeSend != IdJIS) {
125     DisableDlgItem(hWnd, IDC_TERMKANASEND, IDC_TERMKOUT);
126     }
127    
128     SetRB(hWnd, ts->JIS7Katakana, IDC_TERMKANA, IDC_TERMKANA);
129     SetRB(hWnd, ts->JIS7KatakanaSend, IDC_TERMKANASEND, IDC_TERMKANASEND);
130    
131 zmatsuo 9897 {
132     const char **kanji_out_list;
133     int n;
134     n = ts->KanjiIn;
135     n = (n <= 0 || 2 < n) ? IdKanjiInB : n;
136     SetDropDownList(hWnd, IDC_TERMKIN, KanjiInList, n);
137    
138     kanji_out_list = (ts->TermFlag & TF_ALLOWWRONGSEQUENCE) ? KanjiOutList2 : KanjiOutList;
139     n = ts->KanjiOut;
140     n = (n <= 0 || 3 < n) ? IdKanjiOutB : n;
141     SetDropDownList(hWnd, IDC_TERMKOUT, kanji_out_list, n);
142 zmatsuo 8767 }
143    
144 zmatsuo 8798 // characters as wide
145     SetDropDownList(hWnd, IDC_AMBIGUOUS_WIDTH_COMBO, CellWidthList, ts->UnicodeAmbiguousWidth == 1 ? 1 : 2);
146     CheckDlgButton(hWnd, IDC_EMOJI_WIDTH_CHECK, ts->UnicodeEmojiOverride ? BST_CHECKED : BST_UNCHECKED);
147     SetDropDownList(hWnd, IDC_EMOJI_WIDTH_COMBO, CellWidthList, ts->UnicodeEmojiWidth == 1 ? 1 : 2);
148     EnableWindow(GetDlgItem(hWnd, IDC_EMOJI_WIDTH_COMBO), ts->UnicodeEmojiOverride);
149 zmatsuo 8767
150 zmatsuo 10805 // DEC Special Graphics
151     CheckDlgButton(hWnd, IDC_UNICODE2DEC, ts->Dec2Unicode ? BST_UNCHECKED : BST_CHECKED);
152     CheckDlgButton(hWnd, IDC_DEC2UNICODE, ts->Dec2Unicode ? BST_CHECKED : BST_UNCHECKED);
153     CheckDlgButton(hWnd, IDC_DEC2UNICODE_BOXDRAWING,
154     (ts->UnicodeDecSpMapping & 0x01) != 0 ? BST_CHECKED : BST_UNCHECKED);
155     CheckDlgButton(hWnd, IDC_DEC2UNICODE_PUNCTUATION,
156     (ts->UnicodeDecSpMapping & 0x02) != 0 ? BST_CHECKED : BST_UNCHECKED);
157     CheckDlgButton(hWnd, IDC_DEC2UNICODE_MIDDLEDOT,
158     (ts->UnicodeDecSpMapping & 0x04) != 0 ? BST_CHECKED : BST_UNCHECKED);
159    
160 zmatsuo 8767 return TRUE;
161     }
162     case WM_NOTIFY: {
163     NMHDR *nmhdr = (NMHDR *)lp;
164     switch (nmhdr->code) {
165     case PSN_APPLY: {
166 zmatsuo 8769 TTTSet *ts = DlgData->pts;
167    
168 zmatsuo 8767 ts->JIS7KatakanaSend = 0;
169     ts->JIS7Katakana = 0;
170     ts->KanjiIn = 0;
171     ts->KanjiOut = 0;
172    
173     // ���M�R�[�h
174     int curPos = (int)SendDlgItemMessageA(hWnd, IDC_TERMKANJI, CB_GETCURSEL, 0, 0);
175     int id = (int)SendDlgItemMessageA(hWnd, IDC_TERMKANJI, CB_GETITEMDATA, curPos, 0);
176     int lang = id / 100;
177     int coding = id % 100;
178     ts->Language = lang;
179     ts->KanjiCode = coding;
180     if (coding == IdUTF8 && (lang == IdJapanese || lang == IdKorean || lang == IdChinese || lang == IdUtf8)) {
181     ;
182     }
183     else if (lang == IdJapanese && (coding == IdSJIS || coding == IdEUC || coding == IdJIS)) {
184     if (coding == IdJIS) {
185     ts->JIS7Katakana = (IsDlgButtonChecked(hWnd, IDC_TERMKANA) == BST_CHECKED);
186     ts->JIS7KatakanaSend = (IsDlgButtonChecked(hWnd, IDC_TERMKANASEND) == BST_CHECKED);
187 zmatsuo 8769 WORD w = (WORD)GetCurSel(hWnd, IDC_TERMKIN);
188     if (w > 0) {
189 zmatsuo 8767 ts->KanjiIn = w;
190     }
191 zmatsuo 8769 w = (WORD)GetCurSel(hWnd, IDC_TERMKOUT);
192     if (w > 0) {
193 zmatsuo 8767 ts->KanjiOut = w;
194     }
195     }
196     }
197     else if (lang == IdRussian &&
198     (coding == IdWindows || coding == IdKOI8 || coding == Id866 || coding == IdISO)) {
199     }
200 zmatsuo 10768 else if (lang == IdKorean && coding == IdKoreanCP949) {
201 zmatsuo 8767 ;
202     }
203     else if (lang == IdChinese && (coding == IdCnGB2312 || coding == IdCnBig5)) {
204     ;
205     }
206 zmatsuo 9598 else if (lang == IdEnglish) {
207 zmatsuo 8767 ;
208     }
209     else {
210     assert(FALSE);
211     }
212    
213     // ���M�R�[�h
214     curPos = (int)SendDlgItemMessageA(hWnd, IDC_TERMKANJISEND, CB_GETCURSEL, 0, 0);
215     id = (int)SendDlgItemMessageA(hWnd, IDC_TERMKANJISEND, CB_GETITEMDATA, curPos, 0);
216     coding = id % 100;
217     ts->KanjiCodeSend = coding;
218    
219 zmatsuo 8798 // characters as wide
220     ts->UnicodeAmbiguousWidth = (BYTE)GetCurSel(hWnd, IDC_AMBIGUOUS_WIDTH_COMBO);
221     ts->UnicodeEmojiOverride = (BYTE)IsDlgButtonChecked(hWnd, IDC_EMOJI_WIDTH_CHECK);
222     ts->UnicodeEmojiWidth = (BYTE)GetCurSel(hWnd, IDC_EMOJI_WIDTH_COMBO);
223 zmatsuo 8767
224 zmatsuo 10805 // DEC Special Graphics
225     ts->Dec2Unicode = (BYTE)IsDlgButtonChecked(hWnd, IDC_DEC2UNICODE);
226     ts->UnicodeDecSpMapping =
227     (WORD)((IsDlgButtonChecked(hWnd, IDC_DEC2UNICODE_BOXDRAWING) << 0) |
228     (IsDlgButtonChecked(hWnd, IDC_DEC2UNICODE_PUNCTUATION) << 1) |
229     (IsDlgButtonChecked(hWnd, IDC_DEC2UNICODE_MIDDLEDOT) << 2));
230 zmatsuo 8767 break;
231     }
232 zmatsuo 8800 case PSN_HELP: {
233     HWND vtwin = GetParent(hWnd);
234     vtwin = GetParent(vtwin);
235     PostMessage(vtwin, WM_USER_DLGHELP2, HlpMenuSetupAdditionalCoding, 0);
236 zmatsuo 8767 break;
237 zmatsuo 8800 }
238 zmatsuo 8767 default:
239     break;
240     }
241     break;
242     }
243     case WM_COMMAND: {
244     switch (wp) {
245     case IDC_TERMKANJI | (CBN_SELCHANGE << 16): {
246     // ���M�R�[�h
247     int curPos = (int)SendDlgItemMessageA(hWnd, IDC_TERMKANJI, CB_GETCURSEL, 0, 0);
248     int id = (int)SendDlgItemMessageA(hWnd, IDC_TERMKANJI, CB_GETITEMDATA, curPos, 0);
249     if (id == IdJapanese * 100 + IdJIS) {
250     EnableDlgItem(hWnd, IDC_TERMKANA, IDC_TERMKANA);
251     }
252     else {
253     DisableDlgItem(hWnd, IDC_TERMKANA, IDC_TERMKANA);
254     }
255 zmatsuo 8798 if ((id / 100) == IdChinese || (id / 100) == IdJapanese || (id / 100) == IdKorean) {
256     // CJK
257     SendDlgItemMessage(hWnd, IDC_AMBIGUOUS_WIDTH_COMBO, CB_SETCURSEL, 1, 0);
258     CheckDlgButton(hWnd, IDC_EMOJI_WIDTH_CHECK, BST_CHECKED);
259     EnableWindow(GetDlgItem(hWnd, IDC_EMOJI_WIDTH_COMBO), TRUE);
260     SendDlgItemMessage(hWnd, IDC_EMOJI_WIDTH_COMBO, CB_SETCURSEL, 1, 0);
261 zmatsuo 8767 }
262 zmatsuo 8798 else {
263     CheckDlgButton(hWnd, IDC_EMOJI_WIDTH_CHECK, BST_UNCHECKED);
264     SendDlgItemMessage(hWnd, IDC_AMBIGUOUS_WIDTH_COMBO, CB_SETCURSEL, 0, 0);
265     EnableWindow(GetDlgItem(hWnd, IDC_EMOJI_WIDTH_COMBO), FALSE);
266     }
267 zmatsuo 8767
268     if (IsDlgButtonChecked(hWnd, IDC_USE_SAME_CODE) == BST_CHECKED) {
269     // ���M�R�[�h�������l������
270     SendDlgItemMessageA(hWnd, IDC_TERMKANJISEND, CB_SETCURSEL, curPos, 0);
271     goto kanji_send_selchange;
272     }
273     break;
274     }
275     case IDC_TERMKANJISEND | (CBN_SELCHANGE << 16): {
276     kanji_send_selchange:
277     // ���M�R�[�h
278     int curPos = (int)SendDlgItemMessageA(hWnd, IDC_TERMKANJISEND, CB_GETCURSEL, 0, 0);
279     int id = (int)SendDlgItemMessageA(hWnd, IDC_TERMKANJISEND, CB_GETITEMDATA, curPos, 0);
280     if (id == IdJapanese * 100 + IdJIS) {
281     EnableDlgItem(hWnd, IDC_TERMKANASEND, IDC_TERMKOUT);
282     }
283     else {
284     DisableDlgItem(hWnd, IDC_TERMKANASEND, IDC_TERMKOUT);
285     }
286     break;
287     }
288     case IDC_USE_SAME_CODE | (BN_CLICKED << 16): {
289     BOOL enable = (IsDlgButtonChecked(hWnd, IDC_USE_SAME_CODE) == BST_CHECKED) ? FALSE : TRUE;
290     EnableWindow(GetDlgItem(hWnd, IDC_TERMKANJISEND), enable);
291 zmatsuo 8798 break;
292 zmatsuo 8767 }
293 zmatsuo 8798 case IDC_EMOJI_WIDTH_CHECK | (BN_CLICKED << 16): {
294     BOOL enable = (IsDlgButtonChecked(hWnd, IDC_EMOJI_WIDTH_CHECK) == BST_CHECKED) ? TRUE : FALSE;
295     EnableWindow(GetDlgItem(hWnd, IDC_EMOJI_WIDTH_COMBO), enable);
296     break;
297     }
298 zmatsuo 8767 default:
299     break;
300     }
301     break;
302     }
303     default:
304     return FALSE;
305     }
306     return FALSE;
307     }
308    
309 zmatsuo 9936 static UINT CALLBACK CallBack(HWND hwnd, UINT uMsg, struct _PROPSHEETPAGEW *ppsp)
310 zmatsuo 9923 {
311     (void)hwnd;
312     UINT ret_val = 0;
313     switch (uMsg) {
314     case PSPCB_CREATE:
315     ret_val = 1;
316     break;
317     case PSPCB_RELEASE:
318     free((void *)ppsp->pResource);
319     ppsp->pResource = NULL;
320     free((void *)ppsp->lParam);
321     ppsp->lParam = NULL;
322     break;
323     default:
324     break;
325     }
326     return ret_val;
327     }
328    
329 zmatsuo 8767 HPROPSHEETPAGE CodingPageCreate(HINSTANCE inst, TTTSet *pts)
330     {
331     // �� common/tt_res.h �� coding_pp_res.h ���l�����v����������
332     int id = IDD_TABSHEET_CODING;
333    
334 zmatsuo 8769 CodingPPData *Param = (CodingPPData *)calloc(sizeof(CodingPPData), 1);
335 zmatsuo 10614 Param->UILanguageFileW = pts->UILanguageFileW;
336 zmatsuo 8767 Param->pts = pts;
337    
338     PROPSHEETPAGEW_V1 psp = {};
339     psp.dwSize = sizeof(psp);
340 zmatsuo 9923 psp.dwFlags = PSP_DEFAULT | PSP_USECALLBACK | PSP_USETITLE | PSP_HASHELP;
341 zmatsuo 8767 psp.hInstance = inst;
342 zmatsuo 9923 psp.pfnCallback = CallBack;
343     psp.pszTitle = L"coding"; // TODO lng �t�@�C����������
344 zmatsuo 8767 psp.pszTemplate = MAKEINTRESOURCEW(id);
345     #if defined(REWRITE_TEMPLATE)
346     psp.dwFlags |= PSP_DLGINDIRECT;
347 zmatsuo 8769 Param->dlg_templ = TTGetDlgTemplate(inst, MAKEINTRESOURCEA(id));
348     psp.pResource = Param->dlg_templ;
349 zmatsuo 8767 #endif
350    
351     psp.pfnDlgProc = Proc;
352     psp.lParam = (LPARAM)Param;
353    
354 zmatsuo 9324 HPROPSHEETPAGE hpsp = CreatePropertySheetPageW((LPCPROPSHEETPAGEW)&psp);
355 zmatsuo 8767 return hpsp;
356     }

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