Subversion Repositories Kolibri OS

Rev

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