Subversion Repositories Kolibri OS

Rev

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