Subversion Repositories Kolibri OS

Rev

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