Subversion Repositories Kolibri OS

Rev

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

Rev Author Line No. Line
7739 leency 1
//Copyright 2007-2020 by Veliant & Leency
6978 leency 2
//Asper, lev, Lrz, Barsuk, Nable, hidnplayr...
3067 leency 3
 
4085 leency 4
#ifndef AUTOBUILD
5
	#include "lang.h--"
6
#endif
7
 
3107 leency 8
//libraries
7771 leency 9
#define MEMSIZE 1024 * 1000
5499 leency 10
#include "..\lib\gui.h"
4508 leency 11
#include "..\lib\draw_buf.h"
12
#include "..\lib\list_box.h"
13
#include "..\lib\cursor.h"
5978 leency 14
#include "..\lib\collection.h"
6795 leency 15
#include "..\lib\random.h"
7037 leency 16
#include "..\lib\clipboard.h"
5981 leency 17
 
7437 leency 18
// *.obj libraries
5499 leency 19
#include "..\lib\obj\box_lib.h"
7049 leency 20
#include "..\lib\obj\libio.h"
21
#include "..\lib\obj\libimg.h"
5499 leency 22
#include "..\lib\obj\http.h"
5690 leency 23
#include "..\lib\obj\iconv.h"
7748 leency 24
#include "..\lib\obj\proc_lib.h"
7757 leency 25
 
5408 leency 26
//useful patterns
5978 leency 27
#include "..\lib\patterns\history.h"
6058 leency 28
#include "..\lib\patterns\http_downloader.h"
7748 leency 29
#include "..\lib\patterns\simple_open_dialog.h"
7759 leency 30
#include "..\lib\patterns\toolbar_button.h"
5408 leency 31
 
7771 leency 32
#include "texts.h"
33
#include "cache.h"
7757 leency 34
#include "show_src.h"
35
#include "download_manager.h"
7771 leency 36
 
7757 leency 37
bool debug_mode = false;
7771 leency 38
 
7759 leency 39
#include "..\TWB\TWB.c" //HTML Parser, a core component
7757 leency 40
 
7759 leency 41
TWebBrowser WB1;
7771 leency 42
_history history;
7758 leency 43
 
7771 leency 44
#include "history.h"
7752 leency 45
 
7758 leency 46
#define PADDING 9
47
#define TSZE 25
7771 leency 48
#define STATUSBAR_H 15
49
#define TAB_H 20
7758 leency 50
dword TOOLBAR_H = PADDING+TSZE+PADDING+2;
4677 leency 51
 
7771 leency 52
#define URL_SIZE 4000
53
 
7750 leency 54
int action_buf;
7425 leency 55
 
7759 leency 56
_http http = 0;
7758 leency 57
 
7750 leency 58
bool source_mode = false;
7282 leency 59
 
5718 leency 60
progress_bar wv_progress_bar;
7750 leency 61
char stak[4096];
62
proc_info Form;
7748 leency 63
 
7780 leency 64
int menu_id=NULL;
65
 
5718 leency 66
enum {
7771 leency 67
	NEW_TAB=600,
68
	ENCODINGS=700,
69
	BACK_BUTTON=800,
5718 leency 70
	FORWARD_BUTTON,
71
	REFRESH_BUTTON,
72
	GOTOURL_BUTTON,
7759 leency 73
	CHANGE_ENCODING,
6795 leency 74
	SANDWICH_BUTTON,
7750 leency 75
	VIEW_SOURCE,
5718 leency 76
	EDIT_SOURCE,
7758 leency 77
	OPEN_FILE,
78
	NEW_WINDOW,
5718 leency 79
	VIEW_HISTORY,
6795 leency 80
	DOWNLOAD_MANAGER,
7770 leency 81
	CLEAR_CACHE,
7765 leency 82
	UPDATE_BROWSER,
7750 leency 83
	COPY_LINK_URL,
7208 leency 84
	DOWNLOAD_LINK_CONTENTS,
7771 leency 85
	TAB_ID,
86
	TAB_CLOSE_ID = 900
5718 leency 87
};
88
 
7771 leency 89
#include "tabs.h"
90
 
7748 leency 91
char default_dir[] = "/rd/1";
7788 leency 92
od_filter filter2 = { 22, "TXT\0HTM\0HTML\0DOCX\0\0" };
7748 leency 93
 
7755 leency 94
char editURL[URL_SIZE+1];
7758 leency 95
edit_box address_box = {, PADDING+TSZE*2+PADDING+6, PADDING+3, 0xffffff,
96
	0x94AECE, 0xffffff, 0xffffff,0x10000000,URL_SIZE-2,#editURL,0,,19,19};
4534 leency 97
 
7784 leency 98
char editbox_icons[] = FROM "editbox_icons.raw";
4534 leency 99
 
7784 leency 100
 
7748 leency 101
void LoadLibraries()
102
{
103
	load_dll(boxlib,    #box_lib_init,0);
104
	load_dll(libio,     #libio_init,1);
105
	load_dll(libimg,    #libimg_init,1);
106
	load_dll(libHTTP,   #http_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 HandleParam()
113
{
114
	if (param) {
7765 leency 115
		if (!strncmp(#param, "-download_and_exit ", 19)) {
116
			download_and_exit = true;
117
			strcpy(#downloader_edit, #param+19);
118
			Downloader();
7748 leency 119
			ExitProcess();
7765 leency 120
		} else if (!strncmp(#param, "-download ", 10)) {
121
			strcpy(#downloader_edit, #param+10);
122
			//CreateThread(#Downloader,#downloader_stak+4092);
123
			Downloader();
124
			ExitProcess();
125
		} else if (!strncmp(#param, "-source ", 8)) {
7750 leency 126
			source_mode = true;
7765 leency 127
			history.add(#param + 8);
7748 leency 128
		} else {
7755 leency 129
			history.add(#param);
7748 leency 130
		}
131
	} else {
7755 leency 132
		history.add(URL_SERVICE_HOMEPAGE);
7748 leency 133
	}
134
}
135
 
3067 leency 136
void main()
137
{
7758 leency 138
	int i, btn, redirect_count=0;
7748 leency 139
	LoadLibraries();
7762 leency 140
	CreateDir("/tmp0/1/Downloads");
7764 leency 141
	//CreateDir("/tmp0/1/WebView_Cache");
7748 leency 142
	HandleParam();
6045 leency 143
	WB1.list.SetFont(8, 14, 10011000b);
5779 leency 144
	WB1.list.no_selection = true;
7759 leency 145
	WB1.custom_encoding = -1;
6978 leency 146
	SetEventMask(EVM_REDRAW + EVM_KEY + EVM_BUTTON + EVM_MOUSE + EVM_MOUSE_FILTER + EVM_STACK);
147
	loop() switch(WaitEvent())
148
	{
149
		case evMouse:
150
			edit_box_mouse stdcall (#address_box);
151
			mouse.get();
7757 leency 152
			if (PageLinks.HoverAndProceed(mouse.x, WB1.list.first + mouse.y, WB1.list.y, WB1.list.first))
7755 leency 153
			&& (mouse.pkm) && (mouse.up) {
7770 leency 154
				if (WB1.list.MouseOver(mouse.x, mouse.y)) EventShowPageMenu();
7282 leency 155
				break;
6978 leency 156
			}
7282 leency 157
			if (WB1.list.MouseScroll(mouse.vert)) WB1.DrawPage();
6978 leency 158
			scrollbar_v_mouse (#scroll_wv);
159
			if (WB1.list.first != scroll_wv.position)
160
			{
161
				WB1.list.first = scroll_wv.position;
162
				WB1.DrawPage();
3067 leency 163
				break;
6978 leency 164
			}
7758 leency 165
			if (mouse.up) && (! address_box.flags & ed_focus) && (address_box.flags & ed_shift_bac)
166
			{
167
				DrawOmnibox(); //reset text selection
168
			}
6978 leency 169
			break;
5711 leency 170
 
6978 leency 171
		case evButton:
7758 leency 172
			btn = GetButtonID();
173
			if (1==btn) ExitProcess(); else ProcessEvent(btn);
6978 leency 174
			break;
5711 leency 175
 
6978 leency 176
		case evKey:
177
			GetKeys();
7771 leency 178
			//if (key_scancode == SCAN_CODE_F1) {DebugTabs();break;}
179
 
180
			if (key_modifier&KEY_LSHIFT) || (key_modifier&KEY_RSHIFT) {
181
				if (key_scancode == SCAN_CODE_TAB) {EventActivatePreviousTab();break;}
182
			}
183
 
7772 leency 184
			if (ProcessCtrlKeyEvent()) break;
7743 leency 185
 
186
			if (key_scancode == SCAN_CODE_F5) ProcessEvent(REFRESH_BUTTON);
187
 
7506 leency 188
			if (address_box.flags & ed_focus)
6978 leency 189
			{
7742 leency 190
				if (key_scancode == SCAN_CODE_ENTER) {
191
					ProcessEvent(key_scancode);
7771 leency 192
				} else {
6978 leency 193
					EAX = key_editbox;
194
					edit_box_key stdcall(#address_box);
5530 leency 195
				}
7771 leency 196
			} else {
7422 leency 197
				#define KEY_SCROLL_N 11
198
				if (SCAN_CODE_UP   == key_scancode) for (i=0;i
199
				if (SCAN_CODE_DOWN == key_scancode) for (i=0;i
7743 leency 200
				if (key_scancode == SCAN_CODE_F6) {address_box.flags=ed_focus; DrawOmnibox();}
6978 leency 201
				if (WB1.list.ProcessKey(key_scancode)) WB1.DrawPage();
202
				else ProcessEvent(key_scancode);
203
			}
204
			break;
205
 
206
		case evReDraw:
7780 leency 207
			DefineAndDrawWindow(GetScreenWidth()-800/2-random(80), //40
7755 leency 208
				GetScreenHeight()-700/2-random(80),800,700,0x73,0,0,0);
6978 leency 209
			GetProcessInfo(#Form, SelfInfo);
7780 leency 210
			ProcessMenuClick();
7748 leency 211
			system.color.get();
7759 leency 212
			if (Form.status_window>2) break;
6978 leency 213
			if (Form.height<120) { MoveSize(OLD,OLD,OLD,120); break; }
214
			if (Form.width<280) { MoveSize(OLD,OLD,280,OLD); break; }
7748 leency 215
			draw_window();
6978 leency 216
			break;
217
 
218
		case evNetwork:
7758 leency 219
			if (http.transfer <= 0) break;
220
			http.receive();
221
			EventUpdateProgressBar();
222
			if (http.receive_result != 0) break;
223
			if (http.status_code >= 300) && (http.status_code < 400)
224
			{
225
				// Handle redirects
226
				if (redirect_count<=5) {
227
					redirect_count++;
228
					http.handle_redirect();
7282 leency 229
					http.free();
7758 leency 230
					GetAbsoluteURL(#http.redirect_url, history.current());
231
					history.back();
232
					OpenPage(#http.redirect_url);
233
				} else {
234
					notify("'Too many redirects.' -E");
235
					StopLoading();
4536 leency 236
				}
7758 leency 237
			} else {
238
				// Loading the page is complete, free resources
239
				redirect_count = 0;
240
				http.free();
7764 leency 241
				pages_cache.add(history.current(), http.content_pointer, http.content_received);
7758 leency 242
				LoadInternalPage(http.content_pointer, http.content_received);
6978 leency 243
			}
244
	}
3067 leency 245
}
246
 
7772 leency 247
bool ProcessCtrlKeyEvent()
248
{
249
	if (key_modifier&KEY_LCTRL) || (key_modifier&KEY_RCTRL) switch(key_scancode)
250
	{
251
		case SCAN_CODE_KEY_O:
252
			EventOpenDialog();
253
			return true;
254
		case SCAN_CODE_KEY_H:
255
			ProcessEvent(VIEW_HISTORY);
256
			return true;
257
		case SCAN_CODE_KEY_U:
258
			EventViewSource();
259
			return true;
260
		case SCAN_CODE_KEY_T:
261
			EventOpenNewTab(URL_SERVICE_HOMEPAGE);
262
			return true;
263
		case SCAN_CODE_KEY_N:
264
			RunProgram(#program_path, NULL);
265
			return true;
266
		case SCAN_CODE_KEY_J:
267
			ProcessEvent(DOWNLOAD_MANAGER);
268
			return true;
269
		case SCAN_CODE_KEY_R:
270
			ProcessEvent(REFRESH_BUTTON);
271
			return true;
272
		case SCAN_CODE_ENTER:
273
			EventSeachWeb();
274
			return true;
275
		case SCAN_CODE_LEFT:
276
			 ProcessEvent(BACK_BUTTON);
277
			 return true;
278
		case SCAN_CODE_RIGHT:
279
			ProcessEvent(FORWARD_BUTTON);
280
			return true;
281
		case SCAN_CODE_KEY_W:
282
			EventCloseActiveTab();
283
			return true;
284
		case SCAN_CODE_TAB:
285
			EventActivateNextTab();
286
			return true;
287
	}
288
	return false;
289
}
290
 
3067 leency 291
void SetElementSizes()
292
{
7758 leency 293
	address_box.width = Form.cwidth - address_box.left - 52 - 16;
7771 leency 294
	WB1.list.SetSizes(0, TOOLBAR_H+TAB_H, Form.width - 10 - scroll_wv.size_x,
295
		Form.cheight - TOOLBAR_H - STATUSBAR_H - TAB_H, BASIC_LINE_H);
7759 leency 296
	WB1.list.wheel_size = 7 * BASIC_LINE_H;
7746 leency 297
	WB1.list.column_max = WB1.list.w - scroll_wv.size_x / WB1.list.font_w + 1;
6794 leency 298
	WB1.list.visible = WB1.list.h;
3067 leency 299
}
300
 
5981 leency 301
 
7748 leency 302
void draw_window()
3067 leency 303
{
7758 leency 304
	int i;
3067 leency 305
	SetElementSizes();
7758 leency 306
 
307
	DrawBar(0,0, Form.cwidth,PADDING, system.color.work);
308
	DrawBar(0,PADDING+TSZE+1, Form.cwidth,PADDING-1, system.color.work);
7771 leency 309
	DrawBar(0,TOOLBAR_H-2, Form.cwidth,1, MixColors(system.color.work_dark, system.color.work, 180));
7758 leency 310
	DrawBar(0,TOOLBAR_H-1, Form.cwidth,1, system.color.work_graph);
311
	DrawBar(0, PADDING, address_box.left-2, TSZE+1, system.color.work);
312
	DrawBar(address_box.left+address_box.width+18, PADDING, Form.cwidth-address_box.left-address_box.width-18, TSZE+1, system.color.work);
313
 
7759 leency 314
	DrawTopPanelButton(BACK_BUTTON, PADDING-1, PADDING, 30);
315
	DrawTopPanelButton(FORWARD_BUTTON, PADDING+TSZE+PADDING-2, PADDING, 31);
316
	DrawTopPanelButton(SANDWICH_BUTTON, Form.cwidth-PADDING-TSZE-3, PADDING, -1);
7758 leency 317
	for (i=0; i<=2; i++) DrawBar(Form.cwidth-PADDING-TSZE+3, i*5+PADDING+7, 15, 3, system.color.work_graph);
318
 
319
	DrawBar(0,Form.cheight - STATUSBAR_H, Form.cwidth,1, system.color.work_graph);
320
 
321
	DrawRectangle(WB1.list.x + WB1.list.w, WB1.list.y, scroll_wv.size_x,
322
		WB1.list.h-1, scroll_wv.bckg_col);
323
 
7771 leency 324
	if (!BrowserWidthChanged()) {
325
		WB1.DrawPage();
326
		DrawOmnibox();
327
	}
328
	DrawProgress();
329
	DrawStatusBar(NULL);
330
	DrawTabsBar();
331
}
332
 
333
bool BrowserWidthChanged()
334
{
335
	dword source_mode_holder;
336
	if (WB1.list.w!=DrawBuf.bufw) {
337
		DrawBuf.Init(WB1.list.x, WB1.list.y, WB1.list.w, 400*20);
7758 leency 338
		if (!strncmp(history.current(),"http",4)) {
7759 leency 339
			//nihuya ne izyashnoe reshenie, no pust' poka butet tak
7771 leency 340
			source_mode_holder = source_mode;
7758 leency 341
			LoadInternalPage(#loading_text, sizeof(loading_text));
7771 leency 342
			source_mode = source_mode_holder;
7758 leency 343
		}
344
		OpenPage(history.current());
7771 leency 345
		return true;
7282 leency 346
	}
7771 leency 347
	return false;
3067 leency 348
}
349
 
7771 leency 350
 
7759 leency 351
void EventChangeEncodingAndLoadPage(int _new_encoding)
352
{
353
	dword newbuf, newsize;
354
	WB1.custom_encoding = _new_encoding;
355
	newsize = strlen(WB1.o_bufpointer);
356
	newbuf = malloc(newsize);
357
	memmov(newbuf, WB1.o_bufpointer, newsize);
358
	LoadInternalPage(newbuf, newsize);
359
	free(newbuf);
360
}
3067 leency 361
 
7759 leency 362
 
6698 leency 363
void ProcessEvent(dword id__)
4413 leency 364
{
6698 leency 365
	switch (id__)
4413 leency 366
	{
7759 leency 367
		case ENCODINGS...ENCODINGS+6:
368
			EventChangeEncodingAndLoadPage(id__-ENCODINGS);
369
			return;
7758 leency 370
		case NEW_WINDOW:
371
			RunProgram(#program_path, NULL);
6698 leency 372
			return;
5711 leency 373
		case SCAN_CODE_BS:
5718 leency 374
		case BACK_BUTTON:
6021 leency 375
			if (history.back()) {
7755 leency 376
				OpenPage(history.current());
5978 leency 377
			}
5711 leency 378
			return;
5718 leency 379
		case FORWARD_BUTTON:
6021 leency 380
			if (history.forward()) {
7755 leency 381
				OpenPage(history.current());
5978 leency 382
			}
5711 leency 383
			return;
5718 leency 384
		case GOTOURL_BUTTON:
5772 leency 385
		case SCAN_CODE_ENTER:
7742 leency 386
			EventSubmitOmnibox();
5711 leency 387
			return;
5718 leency 388
		case REFRESH_BUTTON:
7771 leency 389
			if (http.transfer) {
5713 leency 390
				StopLoading();
7748 leency 391
				draw_window();
7755 leency 392
			} else {
393
				OpenPage(history.current());
5713 leency 394
			}
395
			return;
7759 leency 396
		case CHANGE_ENCODING:
7770 leency 397
			EventShowEncodingsList();
7759 leency 398
			return;
5718 leency 399
		case SANDWICH_BUTTON:
7770 leency 400
			EventShowMainMenu();
4415 leency 401
			return;
5718 leency 402
		case VIEW_SOURCE:
7750 leency 403
			EventViewSource();
5718 leency 404
			break;
405
		case EDIT_SOURCE:
7755 leency 406
			if (check_is_the_adress_local(history.current())) {
407
				RunProgram("/rd/1/tinypad", history.current());
7750 leency 408
			} else {
7759 leency 409
				CreateFile(WB1.bufsize, WB1.bufpointer, "/tmp0/1/WebView_tmp.htm");
5718 leency 410
				if (!EAX) RunProgram("/rd/1/tinypad", "/tmp0/1/WebView_tmp.htm");
411
			}
4415 leency 412
			return;
5718 leency 413
		case VIEW_HISTORY:
7755 leency 414
			OpenPage(URL_SERVICE_HISTORY);
4544 leency 415
			return;
5718 leency 416
		case DOWNLOAD_MANAGER:
5519 leency 417
			if (!downloader_opened) {
6001 leency 418
				downloader_edit = NULL;
5519 leency 419
				CreateThread(#Downloader,#downloader_stak+4092);
420
			}
4413 leency 421
			return;
7765 leency 422
		case UPDATE_BROWSER:
423
			EventUpdateBrowser();
424
			return;
7770 leency 425
		case CLEAR_CACHE:
426
			pages_cache.clear();
427
			notify(#clear_cache_ok);
428
			return;
7282 leency 429
		case COPY_LINK_URL:
7037 leency 430
			Clipboard__CopyText(PageLinks.GetURL(PageLinks.active));
431
			notify("'URL copied to clipboard'O");
432
			return;
7208 leency 433
		case DOWNLOAD_LINK_CONTENTS:
434
			if (!downloader_opened) {
435
				strcpy(#downloader_edit, PageLinks.GetURL(PageLinks.active));
436
				CreateThread(#Downloader,#downloader_stak+4092);
437
			}
438
			return;
7758 leency 439
		case OPEN_FILE:
440
			EventOpenDialog();
441
			return;
7282 leency 442
		case SCAN_CODE_F12:
443
			debug_mode ^= 1;
444
			if (debug_mode) notify("'Debug mode ON'-I");
445
			else notify("'Debug mode OFF'-I");
446
			return;
7771 leency 447
		case NEW_TAB:
448
			if (http.transfer) break;
449
			EventOpenNewTab(URL_SERVICE_HOMEPAGE);
450
			return;
451
		case TAB_ID...TAB_ID+TABS_MAX:
452
			if (http.transfer) break;
453
			if (mouse.mkm) {
454
				EventTabClose(id__ - TAB_ID);
455
			} else {
456
				EventTabClick(id__ - TAB_ID);
457
			}
458
			return;
459
		case TAB_CLOSE_ID...TAB_CLOSE_ID+TABS_MAX:
460
			EventTabClose(id__ - TAB_CLOSE_ID);
461
			return;
4413 leency 462
	}
463
}
464
 
4636 leency 465
void StopLoading()
466
{
7281 leency 467
	if (http.transfer)
4647 leency 468
	{
7281 leency 469
		EAX = http.transfer;
4647 leency 470
		EAX = EAX.http_msg.content_ptr;		// get pointer to data
471
		$push	EAX							// save it on the stack
7281 leency 472
		http_free stdcall (http.transfer);	// abort connection
4647 leency 473
		$pop	EAX
5631 pavelyakov 474
		free(EAX);						// free data
7281 leency 475
		http.transfer=0;
7746 leency 476
		pause(10);
4647 leency 477
	}
5519 leency 478
	wv_progress_bar.value = 0;
7743 leency 479
	DrawOmnibox();
4645 leency 480
}
481
 
7756 leency 482
//rewrite into
7757 leency 483
//bool strrpl(dword dst, from, into, dst_len);
484
bool ReplaceSpaceInUrl(dword url, size) {
7756 leency 485
	unsigned int i, j;
7757 leency 486
	bool was_changed=false;
487
	for (i=url+size-3; i>url; i--)
7720 leency 488
	{
7756 leency 489
		if (ESBYTE[i]!=' ') continue;
7757 leency 490
		for (j=url+size-3; j>=i; j--) {
491
			ESBYTE[j+3]=ESBYTE[j+2];
7756 leency 492
			ESBYTE[j+2]=ESBYTE[j+1];
493
			ESBYTE[j+1]=ESBYTE[j];
494
		}
495
		ESBYTE[i] = '%';
496
		ESBYTE[i+1] = '2';
497
		ESBYTE[i+2] = '0';
7757 leency 498
		was_changed = true;
7720 leency 499
	}
7757 leency 500
	return was_changed;
7720 leency 501
}
502
 
7755 leency 503
bool GetLocalFileData(dword _path)
4416 leency 504
{
7755 leency 505
	dword data, size;
506
	file_size stdcall (_path);
507
	if (!EBX) {
508
		return false;
509
	} else {
510
		size = EBX;
511
		data = malloc(size);
512
		ReadFile(0, size, data, _path);
513
		LoadInternalPage(data, size);
514
		free(data);
515
		return true;
4692 leency 516
	}
7755 leency 517
}
7282 leency 518
 
7755 leency 519
void OpenPage(dword _open_URL)
520
{
521
	char new_url[URL_SIZE+1];
7788 leency 522
	int unz_id;
7755 leency 523
 
524
	StopLoading();
525
 
7771 leency 526
	if (open_new_tab) {
527
		open_new_tab = false;
528
		EventOpenNewTab(_open_URL);
529
		return;
530
	}
7755 leency 531
 
7771 leency 532
	SetOmniboxText(_open_URL);
533
 
7755 leency 534
	strncpy(#new_url, _open_URL, URL_SIZE);
535
 
536
	//Exclude # from the URL to the load page
537
	//We will bring it back when we get the buffer
538
	if (strrchr(#new_url, '#')) anchors.take_anchor_from(#new_url);
539
 
540
	history.add(#new_url);
541
 
7764 leency 542
	if (pages_cache.has(#new_url)) {
543
		//CACHED PAGE
544
		LoadInternalPage(pages_cache.current_page_buf, pages_cache.current_page_size);
545
 
546
	} else if (!strncmp(#new_url,"WebView:",8)) {
7755 leency 547
		//INTERNAL PAGE
548
		if (!strcmp(#new_url, URL_SERVICE_HOMEPAGE)) LoadInternalPage(#homepage, sizeof(homepage));
549
		else if (!strcmp(#new_url, URL_SERVICE_HELP)) LoadInternalPage(#help, sizeof(help));
550
		else if (!strcmp(#new_url, URL_SERVICE_HISTORY)) ShowHistory();
551
		else LoadInternalPage(#page_not_found, sizeof(page_not_found));
7764 leency 552
 
7755 leency 553
	} else if (!strncmp(#new_url,"http:",5)) || (!strncmp(#new_url,"https:",6)) {
554
		//WEB PAGE
7757 leency 555
		if (ReplaceSpaceInUrl(#new_url, URL_SIZE)) {
556
			strcpy(#editURL, #new_url);
557
		}
558
 
7755 leency 559
		if (!strncmp(#new_url,"http:",5)) {
560
			http.get(#new_url);
561
		} else if (!strncmp(#new_url,"https://",8)) {
562
			strcpy(#new_url, "http://gate.aspero.pro/?site=");
563
			strncat(#new_url, _open_URL, URL_SIZE);
564
			http.get(#new_url);
7282 leency 565
		}
7758 leency 566
 
567
		DrawOmnibox();
568
 
7755 leency 569
		if (!http.transfer) {
4646 leency 570
			StopLoading();
7755 leency 571
			LoadInternalPage(#page_not_found, sizeof(page_not_found));
4646 leency 572
		}
7755 leency 573
	} else {
574
		//LOCAL PAGE
7788 leency 575
		if (UrlExtIs(#new_url,".docx")) {
576
			DeleteFile("/tmp0/1/temp/word/document.xml");
577
			CreateDir("/tmp0/1/temp");
578
			unz_id = RunProgram("/sys/unz", sprintf(#param, "-o \"/tmp0/1/temp\" -h \"%s\"", #new_url));
579
			while (GetProcessSlot(unz_id)) pause(2);
580
			strcpy(#new_url, "/tmp0/1/temp/word/document.xml");
581
		}
7755 leency 582
		if (!GetLocalFileData(#new_url)) {
583
			LoadInternalPage(#page_not_found, sizeof(page_not_found));
4650 leency 584
		}
4636 leency 585
	}
4416 leency 586
}
4415 leency 587
 
7755 leency 588
void EventClickLink(dword _click_URL)
4508 leency 589
{
7756 leency 590
	char new_url[URL_SIZE+1];
4415 leency 591
 
7758 leency 592
	if (open_new_window) {
593
		strcpy(#new_url, _click_URL);
594
		GetAbsoluteURL(#new_url, history.current());
595
		RunProgram(#program_path, #new_url);
596
		return;
597
	}
598
 
7755 leency 599
	if (ESBYTE[_click_URL]=='#') {
600
		if (anchors.get_pos_by_name(_click_URL+1)!=-1) {
601
			WB1.list.first = anchors.get_pos_by_name(_click_URL+1);
602
			WB1.list.CheckDoesValuesOkey();
603
		}
604
		strcpy(#editURL, history.current());
605
		strcat(#editURL, _click_URL);
606
		DrawOmnibox();
607
		WB1.DrawPage();
608
		return;
5768 leency 609
	}
7742 leency 610
 
7755 leency 611
	if (!strncmp(_click_URL,"mailto:", 7)) || (!strncmp(_click_URL,"tel:", 4)) {
612
		notify(_click_URL);
613
		return;
7742 leency 614
	}
4508 leency 615
 
7771 leency 616
	if (http.transfer) {
5774 leency 617
		StopLoading();
6021 leency 618
		history.back();
5774 leency 619
	}
6730 leency 620
 
7755 leency 621
	strcpy(#new_url, _click_URL);
7757 leency 622
	GetAbsoluteURL(#new_url, history.current());
7755 leency 623
 
624
	if (strrchr(#new_url, '#')!=0) {
625
		anchors.take_anchor_from(#new_url);
626
		OpenPage(#new_url);
6730 leency 627
		return;
628
	}
629
 
7755 leency 630
	if (!strncmp(#new_url,"WebView:",8)) {
631
		OpenPage(#new_url);
7742 leency 632
		return;
633
	}
6730 leency 634
 
7755 leency 635
	if (strncmp(#new_url,"http://",7)!=0) && (strncmp(#new_url,"https://",8)!=0)
5774 leency 636
	{
7755 leency 637
		if (UrlExtIs(#new_url,".htm")!=true) && (UrlExtIs(#new_url,".html")!=true)
6730 leency 638
		{
7755 leency 639
			if (strchr(#new_url, '|')) {
640
				ESBYTE[strchr(#new_url, '|')] = NULL;
641
				RunProgram(#new_url, strlen(#new_url)+1+#new_url);
642
			} else {
643
				RunProgram("/sys/@open", #new_url);
7422 leency 644
			}
6730 leency 645
			return;
646
		}
7755 leency 647
	} else {
648
		if (UrlExtIs(#new_url,".png")==true) || (UrlExtIs(#new_url,".jpg")==true)
649
		|| (UrlExtIs(#new_url,".zip")==true) || (UrlExtIs(#new_url,".kex")==true) || (UrlExtIs(#new_url,".pdf")==true)
650
		|| (UrlExtIs(#new_url,".7z")==true) {
6986 leency 651
			if (!downloader_opened) {
7755 leency 652
				strcpy(#downloader_edit, #new_url);
6986 leency 653
				CreateThread(#Downloader,#downloader_stak+4092);
654
			}
655
			else notify("'WebView\nPlease, start a new download only when previous ended.'Et");
6730 leency 656
			return;
5774 leency 657
		}
658
	}
7755 leency 659
	OpenPage(#new_url);
660
}
661
 
662
void EventSubmitOmnibox()
663
{
664
	char new_url[URL_SIZE+1];
665
	if (!editURL[0]) return;
666
	if (!strncmp(#editURL,"http:",5)) || (editURL[0]=='/')
667
	|| (!strncmp(#editURL,"https:",6)) || (!strncmp(#editURL,"WebView:",8)) {
668
		OpenPage(#editURL);
669
	} else {
670
		strcpy(#new_url, "http://");
671
		strncat(#new_url, #editURL, sizeof(new_url)-1);
672
		OpenPage(#new_url);
6931 leency 673
	}
5774 leency 674
}
675
 
7755 leency 676
void LoadInternalPage(dword _bufdata, _in_bufsize){
677
	if (!_bufdata) || (!_in_bufsize) {
7752 leency 678
		LoadInternalPage(#page_not_found, sizeof(page_not_found));
7755 leency 679
	} else {
680
		WB1.list.first = 0; //scroll page to the top
681
		DrawOmnibox();
682
		if(!strrchr(#editURL, '#')) {
683
			strcat(#editURL, #anchors.current);
684
			DrawOmnibox();
685
		}
7759 leency 686
		WB1.ParseHtml(_bufdata, _in_bufsize);
687
		DrawStatusBar(NULL);
7771 leency 688
		DrawActiveTab();
7756 leency 689
		if (source_mode) {
690
			source_mode = false;
7759 leency 691
			ShowSource(WB1.bufpointer, _in_bufsize);
7757 leency 692
		} else {
693
			WB1.DrawPage();
7756 leency 694
		}
7742 leency 695
	}
696
}
697
 
7755 leency 698
byte UrlExtIs(dword base, ext)
7742 leency 699
{
7755 leency 700
	if (!strcmpi(base + strlen(base) - strlen(ext), ext)) return true;
7742 leency 701
	return false;
702
}
703
 
704
void DrawProgress()
705
{
706
	dword persent;
707
	if (http.transfer == 0) return;
7755 leency 708
	if (wv_progress_bar.max) {
709
		persent = wv_progress_bar.value*100/wv_progress_bar.max;
710
	} else {
711
		persent = 10;
712
	}
7758 leency 713
	DrawBar(address_box.left-1, address_box.top+20, persent*address_box.width+16/100, 2, 0x72B7EB);
7742 leency 714
}
715
 
7770 leency 716
void EventShowPageMenu()
6782 leency 717
{
7780 leency 718
	open_lmenu(Form.left + mouse.x+4, Form.top + skin_height + mouse.y, MENU_ALIGN_TOP_LEFT, NULL, #rmb_menu);
719
	menu_id = VIEW_SOURCE;
6782 leency 720
}
721
 
7770 leency 722
void EventShowLinkMenu()
7759 leency 723
{
7780 leency 724
	open_lmenu(Form.left + mouse.x+4, Form.top + skin_height + mouse.y, MENU_ALIGN_TOP_LEFT, NULL, #link_menu);
725
	menu_id = COPY_LINK_URL;
7759 leency 726
}
727
 
7780 leency 728
void EventShowMainMenu()
729
{
730
	open_lmenu(Form.left + Form.cwidth - PADDING, Form.top + skin_height + PADDING + TSZE + 3,
731
		MENU_ALIGN_TOP_RIGHT, NULL, #main_menu);
732
	menu_id = OPEN_FILE;
733
}
734
 
7770 leency 735
void EventShowEncodingsList()
7758 leency 736
{
7780 leency 737
	open_lmenu(Form.left + Form.cwidth, Form.top + skin_height + status_text.start_y + 8,
738
		MENU_ALIGN_BOT_RIGHT, WB1.cur_encoding + 1, "UTF-8\nKOI8-RU\nCP1251\nCP1252\nISO8859-5\nCP866");
739
	menu_id = ENCODINGS;
7758 leency 740
}
741
 
7780 leency 742
void ProcessMenuClick()
6795 leency 743
{
7780 leency 744
	int click_id;
745
	if (menu_id) && (click_id = get_menu_click()) {
746
		click_id += menu_id - 1;
747
		menu_id = NULL;
748
		ProcessEvent(click_id);
749
	}
6795 leency 750
}
751
 
7281 leency 752
void EventUpdateProgressBar()
753
{
754
	wv_progress_bar.max = http.content_length;
755
	if (wv_progress_bar.value != http.content_received)
756
	{
757
		wv_progress_bar.value = http.content_received;
758
		DrawProgress();
759
	}
760
}
6795 leency 761
 
7743 leency 762
void EventSeachWeb()
763
{
7755 leency 764
	char new_url[URL_SIZE+1];
765
	replace_char(#editURL, ' ', '_', URL_SIZE);
766
	strcpy(#new_url, "https://www.google.com/search?q=");
767
	strncat(#new_url, #editURL, URL_SIZE);
768
	OpenPage(#new_url);
7743 leency 769
}
770
 
7748 leency 771
void EventOpenDialog()
772
{
773
	OpenDialog_start stdcall (#o_dialog);
774
	if (o_dialog.status) {
7755 leency 775
		OpenPage(#openfile_path);
7748 leency 776
	}
777
}
778
 
7750 leency 779
void EventViewSource()
780
{
7755 leency 781
	char source_view_param[URL_SIZE+1];
7771 leency 782
	//strcpy(#source_view_param, "-source ");
783
	//strncat(#source_view_param, history.current(), URL_SIZE);
784
	//RunProgram(#program_path, #source_view_param);
785
	source_mode = true;
786
	EventOpenNewTab(history.current());
7750 leency 787
}
788
 
7765 leency 789
dword GetFileSize(dword _path)
790
{
791
	BDVK bdvk;
792
	if (GetFileInfo(_path, #bdvk)!=0) {
793
		return 0;
794
	} else {
795
		return bdvk.sizelo;
796
	}
797
}
798
 
799
void EventUpdateBrowser()
800
{
801
	dword downloader_id, slot_n;
802
	dword current_size;
803
	dword new_size;
804
	int error;
805
 
806
	draw_window();
807
 
808
	downloader_id = RunProgram(#program_path, #update_param);
809
	do {
810
		slot_n = GetProcessSlot(downloader_id);
811
		pause(10);
812
	} while (slot_n!=0);
813
 
814
	current_size = GetFileSize(#program_path);
815
	new_size = GetFileSize("/tmp0/1/Downloads/WebView.com");
816
 
817
	if (!new_size) || (new_size<5000) {
818
		notify(#update_download_error);
819
		return;
820
	}
821
 
822
	if (current_size == new_size) {
823
		notify(#update_is_current);
824
		return;
825
	}
826
 
827
	if (error = CopyFileAtOnce(new_size, "/tmp0/1/Downloads/WebView.com", #program_path)) {
828
		notify(#update_can_not_copy);
829
	} else {
830
		notify(#update_ok);
831
		RunProgram(#program_path, history.current());
832
		ExitProcess();
833
	}
834
}
835
 
7742 leency 836
void DrawStatusBar(dword _status_text)
6795 leency 837
{
7759 leency 838
	status_text.font_color = system.color.work_text;
7748 leency 839
	status_text.start_x = 10;
7759 leency 840
	status_text.start_y = Form.cheight - STATUSBAR_H + 4;
841
	status_text.area_size_x = Form.cwidth - status_text.start_x -3 - 70;
842
	//DrawBar(status_text.start_x, status_text.start_y, status_text.area_size_x, 9, system.color.work);
843
	DrawBar(0,Form.cheight - STATUSBAR_H+1, Form.cwidth,STATUSBAR_H-1, system.color.work);
844
	if (_status_text) {
845
		status_text.text_pointer = _status_text;
846
		PathShow_prepare stdcall(#status_text);
847
		PathShow_draw stdcall(#status_text);
7758 leency 848
	}
7759 leency 849
	DefineHiddenButton(status_text.start_x+status_text.area_size_x+10, status_text.start_y-3,
850
		60, 12, CHANGE_ENCODING);
851
	WriteTextCenter(status_text.start_x+status_text.area_size_x+10,
852
		status_text.start_y, 60, system.color.work_text, WB1.cur_encoding*10+#charsets);
7758 leency 853
}
854
 
855
void DrawOmnibox()
856
{
7784 leency 857
	int imgxoff;
7758 leency 858
 
7759 leency 859
	DrawOvalBorder(address_box.left-2, address_box.top-3, address_box.width+18, 24, system.color.work_graph,
860
		system.color.work_graph, system.color.work_graph, system.color.work_dark);
7758 leency 861
	DrawBar(address_box.left-1, address_box.top-2, address_box.width+18, 1, 0xD8DCD8);
862
	DrawBar(address_box.left-1, address_box.top-1, address_box.width+18, 1, address_box.color);
863
	DrawBar(address_box.left-1, address_box.top, 1, 22, address_box.color);
864
 
865
	if (address_box.flags & ed_focus) address_box.flags = ed_focus; else address_box.flags = 0;
866
	EditBox_UpdateText(#address_box, address_box.flags);
867
	edit_box_draw stdcall(#address_box);
7784 leency 868
	if (http.transfer) imgxoff = 16*23*3; else imgxoff = 0;
869
	_PutImage(address_box.left+address_box.width+1, address_box.top-1, 16, 23, imgxoff + #editbox_icons);
870
	DefineHiddenButton(address_box.left+address_box.width-1, address_box.top-2, 17, 23, REFRESH_BUTTON);
7758 leency 871
 
872
	DrawProgress();
873
}
874
 
7771 leency 875
void SetOmniboxText(dword _text)
876
{
877
	strcpy(#editURL, _text);
878
	address_box.flags=0;
879
	DrawOmnibox();
880
}
7758 leency 881
 
7771 leency 882
 
5631 pavelyakov 883
stop: