Subversion Repositories Kolibri OS

Rev

Rev 7746 | Rev 7749 | 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
 
7281 leency 31
_http http = {0, 0, 0, 0, 0, 0, 0};
32
 
4677 leency 33
 
4026 leency 34
#ifdef LANG_RUS
7748 leency 35
char version[]="Текстовый браузер 1.92";
36
#define T_LOADING "Загрузка страницы..."
37
#define T_RENDERING "Рендеринг..."
6698 leency 38
char page_not_found[] = FROM "html\\page_not_found_ru.htm""\0";
7743 leency 39
char homepage[] = FROM "html\\homepage_ru.htm""\0";
40
char help[] = FROM "html\\help_ru.htm""\0";
6045 leency 41
char accept_language[]= "Accept-Language: ru\n";
42
char rmb_menu[] =
43
"Посмотреть исходник
44
Редактировать исходник
45
История
46
Менеджер загрузок";
7037 leency 47
char link_menu[] =
7208 leency 48
"Копировать ссылку
49
Скачать содержимое ссылки";
4026 leency 50
#else
7746 leency 51
char version[]="Text-based Browser 1.9";
7748 leency 52
#define T_LOADING "Loading..."
53
#define T_RENDERING "Rendering..."
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
 
4074 leency 76
char stak[4096];
5640 pavelyakov 77
 
4026 leency 78
int action_buf;
79
 
6731 leency 80
dword TOOLBAR_H = 40;
5519 leency 81
dword STATUSBAR_H = 15;
4677 leency 82
 
7425 leency 83
dword col_bg = 0xE3E2E2;
84
dword panel_color  = 0xE3E2E2;
85
dword border_color = 0x8C8C8C;
86
 
7282 leency 87
bool debug_mode = false;
88
 
5718 leency 89
progress_bar wv_progress_bar;
7748 leency 90
 
6931 leency 91
bool souce_mode = false;
92
bool open_in_a_new_window = false;
4677 leency 93
 
5718 leency 94
enum {
95
	BACK_BUTTON=1000,
96
	FORWARD_BUTTON,
97
	REFRESH_BUTTON,
98
	GOTOURL_BUTTON,
6795 leency 99
	SANDWICH_BUTTON,
5768 leency 100
	VIEW_SOURCE=1100,
5718 leency 101
	EDIT_SOURCE,
102
	VIEW_HISTORY,
6795 leency 103
	DOWNLOAD_MANAGER,
7282 leency 104
	COPY_LINK_URL=1200,
7208 leency 105
	DOWNLOAD_LINK_CONTENTS,
5718 leency 106
};
107
 
4411 leency 108
#include "..\TWB\TWB.c"
4636 leency 109
#include "history.h"
4718 leency 110
#include "show_src.h"
6001 leency 111
#include "download_manager.h"
3067 leency 112
 
7748 leency 113
char default_dir[] = "/rd/1";
114
od_filter filter2 = { 16, "TXT\0HTM\0HTML\0\0" };
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
 
