Develop and Download Open Source Software

Browse Subversion Repository

Annotation of /trunk/teraterm/teraterm/font_pp.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 10056 - (hide annotations) (download) (as text)
Fri Jul 15 12:59:00 2022 UTC (20 months, 3 weeks ago) by zmatsuo
File MIME type: text/x-c++src
File size: 11204 byte(s)
フォントタブのi18n化,リソースから日本語文字列削除

- lngファイルを使用するよう修正
- 日本語と英語のlngファイル修正
- レイアウト、文言変更に合わせてヘルプを修正
1 zmatsuo 8771 /*
2 nmaya 9048 * (C) 2020- TeraTerm Project
3 zmatsuo 8771 * 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     /* font 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 "font_pp_res.h"
39     #include "dlglib.h"
40     #include "setting.h"
41     #include "vtdisp.h" // for DispSetupFontDlg()
42     #include "buffer.h"
43     #include "compat_win.h" // for CF_INACTIVEFONTS
44 zmatsuo 10047 #include "helpid.h"
45 zmatsuo 8771
46     #include "font_pp.h"
47    
48     // �e���v���[�g�������������s��
49     #define REWRITE_TEMPLATE
50    
51     struct FontPPData {
52     HINSTANCE hInst;
53 zmatsuo 9549 const wchar_t *UILanguageFileW;
54 zmatsuo 8771 TTTSet *pts;
55     DLGTEMPLATE *dlg_templ;
56     // LOGFONTA VTFont;
57     LOGFONTA DlgFont;
58     };
59    
60     static void GetDlgLogFont(HWND hWnd, const TTTSet *ts, LOGFONTA *logfont)
61     {
62     memset(logfont, 0, sizeof(*logfont));
63     logfont->lfHeight = -GetFontPixelFromPoint(hWnd, ts->DialogFontPoint);
64     strncpy_s(logfont->lfFaceName, sizeof(logfont->lfFaceName),ts->DialogFontName, _TRUNCATE);
65     logfont->lfCharSet = ts->DialogFontCharSet;
66     }
67    
68     static void SetDlgLogFont(HWND hWnd, const LOGFONTA *logfont, TTTSet *ts)
69     {
70     strncpy_s(ts->DialogFontName, sizeof(ts->DialogFontName), logfont->lfFaceName, _TRUNCATE);
71     ts->DialogFontPoint = GetFontPointFromPixel(hWnd, -logfont->lfHeight);
72     ts->DialogFontCharSet = logfont->lfCharSet;
73     }
74    
75     static UINT_PTR CALLBACK TFontHook(HWND Dialog, UINT Message, WPARAM wParam, LPARAM lParam)
76     {
77     if (Message == WM_INITDIALOG) {
78     FontPPData *dlg_data = (FontPPData *)(((CHOOSEFONTA *)lParam)->lCustData);
79 zmatsuo 9549 wchar_t *uimsg;
80     static const wchar_t def[] = L"\"Font style\" selection here won't affect actual font appearance.";
81     GetI18nStrWW("Tera Term", "DLG_CHOOSEFONT_STC6", def, dlg_data->UILanguageFileW, &uimsg);
82 zmatsuo 9324 SetDlgItemTextW(Dialog, stc6, uimsg);
83 zmatsuo 9549 free(uimsg);
84 zmatsuo 8771
85     SetFocus(GetDlgItem(Dialog,cmb1));
86    
87     CenterWindow(Dialog, GetParent(Dialog));
88     }
89     return FALSE;
90     }
91    
92 zmatsuo 8832 static BOOL ChooseDlgFont(HWND hWnd, FontPPData *dlg_data)
93 zmatsuo 8771 {
94     const TTTSet *ts = dlg_data->pts;
95    
96     // �_�C�A���O�\��
97     CHOOSEFONTA cf = {};
98     cf.lStructSize = sizeof(cf);
99     cf.hwndOwner = hWnd;
100     cf.lpLogFont = &dlg_data->DlgFont;
101     cf.Flags =
102     CF_SCREENFONTS | CF_INITTOLOGFONTSTRUCT |
103     CF_SHOWHELP | CF_NOVERTFONTS |
104     CF_ENABLEHOOK;
105     if (IsWindows7OrLater() && ts->ListHiddenFonts) {
106     cf.Flags |= CF_INACTIVEFONTS;
107     }
108     cf.lpfnHook = &TFontHook;
109     cf.nFontType = REGULAR_FONTTYPE;
110     cf.hInstance = dlg_data->hInst;
111     cf.lCustData = (LPARAM)dlg_data;
112     BOOL result = ChooseFontA(&cf);
113 zmatsuo 8832 return result;
114 zmatsuo 8771 }
115    
116     static void EnableCodePage(HWND hWnd, BOOL enable)
117     {
118 zmatsuo 10056 EnableWindow(GetDlgItem(hWnd, IDC_VTFONT_CODEPAGE_LABEL), enable);
119     EnableWindow(GetDlgItem(hWnd, IDC_VTFONT_CODEPAGE_EDIT), enable);
120 zmatsuo 8771 }
121    
122     static void SetFontString(HWND hWnd, int item, const LOGFONTA *logfont)
123     {
124     // https://docs.microsoft.com/en-us/windows/win32/api/dimm/ns-dimm-logfonta
125     // http://www.coara.or.jp/~tkuri/D/015.htm#D2002-09-14
126     char b[128];
127     sprintf_s(b, "%s (%d,%d) %d", logfont->lfFaceName, logfont->lfWidth, logfont->lfHeight, logfont->lfCharSet);
128     SetDlgItemTextA(hWnd, item, b);
129     }
130    
131     static void SetVTFontString(HWND hWnd, int item, const TTTSet *ts)
132     {
133     LOGFONTA logfont = {};
134     logfont.lfWidth = ts->VTFontSize.x;
135     logfont.lfHeight = ts->VTFontSize.y;
136     strncpy_s(logfont.lfFaceName, sizeof(logfont.lfFaceName),ts->VTFont, _TRUNCATE);
137     logfont.lfCharSet = ts->VTFontCharSet;
138     SetFontString(hWnd, item, &logfont);
139     }
140    
141     static INT_PTR CALLBACK Proc(HWND hWnd, UINT msg, WPARAM wp, LPARAM lp)
142     {
143     static const DlgTextInfo TextInfos[] = {
144 zmatsuo 10056 { IDC_VTWINFONT, "DLG_TAB_FONT_VTWINFONT" },
145     { IDC_VTFONT_CHOOSE, "DLG_TAB_FONT_BTN_SELECT" },
146     { IDC_VTFONT_TITLE, "DLG_TAB_FONT_VTFONT_TITLE" },
147     { IDC_VTFONT_CODEPAGE_LABEL, "DLG_TAB_FONT_CODEPAGE_LABEL" },
148     { IDC_FONT_QUALITY_LABEL, "DLG_TAB_VISUAL_FONT_QUALITY" },
149     { IDC_DLGFONT, "DLG_TAB_FONT_DLGFONT"},
150     { IDC_DLGFONT_CHOOSE, "DLG_TAB_FONT_BTN_SELECT" },
151     { IDC_DLGFONT_DEFAULT, "DLG_TAB_FONT_BTN_DEFAULT" },
152 zmatsuo 10048 { IDC_LIST_HIDDEN_FONTS, "DLG_TAB_GENERAL_LIST_HIDDEN_FONTS" },
153 zmatsuo 10056 { IDC_LIST_PRO_FONTS, "DLG_TAB_FONT_LIST_PRO_FONTS" },
154     { IDC_CHARACTER_SPACE_TITLE, "DLG_TAB_FONT_CHARACTER_SPACE" },
155 zmatsuo 8771 };
156     FontPPData *dlg_data = (FontPPData *)GetWindowLongPtr(hWnd, DWLP_USER);
157     TTTSet *ts = dlg_data == NULL ? NULL : dlg_data->pts;
158    
159     switch (msg) {
160     case WM_INITDIALOG: {
161     dlg_data = (FontPPData *)(((PROPSHEETPAGEW_V1 *)lp)->lParam);
162     ts = dlg_data->pts;
163     SetWindowLongPtr(hWnd, DWLP_USER, (LONG_PTR)dlg_data);
164 zmatsuo 9359 SetDlgTextsW(hWnd, TextInfos, _countof(TextInfos), dlg_data->pts->UILanguageFileW);
165 zmatsuo 8771
166     GetDlgLogFont(GetParent(hWnd), ts, &dlg_data->DlgFont);
167    
168     SetVTFontString(hWnd, IDC_VTFONT_EDIT, ts);
169    
170     CheckDlgButton(hWnd,
171     UnicodeDebugParam.UseUnicodeApi ? IDC_VTFONT_UNICODE : IDC_VTFONT_ANSI,
172     BST_CHECKED);
173 zmatsuo 10056 SetDlgItemInt(hWnd, IDC_VTFONT_CODEPAGE_EDIT, UnicodeDebugParam.CodePageForANSIDraw, FALSE);
174 zmatsuo 8771 EnableCodePage(hWnd, UnicodeDebugParam.UseUnicodeApi ? FALSE : TRUE);
175    
176     CheckDlgButton(hWnd, IDC_LIST_HIDDEN_FONTS, ts->ListHiddenFonts);
177     EnableWindow(GetDlgItem(hWnd, IDC_LIST_HIDDEN_FONTS), IsWindows7OrLater() ? TRUE : FALSE);
178    
179     SetDlgItemInt(hWnd, IDC_SPACE_RIGHT, ts->FontDW, FALSE);
180     SetDlgItemInt(hWnd, IDC_SPACE_LEFT, ts->FontDH, FALSE);
181     SetDlgItemInt(hWnd, IDC_SPACE_TOP, ts->FontDX, FALSE);
182     SetDlgItemInt(hWnd, IDC_SPACE_BOTTOM, ts->FontDY, FALSE);
183    
184     const static I18nTextInfo visual_font_quality[] = {
185     { "DLG_TAB_VISUAL_FONT_QUALITY_DEFAULT", L"Default" },
186     { "DLG_TAB_VISUAL_FONT_QUALITY_NONANTIALIASED", L"Non-Antialiased" },
187     { "DLG_TAB_VISUAL_FONT_QUALITY_ANTIALIASED", L"Antialiased" },
188     { "DLG_TAB_VISUAL_FONT_QUALITY_CLEARTYPE", L"ClearType" },
189     };
190 zmatsuo 9359 SetI18nListW("Tera Term", hWnd, IDC_FONT_QUALITY, visual_font_quality, _countof(visual_font_quality),
191     ts->UILanguageFileW, 0);
192 zmatsuo 8771 int cur =
193     ts->FontQuality == DEFAULT_QUALITY ? 0 :
194     ts->FontQuality == NONANTIALIASED_QUALITY ? 1 :
195     ts->FontQuality == ANTIALIASED_QUALITY ? 2 :
196     /*ts->FontQuality == CLEARTYPE_QUALITY ? */ 3;
197     SendDlgItemMessage(hWnd, IDC_FONT_QUALITY, CB_SETCURSEL, cur, 0);
198    
199     SetFontString(hWnd, IDC_DLGFONT_EDIT, &dlg_data->DlgFont);
200 zmatsuo 8832
201     break;
202 zmatsuo 8771 }
203     case WM_NOTIFY: {
204     NMHDR *nmhdr = (NMHDR *)lp;
205     switch (nmhdr->code) {
206     case PSN_APPLY: {
207     UnicodeDebugParam.UseUnicodeApi =
208     IsDlgButtonChecked(hWnd, IDC_VTFONT_UNICODE) == BST_CHECKED;
209     UnicodeDebugParam.CodePageForANSIDraw =
210 zmatsuo 10056 GetDlgItemInt(hWnd, IDC_VTFONT_CODEPAGE_EDIT, NULL, FALSE);
211 zmatsuo 8771 // ANSI�\���p���R�[�h�y�[�W����������
212     BuffSetDispCodePage(UnicodeDebugParam.CodePageForANSIDraw);
213     ts->ListHiddenFonts = IsDlgButtonChecked(hWnd, IDC_LIST_HIDDEN_FONTS) == BST_CHECKED;
214    
215     SetDlgLogFont(GetParent(hWnd), &dlg_data->DlgFont, ts);
216    
217 zmatsuo 9549 // font quality
218     int cur = (int)SendDlgItemMessageA(hWnd, IDC_FONT_QUALITY, CB_GETCURSEL, 0, 0);
219     ts->FontQuality =
220     cur == 0 ? DEFAULT_QUALITY :
221     cur == 1 ? NONANTIALIASED_QUALITY :
222     cur == 2 ? ANTIALIASED_QUALITY :
223     CLEARTYPE_QUALITY;
224    
225 zmatsuo 8771 break;
226     }
227 zmatsuo 10047 case PSN_HELP: {
228     HWND vtwin = GetParent(hWnd);
229     vtwin = GetParent(vtwin);
230     PostMessage(vtwin, WM_USER_DLGHELP2, HlpMenuSetupAdditionalFont, 0);
231 zmatsuo 8771 break;
232 zmatsuo 10047 }
233 zmatsuo 8771 default:
234     break;
235     }
236     break;
237     }
238     case WM_COMMAND: {
239     switch (wp) {
240     case IDC_VTFONT_ANSI | (BN_CLICKED << 16):
241     case IDC_VTFONT_UNICODE | (BN_CLICKED << 16): {
242     BOOL enable = (wp & 0xffff) == IDC_VTFONT_ANSI ? TRUE : FALSE;
243     EnableCodePage(hWnd, enable);
244     break;
245     }
246     case IDC_VTFONT_CHOOSE | (BN_CLICKED << 16): {
247     DispSetupFontDlg();
248 zmatsuo 10056 SetDlgItemInt(hWnd, IDC_VTFONT_CODEPAGE_EDIT, UnicodeDebugParam.CodePageForANSIDraw, FALSE);
249 zmatsuo 8771 SetVTFontString(hWnd, IDC_VTFONT_EDIT, ts);
250     break;
251     }
252     case IDC_DLGFONT_CHOOSE | (BN_CLICKED << 16):
253 zmatsuo 8832 if (ChooseDlgFont(hWnd, dlg_data) != FALSE) {
254     SetFontString(hWnd, IDC_DLGFONT_EDIT, &dlg_data->DlgFont);
255     }
256 zmatsuo 8771 break;
257    
258     case IDC_DLGFONT_DEFAULT | (BN_CLICKED << 16): {
259     GetMessageboxFont(&dlg_data->DlgFont);
260     SetFontString(hWnd, IDC_DLGFONT_EDIT, &dlg_data->DlgFont);
261     }
262    
263     default:
264     break;
265     }
266     break;
267     }
268     default:
269     return FALSE;
270     }
271     return FALSE;
272     }
273    
274 zmatsuo 9936 static UINT CALLBACK CallBack(HWND hwnd, UINT uMsg, struct _PROPSHEETPAGEW *ppsp)
275 zmatsuo 9923 {
276     (void)hwnd;
277     UINT ret_val = 0;
278     switch (uMsg) {
279     case PSPCB_CREATE:
280     ret_val = 1;
281     break;
282     case PSPCB_RELEASE:
283     free((void *)ppsp->pResource);
284     ppsp->pResource = NULL;
285     free((void *)ppsp->lParam);
286     ppsp->lParam = NULL;
287     break;
288     default:
289     break;
290     }
291     return ret_val;
292     }
293    
294 zmatsuo 8771 HPROPSHEETPAGE FontPageCreate(HINSTANCE inst, TTTSet *pts)
295     {
296     // �� common/tt_res.h �� font_pp_res.h ���l�����v����������
297     const int id = IDD_TABSHEET_FONT;
298    
299     FontPPData *Param = (FontPPData *)calloc(sizeof(FontPPData), 1);
300     Param->hInst = inst;
301 zmatsuo 9549 Param->UILanguageFileW = pts->UILanguageFileW;
302 zmatsuo 8771 Param->pts = pts;
303    
304     PROPSHEETPAGEW_V1 psp = {};
305     psp.dwSize = sizeof(psp);
306 zmatsuo 10047 psp.dwFlags = PSP_DEFAULT | PSP_USECALLBACK | PSP_USETITLE | PSP_HASHELP;
307 zmatsuo 8771 psp.hInstance = inst;
308 zmatsuo 9923 psp.pfnCallback = CallBack;
309 zmatsuo 10056 wchar_t *UIMsg;
310     GetI18nStrWW("Tera Term", "DLG_TABSHEET_TITLE_FONT",
311     L"Font", pts->UILanguageFileW, &UIMsg);
312     psp.pszTitle = UIMsg;
313 zmatsuo 8771 psp.pszTemplate = MAKEINTRESOURCEW(id);
314     #if defined(REWRITE_TEMPLATE)
315     psp.dwFlags |= PSP_DLGINDIRECT;
316     Param->dlg_templ = TTGetDlgTemplate(inst, MAKEINTRESOURCEA(id));
317     psp.pResource = Param->dlg_templ;
318     #endif
319    
320     psp.pfnDlgProc = Proc;
321     psp.lParam = (LPARAM)Param;
322    
323 zmatsuo 9324 HPROPSHEETPAGE hpsp = CreatePropertySheetPageW((LPPROPSHEETPAGEW)&psp);
324 zmatsuo 10056 free(UIMsg);
325 zmatsuo 8771 return hpsp;
326     }

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