Subversion Repositories Kolibri OS

Rev

Rev 7799 | Rev 7801 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
7739 leency 1
//Copyright 2007-2020 by Veliant & Leency
6978 leency 2
//Asper, lev, Lrz, Barsuk, Nable, hidnplayr...
3067 leency 3
 
4085 leency 4
#ifndef AUTOBUILD
5
	#include "lang.h--"
6
#endif
7
 
3107 leency 8
//libraries
7771 leency 9
#define MEMSIZE 1024 * 1000
5499 leency 10
#include "..\lib\gui.h"
4508 leency 11
#include "..\lib\draw_buf.h"
12
#include "..\lib\list_box.h"
13
#include "..\lib\cursor.h"
5978 leency 14
#include "..\lib\collection.h"
6795 leency 15
#include "..\lib\random.h"
7037 leency 16
#include "..\lib\clipboard.h"
5981 leency 17
 
7437 leency 18
// *.obj libraries
5499 leency 19
#include "..\lib\obj\box_lib.h"
7049 leency 20
#include "..\lib\obj\libio.h"
21
#include "..\lib\obj\libimg.h"
5499 leency 22
#include "..\lib\obj\http.h"
5690 leency 23
#include "..\lib\obj\iconv.h"
7748 leency 24
#include "..\lib\obj\proc_lib.h"
7757 leency 25
 
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"
7759 leency 30
#include "..\lib\patterns\toolbar_button.h"
5408 leency 31
 
7771 leency 32
#include "texts.h"
33
#include "cache.h"
7757 leency 34
#include "show_src.h"
35
#include "download_manager.h"
7771 leency 36
 
7757 leency 37
bool debug_mode = false;
7771 leency 38
 
7791 leency 39
enum {
40
	NEW_TAB=600,
41
	ENCODINGS=700,
42
	BACK_BUTTON=800,
43
	FORWARD_BUTTON,
44
	REFRESH_BUTTON,
45
	GOTOURL_BUTTON,
46
	CHANGE_ENCODING,
47
	SANDWICH_BUTTON,
48
	VIEW_SOURCE,
49
	EDIT_SOURCE,
50
	OPEN_FILE,
51
	NEW_WINDOW,
52
	VIEW_HISTORY,
53
	DOWNLOAD_MANAGER,
54
	CLEAR_CACHE,
55
	UPDATE_BROWSER,
56
	IN_NEW_TAB,
57
	IN_NEW_WINDOW,
58
	COPY_LINK_URL,
59
	DOWNLOAD_LINK_CONTENTS,
60
	TAB_ID,
61
	TAB_CLOSE_ID = 900
62
};
63
 
7759 leency 64
#include "..\TWB\TWB.c" //HTML Parser, a core component
7757 leency 65
 
7759 leency 66
TWebBrowser WB1;
7771 leency 67
_history history;
7758 leency 68
 
7771 leency 69
#include "history.h"
7752 leency 70
 
7758 leency 71
#define PADDING 9
72
#define TSZE 25
7771 leency 73
#define STATUSBAR_H 15
74
#define TAB_H 20
7758 leency 75
dword TOOLBAR_H = PADDING+TSZE+PADDING+2;
4677 leency 76
 
7771 leency 77
#define URL_SIZE 4000
78
 
7750 leency 79
int action_buf;
7425 leency 80
 
7759 leency 81
_http http = 0;
7758 leency 82
 
7750 leency 83
bool source_mode = false;
7282 leency 84
 
5718 leency 85
progress_bar wv_progress_bar;
7750 leency 86
char stak[4096];
87
proc_info Form;
7748 leency 88
 
7780 leency 89
int menu_id=NULL;
90
 
7771 leency 91
#include "tabs.h"
92
 
7748 leency 93
char default_dir[] = "/rd/1";
7788 leency 94
od_filter filter2 = { 22, "TXT\0HTM\0HTML\0DOCX\0\0" };
7748 leency 95
 
