Subversion Repositories Kolibri OS

Rev

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

Rev 7043 Rev 7049
Line 1... Line 1...
1
//Calypte 0.35 - Leency
1
//Calypte 0.35 - Leency
2
//Calypte 0.15 - Punk Joker
2
//Calypte 0.15 - Punk Joker
Line 3... Line 3...
3
 
3
 
Line 4... Line 4...
4
#define MEMSIZE 1024*100
4
#define MEMSIZE 1024*200
5
 
5
 
6
#ifndef AUTOBUILD
6
#ifndef AUTOBUILD
Line 7... Line -...
7
	#include "lang.h--"
-
 
8
#endif
7
	#include "lang.h--"
9
 
8
#endif
10
 
9
 
11
//===================================================//
10
//===================================================//
12
//                                                   //
11
//                                                   //
Line 17... Line 16...
17
#include "../lib/kolibri.h" 
16
#include "../lib/kolibri.h" 
18
#include "../lib/file_system.h"
17
#include "../lib/file_system.h"
19
#include "../lib/gui.h"
18
#include "../lib/gui.h"
20
#include "../lib/list_box.h"
19
#include "../lib/list_box.h"
21
#include "../lib/menu.h"
20
#include "../lib/menu.h"
22
//#include "../lib/collection.h"
21
#include "../lib/collection.h"
23
 
-
 
Line 24... Line 22...
24
 
22
 
25
#include "../lib/obj/iconv.h"
23
#include "../lib/obj/iconv.h"
26
#include "../lib/obj/box_lib.h"
24
#include "../lib/obj/box_lib.h"
27
#include "../lib/obj/libio_lib.h" //TO CHECK: why opendial is a peace of shit!
25
#include "../lib/obj/libio.h"
-
 
26
#include "../lib/obj/proc_lib.h"
Line 28... Line 27...
28
#include "../lib/obj/proc_lib.h"
27
//#include "../lib/obj/libini.h"
Line 29... Line -...
29
 
-
 
30
#include "../lib/patterns/simple_open_dialog.h"
-
 
31
 
-
 
32
 
-
 
33
char default_dir[] = "/rd/1";
28
 
34
od_filter filter2 = { "TXT",0};
29
#include "../lib/patterns/simple_open_dialog.h"
35
 
30
 
36
//===================================================//
31
//===================================================//
37
//                                                   //
32
//                                                   //
Line -... Line 33...
-
 
33
//                       DATA                        //
-
 
34
//                                                   //
-
 
35
//===================================================//
38
//                       DATA                        //
36
 
39
//                                                   //
37
char default_dir[] = "/rd/1";
40
//===================================================//
38
od_filter filter2 = { 8, "TXT\0\0" };
41
 
39
 
Line 87... Line 85...
87
int menu_file_x = 6;
85
int menu_file_x = 6;
88
int menu_encoding_x = NULL;
86
int menu_encoding_x = NULL;
89
int menu_reopen_x = NULL;
87
int menu_reopen_x = NULL;
90
/*======== MENU END ==========*/
88
/*======== MENU END ==========*/
Line 91... Line 89...
91
 
89
 
92
#define TITLE "Calypte v0.3"
90
#define TITLE "Calypte v0.37"
Line 93... Line 91...
93
char win_title[4096] = TITLE;
91
char win_title[4096] = TITLE;
94
 
92
 
95
#define TOPPANELH 23
93
#define TOPPANELH 23
Line 105... Line 103...
105
	
103
	
Line 106... Line 104...
106
dword old_width,old_height;
104
dword old_width,old_height;
107
 
105
 
108
dword bufpointer;
-
 
Line 109... Line 106...
109
dword bufsize;
106
dword bufpointer;
110
dword draw_sruct;
107
dword bufsize;
Line 111... Line 108...
111
 
108
 
Line 112... Line 109...
112
scroll_bar scroll_v = { SCROLL_SIZE,200,398,44,0,2,115,15,0,0xeeeeee,0xBBBbbb,0xeeeeee,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1};
109
scroll_bar scroll_v = { SCROLL_SIZE,200,398,44,0,2,115,15,0,0xeeeeee,0xBBBbbb,0xeeeeee,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1};
113
scroll_bar scroll_h = { SCROLL_SIZE,200,398,44,0,2,115,15,0,0xeeeeee,0xBBBbbb,0xeeeeee,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1};
110
scroll_bar scroll_h = { SCROLL_SIZE,200,398,44,0,2,115,15,0,0xeeeeee,0xBBBbbb,0xeeeeee,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1};
114
 
