Subversion Repositories Kolibri OS

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
5612 punk_joker 1
#define MEMSIZE 0x100000
2
#include "..\lib\kolibri.h"
3
#include "..\lib\strings.h"
4
#include "..\lib\mem.h"
5
#include "..\lib\file_system.h"
6
#include "..\lib\dll.h"
7
#include "..\lib\gui.h"
8
#include "..\lib\obj\box_lib.h"
9
#include "..\lib\obj\proc_lib.h"
10
#include "..\lib\obj\libio_lib.h"
11
 
12
#include "lang.h--"
13
 
14
#ifdef LANG_RUS
15
	?define T_FILE "Файл"
16
	?define T_TYPE "Тип"
17
	?define T_SIZE "Размер"
18
	?define MENU1 "Файл"
19
	?define MENU1_SUBMENU1 "Открыть"
20
	?define MENU1_SUBMENU2 "Закрыть"
21
	?define MENU1_SUBMENU3 "Свойства"
22
	?define MENU1_SUBMENU4 "Выход"
23
	?define ERROR_LOAD_BOX_LIB "Ошибка при загрузке библиотеки - box_lib.obj"
24
	?define ERROR_LOAD_LIBIO "Ошибка при загрузке библиотеки - libio.obj"
25
	?define ERROR_LOAD_PROC_LIB "Ошибка при загрузке библиотеки - proc_lib.obj"
26
#else
27
	?define T_FILE "File"
28
	?define T_TYPE "Type"
29
	?define T_SIZE "Size"
30
	?define MENU1 "File"
31
	?define MENU1_SUBMENU1 "Open"
32
	?define MENU1_SUBMENU2 "Close"
33
	?define MENU1_SUBMENU3 "Properties"
34
	?define MENU1_SUBMENU4 "Exit"
35
	?define ERROR_LOAD_BOX_LIB "Error while loading library - box_lib.obj"
36
	?define ERROR_LOAD_LIBIO "Error while loading library - libio.obj"
37
	?define ERROR_LOAD_PROC_LIB "Error while loading library - proc_lib.obj"
38
#endif
39
 
40
#ifdef LANG_RUS
41
struct menu_text_struct
42
{
43
	char menu[5];
44
	char sub_menu1[8];
45
	char sub_menu2[8];
46
	//char sub_menu3[9];
47
	char sub_menu4[6];
48
	byte end;
49
};
50
#else
51
struct menu_text_struct
52
{
53
	char menu[5];
54
	char sub_menu1[5];
55
	char sub_menu2[6];
56
	//char sub_menu3[11];
57
	char sub_menu4[5];
58
	byte end;
59
};
60
#endif
61
 
62
#define TITLE "Calypte v0.1"
63
 
64
#define TOPPANELH 19
65
#define BOTPANELH 10
66
#define WIN_W 600
67
#define WIN_H 400
68
 
69
proc_info Form;
70
system_colors sc;
71
 
72
byte active_properties = 0;
73
dword properties_window;
74
 
75
#include "include\gui.h"
76
#include "include\properties.h"
77
 
78
struct filter
79
{
80
	dword size;
81
	char ext1[4];
82
	//char ext2[4];
83
	//char ext3[4];
84
	//char ext4[4];
85
	byte end;
86
};
87
 
88
filter filter2;
89
menu_text_struct menu_text_area1;
90
 
91
char win_title[4096] = "Calypte v0.1";
92
 
93
int
94
	cur_row=0,
95
	read=0,
96
	pos=0,
97
	row_num=0,
98
	col_count=0,
99
	row_count=0;
100
 
101
dword old_width,old_height;
102
 
103
proc_info pr_inf;
104
char communication_area_name[] = "FFFFFFFF_open_dialog";
105
byte plugin_path[4096];
106
char default_dir[] = "/rd/1";
107
char open_dialog_path[] = "/rd/1/File managers/opendial"; //opendial
108
byte openfile_path[2048];
109
byte filename_area[4096];
110
 
