Subversion Repositories Kolibri OS

Rev

Rev 5598 | Rev 5676 | 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; //visible = row_max
  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.         int MouseScrollNoSelection(dword scroll_state);
  26.         void debug_values();
  27. };
  28.  
  29.  
  30. void llist::debug_values()
  31. {
  32.         debug("current: ");
  33.         debugi(current);
  34.         debug("first: ");
  35.         debugi(first);
  36.         debug("visible: ");
  37.         debugi(visible);
  38.         debug("count: ");
  39.         debugi(count);
  40. }
  41.  
  42.  
  43.  
  44. void llist::ClearList()
  45. {
  46.         count = visible = first = current = 0;
  47. }
  48.  
  49.  
  50. void llist::SetSizes(int xx, yy, ww, hh, min_hh, line_hh)
  51. {
  52.         x = xx;
  53.         y = yy;
  54.         w = ww;
  55.         h = hh;
  56.         min_h = min_hh;
  57.         line_h = line_hh;
  58.         text_y = line_hh / 2 - 4;
  59.         visible = h / line_h;
  60.         column_max = w / 6;
  61.         //if (visible > count) visible=count;
  62. }
  63.  
  64.  
  65. int llist::MouseScroll(dword scroll_state)
  66. {
  67.         if (count<=visible) return 0;
  68.         if (scroll_state == 65535)
  69.         {
  70.                 if (first == 0) return 0;
  71.                 if (first > 3) first -= 2; else first=0;
  72.                 return 1;
  73.         }
  74.         if (scroll_state == 1)
  75.         {
  76.                 if (visible + first == count) return 0;
  77.                 if (visible+first+3 > count) first = count - visible; else first+=2;
  78.                 return 1;
  79.         }
  80.         return 0;
  81. }
  82.  
  83. int llist::MouseScrollNoSelection(dword scroll_state)
  84. {
  85.         if (count<=visible) return 0;
  86.         if (scroll_state == 65535)
  87.         {
  88.                 if (current == 0) return 0;
  89.                 if (current > 3) current -= 2; else current=0;
  90.                 return 1;
  91.         }
  92.         if (scroll_state == 1)
  93.         {
  94.                 if (visible + current == count) return 0;
  95.                 if (visible+current+3 > count) current = count - visible; else current+=2;
  96.                 return 1;
  97.         }
  98.         return 0;
  99. }
  100.  
  101. int llist::MouseOver(int xx, yy)
  102. {
  103.         if (xx>x) && (xx<x+w) && (yy>y) && (yy<y+h) return 1;
  104.         return 0;
  105. }
  106.  
  107. int llist::ProcessMouse(int xx, yy)
  108. {
  109.         int current_temp;
  110.         if (MouseOver(xx, yy))
  111.         {
  112.                 current_temp = yy - y / line_h + first;
  113.                 if (current_temp != current) && (current_temp<count)
  114.                 {
  115.                         current = current_temp;
  116.                         return 1;
  117.                 }
  118.         }
  119.         return 0;
  120. }
  121.  
  122. int llist::ProcessKey(dword key)
  123. {
  124.         switch(key)
  125.         {
  126.                 case ASCII_KEY_DOWN: return KeyDown();
  127.                 case ASCII_KEY_UP:   return KeyUp();
  128.                 case ASCII_KEY_HOME: return KeyHome();
  129.                 case ASCII_KEY_END:  return KeyEnd();
  130.         }
  131.         return 0;
  132. }
  133.  
  134. int llist::KeyDown()
  135. {
  136.         if (current-first+1<visible)
  137.         {
  138.                 if (current+1>=count) return 0;
  139.                 current++;
  140.         }
  141.         else
  142.         {
  143.                 if (visible+first>=count) return 0;
  144.                 first++;
  145.                 current++;
  146.         }
  147.         return 1;
  148. }
  149.  
  150. int llist::KeyUp()
  151. {
  152.         if (current>first)
  153.         {
  154.                 current--;
  155.         }
  156.         else
  157.         {
  158.                 if (first==0) return 0;
  159.                 first--;
  160.                 current--;
  161.         }
  162.         return 1;
  163. }
  164.  
  165. int llist::KeyHome()
  166. {
  167.         if (current==0) && (first==0) return 0;
  168.         current=0;
  169.         first=0;
  170.         return 1;
  171. }
  172.  
  173. int llist::KeyEnd()
  174. {
  175.         if (current==count-1) && (first==count-visible) return 0;
  176.         current=count-1;
  177.         first=count-visible;
  178.         return 1;
  179. }
  180.  
  181. #endif