Subversion Repositories Kolibri OS

Rev

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