Subversion Repositories Kolibri OS

Rev

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