Develop and Download Open Source Software

Browse Subversion Repository

Annotation of /branches/ttcomtester/teraterm/teraterm/themefile.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 10338 - (hide annotations) (download) (as text)
Fri Oct 28 13:25:45 2022 UTC (17 months, 1 week ago) by zmatsuo
Original Path: trunk/teraterm/teraterm/themefile.cpp
File MIME type: text/x-c++src
File size: 25019 byte(s)
テーマの文字背景の透過設定の種類を増やした

- 次の文字背景部分の透過を個別に設定できるようにした
  - 通常属性(SGR0)部
  - 反転属性(SGR7)部
  - その他の背景部分
- 従来は反転属性(SGR7)以外の文字背景部分しか設定できなかった
- テーマファイルのドキュメント修正
- IDC_CHECK_FAST_SIZE_MOVE にテキストを設定した
  - "Disable theme when moving or resizing window"
  - "ウィンドウ移動/リサイズ時テーマを一時的にdisableする"
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 zmatsuo 10303 #include "codeconv.h"
39 zmatsuo 10256
40     #include "theme.h"
41    
42 zmatsuo 10332 #define BG_SECTION_OLD L"BG"
43     #define BG_SECTION_NEW L"BG Theme"
44     #define COLOR_THEME_SECTION L"Color Theme"
45 zmatsuo 10256
46 zmatsuo 10332 #if !defined(offsetof)
47     #define offsetof(s,m) ((size_t)&(((s*)0)->m))
48     #endif
49    
50 zmatsuo 10303 /**
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 zmatsuo 10332 { 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 zmatsuo 10303
67 zmatsuo 10332 { 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 zmatsuo 10303 };
76    
77 zmatsuo 10332 /**
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 zmatsuo 10256 const BG_PATTERN_ST *ThemeBGPatternList(int index)
93     {
94     static const BG_PATTERN_ST bg_pattern_list[] = {
95 zmatsuo 10332 { 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 zmatsuo 10256 };
103    
104     if (index >= _countof(bg_pattern_list)) {
105     return NULL;
106     }
107     return &bg_pattern_list[index];
108     }
109    
110 zmatsuo 10303 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 zmatsuo 10332 static COLORREF BGGetColor(const wchar_t *section, const wchar_t *key, COLORREF defcolor, const wchar_t *file)
139 zmatsuo 10256 {
140 zmatsuo 10332 COLORREF color = LoadColorOneANSI(section, key, file, defcolor);
141 zmatsuo 10303 return color;
142 zmatsuo 10256 }
143    
144     /*
145     * color theme�p���[�h
146     */
147 zmatsuo 10303 static void ThemeLoadColorOld(const wchar_t *file, TColorTheme *theme)
148 zmatsuo 10256 {
149 zmatsuo 10332 const wchar_t *section = BG_SECTION_OLD;
150 zmatsuo 10303 theme->ansicolor.change = TRUE;
151    
152 zmatsuo 10332 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 zmatsuo 10256
161 zmatsuo 10332 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 zmatsuo 10256
170 zmatsuo 10332 theme->vt.fg = BGGetColor(section, L"VTFore", theme->vt.fg, file);
171     theme->vt.bg = BGGetColor(section, L"VTBack", theme->vt.bg, file);
172 zmatsuo 10303 theme->vt.change = TRUE;
173     theme->vt.enable = TRUE;
174 zmatsuo 10256
175 zmatsuo 10332 theme->blink.fg = BGGetColor(section, L"VTBlinkFore", theme->blink.fg, file);
176     theme->blink.bg = BGGetColor(section, L"VTBlinkBack", theme->blink.bg, file);
177 zmatsuo 10303 theme->blink.change = TRUE;
178     theme->blink.enable = TRUE;
179 zmatsuo 10256
180 zmatsuo 10332 theme->bold.fg = BGGetColor(section, L"VTBoldFore", theme->bold.fg, file);
181     theme->bold.bg = BGGetColor(section, L"VTBoldBack", theme->bold.bg, file);
182 zmatsuo 10303 theme->bold.change = TRUE;
183     theme->bold.enable = TRUE;
184 zmatsuo 10256
185 zmatsuo 10332 theme->underline.fg = BGGetColor(section, L"VTUnderlineFore", theme->underline.fg, file);
186     theme->underline.bg = BGGetColor(section, L"VTUnderlineBack", theme->underline.bg, file);
187 zmatsuo 10303 theme->underline.change = TRUE;
188     theme->underline.enable = TRUE;
189 zmatsuo 10256
190 zmatsuo 10332 theme->reverse.fg = BGGetColor(section, L"VTReverseFore", theme->reverse.fg, file);
191     theme->reverse.bg = BGGetColor(section, L"VTReverseBack", theme->reverse.bg, file);
192 zmatsuo 10303 theme->reverse.change = TRUE;
193     theme->reverse.enable = TRUE;
194 zmatsuo 10256
195 zmatsuo 10332 theme->url.fg = BGGetColor(section, L"URLFore", theme->url.fg, file);
196     theme->url.bg = BGGetColor(section, L"URLBack", theme->url.bg, file);
197 zmatsuo 10303 theme->url.change = TRUE;
198     theme->url.enable = TRUE;
199 zmatsuo 10256 }
200    
201     /**
202 zmatsuo 10303 * save color one attribute
203 zmatsuo 10256 */
204 zmatsuo 10332 static void BGSaveColorOne(const wchar_t *section, const wchar_t *key, const TColorSetting *color, const wchar_t *fn)
205 zmatsuo 10256 {
206 zmatsuo 10303 wchar_t *buf;
207 zmatsuo 10256 COLORREF fg = color->fg;
208     COLORREF bg = color->bg;
209 zmatsuo 10303 int sp_len = 20 - (int)wcslen(key);
210 zmatsuo 10332 aswprintf(&buf, L"%*.*s %d,%d, %3hhu,%3hhu,%3hhu, %3hhu,%3hhu,%3hhu ; #%02x%02x%02x, #%02x%02x%02x",
211 zmatsuo 10303 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 zmatsuo 10256
221 zmatsuo 10332 #if 1
222     static void BGSaveColorANSI(const wchar_t *section, const TAnsiColorSetting *color, const wchar_t *fn)
223 zmatsuo 10303 {
224 zmatsuo 10256 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 zmatsuo 10303 swprintf(color_str, _countof(color_str), L"%hhu,%hhu,%hhu, ", GetRValue(c), GetGValue(c), GetBValue(c));
232 zmatsuo 10256 awcscat(&buff, color_str);
233     }
234    
235 zmatsuo 10332 WritePrivateProfileStringW(section, L"ANSIColor", buff, fn);
236 zmatsuo 10256 free(buff);
237     }
238 zmatsuo 10332 #endif
239 zmatsuo 10256
240 zmatsuo 10303 static void SaveColorOneANSI(const wchar_t *section, const wchar_t *key, const wchar_t *file, COLORREF color, int index)
241 zmatsuo 10256 {
242 zmatsuo 10303 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 zmatsuo 10332 * TODO ����
271 zmatsuo 10303 */
272 zmatsuo 10332 #if 1
273 zmatsuo 10303 void ThemeSaveColorOld(TColorTheme *color_theme, const wchar_t *fn)
274     {
275 zmatsuo 10332 const wchar_t *section = COLOR_THEME_SECTION;
276 zmatsuo 10256
277 zmatsuo 10332 WritePrivateProfileStringW(section, L"Theme", color_theme->name, fn);
278 zmatsuo 10256
279 zmatsuo 10332 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 zmatsuo 10256 }
287 zmatsuo 10332 #endif
288 zmatsuo 10256
289 zmatsuo 10332 /**
290     * �J���[�e�[�}������
291     */
292 zmatsuo 10303 void ThemeSaveColor(TColorTheme *color_theme, const wchar_t *fn)
293     {
294 zmatsuo 10332 const wchar_t *section = COLOR_THEME_SECTION;
295 zmatsuo 10303 WritePrivateProfileStringW(section, L"Theme", color_theme->name, fn);
296    
297 zmatsuo 10332 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 zmatsuo 10303
303     SaveColorANSINew(section, &(color_theme->ansicolor), fn);
304     }
305    
306 zmatsuo 10332 static void WriteInt3(const wchar_t *Sect, const wchar_t *Key, const wchar_t *FName,
307     int i1, int i2, int i3)
308 zmatsuo 10256 {
309 zmatsuo 10332 wchar_t Temp[96];
310     _snwprintf_s(Temp, _countof(Temp), _TRUNCATE, L"%d,%d,%d",
311 zmatsuo 10256 i1, i2,i3);
312 zmatsuo 10332 WritePrivateProfileStringW(Sect, Key, Temp, FName);
313 zmatsuo 10256 }
314    
315 zmatsuo 10332 static void WriteCOLORREF(const wchar_t *Sect, const wchar_t *Key, const wchar_t *FName, COLORREF color)
316 zmatsuo 10256 {
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 zmatsuo 10332 static const wchar_t *GetBGPatternStr(BG_PATTERN id)
325 zmatsuo 10256 {
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 zmatsuo 10332 static BOOL GetBGPatternID(const wchar_t *str, BG_PATTERN *pattern)
341 zmatsuo 10256 {
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 zmatsuo 10332 if (_wcsicmp(st->str, str) == 0) {
352 zmatsuo 10256 *pattern = st->id;
353     return TRUE;
354     }
355     }
356     }
357    
358     void ThemeSaveBG(const BGTheme *bg_theme, const wchar_t *file)
359     {
360 zmatsuo 10332 const wchar_t *section = BG_SECTION_NEW;
361    
362     WritePrivateProfileStringW(section, L"BGDestFile", bg_theme->BGDest.file, file);
363 zmatsuo 10256 #if 0
364 zmatsuo 10332 WritePrivateProfileStringW(section, L"BGDestType",
365 zmatsuo 10256 bg_theme->BGDest.type == BG_PICTURE ? "picture" : "color", file);
366     #endif
367 zmatsuo 10332 WriteCOLORREF(section, L"BGDestColor", file, bg_theme->BGDest.color);
368     WritePrivateProfileStringW(section, L"BGDestPattern", GetBGPatternStr(bg_theme->BGDest.pattern), file);
369 zmatsuo 10256
370 zmatsuo 10332 WritePrivateProfileIntW(section, L"BGSrc1Alpha", bg_theme->BGSrc1.alpha, file);
371 zmatsuo 10256
372 zmatsuo 10332 WritePrivateProfileIntW(section, L"BGSrc2Alpha", bg_theme->BGSrc2.alpha, file);
373     WriteCOLORREF(section, L"BGSrc2Color", file, bg_theme->BGSrc2.color);
374 zmatsuo 10256
375 zmatsuo 10332 WritePrivateProfileIntW(section, L"BGReverseTextAlpha", bg_theme->BGReverseTextAlpha, file);
376 zmatsuo 10338 WritePrivateProfileIntW(section, L"BGTextBackAlpha", bg_theme->TextBackAlpha, file);
377     WritePrivateProfileIntW(section, L"BGBackAlpha", bg_theme->BackAlpha, file);
378 zmatsuo 10256 }
379    
380 zmatsuo 10332 static int BGGetStrIndex(const wchar_t *section, const wchar_t *name, int def, const wchar_t *file, const wchar_t * const *strList, int nList)
381 zmatsuo 10256 {
382 zmatsuo 10332 wchar_t defstr[64];
383     wchar_t str[64];
384 zmatsuo 10256 int i;
385    
386     def %= nList;
387    
388 zmatsuo 10332 wcsncpy_s(defstr, _countof(defstr), strList[def], _TRUNCATE);
389     GetPrivateProfileStringW(section, name, defstr, str, _countof(str), file);
390 zmatsuo 10256
391     for (i = 0; i < nList; i++)
392 zmatsuo 10332 if (!_wcsicmp(str, strList[i]))
393 zmatsuo 10256 return i;
394    
395     return 0;
396     }
397    
398 zmatsuo 10332 static BOOL BGGetOnOff(const wchar_t *section, const wchar_t *name, BOOL def, const wchar_t *file)
399 zmatsuo 10256 {
400 zmatsuo 10332 static const wchar_t * const strList[2] = {L"Off", L"On"};
401 zmatsuo 10256
402 zmatsuo 10332 return (BOOL)BGGetStrIndex(section, name, def, file, strList, 2);
403 zmatsuo 10256 }
404    
405 zmatsuo 10332 static BG_PATTERN BGGetPattern(const wchar_t *section, const wchar_t *name, BG_PATTERN def, const wchar_t *file)
406 zmatsuo 10256 {
407     BG_PATTERN retval;
408 zmatsuo 10332 wchar_t str[64];
409     GetPrivateProfileStringW(section, name, L"", str, _countof(str), file);
410 zmatsuo 10256 if (str[0] == 0) {
411     return def;
412     }
413     if (GetBGPatternID(str, &retval) == FALSE) {
414     retval = def;
415     }
416     return retval;
417     }
418    
419 zmatsuo 10332 static BG_TYPE BGGetType(const wchar_t *section, const wchar_t *name, BG_TYPE def, const wchar_t *file)
420 zmatsuo 10256 {
421 zmatsuo 10332 static const wchar_t *strList[3] = {L"color", L"picture", L"wallpaper"};
422 zmatsuo 10256
423 zmatsuo 10332 return (BG_TYPE)BGGetStrIndex(section, name, def, file, strList, 3);
424 zmatsuo 10256 }
425    
426     /**
427     * BG�����[�h
428     */
429 zmatsuo 10332 void ThemeLoadBGSection(const wchar_t *section, const wchar_t *file, BGTheme *bg_theme)
430 zmatsuo 10256 {
431 zmatsuo 10332 wchar_t pathW[MAX_PATH];
432     wchar_t *p;
433 zmatsuo 10256
434     // Dest �������o��
435 zmatsuo 10332 bg_theme->BGDest.type = BGGetType(section, L"BGDestType", bg_theme->BGDest.type, file);
436     bg_theme->BGDest.pattern = BGGetPattern(section, L"BGPicturePattern", bg_theme->BGDest.pattern, file);
437     bg_theme->BGDest.pattern = BGGetPattern(section, L"BGDestPattern", bg_theme->BGDest.pattern, file);
438     bg_theme->BGDest.antiAlias = BGGetOnOff(section, L"BGDestAntiAlias", bg_theme->BGDest.antiAlias, file);
439     bg_theme->BGDest.color = BGGetColor(section, L"BGPictureBaseColor", bg_theme->BGDest.color, file);
440     bg_theme->BGDest.color = BGGetColor(section, L"BGDestColor", bg_theme->BGDest.color, file);
441     GetPrivateProfileStringW(section, L"BGPictureFile", bg_theme->BGDest.file, pathW, _countof(pathW), file);
442     GetPrivateProfileStringW(section, L"BGDestFile", pathW, pathW, _countof(pathW), file);
443     p = RandomFileW(pathW);
444     if (p != NULL) {
445     wcscpy_s(bg_theme->BGDest.file, _countof(bg_theme->BGDest.file), p);
446     free(p);
447 zmatsuo 10256 }
448 zmatsuo 10332 else {
449     bg_theme->BGDest.file[0] = 0;
450     }
451 zmatsuo 10256
452     // Src1 �������o��
453 zmatsuo 10332 bg_theme->BGSrc1.type = BGGetType(section, L"BGSrc1Type", bg_theme->BGSrc1.type, file);
454     bg_theme->BGSrc1.pattern = BGGetPattern(section, L"BGSrc1Pattern", bg_theme->BGSrc1.pattern, file);
455     bg_theme->BGSrc1.antiAlias = BGGetOnOff(section, L"BGSrc1AntiAlias", bg_theme->BGSrc1.antiAlias, file);
456     bg_theme->BGSrc1.alpha = 255 - GetPrivateProfileIntW(section, L"BGPictureTone", 255 - bg_theme->BGSrc1.alpha, file);
457     bg_theme->BGSrc1.alpha = GetPrivateProfileIntW(section, L"BGSrc1Alpha", bg_theme->BGSrc1.alpha, file);
458     bg_theme->BGSrc1.color = BGGetColor(section, L"BGSrc1Color", bg_theme->BGSrc1.color, file);
459     GetPrivateProfileStringW(section, L"BGSrc1File", bg_theme->BGSrc1.file, pathW, _countof(pathW), file);
460     p = RandomFileW(pathW);
461     if (p != NULL) {
462     wcscpy_s(bg_theme->BGSrc1.file, _countof(bg_theme->BGSrc1.file), p);
463     free(p);
464     }
465     else {
466     bg_theme->BGSrc1.file[0] = 0;
467     }
468 zmatsuo 10256
469     // Src2 �������o��
470 zmatsuo 10332 bg_theme->BGSrc2.type = BGGetType(section, L"BGSrc2Type", bg_theme->BGSrc2.type, file);
471     bg_theme->BGSrc2.pattern = BGGetPattern(section, L"BGSrc2Pattern", bg_theme->BGSrc2.pattern, file);
472     bg_theme->BGSrc2.antiAlias = BGGetOnOff(section, L"BGSrc2AntiAlias", bg_theme->BGSrc2.antiAlias, file);
473     bg_theme->BGSrc2.alpha = 255 - GetPrivateProfileIntW(section, L"BGFadeTone", 255 - bg_theme->BGSrc2.alpha, file);
474     bg_theme->BGSrc2.alpha = GetPrivateProfileIntW(section, L"BGSrc2Alpha", bg_theme->BGSrc2.alpha, file);
475     bg_theme->BGSrc2.color = BGGetColor(section, L"BGFadeColor", bg_theme->BGSrc2.color, file);
476     bg_theme->BGSrc2.color = BGGetColor(section, L"BGSrc2Color", bg_theme->BGSrc2.color, file);
477     GetPrivateProfileStringW(section, L"BGSrc2File", bg_theme->BGSrc2.file, pathW, _countof(pathW), file);
478     p = RandomFileW(pathW);
479     if (p != NULL) {
480     wcscpy_s(bg_theme->BGSrc2.file, _countof(bg_theme->BGSrc2.file), p);
481     free(p);
482     }
483     else {
484     bg_theme->BGSrc2.file[0] = 0;
485     }
486 zmatsuo 10256
487     //�����������o��
488 zmatsuo 10332 bg_theme->BGReverseTextAlpha = GetPrivateProfileIntW(section, L"BGReverseTextTone", bg_theme->BGReverseTextAlpha, file);
489     bg_theme->BGReverseTextAlpha = GetPrivateProfileIntW(section, L"BGReverseTextAlpha", bg_theme->BGReverseTextAlpha, file);
490 zmatsuo 10338 bg_theme->TextBackAlpha = GetPrivateProfileIntW(section, L"BGTextBackAlpha", bg_theme->TextBackAlpha, file);
491     bg_theme->BackAlpha = GetPrivateProfileIntW(section, L"BGBackAlpha", bg_theme->BackAlpha, file);
492 zmatsuo 10256 }
493    
494 zmatsuo 10332 /**
495     * BG�����[�h
496     */
497     void ThemeLoadBG(const wchar_t *file, BGTheme *bg_theme)
498 zmatsuo 10256 {
499 zmatsuo 10332 ThemeLoadBGSection(BG_SECTION_OLD, file, bg_theme);
500     ThemeLoadBGSection(BG_SECTION_NEW, file, bg_theme);
501     }
502    
503     static void ReadANSIColorSetting(const wchar_t *section, TAnsiColorSetting *color, const wchar_t *fn)
504     {
505     wchar_t BuffW[512];
506 zmatsuo 10256 char Buff[512];
507     int c, r, g, b;
508 zmatsuo 10274 // ANSIColor16���A������/�����O���[�v������������������
509     const static int index256[] = {
510     0,
511 zmatsuo 10303 1, 2, 3, 4, 5, 6, 7,
512     8,
513 zmatsuo 10274 9, 10, 11, 12, 13, 14, 15,
514     };
515 zmatsuo 10256
516 zmatsuo 10332 GetPrivateProfileStringW(section, L"ANSIColor", L"0", BuffW, sizeof(BuffW), fn);
517     WideCharToACP_t(BuffW, Buff, _countof(Buff));
518 zmatsuo 10256
519     GetNthNum(Buff, 1, &c);
520     color->change = c;
521    
522     GetNthNum(Buff, 2, &c);
523 zmatsuo 10303 //color->enable = c;
524 zmatsuo 10256
525     for (c=0; c<16; c++) {
526 zmatsuo 10274 int idx = index256[c];
527 zmatsuo 10256 GetNthNum(Buff, c * 3 + 3, &r);
528     GetNthNum(Buff, c * 3 + 4, &g);
529     GetNthNum(Buff, c * 3 + 5, &b);
530 zmatsuo 10274 color->color[idx] = RGB(r, g, b);
531 zmatsuo 10256 }
532     }
533    
534 zmatsuo 10332 static void ReadColorSetting(const wchar_t *section, TColorSetting *color, const wchar_t *key, const wchar_t *fn)
535 zmatsuo 10256 {
536 zmatsuo 10332 wchar_t BuffW[512];
537 zmatsuo 10256 char Buff[512];
538     int c, r, g, b;
539    
540 zmatsuo 10332 GetPrivateProfileStringW(section, key, L"0", BuffW, _countof(BuffW), fn);
541     WideCharToACP_t(BuffW, Buff, _countof(Buff));
542 zmatsuo 10256
543     GetNthNum(Buff, 1, &c);
544     color->change = c;
545    
546     GetNthNum(Buff, 2, &c);
547     color->enable = c;
548    
549     if (color->change && color->enable) {
550     GetNthNum(Buff, 3, &r);
551     GetNthNum(Buff, 4, &g);
552     GetNthNum(Buff, 5, &b);
553     color->fg = RGB(r, g, b);
554    
555     GetNthNum(Buff, 6, &r);
556     GetNthNum(Buff, 7, &g);
557     GetNthNum(Buff, 8, &b);
558     color->bg = RGB(r, g, b);
559     }
560     }
561    
562 zmatsuo 10303 /**
563     * �J���[�e�[�}�v���O�C���� ini �t�@�C����������
564 zmatsuo 10256 */
565 zmatsuo 10303 static void LoadColorPlugin(const wchar_t *fn, TColorTheme *color_theme)
566 zmatsuo 10256 {
567 zmatsuo 10332 const wchar_t *section = COLOR_THEME_SECTION;
568 zmatsuo 10303 wchar_t *name;
569     hGetPrivateProfileStringW(section, L"Theme", NULL, fn, &name);
570     wcscpy_s(color_theme->name, _countof(color_theme->name), name);
571     free(name);
572 zmatsuo 10256
573 zmatsuo 10332 for (int i = 0; i < _countof(color_attr_list); i++) {
574     const wchar_t *key = color_attr_list[i].key;
575     TColorSetting *color = (TColorSetting *)((UINT_PTR)color_theme + color_attr_list[i].offset);
576     ReadColorSetting(section, color, key, fn);
577     }
578 zmatsuo 10256
579 zmatsuo 10332 ReadANSIColorSetting(section, &(color_theme->ansicolor), fn);
580 zmatsuo 10256 }
581    
582 zmatsuo 10303 /**
583     * �J���[�e�[�}�t�@�C����������,1�A�g���r���[�g��
584     */
585     static void LoadColorAttr(const wchar_t *section, const wchar_t *key, const wchar_t *file, TColorSetting *attr)
586 zmatsuo 10256 {
587 zmatsuo 10303 wchar_t *str;
588     DWORD e = hGetPrivateProfileStringW(section, key, NULL, file, &str);
589     if (e != 0 || *str == 0) {
590     free(str);
591     return;
592     }
593 zmatsuo 10256
594 zmatsuo 10303 BOOL change = FALSE;
595     BOOL enable = FALSE;
596     int fields;
597 zmatsuo 10256
598 zmatsuo 10303 DWORD fore_rgb;
599     DWORD back_rgb;
600     fields = swscanf_s(str, L"%d, %d, #%06x, #%06x", &change, &enable, &fore_rgb, &back_rgb);
601     if (fields == 4) {
602     free(str);
603     attr->change = change;
604     attr->enable = enable;
605     attr->fg = RGB((fore_rgb & 0xff0000) >> 16, (fore_rgb & 0x00ff00) >> 8, (fore_rgb & 0x0000ff));
606     attr->bg = RGB((back_rgb & 0xff0000) >> 16, (back_rgb & 0x00ff00) >> 8, (back_rgb & 0x0000ff));
607     return;
608     }
609 zmatsuo 10256
610 zmatsuo 10303 BYTE fg_red, fg_green, fg_blue;
611     BYTE bg_red, bg_green, bg_blue;
612     fields = swscanf_s(str, L"%d, %d, %hhu, %hhu, %hhu, %hhu, %hhu, %hhu", &change, &enable, &fg_red, &fg_green,
613     &fg_blue, &bg_red, &bg_green, &bg_blue);
614     if (fields == 8) {
615     free(str);
616     attr->change = change;
617     attr->enable = enable;
618     attr->fg = RGB(fg_red, fg_green, fg_blue);
619     attr->bg = RGB(bg_red, bg_green, bg_blue);
620     return;
621 zmatsuo 10256 }
622 zmatsuo 10303 fields = swscanf_s(str, L"%d, %d", &change, &enable);
623     if (fields == 2) {
624     free(str);
625     attr->change = change;
626     attr->enable = FALSE; // �F�w���������������������A���������������F������
627     return;
628     }
629     fields = swscanf_s(str, L"%d", &change);
630     free(str);
631     if (fields == 1) {
632     attr->change = FALSE; // �F���X��������
633     return;
634     }
635 zmatsuo 10256 }
636    
637 zmatsuo 10303 /*
638     * color theme�p���[�h
639     */
640     static void ThemeLoadColorDraft(const wchar_t *file, TColorTheme *theme)
641 zmatsuo 10256 {
642 zmatsuo 10332 const wchar_t *section = COLOR_THEME_SECTION;
643 zmatsuo 10256
644 zmatsuo 10303 wchar_t *name;
645     hGetPrivateProfileStringW(section, L"Theme", NULL, file, &name);
646     wcscpy_s(theme->name, _countof(theme->name), name);
647     free(name);
648 zmatsuo 10256
649 zmatsuo 10332 for (int i = 0; i < _countof(color_attr_list); i++) {
650     const wchar_t *key = color_attr_list[i].key;
651     TColorSetting *color = (TColorSetting *)((UINT_PTR)theme + color_attr_list[i].offset);
652     LoadColorAttr(section, key, file, color);
653 zmatsuo 10303 }
654 zmatsuo 10256
655 zmatsuo 10303 theme->ansicolor.change = (BOOL)GetPrivateProfileIntW(section, L"ANSIColor", 1, file);
656     for (int i = 0; i < _countof(ansi_list); i++) {
657     const int index = ansi_list[i].index;
658     const wchar_t *key = ansi_list[i].key;
659     theme->ansicolor.color[index] = LoadColorOneANSI(section, key, file, theme->ansicolor.color[index]);
660     }
661 zmatsuo 10256 }
662    
663 zmatsuo 10303 /*
664     * �J���[�e�[�}ini�t�@�C�������[�h����
665 zmatsuo 10256 */
666 zmatsuo 10303 void ThemeLoadColor(const wchar_t *fn, TColorTheme *color_theme)
667 zmatsuo 10256 {
668 zmatsuo 10303 ThemeGetColorDefault(color_theme);
669     LoadColorPlugin(fn, color_theme);
670     ThemeLoadColorOld(fn, color_theme);
671     ThemeLoadColorDraft(fn, color_theme);
672 zmatsuo 10256 }
673    
674     /**
675     * �e�[�}�t�@�C������������
676     *
677     * @param file �t�@�C����
678     * NULL�������\�������f�t�H���g�l������������
679     * @param bg_theme
680     * @param color_theme
681     */
682     void ThemeLoad(const wchar_t *file, BGTheme *bg_theme, TColorTheme *color_theme)
683     {
684     BOOL bg = FALSE;
685     BOOL color = FALSE;
686     wchar_t *prevDir;
687    
688     // �J�����g�f�B���N�g��������
689     hGetCurrentDirectoryW(&prevDir);
690    
691     // �e�[�}�t�@�C���������f�B���N�g���������I������
692     // �e�[�}�t�@�C�������p�X����������������
693     if (file != NULL) {
694     wchar_t *dir = ExtractDirNameW(file);
695     SetCurrentDirectoryW(dir);
696     free(dir);
697     }
698    
699     {
700     wchar_t sections[128];
701     size_t i;
702     GetPrivateProfileSectionNamesW(sections, _countof(sections), file);
703     for(i = 0; i < _countof(sections); /**/ ) {
704     const wchar_t *p = &sections[i];
705     size_t len = wcslen(p);
706     if (len == 0) {
707     break;
708     }
709 zmatsuo 10332 if (_wcsicmp(p, BG_SECTION_NEW) == 0 || _wcsicmp(p, BG_SECTION_OLD) == 0) {
710 zmatsuo 10256 bg = TRUE;
711     }
712 zmatsuo 10332 else if(_wcsicmp(p, COLOR_THEME_SECTION) == 0) {
713 zmatsuo 10256 color = TRUE;
714     }
715     i += len;
716     }
717     }
718    
719     ThemeGetBGDefault(bg_theme);
720     ThemeGetColorDefault(color_theme);
721    
722     // BG + �J���[�e�[�} ini�t�@�C��
723     if (bg && color) {
724     ThemeLoadBG(file, bg_theme);
725     ThemeLoadColor(file, color_theme);
726     }
727     // BG�e�[�} ini�t�@�C��
728     // TODO �������J���[��������������������������
729     else if (bg) {
730     ThemeLoadBG(file, bg_theme);
731     ThemeLoadColorOld(file, color_theme);
732     }
733     // �J���[�e�[�} ini�t�@�C��
734     else if (color) {
735     ThemeLoadColor(file, color_theme);
736     }
737     else {
738     #if 0
739     static const TTMessageBoxInfoW info = {
740     "Tera Term",
741     "MSG_TT_ERROR", L"Tera Term: ERROR",
742     NULL, L"unknown ini file?",
743     MB_OK|MB_ICONEXCLAMATION
744     };
745     TTMessageBoxW(HVTWin, &info, ts.UILanguageFileW);
746     #endif
747     }
748    
749     // �J�����g�t�H���_����������
750     SetCurrentDirectoryW(prevDir);
751     free(prevDir);
752     }

Back to OSDN">Back to OSDN
ViewVC Help
Powered by ViewVC 1.1.26