7755 leency 96
char editURL[URL_SIZE+1];
7758 leency 97
edit_box address_box = {, PADDING+TSZE*2+PADDING+6, PADDING+3, 0xffffff,
98
	0x94AECE, 0xffffff, 0xffffff,0x10000000,URL_SIZE-2,#editURL,0,,19,19};
4534 leency 99
 
7784 leency 100
char editbox_icons[] = FROM "editbox_icons.raw";
4534 leency 101
 
7784 leency 102
 
7748 leency 103
void LoadLibraries()
104
{
105
	load_dll(boxlib,    #box_lib_init,0);
106
	load_dll(libio,     #libio_init,1);
107
	load_dll(libimg,    #libimg_init,1);
108
	load_dll(libHTTP,   #http_lib_init,1);
109
	load_dll(iconv_lib, #iconv_open,0);
110
	load_dll(Proc_lib,  #OpenDialog_init,0);
111
	OpenDialog_init stdcall (#o_dialog);
112
}
113
 
114
void HandleParam()
115
{
116
	if (param) {
7765 leency 117
		if (!strncmp(#param, "-download_and_exit ", 19)) {
118
			download_and_exit = true;
119
			strcpy(#downloader_edit, #param+19);
120
			Downloader();
7748 leency 121
			ExitProcess();
7765 leency 122
		} else if (!strncmp(#param, "-download ", 10)) {
123
			strcpy(#downloader_edit, #param+10);
124
			//CreateThread(#Downloader,#downloader_stak+4092);
125
			Downloader();
126
			ExitProcess();
127
		} else if (!strncmp(#param, "-source ", 8)) {
7750 leency 128
			source_mode = true;
7765 leency 129
			history.add(#param + 8);
7748 leency 130
		} else {
7755 leency 131
			history.add(#param);
7748 leency 132
		}
133
	} else {
7755 leency 134
		history.add(URL_SERVICE_HOMEPAGE);
7748 leency 135
	}
136
}
137
 
3067 leency 138
void main()
139
{
7758 leency 140
	int i, btn, redirect_count=0;
7748 leency 141
	LoadLibraries();
7762 leency 142
	CreateDir("/tmp0/1/Downloads");
7764 leency 143
	//CreateDir("/tmp0/1/WebView_Cache");
7748 leency 144
	HandleParam();
6045 leency 145
	WB1.list.SetFont(8, 14, 10011000b);
5779 leency 146
	WB1.list.no_selection = true;
7759 leency 147
	WB1.custom_encoding = -1;
6978 leency 148
	SetEventMask(EVM_REDRAW + EVM_KEY + EVM_BUTTON + EVM_MOUSE + EVM_MOUSE_FILTER + EVM_STACK);
149
	loop() switch(WaitEvent())
150
	{
151
		case evMouse:
152
			edit_box_mouse stdcall (#address_box);
153
			mouse.get();
7757 leency 154
			if (PageLinks.HoverAndProceed(mouse.x, WB1.list.first + mouse.y, WB1.list.y, WB1.list.first))
7755 leency 155
			&& (mouse.pkm) && (mouse.up) {
7770 leency 156
				if (WB1.list.MouseOver(mouse.x, mouse.y)) EventShowPageMenu();
7282 leency 157
				break;
6978 leency 158
			}
7282 leency 159
			if (WB1.list.MouseScroll(mouse.vert)) WB1.DrawPage();
6978 leency 160
			scrollbar_v_mouse (#scroll_wv);
161
			if (WB1.list.first != scroll_wv.position)
162
			{
163
				WB1.list.first = scroll_wv.position;
164
				WB1.DrawPage();
3067 leency 165
				break;
6978 leency 166
			}
7758 leency 167
			if (mouse.up) && (! address_box.flags & ed_focus) && (address_box.flags & ed_shift_bac)
168
			{
169
				DrawOmnibox(); //reset text selection
170
			}
6978 leency 171
			break;
5711 leency 172
 
6978 leency 173
		case evButton:
7758 leency 174
			btn = GetButtonID();
175
			if (1==btn) ExitProcess(); else ProcessEvent(btn);
6978 leency 176
			break;
5711 leency 177
 
6978 leency 178
		case evKey:
179
			GetKeys();
7771 leency 180
			//if (key_scancode == SCAN_CODE_F1) {DebugTabs();break;}
181
 
182
			if (key_modifier&KEY_LSHIFT) || (key_modifier&KEY_RSHIFT) {
183
				if (key_scancode == SCAN_CODE_TAB) {EventActivatePreviousTab();break;}
184
			}
185
 
7772 leency 186
			if (ProcessCtrlKeyEvent()) break;
7743 leency 187
 
188
			if (key_scancode == SCAN_CODE_F5) ProcessEvent(REFRESH_BUTTON);
189
 
7506 leency 190
			if (address_box.flags & ed_focus)
6978 leency 191
			{
7742 leency 192
				if (key_scancode == SCAN_CODE_ENTER) {
193
					ProcessEvent(key_scancode);
7771 leency 194
				} else {
6978 leency 195
					EAX = key_editbox;
196
					edit_box_key stdcall(#address_box);
5530 leency 197
				}
7771 leency 198
			} else {
7422 leency 199
				#define KEY_SCROLL_N 11
200
				if (SCAN_CODE_UP   == key_scancode) for (i=0;i
201
				if (SCAN_CODE_DOWN == key_scancode) for (i=0;i
7743 leency 202
				if (key_scancode == SCAN_CODE_F6) {address_box.flags=ed_focus; DrawOmnibox();}
6978 leency 203
				if (WB1.list.ProcessKey(key_scancode)) WB1.DrawPage();
204
				else ProcessEvent(key_scancode);
205
			}
206
			break;
207
 
208
		case evReDraw:
7780 leency 209
			DefineAndDrawWindow(GetScreenWidth()-800/2-random(80), //40
7755 leency 210
				GetScreenHeight()-700/2-random(80),800,700,0x73,0,0,0);
6978 leency 211
			GetProcessInfo(#Form, SelfInfo);
7780 leency 212
			ProcessMenuClick();
7748 leency 213
			system.color.get();
7759 leency 214
			if (Form.status_window>2) break;
6978 leency 215
			if (Form.height<120) { MoveSize(OLD,OLD,OLD,120); break; }
216
			if (Form.width<280) { MoveSize(OLD,OLD,280,OLD); break; }
7748 leency 217
			draw_window();
6978 leency 218
			break;
219
 
220
		case evNetwork:
7758 leency 221
			if (http.transfer <= 0) break;
222
			http.receive();
223
			EventUpdateProgressBar();
224
			if (http.receive_result != 0) break;
225
			if (http.status_code >= 300) && (http.status_code < 400)
226
			{
227
				// Handle redirects
228
				if (redirect_count<=5) {
229
					redirect_count++;
230
					http.handle_redirect();
7282 leency 231
					http.free();
7758 leency 232
					GetAbsoluteURL(#http.redirect_url, history.current());
233
					history.back();
234
					OpenPage(#http.redirect_url);
235
				} else {
236
					notify("'Too many redirects.' -E");
237
					StopLoading();
7791 leency 238
					redirect_count = 0;
4536 leency 239
				}
7758 leency 240
			} else {
241
				// Loading the page is complete, free resources
242
				redirect_count = 0;
243
				http.free();
7764 leency 244
				pages_cache.add(history.current(), http.content_pointer, http.content_received);
7758 leency 245
				LoadInternalPage(http.content_pointer, http.content_received);
6978 leency 246
			}
247
	}
3067 leency 248
}
249
 
7772 leency 250
bool ProcessCtrlKeyEvent()
251
{
252
	if (key_modifier&KEY_LCTRL) || (key_modifier&KEY_RCTRL) switch(key_scancode)
253
	{
254
		case SCAN_CODE_KEY_O:
255
			EventOpenDialog();
256
			return true;
257
		case SCAN_CODE_KEY_H:
258
			ProcessEvent(VIEW_HISTORY);
259
			return true;
260
		case SCAN_CODE_KEY_U:
261
			EventViewSource();
262
			return true;
263
		case SCAN_CODE_KEY_T:
264
			EventOpenNewTab(URL_SERVICE_HOMEPAGE);
265
			return true;
266
		case SCAN_CODE_KEY_N:
267
			RunProgram(#program_path, NULL);
268
			return true;
269
		case SCAN_CODE_KEY_J:
270
			ProcessEvent(DOWNLOAD_MANAGER);
271
			return true;
272
		case SCAN_CODE_KEY_R:
273
			ProcessEvent(REFRESH_BUTTON);
274
			return true;
275
		case SCAN_CODE_ENTER:
276
			EventSeachWeb();
277
			return true;
278
		case SCAN_CODE_LEFT:
279
			 ProcessEvent(BACK_BUTTON);
280
			 return true;
281
		case SCAN_CODE_RIGHT:
282
			ProcessEvent(FORWARD_BUTTON);
283
			return true;
284
		case SCAN_CODE_KEY_W:
285
			EventCloseActiveTab();
286
			return true;
287
		case SCAN_CODE_TAB:
288
			EventActivateNextTab();
289
			return true;
290
	}
291
	return false;
292
}
293
 
3067 leency 294
void SetElementSizes()
295
{
7758 leency 296
	address_box.width = Form.cwidth - address_box.left - 52 - 16;
7771 leency 297
	WB1.list.SetSizes(0, TOOLBAR_H+TAB_H, Form.width - 10 - scroll_wv.size_x,
298
		Form.cheight - TOOLBAR_H - STATUSBAR_H - TAB_H, BASIC_LINE_H);
7759 leency 299
	WB1.list.wheel_size = 7 * BASIC_LINE_H;
7746 leency 300
	WB1.list.column_max = WB1.list.w - scroll_wv.size_x / WB1.list.font_w + 1;
6794 leency 301
	WB1.list.visible = WB1.list.h;
3067 leency 302
}
303
 
5981 leency 304
 
7748 leency 305
void draw_window()
3067 leency 306
{
7758 leency 307
	int i;
3067 leency 308
	SetElementSizes();
7758 leency 309
 
310
	DrawBar(0,0, Form.cwidth,PADDING, system.color.work);
311
	DrawBar(0,PADDING+TSZE+1, Form.cwidth,PADDING-1, system.color.work);
7771 leency 312
	DrawBar(0,TOOLBAR_H-2, Form.cwidth,1, MixColors(system.color.work_dark, system.color.work, 180));
7758 leency 313
	DrawBar(0,TOOLBAR_H-1, Form.cwidth,1, system.color.work_graph);
314
	DrawBar(0, PADDING, address_box.left-2, TSZE+1, system.color.work);
315
	DrawBar(address_box.left+address_box.width+18, PADDING, Form.cwidth-address_box.left-address_box.width-18, TSZE+1, system.color.work);
316
 
7759 leency 317
	DrawTopPanelButton(BACK_BUTTON, PADDING-1, PADDING, 30);
318
	DrawTopPanelButton(FORWARD_BUTTON, PADDING+TSZE+PADDING-2, PADDING, 31);
319
	DrawTopPanelButton(SANDWICH_BUTTON, Form.cwidth-PADDING-TSZE-3, PADDING, -1);
7758 leency 320
	for (i=0; i<=2; i++) DrawBar(Form.cwidth-PADDING-TSZE+3, i*5+PADDING+7, 15, 3, system.color.work_graph);
321
 
322
	DrawBar(0,Form.cheight - STATUSBAR_H, Form.cwidth,1, system.color.work_graph);
323
 
324
	DrawRectangle(WB1.list.x + WB1.list.w, WB1.list.y, scroll_wv.size_x,
325
		WB1.list.h-1, scroll_wv.bckg_col);
326
 
7771 leency 327
	if (!BrowserWidthChanged()) {
328
		WB1.DrawPage();
329
		DrawOmnibox();
330
	}
331
	DrawProgress();
332
	DrawStatusBar(NULL);
333
	DrawTabsBar();
334
}
335
 
336
bool BrowserWidthChanged()
337
{
338
	dword source_mode_holder;
339
	if (WB1.list.w!=DrawBuf.bufw) {
340
		DrawBuf.Init(WB1.list.x, WB1.list.y, WB1.list.w, 400*20);
7758 leency 341
		if (!strncmp(history.current(),"http",4)) {
7759 leency 342
			//nihuya ne izyashnoe reshenie, no pust' poka butet tak
7771 leency 343
			source_mode_holder = source_mode;
7758 leency 344
			LoadInternalPage(#loading_text, sizeof(loading_text));
7771 leency 345
			source_mode = source_mode_holder;
7758 leency 346
		}
347
		OpenPage(history.current());
7771 leency 348
		return true;
7282 leency 349
	}
7771 leency 350
	return false;
3067 leency 351
}
352
 
7771 leency 353
 
7759 leency 354
void EventChangeEncodingAndLoadPage(int _new_encoding)
355
{
356
	dword newbuf, newsize;
357
	WB1.custom_encoding = _new_encoding;
358
	newsize = strlen(WB1.o_bufpointer);
359
	newbuf = malloc(newsize);
360
	memmov(newbuf, WB1.o_bufpointer, newsize);
361
	LoadInternalPage(newbuf, newsize);
362
	free(newbuf);
363
}
3067 leency 364
 
7759 leency 365
 
6698 leency 366
void ProcessEvent(dword id__)
4413 leency 367
{
6698 leency 368
	switch (id__)
4413 leency 369
	{
7759 leency 370
		case ENCODINGS...ENCODINGS+6:
371
			EventChangeEncodingAndLoadPage(id__-ENCODINGS);
372
			return;
7758 leency 373
		case NEW_WINDOW:
374
			RunProgram(#program_path, NULL);
6698 leency 375
			return;
5711 leency 376
		case SCAN_CODE_BS:
5718 leency 377
		case BACK_BUTTON:
6021 leency 378
			if (history.back()) {
7755 leency 379
				OpenPage(history.current());
5978 leency 380
			}
5711 leency 381
			return;
5718 leency 382
		case FORWARD_BUTTON:
6021 leency 383
			if (history.forward()) {
7755 leency 384
				OpenPage(history.current());
5978 leency 385
			}
5711 leency 386
			return;
5718 leency 387
		case GOTOURL_BUTTON:
5772 leency 388
		case SCAN_CODE_ENTER:
7742 leency 389
			EventSubmitOmnibox();
5711 leency 390
			return;
5718 leency 391
		case REFRESH_BUTTON:
7771 leency 392
			if (http.transfer) {
5713 leency 393
				StopLoading();
7748 leency 394
				draw_window();
7755 leency 395
			} else {
396
				OpenPage(history.current());
5713 leency 397
			}
398
			return;
7759 leency 399
		case CHANGE_ENCODING:
7770 leency 400
			EventShowEncodingsList();
7759 leency 401
			return;
5718 leency 402
		case SANDWICH_BUTTON:
7770 leency 403
			EventShowMainMenu();
4415 leency 404
			return;
5718 leency 405
		case VIEW_SOURCE:
7750 leency 406
			EventViewSource();
5718 leency 407
			break;
408
		case EDIT_SOURCE:
7755 leency 409
			if (check_is_the_adress_local(history.current())) {
410
				RunProgram("/rd/1/tinypad", history.current());
7750 leency 411
			} else {
7759 leency 412
				CreateFile(WB1.bufsize, WB1.bufpointer, "/tmp0/1/WebView_tmp.htm");
5718 leency 413
				if (!EAX) RunProgram("/rd/1/tinypad", "/tmp0/1/WebView_tmp.htm");
414
			}
4415 leency 415
			return;
5718 leency 416
		case VIEW_HISTORY:
7755 leency 417
			OpenPage(URL_SERVICE_HISTORY);
4544 leency 418
			return;
5718 leency 419
		case DOWNLOAD_MANAGER:
5519 leency 420
			if (!downloader_opened) {
6001 leency 421
				downloader_edit = NULL;
5519 leency 422
				CreateThread(#Downloader,#downloader_stak+4092);
423
			}
4413 leency 424
			return;
7765 leency 425
		case UPDATE_BROWSER:
426
			EventUpdateBrowser();
427
			return;
7770 leency 428
		case CLEAR_CACHE:
429
			pages_cache.clear();
430
			notify(#clear_cache_ok);
431
			return;
7789 simsanutiy 432
		case IN_NEW_TAB:
433
			open_new_tab = true;
7791 leency 434
			EventClickLink(PageLinks.GetURL(PageLinks.active));
7789 simsanutiy 435
			open_new_tab = false;
436
			return;
437
		case IN_NEW_WINDOW:
7796 leency 438
			open_new_window = true;
7791 leency 439
			EventClickLink(PageLinks.GetURL(PageLinks.active));
7796 leency 440
			open_new_window = false;
7789 simsanutiy 441
			return;
7282 leency 442
		case COPY_LINK_URL:
7037 leency 443
			Clipboard__CopyText(PageLinks.GetURL(PageLinks.active));
444
			notify("'URL copied to clipboard'O");
445
			return;
7208 leency 446
		case DOWNLOAD_LINK_CONTENTS:
447
			if (!downloader_opened) {
448
				strcpy(#downloader_edit, PageLinks.GetURL(PageLinks.active));
449
				CreateThread(#Downloader,#downloader_stak+4092);
450
			}
451
			return;
7758 leency 452
		case OPEN_FILE:
453
			EventOpenDialog();
454
			return;
7282 leency 455
		case SCAN_CODE_F12:
456
			debug_mode ^= 1;
457
			if (debug_mode) notify("'Debug mode ON'-I");
458
			else notify("'Debug mode OFF'-I");
459
			return;
7771 leency 460
		case NEW_TAB:
461
			if (http.transfer) break;
462
			EventOpenNewTab(URL_SERVICE_HOMEPAGE);
463
			return;
464
		case TAB_ID...TAB_ID+TABS_MAX:
465
			if (http.transfer) break;
466
			if (mouse.mkm) {
467
				EventTabClose(id__ - TAB_ID);
468
			} else {
469
				EventTabClick(id__ - TAB_ID);
470
			}
471
			return;
472
		case TAB_CLOSE_ID...TAB_CLOSE_ID+TABS_MAX:
473
			EventTabClose(id__ - TAB_CLOSE_ID);
474
			return;
4413 leency 475
	}
476
}
477
 
4636 leency 478
void StopLoading()
479
{
7281 leency 480
	if (http.transfer)
4647 leency 481
	{
7281 leency 482
		EAX = http.transfer;
4647 leency 483
		EAX = EAX.http_msg.content_ptr;		// get pointer to data
484
		$push	EAX							// save it on the stack
7281 leency 485
		http_free stdcall (http.transfer);	// abort connection
4647 leency 486
		$pop	EAX
5631 pavelyakov 487
		free(EAX);						// free data
7281 leency 488
		http.transfer=0;
7746 leency 489
		pause(10);
4647 leency 490
	}
5519 leency 491
	wv_progress_bar.value = 0;
7743 leency 492
	DrawOmnibox();
4645 leency 493
}
494
 
7756 leency 495
//rewrite into
7757 leency 496
//bool strrpl(dword dst, from, into, dst_len);
497
bool ReplaceSpaceInUrl(dword url, size) {
7756 leency 498
	unsigned int i, j;
7757 leency 499
	bool was_changed=false;
500
	for (i=url+size-3; i>url; i--)
7720 leency 501
	{
7756 leency 502
		if (ESBYTE[i]!=' ') continue;
7757 leency 503
		for (j=url+size-3; j>=i; j--) {
504
			ESBYTE[j+3]=ESBYTE[j+2];
7756 leency 505
			ESBYTE[j+2]=ESBYTE[j+1];
506
			ESBYTE[j+1]=ESBYTE[j];
507
		}
508
		ESBYTE[i] = '%';
509
		ESBYTE[i+1] = '2';
510
		ESBYTE[i+2] = '0';
7757 leency 511
		was_changed = true;
7720 leency 512
	}
7757 leency 513
	return was_changed;
7720 leency 514
}
515
 
7755 leency 516
bool GetLocalFileData(dword _path)
4416 leency 517
{
7800 leency 518
	dword data, size, url_from_file;
7755 leency 519
	file_size stdcall (_path);
520
	if (!EBX) {
521
		return false;
522
	} else {
523
		size = EBX;
524
		data = malloc(size);
525
		ReadFile(0, size, data, _path);
7800 leency 526
		url_from_file = strstri(data, "URL=");
527
		if (UrlExtIs(_path, "url")) && (url_from_file != -1) {
528
			strtrim(url_from_file);
529
			OpenPage(url_from_file);
530
		} else {
531
			LoadInternalPage(data, size);
532
		}
7755 leency 533
		free(data);
534
		return true;
4692 leency 535
	}
7755 leency 536
}
7282 leency 537
 
7755 leency 538
void OpenPage(dword _open_URL)
539
{
540
	char new_url[URL_SIZE+1];
7788 leency 541
	int unz_id;
7755 leency 542
 
543
	StopLoading();
544
 
7771 leency 545
	if (open_new_tab) {
546
		open_new_tab = false;
547
		EventOpenNewTab(_open_URL);
548
		return;
549
	}
7755 leency 550
 
7771 leency 551
	SetOmniboxText(_open_URL);
552
 
7755 leency 553
	strncpy(#new_url, _open_URL, URL_SIZE);
554
 
555
	//Exclude # from the URL to the load page
556
	//We will bring it back when we get the buffer
557
	if (strrchr(#new_url, '#')) anchors.take_anchor_from(#new_url);
558
 
559
	history.add(#new_url);
560
 
7764 leency 561
	if (pages_cache.has(#new_url)) {
562
		//CACHED PAGE
563
		LoadInternalPage(pages_cache.current_page_buf, pages_cache.current_page_size);
564
 
565
	} else if (!strncmp(#new_url,"WebView:",8)) {
7755 leency 566
		//INTERNAL PAGE
567
		if (!strcmp(#new_url, URL_SERVICE_HOMEPAGE)) LoadInternalPage(#homepage, sizeof(homepage));
568
		else if (!strcmp(#new_url, URL_SERVICE_HELP)) LoadInternalPage(#help, sizeof(help));
569
		else if (!strcmp(#new_url, URL_SERVICE_HISTORY)) ShowHistory();
570
		else LoadInternalPage(#page_not_found, sizeof(page_not_found));
7800 leency 571
 
7755 leency 572
	} else if (!strncmp(#new_url,"http:",5)) || (!strncmp(#new_url,"https:",6)) {
573
		//WEB PAGE
7757 leency 574
		if (ReplaceSpaceInUrl(#new_url, URL_SIZE)) {
575
			strcpy(#editURL, #new_url);
576
		}
577
 
7755 leency 578
		if (!strncmp(#new_url,"http:",5)) {
579
			http.get(#new_url);
580
		} else if (!strncmp(#new_url,"https://",8)) {
581
			strcpy(#new_url, "http://gate.aspero.pro/?site=");
582
			strncat(#new_url, _open_URL, URL_SIZE);
583
			http.get(#new_url);
7282 leency 584
		}
7758 leency 585
 
586
		DrawOmnibox();
587
 
7755 leency 588
		if (!http.transfer) {
4646 leency 589
			StopLoading();
7755 leency 590
			LoadInternalPage(#page_not_found, sizeof(page_not_found));
4646 leency 591
		}
7755 leency 592
	} else {
593
		//LOCAL PAGE
7788 leency 594
		if (UrlExtIs(#new_url,".docx")) {
595
			DeleteFile("/tmp0/1/temp/word/document.xml");
596
			CreateDir("/tmp0/1/temp");
597
			unz_id = RunProgram("/sys/unz", sprintf(#param, "-o \"/tmp0/1/temp\" -h \"%s\"", #new_url));
598
			while (GetProcessSlot(unz_id)) pause(2);
599
			strcpy(#new_url, "/tmp0/1/temp/word/document.xml");
600
		}
7755 leency 601
		if (!GetLocalFileData(#new_url)) {
602
			LoadInternalPage(#page_not_found, sizeof(page_not_found));
4650 leency 603
		}
4636 leency 604
	}
4416 leency 605
}
4415 leency 606
 
7755 leency 607
void EventClickLink(dword _click_URL)
4508 leency 608
{
7756 leency 609
	char new_url[URL_SIZE+1];
4415 leency 610
 
7758 leency 611
	if (open_new_window) {
612
		strcpy(#new_url, _click_URL);
613
		GetAbsoluteURL(#new_url, history.current());
614
		RunProgram(#program_path, #new_url);
615
		return;
616
	}
617
 
7755 leency 618
	if (ESBYTE[_click_URL]=='#') {
619
		if (anchors.get_pos_by_name(_click_URL+1)!=-1) {
620
			WB1.list.first = anchors.get_pos_by_name(_click_URL+1);
621
			WB1.list.CheckDoesValuesOkey();
622
		}
623
		strcpy(#editURL, history.current());
624
		strcat(#editURL, _click_URL);
625
		DrawOmnibox();
626
		WB1.DrawPage();
627
		return;
5768 leency 628
	}
7742 leency 629
 
7755 leency 630
	if (!strncmp(_click_URL,"mailto:", 7)) || (!strncmp(_click_URL,"tel:", 4)) {
631
		notify(_click_URL);
632
		return;
7742 leency 633
	}
4508 leency 634
 
7771 leency 635
	if (http.transfer) {
5774 leency 636
		StopLoading();
6021 leency 637
		history.back();
5774 leency 638
	}
6730 leency 639
 
7755 leency 640
	strcpy(#new_url, _click_URL);
7757 leency 641
	GetAbsoluteURL(#new_url, history.current());
7755 leency 642
 
643
	if (strrchr(#new_url, '#')!=0) {
644
		anchors.take_anchor_from(#new_url);
645
		OpenPage(#new_url);
6730 leency 646
		return;
647
	}
648
 
7755 leency 649
	if (!strncmp(#new_url,"WebView:",8)) {
650
		OpenPage(#new_url);
7742 leency 651
		return;
652
	}
6730 leency 653
 
7755 leency 654
	if (strncmp(#new_url,"http://",7)!=0) && (strncmp(#new_url,"https://",8)!=0)
5774 leency 655
	{
7755 leency 656
		if (UrlExtIs(#new_url,".htm")!=true) && (UrlExtIs(#new_url,".html")!=true)
6730 leency 657
		{
7755 leency 658
			if (strchr(#new_url, '|')) {
659
				ESBYTE[strchr(#new_url, '|')] = NULL;
660
				RunProgram(#new_url, strlen(#new_url)+1+#new_url);
661
			} else {
662
				RunProgram("/sys/@open", #new_url);
7422 leency 663
			}
6730 leency 664
			return;
665
		}
7755 leency 666
	} else {
667
		if (UrlExtIs(#new_url,".png")==true) || (UrlExtIs(#new_url,".jpg")==true)
668
		|| (UrlExtIs(#new_url,".zip")==true) || (UrlExtIs(#new_url,".kex")==true) || (UrlExtIs(#new_url,".pdf")==true)
669
		|| (UrlExtIs(#new_url,".7z")==true) {
6986 leency 670
			if (!downloader_opened) {
7755 leency 671
				strcpy(#downloader_edit, #new_url);
6986 leency 672
				CreateThread(#Downloader,#downloader_stak+4092);
673
			}
674
			else notify("'WebView\nPlease, start a new download only when previous ended.'Et");
6730 leency 675
			return;
5774 leency 676
		}
677
	}
7755 leency 678
	OpenPage(#new_url);
679
}
680
 
681
void EventSubmitOmnibox()
682
{
683
	char new_url[URL_SIZE+1];
684
	if (!editURL[0]) return;
685
	if (!strncmp(#editURL,"http:",5)) || (editURL[0]=='/')
686
	|| (!strncmp(#editURL,"https:",6)) || (!strncmp(#editURL,"WebView:",8)) {
687
		OpenPage(#editURL);
688
	} else {
689
		strcpy(#new_url, "http://");
690
		strncat(#new_url, #editURL, sizeof(new_url)-1);
691
		OpenPage(#new_url);
6931 leency 692
	}
5774 leency 693
}
694
 
7755 leency 695
void LoadInternalPage(dword _bufdata, _in_bufsize){
696
	if (!_bufdata) || (!_in_bufsize) {
7752 leency 697
		LoadInternalPage(#page_not_found, sizeof(page_not_found));
7755 leency 698
	} else {
699
		WB1.list.first = 0; //scroll page to the top
700
		DrawOmnibox();
701
		if(!strrchr(#editURL, '#')) {
702
			strcat(#editURL, #anchors.current);
703
			DrawOmnibox();
704
		}
7759 leency 705
		WB1.ParseHtml(_bufdata, _in_bufsize);
706
		DrawStatusBar(NULL);
7771 leency 707
		DrawActiveTab();
7756 leency 708
		if (source_mode) {
709
			source_mode = false;
7799 leency 710
			WB1.custom_encoding = CH_CP866;
7759 leency 711
			ShowSource(WB1.bufpointer, _in_bufsize);
7757 leency 712
		} else {
713
			WB1.DrawPage();
7756 leency 714
		}
7742 leency 715
	}
716
}
717
 
7799 leency 718
bool UrlExtIs(dword base, ext)
7742 leency 719
{
7755 leency 720
	if (!strcmpi(base + strlen(base) - strlen(ext), ext)) return true;
7742 leency 721
	return false;
722
}
723
 
724
void DrawProgress()
725
{
726
	dword persent;
727
	if (http.transfer == 0) return;
7755 leency 728
	if (wv_progress_bar.max) {
729
		persent = wv_progress_bar.value*100/wv_progress_bar.max;
730
	} else {
731
		persent = 10;
732
	}
7758 leency 733
	DrawBar(address_box.left-1, address_box.top+20, persent*address_box.width+16/100, 2, 0x72B7EB);
7742 leency 734
}
735
 
7770 leency 736
void EventShowPageMenu()
6782 leency 737
{
7780 leency 738
	open_lmenu(Form.left + mouse.x+4, Form.top + skin_height + mouse.y, MENU_ALIGN_TOP_LEFT, NULL, #rmb_menu);
739
	menu_id = VIEW_SOURCE;
6782 leency 740
}
741
 
7770 leency 742
void EventShowLinkMenu()
7759 leency 743
{
7780 leency 744
	open_lmenu(Form.left + mouse.x+4, Form.top + skin_height + mouse.y, MENU_ALIGN_TOP_LEFT, NULL, #link_menu);
7789 simsanutiy 745
	menu_id = IN_NEW_TAB;
7759 leency 746
}
747
 
7780 leency 748
void EventShowMainMenu()
749
{
750
	open_lmenu(Form.left + Form.cwidth - PADDING, Form.top + skin_height + PADDING + TSZE + 3,
751
		MENU_ALIGN_TOP_RIGHT, NULL, #main_menu);
752
	menu_id = OPEN_FILE;
753
}
754
 
7770 leency 755
void EventShowEncodingsList()
7758 leency 756
{
7780 leency 757
	open_lmenu(Form.left + Form.cwidth, Form.top + skin_height + status_text.start_y + 8,
758
		MENU_ALIGN_BOT_RIGHT, WB1.cur_encoding + 1, "UTF-8\nKOI8-RU\nCP1251\nCP1252\nISO8859-5\nCP866");
759
	menu_id = ENCODINGS;
7758 leency 760
}
761
 
7780 leency 762
void ProcessMenuClick()
6795 leency 763
{
7780 leency 764
	int click_id;
765
	if (menu_id) && (click_id = get_menu_click()) {
766
		click_id += menu_id - 1;
767
		menu_id = NULL;
768
		ProcessEvent(click_id);
769
	}
6795 leency 770
}
771
 
7281 leency 772
void EventUpdateProgressBar()
773
{
774
	wv_progress_bar.max = http.content_length;
775
	if (wv_progress_bar.value != http.content_received)
776
	{
777
		wv_progress_bar.value = http.content_received;
778
		DrawProgress();
779
	}
780
}
6795 leency 781
 
7743 leency 782
void EventSeachWeb()
783
{
7755 leency 784
	char new_url[URL_SIZE+1];
785
	replace_char(#editURL, ' ', '_', URL_SIZE);
786
	strcpy(#new_url, "https://www.google.com/search?q=");
787
	strncat(#new_url, #editURL, URL_SIZE);
788
	OpenPage(#new_url);
7743 leency 789
}
790
 
7748 leency 791
void EventOpenDialog()
792
{
793
	OpenDialog_start stdcall (#o_dialog);
794
	if (o_dialog.status) {
7755 leency 795
		OpenPage(#openfile_path);
7748 leency 796
	}
797
}
798
 
7750 leency 799
void EventViewSource()
800
{
7755 leency 801
	char source_view_param[URL_SIZE+1];
7771 leency 802
	//strcpy(#source_view_param, "-source ");
803
	//strncat(#source_view_param, history.current(), URL_SIZE);
804
	//RunProgram(#program_path, #source_view_param);
805
	source_mode = true;
806
	EventOpenNewTab(history.current());
7750 leency 807
}
808
 
7765 leency 809
dword GetFileSize(dword _path)
810
{
811
	BDVK bdvk;
812
	if (GetFileInfo(_path, #bdvk)!=0) {
813
		return 0;
814
	} else {
815
		return bdvk.sizelo;
816
	}
817
}
818
 
819
void EventUpdateBrowser()
820
{
821
	dword downloader_id, slot_n;
822
	dword current_size;
823
	dword new_size;
824
	int error;
825
 
826
	draw_window();
827
 
828
	downloader_id = RunProgram(#program_path, #update_param);
829
	do {
830
		slot_n = GetProcessSlot(downloader_id);
831
		pause(10);
832
	} while (slot_n!=0);
833
 
834
	current_size = GetFileSize(#program_path);
835
	new_size = GetFileSize("/tmp0/1/Downloads/WebView.com");
836
 
837
	if (!new_size) || (new_size<5000) {
838
		notify(#update_download_error);
839
		return;
840
	}
841
 
842
	if (current_size == new_size) {
843
		notify(#update_is_current);
844
		return;
845
	}
846
 
847
	if (error = CopyFileAtOnce(new_size, "/tmp0/1/Downloads/WebView.com", #program_path)) {
848
		notify(#update_can_not_copy);
849
	} else {
850
		notify(#update_ok);
851
		RunProgram(#program_path, history.current());
852
		ExitProcess();
853
	}
854
}
855
 
7742 leency 856
void DrawStatusBar(dword _status_text)
6795 leency 857
{
7759 leency 858
	status_text.font_color = system.color.work_text;
7748 leency 859
	status_text.start_x = 10;
7759 leency 860
	status_text.start_y = Form.cheight - STATUSBAR_H + 4;
861
	status_text.area_size_x = Form.cwidth - status_text.start_x -3 - 70;
862
	//DrawBar(status_text.start_x, status_text.start_y, status_text.area_size_x, 9, system.color.work);
863
	DrawBar(0,Form.cheight - STATUSBAR_H+1, Form.cwidth,STATUSBAR_H-1, system.color.work);
864
	if (_status_text) {
865
		status_text.text_pointer = _status_text;
866
		PathShow_prepare stdcall(#status_text);
867
		PathShow_draw stdcall(#status_text);
7758 leency 868
	}
7759 leency 869
	DefineHiddenButton(status_text.start_x+status_text.area_size_x+10, status_text.start_y-3,
870
		60, 12, CHANGE_ENCODING);
871
	WriteTextCenter(status_text.start_x+status_text.area_size_x+10,
872
		status_text.start_y, 60, system.color.work_text, WB1.cur_encoding*10+#charsets);
7758 leency 873
}
874
 
875
void DrawOmnibox()
876
{
7784 leency 877
	int imgxoff;
7758 leency 878
 
7759 leency 879
	DrawOvalBorder(address_box.left-2, address_box.top-3, address_box.width+18, 24, system.color.work_graph,
880
		system.color.work_graph, system.color.work_graph, system.color.work_dark);
7758 leency 881
	DrawBar(address_box.left-1, address_box.top-2, address_box.width+18, 1, 0xD8DCD8);
882
	DrawBar(address_box.left-1, address_box.top-1, address_box.width+18, 1, address_box.color);
883
	DrawBar(address_box.left-1, address_box.top, 1, 22, address_box.color);
884
 
885
	if (address_box.flags & ed_focus) address_box.flags = ed_focus; else address_box.flags = 0;
886
	EditBox_UpdateText(#address_box, address_box.flags);
887
	edit_box_draw stdcall(#address_box);
7784 leency 888
	if (http.transfer) imgxoff = 16*23*3; else imgxoff = 0;
889
	_PutImage(address_box.left+address_box.width+1, address_box.top-1, 16, 23, imgxoff + #editbox_icons);
890
	DefineHiddenButton(address_box.left+address_box.width-1, address_box.top-2, 17, 23, REFRESH_BUTTON);
7758 leency 891
 
892
	DrawProgress();
893
}
894
 
7771 leency 895
void SetOmniboxText(dword _text)
896
{
897
	strcpy(#editURL, _text);
898
	address_box.flags=0;
899
	DrawOmnibox();
900
}
7758 leency 901
 
7771 leency 902
 
5631 pavelyakov 903
stop: