Subversion Repositories Kolibri OS

Rev

Rev 4073 | Rev 4078 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

  1. //list_box
  2.  
  3. struct llist
  4. {
  5.         int x, y, w, h, min_h, line_h;
  6.         int count, visible, first, current;
  7.         int current_temp;
  8.         void ClearList();
  9.         int ProcessKey(dword key);
  10.         int MouseOver(int xx, yy);
  11.         int ProcessMouse(int xx, yy);
  12.         int KeyDown();
  13.         int KeyUp();
  14.         int KeyHome();
  15.         int KeyEnd();
  16.         void SetSizes(int xx, yy, ww, hh, min_hh, line_hh);
  17.         int MouseScroll(dword scroll_state);
  18. };
  19.  
  20.  
  21. void llist::ClearList()
  22. {
  23.         count = visible = first = current = 0;
  24. }
  25.  
  26.  
  27. void llist::SetSizes(int xx, yy, ww, hh, min_hh, line_hh)
  28. {
  29.         x = xx;
  30.         y = yy;
  31.         w = ww;
  32.         h = hh;
  33.         min_h = min_hh;
  34.         line_h = line_hh;
  35.         visible = h / line_h;
  36. }
  37.  
  38.  
  39. int llist::MouseScroll(dword scroll_state)
  40. {
  41.         if (scroll_state == 65535)
  42.         {
  43.                 if (first == 0) return 0;
  44.                 if (first > 3) first -= 2; else first=0;
  45.                 return 1;
  46.         }
  47.         if (scroll_state == 1)
  48.         {
  49.                 if (visible+first+3 >= count) first = count - visible; else first+=2;
  50.                 return 1;
  51.         }
  52.         return 0;
  53. }
  54.  
  55. int llist::MouseOver(int xx, yy)
  56. {
  57.         if (xx>x) && (xx<x+w) && (yy>y) && (yy<y+h) return 1;
  58.         return 0;
  59. }
  60.  
  61. int llist::ProcessMouse(int xx, yy)
  62. {
  63.         if (MouseOver(xx, yy))
  64.         {
  65.                 current_temp = yy - y / line_h + first;
  66.                 if (current_temp != current)
  67.                 {
  68.                         current = current_temp;
  69.                         return 1;
  70.                 }
  71.         }
  72.         return 0;
  73. }
  74.  
  75. int llist::ProcessKey(dword key)
  76. {
  77.         switch(key)
  78.         {
  79.                 case 177: return KeyDown();
  80.                 case 178: return KeyUp();
  81.                 case 180: return KeyHome();
  82.                 case 181: return KeyEnd();
  83.         }
  84.         return 0;
  85. }
  86.  
  87. int llist::KeyDown()
  88. {
  89.         if (current-first+1<visible)
  90.         {
  91.                 if (current+1>=count) return 0;
  92.                 current++;
  93.         }
  94.         else
  95.         {
  96.                 if (visible+first>=count) return 0;
  97.                 first++;
  98.                 current++;
  99.         }
  100.         return 1;
  101. }
  102.  
  103. int llist::KeyUp()
  104. {
  105.         if (current>first)
  106.         {
  107.                 current--;
  108.         }
  109.         else
  110.         {
  111.                 if (first==0) return 0;
  112.                 first--;
  113.                 current--;
  114.         }
  115.         return 1;
  116. }
  117.  
  118. int llist::KeyHome()
  119. {
  120.         if (current==0) && (first==0) return 0;
  121.         current=0;
  122.         first=0;
  123.         return 1;
  124. }
  125.  
  126. int llist::KeyEnd()
  127. {
  128.         if (current==count-1) && (first==count-visible) return 0;
  129.         current=count-1;
  130.         first=count-visible;
  131.         return 1;
  132. }