Subversion Repositories Kolibri OS

Rev

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