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 10047 - (hide annotations) (download) (as text)
Thu Jul 7 14:19:18 2022 UTC (21 months ago) by zmatsuo
File MIME type: text/x-c++src
File size: 10501 byte(s)
[設定] - [その他の設定] - [font] のヘルプボタンを有効にした

- ヘルプの内容はcodingタブのヘルプへのリンク
- helpボタンを有効にしてヘルプを参照できるようにした
- en/setup-additional-coding.html に ja の内容をコピー
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     EnableWindow(GetDlgItem(hWnd, IDC_VTFONT_PAGECODE_LABEL), enable);
119     EnableWindow(GetDlgItem(hWnd, IDC_VTFONT_PAGECODE_EDIT), enable);
120     }
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     {0, "DLG_GEN_TITLE"},
145     };
146     FontPPData *dlg_data = (FontPPData *)GetWindowLongPtr(hWnd, DWLP_USER);
147     TTTSet *ts = dlg_data == NULL ? NULL : dlg_data->pts;
148    
149     switch (msg) {
150     case WM_INITDIALOG: {
151     dlg_data = (FontPPData *)(((PROPSHEETPAGEW_V1 *)lp)->lParam);
152     ts = dlg_data->pts;
153     SetWindowLongPtr(hWnd, DWLP_USER, (LONG_PTR)dlg_data);
154 zmatsuo 9359 SetDlgTextsW(hWnd, TextInfos, _countof(TextInfos), dlg_data->pts->UILanguageFileW);
155 zmatsuo 8771
156     GetDlgLogFont(GetParent(hWnd), ts, &dlg_data->DlgFont);
157    
158     SetVTFontString(hWnd, IDC_VTFONT_EDIT, ts);
159    
160     CheckDlgButton(hWnd,
161     UnicodeDebugParam.UseUnicodeApi ? IDC_VTFONT_UNICODE : IDC_VTFONT_ANSI,
162     BST_CHECKED);
163     SetDlgItemInt(hWnd, IDC_VTFONT_PAGECODE_EDIT, UnicodeDebugParam.CodePageForANSIDraw, FALSE);
164     EnableCodePage(hWnd, UnicodeDebugParam.UseUnicodeApi ? FALSE : TRUE);
165    
166     CheckDlgButton(hWnd, IDC_LIST_HIDDEN_FONTS, ts->ListHiddenFonts);
167     EnableWindow(GetDlgItem(hWnd, IDC_LIST_HIDDEN_FONTS), IsWindows7OrLater() ? TRUE : FALSE);
168    
169     SetDlgItemInt(hWnd, IDC_SPACE_RIGHT, ts->FontDW, FALSE);
170     SetDlgItemInt(hWnd, IDC_SPACE_LEFT, ts->FontDH, FALSE);
171     SetDlgItemInt(hWnd, IDC_SPACE_TOP, ts->FontDX, FALSE);
172     SetDlgItemInt(hWnd, IDC_SPACE_BOTTOM, ts->FontDY, FALSE);
173    
174     const static I18nTextInfo visual_font_quality[] = {
175     { "DLG_TAB_VISUAL_FONT_QUALITY_DEFAULT", L"Default" },
176     { "DLG_TAB_VISUAL_FONT_QUALITY_NONANTIALIASED", L"Non-Antialiased" },
177     { "DLG_TAB_VISUAL_FONT_QUALITY_ANTIALIASED", L"Antialiased" },
178     { "DLG_TAB_VISUAL_FONT_QUALITY_CLEARTYPE", L"ClearType" },
179     };
180 zmatsuo 9359 SetI18nListW("Tera Term", hWnd, IDC_FONT_QUALITY, visual_font_quality, _countof(visual_font_quality),
181     ts->UILanguageFileW, 0);
182 zmatsuo 8771 int cur =
183     ts->FontQuality == DEFAULT_QUALITY ? 0 :
184     ts->FontQuality == NONANTIALIASED_QUALITY ? 1 :
185     ts->FontQuality == ANTIALIASED_QUALITY ? 2 :
186     /*ts->FontQuality == CLEARTYPE_QUALITY ? */ 3;
187     SendDlgItemMessage(hWnd, IDC_FONT_QUALITY, CB_SETCURSEL, cur, 0);
188    
189     SetFontString(hWnd, IDC_DLGFONT_EDIT, &dlg_data->DlgFont);
190 zmatsuo 8832
191     break;
192 zmatsuo 8771 }
193     case WM_NOTIFY: {
194     NMHDR *nmhdr = (NMHDR *)lp;
195     switch (nmhdr->code) {
196     case PSN_APPLY: {
197     UnicodeDebugParam.UseUnicodeApi =
198     IsDlgButtonChecked(hWnd, IDC_VTFONT_UNICODE) == BST_CHECKED;
199     UnicodeDebugParam.CodePageForANSIDraw =
200     GetDlgItemInt(hWnd, IDC_VTFONT_PAGECODE_EDIT, NULL, FALSE);
201     // ANSI�\���p���R�[�h�y�[�W����������
202     BuffSetDispCodePage(UnicodeDebugParam.CodePageForANSIDraw);
203     ts->ListHiddenFonts = IsDlgButtonChecked(hWnd, IDC_LIST_HIDDEN_FONTS) == BST_CHECKED;
204    
205     SetDlgLogFont(GetParent(hWnd), &dlg_data->DlgFont, ts);
206    
207 zmatsuo 9549 // font quality
208     int cur = (int)SendDlgItemMessageA(hWnd, IDC_FONT_QUALITY, CB_GETCURSEL, 0, 0);
209     ts->FontQuality =
210     cur == 0 ? DEFAULT_QUALITY :
211     cur == 1 ? NONANTIALIASED_QUALITY :
212     cur == 2 ? ANTIALIASED_QUALITY :
213     CLEARTYPE_QUALITY;
214    
215 zmatsuo 8771 break;
216     }
217 zmatsuo 10047 case PSN_HELP: {
218     HWND vtwin = GetParent(hWnd);
219     vtwin = GetParent(vtwin);
220     PostMessage(vtwin, WM_USER_DLGHELP2, HlpMenuSetupAdditionalFont, 0);
221 zmatsuo 8771 break;
222 zmatsuo 10047 }
223 zmatsuo 8771 default:
224     break;
225     }
226     break;
227     }
228     case WM_COMMAND: {
229     switch (wp) {
230     case IDC_VTFONT_ANSI | (BN_CLICKED << 16):
231     case IDC_VTFONT_UNICODE | (BN_CLICKED << 16): {
232     BOOL enable = (wp & 0xffff) == IDC_VTFONT_ANSI ? TRUE : FALSE;
233     EnableCodePage(hWnd, enable);
234     break;
235     }
236     case IDC_VTFONT_CHOOSE | (BN_CLICKED << 16): {
237     DispSetupFontDlg();
238     SetDlgItemInt(hWnd, IDC_VTFONT_PAGECODE_EDIT, UnicodeDebugParam.CodePageForANSIDraw, FALSE);
239     SetVTFontString(hWnd, IDC_VTFONT_EDIT, ts);
240     break;
241     }
242     case IDC_DLGFONT_CHOOSE | (BN_CLICKED << 16):
243 zmatsuo 8832 if (ChooseDlgFont(hWnd, dlg_data) != FALSE) {
244     SetFontString(hWnd, IDC_DLGFONT_EDIT, &dlg_data->DlgFont);
245     }
246 zmatsuo 8771 break;
247    
248     case IDC_DLGFONT_DEFAULT | (BN_CLICKED << 16): {
249     GetMessageboxFont(&dlg_data->DlgFont);
250     SetFontString(hWnd, IDC_DLGFONT_EDIT, &dlg_data->DlgFont);
251     }
252    
253     default:
254     break;
255     }
256     break;
257     }
258     default:
259     return FALSE;
260     }
261     return FALSE;
262     }
263    
264 zmatsuo 9936 static UINT CALLBACK CallBack(HWND hwnd, UINT uMsg, struct _PROPSHEETPAGEW *ppsp)
265 zmatsuo 9923 {
266     (void)hwnd;
267     UINT ret_val = 0;
268     switch (uMsg) {
269     case PSPCB_CREATE:
270     ret_val = 1;
271     break;
272     case PSPCB_RELEASE:
273     free((void *)ppsp->pResource);
274     ppsp->pResource = NULL;
275     free((void *)ppsp->lParam);
276     ppsp->lParam = NULL;
277     break;
278     default:
279     break;
280     }
281     return ret_val;
282     }
283    
284 zmatsuo 8771 HPROPSHEETPAGE FontPageCreate(HINSTANCE inst, TTTSet *pts)
285     {
286     // �� common/tt_res.h �� font_pp_res.h ���l�����v����������
287     const int id = IDD_TABSHEET_FONT;
288    
289     FontPPData *Param = (FontPPData *)calloc(sizeof(FontPPData), 1);
290     Param->hInst = inst;
291 zmatsuo 9549 Param->UILanguageFileW = pts->UILanguageFileW;
292 zmatsuo 8771 Param->pts = pts;
293    
294     PROPSHEETPAGEW_V1 psp = {};
295     psp.dwSize = sizeof(psp);
296 zmatsuo 10047 psp.dwFlags = PSP_DEFAULT | PSP_USECALLBACK | PSP_USETITLE | PSP_HASHELP;
297 zmatsuo 8771 psp.hInstance = inst;
298 zmatsuo 9923 psp.pfnCallback = CallBack;
299     psp.pszTitle = L"font"; // TODO lng �t�@�C����������
300 zmatsuo 8771 psp.pszTemplate = MAKEINTRESOURCEW(id);
301     #if defined(REWRITE_TEMPLATE)
302     psp.dwFlags |= PSP_DLGINDIRECT;
303     Param->dlg_templ = TTGetDlgTemplate(inst, MAKEINTRESOURCEA(id));
304     psp.pResource = Param->dlg_templ;
305     #endif
306    
307     psp.pfnDlgProc = Proc;
308     psp.lParam = (LPARAM)Param;
309    
310 zmatsuo 9324 HPROPSHEETPAGE hpsp = CreatePropertySheetPageW((LPPROPSHEETPAGEW)&psp);
311 zmatsuo 8771 return hpsp;
312     }

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