Subversion Repositories Kolibri OS

Rev

Rev 5772 | Go to most recent revision | Blame | Last modification | View Log | Download | RSS feed

  1. CustomCursor CursorPointer;
  2. dword CursorFile = FROM "../TWB/pointer.cur";
  3.  
  4. #define NOLINE    0
  5. #define UNDERLINE 1
  6.  
  7. struct array_link {
  8.         dword link, text;
  9.         int x,y,w,h;
  10.         int underline;
  11. };
  12.  
  13. struct LinksArray {
  14.         array_link links[400];
  15.         char page_links[64000];
  16.         dword buflen;
  17.         int count, active;
  18.         void Hover();
  19.         void AddLink();
  20.         void AddText();
  21.         void ClickLink();
  22.         dword GetURL();
  23.         void Clear();
  24.         void GetAbsoluteURL();
  25.         int UrlAbsolute();
  26. } PageLinks;
  27.  
  28. void LinksArray::AddLink(dword lpath, int link_x, link_y)
  29. {
  30.         links[count].x = link_x;
  31.         links[count].y = link_y;
  32.  
  33.         links[count].link = buflen;
  34.         strcpy(buflen, lpath);
  35.         buflen += strlen(lpath)+1;
  36.         count++;
  37. }
  38.  
  39. void LinksArray::AddText(dword new_text, int link_w, link_h, link_underline)
  40. {
  41.         if (count<1) return;
  42.         links[count-1].w = link_w;
  43.         links[count-1].h = link_h;
  44.         links[count-1].underline = link_underline;
  45.  
  46.         links[count-1].text = buflen;
  47.         strcpy(buflen, new_text);
  48.         buflen += strlen(new_text)+1;
  49. }
  50.  
  51. dword LinksArray::GetURL(int id)
  52. {
  53.         return links[id].link;
  54. }
  55.  
  56. void LinksArray::Clear()
  57. {
  58.         int i;
  59.         for (i=0; i<=count; i++) DeleteButton(i+400);
  60.         buflen = #page_links;
  61.         count = 0;
  62.         active = -1;
  63.         CursorPointer.Restore();
  64. }
  65.  
  66. char temp[sizeof(URL)];
  67. PathShow_data status_text = {0, 17,250, 6, 250, 0, 0, 0x0, 0xFFFfff, 0, #temp, 0};
  68.  
  69. void LinksArray::Hover(dword mx, my, link_col_in, link_col_a, bg_col)
  70. {
  71.         int i;
  72.         signed int WBY =  -WB1.list.first*WB1.list.line_h - WB1.DrawBuf.zoom;
  73.         for (i=0; i<count; i++)
  74.         {
  75.                 if (mx>links[i].x) && (my>links[i].y) && (mx<links[i].x+links[i].w) && (my<links[i].y+links[i].h)
  76.                 {
  77.                         if (mouse.down) DrawRectangle(links[active].x, links[active].y, links[active].w, links[active].h, 0);
  78.                         if (mouse.up) ClickLink();
  79.                         if (active==i) return;
  80.                         CursorPointer.Set();
  81.                         if (links[active].underline) DrawBar(links[active].x, WBY + links[active].y + links[active].h,links[active].w, WB1.DrawBuf.zoom, link_col_in);
  82.                         if (links[i].underline) DrawBar(links[i].x, WBY + links[i].y + links[i].h,links[i].w, WB1.DrawBuf.zoom, bg_col);
  83.                         active = i;
  84.                         status_text.start_x = wv_progress_bar.left + wv_progress_bar.width + 10;
  85.                         status_text.start_y = Form.cheight - STATUSBAR_H + 3;
  86.                         status_text.area_size_x = Form.cwidth - status_text.start_x -3;
  87.                         DrawBar(status_text.start_x, status_text.start_y, status_text.area_size_x, 9, col_bg);
  88.                         status_text.text_pointer = links[active].link;
  89.                         PathShow_prepare stdcall(#status_text);
  90.                         PathShow_draw stdcall(#status_text);
  91.                         return;
  92.                 }
  93.         }
  94.         if (active!=-1)
  95.         {
  96.                 CursorPointer.Restore();
  97.                 if (links[active].underline) DrawBar(links[active].x, WBY + links[active].y  + links[active].h,links[active].w, WB1.DrawBuf.zoom, link_col_in);
  98.                 DrawBar(status_text.start_x, status_text.start_y, status_text.area_size_x, 9, col_bg);
  99.                 active = -1;
  100.         }
  101. }
  102.  
  103. int LinksArray::UrlAbsolute(dword in_URL)
  104. {
  105.         if(!strncmp(in_URL,"http:",5)) return 1;
  106.         if(!strncmp(in_URL,"https:",6)) return 1;
  107.         if(!strncmp(in_URL,"mailto:",7)) return 1;
  108.         if(!strncmp(in_URL,"ftp:",4)) return 1;
  109.         if(!strncmp(in_URL,"WebView:",8)) return 1;
  110.         if(!strncmp(in_URL,"/sys/",5)) return 1;
  111.         if(!strncmp(in_URL,"/hd/",4)) return 1;
  112.         if(!strncmp(in_URL,"/fd/",4)) return 1;
  113.         if(!strncmp(in_URL,"/rd/",4)) return 1;
  114.         if(!strncmp(in_URL,"/tmp/",5)) return 1;
  115.         if(!strncmp(in_URL,"/cd/",4)) return 1;
  116.         if(!strncmp(in_URL,"/bd/",4)) return 1;
  117.         if(!strncmp(in_URL,"/usbhd/",7)) return 1;
  118.         if(!strncmp(in_URL,"/kolibrios/",11)) return 1;
  119.         return 0;
  120. }
  121.  
  122. void LinksArray::GetAbsoluteURL(dword in_URL)
  123. {
  124.         int i;
  125.         dword orig_URL = in_URL;
  126.         char newurl[sizeof(URL)];
  127.  
  128.         if (UrlAbsolute(in_URL)) return;
  129.        
  130.         IF (!strcmpn(in_URL,"./", 2)) in_URL+=2;
  131.         if (!http_transfer)
  132.         {
  133.                 strcpy(#newurl, BrowserHistory.CurrentUrl());
  134.         }
  135.         else
  136.         {
  137.                 strcpy(#newurl, #history_list[BrowserHistory.current-1].Item);
  138.         }
  139.  
  140.         if (ESBYTE[in_URL] == '/') //remove everything after site domain name
  141.         {
  142.                 i = strchr(#newurl+8, '/');
  143.                 if (i) ESBYTE[i]=0;
  144.                 in_URL+=1;
  145.         }
  146.                
  147.         _CUT_ST_LEVEL_MARK:
  148.                
  149.         if (newurl[strrchr(#newurl, '/')-2]<>'/')
  150.         {
  151.                 newurl[strrchr(#newurl, '/')] = 0x00;
  152.         }
  153.        
  154.         IF (!strncmp(in_URL,"../",3))
  155.         {
  156.                 in_URL+=3;
  157.                 newurl[strrchr(#newurl, '/')-1] = 0x00;
  158.                 goto _CUT_ST_LEVEL_MARK;
  159.         }
  160.        
  161.         if (newurl[strlen(#newurl)-1]<>'/') strcat(#newurl, "/");
  162.        
  163.         strcat(#newurl, in_URL);
  164.         strcpy(orig_URL, #newurl);
  165. }
  166.  
  167. void LinksArray::ClickLink()
  168. {
  169.         if (http_transfer > 0)
  170.         {
  171.                 StopLoading();
  172.                 BrowserHistory.current--;
  173.         }
  174.  
  175.         strcpy(#URL, PageLinks.GetURL(PageLinks.active));      
  176.         //#1
  177.         if (URL[0] == '#')
  178.         {
  179.                 strcpy(#anchor, #URL+strrchr(#URL, '#'));              
  180.                 strcpy(#URL, BrowserHistory.CurrentUrl());
  181.                 WB1.list.first=WB1.list.count-WB1.list.visible;
  182.                 ShowPage();
  183.                 return;
  184.         }
  185.         //liner.ru#1
  186.         if (strrchr(#URL, '#')!=-1)
  187.         {
  188.                 strcpy(#anchor, #URL+strrchr(#URL, '#'));
  189.                 URL[strrchr(#URL, '#')-1] = 0x00;
  190.         }
  191.        
  192.         PageLinks.GetAbsoluteURL(#URL);
  193.        
  194.         if (UrlExtIs(".png")==1) || (UrlExtIs(".gif")==1) || (UrlExtIs(".jpg")==1) || (UrlExtIs(".zip")==1) || (UrlExtIs(".kex")==1)
  195.         || (UrlExtIs(".7z")==1) || (UrlExtIs("netcfg")==1)
  196.         {
  197.                 //notify(#URL);
  198.                 if (!strncmp(#URL,"http://", 7))
  199.                 {
  200.                         strcpy(#DL_URL, #URL);
  201.                         CreateThread(#Downloader,#downloader_stak+4092);
  202.                 }
  203.                 else RunProgram("@open", #URL);
  204.                 strcpy(#editURL, BrowserHistory.CurrentUrl());
  205.                 strcpy(#URL, BrowserHistory.CurrentUrl());
  206.                 return;
  207.         }
  208.         if (!strncmp(#URL,"mailto:", 7))
  209.         {
  210.                 notify(#URL);
  211.                 strcpy(#editURL, BrowserHistory.CurrentUrl());
  212.                 strcpy(#URL, BrowserHistory.CurrentUrl());
  213.                 return;
  214.         }
  215.         OpenPage();
  216.         return;
  217. }
  218.