Subversion Repositories Kolibri OS

Rev

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

Rev 8881 Rev 9602
1
#define MEMSIZE 4096*40
1
#define MEMSIZE 4096*40
2
 
2
 
3
#include "../lib/gui.h"
3
#include "../lib/gui.h"
4
#include "../lib/collection.h"
4
#include "../lib/collection.h"
5
#include "../lib/list_box.h"
5
#include "../lib/list_box.h"
6
#include "../lib/fs.h"
6
#include "../lib/fs.h"
7
 
7
 
8
#define ITEM_H 19
8
#define ITEM_H 19
9
#define SEP_H 4
9
#define SEP_H 4
10
 
10
 
11
llist menu1;
11
llist menu1;
12
collection names=0;
12
collection names=0;
13
collection hotkeys=0;
13
collection hotkeys=0;
14
 
14
 
15
int selected, win_x, win_y;
15
int selected, win_x, win_y;
16
 
16
 
17
int max_name_len;
17
int max_name_len;
18
int max_hotkey_len;
18
int max_hotkey_len;
19
int menu_w, menu_h;
19
int menu_w, menu_h;
20
 
20
 
21
void GetWindowPosition()
21
void GetWindowPosition()
22
{
22
{
23
	int position;
23
	int position;
24
	shared_mem = memopen(#shared_name, 16, SHM_OPEN + SHM_WRITE);
24
	shared_mem = memopen(#shared_name, 16, SHM_OPEN + SHM_WRITE);
25
	selected = ESDWORD[shared_mem     ];
25
	selected = ESDWORD[shared_mem     ];
26
	win_x    = ESDWORD[shared_mem +  4];
26
	win_x    = ESDWORD[shared_mem +  4];
27
	win_y    = ESDWORD[shared_mem +  8];
27
	win_y    = ESDWORD[shared_mem +  8];
28
	position = ESDWORD[shared_mem + 12];
28
	position = ESDWORD[shared_mem + 12];
29
	if (position == MENU_TOP_RIGHT) win_x -= menu1.w;
29
	if (position == MENU_TOP_RIGHT) win_x -= menu1.w;
30
	if (position == MENU_BOT_LEFT) win_y -= menu1.h;
30
	if (position == MENU_BOT_LEFT) win_y -= menu1.h;
31
	if (position == MENU_BOT_RIGHT) {
31
	if (position == MENU_BOT_RIGHT) {
32
		win_x -= menu1.w;
32
		win_x -= menu1.w;
33
		win_y -= menu1.h;
33
		win_y -= menu1.h;
34
	}
34
	}
35
}
35
}
36
 
36
 
37
void GetMenuWidths()
37
void GetMenuWidths()
38
{
38
{
39
	int i;
39
	int i;
40
	for (i=0; i
40
	for (i=0; i
41
		max_name_len = math.max(max_name_len, strlen(names.get(i)));
41
		max_name_len = math.max(max_name_len, strlen(names.get(i)));
42
	}
42
	}
43
	for (i=0; i
43
	for (i=0; i
44
		max_hotkey_len = math.max(max_hotkey_len, strlen(hotkeys.get(i)));
44
		max_hotkey_len = math.max(max_hotkey_len, strlen(hotkeys.get(i)));
45
	}
45
	}
46
	max_name_len = max_name_len * 6;
46
	max_name_len = max_name_len * 6;
47
	max_hotkey_len *= 6;
47
	max_hotkey_len *= 6;
48
	if (max_hotkey_len) max_name_len += 12;
48
	if (max_hotkey_len) max_name_len += 12;
49
}
49
}
50
 
50
 
51
void GetMenuItems(dword current_name)
51
void GetMenuItems(dword current_name)
52
{
52
{
53
	dword next_name = strchr(current_name, '\n');
53
	dword next_name = strchr(current_name, '\n');
54
	dword hotkey = strchr(current_name, '|');
54
	dword hotkey = strchr(current_name, '|');
55
 
55
 
56
	ESBYTE[next_name] = '\0';
56
	ESBYTE[next_name] = '\0';
57
 
57
 
58
	if (hotkey) && (hotkey < next_name) {
58
	if (hotkey) && (hotkey < next_name) {
59
		ESBYTE[hotkey] = '\0';
59
		ESBYTE[hotkey] = '\0';
60
	} else {
60
	} else {
61
		if (hotkey) && (!next_name) {
61
		if (hotkey) && (!next_name) {
62
			ESBYTE[hotkey] = '\0';
62
			ESBYTE[hotkey] = '\0';
63
		} else {
63
		} else {
64
			hotkey = " ";
64
			hotkey = " ";
65
		}
65
		}
66
	}
66
	}
67
 
67
 
68
	hotkeys.add(hotkey+1);
68
	hotkeys.add(hotkey+1);
69
	names.add(current_name);
69
	names.add(current_name);
70
 
70
 
71
	if (next_name) GetMenuItems(next_name+2);
71
	if (next_name) GetMenuItems(next_name+2);
72
}
72
}
73
 
73
 
74
int GetSeparatorsCount()
74
int GetSeparatorsCount()
75
{
75
{
76
	int i, count=0;
76
	int i, count=0;
77
	for (i=0; i
77
	for (i=0; i
78
		if (streq(names.get(i), "-")) count++;
78
		if (streq(names.get(i), "-")) count++;
79
	}
79
	}
80
	return count;
80
	return count;
81
}
81
}
82
 
82
 
83
int MoveMouseToHandleSeparators(int _mouse_y)
83
int MoveMouseToHandleSeparators(int _mouse_y)
84
{
84
{
85
	int i, item_y=menu1.y;
85
	int i, item_y=menu1.y;
86
	int item_i=0;
86
	int item_i=0;
87
	for (i=0; i
87
	for (i=0; i
88
	{
88
	{
89
		if (streq(names.get(i), "-")) {
89
		if (streq(names.get(i), "-")) {
90
			item_y += SEP_H;
90
			item_y += SEP_H;
91
		} else {
91
		} else {
92
			item_y += ITEM_H;
92
			item_y += ITEM_H;
93
			item_i++;
93
			item_i++;
94
		}
94
		}
95
		if (_mouse_y >= item_y) && (_mouse_y < item_y + ITEM_H) {
95
		if (_mouse_y >= item_y) && (_mouse_y < item_y + ITEM_H) {
96
			return item_i * ITEM_H + menu1.y;
96
			return item_i * ITEM_H + menu1.y;
97
		}
97
		}
98
	}
98
	}
99
	return _mouse_y;
99
	return _mouse_y;
100
}
100
}
101
 
101
 
102
void main()
102
void main()
103
{
103
{
104
	proc_info Form;
104
	proc_info Form;
105
 
105
 
106
	if (!param) RunProgram("/sys/network/WebView", "http://board.kolibrios.org/viewtopic.php?f=24&t=4233#p74599");
106
	if (!param) RunProgram("/sys/network/WebView", "http://board.kolibrios.org/viewtopic.php?f=24&t=4233#p74599");
107
 
107
 
108
	GetMenuItems(#param);
108
	GetMenuItems(#param);
109
	GetMenuWidths();
109
	GetMenuWidths();
110
 
110
 
111
	menu_w = max_name_len + max_hotkey_len + 23;
111
	menu_w = max_name_len + max_hotkey_len + 23;
112
	menu_h = GetSeparatorsCount() * SEP_H 
112
	menu_h = GetSeparatorsCount() * SEP_H 
113
		+ calc(names.count - GetSeparatorsCount() * ITEM_H);
113
		+ calc(names.count - GetSeparatorsCount() * ITEM_H);
114
 
114
 
115
	menu1.count = names.count;
115
	menu1.count = names.count;
116
	menu1.SetFont(6, 9, 0x80);
116
	menu1.SetFont(6, 9, 0x80);
117
	menu1.SetSizes(2,2, menu_w, menu_h, ITEM_H);
117
	menu1.SetSizes(2,2, menu_w, menu_h, ITEM_H);
118
	menu1.cur_y = -1;
118
	menu1.cur_y = -1;
119
 
119
 
120
	GetWindowPosition();
120
	GetWindowPosition();
121
 
121
 
122
	@SetEventMask(EVM_REDRAW + EVM_KEY + EVM_BUTTON + EVM_MOUSE);
122
	@SetEventMask(EVM_REDRAW + EVM_KEY + EVM_BUTTON + EVM_MOUSE);
123
	loop() switch(WaitEvent())
123
	loop() switch(WaitEvent())
124
	{
124
	{
125
		case evMouse:			
125
		case evMouse:			
126
			GetProcessInfo(#Form, SelfInfo);
126
			GetProcessInfo(#Form, SelfInfo);
127
			if (!CheckActiveProcess(Form.ID)) exit();
127
			if (!CheckActiveProcess(Form.ID)) exit();
128
			mouse.get();
128
			mouse.get();
129
			if (menu1.MouseOver(mouse.x, mouse.y)) {
129
			if (menu1.MouseOver(mouse.x, mouse.y)) {
130
				mouse.y = MoveMouseToHandleSeparators(mouse.y);
130
				mouse.y = MoveMouseToHandleSeparators(mouse.y);
131
				if (menu1.ProcessMouse(mouse.x, mouse.y)) draw_list();
131
				if (menu1.ProcessMouse(mouse.x, mouse.y)) draw_list();
132
				if (mouse.lkm)&&(mouse.up) click();	
132
				if (mouse.lkm)&&(mouse.up) click();	
133
			} 
133
			} 
134
			break;
134
			break;
135
 
135
 
136
		case evKey:
136
		case evKey:
137
			ProcessKeys();
137
			ProcessKeys();
138
			break;
138
			break;
139
 
139
 
140
		case evReDraw:
140
		case evReDraw:
141
			DefineAndDrawWindow(win_x, win_y, menu1.w+4, menu1.h+4, 0x01, 0, 0, 0x01fffFFF);
141
			DefineAndDrawWindow(win_x, win_y, menu1.w+4, menu1.h+4, 0x01, 0, 0, 0x01fffFFF);
142
			sc.get();
142
			sc.get();
143
			Draw3DPopup(0,0,menu1.w+2,menu1.h+2);
143
			Draw3DPopup(0,0,menu1.w+2,menu1.h+2);
144
			draw_list();
144
			draw_list();
145
	}
145
	}
146
}
146
}
147
 
147
 
148
void CorrectLastItem()
148
void CorrectLastItem()
149
{
149
{
150
	if (menu1.cur_y > menu1.count - GetSeparatorsCount() - 1) {
150
	if (menu1.cur_y > menu1.count - GetSeparatorsCount() - 1) {
151
		menu1.cur_y = menu1.count - GetSeparatorsCount() - 1;
151
		menu1.cur_y = menu1.count - GetSeparatorsCount() - 1;
152
	}
152
	}
153
}
153
}
154
 
154
 
155
inline ProcessKeys()
155
inline ProcessKeys()
156
{
156
{
157
	@GetKeyScancode();
157
	@GetKeyScancode();
158
	switch(AL) 
158
	switch(AL) 
159
	{
159
	{
160
		case SCAN_CODE_ESC:
160
		case SCAN_CODE_ESC:
161
			exit();
161
			exit();
162
 
162
 
163
		case SCAN_CODE_ENTER:
163
		case SCAN_CODE_ENTER:
164
			click();
164
			click();
165
 
165
 
166
		case SCAN_CODE_DOWN:
166
		case SCAN_CODE_DOWN:
167
			if (!menu1.KeyDown()) 
167
			if (!menu1.KeyDown()) 
168
			|| (menu1.count - menu1.cur_y - GetSeparatorsCount() -1 < 0) menu1.KeyHome();
168
			|| (menu1.count - menu1.cur_y - GetSeparatorsCount() -1 < 0) menu1.KeyHome();
169
			draw_list();
169
			draw_list();
170
			break;
170
			break;
171
 
171
 
172
		case SCAN_CODE_UP:
172
		case SCAN_CODE_UP:
173
			if (!menu1.KeyUp()) {
173
			if (!menu1.KeyUp()) {
174
				menu1.KeyEnd();
174
				menu1.KeyEnd();
175
				CorrectLastItem();
175
				CorrectLastItem();
176
			}
176
			}
177
			draw_list();
177
			draw_list();
178
			break;
178
			break;
179
 
179
 
180
		case SCAN_CODE_END:
180
		case SCAN_CODE_END:
181
			menu1.KeyEnd();
181
			menu1.KeyEnd();
182
			CorrectLastItem();
182
			CorrectLastItem();
183
			draw_list();
183
			draw_list();
184
			break;			
184
			break;			
185
 
185
 
186
		default:
186
		default:
187
			if (menu1.ProcessKey(AL)) draw_list();
187
			if (menu1.ProcessKey(AL)) draw_list();
188
	}
188
	}
189
}
189
}
190
 
190
 
191
void draw_list()
191
void draw_list()
192
{
192
{
193
	int i, item_y=menu1.y, item_i=0;
193
	int i, item_y=menu1.y, item_i=0;
194
	dword name_color;
194
	dword name_color;
195
	dword hotkey_color;
195
	dword hotkey_color;
196
 
196
 
197
	static dword inactive_background_color;
197
	static dword inactive_background_color;
198
	static dword active_background_color;
198
	static dword active_background_color;
199
	static dword active_top_border_color;
199
	static dword active_top_border_color;
200
	static dword inactive_text_shadow_color;
200
	static dword inactive_text_shadow_color;
201
	static bool skin_dark;
201
	static bool skin_dark;
202
 
202
 
203
	static bool colors_set;
203
	static bool colors_set;
204
	if (!colors_set) {
204
	if (!colors_set) {
205
		colors_set = true;
205
		colors_set = true;
206
		inactive_background_color = MixColors(sc.work, 0xFFFfff,230);
206
		inactive_background_color = MixColors(sc.work, 0xFFFfff,230);
207
		active_background_color = MixColors(sc.button, sc.work,230);
207
		active_background_color = MixColors(sc.button, sc.work,230);
208
		active_top_border_color = MixColors(sc.work_graph, sc.button,240);
208
		active_top_border_color = MixColors(sc.line, sc.button,240);
209
		inactive_text_shadow_color = MixColors(sc.work,0xFFFfff,120);
209
		inactive_text_shadow_color = MixColors(sc.work,0xFFFfff,120);
210
		skin_dark = skin_is_dark();
210
		skin_dark = skin_is_dark();
211
	}
211
	}
212
 
212
 
213
	for (i=0; i
213
	for (i=0; i
214
	{
214
	{
215
		if (streq(names.get(i), "-")) {
215
		if (streq(names.get(i), "-")) {
216
			DrawBar(menu1.x, item_y+0, menu1.w, 1, inactive_background_color);
216
			DrawBar(menu1.x, item_y+0, menu1.w, 1, inactive_background_color);
217
			DrawBar(menu1.x-1, item_y+1, menu1.w+1, 1, sc.work_dark);
217
			DrawBar(menu1.x-1, item_y+1, menu1.w+1, 1, sc.dark);
218
			DrawBar(menu1.x, item_y+2, menu1.w, 1, sc.work_light);
218
			DrawBar(menu1.x, item_y+2, menu1.w, 1, sc.light);
219
			DrawBar(menu1.x, item_y+3, menu1.w, 1, inactive_background_color);
219
			DrawBar(menu1.x, item_y+3, menu1.w, 1, inactive_background_color);
220
			//DrawBar(menu1.x, item_y+0, menu1.w, 4, inactive_background_color);
220
			//DrawBar(menu1.x, item_y+0, menu1.w, 4, inactive_background_color);
221
			//DrawBar(13, item_y+1, menu1.w-24, 1, sc.work_dark);
221
			//DrawBar(13, item_y+1, menu1.w-24, 1, sc.dark);
222
			//DrawBar(13, item_y+2, menu1.w-24, 1, sc.work_light);
222
			//DrawBar(13, item_y+2, menu1.w-24, 1, sc.light);
223
			item_y += SEP_H;
223
			item_y += SEP_H;
224
		} else {
224
		} else {
225
			if (item_i==menu1.cur_y) {
225
			if (item_i==menu1.cur_y) {
226
				hotkey_color = name_color = sc.button_text;
226
				hotkey_color = name_color = sc.button_text;
227
				DrawBar(menu1.x, item_y+1,        menu1.w, ITEM_H-2, active_background_color);
227
				DrawBar(menu1.x, item_y+1,        menu1.w, ITEM_H-2, active_background_color);
228
				DrawBar(menu1.x, item_y,          menu1.w, 1, active_top_border_color);
228
				DrawBar(menu1.x, item_y,          menu1.w, 1, active_top_border_color);
229
				DrawBar(menu1.x, item_y+ITEM_H-1, menu1.w, 1, sc.work_light);
229
				DrawBar(menu1.x, item_y+ITEM_H-1, menu1.w, 1, sc.light);
230
			} else {
230
			} else {
231
				name_color = sc.work_text;
231
				name_color = sc.work_text;
232
				hotkey_color = sc.work_graph;
232
				hotkey_color = sc.line;
233
				DrawBar(menu1.x, item_y, menu1.w, ITEM_H, inactive_background_color);
233
				DrawBar(menu1.x, item_y, menu1.w, ITEM_H, inactive_background_color);
234
				if (!skin_dark) WriteText(13+1, item_y + menu1.text_y +1, 0x80, 
234
				if (!skin_dark) WriteText(13+1, item_y + menu1.text_y +1, 0x80, 
235
					inactive_text_shadow_color, names.get(i));
235
					inactive_text_shadow_color, names.get(i));
236
			}
236
			}
237
			WriteText(-strlen(hotkeys.get(i))*6 + 13 + max_name_len + max_hotkey_len, 
237
			WriteText(-strlen(hotkeys.get(i))*6 + 13 + max_name_len + max_hotkey_len, 
238
				item_y + menu1.text_y, 0x80, hotkey_color, hotkeys.get(i));
238
				item_y + menu1.text_y, 0x80, hotkey_color, hotkeys.get(i));
239
			WriteText(13, item_y + menu1.text_y, 0x80, name_color, names.get(i));
239
			WriteText(13, item_y + menu1.text_y, 0x80, name_color, names.get(i));
240
			item_y += ITEM_H;
240
			item_y += ITEM_H;
241
			item_i++;		
241
			item_i++;		
242
		}
242
		}
243
	}
243
	}
244
	if (selected) WriteText(5, selected-1*ITEM_H + menu1.y + menu1.text_y, 0x80, 0xEE0000, "\x10");
244
	if (selected) WriteText(5, selected-1*ITEM_H + menu1.y + menu1.text_y, 0x80, 0xEE0000, "\x10");
245
}
245
}
246
 
246
 
247
void click()
247
void click()
248
{
248
{
249
	ESDWORD[shared_mem] = menu1.cur_y + 1;
249
	ESDWORD[shared_mem] = menu1.cur_y + 1;
250
	ExitProcess();
250
	ExitProcess();
251
}
251
}
252
 
252
 
253
void exit()
253
void exit()
254
{
254
{
255
	ESDWORD[shared_mem] = 0;
255
	ESDWORD[shared_mem] = 0;
256
	ExitProcess();
256
	ExitProcess();
257
}
257
}