7748 leency 121
void LoadLibraries()
122
{
123
	load_dll(boxlib,    #box_lib_init,0);
124
	load_dll(libio,     #libio_init,1);
125
	load_dll(libimg,    #libimg_init,1);
126
	load_dll(libHTTP,   #http_lib_init,1);
127
	load_dll(iconv_lib, #iconv_open,0);
128
	load_dll(Proc_lib,  #OpenDialog_init,0);
129
	OpenDialog_init stdcall (#o_dialog);
130
}
131
 
132
void HandleParam()
133
{
134
	if (param) {
135
		if (param[0]=='-') && (param[1]=='d') {
136
			strcpy(#downloader_edit, #param+3);
137
			CreateThread(#Downloader,#downloader_stak+4092);
138
			ExitProcess();
139
		} else {
140
			strcpy(#URL, #param);
141
		}
142
	} else {
143
		strcpy(#URL, URL_SERVICE_HOMEPAGE);
144
	}
145
}
146
 
3067 leency 147
void main()
148
{
7748 leency 149
	int redirect_count = 0;
7422 leency 150
	int i;
7748 leency 151
	LoadLibraries();
152
	CreateDir("/tmp0/1/downloads");
7428 leency 153
	Libimg_LoadImage(#skin, "/sys/toolbar.png");
7748 leency 154
	HandleParam();
7437 leency 155
	skin.h = 26;
6045 leency 156
	WB1.list.SetFont(8, 14, 10011000b);
5779 leency 157
	WB1.list.no_selection = true;
6978 leency 158
	SetEventMask(EVM_REDRAW + EVM_KEY + EVM_BUTTON + EVM_MOUSE + EVM_MOUSE_FILTER + EVM_STACK);
159
	loop() switch(WaitEvent())
160
	{
161
		case evMouse:
162
			edit_box_mouse stdcall (#address_box);
163
			mouse.get();
7282 leency 164
			if (PageLinks.HoverAndProceed(mouse.x, WB1.list.first + mouse.y))
165
			&& (bufsize) && (mouse.pkm) && (mouse.up) {
166
				if (WB1.list.MouseOver(mouse.x, mouse.y)) EventShowPageMenu(mouse.x, mouse.y);
167
				break;
6978 leency 168
			}
7282 leency 169
			if (WB1.list.MouseScroll(mouse.vert)) WB1.DrawPage();
6978 leency 170
			scrollbar_v_mouse (#scroll_wv);
171
			if (WB1.list.first != scroll_wv.position)
172
			{
173
				WB1.list.first = scroll_wv.position;
174
				WB1.DrawPage();
3067 leency 175
				break;
6978 leency 176
			}
177
			break;
5711 leency 178
 
6978 leency 179
		case evButton:
180
			ProcessEvent(GetButtonID());
181
			break;
5711 leency 182
 
6978 leency 183
		case evKey:
184
			GetKeys();
7742 leency 185
			if (key_modifier&KEY_LCTRL) || (key_modifier&KEY_RCTRL) {
7748 leency 186
				if (key_scancode == SCAN_CODE_KEY_O) EventOpenDialog();
7742 leency 187
				if (key_scancode == SCAN_CODE_KEY_H) ProcessEvent(VIEW_HISTORY);
188
				if (key_scancode == SCAN_CODE_KEY_U) ProcessEvent(VIEW_SOURCE);
189
				if (key_scancode == SCAN_CODE_KEY_T)
190
				|| (key_scancode == SCAN_CODE_KEY_N) RunProgram(#program_path, NULL);
191
				if (key_scancode == SCAN_CODE_KEY_W) ExitProcess();
192
				if (key_scancode == SCAN_CODE_KEY_J) ProcessEvent(DOWNLOAD_MANAGER);
7743 leency 193
				if (key_scancode == SCAN_CODE_KEY_R) ProcessEvent(REFRESH_BUTTON);
194
				if (key_scancode == SCAN_CODE_ENTER) EventSeachWeb();
195
				if (key_scancode == SCAN_CODE_LEFT)  ProcessEvent(BACK_BUTTON);
196
				if (key_scancode == SCAN_CODE_RIGHT) ProcessEvent(FORWARD_BUTTON);
7742 leency 197
			}
7743 leency 198
 
199
			if (key_scancode == SCAN_CODE_F5) ProcessEvent(REFRESH_BUTTON);
200
 
7506 leency 201
			if (address_box.flags & ed_focus)
6978 leency 202
			{
7742 leency 203
				if (key_scancode == SCAN_CODE_ENTER) {
204
					ProcessEvent(key_scancode);
205
				}
206
				else {
6978 leency 207
					EAX = key_editbox;
208
					edit_box_key stdcall(#address_box);
5530 leency 209
				}
6978 leency 210
			}
211
			else
212
			{
7422 leency 213
				#define KEY_SCROLL_N 11
214
				if (SCAN_CODE_UP   == key_scancode) for (i=0;i
215
				if (SCAN_CODE_DOWN == key_scancode) for (i=0;i
7743 leency 216
				if (key_scancode == SCAN_CODE_F6) {address_box.flags=ed_focus; DrawOmnibox();}
6978 leency 217
				if (WB1.list.ProcessKey(key_scancode)) WB1.DrawPage();
218
				else ProcessEvent(key_scancode);
219
			}
220
			break;
221
 
222
		case evReDraw:
7450 leency 223
			if (menu.cur_y) {
224
				ProcessEvent(menu.cur_y);
225
				menu.cur_y = 0;
6978 leency 226
			}
7748 leency 227
			DefineAndDrawWindow(GetScreenWidth()-800/2-random(80),GetScreenHeight()-600/2-random(80),800,600,0x73,0,0,0);
6978 leency 228
			GetProcessInfo(#Form, SelfInfo);
7748 leency 229
			system.color.get();
230
			col_bg = system.color.work;
6978 leency 231
			if (Form.status_window>2) { DrawTitle(#header); break; }
232
			if (Form.height<120) { MoveSize(OLD,OLD,OLD,120); break; }
233
			if (Form.width<280) { MoveSize(OLD,OLD,280,OLD); break; }
7748 leency 234
			draw_window();
6978 leency 235
			break;
236
 
237
		case evNetwork:
7281 leency 238
			if (http.transfer > 0) {
239
				http.receive();
240
				EventUpdateProgressBar();
7748 leency 241
				DrawStatusBar(T_LOADING);
7281 leency 242
				if (http.receive_result == 0) {
6978 leency 243
					// Handle redirects
7281 leency 244
					if (http.status_code >= 300) && (http.status_code < 400)
4686 leency 245
					{
7748 leency 246
						redirect_count++;
247
						if (redirect_count>5)
4563 leency 248
						{
7282 leency 249
							notify("'Too many redirects.' -E");
250
							StopLoading();
4558 hidnplayr 251
						}
4563 leency 252
						else
253
						{
7282 leency 254
							http.handle_redirect();
255
							http.free();
256
							GetAbsoluteURL(#http.redirect_url);
7748 leency 257
							debug("Redirect: "); debugln(#http.redirect_url);
7282 leency 258
							history.back();
7748 leency 259
							strcpy(#URL, #http.redirect_url);
7282 leency 260
							strcpy(#editURL, #URL);
7743 leency 261
							DrawOmnibox();
7282 leency 262
							OpenPage();
7742 leency 263
							//ProcessLink(history.current());
4558 hidnplayr 264
						}
7282 leency 265
						break;
6978 leency 266
					}
7748 leency 267
					redirect_count = 0;
6978 leency 268
					// Loading the page is complete, free resources
7282 leency 269
					history.add(#URL);
270
					bufpointer = http.content_pointer;
271
					bufsize = http.content_received;
272
					http.free();
273
					SetPageDefaults();
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);
7282 leency 315
	if (!header)
316
		OpenPage();
317
	else {
318
		WB1.DrawPage();
7743 leency 319
		DrawOmnibox();
7282 leency 320
	}
4692 leency 321
	DrawRectangle(scroll_wv.start_x, scroll_wv.start_y, scroll_wv.size_x, scroll_wv.size_y-1, scroll_wv.bckg_col);
4693 leency 322
	DrawProgress();
3067 leency 323
}
324
 
325
 
6698 leency 326
void ProcessEvent(dword id__)
4413 leency 327
{
6698 leency 328
	switch (id__)
4413 leency 329
	{
6698 leency 330
		case 1:
331
			ExitProcess();
332
			return;
5711 leency 333
		case SCAN_CODE_BS:
5718 leency 334
		case BACK_BUTTON:
6021 leency 335
			if (history.back()) {
336
				strcpy(#URL, history.current());
5978 leency 337
				OpenPage();
338
			}
5711 leency 339
			return;
5718 leency 340
		case FORWARD_BUTTON:
6021 leency 341
			if (history.forward()) {
342
				strcpy(#URL, history.current());
5978 leency 343
				OpenPage();
344
			}
5711 leency 345
			return;
5718 leency 346
		case GOTOURL_BUTTON:
5772 leency 347
		case SCAN_CODE_ENTER:
7742 leency 348
			EventSubmitOmnibox();
5711 leency 349
			return;
5718 leency 350
		case REFRESH_BUTTON:
7281 leency 351
			if (http.transfer > 0)
5713 leency 352
			{
353
				StopLoading();
7748 leency 354
				draw_window();
5713 leency 355
			}
356
			else OpenPage();
357
			return;
5718 leency 358
		case SANDWICH_BUTTON:
6795 leency 359
			EventShowPageMenu(Form.cwidth - 215, TOOLBAR_H-6);
4415 leency 360
			return;
5718 leency 361
		case VIEW_SOURCE:
362
			WB1.list.first = 0;
363
			ShowSource();
5773 leency 364
			WB1.LoadInternalPage(bufpointer, bufsize);
5718 leency 365
			break;
366
		case EDIT_SOURCE:
7282 leency 367
			if (!strncmp(#URL,"http",4))
5718 leency 368
			{
7227 leency 369
				CreateFile(bufsize, bufpointer, "/tmp0/1/WebView_tmp.htm");
5718 leency 370
				if (!EAX) RunProgram("/rd/1/tinypad", "/tmp0/1/WebView_tmp.htm");
371
			}
372
			else RunProgram("/rd/1/tinypad", #URL);
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
 
421
void SetPageDefaults()
422
{
423
	strcpy(#header, #version);
424
	WB1.list.count = WB1.list.first = 0;
5704 leency 425
	cur_encoding = CH_NULL;
4645 leency 426
	if (o_bufpointer) o_bufpointer = free(o_bufpointer);
4636 leency 427
}
428
 
7720 leency 429
void ReplaceSpaceInUrl() {
430
	int i;
431
	strcpy(#editURL, #URL);
432
	while (i = strchr(#URL, ' '))
433
	{
434
		i -= #URL;
435
		strlcpy(#URL+i+3, #editURL+i+1, sizeof(URL)-i-4);
436
		URL[i] = '%';
437
		URL[i+1] = '2';
438
		URL[i+2] = '0';
439
	}
440
	strcpy(#editURL, #URL);
441
}
442
 
4416 leency 443
void OpenPage()
444
{
7282 leency 445
	char getUrl[sizeof(URL)];
4636 leency 446
	StopLoading();
4718 leency 447
	souce_mode = false;
4416 leency 448
	strcpy(#editURL, #URL);
6021 leency 449
	history.add(#URL);
5631 pavelyakov 450
	if (!strncmp(#URL,"WebView:",8))
4692 leency 451
	{
452
		SetPageDefaults();
7743 leency 453
		if (!strcmp(#URL, URL_SERVICE_HOMEPAGE)) WB1.LoadInternalPage(#homepage, sizeof(homepage));
454
		else if (!strcmp(#URL, URL_SERVICE_HELP)) WB1.LoadInternalPage(#help, sizeof(help));
5631 pavelyakov 455
		else if (!strcmp(#URL, URL_SERVICE_HISTORY)) ShowHistory();
7739 leency 456
		else {bufsize=0; ShowPage();} //page not found
7743 leency 457
		DrawOmnibox();
4692 leency 458
		return;
459
	}
7282 leency 460
	if (!strncmp(#URL,"http:",5)) || (!strncmp(#URL,"https://",8))
4416 leency 461
	{
7720 leency 462
		ReplaceSpaceInUrl();
7428 leency 463
		img_draw stdcall(skin.image, address_box.left+address_box.width+1, address_box.top-3, 17, skin.h, 68, SKIN_Y);
7282 leency 464
 
465
		if (!strncmp(#URL,"http:",5)) {
466
			http.get(#URL);
467
		}
468
		if (!strncmp(#URL,"https://",8)) {
469
			sprintf(#getUrl, "http://gate.aspero.pro/?site=%s", #URL);
470
			http.get(#getUrl);
471
		}
472
		//http.get(#URL);
7281 leency 473
		if (!http.transfer)
4646 leency 474
		{
475
			StopLoading();
476
			bufsize = 0;
5631 pavelyakov 477
			bufpointer = free(bufpointer);
4646 leency 478
			ShowPage();
479
			return;
480
		}
4416 leency 481
	}
4636 leency 482
	else
483
	{
484
		file_size stdcall (#URL);
7739 leency 485
		if (EBX)
4650 leency 486
		{
7739 leency 487
			bufsize = EBX;
5631 pavelyakov 488
			free(bufpointer);
489
			bufpointer = malloc(bufsize);
4650 leency 490
			SetPageDefaults();
4718 leency 491
			ReadFile(0, bufsize, bufpointer, #URL);
4650 leency 492
		}
4645 leency 493
		ShowPage();
4636 leency 494
	}
4416 leency 495
}
4415 leency 496
 
7742 leency 497
void ProcessAnchor()
4508 leency 498
{
7742 leency 499
	char anchor[256];
500
	int anchor_pos;
501
 
502
	anchor_pos = strrchr(#URL, '#')-1;
503
	strlcpy(#anchor, #URL+anchor_pos, sizeof(anchor));
504
	URL[anchor_pos] = 0x00;
4415 leency 505
 
7742 leency 506
	//#1
507
	if (URL[0] == NULL)
4508 leency 508
	{
7742 leency 509
		if (anchor[1] == NULL) {
510
			WB1.list.first = 0;
511
		}
512
		else {
513
			if (anchors.get_anchor_pos(#anchor+1)!=-1) WB1.list.first = anchors.get_anchor_pos(#anchor+1);
514
		}
515
		strcpy(#URL, history.current());
4508 leency 516
	}
7742 leency 517
	//liner.ru#1
4508 leency 518
	else
5768 leency 519
	{
7742 leency 520
		GetAbsoluteURL(#URL);
521
		OpenPage();
522
		if (anchors.get_anchor_pos(#anchor+1)!=-1) WB1.list.first = anchors.get_anchor_pos(#anchor+1);
5768 leency 523
	}
7742 leency 524
 
525
	WB1.DrawPage();
526
	strcpy(#editURL, #URL);
527
	strcat(#editURL, #anchor);
7743 leency 528
	DrawOmnibox();
4508 leency 529
}
530
 
7742 leency 531
void EventSubmitOmnibox()
5493 leency 532
{
7742 leency 533
	if (!editURL[0]) return;
534
	if (!strncmp(#editURL,"http:",5)) || (editURL[0]=='/')
535
	|| (!strncmp(#editURL,"https:",6)) || (!strncmp(#editURL,"WebView:",8))
536
	{
537
		strcpy(#URL, #editURL);
538
	}
539
	else
540
	{
541
		strlcpy(#URL,"http://",7);
542
		strcat(#URL, #editURL);
543
	}
544
	ProcessLink();
5493 leency 545
}
4508 leency 546
 
7742 leency 547
void EventClickLink()
5772 leency 548
{
7742 leency 549
	strcpy(#URL, PageLinks.GetURL(PageLinks.active));
550
	GetAbsoluteURL(#URL);
551
	ProcessLink();
5772 leency 552
}
5746 leency 553
 
7742 leency 554
void ProcessLink()
5774 leency 555
{
7281 leency 556
	if (http.transfer > 0)
5774 leency 557
	{
558
		StopLoading();
6021 leency 559
		history.back();
5774 leency 560
	}
7742 leency 561
 
562
	if (strrchr(#URL, '#')!=0) {
563
		ProcessAnchor();
5774 leency 564
		return;
565
	}
6730 leency 566
 
7742 leency 567
	if (!strncmp(#URL,"mailto:", 7)) || (!strncmp(#URL,"tel:", 4))
6730 leency 568
	{
569
		notify(#URL);
570
		strcpy(#editURL, history.current());
571
		strcpy(#URL, history.current());
572
		return;
573
	}
574
 
7742 leency 575
	if (!strncmp(#URL,"WebView:",8)) {
576
		OpenPage();
577
		return;
578
	}
6730 leency 579
 
7282 leency 580
	if (strncmp(#URL,"http://",7)!=0) && (strncmp(#URL,"https://",8)!=0)
5774 leency 581
	{
6730 leency 582
		if (UrlExtIs(".htm")!=true) && (UrlExtIs(".html")!=true)
583
		{
7422 leency 584
			if (strchr(#URL, '|')) {
585
				ESBYTE[strchr(#URL, '|')] = NULL;
586
				RunProgram(#URL, strlen(#URL)+1+#URL);
587
			}
588
			else {
589
				RunProgram("/sys/@open", #URL);
590
			}
6730 leency 591
			strcpy(#editURL, history.current());
592
			strcpy(#URL, history.current());
593
			return;
594
		}
595
	}
596
	else
597
	{
598
		if (UrlExtIs(".png")==true) || (UrlExtIs(".gif")==true) || (UrlExtIs(".jpg")==true)
6794 leency 599
		|| (UrlExtIs(".zip")==true) || (UrlExtIs(".kex")==true) || (UrlExtIs(".pdf")==true)
600
		|| (UrlExtIs(".7z")==true) {
6986 leency 601
			if (!downloader_opened) {
602
				strcpy(#downloader_edit, #URL);
603
				CreateThread(#Downloader,#downloader_stak+4092);
604
				strcpy(#editURL, history.current());
605
				strcpy(#URL, history.current());
606
			}
607
			else notify("'WebView\nPlease, start a new download only when previous ended.'Et");
6730 leency 608
			return;
5774 leency 609
		}
610
	}
6931 leency 611
	if (open_in_a_new_window)
612
	{
613
		RunProgram(#program_path, #URL);
614
		strcpy(#editURL, history.current());
615
		strcpy(#URL, history.current());
616
	}
617
	else
618
	{
619
		OpenPage();
620
	}
621
	open_in_a_new_window = false;
5774 leency 622
}
623
 
7743 leency 624
void DrawOmnibox()
7742 leency 625
{
626
	int skin_x_offset;
627
	DrawBar(address_box.left-2, address_box.top-2, address_box.width+3, 2, address_box.color);
628
	DrawBar(address_box.left-2, address_box.top, 2, 22, address_box.color);
629
	//address_box.size = address_box.pos = address_box.shift = address_box.shift_old = strlen(#editURL);
630
	//address_box.offset = 0;
631
	EditBox_UpdateText(#address_box, address_box.flags);
632
	edit_box_draw stdcall(#address_box);
633
	if (http.transfer > 0) skin_x_offset = 68; else skin_x_offset = 51;
634
	img_draw stdcall(skin.image, address_box.left+address_box.width+1, address_box.top-3, 17, skin.h, skin_x_offset, SKIN_Y);
635
}
636
 
637
 
638
void ShowPage()
639
{
7743 leency 640
	DrawOmnibox();
7742 leency 641
	if (!bufsize)
642
	{
7748 leency 643
		WB1.LoadInternalPage(#page_not_found, sizeof(page_not_found));
7742 leency 644
	}
645
	else
646
	{
647
		WB1.Prepare();
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
 
7742 leency 701
void DrawStatusBar(dword _status_text)
6795 leency 702
{
7748 leency 703
	status_text.start_x = 10;
6795 leency 704
	status_text.start_y = Form.cheight - STATUSBAR_H + 3;
705
	status_text.area_size_x = Form.cwidth - status_text.start_x -3;
706
	DrawBar(status_text.start_x, status_text.start_y, status_text.area_size_x, 9, col_bg);
707
	status_text.text_pointer = _status_text;
708
	PathShow_prepare stdcall(#status_text);
709
	PathShow_draw stdcall(#status_text);
710
}
711
 
5631 pavelyakov 712
stop: