Subversion Repositories Kolibri OS

Rev

Rev 3468 | Blame | Last modification | View Log | Download | RSS feed

  1.  
  2. int     downloader_id;
  3.  
  4. dword
  5.         buf,
  6.         filesize,
  7.         blink;
  8.  
  9. char download_path[]="/rd/1/.download";
  10. char search_path[]="http://nigma.ru/index.php?s=";
  11. char version[]=" Text-based Browser 0.99.02";
  12.  
  13.  
  14. struct TWebBrowser {
  15.         int left, top, width, height, line_h;
  16.         void Scan(int);
  17.         void GetNewUrl();
  18.         void OpenPage();
  19.         void ReadHtml(byte);
  20.         void ShowPage();
  21.         void ParseHTML(dword);
  22.         void WhatTextStyle(int left1, top1, width1);
  23.         void DrawPage();
  24.         void DrawScroller();
  25. };     
  26. TWebBrowser WB1;
  27.  
  28. byte rez, b_text, i_text, u_text, s_text, pre_text, blq_text, li_text,
  29.         link, ignor_text, li_tab, cur_encoding;
  30.  
  31. dword text_colors[300],
  32.         text_color_index,
  33.         link_color,
  34.         bg_color;
  35.  
  36. int stroka,
  37.         stolbec,
  38.         tab_len,
  39.         anchor_line_num;
  40.        
  41. char line[500],
  42.         tag[100],
  43.         tagparam[10000],
  44.         parametr[1200],
  45.         options[4096],
  46.         anchor[256];
  47.  
  48. #include "include\history.h"
  49. #include "include\colors.h"
  50. #include "include\unicode_tags.h"
  51. #include "include\img_cache.h"
  52. #include "include\some_code.h"
  53. #include "include\parce_tag.h"
  54.  
  55. //=======================================================================
  56. dword drawbuf;
  57. void DrawBufInit()
  58. {
  59.         free(drawbuf);
  60.         drawbuf = malloc(WB1.width * WB1.line_h +4 * 4 + 8); //+1 for good luck
  61.         ESDWORD[drawbuf] = WB1.width;
  62.         ESDWORD[drawbuf+4] = WB1.line_h;
  63. }
  64. void DrawBufFill()
  65. {
  66.         int i;
  67.         for (i=0; i<WB1.width* WB1.line_h +4 * 4; i+=4) ESDWORD[drawbuf+i+8] = bg_color;
  68. }
  69. void DrawBufBar(dword x, y, w, h, color)
  70. {
  71.         int i, j;
  72.         for (j=0; j<h; j++)
  73.         {
  74.                 for (i = y+j*WB1.width+x*4; i<y+j*WB1.width+x+w*4 ; i+=4) ESDWORD[drawbuf+i+8] = color;
  75.         }
  76. }
  77.  
  78. char shift[]={8,8,4,4};
  79. void DrawBufSkew(dword x, y, w, h)
  80. {
  81.         int i, j;
  82.         stolbec++;
  83.         for (j=0; j<=3; j++)
  84.         {
  85.                 for (i = y+j*WB1.width+x+w+h*4; i>y+j*WB1.width+x+h-12*4 ; i-=4)
  86.                                                                 ESDWORD[drawbuf+i+8] = ESDWORD[-shift[j]+drawbuf+i+8];
  87.         }
  88. }
  89.  
  90. void TextGoDown(int left1, top1, width1)
  91. {
  92.         if (!stroka) DrawBar(WB1.left, WB1.top, WB1.width, 5, bg_color); //çàêðàøèâàåì ôîí íàä ïåðâîé ñòðîêîé
  93.         stroka++;
  94.         if (blq_text) stolbec = 8; else stolbec = 0;
  95.         if (li_text) stolbec = li_tab * 5;
  96.         if (top1>=WB1.top) && ( top1 < WB1.height+WB1.top-10)  && (!anchor)
  97.         {
  98.                 PutPaletteImage(drawbuf+8, WB1.width, WB1.line_h, left1-5, top1, 32,0);
  99.                 DrawBufFill();
  100.         }
  101. }
  102.  
  103. void TWebBrowser::DrawPage()
  104. {
  105.         int start_x, start_y, line_length, magrin_left=5;
  106.        
  107.         if (!header)
  108.         {
  109.                 strcpy(#header, #line);
  110.                 strcat(#header, " -");
  111.                 strcat(#header, #version);
  112.                 line = 0;
  113.                 return;
  114.         }
  115.        
  116.         if (stroka >= 0) && (stroka - 2 < lines.visible) && (line) && (!anchor)
  117.         {
  118.                 start_x = stolbec * 6 + left + magrin_left;
  119.                 start_y = stroka * 10 + top + magrin_left;
  120.                 line_length = strlen(#line) * 6;
  121.  
  122.                 if (use_truetype == 1)
  123.                 {
  124.                         //line_length =  get_length stdcall (#line,-1,16,line_length);
  125.                         text_out stdcall (#line, #fontlol, 17, text_colors[text_color_index], start_x, start_y-3);
  126.                 }
  127.                 else
  128.                 {
  129.                         WriteBufText(start_x, 0, 0x88, text_colors[text_color_index], #line, drawbuf);
  130.                 }
  131.                 IF (b_text)     WriteBufText(start_x+1, 0, 0x88, text_colors[text_color_index], #line, drawbuf);
  132.                 IF (i_text) DrawBufSkew(start_x, 0, line_length, line_h);
  133.                 IF (s_text) DrawBufBar(start_x, 4, line_length, 1, text_colors[text_color_index]);
  134.                 IF (u_text) DrawBufBar(start_x, 8, line_length, 1, text_colors[text_color_index]);
  135.                 IF (link) {
  136.                         UnsafeDefineButton(start_x-2, start_y, line_length + 3, 9, blink + BT_HIDE, 0xB5BFC9);
  137.                         DrawBufBar(start_x, 8, line_length, 1, text_colors[text_color_index]);
  138.                 }
  139.                 stolbec += strlen(#line);
  140.         }
  141. }
  142. //=======================================================================
  143.  
  144. void TWebBrowser::Scan(int id)
  145. {
  146.         if (id >= 400)
  147.         {
  148.                 GetURLfromPageLinks(id);
  149.                
  150.                 //#1
  151.                 if (URL[0] == '#')
  152.                 {
  153.                         strcpy(#anchor, #URL+strrchr(#URL, '#'));
  154.                        
  155.                         strcpy(#URL, BrowserHistory.CurrentUrl());
  156.                        
  157.                         lines.first=lines.all-lines.visible;
  158.                         ShowPage();
  159.                         return;
  160.                 }
  161.                 //liner.ru#1
  162.                 if (strrchr(#URL, '#')<>-1)
  163.                 {
  164.                         strcpy(#anchor, #URL+strrchr(#URL, '#'));
  165.                         URL[strrchr(#URL, '#')-1] = 0x00; //çàãëóøêà
  166.                 }
  167.                
  168.                 GetNewUrl();
  169.                
  170.                 if (!strcmp(#URL + strlen(#URL) - 4, ".gif")) || (!strcmp(#URL + strlen(#URL) - 4, ".png")) || (!strcmp(#URL + strlen(#URL) - 4, ".jpg"))
  171.                 {
  172.                         //if (strstr(#URL,"http:"))
  173.                         RunProgram("/sys/media/kiv", #URL);
  174.                         strcpy(#editURL, BrowserHistory.CurrentUrl());
  175.                         strcpy(#URL, BrowserHistory.CurrentUrl());
  176.                         return;
  177.                 }
  178.                 if (!strcmpn(#URL,"mailto:", 7))
  179.                 {
  180.                         RunProgram("@notify", #URL);
  181.                         strcpy(#editURL, BrowserHistory.CurrentUrl());
  182.                         strcpy(#URL, BrowserHistory.CurrentUrl());
  183.                         return;
  184.                 }
  185.  
  186.                 OpenPage();
  187.                 return;
  188.         }
  189.        
  190.         IF(lines.all < lines.visible) SWITCH(id) //åñëè ìàëî ñòðîê èãíîðèðóåì íåêîòîðûå êíîïêè
  191.         { CASE 183: CASE 184: CASE 180: CASE 181: return; }
  192.        
  193.         switch (id)
  194.         {
  195.                 case 011: //Ctrk+K
  196.                         ReadHtml(_KOI);
  197.                         break;
  198.                 case 021: //Ctrl+U
  199.                         ReadHtml(_UTF);
  200.                         break;
  201.                 case 004: //Ctrl+D
  202.                         ReadHtml(_DOS);
  203.                         break;
  204.                 case 002: //free img cache
  205.                         FreeImgCache();
  206.                         break;
  207.                 case 003:
  208.                         if (!pre_text) pre_text=2;
  209.                                 else pre_text=0;
  210.                         break;                 
  211.                 case 005: //truetype
  212.                         if (use_truetype == 2)
  213.                         {
  214.                                 RunProgram("@notify", "Library does not exists /rd/1/lib/truetype.obj"w);
  215.                                 return;
  216.                         }
  217.                         if (use_truetype == 1) use_truetype=0; else use_truetype=1;
  218.                         break;
  219.                 case BACK:
  220.                         if (!BrowserHistory.GoBack()) return;
  221.                         OpenPage();
  222.                         return;
  223.                 case FORWARD:
  224.                         if (!BrowserHistory.GoForward()) return;
  225.                         OpenPage();
  226.                         return;
  227.                 case 255:  //F12
  228.                         RunProgram("/rd/1/HTMLv_old", #URL);
  229.                         return;
  230.                 case 052:  //F3
  231.                         if (strcmp(get_URL_part(5),"http:")<>0) RunProgram("/rd/1/tinypad", #URL); else RunProgram("/rd/1/tinypad", #download_path);
  232.                         return;
  233.                 case 054: //F5
  234.                         IF(address_box.flags & 0b10) break;
  235.                 case REFRESH:
  236.                         if (GetProcessSlot(downloader_id)<>0)
  237.                         {
  238.                                 KillProcess(downloader_id);
  239.                                 pause(20);
  240.                                 Draw_Window();
  241.                                 return;
  242.                         }
  243.                         anchor_line_num=lines.first; //âåñ¸ëûé êîñòûëü :Ð
  244.                         anchor[0]='|';
  245.                         OpenPage();
  246.                         return;
  247.                 case 014: //Ctrl+N íîâîå îêíî
  248.                 case 020: //Ctrl+T íîâàÿ âêëàäêà
  249.                 case NEWTAB:
  250.                         MoveSize(190,80,OLD,OLD);
  251.                         RunProgram(#program_path, #URL);
  252.                         return;
  253.                        
  254.                 case HOME:
  255.                         strcpy(#editURL, "http://kolibri-n.org/index.php");
  256.                 case GOTOURL:
  257.                 case 0x0D: //enter
  258.                         strcpy(#URL, #editURL);
  259.                         OpenPage();
  260.                         return;
  261.                 case 173:       //ctrl+enter
  262.                 case SEARCHWEB:
  263.                         strcpy(#URL, #search_path);
  264.                         strcat(#URL, #editURL);
  265.                         OpenPage();
  266.                         return;
  267.  
  268.                 case ID1: //ìîòàåì ââåðõ
  269.                         IF(lines.first <= 0) return;
  270.                         lines.first--;
  271.                         break;
  272.                 case ID2: //ìîòàåì âíèç
  273.                         IF(lines.visible + lines.first >= lines.all) return;
  274.                         lines.first++;
  275.                         break;
  276.                 case 183: //PgDown
  277.                         IF(lines.first == lines.all - lines.visible) return;
  278.                         lines.first += lines.visible + 2;
  279.                         IF(lines.visible + lines.first > lines.all) lines.first = lines.all - lines.visible;
  280.                         break;
  281.                 case 184: //PgUp
  282.                         IF(lines.first == 0) return;
  283.                         lines.first -= lines.visible - 2;
  284.                         IF(lines.first < 0) lines.first = 0;
  285.                         break;
  286.                 case 180: //home
  287.                         IF(lines.first == 0) return;
  288.                         lines.first = 0;
  289.                         break;
  290.                 case 181: //end
  291.                         IF (lines.first == lines.all - lines.visible) return;
  292.                         lines.first = lines.all - lines.visible;
  293.                         break;
  294.                 default:
  295.                         return;
  296.         }
  297.         ParseHTML(buf);
  298. }
  299.  
  300.  
  301. char *ABSOLUTE_LINKS[]={ "http:", "mailto:", "ftp:", "/sys/", "/rd/", "/fd/", "/bd/", "/hd/", "/cd/", "/tmp/", 0};
  302. //dword TWebBrowser::GetNewUrl(dword CUR_URL, NEW_URL){
  303. void TWebBrowser::GetNewUrl(){
  304.         int i, len;
  305.        
  306.         for (i=0; ABSOLUTE_LINKS[i]; i++)
  307.         {
  308.                 len=strlen(ABSOLUTE_LINKS[i]);
  309.                 if (!strcmpn(#URL, ABSOLUTE_LINKS[i], len)) return;
  310.         }
  311.                
  312.         IF (!strcmpn(#URL,"./", 2)) strcpy(#URL, #URL+2); //èãíîðèì :)
  313.         if (URL[0] == '/') strcpy(#URL, #URL+1);
  314.  
  315.         strcpy(#editURL, BrowserHistory.CurrentUrl()); //äîñòà¸ì àäðåñ òåêóùåé ñòðàíèöû
  316.                
  317.         _CUT_ST_LEVEL_MARK:
  318.                
  319.                 if (editURL[strrchr(#editURL, '/')-2]<>'/')  // åñëè íå http://
  320.                 {
  321.                         editURL[strrchr(#editURL, '/')] = 0x00; //îáðåçàåì å¸ óðë äî ïîñëåäíåãî /
  322.                 }
  323.                
  324.                 IF (!strcmp(get_URL_part(3),"../")) //íà óðîâåíü ââåðõ
  325.                 {
  326.                         strcpy(#URL,#URL+3);
  327.                         editURL[strrchr(#editURL, '/')-1] = 0x00; //îáðåçàåì å¸ óðë äî ïîñëåäíåãî /
  328.                         goto _CUT_ST_LEVEL_MARK;
  329.                 }
  330.                
  331.                 if (editURL[strlen(#editURL)-1]<>'/') strcat(#editURL, "/");
  332.                
  333.                 strcat(#editURL, #URL); //êëåèì íîâûé àäðåñ
  334.                 strcpy(#URL, #editURL);
  335. }
  336.  
  337.  
  338.        
  339. void TWebBrowser::ReadHtml(byte encoding)
  340. {
  341.         if (!strcmp(get_URL_part(5),"http:")))
  342.                 file_size stdcall (#download_path);
  343.         else
  344.                 file_size stdcall (#URL);
  345.        
  346.         filesize = EBX;
  347.         if (!filesize) return;
  348.        
  349.         mem_Free(buf);
  350.         buf = mem_Alloc(filesize);
  351.         if (!strcmp(get_URL_part(5),"http:")))
  352.                 ReadFile(0, filesize, buf, #download_path);
  353.         else
  354.                 ReadFile(0, filesize, buf, #URL);
  355.                
  356.         cur_encoding = encoding;
  357.         if (encoding==_WIN) wintodos(buf);
  358.         if (encoding==_UTF) utf8rutodos(buf);
  359.         if (encoding==_KOI) koitodos(buf);
  360. }
  361.  
  362.  
  363. void TWebBrowser::OpenPage()
  364. {
  365.         if (GetProcessSlot(downloader_id)<>0) PutPaletteImage(#toolbar,200,42,0,0,8,#toolbar_pal);
  366.         KillProcess(downloader_id);
  367.         strcpy(#editURL, #URL);
  368.         BrowserHistory.AddUrl();
  369.         strcpy(#header, #version);
  370.         pre_text =0;
  371.         if (!strcmp(get_URL_part(5),"http:")))
  372.         {
  373.                 KillProcess(downloader_id); //óáèâàåì ñòàðûé ïðîöåññ
  374.                 DeleteFile(#download_path);
  375.                 IF (URL[strlen(#URL)-1]=='/') URL[strlen(#URL)-1]=NULL;
  376.                 downloader_id = RunProgram("/sys/network/downloader", #URL);
  377.                 //Browser Hack v2.0
  378.                 pause(60);
  379.                 if (GetProcessSlot(downloader_id)<>0)
  380.                 {
  381.                         debug("Browser Hack v2.0: Killing downloader and trying to run it one more!");
  382.                         KillProcess(downloader_id); //óáèâàåì ñòàðûé ïðîöåññ
  383.                         downloader_id = RunProgram("/sys/network/downloader", #URL);
  384.                 }
  385.                 //
  386.                 IF (downloader_id<0) RunProgram("@notify", "Error running Downloader. Internet unavilable.");
  387.                 Draw_Window();
  388.                 return;
  389.         }
  390.         lines.first = lines.all =0;
  391.         ReadHtml(_WIN);
  392.         WB1.ShowPage();
  393. }
  394.  
  395.  
  396. void TWebBrowser::ShowPage()
  397. {
  398.         address_box.size = address_box.pos = strlen(#editURL);
  399.         address_box.offset=0;
  400.         edit_box_draw stdcall(#address_box);
  401.  
  402.         if (!filesize)
  403.         {
  404.                 DrawBar(left, top, width+scroll1.size_x+1, height, 0xFFFFFF); //fill all
  405.                 if (GetProcessSlot(downloader_id)<>0) WriteText(left + 10, top + 18, 0x80, 0, "Loading...");
  406.                 else
  407.                 {
  408.                         WriteText(left + 10, top + 18, 0x80, 0, "Page not found. May be, URL contains some errors.");
  409.                         if (!strcmp(get_URL_part(5),"http:"))) WriteText(left + 10, top + 32, 0x80, 0, "Or Internet unavilable for your configuration.");
  410.                 }
  411.                 //return;
  412.         }
  413.         else
  414.                 ParseHTML(buf);
  415.  
  416.         if (!header) strcpy(#header, #version);
  417.         if (!strcmp(#version, #header)) DrawTitle(#header);
  418. }
  419.  
  420.  
  421.  
  422. void TWebBrowser::ParseHTML(dword bword){
  423.         word bukva[2];
  424.         int j, perenos_num;
  425.         byte ignor_param;
  426.         char temp[768];
  427.        
  428.         if (blink<400) blink=400; else for ( ; blink>400; blink--;) DeleteButton(blink);
  429.         b_text = i_text = u_text = s_text = blq_text =
  430.         li_text = link = ignor_text = text_color_index = text_colors[0] = li_tab = 0; //îáíóëÿåì òåãè
  431.         link_color = 0x0000FF;
  432.         bg_color = 0xFFFFFF;
  433.         DrawBufFill();
  434.         line = NULL;
  435.         strcpy(#page_links,"|");
  436.         strcpy(#header, #version);
  437.         stroka = -lines.first;
  438.         stolbec = 0;
  439.  
  440.         if (pre_text<>2)
  441.         {
  442.                 pre_text=0;
  443.                 if (!strcmp(#URL + strlen(#URL) - 4, ".txt")) pre_text = 1;
  444.                 if (!strcmp(#URL + strlen(#URL) - 4, ".mht")) ignor_text = 1;
  445.         }
  446.        
  447.         for ( ; buf+filesize > bword; bword++;)
  448.         {
  449.                 bukva = ESBYTE[bword];
  450.                 if (ignor_text) && (bukva<>'<') continue;
  451.                 switch (bukva)
  452.                 {
  453.                 case 0x0a:
  454.                         if (pre_text)
  455.                         {
  456.                                 bukva = temp = NULL;
  457.                                 goto NEXT_MARK;
  458.                         }
  459.                 case '\9':
  460.                         if (pre_text) //èíà÷å èä¸ì íà 0x0d     
  461.                         {
  462.                                 tab_len=strlen(#line)/8;
  463.                                 tab_len=tab_len*8;
  464.                                 tab_len=8+tab_len-strlen(#line);
  465.                                 for (j=0; j<tab_len; j++;) chrcat(#line,' ');
  466.                                 break;
  467.                         }
  468.                         goto DEFAULT_MARK;             
  469.                 case '=': //quoted printable
  470.                         if (strcmp(#URL + strlen(#URL) - 4, ".mht")<>0) goto DEFAULT_MARK;
  471.  
  472.                         temp[0] = ESBYTE[bword+1];
  473.                         temp[1] = ESBYTE[bword+2];
  474.                         temp[2] = '\0';
  475.                         if (bukva = Hex2Symb(#temp))
  476.                         {
  477.                                 bword+=2;
  478.                                 goto DEFAULT_MARK;
  479.                         }
  480.                         break;
  481.                        
  482.                 case '&': //&nbsp; and so on
  483.                         bword++;
  484.                         tag=0;
  485.                         for (j=0; (ESBYTE[bword]<>';') && (j<7);   j++, bword++;)
  486.                         {
  487.                                 bukva = ESBYTE[bword];
  488.                                 chrcat(#tag, bukva);
  489.                         }
  490.                        
  491.                         bukva = GetUnicodeSymbol();
  492.                         if (bukva) goto DEFAULT_MARK;
  493.                         break;
  494.                 case '<':
  495.                         bword++; //ïðîìîòàåì ñèìâîë <
  496.                         tag = parametr = tagparam = ignor_param = NULL;
  497.                         if (ESBYTE[bword] == '!') //ôèëüòðàöèÿ âíóòðè <!-- -->, äåðçêî
  498.                         {
  499.                                 bword++;
  500.                                 if (ESBYTE[bword] == '-')
  501.                                 {
  502.                                 HH_:
  503.                                         do
  504.                                         {
  505.                                                 bword++;
  506.                                                 if (buf + filesize <= bword) break 2;
  507.                                         }
  508.                                         while (ESBYTE[bword] <>'-');
  509.                                        
  510.                                         bword++;
  511.                                         if (ESBYTE[bword] <>'-') goto HH_;
  512.                                 }
  513.                         }
  514.                         while (ESBYTE[bword] !='>') && (bword < buf + filesize) //ïîëó÷àåì òåã è åãî ïàðàìåòðû
  515.                         {
  516.                                 bukva = ESBYTE[bword];
  517.                                 if (bukva == '\9') || (bukva == '\x0a') || (bukva == '\x0d') bukva = ' ';
  518.                                 if (!ignor_param) && (bukva <>' ')
  519.                                 {
  520.                                         if (strlen(#tag)<sizeof(tag)) strcat(#tag, #bukva);
  521.                                 }
  522.                                 else
  523.                                 {
  524.                                         ignor_param = true;
  525.                                         if (!ignor_text) && (strlen(#tagparam)+1<sizeof(tagparam)) strcat(#tagparam, #bukva);
  526.                                 }
  527.                                 bword++;
  528.                         }
  529.                         strlwr(#tag);
  530.                         strlwr(#tagparam);
  531.  
  532.                         if (tag[strlen(#tag)-1]=='/') tag[strlen(#tag)-1]=NULL; //for br/
  533.                         if (tagparam) && (strlen(#tagparam) < 4000) GetNextParam();
  534.  
  535.                         if (stolbec + strlen(#line) > lines.column_max) //============the same as NEXT_MARK
  536.                         {
  537.                                 perenos_num = strrchr(#line, ' ');
  538.                                 if (!perenos_num) && (strlen(#line)>lines.column_max) perenos_num=lines.column_max;
  539.                                 strcpy(#temp, #line + perenos_num); //ïåðåíîñ ïî ñëîâàì
  540.                                 line[perenos_num] = 0x00;
  541.                                 if (stroka-1 > lines.visible) && (lines.first <>0) break 1; //óõîäèì...
  542.                                 DrawPage();
  543.                                 strcpy(#line, #temp);                          
  544.                                 TextGoDown(left + 5, stroka * 10 + top + 5, width - 20); //çàêðàøèâàåì ñëåäóùóþ ñòðîêó
  545.                         }
  546.                         DrawPage();
  547.                         line=NULL;
  548.  
  549.                         if (tag) WhatTextStyle(left + 5, stroka * 10 + top + 5, width - 20); //îáðàáîòêà òåãîâ
  550.  
  551.                         tag = parametr = tagparam = ignor_param = NULL;
  552.                         break;
  553.                 default:
  554.                         DEFAULT_MARK:
  555.                         if (bukva<=15) bukva=' ';
  556.                         if (!pre_text) && (bukva == ' ')
  557.                         {
  558.                                 if (line[strlen(#line)-1]==' ') break; //óáðàòü 2 ïðîáåëà ïîäðÿä
  559.                                 if (!stolbec) && (!line) break; //ñòðîêà íå ìîæåò íà÷èíàòüñÿ ñ ïðîáåëà
  560.                         }
  561.                         if (strlen(#line)<sizeof(line)) chrcat(#line, bukva);
  562.  
  563.                         if (stolbec + strlen(#line) > lines.column_max)
  564.                         {
  565.                         NEXT_MARK:
  566.                                 perenos_num = strrchr(#line, ' ');
  567.                                 if (!perenos_num) && (strlen(#line)>lines.column_max) perenos_num=lines.column_max;
  568.                                 strcpy(#temp, #line + perenos_num); //ïåðåíîñ ïî ñëîâàì
  569.                                 line[perenos_num] = 0x00;
  570.                                 if (stroka-1 > lines.visible) && (lines.first <>0) break 1; //óõîäèì...
  571.                                 DrawPage();
  572.                                 strcpy(#line, #temp);                  
  573.                                 TextGoDown(left + 5, stroka * 10 + top + 5, width - 20); //çàêðàøèâàåì ñëåäóùóþ ñòðîêó
  574.                         }
  575.                 }
  576.         }
  577.  
  578.         DrawPage(); //ðèñóåò ïîñëåäíþþ ñòðîêó, ïîòîì ýòî íàäî óáðàòü, îïòèìèçèðîâàâ êîä
  579.         TextGoDown(left + 5, stroka * 10 + top + 5, width - 20); //çàêðàøèâàåì ñëåäóùóþ ñòðîêó
  580.  
  581.         if (lines.visible * 10 + 25 <= height)
  582.                 DrawBar(left, lines.visible * 10 + top + 25, width, -lines.visible * 10 + height - 25, bg_color);
  583.         if (stroka * 10 + 5 <= height)
  584.                 DrawBar(left, stroka * 10 + top + 5, width, -stroka * 10 + height - 5, bg_color); //çàêðàøèâàåì âñ¸ äî êîíöà
  585.         if (lines.first == 0) lines.all = stroka;
  586.         if (anchor) //åñëè ïîñðåäè òåêñòà ïîÿâèòñÿ íîâûé ÿêîðü - áóäåò áåñêîíå÷íûé öèêë
  587.         {
  588.                 anchor=NULL;
  589.                 lines.first=anchor_line_num;
  590.                 ParseHTML(buf);
  591.         }
  592.         DrawScroller();
  593. }
  594.  
  595.  
  596.  
  597. char oldtag[100];
  598. void TWebBrowser::WhatTextStyle(int left1, top1, width1) {
  599.         dword hr_color;
  600.  
  601.         //ïðîâåðÿåì òåã îòêðûâàåòñÿ èëè çàêðûâàåòñÿ
  602.         if (tag[0] == '/')
  603.         {
  604.                  rez = 0;
  605.                  strcpy(#tag, #tag+1);
  606.         }
  607.         else rez = 1;
  608.                
  609.         if (!chTag("html"))
  610.         {
  611.                 IF(!strcmp(#URL + strlen(#URL) - 4, ".mht")) IF (rez==0) ignor_text = 1; ELSE ignor_text = 0;
  612.                 return;
  613.         }
  614.  
  615.         if (!chTag("script")) || (!chTag("style")) || (!chTag("binary")) ignor_text = rez;
  616.  
  617.         if(!chTag("title"))
  618.         {
  619.                 if (rez) header=NULL;
  620.                 else if (!stroka) DrawTitle(#header); //òåã çàêðûëñÿ - âûâåëè ñòðîêó
  621.                 return;
  622.         }
  623.  
  624.         if (ignor_text) return;
  625.  
  626.  
  627.        
  628.         IF(!chTag("q")) strcat(#line, "\"");
  629.  
  630.         if (anchor) && (!strcmp(#parametr, "id=")) //î÷åíü ïëîõî!!! ïîòîìó ÷òî åñëè íå ïîñëåäíèé òåã, ðàáîòàòü íå áóäåò
  631.         {
  632.                 if (!strcmp(#anchor, #options)) anchor_line_num=lines.first+stroka;
  633.         }
  634.        
  635.         if (!chTag("body"))
  636.         {
  637.                 do{
  638.                         if (!strcmp(#parametr, "link=")) link_color = GetColor(#options);
  639.                         if (!strcmp(#parametr, "text=")) text_colors[0]=GetColor(#options);
  640.                         if (!strcmp(#parametr, "bgcolor="))
  641.                         {
  642.                                 bg_color=GetColor(#options);
  643.                                 DrawBufFill();
  644.                         }
  645.                 } while(GetNextParam());
  646.                 return;
  647.         }
  648.  
  649.         if (!chTag("a"))
  650.         {
  651.                 if (rez)
  652.                 {
  653.                         if (link) IF(text_color_index > 0) text_color_index--; //åñëè ïðåäûäóùèé òåã à íå áûë çàêðûò
  654.  
  655.                         do{
  656.                                 if (!strcmp(#parametr, "href="))
  657.                                 {
  658.                                         if (stroka - 1 > lines.visible) || (stroka < -2) return;
  659.                                        
  660.                                         text_color_index++;
  661.                                         text_colors[text_color_index] = text_colors[text_color_index-1];
  662.                                        
  663.                                         link = 1;
  664.                                         blink++;
  665.                                         text_colors[text_color_index] = link_color;
  666.                                         strcat(#page_links, #options);
  667.                                         strcat(#page_links, "|");
  668.                                 }
  669.                                 if (anchor) && (!strcmp(#parametr, "name="))
  670.                                 {
  671.                                         if (!strcmp(#anchor, #options))
  672.                                         {
  673.                                                 anchor_line_num=lines.first+stroka;
  674.                                         }
  675.                                 }
  676.                         } while(GetNextParam());
  677.                 }
  678.                 else {
  679.                         link = 0;
  680.                         IF(text_color_index > 0) text_color_index--;
  681.                 }
  682.                 return;
  683.         }
  684.  
  685.         if (!chTag("font"))
  686.         {
  687.                 if (rez)
  688.                 {
  689.                         text_color_index++;
  690.                         text_colors[text_color_index] = text_colors[text_color_index-1];
  691.                
  692.                         do{
  693.                                 if (strcmp(#parametr, "color=") == 0) //&& (parametr[1] == '#')
  694.                                 {
  695.                                         text_colors[text_color_index] = GetColor(#options);
  696.                                 }
  697.                         } while(GetNextParam());
  698.                 }
  699.                 else
  700.                         if (text_color_index > 0) text_color_index--;
  701.                 return;
  702.         }
  703.         if(!chTag("tr")) || (!chTag("br")) {
  704.                 TextGoDown(left1, top1, width1);
  705.                 return;
  706.         }
  707.         if (!chTag("div")) {
  708.                 IF(oldtag[0] <>'h') TextGoDown(left1, top1, width1);
  709.                 return;
  710.         }
  711.         if (!chTag("p")) {
  712.                 IF(oldtag[0] == 'h') return;
  713.                 TextGoDown(left1, top1, width1);
  714.                 IF(rez) TextGoDown(left1, top1 + 10, width1);
  715.                 return;
  716.         }
  717.         if (!chTag("h1")) || (!chTag("h2")) || (!chTag("h3")) || (!chTag("h4")) {
  718.                 TextGoDown(left1, top1, width1);
  719.                 IF(rez) TextGoDown(left1, top1 + 10, width1);
  720.                 b_text = rez;
  721.                 strcpy(#oldtag, #tag);
  722.                 return;
  723.         }
  724.         else
  725.                 oldtag=NULL;
  726.                
  727.         if (!chTag("b")) || (!chTag("strong")) || (!chTag("big")) {
  728.                 b_text = rez;
  729.                 return;
  730.         }
  731.         if(!chTag("i")) || (!chTag("em")) || (!chTag("subtitle")) {
  732.                 i_text = rez;
  733.                 return;
  734.         }      
  735.         if (!chTag("dt"))
  736.         {
  737.                 li_text = rez;
  738.                 IF(rez == 0) return;
  739.                 TextGoDown(left1, top1, width1);
  740.                 return;
  741.         }
  742.         if(!chTag("li")) || (!chTag("dt")) //íàäî ñäåëàòü âëîæåííûå ñïèñêè
  743.         {
  744.                 li_text = rez;
  745.                 if (rez)
  746.                 {
  747.                         TextGoDown(left1, top1, width1);
  748.                         if (stroka > -1) && (stroka - 2 < lines.visible) DrawBufBar(li_tab * 5 * 6 + left1 - 5, line_h/2-3, 2, 2, 0x555555);
  749.                 }
  750.                 return;
  751.         }
  752.         if (!chTag("u")) || (!chTag("ins")) u_text = rez;
  753.         if (!chTag("s")) || (!chTag("strike")) || (!chTag("del")) s_text = rez;
  754.         if (!chTag("ul")) || (!chTag("ol")) IF(!rez)
  755.         {
  756.                 li_text = rez;
  757.                 li_tab--;
  758.                 TextGoDown(left1, top1, width1);
  759.         } ELSE li_tab++;
  760.         if (!chTag("dd")) stolbec += 5;
  761.         if (!chTag("blockquote")) blq_text = rez;
  762.         if (!chTag("pre")) pre_text = rez;
  763.         if (!chTag("hr"))
  764.         {
  765.                 if (anchor) || (stroka < -1)
  766.                 {
  767.                         stroka+=2;
  768.                         return;
  769.                 }
  770.                 if (strcmp(#parametr, "color=") == 0) hr_color = GetColor(#options); else hr_color = 0x999999;
  771.                 TextGoDown(left1, top1, width1);
  772.                 DrawBufBar(5, WB1.line_h/2, WB1.width-10, 1, hr_color);
  773.                 TextGoDown(left1, top1+WB1.line_h, width1);
  774.         }
  775.         /*
  776.         if (!chTag("input"))
  777.         {
  778.                 do{
  779.                         if (!strcmp(#parametr, "type="))
  780.                         {
  781.                                 if ((!strcmp(#options, "radio")) || (!strcmp(#options, "checkbox")))
  782.                                 {
  783.                                         if (!anchor) && (stroka > 0) CheckBox(stolbec*6 + left1,top1-2,10,10, 0, "\0", 0x888888, text_colors[text_color_index], 0);
  784.                                         stolbec+=2;
  785.                                 }
  786.                                 if ((!strcmp(#options, "text")) || (!strcmp(#options, "password")))
  787.                                 {
  788.                                         if (!anchor) && (stroka > 0) CheckBox(stolbec*6 + left1,top1-2,90,10, 0, "\0", 0x555555, 0, 0);
  789.                                         stolbec+=16;
  790.                                 }
  791.                                 if ((!strcmp(#options, "button")) || (!strcmp(#options, "file")) || (!strcmp(#options, "submit")))
  792.                                 {
  793.                                         if (!anchor) && (stroka > 0) DrawCaptButton(stolbec*6 + left1,top1-2,60,10, 0, 0xCCCccc, 0, "Button");
  794.                                         stolbec+=21;
  795.                                 }
  796.                         }
  797.                 } while(GetNextParam());
  798.         }
  799.         */
  800.         if (!chTag("img"))
  801.         {
  802.                 Images( left1, top1, width1);
  803.                 return;
  804.         }
  805.         if (!chTag("meta")) || (!chTag("?xml"))
  806.         {
  807.                 do{
  808.                         if (!strcmp(#parametr, "charset=")) || (!strcmp(#parametr, "content=")) || (!strcmp(#parametr, "encoding="))
  809.                         {
  810.                                 strcpy(#options, #options[strrchr(#options, '=')]); //ïîèñê â content=
  811.                                 if (!strcmp(#options,"utf-8"))   || (!strcmp(#options,"utf8"))      ReadHtml(_UTF);
  812.                                 if (!strcmp(#options, "koi8-r")) || (!strcmp(#options, "koi8-u"))   ReadHtml(_KOI);
  813.                                 if (!strcmp(#options, "dos"))    || (!strcmp(#options, "cp-866"))   ReadHtml(_DOS);
  814.                         }
  815.                 } while(GetNextParam());
  816.                 return;
  817.         }
  818. }
  819.  
  820.  
  821.  
  822. void TWebBrowser::DrawScroller() //íå îïòèìàëüíàÿ îòðèñîâêà, íî çàòî â îäíîì ìåñòå
  823. {
  824.         scroll1.max_area = lines.all;
  825.         scroll1.cur_area = lines.visible;
  826.         scroll1.position = lines.first;
  827.  
  828.         scroll1.all_redraw=1;
  829.         scroll1.start_x = WB1.left + WB1.width;
  830.         scroll1.size_y=WB1.height;
  831.  
  832.         scrollbar_v_draw(#scroll1);
  833. }
  834.  
  835.