Subversion Repositories Kolibri OS

Rev

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