[ttssh2-commit] [10256] テーマファイルに関連する関数などを themefile.cpp へ移動

Back to archive index
scmno****@osdn***** scmno****@osdn*****
2022年 9月 10日 (土) 00:07:27 JST


Revision: 10256
          https://osdn.net/projects/ttssh2/scm/svn/commits/10256
Author:   zmatsuo
Date:     2022-09-10 00:07:26 +0900 (Sat, 10 Sep 2022)
Log Message:
-----------
テーマファイルに関連する関数などを themefile.cpp へ移動

- bg_theme.h を theme.h へリネーム
- 関数名を Theme~ にリネームした
- BGテーマの設定を行っていると背景画像が表示されなくなる場合があったので修正
- 画像を設定していないのに背景画像チェックボックスのチェックが入ることがあった

Modified Paths:
--------------
    trunk/teraterm/common/teraterm.h
    trunk/teraterm/teraterm/CMakeLists.txt
    trunk/teraterm/teraterm/themedlg.cpp
    trunk/teraterm/teraterm/ttermpro.v16.vcxproj
    trunk/teraterm/teraterm/ttermpro.v16.vcxproj.filters
    trunk/teraterm/teraterm/ttermpro.v8.vcproj
    trunk/teraterm/teraterm/vtdisp.c
    trunk/teraterm/teraterm/vtdisp.h
    trunk/teraterm/ttpset/ttset.c

Added Paths:
-----------
    trunk/teraterm/teraterm/theme.h
    trunk/teraterm/teraterm/themefile.cpp

Removed Paths:
-------------
    trunk/teraterm/teraterm/bg_theme.h

-------------- next part --------------
Modified: trunk/teraterm/common/teraterm.h
===================================================================
--- trunk/teraterm/common/teraterm.h	2022-09-09 14:12:36 UTC (rev 10255)
+++ trunk/teraterm/common/teraterm.h	2022-09-09 15:07:26 UTC (rev 10256)
@@ -54,23 +54,6 @@
 	#endif
 #endif
 
-// Eterm look-feel
-#define BG_SECTION "BG"
-#define BG_SECTIONW L"BG"
-#define BG_DESTFILE "BGDestFile"
-#define BG_DESTFILEW L"BGDestFile"
-#define BG_THEME_DIR L"theme"
-//#define BG_THEME_IMAGEFILE "theme\\ImageFile.INI"
-//#define BG_THEME_IMAGEFILE_DEFAULT "theme\\*.INI"
-#define BG_THEME_IMAGE_BRIGHTNESS_DEFAULT 64
-#define BG_THEME_IMAGE_BRIGHTNESS1 "BGSrc1Alpha"
-#define BG_THEME_IMAGE_BRIGHTNESS1W L"BGSrc1Alpha"
-#define BG_THEME_IMAGE_BRIGHTNESS2 "BGSrc2Alpha"
-//#define BG_THEME_IMAGEFILE_NAME "ImageFile.INI"
-//#define BG_THEME_IMAGEFILE_NAMEW L"ImageFile.INI"
-//#define BG_THEME_THEMEFILE_SCALE "Scale.INI"
-//#define BG_THEME_THEMEFILE_TILE "Tile.INI"
-
 #include "i18n.h"
 #include "ttlib.h"
 

Modified: trunk/teraterm/teraterm/CMakeLists.txt
===================================================================
--- trunk/teraterm/teraterm/CMakeLists.txt	2022-09-09 14:12:36 UTC (rev 10255)
+++ trunk/teraterm/teraterm/CMakeLists.txt	2022-09-09 15:07:26 UTC (rev 10256)
@@ -11,7 +11,6 @@
   ${PACKAGE_NAME} WIN32
   addsetting.cpp
   addsetting.h
-  bg_theme.h
   broadcast.cpp
   broadcast.h
   buffer.c
@@ -61,6 +60,8 @@
   teraprn.h
   teraterm.cpp
   teraterml.h
+  theme.h
+  themefile.cpp
   ttdde.c
   ttdde.h
   ttdebug.cpp

