Subversion Repositories Kolibri OS

Rev

Rev 7755 | Rev 7757 | 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"
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
7755 leency 32
char version[]="Текстовый браузер 2.0 beta2";
6698 leency 33
char page_not_found[] = FROM "html\\page_not_found_ru.htm""\0";
7743 leency 34
char homepage[] = FROM "html\\homepage_ru.htm""\0";
35
char help[] = FROM "html\\help_ru.htm""\0";
6045 leency 36
char accept_language[]= "Accept-Language: ru\n";
37
char rmb_menu[] =
38
"Посмотреть исходник
39
Редактировать исходник
40
История
41
Менеджер загрузок";
7037 leency 42
char link_menu[] =
7208 leency 43
"Копировать ссылку
44
Скачать содержимое ссылки";
4026 leency 45
#else
7755 leency 46
char version[]="Text-based Browser 2.0 beta2";
6698 leency 47
char page_not_found[] = FROM "html\\page_not_found_en.htm""\0";
7743 leency 48
char homepage[] = FROM "html\\homepage_en.htm""\0";
49
char help[] = FROM "html\\help_en.htm""\0";
6045 leency 50
char accept_language[]= "Accept-Language: en\n";
51
char rmb_menu[] =
52
"View source
53
Edit source
54
History
55
Download Manager";
7037 leency 56
char link_menu[] =
7208 leency 57
"Copy link
58
Download link contents";
4026 leency 59
#endif
60
 
7756 leency 61
#define URL_SIZE 4000
7752 leency 62
 
7750 leency 63
dword col_bg = 0xE3E2E2;
64
dword panel_color  = 0xE3E2E2;
7755 leency 65
dword border_color = 0x787878;
6795 leency 66
 
7750 leency 67
bool debug_mode = false;
5631 pavelyakov 68
 
7750 leency 69
_http http = {0, 0, 0, 0, 0, 0, 0};
3067 leency 70
 
7750 leency 71
#include "..\TWB\TWB.c"
72
#include "history.h"
73
#include "show_src.h"
74
#include "download_manager.h"
5640 pavelyakov 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();
7282 leency 161
			if (PageLinks.HoverAndProceed(mouse.x, WB1.list.first + mouse.y))
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();
253
							GetAbsoluteURL(#http.redirect_url);
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) {
7738 leency 280
		WB1.DrawBuf.Init(WB1.list.x, WB1.list.y, WB1.list.w, 800*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();
304
	}
7282 leency 305
	else {
306
		WB1.DrawPage();
7743 leency 307
		DrawOmnibox();
7282 leency 308
	}
7755 leency 309
	DrawRectangle(scroll_wv.start_x, scroll_wv.start_y, scroll_wv.size_x,
310
		scroll_wv.size_y-1, scroll_wv.bckg_col);
4693 leency 311
	DrawProgress();
3067 leency 312
}
313
 
314
 
6698 leency 315
void ProcessEvent(dword id__)
4413 leency 316
{
6698 leency 317
	switch (id__)
4413 leency 318
	{
6698 leency 319
		case 1:
320
			ExitProcess();
321
			return;
5711 leency 322
		case SCAN_CODE_BS:
5718 leency 323
		case BACK_BUTTON:
6021 leency 324
			if (history.back()) {
7755 leency 325
				OpenPage(history.current());
5978 leency 326
			}
5711 leency 327
			return;
5718 leency 328
		case FORWARD_BUTTON:
6021 leency 329
			if (history.forward()) {
7755 leency 330
				OpenPage(history.current());
5978 leency 331
			}
5711 leency 332
			return;
5718 leency 333
		case GOTOURL_BUTTON:
5772 leency 334
		case SCAN_CODE_ENTER:
7742 leency 335
			EventSubmitOmnibox();
5711 leency 336
			return;
5718 leency 337
		case REFRESH_BUTTON:
7755 leency 338
			if (http.transfer > 0) {
5713 leency 339
				StopLoading();
7748 leency 340
				draw_window();
7755 leency 341
			} else {
342
				OpenPage(history.current());
5713 leency 343
			}
344
			return;
5718 leency 345
		case SANDWICH_BUTTON:
6795 leency 346
			EventShowPageMenu(Form.cwidth - 215, TOOLBAR_H-6);
4415 leency 347
			return;
5718 leency 348
		case VIEW_SOURCE:
7750 leency 349
			EventViewSource();
5718 leency 350
			break;
351
		case EDIT_SOURCE:
7755 leency 352
			if (check_is_the_adress_local(history.current())) {
353
				RunProgram("/rd/1/tinypad", history.current());
7750 leency 354
			} else {
7227 leency 355
				CreateFile(bufsize, bufpointer, "/tmp0/1/WebView_tmp.htm");
5718 leency 356
				if (!EAX) RunProgram("/rd/1/tinypad", "/tmp0/1/WebView_tmp.htm");
357
			}
4415 leency 358
			return;
5718 leency 359
		case VIEW_HISTORY:
7755 leency 360
			OpenPage(URL_SERVICE_HISTORY);
4544 leency 361
			return;
5718 leency 362
		case DOWNLOAD_MANAGER:
5519 leency 363
			if (!downloader_opened) {
6001 leency 364
				downloader_edit = NULL;
5519 leency 365
				CreateThread(#Downloader,#downloader_stak+4092);
366
			}
4413 leency 367
			return;
7282 leency 368
		case COPY_LINK_URL:
7037 leency 369
			Clipboard__CopyText(PageLinks.GetURL(PageLinks.active));
370
			notify("'URL copied to clipboard'O");
371
			return;
7208 leency 372
		case DOWNLOAD_LINK_CONTENTS:
373
			if (!downloader_opened) {
374
				strcpy(#downloader_edit, PageLinks.GetURL(PageLinks.active));
375
				CreateThread(#Downloader,#downloader_stak+4092);
376
			}
377
			return;
7282 leency 378
		case SCAN_CODE_F12:
379
			debug_mode ^= 1;
380
			if (debug_mode) notify("'Debug mode ON'-I");
381
			else notify("'Debug mode OFF'-I");
382
			return;
4413 leency 383
	}
384
}
385
 
4636 leency 386
void StopLoading()
387
{
7281 leency 388
	if (http.transfer)
4647 leency 389
	{
7281 leency 390
		EAX = http.transfer;
4647 leency 391
		EAX = EAX.http_msg.content_ptr;		// get pointer to data
392
		$push	EAX							// save it on the stack
7281 leency 393
		http_free stdcall (http.transfer);	// abort connection
4647 leency 394
		$pop	EAX
5631 pavelyakov 395
		free(EAX);						// free data
7281 leency 396
		http.transfer=0;
7746 leency 397
		pause(10);
4647 leency 398
	}
5519 leency 399
	wv_progress_bar.value = 0;
7743 leency 400
	DrawOmnibox();
4645 leency 401
}
402
 
7756 leency 403
//rewrite into
404
//bool strrpl(dword dst, from, to, dst_len); !!!!!!!!
405
void ReplaceSpaceInUrl(dword url, size) {
406
	unsigned int i, j;
407
	for (i=size-3; i>0; i--)
7720 leency 408
	{
7756 leency 409
		if (ESBYTE[i]!=' ') continue;
410
		for (j=size-3; j>i; j--) {
411
			ESBYTE[j+2]=ESBYTE[j+1];
412
			ESBYTE[j+1]=ESBYTE[j];
413
		}
414
		ESBYTE[i] = '%';
415
		ESBYTE[i+1] = '2';
416
		ESBYTE[i+2] = '0';
7720 leency 417
	}
7756 leency 418
	debugln(url);
7720 leency 419
}
420
 
7755 leency 421
bool GetLocalFileData(dword _path)
4416 leency 422
{
7755 leency 423
	dword data, size;
424
	file_size stdcall (_path);
425
	if (!EBX) {
426
		return false;
427
	} else {
428
		size = EBX;
429
		data = malloc(size);
430
		ReadFile(0, size, data, _path);
431
		LoadInternalPage(data, size);
432
		free(data);
433
		return true;
4692 leency 434
	}
7755 leency 435
}
7282 leency 436
 
7755 leency 437
void OpenPage(dword _open_URL)
438
{
439
	char new_url[URL_SIZE+1];
440
 
441
	StopLoading();
442
 
443
	strcpy(#editURL, _open_URL);
444
	DrawOmnibox();
445
 
446
	strncpy(#new_url, _open_URL, URL_SIZE);
447
 
448
	//Exclude # from the URL to the load page
449
	//We will bring it back when we get the buffer
450
	if (strrchr(#new_url, '#')) anchors.take_anchor_from(#new_url);
451
 
452
	history.add(#new_url);
453
 
454
	if (!strncmp(#new_url,"WebView:",8)) {
455
		//INTERNAL PAGE
456
		if (!strcmp(#new_url, URL_SERVICE_HOMEPAGE)) LoadInternalPage(#homepage, sizeof(homepage));
457
		else if (!strcmp(#new_url, URL_SERVICE_HELP)) LoadInternalPage(#help, sizeof(help));
458
		else if (!strcmp(#new_url, URL_SERVICE_HISTORY)) ShowHistory();
459
		else LoadInternalPage(#page_not_found, sizeof(page_not_found));
460
	} else if (!strncmp(#new_url,"http:",5)) || (!strncmp(#new_url,"https:",6)) {
461
		//WEB PAGE
462
		img_draw stdcall(skin.image, address_box.left+address_box.width+1,
463
			address_box.top-3, 17, skin.h, 85, SKIN_Y);
464
 
7756 leency 465
		//ReplaceSpaceInUrl(#new_url, URL_SIZE);
7755 leency 466
		if (!strncmp(#new_url,"http:",5)) {
467
			http.get(#new_url);
468
		} else if (!strncmp(#new_url,"https://",8)) {
469
			strcpy(#new_url, "http://gate.aspero.pro/?site=");
470
			strncat(#new_url, _open_URL, URL_SIZE);
471
			http.get(#new_url);
7282 leency 472
		}
7755 leency 473
		if (!http.transfer) {
4646 leency 474
			StopLoading();
7755 leency 475
			LoadInternalPage(#page_not_found, sizeof(page_not_found));
4646 leency 476
		}
7755 leency 477
	} else {
478
		//LOCAL PAGE
479
		if (!GetLocalFileData(#new_url)) {
480
			LoadInternalPage(#page_not_found, sizeof(page_not_found));
4650 leency 481
		}
4636 leency 482
	}
4416 leency 483
}
4415 leency 484
 
7755 leency 485
void EventClickLink(dword _click_URL)
4508 leency 486
{
7756 leency 487
	char new_url[URL_SIZE+1];
4415 leency 488
 
7755 leency 489
	if (ESBYTE[_click_URL]=='#') {
490
		if (anchors.get_pos_by_name(_click_URL+1)!=-1) {
491
			WB1.list.first = anchors.get_pos_by_name(_click_URL+1);
492
			WB1.list.CheckDoesValuesOkey();
493
		}
494
		strcpy(#editURL, history.current());
495
		strcat(#editURL, _click_URL);
496
		DrawOmnibox();
497
		WB1.DrawPage();
498
		return;
5768 leency 499
	}
7742 leency 500
 
7755 leency 501
	if (!strncmp(_click_URL,"mailto:", 7)) || (!strncmp(_click_URL,"tel:", 4)) {
502
		notify(_click_URL);
503
		return;
7742 leency 504
	}
4508 leency 505
 
7755 leency 506
	if (http.transfer > 0) {
5774 leency 507
		StopLoading();
6021 leency 508
		history.back();
5774 leency 509
	}
6730 leency 510
 
7755 leency 511
	strcpy(#new_url, _click_URL);
512
	GetAbsoluteURL(#new_url);
513
 
514
	if (strrchr(#new_url, '#')!=0) {
515
		anchors.take_anchor_from(#new_url);
516
		OpenPage(#new_url);
6730 leency 517
		return;
518
	}
519
 
7755 leency 520
	if (!strncmp(#new_url,"WebView:",8)) {
521
		OpenPage(#new_url);
7742 leency 522
		return;
523
	}
6730 leency 524
 
7755 leency 525
	if (strncmp(#new_url,"http://",7)!=0) && (strncmp(#new_url,"https://",8)!=0)
5774 leency 526
	{
7755 leency 527
		if (UrlExtIs(#new_url,".htm")!=true) && (UrlExtIs(#new_url,".html")!=true)
6730 leency 528
		{
7755 leency 529
			if (strchr(#new_url, '|')) {
530
				ESBYTE[strchr(#new_url, '|')] = NULL;
531
				RunProgram(#new_url, strlen(#new_url)+1+#new_url);
532
			} else {
533
				RunProgram("/sys/@open", #new_url);
7422 leency 534
			}
6730 leency 535
			return;
536
		}
7755 leency 537
	} else {
538
		if (UrlExtIs(#new_url,".png")==true) || (UrlExtIs(#new_url,".jpg")==true)
539
		|| (UrlExtIs(#new_url,".zip")==true) || (UrlExtIs(#new_url,".kex")==true) || (UrlExtIs(#new_url,".pdf")==true)
540
		|| (UrlExtIs(#new_url,".7z")==true) {
6986 leency 541
			if (!downloader_opened) {
7755 leency 542
				strcpy(#downloader_edit, #new_url);
6986 leency 543
				CreateThread(#Downloader,#downloader_stak+4092);
544
			}
545
			else notify("'WebView\nPlease, start a new download only when previous ended.'Et");
6730 leency 546
			return;
5774 leency 547
		}
548
	}
7755 leency 549
	OpenPage(#new_url);
550
}
551
 
552
void EventSubmitOmnibox()
553
{
554
	char new_url[URL_SIZE+1];
555
	if (!editURL[0]) return;
556
	if (!strncmp(#editURL,"http:",5)) || (editURL[0]=='/')
557
	|| (!strncmp(#editURL,"https:",6)) || (!strncmp(#editURL,"WebView:",8)) {
558
		OpenPage(#editURL);
559
	} else {
560
		strcpy(#new_url, "http://");
561
		strncat(#new_url, #editURL, sizeof(new_url)-1);
562
		OpenPage(#new_url);
6931 leency 563
	}
5774 leency 564
}
565
 
7743 leency 566
void DrawOmnibox()
7742 leency 567
{
568
	int skin_x_offset;
7755 leency 569
 
570
	DrawRectangle(address_box.left-2, address_box.top-3, address_box.width+5, 25,border_color);
571
 
572
	DrawBar(address_box.left-2, address_box.top-2, address_box.width+3, 1,0xD8DCD8);
573
	DrawBar(address_box.left-2, address_box.top-1, address_box.width+3, 1, address_box.color);
574
	img_draw stdcall(skin.image, address_box.left-2, address_box.top-3, 2, skin.h, 102, SKIN_Y);
7750 leency 575
	if (address_box.flags & ed_focus) address_box.flags = ed_focus; else address_box.flags = 0;
7742 leency 576
	EditBox_UpdateText(#address_box, address_box.flags);
577
	edit_box_draw stdcall(#address_box);
7755 leency 578
	if (http.transfer > 0) skin_x_offset = 85; else skin_x_offset = 68;
579
	img_draw stdcall(skin.image, address_box.left+address_box.width+1,
580
		address_box.top-3, 17, skin.h, skin_x_offset, SKIN_Y);
7742 leency 581
}
582
 
7755 leency 583
void LoadInternalPage(dword _bufdata, _in_bufsize){
584
	if (!_bufdata) || (!_in_bufsize) {
7752 leency 585
		LoadInternalPage(#page_not_found, sizeof(page_not_found));
7755 leency 586
	} else {
587
		bufsize = _in_bufsize;
588
		if (bufpointer!=_bufdata) free(bufpointer);
589
		bufpointer = malloc(bufsize);
590
		memmov(bufpointer, _bufdata, bufsize);
591
		WB1.list.first = 0; //scroll page to the top
592
		DrawOmnibox();
593
		if(!strrchr(#editURL, '#')) {
594
			strcat(#editURL, #anchors.current);
595
			DrawOmnibox();
596
		}
7756 leency 597
		if (source_mode) {
598
			source_mode = false;
599
			WB1.ParseHtml();
600
			ShowSource(bufpointer, bufsize);
601
			return;
602
		}
7755 leency 603
		WB1.ParseHtml();
604
		WB1.DrawPage();
7742 leency 605
	}
606
}
607
 
7755 leency 608
byte UrlExtIs(dword base, ext)
7742 leency 609
{
7755 leency 610
	if (!strcmpi(base + strlen(base) - strlen(ext), ext)) return true;
7742 leency 611
	return false;
612
}
613
 
614
void DrawProgress()
615
{
616
	dword persent;
617
	if (http.transfer == 0) return;
7755 leency 618
	if (wv_progress_bar.max) {
619
		persent = wv_progress_bar.value*100/wv_progress_bar.max;
620
	} else {
621
		persent = 10;
622
	}
623
	DrawBar(address_box.left-1, address_box.top+20, persent*address_box.width/100, 2, 0x72B7EB);
7742 leency 624
}
625
 
6795 leency 626
void EventShowPageMenu(dword _left, _top)
6782 leency 627
{
628
	menu.show(Form.left+_left-6,Form.top+_top+skin_height+3, 220, #rmb_menu, VIEW_SOURCE);
629
}
630
 
6795 leency 631
void EventShowLinkMenu(dword _left, _top)
632
{
7282 leency 633
	menu.show(Form.left+_left-6,Form.top+_top+skin_height+3, 220, #link_menu, COPY_LINK_URL);
6795 leency 634
}
635
 
7281 leency 636
void EventUpdateProgressBar()
637
{
638
	wv_progress_bar.max = http.content_length;
639
	if (wv_progress_bar.value != http.content_received)
640
	{
641
		wv_progress_bar.value = http.content_received;
642
		DrawProgress();
643
	}
644
}
6795 leency 645
 
7743 leency 646
void EventSeachWeb()
647
{
7755 leency 648
	char new_url[URL_SIZE+1];
649
	replace_char(#editURL, ' ', '_', URL_SIZE);
650
	strcpy(#new_url, "https://www.google.com/search?q=");
651
	strncat(#new_url, #editURL, URL_SIZE);
652
	OpenPage(#new_url);
7743 leency 653
}
654
 
7748 leency 655
void EventOpenDialog()
656
{
657
	OpenDialog_start stdcall (#o_dialog);
658
	if (o_dialog.status) {
7755 leency 659
		OpenPage(#openfile_path);
7748 leency 660
	}
661
}
662
 
7750 leency 663
void EventViewSource()
664
{
7755 leency 665
	char source_view_param[URL_SIZE+1];
7750 leency 666
	strcpy(#source_view_param, "-s ");
7755 leency 667
	strncat(#source_view_param, history.current(), URL_SIZE);
7750 leency 668
	RunProgram(#program_path, #source_view_param);
669
}
670
 
7742 leency 671
void DrawStatusBar(dword _status_text)
6795 leency 672
{
7748 leency 673
	status_text.start_x = 10;
6795 leency 674
	status_text.start_y = Form.cheight - STATUSBAR_H + 3;
675
	status_text.area_size_x = Form.cwidth - status_text.start_x -3;
676
	DrawBar(status_text.start_x, status_text.start_y, status_text.area_size_x, 9, col_bg);
677
	status_text.text_pointer = _status_text;
678
	PathShow_prepare stdcall(#status_text);
679
	PathShow_draw stdcall(#status_text);
680
}
681
 
5631 pavelyakov 682
stop: