Develop and Download Open Source Software

Browse Subversion Repository

Annotation of /branches/ttcomtester/teraterm/teraterm/font_pp.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 10048 - (hide annotations) (download) (as text)
Sat Jul 9 03:44:40 2022 UTC (21 months ago) by zmatsuo
Original Path: trunk/teraterm/teraterm/font_pp.cpp
File MIME type: text/x-c++src
File size: 10630 byte(s)
フォントタブのタブオーダーを調整、ヘルプを追記

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

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