Subversion Repositories Kolibri OS

Rev

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

Rev Author Line No. Line
7921 leency 1
/*
7957 leency 2
	Quark Code Edit
7921 leency 3
	Author: Kiril Lipatov aka Leency
4
	Licence: GPLv2
5
 
6
	The core components of this app are:
7924 leency 7
		1. list: text grid with keyboard and mouse events
7921 leency 8
		2. lines: the mas of pointers for each line start
9
		3. selection
10
*/
11
 
12
#define MEMSIZE 1024*100
13
 
14
//===================================================//
15
//                                                   //
16
//                       LIB                         //
17
//                                                   //
18
//===================================================//
19
 
20
#include "../lib/io.h"
21
#include "../lib/gui.h"
22
#include "../lib/list_box.h"
23
#include "../lib/draw_buf.h"
24
#include "../lib/events.h"
25
#include "../lib/array.h"
26
#include "../lib/clipboard.h"
27
#include "../lib/math.h"
28
 
29
#include "../lib/obj/box_lib.h"
30
#include "../lib/obj/libini.h"
31
#include "../lib/obj/libimg.h"
32
#include "../lib/obj/iconv.h"
33
#include "../lib/obj/proc_lib.h"
34
 
35
#include "../lib/patterns/simple_open_dialog.h"
36
#include "../lib/patterns/toolbar_button.h"
37
 
38
//===================================================//
39
//                                                   //
40
//                 INTERNAL INCLUDES                 //
41
//                                                   //
42
//===================================================//
43
 
44
proc_info Form;
45
llist list;
46
 
47
#define TOOLBAR_H 38
48
#define TOOLBAR_ICON_WIDTH  24
49
#define TOOLBAR_ICON_HEIGHT 22
50
#define STATUSBAR_H 15
51
#define TAB_H 20
52
 
53
int user_encoding;
54
int real_encoding = CH_CP866;
55
int curcol_scheme;
56
int font_size;
57
 
7945 leency 58
bool enable_edit = false;
7975 leency 59
bool search_next = false;
7945 leency 60
 
7921 leency 61
#include "data.h"
62
 
7941 leency 63
#include "search.h"
7921 leency 64
#include "selection.h"
65
#include "prepare_page.h"
66
 
67
//===================================================//
68
//                                                   //
69
//                       DATA                        //
70
//                                                   //
71
//===================================================//
72
 
73
scroll_bar scroll = { 15,200,398,44,0,2,115,15,0,0xeeeeee,
74
	0xBBBbbb,0xeeeeee,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1};
75
 
76
char title[4196];
77
 
78
int reopenin_mx,
79
    theme_mx,
80
    burger_mx,
81
    search_mx;
82
 
83
enum {
84
	CHANGE_CHARSET=12,
85
	REOPEN_IN_APP=1,
86
	COLOR_SCHEME=8,
87
	RMB_MENU,
88
	BTN_FIND_NEXT,
7924 leency 89
	BTN_FIND_CLOSE,
90
	BTN_CHANGE_CHARSET
7921 leency 91
};
92
 
93
dword menu_id;
94
 
95
EVENTS button;
96
EVENTS key;
97
 
98
//===================================================//
99
//                                                   //
100
//                       CODE                        //
101
//                                                   //
102
//===================================================//
103
 
