Rev 7771 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
7752 | leency | 1 | #include "..\TWB\colors.h" |
2 | #include "..\TWB\anchors.h" |
||
7771 | leency | 3 | #include "..\TWB\parse_tag.h" |
7758 | leency | 4 | #include "..\TWB\special.h" |
7757 | leency | 5 | #include "..\TWB\img_cache.h" |
7759 | leency | 6 | #include "..\TWB\tag_list.h" |
7757 | leency | 7 | dword page_bg; |
7759 | leency | 8 | dword link_color_default; |
7757 | leency | 9 | dword link_color_active; |
10 | #include "..\TWB\links.h" |
||
4411 | leency | 11 | |
7759 | leency | 12 | #define BODY_MARGIN 6 |
13 | #define BASIC_LINE_H 18 |
||
4416 | leency | 14 | |
7771 | leency | 15 | DrawBufer DrawBuf; |
16 | char line[500]; |
||
17 | |||
5746 | leency | 18 | struct _style { |
7752 | leency | 19 | bool |
6794 | leency | 20 | b, u, s, h, |
5746 | leency | 21 | pre, |
22 | blq, |
||
7742 | leency | 23 | button, |
7759 | leency | 24 | image; |
7752 | leency | 25 | dword bg_color; |
7759 | leency | 26 | LIST tag_list; |
27 | dword tag_title; |
||
5746 | leency | 28 | }; |
29 | |||
4411 | leency | 30 | struct TWebBrowser { |
4540 | leency | 31 | llist list; |
5746 | leency | 32 | _style style; |
7752 | leency | 33 | dword draw_y, stolbec; |
6803 | leency | 34 | int zoom; |
7752 | leency | 35 | dword o_bufpointer; |
7759 | leency | 36 | int cur_encoding, custom_encoding; |
37 | bool link, t_html, t_body; |
||
38 | dword bufpointer; |
||
39 | dword bufsize; |
||
40 | |||
7771 | leency | 41 | void Paint(); |
7746 | leency | 42 | void SetPageDefaults(); |
7752 | leency | 43 | void AddCharToTheLine(); |
44 | void ParseHtml(); |
||
5766 | leency | 45 | void SetStyle(); |
7762 | leency | 46 | bool CheckForLineBreak(); |
47 | void NewLine(); |
||
48 | void DrawScroller(); |
||
49 | void ChangeEncoding(); |
||
4411 | leency | 50 | void DrawPage(); |
7759 | leency | 51 | char header[150]; |
52 | }; |
||
4486 | leency | 53 | |
7757 | leency | 54 | scroll_bar scroll_wv = { 15,NULL,NULL,NULL,0,2,NULL,0,0,0xeeeeee,0xBBBbbb,0xeeeeee}; |
4411 | leency | 55 | |
5747 | leency | 56 | //============================================================================================ |
7771 | leency | 57 | void TWebBrowser::Paint() |
4411 | leency | 58 | { |
6803 | leency | 59 | dword start_x, line_length, stolbec_len; |
7762 | leency | 60 | dword text_color__; |
4411 | leency | 61 | |
7759 | leency | 62 | if (style.tag_title) |
4411 | leency | 63 | { |
7759 | leency | 64 | strncpy(#header, #line, sizeof(TWebBrowser.header)-1); |
65 | strncat(#header, " - ", sizeof(TWebBrowser.header)-1); |
||
66 | strncat(#header, #version, sizeof(TWebBrowser.header)-1); |
||
4411 | leency | 67 | line = 0; |
68 | return; |
||
69 | } |
||
7758 | leency | 70 | if (t_html) && (!t_body) { |
71 | line = 0; |
||
72 | return; |
||
73 | } |
||
4411 | leency | 74 | |
6803 | leency | 75 | if (line) |
4411 | leency | 76 | { |
7759 | leency | 77 | start_x = stolbec * list.font_w + BODY_MARGIN + list.x; |
6803 | leency | 78 | stolbec_len = strlen(#line) * zoom; |
5768 | leency | 79 | line_length = stolbec_len * list.font_w; |
4411 | leency | 80 | |
7749 | leency | 81 | if (debug_mode) { |
7750 | leency | 82 | DrawBuf.DrawBar(start_x, draw_y, line_length, list.item_h, 0xDDDddd); |
7749 | leency | 83 | } |
84 | |||
7743 | leency | 85 | if (style.bg_color!=page_bg) { |
7750 | leency | 86 | DrawBuf.DrawBar(start_x, draw_y, line_length, list.item_h, style.bg_color); |
7743 | leency | 87 | } |
88 | |||
7742 | leency | 89 | if (style.image) { |
7743 | leency | 90 | DrawBuf.DrawBar(start_x, draw_y, line_length, list.item_h-1, 0xF9DBCB); |
7742 | leency | 91 | } |
92 | if (style.button) { |
||
93 | DrawBuf.DrawBar(start_x, draw_y, line_length, list.item_h - calc(zoom*2), 0xCCCccc); |
||
94 | DrawBuf.DrawBar(start_x, draw_y + list.item_h - calc(zoom*2), line_length, zoom, 0x999999); |
||
95 | } |
||
96 | |||
7762 | leency | 97 | text_color__ = text_colors[text_color_index]; |
98 | if (link) && (text_colors[text_color_index]==text_colors[0]) text_color__ = link_color_default; |
||
99 | |||
100 | DrawBuf.WriteText(start_x, draw_y, list.font_type, text_color__, #line); |
||
101 | if (style.b) DrawBuf.WriteText(start_x+1, draw_y, list.font_type, text_color__, #line); |
||
102 | if (style.s) DrawBuf.DrawBar(start_x, list.item_h / 2 - zoom + draw_y, line_length, zoom, text_color__); |
||
103 | if (style.u) DrawBuf.DrawBar(start_x, list.item_h - zoom - zoom + draw_y, line_length, zoom, text_color__); |
||
5519 | leency | 104 | if (link) { |
7747 | leency | 105 | if (line[0]==' ') && (line[1]==NULL) {} else { |
7759 | leency | 106 | DrawBuf.DrawBar(start_x, draw_y + list.item_h - calc(zoom*2)-1, line_length, zoom, link_color_default); |
107 | PageLinks.AddText(start_x, draw_y + list.y, line_length, list.item_h - calc(zoom*2)-1, UNDERLINE, zoom); |
||
7746 | leency | 108 | } |
4411 | leency | 109 | } |
4718 | leency | 110 | stolbec += stolbec_len; |
7750 | leency | 111 | if (debug_mode) debug(#line); |
112 | line = NULL; |
||
4411 | leency | 113 | } |
114 | } |
||
5747 | leency | 115 | //============================================================================================ |
7746 | leency | 116 | void TWebBrowser::SetPageDefaults() |
117 | { |
||
118 | style.b = style.u = style.s = style.h = style.blq = t_html = t_body = style.pre = |
||
7759 | leency | 119 | link = text_color_index = text_colors[0] = style.tag_title = false; |
120 | style.tag_list.reset(); |
||
121 | link_color_default = 0x0000FF; |
||
4491 | leency | 122 | link_color_active = 0xFF0000; |
7743 | leency | 123 | page_bg = 0xFFFFFF; |
124 | style.bg_color = page_bg; |
||
125 | DrawBuf.Fill(0, page_bg); |
||
4504 | leency | 126 | PageLinks.Clear(); |
7752 | leency | 127 | anchors.clear(); |
7758 | leency | 128 | header = NULL; |
7759 | leency | 129 | cur_encoding = CH_CP866; |
130 | draw_y = BODY_MARGIN; |
||
4411 | leency | 131 | stolbec = 0; |
132 | line = 0; |
||
7752 | leency | 133 | zoom = 1; |
7757 | leency | 134 | //hold original buffer |
135 | if (o_bufpointer) o_bufpointer=free(o_bufpointer); |
||
136 | o_bufpointer = malloc(bufsize); |
||
137 | memmov(o_bufpointer, bufpointer, bufsize); |
||
7759 | leency | 138 | if (custom_encoding != -1) { |
139 | cur_encoding = custom_encoding; |
||
140 | bufpointer = ChangeCharset(cur_encoding*10+#charsets, "CP866", bufpointer); |
||
141 | } |
||
7746 | leency | 142 | } |
143 | //============================================================================================ |
||
7752 | leency | 144 | void TWebBrowser::AddCharToTheLine(unsigned char _char) |
145 | { |
||
146 | dword line_len; |
||
147 | if (_char<=15) _char=' '; |
||
148 | line_len = strlen(#line); |
||
149 | if (!style.pre) && (_char == ' ') |
||
150 | { |
||
151 | if (line[line_len-1]==' ') return; //no double spaces |
||
152 | if (!stolbec) && (!line) return; //no paces at the beginning of the line |
||
153 | } |
||
7771 | leency | 154 | if (line_len < sizeof(line)) chrcat(#line, _char); |
7752 | leency | 155 | CheckForLineBreak(); |
156 | } |
||
157 | //============================================================================================ |
||
7759 | leency | 158 | void TWebBrowser::ParseHtml(dword _bufpointer, _bufsize){ |
7746 | leency | 159 | word bukva[2]; |
7752 | leency | 160 | char unicode_symbol[10]; |
161 | dword unicode_symbol_result; |
||
7746 | leency | 162 | dword j; |
7752 | leency | 163 | bool ignor_param=false; |
164 | int tab_len; |
||
7746 | leency | 165 | dword bufpos; |
7759 | leency | 166 | bufsize = _bufsize; |
7771 | leency | 167 | if (bufpointer != _bufpointer) { |
168 | bufpointer = malloc(bufsize); |
||
169 | memmov(bufpointer, _bufpointer, bufsize); |
||
170 | } else { |
||
171 | custom_encoding = CH_CP866; |
||
172 | } |
||
7746 | leency | 173 | SetPageDefaults(); |
7749 | leency | 174 | if (strstri(bufpointer, " |
175 | t_body = true; |
||
176 | if (strstri(bufpointer, " |
||
177 | } |
||
5773 | leency | 178 | for (bufpos=bufpointer ; (bufpos < bufpointer+bufsize) && (ESBYTE[bufpos]!=0) ; bufpos++;) |
4411 | leency | 179 | { |
4508 | leency | 180 | bukva = ESBYTE[bufpos]; |
4411 | leency | 181 | switch (bukva) |
182 | { |
||
183 | case 0x0a: |
||
7752 | leency | 184 | if (style.pre) { |
7771 | leency | 185 | Paint(); |
5781 | leency | 186 | NewLine(); |
7752 | leency | 187 | } else { |
188 | AddCharToTheLine(0x0a); |
||
4411 | leency | 189 | } |
7752 | leency | 190 | break; |
191 | case 0x09: |
||
192 | if (style.pre) { |
||
193 | tab_len = strlen(#line) + stolbec % 4; |
||
194 | if (!tab_len) tab_len = 4; else tab_len = 4 - tab_len; |
||
4411 | leency | 195 | for (j=0; j |
7752 | leency | 196 | } else { |
197 | AddCharToTheLine(0x09); |
||
4411 | leency | 198 | } |
7752 | leency | 199 | break; |
4411 | leency | 200 | case '&': // and so on |
7752 | leency | 201 | for (j=1, unicode_symbol=0; (ESBYTE[bufpos+j]<>';') && (j<8); j++) |
4411 | leency | 202 | { |
7749 | leency | 203 | bukva = ESBYTE[bufpos+j]; |
7752 | leency | 204 | chrcat(#unicode_symbol, bukva); |
4411 | leency | 205 | } |
7771 | leency | 206 | if (GetUnicodeSymbol(#line, #unicode_symbol, sizeof(line)-1)) { |
7749 | leency | 207 | bufpos += j; |
7750 | leency | 208 | CheckForLineBreak(); |
7749 | leency | 209 | } else { |
7752 | leency | 210 | AddCharToTheLine('&'); |
7749 | leency | 211 | } |
4411 | leency | 212 | break; |
213 | case '<': |
||
5749 | leency | 214 | bufpos++; |
5768 | leency | 215 | if (!strncmp(bufpos,"!--",3)) |
4411 | leency | 216 | { |
6986 | leency | 217 | bufpos+=3; |
218 | while (strncmp(bufpos,"-->",3)!=0) && (bufpos < bufpointer + bufsize) |
||
219 | { |
||
220 | bufpos++; |
||
221 | } |
||
7746 | leency | 222 | bufpos+=2; |
6986 | leency | 223 | break; |
4411 | leency | 224 | } |
7752 | leency | 225 | tag.reset(); |
226 | if (ESBYTE[bufpos] == '/') { |
||
227 | tag.opened = false; |
||
228 | bufpos++; |
||
229 | } |
||
230 | |||
231 | ignor_param=false; |
||
6735 | leency | 232 | while (ESBYTE[bufpos] !='>') && (bufpos < bufpointer + bufsize) //ïîëó÷à åì òåã è åãî ïà ðà ìåòðû |
4411 | leency | 233 | { |
4508 | leency | 234 | bukva = ESBYTE[bufpos]; |
7762 | leency | 235 | if (bukva == '\x9') || (bukva == '\x0a') || (bukva == '\x0d') bukva = ' '; |
4411 | leency | 236 | if (!ignor_param) && (bukva <>' ') |
237 | { |
||
7752 | leency | 238 | if (strlen(#tag.name)+1 |
4411 | leency | 239 | } |
240 | else |
||
241 | { |
||
242 | ignor_param = true; |
||
7752 | leency | 243 | if (strlen(#tag.params)+1 |
7762 | leency | 244 | //chrncat(#tag.params, bukva, sizeof(tag.params)-1); |
4411 | leency | 245 | } |
4508 | leency | 246 | bufpos++; |
4411 | leency | 247 | } |
7752 | leency | 248 | strlwr(#tag.name); |
4411 | leency | 249 | |
7746 | leency | 250 | // ignore text inside the next tags |
7752 | leency | 251 | if (tag.is("script")) || (tag.is("style")) || (tag.is("binary")) || (tag.is("select")) { |
252 | sprintf(#tag.params, "%s>", #tag.name); |
||
253 | j = strstri(bufpos, #tag.params); |
||
254 | if (j!=-1) bufpos = j-1; |
||
7746 | leency | 255 | break; |
256 | } |
||
257 | |||
7752 | leency | 258 | if (tag.name[strlen(#tag.name)-1]=='/') tag.name[strlen(#tag.name)-1]=NULL; //for br/ !!!!!!!! |
259 | if (tag.params) tag.parse_params(); |
||
7746 | leency | 260 | |
7757 | leency | 261 | if (tag.name) { |
7750 | leency | 262 | CheckForLineBreak(); |
7771 | leency | 263 | Paint(); |
7752 | leency | 264 | if (tag.name) SetStyle(); |
7746 | leency | 265 | } |
4411 | leency | 266 | break; |
267 | default: |
||
7752 | leency | 268 | AddCharToTheLine(ESBYTE[bufpos]); |
4411 | leency | 269 | } |
270 | } |
||
7771 | leency | 271 | Paint(); |
5766 | leency | 272 | NewLine(); |
7752 | leency | 273 | list.count = draw_y; |
7755 | leency | 274 | list.CheckDoesValuesOkey(); |
275 | anchors.current = NULL; |
||
7759 | leency | 276 | custom_encoding = -1; |
7758 | leency | 277 | if (!header) { |
7759 | leency | 278 | strncpy(#header, #version, sizeof(TWebBrowser.header)-1); |
7758 | leency | 279 | DrawTitle(#header); |
280 | } |
||
4411 | leency | 281 | } |
5747 | leency | 282 | //============================================================================================ |
7750 | leency | 283 | bool TWebBrowser::CheckForLineBreak() |
4718 | leency | 284 | { |
7750 | leency | 285 | int line_break_pos; |
4718 | leency | 286 | char new_line_text[4096]; |
7758 | leency | 287 | //Do we need a line break? |
7750 | leency | 288 | if (strlen(#line)*zoom + stolbec < list.column_max) return false; |
7758 | leency | 289 | //Yes, we do. Lets calculate where... |
7750 | leency | 290 | line_break_pos = strrchr(#line, ' '); |
7758 | leency | 291 | //Is a new line fits in the current line? |
7750 | leency | 292 | if (line_break_pos*zoom + stolbec > list.column_max) { |
293 | line_break_pos = list.column_max/zoom - stolbec; |
||
294 | while(line_break_pos) && (line[line_break_pos]!=' ') line_break_pos--; |
||
295 | } |
||
7758 | leency | 296 | //Maybe a new line is too big for the whole new line? Then we have to split it |
7759 | leency | 297 | if (!line_break_pos) && (style.tag_list.level*5 + strlen(#line) * zoom >= list.column_max) { |
7758 | leency | 298 | line_break_pos = list.column_max/zoom - stolbec; |
7742 | leency | 299 | } |
7750 | leency | 300 | strcpy(#new_line_text, #line + line_break_pos); |
7758 | leency | 301 | line[line_break_pos] = 0x00; |
302 | |||
7771 | leency | 303 | Paint(); |
7758 | leency | 304 | |
4718 | leency | 305 | strcpy(#line, #new_line_text); |
306 | NewLine(); |
||
7762 | leency | 307 | //while (CheckForLineBreak()==true) {}; |
7750 | leency | 308 | return true; |
4718 | leency | 309 | } |
5747 | leency | 310 | //============================================================================================ |
5773 | leency | 311 | void TWebBrowser::SetStyle() { |
7749 | leency | 312 | char img_path[4096]=0; |
7752 | leency | 313 | |
314 | dword value; |
||
315 | |||
7755 | leency | 316 | if (value = tag.get_value_of("name=")) || (value = tag.get_value_of("id=")) { |
317 | anchors.add(value, draw_y); |
||
318 | if (anchors.current) && (streq(value, #anchors.current+1)) { |
||
319 | list.first = draw_y; |
||
320 | anchors.current = NULL; |
||
321 | } |
||
7758 | leency | 322 | } |
7752 | leency | 323 | if (tag.is("html")) { |
324 | t_html = tag.opened; |
||
4411 | leency | 325 | return; |
326 | } |
||
7758 | leency | 327 | if (tag.is("title")) { |
7759 | leency | 328 | style.tag_title = tag.opened; |
7758 | leency | 329 | if (!tag.opened) DrawTitle(#header); |
330 | return; |
||
331 | } |
||
7752 | leency | 332 | if (tag.is("body")) { |
333 | t_body = tag.opened; |
||
7759 | leency | 334 | if (value = tag.get_value_of("link=")) link_color_default = GetColor(value); |
7752 | leency | 335 | if (value = tag.get_value_of("alink=")) link_color_active = GetColor(value); |
336 | if (value = tag.get_value_of("text=")) text_colors[0]=GetColor(value); |
||
337 | if (value = tag.get_value_of("bgcolor=")) { |
||
338 | style.bg_color = page_bg = GetColor(value); |
||
339 | DrawBuf.Fill(0, page_bg); |
||
340 | } |
||
7762 | leency | 341 | // Autodetecting encoding if no encoding was set |
342 | if (tag.opened) && (custom_encoding==-1) && (cur_encoding == CH_CP866) { |
||
343 | if (strstr(bufpointer, "\208\190")) ChangeEncoding(CH_UTF8); |
||
344 | else if (chrnum(bufpointer, '\x246')>5) ChangeEncoding(CH_CP1251); |
||
345 | } |
||
4411 | leency | 346 | return; |
347 | } |
||
7762 | leency | 348 | if (tag.is("br")) { NewLine(); return; } |
7780 | leency | 349 | if (tag.is("b")) || (tag.is("strong")) || (tag.is("big")) { |
350 | style.b = tag.opened; |
||
351 | return; |
||
352 | } |
||
7752 | leency | 353 | if (tag.is("a")) { |
354 | if (tag.opened) |
||
4411 | leency | 355 | { |
7752 | leency | 356 | if (value = tag.get_value_of("href=")) && (!strstr(value,"javascript:")) |
357 | { |
||
7762 | leency | 358 | link = true; |
7752 | leency | 359 | PageLinks.AddLink(value); |
360 | } |
||
361 | } else { |
||
7762 | leency | 362 | link = false; |
4411 | leency | 363 | } |
364 | return; |
||
365 | } |
||
7762 | leency | 366 | if (tag.is("iframe")) && (value = tag.get_value_of("src=")) { |
367 | NewLine(); |
||
368 | strcpy(#line, "IFRAME: "); |
||
7771 | leency | 369 | Paint(); |
7762 | leency | 370 | link=true; |
371 | PageLinks.AddLink(value); |
||
7771 | leency | 372 | strncpy(#line, value, sizeof(line)-1); |
7762 | leency | 373 | while (CheckForLineBreak()) {}; |
7771 | leency | 374 | Paint(); |
7762 | leency | 375 | link=false; |
376 | NewLine(); |
||
377 | } |
||
7752 | leency | 378 | if (tag.is("font")) { |
7743 | leency | 379 | style.bg_color = page_bg; |
7752 | leency | 380 | if (tag.opened) |
4411 | leency | 381 | { |
382 | text_color_index++; |
||
383 | text_colors[text_color_index] = text_colors[text_color_index-1]; |
||
7752 | leency | 384 | if (value = tag.get_value_of("color=")) text_colors[text_color_index] = GetColor(value); |
385 | if (value = tag.get_value_of("bg=")) style.bg_color = GetColor(value); |
||
4411 | leency | 386 | } |
5749 | leency | 387 | else if (text_color_index > 0) text_color_index--; |
4411 | leency | 388 | return; |
389 | } |
||
7752 | leency | 390 | if (tag.is("div")) { |
7756 | leency | 391 | if (streq(#tag.prior,"div")) && (tag.opened) return; |
7746 | leency | 392 | NewLine(); |
4411 | leency | 393 | return; |
394 | } |
||
7752 | leency | 395 | if (tag.is("header")) || (tag.is("article")) || (tag.is("footer")) || (tag.is("figure")) { |
7746 | leency | 396 | NewLine(); |
397 | return; |
||
398 | } |
||
7780 | leency | 399 | if (tag.is("p")) || (tag.is("w:p")) { |
7756 | leency | 400 | IF (tag.prior[0] == 'h') || (streq(#tag.prior,"td")) || (streq(#tag.prior,"p")) return; |
4692 | leency | 401 | NewLine(); |
4411 | leency | 402 | return; |
403 | } |
||
7762 | leency | 404 | if (tag.is("pre")) { style.pre = tag.opened; return; } |
7757 | leency | 405 | if (tag.is("td")) { if (tag.opened) AddCharToTheLine(' '); return; } |
7752 | leency | 406 | if (tag.is("tr")) { if (tag.opened) NewLine(); return; } |
407 | if (tag.is("button")) { style.button = tag.opened; stolbec++; return; } |
||
408 | if (tag.is("u")) || (tag.is("ins")) { style.u=tag.opened; return;} |
||
409 | if (tag.is("s")) || (tag.is("strike")) || (tag.is("del")) { style.s=tag.opened; return; } |
||
7764 | leency | 410 | if (tag.is("dl")) { |
411 | if (tag.opened) NewLine(); |
||
412 | return; |
||
413 | } |
||
414 | if (tag.is("dd")) { |
||
415 | //NewLine(); |
||
416 | //if (tag.opened) stolbec += 5; //stolbec overflow! |
||
417 | return; |
||
418 | } |
||
7752 | leency | 419 | if (tag.is("blockquote")) { style.blq = tag.opened; return; } |
7759 | leency | 420 | if (tag.is("code")) { |
421 | if (tag.opened) style.bg_color = 0xe4ffcb; else style.bg_color = page_bg; |
||
422 | style.pre = tag.opened; return; |
||
423 | } |
||
7752 | leency | 424 | if (tag.is("img")) { |
425 | if (value = tag.get_value_of("src=")) strlcpy(#img_path, value, sizeof(img_path)-1); |
||
7771 | leency | 426 | if (value = tag.get_value_of("title=")) && (strlen(value) |
427 | if (value = tag.get_value_of("alt=")) && (strlen(value) |
||
7750 | leency | 428 | if (!img_path) { line=0; return; } |
7742 | leency | 429 | style.image = true; |
430 | text_color_index++; |
||
431 | text_colors[text_color_index] = 0x9A6F29; |
||
432 | if (!line) { |
||
433 | if (!strncmp(#img_path, "data:", 5)) img_path=0; |
||
7749 | leency | 434 | replace_char(#img_path, '?', NULL, strlen(#img_path)); |
7742 | leency | 435 | sprintf(#line, "[%s]", #img_path+strrchr(#img_path, '/')); |
436 | line[50]= NULL; |
||
437 | } |
||
7750 | leency | 438 | while (CheckForLineBreak()) {}; |
7771 | leency | 439 | Paint(); |
7742 | leency | 440 | text_color_index--; |
441 | style.image = false; |
||
7759 | leency | 442 | //ImgCache.Images( list.x, draw_y, list.w); |
7742 | leency | 443 | return; |
444 | } |
||
7758 | leency | 445 | if (tag.is("h4")) { |
446 | NewLine(); |
||
7759 | leency | 447 | NewLine(); |
7758 | leency | 448 | style.h = tag.opened; |
449 | style.b = tag.opened; |
||
450 | } |
||
7752 | leency | 451 | if (tag.is("h1")) || (tag.is("h2")) || (tag.is("h3")) || (tag.is("caption")) { |
452 | style.h = tag.opened; |
||
7758 | leency | 453 | if (tag.opened) { |
7759 | leency | 454 | if (!style.pre) NewLine(); |
6794 | leency | 455 | draw_y += 10; |
7759 | leency | 456 | zoom=2; |
457 | list.font_type |= 10011001b; |
||
458 | list.item_h = BASIC_LINE_H * 2 - 2; |
||
7752 | leency | 459 | if (tag.is("h1")) style.b = true; |
7758 | leency | 460 | } else { |
7752 | leency | 461 | if (tag.is("h1")) style.b = false; |
6794 | leency | 462 | NewLine(); |
7759 | leency | 463 | zoom=1; |
464 | list.font_type = 10011000b; |
||
465 | list.item_h = BASIC_LINE_H; |
||
4411 | leency | 466 | } |
467 | return; |
||
468 | } |
||
7752 | leency | 469 | if (tag.is("dt")) { |
7759 | leency | 470 | style.tag_list.upd_level(tag.opened, DT); |
7752 | leency | 471 | if (tag.opened) NewLine(); |
4411 | leency | 472 | return; |
473 | } |
||
7759 | leency | 474 | if (tag.is("ul")) { |
475 | style.tag_list.upd_level(tag.opened, UL); |
||
476 | if (!tag.opened) && (!style.pre) NewLine(); |
||
477 | return; |
||
478 | } |
||
479 | if (tag.is("ol")) { |
||
480 | style.tag_list.upd_level(tag.opened, OL); |
||
481 | if (!tag.opened) && (!style.pre) NewLine(); |
||
482 | return; |
||
483 | } |
||
484 | if (tag.is("li")) && (tag.opened) |
||
4411 | leency | 485 | { |
7759 | leency | 486 | if (!style.tag_list.level) style.tag_list.upd_level(1, UL); |
487 | if (!style.pre) NewLine(); |
||
488 | if (style.tag_list.get_order_type() == UL) { |
||
7742 | leency | 489 | strcpy(#line, "\31 "); |
7759 | leency | 490 | stolbec = style.tag_list.level * 5 - 2; |
491 | } |
||
492 | if (style.tag_list.get_order_type() == OL) { |
||
493 | sprintf(#line, "%i. ", style.tag_list.inc_counter()); |
||
494 | stolbec = style.tag_list.level * 5 - strlen(#line); |
||
4411 | leency | 495 | } |
496 | return; |
||
497 | } |
||
7762 | leency | 498 | if (tag.is("q")) |
499 | { |
||
500 | if (tag.opened) { |
||
501 | EAX = strlen(#line); |
||
502 | if (line[EAX-1] != ' ') chrcat(#line, ' '); |
||
503 | chrcat(#line, '\"'); |
||
504 | } |
||
505 | if (!tag.opened) strcat(#line, "\" "); |
||
506 | return; |
||
507 | } |
||
7752 | leency | 508 | if (tag.is("hr")) { |
509 | if (value = tag.get_value_of("color=")) EDI = GetColor(value); else EDI = 0x999999; |
||
5773 | leency | 510 | $push edi; |
4692 | leency | 511 | NewLine(); |
5773 | leency | 512 | $pop edi; |
7746 | leency | 513 | draw_y += 10; |
6794 | leency | 514 | DrawBuf.DrawBar(5, draw_y - 1, list.w-10, 1, EDI); |
4692 | leency | 515 | NewLine(); |
7746 | leency | 516 | draw_y += 10; |
5773 | leency | 517 | return; |
4411 | leency | 518 | } |
7759 | leency | 519 | if (custom_encoding == -1) && (tag.is("meta")) || (tag.is("?xml")) { |
7752 | leency | 520 | if (value = tag.get_value_of("charset=")) || (value = tag.get_value_of("content=")) || (value = tag.get_value_of("encoding=")) |
521 | { |
||
522 | value += strrchr(value, '='); //search in content= |
||
523 | strlwr(value); |
||
7762 | leency | 524 | if (streq(value,"utf-8")) || (streq(value,"utf8")) ChangeEncoding(CH_UTF8); |
525 | else if (streq(value,"windows-1251")) || (streq(value,"windows1251")) ChangeEncoding(CH_CP1251); |
||
526 | else if (streq(value,"dos")) || (streq(value,"cp-866")) ChangeEncoding(CH_CP866); |
||
527 | else if (streq(value,"iso-8859-5")) || (streq(value,"iso8859-5")) ChangeEncoding(CH_ISO8859_5); |
||
528 | else if (streq(value,"koi8-r")) || (streq(value,"koi8-u")) ChangeEncoding(CH_KOI8); |
||
7752 | leency | 529 | } |
4411 | leency | 530 | return; |
531 | } |
||
532 | } |
||
7746 | leency | 533 | //============================================================================================ |
4674 | leency | 534 | void TWebBrowser::DrawScroller() |
4411 | leency | 535 | { |
4416 | leency | 536 | scroll_wv.max_area = list.count; |
537 | scroll_wv.cur_area = list.visible; |
||
538 | scroll_wv.position = list.first; |
||
5519 | leency | 539 | scroll_wv.all_redraw = 0; |
4486 | leency | 540 | scroll_wv.start_x = list.x + list.w; |
4508 | leency | 541 | scroll_wv.start_y = list.y; |
5678 | leency | 542 | scroll_wv.size_y = list.h; |
4416 | leency | 543 | scrollbar_v_draw(#scroll_wv); |
4411 | leency | 544 | } |
5747 | leency | 545 | //============================================================================================ |
7762 | leency | 546 | void TWebBrowser::ChangeEncoding(int _new_encoding) |
547 | { |
||
548 | if (cur_encoding == _new_encoding) return; |
||
549 | cur_encoding = _new_encoding; |
||
550 | bufpointer = ChangeCharset(cur_encoding*10+#charsets, "CP866", bufpointer); |
||
551 | if (header) { |
||
552 | ChangeCharset(cur_encoding*10+#charsets, "CP866", #header); |
||
553 | DrawTitle(#header); |
||
554 | } |
||
555 | } |
||
556 | //============================================================================================ |
||
4692 | leency | 557 | void TWebBrowser::NewLine() |
4475 | leency | 558 | { |
6803 | leency | 559 | dword onleft, ontop; |
7742 | leency | 560 | static int empty_line=0; |
4692 | leency | 561 | |
7759 | leency | 562 | if (!stolbec) && (draw_y==BODY_MARGIN) return; |
7742 | leency | 563 | |
7759 | leency | 564 | if (style.tag_list.level) && (stolbec == style.tag_list.level * 5) { |
7742 | leency | 565 | if (empty_line<1) empty_line++; |
566 | else return; |
||
7749 | leency | 567 | } else if (!stolbec) { |
568 | if (empty_line<1) empty_line++; |
||
569 | else return; |
||
7742 | leency | 570 | } else { |
571 | empty_line=0; |
||
572 | } |
||
6794 | leency | 573 | |
7759 | leency | 574 | onleft = list.x + BODY_MARGIN; |
6794 | leency | 575 | ontop = draw_y + list.y; |
4637 | leency | 576 | if (t_html) && (!t_body) return; |
6794 | leency | 577 | draw_y += list.item_h; |
5746 | leency | 578 | if (style.blq) stolbec = 6; else stolbec = 0; |
7759 | leency | 579 | stolbec += style.tag_list.level * 5; |
7750 | leency | 580 | if (debug_mode) debugln(NULL); |
4488 | leency | 581 | } |
5747 | leency | 582 | //============================================================================================ |
5766 | leency | 583 | void TWebBrowser::DrawPage() |
584 | { |
||
6794 | leency | 585 | PutPaletteImage(list.first * DrawBuf.bufw * 4 + buf_data+8, DrawBuf.bufw, list.h, DrawBuf.bufx, DrawBuf.bufy, 32, 0); |
5766 | leency | 586 | DrawScroller(); |
587 | }1)>1)>>>>>': |