Subversion Repositories Kolibri OS

Rev

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