Subversion Repositories Kolibri OS

Rev

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

Rev Author Line No. Line
3067 leency 1
//HTML Viewer in C--
7739 leency 2
//Copyright 2007-2020 by Veliant & Leency
6978 leency 3
//Asper, lev, Lrz, Barsuk, Nable, hidnplayr...
3067 leency 4
 
4085 leency 5
#ifndef AUTOBUILD
6
	#include "lang.h--"
7
#endif
8
 
3107 leency 9
//libraries
7738 leency 10
#define MEMSIZE 1024 * 800
5499 leency 11
#include "..\lib\gui.h"
4508 leency 12
#include "..\lib\draw_buf.h"
13
#include "..\lib\list_box.h"
14
#include "..\lib\cursor.h"
5978 leency 15
#include "..\lib\collection.h"
6795 leency 16
#include "..\lib\random.h"
7037 leency 17
#include "..\lib\clipboard.h"
5981 leency 18
 
7437 leency 19
// *.obj libraries
5499 leency 20
#include "..\lib\obj\box_lib.h"
7049 leency 21
#include "..\lib\obj\libio.h"
22
#include "..\lib\obj\libimg.h"
5499 leency 23
#include "..\lib\obj\http.h"
5690 leency 24
#include "..\lib\obj\iconv.h"
5408 leency 25
//useful patterns
5978 leency 26
#include "..\lib\patterns\history.h"
6058 leency 27
#include "..\lib\patterns\http_downloader.h"
5408 leency 28
 
7281 leency 29
_http http = {0, 0, 0, 0, 0, 0, 0};
30
 
4677 leency 31
 
4026 leency 32
#ifdef LANG_RUS
7746 leency 33
char version[]="Текстовый браузер 1.9";
6045 leency 34
?define IMAGES_CACHE_CLEARED "Кэш картинок очищен"
35
?define T_LAST_SLIDE "Это последний слайд"
36
char loading[] = "Загрузка страницы...
";
6698 leency 37
char page_not_found[] = FROM "html\\page_not_found_ru.htm""\0";
7743 leency 38
char homepage[] = FROM "html\\homepage_ru.htm""\0";
39
char help[] = FROM "html\\help_ru.htm""\0";
6045 leency 40
char accept_language[]= "Accept-Language: ru\n";
41
char rmb_menu[] =
42
"Посмотреть исходник
43
Редактировать исходник
44
История
45
Менеджер загрузок";
7037 leency 46
char link_menu[] =
7208 leency 47
"Копировать ссылку
48
Скачать содержимое ссылки";
4026 leency 49
#else
7746 leency 50
char version[]="Text-based Browser 1.9";
6045 leency 51
?define IMAGES_CACHE_CLEARED "Images cache cleared"
52
?define T_LAST_SLIDE "This slide is the last"
53
char loading[] = "Loading...
";
6698 leency 54
char page_not_found[] = FROM "html\\page_not_found_en.htm""\0";
7743 leency 55
char homepage[] = FROM "html\\homepage_en.htm""\0";
56
char help[] = FROM "html\\help_en.htm""\0";
6045 leency 57
char accept_language[]= "Accept-Language: en\n";
58
char rmb_menu[] =
59
"View source
60
Edit source
61
History
62
Download Manager";
7037 leency 63
char link_menu[] =
7208 leency 64
"Copy link
65
Download link contents";
4026 leency 66
#endif
67
 
6795 leency 68
 
5773 leency 69
#define URL_SERVICE_HISTORY "WebView://history"
7743 leency 70
#define URL_SERVICE_HOMEPAGE "WebView://home"
71
#define URL_SERVICE_HELP "WebView://help"
5773 leency 72
#define URL_SERVICE_SOURCE "WebView://source:"
5631 pavelyakov 73
 
3067 leency 74
proc_info Form;
75
 
5772 leency 76
//char search_path[]="http://nigma.ru/index.php?s=";
4558 hidnplayr 77
int redirected = 0;
3067 leency 78
 
4074 leency 79
char stak[4096];
5640 pavelyakov 80
 
4026 leency 81
int action_buf;
82
 
