Subversion Repositories Kolibri OS

Rev

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