Subversion Repositories Kolibri OS

Rev

Rev 4846 | Rev 5465 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

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