Subversion Repositories Kolibri OS

Rev

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