Subversion Repositories Kolibri OS

Rev

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