Deleted: trunk/teraterm/teraterm/bg_theme.h
===================================================================
--- trunk/teraterm/teraterm/bg_theme.h	2022-09-09 14:12:36 UTC (rev 10255)
+++ trunk/teraterm/teraterm/bg_theme.h	2022-09-09 15:07:26 UTC (rev 10256)
@@ -1,102 +0,0 @@
-/*
- * Copyright (C) 1994-1998 T. Teranishi
- * (C) 2022- TeraTerm Project
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- * 3. The name of the author may not be used to endorse or promote products
- *    derived from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS OR
- * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
- * IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
- * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
- * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#pragma once
-
-#include <windows.h>
-
-typedef enum _BG_TYPE { BG_COLOR = 0, BG_PICTURE, BG_WALLPAPER, BG_NONE } BG_TYPE;
-typedef enum _BG_PATTERN {
-	BG_STRETCH = 0,
-	BG_TILE,
-	BG_CENTER,
-	BG_FIT_WIDTH,
-	BG_FIT_HEIGHT,
-	BG_AUTOFIT,
-	BG_AUTOFILL
-} BG_PATTERN;
-
-typedef struct {
-	BG_TYPE type;
-	BG_PATTERN pattern;
-	BOOL antiAlias;
-	COLORREF color;
-	int alpha;
-	char file[MAX_PATH];
-} TBGSrc;
-
-typedef struct _BGTheme {
-	TBGSrc BGDest;
-	TBGSrc BGSrc1;
-	TBGSrc BGSrc2;
-	int BGReverseTextAlpha;
-} BGTheme;
-
-////////////////////
-// color theme
-////////////////////
-
-typedef struct {
-	BOOL change;
-	BOOL enable;
-	COLORREF fg;
-	COLORREF bg;
-} TColorSetting;
-
-typedef struct {
-	BOOL change;
-	BOOL enable;
-	COLORREF color[16];
-} TAnsiColorSetting;
-
-typedef struct {
-	char name[50];
-	TColorSetting vt;
-	TColorSetting bold;			// SGR 1
-	TColorSetting underline;	// SGR 4
-	TColorSetting blink;		// SGR 5
-	TColorSetting reverse;		// SGR 7
-	TColorSetting url;
-	TAnsiColorSetting ansicolor;
-} TColorTheme;
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-void BGLoad(const wchar_t *fname, BGTheme *bg_theme, TColorTheme *color_theme);
-void BGSave(const BGTheme *bg_theme, const wchar_t *fname);
-void BGSaveColor(TColorTheme *color_theme, const wchar_t *fname);
-void BGSet(const BGTheme *bg_theme);
-void BGGet(BGTheme *bg_theme);
-void GetColorData(TColorTheme *data);
-void BGSetColorData(const TColorTheme *data);
-void BGGetColorDefault(TColorTheme *data);
-#ifdef __cplusplus
-}
-#endif

Copied: trunk/teraterm/teraterm/theme.h (from rev 10255, trunk/teraterm/teraterm/bg_theme.h)
===================================================================
--- trunk/teraterm/teraterm/theme.h	                        (rev 0)
+++ trunk/teraterm/teraterm/theme.h	2022-09-09 15:07:26 UTC (rev 10256)
@@ -0,0 +1,120 @@
+/*
+ * Copyright (C) 1994-1998 T. Teranishi
+ * (C) 2022- TeraTerm Project
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. The name of the author may not be used to endorse or promote products
+ *    derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#pragma once
+
+#include <windows.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+typedef enum _BG_TYPE { BG_COLOR = 0, BG_PICTURE, BG_WALLPAPER, BG_NONE } BG_TYPE;
+typedef enum _BG_PATTERN {
+	BG_STRETCH = 0,
+	BG_TILE,
+	BG_CENTER,
+	BG_FIT_WIDTH,
+	BG_FIT_HEIGHT,
+	BG_AUTOFIT,
+	BG_AUTOFILL
+} BG_PATTERN;
+
+typedef struct {
+	BG_TYPE type;
+	BG_PATTERN pattern;
+	BOOL antiAlias;
+	COLORREF color;
+	int alpha;
+	char file[MAX_PATH];
+} TBGSrc;
+
+typedef struct _BGTheme {
+	TBGSrc BGDest;
+	TBGSrc BGSrc1;
+	TBGSrc BGSrc2;
+	int BGReverseTextAlpha;
+} BGTheme;
+
+////////////////////
+// color theme
+////////////////////
+
+typedef struct {
+	BOOL change;
+	BOOL enable;
+	COLORREF fg;
+	COLORREF bg;
+} TColorSetting;
+
+typedef struct {
+	BOOL change;
+	BOOL enable;
+	COLORREF color[16];
+} TAnsiColorSetting;
+
+typedef struct {
+	char name[50];
+	TColorSetting vt;
+	TColorSetting bold;			// SGR 1
+	TColorSetting underline;	// SGR 4
+	TColorSetting blink;		// SGR 5
+	TColorSetting reverse;		// SGR 7
+	TColorSetting url;
+	TAnsiColorSetting ansicolor;
+} TColorTheme;
+
+typedef struct {
+	BG_PATTERN id;
+	const char *str;
+} BG_PATTERN_ST;
+
+// setting / themefile.cpp
+const BG_PATTERN_ST *ThemeBGPatternList(int index);
+
+// file / themefile.cpp
+void ThemeLoadBG(const wchar_t *file, BGTheme *bg_theme);
+void ThemeLoadColor(const wchar_t *fn, TColorTheme *color_theme);
+void ThemeLoadColorOld(const wchar_t *file, TColorTheme *theme);
+void ThemeLoad(const wchar_t *fname, BGTheme *bg_theme, TColorTheme *color_theme);
+void ThemeSaveBG(const BGTheme *bg_theme, const wchar_t *fname);
+void ThemeSaveColor(TColorTheme *color_theme, const wchar_t *fname);
+
+// setting / vtdisp.c
+void ThemeGetBG(BGTheme *bg_theme);
+void ThemeSetBG(const BGTheme *bg_theme);
+void ThemeGetColor(TColorTheme *data);
+void ThemeSetColor(const TColorTheme *data);
+void ThemeGetColorDefault(TColorTheme *data);
+void ThemeGetColorDefaultTS(const TTTSet *pts, TColorTheme *color_theme);
+void ThemeGetBGDefault(BGTheme *bg_theme);
+
+#ifdef __cplusplus
+}
+#endif

Modified: trunk/teraterm/teraterm/themedlg.cpp
===================================================================
--- trunk/teraterm/teraterm/themedlg.cpp	2022-09-09 14:12:36 UTC (rev 10255)
+++ trunk/teraterm/teraterm/themedlg.cpp	2022-09-09 15:07:26 UTC (rev 10256)
@@ -60,7 +60,7 @@
 #include "tmfc.h"
 #include "tmfc_propdlg.h"
 
-#include "bg_theme.h"
+#include "theme.h"
 #include "themedlg_res.h"
 #include "themedlg.h"
 
@@ -96,7 +96,7 @@
 static void SetWindowTextColor(HWND hWnd, COLORREF color)
 {
 	char str[32];
-	sprintf(str, "%02x%02x%02x", GetRValue(color), GetGValue(color), GetBValue(color));
+	sprintf_s(str, "%02x%02x%02x", GetRValue(color), GetGValue(color), GetBValue(color));
 	SetWindowTextA(hWnd, str);
 }
 
@@ -116,17 +116,17 @@
 	memcpy(elem, &str[0], 2);
 	elem[2] = 0;
 	r = 0;
-	sscanf(elem, "%x", &r);
+	sscanf_s(elem, "%x", &r);
 
 	memcpy(elem, &str[2], 2);
 	elem[2] = 0;
 	g = 0;
-	sscanf(elem, "%x", &g);
+	sscanf_s(elem, "%x", &g);
 
 	memcpy(elem, &str[4], 2);
 	elem[2] = 0;
 	b = 0;
-	sscanf(elem, "%x", &b);
+	sscanf_s(elem, "%x", &b);
 
 	return RGB(r, g, b);
 }
@@ -138,7 +138,8 @@
 
 static void ResetControls(HWND hWnd, const BGTheme *bg_theme)
 {
-	SendDlgItemMessageA(hWnd, IDC_BGIMG_CHECK, BM_SETCHECK, (bg_theme->BGDest.type == BG_PICTURE) ? TRUE : FALSE, 0);
+	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);
 	SetDlgItemTextColor(hWnd, IDC_BGIMG_COLOR_EDIT, bg_theme->BGDest.color);
 	{
@@ -226,7 +227,7 @@
 
 			for (i = 0;; i++) {
 				LRESULT index;
-				const BG_PATTERN_ST *st = GetBGPatternList(i);
+				const BG_PATTERN_ST *st = ThemeBGPatternList(i);
 				if (st == NULL) {
 					break;
 				}
@@ -516,7 +517,7 @@
 		switch (wp) {
 		case IDC_COLOR_DEFAULT_BUTTON | (BN_CLICKED << 16): {
 			// \x83f\x83t\x83H\x83\x8B\x83g
-			BGGetColorDefault(&dlg_data->color_tab.color_theme);
+			ThemeGetColorDefault(&dlg_data->color_tab.color_theme);
 			SetColor(&dlg_data->color_tab.color_theme);
 			SetColorListCtrl(hWnd);
 			break;
@@ -735,8 +736,8 @@
 		case IDC_FILE_PREVIEW_BUTTON | (BN_CLICKED << 16): {
 			set:
 			// preview
-			BGSet(&dlg_data->bg_theme);
-			BGSetColorData(&dlg_data->color_tab.color_theme);
+			ThemeSetBG(&dlg_data->bg_theme);
+			ThemeSetColor(&dlg_data->color_tab.color_theme);
 			BGSetupPrimary(TRUE);
 			InvalidateRect(dlg_data->hVTWin, NULL, FALSE);
 			break;
@@ -760,7 +761,7 @@
 			ofn.lpstrTitle = L"select theme file";
 
 			if (GetOpenFileNameW(&ofn)) {
-				BGLoad(theme_file, &dlg_data->bg_theme, &dlg_data->color_tab.color_theme);
+				ThemeLoad(theme_file, &dlg_data->bg_theme, &dlg_data->color_tab.color_theme);
 
 				static const TTMessageBoxInfoW info = {
 					"Tera Term",
@@ -769,8 +770,8 @@
 					MB_YESNO | MB_ICONWARNING
 				};
 				if (TTMessageBoxW(hWnd, &info, ts->UILanguageFileW) == IDYES) {
-					BGSetColorData(&dlg_data->color_tab.color_theme);
-					BGSet(&dlg_data->bg_theme);
+					ThemeSetColor(&dlg_data->color_tab.color_theme);
+					ThemeSetBG(&dlg_data->bg_theme);
 					//SetColor(&dlg_data->color_tab.color_theme);
 
 					BGSetupPrimary(TRUE);
@@ -802,11 +803,11 @@
 			if (GetSaveFileNameW(&ofn)) {
 				LRESULT checked = SendDlgItemMessageA(hWnd, IDC_FILE_SAVE_BG_CHECK, BM_GETCHECK, 0, 0);
 				if (checked & BST_CHECKED) {
-					BGSave(&dlg_data->bg_theme, theme_file);
+					ThemeSaveBG(&dlg_data->bg_theme, theme_file);
 				}
 				checked = SendDlgItemMessageA(hWnd, IDC_FILE_SAVE_COLOR_CHECK, BM_GETCHECK, 0, 0);
 				if (checked & BST_CHECKED) {
-					BGSaveColor(&dlg_data->color_tab.color_theme, theme_file);
+					ThemeSaveColor(&dlg_data->color_tab.color_theme, theme_file);
 				}
 			}
 			break;
@@ -912,9 +913,9 @@
 	dlg_data->pcv = pcv;
 	dlg_data->pts = pcv->ts;
 	dlg_data->hVTWin = pcv->HWin;
-	BGGet(&dlg_data->bg_theme);
+	ThemeGetBG(&dlg_data->bg_theme);
 	dlg_data->backup.bg_theme = dlg_data->bg_theme;
-	GetColorData(&dlg_data->color_tab.color_theme);
+	ThemeGetColor(&dlg_data->color_tab.color_theme);
 	dlg_data->backup.color_theme = dlg_data->color_tab.color_theme;
 
 	CThemeDlg dlg(hInst, hWnd, dlg_data);
@@ -921,15 +922,15 @@
 	INT_PTR r = dlg.DoModal();
 	if (r == 0) {
 		// cancel\x8E\x9E\x81A\x83o\x83b\x83N\x83A\x83b\x83v\x93\xE0\x97e\x82ɖ߂\xB7
-		BGSet(&dlg_data->backup.bg_theme);
-		BGSetColorData(&dlg_data->color_tab.color_theme);
+		ThemeSetBG(&dlg_data->backup.bg_theme);
+		ThemeSetColor(&dlg_data->color_tab.color_theme);
 		BGSetupPrimary(TRUE);
 		InvalidateRect(dlg_data->hVTWin, NULL, FALSE);
 	}
 	else if (r >= 1) {
 		// ok\x82Ȃ\xC7(Changes were saved by the user)
-		BGSet(&dlg_data->bg_theme);
-		BGSetColorData(&dlg_data->color_tab.color_theme);
+		ThemeSetBG(&dlg_data->bg_theme);
+		ThemeSetColor(&dlg_data->color_tab.color_theme);
 		BGSetupPrimary(TRUE);
 		InvalidateRect(dlg_data->hVTWin, NULL, FALSE);
 	}

Added: trunk/teraterm/teraterm/themefile.cpp
===================================================================
--- trunk/teraterm/teraterm/themefile.cpp	                        (rev 0)
+++ trunk/teraterm/teraterm/themefile.cpp	2022-09-09 15:07:26 UTC (rev 10256)
@@ -0,0 +1,626 @@
+/*
+ * Copyright (C) 1994-1998 T. Teranishi
+ * (C) 2005- TeraTerm Project
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. The name of the author may not be used to endorse or promote products
+ *    derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <string.h>
+#include <stdio.h>
+
+#include "tttypes.h"
+#include "compat_win.h"
+#include "asprintf.h"
+#include "inifile_com.h"
+#include "win32helper.h"
+
+#include "theme.h"
+
+// Eterm look-feel
+#define BG_SECTION "BG"
+#define BG_SECTIONW L"BG"
+#define BG_DESTFILE "BGDestFile"
+#define BG_DESTFILEW L"BGDestFile"
+//#define BG_THEME_IMAGEFILE "theme\\ImageFile.INI"
+//#define BG_THEME_IMAGEFILE_DEFAULT "theme\\*.INI"
+#define BG_THEME_IMAGE_BRIGHTNESS_DEFAULT 64
+#define BG_THEME_IMAGE_BRIGHTNESS1 "BGSrc1Alpha"
+#define BG_THEME_IMAGE_BRIGHTNESS1W L"BGSrc1Alpha"
+#define BG_THEME_IMAGE_BRIGHTNESS2 "BGSrc2Alpha"
+//#define BG_THEME_IMAGEFILE_NAME "ImageFile.INI"
+//#define BG_THEME_IMAGEFILE_NAMEW L"ImageFile.INI"
+//#define BG_THEME_THEMEFILE_SCALE "Scale.INI"
+//#define BG_THEME_THEMEFILE_TILE "Tile.INI"
+
+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" },
+	};
+
+	if (index >= _countof(bg_pattern_list)) {
+		return NULL;
+	}
+	return &bg_pattern_list[index];
+}
+
+static COLORREF BGGetColor(const char *name, COLORREF defcolor, const wchar_t *file)
+{
+	unsigned int r, g, b;
+	char colorstr[256], defstr[256];
+
+	_snprintf_s(defstr, sizeof(defstr), _TRUNCATE, "%d,%d,%d", GetRValue(defcolor), GetGValue(defcolor),
+				GetBValue(defcolor));
+
+	GetPrivateProfileStringAFileW(BG_SECTION, name, defstr, colorstr, 255, file);
+
+	r = g = b = 0;
+
+	sscanf(colorstr, "%d , %d , %d", &r, &g, &b);
+
+	return RGB(r, g, b);
+}
+
+/*
+ *	color theme\x97p\x83\x8D\x81[\x83h
+ */
+void ThemeLoadColorOld(const wchar_t *file, TColorTheme *theme)
+{
+	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 + 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->vt.fg = BGGetColor("VTFore", theme->vt.fg, file);
+	theme->vt.bg = BGGetColor("VTBack", theme->vt.bg, file);
+
+	theme->blink.fg = BGGetColor("VTBlinkFore", theme->blink.fg, file);
+	theme->blink.bg = BGGetColor("VTBlinkBack", theme->blink.bg, file);
+
+	theme->bold.fg = BGGetColor("VTBoldFore", theme->bold.fg, file);
+	theme->bold.bg = BGGetColor("VTBoldBack", theme->bold.bg, file);
+
+	theme->underline.fg = BGGetColor("VTUnderlineFore", theme->underline.fg, file);
+	theme->underline.bg = BGGetColor("VTUnderlineBack", theme->underline.bg, file);
+
+	theme->reverse.fg = BGGetColor("VTReverseFore", theme->reverse.fg, file);
+	theme->reverse.bg = BGGetColor("VTReverseBack", theme->reverse.bg, file);
+
+	theme->url.fg = BGGetColor("URLFore", theme->url.fg, file);
+	theme->url.bg = BGGetColor("URLBack", theme->url.bg, file);
+}
+
+/**
+ *	BG\x82\xF0\x83\x8D\x81[\x83h
+ */
+static void BGSaveColorOne(const TColorSetting *color, const char *key, const wchar_t *fn)
+{
+	char buf[512];
+	COLORREF fg = color->fg;
+	COLORREF bg = color->bg;
+
+	sprintf(buf, "%d,%d, %d,%d,%d, %d,%d,%d", 1, 1,
+			GetRValue(fg), GetGValue(fg), GetBValue(fg),
+			GetRValue(bg), GetGValue(bg), GetBValue(bg));
+	WritePrivateProfileStringAFileW("Color Theme", key, buf, fn);
+}
+
+static void BGSaveColorANSI(TAnsiColorSetting *color, const wchar_t *fn)
+{
+	int i;
+	wchar_t *buff = NULL;
+	awcscat(&buff, L"1, 1, ");
+
+	for (i = 0; i < 16; i++) {
+		wchar_t color_str[32];
+		const COLORREF c = color->color[i];
+		swprintf(color_str, _countof(color_str), L"%d,%d,%d, ", GetRValue(c), GetGValue(c), GetBValue(c));
+		awcscat(&buff, color_str);
+	}
+
+	WritePrivateProfileStringW(L"Color Theme", L"ANSIColor", buff, fn);
+	free(buff);
+}
+
+void ThemeSaveColor(TColorTheme *color_theme, const wchar_t *fn)
+{
+	WritePrivateProfileStringAFileW("Color Theme", "Theme", "teraterm theme editor", 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);
+
+	BGSaveColorANSI(&(color_theme->ansicolor), fn);
+}
+
+void WriteInt3(const char *Sect, const char *Key, const wchar_t *FName,
+			   int i1, int i2, int i3)
+{
+	char Temp[96];
+	_snprintf_s(Temp, sizeof(Temp), _TRUNCATE, "%d,%d,%d",
+	            i1, i2,i3);
+	WritePrivateProfileStringAFileW(Sect, Key, Temp, FName);
+}
+
+void WriteCOLORREF(const char *Sect, const char *Key, const wchar_t *FName, COLORREF color)
+{
+	int red = color & 0xff;
+	int green = (color >> 8) & 0xff;
+	int blue = (color >> 16) & 0xff;
+
+	WriteInt3(Sect, Key, FName, red, green, blue);
+}
+
+static const char *GetBGPatternStr(BG_PATTERN id)
+{
+	int index;
+	for (index = 0;; index++) {
+		const BG_PATTERN_ST *st = ThemeBGPatternList(index);
+		if (st == NULL) {
+			// \x8C\xA9\x82‚\xA9\x82\xE7\x82Ȃ\xA2
+			st = ThemeBGPatternList(0);
+			return st->str;
+		}
+		if (st->id == id) {
+			return st->str;
+		}
+	}
+}
+
+static BOOL GetBGPatternID(const char *str, BG_PATTERN *pattern)
+{
+	int index;
+	for (index = 0;; index++) {
+		const BG_PATTERN_ST *st = ThemeBGPatternList(index);
+		if (st == NULL) {
+			// \x8C\xA9\x82‚\xA9\x82\xE7\x82Ȃ\xA2
+			st = ThemeBGPatternList(0);
+			*pattern = st->id;
+			return FALSE;
+		}
+		if (_stricmp(st->str, str) == 0) {
+			*pattern = st->id;
+			return TRUE;
+		}
+	}
+}
+
+void ThemeSaveBG(const BGTheme *bg_theme, const wchar_t *file)
+{
+	WritePrivateProfileStringAFileW(BG_SECTION, BG_DESTFILE, bg_theme->BGDest.file, file);
+#if 0
+	WritePrivateProfileStringAFileW(BG_SECTION, "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);
+
+	WritePrivateProfileIntAFileW(BG_SECTION, "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(BG_SECTIONW, L"BGReverseTextAlpha", bg_theme->BGReverseTextAlpha, file);
+}
+
+static int BGGetStrIndex(const char *name, int def, const wchar_t *file, const char * const *strList, int nList)
+{
+	char defstr[64], str[64];
+	int i;
+
+	def %= nList;
+
+	strncpy_s(defstr, sizeof(defstr), strList[def], _TRUNCATE);
+	GetPrivateProfileStringAFileW(BG_SECTION, name, defstr, str, 64, file);
+
+	for (i = 0; i < nList; i++)
+		if (!_stricmp(str, strList[i]))
+			return i;
+
+	return 0;
+}
+
+static BOOL BGGetOnOff(const char *name, BOOL def, const wchar_t *file)
+{
+	static const char * const strList[2] = {"Off", "On"};
+
+	return (BOOL)BGGetStrIndex(name, def, file, strList, 2);
+}
+
+static BG_PATTERN BGGetPattern(const char *name, BG_PATTERN def, const wchar_t *file)
+{
+	BG_PATTERN retval;
+	char str[64];
+	GetPrivateProfileStringAFileW(BG_SECTION, name, "", str, _countof(str), file);
+	if (str[0] == 0) {
+		return def;
+	}
+	if (GetBGPatternID(str, &retval) == FALSE) {
+		retval = def;
+	}
+	return retval;
+}
+
+static BG_TYPE BGGetType(const char *name, BG_TYPE def, const wchar_t *file)
+{
+	static const char *strList[3] = {"color", "picture", "wallpaper"};
+
+	return (BG_TYPE)BGGetStrIndex(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)
+{
+	char path[MAX_PATH];
+
+	// 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;
+	}
+
+	// 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.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));
+
+	// 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));
+
+	//\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);
+}
+
+static void ReadANSIColorSetting(TAnsiColorSetting *color, const wchar_t *fn)
+{
+	char Buff[512];
+	int c, r, g, b;
+
+	GetPrivateProfileStringAFileW("Color Theme", "ANSIColor", "0", Buff, sizeof(Buff), fn);
+
+	GetNthNum(Buff, 1, &c);
+	color->change = c;
+
+	GetNthNum(Buff, 2, &c);
+	color->enable = c;
+
+	for (c=0; c<16; c++) {
+		GetNthNum(Buff, c * 3 + 3, &r);
+		GetNthNum(Buff, c * 3 + 4, &g);
+		GetNthNum(Buff, c * 3 + 5, &b);
+		color->color[c] = RGB(r, g, b);
+	}
+}
+
+static void ReadColorSetting(TColorSetting *color, const char *key, const wchar_t *fn)
+{
+	char Buff[512];
+	int c, r, g, b;
+
+	GetPrivateProfileStringAFileW("Color Theme", key, "0", Buff, sizeof(Buff), fn);
+
+	GetNthNum(Buff, 1, &c);
+	color->change = c;
+
+	GetNthNum(Buff, 2, &c);
+	color->enable = c;
+
+	if (color->change && color->enable) {
+		GetNthNum(Buff, 3, &r);
+		GetNthNum(Buff, 4, &g);
+		GetNthNum(Buff, 5, &b);
+		color->fg = RGB(r, g, b);
+
+		GetNthNum(Buff, 6, &r);
+		GetNthNum(Buff, 7, &g);
+		GetNthNum(Buff, 8, &b);
+		color->bg = RGB(r, g, b);
+	}
+
+	return;
+}
+
+/*
+ *	\x83J\x83\x89\x81[\x83e\x81[\x83}ini\x83t\x83@\x83C\x83\x8B\x82\xF0\x83\x8D\x81[\x83h\x82\xB7\x82\xE9
+ */
+void ThemeLoadColor(const wchar_t *fn, TColorTheme *color_theme)
+{
+	GetPrivateProfileStringAFileW("Color Theme", "Theme", "", color_theme->name, _countof(color_theme->name), fn);
+
+	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);
+
+	ReadANSIColorSetting(&(color_theme->ansicolor), fn);
+}
+
+#if 0
+#define SECTION "Color Theme"
+
+static void ReadANSIColorSetting(TAnsiColorSetting *color, const wchar_t *fn)
+{
+	char Buff[512];
+	int c, r, g, b;
+
+	GetPrivateProfileStringAFileW(SECTION, "ANSIColor", "0", Buff, sizeof(Buff), fn);
+
+	GetNthNum(Buff, 1, &c);
+	color->change = c;
+
+	GetNthNum(Buff, 2, &c);
+	color->enable = c;
+
+	for (c=0; c<16; c++) {
+		GetNthNum(Buff, c * 3 + 3, &r);
+		GetNthNum(Buff, c * 3 + 4, &g);
+		GetNthNum(Buff, c * 3 + 5, &b);
+		color->color[c] = RGB(r, g, b);
+	}
+
+	return;
+}
+
+static void ReadColorSetting(TColorSetting *color, char *ent, const wchar_t *fn)
+{
+	char Key[32], Buff[512];
+	int c, r, g, b;
+
+	_snprintf_s(Key, sizeof(Key), _TRUNCATE, "%s", ent);
+	GetPrivateProfileStringAFileW(SECTION, Key, "0", Buff, sizeof(Buff), fn);
+
+	GetNthNum(Buff, 1, &c);
+	color->change = c;
+
+	GetNthNum(Buff, 2, &c);
+	color->enable = c;
+
+	GetNthNum(Buff, 3, &r);
+	GetNthNum(Buff, 4, &g);
+	GetNthNum(Buff, 5, &b);
+	color->fg = RGB(r, g, b);
+
+	GetNthNum(Buff, 6, &r);
+	GetNthNum(Buff, 7, &g);
+	GetNthNum(Buff, 8, &b);
+	color->bg = RGB(r, g, b);
+}
+
+static void ReadColorSetting(TColorSetting *color, char *ent, const wchar_t *fn)
+{
+	char Key[32], Buff[512];
+	int c, r, g, b;
+
+	_snprintf_s(Key, sizeof(Key), _TRUNCATE, "%s", ent);
+	GetPrivateProfileStringAFileW(SECTION, Key, "0", Buff, sizeof(Buff), fn);
+
+	GetNthNum(Buff, 1, &c);
+	color->change = c;
+
+	GetNthNum(Buff, 2, &c);
+	color->enable = c;
+
+	GetNthNum(Buff, 3, &r);
+	GetNthNum(Buff, 4, &g);
+	GetNthNum(Buff, 5, &b);
+	color->fg = RGB(r, g, b);
+
+	GetNthNum(Buff, 6, &r);
+	GetNthNum(Buff, 7, &g);
+	GetNthNum(Buff, 8, &b);
+	color->bg = RGB(r, g, b);
+}
+
+static void ReadColorTheme(const wchar_t *fn, TColorTheme *data)
+{
+	memset(data, 0, sizeof(*data));
+
+	GetPrivateProfileStringAFileW(SECTION, "Theme", "", data->name,
+								  sizeof(data->name), fn);
+	if (data->name[0] == '\0')
+		return;
+
+	ReadColorSetting(&data->vt, "VTColor", fn);
+	ReadColorSetting(&data->bold, "BoldColor", fn);
+	ReadColorSetting(&data->blink, "BlinkColor", fn);
+	ReadColorSetting(&data->reverse, "ReverseColor", fn);
+	ReadColorSetting(&data->url, "URLColor", fn);
+
+	ReadANSIColorSetting(&data->ansicolor, fn);
+}
+
+#endif
+
+#if 0
+static void WriteInt(PCHAR Sect, PCHAR Key, const wchar_t *FName, int i)
+{
+	char Temp[15];
+	_snprintf_s(Temp, sizeof(Temp), _TRUNCATE, "%d", i);
+	WritePrivateProfileStringAFileW(Sect, Key, Temp, FName);
+}
+#endif
+
+/**
+ *	\x83e\x81[\x83}\x83t\x83@\x83C\x83\x8B\x82̏\x91\x82\xAB\x8D\x9E\x82\xDD
+ */
+#if 0
+void BGWriteThemeFile(const wchar_t *theme_file)
+{
+	WritePrivateProfileStringAFileW(BG_SECTION, BG_DESTFILE, BGDest.file, theme_file);
+	BGSrc1.alpha = GetPrivateProfileIntAFileW(BG_SECTION, "BGSrc1Alpha", BGSrc1.alpha, theme_file);
+	WriteInt(BG_SECTION, BG_THEME_IMAGE_BRIGHTNESS1, theme_file, BGSrc1.alpha);
+	WriteInt(BG_SECTION, BG_THEME_IMAGE_BRIGHTNESS2, theme_file, BGSrc2.alpha);
+}
+#endif
+
+/**
+ *	\x83e\x81[\x83}\x83t\x83@\x83C\x83\x8B\x82̏\x91\x82\xAB\x8D\x9E\x82\xDD
+ */
+#if 0
+static void BGWriteIniFile(const wchar_t *file)
+{
+	WritePrivateProfileStringAFileW(BG_SECTION, BG_DESTFILE, BGDest.file, file);
+	WritePrivateProfileStringAFileW(BG_SECTION, "BGDestType",
+									BGDest.type == BG_PICTURE ? "picture" : "color", file);
+	WriteCOLORREF(BG_SECTION, "BGDestColor", file, BGDest.color);
+	WritePrivateProfileStringAFileW(BG_SECTION, "BGDestPattern", GetBGPatternStr(BGDest.pattern), file);
+
+	WritePrivateProfileIntAFileW(BG_SECTION, "BGSrc1Alpha", BGSrc1.alpha, file);
+
+	WritePrivateProfileIntAFileW(BG_SECTION, "BGSrc2Alpha", BGSrc2.alpha, file);
+	WriteCOLORREF(BG_SECTION, "BGSrc2Color", file, BGSrc2.color);
+}
+#endif
+
+/**
+ *	\x83e\x81[\x83}\x83t\x83@\x83C\x83\x8B\x82\xF0\x93ǂݍ\x9E\x82\xDE
+ *
+ * @param file				\x83t\x83@\x83C\x83\x8B\x96\xBC
+ *							NULL\x82̎\x9E\x82͍\\x91\xA2\x91̂Ƀf\x83t\x83H\x83\x8B\x83g\x92l\x82\xAA\x90ݒ肳\x82\xEA\x82\xE9
+ * @param bg_theme
+ * @param color_theme
+*/
+void ThemeLoad(const wchar_t *file, BGTheme *bg_theme, TColorTheme *color_theme)
+{
+	BOOL bg = FALSE;
+	BOOL color = FALSE;
+	wchar_t *prevDir;
+
+	// \x83J\x83\x8C\x83\x93\x83g\x83f\x83B\x83\x8C\x83N\x83g\x83\x8A\x82\xF0\x95ۑ\xB6
+	hGetCurrentDirectoryW(&prevDir);
+
+	// \x83e\x81[\x83}\x83t\x83@\x83C\x83\x8B\x82̂\xA0\x82\xE9\x83f\x83B\x83\x8C\x83N\x83g\x83\x8A\x82Ɉꎞ\x93I\x82Ɉړ\xAE
+	//		\x83e\x81[\x83}\x83t\x83@\x83C\x83\x8B\x91\x8A\x91΃p\x83X\x82œǂݍ\x9E\x82߂\xE9\x82悤
+	if (file != NULL) {
+		wchar_t *dir = ExtractDirNameW(file);
+		SetCurrentDirectoryW(dir);
+		free(dir);
+	}
+
+	{
+		wchar_t sections[128];
+		size_t i;
+		GetPrivateProfileSectionNamesW(sections, _countof(sections), file);
+		for(i = 0; i < _countof(sections); /**/ ) {
+			const wchar_t *p = &sections[i];
+			size_t len = wcslen(p);
+			if (len == 0) {
+				break;
+			}
+			if (_wcsicmp(p, L"BG") == 0) {
+				bg = TRUE;
+			}
+			else if(_wcsicmp(p, L"Color Theme") == 0) {
+				color = TRUE;
+			}
+			i += len;
+		}
+	}
+
+	ThemeGetBGDefault(bg_theme);
+	ThemeGetColorDefault(color_theme);
+
+	// BG + \x83J\x83\x89\x81[\x83e\x81[\x83} ini\x83t\x83@\x83C\x83\x8B
+	if (bg && color) {
+		ThemeLoadBG(file, bg_theme);
+		ThemeLoadColor(file, color_theme);
+	}
+	// BG\x83e\x81[\x83} ini\x83t\x83@\x83C\x83\x8B
+	// TODO \x82\xB1\x82̎\x9E\x83J\x83\x89\x81[\x82͓ǂݍ\x9E\x82܂Ȃ\xA2\x82悤\x82ɂ\xB5\x82\xBD\x82\xA2
+	else if (bg) {
+		ThemeLoadBG(file, bg_theme);
+		ThemeLoadColorOld(file, color_theme);
+	}
+	// \x83J\x83\x89\x81[\x83e\x81[\x83} ini\x83t\x83@\x83C\x83\x8B
+	else if (color) {
+		ThemeLoadColor(file, color_theme);
+	}
+	else {
+#if 0
+		static const TTMessageBoxInfoW info = {
+			"Tera Term",
+			"MSG_TT_ERROR", L"Tera Term: ERROR",
+			NULL, L"unknown ini file?",
+			MB_OK|MB_ICONEXCLAMATION
+		};
+		TTMessageBoxW(HVTWin, &info, ts.UILanguageFileW);
+#endif
+	}
+
+	// \x83J\x83\x8C\x83\x93\x83g\x83t\x83H\x83\x8B\x83_\x82\xF0\x8C\xB3\x82ɖ߂\xB7
+	SetCurrentDirectoryW(prevDir);
+	free(prevDir);
+}

Modified: trunk/teraterm/teraterm/ttermpro.v16.vcxproj
===================================================================
--- trunk/teraterm/teraterm/ttermpro.v16.vcxproj	2022-09-09 14:12:36 UTC (rev 10255)
+++ trunk/teraterm/teraterm/ttermpro.v16.vcxproj	2022-09-09 15:07:26 UTC (rev 10256)
@@ -182,6 +182,7 @@
     <ClCompile Include="teraprn.cpp" />
     <ClCompile Include="teraterm.cpp" />
     <ClCompile Include="themedlg.cpp" />
+    <ClCompile Include="themefile.cpp" />
     <ClCompile Include="ttdde.c" />
     <ClCompile Include="ttdebug.cpp" />
     <ClCompile Include="ttdialog.c" />
@@ -286,6 +287,7 @@
     <ClInclude Include="tekwin.h" />
     <ClInclude Include="telnet.h" />
     <ClInclude Include="teraprn.h" />
+    <ClInclude Include="theme.h" />
     <ClInclude Include="themedlg.h" />
     <ClInclude Include="themedlg_res.h" />
     <ClInclude Include="ttdde.h" />

Modified: trunk/teraterm/teraterm/ttermpro.v16.vcxproj.filters
===================================================================
--- trunk/teraterm/teraterm/ttermpro.v16.vcxproj.filters	2022-09-09 14:12:36 UTC (rev 10255)
+++ trunk/teraterm/teraterm/ttermpro.v16.vcxproj.filters	2022-09-09 15:07:26 UTC (rev 10256)
@@ -219,6 +219,9 @@
     <ClCompile Include="..\ttpcmn\ttcmn_dup.cpp">
       <Filter>ttpcmn</Filter>
     </ClCompile>
+    <ClCompile Include="themefile.cpp">
+      <Filter>Source Files</Filter>
+    </ClCompile>
   </ItemGroup>
   <ItemGroup>
     <Image Include="..\..\cygterm\cygterm.ico">
@@ -504,5 +507,8 @@
     <ClInclude Include="..\ttpcmn\ttcmn_static.h">
       <Filter>ttpcmn</Filter>
     </ClInclude>
+    <ClInclude Include="theme.h">
+      <Filter>Header Files</Filter>
+    </ClInclude>
   </ItemGroup>
 </Project>
\ No newline at end of file

Modified: trunk/teraterm/teraterm/ttermpro.v8.vcproj
===================================================================
--- trunk/teraterm/teraterm/ttermpro.v8.vcproj	2022-09-09 14:12:36 UTC (rev 10255)
+++ trunk/teraterm/teraterm/ttermpro.v8.vcproj	2022-09-09 15:07:26 UTC (rev 10256)
@@ -257,6 +257,10 @@
 				>
 			</File>
 			<File
+				RelativePath=".\themefile.cpp"
+				>
+			</File>
+			<File
 				RelativePath=".\ttdebug.cpp"
 				>
 			</File>
@@ -483,6 +487,10 @@
 				>
 			</File>
 			<File
+				RelativePath=".\theme.h"
+				>
+			</File>
+			<File
 				RelativePath="..\common\tipwin.h"
 				>
 			</File>

Modified: trunk/teraterm/teraterm/vtdisp.c
===================================================================
--- trunk/teraterm/teraterm/vtdisp.c	2022-09-09 14:12:36 UTC (rev 10255)
+++ trunk/teraterm/teraterm/vtdisp.c	2022-09-09 15:07:26 UTC (rev 10256)
@@ -144,7 +144,7 @@
 #include <stdio.h>
 #include <time.h>
 
-#include "bg_theme.h"
+#include "theme.h"
 
 typedef struct _BGSrc
 {
@@ -194,58 +194,6 @@
 
 static HBITMAP GetBitmapHandle(const char *File);
 
-const BG_PATTERN_ST *GetBGPatternList(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" },
-	};
-
-	if (index >= _countof(bg_pattern_list)) {
-		return NULL;
-	}
-	return &bg_pattern_list[index];
-}
-
-static const char *GetBGPatternStr(BG_PATTERN id)
-{
-	int index;
-	for (index = 0;; index++) {
-		const BG_PATTERN_ST *st = GetBGPatternList(index);
-		if (st == NULL) {
-			// \x8C\xA9\x82‚\xA9\x82\xE7\x82Ȃ\xA2
-			st = GetBGPatternList(0);
-			return st->str;
-		}
-		if (st->id == id) {
-			return st->str;
-		}
-	}
-}
-
-static BOOL GetBGPatternID(const char *str, BG_PATTERN *pattern)
-{
-	int index;
-	for (index = 0;; index++) {
-		const BG_PATTERN_ST *st = GetBGPatternList(index);
-		if (st == NULL) {
-			// \x8C\xA9\x82‚\xA9\x82\xE7\x82Ȃ\xA2
-			st = GetBGPatternList(0);
-			*pattern = st->id;
-			return FALSE;
-		}
-		if (_stricmp(st->str, str) == 0) {
-			*pattern = st->id;
-			return TRUE;
-		}
-	}
-}
-
 // LoadImage() \x82\xB5\x82\xA9\x8Eg\x82\xA6\x82Ȃ\xA2\x8A‹\xAB\x82\xA9\x82ǂ\xA4\x82\xA9\x82𔻕ʂ\xB7\x82\xE9\x81B
 // LoadImage()\x82ł\xCD .bmp \x88ȊO\x82̉摜\x83t\x83@\x83C\x83\x8B\x82\xAA\x88\xB5\x82\xA6\x82Ȃ\xA2\x82̂ŗv\x92\x8D\x88ӁB
 // (2014.4.20 yutaka)
@@ -758,10 +706,6 @@
 
 	BGGetWallpaperInfo(&wi);
 
-#ifdef DEBUG_XP
-	strcpy(wi.filename, "c:\\usr\\ttssh2\\1011_01.jpg");
-#endif
-
 	if (IsLoadImageOnlyEnabled()) {
 		//\x95ǎ\x86\x82\xF0\x93ǂݍ\x9E\x82\xDD
 		//LR_CREATEDIBSECTION \x82\xF0\x8Ew\x92肷\x82\xE9\x82̂\xAA\x83R\x83c
@@ -781,12 +725,6 @@
 			goto createdc;
 		}
 
-#ifdef DEBUG_XP
-		//wi.pattern = BG_STRETCH;
-		//wi.pattern = BG_FIT_WIDTH;
-		//wi.pattern = BG_FIT_HEIGHT;
-#endif
-
 		GetObject(hbm,sizeof(bm),&bm);
 		// \x95ǎ\x86\x82̐ݒ\xE8\x82ɍ\x87\x82킹\x82āA\x89摜\x82̃X\x83g\x83\x8C\x83b\x83`\x83T\x83C\x83Y\x82\xF0\x8C\x88\x82߂\xE9\x81B
 		if (wi.pattern == BG_STRETCH) {
@@ -1174,191 +1112,18 @@
   }
 }
 
