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 10303 - (hide annotations) (download) (as text)
Mon Oct 10 04:48:24 2022 UTC (18 months ago) by zmatsuo
Original Path: trunk/teraterm/teraterm/themefile.cpp
File MIME type: text/x-c++src
File size: 23585 byte(s)
カラーテーマファイルのマニュアル追記、読み書きを修正

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

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