Subversion Repositories Kolibri OS

Rev

Rev 8396 | Rev 8410 | 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\tag_list.h"
  6. dword page_bg;
  7. dword link_color_default;
  8. dword link_color_active;
  9. #include "TWB\links.h"
  10.  
  11. #define BODY_MARGIN 6
  12. #define BASIC_LINE_H 18
  13.  
  14. DrawBufer DrawBuf;
  15. char line[500];
  16.  
  17. struct _style {
  18.         bool
  19.         b, u, s, h,
  20.         font,
  21.         pre,
  22.         blq,
  23.         button,
  24.         image;
  25.         dword bg_color;
  26.         LIST tag_list;
  27.         dword tag_title;
  28. };
  29.  
  30. struct TWebBrowser {
  31.         llist list;
  32.         _style style;
  33.         dword draw_y, stolbec;
  34.         int zoom;
  35.         dword o_bufpointer;
  36.         int cur_encoding, custom_encoding;
  37.         bool link, t_html, t_body;
  38.         dword bufpointer;
  39.         dword bufsize;
  40.         dword is_html;
  41.         collection img_url;
  42.  
  43.         void Paint();
  44.         void SetPageDefaults();
  45.         void AddCharToTheLine();
  46.         void ParseHtml();
  47.         void SetStyle();
  48.         bool CheckForLineBreak();
  49.         void NewLine();
  50.         void DrawScroller();
  51.         void ChangeEncoding();
  52.         void DrawPage();
  53.         char header[150];
  54.         char redirect[URL_SIZE];
  55. };
  56.  
  57. scroll_bar scroll_wv = { 15,NULL,NULL,NULL,0,2,NULL,0,0,0xeeeeee,0xBBBbbb,0xeeeeee};
  58.  
  59. //============================================================================================
  60. void TWebBrowser::Paint()
  61. {
  62.         dword start_x, line_length, stolbec_len;
  63.         dword text_color__;
  64.        
  65.         if (style.tag_title)
  66.         {
  67.                 strncpy(#header, #line, sizeof(TWebBrowser.header)-1);
  68.                 strncat(#header, " - ", sizeof(TWebBrowser.header)-1);
  69.                 strncat(#header, #version, sizeof(TWebBrowser.header)-1);
  70.                 line = 0;
  71.                 return;
  72.         }
  73.         if (t_html) && (!t_body) {
  74.                 line = 0;
  75.                 return;
  76.         }
  77.        
  78.         if (line)
  79.         {
  80.                 start_x = stolbec * list.font_w + BODY_MARGIN + list.x;
  81.                 stolbec_len = strlen(#line) * zoom;
  82.                 line_length = stolbec_len * list.font_w;
  83.  
  84.                 if (debug_mode) {
  85.                         DrawBuf.DrawBar(start_x, draw_y, line_length, list.item_h, 0xDDDddd);
  86.                 }
  87.  
  88.                 if (style.bg_color!=page_bg) {
  89.                         DrawBuf.DrawBar(start_x, draw_y, line_length, list.item_h, style.bg_color);
  90.                 }
  91.  
  92.                 if (style.image) {
  93.                         DrawBuf.DrawBar(start_x, draw_y, line_length, list.item_h-1, 0xF9DBCB);
  94.                 }
  95.                 if (style.button) {
  96.                         DrawBuf.DrawBar(start_x, draw_y, line_length, list.item_h - calc(zoom*2), 0xCCCccc);
  97.                         DrawBuf.DrawBar(start_x, draw_y + list.item_h - calc(zoom*2), line_length, zoom, 0x999999);
  98.                 }
  99.  
  100.                 text_color__ = text_colors.get_last();
  101.                 if (link) && (text_color__ == text_colors.get(0)) text_color__ = link_color_default;
  102.  
  103.                 DrawBuf.WriteText(start_x, draw_y, list.font_type, text_color__, #line, NULL);
  104.                 if (style.b) DrawBuf.WriteText(start_x+1, draw_y, list.font_type, text_color__, #line, NULL);
  105.                 if (style.s) DrawBuf.DrawBar(start_x, list.item_h / 2 - zoom + draw_y, line_length, zoom, text_color__);
  106.                 if (style.u) DrawBuf.DrawBar(start_x, list.item_h - zoom - zoom + draw_y, line_length, zoom, text_color__);
  107.                 if (link) {
  108.                         if (line[0]==' ') && (line[1]==NULL) {} else {
  109.                                 DrawBuf.DrawBar(start_x, draw_y + list.item_h - calc(zoom*2)-1, line_length, zoom, link_color_default);
  110.                                 links.add_text(start_x, draw_y + list.y, line_length, list.item_h - calc(zoom*2)-1, zoom);                             
  111.                         }
  112.                 }
  113.                 stolbec += stolbec_len;
  114.                 if (debug_mode) debug(#line);
  115.                 line = NULL;
  116.         }
  117. }
  118. //============================================================================================
  119. void TWebBrowser::SetPageDefaults()
  120. {
  121.         style.b = style.u = style.s = style.h = style.blq = t_html = t_body = style.pre =
  122.         link = style.tag_title = style.font = false;
  123.         style.tag_list.reset();
  124.         link_color_default = 0x0000FF;
  125.         link_color_active = 0xFF0000;
  126.         page_bg = 0xffEBE8E9; //E0E3E3 EBE8E9
  127.         style.bg_color = page_bg;
  128.         DrawBuf.Fill(0, page_bg);
  129.         links.clear();
  130.         anchors.clear();
  131.         img_url.drop();
  132.         text_colors.drop();
  133.         text_colors.add(0);
  134.         header = NULL;
  135.         cur_encoding = CH_CP866;
  136.         draw_y = BODY_MARGIN;
  137.         stolbec = 0;
  138.         line = 0;
  139.         zoom = 1;
  140.         redirect = '\0';
  141.         //hold original buffer
  142.         if (o_bufpointer) o_bufpointer=free(o_bufpointer);
  143.         o_bufpointer = malloc(bufsize);
  144.         memmov(o_bufpointer, bufpointer, bufsize);
  145.         if (custom_encoding != -1) {
  146.                 cur_encoding = custom_encoding;
  147.                 bufpointer = ChangeCharset(cur_encoding, "CP866", bufpointer);
  148.         }
  149. }
  150. //============================================================================================
  151. void TWebBrowser::AddCharToTheLine(unsigned char _char)
  152. {
  153.         dword line_len;
  154.         if (_char<=15) _char=' ';
  155.         line_len = strlen(#line);
  156.         if (!style.pre) && (_char == ' ')
  157.         {
  158.                 if (line[line_len-1]==' ') return; //no double spaces
  159.                 if (!stolbec) && (!line) return; //no paces at the beginning of the line
  160.                 if (link) && (line_len==0) return;
  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) {
  286.                                         EAX = cur_encoding;
  287.                                         $push eax
  288.                                         SetStyle();
  289.                                         $pop eax
  290.                                         // The thing is that UTF if longer than other encodings.
  291.                                         // So if encoding was changed to UTF than $bufpos position is wrong now,
  292.                                         // and we have to start parse from the very beginning
  293.                                         if (EAX != cur_encoding) && (cur_encoding == CH_UTF8) {
  294.                                                 ParseHtml(bufpointer, bufsize);
  295.                                                 return;
  296.                                         }
  297.                                 }
  298.                         }
  299.                         break;
  300.                 default:
  301.                         _DEFAULT:
  302.                         AddCharToTheLine(ESBYTE[bufpos]);
  303.                 }
  304.         }
  305.         Paint();
  306.         NewLine();
  307.         list.count = draw_y;
  308.         list.CheckDoesValuesOkey();
  309.         anchors.current = NULL;
  310.         custom_encoding = -1;
  311.         if (!header) {
  312.                 strncpy(#header, #version, sizeof(TWebBrowser.header)-1);
  313.                 DrawTitle(#header);
  314.         }
  315. }
  316. //============================================================================================
  317. bool TWebBrowser::CheckForLineBreak()
  318. {
  319.         int line_break_pos;
  320.         char new_line_text[4096];
  321.         //Do we need a line break?
  322.         if (strlen(#line)*zoom + stolbec < list.column_max) return false;
  323.         //Yes, we do. Lets calculate where...
  324.         line_break_pos = strrchr(#line, ' ');
  325.         //Is a new line fits in the current line?
  326.         if (line_break_pos*zoom + stolbec > list.column_max) {
  327.                 line_break_pos = list.column_max/zoom - stolbec;
  328.                 while(line_break_pos) && (line[line_break_pos]!=' ') line_break_pos--;
  329.         }
  330.         //Maybe a new line is too big for the whole new line? Then we have to split it
  331.         if (!line_break_pos) && (style.tag_list.level*5 + strlen(#line) * zoom >= list.column_max) {
  332.                 line_break_pos = list.column_max/zoom - stolbec;
  333.         }
  334.         strcpy(#new_line_text, #line + line_break_pos);
  335.         line[line_break_pos] = 0x00;           
  336.        
  337.         Paint();
  338.  
  339.         strcpy(#line, #new_line_text);
  340.         NewLine();
  341.         //while (CheckForLineBreak()==true) {};
  342.         return true;
  343. }
  344. //============================================================================================
  345. void TWebBrowser::SetStyle() {
  346.         char img_path[4096]=0;
  347.         dword imgbuf[44];
  348.         dword cur_img;
  349.         int img_x, img_y, img_w, img_h;
  350.  
  351.         dword value;
  352.  
  353.         if (value = tag.get_value_of("name=")) || (value = tag.get_value_of("id=")) {
  354.                 anchors.add(value, draw_y);
  355.                 if (anchors.current) && (streq(value, #anchors.current+1)) {
  356.                         list.first = draw_y;
  357.                         anchors.current = NULL;
  358.                 }
  359.         }
  360.         if (tag.is("html")) {
  361.                 t_html = tag.opened;
  362.                 return;
  363.         }
  364.         if (tag.is("title")) {
  365.                 style.tag_title = tag.opened;
  366.                 if (!tag.opened) DrawTitle(#header);
  367.                 return;
  368.         }
  369.         if (tag.is("body")) {
  370.                 t_body = tag.opened;
  371.                 if (value = tag.get_value_of("link="))   link_color_default = GetColor(value);
  372.                 if (value = tag.get_value_of("alink="))  link_color_active = GetColor(value);
  373.                 if (value = tag.get_value_of("text="))   text_colors.set(0, GetColor(value));
  374.                 if (value = tag.get_value_of("bgcolor=")) {
  375.                         style.bg_color = page_bg = GetColor(value);
  376.                         DrawBuf.Fill(0, page_bg);
  377.                 }
  378.                 // Autodetecting encoding if no encoding was set
  379.                 if (tag.opened) && (custom_encoding==-1) && (cur_encoding == CH_CP866) {
  380.                         if (strstr(bufpointer, "\208\190")) ChangeEncoding(CH_UTF8);
  381.                         else if (chrnum(bufpointer, '\246')>5) ChangeEncoding(CH_CP1251);
  382.                 }
  383.                 return;
  384.         }
  385.         if (tag.is("br")) { NewLine(); return; }
  386.         if (tag.is("b")) || (tag.is("strong")) || (tag.is("big")) || (tag.is("w:b")) {
  387.                 style.b = tag.opened;
  388.                 return;
  389.         }
  390.         if (tag.is("w:r")) && (!tag.opened) { style.b = false; return; }
  391.         if (tag.is("a")) {
  392.                 if (tag.opened)
  393.                 {
  394.                         if (value = tag.get_value_of("href=")) && (!strstr(value,"javascript:"))
  395.                         {
  396.                                 link = true;
  397.                                 links.add_link(value);
  398.                         }
  399.                 } else {
  400.                         link = false;
  401.                         style.bg_color = page_bg;
  402.                 }
  403.                 return;
  404.         }
  405.         if (tag.is("iframe")) && (value = tag.get_value_of("src=")) {
  406.                 NewLine();
  407.                 strcpy(#line, "IFRAME: ");
  408.                 Paint();
  409.                 link=true;
  410.                 links.add_link(value);
  411.                 strncpy(#line, value, sizeof(line)-1);
  412.                 while (CheckForLineBreak()) {};
  413.                 Paint();
  414.                 link=false;
  415.                 NewLine();
  416.         }
  417.         if (tag.is("font")) {
  418.                 style.font = tag.opened;
  419.                 style.bg_color = page_bg;
  420.                 if (tag.opened)
  421.                 {
  422.                         if (value = tag.get_value_of("bg=")) style.bg_color = GetColor(value);
  423.                         if (value = tag.get_value_of("color=")) {
  424.                                 text_colors.add(GetColor(value));
  425.                         } else {
  426.                                 text_colors.add(text_colors.get_last());
  427.                         }
  428.                 }
  429.                 else text_colors.pop();
  430.                 return;
  431.         }
  432.         if (tag.is("div")) {
  433.                 if (streq(#tag.prior,"div")) && (tag.opened) return;
  434.                 if (!tag.opened) && (style.font) text_colors.pop();
  435.                 NewLine();
  436.                 return;
  437.         }
  438.         if (tag.is("header")) || (tag.is("article")) || (tag.is("footer")) || (tag.is("figure")) {
  439.                 NewLine();
  440.                 return;
  441.         }
  442.         if (tag.is("p")) || (tag.is("w:p"))  {
  443.                 IF (tag.prior[0] == 'h') || (streq(#tag.prior,"td")) || (streq(#tag.prior,"p")) return;
  444.                 NewLine();
  445.                 return;
  446.         }
  447.         if (tag.is("pre")) { style.pre = tag.opened; return; }
  448.         if (tag.is("td")) { if (tag.opened) AddCharToTheLine(' '); return; }
  449.         if (tag.is("tr")) { if (tag.opened) NewLine(); return; }
  450.         if (tag.is("button")) { style.button = tag.opened; stolbec++; return; }
  451.         if (tag.is("u")) || (tag.is("ins")) { style.u=tag.opened; return;}
  452.         if (tag.is("s")) || (tag.is("strike")) || (tag.is("del")) { style.s=tag.opened; return; }
  453.         if (tag.is("dl")) {
  454.                 if (tag.opened) NewLine();
  455.                 return;
  456.         }
  457.         if (tag.is("dd")) {
  458.                 //NewLine();
  459.                 //if (tag.opened) stolbec += 5;  //stolbec overflow!
  460.                 return;
  461.         }
  462.         if (tag.is("blockquote")) { style.blq = tag.opened; return; }
  463.         if (tag.is("code")) {
  464.                 if (tag.opened) style.bg_color = 0xe4ffcb; else style.bg_color = page_bg;
  465.                 style.pre = tag.opened; return;
  466.         }
  467.         if (tag.is("img")) {
  468.                 value = tag.get_value_of("src=");
  469.                 if (!value) goto NOIMG;
  470.  
  471.                 if (!strcmp(value + strrchr(value, '.'), "svg")) goto NOIMG;
  472.  
  473.                 if (streqrp(value, "data:")) {
  474.                         if (!strstr(value, "base64,")) goto NOIMG;
  475.                         value = EAX+7;
  476.                         if (ESBYTE[value]==' ') value++;
  477.                         cur_img = malloc(strlen(value));
  478.                         base64_decode stdcall (value, cur_img, strlen(value));
  479.                         img_decode stdcall (cur_img, EAX, 0);
  480.                         $push eax
  481.                         free(cur_img);
  482.                         $pop eax
  483.                         if (EAX) goto IMGOK; else goto NOIMG;
  484.                 }
  485.  
  486.                 strlcpy(#img_path, value, sizeof(img_path)-1);
  487.                 get_absolute_url(#img_path, history.current());
  488.  
  489.                 if (check_is_the_adress_local(#img_path)) {
  490.                         img_from_file stdcall(#img_path);
  491.                         if (EAX) goto IMGOK; else goto NOIMG;
  492.                 }
  493.  
  494.                 if (cache.has(#img_path)) && (cache.current_size)
  495.                 {
  496.                         img_decode stdcall (cache.current_buf, cache.current_size, 0);
  497.                         if (!EAX) goto NOIMG;
  498.                         IMGOK:
  499.  
  500.                         cur_img = EAX;
  501.                         img_h = ESDWORD[cur_img+8];
  502.                         img_w = ESDWORD[cur_img+4];
  503.  
  504.                         if (img_w / 6 + stolbec > list.column_max) {
  505.                                 NewLine();
  506.                         }
  507.                         img_x = stolbec*list.font_w+3;
  508.                         img_y = draw_y;
  509.  
  510.                         img_w = math.min(img_w, DrawBuf.bufw - img_x);
  511.  
  512.                         stolbec += img_w / 6;
  513.                         if (stolbec > list.column_max) NewLine();
  514.  
  515.                         if (img_h > list.item_h + 5) {
  516.                                 draw_y += img_h - list.item_h;
  517.                                 NewLine();
  518.                         }
  519.  
  520.                         if (link) links.add_text(img_x + list.x, img_y + list.y, img_w, img_h, 0);
  521.  
  522.                         if (img_y + img_h >= DrawBuf.bufh) DrawBuf.IncreaseBufSize();
  523.  
  524.                         if (ESDWORD[cur_img+20] != IMAGE_BPP32) {
  525.                                 img_convert stdcall(cur_img, 0, IMAGE_BPP32, 0, 0);
  526.                                 $push eax
  527.                                 img_destroy stdcall(cur_img);
  528.                                 $pop eax
  529.                                 cur_img = EAX;
  530.                                 if (!EAX) goto NOIMG;
  531.                         }
  532.                         imgbuf[04] = DrawBuf.bufw;
  533.                         imgbuf[08] = DrawBuf.bufh;
  534.                         imgbuf[20] = IMAGE_BPP32;
  535.                         imgbuf[24] = buf_data+8;
  536.                         img_blend stdcall(#imgbuf, cur_img, img_x, img_y, 0, 0, img_w, img_h);
  537.                         img_destroy stdcall(cur_img);
  538.                         return;
  539.                 } else {
  540.                         img_url.add(#img_path);
  541.                 }
  542.                 NOIMG:
  543.  
  544.                 if (value = tag.get_value_of("title=")) && (strlen(value)<sizeof(line)-3) && (value) sprintf(#line, "[%s]", value);
  545.                 if (value = tag.get_value_of("alt=")) && (strlen(value)<sizeof(line)-3) && (value) sprintf(#line, "[%s]", value);
  546.                 if (!line) {
  547.                         if (!strncmp(#img_path, "data:", 5)) img_path=0;
  548.                         replace_char(#img_path, '?', NULL, strlen(#img_path));
  549.                         img_path[sizeof(line)-3] = '\0'; //prevent overflow in sprintf
  550.                         sprintf(#line, "[%s]", #img_path+strrchr(#img_path, '/'));
  551.                         line[50]= NULL;
  552.                 }
  553.                 while (CheckForLineBreak()) {};
  554.  
  555.                 text_colors.add(0x9A6F29);
  556.                 style.image = true;
  557.                 Paint();
  558.                 style.image = false;
  559.                 text_colors.pop();
  560.                 return;
  561.         }
  562.         if (tag.is("h4")) {
  563.                 NewLine();
  564.                 NewLine();
  565.                 style.h = tag.opened;
  566.                 style.b = tag.opened;
  567.         }
  568.         if (tag.is("h1")) || (tag.is("h2")) || (tag.is("h3")) || (tag.is("caption")) {
  569.                 style.h = tag.opened;
  570.                 if (tag.opened) {
  571.                         if (!style.pre) NewLine();
  572.                         draw_y += 10;
  573.                         zoom=2;
  574.                         list.font_type |= 10011001b;
  575.                         list.item_h = BASIC_LINE_H * 2 - 2;
  576.                         if (tag.is("h1")) style.b = true;
  577.                 } else {
  578.                         if (tag.is("h1")) style.b = false;
  579.                         NewLine();
  580.                         zoom=1;
  581.                         list.font_type = 10011000b;
  582.                         list.item_h = BASIC_LINE_H;
  583.                 }
  584.                 return;
  585.         }
  586.         if (tag.is("dt")) {
  587.                 style.tag_list.upd_level(tag.opened, DT);
  588.                 if (tag.opened) NewLine();
  589.                 return;
  590.         }
  591.         if (tag.is("ul")) {
  592.                 style.tag_list.upd_level(tag.opened, UL);
  593.                 if (!tag.opened) && (!style.pre) NewLine();
  594.                 return;
  595.         }
  596.         if (tag.is("ol")) {
  597.                 style.tag_list.upd_level(tag.opened, OL);      
  598.                 if (!tag.opened) && (!style.pre) NewLine();
  599.                 return;
  600.         }
  601.         if (tag.is("li")) && (tag.opened)
  602.         {
  603.                 if (!style.tag_list.level) style.tag_list.upd_level(1, UL);
  604.                 if (!style.pre) NewLine();
  605.                 if (style.tag_list.get_order_type() == UL) {
  606.                         strcpy(#line, "\31 ");
  607.                         stolbec = style.tag_list.level * 5 - 2;
  608.                 }
  609.                 if (style.tag_list.get_order_type() == OL) {
  610.                         sprintf(#line, "%i. ", style.tag_list.inc_counter());
  611.                         stolbec = style.tag_list.level * 5 - strlen(#line);
  612.                 }
  613.                 return;
  614.         }
  615.         if (tag.is("q"))
  616.         {
  617.                 if (tag.opened) {
  618.                         EAX = strlen(#line);
  619.                         if (line[EAX-1] != ' ') chrcat(#line, ' ');
  620.                         chrcat(#line, '\"');
  621.                 }
  622.                 if (!tag.opened) strcat(#line, "\" ");
  623.                 return;
  624.         }
  625.         if (tag.is("hr")) {
  626.                 if (value = tag.get_value_of("color=")) EDI = GetColor(value); else EDI = 0x999999;
  627.                 $push edi;
  628.                 NewLine();
  629.                 $pop edi;
  630.                 draw_y += 10;
  631.                 DrawBuf.DrawBar(5, draw_y - 1, list.w-10, 1, EDI);
  632.                 NewLine();
  633.                 draw_y += 10;
  634.                 return;
  635.         }
  636.         if (tag.is("meta")) {
  637.                 if (streq(tag.get_value_of("http-equiv="), "refresh")) && (value = tag.get_value_of("content=")) {
  638.                         if (value = strstri(value, "url=")) strcpy(#redirect, value);
  639.                 }
  640.         }
  641.         if (custom_encoding == -1) && (tag.is("meta")) || (tag.is("?xml")) {
  642.                 if (value = tag.get_value_of("charset=")) || (value = tag.get_value_of("content=")) || (value = tag.get_value_of("encoding="))
  643.                 {
  644.                         value += strrchr(value, '='); //search in content=
  645.                         if (ESBYTE[value] == '"') value++;
  646.                         strlwr(value);
  647.                         if      (streqrp(value,"utf-8"))        || (streqrp(value,"utf8"))        ChangeEncoding(CH_UTF8);
  648.                         else if (streqrp(value,"windows-1251")) || (streqrp(value,"windows1251")) ChangeEncoding(CH_CP1251);
  649.                         else if (streqrp(value,"dos"))          || (streqrp(value,"cp-866"))      ChangeEncoding(CH_CP866);
  650.                         else if (streqrp(value,"iso-8859-5"))   || (streqrp(value,"iso8859-5"))   ChangeEncoding(CH_ISO8859_5);
  651.                         else if (streqrp(value,"koi8-r"))       || (streqrp(value,"koi8-u"))      ChangeEncoding(CH_KOI8);
  652.                 }
  653.                 return;
  654.         }
  655. }
  656. //============================================================================================
  657. void TWebBrowser::DrawScroller()
  658. {
  659.         scroll_wv.max_area = list.count;
  660.         scroll_wv.cur_area = list.visible;
  661.         scroll_wv.position = list.first;
  662.         scroll_wv.all_redraw = 0;
  663.         scroll_wv.start_x = list.x + list.w;
  664.         scroll_wv.start_y = list.y;
  665.         scroll_wv.size_y = list.h;
  666.         scrollbar_v_draw(#scroll_wv);
  667. }
  668. //============================================================================================
  669. void TWebBrowser::ChangeEncoding(int _new_encoding)
  670. {
  671.         if (cur_encoding == _new_encoding) return;
  672.         cur_encoding = _new_encoding;
  673.         bufpointer = ChangeCharset(cur_encoding, "CP866", bufpointer);
  674.         if (header) {
  675.                 ChangeCharset(cur_encoding, "CP866", #header);
  676.                 DrawTitle(#header);
  677.         }
  678. }
  679. //============================================================================================
  680. void TWebBrowser::NewLine()
  681. {
  682.         dword onleft, ontop;
  683.         static int empty_line=0;
  684.  
  685.         if (!stolbec) && (draw_y==BODY_MARGIN) return;
  686.        
  687.         if (style.tag_list.level) && (stolbec == style.tag_list.level * 5) {
  688.                 if (empty_line<1) empty_line++;
  689.                 else return;
  690.         } else if (!stolbec) {
  691.                 if (empty_line<1) empty_line++;
  692.                 else return;
  693.         } else {
  694.                 empty_line=0;
  695.         }
  696.  
  697.         onleft = list.x + BODY_MARGIN;
  698.         ontop = draw_y + list.y;
  699.         if (t_html) && (!t_body) return;
  700.         draw_y += list.item_h;
  701.         if (style.blq) stolbec = 6; else stolbec = 0;
  702.         stolbec += style.tag_list.level * 5;
  703.         if (debug_mode) debugln(NULL);
  704. }
  705. //============================================================================================
  706. void TWebBrowser::DrawPage()
  707. {
  708.         DrawBuf.Show(list.first, list.h);
  709.         DrawScroller();
  710. }