Revision: 10332 https://osdn.net/projects/ttssh2/scm/svn/commits/10332 Author: zmatsuo Date: 2022-10-24 00:16:14 +0900 (Mon, 24 Oct 2022) Log Message: ----------- テーマファイルの扱いをUnicode化 - UnicodeAPIを使用するよう修正 - 背景テーマのセクション名を "BG theme" へ変更 - "BG" セクションも読み込める - TODO - MAX_PATHが残っている Modified Paths: -------------- trunk/doc/en/html/setup/theme.html trunk/doc/ja/html/setup/theme.html trunk/teraterm/teraterm/theme.h trunk/teraterm/teraterm/themedlg.cpp trunk/teraterm/teraterm/themefile.cpp trunk/teraterm/teraterm/vtdisp.c -------------- next part -------------- Modified: trunk/doc/en/html/setup/theme.html =================================================================== --- trunk/doc/en/html/setup/theme.html 2022-10-23 15:15:59 UTC (rev 10331) +++ trunk/doc/en/html/setup/theme.html 2022-10-23 15:16:14 UTC (rev 10332) @@ -30,7 +30,7 @@ <dl> <dt>BG(\x94w\x8Ci)\x83e\x81[\x83}</dt> <dd> - [BG]\x83Z\x83N\x83V\x83\x87\x83\x93\x82\xAA\x93\xFC\x82\xC1\x82\xBD\x83t\x83@\x83C\x83\x8B<br> + [BG Theme]\x83Z\x83N\x83V\x83\x87\x83\x93\x82\xAA\x93\xFC\x82\xC1\x82\xBD\x83t\x83@\x83C\x83\x8B<br> \x82\xB1\x82̃Z\x83N\x83V\x83\x87\x83\x93\x82ɂ͔w\x8Ci\x89摜\x82̐ݒ肪\x93\xFC\x82\xE9 </dd> <dt>\x83J\x83\x89\x81[\x83e\x81[\x83}</dt> @@ -52,8 +52,12 @@ <h2 id="BGTheme">BG(\x94w\x8Ci)\x83e\x81[\x83}</h2> - \x83Z\x83N\x83V\x83\x87\x83\x93\x96\xBC\x82\xCD"[BG]" + <h3>section</h3> + "BG theme"<br> + + "BG"\x83Z\x83N\x83V\x83\x87\x83\x93\x82\xE0\x93ǂݍ\x9E\x82݉\(\x94p\x8E~\x97\\x92\xE8)\x81B\x97\xBC\x95\xFB\x82\xA0\x82\xE9\x8Fꍇ\x82\xCD"BG theme"\x82\xAA\x97D\x90\xE6\x81B + <dl> <dt>BGDestColor</dt> <dd> @@ -113,20 +117,20 @@ </dd> </dl> - <h3 id="ColorTheme">color theme</h3> + <h2 id="ColorTheme">color theme</h2> - <h4>section</h4> + <h3>section</h3> "Color Theme" - <h4>name</h4> + <h3>name</h3> <dl> - <dt>name</dt> + <dt>Theme</dt> <dd>\x83e\x81[\x83}\x96\xBC\x81A\x92l\x82͕\xB6\x8E\x9A\x97\xF1</dd> </dl> - <h4>attribute color</h4> + <h3>attribute color</h3> <dl> <dt>VTColor</dt> @@ -181,7 +185,7 @@ </dd> </dl> - <h4>ANSI color</h4> + <h3>ANSI color</h3> 256\x90F/16\x90F ANSI color\x82̍ŏ\x89\x82\xCC16\x90F\x81B<br> 8\x90F\x8E\x9E\x82́ADark color\x82\xF0\x8Eg\x97p\x82\xB5\x82Ȃ\xA2 Modified: trunk/doc/ja/html/setup/theme.html =================================================================== --- trunk/doc/ja/html/setup/theme.html 2022-10-23 15:15:59 UTC (rev 10331) +++ trunk/doc/ja/html/setup/theme.html 2022-10-23 15:16:14 UTC (rev 10332) @@ -30,7 +30,7 @@ <dl> <dt>BG(\x94w\x8Ci)\x83e\x81[\x83}</dt> <dd> - [BG]\x83Z\x83N\x83V\x83\x87\x83\x93\x82\xAA\x93\xFC\x82\xC1\x82\xBD\x83t\x83@\x83C\x83\x8B<br> + [BG Theme]\x83Z\x83N\x83V\x83\x87\x83\x93\x82\xAA\x93\xFC\x82\xC1\x82\xBD\x83t\x83@\x83C\x83\x8B<br> \x82\xB1\x82̃Z\x83N\x83V\x83\x87\x83\x93\x82ɂ͔w\x8Ci\x89摜\x82̐ݒ肪\x93\xFC\x82\xE9 </dd> <dt>\x83J\x83\x89\x81[\x83e\x81[\x83}</dt> @@ -52,8 +52,12 @@ <h2 id="BGTheme">BG(\x94w\x8Ci)\x83e\x81[\x83}</h2> - \x83Z\x83N\x83V\x83\x87\x83\x93\x96\xBC\x82\xCD"[BG]" + <h3>section</h3> + "BG theme"<br> + + "BG"\x83Z\x83N\x83V\x83\x87\x83\x93\x82\xE0\x93ǂݍ\x9E\x82݉\(\x94p\x8E~\x97\\x92\xE8)\x81B\x97\xBC\x95\xFB\x82\xA0\x82\xE9\x8Fꍇ\x82\xCD"BG theme"\x82\xAA\x97D\x90\xE6\x81B + <dl> <dt>BGDestColor</dt> <dd> @@ -113,20 +117,20 @@ </dd> </dl> - <h3 id="ColorTheme">color theme</h3> + <h2 id="ColorTheme">color theme</h2> - <h4>section</h4> + <h3>section</h3> "Color Theme" - <h4>name</h4> + <h3>name</h3> <dl> - <dt>name</dt> + <dt>Theme</dt> <dd>\x83e\x81[\x83}\x96\xBC\x81A\x92l\x82͕\xB6\x8E\x9A\x97\xF1</dd> </dl> - <h4>attribute color</h4> + <h3>attribute color</h3> <dl> <dt>VTColor</dt> @@ -181,7 +185,7 @@ </dd> </dl> - <h4>ANSI color</h4> + <h3>ANSI color</h3> 256\x90F/16\x90F ANSI color\x82̍ŏ\x89\x82\xCC16\x90F\x81B<br> 8\x90F\x8E\x9E\x82́ADark color\x82\xF0\x8Eg\x97p\x82\xB5\x82Ȃ\xA2 Modified: trunk/teraterm/teraterm/theme.h =================================================================== --- trunk/teraterm/teraterm/theme.h 2022-10-23 15:15:59 UTC (rev 10331) +++ trunk/teraterm/teraterm/theme.h 2022-10-23 15:16:14 UTC (rev 10332) @@ -52,7 +52,7 @@ BOOL antiAlias; COLORREF color; int alpha; - char file[MAX_PATH]; + wchar_t file[MAX_PATH]; } TBGSrc; typedef struct _BGTheme { @@ -96,7 +96,7 @@ typedef struct { BG_PATTERN id; - const char *str; + const wchar_t *str; } BG_PATTERN_ST; // setting / themefile.cpp Modified: trunk/teraterm/teraterm/themedlg.cpp =================================================================== --- trunk/teraterm/teraterm/themedlg.cpp 2022-10-23 15:15:59 UTC (rev 10331) +++ trunk/teraterm/teraterm/themedlg.cpp 2022-10-23 15:16:14 UTC (rev 10332) @@ -54,7 +54,6 @@ #include "win32helper.h" #include "tipwin2.h" #include "dlglib.h" -#include "inifile_com.h" #include "helpid.h" #include "vtdisp.h" #include "tmfc.h" @@ -140,7 +139,7 @@ { BOOL bg_enable = (bg_theme->BGDest.type == BG_PICTURE && (bg_theme->BGDest.file != NULL && bg_theme->BGDest.file[0] != 0)) ? TRUE : FALSE; SendDlgItemMessageA(hWnd, IDC_BGIMG_CHECK, BM_SETCHECK, bg_enable, 0); - SetDlgItemTextA(hWnd, IDC_BGIMG_EDIT, bg_theme->BGDest.file); + SetDlgItemTextW(hWnd, IDC_BGIMG_EDIT, bg_theme->BGDest.file); SetDlgItemTextColor(hWnd, IDC_BGIMG_COLOR_EDIT, bg_theme->BGDest.color); { LRESULT count = SendDlgItemMessageA(hWnd, IDC_BGIMG_COMBO, CB_GETCOUNT, 0, 0); @@ -172,7 +171,7 @@ LRESULT index; checked = SendDlgItemMessageA(hWnd, IDC_BGIMG_CHECK, BM_GETCHECK, 0, 0); bg_theme->BGDest.type = checked & BST_CHECKED ? BG_PICTURE : BG_NONE; - GetDlgItemTextA(hWnd, IDC_BGIMG_EDIT, bg_theme->BGDest.file, sizeof(bg_theme->BGDest.file)); + GetDlgItemTextW(hWnd, IDC_BGIMG_EDIT, bg_theme->BGDest.file, _countof(bg_theme->BGDest.file)); bg_theme->BGDest.color = GetDlgItemTextColor(hWnd, IDC_BGIMG_COLOR_EDIT); index = SendDlgItemMessageA(hWnd, IDC_BGIMG_COMBO, CB_GETCURSEL, 0, 0); bg_theme->BGDest.pattern = (BG_PATTERN)SendDlgItemMessageA(hWnd, IDC_BGIMG_COMBO, CB_GETITEMDATA, index, 0); @@ -231,7 +230,7 @@ if (st == NULL) { break; } - index = SendDlgItemMessageA(hWnd, IDC_BGIMG_COMBO, CB_ADDSTRING, 0, (LPARAM)st->str); + index = SendDlgItemMessageW(hWnd, IDC_BGIMG_COMBO, CB_ADDSTRING, 0, (LPARAM)st->str); SendDlgItemMessageW(hWnd, IDC_BGIMG_COMBO, CB_SETITEMDATA, index, st->id); } Modified: trunk/teraterm/teraterm/themefile.cpp =================================================================== --- trunk/teraterm/teraterm/themefile.cpp 2022-10-23 15:15:59 UTC (rev 10331) +++ trunk/teraterm/teraterm/themefile.cpp 2022-10-23 15:16:14 UTC (rev 10332) @@ -39,13 +39,14 @@ #include "theme.h" -// Eterm look-feel -#define BG_SECTION "BG" -#define BG_SECTIONW L"BG" -#define BG_DESTFILE "BGDestFile" -#define BG_THEME_IMAGE_BRIGHTNESS1 "BGSrc1Alpha" -#define BG_THEME_IMAGE_BRIGHTNESS2 "BGSrc2Alpha" +#define BG_SECTION_OLD L"BG" +#define BG_SECTION_NEW L"BG Theme" +#define COLOR_THEME_SECTION L"Color Theme" +#if !defined(offsetof) +#define offsetof(s,m) ((size_t)&(((s*)0)->m)) +#endif + /** * ANSI256\x90F\x8E\x9E\x82̐擪16\x90F * INI\x83t\x83@\x83C\x83\x8B\x82\xA9\x82\xE7\x93ǂݍ\x9E\x82ނƂ\xAB\x82̃L\x81[\x83\x8F\x81[\x83h\x82ƐF\x94ԍ\x86\x91Ή\x9E @@ -54,35 +55,50 @@ int index; const wchar_t *key; } ansi_list[] = { - 7 + 8, L"Fore", - 0, L"Back", - 1 + 8, L"Red", - 2 + 8, L"Green", - 3 + 8, L"Yellow", - 4 + 8, L"Blue", - 5 + 8, L"Magenta", - 6 + 8, L"Cyan", + { 7 + 8, L"Fore" }, + { 0, L"Back" }, + { 1 + 8, L"Red" }, + { 2 + 8, L"Green" }, + { 3 + 8, L"Yellow" }, + { 4 + 8, L"Blue" }, + { 5 + 8, L"Magenta" }, + { 6 + 8, L"Cyan" }, - 7, L"DarkFore", - 0 + 8, L"DarkBack", - 1, L"DarkRed", - 2, L"DarkGreen", - 3, L"DarkYellow", - 4, L"DarkBlue", - 5, L"DarkMagenta", - 6, L"DarkCyan", + { 7, L"DarkFore" }, + { 0 + 8, L"DarkBack" }, + { 1, L"DarkRed" }, + { 2, L"DarkGreen" }, + { 3, L"DarkYellow" }, + { 4, L"DarkBlue" }, + { 5, L"DarkMagenta" }, + { 6, L"DarkCyan" }, }; +/** + * INI\x83t\x83@\x83C\x83\x8B\x82̃L\x81[\x83\x8F\x81[\x83h\x82\xC6TColorTheme\x8D\\x91\xA2\x91̂̃\x81\x83\x93\x83o\x81[\x82̑Ή\x9E\x95\ + */ +static const struct { + const wchar_t *key; + size_t offset; +} color_attr_list[] = { + { L"VTColor", offsetof(TColorTheme, vt) }, + { L"BoldColor", offsetof(TColorTheme, bold) }, + { L"BlinkColor", offsetof(TColorTheme, blink) }, + { L"ReverseColor", offsetof(TColorTheme, reverse) }, + { L"URLColor", offsetof(TColorTheme, url) }, + { L"VTUnderlineColor", offsetof(TColorTheme, underline) }, +}; + const BG_PATTERN_ST *ThemeBGPatternList(int index) { static const BG_PATTERN_ST bg_pattern_list[] = { - { BG_STRETCH, "stretch" }, - { BG_TILE, "tile" }, - { BG_CENTER, "center" }, - { BG_FIT_WIDTH, "fit_width" }, - { BG_FIT_HEIGHT, "fit_height" }, - { BG_AUTOFIT, "autofit" }, - { BG_AUTOFILL, "autofill" }, + { BG_STRETCH, L"stretch" }, + { BG_TILE, L"tile" }, + { BG_CENTER, L"center" }, + { BG_FIT_WIDTH, L"fit_width" }, + { BG_FIT_HEIGHT, L"fit_height" }, + { BG_AUTOFIT, L"autofit" }, + { BG_AUTOFILL, L"autofill" }, }; if (index >= _countof(bg_pattern_list)) { @@ -119,12 +135,9 @@ return defcolor; } -static COLORREF BGGetColor(const char *name, COLORREF defcolor, const wchar_t *file) +static COLORREF BGGetColor(const wchar_t *section, const wchar_t *key, COLORREF defcolor, const wchar_t *file) { - const wchar_t *section = BG_SECTIONW; - wchar_t *keyW = ToWcharA(name); - COLORREF color = LoadColorOneANSI(section, keyW, file, defcolor); - free(keyW); + COLORREF color = LoadColorOneANSI(section, key, file, defcolor); return color; } @@ -133,53 +146,54 @@ */ static void ThemeLoadColorOld(const wchar_t *file, TColorTheme *theme) { + const wchar_t *section = BG_SECTION_OLD; theme->ansicolor.change = TRUE; - theme->ansicolor.color[IdFore] = BGGetColor("Fore", theme->ansicolor.color[IdFore], file); - theme->ansicolor.color[IdBack] = BGGetColor("Back", theme->ansicolor.color[IdBack], file); - theme->ansicolor.color[IdRed] = BGGetColor("Red", theme->ansicolor.color[IdRed], file); - theme->ansicolor.color[IdGreen] = BGGetColor("Green", theme->ansicolor.color[IdGreen], file); - theme->ansicolor.color[IdYellow] = BGGetColor("Yellow", theme->ansicolor.color[IdYellow], file); - theme->ansicolor.color[IdBlue] = BGGetColor("Blue", theme->ansicolor.color[IdBlue], file); - theme->ansicolor.color[IdMagenta] = BGGetColor("Magenta", theme->ansicolor.color[IdMagenta], file); - theme->ansicolor.color[IdCyan] = BGGetColor("Cyan", theme->ansicolor.color[IdCyan], file); + theme->ansicolor.color[IdFore] = BGGetColor(section, L"Fore", theme->ansicolor.color[IdFore], file); + theme->ansicolor.color[IdBack] = BGGetColor(section, L"Back", theme->ansicolor.color[IdBack], file); + theme->ansicolor.color[IdRed] = BGGetColor(section, L"Red", theme->ansicolor.color[IdRed], file); + theme->ansicolor.color[IdGreen] = BGGetColor(section, L"Green", theme->ansicolor.color[IdGreen], file); + theme->ansicolor.color[IdYellow] = BGGetColor(section, L"Yellow", theme->ansicolor.color[IdYellow], file); + theme->ansicolor.color[IdBlue] = BGGetColor(section, L"Blue", theme->ansicolor.color[IdBlue], file); + theme->ansicolor.color[IdMagenta] = BGGetColor(section, L"Magenta", theme->ansicolor.color[IdMagenta], file); + theme->ansicolor.color[IdCyan] = BGGetColor(section, L"Cyan", theme->ansicolor.color[IdCyan], file); - theme->ansicolor.color[IdFore + 8] = BGGetColor("DarkFore", theme->ansicolor.color[IdFore + 8], file); - theme->ansicolor.color[IdBack + 8] = BGGetColor("DarkBack", theme->ansicolor.color[IdBack + 8], file); - theme->ansicolor.color[IdRed + 8] = BGGetColor("DarkRed", theme->ansicolor.color[IdRed + 8], file); - theme->ansicolor.color[IdGreen + 8] = BGGetColor("DarkGreen", theme->ansicolor.color[IdGreen + 8], file); - theme->ansicolor.color[IdYellow + 8] = BGGetColor("DarkYellow", theme->ansicolor.color[IdYellow + 8], file); - theme->ansicolor.color[IdBlue + 8] = BGGetColor("DarkBlue", theme->ansicolor.color[IdBlue + 8], file); - theme->ansicolor.color[IdMagenta + 8] = BGGetColor("DarkMagenta", theme->ansicolor.color[IdMagenta + 8], file); - theme->ansicolor.color[IdCyan + 8] = BGGetColor("DarkCyan", theme->ansicolor.color[IdCyan + 8], file); + theme->ansicolor.color[IdFore + 8] = BGGetColor(section, L"DarkFore", theme->ansicolor.color[IdFore + 8], file); + theme->ansicolor.color[IdBack + 8] = BGGetColor(section, L"DarkBack", theme->ansicolor.color[IdBack + 8], file); + theme->ansicolor.color[IdRed + 8] = BGGetColor(section, L"DarkRed", theme->ansicolor.color[IdRed + 8], file); + theme->ansicolor.color[IdGreen + 8] = BGGetColor(section, L"DarkGreen", theme->ansicolor.color[IdGreen + 8], file); + theme->ansicolor.color[IdYellow + 8] = BGGetColor(section, L"DarkYellow", theme->ansicolor.color[IdYellow + 8], file); + theme->ansicolor.color[IdBlue + 8] = BGGetColor(section, L"DarkBlue", theme->ansicolor.color[IdBlue + 8], file); + theme->ansicolor.color[IdMagenta + 8] = BGGetColor(section, L"DarkMagenta", theme->ansicolor.color[IdMagenta + 8], file); + theme->ansicolor.color[IdCyan + 8] = BGGetColor(section, L"DarkCyan", theme->ansicolor.color[IdCyan + 8], file); - theme->vt.fg = BGGetColor("VTFore", theme->vt.fg, file); - theme->vt.bg = BGGetColor("VTBack", theme->vt.bg, file); + theme->vt.fg = BGGetColor(section, L"VTFore", theme->vt.fg, file); + theme->vt.bg = BGGetColor(section, L"VTBack", theme->vt.bg, file); theme->vt.change = TRUE; theme->vt.enable = TRUE; - theme->blink.fg = BGGetColor("VTBlinkFore", theme->blink.fg, file); - theme->blink.bg = BGGetColor("VTBlinkBack", theme->blink.bg, file); + theme->blink.fg = BGGetColor(section, L"VTBlinkFore", theme->blink.fg, file); + theme->blink.bg = BGGetColor(section, L"VTBlinkBack", theme->blink.bg, file); theme->blink.change = TRUE; theme->blink.enable = TRUE; - theme->bold.fg = BGGetColor("VTBoldFore", theme->bold.fg, file); - theme->bold.bg = BGGetColor("VTBoldBack", theme->bold.bg, file); + theme->bold.fg = BGGetColor(section, L"VTBoldFore", theme->bold.fg, file); + theme->bold.bg = BGGetColor(section, L"VTBoldBack", theme->bold.bg, file); theme->bold.change = TRUE; theme->bold.enable = TRUE; - theme->underline.fg = BGGetColor("VTUnderlineFore", theme->underline.fg, file); - theme->underline.bg = BGGetColor("VTUnderlineBack", theme->underline.bg, file); + theme->underline.fg = BGGetColor(section, L"VTUnderlineFore", theme->underline.fg, file); + theme->underline.bg = BGGetColor(section, L"VTUnderlineBack", theme->underline.bg, file); theme->underline.change = TRUE; theme->underline.enable = TRUE; - theme->reverse.fg = BGGetColor("VTReverseFore", theme->reverse.fg, file); - theme->reverse.bg = BGGetColor("VTReverseBack", theme->reverse.bg, file); + theme->reverse.fg = BGGetColor(section, L"VTReverseFore", theme->reverse.fg, file); + theme->reverse.bg = BGGetColor(section, L"VTReverseBack", theme->reverse.bg, file); theme->reverse.change = TRUE; theme->reverse.enable = TRUE; - theme->url.fg = BGGetColor("URLFore", theme->url.fg, file); - theme->url.bg = BGGetColor("URLBack", theme->url.bg, file); + theme->url.fg = BGGetColor(section, L"URLFore", theme->url.fg, file); + theme->url.bg = BGGetColor(section, L"URLBack", theme->url.bg, file); theme->url.change = TRUE; theme->url.enable = TRUE; } @@ -187,13 +201,13 @@ /** * save color one attribute */ -static void SaveColorAttr(const wchar_t *section, const wchar_t *key, const TColorSetting *color, const wchar_t *fn) +static void BGSaveColorOne(const wchar_t *section, const wchar_t *key, const TColorSetting *color, const wchar_t *fn) { wchar_t *buf; COLORREF fg = color->fg; COLORREF bg = color->bg; int sp_len = 20 - (int)wcslen(key); - aswprintf(&buf, L"%*.*s %d,%d, %3hhu,%3hhu,%3hhu, %3hhu,%3hhu,%3hhu ; #%02x%02x%02x, #%02x%02x%02x", + aswprintf(&buf, L"%*.*s %d,%d, %3hhu,%3hhu,%3hhu, %3hhu,%3hhu,%3hhu ; #%02x%02x%02x, #%02x%02x%02x", sp_len, sp_len, L" ", color->change, color->enable, GetRValue(fg), GetGValue(fg), GetBValue(fg), @@ -204,16 +218,9 @@ free(buf); } -static void BGSaveColorOne(const TColorSetting *color, const char *key, const wchar_t *fn) +#if 1 +static void BGSaveColorANSI(const wchar_t *section, const TAnsiColorSetting *color, const wchar_t *fn) { - const wchar_t *section = L"Color Theme"; - wchar_t *keyW = ToWcharA(key); - SaveColorAttr(section, keyW, color, fn); - free(keyW); -} - -static void BGSaveColorANSI(const TAnsiColorSetting *color, const wchar_t *fn) -{ int i; wchar_t *buff = NULL; awcscat(&buff, L"1, 1, "); @@ -225,9 +232,10 @@ awcscat(&buff, color_str); } - WritePrivateProfileStringW(L"Color Theme", L"ANSIColor", buff, fn); + WritePrivateProfileStringW(section, L"ANSIColor", buff, fn); free(buff); } +#endif static void SaveColorOneANSI(const wchar_t *section, const wchar_t *key, const wchar_t *file, COLORREF color, int index) { @@ -259,46 +267,52 @@ /** * \x83J\x83\x89\x81[\x83e\x81[\x83}\x82̕ۑ\xB6 + * TODO \x8D폜 */ +#if 1 void ThemeSaveColorOld(TColorTheme *color_theme, const wchar_t *fn) { - WritePrivateProfileStringAFileW("Color Theme", "Theme", "teraterm theme editor", fn); + const wchar_t *section = COLOR_THEME_SECTION; - BGSaveColorOne(&(color_theme->vt), "VTColor", fn); - BGSaveColorOne(&(color_theme->bold), "BoldColor", fn); - BGSaveColorOne(&(color_theme->blink), "BlinkColor", fn); - BGSaveColorOne(&(color_theme->reverse), "ReverseColor", fn); - BGSaveColorOne(&(color_theme->url), "URLColor", fn); - BGSaveColorOne(&(color_theme->underline), "VTUnderlineColor", fn); + WritePrivateProfileStringW(section, L"Theme", color_theme->name, fn); - BGSaveColorANSI(&(color_theme->ansicolor), fn); + for (int i = 0; i < _countof(color_attr_list); i++) { + const wchar_t *key = color_attr_list[i].key; + const TColorSetting *color = (TColorSetting *)((UINT_PTR)color_theme + color_attr_list[i].offset); + BGSaveColorOne(section, key, color, fn); + } + + BGSaveColorANSI(section, &(color_theme->ansicolor), fn); } +#endif +/** + * \x83J\x83\x89\x81[\x83e\x81[\x83}\x82̕ۑ\xB6 + */ void ThemeSaveColor(TColorTheme *color_theme, const wchar_t *fn) { - const wchar_t *section = L"Color Theme"; + const wchar_t *section = COLOR_THEME_SECTION; WritePrivateProfileStringW(section, L"Theme", color_theme->name, fn); - BGSaveColorOne(&(color_theme->vt), "VTColor", fn); - BGSaveColorOne(&(color_theme->bold), "BoldColor", fn); - BGSaveColorOne(&(color_theme->blink), "BlinkColor", fn); - BGSaveColorOne(&(color_theme->reverse), "ReverseColor", fn); - BGSaveColorOne(&(color_theme->url), "URLColor", fn); - BGSaveColorOne(&(color_theme->underline), "VTUnderlineColor", fn); + for (int i = 0; i < _countof(color_attr_list); i++) { + const wchar_t *key = color_attr_list[i].key; + const TColorSetting *color = (TColorSetting *)((UINT_PTR)color_theme + color_attr_list[i].offset); + BGSaveColorOne(section, key, color, fn); + } SaveColorANSINew(section, &(color_theme->ansicolor), fn); } -void WriteInt3(const char *Sect, const char *Key, const wchar_t *FName, - int i1, int i2, int i3) +static void WriteInt3(const wchar_t *Sect, const wchar_t *Key, const wchar_t *FName, + int i1, int i2, int i3) { - char Temp[96]; - _snprintf_s(Temp, sizeof(Temp), _TRUNCATE, "%d,%d,%d", + wchar_t Temp[96]; + _snwprintf_s(Temp, _countof(Temp), _TRUNCATE, L"%d,%d,%d", i1, i2,i3); - WritePrivateProfileStringAFileW(Sect, Key, Temp, FName); + WritePrivateProfileStringW(Sect, Key, Temp, FName); } -void WriteCOLORREF(const char *Sect, const char *Key, const wchar_t *FName, COLORREF color) +static void WriteCOLORREF(const wchar_t *Sect, const wchar_t *Key, const wchar_t *FName, COLORREF color) { int red = color & 0xff; int green = (color >> 8) & 0xff; @@ -307,7 +321,7 @@ WriteInt3(Sect, Key, FName, red, green, blue); } -static const char *GetBGPatternStr(BG_PATTERN id) +static const wchar_t *GetBGPatternStr(BG_PATTERN id) { int index; for (index = 0;; index++) { @@ -323,7 +337,7 @@ } } -static BOOL GetBGPatternID(const char *str, BG_PATTERN *pattern) +static BOOL GetBGPatternID(const wchar_t *str, BG_PATTERN *pattern) { int index; for (index = 0;; index++) { @@ -334,7 +348,7 @@ *pattern = st->id; return FALSE; } - if (_stricmp(st->str, str) == 0) { + if (_wcsicmp(st->str, str) == 0) { *pattern = st->id; return TRUE; } @@ -343,51 +357,54 @@ void ThemeSaveBG(const BGTheme *bg_theme, const wchar_t *file) { - WritePrivateProfileStringAFileW(BG_SECTION, BG_DESTFILE, bg_theme->BGDest.file, file); + const wchar_t *section = BG_SECTION_NEW; + + WritePrivateProfileStringW(section, L"BGDestFile", bg_theme->BGDest.file, file); #if 0 - WritePrivateProfileStringAFileW(BG_SECTION, "BGDestType", + WritePrivateProfileStringW(section, L"BGDestType", bg_theme->BGDest.type == BG_PICTURE ? "picture" : "color", file); #endif - WriteCOLORREF(BG_SECTION, "BGDestColor", file, bg_theme->BGDest.color); - WritePrivateProfileStringAFileW(BG_SECTION, "BGDestPattern", GetBGPatternStr(bg_theme->BGDest.pattern), file); + WriteCOLORREF(section, L"BGDestColor", file, bg_theme->BGDest.color); + WritePrivateProfileStringW(section, L"BGDestPattern", GetBGPatternStr(bg_theme->BGDest.pattern), file); - WritePrivateProfileIntAFileW(BG_SECTION, "BGSrc1Alpha", bg_theme->BGSrc1.alpha, file); + WritePrivateProfileIntW(section, L"BGSrc1Alpha", bg_theme->BGSrc1.alpha, file); - WritePrivateProfileIntAFileW(BG_SECTION, "BGSrc2Alpha", bg_theme->BGSrc2.alpha, file); - WriteCOLORREF(BG_SECTION, "BGSrc2Color", file, bg_theme->BGSrc2.color); + WritePrivateProfileIntW(section, L"BGSrc2Alpha", bg_theme->BGSrc2.alpha, file); + WriteCOLORREF(section, L"BGSrc2Color", file, bg_theme->BGSrc2.color); - WritePrivateProfileIntW(BG_SECTIONW, L"BGReverseTextAlpha", bg_theme->BGReverseTextAlpha, file); + WritePrivateProfileIntW(section, L"BGReverseTextAlpha", bg_theme->BGReverseTextAlpha, file); } -static int BGGetStrIndex(const char *name, int def, const wchar_t *file, const char * const *strList, int nList) +static int BGGetStrIndex(const wchar_t *section, const wchar_t *name, int def, const wchar_t *file, const wchar_t * const *strList, int nList) { - char defstr[64], str[64]; + wchar_t defstr[64]; + wchar_t str[64]; int i; def %= nList; - strncpy_s(defstr, sizeof(defstr), strList[def], _TRUNCATE); - GetPrivateProfileStringAFileW(BG_SECTION, name, defstr, str, 64, file); + wcsncpy_s(defstr, _countof(defstr), strList[def], _TRUNCATE); + GetPrivateProfileStringW(section, name, defstr, str, _countof(str), file); for (i = 0; i < nList; i++) - if (!_stricmp(str, strList[i])) + if (!_wcsicmp(str, strList[i])) return i; return 0; } -static BOOL BGGetOnOff(const char *name, BOOL def, const wchar_t *file) +static BOOL BGGetOnOff(const wchar_t *section, const wchar_t *name, BOOL def, const wchar_t *file) { - static const char * const strList[2] = {"Off", "On"}; + static const wchar_t * const strList[2] = {L"Off", L"On"}; - return (BOOL)BGGetStrIndex(name, def, file, strList, 2); + return (BOOL)BGGetStrIndex(section, name, def, file, strList, 2); } -static BG_PATTERN BGGetPattern(const char *name, BG_PATTERN def, const wchar_t *file) +static BG_PATTERN BGGetPattern(const wchar_t *section, const wchar_t *name, BG_PATTERN def, const wchar_t *file) { BG_PATTERN retval; - char str[64]; - GetPrivateProfileStringAFileW(BG_SECTION, name, "", str, _countof(str), file); + wchar_t str[64]; + GetPrivateProfileStringW(section, name, L"", str, _countof(str), file); if (str[0] == 0) { return def; } @@ -397,67 +414,94 @@ return retval; } -static BG_TYPE BGGetType(const char *name, BG_TYPE def, const wchar_t *file) +static BG_TYPE BGGetType(const wchar_t *section, const wchar_t *name, BG_TYPE def, const wchar_t *file) { - static const char *strList[3] = {"color", "picture", "wallpaper"}; + static const wchar_t *strList[3] = {L"color", L"picture", L"wallpaper"}; - return (BG_TYPE)BGGetStrIndex(name, def, file, strList, 3); + return (BG_TYPE)BGGetStrIndex(section, name, def, file, strList, 3); } /** * BG\x82\xF0\x83\x8D\x81[\x83h - * TODO \x90F\x82̓Ǐo\x82\xB5 */ -void ThemeLoadBG(const wchar_t *file, BGTheme *bg_theme) +void ThemeLoadBGSection(const wchar_t *section, const wchar_t *file, BGTheme *bg_theme) { - char path[MAX_PATH]; + wchar_t pathW[MAX_PATH]; + wchar_t *p; // Dest \x82̓ǂݏo\x82\xB5 - bg_theme->BGDest.type = BGGetType("BGDestType", bg_theme->BGDest.type, file); - bg_theme->BGDest.pattern = BGGetPattern("BGPicturePattern", bg_theme->BGDest.pattern, file); - bg_theme->BGDest.pattern = BGGetPattern("BGDestPattern", bg_theme->BGDest.pattern, file); - bg_theme->BGDest.antiAlias = BGGetOnOff("BGDestAntiAlias", bg_theme->BGDest.antiAlias, file); - bg_theme->BGDest.color = BGGetColor("BGPictureBaseColor", bg_theme->BGDest.color, file); - bg_theme->BGDest.color = BGGetColor("BGDestColor", bg_theme->BGDest.color, file); - GetPrivateProfileStringAFileW(BG_SECTION, "BGPictureFile", bg_theme->BGDest.file, path, sizeof(bg_theme->BGDest.file), file); - strcpy_s(bg_theme->BGDest.file, _countof(bg_theme->BGDest.file), path); - GetPrivateProfileStringAFileW(BG_SECTION, BG_DESTFILE, bg_theme->BGDest.file, path, MAX_PATH, file); - RandomFile(path, bg_theme->BGDest.file, sizeof(bg_theme->BGDest.file)); - if (bg_theme->BGDest.file[0] == 0) { - // \x83t\x83@\x83C\x83\x8B\x96\xBC\x82\xAA\x96\xB3\x8C\xF8\x82Ȃ̂ŁADest\x82\xF8\x82ɂ\xB7\x82\xE9 - bg_theme->BGDest.type = BG_NONE; + bg_theme->BGDest.type = BGGetType(section, L"BGDestType", bg_theme->BGDest.type, file); + bg_theme->BGDest.pattern = BGGetPattern(section, L"BGPicturePattern", bg_theme->BGDest.pattern, file); + bg_theme->BGDest.pattern = BGGetPattern(section, L"BGDestPattern", bg_theme->BGDest.pattern, file); + bg_theme->BGDest.antiAlias = BGGetOnOff(section, L"BGDestAntiAlias", bg_theme->BGDest.antiAlias, file); + bg_theme->BGDest.color = BGGetColor(section, L"BGPictureBaseColor", bg_theme->BGDest.color, file); + bg_theme->BGDest.color = BGGetColor(section, L"BGDestColor", bg_theme->BGDest.color, file); + GetPrivateProfileStringW(section, L"BGPictureFile", bg_theme->BGDest.file, pathW, _countof(pathW), file); + GetPrivateProfileStringW(section, L"BGDestFile", pathW, pathW, _countof(pathW), file); + p = RandomFileW(pathW); + if (p != NULL) { + wcscpy_s(bg_theme->BGDest.file, _countof(bg_theme->BGDest.file), p); + free(p); } + else { + bg_theme->BGDest.file[0] = 0; + bg_theme->BGDest.type = BG_NONE; // \x94w\x8Ci\x89摜\x96\xB3\x82\xB5 + } // Src1 \x82̓ǂݏo\x82\xB5 - bg_theme->BGSrc1.type = BGGetType("BGSrc1Type", bg_theme->BGSrc1.type, file); - bg_theme->BGSrc1.pattern = BGGetPattern("BGSrc1Pattern", bg_theme->BGSrc1.pattern, file); - bg_theme->BGSrc1.antiAlias = BGGetOnOff("BGSrc1AntiAlias", bg_theme->BGSrc1.antiAlias, file); - bg_theme->BGSrc1.alpha = 255 - GetPrivateProfileIntAFileW(BG_SECTION, "BGPictureTone", 255 - bg_theme->BGSrc1.alpha, file); - if (!strcmp(bg_theme->BGDest.file, "")) + bg_theme->BGSrc1.type = BGGetType(section, L"BGSrc1Type", bg_theme->BGSrc1.type, file); + bg_theme->BGSrc1.pattern = BGGetPattern(section, L"BGSrc1Pattern", bg_theme->BGSrc1.pattern, file); + bg_theme->BGSrc1.antiAlias = BGGetOnOff(section, L"BGSrc1AntiAlias", bg_theme->BGSrc1.antiAlias, file); + bg_theme->BGSrc1.alpha = 255 - GetPrivateProfileIntW(section, L"BGPictureTone", 255 - bg_theme->BGSrc1.alpha, file); + if (bg_theme->BGDest.file[0] == 0) bg_theme->BGSrc1.alpha = 255; - bg_theme->BGSrc1.alpha = GetPrivateProfileIntAFileW(BG_SECTION, "BGSrc1Alpha", bg_theme->BGSrc1.alpha, file); - bg_theme->BGSrc1.color = BGGetColor("BGSrc1Color", bg_theme->BGSrc1.color, file); - GetPrivateProfileStringAFileW(BG_SECTION, "BGSrc1File", bg_theme->BGSrc1.file, path, MAX_PATH, file); - RandomFile(path, bg_theme->BGSrc1.file, sizeof(bg_theme->BGSrc1.file)); + bg_theme->BGSrc1.alpha = GetPrivateProfileIntW(section, L"BGSrc1Alpha", bg_theme->BGSrc1.alpha, file); + bg_theme->BGSrc1.color = BGGetColor(section, L"BGSrc1Color", bg_theme->BGSrc1.color, file); + GetPrivateProfileStringW(section, L"BGSrc1File", bg_theme->BGSrc1.file, pathW, _countof(pathW), file); + p = RandomFileW(pathW); + if (p != NULL) { + wcscpy_s(bg_theme->BGSrc1.file, _countof(bg_theme->BGSrc1.file), p); + free(p); + } + else { + bg_theme->BGSrc1.file[0] = 0; + } // Src2 \x82̓ǂݏo\x82\xB5 - bg_theme->BGSrc2.type = BGGetType("BGSrc2Type", bg_theme->BGSrc2.type, file); - bg_theme->BGSrc2.pattern = BGGetPattern("BGSrc2Pattern", bg_theme->BGSrc2.pattern, file); - bg_theme->BGSrc2.antiAlias = BGGetOnOff("BGSrc2AntiAlias", bg_theme->BGSrc2.antiAlias, file); - bg_theme->BGSrc2.alpha = 255 - GetPrivateProfileIntAFileW(BG_SECTION, "BGFadeTone", 255 - bg_theme->BGSrc2.alpha, file); - bg_theme->BGSrc2.alpha = GetPrivateProfileIntAFileW(BG_SECTION, "BGSrc2Alpha", bg_theme->BGSrc2.alpha, file); - bg_theme->BGSrc2.color = BGGetColor("BGFadeColor", bg_theme->BGSrc2.color, file); - bg_theme->BGSrc2.color = BGGetColor("BGSrc2Color", bg_theme->BGSrc2.color, file); - GetPrivateProfileStringAFileW(BG_SECTION, "BGSrc2File", bg_theme->BGSrc2.file, path, MAX_PATH, file); - RandomFile(path, bg_theme->BGSrc2.file, sizeof(bg_theme->BGSrc2.file)); + bg_theme->BGSrc2.type = BGGetType(section, L"BGSrc2Type", bg_theme->BGSrc2.type, file); + bg_theme->BGSrc2.pattern = BGGetPattern(section, L"BGSrc2Pattern", bg_theme->BGSrc2.pattern, file); + bg_theme->BGSrc2.antiAlias = BGGetOnOff(section, L"BGSrc2AntiAlias", bg_theme->BGSrc2.antiAlias, file); + bg_theme->BGSrc2.alpha = 255 - GetPrivateProfileIntW(section, L"BGFadeTone", 255 - bg_theme->BGSrc2.alpha, file); + bg_theme->BGSrc2.alpha = GetPrivateProfileIntW(section, L"BGSrc2Alpha", bg_theme->BGSrc2.alpha, file); + bg_theme->BGSrc2.color = BGGetColor(section, L"BGFadeColor", bg_theme->BGSrc2.color, file); + bg_theme->BGSrc2.color = BGGetColor(section, L"BGSrc2Color", bg_theme->BGSrc2.color, file); + GetPrivateProfileStringW(section, L"BGSrc2File", bg_theme->BGSrc2.file, pathW, _countof(pathW), file); + p = RandomFileW(pathW); + if (p != NULL) { + wcscpy_s(bg_theme->BGSrc2.file, _countof(bg_theme->BGSrc2.file), p); + free(p); + } + else { + bg_theme->BGSrc2.file[0] = 0; + } //\x82\xBB\x82̑\xBC\x93ǂݏo\x82\xB5 - bg_theme->BGReverseTextAlpha = GetPrivateProfileIntAFileW(BG_SECTION, "BGReverseTextTone", bg_theme->BGReverseTextAlpha, file); - bg_theme->BGReverseTextAlpha = GetPrivateProfileIntAFileW(BG_SECTION, "BGReverseTextAlpha", bg_theme->BGReverseTextAlpha, file); + bg_theme->BGReverseTextAlpha = GetPrivateProfileIntW(section, L"BGReverseTextTone", bg_theme->BGReverseTextAlpha, file); + bg_theme->BGReverseTextAlpha = GetPrivateProfileIntW(section, L"BGReverseTextAlpha", bg_theme->BGReverseTextAlpha, file); } -static void ReadANSIColorSetting(TAnsiColorSetting *color, const wchar_t *fn) +/** + * BG\x82\xF0\x83\x8D\x81[\x83h + */ +void ThemeLoadBG(const wchar_t *file, BGTheme *bg_theme) { + ThemeLoadBGSection(BG_SECTION_OLD, file, bg_theme); + ThemeLoadBGSection(BG_SECTION_NEW, file, bg_theme); +} + +static void ReadANSIColorSetting(const wchar_t *section, TAnsiColorSetting *color, const wchar_t *fn) +{ + wchar_t BuffW[512]; char Buff[512]; int c, r, g, b; // ANSIColor16\x82́A\x96\xBE\x82邢/\x88Â\xA2\x83O\x83\x8B\x81[\x83v\x82\xAA\x93\xFC\x82\xEA\x91ւ\xED\x82\xC1\x82Ă\xA2\x82\xE9 @@ -468,7 +512,8 @@ 9, 10, 11, 12, 13, 14, 15, }; - GetPrivateProfileStringAFileW("Color Theme", "ANSIColor", "0", Buff, sizeof(Buff), fn); + GetPrivateProfileStringW(section, L"ANSIColor", L"0", BuffW, sizeof(BuffW), fn); + WideCharToACP_t(BuffW, Buff, _countof(Buff)); GetNthNum(Buff, 1, &c); color->change = c; @@ -485,12 +530,14 @@ } } -static void ReadColorSetting(TColorSetting *color, const char *key, const wchar_t *fn) +static void ReadColorSetting(const wchar_t *section, TColorSetting *color, const wchar_t *key, const wchar_t *fn) { + wchar_t BuffW[512]; char Buff[512]; int c, r, g, b; - GetPrivateProfileStringAFileW("Color Theme", key, "0", Buff, sizeof(Buff), fn); + GetPrivateProfileStringW(section, key, L"0", BuffW, _countof(BuffW), fn); + WideCharToACP_t(BuffW, Buff, _countof(Buff)); GetNthNum(Buff, 1, &c); color->change = c; @@ -516,19 +563,19 @@ */ static void LoadColorPlugin(const wchar_t *fn, TColorTheme *color_theme) { - const wchar_t *section = L"Color Theme"; + const wchar_t *section = COLOR_THEME_SECTION; wchar_t *name; hGetPrivateProfileStringW(section, L"Theme", NULL, fn, &name); wcscpy_s(color_theme->name, _countof(color_theme->name), name); free(name); - ReadColorSetting(&(color_theme->vt), "VTColor", fn); - ReadColorSetting(&(color_theme->bold), "BoldColor", fn); - ReadColorSetting(&(color_theme->blink), "BlinkColor", fn); - ReadColorSetting(&(color_theme->reverse), "ReverseColor", fn); - ReadColorSetting(&(color_theme->url), "URLColor", fn); + for (int i = 0; i < _countof(color_attr_list); i++) { + const wchar_t *key = color_attr_list[i].key; + TColorSetting *color = (TColorSetting *)((UINT_PTR)color_theme + color_attr_list[i].offset); + ReadColorSetting(section, color, key, fn); + } - ReadANSIColorSetting(&(color_theme->ansicolor), fn); + ReadANSIColorSetting(section, &(color_theme->ansicolor), fn); } /** @@ -591,7 +638,7 @@ */ static void ThemeLoadColorDraft(const wchar_t *file, TColorTheme *theme) { - const wchar_t *section = L"Color Theme"; + const wchar_t *section = COLOR_THEME_SECTION; wchar_t *name; hGetPrivateProfileStringW(section, L"Theme", NULL, file, &name); @@ -598,19 +645,10 @@ wcscpy_s(theme->name, _countof(theme->name), name); free(name); - struct { - const wchar_t *key; - TColorSetting *color; - } attr_list[] = { - L"VTColor", &(theme->vt), - L"BoldColor", &(theme->bold), - L"BlinkColor", &(theme->blink), - L"ReverseColor", &(theme->reverse), - L"URLColor", &(theme->url), - L"VTUnderlineColor", &(theme->underline), - }; - for (int i = 0; i < _countof(attr_list); i++) { - LoadColorAttr(section, attr_list[i].key, file, attr_list[i].color); + for (int i = 0; i < _countof(color_attr_list); i++) { + const wchar_t *key = color_attr_list[i].key; + TColorSetting *color = (TColorSetting *)((UINT_PTR)theme + color_attr_list[i].offset); + LoadColorAttr(section, key, file, color); } theme->ansicolor.change = (BOOL)GetPrivateProfileIntW(section, L"ANSIColor", 1, file); @@ -667,10 +705,10 @@ if (len == 0) { break; } - if (_wcsicmp(p, L"BG") == 0) { + if (_wcsicmp(p, BG_SECTION_NEW) == 0 || _wcsicmp(p, BG_SECTION_OLD) == 0) { bg = TRUE; } - else if(_wcsicmp(p, L"Color Theme") == 0) { + else if(_wcsicmp(p, COLOR_THEME_SECTION) == 0) { color = TRUE; } i += len; Modified: trunk/teraterm/teraterm/vtdisp.c =================================================================== --- trunk/teraterm/teraterm/vtdisp.c 2022-10-23 15:15:59 UTC (rev 10331) +++ trunk/teraterm/teraterm/vtdisp.c 2022-10-23 15:16:14 UTC (rev 10332) @@ -1387,7 +1387,7 @@ static int GetIndex256From16(int index16) { // ANSIColor16\x82́A\x96\xBE\x82邢/\x88Â\xA2\x83O\x83\x8B\x81[\x83v\x82\xAA\x93\xFC\x82\xEA\x91ւ\xED\x82\xC1\x82Ă\xA2\x82\xE9 - const static int index256[] = { + static const int index256[] = { 0, 9, 10, 11, 12, 13, 14, 15, 8, @@ -3735,7 +3735,7 @@ */ void ThemeSetBG(const BGTheme *bg_theme) { - strcpy_s(BGDest.file, _countof(BGDest.file), bg_theme->BGDest.file); + WideCharToACP_t(bg_theme->BGDest.file, BGDest.file, _countof(BGDest.file)); BGDest.type = bg_theme->BGDest.type; BGDest.color = bg_theme->BGDest.color; BGDest.pattern = bg_theme->BGDest.pattern; @@ -3754,7 +3754,7 @@ void ThemeGetBG(BGTheme *bg_theme) { - strcpy_s(bg_theme->BGDest.file, _countof(bg_theme->BGDest.file), BGDest.file); + ACPToWideChar_t(BGDest.file, bg_theme->BGDest.file, _countof(bg_theme->BGDest.file)); bg_theme->BGDest.type = BG_PICTURE; bg_theme->BGDest.color = BGDest.color; bg_theme->BGDest.pattern = BGDest.pattern;