104
void InitDlls()
105
{
106
	load_dll(boxlib,    #box_lib_init,   0);
107
	load_dll(libimg,    #libimg_init,    1);
108
	load_dll(libini,    #lib_init,       1);
109
	load_dll(iconv_lib, #iconv_open,     0);
110
	load_dll(Proc_lib,  #OpenDialog_init,0);
111
	OpenDialog_init stdcall (#o_dialog);
112
}
113
 
114
void LoadFileFromDocPack()
115
{
116
	dword bufsize = atoi(#param + 1) + 20;
117
	dword bufpointer = malloc(bufsize);
118
 
119
	ESDWORD[bufpointer+0] = 0;
120
	ESDWORD[bufpointer+4] = 8;
7924 leency 121
	IpcSetArea(bufpointer, bufsize);
7921 leency 122
 
123
	SetEventMask(EVM_IPC);
124
	if (@WaitEventTimeout(200) != evIPC) {
125
		notify("'IPC FAIL'E");
126
		return;
127
	}
128
 
129
	io.buffer_data = malloc(ESDWORD[bufpointer+12]);
130
	strcpy(io.buffer_data, bufpointer + 16);
131
}
132
 
133
void main()
134
{
135
	InitDlls();
136
	LoadIniSettings();
137
	EventSetColorScheme(curcol_scheme);
138
	if (param[0] == '*') {
139
		LoadFileFromDocPack();
140
		param[0]='\0';
141
		sprintf(#title, "#DOCPACK - %s", #short_app_name);
142
	} else {
143
		if (streq(#param,"-new")) {Form.left+=40;Form.top+=40;}
144
		LoadFile(#param);
145
	}
146
	SetEventMask(EVM_REDRAW + EVM_KEY + EVM_BUTTON + EVM_MOUSE + EVM_MOUSE_FILTER);
147
	loop()
148
	{
149
		switch(@WaitEventTimeout(400))
150
		{
151
			case evMouse:
152
				HandleMouseEvent();
153
				break;
154
			case evKey:
155
				HandleKeyEvent();
156
				break;
157
			case evButton:
158
				HandleButtonEvent();
159
				break;
160
			case evReDraw:
161
				if (CheckActiveProcess(Form.ID)) EventMenuClick();
162
				draw_window();
163
				break;
164
			default:
165
				DrawStatusBar(" "); //clean DrawStatusBar text with delay
166
		}
167
	}
168
}
169
 
170
//===================================================//
171
//                                                   //
172
//                  EVENT HANDLERS                   //
173
//                                                   //
174
//===================================================//
175
 
176
void HandleButtonEvent()
177
{
178
	int btn = GetButtonID();
179
	if (btn==1) {
180
		SaveIniSettings();
181
		ExitProcess();
182
	}
183
	button.press(btn);
184
	switch(btn-10)
185
	{
186
		case BTN_FIND_NEXT:
187
			EventSearchNext();
188
			break;
189
		case BTN_FIND_CLOSE:
190
			search.hide();
191
			break;
7924 leency 192
		case BTN_CHANGE_CHARSET:
193
			EventShowCharsetsList();
194
			break;
7921 leency 195
	}
196
}
197
 
198
void HandleKeyEvent()
199
{
200
	GetKeys();
201
 
7941 leency 202
	switch (key_scancode)
203
	{
204
		case SCAN_CODE_F1:
205
			EventShowInfo();
206
			return;
207
		case SCAN_CODE_ESC:
208
			search.hide();
209
			return;
210
		case SCAN_CODE_ENTER:
211
			if (! search_box.flags & ed_focus) return;
212
		case SCAN_CODE_F3:
213
			EventSearchNext();
214
			return;
215
	}
216
 
217
	if (search.edit_key()) return;
218
 
7921 leency 219
	if (key_modifier & KEY_LCTRL) || (key_modifier & KEY_RCTRL) {
220
		if (key.press(ECTRL + key_scancode)) return;
221
		switch (key_scancode)
222
		{
7941 leency 223
			case SCAN_CODE_KEY_A:
224
				selection.select_all();
225
				DrawPage();
226
				return;
7921 leency 227
			case SCAN_CODE_KEY_X:
228
				EventCut();
229
				return;
230
			case SCAN_CODE_KEY_C:
231
				EventCopy();
232
				return;
233
			case SCAN_CODE_KEY_V:
234
				EventPaste();
235
				return;
236
			case SCAN_CODE_UP:
237
				EventMagnifyPlus();
238
				return;
239
			case SCAN_CODE_DOWN:
240
				EventMagnifyMinus();
241
				return;
242
			case SCAN_CODE_TAB:
243
				EventShowCharsetsList();
244
				return;
245
			case SCAN_CODE_KEY_F:
246
				search.show();
247
				return;
248
		}
249
	}
7941 leency 250
 
251
	if (key_modifier & KEY_LSHIFT) || (key_modifier & KEY_RSHIFT) {
252
		selection.set_start();
7924 leency 253
	} else {
7941 leency 254
		selection.cancel();
7921 leency 255
	}
7941 leency 256
 
257
	if (list.ProcessKey(key_scancode)) {
258
		if (key_modifier & KEY_LSHIFT) || (key_modifier & KEY_RSHIFT) selection.set_end();
259
		DrawPage();
7945 leency 260
		return;
7941 leency 261
	}
7945 leency 262
	if(enable_edit) EventInsertCharIntoText();
7921 leency 263
}
264
 
265
void HandleMouseEvent()
266
{
267
	mouse.get();
268
	list.wheel_size = 7;
269
	if (list.MouseScroll(mouse.vert)) {
7924 leency 270
		DrawPage();
7921 leency 271
		return;
272
	}
273
	if (!scroll.delta2) && (list.MouseOver(mouse.x, mouse.y)) {
274
		if (mouse.key&MOUSE_LEFT) {
275
 
276
			GetKeyModifier();
277
			if (key_modifier & KEY_LSHIFT) || (key_modifier & KEY_RSHIFT) {
7924 leency 278
				if (mouse.down) selection.set_start();
7921 leency 279
				list.ProcessMouse(mouse.x, mouse.y);
280
				if (mouse.up) selection.set_end();
281
				DrawPage();
282
				return;
283
			}
284
 
7941 leency 285
			//as we have lines of variable width, we need to recalculate column_max
286
			list.column_max = lines.len(mouse.y - list.y / list.item_h + list.first);
287
 
7921 leency 288
			list.ProcessMouse(mouse.x, mouse.y);
7941 leency 289
 
7921 leency 290
			if (mouse.down) {
7924 leency 291
				selection.cancel();
7921 leency 292
				selection.set_start();
293
			}
294
			selection.set_end();
295
			DrawPage();
296
		}
297
		if (mouse.key&MOUSE_RIGHT) && (mouse.up) {
298
			EventShowRmbMenu();
299
		}
300
		return;
301
	}
302
	scrollbar_v_mouse (#scroll);
303
	if (list.first != scroll.position) {
304
		list.first = scroll.position;
305
		DrawPage();
306
	}
307
	search.edit_mouse();
308
}
309
 
310
//===================================================//
311
//                                                   //
312
//                      EVENTS                       //
313
//                                                   //
314
//===================================================//
315
 
316
bool EventSearchNext()
317
{
7975 leency 318
	int new_y = search.find_next(list.first+1);
7921 leency 319
	if (new_y) {
7945 leency 320
		list.first = new_y;
7921 leency 321
		list.CheckDoesValuesOkey();
7975 leency 322
		search_next = true;
323
		DrawPage();
7921 leency 324
	}
325
}
326
 
327
void EventNewFile()
328
{
329
	RunProgram(#program_path, "-new");
330
}
331
 
332
void EventOpenDialog()
333
{
334
	OpenDialog_start stdcall (#o_dialog);
335
	if (o_dialog.status) {
336
		LoadFile(#openfile_path);
337
		ParseAndPaint();
338
	}
339
}
340
 
341
void EventSave()
342
{
343
	int res;
344
	char backy_param[4096];
345
	if (io.buffer_data) {
346
		io.dir.make("/tmp0/1/quark_backups");
347
		sprintf(#backy_param, "%s -o /tmp0/1/quark_backups", #param);
348
		io.run("/sys/develop/backy", #backy_param);
349
		if (! io.write(#param, io.buffer_data) ) {
350
			notify(FILE_SAVED_WELL);
351
		} else {
352
			notify(FILE_NOT_SAVED);
353
		}
354
	}
355
}
356
 
357
void EventShowFileInfo()
358
{
359
	char ss_param[4096];
360
	if (!param) return;
361
	strcpy(#ss_param, "-p ");
362
	strcpy(#ss_param+3, #param);
363
	RunProgram("/sys/File managers/Eolite", #ss_param);
364
}
365
 
366
void EventMagnifyMinus()
367
{
368
	SetSizes('S');
369
	ParseAndPaint();
370
}
371
 
372
void EventMagnifyPlus()
373
{
374
	SetSizes('M');
375
	ParseAndPaint();
376
}
377
 
378
void EventShowCharsetsList()
379
{
380
	menu_id = CHANGE_CHARSET;
8020 leency 381
	open_lmenu(Form.cwidth-4, Form.cheight - 6, MENU_BOT_RIGHT,
382
		user_encoding+1,
7921 leency 383
		"UTF-8\nKOI8-RU\nCP1251\nCP1252\nISO8859-5\nCP866\nAUTO");
384
}
385
 
386
void EventShowReopenMenu()
387
{
388
	menu_id = REOPEN_IN_APP;
8020 leency 389
	open_lmenu(reopenin_mx + 23, 29, MENU_TOP_RIGHT, NULL,
7921 leency 390
		"Tinypad\nTextEdit\nWebView\nFB2Read\nHexView\nOther");
391
}
392
 
393
void EventShowThemesList()
394
{
395
	menu_id = COLOR_SCHEME;
8020 leency 396
	open_lmenu(theme_mx + 23, 29, MENU_TOP_RIGHT,
7921 leency 397
		curcol_scheme+1, #color_scheme_names);
398
}
399
 
400
void EventShowRmbMenu()
401
{
402
	menu_id = RMB_MENU;
8020 leency 403
	open_lmenu(mouse.x, mouse.y, MENU_TOP_LEFT, NULL, #rmb_menu);
7921 leency 404
}
405
 
406
 
407
void EventSetColorScheme(dword _setn)
408
{
409
	curcol_scheme = _setn;
7960 leency 410
	theme.bg      = color_schemes[curcol_scheme*6];
411
	theme.text    = color_schemes[curcol_scheme*6+1];
7921 leency 412
	scroll.bckg_col = theme.bg;
7960 leency 413
	scroll.frnt_col = scroll.line_col = color_schemes[curcol_scheme*6+2];
414
	selection.color = color_schemes[curcol_scheme*6+3];
415
	theme.cursor    = color_schemes[curcol_scheme*6+4];
416
	theme.found     = color_schemes[curcol_scheme*6+5];
7921 leency 417
	if (list.count) ParseAndPaint();
418
}
419
 
420
 
421
void EventShowInfo() {
422
	static dword shared_about;
423
	if (!shared_about) {
424
		shared_about = memopen("QUARK_ABOUT", sizeof(about)+1, SHM_OPEN_ALWAYS + SHM_READ);
425
		strcpy(shared_about, #about);
426
	}
427
	RunProgram("/sys/dialog", "-info 122 *QUARK_ABOUT");
428
}
429
 
430
void EventChangeCharset(dword id)
431
{
432
	if (param[0]=='\0') return;
433
	user_encoding = id;
7957 leency 434
	LoadFile(#param);
7921 leency 435
	ParseAndPaint();
436
	draw_window();
437
}
438
 
439
void EventOpenFileInOtherApp(dword _id)
440
{
441
	dword app;
442
	byte open_param[4096];
443
	switch(_id) {
444
		case 0: app = "/sys/tinypad"; break;
445
		case 1: app = "/sys/develop/t_edit"; break;
446
		case 2: app = "/sys/network/webview"; break;
447
		case 3: app = "/sys/fb2read"; break;
448
		case 4: app = "/sys/develop/heed"; break;
449
		case 5: open_param[0]='~';
450
			strcpy(#open_param+1,#param);
451
			RunProgram("/sys/@open", #open_param);
452
			return;
453
	}
454
	RunProgram(app, #param);
455
}
456
 
457
void EventMenuClick()
458
{
459
	dword click_id = get_menu_click();
460
 
461
	if (click_id) && (menu_id) switch(menu_id)
462
	{
463
		case CHANGE_CHARSET: EventChangeCharset(click_id-1); break;
464
		case REOPEN_IN_APP:  EventOpenFileInOtherApp(click_id-1); break;
465
		case COLOR_SCHEME:   EventSetColorScheme(click_id-1); break;
466
		case RMB_MENU:       EventRbmMenuClick(click_id-1); break;
467
		default: notify("'Error: wrong menu number'E");
468
	}
469
	menu_id = NULL;
470
}
471
 
472
void EventClickSearch()
473
{
474
	if (search.visible) {
475
		search.hide();
476
	} else {
477
		search.show();
478
	}
479
}
480
 
481
void EventInsertCharIntoText()
482
{
483
	dword cursor_pos = lines.get(list.cur_y) + list.cur_x;
484
 
485
	switch(key_scancode)
486
	{
487
		case SCAN_CODE_DOWN:
488
		case SCAN_CODE_UP:
489
		case SCAN_CODE_HOME:
490
		case SCAN_CODE_END:
491
		case SCAN_CODE_PGUP:
492
		case SCAN_CODE_PGDN:
493
		return;
494
		case SCAN_CODE_BS:
495
		case SCAN_CODE_DEL:
496
		notify("'Not supported yet'A");
497
		return;
498
	}
499
 
500
	if (list.cur_x >= list.column_max) return;
501
 
502
	ESBYTE[cursor_pos] = key_ascii;
503
	list.KeyRight();
504
	PaintVisible();
505
}
506
 
507
void EventOpenSysfuncs()
508
{
509
	if (io.run("/sys/docpack", "f") <= 0) {
510
		notify("'Can not open SysFunctions because\n/rd/1/docpack is not found!'E");
511
	}
512
}
513
 
514
void EventOpenPipet()
515
{
516
	io.run("/sys/develop/pipet", NULL);
517
}
518
 
519
void EventRbmMenuClick(dword id)
520
{
521
	switch(id) {
522
		case 0: EventCut(); break;
523
		case 1: EventCopy(); break;
524
		case 2: EventPaste(); break;
525
		case 3: EventRevealInFolder(); break;
526
		case 4: EventCopyFilePath(); break;
527
	}
528
}
529
 
530
void EventCut()
531
{
532
	//selection.copy();
533
}
534
 
535
void EventCopy()
536
{
537
	char copy_status_text[32];
538
 
539
	dword copy_buf;
540
	dword copy_len;
541
	dword copy_start;
542
	dword copy_end;
543
 
544
	if (selection.is_active()) {
545
		copy_start = selection.start_offset;
546
		copy_end = selection.end_offset;
547
		if (copy_start > copy_end) copy_start >< copy_end;
548
	} else {
549
		copy_start = lines.get(list.cur_y);
550
		copy_end = lines.get(list.cur_y+1);
551
	}
552
	copy_len = copy_end - copy_start;
553
	copy_buf = malloc(copy_len + 2);
554
	strncpy(copy_buf, copy_start, copy_len);
555
	ESBYTE[copy_buf+copy_len] = '\0';
556
	Clipboard__CopyText(copy_buf);
557
	free(copy_buf);
558
 
559
	sprintf(#copy_status_text, #copied_chars, copy_len);
560
	DrawStatusBar(#copy_status_text);
561
}
562
 
563
void EventPaste()
564
{
565
	//selection.copy();
566
}
567
 
568
void EventRevealInFolder()
569
{
570
	RunProgram("/sys/File managers/Eolite", #param);
571
}
572
 
573
void EventCopyFilePath()
574
{
575
	char copy_status_text[32];
576
	Clipboard__CopyText(#param);
577
	sprintf(#copy_status_text, #copied_chars, strlen(#param));
578
	DrawStatusBar(#copy_status_text);
579
}
580
 
7945 leency 581
void EventEnableEdit()
582
{
583
	enable_edit ^= 1;
584
	if (enable_edit) notify("'Edit mode is enabled.\nNow you can only replace text, not insert, nor delete.'I");
585
	draw_window();
586
}
587
 
7921 leency 588
//===================================================//
589
//                                                   //
590
//               DRAWS AND OTHER FUNCS               //
591
//                                                   //
592
//===================================================//
593
 
594
void EncodeToDos()
595
{
596
	real_encoding = user_encoding;
597
 
598
	// Autodetecting charset
599
	if (real_encoding == CH_AUTO) {
600
		real_encoding = CH_CP866;
601
		if (strstr(io.buffer_data, "\208\190")) real_encoding = CH_UTF8;
602
		else {
603
			if (chrnum(io.buffer_data, '\246')>5)
7957 leency 604
			|| (strstr(io.buffer_data, "\239\240")) real_encoding = CH_CP1251;
7921 leency 605
		}
606
	}
7957 leency 607
	if (real_encoding != CH_CP866) {
7921 leency 608
		ChangeCharset(real_encoding, "CP866", io.buffer_data);
7957 leency 609
	}
7921 leency 610
}
611
 
612
void LoadFile(dword f_path)
613
{
614
	if (io.buffer_data) free(io.buffer_data);
615
	if (ESBYTE[f_path]) {
616
		strcpy(#param, f_path);
617
		if (!io.read(#param)) goto NO_DATA;
618
		sprintf(#title, "%s - %s", #param, #short_app_name);
619
		EncodeToDos();
620
	}
621
	else {
622
		NO_DATA:
623
		io.buffer_data = malloc(sizeof(intro));
624
		strcpy(io.buffer_data, #intro);
625
		strcpy(#title, #short_app_name);
626
	}
627
	list.ClearList();
628
}
629
 
630
int AddTopBarButton(dword _event, _hotkey, char image_id, int x, pressed) {
631
	if (_hotkey) key.add_n(_hotkey, _event);
632
	return DrawTopPanelButton(button.add(_event), x, 5, image_id, pressed);
633
}
634
 
635
 
636
void DrawToolbar()
637
{
638
	#define SMALL_GAP 26+5
639
	#define BIG_GAP 26+18
640
	incn x;
641
	bool thema = false;
642
	bool reopa = false;
643
 
644
	bool serha = search.draw(BTN_FIND_NEXT+10, BTN_FIND_CLOSE+10, Form.cheight - SEARCH_H - STATUSBAR_H);
645
	if (menu_id == COLOR_SCHEME) thema = true;
646
	if (menu_id == REOPEN_IN_APP) reopa = true;
647
 
648
	DrawBar(0, 0, Form.cwidth, TOOLBAR_H - 1, sc.work);
649
	DrawBar(0, TOOLBAR_H - 1, Form.cwidth, 1, sc.work_graph);
650
 
7945 leency 651
	x.set(-SMALL_GAP+8);
652
	if(enable_edit) AddTopBarButton(#EventNewFile,        ECTRL+SCAN_CODE_KEY_N, 2,  x.inc(SMALL_GAP), false);
653
	                AddTopBarButton(#EventOpenDialog,     ECTRL+SCAN_CODE_KEY_O, 0,  x.inc(SMALL_GAP), false);
654
	if(enable_edit) && (param[0]) AddTopBarButton(#EventSave,           ECTRL+SCAN_CODE_KEY_S, 5,  x.inc(SMALL_GAP), false);
655
	                AddTopBarButton(#EventShowFileInfo,   ECTRL+SCAN_CODE_KEY_I, 10, x.inc(SMALL_GAP), false);
656
	                AddTopBarButton(#EventMagnifyMinus,   ECTRL+SCAN_CODE_MINUS, 33, x.inc(BIG_GAP),   false);
657
	                AddTopBarButton(#EventMagnifyPlus,    ECTRL+SCAN_CODE_PLUS,  32, x.inc(SMALL_GAP), false);
658
	                AddTopBarButton(#EventClickSearch,    ECTRL+SCAN_CODE_KEY_F, 49, x.inc(BIG_GAP),   serha);  search_mx = EAX;
7921 leency 659
	x.set(Form.cwidth-4);
7945 leency 660
	                AddTopBarButton(#EventEnableEdit,       NULL,                  38, x.inc(-SMALL_GAP), enable_edit);
661
	//if(enable_edit) AddTopBarButton(#EventShowInfo,       NULL,                  -1, x.inc(-SMALL_GAP), false); burger_mx = EAX;
662
	                AddTopBarButton(#EventShowThemesList, NULL,                  40, x.inc(-BIG_GAP), thema); theme_mx = EAX;
663
	                AddTopBarButton(#EventShowReopenMenu, ECTRL+SCAN_CODE_KEY_E, 16, x.inc(-SMALL_GAP),   reopa); reopenin_mx = EAX;
664
	if(enable_edit) AddTopBarButton(#EventOpenSysfuncs,   NULL,                  18, x.inc(-SMALL_GAP), false);
665
	if(enable_edit) AddTopBarButton(#EventOpenPipet,      NULL,                  39, x.inc(-SMALL_GAP), false);
7921 leency 666
}
667
 
668
void DrawStatusBar(dword _in_text)
669
{
670
	static char status_text[64];
671
	if (Form.status_window>2) return;
672
	if (_in_text) strncpy(#status_text, _in_text, sizeof(status_text));
673
	DrawBar(0,Form.cheight - STATUSBAR_H, Form.cwidth,1, sc.work_graph);
674
	DrawBar(0,Form.cheight - STATUSBAR_H+1, Form.cwidth,STATUSBAR_H-1, sc.work);
675
	WriteText(5, Form.cheight - STATUSBAR_H + 4, 0x80, sc.work_text, #status_text);
7924 leency 676
	if (param[0]) {
677
		WriteTextCenter(Form.cwidth-70, Form.cheight - STATUSBAR_H + 4,
678
			60, sc.work_text, real_encoding*10+#charsets);
679
		DefineHiddenButton(Form.cwidth-70, Form.cheight - STATUSBAR_H + 1,
680
			60, 12, BTN_CHANGE_CHARSET+10);
681
	}
7921 leency 682
}
683
 
684
void draw_window()
685
{
686
	int old_w = list.w;
687
	DefineAndDrawWindow(Form.left,Form.top,Form.width,Form.height,0x73,0,#title,0);
688
	GetProcessInfo(#Form, SelfInfo);
689
	sc.get();
690
	if (Form.status_window>2) return;
7975 leency 691
	if (Form.width  < 450) { MoveSize(OLD,OLD,450,OLD); return; }
7921 leency 692
	if (Form.height < 200) { MoveSize(OLD,OLD,OLD,200); return; }
693
 
694
	button.init(40);
695
	key.init(40);
696
 
697
	SetSizes(font_size);
698
 
699
	if ((list.w == old_w) && (list.count)) {
700
		DrawPage();
701
	} else {
702
		ParseAndPaint();
703
	}
704
 
705
	DrawToolbar();
706
	DrawStatusBar(NULL);
707
}
708
 
709
void DrawPage()
710
{
711
	scroll.max_area = list.count;
712
	scroll.cur_area = list.visible;
713
	scroll.position = list.first;
714
	scroll.all_redraw = 0;
715
	scroll.start_x = list.x + list.w;
716
	scroll.start_y = list.y;
717
	scroll.size_y = list.h;
718
	scrollbar_v_draw(#scroll);
719
 
720
	DrawRectangle(scroll.start_x, scroll.start_y, scroll.size_x,
721
		scroll.size_y-1, scroll.bckg_col);
722
	PaintVisible();
723
}
724
 
725
 
726
void SetSizes(char _size)
727
{
728
	font_size = _size;
729
	if (font_size == 'S') list.SetFont(6, 9, 00001000b);
730
	if (font_size == 'M') list.SetFont(8, 14, 00011000b);
731
	list.item_w = list.font_w;
732
	list.horisontal_selelection = true;
733
	list.SetSizes(0, TOOLBAR_H, Form.cwidth-scroll.size_x-1,
7945 leency 734
		Form.cheight - TOOLBAR_H - calc(search.visible * SEARCH_H) - STATUSBAR_H /*- TAB_H*/,
7921 leency 735
		math.round(list.font_h * 1.4));
736
}