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 10274 - (hide annotations) (download) (as text)
Sun Sep 18 16:07:06 2022 UTC (18 months, 3 weeks ago) by zmatsuo
Original Path: trunk/teraterm/teraterm/themefile.cpp
File MIME type: text/x-c++src
File size: 20971 byte(s)
描画部分(vtdisp.c内)のカラーテーブルをANSI color 256色と同じ並びにした

- 従来は[0-7]が明るい原色8色,[8-15]が暗い色8色で、入れ替わっていた
- tera Tera Term Pro 2.3.ini の誤り修正

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

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