Subversion Repositories Kolibri OS

Rev

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

  1. CustomCursor CursorPointer;
  2. dword CursorFile = FROM "../TWB/pointer.cur";
  3. #include "..\lib\collection.h"
  4.  
  5. #define NOLINE    0
  6. #define UNDERLINE 1
  7.  
  8. #define MAXLINKS 2000
  9.  
  10. bool open_new_window=false;
  11. bool open_new_tab=false;
  12.  
  13. struct array_link {
  14.         dword link;
  15.         unsigned int x,y,w,h;
  16.         unsigned int unic_id;
  17.         int underline, underline_h;
  18. };
  19.  
  20. struct LinksArray {
  21.         array_link links[MAXLINKS];
  22.         collection page_links;
  23.         unsigned int count;
  24.         unsigned int unic_count;
  25.         unsigned int active;
  26.         bool HoverAndProceed();
  27.         bool Click();
  28.         void AddLink();
  29.         void AddText();
  30.         dword GetURL();
  31.         void Clear();
  32.         void DrawUnderline();
  33. } PageLinks;
  34.  
  35. void LinksArray::AddLink(dword lpath)
  36. {
  37.         if (count>= MAXLINKS) return;
  38.         page_links.add(lpath);
  39.         unic_count++;
  40. }
  41.  
  42. void LinksArray::AddText(dword _x, _y, _w, _h, _link_underline, _underline_h)
  43. {
  44.         if (count>= MAXLINKS) return;
  45.         links[count].x = _x;
  46.         links[count].y = _y;
  47.         links[count].w = _w;
  48.         links[count].h = _h;
  49.         links[count].underline = _link_underline;
  50.         links[count].underline_h = _underline_h;
  51.         links[count].link = page_links.get(page_links.count-1);
  52.         links[count].unic_id = unic_count;
  53.         count++;
  54. }
  55.  
  56. dword LinksArray::GetURL(int id)
  57. {
  58.         return links[id].link;
  59. }
  60.  
  61. void LinksArray::Clear()
  62. {
  63.         page_links.drop();
  64.         page_links.realloc_size = 4096 * 32;
  65.         count = 0;
  66.         active = -1;
  67.         unic_count = 0;
  68.         CursorPointer.Restore();
  69.         open_new_window = false;
  70. }
  71.  
  72. void LinksArray::DrawUnderline(dword und_id, list_first, list_y, color)
  73. {
  74.         int i;
  75.         for (i=0; i<count; i++)
  76.         {
  77.                 if (links[i].unic_id==links[und_id].unic_id) && (links[i].y + links[i].h - list_first > list_y) {
  78.                         DrawBar(links[i].x, links[i].y + links[i].h - list_first, links[i].w, links[i].underline_h, color);
  79.                 }              
  80.         }
  81. }
  82.  
  83. PathShow_data status_text = {0, 17,250, 6, 250};
  84.  
  85. bool LinksArray::Click(dword list_first)
  86. {
  87.         if (mouse.lkm) && (mouse.down) {
  88.                 DrawRectangle(links[active].x, -list_first + links[active].y,
  89.                 links[active].w, links[active].h, 0);
  90.                 return false;
  91.         }
  92.         if (mouse.mkm) && (mouse.up) {
  93.                 if (key_modifier&KEY_LSHIFT) || (key_modifier&KEY_RSHIFT) {
  94.                         open_new_window = true;
  95.                         EventClickLink(PageLinks.GetURL(PageLinks.active));
  96.                         open_new_window = false;
  97.                 } else {
  98.                         open_new_tab = true;
  99.                         EventClickLink(PageLinks.GetURL(PageLinks.active));
  100.                         open_new_tab = false;
  101.                 }
  102.                 return false;
  103.         }
  104.         if (mouse.lkm) && (mouse.up) {
  105.                 CursorPointer.Restore();
  106.                 EventClickLink(PageLinks.GetURL(PageLinks.active));
  107.                 return false;
  108.         }
  109.         if (mouse.pkm) && (mouse.up) {
  110.                 EventShowLinkMenu();
  111.                 return false;
  112.         }
  113. }
  114.  
  115. bool LinksArray::HoverAndProceed(dword mx, my, list_y, list_first)
  116. {
  117.         int i;
  118.         if (!count) return true;
  119.         for (i=0; i<count; i++)
  120.         {
  121.                 if (mx>links[i].x) && (my>links[i].y)
  122.                 && (mx<links[i].x+links[i].w) && (my<links[i].y+links[i].h)
  123.                 && (my>list_y+list_first)
  124.                 {
  125.                         if (active!=i) {
  126.                                 CursorPointer.Load(#CursorFile);
  127.                                 CursorPointer.Set();
  128.  
  129.                                 if (links[active].underline) {
  130.                                         DrawUnderline(active, list_first, list_y, link_color_default);                 
  131.                                 }
  132.  
  133.                                 if (links[i].underline) {
  134.                                         DrawUnderline(i, list_first, list_y, page_bg);
  135.                                 }
  136.  
  137.                                 active = i;
  138.                                 DrawStatusBar(links[active].link);
  139.                         }
  140.                         Click(list_first);
  141.                         return true;
  142.                 }
  143.         }
  144.         if (active!=-1)
  145.         {
  146.                 CursorPointer.Restore();
  147.                 if (links[active].underline) {
  148.                         DrawUnderline(active, list_first, list_y, link_color_default);
  149.                 }
  150.                 DrawStatusBar(NULL);
  151.                 active = -1;
  152.         }
  153. }
  154.  
  155.