Subversion Repositories Kolibri OS

Rev

Rev 8363 | Rev 8396 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

  1. #include "TWB\colors.h"
  2. #include "TWB\anchors.h"
  3. #include "TWB\parse_tag.h"
  4. #include "TWB\special.h"
  5. #include "TWB\img.h"
  6. #include "TWB\tag_list.h"
  7. dword page_bg;
  8. dword link_color_default;
  9. dword link_color_active;
  10. #include "TWB\links.h"
  11.  
  12. #define BODY_MARGIN 6
  13. #define BASIC_LINE_H 18
  14.  
  15. DrawBufer DrawBuf;
  16. char line[500];
  17.  
  18. struct _style {
  19.         bool
  20.         b, u, s, h,
  21.         font,
  22.         pre,
  23.         blq,
  24.         button,
  25.         image;
  26.         dword bg_color;
  27.         LIST tag_list;
  28.         dword tag_title;
  29. };
  30.  
  31. struct TWebBrowser {
  32.         llist list;
  33.         _style style;
  34.         _img img;
  35.         dword draw_y, stolbec;
  36.         int zoom;
  37.         dword o_bufpointer;
  38.         int cur_encoding, custom_encoding;
  39.         bool link, t_html, t_body;
  40.         dword bufpointer;
  41.         dword bufsize;
  42.         dword is_html;
  43.  
  44.         void Paint();
  45.         void SetPageDefaults();
  46.         void AddCharToTheLine();
  47.         void ParseHtml();
  48.         void SetStyle();
  49.         bool CheckForLineBreak();
  50.         void NewLine();
  51.         void DrawScroller();
  52.         void ChangeEncoding();
  53.         void DrawPage();
  54.         char header[150];
  55.         char redirect[URL_SIZE];
  56. };
  57.  
  58. scroll_bar scroll_wv = { 15,NULL,NULL,NULL,0,2,NULL,0,0,0xeeeeee,0xBBBbbb,0xeeeeee};
  59.  
  60. //============================================================================================
  61. void TWebBrowser::Paint()
  62. {
  63.         dword start_x, line_length, stolbec_len;
  64.         dword text_color__;
  65.        
  66.         if (style.tag_title)
  67.         {
  68.                 strncpy(#header, #line, sizeof(TWebBrowser.header)-1);
  69.                 strncat(#header, " - ", sizeof(TWebBrowser.header)-1);
  70.                 strncat(#header, #version, sizeof(TWebBrowser.header)-1);
  71.                 line = 0;
  72.                 return;
  73.         }
  74.         if (t_html) && (!t_body) {
  75.                 line = 0;
  76.                 return;
  77.         }
  78.        
  79.         if (line)
  80.         {
  81.                 start_x = stolbec * list.font_w + BODY_MARGIN + list.x;
  82.                 stolbec_len = strlen(#line) * zoom;
  83.                 line_length = stolbec_len * list.font_w;
  84.  
  85.                 if (debug_mode) {
  86.                         DrawBuf.DrawBar(start_x, draw_y, line_length, list.item_h, 0xDDDddd);
  87.                 }
  88.  
  89.                 if (style.bg_color!=page_bg) {
  90.                         DrawBuf.DrawBar(start_x, draw_y, line_length, list.item_h, style.bg_color);
  91.                 }
  92.  
  93.                 if (style.image) {
  94.                         DrawBuf.DrawBar(start_x, draw_y, line_length, list.item_h-1, 0xF9DBCB);
  95.                 }
  96.                 if (style.button) {
  97.                         DrawBuf.DrawBar(start_x, draw_y, line_length, list.item_h - calc(zoom*2), 0xCCCccc);
  98.                         DrawBuf.DrawBar(start_x, draw_y + list.item_h - calc(zoom*2), line_length, zoom, 0x999999);
  99.                 }
  100.  
  101.                 text_color__ = text_colors.get_last();
  102.                 if (link) && (text_color__ == text_colors.get(0)) text_color__ = link_color_default;
  103.  
  104.                 DrawBuf.WriteText(start_x, draw_y, list.font_type, text_color__, #line, NULL);
  105.                 if (style.b) DrawBuf.WriteText(start_x+1, draw_y, list.font_type, text_color__, #line, NULL);
  106.                 if (style.s) DrawBuf.DrawBar(start_x, list.item_h / 2 - zoom + draw_y, line_length, zoom, text_color__);
  107.                 if (style.u) DrawBuf.DrawBar(start_x, list.item_h - zoom - zoom + draw_y, line_length, zoom, text_color__);
  108.                 if (link) {
  109.                         if (line[0]==' ') && (line[1]==NULL) {} else {
  110.                                 DrawBuf.DrawBar(start_x, draw_y + list.item_h - calc(zoom*2)-1, line_length, zoom, link_color_default);
  111.                                 links.add_text(start_x, draw_y + list.y, line_length, list.item_h - calc(zoom*2)-1, zoom);                             
  112.                         }
  113.                 }
  114.                 stolbec += stolbec_len;
  115.                 if (debug_mode) debug(#line);
  116.                 line = NULL;
  117.         }
  118. }
  119. //============================================================================================
  120. void TWebBrowser::SetPageDefaults()
  121. {
  122.         style.b = style.u = style.s = style.h = style.blq = t_html = t_body = style.pre =
  123.         link = style.tag_title = style.font = false;
  124.         style.tag_list.reset();
  125.         link_color_default = 0x0000FF;
  126.         link_color_active = 0xFF0000;
  127.         page_bg = 0xEBE8E9; //E0E3E3 EBE8E9
  128.         style.bg_color = page_bg;
  129.         DrawBuf.Fill(0, page_bg);
  130.         links.clear();
  131.         anchors.clear();
  132.         img.clear();
  133.         text_colors.drop();
  134.         text_colors.add(0);
  135.         header = NULL;
  136.         cur_encoding = CH_CP866;
  137.         draw_y = BODY_MARGIN;
  138.         stolbec = 0;
  139.         line = 0;
  140.         zoom = 1;
  141.         redirect = '\0';
  142.         //hold original buffer
  143.         if (o_bufpointer) o_bufpointer=free(o_bufpointer);
  144.         o_bufpointer = malloc(bufsize);
  145.         memmov(o_bufpointer, bufpointer, bufsize);
  146.         if (custom_encoding != -1) {
  147.                 cur_encoding = custom_encoding;
  148.                 bufpointer = ChangeCharset(cur_encoding, "CP866", bufpointer);
  149.         }
  150. }
  151. //============================================================================================
  152. void TWebBrowser::AddCharToTheLine(unsigned char _char)
  153. {
  154.         dword line_len;
  155.         if (_char<=15) _char=' ';
  156.         line_len = strlen(#line);
  157.         if (!style.pre) && (_char == ' ')
  158.         {
  159.                 if (line[line_len-1]==' ') return; //no double spaces
  160.                 if (!stolbec) && (!line) return; //no paces at the beginning of the line
  161.                 if (link) && (line_len==0) return;
  162.         }
  163.         if (line_len < sizeof(line)) chrcat(#line, _char);
  164.         CheckForLineBreak();
  165. }
  166. //============================================================================================
  167. void TWebBrowser::ParseHtml(dword _bufpointer, _bufsize){
  168.         word bukva[2];
  169.         char unicode_symbol[10];
  170.         dword unicode_symbol_result;
  171.         dword j;
  172.         bool ignor_param=false;
  173.         int tab_len;
  174.         dword bufpos;
  175.         bufsize = _bufsize;
  176.         if (bufpointer != _bufpointer) {
  177.                 bufpointer = malloc(bufsize);
  178.                 memmov(bufpointer, _bufpointer, bufsize);
  179.         } else {
  180.                 custom_encoding = CH_CP866;    
  181.         }
  182.         SetPageDefaults();
  183.         is_html = true;
  184.         if (!strstri(bufpointer, "<body")) {
  185.                 t_body = true;
  186.                 if (!strstri(bufpointer, "<html")) && (!strstr(bufpointer, "<?xml")) && (!strstr(bufpointer, "<xml")) {
  187.                         style.pre = true; //show linebreaks for a plaint text
  188.                         is_html = false;
  189.                 }
  190.         }
  191.         for (bufpos=bufpointer ; (bufpos < bufpointer+bufsize) && (ESBYTE[bufpos]!=0) ; bufpos++;)
  192.         {
  193.                 //bukva = ESBYTE[bufpos];
  194.                 switch (ESBYTE[bufpos])
  195.                 {
  196.                 case 0x0a:
  197.                         if (style.pre) {
  198.                                 Paint();
  199.                                 NewLine();
  200.                         } else {
  201.                                 AddCharToTheLine(0x0a);
  202.                         }
  203.                         break;
  204.                 case 0x09:
  205.                         if (style.pre) {
  206.                                 tab_len = strlen(#line) + stolbec % 4;
  207.                                 if (!tab_len) tab_len = 4; else tab_len = 4 - tab_len;
  208.                                 for (j=0; j<tab_len; j++;) chrcat(#line,' ');
  209.                         } else {
  210.                                 AddCharToTheLine(0x09);
  211.                         }
  212.                         break;
  213.                 case '&': //&nbsp; and so on
  214.                         for (j=1, unicode_symbol=0; (ESBYTE[bufpos+j]<>';') && (!__isWhite(ESBYTE[bufpos+j])) && (j<8); j++)
  215.                         {
  216.                                 bukva = ESBYTE[bufpos+j];
  217.                                 chrcat(#unicode_symbol, bukva);
  218.                         }
  219.                         if (GetUnicodeSymbol(#line, #unicode_symbol, sizeof(line)-1)) {
  220.                                 bufpos += j;
  221.                                 CheckForLineBreak();
  222.                         } else {
  223.                                 AddCharToTheLine('&');
  224.                         }
  225.                         break;
  226.                 case '<':
  227.                         if (!is_html) goto _DEFAULT;
  228.                         bufpos++;
  229.                         switch (ESBYTE[bufpos]) {
  230.                                 case '!':
  231.                                 case '/':
  232.                                 case 'a'...'z':
  233.                                 case 'A'...'Z':
  234.                                         goto _TAG;
  235.                                 default:
  236.                                         goto _DEFAULT;
  237.                         }
  238.                         _TAG:
  239.                         if (!strncmp(bufpos,"!--",3))
  240.                         {
  241.                                 bufpos+=3;
  242.                                 //STRSTR
  243.                                 while (strncmp(bufpos,"-->",3)!=0) && (bufpos < bufpointer + bufsize)
  244.                                 {
  245.                                         bufpos++;
  246.                                 }
  247.                                 bufpos+=2;
  248.                                 break;
  249.                         }
  250.                         tag.reset();
  251.                         if (ESBYTE[bufpos] == '/') {
  252.                                 tag.opened = false;
  253.                                 bufpos++;
  254.                         }
  255.  
  256.                         ignor_param=false;
  257.                         while (ESBYTE[bufpos] !='>') && (bufpos < bufpointer + bufsize) //ïîëó÷àåì òåã è åãî ïàðàìåòðû
  258.                         //&& (!chrnum(#tag.params,'\"') % 2) //<a title="<small>ATI</small><br>9800xt" href="vgamuseum.ru/9800xt">
  259.                         {
  260.                                 bukva = ESBYTE[bufpos];
  261.                                 if (__isWhite(bukva)) bukva = ' ';
  262.                                 if (!ignor_param) && (bukva!=' ') {
  263.                                         if (strlen(#tag.name)+1<sizeof(tag.name)) chrcat(#tag.name, bukva);
  264.                                 } else {
  265.                                         ignor_param = true;
  266.                                         if (strlen(#tag.params)+1<sizeof(tag.params)) strcat(#tag.params, #bukva);
  267.                                         //chrncat(#tag.params, bukva, sizeof(tag.params)-1);
  268.                                 }
  269.                                 bufpos++;
  270.                         }
  271.                         strlwr(#tag.name);
  272.  
  273.                         // ignore text inside the next tags
  274.                         if (tag.is("script")) || (tag.is("style")) || (tag.is("binary")) || (tag.is("select"))  {
  275.                                 sprintf(#tag.params, "</%s>", #tag.name);
  276.                                 if (j = strstri(bufpos, #tag.params)) bufpos = j-1;
  277.                                 break;
  278.                         }
  279.  
  280.                         if (tag.name[strlen(#tag.name)-1]=='/') tag.name[strlen(#tag.name)-1]=NULL; //for br/ !!!!!!!!
  281.                         if (tag.params) tag.parse_params();
  282.  
  283.                         if (tag.name) {
  284.                                 CheckForLineBreak();
  285.                                 Paint();
  286.                                 if (tag.name) SetStyle();
  287.                         }
  288.                         break;
  289.                 default:
  290.                         _DEFAULT:
  291.                         AddCharToTheLine(ESBYTE[bufpos]);
  292.                 }
  293.         }
  294.         Paint();
  295.         NewLine();
  296.         list.count = draw_y;
  297.         list.CheckDoesValuesOkey();
  298.         anchors.current = NULL;
  299.         custom_encoding = -1;
  300.         if (!header) {
  301.                 strncpy(#header, #version, sizeof(TWebBrowser.header)-1);
  302.                 DrawTitle(#header);
  303.         }
  304. }
  305. //============================================================================================
  306. bool TWebBrowser::CheckForLineBreak()
  307. {
  308.         int line_break_pos;
  309.         char new_line_text[4096];
  310.         //Do we need a line break?
  311.         if (strlen(#line)*zoom + stolbec < list.column_max) return false;
  312.         //Yes, we do. Lets calculate where...
  313.         line_break_pos = strrchr(#line, ' ');
  314.         //Is a new line fits in the current line?
  315.         if (line_break_pos*zoom + stolbec > list.column_max) {
  316.                 line_break_pos = list.column_max/zoom - stolbec;
  317.                 while(line_break_pos) && (line[line_break_pos]!=' ') line_break_pos--;
  318.         }
  319.         //Maybe a new line is too big for the whole new line? Then we have to split it
  320.         if (!line_break_pos) && (style.tag_list.level*5 + strlen(#line) * zoom >= list.column_max) {
  321.                 line_break_pos = list.column_max/zoom - stolbec;
  322.         }
  323.         strcpy(#new_line_text, #line + line_break_pos);
  324.         line[line_break_pos] = 0x00;           
  325.        
  326.         Paint();
  327.  
  328.         strcpy(#line, #new_line_text);
  329.         NewLine();
  330.         //while (CheckForLineBreak()==true) {};
  331.         return true;
  332. }
  333. //============================================================================================
  334. void TWebBrowser::SetStyle() {
  335.         char img_path[4096]=0;
  336.  
  337.         dword value;
  338.  
  339.         if (value = tag.get_value_of("name=")) || (value = tag.get_value_of("id=")) {
  340.                 anchors.add(value, draw_y);
  341.                 if (anchors.current) && (streq(value, #anchors.current+1)) {
  342.                         list.first = draw_y;
  343.                         anchors.current = NULL;
  344.                 }
  345.         }
  346.         if (tag.is("html")) {
  347.                 t_html = tag.opened;
  348.                 return;
  349.         }
  350.         if (tag.is("title")) {
  351.                 style.tag_title = tag.opened;
  352.                 if (!tag.opened) DrawTitle(#header);
  353.                 return;
  354.         }
  355.         if (tag.is("body")) {
  356.                 t_body = tag.opened;
  357.                 if (value = tag.get_value_of("link="))   link_color_default = GetColor(value);
  358.                 if (value = tag.get_value_of("alink="))  link_color_active = GetColor(value);
  359.                 if (value = tag.get_value_of("text="))   text_colors.set(0, GetColor(value));
  360.                 if (value = tag.get_value_of("bgcolor=")) {
  361.                         style.bg_color = page_bg = GetColor(value);
  362.                         DrawBuf.Fill(0, page_bg);
  363.                 }
  364.                 // Autodetecting encoding if no encoding was set
  365.                 if (tag.opened) && (custom_encoding==-1) && (cur_encoding == CH_CP866) {
  366.                         if (strstr(bufpointer, "\208\190")) ChangeEncoding(CH_UTF8);
  367.                         else if (chrnum(bufpointer, '\246')>5) ChangeEncoding(CH_CP1251);
  368.                 }
  369.                 return;
  370.         }
  371.         if (tag.is("br")) { NewLine(); return; }
  372.         if (tag.is("b")) || (tag.is("strong")) || (tag.is("big")) || (tag.is("w:b")) {
  373.                 style.b = tag.opened;
  374.                 return;
  375.         }
  376.         if (tag.is("w:r")) && (!tag.opened) { style.b = false; return; }
  377.         if (tag.is("a")) {
  378.                 if (tag.opened)
  379.                 {
  380.                         if (value = tag.get_value_of("href=")) && (!strstr(value,"javascript:"))
  381.                         {
  382.                                 link = true;
  383.                                 links.add_link(value);
  384.                         }
  385.                 } else {
  386.                         link = false;
  387.                         style.bg_color = page_bg;
  388.                 }
  389.                 return;
  390.         }
  391.         if (tag.is("iframe")) && (value = tag.get_value_of("src=")) {
  392.                 NewLine();
  393.                 strcpy(#line, "IFRAME: ");
  394.                 Paint();
  395.                 link=true;
  396.                 links.add_link(value);
  397.                 strncpy(#line, value, sizeof(line)-1);
  398.                 while (CheckForLineBreak()) {};
  399.                 Paint();
  400.                 link=false;
  401.                 NewLine();
  402.         }
  403.         if (tag.is("font")) {
  404.                 style.font = tag.opened;
  405.                 style.bg_color = page_bg;
  406.                 if (tag.opened)
  407.                 {
  408.                         if (value = tag.get_value_of("bg=")) style.bg_color = GetColor(value);
  409.                         if (value = tag.get_value_of("color=")) {
  410.                                 text_colors.add(GetColor(value));
  411.                         } else {
  412.                                 text_colors.add(text_colors.get_last());
  413.                         }
  414.                 }
  415.                 else text_colors.pop();
  416.                 return;
  417.         }
  418.         if (tag.is("div")) {
  419.                 if (streq(#tag.prior,"div")) && (tag.opened) return;
  420.                 if (!tag.opened) && (style.font) text_colors.pop();
  421.                 NewLine();
  422.                 return;
  423.         }
  424.         if (tag.is("header")) || (tag.is("article")) || (tag.is("footer")) || (tag.is("figure")) {
  425.                 NewLine();
  426.                 return;
  427.         }
  428.         if (tag.is("p")) || (tag.is("w:p"))  {
  429.                 IF (tag.prior[0] == 'h') || (streq(#tag.prior,"td")) || (streq(#tag.prior,"p")) return;
  430.                 NewLine();
  431.                 return;
  432.         }
  433.         if (tag.is("pre")) { style.pre = tag.opened; return; }
  434.         if (tag.is("td")) { if (tag.opened) AddCharToTheLine(' '); return; }
  435.         if (tag.is("tr")) { if (tag.opened) NewLine(); return; }
  436.         if (tag.is("button")) { style.button = tag.opened; stolbec++; return; }
  437.         if (tag.is("u")) || (tag.is("ins")) { style.u=tag.opened; return;}
  438.         if (tag.is("s")) || (tag.is("strike")) || (tag.is("del")) { style.s=tag.opened; return; }
  439.         if (tag.is("dl")) {
  440.                 if (tag.opened) NewLine();
  441.                 return;
  442.         }
  443.         if (tag.is("dd")) {
  444.                 //NewLine();
  445.                 //if (tag.opened) stolbec += 5;  //stolbec overflow!
  446.                 return;
  447.         }
  448.         if (tag.is("blockquote")) { style.blq = tag.opened; return; }
  449.         if (tag.is("code")) {
  450.                 if (tag.opened) style.bg_color = 0xe4ffcb; else style.bg_color = page_bg;
  451.                 style.pre = tag.opened; return;
  452.         }
  453.         if (tag.is("img")) {
  454.                 value = tag.get_value_of("src=");
  455.                 if (!value) value = tag.get_value_of("data-src=");
  456.                 if (!value) goto NOIMG;
  457.  
  458.                 if (!strcmp(value + strrchr(value, '.'), "svg")) goto NOIMG;
  459.  
  460.                 strlcpy(#img_path, value, sizeof(img_path)-1);
  461.                 get_absolute_url(#img_path, history.current());
  462.  
  463.                 //if (check_is_the_adress_local(#img_path)) <== load local files
  464.                 if (cache.has(#img_path)) && (cache.current_size)
  465.                 {
  466.                         img_decode stdcall (cache.current_buf, cache.current_size, 0);
  467.                         if (!EAX) goto NOIMG;
  468.  
  469.                         EDI = EAX;
  470.                         img.w.add(ESDWORD[EDI+4]);
  471.                         img.h.add(ESDWORD[EDI+8]);
  472.                         img_destroy stdcall(EDI);
  473.  
  474.                         img.url.add(#img_path);
  475.  
  476.                         if (img.w.get_last() / 6 + stolbec > list.column_max) {
  477.                                 NewLine();
  478.                         }
  479.                         img.x.add(stolbec*list.font_w+3);
  480.                         img.y.add(draw_y);
  481.  
  482.                         stolbec += img.w.get_last() / 6;
  483.                         if (stolbec > list.column_max) NewLine();
  484.  
  485.                         if (img.h.get_last() > list.item_h) {
  486.                                 draw_y += img.h.get_last() - list.item_h;
  487.                                 NewLine();
  488.                         }
  489.  
  490.                         if (link) links.add_text(
  491.                                 img.x.get_last() + list.x,
  492.                                 img.y.get_last() + list.y,
  493.                                 img.w.get_last(),
  494.                                 img.h.get_last(),
  495.                                 0);
  496.  
  497.  
  498.                         return;
  499.                 } else {
  500.                         img.url.add(#img_path);
  501.                 }
  502.                 NOIMG:
  503.  
  504.                 /*
  505.                 if (streqrp(value, "data:")) {
  506.                         EAX = strstr(value, "base64,");
  507.                         if (value == EAX) return;
  508.                         value = EAX;
  509.                         //cache.add(history.current(), http.content_pointer, http.content_received, PAGE);
  510.                         base64_decode stdcall (#pass_b64, value, strlen(value));
  511.                 } else
  512.                 */
  513.  
  514.                 if (value = tag.get_value_of("title=")) && (strlen(value)<sizeof(line)-3) && (value) sprintf(#line, "[%s]", value);
  515.                 if (value = tag.get_value_of("alt=")) && (strlen(value)<sizeof(line)-3) && (value) sprintf(#line, "[%s]", value);
  516.                 if (!line) {
  517.                         if (!strncmp(#img_path, "data:", 5)) img_path=0;
  518.                         replace_char(#img_path, '?', NULL, strlen(#img_path));
  519.                         img_path[sizeof(line)-3] = '\0'; //prevent overflow in sprintf
  520.                         sprintf(#line, "[%s]", #img_path+strrchr(#img_path, '/'));
  521.                         line[50]= NULL;
  522.                 }
  523.                 while (CheckForLineBreak()) {};
  524.  
  525.                 text_colors.add(0x9A6F29);
  526.                 style.image = true;
  527.                 Paint();
  528.                 style.image = false;
  529.                 text_colors.pop();
  530.                 return;
  531.         }
  532.         if (tag.is("h4")) {
  533.                 NewLine();
  534.                 NewLine();
  535.                 style.h = tag.opened;
  536.                 style.b = tag.opened;
  537.         }
  538.         if (tag.is("h1")) || (tag.is("h2")) || (tag.is("h3")) || (tag.is("caption")) {
  539.                 style.h = tag.opened;
  540.                 if (tag.opened) {
  541.                         if (!style.pre) NewLine();
  542.                         draw_y += 10;
  543.                         zoom=2;
  544.                         list.font_type |= 10011001b;
  545.                         list.item_h = BASIC_LINE_H * 2 - 2;
  546.                         if (tag.is("h1")) style.b = true;
  547.                 } else {
  548.                         if (tag.is("h1")) style.b = false;
  549.                         NewLine();
  550.                         zoom=1;
  551.                         list.font_type = 10011000b;
  552.                         list.item_h = BASIC_LINE_H;
  553.                 }
  554.                 return;
  555.         }
  556.         if (tag.is("dt")) {
  557.                 style.tag_list.upd_level(tag.opened, DT);
  558.                 if (tag.opened) NewLine();
  559.                 return;
  560.         }
  561.         if (tag.is("ul")) {
  562.                 style.tag_list.upd_level(tag.opened, UL);
  563.                 if (!tag.opened) && (!style.pre) NewLine();
  564.                 return;
  565.         }
  566.         if (tag.is("ol")) {
  567.                 style.tag_list.upd_level(tag.opened, OL);      
  568.                 if (!tag.opened) && (!style.pre) NewLine();
  569.                 return;
  570.         }
  571.         if (tag.is("li")) && (tag.opened)
  572.         {
  573.                 if (!style.tag_list.level) style.tag_list.upd_level(1, UL);
  574.                 if (!style.pre) NewLine();
  575.                 if (style.tag_list.get_order_type() == UL) {
  576.                         strcpy(#line, "\31 ");
  577.                         stolbec = style.tag_list.level * 5 - 2;
  578.                 }
  579.                 if (style.tag_list.get_order_type() == OL) {
  580.                         sprintf(#line, "%i. ", style.tag_list.inc_counter());
  581.                         stolbec = style.tag_list.level * 5 - strlen(#line);
  582.                 }
  583.                 return;
  584.         }
  585.         if (tag.is("q"))
  586.         {
  587.                 if (tag.opened) {
  588.                         EAX = strlen(#line);
  589.                         if (line[EAX-1] != ' ') chrcat(#line, ' ');
  590.                         chrcat(#line, '\"');
  591.                 }
  592.                 if (!tag.opened) strcat(#line, "\" ");
  593.                 return;
  594.         }
  595.         if (tag.is("hr")) {
  596.                 if (value = tag.get_value_of("color=")) EDI = GetColor(value); else EDI = 0x999999;
  597.                 $push edi;
  598.                 NewLine();
  599.                 $pop edi;
  600.                 draw_y += 10;
  601.                 DrawBuf.DrawBar(5, draw_y - 1, list.w-10, 1, EDI);
  602.                 NewLine();
  603.                 draw_y += 10;
  604.                 return;
  605.         }
  606.         if (tag.is("meta")) {
  607.                 if (streq(tag.get_value_of("http-equiv="), "refresh")) && (value = tag.get_value_of("content=")) {
  608.                         if (value = strstri(value, "url=")) strcpy(#redirect, value);
  609.                 }
  610.         }
  611.         if (custom_encoding == -1) && (tag.is("meta")) || (tag.is("?xml")) {
  612.                 if (value = tag.get_value_of("charset=")) || (value = tag.get_value_of("content=")) || (value = tag.get_value_of("encoding="))
  613.                 {
  614.                         value += strrchr(value, '='); //search in content=
  615.                         if (ESBYTE[value] == '"') value++;
  616.                         strlwr(value);
  617.                         if      (streqrp(value,"utf-8"))        || (streqrp(value,"utf8"))        ChangeEncoding(CH_UTF8);
  618.                         else if (streqrp(value,"windows-1251")) || (streqrp(value,"windows1251")) ChangeEncoding(CH_CP1251);
  619.                         else if (streqrp(value,"dos"))          || (streqrp(value,"cp-866"))      ChangeEncoding(CH_CP866);
  620.                         else if (streqrp(value,"iso-8859-5"))   || (streqrp(value,"iso8859-5"))   ChangeEncoding(CH_ISO8859_5);
  621.                         else if (streqrp(value,"koi8-r"))       || (streqrp(value,"koi8-u"))      ChangeEncoding(CH_KOI8);
  622.                 }
  623.                 return;
  624.         }
  625. }
  626. //============================================================================================
  627. void TWebBrowser::DrawScroller()
  628. {
  629.         scroll_wv.max_area = list.count;
  630.         scroll_wv.cur_area = list.visible;
  631.         scroll_wv.position = list.first;
  632.         scroll_wv.all_redraw = 0;
  633.         scroll_wv.start_x = list.x + list.w;
  634.         scroll_wv.start_y = list.y;
  635.         scroll_wv.size_y = list.h;
  636.         scrollbar_v_draw(#scroll_wv);
  637. }
  638. //============================================================================================
  639. void TWebBrowser::ChangeEncoding(int _new_encoding)
  640. {
  641.         if (cur_encoding == _new_encoding) return;
  642.         cur_encoding = _new_encoding;
  643.         bufpointer = ChangeCharset(cur_encoding, "CP866", bufpointer);
  644.         if (header) {
  645.                 ChangeCharset(cur_encoding, "CP866", #header);
  646.                 DrawTitle(#header);
  647.         }
  648. }
  649. //============================================================================================
  650. void TWebBrowser::NewLine()
  651. {
  652.         dword onleft, ontop;
  653.         static int empty_line=0;
  654.  
  655.         if (!stolbec) && (draw_y==BODY_MARGIN) return;
  656.        
  657.         if (style.tag_list.level) && (stolbec == style.tag_list.level * 5) {
  658.                 if (empty_line<1) empty_line++;
  659.                 else return;
  660.         } else if (!stolbec) {
  661.                 if (empty_line<1) empty_line++;
  662.                 else return;
  663.         } else {
  664.                 empty_line=0;
  665.         }
  666.  
  667.         onleft = list.x + BODY_MARGIN;
  668.         ontop = draw_y + list.y;
  669.         if (t_html) && (!t_body) return;
  670.         draw_y += list.item_h;
  671.         if (style.blq) stolbec = 6; else stolbec = 0;
  672.         stolbec += style.tag_list.level * 5;
  673.         if (debug_mode) debugln(NULL);
  674. }
  675. //============================================================================================
  676. void TWebBrowser::DrawPage()
  677. {
  678.         int i, img_y;
  679.         PutPaletteImage(list.first * DrawBuf.bufw * 4 + buf_data+8, DrawBuf.bufw, list.h, DrawBuf.bufx, DrawBuf.bufy, 32, 0);
  680.         DrawScroller();
  681.         //img.draw_all(list.x, list.y, list.w, list.h, list.first);
  682.  
  683.         for (i=0; i<img.url.count; i++)
  684.         {
  685.                 img_y = img.y.get(i);
  686.  
  687.                 if (img_y + img.h.get(i) > list.first) && (img_y - list.h < list.first)
  688.                 && (cache.has(img.url.get(i))) img.draw(list.x, list.y, list.w, list.h, list.first, i);
  689.         }
  690. }