Subversion Repositories Kolibri OS

Rev

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