Subversion Repositories Kolibri OS

Rev

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

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