Subversion Repositories Kolibri OS

Rev

Rev 3477 | 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.02a";
  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.                 /*
  379.                 pause(60);
  380.                 if (GetProcessSlot(downloader_id)<>0)
  381.                 {
  382.                         debug("Browser Hack v2.0: Killing downloader and trying to run it one more!");
  383.                         KillProcess(downloader_id); //óáèâàåì ñòàðûé ïðîöåññ
  384.                         downloader_id = RunProgram("/sys/network/downloader", #URL);
  385.                 }
  386.                 */
  387.                 IF (downloader_id<0) RunProgram("@notify", "Error running Downloader. Internet unavilable.");
  388.                 Draw_Window();
  389.                 return;
  390.         }
  391.         lines.first = lines.all =0;
  392.         ReadHtml(_WIN);
  393.         WB1.ShowPage();
  394. }
  395.  
  396.  
  397. void TWebBrowser::ShowPage()
  398. {
  399.         address_box.size = address_box.pos = strlen(#editURL);
  400.         address_box.offset=0;
  401.         edit_box_draw stdcall(#address_box);
  402.  
  403.         if (!filesize)
  404.         {
  405.                 DrawBar(left, top, width+scroll1.size_x+1, height, 0xFFFFFF); //fill all
  406.                 if (GetProcessSlot(downloader_id)<>0) WriteText(left + 10, top + 18, 0x80, 0, "Loading...");
  407.                 else
  408.                 {
  409.                         WriteText(left + 10, top + 18, 0x80, 0, "Page not found. May be, URL contains some errors.");
  410.                         if (!strcmp(get_URL_part(5),"http:"))) WriteText(left + 10, top + 32, 0x80, 0, "Or Internet unavilable for your configuration.");
  411.                 }
  412.                 //return;
  413.         }
  414.         else
  415.                 ParseHTML(buf);
  416.  
  417.         if (!header) strcpy(#header, #version);
  418.         if (!strcmp(#version, #header)) DrawTitle(#header);
  419. }
  420.  
  421.  
  422.  
  423. void TWebBrowser::ParseHTML(dword bword){
  424.         word bukva[2];
  425.         int j, perenos_num;
  426.         byte ignor_param;
  427.         char temp[768];
  428.        
  429.         if (blink<400) blink=400; else for ( ; blink>400; blink--;) DeleteButton(blink);
  430.         b_text = i_text = u_text = s_text = blq_text =
  431.         li_text = link = ignor_text = text_color_index = text_colors[0] = li_tab = 0; //îáíóëÿåì òåãè
  432.         link_color = 0x0000FF;
  433.         bg_color = 0xFFFFFF;
  434.         DrawBufFill();
  435.         line = NULL;
  436.         strcpy(#page_links,"|");
  437.         strcpy(#header, #version);
  438.         stroka = -lines.first;
  439.         stolbec = 0;
  440.  
  441.         if (pre_text<>2)
  442.         {
  443.                 pre_text=0;
  444.                 if (!strcmp(#URL + strlen(#URL) - 4, ".txt")) pre_text = 1;
  445.                 if (!strcmp(#URL + strlen(#URL) - 4, ".mht")) ignor_text = 1;
  446.         }
  447.        
  448.         for ( ; buf+filesize > bword; bword++;)
  449.         {
  450.                 bukva = ESBYTE[bword];
  451.                 if (ignor_text) && (bukva<>'<') continue;
  452.                 switch (bukva)
  453.                 {
  454.                 case 0x0a:
  455.                         if (pre_text)
  456.                         {
  457.                                 bukva = temp = NULL;
  458.                                 goto NEXT_MARK;
  459.                         }
  460.                 case '\9':
  461.                         if (pre_text) //èíà÷å èä¸ì íà 0x0d     
  462.                         {
  463.                                 tab_len=strlen(#line)/8;
  464.                                 tab_len=tab_len*8;
  465.                                 tab_len=8+tab_len-strlen(#line);
  466.                                 for (j=0; j<tab_len; j++;) chrcat(#line,' ');
  467.                                 break;
  468.                         }
  469.                         goto DEFAULT_MARK;             
  470.                 case '=': //quoted printable
  471.                         if (strcmp(#URL + strlen(#URL) - 4, ".mht")<>0) goto DEFAULT_MARK;
  472.  
  473.                         temp[0] = ESBYTE[bword+1];
  474.                         temp[1] = ESBYTE[bword+2];
  475.                         temp[2] = '\0';
  476.                         if (bukva = Hex2Symb(#temp))
  477.                         {
  478.                                 bword+=2;
  479.                                 goto DEFAULT_MARK;
  480.                         }
  481.                         break;
  482.                        
  483.                 case '&': //&nbsp; and so on
  484.                         bword++;
  485.                         tag=0;
  486.                         for (j=0; (ESBYTE[bword]<>';') && (j<7);   j++, bword++;)
  487.                         {
  488.                                 bukva = ESBYTE[bword];
  489.                                 chrcat(#tag, bukva);
  490.                         }
  491.                        
  492.                         bukva = GetUnicodeSymbol();
  493.                         if (bukva) goto DEFAULT_MARK;
  494.                         break;
  495.                 case '<':
  496.                         bword++; //ïðîìîòàåì ñèìâîë <
  497.                         tag = parametr = tagparam = ignor_param = NULL;
  498.                         if (ESBYTE[bword] == '!') //ôèëüòðàöèÿ âíóòðè <!-- -->, äåðçêî
  499.                         {
  500.                                 bword++;
  501.                                 if (ESBYTE[bword] == '-')
  502.                                 {
  503.                                 HH_:
  504.                                         do
  505.                                         {
  506.                                                 bword++;
  507.                                                 if (buf + filesize <= bword) break 2;
  508.                                         }
  509.                                         while (ESBYTE[bword] <>'-');
  510.                                        
  511.                                         bword++;
  512.                                         if (ESBYTE[bword] <>'-') goto HH_;
  513.                                 }
  514.                         }
  515.                         while (ESBYTE[bword] !='>') && (bword < buf + filesize) //ïîëó÷àåì òåã è åãî ïàðàìåòðû
  516.                         {
  517.                                 bukva = ESBYTE[bword];
  518.                                 if (bukva == '\9') || (bukva == '\x0a') || (bukva == '\x0d') bukva = ' ';
  519.                                 if (!ignor_param) && (bukva <>' ')
  520.                                 {
  521.                                         if (strlen(#tag)<sizeof(tag)) strcat(#tag, #bukva);
  522.                                 }
  523.                                 else
  524.                                 {
  525.                                         ignor_param = true;
  526.                                         if (!ignor_text) && (strlen(#tagparam)+1<sizeof(tagparam)) strcat(#tagparam, #bukva);
  527.                                 }
  528.                                 bword++;
  529.                         }
  530.                         strlwr(#tag);
  531.                         strlwr(#tagparam);
  532.  
  533.                         if (tag[strlen(#tag)-1]=='/') tag[strlen(#tag)-1]=NULL; //for br/
  534.                         if (tagparam) && (strlen(#tagparam) < 4000) GetNextParam();
  535.  
  536.                         if (stolbec + strlen(#line) > lines.column_max) //============the same as NEXT_MARK
  537.                         {
  538.                                 perenos_num = strrchr(#line, ' ');
  539.                                 if (!perenos_num) && (strlen(#line)>lines.column_max) perenos_num=lines.column_max;
  540.                                 strcpy(#temp, #line + perenos_num); //ïåðåíîñ ïî ñëîâàì
  541.                                 line[perenos_num] = 0x00;
  542.                                 if (stroka-1 > lines.visible) && (lines.first <>0) break 1; //óõîäèì...
  543.                                 DrawPage();
  544.                                 strcpy(#line, #temp);                          
  545.                                 TextGoDown(left + 5, stroka * 10 + top + 5, width - 20); //çàêðàøèâàåì ñëåäóùóþ ñòðîêó
  546.                         }
  547.                         DrawPage();
  548.                         line=NULL;
  549.  
  550.                         if (tag) WhatTextStyle(left + 5, stroka * 10 + top + 5, width - 20); //îáðàáîòêà òåãîâ
  551.  
  552.                         tag = parametr = tagparam = ignor_param = NULL;
  553.                         break;
  554.                 default:
  555.                         DEFAULT_MARK:
  556.                         if (bukva<=15) bukva=' ';
  557.                         if (!pre_text) && (bukva == ' ')
  558.                         {
  559.                                 if (line[strlen(#line)-1]==' ') break; //óáðàòü 2 ïðîáåëà ïîäðÿä
  560.                                 if (!stolbec) && (!line) break; //ñòðîêà íå ìîæåò íà÷èíàòüñÿ ñ ïðîáåëà
  561.                         }
  562.                         if (strlen(#line)<sizeof(line)) chrcat(#line, bukva);
  563.  
  564.                         if (stolbec + strlen(#line) > lines.column_max)
  565.                         {
  566.                         NEXT_MARK:
  567.                                 perenos_num = strrchr(#line, ' ');
  568.                                 if (!perenos_num) && (strlen(#line)>lines.column_max) perenos_num=lines.column_max;
  569.                                 strcpy(#temp, #line + perenos_num); //ïåðåíîñ ïî ñëîâàì
  570.                                 line[perenos_num] = 0x00;
  571.                                 if (stroka-1 > lines.visible) && (lines.first <>0) break 1; //óõîäèì...
  572.                                 DrawPage();
  573.                                 strcpy(#line, #temp);                  
  574.                                 TextGoDown(left + 5, stroka * 10 + top + 5, width - 20); //çàêðàøèâàåì ñëåäóùóþ ñòðîêó
  575.                         }
  576.                 }
  577.         }
  578.  
  579.         DrawPage(); //ðèñóåò ïîñëåäíþþ ñòðîêó, ïîòîì ýòî íàäî óáðàòü, îïòèìèçèðîâàâ êîä
  580.         TextGoDown(left + 5, stroka * 10 + top + 5, width - 20); //çàêðàøèâàåì ñëåäóùóþ ñòðîêó
  581.  
  582.         if (lines.visible * 10 + 25 <= height)
  583.                 DrawBar(left, lines.visible * 10 + top + 25, width, -lines.visible * 10 + height - 25, bg_color);
  584.         if (stroka * 10 + 5 <= height)
  585.                 DrawBar(left, stroka * 10 + top + 5, width, -stroka * 10 + height - 5, bg_color); //çàêðàøèâàåì âñ¸ äî êîíöà
  586.         if (lines.first == 0) lines.all = stroka;
  587.         if (anchor) //åñëè ïîñðåäè òåêñòà ïîÿâèòñÿ íîâûé ÿêîðü - áóäåò áåñêîíå÷íûé öèêë
  588.         {
  589.                 anchor=NULL;
  590.                 lines.first=anchor_line_num;
  591.                 ParseHTML(buf);
  592.         }
  593.         DrawScroller();
  594. }
  595.  
  596.  
  597.  
  598. char oldtag[100];
  599. void TWebBrowser::WhatTextStyle(int left1, top1, width1) {
  600.         dword hr_color;
  601.  
  602.         //ïðîâåðÿåì òåã îòêðûâàåòñÿ èëè çàêðûâàåòñÿ
  603.         if (tag[0] == '/')
  604.         {
  605.                  rez = 0;
  606.                  strcpy(#tag, #tag+1);
  607.         }
  608.         else rez = 1;
  609.                
  610.         if (!chTag("html"))
  611.         {
  612.                 IF(!strcmp(#URL + strlen(#URL) - 4, ".mht")) IF (rez==0) ignor_text = 1; ELSE ignor_text = 0;
  613.                 return;
  614.         }
  615.  
  616.         if (!chTag("script")) || (!chTag("style")) || (!chTag("binary")) ignor_text = rez;
  617.  
  618.         if(!chTag("title"))
  619.         {
  620.                 if (rez) header=NULL;
  621.                 else if (!stroka) DrawTitle(#header); //òåã çàêðûëñÿ - âûâåëè ñòðîêó
  622.                 return;
  623.         }
  624.  
  625.         if (ignor_text) return;
  626.  
  627.  
  628.        
  629.         IF(!chTag("q")) strcat(#line, "\"");
  630.  
  631.         if (anchor) && (!strcmp(#parametr, "id=")) //î÷åíü ïëîõî!!! ïîòîìó ÷òî åñëè íå ïîñëåäíèé òåã, ðàáîòàòü íå áóäåò
  632.         {
  633.                 if (!strcmp(#anchor, #options)) anchor_line_num=lines.first+stroka;
  634.         }
  635.        
  636.         if (!chTag("body"))
  637.         {
  638.                 do{
  639.                         if (!strcmp(#parametr, "link=")) link_color = GetColor(#options);
  640.                         if (!strcmp(#parametr, "text=")) text_colors[0]=GetColor(#options);
  641.                         if (!strcmp(#parametr, "bgcolor="))
  642.                         {
  643.                                 bg_color=GetColor(#options);
  644.                                 DrawBufFill();
  645.                         }
  646.                 } while(GetNextParam());
  647.                 return;
  648.         }
  649.  
  650.         if (!chTag("a"))
  651.         {
  652.                 if (rez)
  653.                 {
  654.                         if (link) IF(text_color_index > 0) text_color_index--; //åñëè ïðåäûäóùèé òåã à íå áûë çàêðûò
  655.  
  656.                         do{
  657.                                 if (!strcmp(#parametr, "href="))
  658.                                 {
  659.                                         if (stroka - 1 > lines.visible) || (stroka < -2) return;
  660.                                        
  661.                                         text_color_index++;
  662.                                         text_colors[text_color_index] = text_colors[text_color_index-1];
  663.                                        
  664.                                         link = 1;
  665.                                         blink++;
  666.                                         text_colors[text_color_index] = link_color;
  667.                                         strcat(#page_links, #options);
  668.                                         strcat(#page_links, "|");
  669.                                 }
  670.                                 if (anchor) && (!strcmp(#parametr, "name="))
  671.                                 {
  672.                                         if (!strcmp(#anchor, #options))
  673.                                         {
  674.                                                 anchor_line_num=lines.first+stroka;
  675.                                         }
  676.                                 }
  677.                         } while(GetNextParam());
  678.                 }
  679.                 else {
  680.                         link = 0;
  681.                         IF(text_color_index > 0) text_color_index--;
  682.                 }
  683.                 return;
  684.         }
  685.  
  686.         if (!chTag("font"))
  687.         {
  688.                 if (rez)
  689.                 {
  690.                         text_color_index++;
  691.                         text_colors[text_color_index] = text_colors[text_color_index-1];
  692.                
  693.                         do{
  694.                                 if (strcmp(#parametr, "color=") == 0) //&& (parametr[1] == '#')
  695.                                 {
  696.                                         text_colors[text_color_index] = GetColor(#options);
  697.                                 }
  698.                         } while(GetNextParam());
  699.                 }
  700.                 else
  701.                         if (text_color_index > 0) text_color_index--;
  702.                 return;
  703.         }
  704.         if(!chTag("tr")) || (!chTag("br")) {
  705.                 TextGoDown(left1, top1, width1);
  706.                 return;
  707.         }
  708.         if (!chTag("div")) {
  709.                 IF(oldtag[0] <>'h') TextGoDown(left1, top1, width1);
  710.                 return;
  711.         }
  712.         if (!chTag("p")) {
  713.                 IF(oldtag[0] == 'h') return;
  714.                 TextGoDown(left1, top1, width1);
  715.                 IF(rez) TextGoDown(left1, top1 + 10, width1);
  716.                 return;
  717.         }
  718.         if (!chTag("h1")) || (!chTag("h2")) || (!chTag("h3")) || (!chTag("h4")) {
  719.                 TextGoDown(left1, top1, width1);
  720.                 IF(rez) TextGoDown(left1, top1 + 10, width1);
  721.                 b_text = rez;
  722.                 strcpy(#oldtag, #tag);
  723.                 return;
  724.         }
  725.         else
  726.                 oldtag=NULL;
  727.                
  728.         if (!chTag("b")) || (!chTag("strong")) || (!chTag("big")) {
  729.                 b_text = rez;
  730.                 return;
  731.         }
  732.         if(!chTag("i")) || (!chTag("em")) || (!chTag("subtitle")) {
  733.                 i_text = rez;
  734.                 return;
  735.         }      
  736.         if (!chTag("dt"))
  737.         {
  738.                 li_text = rez;
  739.                 IF(rez == 0) return;
  740.                 TextGoDown(left1, top1, width1);
  741.                 return;
  742.         }
  743.         if(!chTag("li")) || (!chTag("dt")) //íàäî ñäåëàòü âëîæåííûå ñïèñêè
  744.         {
  745.                 li_text = rez;
  746.                 if (rez)
  747.                 {
  748.                         TextGoDown(left1, top1, width1);
  749.                         if (stroka > -1) && (stroka - 2 < lines.visible) DrawBufBar(li_tab * 5 * 6 + left1 - 5, line_h/2-3, 2, 2, 0x555555);
  750.                 }
  751.                 return;
  752.         }
  753.         if (!chTag("u")) || (!chTag("ins")) u_text = rez;
  754.         if (!chTag("s")) || (!chTag("strike")) || (!chTag("del")) s_text = rez;
  755.         if (!chTag("ul")) || (!chTag("ol")) IF(!rez)
  756.         {
  757.                 li_text = rez;
  758.                 li_tab--;
  759.                 TextGoDown(left1, top1, width1);
  760.         } ELSE li_tab++;
  761.         if (!chTag("dd")) stolbec += 5;
  762.         if (!chTag("blockquote")) blq_text = rez;
  763.         if (!chTag("pre")) pre_text = rez;
  764.         if (!chTag("hr"))
  765.         {
  766.                 if (anchor) || (stroka < -1)
  767.                 {
  768.                         stroka+=2;
  769.                         return;
  770.                 }
  771.                 if (strcmp(#parametr, "color=") == 0) hr_color = GetColor(#options); else hr_color = 0x999999;
  772.                 TextGoDown(left1, top1, width1);
  773.                 DrawBufBar(5, WB1.line_h/2, WB1.width-10, 1, hr_color);
  774.                 TextGoDown(left1, top1+WB1.line_h, width1);
  775.         }
  776.         /*
  777.         if (!chTag("input"))
  778.         {
  779.                 do{
  780.                         if (!strcmp(#parametr, "type="))
  781.                         {
  782.                                 if ((!strcmp(#options, "radio")) || (!strcmp(#options, "checkbox")))
  783.                                 {
  784.                                         if (!anchor) && (stroka > 0) CheckBox(stolbec*6 + left1,top1-2,10,10, 0, "\0", 0x888888, text_colors[text_color_index], 0);
  785.                                         stolbec+=2;
  786.                                 }
  787.                                 if ((!strcmp(#options, "text")) || (!strcmp(#options, "password")))
  788.                                 {
  789.                                         if (!anchor) && (stroka > 0) CheckBox(stolbec*6 + left1,top1-2,90,10, 0, "\0", 0x555555, 0, 0);
  790.                                         stolbec+=16;
  791.                                 }
  792.                                 if ((!strcmp(#options, "button")) || (!strcmp(#options, "file")) || (!strcmp(#options, "submit")))
  793.                                 {
  794.                                         if (!anchor) && (stroka > 0) DrawCaptButton(stolbec*6 + left1,top1-2,60,10, 0, 0xCCCccc, 0, "Button");
  795.                                         stolbec+=21;
  796.                                 }
  797.                         }
  798.                 } while(GetNextParam());
  799.         }
  800.         */
  801.         if (!chTag("img"))
  802.         {
  803.                 Images( left1, top1, width1);
  804.                 return;
  805.         }
  806.         if (!chTag("meta")) || (!chTag("?xml"))
  807.         {
  808.                 do{
  809.                         if (!strcmp(#parametr, "charset=")) || (!strcmp(#parametr, "content=")) || (!strcmp(#parametr, "encoding="))
  810.                         {
  811.                                 strcpy(#options, #options[strrchr(#options, '=')]); //ïîèñê â content=
  812.                                 if (!strcmp(#options,"utf-8"))   || (!strcmp(#options,"utf8"))      ReadHtml(_UTF);
  813.                                 if (!strcmp(#options, "koi8-r")) || (!strcmp(#options, "koi8-u"))   ReadHtml(_KOI);
  814.                                 if (!strcmp(#options, "dos"))    || (!strcmp(#options, "cp-866"))   ReadHtml(_DOS);
  815.                         }
  816.                 } while(GetNextParam());
  817.                 return;
  818.         }
  819. }
  820.  
  821.  
  822.  
  823. void TWebBrowser::DrawScroller() //íå îïòèìàëüíàÿ îòðèñîâêà, íî çàòî â îäíîì ìåñòå
  824. {
  825.         scroll1.max_area = lines.all;
  826.         scroll1.cur_area = lines.visible;
  827.         scroll1.position = lines.first;
  828.  
  829.         scroll1.all_redraw=1;
  830.         scroll1.start_x = WB1.left + WB1.width;
  831.         scroll1.size_y=WB1.height;
  832.  
  833.         scrollbar_v_draw(#scroll1);
  834. }
  835.  
  836.