2013-02-04 14:15:13 +01:00
|
|
|
//list_box
|
2015-07-22 20:32:54 +02:00
|
|
|
#ifndef INCLUDE_LIST_BOX_H
|
|
|
|
#define INCLUDE_LIST_BOX_H
|
2015-08-04 17:48:36 +02:00
|
|
|
#print "[include <list_box.h>]\n"
|
2015-07-22 20:32:54 +02:00
|
|
|
|
|
|
|
#ifndef INCLUDE_KOLIBRI_H
|
|
|
|
#include "../lib/kolibri.h"
|
|
|
|
#endif
|
2013-02-04 14:15:13 +01:00
|
|
|
|
|
|
|
struct llist
|
|
|
|
{
|
2013-10-24 00:05:17 +02:00
|
|
|
int x, y, w, h, min_h, line_h, text_y;
|
2013-12-27 12:15:17 +01:00
|
|
|
int column_max;
|
2015-07-24 23:48:31 +02:00
|
|
|
int count, visible, first, current; //visible = row_max
|
2013-12-26 22:48:54 +01:00
|
|
|
int active;
|
2013-02-04 14:15:13 +01:00
|
|
|
void ClearList();
|
2013-10-23 21:03:10 +02:00
|
|
|
int MouseOver(int xx, yy);
|
|
|
|
int ProcessMouse(int xx, yy);
|
2015-08-07 16:55:16 +02:00
|
|
|
int ProcessKey(dword key);
|
2013-10-20 14:20:57 +02:00
|
|
|
int KeyDown();
|
|
|
|
int KeyUp();
|
2013-10-21 00:47:10 +02:00
|
|
|
int KeyHome();
|
|
|
|
int KeyEnd();
|
2015-08-07 16:55:16 +02:00
|
|
|
int KeyPgDown();
|
|
|
|
int KeyPgUp();
|
|
|
|
void CheckDoesValuesOkey();
|
2013-02-04 14:15:13 +01:00
|
|
|
void SetSizes(int xx, yy, ww, hh, min_hh, line_hh);
|
|
|
|
int MouseScroll(dword scroll_state);
|
2015-07-24 23:48:31 +02:00
|
|
|
int MouseScrollNoSelection(dword scroll_state);
|
|
|
|
void debug_values();
|
2013-02-04 14:15:13 +01:00
|
|
|
};
|
|
|
|
|
2015-02-18 20:52:40 +01:00
|
|
|
|
2015-07-24 23:48:31 +02:00
|
|
|
void llist::debug_values()
|
|
|
|
{
|
2015-08-07 16:55:16 +02:00
|
|
|
char yi[128];
|
|
|
|
sprintf(#yi, "%s %d %s %d %s %d %s %d", "current:", current, "first:", first,
|
|
|
|
"visible:", visible, "count:", count);
|
|
|
|
debugln(#yi);
|
2015-07-24 23:48:31 +02:00
|
|
|
}
|
2015-02-18 20:52:40 +01:00
|
|
|
|
2014-03-18 00:10:13 +01:00
|
|
|
|
2013-02-04 14:15:13 +01:00
|
|
|
|
|
|
|
void llist::ClearList()
|
|
|
|
{
|
|
|
|
count = visible = first = current = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void llist::SetSizes(int xx, yy, ww, hh, min_hh, line_hh)
|
|
|
|
{
|
|
|
|
x = xx;
|
|
|
|
y = yy;
|
|
|
|
w = ww;
|
|
|
|
h = hh;
|
|
|
|
min_h = min_hh;
|
|
|
|
line_h = line_hh;
|
2015-08-07 16:55:16 +02:00
|
|
|
text_y = line_h / 2 - 4;
|
2013-03-12 17:19:10 +01:00
|
|
|
visible = h / line_h;
|
2015-07-24 23:48:31 +02:00
|
|
|
column_max = w / 6;
|
2014-04-17 20:07:07 +02:00
|
|
|
//if (visible > count) visible=count;
|
2013-02-04 14:15:13 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int llist::MouseScroll(dword scroll_state)
|
|
|
|
{
|
2014-01-27 02:17:07 +01:00
|
|
|
if (count<=visible) return 0;
|
2013-02-04 14:15:13 +01:00
|
|
|
if (scroll_state == 65535)
|
|
|
|
{
|
|
|
|
if (first == 0) return 0;
|
|
|
|
if (first > 3) first -= 2; else first=0;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
if (scroll_state == 1)
|
|
|
|
{
|
2015-02-18 20:52:40 +01:00
|
|
|
if (visible + first == count) return 0;
|
|
|
|
if (visible+first+3 > count) first = count - visible; else first+=2;
|
2013-02-04 14:15:13 +01:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
return 0;
|
2013-10-20 14:20:57 +02:00
|
|
|
}
|
|
|
|
|
2015-07-24 23:48:31 +02:00
|
|
|
int llist::MouseScrollNoSelection(dword scroll_state)
|
|
|
|
{
|
|
|
|
if (count<=visible) return 0;
|
|
|
|
if (scroll_state == 65535)
|
|
|
|
{
|
|
|
|
if (current == 0) return 0;
|
|
|
|
if (current > 3) current -= 2; else current=0;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
if (scroll_state == 1)
|
|
|
|
{
|
|
|
|
if (visible + current == count) return 0;
|
|
|
|
if (visible+current+3 > count) current = count - visible; else current+=2;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2013-10-23 21:03:10 +02:00
|
|
|
int llist::MouseOver(int xx, yy)
|
|
|
|
{
|
|
|
|
if (xx>x) && (xx<x+w) && (yy>y) && (yy<y+h) return 1;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int llist::ProcessMouse(int xx, yy)
|
|
|
|
{
|
2013-10-24 00:05:17 +02:00
|
|
|
int current_temp;
|
2013-10-23 21:03:10 +02:00
|
|
|
if (MouseOver(xx, yy))
|
|
|
|
{
|
|
|
|
current_temp = yy - y / line_h + first;
|
2013-10-24 00:05:17 +02:00
|
|
|
if (current_temp != current) && (current_temp<count)
|
2013-10-23 21:03:10 +02:00
|
|
|
{
|
|
|
|
current = current_temp;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2013-10-22 23:35:16 +02:00
|
|
|
int llist::ProcessKey(dword key)
|
|
|
|
{
|
|
|
|
switch(key)
|
|
|
|
{
|
2015-08-09 23:59:25 +02:00
|
|
|
case SCAN_CODE_DOWN: return KeyDown();
|
|
|
|
case SCAN_CODE_UP: return KeyUp();
|
|
|
|
case SCAN_CODE_HOME: return KeyHome();
|
|
|
|
case SCAN_CODE_END: return KeyEnd();
|
|
|
|
case SCAN_CODE_PGUP: return KeyPgUp();
|
|
|
|
case SCAN_CODE_PGDN: return KeyPgDown();
|
2013-10-22 23:35:16 +02:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2013-10-20 14:20:57 +02:00
|
|
|
int llist::KeyDown()
|
|
|
|
{
|
|
|
|
if (current-first+1<visible)
|
|
|
|
{
|
2015-08-07 16:55:16 +02:00
|
|
|
if (current + 1 >= count) return 0;
|
2013-10-20 14:20:57 +02:00
|
|
|
current++;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2015-08-07 16:55:16 +02:00
|
|
|
if (visible + first >= count) return 0;
|
2013-10-20 14:20:57 +02:00
|
|
|
first++;
|
|
|
|
current++;
|
|
|
|
}
|
2015-08-07 16:55:16 +02:00
|
|
|
if (current < first) || (current > first + visible)
|
|
|
|
{
|
|
|
|
first = current;
|
|
|
|
CheckDoesValuesOkey();
|
|
|
|
}
|
2013-10-20 14:20:57 +02:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
int llist::KeyUp()
|
|
|
|
{
|
2015-08-07 16:55:16 +02:00
|
|
|
if (current > first)
|
2013-10-20 14:20:57 +02:00
|
|
|
{
|
|
|
|
current--;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2015-08-07 16:55:16 +02:00
|
|
|
if (first == 0) return 0;
|
2013-10-20 14:20:57 +02:00
|
|
|
first--;
|
|
|
|
current--;
|
|
|
|
}
|
2015-08-07 16:55:16 +02:00
|
|
|
if (current < first) || (current > first + visible)
|
|
|
|
{
|
|
|
|
first = current;
|
|
|
|
CheckDoesValuesOkey();
|
|
|
|
}
|
2013-10-20 14:20:57 +02:00
|
|
|
return 1;
|
2013-10-21 00:47:10 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
int llist::KeyHome()
|
|
|
|
{
|
|
|
|
if (current==0) && (first==0) return 0;
|
2015-08-07 16:55:16 +02:00
|
|
|
current = first = 0;
|
2013-10-21 00:47:10 +02:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
int llist::KeyEnd()
|
|
|
|
{
|
|
|
|
if (current==count-1) && (first==count-visible) return 0;
|
2015-08-07 16:55:16 +02:00
|
|
|
current = count-1;
|
|
|
|
first = count - visible;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
int llist::KeyPgUp()
|
|
|
|
{
|
|
|
|
if (count <= visible) return KeyHome();
|
|
|
|
if (first == 0) return 0;
|
|
|
|
first -= visible;
|
|
|
|
CheckDoesValuesOkey();
|
2013-10-21 00:47:10 +02:00
|
|
|
return 1;
|
2015-07-22 20:32:54 +02:00
|
|
|
}
|
|
|
|
|
2015-08-07 16:55:16 +02:00
|
|
|
int llist::KeyPgDown()
|
|
|
|
{
|
|
|
|
if (count <= visible) return KeyEnd();
|
|
|
|
if (first == count - visible) return 0;
|
|
|
|
first += visible;
|
|
|
|
CheckDoesValuesOkey();
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
void llist::CheckDoesValuesOkey()
|
|
|
|
{
|
|
|
|
if (first < 0) first = 0;
|
|
|
|
if (visible + first > count) first = count - visible;
|
|
|
|
if (current >= count) current = count - 1;
|
|
|
|
if (current < 0) current = 0;
|
|
|
|
}
|
|
|
|
|
2015-07-22 20:32:54 +02:00
|
|
|
#endif
|