Rev 7757 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 7757 | Rev 7758 | ||
---|---|---|---|
Line 1... | Line 1... | ||
1 | #include "..\TWB\colors.h" |
1 | #include "..\TWB\colors.h" |
2 | #include "..\TWB\anchors.h" |
2 | #include "..\TWB\anchors.h" |
3 | #include "..\TWB\parce_tag.h" |
3 | #include "..\TWB\parce_tag.h" |
4 | #include "..\TWB\absolute_url.h" |
4 | #include "..\TWB\special.h" |
5 | #include "..\TWB\unicode_tags.h" |
- | |
6 | #include "..\TWB\img_cache.h" |
5 | #include "..\TWB\img_cache.h" |
7 | dword page_bg; |
6 | dword page_bg; |
8 | dword link_color_inactive; |
7 | dword link_color_inactive; |
9 | dword link_color_active; |
8 | dword link_color_active; |
10 | #include "..\TWB\links.h" |
9 | #include "..\TWB\links.h" |
Line 20... | Line 19... | ||
20 | li_tab, |
19 | li_tab, |
21 | button, |
20 | button, |
22 | image, |
21 | image, |
23 | align; |
22 | align; |
24 | dword bg_color; |
23 | dword bg_color; |
- | 24 | ||
- | 25 | dword main_title; |
|
25 | }; |
26 | }; |
Line 26... | Line 27... | ||
26 | 27 | ||
27 | struct TWebBrowser { |
28 | struct TWebBrowser { |
28 | llist list; |
29 | llist list; |
Line 61... | Line 62... | ||
61 | //============================================================================================ |
62 | //============================================================================================ |
62 | void TWebBrowser::DrawStyle() |
63 | void TWebBrowser::DrawStyle() |
63 | { |
64 | { |
64 | dword start_x, line_length, stolbec_len; |
65 | dword start_x, line_length, stolbec_len; |
Line 65... | Line 66... | ||
65 | 66 | ||
66 | if (!header) |
67 | if (style.main_title) |
67 | { |
68 | { |
- | 69 | strncpy(#header, #line, sizeof(header)-1); |
|
- | 70 | strncat(#header, " - ", sizeof(header)-1); |
|
- | 71 | strncat(#header, #version, sizeof(header)-1); |
|
- | 72 | line = 0; |
|
- | 73 | return; |
|
- | 74 | } |
|
68 | strncpy(#header, #line, sizeof(header)-1); |
75 | if (t_html) && (!t_body) { |
69 | line = 0; |
76 | line = 0; |
70 | return; |
77 | return; |
71 | } |
- | |
Line 72... | Line 78... | ||
72 | if (t_html) && (!t_body) return; |
78 | } |
73 | 79 | ||
74 | if (line) |
80 | if (line) |
75 | { |
81 | { |
Line 110... | Line 116... | ||
110 | } |
116 | } |
111 | //============================================================================================ |
117 | //============================================================================================ |
112 | void TWebBrowser::SetPageDefaults() |
118 | void TWebBrowser::SetPageDefaults() |
113 | { |
119 | { |
114 | style.b = style.u = style.s = style.h = style.blq = t_html = t_body = style.pre = |
120 | style.b = style.u = style.s = style.h = style.blq = t_html = t_body = style.pre = |
115 | style.li = link = text_color_index = text_colors[0] = style.li_tab = false; |
121 | style.li = link = text_color_index = text_colors[0] = style.li_tab = style.main_title = false; |
116 | style.align = ALIGN_LEFT; |
122 | style.align = ALIGN_LEFT; |
117 | link_color_inactive = 0x0000FF; |
123 | link_color_inactive = 0x0000FF; |
118 | link_color_active = 0xFF0000; |
124 | link_color_active = 0xFF0000; |
119 | page_bg = 0xFFFFFF; |
125 | page_bg = 0xFFFFFF; |
120 | style.bg_color = page_bg; |
126 | style.bg_color = page_bg; |
121 | DrawBuf.Fill(0, page_bg); |
127 | DrawBuf.Fill(0, page_bg); |
122 | PageLinks.Clear(); |
128 | PageLinks.Clear(); |
123 | anchors.clear(); |
129 | anchors.clear(); |
124 | strncpy(#header, #version, sizeof(header)-1); |
130 | header = NULL; |
125 | cur_encoding = CH_NULL; |
131 | cur_encoding = CH_NULL; |
126 | draw_y = body_magrin; |
132 | draw_y = body_magrin; |
127 | stolbec = 0; |
133 | stolbec = 0; |
128 | line = 0; |
134 | line = 0; |
129 | zoom = 1; |
135 | zoom = 1; |
Line 256... | Line 262... | ||
256 | DrawStyle(); |
262 | DrawStyle(); |
257 | NewLine(); |
263 | NewLine(); |
258 | list.count = draw_y; |
264 | list.count = draw_y; |
259 | list.CheckDoesValuesOkey(); |
265 | list.CheckDoesValuesOkey(); |
260 | anchors.current = NULL; |
266 | anchors.current = NULL; |
- | 267 | if (!header) { |
|
- | 268 | strncpy(#header, #version, sizeof(header)-1); |
|
- | 269 | DrawTitle(#header); |
|
- | 270 | } |
|
261 | } |
271 | } |
262 | //============================================================================================ |
272 | //============================================================================================ |
263 | bool TWebBrowser::CheckForLineBreak() |
273 | bool TWebBrowser::CheckForLineBreak() |
264 | { |
274 | { |
265 | int line_break_pos; |
275 | int line_break_pos; |
266 | char new_line_text[4096]; |
276 | char new_line_text[4096]; |
- | 277 | //Do we need a line break? |
|
267 | if (strlen(#line)*zoom + stolbec < list.column_max) return false; |
278 | if (strlen(#line)*zoom + stolbec < list.column_max) return false; |
- | 279 | //Yes, we do. Lets calculate where... |
|
268 | line_break_pos = strrchr(#line, ' '); |
280 | line_break_pos = strrchr(#line, ' '); |
- | 281 | //Is a new line fits in the current line? |
|
269 | if (line_break_pos*zoom + stolbec > list.column_max) { |
282 | if (line_break_pos*zoom + stolbec > list.column_max) { |
270 | line_break_pos = list.column_max/zoom - stolbec; |
283 | line_break_pos = list.column_max/zoom - stolbec; |
271 | while(line_break_pos) && (line[line_break_pos]!=' ') line_break_pos--; |
284 | while(line_break_pos) && (line[line_break_pos]!=' ') line_break_pos--; |
272 | } |
285 | } |
- | 286 | //Maybe a new line is too big for the whole new line? Then we have to split it |
|
273 | if (!line_break_pos) && (strlen(#line)*zoom>list.column_max) { |
287 | if (!line_break_pos) && (style.li_tab*5 + strlen(#line) * zoom >= list.column_max) { |
274 | line_break_pos=list.column_max/zoom; |
288 | line_break_pos = list.column_max/zoom - stolbec; |
275 | if (!stolbec)&&(style.pre) draw_y-=list.item_h; //hack to fix https://prnt.sc/rk3kyt |
- | |
276 | } |
289 | } |
277 | strcpy(#new_line_text, #line + line_break_pos); |
290 | strcpy(#new_line_text, #line + line_break_pos); |
278 | line[line_break_pos] = 0x00; |
291 | line[line_break_pos] = 0x00; |
- | 292 | ||
279 | DrawStyle(); |
293 | DrawStyle(); |
- | 294 | ||
280 | strcpy(#line, #new_line_text); |
295 | strcpy(#line, #new_line_text); |
281 | NewLine(); |
296 | NewLine(); |
282 | //if (strlen(#line)*zoom + stolbec > list.column_max)CheckForLineBreak(); |
297 | //if (strlen(#line)*zoom + stolbec > list.column_max)CheckForLineBreak(); |
283 | return true; |
298 | return true; |
284 | } |
299 | } |
Line 294... | Line 309... | ||
294 | if (anchors.current) && (streq(value, #anchors.current+1)) { |
309 | if (anchors.current) && (streq(value, #anchors.current+1)) { |
295 | list.first = draw_y; |
310 | list.first = draw_y; |
296 | anchors.current = NULL; |
311 | anchors.current = NULL; |
297 | } |
312 | } |
298 | } |
313 | } |
299 | - | ||
300 | if (tag.is("html")) { |
314 | if (tag.is("html")) { |
301 | t_html = tag.opened; |
315 | t_html = tag.opened; |
302 | return; |
316 | return; |
303 | } |
317 | } |
304 | if (tag.is("title")) { |
- | |
305 | if (tag.opened) header=NULL; |
- | |
306 | return; |
- | |
307 | } |
- | |
308 | - | ||
309 | if (tag.is("q")) |
318 | if (tag.is("q")) |
310 | { |
319 | { |
311 | if (tag.opened) { |
320 | if (tag.opened) { |
312 | meta_encoding = strlen(#line); |
321 | meta_encoding = strlen(#line); |
313 | if (line[meta_encoding-1] != ' ') chrcat(#line, ' '); |
322 | if (line[meta_encoding-1] != ' ') chrcat(#line, ' '); |
314 | chrcat(#line, '\"'); |
323 | chrcat(#line, '\"'); |
315 | } |
324 | } |
316 | if (!tag.opened) strcat(#line, "\" "); |
325 | if (!tag.opened) strcat(#line, "\" "); |
317 | return; |
326 | return; |
318 | } |
327 | } |
- | 328 | if (tag.is("title")) { |
|
- | 329 | style.main_title = tag.opened; |
|
- | 330 | if (!tag.opened) DrawTitle(#header); |
|
- | 331 | return; |
|
- | 332 | } |
|
319 | if (tag.is("body")) { |
333 | if (tag.is("body")) { |
320 | t_body = tag.opened; |
334 | t_body = tag.opened; |
321 | if (value = tag.get_value_of("link=")) link_color_inactive = GetColor(value); |
335 | if (value = tag.get_value_of("link=")) link_color_inactive = GetColor(value); |
322 | if (value = tag.get_value_of("alink=")) link_color_active = GetColor(value); |
336 | if (value = tag.get_value_of("alink=")) link_color_active = GetColor(value); |
323 | if (value = tag.get_value_of("text=")) text_colors[0]=GetColor(value); |
337 | if (value = tag.get_value_of("text=")) text_colors[0]=GetColor(value); |
324 | if (value = tag.get_value_of("bgcolor=")) { |
338 | if (value = tag.get_value_of("bgcolor=")) { |
325 | style.bg_color = page_bg = GetColor(value); |
339 | style.bg_color = page_bg = GetColor(value); |
326 | DrawBuf.Fill(0, page_bg); |
340 | DrawBuf.Fill(0, page_bg); |
327 | } |
341 | } |
328 | if (tag.opened) { |
- | |
329 | if (cur_encoding==CH_NULL) { |
- | |
330 | cur_encoding = CH_CP866; |
- | |
331 | //BufEncode(CH_UTF8); |
- | |
332 | debugln("Document has no information about encoding!"); |
- | |
333 | } |
- | |
334 | if (!streq(#header, #version)) { |
- | |
335 | ChangeCharset(charsets[cur_encoding], "CP866", #header); |
- | |
336 | strncat(#header, " - ", sizeof(header)-1); |
- | |
337 | strncat(#header, #version, sizeof(header)-1); |
- | |
338 | } |
- | |
339 | DrawTitle(#header); |
- | |
340 | } |
- | |
341 | return; |
342 | return; |
342 | } |
343 | } |
343 | if (tag.is("a")) { |
344 | if (tag.is("a")) { |
344 | if (tag.opened) |
345 | if (tag.opened) |
345 | { |
346 | { |
Line 413... | Line 414... | ||
413 | text_color_index--; |
414 | text_color_index--; |
414 | style.image = false; |
415 | style.image = false; |
415 | //ImgCache.Images( list.x, draw_y, WB1.list.w); |
416 | //ImgCache.Images( list.x, draw_y, WB1.list.w); |
416 | return; |
417 | return; |
417 | } |
418 | } |
- | 419 | if (tag.is("h4")) { |
|
- | 420 | NewLine(); |
|
- | 421 | style.h = tag.opened; |
|
- | 422 | style.b = tag.opened; |
|
- | 423 | } |
|
418 | if (tag.is("h1")) || (tag.is("h2")) || (tag.is("h3")) || (tag.is("caption")) { |
424 | if (tag.is("h1")) || (tag.is("h2")) || (tag.is("h3")) || (tag.is("caption")) { |
419 | style.h = tag.opened; |
425 | style.h = tag.opened; |
420 | if (tag.opened) |
426 | if (tag.opened) { |
421 | { |
- | |
422 | NewLine(); |
427 | NewLine(); |
423 | draw_y += 10; |
428 | draw_y += 10; |
424 | WB1.zoom=2; |
429 | WB1.zoom=2; |
425 | WB1.list.font_type |= 10011001b; |
430 | WB1.list.font_type |= 10011001b; |
426 | if (value = tag.get_value_of("align=")) { |
- | |
427 | if (streq(value, "center")) style.align = ALIGN_CENTER; |
- | |
428 | if (streq(value, "right")) style.align = ALIGN_RIGHT; |
- | |
429 | } |
- | |
430 | list.item_h = basic_line_h * 2; |
431 | list.item_h = basic_line_h * 2 - 2; |
431 | if (tag.is("h1")) style.b = true; |
432 | if (tag.is("h1")) style.b = true; |
432 | } |
- | |
433 | else |
433 | } else { |
434 | { |
- | |
435 | if (tag.is("h1")) style.b = false; |
434 | if (tag.is("h1")) style.b = false; |
436 | NewLine(); |
435 | NewLine(); |
437 | WB1.zoom=1; |
436 | WB1.zoom=1; |
438 | WB1.list.font_type = 10011000b; |
437 | WB1.list.font_type = 10011000b; |
439 | style.align = ALIGN_LEFT; |
- | |
440 | list.item_h = basic_line_h; |
438 | list.item_h = basic_line_h; |
441 | } |
439 | } |
442 | return; |
440 | return; |
443 | } |
441 | } |
444 | if (tag.is("dt")) { |
442 | if (tag.is("dt")) { |
Line 449... | Line 447... | ||
449 | if (tag.is("li")) || (tag.is("dt")) |
447 | if (tag.is("li")) || (tag.is("dt")) |
450 | { |
448 | { |
451 | style.li = tag.opened; |
449 | style.li = tag.opened; |
452 | if (tag.opened) |
450 | if (tag.opened) |
453 | { |
451 | { |
- | 452 | if (style.li_tab==0) style.li_tab++; |
|
454 | NewLine(); |
453 | NewLine(); |
455 | stolbec = style.li_tab * 5 - 2; |
454 | stolbec = style.li_tab * 5 - 2; |
456 | strcpy(#line, "\31 "); |
455 | strcpy(#line, "\31 "); |
457 | //stolbec-=2; |
456 | //stolbec-=2; |
458 | } |
457 | } |
Line 460... | Line 459... | ||
460 | } |
459 | } |
461 | if (tag.is("ul")) || (tag.is("ol")) { |
460 | if (tag.is("ul")) || (tag.is("ol")) { |
462 | if (!tag.opened) |
461 | if (!tag.opened) |
463 | { |
462 | { |
464 | style.li = false; |
463 | style.li = false; |
465 | style.li_tab--; |
464 | if (style.li_tab>0) style.li_tab--; |
466 | NewLine(); |
465 | NewLine(); |
467 | } |
466 | } |
- | 467 | else { |
|
468 | else style.li_tab++; |
468 | if (style.li_tab<5) style.li_tab++; |
- | 469 | } |
|
469 | } |
470 | } |
470 | if (tag.is("hr")) { |
471 | if (tag.is("hr")) { |
471 | if (value = tag.get_value_of("color=")) EDI = GetColor(value); else EDI = 0x999999; |
472 | if (value = tag.get_value_of("color=")) EDI = GetColor(value); else EDI = 0x999999; |
472 | $push edi; |
473 | $push edi; |
473 | NewLine(); |
474 | NewLine(); |
Line 488... | Line 489... | ||
488 | else if (streq(value,"windows-1251")) || (streq(value,"windows1251")) meta_encoding = CH_CP1251; |
489 | else if (streq(value,"windows-1251")) || (streq(value,"windows1251")) meta_encoding = CH_CP1251; |
489 | else if (streq(value,"dos")) || (streq(value,"cp-866")) meta_encoding = CH_CP866; |
490 | else if (streq(value,"dos")) || (streq(value,"cp-866")) meta_encoding = CH_CP866; |
490 | else if (streq(value,"iso-8859-5")) || (streq(value,"iso8859-5")) meta_encoding = CH_ISO8859_5; |
491 | else if (streq(value,"iso-8859-5")) || (streq(value,"iso8859-5")) meta_encoding = CH_ISO8859_5; |
491 | else if (streq(value,"koi8-r")) || (streq(value,"koi8-u")) meta_encoding = CH_KOI8; |
492 | else if (streq(value,"koi8-r")) || (streq(value,"koi8-u")) meta_encoding = CH_KOI8; |
492 | } |
493 | } |
493 | if (meta_encoding!=CH_NULL) BufEncode(meta_encoding); |
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 | } |
|
494 | return; |
501 | return; |
495 | } |
502 | } |
496 | } |
503 | } |
497 | //============================================================================================ |
504 | //============================================================================================ |
498 | void TWebBrowser::BufEncode(dword set_new_encoding) |
505 | void TWebBrowser::BufEncode(dword set_new_encoding) |