Subversion Repositories Kolibri OS

Rev

Rev 5778 | Rev 5781 | 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. #print "[include <list_box.h>]\n"
  5.  
  6. #ifndef INCLUDE_KOLIBRI_H
  7. #include "../lib/kolibri.h"
  8. #endif
  9.  
  10. struct llist
  11. {
  12.         int x, y, w, h, line_h, text_y;
  13.         int count, visible, first, current, column_max; //visible = row_max
  14.         dword font_w, font_h, font_type;
  15.         byte wheel_size;
  16.         byte active;
  17.         byte no_selection;
  18.         void ClearList();
  19.         int MouseOver(int xx, yy);
  20.         int ProcessMouse(int xx, yy);
  21.         int ProcessKey(dword key);
  22.         int KeyDown();
  23.         int KeyUp();
  24.         int KeyHome();
  25.         int KeyEnd();
  26.         int KeyPgDown();
  27.         int KeyPgUp();
  28.         void CheckDoesValuesOkey();
  29.         void SetSizes(int xx, yy, ww, hh, line_hh);
  30.         void SetFont(dword font_ww, font_hh, font_tt);
  31.         int MouseScroll(dword scroll_state);
  32.         void debug_values();
  33. };
  34.  
  35.  
  36. void llist::debug_values()
  37. {
  38.         char yi[128];
  39.         sprintf(#yi, "%s %d %s %d %s %d %s %d", "current:", current, "first:", first,
  40.         "visible:", visible, "count:", count);
  41.         debugln(#yi);
  42. }
  43.  
  44.  
  45.  
  46. void llist::ClearList()
  47. {
  48.         count = visible = first = current = 0;
  49. }
  50.  
  51.  
  52. void llist::SetSizes(int xx, yy, ww, hh, line_hh)
  53. {
  54.         x = xx;
  55.         y = yy;
  56.         w = ww;
  57.         h = hh;
  58.         line_h = line_hh;
  59.         text_y = line_h - font_h / 2;
  60.         visible = h / line_h;
  61.         wheel_size = 3;
  62.         //if (visible > count) visible=count;
  63. }
  64.  
  65. void llist::SetFont(dword font_ww, font_hh, font_tt)
  66. {
  67.         font_w = font_ww;
  68.         font_h = font_hh;
  69.         font_type = font_tt;
  70. }
  71.  
  72.  
  73. int llist::MouseScroll(dword scroll_state)
  74. {
  75.         if (count<=visible) return 0;
  76.         if (scroll_state == 65535)
  77.         {
  78.                 if (first == 0) return 0;
  79.                 if (first > wheel_size+1) first -= wheel_size; else first=0;
  80.                 return 1;
  81.         }
  82.         if (scroll_state == 1)
  83.         {
  84.                 if (visible + first == count) return 0;
  85.                 if (visible+first+wheel_size+1 > count) first = count - visible; else first+=wheel_size;
  86.                 return 1;
  87.         }
  88.         return 0;
  89. }
  90.  
  91.  
  92. int llist::MouseOver(int xx, yy)
  93. {
  94.         if (xx>x) && (xx<x+w) && (yy>y) && (yy<y+h) return 1;
  95.         return 0;
  96. }
  97.  
  98. int llist::ProcessMouse(int xx, yy)
  99. {
  100.         int current_temp;
  101.         if (MouseOver(xx, yy))
  102.         {
  103.                 current_temp = yy - y / line_h + first;
  104.                 if (current_temp != current) && (current_temp<count)
  105.                 {
  106.                         current = current_temp;
  107.                         return 1;
  108.                 }
  109.         }
  110.         return 0;
  111. }
  112.  
  113. int llist::ProcessKey(dword key)
  114. {
  115.         switch(key)
  116.         {
  117.                 case SCAN_CODE_DOWN: return KeyDown();
  118.                 case SCAN_CODE_UP:   return KeyUp();
  119.                 case SCAN_CODE_HOME: return KeyHome();
  120.                 case SCAN_CODE_END:  return KeyEnd();
  121.                 case SCAN_CODE_PGUP: return KeyPgUp();
  122.                 case SCAN_CODE_PGDN: return KeyPgDown();
  123.         }
  124.         return 0;
  125. }
  126.  
  127. int llist::KeyDown()
  128. {
  129.         if (current-first+1<visible) && (!no_selection)
  130.         {
  131.                 if (current + 1 >= count) return 0;
  132.                 current++;
  133.         }
  134.         else
  135.         {
  136.                 if (visible + first >= count) return 0;
  137.                 first++;
  138.                 current++;
  139.         }
  140.         if (current < first) || (current > first + visible)
  141.         {
  142.                 first = current;
  143.                 CheckDoesValuesOkey();
  144.         }
  145.         return 1;
  146. }
  147.  
  148. int llist::KeyUp()
  149. {
  150.         if (current > first) && (!no_selection)
  151.         {
  152.                 current--;
  153.         }
  154.         else
  155.         {
  156.                 if (first == 0) return 0;
  157.                 first--;
  158.                 current--;
  159.         }
  160.         if (current < first) || (current > first + visible)
  161.         {
  162.                 first = current;
  163.                 CheckDoesValuesOkey();
  164.         }
  165.         return 1;
  166. }
  167.  
  168. int llist::KeyHome()
  169. {
  170.         if (current==0) && (first==0) return 0;
  171.         current = first = 0;
  172.         return 1;
  173. }
  174.  
  175. int llist::KeyEnd()
  176. {
  177.         if (current==count-1) && (first==count-visible) return 0;
  178.         current = count-1;
  179.         first = count - visible;
  180.         return 1;
  181. }
  182.  
  183. int llist::KeyPgUp()
  184. {
  185.         if (count <= visible) return KeyHome();
  186.         if (first == 0) return 0;
  187.         first -= visible;
  188.         CheckDoesValuesOkey();
  189.         return 1;
  190. }
  191.  
  192. int llist::KeyPgDown()
  193. {
  194.         if (count <= visible) return KeyEnd();
  195.         if (first == count - visible) return 0;
  196.         first += visible;
  197.         CheckDoesValuesOkey();
  198.         return 1;
  199. }
  200.  
  201. void llist::CheckDoesValuesOkey()
  202. {
  203.         if (first < 0) first = 0;
  204.         if (visible + first > count) first = count - visible;
  205.         if (current >= count) current = count - 1;
  206.         if (current < 0) current = 0;
  207. }
  208.  
  209. void llist_copy(dword dest, src)
  210. {
  211.         EDI = dest;
  212.         ESI = src;
  213.         EDI.llist.x = ESI.llist.x;
  214.         EDI.llist.y = ESI.llist.y;
  215.         EDI.llist.w = ESI.llist.w;
  216.         EDI.llist.h = ESI.llist.h;
  217.         EDI.llist.line_h = ESI.llist.line_h;
  218.         EDI.llist.text_y = ESI.llist.text_y;
  219.         EDI.llist.font_w = ESI.llist.font_w;
  220.         EDI.llist.font_h = ESI.llist.font_h;
  221.         EDI.llist.font_type = ESI.llist.font_type;
  222.         EDI.llist.count = ESI.llist.count;
  223.         EDI.llist.visible = ESI.llist.visible;
  224.         EDI.llist.first = ESI.llist.first;
  225.         EDI.llist.current = ESI.llist.current;
  226.         EDI.llist.column_max = ESI.llist.column_max;
  227.         EDI.llist.active = ESI.llist.active;
  228. }
  229.  
  230. #endif