111
opendialog o_dialog = {0, #pr_inf, #communication_area_name, 0, #plugin_path, #default_dir, #open_dialog_path, #draw_window, 0, #openfile_path, #filename_area, #filter2, 420, 200, 320, 120};
112
 
113
dword bufpointer;
114
dword bufsize;
115
dword draw_sruct;
116
 
117
menu_data menudata1 = {0, 40, 2, 15, 2, #menu_text_area1.menu, #menu_text_area1.sub_menu1, #menu_text_area1.end, 0, 0, 80, 2, 100, 18, 0xEEEEEE, 0xFF, 0xEEEEEE, 0, 0, 0, #Form, 0, 0, 0, 16, 0, 0, 0x00CC00, 0, 0xFFFFFF, 0, 8, 0, 0};
118
 
119
void main()
120
{
121
	int id, key;
122
 
123
	strcpy(#filter2.ext1, "TXT");
124
	//strcpy(#filter2.ext2, "ASM");
125
	//strcpy(#filter2.ext3, "INC\0");
126
	//strcpy(#filter2.ext4, "\0");
127
	filter2.size = 8;
128
	filter2.end = 0;
129
 
130
	strcpy(#menu_text_area1.menu, MENU1);
131
	strcpy(#menu_text_area1.sub_menu1, MENU1_SUBMENU1);
132
	strcpy(#menu_text_area1.sub_menu2, MENU1_SUBMENU2);
133
	//strcpy(#menu_text_area1.sub_menu3, MENU1_SUBMENU3);
134
	strcpy(#menu_text_area1.sub_menu4, MENU1_SUBMENU4);
135
	menu_text_area1.end = 0;
136
 
137
	mem_Init();
138
	if (load_dll2(boxlib, #box_lib_init,0)!=0) notify(ERROR_LOAD_BOX_LIB);
139
	if (load_dll2(libio, #libio_init,1)!=0) notify(ERROR_LOAD_LIBIO);
140
	if (load_dll2(Proc_lib, #OpenDialog_init,0)!=0) notify(ERROR_LOAD_PROC_LIB);
141
	OpenDialog_init stdcall (#o_dialog);
142
	SetEventMask(0x27);
143
	loop()
144
	{
145
      switch(WaitEvent())
146
      {
147
		case evMouse:
148
			menu_bar_mouse stdcall (#menudata1);
149
			if (menudata1.click==1)
150
			{
151
				switch(menudata1.cursor_out)
152
				{
153
					case 1:
154
						OpenDialog_start stdcall (#o_dialog);
155
						OpenFile(#openfile_path);
156
						Prepare();
157
						draw_window();
158
						break;
159
					case 2:
160
						read = 0;
161
						strcpy(#win_title, TITLE);
162
						FreeBuf();
163
						draw_window();
164
						break;
165
					case 3:
166
						if (!active_properties)
167
						{
168
							SwitchToAnotherThread();
169
							properties_window = CreateThread(#properties_dialog, #properties_stak+4092);
170
							break;
171
						}
172
						else
173
						{
174
							ActivateWindow(GetProcessSlot(properties_window));
175
						}
176
						break;
177
					case 4:
178
						ExitProcess();
179
				}
180
			}
181
			break;
182
 
183
        case evButton:
184
            id=GetButtonID();
185
            if (id==1) || (id==10) ExitProcess();
186
			break;
187
 
188
        case evKey:
189
			key = GetKey();
190
			switch (key)
191
			{
192
				if (Form.status_window>2) break;
193
				case 015:               //Ctrl+O
194
					OpenDialog_start stdcall (#o_dialog);
195
					OpenFile(#openfile_path);
196
					Prepare();
197
					draw_window();
198
					break;
199
				case ASCII_KEY_HOME:
200
					cur_row = 0;
201
					DrawText();
202
					break;
203
				case ASCII_KEY_END:
204
					cur_row = row_num - row_count - 1;
205
					DrawText();
206
					break;
207
				case ASCII_KEY_UP:
208
					if (!cur_row) break;
209
					else cur_row = cur_row-1;
210
					DrawText();
211
					break;
212
				case ASCII_KEY_DOWN:
213
					if (cur_row+row_count>=row_num) break;
214
					cur_row = cur_row+1;
215
					DrawText();
216
					break;
217
				case ASCII_KEY_PGUP:
218
					if (!cur_row) break;
219
					if (cur_row
220
					else cur_row = cur_row-row_count;
221
					DrawText();
222
					break;
223
				case ASCII_KEY_PGDN:
224
					if (cur_row+row_count>row_num) break;
225
					cur_row = cur_row+row_count;
226
					DrawText();
227
					break;
228
			}
229
			break;
230
 
231
         case evReDraw:
232
			draw_window();
233
			break;
234
      }
235
   }
236
}
237
 
238
 
239
void draw_window()
240
{
241
	sc.get();
242
	DefineAndDrawWindow(GetScreenWidth()-WIN_W/2,GetScreenHeight()-WIN_H/2,WIN_W,WIN_H,0x73,0xFFFFFF,#win_title);
243
	GetProcessInfo(#Form, SelfInfo);
244
	DrawBar(0, 0, Form.cwidth, TOPPANELH, sc.work);
245
	DrawBar(0, Form.cheight-BOTPANELH, Form.cwidth, BOTPANELH, sc.work);
246
 
247
	menudata1.bckg_col = sc.work;
248
	menu_bar_draw stdcall (#menudata1);
249
 
250
	if (old_width!=Form.width) || (old_height!=Form.height)
251
	{
252
		old_width = Form.width;
253
		old_height = Form.height;
254
 
255
		col_count = Form.cwidth/6;
256
		row_count = Form.cheight-BOTPANELH-TOPPANELH-2;
257
		row_count = row_count/10;
258
 
259
		if (read==1) Prepare();
260
	}
261
	if (read==1)
262
	{
263
		DrawText();
264
	}
265
	else DrawBar(0, TOPPANELH, Form.cwidth, Form.cheight-BOTPANELH-TOPPANELH, 0xFFFFFF);
266
}
267
 
268
void OpenFile(dword path)
269
{
270
	strcpy(#win_title, TITLE);
271
	strcat(#win_title, " - ");
272
	strcat(#win_title, path);
273
	file_size stdcall (path);
274
	bufsize = EBX;
275
	if (bufsize)
276
	{
277
		mem_Free(bufpointer);
278
		bufpointer = mem_Alloc(bufsize);
279
		ReadFile(0, bufsize, bufpointer, path);
280
		read=1;
281
	}
282
}
283
 
284
void FreeBuf()
285
{
286
	int i;
287
	for (i=0; i
288
	{
289
		mem_Free(DSDWORD[i*4+draw_sruct]);
290
	}
291
	mem_Free(draw_sruct);
292
	mem_Free(bufpointer);
293
}
294
 
295
void Prepare()
296
{
297
	int i, sub_pos;
298
	int len_str = 0;
299
	byte do_eof = 0;
300
	word bukva[2];
301
	dword address;
302
	row_num = 0;
303
	while(1)
304
	{
305
		while(1)
306
		{
307
			bukva = DSBYTE[bufpointer+pos+len_str];
308
			if (bukva=='\0')
309
			{
310
				do_eof = 1;
311
				break;
312
			}
313
			if (bukva==0x0a) break;
314
			else len_str++;
315
		}
316
		if (len_str<=col_count)
317
		{
318
			pos=pos+len_str+1;
319
			row_num++;
320
		}
321
		else
322
		{
323
			pos=pos+col_count;
324
			row_num++;
325
		}
326
		len_str = 0;
327
		if (do_eof) break;
328
	}
329
	mem_Free(draw_sruct);
330
	draw_sruct = mem_Alloc(row_num*4);
331
	pos=0;
332
	sub_pos=0;
333
	len_str = 0;
334
	do_eof = 0;
335
	while(1)
336
	{
337
		while(1)
338
		{
339
			bukva = DSBYTE[bufpointer+pos+len_str];
340
			if (bukva=='\0')
341
			{
342
				do_eof = 1;
343
				break;
344
			}
345
			if (bukva==0x0a) break;
346
			else len_str++;
347
		}
348
		if (len_str<=col_count)
349
		{
350
			address = mem_Alloc(len_str+1);
351
			ESDWORD[sub_pos*4+draw_sruct] = address;
352
			strlcpy(DSDWORD[sub_pos*4+draw_sruct], bufpointer+pos, len_str);
353
			pos=pos+len_str+1;
354
			sub_pos++;
355
		}
356
		else
357
		{
358
			address = mem_Alloc(len_str+1);
359
			ESDWORD[sub_pos*4+draw_sruct] = address;
360
			strlcpy(DSDWORD[sub_pos*4+draw_sruct], bufpointer+pos, col_count);
361
			pos=pos+col_count;
362
			sub_pos++;
363
		}
364
		len_str = 0;
365
		if (pos>=bufsize-1) break;
366
	}
367
	pos=0;
368
}
369
 
370
void DrawText()
371
{
372
	int i, top, num_line;
373
	if (row_num
374
	else
375
	{
376
		if (row_num-cur_row<=row_count) top = row_num-cur_row-1;
377
		else top = row_count;
378
	}
379
	DrawBar(0, TOPPANELH, Form.cwidth, 3, 0xFFFFFF);
380
	for (i=0, num_line = cur_row; i
381
	{
382
		DrawBar(0, i*10+TOPPANELH+3, Form.cwidth, 10, 0xFFFFFF);
383
		WriteText(2, i*10+TOPPANELH+3, 0x80, 0x000000, DSDWORD[num_line*4+draw_sruct]);
384
	}
385
	DrawBar(0, i*10+TOPPANELH+3, Form.cwidth, -i*10-TOPPANELH-BOTPANELH+Form.cheight, 0xFFFFFF);
386
}
387
 
388
stop:
389
char properties_stak[4096];