Subversion Repositories Kolibri OS

Rev

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