Subversion Repositories Kolibri OS

Rev

Rev 5678 | Rev 5690 | 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--
3987 leency 2
//Copyright 2007-2013 by Veliant & Leency
3107 leency 3
//Asper, lev, Lrz, Barsuk, Nable...
3067 leency 4
//home icon - rachel fu, GPL licence
5
 
4085 leency 6
#ifndef AUTOBUILD
7
	#include "lang.h--"
8
#endif
9
 
3107 leency 10
//libraries
3363 leency 11
#define MEMSIZE 0x100000
3067 leency 12
#include "..\lib\strings.h"
5499 leency 13
#include "..\lib\gui.h"
3067 leency 14
#include "..\lib\encoding.h"
15
#include "..\lib\file_system.h"
16
#include "..\lib\mem.h"
4508 leency 17
#include "..\lib\draw_buf.h"
18
#include "..\lib\list_box.h"
19
#include "..\lib\cursor.h"
20
 
3107 leency 21
//*.obj libraries
5499 leency 22
#include "..\lib\obj\box_lib.h"
23
#include "..\lib\obj\libio_lib.h"
24
#include "..\lib\obj\libimg_lib.h"
25
#include "..\lib\obj\http.h"
3067 leency 26
 
5408 leency 27
//useful patterns
28
#include "..\lib\patterns\libimg_load_skin.h"
29
 
5493 leency 30
char homepage[] = FROM "html\\homepage.htm";
4677 leency 31
 
4026 leency 32
#ifdef LANG_RUS
5685 leency 33
	char version[]=" Текстовый браузер 1.15";
4416 leency 34
	?define IMAGES_CACHE_CLEARED "Кэш картинок очищен"
4417 leency 35
	?define T_LAST_SLIDE "Это последний слайд"
4550 leency 36
	char loading[] = "Загрузка страницы...
";
4677 leency 37
	char page_not_found[] = FROM "html\page_not_found_ru.htm";
4649 leency 38
	char accept_language[]= "Accept-Language: ru\n";
4026 leency 39
#else
5685 leency 40
	char version[]=" Text-based Browser 1.15";
4026 leency 41
	?define IMAGES_CACHE_CLEARED "Images cache cleared"
4417 leency 42
	?define T_LAST_SLIDE "This slide is the last"
4550 leency 43
	char loading[] = "Loading...
";
4677 leency 44
	char page_not_found[] = FROM "html\page_not_found_en.htm";
4649 leency 45
	char accept_language[]= "Accept-Language: en\n";
4026 leency 46
#endif
47
 
5631 pavelyakov 48
 
49
 
3067 leency 50
proc_info Form;
5519 leency 51
#define WIN_W 799
52
#define WIN_H 559
3067 leency 53
 
4416 leency 54
char search_path[]="http://nigma.ru/index.php?s=";
4558 hidnplayr 55
char str_location[]="location\0";
56
int redirected = 0;
3067 leency 57
 
4074 leency 58
char stak[4096];
5640 pavelyakov 59
 
4026 leency 60
int action_buf;
61
 
4565 leency 62
dword http_transfer = 0;
4537 leency 63
dword http_buffer;
4534 leency 64
 
4692 leency 65
dword TAB_H = false; //19;
4677 leency 66
dword TAB_W = 150;
4692 leency 67
dword TOOLBAR_H = 31; //50;
5519 leency 68
dword STATUSBAR_H = 15;
4718 leency 69
dword col_bg;
70
dword panel_color;
71
dword border_color;
4677 leency 72
 
5519 leency 73
progress_bar wv_progress_bar = {0, 10, 83, 150, 12, 0, 0, 100, 0xeeeEEE, 8072B7EBh, 0x9F9F9F};
4718 leency 74
byte souce_mode = false;
4677 leency 75
 
4411 leency 76
#include "..\TWB\TWB.c"
77
#include "menu_rmb.h"
4636 leency 78
#include "history.h"
4718 leency 79
#include "show_src.h"
5685 leency 80
#include "network_get.h"
5493 leency 81
#include "downloader.h"
3067 leency 82
 