111
 
115
//collection s;
112
collection s;
116
 
113
 
Line 117... Line 114...
117
//===================================================//
114
//===================================================//
118
//                                                   //
115
//                                                   //
-
 
116
//                       CODE                        //
-
 
117
//                                                   //
119
//                       CODE                        //
118
//===================================================//
120
//                                                   //
119
 
-
 
120
void main()
121
//===================================================//
121
{   
122
 
122
	int id;
123
void InitDlls()
123
 
124
{
-
 
Line 125... Line 124...
125
	load_dll(boxlib,    #box_lib_init,   0);
124
	load_dll(boxlib,    #box_lib_init,   0);
126
	load_dll(libio,     #libio_init,     1);
125
	load_dll(libio,     #libio_init,     1);
127
	load_dll(iconv_lib, #iconv_open,     0);
126
	//load_dll(libini,    #lib_init,       1);
-
 
127
	load_dll(iconv_lib, #iconv_open,     0);
128
	load_dll(Proc_lib,  #OpenDialog_init,0);
128
	load_dll(Proc_lib,  #OpenDialog_init,0);
129
	OpenDialog_init stdcall (#o_dialog);
129
	OpenDialog_init stdcall (#o_dialog);
-
 
130
 
Line 130... Line 131...
130
}
131
	if (param)
-
 
132
	{
131
 
133
		draw_window();
132
void main()
134
		OpenFile(#param);
133
{   
135
		Prepare();
134
	int id;
136
		DrawText();
135
 
137
	}
Line 169... Line 171...
169
			}
171
			}
170
			if (rows.ProcessKey(key_scancode)) DrawText();
172
			if (rows.ProcessKey(key_scancode)) DrawText();
171
			break;
173
			break;
Line 172... Line 174...
172
		 
174
		 
173
		 case evReDraw:
175
		 case evReDraw:
174
			if (menu.list.cur_y) {
-
 
175
				if (menu.list.cur_y == FILE_SUBMENU_ID_OPEN) EventOpenFile();
-
 
176
				if (menu.list.cur_y == FILE_SUBMENU_ID_CLOSE) EventCloseFile();
-
 
177
				if (menu.list.cur_y == FILE_SUBMENU_ID_PROPERTIES) EventShowFileProperties();
-
 
178
				if (menu.list.cur_y == FILE_SUBMENU_ID_EXIT) ExitProcess();
-
 
179
 
-
 
180
				if (menu.list.cur_y > MENU_ID_ENCODING) && (menu.list.cur_y < MENU_ID_ENCODING + 10) 
-
 
181
					EventChangeEncoding(menu.list.cur_y - MENU_ID_ENCODING);
-
 
182
 
-
 
183
				if (menu.list.cur_y == FILE_SUBMENU_ID_TINYPAD) ReopenFileIn("/sys/tinypad");
-
 
184
				if (menu.list.cur_y == FILE_SUBMENU_ID_TEXTEDIT) ReopenFileIn("/sys/develop/t_edit");
-
 
185
				if (menu.list.cur_y == FILE_SUBMENU_ID_TEXTREAD) ReopenFileIn("/sys/txtread");
-
 
186
				if (menu.list.cur_y == FILE_SUBMENU_ID_WEBVIEW) ReopenFileIn("/sys/network/webview");
-
 
187
				if (menu.list.cur_y == FILE_SUBMENU_ID_FB2READ) ReopenFileIn("/sys/fb2read");
-
 
188
				if (menu.list.cur_y == FILE_SUBMENU_ID_HEXVIEW) ReopenFileIn("/sys/develop/heed");
-
 
189
				
-
 
190
 
-
 
191
				menu.list.cur_y = 0;
-
 
192
			};
176
			if (menu.list.cur_y) EventMenuClick();
193
			draw_window();
177
			draw_window();
194
			break;
178
			break;
195
	  }
179
	  }
196
   }
180
   }
Line 197... Line -...
197
}
-
 
198
 
-
 
199
void ReopenFileIn(dword _app)
-
 
200
{
-
 
201
	RunProgram(_app, #param);
-
 
202
}
-
 
203
 
-
 
204
void EventShowMenu(dword _menu_item_x, _menu_list, _id, _selected)
-
 
205
{
-
 
206
	menu.selected = _selected;
-
 
207
	menu.show(
-
 
208
	Form.left+5 + _menu_item_x, 
-
 
209
	Form.top+skin_height + TOPPANELH, 
-
 
210
	140, 
-
 
211
	_menu_list, 
-
 
212
	_id);	
-
 
213
}
-
 
214
 
-
 
215
void EventOpenFile()
-
 
216
{
-
 
217
	OpenDialog_start stdcall (#o_dialog);
-
 
218
	if (!o_dialog.status) return;
-
 
219
	OpenFile(#openfile_path);
-
 
220
	Prepare();
-
 
221
	draw_window();
-
 
222
}
-
 
223
 
-
 
224
void EventCloseFile()
-
 
225
{
-
 
226
	if (!bufpointer) return;
-
 
227
	strcpy(#win_title, TITLE);
-
 
228
	FreeBuf();
-
 
229
	draw_window();	
-
 
230
}
-
 
231
 
-
 
232
void EventShowFileProperties()
-
 
233
{
-
 
234
char ss_param[4096];
-
 
235
	if (!bufpointer) return;
-
 
236
	sprintf(#ss_param, "-p %s", #param);
-
 
237
	RunProgram("/sys/File managers/Eolite", #ss_param);
-
 
238
}
-
 
239
 
-
 
240
void EventChangeEncoding(dword id)
-
 
241
{
-
 
242
	encoding = id;
-
 
243
	OpenFile(#openfile_path);
-
 
244
	Prepare();
-
 
245
	draw_window();
-
 
246
}
181
}
247
 
182
 
248
int DrawMenuButton(dword x,y,id,text)
183
int DrawMenuButton(dword x,y,id,text)
249
{
184
{
250
	int textlen = strlen(text)*8;
185
	int textlen = strlen(text)*8;
Line 255... Line 190...
255
}
190
}
Line 256... Line 191...
256
 
191
 
257
void draw_window()
192
void draw_window()
258
{
193
{
259
	system.color.get();
194
	system.color.get();
260
	DefineAndDrawWindow(GetScreenWidth()-WIN_W/2,GetScreenHeight()-WIN_H/2,WIN_W,WIN_H,0x73,0xFFFFFF,#win_title,0);
195
	DefineAndDrawWindow(screen.width-WIN_W/2,screen.height-WIN_H/2,WIN_W,WIN_H,0x73,0xFFFFFF,#win_title,0);
261
	GetProcessInfo(#Form, SelfInfo);
196
	GetProcessInfo(#Form, SelfInfo);
262
	DrawBar(0, 0, Form.cwidth, TOPPANELH-1, system.color.work);
197
	DrawBar(0, 0, Form.cwidth, TOPPANELH-1, system.color.work);
263
	DrawBar(0, TOPPANELH-1, Form.cwidth, 1, system.color.work_dark);
198
	DrawBar(0, TOPPANELH-1, Form.cwidth, 1, system.color.work_dark);
Line 296... Line 231...
296
		bufpointer = mem_Free(bufpointer);
231
		bufpointer = mem_Free(bufpointer);
297
		bufpointer = mem_Alloc(bufsize);
232
		bufpointer = mem_Alloc(bufsize);
298
		if (ReadFile(0, bufsize, bufpointer, #param) != 0) {
233
		if (ReadFile(0, bufsize, bufpointer, #param) != 0) {
299
			bufpointer = 0;
234
			bufpointer = 0;
300
			notify("'Error opening file'-E");
235
			notify("'Error opening file'-E");
-
 
236
			return;
301
		}
237
		}
302
	}
238
	}
303
	if (encoding!=CH_CP866) ChangeCharset(charsets[encoding], "CP866", bufpointer);
239
	if (encoding!=CH_CP866) ChangeCharset(charsets[encoding], "CP866", bufpointer);
304
}
240
}
Line 305... Line -...
305
 
-
 
306
void FreeBuf()
-
 
307
{
-
 
308
	int i;
-
 
309
	if (!bufpointer) return;
-
 
310
	for (i=0; i
-
 
311
	{
-
 
312
		mem_Free(DSDWORD[i*4+draw_sruct]);
-
 
313
	}
-
 
314
	draw_sruct = mem_Free(draw_sruct);
-
 
315
	bufpointer = mem_Free(bufpointer);
-
 
316
}
-
 
317
 
241
 
318
enum {
242
enum {
319
	PARSE_CALCULATE_ROWS_COUNT,
243
	PARSE_CALCULATE_ROWS_COUNT,
320
	PARSE_DRAW_PREPARE,
244
	PARSE_DRAW_PREPARE,
321
};
245
};
Line 340... Line 264...
340
			if (bukva==0x0a) break;
264
			if (bukva==0x0a) break;
341
			else len_str++;
265
			else len_str++;
342
		}
266
		}
343
		if (len_str<=rows.column_max) 
267
		if (len_str<=rows.column_max) 
344
		{
268
		{
345
			if (mode==PARSE_DRAW_PREPARE)
269
			if (mode==PARSE_DRAW_PREPARE) s.addn(bufpointer+pos, len_str);
346
			{
-
 
347
				ESDWORD[sub_pos*4+draw_sruct] = mem_Alloc(len_str+1);
-
 
348
				strlcpy(DSDWORD[sub_pos*4+draw_sruct], bufpointer+pos, len_str); //-1 to do not show \n symbol				
-
 
349
			}
-
 
350
			pos += len_str+1;
270
			pos += len_str+1;
351
		}
271
		}
352
		else
272
		else
353
		{
273
		{
354
			if (mode==PARSE_DRAW_PREPARE)
-
 
355
			{
-
 
356
				ESDWORD[sub_pos*4+draw_sruct] = mem_Alloc(len_str+1);
-
 
357
				strlcpy(DSDWORD[sub_pos*4+draw_sruct], bufpointer+pos, rows.column_max);					
274
			if (mode==PARSE_DRAW_PREPARE) s.addn(bufpointer+pos, rows.column_max);
358
			}
-
 
359
			pos += rows.column_max;
275
			pos += rows.column_max;
360
		}
276
		}
361
		sub_pos++;
277
		sub_pos++;
362
		if (mode==PARSE_CALCULATE_ROWS_COUNT) if (do_eof) break;
278
		if (mode==PARSE_CALCULATE_ROWS_COUNT) if (do_eof) break;
363
		if (mode==PARSE_DRAW_PREPARE) if (pos>=bufsize-1) break;
279
		if (mode==PARSE_DRAW_PREPARE) if (pos>=bufsize-1) break;
364
		len_str = 0;
280
		len_str = 0;
365
	}
281
	}
366
	if (mode == PARSE_CALCULATE_ROWS_COUNT)
282
	if (mode == PARSE_CALCULATE_ROWS_COUNT)
367
	{
283
	{
368
		rows.count = sub_pos;
284
		rows.count = sub_pos;
369
		draw_sruct = mem_Free(draw_sruct);
-
 
370
		draw_sruct = mem_Alloc(rows.count*4);
-
 
371
		Parse(PARSE_DRAW_PREPARE);
285
		Parse(PARSE_DRAW_PREPARE);
372
 
-
 
373
	}
286
	}
374
}
287
}
Line 375... Line 288...
375
 
288
 
376
void Prepare()
289
void Prepare()
Line 390... Line 303...
390
	}
303
	}
Line 391... Line 304...
391
 
304
 
392
	if (bufpointer) for (i=0; i
305
	if (bufpointer) for (i=0; i
393
	{
306
	{
394
		DrawBar(0, i*rows.item_h+TOPPANELH, rows.w, rows.item_h, 0xFFFFFF);
307
		DrawBar(0, i*rows.item_h+TOPPANELH, rows.w, rows.item_h, 0xFFFFFF);
395
		WriteText(2, i*rows.item_h+TOPPANELH, 0x90, 0x000000, DSDWORD[i+rows.first*4+draw_sruct]);
308
		WriteText(2, i*rows.item_h+TOPPANELH, 0x90, 0x000000, s.get(i+rows.first));
396
	}
309
	}
397
	DrawBar(0, i*rows.item_h+rows.y, rows.w, -i*rows.item_h + rows.h, 0xFFFfff);
310
	DrawBar(0, i*rows.item_h+rows.y, rows.w, -i*rows.item_h + rows.h, 0xFFFfff);
398
	DrawVerticalScroll();
311
	DrawVerticalScroll();
Line 408... Line 321...
408
	scroll_v.start_x = rows.w + rows.x -1;
321
	scroll_v.start_x = rows.w + rows.x -1;
409
	scroll_v.all_redraw = 0;
322
	scroll_v.all_redraw = 0;
410
	scrollbar_v_draw(#scroll_v);
323
	scrollbar_v_draw(#scroll_v);
411
}
324
}
Line -... Line 325...
-
 
325
 
-
 
326
//===================================================//
-
 
327
//                                                   //
-
 
328
//                      EVENTS                       //
-
 
329
//                                                   //
-
 
330
//===================================================//
-
 
331
 
-
 
332
void EventMenuClick()
-
 
333
{
-
 
334
	switch(menu.list.cur_y)
-
 
335
	{
-
 
336
		//File
-
 
337
		case FILE_SUBMENU_ID_OPEN: EventOpenFile(); break;
-
 
338
		case FILE_SUBMENU_ID_CLOSE: EventCloseFile(); break;
-
 
339
		case FILE_SUBMENU_ID_PROPERTIES: EventShowFileProperties(); break;
-
 
340
		case FILE_SUBMENU_ID_EXIT: ExitProcess(); break;
-
 
341
		//Encoding
-
 
342
		case MENU_ID_ENCODING...MENU_ID_ENCODING+9: EventChangeEncoding(menu.list.cur_y-MENU_ID_ENCODING); break;
-
 
343
		//Reopen
-
 
344
		case FILE_SUBMENU_ID_TINYPAD: EventOpenFileInAnotherProgram("/sys/tinypad"); break;
-
 
345
		case FILE_SUBMENU_ID_TEXTEDIT: EventOpenFileInAnotherProgram("/sys/develop/t_edit"); break;
-
 
346
		case FILE_SUBMENU_ID_TEXTREAD: EventOpenFileInAnotherProgram("/sys/txtread"); break;
-
 
347
		case FILE_SUBMENU_ID_WEBVIEW: EventOpenFileInAnotherProgram("/sys/network/webview"); break;
-
 
348
		case FILE_SUBMENU_ID_FB2READ: EventOpenFileInAnotherProgram("/sys/fb2read"); break;
-
 
349
		case FILE_SUBMENU_ID_HEXVIEW: EventOpenFileInAnotherProgram("/sys/develop/heed"); break;
-
 
350
	}
-
 
351
	menu.list.cur_y = 0;
-
 
352
}
-
 
353
 
-
 
354
void EventShowMenu(dword _menu_item_x, _menu_list, _id, _selected)
-
 
355
{
-
 
356
	menu.selected = _selected;
-
 
357
	menu.show(
-
 
358
	Form.left+5 + _menu_item_x, 
-
 
359
	Form.top+skin_height + TOPPANELH, 
-
 
360
	140, 
-
 
361
	_menu_list, 
-
 
362
	_id);	
-
 
363
}
-
 
364
 
-
 
365
void EventOpenFile()
-
 
366
{
-
 
367
	OpenDialog_start stdcall (#o_dialog);
-
 
368
	if (!o_dialog.status) return;
-
 
369
	OpenFile(#openfile_path);
-
 
370
	Prepare();
-
 
371
	draw_window();
-
 
372
}
-
 
373
 
-
 
374
void EventCloseFile()
-
 
375
{
-
 
376
	if (!bufpointer) return;
-
 
377
	s.drop();
-
 
378
	bufpointer = mem_Free(bufpointer);
-
 
379
	strcpy(#win_title, TITLE);
-
 
380
	draw_window();	
-
 
381
}
-
 
382
 
-
 
383
void EventShowFileProperties()
-
 
384
{
-
 
385
char ss_param[4096];
-
 
386
	if (!bufpointer) return;
-
 
387
	sprintf(#ss_param, "-p %s", #param);
-
 
388
	RunProgram("/sys/File managers/Eolite", #ss_param);
-
 
389
}
-
 
390
 
-
 
391
void EventChangeEncoding(dword id)
-
 
392
{
-
 
393
	encoding = id;
-
 
394
	OpenFile(#openfile_path);
-
 
395
	Prepare();
-
 
396
	draw_window();
-
 
397
}
-
 
398
 
-
 
399
void EventOpenFileInAnotherProgram(dword _app)
-
 
400
{
-
 
401
	RunProgram(_app, #param);
-
 
402
}
-
 
403
 
-
 
404
 
412
 
405
 
413
stop:
406
stop: