Subversion Repositories Kolibri OS

Rev

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