Subversion Repositories Kolibri OS

Rev

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