Subversion Repositories Kolibri OS

Rev

Rev 7422 | Rev 7507 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
5674 pavelyakov 1
/////////////////////////////////////////////////////////////////////////////////////////
2
 /////////////////////////                   GUI                      ////////////////////
5482 leency 3
/////////////////////////////////////////////////////////////////////////////////////////
4
 
5499 leency 5
#include "..\lib\gui.h"
6
#include "..\lib\obj\box_lib.h"
3067 leency 7
 
8
#ifdef LANG_RUS
7422 leency 9
?define T_ADD_DISK " Добавить диск [Ins]"
10
?define T_DELETE_DISK " Удалить диск [Del]"
11
?define INTRO_TEXT_1 "Здесь будет отображаться список"
12
?define INTRO_TEXT_2 "виртуальных дисков в системе."
13
?define INTRO_TEXT_3 "Попробуйте добавить один..."
14
?define SIZE_TEXT "Размер:"
15
?define NOTIFY_TEXT_NO_DISK    "'Для начала добавьте хотя бы один диск' -W"
16
?define NOTIFY_SYSTEM_DISK0    "'Диск с номером 0 является системным и удалять его не рекомендуется.
17
В случае, если вы точно знаете, что делаете, удалить его можно с зажатой клавишей SHIFT.' -W"
18
?define NOTIFY_TEXT_DISK_LIMIT "'Достигнут предел количества виртуальных дисков' -W"
19
?define FREE_RAM_TEXT "Размер свободной оперативной памяти: "
3067 leency 20
 
21
#else
7422 leency 22
?define T_ADD_DISK " Add disk [Ins]"
23
?define T_DELETE_DISK " Delete disk [Del]"
24
?define INTRO_TEXT_1 " There will be list of mounted"
25
?define INTRO_TEXT_2 " virtual disks."
26
?define INTRO_TEXT_3 " Try to add one..."
27
?define SIZE_TEXT "Size:"
28
?define NOTIFY_TEXT_NO_DISK    "'You need to have at least one disk' -W"
29
?define NOTIFY_SYSTEM_DISK0    "'Disc number 0 is a system disk. It is not recommended to delete it.
30
In case when you know what you are doing you can delete it with the SHIFT key pressed.' -W"
31
?define NOTIFY_TEXT_DISK_LIMIT "'Reached the limit of the number of virtual disks' -W"
32
?define FREE_RAM_TEXT "Free RAM size: "
3067 leency 33
#endif
34
 
5482 leency 35
struct path_string { unsigned char Item[10]; };
36
path_string disk_list[10];
3067 leency 37
 
38
dword devbuf;
5482 leency 39
char disk_num;
40
char selected;
3067 leency 41
 
42
proc_info Form;
43
 
5482 leency 44
unsigned char icons[] = FROM "icons.raw";
6678 leency 45
#define TOPPANELH 68
46
#define BOTPANELH 26
3067 leency 47
 
7506 leency 48
char new_disk_size[7];
7252 leency 49
edit_box edit_disk_size= {50,0,7,0xffffff,0x94AECE,0xFFFfff,0xffffff,0x10000000,
7506 leency 50
	sizeof(new_disk_size)-2,#new_disk_size,0, ed_focus+ed_figure_only};
3067 leency 51
 
52
void Main_Window()
53
{
6640 leency 54
	word id;
6678 leency 55
	int x;
56
 
5626 leency 57
	load_dll(boxlib, #box_lib_init,0);
4041 punk_joker 58
	GetSizeDisk();
6193 leency 59
	edit_disk_size.left = strlen(SIZE_TEXT)*9 + 10;
3866 punk_joker 60
	SetEventMask(0x27);
3067 leency 61
	loop()
62
	{
63
		switch(WaitEvent())
64
		{
3866 punk_joker 65
		case evMouse:
4425 leency 66
			if (!CheckActiveProcess(Form.ID)) break;
3866 punk_joker 67
			edit_box_mouse stdcall (#edit_disk_size);
68
			break;
69
 
3067 leency 70
		case evButton:
5482 leency 71
			id=GetButtonID();
72
			if (id==1) return;
3067 leency 73
			if (id==10) AddDisk();
7422 leency 74
			if (id==11) {
75
				GetKeys();
76
				DelDisk();
77
			}
3067 leency 78
			if (id>=20)
79
			{
80
				if (selected==id-20) OpenTmpDisk();
81
				selected=id-20;
82
				DrawTmpDisks();
83
			}
84
            break;
85
        case evKey:
6640 leency 86
			GetKeys();
87
			// PROCESS KEYS WHEN EDIT BOX INACTIVE
88
			if ( !asm test edit_disk_size.flags, 2)	switch(key_scancode)
3067 leency 89
			{
6640 leency 90
				case SCAN_CODE_TAB:
91
					edit_disk_size.flags=1000000000000010b;
5482 leency 92
					edit_box_draw stdcall (#edit_disk_size);
6640 leency 93
					DrawTmpDisks();
5482 leency 94
					break;
6640 leency 95
				case SCAN_CODE_UP:
5482 leency 96
					if (selected==0) break;
97
					selected--;
98
					DrawTmpDisks();
99
					break;
6640 leency 100
				case SCAN_CODE_DOWN:
5482 leency 101
					if (selected+2>disk_num) break;
102
					selected++;
103
					DrawTmpDisks();
104
					break;
6640 leency 105
				case SCAN_CODE_LEFT:
5482 leency 106
					if (selected<3) break;
107
					selected-=3;
108
					DrawTmpDisks();
109
					break;
6640 leency 110
				case SCAN_CODE_RIGHT:
5482 leency 111
					if (selected+4>disk_num) break;
112
					selected+=3;
113
					DrawTmpDisks();
6640 leency 114
					break;
115
				case SCAN_CODE_INS:
116
					AddDisk();
5482 leency 117
					break;
6640 leency 118
				case SCAN_CODE_DEL:
7422 leency 119
					DelDisk();
6640 leency 120
					break;
121
				case SCAN_CODE_ENTER:
122
					OpenTmpDisk();
123
					break;
3067 leency 124
			}
6640 leency 125
			// PROCESS KEYS WHEN EDIT BOX ACTIVE
126
			else switch(key_scancode)
127
			{
128
				case SCAN_CODE_TAB:
129
					edit_disk_size.flags=1000000000000000b;
130
					edit_box_draw stdcall (#edit_disk_size);
131
					DrawTmpDisks();
132
					break;
133
				case SCAN_CODE_ENTER:
134
				case SCAN_CODE_INS:
135
					AddDisk();
136
					break;
137
				default:
138
					EAX = key_editbox;
139
					edit_box_key stdcall(#edit_disk_size);
140
					break;
141
			}
3067 leency 142
			break;
3306 leency 143
         case evReDraw:
5674 pavelyakov 144
			system.color.get();
7422 leency 145
			DefineAndDrawWindow(170,150,405,290,0x74,system.color.work,"Virtual Disk Manager 0.67a",0);
3306 leency 146
			GetProcessInfo(#Form, SelfInfo);
3907 0CodErr 147
			if (Form.status_window>2) break;
3306 leency 148
 
5674 pavelyakov 149
			DrawBar(0,0,  Form.cwidth,TOPPANELH, system.color.work);
150
			DrawBar(0,TOPPANELH, Form.cwidth,1,  system.color.work_graph);
6678 leency 151
			WriteText(6, 9, 0x90, system.color.work_text, SIZE_TEXT);
152
			WriteText(edit_disk_size.left + edit_disk_size.width + 12, 9, 0x90, system.color.work_text, "MB.");
6278 leency 153
			DrawEditBox(#edit_disk_size);
6678 leency 154
			x = 6;
155
			x = 6 + DrawStandartCaptButton(6, 36, 10, T_ADD_DISK);
156
			DrawStandartCaptButton(x, 36, 11, T_DELETE_DISK);
157
			_PutImage(6+6, 42,  14,14,   #icons);
158
			_PutImage(x+6, 42,  14,14,   1*14*14*3+#icons);
3306 leency 159
			GetDisks();
160
			DrawTmpDisks();
3067 leency 161
		}
162
	}
163
}
164
 
5482 leency 165
 
4041 punk_joker 166
void GetSizeDisk()
167
{
168
	int fr;
6278 leency 169
	fr = GetFreeRAM() / 5 * 2;
4041 punk_joker 170
	fr = itoa(fr / 2048);
5482 leency 171
	strcpy(#new_disk_size, fr);
7506 leency 172
	EditBox_UpdateText(#edit_disk_size, edit_disk_size.flags);
4041 punk_joker 173
	edit_box_draw stdcall (#edit_disk_size);
174
}
3067 leency 175
 
5482 leency 176
 
3067 leency 177
void OpenTmpDisk()
178
{
5482 leency 179
	unsigned char eol_param[10];
3067 leency 180
	if (!disk_num) return;
181
	strcpy(#eol_param, "/tmp#/1/");
5482 leency 182
	eol_param[4] = disk_list[selected].Item[3];
3067 leency 183
	RunProgram("/sys/File managers/Eolite", #eol_param);
184
}
185
 
186
 
187
void GetDisks()
188
{
189
	unsigned int j, fcount=30;
5482 leency 190
	unsigned char disk_name[10];
3067 leency 191
 
192
	mem_Free(devbuf);
193
	devbuf= mem_Alloc(32);
194
	ReadDir(0, devbuf, "/");
195
	fcount=ESDWORD[devbuf+8];
196
	mem_Free(devbuf);
197
	devbuf = mem_Alloc(fcount+1*304+32);
198
	ReadDir(fcount, devbuf, "/");
199
 
200
	disk_num=0;
201
	for (j=0; j
202
	{
203
		strcpy(#disk_name, j*304+devbuf+72);
204
		if (disk_name[0]!='t') continue;
205
		strcpy(#disk_list[disk_num].Item, #disk_name);
206
		disk_num++;
207
	}
208
	if (disk_num>12) disk_num=12;
209
}
210
 
211
 
6678 leency 212
unsigned int disk_pos_x[]={13,13,13,102,102,102,191,191,191,279,279,279};
213
unsigned int disk_pos_y[]={79,127,175, 79,127,175, 79,127,175, 79,127,175};
3067 leency 214
 
215
void DrawTmpDisks()
216
{
6640 leency 217
	dword selection_color;
218
	dword selection_active = 0x0080FF;
219
	dword selection_inactive = 0x757489;
3975 leency 220
	char free_ram_text[60];
5484 leency 221
	byte i, real_id;
5482 leency 222
	int FreeRAM=GetFreeRAM()/1024;
223
 
6193 leency 224
	DrawBar(0,TOPPANELH+1, Form.cwidth,Form.cheight-TOPPANELH-BOTPANELH-2, 0xFFFFFF);
5674 pavelyakov 225
	DrawBar(0,Form.cheight-BOTPANELH-1, Form.cwidth,1, system.color.work_graph);
226
	DrawBar(0,Form.cheight-BOTPANELH, Form.cwidth,BOTPANELH, system.color.work);
6678 leency 227
	sprintf(#free_ram_text, "%s%i MB", FREE_RAM_TEXT, FreeRAM);
228
	WriteText(10, Form.cheight-20, 0x90, system.color.work_text, #free_ram_text);
3067 leency 229
	if (disk_num==0)
230
	{
6678 leency 231
		WriteText(17,TOPPANELH+15,    0x90, 0x777777, INTRO_TEXT_1);
232
		WriteText(17,TOPPANELH+15+15, 0x90, 0x777777, INTRO_TEXT_2);
233
		WriteText(17,TOPPANELH+15+42, 0x90, 0x777777, INTRO_TEXT_3);
3067 leency 234
		return;
235
	};
3306 leency 236
	if (selected>=disk_num) selected=disk_num-1; //restore selected
3067 leency 237
	for (i=0; i<10; i++) DeleteButton(20+i);
238
	for (i=0; i
239
	{
6678 leency 240
		DefineButton(disk_pos_x[i], disk_pos_y[i], 80, 40, 20+i, 0xFFFfff);
241
		WriteText(disk_pos_x[i]+26,disk_pos_y[i]+6,  10110000b, 0x222222, #disk_list[i].Item);
5484 leency 242
		real_id = disk_list[i].Item[3] - '0';
6678 leency 243
		WriteText(disk_pos_x[i]+27,disk_pos_y[i]+24, 0x80, 0x555555, ConvertSize(disk_sizes[real_id]));
244
		_PutImage(disk_pos_x[i]+6,disk_pos_y[i]+6, 14,14, 2*14*14*3+#icons);
6047 leency 245
		if (selected==i) {
7506 leency 246
			if ( edit_disk_size.flags & ed_focus) selection_color = selection_inactive; else selection_color = selection_active;
6678 leency 247
			DrawWideRectangle(disk_pos_x[i], disk_pos_y[i], 80, 40, 2, selection_color);
6047 leency 248
			PutPixel(disk_pos_x[i], disk_pos_y[i], 0xFFFfff);
249
		}
3067 leency 250
	}
251
}
252
 
5482 leency 253
 
3067 leency 254
void AddDisk()
255
{
5482 leency 256
	byte i, j, err;
3067 leency 257
	if (disk_num>=10)
258
	{
259
		notify(NOTIFY_TEXT_DISK_LIMIT);
260
		return;
261
	}
3866 punk_joker 262
 
3067 leency 263
	param[0]='a';
264
	for (i=0; i<9; i++)
265
	{
266
		for (j=0; j<=disk_num; j++)
267
		{
268
			if (i+48==disk_list[j].Item[3]) continue 1;
269
		}
270
		break;
271
	}
3866 punk_joker 272
 
3067 leency 273
	param[1]=i+48;
3866 punk_joker 274
	param[2]='s';
275
	param[3]='\0';
5482 leency 276
	strcat(#param, #new_disk_size);
3306 leency 277
	err = Console_Work();
278
	if ((err!=0) && (err<7)) notify(rezult_text[err]);
3081 leency 279
	pause(5);
3067 leency 280
	GetDisks();
281
	DrawTmpDisks();
4041 punk_joker 282
	GetSizeDisk();
3067 leency 283
}
284
 
285
 
5482 leency 286
void DelDisk()
287
{
288
	byte err;
289
	if (disk_num==0)
290
	{
291
		notify(NOTIFY_TEXT_NO_DISK);
292
		return;
293
	}
7422 leency 294
	if (disk_list[selected].Item[3]=='0') && (! key_modifier & KEY_LSHIFT) && (! key_modifier & KEY_RSHIFT)
295
	{
296
		notify(NOTIFY_SYSTEM_DISK0);
297
		return;
298
	}
5482 leency 299
	param[0]='d';
300
	param[1]=disk_list[selected].Item[3];
301
	err = byte Console_Work();
302
	if ((err!=0) && (err<7)) notify(rezult_text[err]);
303
	pause(15);
304
	GetDisks();
305
	DrawTmpDisks();
306
}
3067 leency 307