Subversion Repositories Kolibri OS

Rev

Rev 5631 | Rev 5651 | 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
5531 leency 33
	char version[]=" Текстовый браузер 1.12";
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
5531 leency 40
	char version[]=" Text-based Browser 1.12";
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"
5493 leency 80
#include "downloader.h"
3067 leency 81
 
4534 leency 82
char editURL[sizeof(URL)];
83
int	mouse_twb;
4677 leency 84
edit_box address_box = {250,55,34,0xffffff,0x94AECE,0xffffff,0xffffff,0,sizeof(URL),#editURL,#mouse_twb,2,19,19};
4534 leency 85
 
4677 leency 86
#define URL_SERVICE_HISTORY "WebView://history"
87
#define URL_SERVICE_HOME "WebView://home"
4718 leency 88
#define URL_SERVICE_SOURCE "WebView://source:"
4534 leency 89
 
4488 leency 90
enum { BACK=300, FORWARD, REFRESH, HOME, NEWTAB, GOTOURL, SEARCHWEB, INPUT_CH, INPUT_BT, BTN_UP, BTN_DOWN };
3067 leency 91
 
5408 leency 92
libimg_image skin;
4488 leency 93
 
5408 leency 94
int SetSkinColors()
4677 leency 95
{
4718 leency 96
	dword image_data;
97
	image_data = DSDWORD[skin.image+24];
4846 leency 98
	col_bg = DSDWORD[image_data];
4718 leency 99
	panel_color  = DSDWORD[skin.w*4*4 + image_data];
100
	border_color = DSDWORD[skin.w*4*7 + image_data];
5519 leency 101
	wv_progress_bar.progress_color = DSDWORD[skin.w*4*10 + image_data];
4718 leency 102
	$and col_bg, 0x00ffffff
103
	$and panel_color, 0x00ffffff
104
	$and border_color, 0x00ffffff
5519 leency 105
	$and wv_progress_bar.progress_color, 0x00ffffff
4677 leency 106
}
107
 
4686 leency 108
void DrawProgress()
109
{
110
	unsigned long btn;
5519 leency 111
	//progressbar_draw stdcall(#wv_progress_bar);
112
	wv_progress_bar.width = wv_progress_bar.left = 0;
4686 leency 113
	if (http_transfer == 0) return;
5519 leency 114
	if (wv_progress_bar.max) btn = address_box.width*wv_progress_bar.value/wv_progress_bar.max; else btn = 30;
115
	DrawBar(address_box.left-1, address_box.top+14, btn, 2, wv_progress_bar.progress_color);
4686 leency 116
}
117
 
4718 leency 118
 
3067 leency 119
void main()
120
{
4686 leency 121
	unsigned long key, btn;
3067 leency 122
	int half_scroll_size;
4026 leency 123
	int scroll_used=0, show_menu;
3067 leency 124
 
125
	mem_Init();
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
 
5519 leency 134
	WB1.DrawBuf.zoomf = 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
				{
5640 pavelyakov 181
					mouse.y = mouse.y / WB1.DrawBuf.zoomf + 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;
5519 leency 286
	WB1.list.SetSizes(0, TOOLBAR_H, Form.width - 10 - scroll_wv.size_x / WB1.DrawBuf.zoomf, Form.cheight - TOOLBAR_H - STATUSBAR_H / WB1.DrawBuf.zoomf, 0, 11);
4651 leency 287
	WB1.list.column_max = WB1.list.w - scroll_wv.size_x / 6;
4692 leency 288
	WB1.list.visible = WB1.list.h - 5 / WB1.list.line_h;
4674 leency 289
	WB1.DrawBuf.Init(WB1.list.x, WB1.list.y, WB1.list.w, WB1.list.line_h);
3067 leency 290
}
291
 
292
void Draw_Window()
293
{
4677 leency 294
	int img_off;
295
	// tab {
4692 leency 296
	if (TAB_H)
297
	{
298
		DrawBar(0, 0, TAB_W, TAB_H+1, panel_color);
299
		WriteText(5, 7, 0x80, 0xfdfdFd, "Index.htm");
300
		WriteText(4, 6, 0x80, 0, "Index.htm");
301
		DrawBar(TAB_W,0, Form.cwidth-TAB_W,TAB_H, col_bg);
302
		DrawBar(TAB_W-1,TAB_H, Form.cwidth-TAB_W+1,1, border_color);
303
		img_draw stdcall(skin.image, TAB_W-13, 0, 30, skin.h, 101, 0);
304
	}
305
	else DrawBar(0,0, Form.cwidth,1, col_bg);
4677 leency 306
	// }
4686 leency 307
	DrawBar(0,TAB_H+1, Form.cwidth,TOOLBAR_H-TAB_H-3, panel_color);
308
	DrawBar(0,TOOLBAR_H-2, Form.cwidth,1, 0xe9e9e9);
4677 leency 309
	DrawBar(0,TOOLBAR_H-1, Form.cwidth,1, border_color);
3067 leency 310
	SetElementSizes();
4677 leency 311
	DrawRectangle(address_box.left-1, address_box.top-1, address_box.width+2, 16,address_box.color);
312
	DrawRectangle(address_box.left-2, address_box.top-2, address_box.width+4, 18,border_color);
313
	// < / >
314
	DefineButton(address_box.left-49, address_box.top-1, 23, skin.h-2, 300+BT_HIDE, 0);
315
	DefineButton(address_box.left-25, address_box.top-1, 23, skin.h-2, 301+BT_HIDE, 0);
316
	img_draw stdcall(skin.image, address_box.left-50, address_box.top-2, 48, skin.h, 3, 0);
317
	// refrash
318
	DefineButton(address_box.left+address_box.width+1, address_box.top-2, 16, skin.h-1, REFRESH+BT_HIDE+BT_NOFRAME, 0);
319
	if (http_transfer > 0) img_off = 131; else img_off = 52;
320
	img_draw stdcall(skin.image, address_box.left+address_box.width+1, address_box.top-2, 17, skin.h, img_off, 0);
321
	// config
322
	DefineButton(Form.cwidth-23, address_box.top-2, 17, skin.h-1, 312+BT_HIDE, 0);
4692 leency 323
	img_draw stdcall(skin.image, Form.cwidth-22, address_box.top-2, 16, skin.h, 85, 0);
4677 leency 324
	//status bar
325
	DrawBar(0,Form.cheight - STATUSBAR_H, Form.cwidth,STATUSBAR_H, col_bg);
326
	DrawBar(0,Form.cheight - STATUSBAR_H, Form.cwidth,1, border_color);
5519 leency 327
	wv_progress_bar.top = Form.cheight - STATUSBAR_H + 4;
4692 leency 328
	ShowPage();
329
	DrawRectangle(scroll_wv.start_x, scroll_wv.start_y, scroll_wv.size_x, scroll_wv.size_y-1, scroll_wv.bckg_col);
4693 leency 330
	DrawProgress();
3067 leency 331
}
332
 
333
 
4636 leency 334
void ChangeCharset(byte new_charset)
335
{
336
	BufEncode(new_charset);
337
	WB1.Parse();
338
}
339
 
4413 leency 340
void Scan(int id)
341
{
4636 leency 342
	action_buf=0;
343
	if (id >= 400)
344
	{
345
		ProcessLinks(id);
346
		return;
347
	}
4413 leency 348
	switch (id)
349
	{
350
		case 011: //Ctrk+K
4636 leency 351
			ChangeCharset(_KOI);
4415 leency 352
			return;
353
 
4413 leency 354
		case 021: //Ctrl+U
4636 leency 355
			ChangeCharset(_UTF);
4415 leency 356
			return;
357
 
4413 leency 358
		case 004: //Ctrl+D
4636 leency 359
			ChangeCharset(_DOS);
4415 leency 360
			return;
361
 
4533 leency 362
		case 005: //Win encoding
4636 leency 363
			ChangeCharset(_WIN);
4533 leency 364
			return;
365
 
366
		case 009: //free img cache
4491 leency 367
			ImgCache.Free();
4416 leency 368
			notify(IMAGES_CACHE_CLEARED);
4636 leency 369
			WB1.Parse();
4415 leency 370
			return;
371
 
4546 leency 372
		case 003: //history
4677 leency 373
			strcpy(#URL, URL_SERVICE_HISTORY);
4544 leency 374
			OpenPage();
375
			return;
376
 
5493 leency 377
		case 006: //download manager
5519 leency 378
			if (!downloader_opened) {
5631 pavelyakov 379
				strncpy(#DL_URL, "http://",7);
5519 leency 380
				CreateThread(#Downloader,#downloader_stak+4092);
381
			}
5493 leency 382
			return;
383
 
5530 leency 384
		case ASCII_KEY_BS:
4413 leency 385
		case BACK:
386
			if (!BrowserHistory.GoBack()) return;
4416 leency 387
			OpenPage();
4413 leency 388
			return;
389
		case FORWARD:
390
			if (!BrowserHistory.GoForward()) return;
4416 leency 391
			OpenPage();
4413 leency 392
			return;
4718 leency 393
		case 052: //F3
4725 leency 394
			WB1.list.first = 0;
4718 leency 395
			ShowSource();
4719 leency 396
			WB1.Parse();
4718 leency 397
			break;
398
		case 053: //F4
5631 pavelyakov 399
			if (!strncmp(#URL,"http:",5))
4636 leency 400
			{
4718 leency 401
				WriteFile(bufsize, bufpointer, "/tmp0/1/WebView_tmp.htm");
5631 pavelyakov 402
				if (!EAX) RunProgram("/rd/1/tinypad", "/tmp0/1/WebView_tmp.htm");
4636 leency 403
			}
5631 pavelyakov 404
			else RunProgram("/rd/1/tinypad", #URL);
4413 leency 405
			return;
406
		case 054: //F5
4688 leency 407
			IF(address_box.flags & 0b10) return;
4413 leency 408
		case REFRESH:
4643 leency 409
			if (http_transfer > 0)
410
			{
411
				StopLoading();
412
				Draw_Window();
413
			}
4636 leency 414
			else OpenPage();
4413 leency 415
			return;
4415 leency 416
		case 014:
417
		case 020:
4413 leency 418
		case NEWTAB:
419
			MoveSize(190,80,OLD,OLD);
420
			RunProgram(#program_path, #URL);
421
			return;
422
		case GOTOURL:
423
		case 0x0D: //enter
4718 leency 424
			if (!editURL[0]) return;
5631 pavelyakov 425
			if (strncmp(#editURL,"http:",5)) && (editURL[0]!='/') && (strncmp(#editURL,"WebView:",9)) strncpy(#URL,"http://",7);
4692 leency 426
			else
427
				URL[0] = 0;
4413 leency 428
			strcat(#URL, #editURL);
4416 leency 429
			OpenPage();
4413 leency 430
			return;
431
		case SEARCHWEB:
5631 pavelyakov 432
			sprintf(#URL,"%s%s",#search_path,#editURL);
4416 leency 433
			OpenPage();
4413 leency 434
			return;
435
 
436
		case 183: //PgDown
4415 leency 437
			if (WB1.list.count < WB1.list.visible) return;
438
			IF(WB1.list.first == WB1.list.count - WB1.list.visible) return;
439
			WB1.list.first += WB1.list.visible + 2;
440
			IF(WB1.list.visible + WB1.list.first > WB1.list.count) WB1.list.first = WB1.list.count - WB1.list.visible;
4636 leency 441
			WB1.Parse();
4415 leency 442
			return;
443
 
4413 leency 444
		case 184: //PgUp
4415 leency 445
			if (WB1.list.count < WB1.list.visible) return;
446
			IF(WB1.list.first == 0) return;
447
			WB1.list.first -= WB1.list.visible - 2;
448
			IF(WB1.list.first < 0) WB1.list.first = 0;
4636 leency 449
			WB1.Parse();
4415 leency 450
			return;
451
 
452
		case 178:
4544 leency 453
		case BTN_UP:
4416 leency 454
			if (WB1.list.first <= 0) return;
4415 leency 455
			WB1.list.first--;
4636 leency 456
			WB1.Parse();
4415 leency 457
			return;
458
 
459
		case 177:
4544 leency 460
		case BTN_DOWN:
4416 leency 461
			if (WB1.list.visible + WB1.list.first >= WB1.list.count) return;
4415 leency 462
			WB1.list.first++;
4636 leency 463
			WB1.Parse();
4415 leency 464
			return;
465
 
4413 leency 466
		case 180: //home
4636 leency 467
			if (WB1.list.KeyHome()) WB1.Parse();
4415 leency 468
			return;
469
 
4413 leency 470
		case 181: //end
4415 leency 471
			if (WB1.list.count < WB1.list.visible) return;
4636 leency 472
			if (WB1.list.KeyEnd()) WB1.Parse();
4413 leency 473
			return;
4677 leency 474
		case 312:
475
			SwitchToAnotherThread();
5640 pavelyakov 476
			mouse.y = TOOLBAR_H-6;
477
			mouse.x = Form.cwidth - 167;
4677 leency 478
			CreateThread(#menu_rmb,#stak+4092);
5519 leency 479
			return;
480
		case 122:
481
			if (WB1.DrawBuf.zoomf==1) WB1.DrawBuf.zoomf=2; else WB1.DrawBuf.zoomf=1;
482
			Draw_Window();
4413 leency 483
	}
484
}
485
 
486
 
487
 
4415 leency 488
void ProcessLinks(int id)
489
{
4687 leency 490
	if (http_transfer > 0)
491
	{
492
		StopLoading();
493
		BrowserHistory.current--;
494
	}
495
 
4544 leency 496
	strcpy(#URL, PageLinks.GetURL(id-401));
4417 leency 497
	//$1 - Condition Script
498
	if (URL[0] == '$')
499
	{
500
		if (URL[1]=='-') && (condition_href) condition_href--;
5631 pavelyakov 501
		else if (URL[1]=='+')
4417 leency 502
		{
503
			if (condition_href
504
		}
5631 pavelyakov 505
		else condition_href = atoi(#URL+1);
4417 leency 506
		strcpy(#URL, BrowserHistory.CurrentUrl());
4508 leency 507
		ShowPage();
4417 leency 508
		return;
509
	}
4415 leency 510
	//#1
511
	if (URL[0] == '#')
512
	{
4417 leency 513
		strcpy(#anchor, #URL+strrchr(#URL, '#'));
4415 leency 514
		strcpy(#URL, BrowserHistory.CurrentUrl());
515
		WB1.list.first=WB1.list.count-WB1.list.visible;
4508 leency 516
		ShowPage();
4415 leency 517
		return;
518
	}
519
	//liner.ru#1
4417 leency 520
	if (strrchr(#URL, '#')!=-1)
4415 leency 521
	{
522
		strcpy(#anchor, #URL+strrchr(#URL, '#'));
4416 leency 523
		URL[strrchr(#URL, '#')-1] = 0x00;
4415 leency 524
	}
525
 
4686 leency 526
	PageLinks.GetAbsoluteURL(#URL);
4415 leency 527
 
5519 leency 528
	if (UrlExtIs(".png")==1) || (UrlExtIs(".gif")==1) || (UrlExtIs(".jpg")==1) || (UrlExtIs(".zip")==1) || (UrlExtIs(".kex")==1)
5493 leency 529
	|| (UrlExtIs(".7z")==1) || (UrlExtIs("netcfg")==1)
4415 leency 530
	{
5509 leency 531
		//notify(#URL);
5631 pavelyakov 532
		if (!strncmp(#URL,"http://", 7))
5493 leency 533
		{
534
			strcpy(#DL_URL, #URL);
535
			CreateThread(#Downloader,#downloader_stak+4092);
536
		}
5631 pavelyakov 537
		else RunProgram("@open", #URL);
4415 leency 538
		strcpy(#editURL, BrowserHistory.CurrentUrl());
539
		strcpy(#URL, BrowserHistory.CurrentUrl());
540
		return;
541
	}
5631 pavelyakov 542
	if (!strncmp(#URL,"mailto:", 7))
4415 leency 543
	{
544
		notify(#URL);
545
		strcpy(#editURL, BrowserHistory.CurrentUrl());
546
		strcpy(#URL, BrowserHistory.CurrentUrl());
547
		return;
548
	}
4416 leency 549
	OpenPage();
4415 leency 550
	return;
551
}
552
 
4636 leency 553
void StopLoading()
554
{
5631 pavelyakov 555
	if (http_transfer)
4647 leency 556
	{
557
		EAX = http_transfer;
558
		EAX = EAX.http_msg.content_ptr;		// get pointer to data
559
		$push	EAX							// save it on the stack
560
		http_free stdcall (http_transfer);	// abort connection
561
		$pop	EAX
5631 pavelyakov 562
		free(EAX);						// free data
4647 leency 563
		http_transfer=0;
564
		bufsize = 0;
5631 pavelyakov 565
		bufpointer = free(bufpointer);
4647 leency 566
	}
5519 leency 567
	wv_progress_bar.value = 0;
4677 leency 568
	img_draw stdcall(skin.image, address_box.left+address_box.width+1, address_box.top-2, 17, skin.h, 52, 0);
4645 leency 569
}
570
 
571
void SetPageDefaults()
572
{
573
	strcpy(#header, #version);
574
	pre_text = 0;
575
	WB1.list.count = WB1.list.first = 0;
576
	stroka = 0;
577
	cur_encoding = _DEFAULT;
578
	if (o_bufpointer) o_bufpointer = free(o_bufpointer);
4636 leency 579
	anchor_line_num=WB1.list.first;
580
	anchor[0]='|';
581
}
582
 
4416 leency 583
void OpenPage()
584
{
4636 leency 585
	StopLoading();
4718 leency 586
	souce_mode = false;
4416 leency 587
	strcpy(#editURL, #URL);
4687 leency 588
	BrowserHistory.AddUrl();
5631 pavelyakov 589
	if (!strncmp(#URL,"WebView:",8))
4692 leency 590
	{
591
		SetPageDefaults();
5631 pavelyakov 592
		if (!strcmp(#URL, URL_SERVICE_HOME)) WB1.Prepare(#homepage, sizeof(homepage));
593
		else if (!strcmp(#URL, URL_SERVICE_HISTORY)) ShowHistory();
4692 leency 594
		return;
595
	}
5631 pavelyakov 596
	if (!strncmp(#URL,"http:",5))
4416 leency 597
	{
4677 leency 598
		img_draw stdcall(skin.image, address_box.left+address_box.width+1, address_box.top-2, 17, skin.h, 131, 0);
5534 hidnplayr 599
		http_get stdcall (#URL, 0, 0, #accept_language);
4636 leency 600
		http_transfer = EAX;
5631 pavelyakov 601
		if (!http_transfer)
4646 leency 602
		{
603
			StopLoading();
604
			bufsize = 0;
5631 pavelyakov 605
			bufpointer = free(bufpointer);
4646 leency 606
			ShowPage();
607
			return;
608
		}
4416 leency 609
	}
4636 leency 610
	else
611
	{
612
		file_size stdcall (#URL);
613
		bufsize = EBX;
4650 leency 614
		if (bufsize)
615
		{
5631 pavelyakov 616
			free(bufpointer);
617
			bufpointer = malloc(bufsize);
4650 leency 618
			SetPageDefaults();
4718 leency 619
			ReadFile(0, bufsize, bufpointer, #URL);
620
			//ShowSource();
4650 leency 621
		}
4645 leency 622
		ShowPage();
4636 leency 623
	}
4416 leency 624
}
4415 leency 625
 
4718 leency 626
DrawEditBox()
4508 leency 627
{
4718 leency 628
	address_box.size = address_box.pos = address_box.shift = address_box.shift_old = strlen(#editURL);
629
	address_box.offset = 0;
4508 leency 630
	edit_box_draw stdcall(#address_box);
4718 leency 631
}
4415 leency 632
 
4718 leency 633
 
634
void ShowPage()
635
{
636
	DrawEditBox();
4540 leency 637
	if (!bufsize)
4508 leency 638
	{
639
		PageLinks.Clear();
5631 pavelyakov 640
		if (http_transfer)
4636 leency 641
		{
642
			WB1.Prepare(#loading, sizeof(loading));
643
		}
4508 leency 644
		else
4636 leency 645
			WB1.Prepare(#page_not_found, sizeof(page_not_found));
4508 leency 646
	}
647
	else
4636 leency 648
		WB1.Parse();
4415 leency 649
 
4508 leency 650
	if (!header) strcpy(#header, #version);
651
	if (!strcmp(#version, #header)) DrawTitle(#header);
652
}
653
 
5493 leency 654
byte UrlExtIs(dword ext)
655
{
5631 pavelyakov 656
	if (!strcmpi(#URL + strlen(#URL) - strlen(ext), ext)) return true;
657
	return false;
5493 leency 658
}
4508 leency 659
 
4544 leency 660
 
5493 leency 661
char downloader_stak[4096];
5631 pavelyakov 662
stop: