Subversion Repositories Kolibri OS

Rev

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