6731 leency 83
dword TOOLBAR_H = 40;
5519 leency 84
dword STATUSBAR_H = 15;
4677 leency 85
 
7425 leency 86
dword col_bg = 0xE3E2E2;
87
dword panel_color  = 0xE3E2E2;
88
dword border_color = 0x8C8C8C;
89
 
7282 leency 90
bool debug_mode = false;
91
 
5718 leency 92
progress_bar wv_progress_bar;
6931 leency 93
bool souce_mode = false;
94
bool open_in_a_new_window = false;
4677 leency 95
 
5718 leency 96
enum {
97
	BACK_BUTTON=1000,
98
	FORWARD_BUTTON,
99
	REFRESH_BUTTON,
100
	GOTOURL_BUTTON,
6795 leency 101
	SANDWICH_BUTTON,
5768 leency 102
	VIEW_SOURCE=1100,
5718 leency 103
	EDIT_SOURCE,
104
	VIEW_HISTORY,
7037 leency 105
	//FREE_IMG_CACHE,
6795 leency 106
	DOWNLOAD_MANAGER,
7282 leency 107
	COPY_LINK_URL=1200,
7208 leency 108
	DOWNLOAD_LINK_CONTENTS,
5718 leency 109
};
110
 
4411 leency 111
#include "..\TWB\TWB.c"
4636 leency 112
#include "history.h"
4718 leency 113
#include "show_src.h"
6001 leency 114
#include "download_manager.h"
3067 leency 115
 
4534 leency 116
char editURL[sizeof(URL)];
7746 leency 117
edit_box address_box = {250,60,30,0xffffff,0x94AECE,0xffffff,0xffffff,0x10000000,sizeof(URL)-2,#editURL,0,NULL,19,19};
4534 leency 118
 
7428 leency 119
#define SKIN_Y 24
4534 leency 120
 
3067 leency 121
void main()
122
{
7422 leency 123
	int i;
5626 leency 124
	load_dll(boxlib, #box_lib_init,0);
125
	load_dll(libio, #libio_init,1);
126
	load_dll(libimg, #libimg_init,1);
127
	load_dll(libHTTP, #http_lib_init,1);
5690 leency 128
	load_dll(iconv_lib, #iconv_open,0);
7428 leency 129
	Libimg_LoadImage(#skin, "/sys/toolbar.png");
7437 leency 130
	skin.h = 26;
7425 leency 131
	wv_progress_bar.progress_color = 0x72B7EB;
5772 leency 132
	CreateDir("/tmp0/1/downloads");
7521 leency 133
	if (param) && (param[0]=='-') && (param[1]=='d') {
134
		strcpy(#downloader_edit, #param+3);
135
		CreateThread(#Downloader,#downloader_stak+4092);
136
		ExitProcess();
137
	}
7743 leency 138
	else if (param) strcpy(#URL, #param); else strcpy(#URL, URL_SERVICE_HOMEPAGE);
6045 leency 139
	WB1.list.SetFont(8, 14, 10011000b);
5779 leency 140
	WB1.list.no_selection = true;
6978 leency 141
	SetEventMask(EVM_REDRAW + EVM_KEY + EVM_BUTTON + EVM_MOUSE + EVM_MOUSE_FILTER + EVM_STACK);
142
	loop() switch(WaitEvent())
143
	{
144
		case evMouse:
145
			edit_box_mouse stdcall (#address_box);
146
			mouse.get();
7282 leency 147
			if (PageLinks.HoverAndProceed(mouse.x, WB1.list.first + mouse.y))
148
			&& (bufsize) && (mouse.pkm) && (mouse.up) {
149
				if (WB1.list.MouseOver(mouse.x, mouse.y)) EventShowPageMenu(mouse.x, mouse.y);
150
				break;
6978 leency 151
			}
7282 leency 152
			if (WB1.list.MouseScroll(mouse.vert)) WB1.DrawPage();
6978 leency 153
			scrollbar_v_mouse (#scroll_wv);
154
			if (WB1.list.first != scroll_wv.position)
155
			{
156
				WB1.list.first = scroll_wv.position;
157
				WB1.DrawPage();
3067 leency 158
				break;
6978 leency 159
			}
160
			break;
5711 leency 161
 
6978 leency 162
		case evButton:
163
			ProcessEvent(GetButtonID());
164
			break;
5711 leency 165
 
6978 leency 166
		case evKey:
167
			GetKeys();
7742 leency 168
			if (key_modifier&KEY_LCTRL) || (key_modifier&KEY_RCTRL) {
169
				if (key_scancode == SCAN_CODE_KEY_H) ProcessEvent(VIEW_HISTORY);
170
				if (key_scancode == SCAN_CODE_KEY_U) ProcessEvent(VIEW_SOURCE);
171
				if (key_scancode == SCAN_CODE_KEY_T)
172
				|| (key_scancode == SCAN_CODE_KEY_N) RunProgram(#program_path, NULL);
173
				if (key_scancode == SCAN_CODE_KEY_W) ExitProcess();
174
				if (key_scancode == SCAN_CODE_KEY_J) ProcessEvent(DOWNLOAD_MANAGER);
7743 leency 175
				if (key_scancode == SCAN_CODE_KEY_R) ProcessEvent(REFRESH_BUTTON);
176
				if (key_scancode == SCAN_CODE_ENTER) EventSeachWeb();
177
				if (key_scancode == SCAN_CODE_LEFT)  ProcessEvent(BACK_BUTTON);
178
				if (key_scancode == SCAN_CODE_RIGHT) ProcessEvent(FORWARD_BUTTON);
7742 leency 179
			}
7743 leency 180
 
181
			if (key_scancode == SCAN_CODE_F5) ProcessEvent(REFRESH_BUTTON);
182
 
7506 leency 183
			if (address_box.flags & ed_focus)
6978 leency 184
			{
7742 leency 185
				if (key_scancode == SCAN_CODE_ENTER) {
186
					ProcessEvent(key_scancode);
187
				}
188
				else {
6978 leency 189
					EAX = key_editbox;
190
					edit_box_key stdcall(#address_box);
5530 leency 191
				}
6978 leency 192
			}
193
			else
194
			{
7422 leency 195
				#define KEY_SCROLL_N 11
196
				if (SCAN_CODE_UP   == key_scancode) for (i=0;i
197
				if (SCAN_CODE_DOWN == key_scancode) for (i=0;i
7743 leency 198
				if (key_scancode == SCAN_CODE_F6) {address_box.flags=ed_focus; DrawOmnibox();}
6978 leency 199
				if (WB1.list.ProcessKey(key_scancode)) WB1.DrawPage();
200
				else ProcessEvent(key_scancode);
201
			}
202
			break;
203
 
204
		case evReDraw:
7450 leency 205
			if (menu.cur_y) {
206
				ProcessEvent(menu.cur_y);
207
				menu.cur_y = 0;
6978 leency 208
			}
209
			DefineAndDrawWindow(GetScreenWidth()-800/2-random(80),GetScreenHeight()-600/2-random(80),800,600,0x73,col_bg,0,0);
210
			GetProcessInfo(#Form, SelfInfo);
211
			if (Form.status_window>2) { DrawTitle(#header); break; }
212
			if (Form.height<120) { MoveSize(OLD,OLD,OLD,120); break; }
213
			if (Form.width<280) { MoveSize(OLD,OLD,280,OLD); break; }
214
			Draw_Window();
215
			break;
216
 
217
		case evNetwork:
7281 leency 218
			if (http.transfer > 0) {
219
				http.receive();
220
				EventUpdateProgressBar();
221
				if (http.receive_result == 0) {
6978 leency 222
					// Handle redirects
7281 leency 223
					if (http.status_code >= 300) && (http.status_code < 400)
4686 leency 224
					{
6978 leency 225
						redirected++;
7282 leency 226
						if (redirected>5)
4563 leency 227
						{
7282 leency 228
							notify("'Too many redirects.' -E");
229
							StopLoading();
4558 hidnplayr 230
						}
4563 leency 231
						else
232
						{
7282 leency 233
							http.handle_redirect();
234
							http.free();
235
							GetAbsoluteURL(#http.redirect_url);
236
							history.back();
237
							strcpy(#editURL, #URL);
7743 leency 238
							DrawOmnibox();
7282 leency 239
							OpenPage();
7742 leency 240
							//ProcessLink(history.current());
4558 hidnplayr 241
						}
7282 leency 242
						break;
6978 leency 243
					}
7282 leency 244
					redirected = 0;
6978 leency 245
					// Loading the page is complete, free resources
7282 leency 246
					history.add(#URL);
247
					bufpointer = http.content_pointer;
248
					bufsize = http.content_received;
249
					http.free();
250
					SetPageDefaults();
251
					ShowPage();
4536 leency 252
				}
6978 leency 253
			}
254
	}
3067 leency 255
}
256
 
257
void SetElementSizes()
258
{
6731 leency 259
	address_box.top = TOOLBAR_H/2-10;
6794 leency 260
	basic_line_h = calc(WB1.list.font_h * 130) / 100;
6731 leency 261
	address_box.width = Form.cwidth - address_box.left - 50;
6803 leency 262
	WB1.list.SetSizes(0, TOOLBAR_H, Form.width - 10 - scroll_wv.size_x,
6794 leency 263
		Form.cheight - TOOLBAR_H - STATUSBAR_H, basic_line_h);
264
	WB1.list.wheel_size = 7 * basic_line_h;
7746 leency 265
	WB1.list.column_max = WB1.list.w - scroll_wv.size_x / WB1.list.font_w + 1;
6794 leency 266
	WB1.list.visible = WB1.list.h;
6045 leency 267
	if (WB1.list.w!=WB1.DrawBuf.bufw) {
7738 leency 268
		WB1.DrawBuf.Init(WB1.list.x, WB1.list.y, WB1.list.w, 800*20);
6698 leency 269
		ProcessEvent(REFRESH_BUTTON);
6045 leency 270
	}
3067 leency 271
}
272
 
5981 leency 273
 
5982 leency 274
 
3067 leency 275
void Draw_Window()
276
{
5772 leency 277
	DrawBar(0,0, Form.cwidth,TOOLBAR_H-2, panel_color);
5718 leency 278
	DrawBar(0,TOOLBAR_H-2, Form.cwidth,1, 0xD7D0D3);
4677 leency 279
	DrawBar(0,TOOLBAR_H-1, Form.cwidth,1, border_color);
3067 leency 280
	SetElementSizes();
6731 leency 281
	DrawRectangle(address_box.left-3, address_box.top-3, address_box.width+5, 25,border_color);
282
	DefineButton(address_box.left-52, address_box.top-2, 24, skin.h-2, BACK_BUTTON+BT_HIDE, 0);
283
	DefineButton(address_box.left-27, address_box.top-2, 24, skin.h-2, FORWARD_BUTTON+BT_HIDE, 0);
7428 leency 284
	img_draw stdcall(skin.image, address_box.left-53, address_box.top-3, 51, skin.h, 0, SKIN_Y);
5718 leency 285
	DefineButton(address_box.left+address_box.width+1, address_box.top-3, 16, skin.h-1, REFRESH_BUTTON+BT_HIDE+BT_NOFRAME, 0);
6731 leency 286
	DefineButton(Form.cwidth-27, address_box.top-3, 23, skin.h-1, SANDWICH_BUTTON+BT_HIDE, 0);
7428 leency 287
	img_draw stdcall(skin.image, Form.cwidth-24, address_box.top-3, 17, skin.h, 102, SKIN_Y);
4677 leency 288
	DrawBar(0,Form.cheight - STATUSBAR_H, Form.cwidth,STATUSBAR_H, col_bg);
289
	DrawBar(0,Form.cheight - STATUSBAR_H, Form.cwidth,1, border_color);
7282 leency 290
	if (!header)
291
		OpenPage();
292
	else {
293
		WB1.DrawPage();
7743 leency 294
		DrawOmnibox();
7282 leency 295
	}
4692 leency 296
	DrawRectangle(scroll_wv.start_x, scroll_wv.start_y, scroll_wv.size_x, scroll_wv.size_y-1, scroll_wv.bckg_col);
4693 leency 297
	DrawProgress();
3067 leency 298
}
299
 
300
 
6698 leency 301
void ProcessEvent(dword id__)
4413 leency 302
{
6698 leency 303
	switch (id__)
4413 leency 304
	{
6698 leency 305
		case 1:
306
			ExitProcess();
307
			return;
5711 leency 308
		case SCAN_CODE_BS:
5718 leency 309
		case BACK_BUTTON:
6021 leency 310
			if (history.back()) {
311
				strcpy(#URL, history.current());
5978 leency 312
				OpenPage();
313
			}
5711 leency 314
			return;
5718 leency 315
		case FORWARD_BUTTON:
6021 leency 316
			if (history.forward()) {
317
				strcpy(#URL, history.current());
5978 leency 318
				OpenPage();
319
			}
5711 leency 320
			return;
5718 leency 321
		case GOTOURL_BUTTON:
5772 leency 322
		case SCAN_CODE_ENTER:
7742 leency 323
			EventSubmitOmnibox();
5711 leency 324
			return;
5718 leency 325
		case REFRESH_BUTTON:
7281 leency 326
			if (http.transfer > 0)
5713 leency 327
			{
328
				StopLoading();
329
				Draw_Window();
330
			}
331
			else OpenPage();
332
			return;
5718 leency 333
		case SANDWICH_BUTTON:
6795 leency 334
			EventShowPageMenu(Form.cwidth - 215, TOOLBAR_H-6);
4415 leency 335
			return;
5718 leency 336
		case VIEW_SOURCE:
337
			WB1.list.first = 0;
338
			ShowSource();
5773 leency 339
			WB1.LoadInternalPage(bufpointer, bufsize);
5718 leency 340
			break;
341
		case EDIT_SOURCE:
7282 leency 342
			if (!strncmp(#URL,"http",4))
5718 leency 343
			{
7227 leency 344
				CreateFile(bufsize, bufpointer, "/tmp0/1/WebView_tmp.htm");
5718 leency 345
				if (!EAX) RunProgram("/rd/1/tinypad", "/tmp0/1/WebView_tmp.htm");
346
			}
347
			else RunProgram("/rd/1/tinypad", #URL);
4415 leency 348
			return;
7037 leency 349
		// case FREE_IMG_CACHE:
350
		// 	ImgCache.Free();
351
		// 	notify(IMAGES_CACHE_CLEARED);
352
		// 	WB1.DrawPage();
353
		// 	return;
5718 leency 354
		case VIEW_HISTORY:
4677 leency 355
			strcpy(#URL, URL_SERVICE_HISTORY);
4544 leency 356
			OpenPage();
357
			return;
5718 leency 358
		case DOWNLOAD_MANAGER:
5519 leency 359
			if (!downloader_opened) {
6001 leency 360
				downloader_edit = NULL;
5519 leency 361
				CreateThread(#Downloader,#downloader_stak+4092);
362
			}
4413 leency 363
			return;
7282 leency 364
		case COPY_LINK_URL:
7037 leency 365
			Clipboard__CopyText(PageLinks.GetURL(PageLinks.active));
366
			notify("'URL copied to clipboard'O");
367
			return;
7208 leency 368
		case DOWNLOAD_LINK_CONTENTS:
369
			if (!downloader_opened) {
370
				strcpy(#downloader_edit, PageLinks.GetURL(PageLinks.active));
371
				CreateThread(#Downloader,#downloader_stak+4092);
372
			}
373
			return;
7282 leency 374
		case SCAN_CODE_F12:
375
			debug_mode ^= 1;
376
			if (debug_mode) notify("'Debug mode ON'-I");
377
			else notify("'Debug mode OFF'-I");
378
			return;
4413 leency 379
	}
380
}
381
 
4636 leency 382
void StopLoading()
383
{
7281 leency 384
	if (http.transfer)
4647 leency 385
	{
7281 leency 386
		EAX = http.transfer;
4647 leency 387
		EAX = EAX.http_msg.content_ptr;		// get pointer to data
388
		$push	EAX							// save it on the stack
7281 leency 389
		http_free stdcall (http.transfer);	// abort connection
4647 leency 390
		$pop	EAX
5631 pavelyakov 391
		free(EAX);						// free data
7281 leency 392
		http.transfer=0;
4647 leency 393
		bufsize = 0;
5631 pavelyakov 394
		bufpointer = free(bufpointer);
7746 leency 395
		pause(10);
4647 leency 396
	}
5519 leency 397
	wv_progress_bar.value = 0;
7743 leency 398
	DrawOmnibox();
4645 leency 399
}
400
 
401
void SetPageDefaults()
402
{
403
	strcpy(#header, #version);
404
	WB1.list.count = WB1.list.first = 0;
5704 leency 405
	cur_encoding = CH_NULL;
4645 leency 406
	if (o_bufpointer) o_bufpointer = free(o_bufpointer);
4636 leency 407
}
408
 
7720 leency 409
void ReplaceSpaceInUrl() {
410
	int i;
411
	strcpy(#editURL, #URL);
412
	while (i = strchr(#URL, ' '))
413
	{
414
		i -= #URL;
415
		strlcpy(#URL+i+3, #editURL+i+1, sizeof(URL)-i-4);
416
		URL[i] = '%';
417
		URL[i+1] = '2';
418
		URL[i+2] = '0';
419
	}
420
	strcpy(#editURL, #URL);
421
}
422
 
4416 leency 423
void OpenPage()
424
{
7282 leency 425
	char getUrl[sizeof(URL)];
4636 leency 426
	StopLoading();
4718 leency 427
	souce_mode = false;
4416 leency 428
	strcpy(#editURL, #URL);
6021 leency 429
	history.add(#URL);
5631 pavelyakov 430
	if (!strncmp(#URL,"WebView:",8))
4692 leency 431
	{
432
		SetPageDefaults();
7743 leency 433
		if (!strcmp(#URL, URL_SERVICE_HOMEPAGE)) WB1.LoadInternalPage(#homepage, sizeof(homepage));
434
		else if (!strcmp(#URL, URL_SERVICE_HELP)) WB1.LoadInternalPage(#help, sizeof(help));
5631 pavelyakov 435
		else if (!strcmp(#URL, URL_SERVICE_HISTORY)) ShowHistory();
7739 leency 436
		else {bufsize=0; ShowPage();} //page not found
7743 leency 437
		DrawOmnibox();
4692 leency 438
		return;
439
	}
7282 leency 440
	if (!strncmp(#URL,"http:",5)) || (!strncmp(#URL,"https://",8))
4416 leency 441
	{
7720 leency 442
		ReplaceSpaceInUrl();
7428 leency 443
		img_draw stdcall(skin.image, address_box.left+address_box.width+1, address_box.top-3, 17, skin.h, 68, SKIN_Y);
7282 leency 444
 
445
		if (!strncmp(#URL,"http:",5)) {
446
			http.get(#URL);
447
		}
448
		if (!strncmp(#URL,"https://",8)) {
449
			sprintf(#getUrl, "http://gate.aspero.pro/?site=%s", #URL);
450
			http.get(#getUrl);
451
		}
452
		//http.get(#URL);
7281 leency 453
		if (!http.transfer)
4646 leency 454
		{
455
			StopLoading();
456
			bufsize = 0;
5631 pavelyakov 457
			bufpointer = free(bufpointer);
4646 leency 458
			ShowPage();
459
			return;
460
		}
4416 leency 461
	}
4636 leency 462
	else
463
	{
464
		file_size stdcall (#URL);
7739 leency 465
		if (EBX)
4650 leency 466
		{
7739 leency 467
			bufsize = EBX;
5631 pavelyakov 468
			free(bufpointer);
469
			bufpointer = malloc(bufsize);
4650 leency 470
			SetPageDefaults();
4718 leency 471
			ReadFile(0, bufsize, bufpointer, #URL);
4650 leency 472
		}
4645 leency 473
		ShowPage();
4636 leency 474
	}
4416 leency 475
}
4415 leency 476
 
7742 leency 477
void ProcessAnchor()
4508 leency 478
{
7742 leency 479
	char anchor[256];
480
	int anchor_pos;
481
 
482
	anchor_pos = strrchr(#URL, '#')-1;
483
	strlcpy(#anchor, #URL+anchor_pos, sizeof(anchor));
484
	URL[anchor_pos] = 0x00;
4415 leency 485
 
7742 leency 486
	//#1
487
	if (URL[0] == NULL)
4508 leency 488
	{
7742 leency 489
		if (anchor[1] == NULL) {
490
			WB1.list.first = 0;
491
		}
492
		else {
493
			if (anchors.get_anchor_pos(#anchor+1)!=-1) WB1.list.first = anchors.get_anchor_pos(#anchor+1);
494
		}
495
		strcpy(#URL, history.current());
4508 leency 496
	}
7742 leency 497
	//liner.ru#1
4508 leency 498
	else
5768 leency 499
	{
7742 leency 500
		GetAbsoluteURL(#URL);
501
		OpenPage();
502
		if (anchors.get_anchor_pos(#anchor+1)!=-1) WB1.list.first = anchors.get_anchor_pos(#anchor+1);
5768 leency 503
	}
7742 leency 504
 
505
	WB1.DrawPage();
506
	strcpy(#editURL, #URL);
507
	strcat(#editURL, #anchor);
7743 leency 508
	DrawOmnibox();
4508 leency 509
}
510
 
7742 leency 511
void EventSubmitOmnibox()
5493 leency 512
{
7742 leency 513
	if (!editURL[0]) return;
514
	if (!strncmp(#editURL,"http:",5)) || (editURL[0]=='/')
515
	|| (!strncmp(#editURL,"https:",6)) || (!strncmp(#editURL,"WebView:",8))
516
	{
517
		strcpy(#URL, #editURL);
518
	}
519
	else
520
	{
521
		strlcpy(#URL,"http://",7);
522
		strcat(#URL, #editURL);
523
	}
524
	ProcessLink();
5493 leency 525
}
4508 leency 526
 
7742 leency 527
void EventClickLink()
5772 leency 528
{
7742 leency 529
	strcpy(#URL, PageLinks.GetURL(PageLinks.active));
530
	GetAbsoluteURL(#URL);
531
	ProcessLink();
5772 leency 532
}
5746 leency 533
 
7742 leency 534
void ProcessLink()
5774 leency 535
{
7281 leency 536
	if (http.transfer > 0)
5774 leency 537
	{
538
		StopLoading();
6021 leency 539
		history.back();
5774 leency 540
	}
7742 leency 541
 
542
	if (strrchr(#URL, '#')!=0) {
543
		ProcessAnchor();
5774 leency 544
		return;
545
	}
6730 leency 546
 
7742 leency 547
	if (!strncmp(#URL,"mailto:", 7)) || (!strncmp(#URL,"tel:", 4))
6730 leency 548
	{
549
		notify(#URL);
550
		strcpy(#editURL, history.current());
551
		strcpy(#URL, history.current());
552
		return;
553
	}
554
 
7742 leency 555
	if (!strncmp(#URL,"WebView:",8)) {
556
		OpenPage();
557
		return;
558
	}
6730 leency 559
 
7282 leency 560
	if (strncmp(#URL,"http://",7)!=0) && (strncmp(#URL,"https://",8)!=0)
5774 leency 561
	{
6730 leency 562
		if (UrlExtIs(".htm")!=true) && (UrlExtIs(".html")!=true)
563
		{
7422 leency 564
			if (strchr(#URL, '|')) {
565
				ESBYTE[strchr(#URL, '|')] = NULL;
566
				RunProgram(#URL, strlen(#URL)+1+#URL);
567
			}
568
			else {
569
				RunProgram("/sys/@open", #URL);
570
			}
6730 leency 571
			strcpy(#editURL, history.current());
572
			strcpy(#URL, history.current());
573
			return;
574
		}
575
	}
576
	else
577
	{
578
		if (UrlExtIs(".png")==true) || (UrlExtIs(".gif")==true) || (UrlExtIs(".jpg")==true)
6794 leency 579
		|| (UrlExtIs(".zip")==true) || (UrlExtIs(".kex")==true) || (UrlExtIs(".pdf")==true)
580
		|| (UrlExtIs(".7z")==true) {
6986 leency 581
			if (!downloader_opened) {
582
				strcpy(#downloader_edit, #URL);
583
				CreateThread(#Downloader,#downloader_stak+4092);
584
				strcpy(#editURL, history.current());
585
				strcpy(#URL, history.current());
586
			}
587
			else notify("'WebView\nPlease, start a new download only when previous ended.'Et");
6730 leency 588
			return;
5774 leency 589
		}
590
	}
6931 leency 591
	if (open_in_a_new_window)
592
	{
593
		RunProgram(#program_path, #URL);
594
		strcpy(#editURL, history.current());
595
		strcpy(#URL, history.current());
596
	}
597
	else
598
	{
599
		OpenPage();
600
	}
601
	open_in_a_new_window = false;
5774 leency 602
}
603
 
7743 leency 604
void DrawOmnibox()
7742 leency 605
{
606
	int skin_x_offset;
607
	DrawBar(address_box.left-2, address_box.top-2, address_box.width+3, 2, address_box.color);
608
	DrawBar(address_box.left-2, address_box.top, 2, 22, address_box.color);
609
	//address_box.size = address_box.pos = address_box.shift = address_box.shift_old = strlen(#editURL);
610
	//address_box.offset = 0;
611
	EditBox_UpdateText(#address_box, address_box.flags);
612
	edit_box_draw stdcall(#address_box);
613
	if (http.transfer > 0) skin_x_offset = 68; else skin_x_offset = 51;
614
	img_draw stdcall(skin.image, address_box.left+address_box.width+1, address_box.top-3, 17, skin.h, skin_x_offset, SKIN_Y);
615
}
616
 
617
 
618
void ShowPage()
619
{
7743 leency 620
	DrawOmnibox();
7742 leency 621
	if (!bufsize)
622
	{
623
		if (http.transfer) WB1.LoadInternalPage(#loading, sizeof(loading));
624
		else WB1.LoadInternalPage(#page_not_found, sizeof(page_not_found));
625
	}
626
	else
627
	{
628
		WB1.Prepare();
629
	}
630
}
631
 
632
byte UrlExtIs(dword ext)
633
{
634
	if (!strcmpi(#URL + strlen(#URL) - strlen(ext), ext)) return true;
635
	return false;
636
}
637
 
638
void DrawProgress()
639
{
640
	dword persent;
641
	if (http.transfer == 0) return;
642
	if (wv_progress_bar.max) persent = wv_progress_bar.value*100/wv_progress_bar.max; else persent = 10;
643
	DrawBar(address_box.left-2, address_box.top+20, persent*address_box.width/100, 2, wv_progress_bar.progress_color);
644
}
645
 
6795 leency 646
void EventShowPageMenu(dword _left, _top)
6782 leency 647
{
648
	menu.show(Form.left+_left-6,Form.top+_top+skin_height+3, 220, #rmb_menu, VIEW_SOURCE);
649
}
650
 
6795 leency 651
void EventShowLinkMenu(dword _left, _top)
652
{
7282 leency 653
	menu.show(Form.left+_left-6,Form.top+_top+skin_height+3, 220, #link_menu, COPY_LINK_URL);
6795 leency 654
}
655
 
7281 leency 656
void EventUpdateProgressBar()
657
{
658
	wv_progress_bar.max = http.content_length;
659
	if (wv_progress_bar.value != http.content_received)
660
	{
661
		wv_progress_bar.value = http.content_received;
662
		DrawProgress();
663
	}
664
}
6795 leency 665
 
7743 leency 666
void EventSeachWeb()
667
{
668
	sprintf(#URL, "https://www.google.com/search?q=%s", #editURL);
669
	ProcessLink();
670
}
671
 
7742 leency 672
void DrawStatusBar(dword _status_text)
6795 leency 673
{
674
	status_text.start_x = wv_progress_bar.left + wv_progress_bar.width + 10;
675
	status_text.start_y = Form.cheight - STATUSBAR_H + 3;
676
	status_text.area_size_x = Form.cwidth - status_text.start_x -3;
677
	DrawBar(status_text.start_x, status_text.start_y, status_text.area_size_x, 9, col_bg);
678
	status_text.text_pointer = _status_text;
679
	PathShow_prepare stdcall(#status_text);
680
	PathShow_draw stdcall(#status_text);
681
}
682
 
5631 pavelyakov 683
stop: