Subversion Repositories Kolibri OS

Rev

Rev 5702 | Rev 5710 | 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
5598 pavelyakov 2
#ifndef INCLUDE_LIST_BOX_H
3
#define INCLUDE_LIST_BOX_H
5676 pavelyakov 4
#print "[include ]\n"
3225 leency 5
 
5598 pavelyakov 6
#ifndef INCLUDE_KOLIBRI_H
7
#include "../lib/kolibri.h"
8
#endif
9
 
3225 leency 10
struct llist
11
{
5709 leency 12
	int x, y, w, h, line_h, char_w, char_h, text_y;
13
	int count, visible, first, current, column_max; //visible = row_max
4409 leency 14
	int active;
3225 leency 15
	void ClearList();
4077 leency 16
	int MouseOver(int xx, yy);
17
	int ProcessMouse(int xx, yy);
5694 leency 18
	int ProcessKey(dword key);
4059 leency 19
	int KeyDown();
20
	int KeyUp();
4063 leency 21
	int KeyHome();
22
	int KeyEnd();
5694 leency 23
	int KeyPgDown();
24
	int KeyPgUp();
25
	void CheckDoesValuesOkey();
3225 leency 26
	void SetSizes(int xx, yy, ww, hh, min_hh, line_hh);
27
	int MouseScroll(dword scroll_state);
5616 leency 28
	int MouseScrollNoSelection(dword scroll_state);
29
	void debug_values();
3225 leency 30
};
31
 
32
 
5616 leency 33
void llist::debug_values()
34
{
5694 leency 35
	char yi[128];
36
	sprintf(#yi, "%s %d %s %d %s %d %s %d", "current:", current, "first:", first,
37
	"visible:", visible, "count:", count);
38
	debugln(#yi);
5616 leency 39
}
4662 leency 40
 
5421 leency 41
 
42
 
3225 leency 43
void llist::ClearList()
44
{
45
	count = visible = first = current = 0;
46
}
47
 
48
 
5709 leency 49
void llist::SetSizes(int xx, yy, ww, hh, line_hh)
3225 leency 50
{
51
	x = xx;
52
	y = yy;
53
	w = ww;
54
	h = hh;
55
	line_h = line_hh;
5694 leency 56
	text_y = line_h / 2 - 4;
3368 leency 57
	visible = h / line_h;
4846 leency 58
	//if (visible > count) visible=count;
3225 leency 59
}
60
 
61
 
62
int llist::MouseScroll(dword scroll_state)
63
{
4533 leency 64
	if (count<=visible) return 0;
3225 leency 65
	if (scroll_state == 65535)
66
	{
67
		if (first == 0) return 0;
68
		if (first > 3) first -= 2; else first=0;
69
		return 1;
70
	}
71
	if (scroll_state == 1)
72
	{
5421 leency 73
		if (visible + first == count) return 0;
74
		if (visible+first+3 > count) first = count - visible; else first+=2;
3225 leency 75
		return 1;
76
	}
77
	return 0;
4059 leency 78
}
79
 
5616 leency 80
int llist::MouseScrollNoSelection(dword scroll_state)
81
{
82
	if (count<=visible) return 0;
83
	if (scroll_state == 65535)
84
	{
85
		if (current == 0) return 0;
86
		if (current > 3) current -= 2; else current=0;
87
		return 1;
88
	}
89
	if (scroll_state == 1)
90
	{
91
		if (visible + current == count) return 0;
92
		if (visible+current+3 > count) current = count - visible; else current+=2;
93
		return 1;
94
	}
95
	return 0;
96
}
97
 
4077 leency 98
int llist::MouseOver(int xx, yy)
99
{
100
	if (xx>x) && (xxy) && (yy
101
	return 0;
102
}
103
 
104
int llist::ProcessMouse(int xx, yy)
105
{
4078 leency 106
	int current_temp;
4077 leency 107
	if (MouseOver(xx, yy))
108
	{
109
		current_temp = yy - y / line_h + first;
4078 leency 110
		if (current_temp != current) && (current_temp
4077 leency 111
		{
112
			current = current_temp;
113
			return 1;
114
		}
115
	}
116
	return 0;
117
}
118
 
4073 leency 119
int llist::ProcessKey(dword key)
120
{
121
	switch(key)
122
	{
5702 punk_joker 123
		case SCAN_CODE_DOWN: return KeyDown();
124
		case SCAN_CODE_UP:   return KeyUp();
125
		case SCAN_CODE_HOME: return KeyHome();
126
		case SCAN_CODE_END:  return KeyEnd();
127
		case SCAN_CODE_PGUP: return KeyPgUp();
128
		case SCAN_CODE_PGDN: return KeyPgDown();
4073 leency 129
	}
130
	return 0;
131
}
132
 
4059 leency 133
int llist::KeyDown()
134
{
135
	if (current-first+1
136
	{
5694 leency 137
		if (current + 1 >= count) return 0;
4059 leency 138
		current++;
139
	}
140
	else
141
	{
5694 leency 142
		if (visible + first >= count) return 0;
4059 leency 143
		first++;
144
		current++;
145
	}
5694 leency 146
	if (current < first) || (current > first + visible)
147
	{
148
		first = current;
149
		CheckDoesValuesOkey();
150
	}
4059 leency 151
	return 1;
152
}
153
 
154
int llist::KeyUp()
155
{
5694 leency 156
	if (current > first)
4059 leency 157
	{
158
		current--;
159
	}
160
	else
161
	{
5694 leency 162
		if (first == 0) return 0;
4059 leency 163
		first--;
164
		current--;
165
	}
5694 leency 166
	if (current < first) || (current > first + visible)
167
	{
168
		first = current;
169
		CheckDoesValuesOkey();
170
	}
4059 leency 171
	return 1;
4063 leency 172
}
173
 
174
int llist::KeyHome()
175
{
176
	if (current==0) && (first==0) return 0;
5694 leency 177
	current = first = 0;
4063 leency 178
	return 1;
179
}
180
 
181
int llist::KeyEnd()
182
{
183
	if (current==count-1) && (first==count-visible) return 0;
5694 leency 184
	current = count-1;
185
	first = count - visible;
4063 leency 186
	return 1;
5598 pavelyakov 187
}
188
 
5694 leency 189
int llist::KeyPgUp()
190
{
191
	if (count <= visible) return KeyHome();
192
	if (first == 0) return 0;
193
	first -= visible;
194
	CheckDoesValuesOkey();
195
	return 1;
196
}
197
 
198
int llist::KeyPgDown()
199
{
200
	if (count <= visible) return KeyEnd();
201
	if (first == count - visible) return 0;
202
	first += visible;
203
	CheckDoesValuesOkey();
204
	return 1;
205
}
206
 
207
void llist::CheckDoesValuesOkey()
208
{
209
	if (first < 0) first = 0;
210
	if (visible + first > count) first = count - visible;
211
	if (current >= count) current = count - 1;
212
	if (current < 0) current = 0;
213
}
214
 
5598 pavelyakov 215
#endif