4534 leency 83
char editURL[sizeof(URL)];
84
int	mouse_twb;
4677 leency 85
edit_box address_box = {250,55,34,0xffffff,0x94AECE,0xffffff,0xffffff,0,sizeof(URL),#editURL,#mouse_twb,2,19,19};
4534 leency 86
 
4677 leency 87
#define URL_SERVICE_HISTORY "WebView://history"
88
#define URL_SERVICE_HOME "WebView://home"
4718 leency 89
#define URL_SERVICE_SOURCE "WebView://source:"
4534 leency 90
 
4488 leency 91
enum { BACK=300, FORWARD, REFRESH, HOME, NEWTAB, GOTOURL, SEARCHWEB, INPUT_CH, INPUT_BT, BTN_UP, BTN_DOWN };
3067 leency 92
 
5408 leency 93
libimg_image skin;
4488 leency 94
 
5408 leency 95
int SetSkinColors()
4677 leency 96
{
4718 leency 97
	dword image_data;
98
	image_data = DSDWORD[skin.image+24];
4846 leency 99
	col_bg = DSDWORD[image_data];
4718 leency 100
	panel_color  = DSDWORD[skin.w*4*4 + image_data];
101
	border_color = DSDWORD[skin.w*4*7 + image_data];
5519 leency 102
	wv_progress_bar.progress_color = DSDWORD[skin.w*4*10 + image_data];
4718 leency 103
	$and col_bg, 0x00ffffff
104
	$and panel_color, 0x00ffffff
105
	$and border_color, 0x00ffffff
5519 leency 106
	$and wv_progress_bar.progress_color, 0x00ffffff
4677 leency 107
}
108
 
4686 leency 109
void DrawProgress()
110
{
111
	unsigned long btn;
5519 leency 112
	//progressbar_draw stdcall(#wv_progress_bar);
113
	wv_progress_bar.width = wv_progress_bar.left = 0;
4686 leency 114
	if (http_transfer == 0) return;
5519 leency 115
	if (wv_progress_bar.max) btn = address_box.width*wv_progress_bar.value/wv_progress_bar.max; else btn = 30;
116
	DrawBar(address_box.left-1, address_box.top+14, btn, 2, wv_progress_bar.progress_color);
4686 leency 117
}
118
 
4718 leency 119
 
3067 leency 120
void main()
121
{
4686 leency 122
	unsigned long key, btn;
3067 leency 123
	int half_scroll_size;
4026 leency 124
	int scroll_used=0, show_menu;
3067 leency 125
 
4536 leency 126
	CursorPointer.Load(#CursorFile);
5626 leency 127
	load_dll(boxlib, #box_lib_init,0);
128
	load_dll(libio, #libio_init,1);
129
	load_dll(libimg, #libimg_init,1);
130
	load_dll(libHTTP, #http_lib_init,1);
5408 leency 131
	Libimg_LoadImage(#skin, abspath("wv_skin.png"));
132
	SetSkinColors();
3067 leency 133
 
5678 leency 134
	WB1.DrawBuf.zoom = 1;
3067 leency 135
	Form.width=WIN_W;
136
	Form.height=WIN_H;
137
	SetElementSizes();
5493 leency 138
	if (param) strcpy(#URL, #param); else strcpy(#URL, URL_SERVICE_HOME);
4416 leency 139
	OpenPage();
3067 leency 140
 
5493 leency 141
	CreateDir("/tmp0/1/downloads");
142
 
4536 leency 143
	SetEventMask(0xa7);
5631 pavelyakov 144
	BEGIN_LOOP_APPLICATION:
3067 leency 145
		WaitEventTimeout(2);
146
		switch(EAX & 0xFF)
147
		{
148
			CASE evMouse:
4081 leency 149
				if (!CheckActiveProcess(Form.ID)) break;
4636 leency 150
				//Edit URL
3466 leency 151
				edit_box_mouse stdcall (#address_box);
5640 pavelyakov 152
				mouse.get();
4636 leency 153
				//Links hover
5640 pavelyakov 154
				if (mouse.y>WB1.list.y) PageLinks.Hover(mouse.x, mouse.y, link_color_inactive, link_color_active, bg_color);
4636 leency 155
				//Menu
5640 pavelyakov 156
				if (mouse.y>WB1.list.y) && (mouse.y
3067 leency 157
				{
5640 pavelyakov 158
					if (mouse.pkm) && (mouse.up)
4026 leency 159
					{
160
						SwitchToAnotherThread();
4074 leency 161
						CreateThread(#menu_rmb,#stak+4092);
4026 leency 162
						break;
163
					}
3067 leency 164
				}
4636 leency 165
				//Mouse scroll
5640 pavelyakov 166
				if (mouse.vert)
3067 leency 167
				{
5640 pavelyakov 168
					if (WB1.list.MouseScroll(mouse.vert)) WB1.Parse();
3067 leency 169
				}
4636 leency 170
				//Drag scroller
4677 leency 171
				scroll_wv.all_redraw = 0;
5640 pavelyakov 172
				if (!mouse.lkm) scroll_used=0;
173
				if (mouse.x>=scroll_wv.start_x) && (mouse.x<=scroll_wv.start_x+scroll_wv.size_x)
174
				&& (mouse.y>=scroll_wv.start_y+scroll_wv.btn_height) && (-scroll_wv.btn_height+scroll_wv.start_y+scroll_wv.size_y>mouse.y)
175
				&& (WB1.list.count>WB1.list.visible) && (mouse.lkm)
4026 leency 176
				{
177
					scroll_used=1;
4636 leency 178
				}
3067 leency 179
				if (scroll_used)
180
				{
5678 leency 181
					mouse.y = mouse.y + 5;
4415 leency 182
					half_scroll_size = WB1.list.h - 16 * WB1.list.visible / WB1.list.count - 3 /2;
5640 pavelyakov 183
					if (half_scroll_size+WB1.list.y>mouse.y) || (mouse.y<0) || (mouse.y>4000) mouse.y=half_scroll_size+WB1.list.y;
4416 leency 184
					btn=WB1.list.first;
5640 pavelyakov 185
					WB1.list.first = mouse.y -half_scroll_size -WB1.list.y * WB1.list.count / WB1.list.h;
4415 leency 186
					if (WB1.list.visible+WB1.list.first>WB1.list.count) WB1.list.first=WB1.list.count-WB1.list.visible;
5631 pavelyakov 187
					if (btn!=WB1.list.first) WB1.Parse();
3067 leency 188
				}
189
				break;
190
			case evButton:
191
				btn=GetButtonID();
4636 leency 192
				if (btn==1)	ExitProcess();
193
				Scan(btn);
3067 leency 194
				break;
195
			case evKey:
5530 leency 196
				key = GetKey();
5531 leency 197
				if (address_box.flags & 0b10)
5530 leency 198
				{
5531 leency 199
					if (key==ASCII_KEY_ENTER) Scan(key); else
5631 pavelyakov 200
					if (key!=0x0d) && (key!=183) && (key!=184) {EAX=key<<8; edit_box_key stdcall(#address_box);}
5530 leency 201
				}
202
				else Scan(key);
203
				break;
3067 leency 204
 
205
			case evReDraw:
4636 leency 206
				if (action_buf) Scan(action_buf);
4725 leency 207
				DefineAndDrawWindow(GetScreenWidth()-WIN_W/2,GetScreenHeight()-WIN_H/2,WIN_W,WIN_H,0x73,col_bg,0,0);
208
				GetProcessInfo(#Form, SelfInfo);
4727 leency 209
				if (Form.status_window>2) { DrawTitle(#header); break; }
4725 leency 210
				if (Form.height<120) MoveSize(OLD,OLD,OLD,120);
211
				if (Form.width<280) MoveSize(OLD,OLD,280,OLD);
3067 leency 212
				Draw_Window();
213
				break;
4540 leency 214
 
4536 leency 215
			case evNetwork:
4540 leency 216
				if (http_transfer > 0) {
5534 hidnplayr 217
					http_receive stdcall (http_transfer);
4677 leency 218
					$push EAX
219
					ESI = http_transfer;
5519 leency 220
					wv_progress_bar.max = ESI.http_msg.content_length;
221
					if (wv_progress_bar.value != ESI.http_msg.content_received)
4686 leency 222
					{
5519 leency 223
						wv_progress_bar.value = ESI.http_msg.content_received;
4686 leency 224
						DrawProgress();
225
					}
4677 leency 226
					$pop EAX
227
					if (EAX == 0) {
4558 hidnplayr 228
						ESI = http_transfer;
229
						// Handle redirects
4563 leency 230
						if (ESI.http_msg.status >= 300) && (ESI.http_msg.status < 400)
231
						{
4558 hidnplayr 232
							redirected++;
4563 leency 233
							if (redirected<=5)
234
							{
4558 hidnplayr 235
								http_find_header_field stdcall (http_transfer, #str_location);
236
								if (EAX!=0) {
237
									ESI = EAX;
238
									EDI = #URL;
239
									do {
240
										$lodsb;
241
										$stosb;
242
									} while (AL != 0) && (AL != 13) && (AL != 10));
243
									DSBYTE[EDI-1]='\0';
244
								}
4563 leency 245
							}
246
							else
247
							{
4558 hidnplayr 248
							//TODO: display error (too many redirects)
249
							}
4563 leency 250
						}
251
						else
252
						{
4558 hidnplayr 253
							redirected = 0;
254
						}
4554 leency 255
						// Loading the page is complete, free resources
4563 leency 256
						if (redirected>0)
257
						{
4643 leency 258
							http_free stdcall (http_transfer);
259
							http_transfer=0;
4686 leency 260
							PageLinks.GetAbsoluteURL(#URL);
4687 leency 261
							BrowserHistory.current--;
4558 hidnplayr 262
							strcpy(#editURL, #URL);
263
							OpenPage();
4563 leency 264
						}
265
						else
266
						{
4686 leency 267
							BrowserHistory.AddUrl();
4643 leency 268
							ESI = http_transfer;
269
							bufpointer = ESI.http_msg.content_ptr;
270
							bufsize = ESI.http_msg.content_received;
271
							http_free stdcall (http_transfer);
272
							http_transfer=0;
4645 leency 273
							SetPageDefaults();
4558 hidnplayr 274
							Draw_Window();		// stop button => refresh button
275
						}
4536 leency 276
					}
277
				}
3067 leency 278
		}
5631 pavelyakov 279
	goto BEGIN_LOOP_APPLICATION;
3067 leency 280
}
281
 
282
void SetElementSizes()
283
{
4677 leency 284
	address_box.top = TOOLBAR_H-TAB_H/2-7+TAB_H;
285
	address_box.width = Form.cwidth - address_box.left - 25 - 22;
5678 leency 286
	WB1.list.SetSizes(0, TOOLBAR_H, Form.width - 10 - scroll_wv.size_x / WB1.DrawBuf.zoom,
287
		Form.cheight - TOOLBAR_H - STATUSBAR_H, 0, 11*WB1.DrawBuf.zoom);
4651 leency 288
	WB1.list.column_max = WB1.list.w - scroll_wv.size_x / 6;
4692 leency 289
	WB1.list.visible = WB1.list.h - 5 / WB1.list.line_h;
4674 leency 290
	WB1.DrawBuf.Init(WB1.list.x, WB1.list.y, WB1.list.w, WB1.list.line_h);
3067 leency 291
}
292
 
293
void Draw_Window()
294
{
4677 leency 295
	int img_off;
296
	// tab {
4692 leency 297
	if (TAB_H)
298
	{
299
		DrawBar(0, 0, TAB_W, TAB_H+1, panel_color);
300
		WriteText(5, 7, 0x80, 0xfdfdFd, "Index.htm");
301
		WriteText(4, 6, 0x80, 0, "Index.htm");
302
		DrawBar(TAB_W,0, Form.cwidth-TAB_W,TAB_H, col_bg);
303
		DrawBar(TAB_W-1,TAB_H, Form.cwidth-TAB_W+1,1, border_color);
304
		img_draw stdcall(skin.image, TAB_W-13, 0, 30, skin.h, 101, 0);
305
	}
306
	else DrawBar(0,0, Form.cwidth,1, col_bg);
4677 leency 307
	// }
4686 leency 308
	DrawBar(0,TAB_H+1, Form.cwidth,TOOLBAR_H-TAB_H-3, panel_color);
309
	DrawBar(0,TOOLBAR_H-2, Form.cwidth,1, 0xe9e9e9);
4677 leency 310
	DrawBar(0,TOOLBAR_H-1, Form.cwidth,1, border_color);
3067 leency 311
	SetElementSizes();
4677 leency 312
	DrawRectangle(address_box.left-1, address_box.top-1, address_box.width+2, 16,address_box.color);
313
	DrawRectangle(address_box.left-2, address_box.top-2, address_box.width+4, 18,border_color);
314
	// < / >
315
	DefineButton(address_box.left-49, address_box.top-1, 23, skin.h-2, 300+BT_HIDE, 0);
316
	DefineButton(address_box.left-25, address_box.top-1, 23, skin.h-2, 301+BT_HIDE, 0);
317
	img_draw stdcall(skin.image, address_box.left-50, address_box.top-2, 48, skin.h, 3, 0);
318
	// refrash
319
	DefineButton(address_box.left+address_box.width+1, address_box.top-2, 16, skin.h-1, REFRESH+BT_HIDE+BT_NOFRAME, 0);
320
	if (http_transfer > 0) img_off = 131; else img_off = 52;
321
	img_draw stdcall(skin.image, address_box.left+address_box.width+1, address_box.top-2, 17, skin.h, img_off, 0);
322
	// config
323
	DefineButton(Form.cwidth-23, address_box.top-2, 17, skin.h-1, 312+BT_HIDE, 0);
4692 leency 324
	img_draw stdcall(skin.image, Form.cwidth-22, address_box.top-2, 16, skin.h, 85, 0);
4677 leency 325
	//status bar
326
	DrawBar(0,Form.cheight - STATUSBAR_H, Form.cwidth,STATUSBAR_H, col_bg);
327
	DrawBar(0,Form.cheight - STATUSBAR_H, Form.cwidth,1, border_color);
5519 leency 328
	wv_progress_bar.top = Form.cheight - STATUSBAR_H + 4;
4692 leency 329
	ShowPage();
330
	DrawRectangle(scroll_wv.start_x, scroll_wv.start_y, scroll_wv.size_x, scroll_wv.size_y-1, scroll_wv.bckg_col);
4693 leency 331
	DrawProgress();
3067 leency 332
}
333
 
334
 
4636 leency 335
void ChangeCharset(byte new_charset)
336
{
337
	BufEncode(new_charset);
338
	WB1.Parse();
339
}
340
 
4413 leency 341
void Scan(int id)
342
{
4636 leency 343
	action_buf=0;
344
	if (id >= 400)
345
	{
346
		ProcessLinks(id);
347
		return;
348
	}
4413 leency 349
	switch (id)
350
	{
351
		case 011: //Ctrk+K
4636 leency 352
			ChangeCharset(_KOI);
4415 leency 353
			return;
354
 
4413 leency 355
		case 021: //Ctrl+U
4636 leency 356
			ChangeCharset(_UTF);
4415 leency 357
			return;
358
 
4413 leency 359
		case 004: //Ctrl+D
4636 leency 360
			ChangeCharset(_DOS);
4415 leency 361
			return;
362
 
4533 leency 363
		case 005: //Win encoding
4636 leency 364
			ChangeCharset(_WIN);
4533 leency 365
			return;
366
 
367
		case 009: //free img cache
4491 leency 368
			ImgCache.Free();
4416 leency 369
			notify(IMAGES_CACHE_CLEARED);
4636 leency 370
			WB1.Parse();
4415 leency 371
			return;
372
 
4546 leency 373
		case 003: //history
4677 leency 374
			strcpy(#URL, URL_SERVICE_HISTORY);
4544 leency 375
			OpenPage();
376
			return;
377
 
5493 leency 378
		case 006: //download manager
5519 leency 379
			if (!downloader_opened) {
5631 pavelyakov 380
				strncpy(#DL_URL, "http://",7);
5519 leency 381
				CreateThread(#Downloader,#downloader_stak+4092);
382
			}
5493 leency 383
			return;
384
 
5530 leency 385
		case ASCII_KEY_BS:
4413 leency 386
		case BACK:
387
			if (!BrowserHistory.GoBack()) return;
4416 leency 388
			OpenPage();
4413 leency 389
			return;
390
		case FORWARD:
391
			if (!BrowserHistory.GoForward()) return;
4416 leency 392
			OpenPage();
4413 leency 393
			return;
4718 leency 394
		case 052: //F3
4725 leency 395
			WB1.list.first = 0;
4718 leency 396
			ShowSource();
4719 leency 397
			WB1.Parse();
4718 leency 398
			break;
399
		case 053: //F4
5631 pavelyakov 400
			if (!strncmp(#URL,"http:",5))
4636 leency 401
			{
4718 leency 402
				WriteFile(bufsize, bufpointer, "/tmp0/1/WebView_tmp.htm");
5631 pavelyakov 403
				if (!EAX) RunProgram("/rd/1/tinypad", "/tmp0/1/WebView_tmp.htm");
4636 leency 404
			}
5631 pavelyakov 405
			else RunProgram("/rd/1/tinypad", #URL);
4413 leency 406
			return;
407
		case 054: //F5
4688 leency 408
			IF(address_box.flags & 0b10) return;
4413 leency 409
		case REFRESH:
4643 leency 410
			if (http_transfer > 0)
411
			{
412
				StopLoading();
413
				Draw_Window();
414
			}
4636 leency 415
			else OpenPage();
4413 leency 416
			return;
4415 leency 417
		case 014:
418
		case 020:
4413 leency 419
		case NEWTAB:
420
			MoveSize(190,80,OLD,OLD);
421
			RunProgram(#program_path, #URL);
422
			return;
423
		case GOTOURL:
424
		case 0x0D: //enter
4718 leency 425
			if (!editURL[0]) return;
5631 pavelyakov 426
			if (strncmp(#editURL,"http:",5)) && (editURL[0]!='/') && (strncmp(#editURL,"WebView:",9)) strncpy(#URL,"http://",7);
4692 leency 427
			else
428
				URL[0] = 0;
4413 leency 429
			strcat(#URL, #editURL);
4416 leency 430
			OpenPage();
4413 leency 431
			return;
432
		case SEARCHWEB:
5631 pavelyakov 433
			sprintf(#URL,"%s%s",#search_path,#editURL);
4416 leency 434
			OpenPage();
4413 leency 435
			return;
436
 
437
		case 183: //PgDown
4415 leency 438
			if (WB1.list.count < WB1.list.visible) return;
439
			IF(WB1.list.first == WB1.list.count - WB1.list.visible) return;
440
			WB1.list.first += WB1.list.visible + 2;
441
			IF(WB1.list.visible + WB1.list.first > WB1.list.count) WB1.list.first = WB1.list.count - WB1.list.visible;
4636 leency 442
			WB1.Parse();
4415 leency 443
			return;
444
 
4413 leency 445
		case 184: //PgUp
4415 leency 446
			if (WB1.list.count < WB1.list.visible) return;
447
			IF(WB1.list.first == 0) return;
448
			WB1.list.first -= WB1.list.visible - 2;
449
			IF(WB1.list.first < 0) WB1.list.first = 0;
4636 leency 450
			WB1.Parse();
4415 leency 451
			return;
452
 
453
		case 178:
4544 leency 454
		case BTN_UP:
4416 leency 455
			if (WB1.list.first <= 0) return;
4415 leency 456
			WB1.list.first--;
4636 leency 457
			WB1.Parse();
4415 leency 458
			return;
459
 
460
		case 177:
4544 leency 461
		case BTN_DOWN:
4416 leency 462
			if (WB1.list.visible + WB1.list.first >= WB1.list.count) return;
4415 leency 463
			WB1.list.first++;
4636 leency 464
			WB1.Parse();
4415 leency 465
			return;
466
 
4413 leency 467
		case 180: //home
4636 leency 468
			if (WB1.list.KeyHome()) WB1.Parse();
4415 leency 469
			return;
470
 
4413 leency 471
		case 181: //end
4415 leency 472
			if (WB1.list.count < WB1.list.visible) return;
4636 leency 473
			if (WB1.list.KeyEnd()) WB1.Parse();
4413 leency 474
			return;
4677 leency 475
		case 312:
476
			SwitchToAnotherThread();
5640 pavelyakov 477
			mouse.y = TOOLBAR_H-6;
478
			mouse.x = Form.cwidth - 167;
4677 leency 479
			CreateThread(#menu_rmb,#stak+4092);
5519 leency 480
			return;
481
		case 122:
5678 leency 482
			if (WB1.DrawBuf.zoom==1) WB1.DrawBuf.zoom=2; else WB1.DrawBuf.zoom=1;
5519 leency 483
			Draw_Window();
4413 leency 484
	}
485
}
486
 
487
 
488
 
4415 leency 489
void ProcessLinks(int id)
490
{
4687 leency 491
	if (http_transfer > 0)
492
	{
493
		StopLoading();
494
		BrowserHistory.current--;
495
	}
496
 
4544 leency 497
	strcpy(#URL, PageLinks.GetURL(id-401));
4417 leency 498
	//$1 - Condition Script
499
	if (URL[0] == '$')
500
	{
501
		if (URL[1]=='-') && (condition_href) condition_href--;
5631 pavelyakov 502
		else if (URL[1]=='+')
4417 leency 503
		{
504
			if (condition_href
505
		}
5631 pavelyakov 506
		else condition_href = atoi(#URL+1);
4417 leency 507
		strcpy(#URL, BrowserHistory.CurrentUrl());
4508 leency 508
		ShowPage();
4417 leency 509
		return;
510
	}
4415 leency 511
	//#1
512
	if (URL[0] == '#')
513
	{
4417 leency 514
		strcpy(#anchor, #URL+strrchr(#URL, '#'));
4415 leency 515
		strcpy(#URL, BrowserHistory.CurrentUrl());
516
		WB1.list.first=WB1.list.count-WB1.list.visible;
4508 leency 517
		ShowPage();
4415 leency 518
		return;
519
	}
520
	//liner.ru#1
4417 leency 521
	if (strrchr(#URL, '#')!=-1)
4415 leency 522
	{
523
		strcpy(#anchor, #URL+strrchr(#URL, '#'));
4416 leency 524
		URL[strrchr(#URL, '#')-1] = 0x00;
4415 leency 525
	}
526
 
4686 leency 527
	PageLinks.GetAbsoluteURL(#URL);
4415 leency 528
 
5519 leency 529
	if (UrlExtIs(".png")==1) || (UrlExtIs(".gif")==1) || (UrlExtIs(".jpg")==1) || (UrlExtIs(".zip")==1) || (UrlExtIs(".kex")==1)
5493 leency 530
	|| (UrlExtIs(".7z")==1) || (UrlExtIs("netcfg")==1)
4415 leency 531
	{
5509 leency 532
		//notify(#URL);
5631 pavelyakov 533
		if (!strncmp(#URL,"http://", 7))
5493 leency 534
		{
535
			strcpy(#DL_URL, #URL);
536
			CreateThread(#Downloader,#downloader_stak+4092);
537
		}
5631 pavelyakov 538
		else RunProgram("@open", #URL);
4415 leency 539
		strcpy(#editURL, BrowserHistory.CurrentUrl());
540
		strcpy(#URL, BrowserHistory.CurrentUrl());
541
		return;
542
	}
5631 pavelyakov 543
	if (!strncmp(#URL,"mailto:", 7))
4415 leency 544
	{
545
		notify(#URL);
546
		strcpy(#editURL, BrowserHistory.CurrentUrl());
547
		strcpy(#URL, BrowserHistory.CurrentUrl());
548
		return;
549
	}
4416 leency 550
	OpenPage();
4415 leency 551
	return;
552
}
553
 
4636 leency 554
void StopLoading()
555
{
5631 pavelyakov 556
	if (http_transfer)
4647 leency 557
	{
558
		EAX = http_transfer;
559
		EAX = EAX.http_msg.content_ptr;		// get pointer to data
560
		$push	EAX							// save it on the stack
561
		http_free stdcall (http_transfer);	// abort connection
562
		$pop	EAX
5631 pavelyakov 563
		free(EAX);						// free data
4647 leency 564
		http_transfer=0;
565
		bufsize = 0;
5631 pavelyakov 566
		bufpointer = free(bufpointer);
4647 leency 567
	}
5519 leency 568
	wv_progress_bar.value = 0;
4677 leency 569
	img_draw stdcall(skin.image, address_box.left+address_box.width+1, address_box.top-2, 17, skin.h, 52, 0);
4645 leency 570
}
571
 
572
void SetPageDefaults()
573
{
574
	strcpy(#header, #version);
575
	pre_text = 0;
576
	WB1.list.count = WB1.list.first = 0;
577
	stroka = 0;
578
	cur_encoding = _DEFAULT;
579
	if (o_bufpointer) o_bufpointer = free(o_bufpointer);
4636 leency 580
	anchor_line_num=WB1.list.first;
581
	anchor[0]='|';
582
}
583
 
4416 leency 584
void OpenPage()
585
{
4636 leency 586
	StopLoading();
4718 leency 587
	souce_mode = false;
4416 leency 588
	strcpy(#editURL, #URL);
4687 leency 589
	BrowserHistory.AddUrl();
5631 pavelyakov 590
	if (!strncmp(#URL,"WebView:",8))
4692 leency 591
	{
592
		SetPageDefaults();
5631 pavelyakov 593
		if (!strcmp(#URL, URL_SERVICE_HOME)) WB1.Prepare(#homepage, sizeof(homepage));
594
		else if (!strcmp(#URL, URL_SERVICE_HISTORY)) ShowHistory();
4692 leency 595
		return;
596
	}
5631 pavelyakov 597
	if (!strncmp(#URL,"http:",5))
4416 leency 598
	{
4677 leency 599
		img_draw stdcall(skin.image, address_box.left+address_box.width+1, address_box.top-2, 17, skin.h, 131, 0);
5534 hidnplayr 600
		http_get stdcall (#URL, 0, 0, #accept_language);
4636 leency 601
		http_transfer = EAX;
5631 pavelyakov 602
		if (!http_transfer)
4646 leency 603
		{
604
			StopLoading();
605
			bufsize = 0;
5631 pavelyakov 606
			bufpointer = free(bufpointer);
4646 leency 607
			ShowPage();
608
			return;
609
		}
4416 leency 610
	}
4636 leency 611
	else
612
	{
613
		file_size stdcall (#URL);
614
		bufsize = EBX;
4650 leency 615
		if (bufsize)
616
		{
5631 pavelyakov 617
			free(bufpointer);
618
			bufpointer = malloc(bufsize);
4650 leency 619
			SetPageDefaults();
4718 leency 620
			ReadFile(0, bufsize, bufpointer, #URL);
621
			//ShowSource();
4650 leency 622
		}
4645 leency 623
		ShowPage();
4636 leency 624
	}
4416 leency 625
}
4415 leency 626
 
4718 leency 627
DrawEditBox()
4508 leency 628
{
4718 leency 629
	address_box.size = address_box.pos = address_box.shift = address_box.shift_old = strlen(#editURL);
630
	address_box.offset = 0;
4508 leency 631
	edit_box_draw stdcall(#address_box);
4718 leency 632
}
4415 leency 633
 
4718 leency 634
 
635
void ShowPage()
636
{
637
	DrawEditBox();
4540 leency 638
	if (!bufsize)
4508 leency 639
	{
640
		PageLinks.Clear();
5631 pavelyakov 641
		if (http_transfer)
4636 leency 642
		{
643
			WB1.Prepare(#loading, sizeof(loading));
644
		}
4508 leency 645
		else
4636 leency 646
			WB1.Prepare(#page_not_found, sizeof(page_not_found));
4508 leency 647
	}
648
	else
4636 leency 649
		WB1.Parse();
4415 leency 650
 
4508 leency 651
	if (!header) strcpy(#header, #version);
652
	if (!strcmp(#version, #header)) DrawTitle(#header);
653
}
654
 
5493 leency 655
byte UrlExtIs(dword ext)
656
{
5631 pavelyakov 657
	if (!strcmpi(#URL + strlen(#URL) - strlen(ext), ext)) return true;
658
	return false;
5493 leency 659
}
4508 leency 660
 
4544 leency 661
 
5493 leency 662
char downloader_stak[4096];
5631 pavelyakov 663
stop: