Subversion Repositories Kolibri OS

Rev

Rev 7654 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 7654 Rev 7769
Line 16... Line 16...
16
#include "..\lib\collection.h"
16
#include "..\lib\collection.h"
Line 17... Line 17...
17
 
17
 
18
proc_info Form;
18
proc_info Form;
19
llist list;
19
llist list;
20
collection app_path_collection;
20
collection app_path_collection;
Line 21... Line 21...
21
byte kolibrios_mounted;
21
bool kolibrios_mounted;
22
 
22
 
Line 23... Line 23...
23
int window_width,
23
int window_width,
24
	window_height;
24
	window_height;
25
 
25
 
26
int list_pos, 
26
int list_pos, 
Line 27... Line 27...
27
	row,
27
	row,
28
	col,
28
	col,
Line 29... Line 29...
29
	default_icon;
29
	default_icon;
Line 30... Line 30...
30
 
30
 
31
char window_title[128],
31
char window_title[128],
Line 40... Line 40...
40
 	dword graph;
40
 	dword graph;
41
 	dword dark;
41
 	dword dark;
42
 	dword light;
42
 	dword light;
43
 } swc;
43
 } swc;
Line 44... Line 44...
44
 
44
 
Line 45... Line 45...
45
block ipos[128];
45
block selection[128];
46
 
46
 
47
void load_config()
-
 
-
 
47
void load_ini_config(dword _ini_path)
48
{
48
{
49
	ini_get_str stdcall (#settings_ini_path, "Config", "title", #window_title, sizeof(window_title), "Software widget");
49
	_ini ini;
50
	ini_get_int stdcall (#settings_ini_path, "Config", "win_width", 690);
50
	ini.path = _ini_path;
51
	window_width = EAX;
51
	ini.section = "Config";
52
	ini_get_int stdcall (#settings_ini_path, "Config", "cell_w", 73);
52
	ini.GetString("title", #window_title, sizeof(window_title), "Software widget");
53
	list.item_w = EAX;
53
	window_width = ini.GetInt("win_width", 690);
54
	ini_get_int stdcall (#settings_ini_path, "Config", "cell_h", 71);
54
	list.item_w  = ini.GetInt("cell_w", 73);
55
	list.item_h = EAX;
-
 
56
	ini_get_int stdcall (#settings_ini_path, "Config", "default_icon", 2);
55
	list.item_h  = ini.GetInt("cell_h", 71);
Line 57... Line -...
57
	default_icon = EAX;
-
 
58
}
56
	default_icon = ini.GetInt("default_icon", 2);
59
 
57
}
60
 
58
 
61
void main()
59
void main()
62
{   
60
{   
63
	dword id;
61
	dword id;
64
	kfont.init(DEFAULT_FONT);
62
	kfont.init(DEFAULT_FONT);
Line 65... Line 63...
65
	load_dll(libio,  #libio_init,1);
63
	load_dll(libio,  #libio_init,1);
Line 66... Line 64...
66
	load_dll(libimg, #libimg_init,1);
64
	load_dll(libimg, #libimg_init,1);
67
	load_dll(libini, #lib_init,1);
-
 
68
 
65
	load_dll(libini, #lib_init,1);
69
	kolibrios_mounted = dir_exists("/kolibrios");
-
 
70
 
66
 
71
	if (param)
-
 
-
 
67
	kolibrios_mounted = dir_exists("/kolibrios");
72
	{
68
 
73
		strcpy(#settings_ini_path, #param);
69
	if (param) {
74
	}
70
		strcpy(#settings_ini_path, #param);
Line 75... Line 71...
75
	else
71
	} else {
76
	{
72
		strcpy(#settings_ini_path, "/sys/settings/");
77
		strcat(#settings_ini_path, I_Path + strrchr(I_Path, '/'));
73
		strcat(#settings_ini_path, I_Path + strrchr(I_Path, '/'));
Line 78... Line 74...
78
		strcat(#settings_ini_path, ".ini");		
74
		strcat(#settings_ini_path, ".ini");		
79
	}
75
	}
Line 96... Line 92...
96
		case evKey:
92
		case evKey:
97
			GetKeys();
93
			GetKeys();
98
			if (SCAN_CODE_LEFT == key_scancode) key_scancode = SCAN_CODE_UP;
94
			if (SCAN_CODE_LEFT == key_scancode) key_scancode = SCAN_CODE_UP;
99
			if (SCAN_CODE_RIGHT == key_scancode) key_scancode = SCAN_CODE_DOWN;
95
			if (SCAN_CODE_RIGHT == key_scancode) key_scancode = SCAN_CODE_DOWN;
100
			if (list.ProcessKey(key_scancode)) DrawSelection();
96
			if (list.ProcessKey(key_scancode)) DrawSelection();
101
			if (SCAN_CODE_ENTER == key_scancode) EventRunApp(list.cur_y);
97
			if (SCAN_CODE_ENTER == key_scancode) EventIconClick(list.cur_y);
102
			break;
98
			break;
Line 103... Line 99...
103
 
99
 
104
		case evButton:
100
		case evButton:
105
			id=GetButtonID();               
101
			id=GetButtonID();               
106
			if (id==1) ExitProcess();
102
			if (id==1) ExitProcess();
107
			if (id>=100) EventRunApp(id-100);
103
			if (id>=100) EventIconClick(id-100);
Line 108... Line 104...
108
			break;
104
			break;
109
 
105
 
110
		case evReDraw:
106
		case evReDraw:
Line 118... Line 114...
118
			if (small_screen) {
114
			if (small_screen) {
119
				DrawTitle(#window_title);
115
				DrawTitle(#window_title);
120
				list.y = 0;	
116
				list.y = 0;	
121
			} else {
117
			} else {
122
				DrawTitle(NULL); 
118
				DrawTitle(NULL); 
123
				draw_top_bar();
119
				DrawTopBar();
124
			}
120
			}
125
			DrawList();
121
			DrawList();
126
			DrawBar(0, row +1 * list.item_h + list_pos, Form.cwidth, -row - 1 * list.item_h - list_pos + Form.cheight, swc.list_bg);
122
			DrawBar(0, row +1 * list.item_h + list_pos, Form.cwidth, -row - 1 * list.item_h - list_pos + Form.cheight, swc.list_bg);
127
			DrawSelection();
123
			DrawSelection();
128
	}
124
	}
Line 167... Line 163...
167
	list.visible = list.count;
163
	list.visible = list.count;
168
}
164
}
Line 169... Line 165...
169
 
165
 
170
byte draw_icons_from_section(dword key_value, key_name, sec_name, f_name)
166
byte draw_icons_from_section(dword key_value, key_name, sec_name, f_name)
171
{
-
 
172
	int tmp,
167
{
173
		icon_id,
168
	int icon_id = default_icon,
174
		icon_char_pos;
169
		icon_char_pos;
-
 
170
	int space_pos;
-
 
171
 
Line 175... Line 172...
175
	int text_w;
172
	dword icon_x, icon_y, text_x, text_y;
176
 
173
 
177
	//do not show items located in /kolibrios/ if this directory not mounted
174
	//do not show items located in /kolibrios/ if this directory not mounted
Line 182... Line 179...
182
		row++;
179
		row++;
183
		col=0;
180
		col=0;
184
	}
181
	}
Line 185... Line 182...
185
 
182
 
186
	if (col==0) DrawBar(0, row * list.item_h + list_pos, Form.cwidth, list.item_h, swc.list_bg);
183
	if (col==0) DrawBar(0, row * list.item_h + list_pos, Form.cwidth, list.item_h, swc.list_bg);
187
	DefineButton(col*list.item_w+6, row*list.item_h + list_pos,list.item_w,list.item_h-5,list.count + 100 + BT_HIDE,0);
-
 
Line 188... Line 184...
188
	tmp = list.item_w/2;
184
	DefineButton(col*list.item_w+6, row*list.item_h + list_pos,list.item_w,list.item_h-3,list.count + 100 + BT_HIDE,0);
189
 
185
 
190
	icon_char_pos = strchr(key_value, ',');
186
	icon_char_pos = strchr(key_value, ',');
-
 
187
	icon_x = col*list.item_w+calc(list.item_w/2)-10;
-
 
188
	icon_y = row*list.item_h+5 + list_pos;
191
	if (icon_char_pos) icon_id = atoi(icon_char_pos+1); else icon_id = default_icon;
189
	selection[list.count].x = icon_x-2;
192
	img_draw stdcall(skin.image, col*list.item_w+tmp-10, row*list.item_h+5 + list_pos, 32, 32, 0, icon_id*32);
190
	selection[list.count].y = icon_y-2;
-
 
191
	if (icon_char_pos) ESBYTE[icon_char_pos] = '\0'; //delete icon from string
-
 
192
	app_path_collection.add(key_value);
-
 
193
 
-
 
194
	text_x = col*list.item_w+5;
193
	if (icon_char_pos) ESBYTE[icon_char_pos] = '\0'; //delete icon from string
195
	text_y = list.item_h - 40 / 2;
-
 
196
	if (kfont.getsize(key_name)+30
-
 
197
		kfont.WriteIntoWindowCenter(text_x, row*list.item_h+46 + list_pos, list.item_w,0, swc.list_bg, swc.text, 12, key_name);
-
 
198
	} else {
194
	app_path_collection.add(key_value);
199
		space_pos = strrchr(key_name, ' ');
195
	//kfont.WriteIntoWindowCenter(col*list.item_w+7,row*list.item_h+47 + list_pos, list.item_w,0, swc.list_bg, swc.dark, 12, key_name);
200
		ESBYTE[key_name+space_pos-1] = '\0';
-
 
201
		kfont.WriteIntoWindowCenter(text_x, row*list.item_h+46 + list_pos - 2, list.item_w,0, swc.list_bg, swc.text, 12, key_name);
196
	text_w = kfont.WriteIntoWindowCenter(col*list.item_w+5,row*list.item_h+46 + list_pos, list.item_w,0, swc.list_bg, swc.text, 12, key_name);
202
		kfont.WriteIntoWindowCenter(text_x, row*list.item_h+46 + list_pos + 14, list.item_w,0, swc.list_bg, swc.text, 12, key_name+space_pos);
197
	ipos[list.count].x = list.item_w-text_w/2+calc(col*list.item_w)+5;
203
	}
198
	ipos[list.count].y = row*list.item_h+46 + list_pos + 16;
204
	if (icon_char_pos) icon_id = atoi(icon_char_pos+1);
199
	ipos[list.count].w = text_w;
205
	img_draw stdcall(skin.image, icon_x, icon_y, 32, 32, 0, icon_id*32);
200
	list.count++;
206
	list.count++;
201
	col++;
207
	col++;
Line 229... Line 235...
229
	}
235
	}
230
	ini_enum_keys stdcall (f_name, sec_name, #draw_icons_from_section);
236
	ini_enum_keys stdcall (f_name, sec_name, #draw_icons_from_section);
231
	return true;
237
	return true;
232
}
238
}
Line 233... Line 239...
233
 
239
 
234
void draw_top_bar()
240
void DrawTopBar()
235
{
241
{
236
	DrawBar(0,0,Form.cwidth, list.y-2, system.color.work);
242
	DrawBar(0,0,Form.cwidth, list.y-2, system.color.work);
237
	DrawBar(0,list.y-2, Form.cwidth, 1, MixColors(system.color.work, system.color.work_graph, 180));
243
	DrawBar(0,list.y-2, Form.cwidth, 1, MixColors(system.color.work, system.color.work_graph, 180));
238
	DrawBar(0,list.y-1, Form.cwidth, 1, system.color.work_graph);
244
	DrawBar(0,list.y-1, Form.cwidth, 1, system.color.work_graph);
239
	kfont.WriteIntoWindowCenter(0,5, Form.cwidth, list.y, system.color.work, system.color.work_text, 16, #window_title);
245
	kfont.WriteIntoWindowCenter(0,5, Form.cwidth, list.y, system.color.work, system.color.work_text, 16, #window_title);
Line 240... Line 246...
240
}
246
}
241
 
247
 
242
void EventRunApp(dword appid)
248
void EventIconClick(dword appid)
243
{
249
{
244
	char run_app_path[4096]=0;
250
	char run_app_path[4096]=0;
245
	dword app_path = app_path_collection.get(appid);
251
	dword app_path = app_path_collection.get(appid);
Line 262... Line 268...
262
		app_path+=3;
268
		app_path+=3;
263
	}
269
	}
264
	strcat(#run_app_path, app_path);
270
	strcat(#run_app_path, app_path);
265
	// }end
271
	// }end
Line 266... Line 272...
266
 
272
 
267
	if (file_exists(#run_app_path))
-
 
268
	{
273
	if (file_exists(#run_app_path)) {
269
		io.run(#run_app_path, param_pos); //0 or offset
274
		io.run(#run_app_path, param_pos); //0 or offset
270
		if (param_pos) ESBYTE[param_pos - 1] = '|';
-
 
271
	}
275
		if (param_pos) ESBYTE[param_pos - 1] = '|';
272
	else
-
 
273
	{
276
	} else {
274
		notify("'Application not found' -E");
277
		notify("'Application not found' -E");
275
	}
278
	}
Line 276... Line 279...
276
}
279
}
277
 
280
 
278
void DrawSelection()
281
void DrawSelection()
279
{
282
{
280
	int i;
283
	int i;
281
	dword col;
284
	dword col;
282
	for (i=0; i
285
	for (i=0; i
283
		if (i==list.cur_y) col=0x0080FF; else col=swc.list_bg;
286
		if (i==list.cur_y) col=0x0080FF; else col=swc.list_bg;
284
		DrawBar(ipos[i].x, ipos[i].y, ipos[i].w+2, 3, col);
287
		DrawWideRectangle(selection[i].x, selection[i].y, 36, 36, 2, col);
Line 285... Line 288...
285
	}
288
	}