Subversion Repositories Kolibri OS

Rev

Rev 9602 | Details | Compare with Previous | Last modification | View Log | RSS feed

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