-static COLORREF BGGetColor(const char *name, COLORREF defcolor, const wchar_t *file)
-{
-	unsigned int r, g, b;
-	char colorstr[256], defstr[256];
-
-	_snprintf_s(defstr, sizeof(defstr), _TRUNCATE, "%d,%d,%d", GetRValue(defcolor), GetGValue(defcolor),
-				GetBValue(defcolor));
-
-	GetPrivateProfileStringAFileW(BG_SECTION, name, defstr, colorstr, 255, file);
-
-	r = g = b = 0;
-
-	sscanf_s(colorstr, "%d , %d , %d", &r, &g, &b);
-
-	return RGB(r, g, b);
-}
-
-static int BGGetStrIndex(const char *name, int def, const wchar_t *file, const char * const *strList, int nList)
-{
-	char defstr[64], str[64];
-	int i;
-
-	def %= nList;
-
-	strncpy_s(defstr, sizeof(defstr), strList[def], _TRUNCATE);
-	GetPrivateProfileStringAFileW(BG_SECTION, name, defstr, str, 64, file);
-
-	for (i = 0; i < nList; i++)
-		if (!_stricmp(str, strList[i]))
-			return i;
-
-	return 0;
-}
-
-static BOOL BGGetOnOff(const char *name, BOOL def, const wchar_t *file)
-{
-	static const char * const strList[2] = {"Off", "On"};
-
-	return BGGetStrIndex(name, def, file, strList, 2);
-}
-
-static BG_PATTERN BGGetPattern(const char *name, BG_PATTERN def, const wchar_t *file)
-{
-	BG_PATTERN retval;
-	char str[64];
-	GetPrivateProfileStringAFileW(BG_SECTION, name, "", str, _countof(str), file);
-	if (str[0] == 0) {
-		return def;
-	}
-	if (GetBGPatternID(str, &retval) == FALSE) {
-		retval = def;
-	}
-	return retval;
-}
-
-static BG_TYPE BGGetType(const char *name, BG_TYPE def, const wchar_t *file)
-{
-	static const char *strList[3] = {"color", "picture", "wallpaper"};
-
-	return BGGetStrIndex(name, def, file, strList, 3);
-}
-
-static void BGReadTextColorConfig(const wchar_t *file)
-{
-	ANSIColor[IdFore] = BGGetColor("Fore", ANSIColor[IdFore], file);
-	ANSIColor[IdBack] = BGGetColor("Back", ANSIColor[IdBack], file);
-	ANSIColor[IdRed] = BGGetColor("Red", ANSIColor[IdRed], file);
-	ANSIColor[IdGreen] = BGGetColor("Green", ANSIColor[IdGreen], file);
-	ANSIColor[IdYellow] = BGGetColor("Yellow", ANSIColor[IdYellow], file);
-	ANSIColor[IdBlue] = BGGetColor("Blue", ANSIColor[IdBlue], file);
-	ANSIColor[IdMagenta] = BGGetColor("Magenta", ANSIColor[IdMagenta], file);
-	ANSIColor[IdCyan] = BGGetColor("Cyan", ANSIColor[IdCyan], file);
-
-	ANSIColor[IdFore + 8] = BGGetColor("DarkFore", ANSIColor[IdFore + 8], file);
-	ANSIColor[IdBack + 8] = BGGetColor("DarkBack", ANSIColor[IdBack + 8], file);
-	ANSIColor[IdRed + 8] = BGGetColor("DarkRed", ANSIColor[IdRed + 8], file);
-	ANSIColor[IdGreen + 8] = BGGetColor("DarkGreen", ANSIColor[IdGreen + 8], file);
-	ANSIColor[IdYellow + 8] = BGGetColor("DarkYellow", ANSIColor[IdYellow + 8], file);
-	ANSIColor[IdBlue + 8] = BGGetColor("DarkBlue", ANSIColor[IdBlue + 8], file);
-	ANSIColor[IdMagenta + 8] = BGGetColor("DarkMagenta", ANSIColor[IdMagenta + 8], file);
-	ANSIColor[IdCyan + 8] = BGGetColor("DarkCyan", ANSIColor[IdCyan + 8], file);
-
-	BGVTColor[0] = BGGetColor("VTFore", BGVTColor[0], file);
-	BGVTColor[1] = BGGetColor("VTBack", BGVTColor[1], file);
-
-	BGVTBlinkColor[0] = BGGetColor("VTBlinkFore", BGVTBlinkColor[0], file);
-	BGVTBlinkColor[1] = BGGetColor("VTBlinkBack", BGVTBlinkColor[1], file);
-
-	BGVTBoldColor[0] = BGGetColor("VTBoldFore", BGVTBoldColor[0], file);
-	BGVTBoldColor[1] = BGGetColor("VTBoldBack", BGVTBoldColor[1], file);
-
-	BGVTUnderlineColor[0] = BGGetColor("VTUnderlineFore", BGVTUnderlineColor[0], file);
-	BGVTUnderlineColor[1] = BGGetColor("VTUnderlineBack", BGVTUnderlineColor[1], file);
-
-	BGVTReverseColor[0] = BGGetColor("VTReverseFore", BGVTReverseColor[0], file);
-	BGVTReverseColor[1] = BGGetColor("VTReverseBack", BGVTReverseColor[1], file);
-
-	BGURLColor[0] = BGGetColor("URLFore", BGURLColor[0], file);
-	BGURLColor[1] = BGGetColor("URLBack", BGURLColor[1], file);
-}
-
 /**
- *	\x83e\x81[\x83}\x83t\x83@\x83C\x83\x8B\x82̓ǂݍ\x9E\x82\xDD
+ *	\x83e\x81[\x83}\x83t\x83@\x83C\x83\x8B\x82\xF0\x93ǂݍ\x9E\x82\xF1\x82Őݒ肷\x82\xE9
+ *
+ *	@param file		NULL\x82̎\x9E\x83t\x83@\x83C\x83\x8B\x82\xF0\x93ǂݍ\x9E\x82܂Ȃ\xA2(\x83f\x83t\x83H\x83\x8B\x83g\x92l\x82Őݒ\xE8)
  */
 static void BGReadIniFile(const wchar_t *file)
 {
-	wchar_t *dir;
-	wchar_t *prevDir;
-	char path[MAX_PATH];
-
-	// \x83J\x83\x8C\x83\x93\x83g\x83f\x83B\x83\x8C\x83N\x83g\x83\x8A\x82\xF0\x95ۑ\xB6
-	hGetCurrentDirectoryW(&prevDir);
-
-	// \x83e\x81[\x83}\x83t\x83@\x83C\x83\x8B\x82̂\xA0\x82\xE9\x83f\x83B\x83\x8C\x83N\x83g\x83\x8A\x82Ɉꎞ\x93I\x82Ɉړ\xAE
-	//		\x83e\x81[\x83}\x83t\x83@\x83C\x83\x8B\x91\x8A\x91΃p\x83X\x82œǂݍ\x9E\x82߂\xE9\x82悤
-	dir = ExtractDirNameW(file);
-	SetCurrentDirectoryW(dir);
-	free(dir);
-
-	//\x83f\x83t\x83H\x83\x8B\x83g\x92l
-	BGDest.type = BG_PICTURE;
-	BGDest.pattern = BG_STRETCH;
-	BGDest.color = RGB(0, 0, 0);
-	BGDest.antiAlias = TRUE;
-	strncpy_s(BGDest.file, sizeof(BGDest.file), "", _TRUNCATE);
-
-	BGSrc1.type = BG_WALLPAPER;
-	BGSrc1.pattern = BG_STRETCH;
-	BGSrc1.color = RGB(255, 255, 255);
-	BGSrc1.antiAlias = TRUE;
-//	BGSrc1.alpha = 255;
-	BGSrc1.alpha = 0;
-	strncpy_s(BGSrc1.file, sizeof(BGSrc1.file), "", _TRUNCATE);
-
-	BGSrc2.type = BG_COLOR;
-	BGSrc2.pattern = BG_STRETCH;
-	BGSrc2.color = RGB(0, 0, 0);
-	BGSrc2.antiAlias = TRUE;
-//	BGSrc2.alpha = 128;
-	BGSrc2.alpha = 0;
-	strncpy_s(BGSrc2.file, sizeof(BGSrc2.file), "", _TRUNCATE);
-
-	BGReverseTextAlpha = 255;
-
-	// Dest \x82̓ǂݏo\x82\xB5
-	BGDest.type = BGGetType("BGDestType", BGDest.type, file);
-	BGDest.pattern = BGGetPattern("BGPicturePattern", BGSrc1.pattern, file);
-	BGDest.pattern = BGGetPattern("BGDestPattern", BGDest.pattern, file);
-	BGDest.antiAlias = BGGetOnOff("BGDestAntiAlias", BGDest.antiAlias, file);
-	BGDest.color = BGGetColor("BGPictureBaseColor", BGDest.color, file);
-	BGDest.color = BGGetColor("BGDestColor", BGDest.color, file);
-	GetPrivateProfileStringAFileW(BG_SECTION, "BGPictureFile", BGDest.file, path, MAX_PATH, file);
-	strcpy_s(BGDest.file, _countof(BGDest.file), path);
-	GetPrivateProfileStringAFileW(BG_SECTION, BG_DESTFILE, BGDest.file, path, MAX_PATH, file);
-	RandomFile(path, BGDest.file, sizeof(BGDest.file));
-
-	// Src1 \x82̓ǂݏo\x82\xB5
-	BGSrc1.type = BGGetType("BGSrc1Type", BGSrc1.type, file);
-	BGSrc1.pattern = BGGetPattern("BGSrc1Pattern", BGSrc1.pattern, file);
-	BGSrc1.antiAlias = BGGetOnOff("BGSrc1AntiAlias", BGSrc1.antiAlias, file);
-	BGSrc1.alpha = 255 - GetPrivateProfileIntAFileW(BG_SECTION, "BGPictureTone", 255 - BGSrc1.alpha, file);
-	BGSrc1.alpha = GetPrivateProfileIntAFileW(BG_SECTION, "BGSrc1Alpha", BGSrc1.alpha, file);
-	BGSrc1.color = BGGetColor("BGSrc1Color", BGSrc1.color, file);
-	GetPrivateProfileStringAFileW(BG_SECTION, "BGSrc1File", BGSrc1.file, path, MAX_PATH, file);
-	RandomFile(path, BGSrc1.file, sizeof(BGSrc1.file));
-
-	// Src2 \x82̓ǂݏo\x82\xB5
-	BGSrc2.type = BGGetType("BGSrc2Type", BGSrc2.type, file);
-	BGSrc2.pattern = BGGetPattern("BGSrc2Pattern", BGSrc2.pattern, file);
-	BGSrc2.antiAlias = BGGetOnOff("BGSrc2AntiAlias", BGSrc2.antiAlias, file);
-	BGSrc2.alpha = 255 - GetPrivateProfileIntAFileW(BG_SECTION, "BGFadeTone", 255 - BGSrc2.alpha, file);
-	BGSrc2.alpha = GetPrivateProfileIntAFileW(BG_SECTION, "BGSrc2Alpha", BGSrc2.alpha, file);
-	BGSrc2.color = BGGetColor("BGFadeColor", BGSrc2.color, file);
-	BGSrc2.color = BGGetColor("BGSrc2Color", BGSrc2.color, file);
-	GetPrivateProfileStringAFileW(BG_SECTION, "BGSrc2File", BGSrc2.file, path, MAX_PATH, file);
-	RandomFile(path, BGSrc2.file, sizeof(BGSrc2.file));
-
-	//\x82\xBB\x82̑\xBC\x93ǂݏo\x82\xB5
-	BGReverseTextAlpha = GetPrivateProfileIntAFileW(BG_SECTION, "BGReverseTextTone", BGReverseTextAlpha, file);
-	BGReverseTextAlpha = GetPrivateProfileIntAFileW(BG_SECTION, "BGReverseTextAlpha", BGReverseTextAlpha, file);
-	BGReadTextColorConfig(file);
-
-	// \x83J\x83\x8C\x83\x93\x83g\x83t\x83H\x83\x8B\x83_\x82\xF0\x8C\xB3\x82ɖ߂\xB7
-	SetCurrentDirectoryW(prevDir);
-	free(prevDir);
+	BGTheme bg_theme;
+	TColorTheme color_theme;
+	ThemeLoad(file, &bg_theme, &color_theme);
+	ThemeSetBG(&bg_theme);
+	ThemeSetColor(&color_theme);
 }
 
 static void BGDestruct(void)
@@ -1383,27 +1148,9 @@
 
 static void BGSetDefaultColor(TTTSet *pts)
 {
-	// VTColor \x82\xF0\x93ǂݍ\x9E\x82\xDD
-	BGVTColor[0] = pts->VTColor[0];
-	BGVTColor[1] = pts->VTColor[1];
-
-	BGVTBoldColor[0] = pts->VTBoldColor[0];
-	BGVTBoldColor[1] = pts->VTBoldColor[1];
-
-	BGVTUnderlineColor[0] = pts->VTUnderlineColor[0];
-	BGVTUnderlineColor[1] = pts->VTUnderlineColor[1];
-
-	BGVTBlinkColor[0] = pts->VTBlinkColor[0];
-	BGVTBlinkColor[1] = pts->VTBlinkColor[1];
-
-	BGVTReverseColor[0] = pts->VTReverseColor[0];
-	BGVTReverseColor[1] = pts->VTReverseColor[1];
-
-	BGURLColor[0] = pts->URLColor[0];
-	BGURLColor[1] = pts->URLColor[1];
-
-	// ANSI color\x90ݒ\xE8\x82̂ق\xA4\x82\xF0\x97D\x90悳\x82\xB9\x82\xE9 (2005.2.3 yutaka)
-	InitColorTable();
+	TColorTheme color_theme;
+	ThemeGetColorDefaultTS(pts, &color_theme);
+	ThemeSetColor(&color_theme);
 }
 
 /*
@@ -1417,6 +1164,8 @@
 {
 	(void)initialize_once;
 
+	InitColorTable();
+
 	BGSetDefaultColor(&ts);
 
 	//\x83\x8A\x83\\x81[\x83X\x89\xF0\x95\xFA
@@ -1442,15 +1191,6 @@
 	else {
 		BGAlphaBlend = AlphaBlendWithoutAPI;
 	}
-
-	// BG \x82\xAA\x97L\x8C\xF8\x82\xA9\x83`\x83F\x83b\x83N
-#if 0
-	BGEnable = ts.EtermLookfeel.BGEnable;
-	if (!BGEnable)
-		return;
-#endif
-
-//	BGLoadThemeFile(&ts);
 }
 
 /**
@@ -1485,15 +1225,19 @@
 	}
 }
 
+/**
+ *	\x83e\x81[\x83}\x82̐ݒ\xE8\x82\xF0\x8Ds\x82\xA4
+ *		\x83e\x81[\x83}\x96\xB3\x82\xB5\x82Ȃ\xE7\x83f\x83t\x83H\x83\x8B\x83g\x90ݒ肷\x82\xE9
+ *		\x83e\x81[\x83}\x82\xA0\x82\xE8\x82Ȃ\xE7\x83e\x81[\x83}\x83t\x83@\x83C\x83\x8B\x82\xF0\x93ǂݏo\x82\xB5\x82Đݒ肷\x82\xE9
+ */
 void BGLoadThemeFile(TTTSet *pts)
 {
-	//\x90ݒ\xE8\x82̓ǂݏo\x82\xB5
-	BGReadIniFile(pts->SetupFNameW);
-
 	// \x83R\x83\x93\x83t\x83B\x83O\x83t\x83@\x83C\x83\x8B(\x83e\x81[\x83}\x83t\x83@\x83C\x83\x8B)\x82̌\x88\x92\xE8
 	switch(pts->EtermLookfeel.BGEnable) {
 	case 0:
 	default:
+		// \x83e\x81[\x83}\x96\xB3\x82\xB5
+		BGReadIniFile(NULL);
 		BGEnable = FALSE;
 		break;
 	case 1:
@@ -3761,60 +3505,8 @@
 	return color;
 }
 
-static void WriteInt(PCHAR Sect, PCHAR Key, const wchar_t *FName, int i)
+void ThemeGetColor(TColorTheme *data)
 {
-	char Temp[15];
-	_snprintf_s(Temp, sizeof(Temp), _TRUNCATE, "%d", i);
-	WritePrivateProfileStringAFileW(Sect, Key, Temp, FName);
-}
-
-void BGWriteThemeFile(const wchar_t *theme_file)
-{
-	WritePrivateProfileStringAFileW(BG_SECTION, BG_DESTFILE, BGDest.file, theme_file);
-	BGSrc1.alpha = GetPrivateProfileIntAFileW(BG_SECTION, "BGSrc1Alpha", BGSrc1.alpha, theme_file);
-	WriteInt(BG_SECTION, BG_THEME_IMAGE_BRIGHTNESS1, theme_file, BGSrc1.alpha);
-	WriteInt(BG_SECTION, BG_THEME_IMAGE_BRIGHTNESS2, theme_file, BGSrc2.alpha);
-}
-
-void WriteInt3(const char *Sect, const char *Key, const wchar_t *FName,
-			   int i1, int i2, int i3)
-{
-	char Temp[96];
-	_snprintf_s(Temp, sizeof(Temp), _TRUNCATE, "%d,%d,%d",
-	            i1, i2,i3);
-	WritePrivateProfileStringAFileW(Sect, Key, Temp, FName);
-}
-
-void WriteCOLORREF(const char *Sect, const char *Key, const wchar_t *FName, COLORREF color)
-{
-	int red = color & 0xff;
-	int green = (color >> 8) & 0xff;
-	int blue = (color >> 16) & 0xff;
-
-	WriteInt3(Sect, Key, FName, red, green, blue);
-}
-
-/**
- *	\x83e\x81[\x83}\x83t\x83@\x83C\x83\x8B\x82̏\x91\x82\xAB\x8D\x9E\x82\xDD
- */
-#if 0
-static void BGWriteIniFile(const wchar_t *file)
-{
-	WritePrivateProfileStringAFileW(BG_SECTION, BG_DESTFILE, BGDest.file, file);
-	WritePrivateProfileStringAFileW(BG_SECTION, "BGDestType",
-									BGDest.type == BG_PICTURE ? "picture" : "color", file);
-	WriteCOLORREF(BG_SECTION, "BGDestColor", file, BGDest.color);
-	WritePrivateProfileStringAFileW(BG_SECTION, "BGDestPattern", GetBGPatternStr(BGDest.pattern), file);
-
-	WritePrivateProfileIntAFileW(BG_SECTION, "BGSrc1Alpha", BGSrc1.alpha, file);
-
-	WritePrivateProfileIntAFileW(BG_SECTION, "BGSrc2Alpha", BGSrc2.alpha, file);
-	WriteCOLORREF(BG_SECTION, "BGSrc2Color", file, BGSrc2.color);
-}
-#endif
-
-void GetColorData(TColorTheme *data)
-{
 	int i;
 
 	data->vt.fg = BGVTColor[0];
@@ -3834,7 +3526,7 @@
 	}
 }
 
-void BGSetColorData(const TColorTheme *data)
+void ThemeSetColor(const TColorTheme *data)
 {
 	int i;
 
@@ -3855,50 +3547,10 @@
 	}
 }
 
-/*
- *	color theme\x97p\x83\x8D\x81[\x83h
- */
-static void BGReadColorTheme(const wchar_t *file, TColorTheme *color_theme)
-{
-	TAnsiColorSetting *ansi = &color_theme->ansicolor;
-	ansi->color[IdFore] = BGGetColor("Fore", ansi->color[IdFore], file);
-	ansi->color[IdBack] = BGGetColor("Back", ansi->color[IdBack], file);
-	ansi->color[IdRed] = BGGetColor("Red", ansi->color[IdRed], file);
-	ansi->color[IdGreen] = BGGetColor("Green", ansi->color[IdGreen], file);
-	ansi->color[IdYellow] = BGGetColor("Yellow", ansi->color[IdYellow], file);
-	ansi->color[IdBlue] = BGGetColor("Blue", ansi->color[IdBlue], file);
-	ansi->color[IdMagenta] = BGGetColor("Magenta", ansi->color[IdMagenta], file);
-	ansi->color[IdCyan] = BGGetColor("Cyan", ansi->color[IdCyan], file);
-
-	ansi->color[IdFore + 8] = BGGetColor("DarkFore", ansi->color[IdFore + 8], file);
-	ansi->color[IdBack + 8] = BGGetColor("DarkBack", ansi->color[IdBack + 8], file);
-	ansi->color[IdRed + 8] = BGGetColor("DarkRed", ansi->color[IdRed + 8], file);
-	ansi->color[IdGreen + 8] = BGGetColor("DarkGreen", ansi->color[IdGreen + 8], file);
-	ansi->color[IdYellow + 8] = BGGetColor("DarkYellow", ansi->color[IdYellow + 8], file);
-	ansi->color[IdBlue + 8] = BGGetColor("DarkBlue", ansi->color[IdBlue + 8], file);
-	ansi->color[IdMagenta + 8] = BGGetColor("DarkMagenta", ansi->color[IdMagenta + 8], file);
-	ansi->color[IdCyan + 8] = BGGetColor("DarkCyan", ansi->color[IdCyan + 8], file);
-
-	color_theme->vt.fg = BGGetColor("VTFore", color_theme->vt.fg, file);
-	color_theme->vt.bg = BGGetColor("VTBack", color_theme->vt.bg, file);
-
-	color_theme->blink.fg = BGGetColor("VTBlinkFore", color_theme->blink.fg, file);
-	color_theme->blink.bg = BGGetColor("VTBlinkBack", color_theme->blink.bg, file);
-
-	color_theme->bold.fg = BGGetColor("VTBoldFore", color_theme->bold.fg, file);
-	color_theme->bold.bg = BGGetColor("VTBoldBack", color_theme->bold.bg, file);
-
-	color_theme->reverse.fg = BGGetColor("VTReverseFore", color_theme->reverse.fg, file);
-	color_theme->reverse.bg = BGGetColor("VTReverseBack", color_theme->reverse.bg, file);
-
-	color_theme->url.fg = BGGetColor("URLFore", color_theme->url.fg, file);
-	color_theme->url.bg = BGGetColor("URLBack", color_theme->url.bg, file);
-}
-
 /**
  * \x83f\x83t\x83H\x83\x8B\x83g\x92l\x82ŏ\x89\x8A\x{227B0B7}\x82\xE9
  */
-static void BGSetDefault(BGTheme *bg_theme)
+void ThemeGetBGDefault(BGTheme *bg_theme)
 {
 	bg_theme->BGDest.type = BG_PICTURE;
 	bg_theme->BGDest.pattern = BG_STRETCH;
@@ -3910,7 +3562,7 @@
 	bg_theme->BGSrc1.pattern = BG_STRETCH;
 	bg_theme->BGSrc1.color = RGB(255, 255, 255);
 	bg_theme->BGSrc1.antiAlias = TRUE;
-	bg_theme->BGSrc1.alpha = 255;
+	bg_theme->BGSrc1.alpha = 0;
 	bg_theme->BGSrc1.file[0] = 0;
 
 	bg_theme->BGSrc2.type = BG_COLOR;
@@ -3917,12 +3569,13 @@
 	bg_theme->BGSrc2.pattern = BG_STRETCH;
 	bg_theme->BGSrc2.color = RGB(0, 0, 0);
 	bg_theme->BGSrc2.antiAlias = TRUE;
-	bg_theme->BGSrc2.alpha = 128;
+	bg_theme->BGSrc2.alpha = 0;
 	bg_theme->BGSrc2.file[0] = 0;
 
-	BGReverseTextAlpha = 255;
+	bg_theme->BGReverseTextAlpha = 255;
 }
 
