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 10332 - (hide annotations) (download) (as text)
Sun Oct 23 15:16:14 2022 UTC (17 months, 2 weeks ago) by zmatsuo
Original Path: trunk/teraterm/teraterm/themefile.cpp
File MIME type: text/x-c++src
File size: 24765 byte(s)
テーマファイルの扱いをUnicode化

- UnicodeAPIを使用するよう修正
- 背景テーマのセクション名を "BG theme" へ変更
  - "BG" セクションも読み込める
- TODO
  - MAX_PATHが残っている
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 10256 }
377    
378 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)
379 zmatsuo 10256 {
380 zmatsuo 10332 wchar_t defstr[64];
381     wchar_t str[64];
382 zmatsuo 10256 int i;
383    
384     def %= nList;
385    
386 zmatsuo 10332 wcsncpy_s(defstr, _countof(defstr), strList[def], _TRUNCATE);
387     GetPrivateProfileStringW(section, name, defstr, str, _countof(str), file);
388 zmatsuo 10256
389     for (i = 0; i < nList; i++)
390 zmatsuo 10332 if (!_wcsicmp(str, strList[i]))
391 zmatsuo 10256 return i;
392    
393     return 0;
394     }
395    
396 zmatsuo 10332 static BOOL BGGetOnOff(const wchar_t *section, const wchar_t *name, BOOL def, const wchar_t *file)
397 zmatsuo 10256 {
398 zmatsuo 10332 static const wchar_t * const strList[2] = {L"Off", L"On"};
399 zmatsuo 10256
400 zmatsuo 10332 return (BOOL)BGGetStrIndex(section, name, def, file, strList, 2);
401 zmatsuo 10256 }
402    
403 zmatsuo 10332 static BG_PATTERN BGGetPattern(const wchar_t *section, const wchar_t *name, BG_PATTERN def, const wchar_t *file)
404 zmatsuo 10256 {
405     BG_PATTERN retval;
406 zmatsuo 10332 wchar_t str[64];
407     GetPrivateProfileStringW(section, name, L"", str, _countof(str), file);
408 zmatsuo 10256 if (str[0] == 0) {
409     return def;
410     }
411     if (GetBGPatternID(str, &retval) == FALSE) {
412     retval = def;
413     }
414     return retval;
415     }
416    
417 zmatsuo 10332 static BG_TYPE BGGetType(const wchar_t *section, const wchar_t *name, BG_TYPE def, const wchar_t *file)
418 zmatsuo 10256 {
419 zmatsuo 10332 static const wchar_t *strList[3] = {L"color", L"picture", L"wallpaper"};
420 zmatsuo 10256
421 zmatsuo 10332 return (BG_TYPE)BGGetStrIndex(section, name, def, file, strList, 3);
422 zmatsuo 10256 }
423    
424     /**
425     * BG�����[�h
426     */
427 zmatsuo 10332 void ThemeLoadBGSection(const wchar_t *section, const wchar_t *file, BGTheme *bg_theme)
428 zmatsuo 10256 {
429 zmatsuo 10332 wchar_t pathW[MAX_PATH];
430     wchar_t *p;
431 zmatsuo 10256
432     // Dest �������o��
433 zmatsuo 10332 bg_theme->BGDest.type = BGGetType(section, L"BGDestType", bg_theme->BGDest.type, file);
434     bg_theme->BGDest.pattern = BGGetPattern(section, L"BGPicturePattern", bg_theme->BGDest.pattern, file);
435     bg_theme->BGDest.pattern = BGGetPattern(section, L"BGDestPattern", bg_theme->BGDest.pattern, file);
436     bg_theme->BGDest.antiAlias = BGGetOnOff(section, L"BGDestAntiAlias", bg_theme->BGDest.antiAlias, file);
437     bg_theme->BGDest.color = BGGetColor(section, L"BGPictureBaseColor", bg_theme->BGDest.color, file);
438     bg_theme->BGDest.color = BGGetColor(section, L"BGDestColor", bg_theme->BGDest.color, file);
439     GetPrivateProfileStringW(section, L"BGPictureFile", bg_theme->BGDest.file, pathW, _countof(pathW), file);
440     GetPrivateProfileStringW(section, L"BGDestFile", pathW, pathW, _countof(pathW), file);
441     p = RandomFileW(pathW);
442     if (p != NULL) {
443     wcscpy_s(bg_theme->BGDest.file, _countof(bg_theme->BGDest.file), p);
444     free(p);
445 zmatsuo 10256 }
446 zmatsuo 10332 else {
447     bg_theme->BGDest.file[0] = 0;
448     bg_theme->BGDest.type = BG_NONE; // �w�i��������
449     }
450 zmatsuo 10256
451     // Src1 �������o��
452 zmatsuo 10332 bg_theme->BGSrc1.type = BGGetType(section, L"BGSrc1Type", bg_theme->BGSrc1.type, file);
453     bg_theme->BGSrc1.pattern = BGGetPattern(section, L"BGSrc1Pattern", bg_theme->BGSrc1.pattern, file);
454     bg_theme->BGSrc1.antiAlias = BGGetOnOff(section, L"BGSrc1AntiAlias", bg_theme->BGSrc1.antiAlias, file);
455     bg_theme->BGSrc1.alpha = 255 - GetPrivateProfileIntW(section, L"BGPictureTone", 255 - bg_theme->BGSrc1.alpha, file);
456     if (bg_theme->BGDest.file[0] == 0)
457 zmatsuo 10256 bg_theme->BGSrc1.alpha = 255;
458 zmatsuo 10332 bg_theme->BGSrc1.alpha = GetPrivateProfileIntW(section, L"BGSrc1Alpha", bg_theme->BGSrc1.alpha, file);
459     bg_theme->BGSrc1.color = BGGetColor(section, L"BGSrc1Color", bg_theme->BGSrc1.color, file);
460     GetPrivateProfileStringW(section, L"BGSrc1File", bg_theme->BGSrc1.file, pathW, _countof(pathW), file);
461     p = RandomFileW(pathW);
462     if (p != NULL) {
463     wcscpy_s(bg_theme->BGSrc1.file, _countof(bg_theme->BGSrc1.file), p);
464     free(p);
465     }
466     else {
467     bg_theme->BGSrc1.file[0] = 0;
468     }
469 zmatsuo 10256
470     // Src2 �������o��
471 zmatsuo 10332 bg_theme->BGSrc2.type = BGGetType(section, L"BGSrc2Type", bg_theme->BGSrc2.type, file);
472     bg_theme->BGSrc2.pattern = BGGetPattern(section, L"BGSrc2Pattern", bg_theme->BGSrc2.pattern, file);
473     bg_theme->BGSrc2.antiAlias = BGGetOnOff(section, L"BGSrc2AntiAlias", bg_theme->BGSrc2.antiAlias, file);
474     bg_theme->BGSrc2.alpha = 255 - GetPrivateProfileIntW(section, L"BGFadeTone", 255 - bg_theme->BGSrc2.alpha, file);
475     bg_theme->BGSrc2.alpha = GetPrivateProfileIntW(section, L"BGSrc2Alpha", bg_theme->BGSrc2.alpha, file);
476     bg_theme->BGSrc2.color = BGGetColor(section, L"BGFadeColor", bg_theme->BGSrc2.color, file);
477     bg_theme->BGSrc2.color = BGGetColor(section, L"BGSrc2Color", bg_theme->BGSrc2.color, file);
478     GetPrivateProfileStringW(section, L"BGSrc2File", bg_theme->BGSrc2.file, pathW, _countof(pathW), file);
479     p = RandomFileW(pathW);
480     if (p != NULL) {
481     wcscpy_s(bg_theme->BGSrc2.file, _countof(bg_theme->BGSrc2.file), p);
482     free(p);
483     }
484     else {
485     bg_theme->BGSrc2.file[0] = 0;
486     }
487 zmatsuo 10256
488     //�����������o��
489 zmatsuo 10332 bg_theme->BGReverseTextAlpha = GetPrivateProfileIntW(section, L"BGReverseTextTone", bg_theme->BGReverseTextAlpha, file);
490     bg_theme->BGReverseTextAlpha = GetPrivateProfileIntW(section, L"BGReverseTextAlpha", bg_theme->BGReverseTextAlpha, file);
491 zmatsuo 10256 }
492    
493 zmatsuo 10332 /**
494     * BG�����[�h
495     */
496     void ThemeLoadBG(const wchar_t *file, BGTheme *bg_theme)
497 zmatsuo 10256 {
498 zmatsuo 10332 ThemeLoadBGSection(BG_SECTION_OLD, file, bg_theme);
499     ThemeLoadBGSection(BG_SECTION_NEW, file, bg_theme);
500     }
501    
502     static void ReadANSIColorSetting(const wchar_t *section, TAnsiColorSetting *color, const wchar_t *fn)
503     {
504     wchar_t BuffW[512];
505 zmatsuo 10256 char Buff[512];
506     int c, r, g, b;
507 zmatsuo 10274 // ANSIColor16���A������/�����O���[�v������������������
508     const static int index256[] = {
509     0,
510 zmatsuo 10303 1, 2, 3, 4, 5, 6, 7,
511     8,
512 zmatsuo 10274 9, 10, 11, 12, 13, 14, 15,
513     };
514 zmatsuo 10256
515 zmatsuo 10332 GetPrivateProfileStringW(section, L"ANSIColor", L"0", BuffW, sizeof(BuffW), fn);
516     WideCharToACP_t(BuffW, Buff, _countof(Buff));
517 zmatsuo 10256
518     GetNthNum(Buff, 1, &c);
519     color->change = c;
520    
521     GetNthNum(Buff, 2, &c);
522 zmatsuo 10303 //color->enable = c;
523 zmatsuo 10256
524     for (c=0; c<16; c++) {
525 zmatsuo 10274 int idx = index256[c];
526 zmatsuo 10256 GetNthNum(Buff, c * 3 + 3, &r);
527     GetNthNum(Buff, c * 3 + 4, &g);
528     GetNthNum(Buff, c * 3 + 5, &b);
529 zmatsuo 10274 color->color[idx] = RGB(r, g, b);
530 zmatsuo 10256 }
531     }
532    
533 zmatsuo 10332 static void ReadColorSetting(const wchar_t *section, TColorSetting *color, const wchar_t *key, const wchar_t *fn)
534 zmatsuo 10256 {
535 zmatsuo 10332 wchar_t BuffW[512];
536 zmatsuo 10256 char Buff[512];
537     int c, r, g, b;
538    
539 zmatsuo 10332 GetPrivateProfileStringW(section, key, L"0", BuffW, _countof(BuffW), fn);
540     WideCharToACP_t(BuffW, Buff, _countof(Buff));
541 zmatsuo 10256
542     GetNthNum(Buff, 1, &c);
543     color->change = c;
544    
545     GetNthNum(Buff, 2, &c);
546     color->enable = c;
547    
548     if (color->change && color->enable) {
549     GetNthNum(Buff, 3, &r);
550     GetNthNum(Buff, 4, &g);
551     GetNthNum(Buff, 5, &b);
552     color->fg = RGB(r, g, b);
553    
554     GetNthNum(Buff, 6, &r);
555     GetNthNum(Buff, 7, &g);
556     GetNthNum(Buff, 8, &b);
557     color->bg = RGB(r, g, b);
558     }
559     }
560    
561 zmatsuo 10303 /**
562     * �J���[�e�[�}�v���O�C���� ini �t�@�C����������
563 zmatsuo 10256 */
564 zmatsuo 10303 static void LoadColorPlugin(const wchar_t *fn, TColorTheme *color_theme)
565 zmatsuo 10256 {
566 zmatsuo 10332 const wchar_t *section = COLOR_THEME_SECTION;
567 zmatsuo 10303 wchar_t *name;
568     hGetPrivateProfileStringW(section, L"Theme", NULL, fn, &name);
569     wcscpy_s(color_theme->name, _countof(color_theme->name), name);
570     free(name);
571 zmatsuo 10256
572 zmatsuo 10332 for (int i = 0; i < _countof(color_attr_list); i++) {
573     const wchar_t *key = color_attr_list[i].key;
574     TColorSetting *color = (TColorSetting *)((UINT_PTR)color_theme + color_attr_list[i].offset);
575     ReadColorSetting(section, color, key, fn);
576     }
577 zmatsuo 10256
578 zmatsuo 10332 ReadANSIColorSetting(section, &(color_theme->ansicolor), fn);
579 zmatsuo 10256 }
580    
581 zmatsuo 10303 /**
582     * �J���[�e�[�}�t�@�C����������,1�A�g���r���[�g��
583     */
584     static void LoadColorAttr(const wchar_t *section, const wchar_t *key, const wchar_t *file, TColorSetting *attr)
585 zmatsuo 10256 {
586 zmatsuo 10303 wchar_t *str;
587     DWORD e = hGetPrivateProfileStringW(section, key, NULL, file, &str);
588     if (e != 0 || *str == 0) {
589     free(str);
590     return;
591     }
592 zmatsuo 10256
593 zmatsuo 10303 BOOL change = FALSE;
594     BOOL enable = FALSE;
595     int fields;
596 zmatsuo 10256
597 zmatsuo 10303 DWORD fore_rgb;
598     DWORD back_rgb;
599     fields = swscanf_s(str, L"%d, %d, #%06x, #%06x", &change, &enable, &fore_rgb, &back_rgb);
600     if (fields == 4) {
601     free(str);
602     attr->change = change;
603     attr->enable = enable;
604     attr->fg = RGB((fore_rgb & 0xff0000) >> 16, (fore_rgb & 0x00ff00) >> 8, (fore_rgb & 0x0000ff));
605     attr->bg = RGB((back_rgb & 0xff0000) >> 16, (back_rgb & 0x00ff00) >> 8, (back_rgb & 0x0000ff));
606     return;
607     }
608 zmatsuo 10256
609 zmatsuo 10303 BYTE fg_red, fg_green, fg_blue;
610     BYTE bg_red, bg_green, bg_blue;
611     fields = swscanf_s(str, L"%d, %d, %hhu, %hhu, %hhu, %hhu, %hhu, %hhu", &change, &enable, &fg_red, &fg_green,
612     &fg_blue, &bg_red, &bg_green, &bg_blue);
613     if (fields == 8) {
614     free(str);
615     attr->change = change;
616     attr->enable = enable;
617     attr->fg = RGB(fg_red, fg_green, fg_blue);
618     attr->bg = RGB(bg_red, bg_green, bg_blue);
619     return;
620 zmatsuo 10256 }
621 zmatsuo 10303 fields = swscanf_s(str, L"%d, %d", &change, &enable);
622     if (fields == 2) {
623     free(str);
624     attr->change = change;
625     attr->enable = FALSE; // �F�w���������������������A���������������F������
626     return;
627     }
628     fields = swscanf_s(str, L"%d", &change);
629     free(str);
630     if (fields == 1) {
631     attr->change = FALSE; // �F���X��������
632     return;
633     }
634 zmatsuo 10256 }
635    
636 zmatsuo 10303 /*
637     * color theme�p���[�h
638     */
639     static void ThemeLoadColorDraft(const wchar_t *file, TColorTheme *theme)
640 zmatsuo 10256 {
641 zmatsuo 10332 const wchar_t *section = COLOR_THEME_SECTION;
642 zmatsuo 10256
643 zmatsuo 10303 wchar_t *name;
644     hGetPrivateProfileStringW(section, L"Theme", NULL, file, &name);
645     wcscpy_s(theme->name, _countof(theme->name), name);
646     free(name);
647 zmatsuo 10256
648 zmatsuo 10332 for (int i = 0; i < _countof(color_attr_list); i++) {
649     const wchar_t *key = color_attr_list[i].key;
650     TColorSetting *color = (TColorSetting *)((UINT_PTR)theme + color_attr_list[i].offset);
651     LoadColorAttr(section, key, file, color);
652 zmatsuo 10303 }
653 zmatsuo 10256
654 zmatsuo 10303 theme->ansicolor.change = (BOOL)GetPrivateProfileIntW(section, L"ANSIColor", 1, file);
655     for (int i = 0; i < _countof(ansi_list); i++) {
656     const int index = ansi_list[i].index;
657     const wchar_t *key = ansi_list[i].key;
658     theme->ansicolor.color[index] = LoadColorOneANSI(section, key, file, theme->ansicolor.color[index]);
659     }
660 zmatsuo 10256 }
661    
662 zmatsuo 10303 /*
663     * �J���[�e�[�}ini�t�@�C�������[�h����
664 zmatsuo 10256 */
665 zmatsuo 10303 void ThemeLoadColor(const wchar_t *fn, TColorTheme *color_theme)
666 zmatsuo 10256 {
667 zmatsuo 10303 ThemeGetColorDefault(color_theme);
668     LoadColorPlugin(fn, color_theme);
669     ThemeLoadColorOld(fn, color_theme);
670     ThemeLoadColorDraft(fn, color_theme);
671 zmatsuo 10256 }
672    
673     /**
674     * �e�[�}�t�@�C������������
675     *
676     * @param file �t�@�C����
677     * NULL�������\�������f�t�H���g�l������������
678     * @param bg_theme
679     * @param color_theme
680     */
681     void ThemeLoad(const wchar_t *file, BGTheme *bg_theme, TColorTheme *color_theme)
682     {
683     BOOL bg = FALSE;
684     BOOL color = FALSE;
685     wchar_t *prevDir;
686    
687     // �J�����g�f�B���N�g��������
688     hGetCurrentDirectoryW(&prevDir);
689    
690     // �e�[�}�t�@�C���������f�B���N�g���������I������
691     // �e�[�}�t�@�C�������p�X����������������
692     if (file != NULL) {
693     wchar_t *dir = ExtractDirNameW(file);
694     SetCurrentDirectoryW(dir);
695     free(dir);
696     }
697    
698     {
699     wchar_t sections[128];
700     size_t i;
701     GetPrivateProfileSectionNamesW(sections, _countof(sections), file);
702     for(i = 0; i < _countof(sections); /**/ ) {
703     const wchar_t *p = &sections[i];
704     size_t len = wcslen(p);
705     if (len == 0) {
706     break;
707     }
708 zmatsuo 10332 if (_wcsicmp(p, BG_SECTION_NEW) == 0 || _wcsicmp(p, BG_SECTION_OLD) == 0) {
709 zmatsuo 10256 bg = TRUE;
710     }
711 zmatsuo 10332 else if(_wcsicmp(p, COLOR_THEME_SECTION) == 0) {
712 zmatsuo 10256 color = TRUE;
713     }
714     i += len;
715     }
716     }
717    
718     ThemeGetBGDefault(bg_theme);
719     ThemeGetColorDefault(color_theme);
720    
721     // BG + �J���[�e�[�} ini�t�@�C��
722     if (bg && color) {
723     ThemeLoadBG(file, bg_theme);
724     ThemeLoadColor(file, color_theme);
725     }
726     // BG�e�[�} ini�t�@�C��
727     // TODO �������J���[��������������������������
728     else if (bg) {
729     ThemeLoadBG(file, bg_theme);
730     ThemeLoadColorOld(file, color_theme);
731     }
732     // �J���[�e�[�} ini�t�@�C��
733     else if (color) {
734     ThemeLoadColor(file, color_theme);
735     }
736     else {
737     #if 0
738     static const TTMessageBoxInfoW info = {
739     "Tera Term",
740     "MSG_TT_ERROR", L"Tera Term: ERROR",
741     NULL, L"unknown ini file?",
742     MB_OK|MB_ICONEXCLAMATION
743     };
744     TTMessageBoxW(HVTWin, &info, ts.UILanguageFileW);
745     #endif
746     }
747    
748     // �J�����g�t�H���_����������
749     SetCurrentDirectoryW(prevDir);
750     free(prevDir);
751     }

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