Subversion Repositories Kolibri OS

Rev

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