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