Subversion Repositories Kolibri OS

Rev

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