| 1 |
zmatsuo |
10256 |
/* |
| 2 |
|
|
* Copyright (C) 1994-1998 T. Teranishi |
| 3 |
|
|
* (C) 2005- TeraTerm Project |
| 4 |
|
|
* All rights reserved. |
| 5 |
|
|
* |
| 6 |
|
|
* Redistribution and use in source and binary forms, with or without |
| 7 |
|
|
* modification, are permitted provided that the following conditions |
| 8 |
|
|
* are met: |
| 9 |
|
|
* |
| 10 |
|
|
* 1. Redistributions of source code must retain the above copyright |
| 11 |
|
|
* notice, this list of conditions and the following disclaimer. |
| 12 |
|
|
* 2. Redistributions in binary form must reproduce the above copyright |
| 13 |
|
|
* notice, this list of conditions and the following disclaimer in the |
| 14 |
|
|
* documentation and/or other materials provided with the distribution. |
| 15 |
|
|
* 3. The name of the author may not be used to endorse or promote products |
| 16 |
|
|
* derived from this software without specific prior written permission. |
| 17 |
|
|
* |
| 18 |
|
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS OR |
| 19 |
|
|
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
| 20 |
|
|
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
| 21 |
|
|
* IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY DIRECT, INDIRECT, |
| 22 |
|
|
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
| 23 |
|
|
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 24 |
|
|
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 25 |
|
|
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 26 |
|
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
| 27 |
|
|
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 28 |
|
|
*/ |
| 29 |
|
|
|
| 30 |
|
|
#include <string.h> |
| 31 |
|
|
#include <stdio.h> |
| 32 |
|
|
|
| 33 |
|
|
#include "tttypes.h" |
| 34 |
|
|
#include "compat_win.h" |
| 35 |
|
|
#include "asprintf.h" |
| 36 |
|
|
#include "inifile_com.h" |
| 37 |
|
|
#include "win32helper.h" |
| 38 |
|
|
|
| 39 |
|
|
#include "theme.h" |
| 40 |
|
|
|
| 41 |
|
|
// Eterm look-feel |
| 42 |
|
|
#define BG_SECTION "BG" |
| 43 |
|
|
#define BG_SECTIONW L"BG" |
| 44 |
|
|
#define BG_DESTFILE "BGDestFile" |
| 45 |
|
|
#define BG_DESTFILEW L"BGDestFile" |
| 46 |
|
|
//#define BG_THEME_IMAGEFILE "theme\\ImageFile.INI" |
| 47 |
|
|
//#define BG_THEME_IMAGEFILE_DEFAULT "theme\\*.INI" |
| 48 |
|
|
#define BG_THEME_IMAGE_BRIGHTNESS_DEFAULT 64 |
| 49 |
|
|
#define BG_THEME_IMAGE_BRIGHTNESS1 "BGSrc1Alpha" |
| 50 |
|
|
#define BG_THEME_IMAGE_BRIGHTNESS1W L"BGSrc1Alpha" |
| 51 |
|
|
#define BG_THEME_IMAGE_BRIGHTNESS2 "BGSrc2Alpha" |
| 52 |
|
|
//#define BG_THEME_IMAGEFILE_NAME "ImageFile.INI" |
| 53 |
|
|
//#define BG_THEME_IMAGEFILE_NAMEW L"ImageFile.INI" |
| 54 |
|
|
//#define BG_THEME_THEMEFILE_SCALE "Scale.INI" |
| 55 |
|
|
//#define BG_THEME_THEMEFILE_TILE "Tile.INI" |
| 56 |
|
|
|
| 57 |
|
|
const BG_PATTERN_ST *ThemeBGPatternList(int index) |
| 58 |
|
|
{ |
| 59 |
|
|
static const BG_PATTERN_ST bg_pattern_list[] = { |
| 60 |
|
|
{ BG_STRETCH, "stretch" }, |
| 61 |
|
|
{ BG_TILE, "tile" }, |
| 62 |
|
|
{ BG_CENTER, "center" }, |
| 63 |
|
|
{ BG_FIT_WIDTH, "fit_width" }, |
| 64 |
|
|
{ BG_FIT_HEIGHT, "fit_height" }, |
| 65 |
|
|
{ BG_AUTOFIT, "autofit" }, |
| 66 |
|
|
{ BG_AUTOFILL, "autofill" }, |
| 67 |
|
|
}; |
| 68 |
|
|
|
| 69 |
|
|
if (index >= _countof(bg_pattern_list)) { |
| 70 |
|
|
return NULL; |
| 71 |
|
|
} |
| 72 |
|
|
return &bg_pattern_list[index]; |
| 73 |
|
|
} |
| 74 |
|
|
|
| 75 |
|
|
static COLORREF BGGetColor(const char *name, COLORREF defcolor, const wchar_t *file) |
| 76 |
|
|
{ |
| 77 |
|
|
unsigned int r, g, b; |
| 78 |
|
|
char colorstr[256], defstr[256]; |
| 79 |
|
|
|
| 80 |
|
|
_snprintf_s(defstr, sizeof(defstr), _TRUNCATE, "%d,%d,%d", GetRValue(defcolor), GetGValue(defcolor), |
| 81 |
|
|
GetBValue(defcolor)); |
| 82 |
|
|
|
| 83 |
|
|
GetPrivateProfileStringAFileW(BG_SECTION, name, defstr, colorstr, 255, file); |
| 84 |
|
|
|
| 85 |
|
|
r = g = b = 0; |
| 86 |
|
|
|
| 87 |
|
|
sscanf(colorstr, "%d , %d , %d", &r, &g, &b); |
| 88 |
|
|
|
| 89 |
|
|
return RGB(r, g, b); |
| 90 |
|
|
} |
| 91 |
|
|
|
| 92 |
|
|
/* |
| 93 |
|
|
* color theme�p���[�h |
| 94 |
|
|
*/ |
| 95 |
|
|
void ThemeLoadColorOld(const wchar_t *file, TColorTheme *theme) |
| 96 |
|
|
{ |
| 97 |
|
|
theme->ansicolor.color[IdFore] = BGGetColor("Fore", theme->ansicolor.color[IdFore], file); |
| 98 |
|
|
theme->ansicolor.color[IdBack] = BGGetColor("Back", theme->ansicolor.color[IdBack], file); |
| 99 |
|
|
theme->ansicolor.color[IdRed] = BGGetColor("Red", theme->ansicolor.color[IdRed], file); |
| 100 |
|
|
theme->ansicolor.color[IdGreen] = BGGetColor("Green", theme->ansicolor.color[IdGreen], file); |
| 101 |
|
|
theme->ansicolor.color[IdYellow] = BGGetColor("Yellow", theme->ansicolor.color[IdYellow], file); |
| 102 |
|
|
theme->ansicolor.color[IdBlue] = BGGetColor("Blue", theme->ansicolor.color[IdBlue], file); |
| 103 |
|
|
theme->ansicolor.color[IdMagenta] = BGGetColor("Magenta", theme->ansicolor.color[IdMagenta], file); |
| 104 |
|
|
theme->ansicolor.color[IdCyan] = BGGetColor("Cyan", theme->ansicolor.color[IdCyan], file); |
| 105 |
|
|
|
| 106 |
|
|
theme->ansicolor.color[IdFore + 8] = BGGetColor("DarkFore", theme->ansicolor.color[IdFore + 8], file); |
| 107 |
|
|
theme->ansicolor.color[IdBack + 8] = BGGetColor("DarkBack", theme->ansicolor.color[IdBack + 8], file); |
| 108 |
|
|
theme->ansicolor.color[IdRed + 8] = BGGetColor("DarkRed", theme->ansicolor.color[IdRed + 8], file); |
| 109 |
|
|
theme->ansicolor.color[IdGreen + 8] = BGGetColor("DarkGreen", theme->ansicolor.color[IdGreen + 8], file); |
| 110 |
|
|
theme->ansicolor.color[IdYellow + 8] = BGGetColor("DarkYellow", theme->ansicolor.color[IdYellow + 8], file); |
| 111 |
|
|
theme->ansicolor.color[IdBlue + 8] = BGGetColor("DarkBlue", theme->ansicolor.color[IdBlue + 8], file); |
| 112 |
|
|
theme->ansicolor.color[IdMagenta + 8] = BGGetColor("DarkMagenta", theme->ansicolor.color[IdMagenta + 8], file); |
| 113 |
|
|
theme->ansicolor.color[IdCyan + 8] = BGGetColor("DarkCyan", theme->ansicolor.color[IdCyan + 8], file); |
| 114 |
|
|
|
| 115 |
|
|
theme->vt.fg = BGGetColor("VTFore", theme->vt.fg, file); |
| 116 |
|
|
theme->vt.bg = BGGetColor("VTBack", theme->vt.bg, file); |
| 117 |
|
|
|
| 118 |
|
|
theme->blink.fg = BGGetColor("VTBlinkFore", theme->blink.fg, file); |
| 119 |
|
|
theme->blink.bg = BGGetColor("VTBlinkBack", theme->blink.bg, file); |
| 120 |
|
|
|
| 121 |
|
|
theme->bold.fg = BGGetColor("VTBoldFore", theme->bold.fg, file); |
| 122 |
|
|
theme->bold.bg = BGGetColor("VTBoldBack", theme->bold.bg, file); |
| 123 |
|
|
|
| 124 |
|
|
theme->underline.fg = BGGetColor("VTUnderlineFore", theme->underline.fg, file); |
| 125 |
|
|
theme->underline.bg = BGGetColor("VTUnderlineBack", theme->underline.bg, file); |
| 126 |
|
|
|
| 127 |
|
|
theme->reverse.fg = BGGetColor("VTReverseFore", theme->reverse.fg, file); |
| 128 |
|
|
theme->reverse.bg = BGGetColor("VTReverseBack", theme->reverse.bg, file); |
| 129 |
|
|
|
| 130 |
|
|
theme->url.fg = BGGetColor("URLFore", theme->url.fg, file); |
| 131 |
|
|
theme->url.bg = BGGetColor("URLBack", theme->url.bg, file); |
| 132 |
|
|
} |
| 133 |
|
|
|
| 134 |
|
|
/** |
| 135 |
|
|
* BG�����[�h |
| 136 |
|
|
*/ |
| 137 |
|
|
static void BGSaveColorOne(const TColorSetting *color, const char *key, const wchar_t *fn) |
| 138 |
|
|
{ |
| 139 |
|
|
char buf[512]; |
| 140 |
|
|
COLORREF fg = color->fg; |
| 141 |
|
|
COLORREF bg = color->bg; |
| 142 |
|
|
|
| 143 |
|
|
sprintf(buf, "%d,%d, %d,%d,%d, %d,%d,%d", 1, 1, |
| 144 |
|
|
GetRValue(fg), GetGValue(fg), GetBValue(fg), |
| 145 |
|
|
GetRValue(bg), GetGValue(bg), GetBValue(bg)); |
| 146 |
|
|
WritePrivateProfileStringAFileW("Color Theme", key, buf, fn); |
| 147 |
|
|
} |
| 148 |
|
|
|
| 149 |
|
|
static void BGSaveColorANSI(TAnsiColorSetting *color, const wchar_t *fn) |
| 150 |
|
|
{ |
| 151 |
|
|
int i; |
| 152 |
|
|
wchar_t *buff = NULL; |
| 153 |
|
|
awcscat(&buff, L"1, 1, "); |
| 154 |
|
|
|
| 155 |
|
|
for (i = 0; i < 16; i++) { |
| 156 |
|
|
wchar_t color_str[32]; |
| 157 |
|
|
const COLORREF c = color->color[i]; |
| 158 |
|
|
swprintf(color_str, _countof(color_str), L"%d,%d,%d, ", GetRValue(c), GetGValue(c), GetBValue(c)); |
| 159 |
|
|
awcscat(&buff, color_str); |
| 160 |
|
|
} |
| 161 |
|
|
|
| 162 |
|
|
WritePrivateProfileStringW(L"Color Theme", L"ANSIColor", buff, fn); |
| 163 |
|
|
free(buff); |
| 164 |
|
|
} |
| 165 |
|
|
|
| 166 |
|
|
void ThemeSaveColor(TColorTheme *color_theme, const wchar_t *fn) |
| 167 |
|
|
{ |
| 168 |
|
|
WritePrivateProfileStringAFileW("Color Theme", "Theme", "teraterm theme editor", fn); |
| 169 |
|
|
|
| 170 |
|
|
BGSaveColorOne(&(color_theme->vt), "VTColor", fn); |
| 171 |
|
|
BGSaveColorOne(&(color_theme->bold), "BoldColor", fn); |
| 172 |
|
|
BGSaveColorOne(&(color_theme->blink), "BlinkColor", fn); |
| 173 |
|
|
BGSaveColorOne(&(color_theme->reverse), "ReverseColor", fn); |
| 174 |
|
|
BGSaveColorOne(&(color_theme->url), "URLColor", fn); |
| 175 |
|
|
|
| 176 |
|
|
BGSaveColorANSI(&(color_theme->ansicolor), fn); |
| 177 |
|
|
} |
| 178 |
|
|
|
| 179 |
|
|
void WriteInt3(const char *Sect, const char *Key, const wchar_t *FName, |
| 180 |
|
|
int i1, int i2, int i3) |
| 181 |
|
|
{ |
| 182 |
|
|
char Temp[96]; |
| 183 |
|
|
_snprintf_s(Temp, sizeof(Temp), _TRUNCATE, "%d,%d,%d", |
| 184 |
|
|
i1, i2,i3); |
| 185 |
|
|
WritePrivateProfileStringAFileW(Sect, Key, Temp, FName); |
| 186 |
|
|
} |
| 187 |
|
|
|
| 188 |
|
|
void WriteCOLORREF(const char *Sect, const char *Key, const wchar_t *FName, COLORREF color) |
| 189 |
|
|
{ |
| 190 |
|
|
int red = color & 0xff; |
| 191 |
|
|
int green = (color >> 8) & 0xff; |
| 192 |
|
|
int blue = (color >> 16) & 0xff; |
| 193 |
|
|
|
| 194 |
|
|
WriteInt3(Sect, Key, FName, red, green, blue); |
| 195 |
|
|
} |
| 196 |
|
|
|
| 197 |
|
|
static const char *GetBGPatternStr(BG_PATTERN id) |
| 198 |
|
|
{ |
| 199 |
|
|
int index; |
| 200 |
|
|
for (index = 0;; index++) { |
| 201 |
|
|
const BG_PATTERN_ST *st = ThemeBGPatternList(index); |
| 202 |
|
|
if (st == NULL) { |
| 203 |
|
|
// ������������ |
| 204 |
|
|
st = ThemeBGPatternList(0); |
| 205 |
|
|
return st->str; |
| 206 |
|
|
} |
| 207 |
|
|
if (st->id == id) { |
| 208 |
|
|
return st->str; |
| 209 |
|
|
} |
| 210 |
|
|
} |
| 211 |
|
|
} |
| 212 |
|
|
|
| 213 |
|
|
static BOOL GetBGPatternID(const char *str, BG_PATTERN *pattern) |
| 214 |
|
|
{ |
| 215 |
|
|
int index; |
| 216 |
|
|
for (index = 0;; index++) { |
| 217 |
|
|
const BG_PATTERN_ST *st = ThemeBGPatternList(index); |
| 218 |
|
|
if (st == NULL) { |
| 219 |
|
|
// ������������ |
| 220 |
|
|
st = ThemeBGPatternList(0); |
| 221 |
|
|
*pattern = st->id; |
| 222 |
|
|
return FALSE; |
| 223 |
|
|
} |
| 224 |
|
|
if (_stricmp(st->str, str) == 0) { |
| 225 |
|
|
*pattern = st->id; |
| 226 |
|
|
return TRUE; |
| 227 |
|
|
} |
| 228 |
|
|
} |
| 229 |
|
|
} |
| 230 |
|
|
|
| 231 |
|
|
void ThemeSaveBG(const BGTheme *bg_theme, const wchar_t *file) |
| 232 |
|
|
{ |
| 233 |
|
|
WritePrivateProfileStringAFileW(BG_SECTION, BG_DESTFILE, bg_theme->BGDest.file, file); |
| 234 |
|
|
#if 0 |
| 235 |
|
|
WritePrivateProfileStringAFileW(BG_SECTION, "BGDestType", |
| 236 |
|
|
bg_theme->BGDest.type == BG_PICTURE ? "picture" : "color", file); |
| 237 |
|
|
#endif |
| 238 |
|
|
WriteCOLORREF(BG_SECTION, "BGDestColor", file, bg_theme->BGDest.color); |
| 239 |
|
|
WritePrivateProfileStringAFileW(BG_SECTION, "BGDestPattern", GetBGPatternStr(bg_theme->BGDest.pattern), file); |
| 240 |
|
|
|
| 241 |
|
|
WritePrivateProfileIntAFileW(BG_SECTION, "BGSrc1Alpha", bg_theme->BGSrc1.alpha, file); |
| 242 |
|
|
|
| 243 |
|
|
WritePrivateProfileIntAFileW(BG_SECTION, "BGSrc2Alpha", bg_theme->BGSrc2.alpha, file); |
| 244 |
|
|
WriteCOLORREF(BG_SECTION, "BGSrc2Color", file, bg_theme->BGSrc2.color); |
| 245 |
|
|
|
| 246 |
|
|
WritePrivateProfileIntW(BG_SECTIONW, L"BGReverseTextAlpha", bg_theme->BGReverseTextAlpha, file); |
| 247 |
|
|
} |
| 248 |
|
|
|
| 249 |
|
|
static int BGGetStrIndex(const char *name, int def, const wchar_t *file, const char * const *strList, int nList) |
| 250 |
|
|
{ |
| 251 |
|
|
char defstr[64], str[64]; |
| 252 |
|
|
int i; |
| 253 |
|
|
|
| 254 |
|
|
def %= nList; |
| 255 |
|
|
|
| 256 |
|
|
strncpy_s(defstr, sizeof(defstr), strList[def], _TRUNCATE); |
| 257 |
|
|
GetPrivateProfileStringAFileW(BG_SECTION, name, defstr, str, 64, file); |
| 258 |
|
|
|
| 259 |
|
|
for (i = 0; i < nList; i++) |
| 260 |
|
|
if (!_stricmp(str, strList[i])) |
| 261 |
|
|
return i; |
| 262 |
|
|
|
| 263 |
|
|
return 0; |
| 264 |
|
|
} |
| 265 |
|
|
|
| 266 |
|
|
static BOOL BGGetOnOff(const char *name, BOOL def, const wchar_t *file) |
| 267 |
|
|
{ |
| 268 |
|
|
static const char * const strList[2] = {"Off", "On"}; |
| 269 |
|
|
|
| 270 |
|
|
return (BOOL)BGGetStrIndex(name, def, file, strList, 2); |
| 271 |
|
|
} |
| 272 |
|
|
|
| 273 |
|
|
static BG_PATTERN BGGetPattern(const char *name, BG_PATTERN def, const wchar_t *file) |
| 274 |
|
|
{ |
| 275 |
|
|
BG_PATTERN retval; |
| 276 |
|
|
char str[64]; |
| 277 |
|
|
GetPrivateProfileStringAFileW(BG_SECTION, name, "", str, _countof(str), file); |
| 278 |
|
|
if (str[0] == 0) { |
| 279 |
|
|
return def; |
| 280 |
|
|
} |
| 281 |
|
|
if (GetBGPatternID(str, &retval) == FALSE) { |
| 282 |
|
|
retval = def; |
| 283 |
|
|
} |
| 284 |
|
|
return retval; |
| 285 |
|
|
} |
| 286 |
|
|
|
| 287 |
|
|
static BG_TYPE BGGetType(const char *name, BG_TYPE def, const wchar_t *file) |
| 288 |
|
|
{ |
| 289 |
|
|
static const char *strList[3] = {"color", "picture", "wallpaper"}; |
| 290 |
|
|
|
| 291 |
|
|
return (BG_TYPE)BGGetStrIndex(name, def, file, strList, 3); |
| 292 |
|
|
} |
| 293 |
|
|
|
| 294 |
|
|
/** |
| 295 |
|
|
* BG�����[�h |
| 296 |
|
|
* TODO �F�����o�� |
| 297 |
|
|
*/ |
| 298 |
|
|
void ThemeLoadBG(const wchar_t *file, BGTheme *bg_theme) |
| 299 |
|
|
{ |
| 300 |
|
|
char path[MAX_PATH]; |
| 301 |
|
|
|
| 302 |
|
|
// Dest �������o�� |
| 303 |
|
|
bg_theme->BGDest.type = BGGetType("BGDestType", bg_theme->BGDest.type, file); |
| 304 |
|
|
bg_theme->BGDest.pattern = BGGetPattern("BGPicturePattern", bg_theme->BGDest.pattern, file); |
| 305 |
|
|
bg_theme->BGDest.pattern = BGGetPattern("BGDestPattern", bg_theme->BGDest.pattern, file); |
| 306 |
|
|
bg_theme->BGDest.antiAlias = BGGetOnOff("BGDestAntiAlias", bg_theme->BGDest.antiAlias, file); |
| 307 |
|
|
bg_theme->BGDest.color = BGGetColor("BGPictureBaseColor", bg_theme->BGDest.color, file); |
| 308 |
|
|
bg_theme->BGDest.color = BGGetColor("BGDestColor", bg_theme->BGDest.color, file); |
| 309 |
|
|
GetPrivateProfileStringAFileW(BG_SECTION, "BGPictureFile", bg_theme->BGDest.file, path, sizeof(bg_theme->BGDest.file), file); |
| 310 |
|
|
strcpy_s(bg_theme->BGDest.file, _countof(bg_theme->BGDest.file), path); |
| 311 |
|
|
GetPrivateProfileStringAFileW(BG_SECTION, BG_DESTFILE, bg_theme->BGDest.file, path, MAX_PATH, file); |
| 312 |
|
|
RandomFile(path, bg_theme->BGDest.file, sizeof(bg_theme->BGDest.file)); |
| 313 |
|
|
if (bg_theme->BGDest.file[0] == 0) { |
| 314 |
|
|
// �t�@�C�����������������ADest������������ |
| 315 |
|
|
bg_theme->BGDest.type = BG_NONE; |
| 316 |
|
|
} |
| 317 |
|
|
|
| 318 |
|
|
// Src1 �������o�� |
| 319 |
|
|
bg_theme->BGSrc1.type = BGGetType("BGSrc1Type", bg_theme->BGSrc1.type, file); |
| 320 |
|
|
bg_theme->BGSrc1.pattern = BGGetPattern("BGSrc1Pattern", bg_theme->BGSrc1.pattern, file); |
| 321 |
|
|
bg_theme->BGSrc1.antiAlias = BGGetOnOff("BGSrc1AntiAlias", bg_theme->BGSrc1.antiAlias, file); |
| 322 |
|
|
bg_theme->BGSrc1.alpha = 255 - GetPrivateProfileIntAFileW(BG_SECTION, "BGPictureTone", 255 - bg_theme->BGSrc1.alpha, file); |
| 323 |
|
|
if (!strcmp(bg_theme->BGDest.file, "")) |
| 324 |
|
|
bg_theme->BGSrc1.alpha = 255; |
| 325 |
|
|
bg_theme->BGSrc1.alpha = GetPrivateProfileIntAFileW(BG_SECTION, "BGSrc1Alpha", bg_theme->BGSrc1.alpha, file); |
| 326 |
|
|
bg_theme->BGSrc1.color = BGGetColor("BGSrc1Color", bg_theme->BGSrc1.color, file); |
| 327 |
|
|
GetPrivateProfileStringAFileW(BG_SECTION, "BGSrc1File", bg_theme->BGSrc1.file, path, MAX_PATH, file); |
| 328 |
|
|
RandomFile(path, bg_theme->BGSrc1.file, sizeof(bg_theme->BGSrc1.file)); |
| 329 |
|
|
|
| 330 |
|
|
// Src2 �������o�� |
| 331 |
|
|
bg_theme->BGSrc2.type = BGGetType("BGSrc2Type", bg_theme->BGSrc2.type, file); |
| 332 |
|
|
bg_theme->BGSrc2.pattern = BGGetPattern("BGSrc2Pattern", bg_theme->BGSrc2.pattern, file); |
| 333 |
|
|
bg_theme->BGSrc2.antiAlias = BGGetOnOff("BGSrc2AntiAlias", bg_theme->BGSrc2.antiAlias, file); |
| 334 |
|
|
bg_theme->BGSrc2.alpha = 255 - GetPrivateProfileIntAFileW(BG_SECTION, "BGFadeTone", 255 - bg_theme->BGSrc2.alpha, file); |
| 335 |
|
|
bg_theme->BGSrc2.alpha = GetPrivateProfileIntAFileW(BG_SECTION, "BGSrc2Alpha", bg_theme->BGSrc2.alpha, file); |
| 336 |
|
|
bg_theme->BGSrc2.color = BGGetColor("BGFadeColor", bg_theme->BGSrc2.color, file); |
| 337 |
|
|
bg_theme->BGSrc2.color = BGGetColor("BGSrc2Color", bg_theme->BGSrc2.color, file); |
| 338 |
|
|
GetPrivateProfileStringAFileW(BG_SECTION, "BGSrc2File", bg_theme->BGSrc2.file, path, MAX_PATH, file); |
| 339 |
|
|
RandomFile(path, bg_theme->BGSrc2.file, sizeof(bg_theme->BGSrc2.file)); |
| 340 |
|
|
|
| 341 |
|
|
//�����������o�� |
| 342 |
|
|
bg_theme->BGReverseTextAlpha = GetPrivateProfileIntAFileW(BG_SECTION, "BGReverseTextTone", bg_theme->BGReverseTextAlpha, file); |
| 343 |
|
|
bg_theme->BGReverseTextAlpha = GetPrivateProfileIntAFileW(BG_SECTION, "BGReverseTextAlpha", bg_theme->BGReverseTextAlpha, file); |
| 344 |
|
|
} |
| 345 |
|
|
|
| 346 |
|
|
static void ReadANSIColorSetting(TAnsiColorSetting *color, const wchar_t *fn) |
| 347 |
|
|
{ |
| 348 |
|
|
char Buff[512]; |
| 349 |
|
|
int c, r, g, b; |
| 350 |
|
|
|
| 351 |
|
|
GetPrivateProfileStringAFileW("Color Theme", "ANSIColor", "0", Buff, sizeof(Buff), fn); |
| 352 |
|
|
|
| 353 |
|
|
GetNthNum(Buff, 1, &c); |
| 354 |
|
|
color->change = c; |
| 355 |
|
|
|
| 356 |
|
|
GetNthNum(Buff, 2, &c); |
| 357 |
|
|
color->enable = c; |
| 358 |
|
|
|
| 359 |
|
|
for (c=0; c<16; c++) { |
| 360 |
|
|
GetNthNum(Buff, c * 3 + 3, &r); |
| 361 |
|
|
GetNthNum(Buff, c * 3 + 4, &g); |
| 362 |
|
|
GetNthNum(Buff, c * 3 + 5, &b); |
| 363 |
|
|
color->color[c] = RGB(r, g, b); |
| 364 |
|
|
} |
| 365 |
|
|
} |
| 366 |
|
|
|
| 367 |
|
|
static void ReadColorSetting(TColorSetting *color, const char *key, const wchar_t *fn) |
| 368 |
|
|
{ |
| 369 |
|
|
char Buff[512]; |
| 370 |
|
|
int c, r, g, b; |
| 371 |
|
|
|
| 372 |
|
|
GetPrivateProfileStringAFileW("Color Theme", key, "0", Buff, sizeof(Buff), fn); |
| 373 |
|
|
|
| 374 |
|
|
GetNthNum(Buff, 1, &c); |
| 375 |
|
|
color->change = c; |
| 376 |
|
|
|
| 377 |
|
|
GetNthNum(Buff, 2, &c); |
| 378 |
|
|
color->enable = c; |
| 379 |
|
|
|
| 380 |
|
|
if (color->change && color->enable) { |
| 381 |
|
|
GetNthNum(Buff, 3, &r); |
| 382 |
|
|
GetNthNum(Buff, 4, &g); |
| 383 |
|
|
GetNthNum(Buff, 5, &b); |
| 384 |
|
|
color->fg = RGB(r, g, b); |
| 385 |
|
|
|
| 386 |
|
|
GetNthNum(Buff, 6, &r); |
| 387 |
|
|
GetNthNum(Buff, 7, &g); |
| 388 |
|
|
GetNthNum(Buff, 8, &b); |
| 389 |
|
|
color->bg = RGB(r, g, b); |
| 390 |
|
|
} |
| 391 |
|
|
|
| 392 |
|
|
return; |
| 393 |
|
|
} |
| 394 |
|
|
|
| 395 |
|
|
/* |
| 396 |
|
|
* �J���[�e�[�}ini�t�@�C�������[�h���� |
| 397 |
|
|
*/ |
| 398 |
|
|
void ThemeLoadColor(const wchar_t *fn, TColorTheme *color_theme) |
| 399 |
|
|
{ |
| 400 |
|
|
GetPrivateProfileStringAFileW("Color Theme", "Theme", "", color_theme->name, _countof(color_theme->name), fn); |
| 401 |
|
|
|
| 402 |
|
|
ReadColorSetting(&(color_theme->vt), "VTColor", fn); |
| 403 |
|
|
ReadColorSetting(&(color_theme->bold), "BoldColor", fn); |
| 404 |
|
|
ReadColorSetting(&(color_theme->blink), "BlinkColor", fn); |
| 405 |
|
|
ReadColorSetting(&(color_theme->reverse), "ReverseColor", fn); |
| 406 |
|
|
ReadColorSetting(&(color_theme->url), "URLColor", fn); |
| 407 |
|
|
|
| 408 |
|
|
ReadANSIColorSetting(&(color_theme->ansicolor), fn); |
| 409 |
|
|
} |
| 410 |
|
|
|
| 411 |
|
|
#if 0 |
| 412 |
|
|
#define SECTION "Color Theme" |
| 413 |
|
|
|
| 414 |
|
|
static void ReadANSIColorSetting(TAnsiColorSetting *color, const wchar_t *fn) |
| 415 |
|
|
{ |
| 416 |
|
|
char Buff[512]; |
| 417 |
|
|
int c, r, g, b; |
| 418 |
|
|
|
| 419 |
|
|
GetPrivateProfileStringAFileW(SECTION, "ANSIColor", "0", Buff, sizeof(Buff), fn); |
| 420 |
|
|
|
| 421 |
|
|
GetNthNum(Buff, 1, &c); |
| 422 |
|
|
color->change = c; |
| 423 |
|
|
|
| 424 |
|
|
GetNthNum(Buff, 2, &c); |
| 425 |
|
|
color->enable = c; |
| 426 |
|
|
|
| 427 |
|
|
for (c=0; c<16; c++) { |
| 428 |
|
|
GetNthNum(Buff, c * 3 + 3, &r); |
| 429 |
|
|
GetNthNum(Buff, c * 3 + 4, &g); |
| 430 |
|
|
GetNthNum(Buff, c * 3 + 5, &b); |
| 431 |
|
|
color->color[c] = RGB(r, g, b); |
| 432 |
|
|
} |
| 433 |
|
|
|
| 434 |
|
|
return; |
| 435 |
|
|
} |
| 436 |
|
|
|
| 437 |
|
|
static void ReadColorSetting(TColorSetting *color, char *ent, const wchar_t *fn) |
| 438 |
|
|
{ |
| 439 |
|
|
char Key[32], Buff[512]; |
| 440 |
|
|
int c, r, g, b; |
| 441 |
|
|
|
| 442 |
|
|
_snprintf_s(Key, sizeof(Key), _TRUNCATE, "%s", ent); |
| 443 |
|
|
GetPrivateProfileStringAFileW(SECTION, Key, "0", Buff, sizeof(Buff), fn); |
| 444 |
|
|
|
| 445 |
|
|
GetNthNum(Buff, 1, &c); |
| 446 |
|
|
color->change = c; |
| 447 |
|
|
|
| 448 |
|
|
GetNthNum(Buff, 2, &c); |
| 449 |
|
|
color->enable = c; |
| 450 |
|
|
|
| 451 |
|
|
GetNthNum(Buff, 3, &r); |
| 452 |
|
|
GetNthNum(Buff, 4, &g); |
| 453 |
|
|
GetNthNum(Buff, 5, &b); |
| 454 |
|
|
color->fg = RGB(r, g, b); |
| 455 |
|
|
|
| 456 |
|
|
GetNthNum(Buff, 6, &r); |
| 457 |
|
|
GetNthNum(Buff, 7, &g); |
| 458 |
|
|
GetNthNum(Buff, 8, &b); |
| 459 |
|
|
color->bg = RGB(r, g, b); |
| 460 |
|
|
} |
| 461 |
|
|
|
| 462 |
|
|
static void ReadColorSetting(TColorSetting *color, char *ent, const wchar_t *fn) |
| 463 |
|
|
{ |
| 464 |
|
|
char Key[32], Buff[512]; |
| 465 |
|
|
int c, r, g, b; |
| 466 |
|
|
|
| 467 |
|
|
_snprintf_s(Key, sizeof(Key), _TRUNCATE, "%s", ent); |
| 468 |
|
|
GetPrivateProfileStringAFileW(SECTION, Key, "0", Buff, sizeof(Buff), fn); |
| 469 |
|
|
|
| 470 |
|
|
GetNthNum(Buff, 1, &c); |
| 471 |
|
|
color->change = c; |
| 472 |
|
|
|
| 473 |
|
|
GetNthNum(Buff, 2, &c); |
| 474 |
|
|
color->enable = c; |
| 475 |
|
|
|
| 476 |
|
|
GetNthNum(Buff, 3, &r); |
| 477 |
|
|
GetNthNum(Buff, 4, &g); |
| 478 |
|
|
GetNthNum(Buff, 5, &b); |
| 479 |
|
|
color->fg = RGB(r, g, b); |
| 480 |
|
|
|
| 481 |
|
|
GetNthNum(Buff, 6, &r); |
| 482 |
|
|
GetNthNum(Buff, 7, &g); |
| 483 |
|
|
GetNthNum(Buff, 8, &b); |
| 484 |
|
|
color->bg = RGB(r, g, b); |
| 485 |
|
|
} |
| 486 |
|
|
|
| 487 |
|
|
static void ReadColorTheme(const wchar_t *fn, TColorTheme *data) |
| 488 |
|
|
{ |
| 489 |
|
|
memset(data, 0, sizeof(*data)); |
| 490 |
|
|
|
| 491 |
|
|
GetPrivateProfileStringAFileW(SECTION, "Theme", "", data->name, |
| 492 |
|
|
sizeof(data->name), fn); |
| 493 |
|
|
if (data->name[0] == '\0') |
| 494 |
|
|
return; |
| 495 |
|
|
|
| 496 |
|
|
ReadColorSetting(&data->vt, "VTColor", fn); |
| 497 |
|
|
ReadColorSetting(&data->bold, "BoldColor", fn); |
| 498 |
|
|
ReadColorSetting(&data->blink, "BlinkColor", fn); |
| 499 |
|
|
ReadColorSetting(&data->reverse, "ReverseColor", fn); |
| 500 |
|
|
ReadColorSetting(&data->url, "URLColor", fn); |
| 501 |
|
|
|
| 502 |
|
|
ReadANSIColorSetting(&data->ansicolor, fn); |
| 503 |
|
|
} |
| 504 |
|
|
|
| 505 |
|
|
#endif |
| 506 |
|
|
|
| 507 |
|
|
#if 0 |
| 508 |
|
|
static void WriteInt(PCHAR Sect, PCHAR Key, const wchar_t *FName, int i) |
| 509 |
|
|
{ |
| 510 |
|
|
char Temp[15]; |
| 511 |
|
|
_snprintf_s(Temp, sizeof(Temp), _TRUNCATE, "%d", i); |
| 512 |
|
|
WritePrivateProfileStringAFileW(Sect, Key, Temp, FName); |
| 513 |
|
|
} |
| 514 |
|
|
#endif |
| 515 |
|
|
|
| 516 |
|
|
/** |
| 517 |
|
|
* �e�[�}�t�@�C������������ |
| 518 |
|
|
*/ |
| 519 |
|
|
#if 0 |
| 520 |
|
|
void BGWriteThemeFile(const wchar_t *theme_file) |
| 521 |
|
|
{ |
| 522 |
|
|
WritePrivateProfileStringAFileW(BG_SECTION, BG_DESTFILE, BGDest.file, theme_file); |
| 523 |
|
|
BGSrc1.alpha = GetPrivateProfileIntAFileW(BG_SECTION, "BGSrc1Alpha", BGSrc1.alpha, theme_file); |
| 524 |
|
|
WriteInt(BG_SECTION, BG_THEME_IMAGE_BRIGHTNESS1, theme_file, BGSrc1.alpha); |
| 525 |
|
|
WriteInt(BG_SECTION, BG_THEME_IMAGE_BRIGHTNESS2, theme_file, BGSrc2.alpha); |
| 526 |
|
|
} |
| 527 |
|
|
#endif |
| 528 |
|
|
|
| 529 |
|
|
/** |
| 530 |
|
|
* �e�[�}�t�@�C������������ |
| 531 |
|
|
*/ |
| 532 |
|
|
#if 0 |
| 533 |
|
|
static void BGWriteIniFile(const wchar_t *file) |
| 534 |
|
|
{ |
| 535 |
|
|
WritePrivateProfileStringAFileW(BG_SECTION, BG_DESTFILE, BGDest.file, file); |
| 536 |
|
|
WritePrivateProfileStringAFileW(BG_SECTION, "BGDestType", |
| 537 |
|
|
BGDest.type == BG_PICTURE ? "picture" : "color", file); |
| 538 |
|
|
WriteCOLORREF(BG_SECTION, "BGDestColor", file, BGDest.color); |
| 539 |
|
|
WritePrivateProfileStringAFileW(BG_SECTION, "BGDestPattern", GetBGPatternStr(BGDest.pattern), file); |
| 540 |
|
|
|
| 541 |
|
|
WritePrivateProfileIntAFileW(BG_SECTION, "BGSrc1Alpha", BGSrc1.alpha, file); |
| 542 |
|
|
|
| 543 |
|
|
WritePrivateProfileIntAFileW(BG_SECTION, "BGSrc2Alpha", BGSrc2.alpha, file); |
| 544 |
|
|
WriteCOLORREF(BG_SECTION, "BGSrc2Color", file, BGSrc2.color); |
| 545 |
|
|
} |
| 546 |
|
|
#endif |
| 547 |
|
|
|
| 548 |
|
|
/** |
| 549 |
|
|
* �e�[�}�t�@�C������������ |
| 550 |
|
|
* |
| 551 |
|
|
* @param file �t�@�C���� |
| 552 |
|
|
* NULL�������\�������f�t�H���g�l������������ |
| 553 |
|
|
* @param bg_theme |
| 554 |
|
|
* @param color_theme |
| 555 |
|
|
*/ |
| 556 |
|
|
void ThemeLoad(const wchar_t *file, BGTheme *bg_theme, TColorTheme *color_theme) |
| 557 |
|
|
{ |
| 558 |
|
|
BOOL bg = FALSE; |
| 559 |
|
|
BOOL color = FALSE; |
| 560 |
|
|
wchar_t *prevDir; |
| 561 |
|
|
|
| 562 |
|
|
// �J�����g�f�B���N�g�������� |
| 563 |
|
|
hGetCurrentDirectoryW(&prevDir); |
| 564 |
|
|
|
| 565 |
|
|
// �e�[�}�t�@�C���������f�B���N�g���������I������ |
| 566 |
|
|
// �e�[�}�t�@�C�������p�X���������������� |
| 567 |
|
|
if (file != NULL) { |
| 568 |
|
|
wchar_t *dir = ExtractDirNameW(file); |
| 569 |
|
|
SetCurrentDirectoryW(dir); |
| 570 |
|
|
free(dir); |
| 571 |
|
|
} |
| 572 |
|
|
|
| 573 |
|
|
{ |
| 574 |
|
|
wchar_t sections[128]; |
| 575 |
|
|
size_t i; |
| 576 |
|
|
GetPrivateProfileSectionNamesW(sections, _countof(sections), file); |
| 577 |
|
|
for(i = 0; i < _countof(sections); /**/ ) { |
| 578 |
|
|
const wchar_t *p = §ions[i]; |
| 579 |
|
|
size_t len = wcslen(p); |
| 580 |
|
|
if (len == 0) { |
| 581 |
|
|
break; |
| 582 |
|
|
} |
| 583 |
|
|
if (_wcsicmp(p, L"BG") == 0) { |
| 584 |
|
|
bg = TRUE; |
| 585 |
|
|
} |
| 586 |
|
|
else if(_wcsicmp(p, L"Color Theme") == 0) { |
| 587 |
|
|
color = TRUE; |
| 588 |
|
|
} |
| 589 |
|
|
i += len; |
| 590 |
|
|
} |
| 591 |
|
|
} |
| 592 |
|
|
|
| 593 |
|
|
ThemeGetBGDefault(bg_theme); |
| 594 |
|
|
ThemeGetColorDefault(color_theme); |
| 595 |
|
|
|
| 596 |
|
|
// BG + �J���[�e�[�} ini�t�@�C�� |
| 597 |
|
|
if (bg && color) { |
| 598 |
|
|
ThemeLoadBG(file, bg_theme); |
| 599 |
|
|
ThemeLoadColor(file, color_theme); |
| 600 |
|
|
} |
| 601 |
|
|
// BG�e�[�} ini�t�@�C�� |
| 602 |
|
|
// TODO �������J���[�������������������������� |
| 603 |
|
|
else if (bg) { |
| 604 |
|
|
ThemeLoadBG(file, bg_theme); |
| 605 |
|
|
ThemeLoadColorOld(file, color_theme); |
| 606 |
|
|
} |
| 607 |
|
|
// �J���[�e�[�} ini�t�@�C�� |
| 608 |
|
|
else if (color) { |
| 609 |
|
|
ThemeLoadColor(file, color_theme); |
| 610 |
|
|
} |
| 611 |
|
|
else { |
| 612 |
|
|
#if 0 |
| 613 |
|
|
static const TTMessageBoxInfoW info = { |
| 614 |
|
|
"Tera Term", |
| 615 |
|
|
"MSG_TT_ERROR", L"Tera Term: ERROR", |
| 616 |
|
|
NULL, L"unknown ini file?", |
| 617 |
|
|
MB_OK|MB_ICONEXCLAMATION |
| 618 |
|
|
}; |
| 619 |
|
|
TTMessageBoxW(HVTWin, &info, ts.UILanguageFileW); |
| 620 |
|
|
#endif |
| 621 |
|
|
} |
| 622 |
|
|
|
| 623 |
|
|
// �J�����g�t�H���_���������� |
| 624 |
|
|
SetCurrentDirectoryW(prevDir); |
| 625 |
|
|
free(prevDir); |
| 626 |
|
|
} |