Subversion Repositories Kolibri OS

Rev

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

Rev Author Line No. Line
7043 leency 1
//Calypte 0.35 - Leency
7041 leency 2
//Calypte 0.15 - Punk Joker
3
 
7049 leency 4
#define MEMSIZE 1024*200
7041 leency 5
 
5614 punk_joker 6
#ifndef AUTOBUILD
7
	#include "lang.h--"
8
#endif
9
 
7041 leency 10
//===================================================//
11
//                                                   //
12
//                       LIB                         //
13
//                                                   //
14
//===================================================//
5915 punk_joker 15
 
7041 leency 16
#include "../lib/kolibri.h"
7219 leency 17
#include "../lib/fs.h"
7041 leency 18
#include "../lib/gui.h"
19
#include "../lib/list_box.h"
20
#include "../lib/menu.h"
7049 leency 21
#include "../lib/collection.h"
5915 punk_joker 22
 
7041 leency 23
#include "../lib/obj/iconv.h"
7043 leency 24
#include "../lib/obj/box_lib.h"
7049 leency 25
#include "../lib/obj/libio.h"
7041 leency 26
#include "../lib/obj/proc_lib.h"
7290 punk_joker 27
#include "../lib/obj/librasterworks.h"
5915 punk_joker 28
 
7041 leency 29
#include "../lib/patterns/simple_open_dialog.h"
5915 punk_joker 30
 
7041 leency 31
//===================================================//
32
//                                                   //
33
//                       DATA                        //
34
//                                                   //
35
//===================================================//
5915 punk_joker 36
 
7049 leency 37
char default_dir[] = "/rd/1";
38
od_filter filter2 = { 8, "TXT\0\0" };
39
 
7041 leency 40
/*=========  MENU  ==========*/
41
?define MENU1 "File"
42
?define MENU2 "Encoding"
43
?define MENU3 "Reopen"
5612 punk_joker 44
 
7041 leency 45
char menu_file_list[] =
46
"Open
47
Close
48
Properties
49
Exit";
5612 punk_joker 50
 
7041 leency 51
char menu_encoding_list[] =
52
"UTF-8
53
KOI8-RU
54
CP1251
55
CP1252
56
ISO8859-5
57
CP866";
5915 punk_joker 58
 
7041 leency 59
char menu_reopen_list[] =
60
"Tinypad
61
TextEdit
62
TextRead
63
WebView
64
FB2Read
65
HexView";
5612 punk_joker 66
 
7290 punk_joker 67
enum
68
{
7041 leency 69
	MENU_ID_FILE=10,
70
	FILE_SUBMENU_ID_OPEN=10,
71
	FILE_SUBMENU_ID_CLOSE,
72
	FILE_SUBMENU_ID_PROPERTIES,
73
	FILE_SUBMENU_ID_EXIT,
5674 pavelyakov 74
 
7041 leency 75
	MENU_ID_ENCODING=20,
5612 punk_joker 76
 
7041 leency 77
	MENU_ID_REOPEN=30,
78
	FILE_SUBMENU_ID_TINYPAD=30,
79
	FILE_SUBMENU_ID_TEXTEDIT,
80
	FILE_SUBMENU_ID_TEXTREAD,
81
	FILE_SUBMENU_ID_WEBVIEW,
82
	FILE_SUBMENU_ID_FB2READ,
83
	FILE_SUBMENU_ID_HEXVIEW
5612 punk_joker 84
};
85
 
7041 leency 86
int menu_file_x = 6;
87
int menu_encoding_x = NULL;
88
int menu_reopen_x = NULL;
89
/*======== MENU END ==========*/
5612 punk_joker 90
 
7290 punk_joker 91
#define TITLE "Calypte v0.38 dev"
7041 leency 92
char win_title[4096] = TITLE;
5612 punk_joker 93
 
