Subversion Repositories Kolibri OS

Rev

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