1 #include "CodeEditor.h"
2
3 namespace Upp {
4
5 HlStyle HighlightSetup::hl_style[HL_COUNT];
6 byte HighlightSetup::hilite_scope = 0;
7 byte HighlightSetup::hilite_ifdef = 1;
8 byte HighlightSetup::hilite_bracket = 1;
9 bool HighlightSetup::thousands_separator = true;
10
11 bool HighlightSetup::indent_spaces = false;
12 bool HighlightSetup::no_parenthesis_indent = false;
13 int HighlightSetup::indent_amount = 4;
14
15 #define HL_COLOR(x, a, b) #x,
16 static const char *s_hl_color[] = {
17 #include "hl_color.i"
18 };
19 #undef HL_COLOR
20
21 #define HL_COLOR(a, x, b) x,
22 static const char *s_hl_name[] = {
23 #include "hl_color.i"
24 };
25 #undef HL_COLOR
26
27 #define HL_COLOR(a, b, x) x,
28 static bool s_hl_font[] = {
29 #include "hl_color.i"
30 };
31 #undef HL_COLOR
32
GetHlStyle(int i)33 const HlStyle& HighlightSetup::GetHlStyle(int i)
34 {
35 return hl_style[i];
36 }
37
GetHlName(int i)38 const char *HighlightSetup::GetHlName(int i)
39 {
40 return s_hl_name[i];
41 }
42
HasHlFont(int i)43 bool HighlightSetup::HasHlFont(int i)
44 {
45 return s_hl_font[i];
46 }
47
SetHlStyle(int i,Color c,bool bold,bool italic,bool underline)48 void HighlightSetup::SetHlStyle(int i, Color c, bool bold, bool italic, bool underline)
49 {
50 HlStyle& st = hl_style[i];
51 st.color = c;
52 st.bold = bold;
53 st.italic = italic;
54 st.underline = underline;
55 }
56
LoadHlStyles(const char * s)57 void HighlightSetup::LoadHlStyles(const char *s)
58 {
59 CParser p(s);
60 try {
61 while(!p.IsEof()) {
62 String id = p.ReadId();
63 Color c = ReadColor(p);
64 bool bold = false;
65 bool italic = false;
66 bool underline = false;
67 for(;;)
68 if(p.Id("bold"))
69 bold = true;
70 else
71 if(p.Id("italic"))
72 italic = true;
73 else
74 if(p.Id("underline"))
75 underline = true;
76 else
77 break;
78 for(int i = 0; i < HL_COUNT; i++)
79 if(id == s_hl_color[i]) {
80 SetHlStyle(i, c, bold, italic, underline);
81 break;
82 }
83 p.PassChar(';');
84 }
85 }
86 catch(CParser::Error) {
87 DefaultHlStyles();
88 }
89 }
90
StoreHlStyles()91 String HighlightSetup::StoreHlStyles()
92 {
93 String r;
94 for(int i = 0; i < HL_COUNT; i++) {
95 const HlStyle& s = GetHlStyle(i);
96 r << Format("%-25s", s_hl_color[i]) << ' ' << FormatColor(s.color);
97 if(s.bold)
98 r << " bold";
99 if(s.italic)
100 r << " italic";
101 if(s.underline)
102 r << " underline";
103 r << ";\r\n";
104 }
105 return r;
106 }
107
DarkTheme()108 void HighlightSetup::DarkTheme()
109 {
110 SetHlStyle(INK_NORMAL, White);
111 SetHlStyle(PAPER_NORMAL, Color(1, 1, 1));
112 SetHlStyle(INK_SELECTED, Color(1, 1, 1));
113 SetHlStyle(PAPER_SELECTED, Color(97, 217, 255));
114 SetHlStyle(INK_DISABLED, Color(184, 184, 184));
115 SetHlStyle(PAPER_READONLY, Color(24, 24, 24));
116 SetHlStyle(INK_COMMENT, Color(173, 255, 173), false, true);
117 SetHlStyle(INK_COMMENT_WORD, Color(235, 235, 255), true, true);
118 SetHlStyle(PAPER_COMMENT_WORD, Color(99, 99, 0));
119 SetHlStyle(INK_CONST_STRING, Color(248, 162, 162));
120 SetHlStyle(INK_CONST_STRINGOP, Color(214, 214, 255));
121 SetHlStyle(INK_RAW_STRING, Color(235, 235, 255));
122 SetHlStyle(INK_OPERATOR, Color(214, 214, 255));
123 SetHlStyle(INK_KEYWORD, Color(214, 214, 255), true);
124 SetHlStyle(INK_UPP, Color(108, 236, 236));
125 SetHlStyle(PAPER_LNG, Color(13, 13, 0));
126 SetHlStyle(INK_ERROR, Color(255, 185, 185));
127 SetHlStyle(INK_PAR0, White);
128 SetHlStyle(INK_PAR1, Color(173, 255, 173));
129 SetHlStyle(INK_PAR2, Color(255, 149, 255));
130 SetHlStyle(INK_PAR3, Color(214, 214, 86));
131 SetHlStyle(INK_CONST_INT, Color(255, 137, 137));
132 SetHlStyle(INK_CONST_FLOAT, Color(255, 149, 255));
133 SetHlStyle(INK_CONST_HEX, Color(235, 235, 255));
134 SetHlStyle(INK_CONST_OCT, Color(235, 235, 255));
135 SetHlStyle(PAPER_BRACKET0, Color(26, 26, 0));
136 SetHlStyle(PAPER_BRACKET, Color(99, 99, 0), true);
137 SetHlStyle(PAPER_BLOCK1, Color(16, 16, 31));
138 SetHlStyle(PAPER_BLOCK2, Color(5, 20, 5));
139 SetHlStyle(PAPER_BLOCK3, Color(3, 3, 0));
140 SetHlStyle(PAPER_BLOCK4, Color(20, 5, 20));
141 SetHlStyle(INK_MACRO, Color(255, 149, 255));
142 SetHlStyle(PAPER_MACRO, Color(11, 11, 0));
143 SetHlStyle(PAPER_IFDEF, Color(0, 18, 18));
144 SetHlStyle(INK_IFDEF, Color(131, 131, 131));
145 SetHlStyle(INK_UPPER, White);
146 SetHlStyle(INK_SQLBASE, White);
147 SetHlStyle(INK_SQLFUNC, White);
148 SetHlStyle(INK_SQLBOOL, White);
149 SetHlStyle(INK_UPPMACROS, Color(108, 236, 236));
150 SetHlStyle(INK_UPPLOGS, Color(173, 255, 173));
151 SetHlStyle(INK_DIFF_FILE_INFO, White, true);
152 SetHlStyle(INK_DIFF_HEADER, Color(103, 202, 255));
153 SetHlStyle(INK_DIFF_ADDED, Color(182, 196, 255));
154 SetHlStyle(INK_DIFF_REMOVED, Color(255, 185, 185));
155 SetHlStyle(INK_DIFF_COMMENT, Color(173, 255, 173));
156 SetHlStyle(PAPER_SELWORD, Color(99, 99, 0));
157 SetHlStyle(PAPER_ERROR, Color(90, 40, 40));
158 SetHlStyle(PAPER_WARNING, Color(21, 21, 0));
159 SetHlStyle(SHOW_LINE, Color(27, 75, 26));
160 SetHlStyle(SHOW_COLUMN, Color(56, 33, 29));
161 SetHlStyle(WHITESPACE, Color(68, 128, 176));
162 SetHlStyle(WARN_WHITESPACE, Color(206, 141, 141));
163 }
164
WhiteTheme()165 void HighlightSetup::WhiteTheme()
166 {
167 SetHlStyle(INK_COMMENT, Green, false, true);
168 SetHlStyle(PAPER_COMMENT_WORD, Yellow, false, false);
169 SetHlStyle(INK_COMMENT_WORD, Blue, true, true);
170 SetHlStyle(INK_CONST_STRING, Red);
171 SetHlStyle(INK_RAW_STRING, Blue);
172 SetHlStyle(INK_CONST_STRINGOP, LtBlue);
173 SetHlStyle(INK_CONST_INT, Red);
174 SetHlStyle(INK_CONST_FLOAT, Magenta);
175 SetHlStyle(INK_CONST_HEX, Blue);
176 SetHlStyle(INK_CONST_OCT, Blue);
177
178 SetHlStyle(INK_OPERATOR, LtBlue);
179 SetHlStyle(INK_KEYWORD, LtBlue, true);
180 SetHlStyle(INK_UPP, Cyan);
181 SetHlStyle(PAPER_LNG, Color(255, 255, 224));
182 SetHlStyle(INK_ERROR, LtRed);
183 SetHlStyle(INK_PAR0, Black);
184 SetHlStyle(INK_PAR1, Green);
185 SetHlStyle(INK_PAR2, Magenta);
186 SetHlStyle(INK_PAR3, Brown);
187
188 SetHlStyle(INK_UPPER, Black);
189 SetHlStyle(INK_SQLBASE, Black);
190 SetHlStyle(INK_SQLFUNC, Black);
191 SetHlStyle(INK_SQLBOOL, Black);
192 SetHlStyle(INK_UPPMACROS, Cyan);
193 SetHlStyle(INK_UPPLOGS, Green);
194
195 SetHlStyle(INK_DIFF_FILE_INFO, Black, true);
196 SetHlStyle(INK_DIFF_HEADER, Color(28, 127, 200));
197 SetHlStyle(INK_DIFF_ADDED, Color(28, 42, 255));
198 SetHlStyle(INK_DIFF_REMOVED, Color(255, 0, 0));
199 SetHlStyle(INK_DIFF_COMMENT, Green);
200
201 SetHlStyle(PAPER_BLOCK1, Blend(LtBlue, White, 240));
202 SetHlStyle(PAPER_BLOCK2, Blend(LtGreen, White, 240));
203 SetHlStyle(PAPER_BLOCK3, Blend(LtYellow, White, 240));
204 SetHlStyle(PAPER_BLOCK4, Blend(LtMagenta, White, 240));
205
206 SetHlStyle(INK_MACRO, Magenta);
207 SetHlStyle(PAPER_MACRO, Color(255, 255, 230));
208 SetHlStyle(PAPER_IFDEF, Color(230, 255, 255));
209 SetHlStyle(INK_IFDEF, Color(170, 170, 170));
210
211 SetHlStyle(PAPER_BRACKET0, LtYellow);
212 SetHlStyle(PAPER_BRACKET, Yellow, true);
213
214 SetHlStyle(INK_NORMAL, SColorText);
215 SetHlStyle(INK_DISABLED, SColorDisabled);
216 SetHlStyle(INK_SELECTED, SColorHighlightText);
217 SetHlStyle(PAPER_NORMAL, SColorPaper);
218 SetHlStyle(PAPER_READONLY, SColorFace);
219 SetHlStyle(PAPER_SELECTED, SColorHighlight);
220
221 SetHlStyle(PAPER_SELWORD, Yellow);
222
223 SetHlStyle(PAPER_ERROR, Blend(White(), LtRed(), 50));
224 SetHlStyle(PAPER_WARNING, Blend(White(), Yellow(), 50));
225
226 SetHlStyle(SHOW_LINE, Color(199, 247, 198));
227 SetHlStyle(SHOW_COLUMN, Color(247, 224, 220));
228
229 SetHlStyle(WHITESPACE, Blend(SColorLight, SColorHighlight));
230 SetHlStyle(WARN_WHITESPACE, Blend(SColorLight, SRed));
231 }
232
DefaultHlStyles()233 void HighlightSetup::DefaultHlStyles()
234 {
235 if(IsDarkTheme())
236 DarkTheme();
237 else
238 WhiteTheme();
239 }
240
241 }
242