Subversion Repositories Kolibri OS

Rev

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