Subversion Repositories Kolibri OS

Rev

Rev 7924 | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 7924 Rev 7941
1
#ifndef INCLUDE_LIST_BOX_H
1
#ifndef INCLUDE_LIST_BOX_H
2
#define INCLUDE_LIST_BOX_H
2
#define INCLUDE_LIST_BOX_H
3
 
3
 
4
#ifndef INCLUDE_KOLIBRI_H
4
#ifndef INCLUDE_KOLIBRI_H
5
#include "../lib/kolibri.h"
5
#include "../lib/kolibri.h"
6
#endif
6
#endif
7
 
7
 
8
struct llist
8
struct llist
9
{
9
{
10
	int x, y, w, h, item_h, item_w;
10
	int x, y, w, h, item_h, item_w;
11
	int count, visible, first, column_max; //visible = row_max
11
	int count, visible, first, column_max; //visible = row_max
12
	int cur_x, cur_y;
12
	int cur_x, cur_y;
13
	int text_y;
13
	int text_y;
14
	byte font_w, font_h, font_type;
14
	byte font_w, font_h, font_type;
15
	byte wheel_size;
15
	byte wheel_size;
16
	byte active;
16
	byte active;
17
	byte no_selection;
17
	byte no_selection;
18
	byte horisontal_selelection;
18
	byte horisontal_selelection;
19
	void ClearList();
19
	void ClearList();
20
	void SetSizes(int xx, yy, ww, hh, item_hh);
20
	void SetSizes(int xx, yy, ww, hh, item_hh);
21
	void SetFont(dword font_ww, font_hh, font_tt);
21
	void SetFont(dword font_ww, font_hh, font_tt);
22
	int ProcessKey(dword key);
22
	int ProcessKey(dword key);
23
	int ProcessMouse(int xx, yy);
23
	int ProcessMouse(int xx, yy);
24
	int MouseOver(int xx, yy);
24
	int MouseOver(int xx, yy);
25
	int MouseScroll(dword scroll_state);
25
	int MouseScroll(dword scroll_state);
26
	int KeyDown(); 
26
	int KeyDown(); 
27
	int KeyUp(); 
27
	int KeyUp(); 
28
	int KeyHome(); 
28
	int KeyHome(); 
29
	int KeyHomeHor(); 
29
	int KeyHomeHor(); 
30
	int KeyEnd(); 
30
	int KeyEnd(); 
31
	int KeyEndHor(); 
31
	int KeyEndHor(); 
32
	int KeyPgDown(); 
32
	int KeyPgDown(); 
33
	int KeyPgUp(); 
33
	int KeyPgUp(); 
34
	int KeyLeft(); 
34
	int KeyLeft(); 
35
	int KeyRight();
35
	int KeyRight();
36
	void CheckDoesValuesOkey();
36
	void CheckDoesValuesOkey();
37
	void debug();
37
	void debug();
38
};
38
};
39
 
39
 
40
:void llist::debug()
40
:void llist::debug()
41
{
41
{
42
	char yi[128];
42
	char yi[128];
43
	sprintf(#yi, "%s %d %s %d %s %d %s %d %s %d %s %d", "first:", first, "visible:", visible, "count:", count, "col_max:", column_max, "cur_y:", cur_y, "cur_x:", cur_x);
43
	sprintf(#yi, "%s %d %s %d %s %d %s %d %s %d %s %d", "first:", first, "visible:", visible, "count:", count, "col_max:", column_max, "cur_y:", cur_y, "cur_x:", cur_x);
44
	debugln(#yi);
44
	debugln(#yi);
45
}
45
}
46
 
46
 
47
 
47
 
48
:void llist::ClearList()
48
:void llist::ClearList()
49
{
49
{
50
	count = visible = first = cur_y = cur_x = 0;
50
	count = visible = first = cur_y = cur_x = 0;
51
}
51
}
52
 
52
 
53
 
53
 
54
:void llist::SetSizes(int xx, yy, ww, hh, item_hh)
54
:void llist::SetSizes(int xx, yy, ww, hh, item_hh)
55
{
55
{
56
	x = xx;
56
	x = xx;
57
	y = yy;
57
	y = yy;
58
	w = ww;
58
	w = ww;
59
	h = hh;
59
	h = hh;
60
	item_h = item_hh;
60
	item_h = item_hh;
61
	text_y = item_h - font_h / 2;
61
	text_y = item_h - font_h / 2;
62
	visible = h / item_h;
62
	visible = h / item_h;
63
	wheel_size = 3;
63
	wheel_size = 3;
64
	CheckDoesValuesOkey();
64
	CheckDoesValuesOkey();
65
}
65
}
66
 
66
 
67
 
67
 
68
:void llist::SetFont(dword font_ww, font_hh, font_tt)
68
:void llist::SetFont(dword font_ww, font_hh, font_tt)
69
{
69
{
70
	font_w = font_ww;
70
	font_w = font_ww;
71
	font_h = font_hh;
71
	font_h = font_hh;
72
	font_type = font_tt;
72
	font_type = font_tt;
73
}
73
}
74
 
74
 
75
 
75
 
76
:int llist::MouseScroll(dword scroll_state)
76
:int llist::MouseScroll(dword scroll_state)
77
{
77
{
78
	if (count<=visible) return 0;
78
	if (count<=visible) return 0;
79
	if (scroll_state == 65535)
79
	if (scroll_state == 65535)
80
	{
80
	{
81
		if (first == 0) return 0;
81
		if (first == 0) return 0;
82
		if (first > wheel_size+1) first -= wheel_size; else first=0;
82
		if (first > wheel_size+1) first -= wheel_size; else first=0;
83
		CheckDoesValuesOkey();
83
		CheckDoesValuesOkey();
84
		return 1;
84
		return 1;
85
	} 
85
	} 
86
	if (scroll_state == 1)
86
	if (scroll_state == 1)
87
	{
87
	{
88
		if (visible + first == count) return 0;
88
		if (visible + first == count) return 0;
89
		if (visible+first+wheel_size+1 > count) first = count - visible; else first+=wheel_size;
89
		if (visible+first+wheel_size+1 > count) first = count - visible; else first+=wheel_size;
90
		CheckDoesValuesOkey();
90
		CheckDoesValuesOkey();
91
		return 1;
91
		return 1;
92
	}
92
	}
93
	return 0;
93
	return 0;
94
}
94
}
95
 
95
 
96
 
96
 
97
:int llist::MouseOver(int xx, yy)
97
:int llist::MouseOver(int xx, yy)
98
{
98
{
99
	if (xx>x) && (xxy) && (yy
99
	if (xx>x) && (xxy) && (yy
100
	return 0;
100
	return 0;
101
}
101
}
102
 
102
 
103
:int llist::ProcessMouse(int xx, yy)
103
:int llist::ProcessMouse(int xx, yy)
104
{
104
{
105
	int cur_y_temp, cur_x_temp, ret=0;
105
	int new_cur_y, new_cur_x, ret=0;
106
	if (MouseOver(xx, yy))
106
	if (MouseOver(xx, yy))
107
	{
107
	{
108
		cur_y_temp = yy - y / item_h + first;
108
		new_cur_y = yy - y / item_h + first;
109
		if (cur_y_temp != cur_y) && (cur_y_temp
109
		if (new_cur_y != cur_y) && (new_cur_y
110
		{
110
		{
111
			cur_y = cur_y_temp;
111
			cur_y = new_cur_y;
112
			ret = 1;
112
			ret = 1;
113
		}
113
		}
114
		if (horisontal_selelection) 
114
		if (horisontal_selelection) 
115
		{		
115
		{		
116
			cur_x_temp = xx - x / item_w;
116
			new_cur_x = xx - x / item_w;
117
			if (cur_x_temp != cur_x) && (cur_x_temp
117
			if (new_cur_x != cur_x) && (new_cur_x
118
			{
118
			{
119
				cur_x = cur_x_temp;
119
				cur_x = new_cur_x;
120
				ret = 1;
120
				ret = 1;
121
			}
121
			}
122
		}
122
		}
123
	}
123
	}
124
	return ret;
124
	return ret;
125
}
125
}
126
 
126
 
127
:int llist::ProcessKey(dword key)
127
:int llist::ProcessKey(dword key)
128
{
128
{
129
	if (horisontal_selelection) {
129
	if (horisontal_selelection) {
130
		if (key_modifier & KEY_LCTRL) || (key_modifier & KEY_RCTRL)	switch(key)	{
130
		if (key_modifier & KEY_LCTRL) || (key_modifier & KEY_RCTRL)	switch(key)	{
131
			case SCAN_CODE_HOME:  KeyHome(); break;
131
			case SCAN_CODE_HOME:  KeyHome(); break;
132
			case SCAN_CODE_END:   KeyEnd();
132
			case SCAN_CODE_END:   KeyEnd();
133
		} 
133
		} 
134
		switch(key) {
134
		switch(key) {
135
			case SCAN_CODE_LEFT:  return KeyLeft();
135
			case SCAN_CODE_LEFT:  return KeyLeft();
136
			case SCAN_CODE_RIGHT: return KeyRight();
136
			case SCAN_CODE_RIGHT: return KeyRight();
137
			case SCAN_CODE_HOME:  return KeyHomeHor();
137
			case SCAN_CODE_HOME:  return KeyHomeHor();
138
			case SCAN_CODE_END:   return KeyEndHor();
138
			case SCAN_CODE_END:   return KeyEndHor();
139
		}
139
		}
140
	} 
140
	} 
141
	switch(key)
141
	switch(key)
142
	{
142
	{
143
		case SCAN_CODE_DOWN: return KeyDown();
143
		case SCAN_CODE_DOWN: return KeyDown();
144
		case SCAN_CODE_UP:   return KeyUp();
144
		case SCAN_CODE_UP:   return KeyUp();
145
		case SCAN_CODE_HOME: return KeyHome();
145
		case SCAN_CODE_HOME: return KeyHome();
146
		case SCAN_CODE_END:  return KeyEnd();
146
		case SCAN_CODE_END:  return KeyEnd();
147
		case SCAN_CODE_PGUP: return KeyPgUp();
147
		case SCAN_CODE_PGUP: return KeyPgUp();
148
		case SCAN_CODE_PGDN: return KeyPgDown();
148
		case SCAN_CODE_PGDN: return KeyPgDown();
149
	}
149
	}
150
	return 0;
150
	return 0;
151
}
151
}
152
 
152
 
153
:int llist::KeyDown()
153
:int llist::KeyDown()
154
{
154
{
155
	if (no_selection)
155
	if (no_selection)
156
	{
156
	{
157
		if (visible + first >= count) return 0;
157
		if (visible + first >= count) return 0;
158
		first++;
158
		first++;
159
		return 1;		
159
		return 1;		
160
	}
160
	}
161
 
161
 
162
	if (cur_y-first+1
162
	if (cur_y-first+1
163
	{
163
	{
164
		if (cur_y + 1 >= count) return 0;
164
		if (cur_y + 1 >= count) return 0;
165
		cur_y++;
165
		cur_y++;
166
	}
166
	}
167
	else 
167
	else 
168
	{
168
	{
169
		if (visible + first >= count) return 0;
169
		if (visible + first >= count) return 0;
170
		first++;
170
		first++;
171
		cur_y++;
171
		cur_y++;
172
	}
172
	}
173
	if (cur_y < first) || (cur_y >= first + visible)
173
	if (cur_y < first) || (cur_y >= first + visible)
174
	{
174
	{
175
		first = cur_y;
175
		first = cur_y;
176
	}
176
	}
177
	CheckDoesValuesOkey();
177
	CheckDoesValuesOkey();
178
	return 1;
178
	return 1;
179
}
179
}
180
 
180
 
181
:int llist::KeyUp()
181
:int llist::KeyUp()
182
{
182
{
183
	if (no_selection)
183
	if (no_selection)
184
	{
184
	{
185
		if (first == 0) return 0;
185
		if (first == 0) return 0;
186
		first--;
186
		first--;
187
		return 1;
187
		return 1;
188
	}
188
	}
189
 
189
 
190
	if (cur_y > first)
190
	if (cur_y > first)
191
	{
191
	{
192
		cur_y--;
192
		cur_y--;
193
	}
193
	}
194
	else
194
	else
195
	{
195
	{
196
		if (first == 0) return 0;
196
		if (first == 0) return 0;
197
		first--;
197
		first--;
198
		cur_y--;
198
		cur_y--;
199
	}
199
	}
200
	if (cur_y < first) || (cur_y > first + visible)
200
	if (cur_y < first) || (cur_y > first + visible)
201
	{
201
	{
202
		first = cur_y;
202
		first = cur_y;
203
		CheckDoesValuesOkey();
203
		CheckDoesValuesOkey();
204
	}
204
	}
205
	return 1;
205
	return 1;
206
}
206
}
207
 
207
 
208
:int llist::KeyHomeHor()
208
:int llist::KeyHomeHor()
209
{
209
{
210
	if (cur_x==0) return 0;
210
	if (cur_x==0) return 0;
211
	cur_x = 0;
211
	cur_x = 0;
212
	return 1;
212
	return 1;
213
}
213
}
214
 
214
 
215
:int llist::KeyEndHor()
215
:int llist::KeyEndHor()
216
{
216
{
217
	if (cur_x==column_max) return 0;
217
	if (cur_x==column_max) return 0;
218
	cur_x = column_max;
218
	cur_x = column_max;
219
	CheckDoesValuesOkey();
219
	CheckDoesValuesOkey();
220
	return 1;
220
	return 1;
221
}
221
}
222
 
222
 
223
:int llist::KeyHome()
223
:int llist::KeyHome()
224
{
224
{
225
	if (cur_y==0) && (first==0) return 0;
225
	if (cur_y==0) && (first==0) return 0;
226
	cur_y = first = 0;
226
	cur_y = first = 0;
227
	return 1;
227
	return 1;
228
}
228
}
229
 
229
 
230
:int llist::KeyEnd()
230
:int llist::KeyEnd()
231
{
231
{
232
	if (cur_y==count-1) && (first==count-visible) return 0;
232
	if (cur_y==count-1) && (first==count-visible) return 0;
233
	cur_y = count-1;
233
	cur_y = count-1;
234
	first = count - visible;
234
	first = count - visible;
235
	CheckDoesValuesOkey();
235
	CheckDoesValuesOkey();
236
	return 1;
236
	return 1;
237
}
237
}
238
 
238
 
239
:int llist::KeyPgUp()
239
:int llist::KeyPgUp()
240
{
240
{
241
	if (count <= visible) return KeyHome();
241
	if (count <= visible) return KeyHome();
242
	if (first == 0) return 0;
242
	if (first == 0) return 0;
243
	first -= visible;
243
	first -= visible;
244
	cur_y = first;
244
	cur_y = first;
245
	CheckDoesValuesOkey();
245
	CheckDoesValuesOkey();
246
	return 1;
246
	return 1;
247
}
247
}
248
 
248
 
249
:int llist::KeyPgDown()
249
:int llist::KeyPgDown()
250
{
250
{
251
	if (count <= visible) return KeyEnd();
251
	if (count <= visible) return KeyEnd();
252
	if (first == count - visible) return 0;
252
	if (first == count - visible) return 0;
253
	first += visible;
253
	first += visible;
254
	cur_y = first + visible - 1;
254
	cur_y = first + visible - 1;
255
	CheckDoesValuesOkey();
255
	CheckDoesValuesOkey();
256
	return 1;
256
	return 1;
257
}
257
}
258
 
258
 
259
:void llist::CheckDoesValuesOkey()
259
:void llist::CheckDoesValuesOkey()
260
{
260
{
261
	if (visible + first > count) first = count - visible;
261
	if (visible + first > count) first = count - visible;
262
	if (first < 0) first = 0;
262
	if (first < 0) first = 0;
263
	if (cur_y >= count) cur_y = count - 1;
263
	if (cur_y >= count) cur_y = count - 1;
264
	if (cur_x >= column_max) cur_x = column_max;
264
	if (cur_x >= column_max) cur_x = column_max;
265
	if (cur_y < 0) cur_y = 0;
265
	if (cur_y < 0) cur_y = 0;
266
	if (cur_x < 0) cur_x = 0;
266
	if (cur_x < 0) cur_x = 0;
267
}
267
}
268
 
268
 
269
:int llist::KeyRight()
269
:int llist::KeyRight()
270
{
270
{
271
	if (cur_x < column_max)
271
	if (cur_x < column_max)
272
	{
272
	{
273
		cur_x++;
273
		cur_x++;
274
	}
274
	}
275
	else 
275
	else 
276
	{
276
	{
277
		if (!KeyDown()) return 0;
277
		if (!KeyDown()) return 0;
278
		cur_x = 0;
278
		cur_x = 0;
279
	}
279
	}
280
	return 1;
280
	return 1;
281
}
281
}
282
 
282
 
283
:int llist::KeyLeft()
283
:int llist::KeyLeft()
284
{
284
{
285
	if (cur_x > 0)
285
	if (cur_x > 0)
286
	{
286
	{
287
		cur_x--;
287
		cur_x--;
288
	}
288
	}
289
	else 
289
	else 
290
	{
290
	{
291
		if (!KeyUp()) return 0;
291
		if (!KeyUp()) return 0;
292
		cur_x = column_max;
292
		cur_x = column_max;
293
	}
293
	}
294
	return 1;
294
	return 1;
295
}
295
}
296
 
296
 
297
 
297
 
298
:void llist_copy(dword dest, src)
298
:void llist_copy(dword dest, src)
299
{
299
{
300
	memmov(dest, src, sizeof(llist));
300
	memmov(dest, src, sizeof(llist));
301
	/*
301
	/*
302
	EDI = dest;
302
	EDI = dest;
303
	ESI = src;
303
	ESI = src;
304
	EDI.llist.x = ESI.llist.x;
304
	EDI.llist.x = ESI.llist.x;
305
	EDI.llist.y = ESI.llist.y;
305
	EDI.llist.y = ESI.llist.y;
306
	EDI.llist.w = ESI.llist.w;
306
	EDI.llist.w = ESI.llist.w;
307
	EDI.llist.h = ESI.llist.h;
307
	EDI.llist.h = ESI.llist.h;
308
	EDI.llist.item_h = ESI.llist.item_h;
308
	EDI.llist.item_h = ESI.llist.item_h;
309
	EDI.llist.text_y = ESI.llist.text_y;
309
	EDI.llist.text_y = ESI.llist.text_y;
310
	EDI.llist.font_w = ESI.llist.font_w;
310
	EDI.llist.font_w = ESI.llist.font_w;
311
	EDI.llist.font_h = ESI.llist.font_h;
311
	EDI.llist.font_h = ESI.llist.font_h;
312
	EDI.llist.font_type = ESI.llist.font_type;
312
	EDI.llist.font_type = ESI.llist.font_type;
313
	EDI.llist.count = ESI.llist.count;
313
	EDI.llist.count = ESI.llist.count;
314
	EDI.llist.visible = ESI.llist.visible;
314
	EDI.llist.visible = ESI.llist.visible;
315
	EDI.llist.first = ESI.llist.first;
315
	EDI.llist.first = ESI.llist.first;
316
	EDI.llist.cur_y = ESI.llist.cur_y;
316
	EDI.llist.cur_y = ESI.llist.cur_y;
317
	EDI.llist.column_max = ESI.llist.column_max;
317
	EDI.llist.column_max = ESI.llist.column_max;
318
	EDI.llist.active = ESI.llist.active;
318
	EDI.llist.active = ESI.llist.active;
319
	*/
319
	*/
320
}
320
}
321
 
321
 
322
#endif
322
#endif
323
>
323
>
324
>
324
>
325
>
325
>