+#if 0
 static void GetDefaultColor(TColorSetting *tc, const COLORREF *color, int field)
 {
 	tc->change = TRUE;
@@ -3932,15 +3585,17 @@
 
 	return;
 }
+#endif
 
 /**
  *	\x83f\x83t\x83H\x83\x8B\x83g\x90F\x82\xF0\x83Z\x83b\x83g\x82\xB7\x82\xE9
- *	 BGSetDefaultColor(TTTSet *pts) \x82Ɠ\xAF\x82\xB6
  */
-static void BGSetColorDefault(const TTTSet *pts, TColorTheme *color_theme)
+void ThemeGetColorDefaultTS(const TTTSet *pts, TColorTheme *color_theme)
 {
 	int i;
 
+	color_theme->name[0] = 0;
+
 	color_theme->vt.fg = pts->VTColor[0];
 	color_theme->vt.bg = pts->VTColor[1];
 
@@ -3956,6 +3611,9 @@
 	color_theme->url.fg = pts->URLColor[0];
 	color_theme->url.bg = pts->URLColor[1];
 
+	color_theme->underline.fg = pts->VTUnderlineColor[0];
+	color_theme->underline.bg = pts->VTUnderlineColor[1];
+
 	for (i = IdBack ; i <= IdFore+8 ; i++)
 		color_theme->ansicolor.color[i] = pts->ANSIColor[i];
 
@@ -3977,320 +3635,9 @@
 }
 
 /**
- *	BG\x82\xF0\x83\x8D\x81[\x83h
- *		TODO \x90F\x82̓Ǐo\x82\xB5
- */
-static void BGLoadBG(const wchar_t *file, BGTheme *bg_theme)
-{
-	char path[MAX_PATH];
-
-	// 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;
-	}
-
-	// 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.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));
-
-	// 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));
-
-	//\x82\xBB\x82̑\xBC\x93ǂݏo\x82\xB5
-	bg_theme->BGReverseTextAlpha = GetPrivateProfileIntAFileW(BG_SECTION, "BGReverseTextTone", BGReverseTextAlpha, file);
-	bg_theme->BGReverseTextAlpha = GetPrivateProfileIntAFileW(BG_SECTION, "BGReverseTextAlpha", BGReverseTextAlpha, file);
-}
-
-static void ReadANSIColorSetting(TAnsiColorSetting *color, const wchar_t *fn)
-{
-	char Buff[512];
-	int c, r, g, b;
-
-	GetPrivateProfileStringAFileW("Color Theme", "ANSIColor", "0", Buff, sizeof(Buff), fn);
-
-	GetNthNum(Buff, 1, &c);
-	color->change = c;
-
-	GetNthNum(Buff, 2, &c);
-	color->enable = c;
-
-	for (c=0; c<16; c++) {
-		GetNthNum(Buff, c * 3 + 3, &r);
-		GetNthNum(Buff, c * 3 + 4, &g);
-		GetNthNum(Buff, c * 3 + 5, &b);
-		color->color[c] = RGB(r, g, b);
-	}
-}
-
-static void ReadColorSetting(TColorSetting *color, const char *key, const wchar_t *fn)
-{
-	char Buff[512];
-	int c, r, g, b;
-
-	GetPrivateProfileStringAFileW("Color Theme", key, "0", Buff, sizeof(Buff), fn);
-
-	GetNthNum(Buff, 1, &c);
-	color->change = c;
-
-	GetNthNum(Buff, 2, &c);
-	color->enable = c;
-
-	if (color->change && color->enable) {
-		GetNthNum(Buff, 3, &r);
-		GetNthNum(Buff, 4, &g);
-		GetNthNum(Buff, 5, &b);
-		color->fg = RGB(r, g, b);
-
-		GetNthNum(Buff, 6, &r);
-		GetNthNum(Buff, 7, &g);
-		GetNthNum(Buff, 8, &b);
-		color->bg = RGB(r, g, b);
-	}
-
-	return;
-}
-
-/*
- *	\x83J\x83\x89\x81[\x83e\x81[\x83}ini\x83t\x83@\x83C\x83\x8B\x82\xF0\x83\x8D\x81[\x83h\x82\xB7\x82\xE9
- */
-static void BGReadColorThemeIniFile(const wchar_t *fn, TColorTheme *color_theme)
-{
-	GetPrivateProfileStringAFileW("Color Theme", "Theme", "", color_theme->name, _countof(color_theme->name), fn);
-
-	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);
-
-	ReadANSIColorSetting(&(color_theme->ansicolor), fn);
-}
-
-#if 0
-#define SECTION "Color Theme"
-
-static void ReadANSIColorSetting(TAnsiColorSetting *color, const wchar_t *fn)
-{
-	char Buff[512];
-	int c, r, g, b;
-
-	GetPrivateProfileStringAFileW(SECTION, "ANSIColor", "0", Buff, sizeof(Buff), fn);
-
-	GetNthNum(Buff, 1, &c);
-	color->change = c;
-
-	GetNthNum(Buff, 2, &c);
-	color->enable = c;
-
-	for (c=0; c<16; c++) {
-		GetNthNum(Buff, c * 3 + 3, &r);
-		GetNthNum(Buff, c * 3 + 4, &g);
-		GetNthNum(Buff, c * 3 + 5, &b);
-		color->color[c] = RGB(r, g, b);
-	}
-
-	return;
-}
-
-static void ReadColorSetting(TColorSetting *color, char *ent, const wchar_t *fn)
-{
-	char Key[32], Buff[512];
-	int c, r, g, b;
-
-	_snprintf_s(Key, sizeof(Key), _TRUNCATE, "%s", ent);
-	GetPrivateProfileStringAFileW(SECTION, Key, "0", Buff, sizeof(Buff), fn);
-
-	GetNthNum(Buff, 1, &c);
-	color->change = c;
-
-	GetNthNum(Buff, 2, &c);
-	color->enable = c;
-
-	GetNthNum(Buff, 3, &r);
-	GetNthNum(Buff, 4, &g);
-	GetNthNum(Buff, 5, &b);
-	color->fg = RGB(r, g, b);
-
-	GetNthNum(Buff, 6, &r);
-	GetNthNum(Buff, 7, &g);
-	GetNthNum(Buff, 8, &b);
-	color->bg = RGB(r, g, b);
-}
-
-static void ReadColorSetting(TColorSetting *color, char *ent, const wchar_t *fn)
-{
-	char Key[32], Buff[512];
-	int c, r, g, b;
-
-	_snprintf_s(Key, sizeof(Key), _TRUNCATE, "%s", ent);
-	GetPrivateProfileStringAFileW(SECTION, Key, "0", Buff, sizeof(Buff), fn);
-
-	GetNthNum(Buff, 1, &c);
-	color->change = c;
-
-	GetNthNum(Buff, 2, &c);
-	color->enable = c;
-
-	GetNthNum(Buff, 3, &r);
-	GetNthNum(Buff, 4, &g);
-	GetNthNum(Buff, 5, &b);
-	color->fg = RGB(r, g, b);
-
-	GetNthNum(Buff, 6, &r);
-	GetNthNum(Buff, 7, &g);
-	GetNthNum(Buff, 8, &b);
-	color->bg = RGB(r, g, b);
-}
-
-static void ReadColorTheme(const wchar_t *fn, TColorTheme *data)
-{
-	memset(data, 0, sizeof(*data));
-
-	GetPrivateProfileStringAFileW(SECTION, "Theme", "", data->name,
-								  sizeof(data->name), fn);
-	if (data->name[0] == '\0')
-		return;
-
-	ReadColorSetting(&data->vt, "VTColor", fn);
-	ReadColorSetting(&data->bold, "BoldColor", fn);
-	ReadColorSetting(&data->blink, "BlinkColor", fn);
-	ReadColorSetting(&data->reverse, "ReverseColor", fn);
-	ReadColorSetting(&data->url, "URLColor", fn);
-
-	ReadANSIColorSetting(&data->ansicolor, fn);
-}
-
-#endif
-
-/**
- *	BG\x97p\x83\x8D\x81[\x83h
- *		\x8C\xB3 BGReadIniFile(const wchar_t *file)
- *
- */
-void BGLoad(const wchar_t *file, BGTheme *bg_theme, TColorTheme *color_theme)
-{
-	BOOL bg = FALSE;
-	BOOL color = FALSE;
-	wchar_t *dir;
-	wchar_t *prevDir;
-
-	// \x83J\x83\x8C\x83\x93\x83g\x83f\x83B\x83\x8C\x83N\x83g\x83\x8A\x82\xF0\x95ۑ\xB6
-	hGetCurrentDirectoryW(&prevDir);
-
-	// \x83e\x81[\x83}\x83t\x83@\x83C\x83\x8B\x82̂\xA0\x82\xE9\x83f\x83B\x83\x8C\x83N\x83g\x83\x8A\x82Ɉꎞ\x93I\x82Ɉړ\xAE
-	//		\x83e\x81[\x83}\x83t\x83@\x83C\x83\x8B\x91\x8A\x91΃p\x83X\x82œǂݍ\x9E\x82߂\xE9\x82悤
-	dir = ExtractDirNameW(file);
-	SetCurrentDirectoryW(dir);
-	free(dir);
-
-	{
-		wchar_t sections[128];
-		size_t i;
-		GetPrivateProfileSectionNamesW(sections, _countof(sections), file);
-		for(i = 0; i < _countof(sections); /**/ ) {
-			const wchar_t *p = &sections[i];
-			size_t len = wcslen(p);
-			if (len == 0) {
-				break;
-			}
-			if (_wcsicmp(p, L"BG") == 0) {
-				bg = TRUE;
-			}
-			else if(_wcsicmp(p, L"Color Theme") == 0) {
-				color = TRUE;
-			}
-			i += len;
-		}
-	}
-
-
-	// BG + \x83J\x83\x89\x81[\x83e\x81[\x83} ini\x83t\x83@\x83C\x83\x8B
-	if (bg && color) {
-		BGSetDefault(bg_theme);
-		BGSetColorDefault(&ts, color_theme);
-
-		BGLoadBG(file, bg_theme);
-		BGReadColorThemeIniFile(file, color_theme);
-	}
-	// BG\x83e\x81[\x83} ini\x83t\x83@\x83C\x83\x8B
-	// TODO \x82\xB1\x82̎\x9E\x83J\x83\x89\x81[\x82͓ǂݍ\x9E\x82܂Ȃ\xA2\x82悤\x82ɂ\xB5\x82\xBD\x82\xA2
-	else if (bg) {
-		BGSetDefault(bg_theme);
-		BGSetColorDefault(&ts, color_theme);
-
-		BGLoadBG(file, bg_theme);
-		BGReadColorTheme(file, color_theme);
-	}
-	// \x83J\x83\x89\x81[\x83e\x81[\x83} ini\x83t\x83@\x83C\x83\x8B
-	else if (color) {
-		BGSetColorDefault(&ts, color_theme);
-
-		BGReadColorThemeIniFile(file, color_theme);
-	}
-	else {
-		static const TTMessageBoxInfoW info = {
-			"Tera Term",
-			"MSG_TT_ERROR", L"Tera Term: ERROR",
-			NULL, L"unknown ini file?",
-			MB_OK|MB_ICONEXCLAMATION
-		};
-		TTMessageBoxW(HVTWin, &info, ts.UILanguageFileW);
-	}
-
-	// \x83J\x83\x8C\x83\x93\x83g\x83t\x83H\x83\x8B\x83_\x82\xF0\x8C\xB3\x82ɖ߂\xB7
-	SetCurrentDirectoryW(prevDir);
-	free(prevDir);
-}
-
-void BGSave(const BGTheme *bg_theme, const wchar_t *file)
-{
-	WritePrivateProfileStringAFileW(BG_SECTION, BG_DESTFILE, bg_theme->BGDest.file, file);
-#if 0
-	WritePrivateProfileStringAFileW(BG_SECTION, "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);
-
-	WritePrivateProfileIntAFileW(BG_SECTION, "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(BG_SECTIONW, L"BGReverseTextAlpha", bg_theme->BGReverseTextAlpha, file);
-}
-
-/**
  *	BG\x83e\x81[\x83}\x82\xF0\x83Z\x83b\x83g\x82\xB7\x82\xE9
  */
-void BGSet(const BGTheme *bg_theme)
+void ThemeSetBG(const BGTheme *bg_theme)
 {
 	strcpy_s(BGDest.file, _countof(BGDest.file), bg_theme->BGDest.file);
 	BGDest.type = bg_theme->BGDest.type;
@@ -4309,15 +3656,17 @@
 	DecideBGEnable();
 }
 
-void BGGet(BGTheme *bg_theme)
+void ThemeGetBG(BGTheme *bg_theme)
 {
 	strcpy_s(bg_theme->BGDest.file, _countof(bg_theme->BGDest.file), BGDest.file);
-	bg_theme->BGDest.type = BGDest.type;
+	bg_theme->BGDest.type = BG_PICTURE;
 	bg_theme->BGDest.color = BGDest.color;
 	bg_theme->BGDest.pattern = BGDest.pattern;
 
+	bg_theme->BGSrc1.type = BG_WALLPAPER;
 	bg_theme->BGSrc1.alpha = BGSrc1.alpha;
 
+	bg_theme->BGSrc2.type = BG_COLOR;
 	bg_theme->BGSrc2.alpha = BGSrc2.alpha;
 	bg_theme->BGSrc2.color = BGSrc2.color;
 
@@ -4327,52 +3676,7 @@
 /**
  *	\x83f\x83t\x83H\x83\x8B\x83g\x82̐F\x82\xF0\x8E擾
  */
-void BGGetColorDefault(TColorTheme *color_theme)
+void ThemeGetColorDefault(TColorTheme *color_theme)
 {
-	BGSetColorDefault(&ts, color_theme);
+	ThemeGetColorDefaultTS(&ts, color_theme);
 }
-
-/**
- *	BG\x82\xF0\x83\x8D\x81[\x83h
- */
-static void BGSaveColorOne(const TColorSetting *color, const char *key, const wchar_t *fn)
-{
-	char buf[512];
-	COLORREF fg = color->fg;
-	COLORREF bg = color->bg;
-
-	sprintf_s(buf, _countof(buf), "%d,%d, %d,%d,%d, %d,%d,%d", 1, 1,
-			  GetRValue(fg), GetGValue(fg), GetBValue(fg),
-			  GetRValue(bg), GetGValue(bg), GetBValue(bg));
-	WritePrivateProfileStringAFileW("Color Theme", key, buf, fn);
-}
-
-static void BGSaveColorANSI(TAnsiColorSetting *color, const wchar_t *fn)
-{
-	int i;
-	wchar_t *buff = NULL;
-	awcscat(&buff, L"1, 1, ");
-
-	for (i = 0; i < 16; i++) {
-		wchar_t color_str[32];
-		const COLORREF c = color->color[i];
-		swprintf(color_str, _countof(color_str), L"%d,%d,%d, ", GetRValue(c), GetGValue(c), GetBValue(c));
-		awcscat(&buff, color_str);
-	}
-
-	WritePrivateProfileStringW(L"Color Theme", L"ANSIColor", buff, fn);
-	free(buff);
-}
-
-void BGSaveColor(TColorTheme *color_theme, const wchar_t *fn)
-{
-	WritePrivateProfileStringAFileW("Color Theme", "Theme", "teraterm theme editor", 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);
-
-	BGSaveColorANSI(&(color_theme->ansicolor), fn);
-}

Modified: trunk/teraterm/teraterm/vtdisp.h
===================================================================
--- trunk/teraterm/teraterm/vtdisp.h	2022-09-09 14:12:36 UTC (rev 10255)
+++ trunk/teraterm/teraterm/vtdisp.h	2022-09-09 15:07:26 UTC (rev 10256)
@@ -29,6 +29,8 @@
 
 /* TERATERM.EXE, VT terminal display routines */
 
+#pragma once
+
 #include "buffer.h"		// for TCharAttr
 
 #ifdef __cplusplus
@@ -39,7 +41,6 @@
 void BGInitialize(BOOL initialize_once);
 void BGLoadThemeFile(TTTSet *pts);
 void BGSetupPrimary(BOOL forceSetup);
-void BGWriteThemeFile(const wchar_t *theme_file);
 
 void BGOnSettingChange(void);
 void BGOnEnterSizeMove(void);
@@ -147,15 +148,8 @@
 #define WINDOW_REFRESH  6
 #define WINDOW_TOGGLE_MAXIMIZE 7
 
-#include "bg_theme.h"
+#include "theme.h"
 
-typedef struct {
-	BG_PATTERN id;
-	const char *str;
-} BG_PATTERN_ST;
-
-const BG_PATTERN_ST *GetBGPatternList(int index);
-
 #ifdef __cplusplus
 }
 #endif

Modified: trunk/teraterm/ttpset/ttset.c
===================================================================
--- trunk/teraterm/ttpset/ttset.c	2022-09-09 14:12:36 UTC (rev 10255)
+++ trunk/teraterm/ttpset/ttset.c	2022-09-09 15:07:26 UTC (rev 10256)
@@ -56,6 +56,8 @@
 
 #define Section "Tera Term"
 #define SectionW L"Tera Term"
+#define BG_SECTION "BG"
+#define BG_SECTIONW L"BG"
 
 #define MaxStrLen (LONG)512
 
@@ -2845,30 +2847,17 @@
 	/* ZMODEM \x8E\xF3\x90M\x83R\x83}\x83\x93\x83h (2007.12.21 yutaka) */
 	WritePrivateProfileString(Section, "ZmodemRcvCommand", ts->ZModemRcvCommand, FName);
 
-	/* update file */
-	WritePrivateProfileString(NULL, NULL, NULL, FName);
-
 	DispWriteIni(FName, ts);
 
 	// theme\x83t\x83H\x83\x8B\x83_\x82\xF0\x8D\xEC\x82\xE9
+#if 0	// Tera Term \x82\xAA\x83t\x83@\x83C\x83\x8B\x95ۑ\xB6\x8E\x9E\x82ɍ\xEC\x82\xE9?
 	{
+#define BG_THEME_DIR L"theme"
 		wchar_t *theme_folder = NULL;
 		awcscats(&theme_folder, ts->HomeDirW, L"\\", BG_THEME_DIR, NULL);
 		CreateDirectoryW(theme_folder, NULL);
 		free(theme_folder);
 	}
-
-	// \x83e\x81[\x83}\x83t\x83@\x83C\x83\x8B\x82ɕۑ\xB6("theme\\ImageFile.INI")
-	//		TODO BGThemeFile\x82̓`\x83F\x83b\x83N\x82\xB5\x82Ȃ\xAD\x82Ă悢?
-#if 0
-	{
-		wchar_t *theme_file = NULL;
-		aswprintf(&theme_file, L"%s\\%hs", ts->HomeDirW, BG_THEME_IMAGEFILE);
-		WritePrivateProfileStringAFileW(BG_SECTION, BG_DESTFILE, ts->BGImageFilePath, theme_file);
-		WriteInt(BG_SECTION, BG_THEME_IMAGE_BRIGHTNESS1, theme_file, ts->BGImgBrightness);
-		WriteInt(BG_SECTION, BG_THEME_IMAGE_BRIGHTNESS2, theme_file, ts->BGImgBrightness);
-		free(theme_file);
-	}
 #endif
 
 	// UseNormalBGColor


ttssh2-commit メーリングリストの案内
Back to archive index