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