Subversion Repositories Kolibri OS

Rev

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