| 1 |
/* |
| 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 |
#include "codeconv.h" |
| 39 |
|
| 40 |
#include "theme.h" |
| 41 |
|
| 42 |
#define BG_SECTION_OLD L"BG" |
| 43 |
#define BG_SECTION_NEW L"BG Theme" |
| 44 |
#define COLOR_THEME_SECTION L"Color Theme" |
| 45 |
|
| 46 |
#if !defined(offsetof) |
| 47 |
#define offsetof(s,m) ((size_t)&(((s*)0)->m)) |
| 48 |
#endif |
| 49 |
|
| 50 |
/** |
| 51 |
* ANSI256�F��������16�F |
| 52 |
* INI�t�@�C���������������������L�[���[�h���F�������� |
| 53 |
*/ |
| 54 |
static const struct { |
| 55 |
int index; |
| 56 |
const wchar_t *key; |
| 57 |
} ansi_list[] = { |
| 58 |
{ 7 + 8, L"Fore" }, |
| 59 |
{ 0, L"Back" }, |
| 60 |
{ 1 + 8, L"Red" }, |
| 61 |
{ 2 + 8, L"Green" }, |
| 62 |
{ 3 + 8, L"Yellow" }, |
| 63 |
{ 4 + 8, L"Blue" }, |
| 64 |
{ 5 + 8, L"Magenta" }, |
| 65 |
{ 6 + 8, L"Cyan" }, |
| 66 |
|
| 67 |
{ 7, L"DarkFore" }, |
| 68 |
{ 0 + 8, L"DarkBack" }, |
| 69 |
{ 1, L"DarkRed" }, |
| 70 |
{ 2, L"DarkGreen" }, |
| 71 |
{ 3, L"DarkYellow" }, |
| 72 |
{ 4, L"DarkBlue" }, |
| 73 |
{ 5, L"DarkMagenta" }, |
| 74 |
{ 6, L"DarkCyan" }, |
| 75 |
}; |
| 76 |
|
| 77 |
/** |
| 78 |
* INI�t�@�C�����L�[���[�h��TColorTheme�\�����������o�[�������\ |
| 79 |
*/ |
| 80 |
static const struct { |
| 81 |
const wchar_t *key; |
| 82 |
size_t offset; |
| 83 |
} color_attr_list[] = { |
| 84 |
{ L"VTColor", offsetof(TColorTheme, vt) }, |
| 85 |
{ L"BoldColor", offsetof(TColorTheme, bold) }, |
| 86 |
{ L"BlinkColor", offsetof(TColorTheme, blink) }, |
| 87 |
{ L"ReverseColor", offsetof(TColorTheme, reverse) }, |
| 88 |
{ L"URLColor", offsetof(TColorTheme, url) }, |
| 89 |
{ L"VTUnderlineColor", offsetof(TColorTheme, underline) }, |
| 90 |
}; |
| 91 |
|
| 92 |
const BG_PATTERN_ST *ThemeBGPatternList(int index) |
| 93 |
{ |
| 94 |
static const BG_PATTERN_ST bg_pattern_list[] = { |
| 95 |
{ BG_STRETCH, L"stretch" }, |
| 96 |
{ BG_TILE, L"tile" }, |
| 97 |
{ BG_CENTER, L"center" }, |
| 98 |
{ BG_FIT_WIDTH, L"fit_width" }, |
| 99 |
{ BG_FIT_HEIGHT, L"fit_height" }, |
| 100 |
{ BG_AUTOFIT, L"autofit" }, |
| 101 |
{ BG_AUTOFILL, L"autofill" }, |
| 102 |
}; |
| 103 |
|
| 104 |
if (index >= _countof(bg_pattern_list)) { |
| 105 |
return NULL; |
| 106 |
} |
| 107 |
return &bg_pattern_list[index]; |
| 108 |
} |
| 109 |
|
| 110 |
static COLORREF LoadColorOneANSI(const wchar_t *section, const wchar_t *key, const wchar_t *file, COLORREF defcolor) |
| 111 |
{ |
| 112 |
int r; |
| 113 |
wchar_t *str; |
| 114 |
DWORD e = hGetPrivateProfileStringW(section, key, NULL, file, &str); |
| 115 |
if (e != 0 || *str == 0) { |
| 116 |
free(str); |
| 117 |
return defcolor; |
| 118 |
} |
| 119 |
if (*str == L'#') { |
| 120 |
// #RRGGBB �`�� |
| 121 |
DWORD i32; |
| 122 |
r = swscanf_s(str, L"#%08x", &i32); |
| 123 |
if (r == 1) { |
| 124 |
free(str); |
| 125 |
return RGB((i32 & 0xff0000) >> 16, (i32 & 0x00ff00) >> 8, (i32 & 0x0000ff)); |
| 126 |
} |
| 127 |
} |
| 128 |
// R, G, B �`�� |
| 129 |
int red, green, blue; |
| 130 |
r = swscanf_s(str, L"%d , %d , %d", &red, &green, &blue); |
| 131 |
free(str); |
| 132 |
if (r == 3) { |
| 133 |
return RGB(red, green, blue); |
| 134 |
} |
| 135 |
return defcolor; |
| 136 |
} |
| 137 |
|
| 138 |
static COLORREF BGGetColor(const wchar_t *section, const wchar_t *key, COLORREF defcolor, const wchar_t *file) |
| 139 |
{ |
| 140 |
COLORREF color = LoadColorOneANSI(section, key, file, defcolor); |
| 141 |
return color; |
| 142 |
} |
| 143 |
|
| 144 |
/* |
| 145 |
* color theme�p���[�h |
| 146 |
*/ |
| 147 |
static void ThemeLoadColorOld(const wchar_t *file, TColorTheme *theme) |
| 148 |
{ |
| 149 |
const wchar_t *section = BG_SECTION_OLD; |
| 150 |
theme->ansicolor.change = TRUE; |
| 151 |
|
| 152 |
theme->ansicolor.color[IdFore] = BGGetColor(section, L"Fore", theme->ansicolor.color[IdFore], file); |
| 153 |
theme->ansicolor.color[IdBack] = BGGetColor(section, L"Back", theme->ansicolor.color[IdBack], file); |
| 154 |
theme->ansicolor.color[IdRed] = BGGetColor(section, L"Red", theme->ansicolor.color[IdRed], file); |
| 155 |
theme->ansicolor.color[IdGreen] = BGGetColor(section, L"Green", theme->ansicolor.color[IdGreen], file); |
| 156 |
theme->ansicolor.color[IdYellow] = BGGetColor(section, L"Yellow", theme->ansicolor.color[IdYellow], file); |
| 157 |
theme->ansicolor.color[IdBlue] = BGGetColor(section, L"Blue", theme->ansicolor.color[IdBlue], file); |
| 158 |
theme->ansicolor.color[IdMagenta] = BGGetColor(section, L"Magenta", theme->ansicolor.color[IdMagenta], file); |
| 159 |
theme->ansicolor.color[IdCyan] = BGGetColor(section, L"Cyan", theme->ansicolor.color[IdCyan], file); |
| 160 |
|
| 161 |
theme->ansicolor.color[IdFore + 8] = BGGetColor(section, L"DarkFore", theme->ansicolor.color[IdFore + 8], file); |
| 162 |
theme->ansicolor.color[IdBack + 8] = BGGetColor(section, L"DarkBack", theme->ansicolor.color[IdBack + 8], file); |
| 163 |
theme->ansicolor.color[IdRed + 8] = BGGetColor(section, L"DarkRed", theme->ansicolor.color[IdRed + 8], file); |
| 164 |
theme->ansicolor.color[IdGreen + 8] = BGGetColor(section, L"DarkGreen", theme->ansicolor.color[IdGreen + 8], file); |
| 165 |
theme->ansicolor.color[IdYellow + 8] = BGGetColor(section, L"DarkYellow", theme->ansicolor.color[IdYellow + 8], file); |
| 166 |
theme->ansicolor.color[IdBlue + 8] = BGGetColor(section, L"DarkBlue", theme->ansicolor.color[IdBlue + 8], file); |
| 167 |
theme->ansicolor.color[IdMagenta + 8] = BGGetColor(section, L"DarkMagenta", theme->ansicolor.color[IdMagenta + 8], file); |
| 168 |
theme->ansicolor.color[IdCyan + 8] = BGGetColor(section, L"DarkCyan", theme->ansicolor.color[IdCyan + 8], file); |
| 169 |
|
| 170 |
theme->vt.fg = BGGetColor(section, L"VTFore", theme->vt.fg, file); |
| 171 |
theme->vt.bg = BGGetColor(section, L"VTBack", theme->vt.bg, file); |
| 172 |
theme->vt.change = TRUE; |
| 173 |
theme->vt.enable = TRUE; |
| 174 |
|
| 175 |
theme->blink.fg = BGGetColor(section, L"VTBlinkFore", theme->blink.fg, file); |
| 176 |
theme->blink.bg = BGGetColor(section, L"VTBlinkBack", theme->blink.bg, file); |
| 177 |
theme->blink.change = TRUE; |
| 178 |
theme->blink.enable = TRUE; |
| 179 |
|
| 180 |
theme->bold.fg = BGGetColor(section, L"VTBoldFore", theme->bold.fg, file); |
| 181 |
theme->bold.bg = BGGetColor(section, L"VTBoldBack", theme->bold.bg, file); |
| 182 |
theme->bold.change = TRUE; |
| 183 |
theme->bold.enable = TRUE; |
| 184 |
|
| 185 |
theme->underline.fg = BGGetColor(section, L"VTUnderlineFore", theme->underline.fg, file); |
| 186 |
theme->underline.bg = BGGetColor(section, L"VTUnderlineBack", theme->underline.bg, file); |
| 187 |
theme->underline.change = TRUE; |
| 188 |
theme->underline.enable = TRUE; |
| 189 |
|
| 190 |
theme->reverse.fg = BGGetColor(section, L"VTReverseFore", theme->reverse.fg, file); |
| 191 |
theme->reverse.bg = BGGetColor(section, L"VTReverseBack", theme->reverse.bg, file); |
| 192 |
theme->reverse.change = TRUE; |
| 193 |
theme->reverse.enable = TRUE; |
| 194 |
|
| 195 |
theme->url.fg = BGGetColor(section, L"URLFore", theme->url.fg, file); |
| 196 |
theme->url.bg = BGGetColor(section, L"URLBack", theme->url.bg, file); |
| 197 |
theme->url.change = TRUE; |
| 198 |
theme->url.enable = TRUE; |
| 199 |
} |
| 200 |
|
| 201 |
/** |
| 202 |
* save color one attribute |
| 203 |
*/ |
| 204 |
static void BGSaveColorOne(const wchar_t *section, const wchar_t *key, const TColorSetting *color, const wchar_t *fn) |
| 205 |
{ |
| 206 |
wchar_t *buf; |
| 207 |
COLORREF fg = color->fg; |
| 208 |
COLORREF bg = color->bg; |
| 209 |
int sp_len = 20 - (int)wcslen(key); |
| 210 |
aswprintf(&buf, L"%*.*s %d,%d, %3hhu,%3hhu,%3hhu, %3hhu,%3hhu,%3hhu ; #%02x%02x%02x, #%02x%02x%02x", |
| 211 |
sp_len, sp_len, L" ", |
| 212 |
color->change, color->enable, |
| 213 |
GetRValue(fg), GetGValue(fg), GetBValue(fg), |
| 214 |
GetRValue(bg), GetGValue(bg), GetBValue(bg), |
| 215 |
GetRValue(fg), GetGValue(fg), GetBValue(fg), |
| 216 |
GetRValue(bg), GetGValue(bg), GetBValue(bg)); |
| 217 |
WritePrivateProfileStringW(section, key, buf, fn); |
| 218 |
free(buf); |
| 219 |
} |
| 220 |
|
| 221 |
#if 1 |
| 222 |
static void BGSaveColorANSI(const wchar_t *section, const TAnsiColorSetting *color, const wchar_t *fn) |
| 223 |
{ |
| 224 |
int i; |
| 225 |
wchar_t *buff = NULL; |
| 226 |
awcscat(&buff, L"1, 1, "); |
| 227 |
|
| 228 |
for (i = 0; i < 16; i++) { |
| 229 |
wchar_t color_str[32]; |
| 230 |
const COLORREF c = color->color[i]; |
| 231 |
swprintf(color_str, _countof(color_str), L"%hhu,%hhu,%hhu, ", GetRValue(c), GetGValue(c), GetBValue(c)); |
| 232 |
awcscat(&buff, color_str); |
| 233 |
} |
| 234 |
|
| 235 |
WritePrivateProfileStringW(section, L"ANSIColor", buff, fn); |
| 236 |
free(buff); |
| 237 |
} |
| 238 |
#endif |
| 239 |
|
| 240 |
static void SaveColorOneANSI(const wchar_t *section, const wchar_t *key, const wchar_t *file, COLORREF color, int index) |
| 241 |
{ |
| 242 |
const BYTE r = GetRValue(color); |
| 243 |
const BYTE g = GetGValue(color); |
| 244 |
const BYTE b = GetBValue(color); |
| 245 |
int sp_len = 20 - (int)wcslen(key); |
| 246 |
wchar_t *str; |
| 247 |
aswprintf(&str, L"%*.*s %3hhu, %3hhu, %3hhu ; #%02hhx%02hhx%02hhx ; ANSIColor[%2d]", |
| 248 |
sp_len, sp_len, L" ", |
| 249 |
r, g, b, r, g, b, index); |
| 250 |
WritePrivateProfileStringW(section, key, str, file); |
| 251 |
free(str); |
| 252 |
} |
| 253 |
|
| 254 |
static void SaveColorANSINew(const wchar_t *section, const TAnsiColorSetting *color, const wchar_t *fname) |
| 255 |
{ |
| 256 |
wchar_t *str; |
| 257 |
aswprintf(&str, L"%d", color->change); |
| 258 |
WritePrivateProfileStringW(section, L"ANSIColor", str, fname); |
| 259 |
free(str); |
| 260 |
|
| 261 |
for (int i = 0; i < _countof(ansi_list); i++) { |
| 262 |
const int index = ansi_list[i].index; |
| 263 |
const wchar_t *key = ansi_list[i].key; |
| 264 |
SaveColorOneANSI(section, key, fname, color->color[index], index); |
| 265 |
} |
| 266 |
} |
| 267 |
|
| 268 |
/** |
| 269 |
* �J���[�e�[�}������ |
| 270 |
* TODO ���� |
| 271 |
*/ |
| 272 |
#if 1 |
| 273 |
void ThemeSaveColorOld(TColorTheme *color_theme, const wchar_t *fn) |
| 274 |
{ |
| 275 |
const wchar_t *section = COLOR_THEME_SECTION; |
| 276 |
|
| 277 |
WritePrivateProfileStringW(section, L"Theme", color_theme->name, fn); |
| 278 |
|
| 279 |
for (int i = 0; i < _countof(color_attr_list); i++) { |
| 280 |
const wchar_t *key = color_attr_list[i].key; |
| 281 |
const TColorSetting *color = (TColorSetting *)((UINT_PTR)color_theme + color_attr_list[i].offset); |
| 282 |
BGSaveColorOne(section, key, color, fn); |
| 283 |
} |
| 284 |
|
| 285 |
BGSaveColorANSI(section, &(color_theme->ansicolor), fn); |
| 286 |
} |
| 287 |
#endif |
| 288 |
|
| 289 |
/** |
| 290 |
* �J���[�e�[�}������ |
| 291 |
*/ |
| 292 |
void ThemeSaveColor(TColorTheme *color_theme, const wchar_t *fn) |
| 293 |
{ |
| 294 |
const wchar_t *section = COLOR_THEME_SECTION; |
| 295 |
WritePrivateProfileStringW(section, L"Theme", color_theme->name, fn); |
| 296 |
|
| 297 |
for (int i = 0; i < _countof(color_attr_list); i++) { |
| 298 |
const wchar_t *key = color_attr_list[i].key; |
| 299 |
const TColorSetting *color = (TColorSetting *)((UINT_PTR)color_theme + color_attr_list[i].offset); |
| 300 |
BGSaveColorOne(section, key, color, fn); |
| 301 |
} |
| 302 |
|
| 303 |
SaveColorANSINew(section, &(color_theme->ansicolor), fn); |
| 304 |
} |
| 305 |
|
| 306 |
static void WriteInt3(const wchar_t *Sect, const wchar_t *Key, const wchar_t *FName, |
| 307 |
int i1, int i2, int i3) |
| 308 |
{ |
| 309 |
wchar_t Temp[96]; |
| 310 |
_snwprintf_s(Temp, _countof(Temp), _TRUNCATE, L"%d,%d,%d", |
| 311 |
i1, i2,i3); |
| 312 |
WritePrivateProfileStringW(Sect, Key, Temp, FName); |
| 313 |
} |
| 314 |
|
| 315 |
static void WriteCOLORREF(const wchar_t *Sect, const wchar_t *Key, const wchar_t *FName, COLORREF color) |
| 316 |
{ |
| 317 |
int red = color & 0xff; |
| 318 |
int green = (color >> 8) & 0xff; |
| 319 |
int blue = (color >> 16) & 0xff; |
| 320 |
|
| 321 |
WriteInt3(Sect, Key, FName, red, green, blue); |
| 322 |
} |
| 323 |
|
| 324 |
static const wchar_t *GetBGPatternStr(BG_PATTERN id) |
| 325 |
{ |
| 326 |
int index; |
| 327 |
for (index = 0;; index++) { |
| 328 |
const BG_PATTERN_ST *st = ThemeBGPatternList(index); |
| 329 |
if (st == NULL) { |
| 330 |
// ������������ |
| 331 |
st = ThemeBGPatternList(0); |
| 332 |
return st->str; |
| 333 |
} |
| 334 |
if (st->id == id) { |
| 335 |
return st->str; |
| 336 |
} |
| 337 |
} |
| 338 |
} |
| 339 |
|
| 340 |
static BOOL GetBGPatternID(const wchar_t *str, BG_PATTERN *pattern) |
| 341 |
{ |
| 342 |
int index; |
| 343 |
for (index = 0;; index++) { |
| 344 |
const BG_PATTERN_ST *st = ThemeBGPatternList(index); |
| 345 |
if (st == NULL) { |
| 346 |
// ������������ |
| 347 |
st = ThemeBGPatternList(0); |
| 348 |
*pattern = st->id; |
| 349 |
return FALSE; |
| 350 |
} |
| 351 |
if (_wcsicmp(st->str, str) == 0) { |
| 352 |
*pattern = st->id; |
| 353 |
return TRUE; |
| 354 |
} |
| 355 |
} |
| 356 |
} |
| 357 |
|
| 358 |
void ThemeSaveBG(const BGTheme *bg_theme, const wchar_t *file) |
| 359 |
{ |
| 360 |
const wchar_t *section = BG_SECTION_NEW; |
| 361 |
|
| 362 |
WritePrivateProfileIntW(section, L"BGDestEnable", bg_theme->BGDest.enable, file); |
| 363 |
WritePrivateProfileStringW(section, L"BGDestFile", bg_theme->BGDest.file, file); |
| 364 |
#if 0 |
| 365 |
WritePrivateProfileStringW(section, L"BGDestType", |
| 366 |
bg_theme->BGDest.type == BG_PICTURE ? "picture" : "color", file); |
| 367 |
#endif |
| 368 |
WriteCOLORREF(section, L"BGDestColor", file, bg_theme->BGDest.color); |
| 369 |
WritePrivateProfileStringW(section, L"BGDestPattern", GetBGPatternStr(bg_theme->BGDest.pattern), file); |
| 370 |
WritePrivateProfileIntW(section, L"BGDestAlpha", bg_theme->BGDest.alpha, file); |
| 371 |
|
| 372 |
WritePrivateProfileIntW(section, L"BGSrc1Enable", bg_theme->BGSrc1.enable, file); |
| 373 |
WritePrivateProfileIntW(section, L"BGSrc1Alpha", bg_theme->BGSrc1.alpha, file); |
| 374 |
|
| 375 |
WritePrivateProfileIntW(section, L"BGSrc2Enable", bg_theme->BGSrc2.enable, file); |
| 376 |
WritePrivateProfileIntW(section, L"BGSrc2Alpha", bg_theme->BGSrc2.alpha, file); |
| 377 |
WriteCOLORREF(section, L"BGSrc2Color", file, bg_theme->BGSrc2.color); |
| 378 |
|
| 379 |
WritePrivateProfileIntW(section, L"BGReverseTextAlpha", bg_theme->BGReverseTextAlpha, file); |
| 380 |
WritePrivateProfileIntW(section, L"BGTextBackAlpha", bg_theme->TextBackAlpha, file); |
| 381 |
WritePrivateProfileIntW(section, L"BGBackAlpha", bg_theme->BackAlpha, file); |
| 382 |
} |
| 383 |
|
| 384 |
static int BGGetStrIndex(const wchar_t *section, const wchar_t *name, int def, const wchar_t *file, const wchar_t * const *strList, int nList) |
| 385 |
{ |
| 386 |
wchar_t defstr[64]; |
| 387 |
wchar_t str[64]; |
| 388 |
int i; |
| 389 |
|
| 390 |
def %= nList; |
| 391 |
|
| 392 |
wcsncpy_s(defstr, _countof(defstr), strList[def], _TRUNCATE); |
| 393 |
GetPrivateProfileStringW(section, name, defstr, str, _countof(str), file); |
| 394 |
|
| 395 |
for (i = 0; i < nList; i++) |
| 396 |
if (!_wcsicmp(str, strList[i])) |
| 397 |
return i; |
| 398 |
|
| 399 |
return 0; |
| 400 |
} |
| 401 |
|
| 402 |
static BOOL BGGetOnOff(const wchar_t *section, const wchar_t *name, BOOL def, const wchar_t *file) |
| 403 |
{ |
| 404 |
static const wchar_t * const strList[2] = {L"Off", L"On"}; |
| 405 |
|
| 406 |
return (BOOL)BGGetStrIndex(section, name, def, file, strList, 2); |
| 407 |
} |
| 408 |
|
| 409 |
static BG_PATTERN BGGetPattern(const wchar_t *section, const wchar_t *name, BG_PATTERN def, const wchar_t *file) |
| 410 |
{ |
| 411 |
BG_PATTERN retval; |
| 412 |
wchar_t str[64]; |
| 413 |
GetPrivateProfileStringW(section, name, L"", str, _countof(str), file); |
| 414 |
if (str[0] == 0) { |
| 415 |
return def; |
| 416 |
} |
| 417 |
if (GetBGPatternID(str, &retval) == FALSE) { |
| 418 |
retval = def; |
| 419 |
} |
| 420 |
return retval; |
| 421 |
} |
| 422 |
|
| 423 |
static BG_TYPE BGGetType(const wchar_t *section, const wchar_t *name, BG_TYPE def, const wchar_t *file) |
| 424 |
{ |
| 425 |
static const wchar_t *strList[3] = {L"color", L"picture", L"wallpaper"}; |
| 426 |
|
| 427 |
return (BG_TYPE)BGGetStrIndex(section, name, def, file, strList, 3); |
| 428 |
} |
| 429 |
|
| 430 |
/** |
| 431 |
* BG�����[�h |
| 432 |
*/ |
| 433 |
void ThemeLoadBGSection(const wchar_t *section, const wchar_t *file, BGTheme *bg_theme) |
| 434 |
{ |
| 435 |
wchar_t pathW[MAX_PATH]; |
| 436 |
wchar_t *p; |
| 437 |
|
| 438 |
// Dest �������o�� |
| 439 |
bg_theme->BGDest.enable = GetPrivateProfileIntW(section, L"BGDestEnable", 0, file); |
| 440 |
bg_theme->BGDest.type = BGGetType(section, L"BGDestType", bg_theme->BGDest.type, file); |
| 441 |
bg_theme->BGDest.pattern = BGGetPattern(section, L"BGPicturePattern", bg_theme->BGDest.pattern, file); |
| 442 |
bg_theme->BGDest.pattern = BGGetPattern(section, L"BGDestPattern", bg_theme->BGDest.pattern, file); |
| 443 |
bg_theme->BGDest.antiAlias = BGGetOnOff(section, L"BGDestAntiAlias", bg_theme->BGDest.antiAlias, file); |
| 444 |
bg_theme->BGDest.alpha = GetPrivateProfileIntW(section, L"BGDestAlpha", bg_theme->BGDest.alpha, file); |
| 445 |
bg_theme->BGDest.color = BGGetColor(section, L"BGPictureBaseColor", bg_theme->BGDest.color, file); |
| 446 |
bg_theme->BGDest.color = BGGetColor(section, L"BGDestColor", bg_theme->BGDest.color, file); |
| 447 |
GetPrivateProfileStringW(section, L"BGPictureFile", bg_theme->BGDest.file, pathW, _countof(pathW), file); |
| 448 |
GetPrivateProfileStringW(section, L"BGDestFile", pathW, pathW, _countof(pathW), file); |
| 449 |
p = RandomFileW(pathW); |
| 450 |
if (p != NULL) { |
| 451 |
wcscpy_s(bg_theme->BGDest.file, _countof(bg_theme->BGDest.file), p); |
| 452 |
free(p); |
| 453 |
} |
| 454 |
else { |
| 455 |
bg_theme->BGDest.file[0] = 0; |
| 456 |
} |
| 457 |
|
| 458 |
// Src1 �������o�� |
| 459 |
bg_theme->BGSrc1.enable = GetPrivateProfileIntW(section, L"BGSrc1Enable", 0, file); |
| 460 |
bg_theme->BGSrc1.type = BGGetType(section, L"BGSrc1Type", bg_theme->BGSrc1.type, file); |
| 461 |
bg_theme->BGSrc1.pattern = BGGetPattern(section, L"BGSrc1Pattern", bg_theme->BGSrc1.pattern, file); |
| 462 |
bg_theme->BGSrc1.antiAlias = BGGetOnOff(section, L"BGSrc1AntiAlias", bg_theme->BGSrc1.antiAlias, file); |
| 463 |
bg_theme->BGSrc1.alpha = 255 - GetPrivateProfileIntW(section, L"BGPictureTone", 255 - bg_theme->BGSrc1.alpha, file); |
| 464 |
bg_theme->BGSrc1.alpha = GetPrivateProfileIntW(section, L"BGSrc1Alpha", bg_theme->BGSrc1.alpha, file); |
| 465 |
bg_theme->BGSrc1.color = BGGetColor(section, L"BGSrc1Color", bg_theme->BGSrc1.color, file); |
| 466 |
GetPrivateProfileStringW(section, L"BGSrc1File", bg_theme->BGSrc1.file, pathW, _countof(pathW), file); |
| 467 |
p = RandomFileW(pathW); |
| 468 |
if (p != NULL) { |
| 469 |
wcscpy_s(bg_theme->BGSrc1.file, _countof(bg_theme->BGSrc1.file), p); |
| 470 |
free(p); |
| 471 |
} |
| 472 |
else { |
| 473 |
bg_theme->BGSrc1.file[0] = 0; |
| 474 |
} |
| 475 |
|
| 476 |
// Src2 �������o�� |
| 477 |
bg_theme->BGSrc2.enable = GetPrivateProfileIntW(section, L"BGSrc2Enable", 0, file); |
| 478 |
bg_theme->BGSrc2.type = BGGetType(section, L"BGSrc2Type", bg_theme->BGSrc2.type, file); |
| 479 |
bg_theme->BGSrc2.pattern = BGGetPattern(section, L"BGSrc2Pattern", bg_theme->BGSrc2.pattern, file); |
| 480 |
bg_theme->BGSrc2.antiAlias = BGGetOnOff(section, L"BGSrc2AntiAlias", bg_theme->BGSrc2.antiAlias, file); |
| 481 |
bg_theme->BGSrc2.alpha = 255 - GetPrivateProfileIntW(section, L"BGFadeTone", 255 - bg_theme->BGSrc2.alpha, file); |
| 482 |
bg_theme->BGSrc2.alpha = GetPrivateProfileIntW(section, L"BGSrc2Alpha", bg_theme->BGSrc2.alpha, file); |
| 483 |
bg_theme->BGSrc2.color = BGGetColor(section, L"BGFadeColor", bg_theme->BGSrc2.color, file); |
| 484 |
bg_theme->BGSrc2.color = BGGetColor(section, L"BGSrc2Color", bg_theme->BGSrc2.color, file); |
| 485 |
GetPrivateProfileStringW(section, L"BGSrc2File", bg_theme->BGSrc2.file, pathW, _countof(pathW), file); |
| 486 |
p = RandomFileW(pathW); |
| 487 |
if (p != NULL) { |
| 488 |
wcscpy_s(bg_theme->BGSrc2.file, _countof(bg_theme->BGSrc2.file), p); |
| 489 |
free(p); |
| 490 |
} |
| 491 |
else { |
| 492 |
bg_theme->BGSrc2.file[0] = 0; |
| 493 |
} |
| 494 |
|
| 495 |
//�����������o�� |
| 496 |
bg_theme->BGReverseTextAlpha = GetPrivateProfileIntW(section, L"BGReverseTextTone", bg_theme->BGReverseTextAlpha, file); |
| 497 |
bg_theme->BGReverseTextAlpha = GetPrivateProfileIntW(section, L"BGReverseTextAlpha", bg_theme->BGReverseTextAlpha, file); |
| 498 |
bg_theme->TextBackAlpha = GetPrivateProfileIntW(section, L"BGTextBackAlpha", bg_theme->TextBackAlpha, file); |
| 499 |
bg_theme->BackAlpha = GetPrivateProfileIntW(section, L"BGBackAlpha", bg_theme->BackAlpha, file); |
| 500 |
} |
| 501 |
|
| 502 |
/** |
| 503 |
* BG�����[�h |
| 504 |
*/ |
| 505 |
void ThemeLoadBG(const wchar_t *file, BGTheme *bg_theme) |
| 506 |
{ |
| 507 |
ThemeLoadBGSection(BG_SECTION_OLD, file, bg_theme); |
| 508 |
ThemeLoadBGSection(BG_SECTION_NEW, file, bg_theme); |
| 509 |
} |
| 510 |
|
| 511 |
static void ReadANSIColorSetting(const wchar_t *section, TAnsiColorSetting *color, const wchar_t *fn) |
| 512 |
{ |
| 513 |
wchar_t BuffW[512]; |
| 514 |
char Buff[512]; |
| 515 |
int c, r, g, b; |
| 516 |
// ANSIColor16���A������/�����O���[�v������������������ |
| 517 |
const static int index256[] = { |
| 518 |
0, |
| 519 |
1, 2, 3, 4, 5, 6, 7, |
| 520 |
8, |
| 521 |
9, 10, 11, 12, 13, 14, 15, |
| 522 |
}; |
| 523 |
|
| 524 |
GetPrivateProfileStringW(section, L"ANSIColor", L"0", BuffW, sizeof(BuffW), fn); |
| 525 |
WideCharToACP_t(BuffW, Buff, _countof(Buff)); |
| 526 |
|
| 527 |
GetNthNum(Buff, 1, &c); |
| 528 |
color->change = c; |
| 529 |
|
| 530 |
GetNthNum(Buff, 2, &c); |
| 531 |
//color->enable = c; |
| 532 |
|
| 533 |
for (c=0; c<16; c++) { |
| 534 |
int idx = index256[c]; |
| 535 |
GetNthNum(Buff, c * 3 + 3, &r); |
| 536 |
GetNthNum(Buff, c * 3 + 4, &g); |
| 537 |
GetNthNum(Buff, c * 3 + 5, &b); |
| 538 |
color->color[idx] = RGB(r, g, b); |
| 539 |
} |
| 540 |
} |
| 541 |
|
| 542 |
static void ReadColorSetting(const wchar_t *section, TColorSetting *color, const wchar_t *key, const wchar_t *fn) |
| 543 |
{ |
| 544 |
wchar_t BuffW[512]; |
| 545 |
char Buff[512]; |
| 546 |
int c, r, g, b; |
| 547 |
|
| 548 |
GetPrivateProfileStringW(section, key, L"0", BuffW, _countof(BuffW), fn); |
| 549 |
WideCharToACP_t(BuffW, Buff, _countof(Buff)); |
| 550 |
|
| 551 |
GetNthNum(Buff, 1, &c); |
| 552 |
color->change = c; |
| 553 |
|
| 554 |
GetNthNum(Buff, 2, &c); |
| 555 |
color->enable = c; |
| 556 |
|
| 557 |
if (color->change && color->enable) { |
| 558 |
GetNthNum(Buff, 3, &r); |
| 559 |
GetNthNum(Buff, 4, &g); |
| 560 |
GetNthNum(Buff, 5, &b); |
| 561 |
color->fg = RGB(r, g, b); |
| 562 |
|
| 563 |
GetNthNum(Buff, 6, &r); |
| 564 |
GetNthNum(Buff, 7, &g); |
| 565 |
GetNthNum(Buff, 8, &b); |
| 566 |
color->bg = RGB(r, g, b); |
| 567 |
} |
| 568 |
} |
| 569 |
|
| 570 |
/** |
| 571 |
* �J���[�e�[�}�v���O�C���� ini �t�@�C���������� |
| 572 |
*/ |
| 573 |
static void LoadColorPlugin(const wchar_t *fn, TColorTheme *color_theme) |
| 574 |
{ |
| 575 |
const wchar_t *section = COLOR_THEME_SECTION; |
| 576 |
wchar_t *name; |
| 577 |
hGetPrivateProfileStringW(section, L"Theme", NULL, fn, &name); |
| 578 |
wcscpy_s(color_theme->name, _countof(color_theme->name), name); |
| 579 |
free(name); |
| 580 |
|
| 581 |
for (int i = 0; i < _countof(color_attr_list); i++) { |
| 582 |
const wchar_t *key = color_attr_list[i].key; |
| 583 |
TColorSetting *color = (TColorSetting *)((UINT_PTR)color_theme + color_attr_list[i].offset); |
| 584 |
ReadColorSetting(section, color, key, fn); |
| 585 |
} |
| 586 |
|
| 587 |
ReadANSIColorSetting(section, &(color_theme->ansicolor), fn); |
| 588 |
} |
| 589 |
|
| 590 |
/** |
| 591 |
* �J���[�e�[�}�t�@�C����������,1�A�g���r���[�g�� |
| 592 |
*/ |
| 593 |
static void LoadColorAttr(const wchar_t *section, const wchar_t *key, const wchar_t *file, TColorSetting *attr) |
| 594 |
{ |
| 595 |
wchar_t *str; |
| 596 |
DWORD e = hGetPrivateProfileStringW(section, key, NULL, file, &str); |
| 597 |
if (e != 0 || *str == 0) { |
| 598 |
free(str); |
| 599 |
return; |
| 600 |
} |
| 601 |
|
| 602 |
BOOL change = FALSE; |
| 603 |
BOOL enable = FALSE; |
| 604 |
int fields; |
| 605 |
|
| 606 |
DWORD fore_rgb; |
| 607 |
DWORD back_rgb; |
| 608 |
fields = swscanf_s(str, L"%d, %d, #%06x, #%06x", &change, &enable, &fore_rgb, &back_rgb); |
| 609 |
if (fields == 4) { |
| 610 |
free(str); |
| 611 |
attr->change = change; |
| 612 |
attr->enable = enable; |
| 613 |
attr->fg = RGB((fore_rgb & 0xff0000) >> 16, (fore_rgb & 0x00ff00) >> 8, (fore_rgb & 0x0000ff)); |
| 614 |
attr->bg = RGB((back_rgb & 0xff0000) >> 16, (back_rgb & 0x00ff00) >> 8, (back_rgb & 0x0000ff)); |
| 615 |
return; |
| 616 |
} |
| 617 |
|
| 618 |
BYTE fg_red, fg_green, fg_blue; |
| 619 |
BYTE bg_red, bg_green, bg_blue; |
| 620 |
fields = swscanf_s(str, L"%d, %d, %hhu, %hhu, %hhu, %hhu, %hhu, %hhu", &change, &enable, &fg_red, &fg_green, |
| 621 |
&fg_blue, &bg_red, &bg_green, &bg_blue); |
| 622 |
if (fields == 8) { |
| 623 |
free(str); |
| 624 |
attr->change = change; |
| 625 |
attr->enable = enable; |
| 626 |
attr->fg = RGB(fg_red, fg_green, fg_blue); |
| 627 |
attr->bg = RGB(bg_red, bg_green, bg_blue); |
| 628 |
return; |
| 629 |
} |
| 630 |
fields = swscanf_s(str, L"%d, %d", &change, &enable); |
| 631 |
if (fields == 2) { |
| 632 |
free(str); |
| 633 |
attr->change = change; |
| 634 |
attr->enable = FALSE; // �F�w���������������������A���������������F������ |
| 635 |
return; |
| 636 |
} |
| 637 |
fields = swscanf_s(str, L"%d", &change); |
| 638 |
free(str); |
| 639 |
if (fields == 1) { |
| 640 |
attr->change = FALSE; // �F���X�������� |
| 641 |
return; |
| 642 |
} |
| 643 |
} |
| 644 |
|
| 645 |
/* |
| 646 |
* color theme�p���[�h |
| 647 |
*/ |
| 648 |
static void ThemeLoadColorDraft(const wchar_t *file, TColorTheme *theme) |
| 649 |
{ |
| 650 |
const wchar_t *section = COLOR_THEME_SECTION; |
| 651 |
|
| 652 |
wchar_t *name; |
| 653 |
hGetPrivateProfileStringW(section, L"Theme", NULL, file, &name); |
| 654 |
wcscpy_s(theme->name, _countof(theme->name), name); |
| 655 |
free(name); |
| 656 |
|
| 657 |
for (int i = 0; i < _countof(color_attr_list); i++) { |
| 658 |
const wchar_t *key = color_attr_list[i].key; |
| 659 |
TColorSetting *color = (TColorSetting *)((UINT_PTR)theme + color_attr_list[i].offset); |
| 660 |
LoadColorAttr(section, key, file, color); |
| 661 |
} |
| 662 |
|
| 663 |
theme->ansicolor.change = (BOOL)GetPrivateProfileIntW(section, L"ANSIColor", 1, file); |
| 664 |
for (int i = 0; i < _countof(ansi_list); i++) { |
| 665 |
const int index = ansi_list[i].index; |
| 666 |
const wchar_t *key = ansi_list[i].key; |
| 667 |
theme->ansicolor.color[index] = LoadColorOneANSI(section, key, file, theme->ansicolor.color[index]); |
| 668 |
} |
| 669 |
} |
| 670 |
|
| 671 |
/* |
| 672 |
* �J���[�e�[�}ini�t�@�C�������[�h���� |
| 673 |
*/ |
| 674 |
void ThemeLoadColor(const wchar_t *fn, TColorTheme *color_theme) |
| 675 |
{ |
| 676 |
ThemeGetColorDefault(color_theme); |
| 677 |
LoadColorPlugin(fn, color_theme); |
| 678 |
ThemeLoadColorOld(fn, color_theme); |
| 679 |
ThemeLoadColorDraft(fn, color_theme); |
| 680 |
} |
| 681 |
|
| 682 |
/** |
| 683 |
* �e�[�}�t�@�C������������ |
| 684 |
* |
| 685 |
* @param file �t�@�C���� |
| 686 |
* NULL�������\�������f�t�H���g�l������������ |
| 687 |
* @param bg_theme |
| 688 |
* @param color_theme |
| 689 |
*/ |
| 690 |
void ThemeLoad(const wchar_t *file, BGTheme *bg_theme, TColorTheme *color_theme) |
| 691 |
{ |
| 692 |
BOOL bg = FALSE; |
| 693 |
BOOL color = FALSE; |
| 694 |
wchar_t *prevDir; |
| 695 |
|
| 696 |
// �J�����g�f�B���N�g�������� |
| 697 |
hGetCurrentDirectoryW(&prevDir); |
| 698 |
|
| 699 |
// �e�[�}�t�@�C���������f�B���N�g���������I������ |
| 700 |
// �e�[�}�t�@�C�������p�X���������������� |
| 701 |
if (file != NULL) { |
| 702 |
wchar_t *dir = ExtractDirNameW(file); |
| 703 |
SetCurrentDirectoryW(dir); |
| 704 |
free(dir); |
| 705 |
} |
| 706 |
|
| 707 |
{ |
| 708 |
wchar_t sections[128]; |
| 709 |
size_t i; |
| 710 |
GetPrivateProfileSectionNamesW(sections, _countof(sections), file); |
| 711 |
for(i = 0; i < _countof(sections); /**/ ) { |
| 712 |
const wchar_t *p = §ions[i]; |
| 713 |
size_t len = wcslen(p); |
| 714 |
if (len == 0) { |
| 715 |
break; |
| 716 |
} |
| 717 |
if (_wcsicmp(p, BG_SECTION_NEW) == 0 || _wcsicmp(p, BG_SECTION_OLD) == 0) { |
| 718 |
bg = TRUE; |
| 719 |
} |
| 720 |
else if(_wcsicmp(p, COLOR_THEME_SECTION) == 0) { |
| 721 |
color = TRUE; |
| 722 |
} |
| 723 |
i += len; |
| 724 |
} |
| 725 |
} |
| 726 |
|
| 727 |
ThemeGetBGDefault(bg_theme); |
| 728 |
ThemeGetColorDefault(color_theme); |
| 729 |
|
| 730 |
// BG + �J���[�e�[�} ini�t�@�C�� |
| 731 |
if (bg && color) { |
| 732 |
ThemeLoadBG(file, bg_theme); |
| 733 |
ThemeLoadColor(file, color_theme); |
| 734 |
} |
| 735 |
// BG�e�[�} ini�t�@�C�� |
| 736 |
// TODO �������J���[�������������������������� |
| 737 |
else if (bg) { |
| 738 |
ThemeLoadBG(file, bg_theme); |
| 739 |
ThemeLoadColorOld(file, color_theme); |
| 740 |
} |
| 741 |
// �J���[�e�[�} ini�t�@�C�� |
| 742 |
else if (color) { |
| 743 |
ThemeLoadColor(file, color_theme); |
| 744 |
} |
| 745 |
else { |
| 746 |
#if 0 |
| 747 |
static const TTMessageBoxInfoW info = { |
| 748 |
"Tera Term", |
| 749 |
"MSG_TT_ERROR", L"Tera Term: ERROR", |
| 750 |
NULL, L"unknown ini file?", |
| 751 |
MB_OK|MB_ICONEXCLAMATION |
| 752 |
}; |
| 753 |
TTMessageBoxW(HVTWin, &info, ts.UILanguageFileW); |
| 754 |
#endif |
| 755 |
} |
| 756 |
|
| 757 |
// �J�����g�t�H���_���������� |
| 758 |
SetCurrentDirectoryW(prevDir); |
| 759 |
free(prevDir); |
| 760 |
} |