-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathColorFile.cpp
More file actions
132 lines (116 loc) · 2.72 KB
/
Copy pathColorFile.cpp
File metadata and controls
132 lines (116 loc) · 2.72 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
// ColorFile.cpp: implementation of the CColorFile class.
//
//////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "ColorFile.h"
#include <no5tl\inifile.h>
LPCTSTR GLOBAL_SECTION = _T("@global");
LPCTSTR COLOR_SECTION = _T("colors");
class CColorFile : public IColorFile
{
NO5TL::CPrivateIniFile m_ini;
typedef CSimpleValArray<int> CIntList;
typedef CSimpleArray<CString> CStringList;
public:
virtual BOOL SetFileName(LPCTSTR pFullPath)
{
return m_ini.Create(pFullPath);
}
virtual BOOL AddColorSet(LPCTSTR name,CColorList &colors)
{
CIntList icolors;
BOOL res;
TransformList(icolors,colors);
res = m_ini.WriteIntList(COLOR_SECTION,name,icolors);
if(res){
AddName(name);
}
return res;
}
virtual BOOL GetColorSet(LPCTSTR name,CColorList &colors)
{
CIntList icolors;
int res;
res = m_ini.GetIntList(COLOR_SECTION,name,icolors);
if(res >= 0){
colors.RemoveAll();
if(res > 0)
TransformList(colors,icolors);
}
return res >= 0;
}
virtual BOOL DeleteColorSet(LPCTSTR name)
{
BOOL res = m_ini.DeleteKey(COLOR_SECTION,name);
if(res){
RemoveName(name);
}
return res;
}
virtual BOOL GetNames(CSimpleArray<CString> &names)
{
int count = m_ini.GetStringList(GLOBAL_SECTION,"names",names);
return count >= 0;
}
private:
void TransformList(CIntList &to,const CColorList &from)
{
const int count = from.GetSize();
int i;
CYahooColor color;
to.RemoveAll();
for(i=0;i<count;i++){
color = from[i];
to.Add((int)(COLORREF)color);
}
}
void TransformList(CColorList &to,const CIntList &from)
{
const int count = from.GetSize();
int i;
CYahooColor color;
to.RemoveAll();
for(i=0;i<count;i++){
color = (COLORREF)(from[i] & 0x00FFFFFF);
to.Add(color);
}
}
void AddName(LPCTSTR name)
{
CSimpleArray<CString> names;
m_ini.GetStringList(GLOBAL_SECTION,"names",names);
if(NO5TL::StringArray_FindNoCase(names,name) < 0){
names.Add(CString(name));
m_ini.WriteStringList("@global","names",names);
}
}
void RemoveName(LPCTSTR name)
{
CSimpleArray<CString> names;
int index;
m_ini.GetStringList(GLOBAL_SECTION,"names",names);
index = NO5TL::StringArray_FindNoCase(names,name);
if(index >=0){
names.RemoveAt(index);
m_ini.WriteStringList("@global","names",names);
}
}
};
BOOL ColorFileCreate(IColorFile **pp)
{
BOOL res = FALSE;
CColorFile *pObj = new CColorFile();
if(pObj){
*pp = (IColorFile *)pObj;
res = TRUE;
}
return res;
}
void ColorFileDestroy(IColorFile **pp)
{
CColorFile *pObj = (CColorFile *)(*pp);
if(pObj){
delete pObj;
*pp = NULL;
}
}