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 9359 - (hide annotations) (download) (as text)
Sat Aug 14 03:26:30 2021 UTC (2 years, 7 months ago) by zmatsuo
Original Path: trunk/teraterm/teraterm/font_pp.cpp
File MIME type: text/x-c++src
File size: 9804 byte(s)
UILanguageFile を unicode版(UILanguageFileW)へ切り替え

- SetDlgTexts() -> SetDlgTextsW()
- get_lang_msgW() ->GetI18nStrWW()
- SetI18nList() -> SetI18nListW()
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    
45     #include "font_pp.h"
46    
47     // �e���v���[�g�������������s��
48     #define REWRITE_TEMPLATE
49    
50     struct FontPPData {
51     HINSTANCE hInst;
52     const char *UILanguageFile;
53     TTTSet *pts;
54     DLGTEMPLATE *dlg_templ;
55     // LOGFONTA VTFont;
56     LOGFONTA DlgFont;
57     };
58    
59     static void GetDlgLogFont(HWND hWnd, const TTTSet *ts, LOGFONTA *logfont)
60     {
61     memset(logfont, 0, sizeof(*logfont));
62     logfont->lfHeight = -GetFontPixelFromPoint(hWnd, ts->DialogFontPoint);
63     strncpy_s(logfont->lfFaceName, sizeof(logfont->lfFaceName),ts->DialogFontName, _TRUNCATE);
64     logfont->lfCharSet = ts->DialogFontCharSet;
65     }
66    
67     static void SetDlgLogFont(HWND hWnd, const LOGFONTA *logfont, TTTSet *ts)
68     {
69     strncpy_s(ts->DialogFontName, sizeof(ts->DialogFontName), logfont->lfFaceName, _TRUNCATE);
70     ts->DialogFontPoint = GetFontPointFromPixel(hWnd, -logfont->lfHeight);
71     ts->DialogFontCharSet = logfont->lfCharSet;
72     }
73    
74     static UINT_PTR CALLBACK TFontHook(HWND Dialog, UINT Message, WPARAM wParam, LPARAM lParam)
75     {
76     if (Message == WM_INITDIALOG) {
77     FontPPData *dlg_data = (FontPPData *)(((CHOOSEFONTA *)lParam)->lCustData);
78     wchar_t uimsg[MAX_UIMSG];
79     get_lang_msgW("DLG_CHOOSEFONT_STC6", uimsg, _countof(uimsg),
80     L"\"Font style\" selection here won't affect actual font appearance.", dlg_data->UILanguageFile);
81 zmatsuo 9324 SetDlgItemTextW(Dialog, stc6, uimsg);
82 zmatsuo 8771
83     SetFocus(GetDlgItem(Dialog,cmb1));
84    
85     CenterWindow(Dialog, GetParent(Dialog));
86     }
87     return FALSE;
88     }
89    
90 zmatsuo 8832 static BOOL ChooseDlgFont(HWND hWnd, FontPPData *dlg_data)
91 zmatsuo 8771 {
92     const TTTSet *ts = dlg_data->pts;
93    
94     // �_�C�A���O�\��
95     CHOOSEFONTA cf = {};
96     cf.lStructSize = sizeof(cf);
97     cf.hwndOwner = hWnd;
98     cf.lpLogFont = &dlg_data->DlgFont;
99     cf.Flags =
100     CF_SCREENFONTS | CF_INITTOLOGFONTSTRUCT |
101     CF_SHOWHELP | CF_NOVERTFONTS |
102     CF_ENABLEHOOK;
103     if (IsWindows7OrLater() && ts->ListHiddenFonts) {
104     cf.Flags |= CF_INACTIVEFONTS;
105     }
106     cf.lpfnHook = &TFontHook;
107     cf.nFontType = REGULAR_FONTTYPE;
108     cf.hInstance = dlg_data->hInst;
109     cf.lCustData = (LPARAM)dlg_data;
110     BOOL result = ChooseFontA(&cf);
111 zmatsuo 8832 return result;
112 zmatsuo 8771 }
113    
114     static void EnableCodePage(HWND hWnd, BOOL enable)
115     {
116     EnableWindow(GetDlgItem(hWnd, IDC_VTFONT_PAGECODE_LABEL), enable);
117     EnableWindow(GetDlgItem(hWnd, IDC_VTFONT_PAGECODE_EDIT), enable);
118     }
119    
120     static void SetFontString(HWND hWnd, int item, const LOGFONTA *logfont)
121     {
122     // https://docs.microsoft.com/en-us/windows/win32/api/dimm/ns-dimm-logfonta
123     // http://www.coara.or.jp/~tkuri/D/015.htm#D2002-09-14
124     char b[128];
125     sprintf_s(b, "%s (%d,%d) %d", logfont->lfFaceName, logfont->lfWidth, logfont->lfHeight, logfont->lfCharSet);
126     SetDlgItemTextA(hWnd, item, b);
127     }
128    
129     static void SetVTFontString(HWND hWnd, int item, const TTTSet *ts)
130     {
131     LOGFONTA logfont = {};
132     logfont.lfWidth = ts->VTFontSize.x;
133     logfont.lfHeight = ts->VTFontSize.y;
134     strncpy_s(logfont.lfFaceName, sizeof(logfont.lfFaceName),ts->VTFont, _TRUNCATE);
135     logfont.lfCharSet = ts->VTFontCharSet;
136     SetFontString(hWnd, item, &logfont);
137     }
138    
139     static INT_PTR CALLBACK Proc(HWND hWnd, UINT msg, WPARAM wp, LPARAM lp)
140     {
141     static const DlgTextInfo TextInfos[] = {
142     {0, "DLG_GEN_TITLE"},
143     };
144     FontPPData *dlg_data = (FontPPData *)GetWindowLongPtr(hWnd, DWLP_USER);
145     TTTSet *ts = dlg_data == NULL ? NULL : dlg_data->pts;
146    
147     switch (msg) {
148     case WM_INITDIALOG: {
149     dlg_data = (FontPPData *)(((PROPSHEETPAGEW_V1 *)lp)->lParam);
150     ts = dlg_data->pts;
151     SetWindowLongPtr(hWnd, DWLP_USER, (LONG_PTR)dlg_data);
152 zmatsuo 9359 SetDlgTextsW(hWnd, TextInfos, _countof(TextInfos), dlg_data->pts->UILanguageFileW);
153 zmatsuo 8771
154     GetDlgLogFont(GetParent(hWnd), ts, &dlg_data->DlgFont);
155    
156     SetVTFontString(hWnd, IDC_VTFONT_EDIT, ts);
157    
158     CheckDlgButton(hWnd,
159     UnicodeDebugParam.UseUnicodeApi ? IDC_VTFONT_UNICODE : IDC_VTFONT_ANSI,
160     BST_CHECKED);
161     SetDlgItemInt(hWnd, IDC_VTFONT_PAGECODE_EDIT, UnicodeDebugParam.CodePageForANSIDraw, FALSE);
162     EnableCodePage(hWnd, UnicodeDebugParam.UseUnicodeApi ? FALSE : TRUE);
163    
164     CheckDlgButton(hWnd, IDC_LIST_HIDDEN_FONTS, ts->ListHiddenFonts);
165     EnableWindow(GetDlgItem(hWnd, IDC_LIST_HIDDEN_FONTS), IsWindows7OrLater() ? TRUE : FALSE);
166    
167     SetDlgItemInt(hWnd, IDC_SPACE_RIGHT, ts->FontDW, FALSE);
168     SetDlgItemInt(hWnd, IDC_SPACE_LEFT, ts->FontDH, FALSE);
169     SetDlgItemInt(hWnd, IDC_SPACE_TOP, ts->FontDX, FALSE);
170     SetDlgItemInt(hWnd, IDC_SPACE_BOTTOM, ts->FontDY, FALSE);
171    
172     const static I18nTextInfo visual_font_quality[] = {
173     { "DLG_TAB_VISUAL_FONT_QUALITY_DEFAULT", L"Default" },
174     { "DLG_TAB_VISUAL_FONT_QUALITY_NONANTIALIASED", L"Non-Antialiased" },
175     { "DLG_TAB_VISUAL_FONT_QUALITY_ANTIALIASED", L"Antialiased" },
176     { "DLG_TAB_VISUAL_FONT_QUALITY_CLEARTYPE", L"ClearType" },
177     };
178 zmatsuo 9359 SetI18nListW("Tera Term", hWnd, IDC_FONT_QUALITY, visual_font_quality, _countof(visual_font_quality),
179     ts->UILanguageFileW, 0);
180 zmatsuo 8771 int cur =
181     ts->FontQuality == DEFAULT_QUALITY ? 0 :
182     ts->FontQuality == NONANTIALIASED_QUALITY ? 1 :
183     ts->FontQuality == ANTIALIASED_QUALITY ? 2 :
184     /*ts->FontQuality == CLEARTYPE_QUALITY ? */ 3;
185     SendDlgItemMessage(hWnd, IDC_FONT_QUALITY, CB_SETCURSEL, cur, 0);
186    
187     SetFontString(hWnd, IDC_DLGFONT_EDIT, &dlg_data->DlgFont);
188 zmatsuo 8832
189     break;
190 zmatsuo 8771 }
191     case WM_NOTIFY: {
192     NMHDR *nmhdr = (NMHDR *)lp;
193     switch (nmhdr->code) {
194     case PSN_APPLY: {
195     UnicodeDebugParam.UseUnicodeApi =
196     IsDlgButtonChecked(hWnd, IDC_VTFONT_UNICODE) == BST_CHECKED;
197     UnicodeDebugParam.CodePageForANSIDraw =
198     GetDlgItemInt(hWnd, IDC_VTFONT_PAGECODE_EDIT, NULL, FALSE);
199     // ANSI�\���p���R�[�h�y�[�W����������
200     BuffSetDispCodePage(UnicodeDebugParam.CodePageForANSIDraw);
201     ts->ListHiddenFonts = IsDlgButtonChecked(hWnd, IDC_LIST_HIDDEN_FONTS) == BST_CHECKED;
202    
203     SetDlgLogFont(GetParent(hWnd), &dlg_data->DlgFont, ts);
204    
205     break;
206     }
207     case PSN_HELP:
208     MessageBox(hWnd, "Tera Term", "not implimented",
209     MB_OK | MB_ICONEXCLAMATION);
210     break;
211     default:
212     break;
213     }
214     break;
215     }
216     case WM_COMMAND: {
217     switch (wp) {
218     case IDC_VTFONT_ANSI | (BN_CLICKED << 16):
219     case IDC_VTFONT_UNICODE | (BN_CLICKED << 16): {
220     BOOL enable = (wp & 0xffff) == IDC_VTFONT_ANSI ? TRUE : FALSE;
221     EnableCodePage(hWnd, enable);
222     break;
223     }
224     case IDC_VTFONT_CHOOSE | (BN_CLICKED << 16): {
225     DispSetupFontDlg();
226     SetDlgItemInt(hWnd, IDC_VTFONT_PAGECODE_EDIT, UnicodeDebugParam.CodePageForANSIDraw, FALSE);
227     SetVTFontString(hWnd, IDC_VTFONT_EDIT, ts);
228     break;
229     }
230     case IDC_DLGFONT_CHOOSE | (BN_CLICKED << 16):
231 zmatsuo 8832 if (ChooseDlgFont(hWnd, dlg_data) != FALSE) {
232     SetFontString(hWnd, IDC_DLGFONT_EDIT, &dlg_data->DlgFont);
233     }
234 zmatsuo 8771 break;
235    
236     case IDC_DLGFONT_DEFAULT | (BN_CLICKED << 16): {
237     GetMessageboxFont(&dlg_data->DlgFont);
238     SetFontString(hWnd, IDC_DLGFONT_EDIT, &dlg_data->DlgFont);
239     }
240    
241     default:
242     break;
243     }
244     break;
245     }
246     case WM_DESTROY: {
247     free(dlg_data->dlg_templ);
248     free(dlg_data);
249     SetWindowLongPtr(hWnd, DWLP_USER, NULL);
250     break;
251     }
252     default:
253     return FALSE;
254     }
255     return FALSE;
256     }
257    
258     HPROPSHEETPAGE FontPageCreate(HINSTANCE inst, TTTSet *pts)
259     {
260     // �� common/tt_res.h �� font_pp_res.h ���l�����v����������
261     const int id = IDD_TABSHEET_FONT;
262    
263     FontPPData *Param = (FontPPData *)calloc(sizeof(FontPPData), 1);
264     Param->hInst = inst;
265     Param->UILanguageFile = pts->UILanguageFile;
266     Param->pts = pts;
267    
268     PROPSHEETPAGEW_V1 psp = {};
269     psp.dwSize = sizeof(psp);
270     psp.dwFlags = PSP_DEFAULT;
271     psp.hInstance = inst;
272     psp.pszTemplate = MAKEINTRESOURCEW(id);
273     #if defined(REWRITE_TEMPLATE)
274     psp.dwFlags |= PSP_DLGINDIRECT;
275     Param->dlg_templ = TTGetDlgTemplate(inst, MAKEINTRESOURCEA(id));
276     psp.pResource = Param->dlg_templ;
277     #endif
278     psp.pszTitle = L"font";
279     psp.dwFlags |= (PSP_USETITLE /*| PSP_HASHELP */);
280    
281     psp.pfnDlgProc = Proc;
282     psp.lParam = (LPARAM)Param;
283    
284 zmatsuo 9324 HPROPSHEETPAGE hpsp = CreatePropertySheetPageW((LPPROPSHEETPAGEW)&psp);
285 zmatsuo 8771 return hpsp;
286     }

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