Rev 8572 | Rev 9263 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 8572 | Rev 9103 | ||
---|---|---|---|
1 | #include "TWB\colors.h" |
1 | #include "TWB\colors.h" |
2 | #include "TWB\anchors.h" |
2 | #include "TWB\anchors.h" |
3 | #include "TWB\parse_tag.h" |
3 | #include "TWB\parse_tag.h" |
4 | #include "TWB\special.h" |
4 | #include "TWB\special.h" |
5 | #include "TWB\tag_list.h" |
5 | #include "TWB\tag_list.h" |
6 | #define DEFAULT_BG_COL 0xffEBE8E9; |
6 | #define DEFAULT_BG_COL 0xffEBE8E9; |
7 | dword link_color_default; |
7 | dword link_color_default; |
8 | dword link_color_active; |
8 | dword link_color_active; |
9 | #include "TWB\links.h" |
9 | #include "TWB\links.h" |
10 | 10 | ||
11 | #define BODY_MARGIN 6 |
11 | #define BODY_MARGIN 6 |
12 | #define BASIC_CHAR_W 8 |
12 | #define BASIC_CHAR_W 8 |
13 | #define BASIC_LINE_H 18 |
13 | #define BASIC_LINE_H 18 |
14 | 14 | ||
15 | struct STYLE { |
15 | struct STYLE { |
16 | bool |
16 | bool |
17 | b, u, s, h, |
17 | b, u, s, h, |
18 | font, |
18 | font, |
19 | pre, |
19 | pre, |
20 | blq, |
20 | blq, |
21 | button, |
21 | button, |
22 | image; |
22 | image; |
23 | LIST tag_list; |
23 | LIST tag_list; |
24 | dword title; |
24 | dword title; |
25 | dword cur_line_h; |
25 | dword cur_line_h; |
26 | void reset(); |
26 | void reset(); |
27 | }; |
27 | }; |
28 | 28 | ||
29 | void STYLE::reset() |
29 | void STYLE::reset() |
30 | { |
30 | { |
31 | b = u = s = h = blq = pre = title = false; |
31 | b = u = s = h = blq = pre = title = false; |
32 | font = false; |
32 | font = false; |
33 | cur_line_h = NULL; |
33 | cur_line_h = NULL; |
34 | tag_list.reset(); |
34 | tag_list.reset(); |
35 | } |
35 | } |
36 | 36 | ||
37 | struct TWebBrowser { |
37 | struct TWebBrowser { |
38 | llist list; |
38 | llist list; |
39 | STYLE style; |
39 | STYLE style; |
40 | dword draw_y, draw_x, draw_w, left_gap; |
40 | dword draw_y, draw_x, draw_w, left_gap; |
41 | dword o_bufpointer; |
41 | dword o_bufpointer; |
42 | int cur_encoding, custom_encoding; |
42 | int cur_encoding, custom_encoding; |
43 | bool link, t_html, t_body; |
43 | bool link, t_html, t_body; |
44 | dword bufpointer; |
44 | dword bufpointer; |
45 | dword bufsize; |
45 | dword bufsize; |
46 | dword is_html; |
46 | dword is_html; |
47 | collection img_url; |
47 | collection img_url; |
48 | char header[150]; |
48 | char header[150]; |
49 | char linebuf[500]; |
49 | char linebuf[500]; |
50 | char redirect[URL_SIZE]; |
50 | char redirect[URL_SIZE]; |
- | 51 | ||
- | 52 | bool secondrun; |
|
51 | 53 | ||
52 | void SetStyle(); |
54 | void SetStyle(); |
53 | void RenderTextbuf(); |
55 | void RenderTextbuf(); |
54 | void RenderLine(); |
56 | void RenderLine(); |
55 | bool RenderImage(); |
57 | bool RenderImage(); |
56 | 58 | ||
57 | void SetPageDefaults(); |
59 | void SetPageDefaults(); |
58 | void ParseHtml(); |
60 | void ParseHtml(); |
59 | void Reparse(); |
61 | void Reparse(); |
60 | void NewLine(); |
62 | void NewLine(); |
61 | void ChangeEncoding(); |
63 | void ChangeEncoding(); |
62 | void AddCharToTheLine(); |
64 | void AddCharToTheLine(); |
63 | void DrawPage(); |
65 | void DrawPage(); |
64 | 66 | ||
65 | void tag_a(); |
67 | void tag_a(); |
66 | void tag_p(); |
68 | void tag_p(); |
67 | void tag_img(); |
69 | void tag_img(); |
68 | void tag_div(); |
70 | void tag_div(); |
69 | void tag_h1234_caption(); |
71 | void tag_h1234_caption(); |
70 | void tag_ol_ul_dt(); |
72 | void tag_ol_ul_dt(); |
71 | void tag_li(); |
73 | void tag_li(); |
72 | void tag_q(); |
74 | void tag_q(); |
73 | void tag_hr(); |
75 | void tag_hr(); |
74 | void tag_code(); |
76 | void tag_code(); |
75 | void tag_meta_xml(); |
77 | void tag_meta_xml(); |
76 | void tag_body(); |
78 | void tag_body(); |
77 | void tag_iframe(); |
79 | void tag_iframe(); |
78 | void tag_title(); |
80 | void tag_title(); |
79 | void tag_font(); |
81 | void tag_font(); |
80 | void tag_table_reset(); |
82 | void tag_table_reset(); |
81 | void tag_table(); |
83 | void tag_table(); |
82 | void tag_td(); |
84 | void tag_td(); |
83 | void tag_tr(); |
85 | void tag_tr(); |
84 | }; |
86 | }; |
85 | 87 | ||
86 | #include "TWB\render.h" |
88 | #include "TWB\render.h" |
87 | #include "TWB\set_style.h" |
89 | #include "TWB\set_style.h" |
88 | //============================================================================================ |
90 | //============================================================================================ |
89 | void TWebBrowser::SetPageDefaults() |
91 | void TWebBrowser::SetPageDefaults() |
90 | { |
92 | { |
91 | t_html = t_body = link = false; |
93 | t_html = t_body = link = false; |
92 | style.reset(); |
94 | style.reset(); |
93 | link_color_default = 0x0000FF; |
95 | link_color_default = 0x0000FF; |
94 | link_color_active = 0xFF0000; |
96 | link_color_active = 0xFF0000; |
95 | style.cur_line_h = list.item_h; |
97 | style.cur_line_h = list.item_h; |
96 | links.clear(); |
98 | links.clear(); |
97 | anchors.clear(); |
99 | anchors.clear(); |
98 | img_url.drop(); |
100 | img_url.drop(); |
99 | text_colors.drop(); |
101 | text_colors.drop(); |
100 | text_colors.add(0); |
102 | text_colors.add(0); |
101 | bg_colors.drop(); |
103 | bg_colors.drop(); |
102 | bg_colors.add(DEFAULT_BG_COL); |
104 | bg_colors.add(DEFAULT_BG_COL); |
103 | canvas.Fill(0, DEFAULT_BG_COL); |
105 | canvas.Fill(0, DEFAULT_BG_COL); |
104 | header = NULL; |
106 | header = NULL; |
105 | draw_y = BODY_MARGIN; |
107 | draw_y = BODY_MARGIN; |
106 | draw_x = left_gap = BODY_MARGIN; |
108 | draw_x = left_gap = BODY_MARGIN; |
107 | draw_w = list.w - BODY_MARGIN; |
109 | draw_w = list.w - BODY_MARGIN; |
108 | linebuf = 0; |
110 | linebuf = 0; |
109 | redirect = '\0'; |
111 | redirect = '\0'; |
110 | list.SetFont(8, 14, 10011000b); |
112 | list.SetFont(8, 14, 10011000b); |
111 | tag_table_reset(); |
113 | tag_table_reset(); |
- | 114 | is_html = true; |
|
- | 115 | if (!strstri(bufpointer, " |
|
- | 116 | t_body = true; |
|
- | 117 | if (!strstri(bufpointer, " |
|
- | 118 | && (!strstr(bufpointer, " |
|
- | 119 | style.pre = true; //show linebreaks for a plaint text |
|
- | 120 | is_html = false; |
|
- | 121 | } |
|
- | 122 | } |
|
112 | } |
123 | } |
113 | //============================================================================================ |
124 | //============================================================================================ |
114 | void TWebBrowser::Reparse() |
125 | void TWebBrowser::Reparse() |
115 | { |
126 | { |
116 | ParseHtml(bufpointer, bufsize); |
127 | ParseHtml(bufpointer, bufsize); |
117 | } |
128 | } |
118 | //============================================================================================ |
129 | //============================================================================================ |
119 | void TWebBrowser::ParseHtml(dword _bufpointer, _bufsize){ |
130 | void TWebBrowser::ParseHtml(dword _bufpointer, _bufsize){ |
120 | int tab_len; |
131 | int tab_len; |
121 | dword bufpos; |
132 | dword bufpos; |
122 | bufsize = _bufsize; |
133 | bufsize = _bufsize; |
123 | 134 | ||
124 | if (list.w!=canvas.bufw) canvas.Init(list.x, list.y, list.w, 400*20); |
135 | if (list.w!=canvas.bufw) canvas.Init(list.x, list.y, list.w, 400*20); |
125 | 136 | ||
126 | if (bufpointer == _bufpointer) { |
137 | if (bufpointer == _bufpointer) { |
127 | custom_encoding = cur_encoding; |
138 | custom_encoding = cur_encoding; |
128 | } else { |
139 | } else { |
129 | bufpointer = malloc(bufsize); |
140 | bufpointer = malloc(bufsize); |
130 | memmov(bufpointer, _bufpointer, bufsize); |
141 | memmov(bufpointer, _bufpointer, bufsize); |
131 | 142 | ||
132 | //hold original buffer |
143 | //hold original buffer |
133 | o_bufpointer = malloc(bufsize); |
144 | o_bufpointer = malloc(bufsize); |
134 | memmov(o_bufpointer, bufpointer, bufsize); |
145 | memmov(o_bufpointer, bufpointer, bufsize); |
135 | 146 | ||
136 | cur_encoding = CH_CP866; |
147 | cur_encoding = CH_CP866; |
137 | if (custom_encoding != -1) { |
148 | if (custom_encoding != -1) { |
138 | cur_encoding = custom_encoding; |
149 | cur_encoding = custom_encoding; |
139 | bufpointer = ChangeCharset(cur_encoding, "CP866", bufpointer); |
150 | bufpointer = ChangeCharset(cur_encoding, "CP866", bufpointer); |
140 | bufsize = strlen(bufpointer); |
151 | bufsize = strlen(bufpointer); |
141 | } |
152 | } |
142 | } |
153 | } |
143 | 154 | ||
- | 155 | ||
- | 156 | tr_col_count.drop(); |
|
- | 157 | secondrun = false; |
|
- | 158 | ||
- | 159 | _PARSE_START_: |
|
144 | 160 | ||
145 | SetPageDefaults(); |
- | |
146 | is_html = true; |
- | |
147 | if (!strstri(bufpointer, " |
- | |
148 | t_body = true; |
- | |
149 | if (!strstri(bufpointer, " |
- | |
150 | && (!strstr(bufpointer, " |
- | |
151 | style.pre = true; //show linebreaks for a plaint text |
- | |
152 | is_html = false; |
- | |
153 | } |
- | |
154 | } |
161 | SetPageDefaults(); |
155 | for (bufpos=bufpointer ; (bufpos < bufpointer+bufsize) && (ESBYTE[bufpos]!=0) ; bufpos++;) |
- | |
156 | { |
- | |
157 | switch (ESBYTE[bufpos]) |
162 | for (bufpos=bufpointer; bufpos < bufpointer+bufsize; bufpos++;) |
158 | { |
- | |
159 | case 0x0a: |
163 | { |
- | 164 | if (style.pre) { |
|
160 | if (style.pre) { |
165 | if (ESBYTE[bufpos] == 0x0a) { |
161 | RenderTextbuf(); |
166 | RenderTextbuf(); |
162 | NewLine(); |
- | |
163 | } else { |
167 | NewLine(); |
164 | goto _DEFAULT; |
168 | continue; |
165 | } |
- | |
166 | break; |
- | |
167 | case 0x09: |
169 | } |
168 | if (style.pre) { |
170 | if (ESBYTE[bufpos] == 0x09) { |
169 | tab_len = draw_x - left_gap / list.font_w + strlen(#linebuf) % 4; |
171 | tab_len = draw_x - left_gap / list.font_w + strlen(#linebuf) % 4; |
170 | if (!tab_len) tab_len = 4; else tab_len = 4 - tab_len; |
172 | if (!tab_len) tab_len = 4; else tab_len = 4 - tab_len; |
171 | while (tab_len) {chrcat(#linebuf,' '); tab_len--;} |
173 | while (tab_len) {chrcat(#linebuf,' '); tab_len--;} |
172 | } else { |
174 | continue; |
173 | goto _DEFAULT; |
175 | } |
174 | } |
176 | } |
175 | break; |
- | |
176 | case '&': // and so on |
177 | if (ESBYTE[bufpos] == '&') { |
177 | bufpos = GetUnicodeSymbol(#linebuf, sizeof(TWebBrowser.linebuf), bufpos+1, bufpointer+bufsize); |
178 | bufpos = GetUnicodeSymbol(#linebuf, sizeof(TWebBrowser.linebuf), bufpos+1, bufpointer+bufsize); |
178 | break; |
179 | continue; |
179 | case '<': |
180 | } |
180 | if (!is_html) goto _DEFAULT; |
181 | if (ESBYTE[bufpos] == '<') && (is_html) { |
181 | if (!strchr("!/?abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ", ESBYTE[bufpos+1])) goto _DEFAULT; |
182 | if (strchr("!/?abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ", ESBYTE[bufpos+1])) { |
182 | bufpos++; |
183 | bufpos++; |
183 | if (tag.parse(#bufpos, bufpointer + bufsize)) { |
184 | if (tag.parse(#bufpos, bufpointer + bufsize)) { |
- | 185 | ||
- | 186 | /* |
|
- | 187 | if (secondrun) |
|
- | 188 | { |
|
- | 189 | if (streq(#tag.name, "tr")) debugln(" "); |
|
- | 190 | if (!tag.opened) { |
|
- | 191 | debugch('/'); |
|
- | 192 | } else { |
|
- | 193 | debugch(' '); |
|
- | 194 | } |
|
- | 195 | debugln(sprintf(#param, "%s x%i y%i %s", |
|
- | 196 | #tag.name, draw_x, draw_y, #linebuf)); |
|
- | 197 | } |
|
- | 198 | //*/ |
|
- | 199 | ||
184 | RenderTextbuf(); |
200 | RenderTextbuf(); |
185 | $push cur_encoding |
201 | $push cur_encoding |
186 | SetStyle(); |
202 | SetStyle(); |
187 | $pop eax |
203 | $pop eax |
188 | // The thing is that UTF if longer than other encodings. |
204 | // The thing is that UTF if longer than other encodings. |
189 | // So if encoding was changed from UTF to DOS than $bufpos position got wrong, |
205 | // So if encoding was changed from UTF to DOS than $bufpos position got wrong, |
190 | // and we have to start parse from the very beginning |
206 | // and we have to start parse from the very beginning |
191 | if (EAX != cur_encoding) && (cur_encoding == CH_UTF8) { |
207 | if (EAX != cur_encoding) && (cur_encoding == CH_UTF8) { |
192 | ParseHtml(bufpointer, strlen(bufpointer)); |
208 | ParseHtml(bufpointer, strlen(bufpointer)); |
193 | return; |
209 | return; |
194 | } |
210 | } |
195 | } |
211 | } |
196 | break; |
212 | continue; |
197 | default: |
213 | } |
198 | _DEFAULT: |
214 | } |
199 | AddCharToTheLine(ESBYTE[bufpos]); |
215 | AddCharToTheLine(ESBYTE[bufpos]); |
200 | } |
216 | } |
- | 217 | ||
- | 218 | if (!secondrun) { |
|
- | 219 | secondrun = true; |
|
- | 220 | goto _PARSE_START_; |
|
201 | } |
221 | } |
- | 222 | ||
202 | RenderTextbuf(); |
223 | RenderTextbuf(); |
203 | list.count = draw_y + style.cur_line_h; |
224 | list.count = draw_y + style.cur_line_h; |
204 | 225 | ||
205 | canvas.bufh = math.max(list.visible, list.count); |
226 | canvas.bufh = math.max(list.visible, list.count); |
206 | buf_data = realloc(buf_data, canvas.bufh * canvas.bufw * 4 + 8); |
227 | buf_data = realloc(buf_data, canvas.bufh * canvas.bufw * 4 + 8); |
207 | 228 | ||
208 | list.CheckDoesValuesOkey(); |
229 | list.CheckDoesValuesOkey(); |
209 | anchors.current = NULL; |
230 | anchors.current = NULL; |
210 | if (!header) { |
231 | if (!header) { |
211 | strncpy(#header, #version, sizeof(TWebBrowser.header)-1); |
232 | strncpy(#header, #version, sizeof(TWebBrowser.header)-1); |
212 | DrawTitle(#header); |
233 | DrawTitle(#header); |
213 | } |
234 | } |
214 | } |
235 | } |
215 | //============================================================================================ |
236 | //============================================================================================ |
216 | void TWebBrowser::AddCharToTheLine(unsigned char _char) |
237 | void TWebBrowser::AddCharToTheLine(unsigned char _char) |
217 | { |
238 | { |
218 | dword line_len = strlen(#linebuf); |
239 | dword line_len = strlen(#linebuf); |
219 | if (_char<=15) _char=' '; |
240 | if (_char<=15) _char=' '; |
220 | if (!style.pre) && (_char == ' ') |
241 | if (!style.pre) && (_char == ' ') |
221 | { |
242 | { |
222 | if (linebuf[line_len-1]==' ') return; //no double spaces |
243 | if (linebuf[line_len-1]==' ') return; //no double spaces |
223 | if (draw_x==left_gap) && (!linebuf) return; //no paces at the beginning of the line |
244 | if (draw_x==left_gap) && (!linebuf) return; //no paces at the beginning of the line |
224 | if (link) && (line_len==0) return; |
245 | if (link) && (line_len==0) return; |
225 | } |
246 | } |
226 | if (line_len < sizeof(TWebBrowser.linebuf)) { |
247 | if (line_len < sizeof(TWebBrowser.linebuf)) { |
227 | chrcat(#linebuf+line_len, _char); |
248 | chrcat(#linebuf+line_len, _char); |
228 | } else { |
249 | } else { |
229 | RenderTextbuf(); |
250 | RenderTextbuf(); |
230 | } |
251 | } |
231 | } |
252 | } |
232 | //============================================================================================ |
253 | //============================================================================================ |
233 | void TWebBrowser::ChangeEncoding(int _new_encoding) |
254 | void TWebBrowser::ChangeEncoding(int _new_encoding) |
234 | { |
255 | { |
235 | if (cur_encoding == _new_encoding) return; |
256 | if (cur_encoding == _new_encoding) return; |
236 | cur_encoding = _new_encoding; |
257 | cur_encoding = _new_encoding; |
237 | bufpointer = ChangeCharset(cur_encoding, "CP866", bufpointer); |
258 | bufpointer = ChangeCharset(cur_encoding, "CP866", bufpointer); |
238 | if (header) { |
259 | if (header) { |
239 | ChangeCharset(cur_encoding, "CP866", #header); |
260 | ChangeCharset(cur_encoding, "CP866", #header); |
240 | DrawTitle(#header); |
261 | DrawTitle(#header); |
241 | } |
262 | } |
242 | } |
263 | } |
243 | //============================================================================================ |
264 | //============================================================================================ |
244 | scroll_bar scroll_wv = { 15,NULL,NULL,NULL, |
265 | scroll_bar scroll_wv = { 15,NULL,NULL,NULL, |
245 | 0,2,NULL,0,0,0xeeeeee,0xBBBbbb,0xeeeeee}; |
266 | 0,2,NULL,0,0,0xeeeeee,0xBBBbbb,0xeeeeee}; |
246 | 267 | ||
247 | void TWebBrowser::DrawPage() |
268 | void TWebBrowser::DrawPage() |
248 | { |
269 | { |
249 | if (list.w!=canvas.bufw) Reparse(); |
270 | if (list.w!=canvas.bufw) Reparse(); |
250 | canvas.Show(list.first, list.h); |
271 | canvas.Show(list.first, list.h); |
251 | 272 | ||
252 | scroll_wv.max_area = list.count; |
273 | scroll_wv.max_area = list.count; |
253 | scroll_wv.cur_area = list.visible; |
274 | scroll_wv.cur_area = list.visible; |
254 | scroll_wv.position = list.first; |
275 | scroll_wv.position = list.first; |
255 | scroll_wv.all_redraw = 0; |
276 | scroll_wv.all_redraw = 0; |
256 | scroll_wv.start_x = list.x + list.w; |
277 | scroll_wv.start_x = list.x + list.w; |
257 | scroll_wv.start_y = list.y; |
278 | scroll_wv.start_y = list.y; |
258 | scroll_wv.size_y = list.h; |
279 | scroll_wv.size_y = list.h; |
259 | 280 | ||
260 | if (list.count <= list.visible) { |
281 | if (list.count <= list.visible) { |
261 | DrawBar(scroll_wv.start_x, scroll_wv.start_y, scroll_wv.size_x, |
282 | DrawBar(scroll_wv.start_x, scroll_wv.start_y, scroll_wv.size_x, |
262 | scroll_wv.size_y, bg_colors.get(0) & 0x00FFFFFF); |
283 | scroll_wv.size_y, bg_colors.get(0) & 0x00FFFFFF); |
263 | } else { |
284 | } else { |
264 | scrollbar_v_draw(#scroll_wv); |
285 | scrollbar_v_draw(#scroll_wv); |
265 | } |
286 | } |
266 | }=>>=15)>': |
287 | }=>>=15)>')>>?xml"))> |
267 | >>?xml"))> |