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