Subversion Repositories Kolibri OS

Rev

Rev 4063 | Rev 4077 | 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;
  6.         int count, visible, first, current;
  7.         int current_temp;
  8.         void ClearList();
  9.         int ProcessKey(dword key);
  10.         int KeyDown();
  11.         int KeyUp();
  12.         int KeyHome();
  13.         int KeyEnd();
  14.         void SetSizes(int xx, yy, ww, hh, min_hh, line_hh);
  15.         int MouseScroll(dword scroll_state);
  16. };
  17.  
  18.  
  19. void llist::ClearList()
  20. {
  21.         count = visible = first = current = 0;
  22. }
  23.  
  24.  
  25. void llist::SetSizes(int xx, yy, ww, hh, min_hh, line_hh)
  26. {
  27.         x = xx;
  28.         y = yy;
  29.         w = ww;
  30.         h = hh;
  31.         min_h = min_hh;
  32.         line_h = line_hh;
  33.         visible = h / line_h;
  34. }
  35.  
  36.  
  37. int llist::MouseScroll(dword scroll_state)
  38. {
  39.         if (scroll_state == 65535)
  40.         {
  41.                 if (first == 0) return 0;
  42.                 if (first > 3) first -= 2; else first=0;
  43.                 return 1;
  44.         }
  45.         if (scroll_state == 1)
  46.         {
  47.                 if (visible+first+3 >= count) first = count - visible; else first+=2;
  48.                 return 1;
  49.         }
  50.         return 0;
  51. }
  52.  
  53. int llist::ProcessKey(dword key)
  54. {
  55.         switch(key)
  56.         {
  57.                 case 177: return KeyDown();
  58.                 case 178: return KeyUp();
  59.                 case 180: return KeyHome();
  60.                 case 181: return KeyEnd();
  61.         }
  62.         return 0;
  63. }
  64.  
  65. int llist::KeyDown()
  66. {
  67.         if (current-first+1<visible)
  68.         {
  69.                 if (current+1>=count) return 0;
  70.                 current++;
  71.         }
  72.         else
  73.         {
  74.                 if (visible+first>=count) return 0;
  75.                 first++;
  76.                 current++;
  77.         }
  78.         return 1;
  79. }
  80.  
  81. int llist::KeyUp()
  82. {
  83.         if (current>first)
  84.         {
  85.                 current--;
  86.         }
  87.         else
  88.         {
  89.                 if (first==0) return 0;
  90.                 first--;
  91.                 current--;
  92.         }
  93.         return 1;
  94. }
  95.  
  96. int llist::KeyHome()
  97. {
  98.         if (current==0) && (first==0) return 0;
  99.         current=0;
  100.         first=0;
  101.         return 1;
  102. }
  103.  
  104. int llist::KeyEnd()
  105. {
  106.         if (current==count-1) && (first==count-visible) return 0;
  107.         current=count-1;
  108.         first=count-visible;
  109.         return 1;
  110. }