Subversion Repositories Kolibri OS

Rev

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