Subversion Repositories Kolibri OS

Rev

Rev 3986 | 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.04";
  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 052:  //F3
  228.                         if (strcmp(get_URL_part(5),"http:")<>0) RunProgram("/rd/1/tinypad", #URL); else RunProgram("/rd/1/tinypad", #download_path);
  229.                         return;
  230.                 case 054: //F5
  231.                         IF(address_box.flags & 0b10) break;
  232.                 case REFRESH:
  233.                         if (GetProcessSlot(downloader_id)<>0)
  234.                         {
  235.                                 KillProcess(downloader_id);
  236.                                 pause(20);
  237.                                 Draw_Window();
  238.                                 return;
  239.                         }
  240.                         anchor_line_num=lines.first; //âåñ¸ëûé êîñòûëü :Ð
  241.                         anchor[0]='|';
  242.                         OpenPage();
  243.                         return;
  244.                 case 014: //Ctrl+N íîâîå îêíî
  245.                 case 020: //Ctrl+T íîâàÿ âêëàäêà
  246.                 case NEWTAB:
  247.                         MoveSize(190,80,OLD,OLD);
  248.                         RunProgram(#program_path, #URL);
  249.                         return;
  250.                        
  251.                 case HOME:
  252.                         strcpy(#editURL, "http://kolibrios.org/en/index.htm");
  253.                 case GOTOURL:
  254.                 case 0x0D: //enter
  255.                         //ïî÷åìó ttp://? Ãîñïîäà, îòëè÷íûé âîïðîñ. Äåëî â òîì, ÷òî ýòî õàê.
  256.                         //strstr() åñëè íå íàøëî âîçâðàùàåò 0 è â ñëó÷àå óñïåõà âîçâðàùàåò 0. Òàê ÷òî ýòî õàê.
  257.                         if ((strstr(#editURL,"ttp://")==0) && (editURL[0]!='/')) strcpy(#URL,"http://"); else URL[0] = 0;
  258.                         strcat(#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.         strcpy(#editURL, BrowserHistory.CurrentUrl()); //äîñòà¸ì àäðåñ òåêóùåé ñòðàíèöû
  314.  
  315.         if (URL[0] == '/')
  316.         {
  317.                 i = strchr(#editURL+8, '/');
  318.                 editURL[i+7]=0;
  319.                 strcpy(#URL, #URL+1);
  320.         }
  321.                
  322.         _CUT_ST_LEVEL_MARK:
  323.                
  324.                 if (editURL[strrchr(#editURL, '/')-2]<>'/')  // åñëè íå http://
  325.                 {
  326.                         editURL[strrchr(#editURL, '/')] = 0x00; //îáðåçàåì å¸ óðë äî ïîñëåäíåãî /
  327.                 }
  328.                
  329.                 IF (!strcmp(get_URL_part(3),"../")) //íà óðîâåíü ââåðõ
  330.                 {
  331.                         strcpy(#URL,#URL+3);
  332.                         editURL[strrchr(#editURL, '/')-1] = 0x00; //îáðåçàåì å¸ óðë äî ïîñëåäíåãî /
  333.                         goto _CUT_ST_LEVEL_MARK;
  334.                 }
  335.                
  336.                 if (editURL[strlen(#editURL)-1]<>'/') strcat(#editURL, "/");
  337.                
  338.                 strcat(#editURL, #URL); //êëåèì íîâûé àäðåñ
  339.                 strcpy(#URL, #editURL);
  340. }
  341.  
  342.  
  343.        
  344. void TWebBrowser::ReadHtml(byte encoding)
  345. {
  346.         if (!strcmp(get_URL_part(5),"http:")))
  347.                 file_size stdcall (#download_path);
  348.         else
  349.                 file_size stdcall (#URL);
  350.        
  351.         filesize = EBX;
  352.         if (!filesize) return;
  353.        
  354.         mem_Free(buf);
  355.         buf = mem_Alloc(filesize);
  356.         if (!strcmp(get_URL_part(5),"http:")))
  357.                 ReadFile(0, filesize, buf, #download_path);
  358.         else
  359.                 ReadFile(0, filesize, buf, #URL);
  360.                
  361.         cur_encoding = encoding;
  362.         if (encoding==_WIN) wintodos(buf);
  363.         if (encoding==_UTF) utf8rutodos(buf);
  364.         if (encoding==_KOI) koitodos(buf);
  365. }
  366.  
  367.  
  368. void TWebBrowser::OpenPage()
  369. {
  370.         if (GetProcessSlot(downloader_id)<>0) PutPaletteImage(#toolbar,200,42,0,0,8,#toolbar_pal);
  371.         KillProcess(downloader_id);
  372.         strcpy(#editURL, #URL);
  373.         BrowserHistory.AddUrl();
  374.         strcpy(#header, #version);
  375.         pre_text =0;
  376.         if (!strcmp(get_URL_part(5),"http:")))
  377.         {
  378.                 KillProcess(downloader_id); //óáèâàåì ñòàðûé ïðîöåññ
  379.                 DeleteFile(#download_path);
  380.                 IF (URL[strlen(#URL)-1]=='/') URL[strlen(#URL)-1]=NULL;
  381.                 downloader_id = RunProgram("/sys/network/downloader", #URL);
  382.                 //Browser Hack v2.0
  383.                 /*
  384.                 pause(60);
  385.                 if (GetProcessSlot(downloader_id)<>0)
  386.                 {
  387.                         debug("Browser Hack v2.0: Killing downloader and trying to run it one more!");
  388.                         KillProcess(downloader_id); //óáèâàåì ñòàðûé ïðîöåññ
  389.                         downloader_id = RunProgram("/sys/network/downloader", #URL);
  390.                 }
  391.                 */
  392.                 IF (downloader_id<0) RunProgram("@notify", "Error running Downloader. Internet unavilable.");
  393.                 Draw_Window();
  394.                 return;
  395.         }
  396.         lines.first = lines.all =0;
  397.         ReadHtml(_WIN);
  398.         WB1.ShowPage();
  399. }
  400.  
  401.  
  402. void TWebBrowser::ShowPage()
  403. {
  404.         address_box.size = address_box.pos = strlen(#editURL);
  405.         address_box.offset=0;
  406.         edit_box_draw stdcall(#address_box);
  407.  
  408.         if (!filesize)
  409.         {
  410.                 DrawBar(left, top, width+scroll1.size_x+1, height, 0xFFFFFF); //fill all
  411.                 if (GetProcessSlot(downloader_id)<>0) WriteText(left + 10, top + 18, 0x80, 0, "Loading...");
  412.                 else
  413.                 {
  414.                         WriteText(left + 10, top + 18, 0x80, 0, "Page not found. May be, URL contains some errors.");
  415.                         if (!strcmp(get_URL_part(5),"http:"))) WriteText(left + 10, top + 32, 0x80, 0, "Or Internet unavilable for your configuration.");
  416.                 }
  417.                 //return;
  418.         }
  419.         else
  420.                 ParseHTML(buf);
  421.  
  422.         if (!header) strcpy(#header, #version);
  423.         if (!strcmp(#version, #header)) DrawTitle(#header);
  424. }
  425.  
  426.  
  427.  
  428. void TWebBrowser::ParseHTML(dword bword){
  429.         word bukva[2];
  430.         int j, perenos_num;
  431.         byte ignor_param;
  432.         char temp[768];
  433.        
  434.         if (blink<400) blink=400; else for ( ; blink>400; blink--;) DeleteButton(blink);
  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.         DrawBufFill();
  440.         line = NULL;
  441.         strcpy(#page_links,"|");
  442.         strcpy(#header, #version);
  443.         stroka = -lines.first;
  444.         stolbec = 0;
  445.  
  446.         if (pre_text<>2)
  447.         {
  448.                 pre_text=0;
  449.                 if (!strcmp(#URL + strlen(#URL) - 4, ".txt")) pre_text = 1;
  450.                 if (!strcmp(#URL + strlen(#URL) - 4, ".mht")) ignor_text = 1;
  451.         }
  452.        
  453.         for ( ; buf+filesize > bword; bword++;)
  454.         {
  455.                 bukva = ESBYTE[bword];
  456.                 if (ignor_text) && (bukva<>'<') continue;
  457.                 switch (bukva)
  458.                 {
  459.                 case 0x0a:
  460.                         if (pre_text)
  461.                         {
  462.                                 bukva = temp = NULL;
  463.                                 goto NEXT_MARK;
  464.                         }
  465.                 case '\9':
  466.                         if (pre_text) //èíà÷å èä¸ì íà 0x0d     
  467.                         {
  468.                                 tab_len=strlen(#line)/8;
  469.                                 tab_len=tab_len*8;
  470.                                 tab_len=8+tab_len-strlen(#line);
  471.                                 for (j=0; j<tab_len; j++;) chrcat(#line,' ');
  472.                                 break;
  473.                         }
  474.                         goto DEFAULT_MARK;             
  475.                 case '=': //quoted printable
  476.                         if (strcmp(#URL + strlen(#URL) - 4, ".mht")<>0) goto DEFAULT_MARK;
  477.  
  478.                         temp[0] = ESBYTE[bword+1];
  479.                         temp[1] = ESBYTE[bword+2];
  480.                         temp[2] = '\0';
  481.                         if (bukva = Hex2Symb(#temp))
  482.                         {
  483.                                 bword+=2;
  484.                                 goto DEFAULT_MARK;
  485.                         }
  486.                         break;
  487.                        
  488.                 case '&': //&nbsp; and so on
  489.                         bword++;
  490.                         tag=0;
  491.                         for (j=0; (ESBYTE[bword]<>';') && (j<7);   j++, bword++;)
  492.                         {
  493.                                 bukva = ESBYTE[bword];
  494.                                 chrcat(#tag, bukva);
  495.                         }
  496.                        
  497.                         bukva = GetUnicodeSymbol();
  498.                         if (bukva) goto DEFAULT_MARK;
  499.                         break;
  500.                 case '<':
  501.                         bword++; //ïðîìîòàåì ñèìâîë <
  502.                         tag = parametr = tagparam = ignor_param = NULL;
  503.                         if (ESBYTE[bword] == '!') //ôèëüòðàöèÿ âíóòðè <!-- -->, äåðçêî
  504.                         {
  505.                                 bword++;
  506.                                 if (ESBYTE[bword] == '-')
  507.                                 {
  508.                                 HH_:
  509.                                         do
  510.                                         {
  511.                                                 bword++;
  512.                                                 if (buf + filesize <= bword) break 2;
  513.                                         }
  514.                                         while (ESBYTE[bword] <>'-');
  515.                                        
  516.                                         bword++;
  517.                                         if (ESBYTE[bword] <>'-') goto HH_;
  518.                                 }
  519.                         }
  520.                         while (ESBYTE[bword] !='>') && (bword < buf + filesize) //ïîëó÷àåì òåã è åãî ïàðàìåòðû
  521.                         {
  522.                                 bukva = ESBYTE[bword];
  523.                                 if (bukva == '\9') || (bukva == '\x0a') || (bukva == '\x0d') bukva = ' ';
  524.                                 if (!ignor_param) && (bukva <>' ')
  525.                                 {
  526.                                         if (strlen(#tag)<sizeof(tag)) strcat(#tag, #bukva);
  527.                                 }
  528.                                 else
  529.                                 {
  530.                                         ignor_param = true;
  531.                                         if (!ignor_text) && (strlen(#tagparam)+1<sizeof(tagparam)) strcat(#tagparam, #bukva);
  532.                                 }
  533.                                 bword++;
  534.                         }
  535.                         strlwr(#tag);
  536.                         strlwr(#tagparam);
  537.  
  538.                         if (tag[strlen(#tag)-1]=='/') tag[strlen(#tag)-1]=NULL; //for br/
  539.                         if (tagparam) && (strlen(#tagparam) < 4000) GetNextParam();
  540.  
  541.                         if (stolbec + strlen(#line) > lines.column_max) //============the same as NEXT_MARK
  542.                         {
  543.                                 perenos_num = strrchr(#line, ' ');
  544.                                 if (!perenos_num) && (strlen(#line)>lines.column_max) perenos_num=lines.column_max;
  545.                                 strcpy(#temp, #line + perenos_num); //ïåðåíîñ ïî ñëîâàì
  546.                                 line[perenos_num] = 0x00;
  547.                                 if (stroka-1 > lines.visible) && (lines.first <>0) break 1; //óõîäèì...
  548.                                 DrawPage();
  549.                                 strcpy(#line, #temp);                          
  550.                                 TextGoDown(left + 5, stroka * 10 + top + 5, width - 20); //çàêðàøèâàåì ñëåäóùóþ ñòðîêó
  551.                         }
  552.                         DrawPage();
  553.                         line=NULL;
  554.  
  555.                         if (tag) WhatTextStyle(left + 5, stroka * 10 + top + 5, width - 20); //îáðàáîòêà òåãîâ
  556.  
  557.                         tag = parametr = tagparam = ignor_param = NULL;
  558.                         break;
  559.                 default:
  560.                         DEFAULT_MARK:
  561.                         if (bukva<=15) bukva=' ';
  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.