Subversion Repositories Kolibri OS

Rev

Rev 8365 | Rev 8407 | 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) 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.         dword imgbuf[44];
  336.         dword cur_img;
  337.         int img_x, img_y, img_w, img_h;
  338.  
  339.         dword value;
  340.  
  341.         if (value = tag.get_value_of("name=")) || (value = tag.get_value_of("id=")) {
  342.                 anchors.add(value, draw_y);
  343.                 if (anchors.current) && (streq(value, #anchors.current+1)) {
  344.                         list.first = draw_y;
  345.                         anchors.current = NULL;
  346.                 }
  347.         }
  348.         if (tag.is("html")) {
  349.                 t_html = tag.opened;
  350.                 return;
  351.         }
  352.         if (tag.is("title")) {
  353.                 style.tag_title = tag.opened;
  354.                 if (!tag.opened) DrawTitle(#header);
  355.                 return;
  356.         }
  357.         if (tag.is("body")) {
  358.                 t_body = tag.opened;
  359.                 if (value = tag.get_value_of("link="))   link_color_default = GetColor(value);
  360.                 if (value = tag.get_value_of("alink="))  link_color_active = GetColor(value);
  361.                 if (value = tag.get_value_of("text="))   text_colors.set(0, GetColor(value));
  362.                 if (value = tag.get_value_of("bgcolor=")) {
  363.                         style.bg_color = page_bg = GetColor(value);
  364.                         DrawBuf.Fill(0, page_bg);
  365.                 }
  366.                 // Autodetecting encoding if no encoding was set
  367.                 if (tag.opened) && (custom_encoding==-1) && (cur_encoding == CH_CP866) {
  368.                         if (strstr(bufpointer, "\208\190")) ChangeEncoding(CH_UTF8);
  369.                         else if (chrnum(bufpointer, '\246')>5) ChangeEncoding(CH_CP1251);
  370.                 }
  371.                 return;
  372.         }
  373.         if (tag.is("br")) { NewLine(); return; }
  374.         if (tag.is("b")) || (tag.is("strong")) || (tag.is("big")) || (tag.is("w:b")) {
  375.                 style.b = tag.opened;
  376.                 return;
  377.         }
  378.         if (tag.is("w:r")) && (!tag.opened) { style.b = false; return; }
  379.         if (tag.is("a")) {
  380.                 if (tag.opened)
  381.                 {
  382.                         if (value = tag.get_value_of("href=")) && (!strstr(value,"javascript:"))
  383.                         {
  384.                                 link = true;
  385.                                 links.add_link(value);
  386.                         }
  387.                 } else {
  388.                         link = false;
  389.                         style.bg_color = page_bg;
  390.                 }
  391.                 return;
  392.         }
  393.         if (tag.is("iframe")) && (value = tag.get_value_of("src=")) {
  394.                 NewLine();
  395.                 strcpy(#line, "IFRAME: ");
  396.                 Paint();
  397.                 link=true;
  398.                 links.add_link(value);
  399.                 strncpy(#line, value, sizeof(line)-1);
  400.                 while (CheckForLineBreak()) {};
  401.                 Paint();
  402.                 link=false;
  403.                 NewLine();
  404.         }
  405.         if (tag.is("font")) {
  406.                 style.font = tag.opened;
  407.                 style.bg_color = page_bg;
  408.                 if (tag.opened)
  409.                 {
  410.                         if (value = tag.get_value_of("bg=")) style.bg_color = GetColor(value);
  411.                         if (value = tag.get_value_of("color=")) {
  412.                                 text_colors.add(GetColor(value));
  413.                         } else {
  414.                                 text_colors.add(text_colors.get_last());
  415.                         }
  416.                 }
  417.                 else text_colors.pop();
  418.                 return;
  419.         }
  420.         if (tag.is("div")) {
  421.                 if (streq(#tag.prior,"div")) && (tag.opened) return;
  422.                 if (!tag.opened) && (style.font) text_colors.pop();
  423.                 NewLine();
  424.                 return;
  425.         }
  426.         if (tag.is("header")) || (tag.is("article")) || (tag.is("footer")) || (tag.is("figure")) {
  427.                 NewLine();
  428.                 return;
  429.         }
  430.         if (tag.is("p")) || (tag.is("w:p"))  {
  431.                 IF (tag.prior[0] == 'h') || (streq(#tag.prior,"td")) || (streq(#tag.prior,"p")) return;
  432.                 NewLine();
  433.                 return;
  434.         }
  435.         if (tag.is("pre")) { style.pre = tag.opened; return; }
  436.         if (tag.is("td")) { if (tag.opened) AddCharToTheLine(' '); return; }
  437.         if (tag.is("tr")) { if (tag.opened) NewLine(); return; }
  438.         if (tag.is("button")) { style.button = tag.opened; stolbec++; return; }
  439.         if (tag.is("u")) || (tag.is("ins")) { style.u=tag.opened; return;}
  440.         if (tag.is("s")) || (tag.is("strike")) || (tag.is("del")) { style.s=tag.opened; return; }
  441.         if (tag.is("dl")) {
  442.                 if (tag.opened) NewLine();
  443.                 return;
  444.         }
  445.         if (tag.is("dd")) {
  446.                 //NewLine();
  447.                 //if (tag.opened) stolbec += 5;  //stolbec overflow!
  448.                 return;
  449.         }
  450.         if (tag.is("blockquote")) { style.blq = tag.opened; return; }
  451.         if (tag.is("code")) {
  452.                 if (tag.opened) style.bg_color = 0xe4ffcb; else style.bg_color = page_bg;
  453.                 style.pre = tag.opened; return;
  454.         }
  455.         if (tag.is("img")) {
  456.                 value = tag.get_value_of("src=");
  457.                 if (!value) goto NOIMG;
  458.  
  459.                 if (!strcmp(value + strrchr(value, '.'), "svg")) goto NOIMG;
  460.  
  461.                 if (streqrp(value, "data:")) {
  462.                         if (!strstr(value, "base64,")) goto NOIMG;
  463.                         value = EAX+7;
  464.                         if (ESBYTE[value]==' ') value++;
  465.                         cur_img = malloc(strlen(value));
  466.                         base64_decode stdcall (value, cur_img, strlen(value));
  467.                         img_decode stdcall (cur_img, EAX, 0);
  468.                         $push eax
  469.                         free(cur_img);
  470.                         $pop eax
  471.                         if (EAX) goto IMGOK; else goto NOIMG;
  472.                 }
  473.  
  474.                 strlcpy(#img_path, value, sizeof(img_path)-1);
  475.                 get_absolute_url(#img_path, history.current());
  476.  
  477.                 if (check_is_the_adress_local(#img_path)) {
  478.                         img_from_file stdcall(#img_path);
  479.                         if (EAX) goto IMGOK; else goto NOIMG;
  480.                 }
  481.  
  482.                 if (cache.has(#img_path)) && (cache.current_size)
  483.                 {
  484.                         img_decode stdcall (cache.current_buf, cache.current_size, 0);
  485.                         if (!EAX) goto NOIMG;
  486.                         IMGOK:
  487.  
  488.                         cur_img = EAX;
  489.                         img_h = ESDWORD[cur_img+8];
  490.                         img_w = ESDWORD[cur_img+4];
  491.  
  492.                         if (img_w / 6 + stolbec > list.column_max) {
  493.                                 NewLine();
  494.                         }
  495.                         img_x = stolbec*list.font_w+3;
  496.                         img_y = draw_y;
  497.  
  498.                         img_w = math.min(img_w, DrawBuf.bufw - img_x);
  499.  
  500.                         stolbec += img_w / 6;
  501.                         if (stolbec > list.column_max) NewLine();
  502.  
  503.                         if (img_h > list.item_h + 5) {
  504.                                 draw_y += img_h - list.item_h;
  505.                                 NewLine();
  506.                         }
  507.  
  508.                         if (link) links.add_text(img_x + list.x, img_y + list.y, img_w, img_h, 0);
  509.  
  510.                         if (img_y + img_h >= DrawBuf.bufh) DrawBuf.IncreaseBufSize();
  511.  
  512.                         if (ESDWORD[cur_img+20] != IMAGE_BPP32) {
  513.                                 img_convert stdcall(cur_img, 0, IMAGE_BPP32, 0, 0);
  514.                                 $push eax
  515.                                 img_destroy stdcall(cur_img);
  516.                                 $pop eax
  517.                                 cur_img = EAX;
  518.                                 if (!EAX) goto NOIMG;
  519.                         }
  520.                         imgbuf[04] = DrawBuf.bufw;
  521.                         imgbuf[08] = DrawBuf.bufh;
  522.                         imgbuf[20] = IMAGE_BPP32;
  523.                         imgbuf[24] = buf_data+8;
  524.                         img_blend stdcall(#imgbuf, cur_img, img_x, img_y, 0, 0, img_w, img_h);
  525.                         img_destroy stdcall(cur_img);
  526.                         return;
  527.                 } else {
  528.                         img_url.add(#img_path);
  529.                 }
  530.                 NOIMG:
  531.  
  532.                 if (value = tag.get_value_of("title=")) && (strlen(value)<sizeof(line)-3) && (value) sprintf(#line, "[%s]", value);
  533.                 if (value = tag.get_value_of("alt=")) && (strlen(value)<sizeof(line)-3) && (value) sprintf(#line, "[%s]", value);
  534.                 if (!line) {
  535.                         if (!strncmp(#img_path, "data:", 5)) img_path=0;
  536.                         replace_char(#img_path, '?', NULL, strlen(#img_path));
  537.                         img_path[sizeof(line)-3] = '\0'; //prevent overflow in sprintf
  538.                         sprintf(#line, "[%s]", #img_path+strrchr(#img_path, '/'));
  539.                         line[50]= NULL;
  540.                 }
  541.                 while (CheckForLineBreak()) {};
  542.  
  543.                 text_colors.add(0x9A6F29);
  544.                 style.image = true;
  545.                 Paint();
  546.                 style.image = false;
  547.                 text_colors.pop();
  548.                 return;
  549.         }
  550.         if (tag.is("h4")) {
  551.                 NewLine();
  552.                 NewLine();
  553.                 style.h = tag.opened;
  554.                 style.b = tag.opened;
  555.         }
  556.         if (tag.is("h1")) || (tag.is("h2")) || (tag.is("h3")) || (tag.is("caption")) {
  557.                 style.h = tag.opened;
  558.                 if (tag.opened) {
  559.                         if (!style.pre) NewLine();
  560.                         draw_y += 10;
  561.                         zoom=2;
  562.                         list.font_type |= 10011001b;
  563.                         list.item_h = BASIC_LINE_H * 2 - 2;
  564.                         if (tag.is("h1")) style.b = true;
  565.                 } else {
  566.                         if (tag.is("h1")) style.b = false;
  567.                         NewLine();
  568.                         zoom=1;
  569.                         list.font_type = 10011000b;
  570.                         list.item_h = BASIC_LINE_H;
  571.                 }
  572.                 return;
  573.         }
  574.         if (tag.is("dt")) {
  575.                 style.tag_list.upd_level(tag.opened, DT);
  576.                 if (tag.opened) NewLine();
  577.                 return;
  578.         }
  579.         if (tag.is("ul")) {
  580.                 style.tag_list.upd_level(tag.opened, UL);
  581.                 if (!tag.opened) && (!style.pre) NewLine();
  582.                 return;
  583.         }
  584.         if (tag.is("ol")) {
  585.                 style.tag_list.upd_level(tag.opened, OL);      
  586.                 if (!tag.opened) && (!style.pre) NewLine();
  587.                 return;
  588.         }
  589.         if (tag.is("li")) && (tag.opened)
  590.         {
  591.                 if (!style.tag_list.level) style.tag_list.upd_level(1, UL);
  592.                 if (!style.pre) NewLine();
  593.                 if (style.tag_list.get_order_type() == UL) {
  594.                         strcpy(#line, "\31 ");
  595.                         stolbec = style.tag_list.level * 5 - 2;
  596.                 }
  597.                 if (style.tag_list.get_order_type() == OL) {
  598.                         sprintf(#line, "%i. ", style.tag_list.inc_counter());
  599.                         stolbec = style.tag_list.level * 5 - strlen(#line);
  600.                 }
  601.                 return;
  602.         }
  603.         if (tag.is("q"))
  604.         {
  605.                 if (tag.opened) {
  606.                         EAX = strlen(#line);
  607.                         if (line[EAX-1] != ' ') chrcat(#line, ' ');
  608.                         chrcat(#line, '\"');
  609.                 }
  610.                 if (!tag.opened) strcat(#line, "\" ");
  611.                 return;
  612.         }
  613.         if (tag.is("hr")) {
  614.                 if (value = tag.get_value_of("color=")) EDI = GetColor(value); else EDI = 0x999999;
  615.                 $push edi;
  616.                 NewLine();
  617.                 $pop edi;
  618.                 draw_y += 10;
  619.                 DrawBuf.DrawBar(5, draw_y - 1, list.w-10, 1, EDI);
  620.                 NewLine();
  621.                 draw_y += 10;
  622.                 return;
  623.         }
  624.         if (tag.is("meta")) {
  625.                 if (streq(tag.get_value_of("http-equiv="), "refresh")) && (value = tag.get_value_of("content=")) {
  626.                         if (value = strstri(value, "url=")) strcpy(#redirect, value);
  627.                 }
  628.         }
  629.         if (custom_encoding == -1) && (tag.is("meta")) || (tag.is("?xml")) {
  630.                 if (value = tag.get_value_of("charset=")) || (value = tag.get_value_of("content=")) || (value = tag.get_value_of("encoding="))
  631.                 {
  632.                         value += strrchr(value, '='); //search in content=
  633.                         if (ESBYTE[value] == '"') value++;
  634.                         strlwr(value);
  635.                         if      (streqrp(value,"utf-8"))        || (streqrp(value,"utf8"))        ChangeEncoding(CH_UTF8);
  636.                         else if (streqrp(value,"windows-1251")) || (streqrp(value,"windows1251")) ChangeEncoding(CH_CP1251);
  637.                         else if (streqrp(value,"dos"))          || (streqrp(value,"cp-866"))      ChangeEncoding(CH_CP866);
  638.                         else if (streqrp(value,"iso-8859-5"))   || (streqrp(value,"iso8859-5"))   ChangeEncoding(CH_ISO8859_5);
  639.                         else if (streqrp(value,"koi8-r"))       || (streqrp(value,"koi8-u"))      ChangeEncoding(CH_KOI8);
  640.                 }
  641.                 return;
  642.         }
  643. }
  644. //============================================================================================
  645. void TWebBrowser::DrawScroller()
  646. {
  647.         scroll_wv.max_area = list.count;
  648.         scroll_wv.cur_area = list.visible;
  649.         scroll_wv.position = list.first;
  650.         scroll_wv.all_redraw = 0;
  651.         scroll_wv.start_x = list.x + list.w;
  652.         scroll_wv.start_y = list.y;
  653.         scroll_wv.size_y = list.h;
  654.         scrollbar_v_draw(#scroll_wv);
  655. }
  656. //============================================================================================
  657. void TWebBrowser::ChangeEncoding(int _new_encoding)
  658. {
  659.         if (cur_encoding == _new_encoding) return;
  660.         cur_encoding = _new_encoding;
  661.         bufpointer = ChangeCharset(cur_encoding, "CP866", bufpointer);
  662.         if (header) {
  663.                 ChangeCharset(cur_encoding, "CP866", #header);
  664.                 DrawTitle(#header);
  665.         }
  666. }
  667. //============================================================================================
  668. void TWebBrowser::NewLine()
  669. {
  670.         dword onleft, ontop;
  671.         static int empty_line=0;
  672.  
  673.         if (!stolbec) && (draw_y==BODY_MARGIN) return;
  674.        
  675.         if (style.tag_list.level) && (stolbec == style.tag_list.level * 5) {
  676.                 if (empty_line<1) empty_line++;
  677.                 else return;
  678.         } else if (!stolbec) {
  679.                 if (empty_line<1) empty_line++;
  680.                 else return;
  681.         } else {
  682.                 empty_line=0;
  683.         }
  684.  
  685.         onleft = list.x + BODY_MARGIN;
  686.         ontop = draw_y + list.y;
  687.         if (t_html) && (!t_body) return;
  688.         draw_y += list.item_h;
  689.         if (style.blq) stolbec = 6; else stolbec = 0;
  690.         stolbec += style.tag_list.level * 5;
  691.         if (debug_mode) debugln(NULL);
  692. }
  693. //============================================================================================
  694. void TWebBrowser::DrawPage()
  695. {
  696.         DrawBuf.Show(list.first, list.h);
  697.         DrawScroller();
  698. }