Subversion Repositories Kolibri OS

Rev

Rev 4415 | Rev 4846 | 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 (count<=visible) return 0;
  45.         if (scroll_state == 65535)
  46.         {
  47.                 if (first == 0) return 0;
  48.                 if (first > 3) first -= 2; else first=0;
  49.                 return 1;
  50.         }
  51.         if (scroll_state == 1)
  52.         {
  53.                 if (visible+first+3 >= count) first = count - visible; else first+=2;
  54.                 return 1;
  55.         }
  56.         return 0;
  57. }
  58.  
  59. int llist::MouseOver(int xx, yy)
  60. {
  61.         if (xx>x) && (xx<x+w) && (yy>y) && (yy<y+h) return 1;
  62.         return 0;
  63. }
  64.  
  65. int llist::ProcessMouse(int xx, yy)
  66. {
  67.         int current_temp;
  68.         if (MouseOver(xx, yy))
  69.         {
  70.                 current_temp = yy - y / line_h + first;
  71.                 if (current_temp != current) && (current_temp<count)
  72.                 {
  73.                         current = current_temp;
  74.                         return 1;
  75.                 }
  76.         }
  77.         return 0;
  78. }
  79.  
  80. int llist::ProcessKey(dword key)
  81. {
  82.         switch(key)
  83.         {
  84.                 case 177: return KeyDown();
  85.                 case 178: return KeyUp();
  86.                 case 180: return KeyHome();
  87.                 case 181: return KeyEnd();
  88.         }
  89.         return 0;
  90. }
  91.  
  92. int llist::KeyDown()
  93. {
  94.         if (current-first+1<visible)
  95.         {
  96.                 if (current+1>=count) return 0;
  97.                 current++;
  98.         }
  99.         else
  100.         {
  101.                 if (visible+first>=count) return 0;
  102.                 first++;
  103.                 current++;
  104.         }
  105.         return 1;
  106. }
  107.  
  108. int llist::KeyUp()
  109. {
  110.         if (current>first)
  111.         {
  112.                 current--;
  113.         }
  114.         else
  115.         {
  116.                 if (first==0) return 0;
  117.                 first--;
  118.                 current--;
  119.         }
  120.         return 1;
  121. }
  122.  
  123. int llist::KeyHome()
  124. {
  125.         if (current==0) && (first==0) return 0;
  126.         current=0;
  127.         first=0;
  128.         return 1;
  129. }
  130.  
  131. int llist::KeyEnd()
  132. {
  133.         if (current==count-1) && (first==count-visible) return 0;
  134.         current=count-1;
  135.         first=count-visible;
  136.         return 1;
  137. }