Subversion Repositories Kolibri OS

Rev

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