7041 leency 94
#define TOPPANELH 23
95
#define BOTPANELH 10
96
#define WIN_W 750
97
#define WIN_H 550
7043 leency 98
#define SCROLL_SIZE 15
7041 leency 99
 
100
proc_info Form;
101
llist rows;
102
 
103
int encoding;
5915 punk_joker 104
 
105
dword old_width,old_height;
5612 punk_joker 106
 
107
dword bufpointer;
108
dword bufsize;
109
 
7043 leency 110
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};
111
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};
112
 
7049 leency 113
collection s;
7043 leency 114
 
7041 leency 115
//===================================================//
116
//                                                   //
117
//                       CODE                        //
118
//                                                   //
119
//===================================================//
5612 punk_joker 120
 
7049 leency 121
void main()
122
{
123
	int id;
124
 
7043 leency 125
	load_dll(boxlib,    #box_lib_init,   0);
7041 leency 126
	load_dll(libio,     #libio_init,     1);
7049 leency 127
	//load_dll(libini,    #lib_init,       1);
7041 leency 128
	load_dll(iconv_lib, #iconv_open,     0);
129
	load_dll(Proc_lib,  #OpenDialog_init,0);
7290 punk_joker 130
	load_dll(librasterworks,  #rasterworks_drawText,0);
7041 leency 131
	OpenDialog_init stdcall (#o_dialog);
132
 
7049 leency 133
	if (param)
134
	{
135
		draw_window();
136
		OpenFile(#param);
137
		Prepare();
138
		DrawText();
139
	}
140
 
141
	SetEventMask(EVM_REDRAW+EVM_KEY+EVM_BUTTON+EVM_MOUSE+EVM_MOUSE_FILTER);
5612 punk_joker 142
 
143
	loop()
144
	{
7041 leency 145
	  switch(WaitEvent())
146
	  {
5612 punk_joker 147
		case evMouse:
7041 leency 148
			mouse.get();
149
			rows.wheel_size = 3;
7290 punk_joker 150
			if (rows.MouseScroll(mouse.vert))
151
			{
7041 leency 152
				DrawText();
5612 punk_joker 153
			}
154
			break;
155
 
7041 leency 156
		case evButton:
5915 punk_joker 157
			id=GetButtonID();
7290 punk_joker 158
			if (id==1)
159
			{
160
				ExitProcess();
161
			}
7043 leency 162
			if (id==MENU_ID_FILE)
7290 punk_joker 163
			{
7043 leency 164
				EventShowMenu(menu_file_x, #menu_file_list, MENU_ID_FILE, NULL);
7290 punk_joker 165
			}
7043 leency 166
			if (id==MENU_ID_ENCODING)
7290 punk_joker 167
			{
7043 leency 168
				EventShowMenu(menu_encoding_x, #menu_encoding_list, MENU_ID_ENCODING, encoding+1);
7290 punk_joker 169
			}
7043 leency 170
			if (id==MENU_ID_REOPEN)
7290 punk_joker 171
			{
7043 leency 172
				EventShowMenu(menu_reopen_x, #menu_reopen_list, MENU_ID_REOPEN, NULL);
7290 punk_joker 173
			}
5612 punk_joker 174
			break;
5915 punk_joker 175
 
7041 leency 176
		case evKey:
177
			GetKeys();
178
			if (key_modifier&KEY_LCTRL) || (key_modifier&KEY_RCTRL)
5612 punk_joker 179
			{
7290 punk_joker 180
				if (key_scancode == SCAN_CODE_KEY_O)
181
				{
182
					EventOpenFile();
183
				}
5705 punk_joker 184
				break;
185
			}
7290 punk_joker 186
			if (rows.ProcessKey(key_scancode))
187
			{
188
				DrawText();
189
			}
5612 punk_joker 190
			break;
7041 leency 191
 
192
		 case evReDraw:
7290 punk_joker 193
			if (menu.list.cur_y)
194
			{
195
				EventMenuClick();
196
			}
5612 punk_joker 197
			draw_window();
198
			break;
7041 leency 199
	  }
5612 punk_joker 200
   }
201
}
202
 
7041 leency 203
int DrawMenuButton(dword x,y,id,text)
204
{
205
	int textlen = strlen(text)*8;
206
	int padding = 12;
207
	DefineHiddenButton(x, y, textlen+padding+padding, TOPPANELH-2, id);
208
	WriteText(x+padding,y+4, 0x90, MixColors(system.color.work, system.color.work_text, 70), text);
209
	return textlen+padding+padding;
210
}
211
 
5612 punk_joker 212
void draw_window()
213
{
5674 pavelyakov 214
	system.color.get();
7049 leency 215
	DefineAndDrawWindow(screen.width-WIN_W/2,screen.height-WIN_H/2,WIN_W,WIN_H,0x73,0xFFFFFF,#win_title,0);
5612 punk_joker 216
	GetProcessInfo(#Form, SelfInfo);
7041 leency 217
	DrawBar(0, 0, Form.cwidth, TOPPANELH-1, system.color.work);
218
	DrawBar(0, TOPPANELH-1, Form.cwidth, 1, system.color.work_dark);
5674 pavelyakov 219
	DrawBar(0, Form.cheight-BOTPANELH, Form.cwidth, BOTPANELH, system.color.work);
5612 punk_joker 220
 
7041 leency 221
	menu_encoding_x = menu_file_x + DrawMenuButton(menu_file_x, 0, MENU_ID_FILE, MENU1);
222
	menu_reopen_x = menu_encoding_x + DrawMenuButton(menu_encoding_x, 0, MENU_ID_ENCODING, MENU2);
223
	DrawMenuButton(menu_reopen_x, 0, MENU_ID_REOPEN, MENU3);
224
 
5612 punk_joker 225
	if (old_width!=Form.width) || (old_height!=Form.height)
226
	{
227
		old_width = Form.width;
228
		old_height = Form.height;
5915 punk_joker 229
 
7041 leency 230
		rows.no_selection = true;
231
		rows.SetFont(8, 14, 0x90);
7043 leency 232
		rows.SetSizes(0, TOPPANELH, Form.cwidth - SCROLL_SIZE, Form.cheight - TOPPANELH - BOTPANELH, 20);
7041 leency 233
		rows.column_max = rows.w / rows.font_w;
234
 
7290 punk_joker 235
		if (bufpointer)
236
		{
237
			Prepare();
238
		}
7041 leency 239
		rows.CheckDoesValuesOkey();
5612 punk_joker 240
	}
7043 leency 241
	DrawRectangle(rows.x+rows.w-1, rows.y, SCROLL_SIZE, rows.h-1, 0xEEEeee);
242
	DrawText();
5612 punk_joker 243
}
244
 
7041 leency 245
void OpenFile(dword _path)
5612 punk_joker 246
{
7041 leency 247
	strcpy(#param, _path);
248
	sprintf(#win_title, "%s - %s", TITLE, #param);
249
	rows.KeyHome();
250
	file_size stdcall (#param);
5612 punk_joker 251
	bufsize = EBX;
252
	if (bufsize)
253
	{
7041 leency 254
		bufpointer = mem_Free(bufpointer);
5612 punk_joker 255
		bufpointer = mem_Alloc(bufsize);
7290 punk_joker 256
		if (ReadFile(0, bufsize, bufpointer, #param) != 0)
257
		{
7041 leency 258
			bufpointer = 0;
259
			notify("'Error opening file'-E");
7049 leency 260
			return;
7041 leency 261
		}
5612 punk_joker 262
	}
7290 punk_joker 263
	if (encoding!=CH_CP866)
264
	{
265
		ChangeCharset(charsets[encoding], "CP866", bufpointer);
266
	}
5612 punk_joker 267
}
268
 
7290 punk_joker 269
enum
270
{
7041 leency 271
	PARSE_CALCULATE_ROWS_COUNT,
272
	PARSE_DRAW_PREPARE,
273
};
7290 punk_joker 274
 
7041 leency 275
void Parse(int mode)
5612 punk_joker 276
{
7041 leency 277
	int pos=0;
278
	int sub_pos=0;
5612 punk_joker 279
	int len_str = 0;
7041 leency 280
	bool do_eof = false;
5612 punk_joker 281
	word bukva[2];
7041 leency 282
 
5612 punk_joker 283
	while(1)
284
	{
285
		while(1)
286
		{
5915 punk_joker 287
			bukva = DSBYTE[bufpointer+pos+len_str];
5612 punk_joker 288
			if (bukva=='\0')
289
			{
7041 leency 290
				do_eof = true;
5612 punk_joker 291
				break;
292
			}
7290 punk_joker 293
			if (bukva==0x0a)
294
			{
295
				break;
296
			}
297
			else
298
			{
299
				len_str++;
300
			}
5612 punk_joker 301
		}
7041 leency 302
		if (len_str<=rows.column_max)
5612 punk_joker 303
		{
7290 punk_joker 304
			if (mode==PARSE_DRAW_PREPARE)
305
			{
306
				s.addn(bufpointer+pos, len_str);
307
			}
7041 leency 308
			pos += len_str+1;
5612 punk_joker 309
		}
310
		else
311
		{
7290 punk_joker 312
			if (mode==PARSE_DRAW_PREPARE)
313
			{
314
				s.addn(bufpointer+pos, rows.column_max);
315
			}
7041 leency 316
			pos += rows.column_max;
5612 punk_joker 317
		}
7041 leency 318
		sub_pos++;
7290 punk_joker 319
		if (mode==PARSE_CALCULATE_ROWS_COUNT) && (do_eof)
320
		{
321
			break;
322
		}
323
		if (mode==PARSE_DRAW_PREPARE) && (pos>=bufsize-1)
324
		{
325
			break;
326
		}
5612 punk_joker 327
		len_str = 0;
328
	}
7041 leency 329
	if (mode == PARSE_CALCULATE_ROWS_COUNT)
330
	{
331
		rows.count = sub_pos;
332
		Parse(PARSE_DRAW_PREPARE);
333
	}
5612 punk_joker 334
}
335
 
7041 leency 336
void Prepare()
337
{
338
	Parse(PARSE_CALCULATE_ROWS_COUNT);
339
}
340
 
5612 punk_joker 341
void DrawText()
342
{
7043 leency 343
	int i=0, top;
7041 leency 344
 
7290 punk_joker 345
	if (rows.count
346
	{
347
		top = rows.count;
348
	}
5612 punk_joker 349
	else
350
	{
7290 punk_joker 351
		if (rows.count-rows.first<=rows.visible)
352
		{
353
			top = rows.count-rows.first-1;
354
		}
355
		else
356
		{
357
			top = rows.visible;
358
		}
5612 punk_joker 359
	}
7041 leency 360
 
7290 punk_joker 361
	if (bufpointer)
5612 punk_joker 362
	{
7290 punk_joker 363
		for (i=0; i
364
		{
365
			DrawBar(0, i*rows.item_h+TOPPANELH, rows.w, rows.item_h, 0xFFFFFF);
366
			WriteText(2, i*rows.item_h+TOPPANELH, 0x90, 0x000000, s.get(i+rows.first));
367
		}
5612 punk_joker 368
	}
7041 leency 369
	DrawBar(0, i*rows.item_h+rows.y, rows.w, -i*rows.item_h + rows.h, 0xFFFfff);
7043 leency 370
	DrawVerticalScroll();
5612 punk_joker 371
}
372
 
7043 leency 373
void DrawVerticalScroll()
374
{
375
	scroll_v.max_area = rows.count;
376
	scroll_v.cur_area = rows.visible;
377
	scroll_v.position = rows.first;
378
	scroll_v.start_y = rows.y;
379
	scroll_v.size_y = rows.h;
380
	scroll_v.start_x = rows.w + rows.x -1;
381
	scroll_v.all_redraw = 0;
382
	scrollbar_v_draw(#scroll_v);
383
}
384
 
7049 leency 385
//===================================================//
386
//                                                   //
387
//                      EVENTS                       //
388
//                                                   //
389
//===================================================//
390
 
391
void EventMenuClick()
392
{
393
	switch(menu.list.cur_y)
394
	{
395
		//File
7290 punk_joker 396
		case FILE_SUBMENU_ID_OPEN:
397
			EventOpenFile();
398
			break;
399
		case FILE_SUBMENU_ID_CLOSE:
400
			EventCloseFile();
401
			break;
402
		case FILE_SUBMENU_ID_PROPERTIES:
403
			EventShowFileProperties();
404
			break;
405
		case FILE_SUBMENU_ID_EXIT:
406
			ExitProcess();
407
			break;
7049 leency 408
		//Encoding
7290 punk_joker 409
		case MENU_ID_ENCODING...MENU_ID_ENCODING+9:
410
			EventChangeEncoding(menu.list.cur_y-MENU_ID_ENCODING);
411
			break;
7049 leency 412
		//Reopen
7290 punk_joker 413
		case FILE_SUBMENU_ID_TINYPAD:
414
			EventOpenFileInAnotherProgram("/sys/tinypad");
415
			break;
416
		case FILE_SUBMENU_ID_TEXTEDIT:
417
			EventOpenFileInAnotherProgram("/sys/develop/t_edit");
418
			break;
419
		case FILE_SUBMENU_ID_TEXTREAD:
420
			EventOpenFileInAnotherProgram("/sys/txtread");
421
			break;
422
		case FILE_SUBMENU_ID_WEBVIEW:
423
			EventOpenFileInAnotherProgram("/sys/network/webview");
424
			break;
425
		case FILE_SUBMENU_ID_FB2READ:
426
			EventOpenFileInAnotherProgram("/sys/fb2read");
427
			break;
428
		case FILE_SUBMENU_ID_HEXVIEW:
429
			EventOpenFileInAnotherProgram("/sys/develop/heed");
430
			break;
7049 leency 431
	}
432
	menu.list.cur_y = 0;
433
}
434
 
435
void EventShowMenu(dword _menu_item_x, _menu_list, _id, _selected)
436
{
437
	menu.selected = _selected;
7290 punk_joker 438
	menu.show(Form.left+5 + _menu_item_x, Form.top+skin_height + TOPPANELH, 140, _menu_list, _id);
7049 leency 439
}
440
 
441
void EventOpenFile()
442
{
443
	OpenDialog_start stdcall (#o_dialog);
7290 punk_joker 444
	if (o_dialog.status)
445
	{
446
		OpenFile(#openfile_path);
447
		Prepare();
448
		draw_window();
449
	}
7049 leency 450
}
451
 
452
void EventCloseFile()
453
{
7290 punk_joker 454
	if (bufpointer)
455
	{
456
		s.drop();
457
		bufpointer = mem_Free(bufpointer);
458
		strcpy(#win_title, TITLE);
459
		draw_window();
460
	}
7049 leency 461
}
462
 
463
void EventShowFileProperties()
464
{
7290 punk_joker 465
	char ss_param[4096];
466
	if (bufpointer)
467
	{
468
		sprintf(#ss_param, "-p %s", #param);
469
		RunProgram("/sys/File managers/Eolite", #ss_param);
470
	}
7049 leency 471
}
472
 
473
void EventChangeEncoding(dword id)
474
{
475
	encoding = id;
476
	OpenFile(#openfile_path);
477
	Prepare();
478
	draw_window();
479
}
480
 
481
void EventOpenFileInAnotherProgram(dword _app)
482
{
483
	RunProgram(_app, #param);
484
}
485
 
486
 
487
 
7290 punk_joker 488
stop: