Subversion Repositories Kolibri OS

Rev

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