Subversion Repositories Kolibri OS

Rev

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