Subversion Repositories Kolibri OS

Rev

Rev 5421 | Rev 5616 | 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 == count) return 0;
  69.                 if (visible+first+3 > count) first = count - visible; else first+=2;
  70.                 return 1;
  71.         }
  72.         return 0;
  73. }
  74.  
  75. int llist::MouseOver(int xx, yy)
  76. {
  77.         if (xx>x) && (xx<x+w) && (yy>y) && (yy<y+h) return 1;
  78.         return 0;
  79. }
  80.  
  81. int llist::ProcessMouse(int xx, yy)
  82. {
  83.         int current_temp;
  84.         if (MouseOver(xx, yy))
  85.         {
  86.                 current_temp = yy - y / line_h + first;
  87.                 if (current_temp != current) && (current_temp<count)
  88.                 {
  89.                         current = current_temp;
  90.                         return 1;
  91.                 }
  92.         }
  93.         return 0;
  94. }
  95.  
  96. int llist::ProcessKey(dword key)
  97. {
  98.         switch(key)
  99.         {
  100.                 case ASCII_KEY_DOWN: return KeyDown();
  101.                 case ASCII_KEY_UP:   return KeyUp();
  102.                 case ASCII_KEY_HOME: return KeyHome();
  103.                 case ASCII_KEY_END:  return KeyEnd();
  104.         }
  105.         return 0;
  106. }
  107.  
  108. int llist::KeyDown()
  109. {
  110.         if (current-first+1<visible)
  111.         {
  112.                 if (current+1>=count) return 0;
  113.                 current++;
  114.         }
  115.         else
  116.         {
  117.                 if (visible+first>=count) return 0;
  118.                 first++;
  119.                 current++;
  120.         }
  121.         return 1;
  122. }
  123.  
  124. int llist::KeyUp()
  125. {
  126.         if (current>first)
  127.         {
  128.                 current--;
  129.         }
  130.         else
  131.         {
  132.                 if (first==0) return 0;
  133.                 first--;
  134.                 current--;
  135.         }
  136.         return 1;
  137. }
  138.  
  139. int llist::KeyHome()
  140. {
  141.         if (current==0) && (first==0) return 0;
  142.         current=0;
  143.         first=0;
  144.         return 1;
  145. }
  146.  
  147. int llist::KeyEnd()
  148. {
  149.         if (current==count-1) && (first==count-visible) return 0;
  150.         current=count-1;
  151.         first=count-visible;
  152.         return 1;
  153. }