Subversion Repositories Kolibri OS

Rev

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