Subversion Repositories Kolibri OS

Rev

Rev 3059 | 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.                         if (stolbec + strlen(#line) > lines.column_max)
  467.                         {
  468.                                 perenos_num = strrchr(#line, ' ');
  469.                                 if (!perenos_num) && (strlen(#line)>lines.column_max) perenos_num=lines.column_max;
  470.                                 strcpy(#temp, #line + perenos_num); //ïåðåíîñ ïî ñëîâàì
  471.                                 line[perenos_num] = 0x00;
  472.                                 if (stroka >= lines.visible) && (lines.first <>0) break 1; //óõîäèì...
  473.                                 DrawPage();
  474.                                 strcpy(#line, #temp);
  475.                                
  476.                                 TextGoDown(left + 5, stroka * 10 + top + 5, width - 20); //çàêðàøèâàåì ñëåäóùóþ ñòðîêó
  477.                         }
  478.                         DrawPage();
  479.                         line=NULL;
  480.  
  481.                         if (tag) WhatTextStyle(left + 5, stroka * 10 + top + 5, width - 20); //îáðàáîòêà òåãîâ
  482.  
  483.                         tag = parametr = tagparam = ignor_param = NULL;
  484.                         break;
  485.                 default:
  486.                         DEFAULT_MARK:
  487.                         if (!pre_text) && (bukva == ' ')
  488.                         {
  489.                                 if (line[strlen(#line)-1]==' ') break; //óáðàòü 2 ïðîáåëà ïîäðÿä
  490.                                 if (!stolbec) && (!line) break; //ñòðîêà íå ìîæåò íà÷èíàòüñÿ ñ ïðîáåëà
  491.                         }
  492.                         if (strlen(#line)<sizeof(line)) strcat(#line, #bukva);
  493.  
  494.                         if (stolbec + strlen(#line) > lines.column_max)
  495.                         {
  496.                         NEXT_MARK:
  497.                                 perenos_num = strrchr(#line, ' ');
  498.                                 if (!perenos_num) && (strlen(#line)>lines.column_max) perenos_num=lines.column_max;
  499.                                 strcpy(#temp, #line + perenos_num); //ïåðåíîñ ïî ñëîâàì
  500.                                 line[perenos_num] = 0x00;
  501.                                 if (stroka >= lines.visible) && (lines.first <>0) break 1; //óõîäèì...
  502.                                 DrawPage();
  503.                                 strcpy(#line, #temp);
  504.                                
  505.                                 TextGoDown(left + 5, stroka * 10 + top + 5, width - 20); //çàêðàøèâàåì ñëåäóùóþ ñòðîêó
  506.                         }
  507.                 }
  508.         }
  509.  
  510.         DrawPage(); //ðèñóåò ïîñëåäíþþ ñòðîêó, ïîòîì ýòî íàäî óáðàòü, îïòèìèçèðîâàâ êîä
  511.         if (lines.visible * 10 + 25 <= height)
  512.                 DrawBar(left, lines.visible * 10 + top + 25, width - 15, -lines.visible * 10 + height - 25, bg_color);
  513.         if (stroka * 10 + 15 <= height)
  514.                 DrawBar(left, stroka * 10 + top + 15, width - 15, -stroka * 10 + height - 15, bg_color); //çàêðàøèâàåì âñ¸ äî êîíöà
  515.         if (lines.first == 0) lines.all = stroka;
  516.         if (anchor)
  517.         {
  518.                 //åñëè ïîñðåäè òåêñòà ïîÿâèòñÿ íîâûé ÿêîðü - áóäåò áåñêîíå÷íûé öèêë
  519.                 anchor='';
  520.                 lines.first=anchor_line_num;
  521.                 ParseHTML(buf);
  522.         }
  523.  
  524.         DrawScroller();
  525. }
  526.  
  527. void TWebBrowser::DrawPage() //ðåçàòü çäåñü!!1!
  528. {
  529.         int start_x, start_y, line_length;
  530.         char temp[sizeof(line)];
  531.        
  532.         if (!header) //&& (tag)
  533.         {
  534.                 if (strlen(#version)+strlen(#line)+2>sizeof(header))
  535.                 {
  536.                         strcpy(#temp, #line);
  537.                         temp[sizeof(header)-strlen(#version)-2]=0;
  538.                         strcpy(#header, #temp);
  539.                         strcpy(#line, #line+strlen(#temp));
  540.                 }
  541.                 else
  542.                 {
  543.                         strcpy(#header, #line);
  544.                         line=0;
  545.                 }
  546.                        
  547.                 strcat(#header, " -");
  548.                 strcat(#header, #version);
  549.                 return;
  550.         }
  551.        
  552.         if (stroka >= 0) && (stroka - 2 < lines.visible) && (line) && (!anchor)
  553.         {
  554.                 if (!stroka) && (!stolbec)
  555.                 {
  556.                         DrawBar(left, top, width-15, 15, bg_color); //çàêðàøèâàåì ïåðâóþ ñòðîêó
  557.                         first_line_drawed=1;
  558.                 }
  559.                
  560.                 start_x=stolbec * 6 + left+5;
  561.                 start_y=stroka * 10 + top + 5;
  562.                 line_length=strlen(#line)*6;
  563.  
  564.                 if (use_truetype == 1)
  565.                 {
  566.                         //line_length =  get_length stdcall (#line,-1,16,line_length);
  567.                         text_out stdcall (#line, #fontlol, 17, text_colors[text_color_index], start_x, start_y-3);
  568.                 }
  569.                 else
  570.                 {
  571.                         WriteText(start_x, start_y, 0x80, text_colors[text_color_index], #line, 0);
  572.                         IF (b_text)     { $add ebx, 1<<16   $int 0x40 }
  573.                 }
  574.                 IF (i_text) Skew(start_x, start_y, line_length+6, 10);
  575.                 IF (s_text) DrawBar(start_x, start_y + 4, line_length, 1, text_colors[text_color_index]);
  576.                 IF (u_text) DrawBar(start_x, start_y + 8, line_length, 1, text_colors[text_color_index]);
  577.                 IF (link) {
  578.                         DefineButton(start_x-2, start_y, line_length + 3, 9, blink + BT_HIDE, 0xB5BFC9);
  579.                         DrawBar(start_x, start_y + 8, line_length, 1, text_colors[text_color_index]);
  580.                 }
  581.                 stolbec += strlen(#line);
  582.         }
  583. }
  584.  
  585.  
  586. char oldtag[100];
  587. void TWebBrowser::WhatTextStyle(int left1, top1, width1) {
  588.         dword hr_color;
  589.  
  590.     dword image;
  591.     char temp[4096], alt[4096];
  592.     int w=0, h=0, img_lines_first=0;
  593.  
  594.         //ïðîâåðÿåì òåã îòêðûâàåòñÿ èëè çàêðûâàåòñÿ
  595.         if (tag[0] == '/')
  596.         {
  597.                 rez = 0;
  598.                 strcpy(#tag, #tag+1);
  599.         }
  600.         else
  601.                 rez = 1;
  602.                
  603.         if (!chTag("html")) {
  604.                 IF(!strcmp(#URL + strlen(#URL) - 4, ".mht")) IF (rez==0) ignor_text = 1; ELSE ignor_text = 0;
  605.                 return;
  606.         }
  607.  
  608.         if (!chTag("script")) || (!chTag("style")) || (!chTag("binary")) ignor_text = rez;
  609.  
  610.         if(!chTag("title"))
  611.         {
  612.                 if (rez)
  613.                 {
  614.                         header=0;
  615.                 }
  616.                 else //òåã çàêðûëñÿ - âûâåëè ñòðîêó
  617.                 {
  618.                         if (stroka==0) DrawTitle(#header);
  619.                 }
  620.                 return;
  621.         }
  622.  
  623.         if (ignor_text) return;
  624.  
  625.  
  626.  
  627.        
  628.         IF(!chTag("q")) strcat(#line, "\"");
  629.  
  630.  
  631.         if (anchor) && (!strcmp(#parametr, "id=")) //î÷åíü ïëîõî!!! ïîòîìó ÷òî åñëè íå ïîñëåäíèé òåã, ðàáîòàòü íå áóäåò
  632.         {
  633.                 if (!strcmp(#anchor, #options))
  634.                 {
  635.                         anchor_line_num=lines.first+stroka;
  636.                 }
  637.         }
  638.        
  639.         if (!chTag("body"))
  640.         {
  641.                 BODY_MARK:
  642.                
  643.                 if (!strcmp(#parametr, "link="))
  644.                         link_color = GetColor(#options);
  645.                
  646.                 if (!strcmp(#parametr, "text="))
  647.                         text_colors[0]=GetColor(#options);
  648.                
  649.                 if (!strcmp(#parametr, "bgcolor="))
  650.                         bg_color=GetColor(#options);
  651.                
  652.                 IF(tagparam)
  653.                 {
  654.                         GetNextParam();
  655.                         GOTO BODY_MARK;
  656.                 }
  657.                
  658.                 return;
  659.         }
  660.  
  661.         if (!chTag("a"))
  662.         {
  663.                 if (rez)
  664.                 {
  665.                          
  666.                         if (link) IF(text_color_index > 0) text_color_index--; //åñëè ïðåäûäóùèé òåã à íå áûë çàêðûò
  667.  
  668.                         _A_MARK:
  669.                         if (!strcmp(#parametr, "href="))
  670.                         {
  671.                                 if (stroka - 1 > lines.visible) || (stroka < -2) return;
  672.                                
  673.                                 text_color_index++;
  674.                                 text_colors[text_color_index] = text_colors[text_color_index-1];
  675.                                
  676.                                 link = 1;
  677.                                 blink++;
  678.                                 text_colors[text_color_index] = link_color;
  679.                                 strcat(#page_links, #options);
  680.                                 strcat(#page_links, "|");
  681.                         }
  682.                         if (anchor) && (!strcmp(#parametr, "name="))
  683.                         {
  684.                                 if (!strcmp(#anchor, #options))
  685.                                 {
  686.                                         anchor_line_num=lines.first+stroka;
  687.                                 }
  688.                         }
  689.                         if (tagparam)
  690.                         {
  691.                                 GetNextParam();
  692.                                 GOTO _A_MARK;
  693.                         }
  694.                 }
  695.                 else {
  696.                         link = 0;
  697.                         IF(text_color_index > 0) text_color_index--;
  698.                 }
  699.                 return;
  700.         }
  701.  
  702.  
  703.         if (!chTag("font"))
  704.         {
  705.                 if (rez)
  706.                 {
  707.                         text_color_index++;
  708.                         text_colors[text_color_index] = text_colors[text_color_index-1];
  709.                
  710.                         COL_MARK:
  711.                         if (strcmp(#parametr, "color=") == 0) //&& (parametr[1] == '#')
  712.                         {
  713.                                 text_colors[text_color_index] = GetColor(#options);
  714.                         }
  715.                         IF(tagparam) {
  716.                                 GetNextParam();
  717.                                 GOTO COL_MARK;
  718.                         }
  719.                 }
  720.                 else
  721.                         if (text_color_index > 0) text_color_index--;
  722.                 return;
  723.         }
  724.  
  725.         if(!chTag("tr")) || (!chTag("br")) {
  726.                 TextGoDown(left1, top1, width1);
  727.                 return;
  728.         }
  729.         if (!chTag("div")) {
  730.                 IF(oldtag[0] <>'h') TextGoDown(left1, top1, width1);
  731.                 return;
  732.         }
  733.         if (!chTag("p")) {
  734.                 IF(oldtag[0] == 'h') return;
  735.                 TextGoDown(left1, top1, width1);
  736.                 IF(rez) TextGoDown(left1, top1 + 10, width1);
  737.                 return;
  738.         }
  739.  
  740.         if (!chTag("h1")) || (!chTag("h2")) || (!chTag("h3")) || (!chTag("h4")) {
  741.                 TextGoDown(left1, top1, width1);
  742.                 IF(rez) TextGoDown(left1, top1 + 10, width1);
  743.                 b_text = rez;
  744.                 strcpy(#oldtag, #tag);
  745.                 return;
  746.         }
  747.         else
  748.                 oldtag='';
  749.                
  750.         if (!chTag("b")) || (!chTag("strong")) || (!chTag("big")) {
  751.                 b_text = rez;
  752.                 return;
  753.         }
  754.         ////////////////////////////
  755.         if(!chTag("i")) || (!chTag("em")) || (!chTag("subtitle")) {
  756.                 i_text = rez;
  757.                 return;
  758.         }      
  759.         ////////////////////////////
  760.         if (!chTag("dt"))
  761.         {
  762.                 li_text = rez;
  763.                 IF(rez == 0) return;
  764.                 TextGoDown(left1, top1, width1);
  765.                 return;
  766.         }
  767.         /////////////////////////////
  768.         if(!chTag("li")) || (!chTag("dt")) //íàäî ñäåëàòü âëîæåííûå ñïèñêè
  769.         {
  770.                 li_text = rez;
  771.                 IF(rez == 0) return;
  772.                 TextGoDown(left1, top1, width1);
  773.                 IF(stroka > -1) && (stroka - 2 < lines.visible) DrawBar(li_tab * 5 * 6 + left1 - 5, top1 + 12, 2, 2, 0);
  774.                 return;
  775.         }
  776.         ////////////////////////////
  777.         IF(!chTag("u")) || (!chTag("ins")) u_text = rez;
  778.         IF(!chTag("s")) || (!chTag("strike")) || (!chTag("del")) s_text = rez;
  779.         IF(!chTag("ul")) || (!chTag("ol")) IF(!rez) {
  780.                 li_text = rez;
  781.                 li_tab--;
  782.                 TextGoDown(left1, top1, width1);
  783.         } ELSE li_tab++;
  784.         IF(!chTag("dd")) stolbec += 5;
  785.         IF(!chTag("blockquote")) blq_text = rez;
  786.         IF(!chTag("pre")) pre_text = rez;
  787.         IF(!chTag("hr")) {
  788.                 TextGoDown(left1, top1, width1);
  789.                 TextGoDown(left1, top1 + 10, width1);
  790.                 IF(strcmp(#parametr, "color=") == 0) hr_color = GetColor(#options);
  791.                 ELSE hr_color = 0x999999;
  792.                 IF(stroka > 0) DrawBar(left1, top1 + 14, width1 - 8, 1, hr_color);
  793.         }
  794.  
  795.         if (!chTag("img"))
  796.         {
  797.                 if (GetFileInfo(libimg)<>0) return;  //åñëè áèáëèîòåêè íåò
  798.                 IMG_TAG:
  799.                         if (!strcmp(#parametr,"src="))   //íàäî îáúåäèíèòü ñ GetNewUrl()
  800.                         {
  801.                                 if (downloader_id) strcpy(#temp, #history_list[history_current-1].Item);
  802.                                         else strcpy(#temp, BrowserHistory.CurrentUrl()); //äîñòà¸ì àäðåñ òåêóùåé ñòðàíèöû
  803.                                 if (strcmpn(#temp, "http:", 5)!=0) || (strcmpn(#options, "http:", 5)!=0)
  804.                                 {
  805.                                         temp[strrchr(#temp, '/')] = 0x00; //îáðåçàåì å¸ óðë äî ïîñëåäíåãî /
  806.                                         strcat(#temp, #options);
  807.                                         image=load_image(#temp);
  808.                                         w=DSWORD[image+4];
  809.                                         h=DSWORD[image+8];
  810.                                 }
  811.                         }
  812.                         if (!strcmp(#parametr,"alt="))
  813.                         {
  814.                                 strcpy(#alt, "[");
  815.                                 strcat(#alt, #options);
  816.                                 strcat(#alt, "]");
  817.                         }
  818.  
  819.                 IF(tagparam)
  820.                 {
  821.                         GetNextParam();
  822.                         GOTO IMG_TAG;
  823.                 }
  824.                
  825.                 if (!image)
  826.                 {
  827.                         if (alt) && (link) strcat(#line, #alt);
  828.                         return;
  829.                 }
  830.                
  831.                 if (w>width1) w=width1;
  832.                
  833.                 if (stroka==0) DrawBar(left, top, width-15, 15, bg_color); //çàêðàøèâàåì ïåðâóþ ñòðîêó
  834.                 stroka+=h/10;
  835.                 if (top1+h<WB1.top) || (top1>WB1.top+WB1.height-10) return; //åñëè ÂѨ èçîáðàæåíèå óøëî ÂÅÐÕ èëè ÂÍÈÇ
  836.                 if (top1<WB1.top) //åñëè ÷àñòü èçîáðàæåíèÿ ñâåðõó
  837.                 {
  838.                         DrawBar(left, top, width-15, 10, bg_color); //çàêðàøèâàåì ïåðâóþ ñòðîêó
  839.                         img_lines_first=WB1.top-top1;
  840.                         h=h-img_lines_first;
  841.                         top1=WB1.top;
  842.                 }
  843.                 if (top1>WB1.top+WB1.height-h-15) //åñëè ÷àñòü èçîáðàæåíèÿ ñíèçó
  844.                 {
  845.                         h=WB1.top+WB1.height-top1-15;
  846.                 }      
  847.                 if (h<=0) return;
  848.                 if (anchor) return;
  849.                
  850.                 img_draw stdcall (image,left1-5,top1+10,w, h,0,img_lines_first);
  851.                 DrawBar(left1+w - 5, top1 + 10, width1-w + 5, h, bg_color);
  852.                 IF (link) DefineButton(left1 - 5, top1+10, w, h, blink + BT_HIDE, 0xB5BFC9);
  853.                 return;
  854.         }
  855.  
  856.         if (!chTag("meta")) || (!chTag("?xml"))
  857.         {
  858.                 META:
  859.                 if (!strcmp(#parametr, "charset=")) || (!strcmp(#parametr, "content=")) || (!strcmp(#parametr, "encoding="))
  860.                 {
  861.                         strcpy(#options, #options[strrchr(#options, '=')]); //ïîèñê â content=
  862.  
  863.                         if (!strcmp(#options,"utf-8"))   || (!strcmp(#options,"utf8"))      ReadHtml(_UTF);
  864.                         if (!strcmp(#options, "koi8-r")) || (!strcmp(#options, "koi8-u"))   ReadHtml(_KOI);
  865.                         if (!strcmp(#options, "dos"))    || (!strcmp(#options, "cp-866"))   ReadHtml(_DOS);
  866.                 }
  867.                 if (tagparam)
  868.                 {
  869.                         GetNextParam();
  870.                         goto META;
  871.                 }
  872.                 return;
  873.         }
  874. }
  875.  
  876.  
  877. void TextGoDown(int left1, top1, width1)
  878. {
  879.         if (!stroka) && (!stolbec) && (!first_line_drawed)
  880.         {
  881.                 DrawBar(WB1.left, WB1.top, WB1.width-15, 15, bg_color); //çàêðàøèâàåì ïåðâóþ ñòðîêó
  882.                 first_line_drawed=1;
  883.         }
  884.         stroka++;
  885.         if (blq_text) stolbec = 8;
  886.         ELSE stolbec = 0;
  887.         if (li_text) stolbec = li_tab * 5;
  888.         IF(stroka >= 0) && (stroka - 2 < lines.visible)  && (!anchor) DrawBar(left1 - 5, top1 + 10, width1 + 5, 10, bg_color);
  889. }
  890.  
  891.  
  892. //ñêðîëë
  893. void TWebBrowser::DrawScroller() //íå îïòèìàëüíàÿ îòðèñîâêà, íî çàòî â îäíîì ìåñòå
  894. {
  895.         scroll1.max_area = lines.all;
  896.         scroll1.cur_area = lines.visible;
  897.         scroll1.position = lines.first;
  898.  
  899.         scroll1.all_redraw=1;
  900.         scroll1.start_x=Form.width-28; //left + width - 15
  901.         scroll1.size_y=WB1.height;
  902.  
  903.         scrollbar_v_draw(#scroll1);
  904. }
  905.