Subversion Repositories Kolibri OS

Rev

Rev 4533 | Rev 4846 | 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);
4662 leency 19
	//void debug_values();
3225 leency 20
};
21
 
4662 leency 22
/*
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
}
34
*/
3225 leency 35
 
4662 leency 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;
4078 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
	{
68
		if (visible+first+3 >= count) first = count - visible; else first+=2;
69
		return 1;
70
	}
71
	return 0;
4059 leency 72
}
73
 
4077 leency 74
int llist::MouseOver(int xx, yy)
75
{
76
	if (xx>x) && (xxy) && (yy
77
	return 0;
78
}
79
 
80
int llist::ProcessMouse(int xx, yy)
81
{
4078 leency 82
	int current_temp;
4077 leency 83
	if (MouseOver(xx, yy))
84
	{
85
		current_temp = yy - y / line_h + first;
4078 leency 86
		if (current_temp != current) && (current_temp
4077 leency 87
		{
88
			current = current_temp;
89
			return 1;
90
		}
91
	}
92
	return 0;
93
}
94
 
4073 leency 95
int llist::ProcessKey(dword key)
96
{
97
	switch(key)
98
	{
99
		case 177: return KeyDown();
100
		case 178: return KeyUp();
101
		case 180: return KeyHome();
102
		case 181: return KeyEnd();
103
	}
104
	return 0;
105
}
106
 
4059 leency 107
int llist::KeyDown()
108
{
109
	if (current-first+1
110
	{
4063 leency 111
		if (current+1>=count) return 0;
4059 leency 112
		current++;
113
	}
114
	else
115
	{
4063 leency 116
		if (visible+first>=count) return 0;
4059 leency 117
		first++;
118
		current++;
119
	}
120
	return 1;
121
}
122
 
123
int llist::KeyUp()
124
{
125
	if (current>first)
126
	{
127
		current--;
128
	}
129
	else
130
	{
4063 leency 131
		if (first==0) return 0;
4059 leency 132
		first--;
133
		current--;
134
	}
135
	return 1;
4063 leency 136
}
137
 
138
int llist::KeyHome()
139
{
140
	if (current==0) && (first==0) return 0;
141
	current=0;
142
	first=0;
143
	return 1;
144
}
145
 
146
int llist::KeyEnd()
147
{
148
	if (current==count-1) && (first==count-visible) return 0;
149
	current=count-1;
150
	first=count-visible;
151
	return 1;
3225 leency 152
}