Subversion Repositories Kolibri OS

Rev

Rev 5445 | Rev 5499 | 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"
14
#include "..\lib\figures.h"
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
24
#include "..\lib\lib.obj\box_lib.h"
25
#include "..\lib\lib.obj\libio_lib.h"
26
#include "..\lib\lib.obj\libimg_lib.h"
4536 leency 27
#include "..\lib\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
5493 leency 35
	char version[]=" Текстовый браузер 1.0";
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
5493 leency 42
	char version[]=" Text-based Browser 1.0";
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;
51
#define WIN_W 640
52
#define WIN_H 480
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;
4718 leency 68
dword STATUSBAR_H =15;
69
dword col_bg;
70
dword panel_color;
71
dword border_color;
4677 leency 72
 
5445 leency 73
progress_bar 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];
101
	progress_bar.progress_color = DSDWORD[skin.w*4*10 + image_data];
102
	$and col_bg, 0x00ffffff
103
	$and panel_color, 0x00ffffff
104
	$and border_color, 0x00ffffff
105
	$and progress_bar.progress_color, 0x00ffffff
4677 leency 106
}
107
 
4686 leency 108
void DrawProgress()
109
{
110
	unsigned long btn;
111
	//progressbar_draw stdcall(#progress_bar);
112
	progress_bar.width = progress_bar.left = 0;
113
	if (http_transfer == 0) return;
114
	if (progress_bar.max) btn = address_box.width*progress_bar.value/progress_bar.max; else btn = 30;
115
	DrawBar(address_box.left-1, address_box.top+14, btn, 2, progress_bar.progress_color);
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
 
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);
3067 leency 143
	loop()
144
	{
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);
3067 leency 152
				m.get();
4636 leency 153
				//Links hover
4550 leency 154
				if (m.y>WB1.list.y) PageLinks.Hover(m.x, m.y, link_color_inactive, link_color_active, bg_color);
4636 leency 155
				//Menu
4540 leency 156
				if (m.y>WB1.list.y) && (m.y
3067 leency 157
				{
4026 leency 158
					if (m.pkm)
159
					{
160
						show_menu = 1;
161
					}
162
					if (!m.pkm) && (show_menu)
163
					{
164
						show_menu = 0;
165
						SwitchToAnotherThread();
4074 leency 166
						CreateThread(#menu_rmb,#stak+4092);
4026 leency 167
						break;
168
					}
3067 leency 169
				}
4636 leency 170
				//Mouse scroll
4415 leency 171
				if (m.vert)
3067 leency 172
				{
4636 leency 173
					if (WB1.list.MouseScroll(m.vert)) WB1.Parse();
3067 leency 174
				}
4636 leency 175
				//Drag scroller
4677 leency 176
				scroll_wv.all_redraw = 0;
3067 leency 177
				if (!m.lkm) scroll_used=0;
4416 leency 178
				if (m.x>=scroll_wv.start_x) && (m.x<=scroll_wv.start_x+scroll_wv.size_x)
179
				&& (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 180
				&& (WB1.list.count>WB1.list.visible) && (m.lkm)
4026 leency 181
				{
182
					scroll_used=1;
4636 leency 183
				}
3067 leency 184
				if (scroll_used)
185
				{
4415 leency 186
					half_scroll_size = WB1.list.h - 16 * WB1.list.visible / WB1.list.count - 3 /2;
4416 leency 187
					if (half_scroll_size+WB1.list.y>m.y) || (m.y<0) || (m.y>4000) m.y=half_scroll_size+WB1.list.y;
188
					btn=WB1.list.first;
4415 leency 189
					WB1.list.first = m.y -half_scroll_size -WB1.list.y * WB1.list.count / WB1.list.h;
190
					if (WB1.list.visible+WB1.list.first>WB1.list.count) WB1.list.first=WB1.list.count-WB1.list.visible;
4636 leency 191
					if (btn<>WB1.list.first) WB1.Parse();
3067 leency 192
				}
193
				break;
194
			case evButton:
195
				btn=GetButtonID();
4636 leency 196
				if (btn==1)	ExitProcess();
197
				Scan(btn);
3067 leency 198
				break;
199
			case evKey:
200
				key = GetKey();
201
 
4416 leency 202
				if (address_box.flags & 0b10) SWITCH(key)
4718 leency 203
					{ CASE 52: CASE 53: CASE 54: CASE 180: CASE 181: goto _EDIT_MARK; }
3067 leency 204
 
4413 leency 205
				Scan(key);
3067 leency 206
 
207
				_EDIT_MARK:
4416 leency 208
				if (key<>0x0d) && (key<>183) && (key<>184) {EAX=key<<8; edit_box_key stdcall(#address_box);}
3067 leency 209
				break;
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;
225
					progress_bar.max = ESI.http_msg.content_length;
4686 leency 226
					if (progress_bar.value != ESI.http_msg.content_received)
227
					{
228
						progress_bar.value = ESI.http_msg.content_received;
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;
4718 leency 291
	WB1.list.SetSizes(0, TOOLBAR_H, Form.width - 10 - scroll_wv.size_x, Form.cheight - TOOLBAR_H - STATUSBAR_H, 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);
332
	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
383
			DL_URL[0] = 0;
384
			CreateThread(#Downloader,#downloader_stak+4092);
385
			return;
386
 
4413 leency 387
		case BACK:
388
			if (!BrowserHistory.GoBack()) return;
4416 leency 389
			OpenPage();
4413 leency 390
			return;
391
		case FORWARD:
392
			if (!BrowserHistory.GoForward()) return;
4416 leency 393
			OpenPage();
4413 leency 394
			return;
4718 leency 395
		case 052: //F3
4725 leency 396
			WB1.list.first = 0;
4718 leency 397
			ShowSource();
4719 leency 398
			WB1.Parse();
4718 leency 399
			break;
400
		case 053: //F4
4636 leency 401
			if (strncmp(#URL,"http:",5)==0)
402
			{
4718 leency 403
				WriteFile(bufsize, bufpointer, "/tmp0/1/WebView_tmp.htm");
404
				if (EAX==0) RunProgram("/rd/1/tinypad", "/tmp0/1/WebView_tmp.htm");
4636 leency 405
			}
406
			else
407
			{
408
				RunProgram("/rd/1/tinypad", #URL);
409
			}
4413 leency 410
			return;
411
		case 054: //F5
4688 leency 412
			IF(address_box.flags & 0b10) return;
4413 leency 413
		case REFRESH:
4643 leency 414
			if (http_transfer > 0)
415
			{
416
				StopLoading();
417
				Draw_Window();
418
			}
4636 leency 419
			else OpenPage();
4413 leency 420
			return;
4415 leency 421
		case 014:
422
		case 020:
4413 leency 423
		case NEWTAB:
424
			MoveSize(190,80,OLD,OLD);
425
			RunProgram(#program_path, #URL);
426
			return;
427
		case GOTOURL:
428
		case 0x0D: //enter
4718 leency 429
			if (!editURL[0]) return;
4692 leency 430
			if ((strncmp(#editURL,"http:",5)!=0) && (editURL[0]!='/') && ((strncmp(#editURL,"WebView:",8)!=0))
431
			{
432
				strcpy(#URL,"http://");
433
			}
434
			else
435
				URL[0] = 0;
4413 leency 436
			strcat(#URL, #editURL);
4416 leency 437
			OpenPage();
4413 leency 438
			return;
439
		case SEARCHWEB:
440
			strcpy(#URL, #search_path);
441
			strcat(#URL, #editURL);
4416 leency 442
			OpenPage();
4413 leency 443
			return;
444
 
445
		case 183: //PgDown
4415 leency 446
			if (WB1.list.count < WB1.list.visible) return;
447
			IF(WB1.list.first == WB1.list.count - WB1.list.visible) return;
448
			WB1.list.first += WB1.list.visible + 2;
449
			IF(WB1.list.visible + WB1.list.first > WB1.list.count) WB1.list.first = WB1.list.count - WB1.list.visible;
4636 leency 450
			WB1.Parse();
4415 leency 451
			return;
452
 
4413 leency 453
		case 184: //PgUp
4415 leency 454
			if (WB1.list.count < WB1.list.visible) return;
455
			IF(WB1.list.first == 0) return;
456
			WB1.list.first -= WB1.list.visible - 2;
457
			IF(WB1.list.first < 0) WB1.list.first = 0;
4636 leency 458
			WB1.Parse();
4415 leency 459
			return;
460
 
461
		case 178:
4544 leency 462
		case BTN_UP:
4416 leency 463
			if (WB1.list.first <= 0) return;
4415 leency 464
			WB1.list.first--;
4636 leency 465
			WB1.Parse();
4415 leency 466
			return;
467
 
468
		case 177:
4544 leency 469
		case BTN_DOWN:
4416 leency 470
			if (WB1.list.visible + WB1.list.first >= WB1.list.count) return;
4415 leency 471
			WB1.list.first++;
4636 leency 472
			WB1.Parse();
4415 leency 473
			return;
474
 
4413 leency 475
		case 180: //home
4636 leency 476
			if (WB1.list.KeyHome()) WB1.Parse();
4415 leency 477
			return;
478
 
4413 leency 479
		case 181: //end
4415 leency 480
			if (WB1.list.count < WB1.list.visible) return;
4636 leency 481
			if (WB1.list.KeyEnd()) WB1.Parse();
4413 leency 482
			return;
4677 leency 483
		case 312:
484
			SwitchToAnotherThread();
485
			m.y = TOOLBAR_H-6;
486
			m.x = Form.cwidth - 167;
487
			CreateThread(#menu_rmb,#stak+4092);
4413 leency 488
	}
489
}
490
 
491
 
492
 
4415 leency 493
void ProcessLinks(int id)
494
{
4687 leency 495
	if (http_transfer > 0)
496
	{
497
		StopLoading();
498
		BrowserHistory.current--;
499
	}
500
 
4544 leency 501
	strcpy(#URL, PageLinks.GetURL(id-401));
4417 leency 502
	//$1 - Condition Script
503
	if (URL[0] == '$')
504
	{
505
		if (URL[1]=='-') && (condition_href) condition_href--;
506
		if (URL[1]=='+')
507
		{
508
			if (condition_href
509
		}
510
		if (URL[1]!='-') && (URL[1]!='+') condition_href = atoi(#URL+1);
511
		strcpy(#URL, BrowserHistory.CurrentUrl());
4508 leency 512
		ShowPage();
4417 leency 513
		return;
514
	}
4415 leency 515
	//#1
516
	if (URL[0] == '#')
517
	{
4417 leency 518
		strcpy(#anchor, #URL+strrchr(#URL, '#'));
4415 leency 519
		strcpy(#URL, BrowserHistory.CurrentUrl());
520
		WB1.list.first=WB1.list.count-WB1.list.visible;
4508 leency 521
		ShowPage();
4415 leency 522
		return;
523
	}
524
	//liner.ru#1
4417 leency 525
	if (strrchr(#URL, '#')!=-1)
4415 leency 526
	{
527
		strcpy(#anchor, #URL+strrchr(#URL, '#'));
4416 leency 528
		URL[strrchr(#URL, '#')-1] = 0x00;
4415 leency 529
	}
530
 
4686 leency 531
	PageLinks.GetAbsoluteURL(#URL);
4415 leency 532
 
5493 leency 533
	if (UrlExtIs(".png")==1) || (UrlExtIs(".gif")==1) || (UrlExtIs(".jpg")==1) || (UrlExtIs(".zip")==1)
534
	|| (UrlExtIs(".7z")==1) || (UrlExtIs("netcfg")==1)
4415 leency 535
	{
5493 leency 536
		notify(#URL);
537
		if (strcmpn(#URL,"http://:", 8)==0)
538
		{
539
			strcpy(#DL_URL, #URL);
540
			CreateThread(#Downloader,#downloader_stak+4092);
541
		}
542
		else
543
		{
544
			RunProgram("@open", #URL);
545
		}
4415 leency 546
		strcpy(#editURL, BrowserHistory.CurrentUrl());
547
		strcpy(#URL, BrowserHistory.CurrentUrl());
548
		return;
549
	}
550
	if (!strcmpn(#URL,"mailto:", 7))
551
	{
552
		notify(#URL);
553
		strcpy(#editURL, BrowserHistory.CurrentUrl());
554
		strcpy(#URL, BrowserHistory.CurrentUrl());
555
		return;
556
	}
4416 leency 557
	OpenPage();
4415 leency 558
	return;
559
}
560
 
4636 leency 561
void StopLoading()
562
{
4647 leency 563
	if (http_transfer<>0)
564
	{
565
		EAX = http_transfer;
566
		EAX = EAX.http_msg.content_ptr;		// get pointer to data
567
		$push	EAX							// save it on the stack
568
		http_free stdcall (http_transfer);	// abort connection
569
		$pop	EAX
570
		mem_Free(EAX);						// free data
571
		http_transfer=0;
572
		bufsize = 0;
4650 leency 573
		bufpointer = mem_Free(bufpointer);
4647 leency 574
	}
4677 leency 575
	progress_bar.value = 0;
576
	img_draw stdcall(skin.image, address_box.left+address_box.width+1, address_box.top-2, 17, skin.h, 52, 0);
4645 leency 577
}
578
 
579
void SetPageDefaults()
580
{
581
	strcpy(#header, #version);
582
	pre_text = 0;
583
	WB1.list.count = WB1.list.first = 0;
584
	stroka = 0;
585
	cur_encoding = _DEFAULT;
586
	if (o_bufpointer) o_bufpointer = free(o_bufpointer);
4636 leency 587
	anchor_line_num=WB1.list.first;
588
	anchor[0]='|';
589
}
590
 
4416 leency 591
void OpenPage()
592
{
4636 leency 593
	StopLoading();
4718 leency 594
	souce_mode = false;
4416 leency 595
	strcpy(#editURL, #URL);
4687 leency 596
	BrowserHistory.AddUrl();
4692 leency 597
	if (strncmp(#URL,"WebView:",8)==0)
598
	{
599
		SetPageDefaults();
600
		if (strcmp(#URL, URL_SERVICE_HOME)==0)
601
		{
602
			WB1.Prepare(#homepage, sizeof(homepage));
603
		}
604
		if (strcmp(#URL, URL_SERVICE_HISTORY)==0)
605
		{
606
			ShowHistory();
607
		}
608
		return;
609
	}
4636 leency 610
	if (strncmp(#URL,"http:",5)==0)
4416 leency 611
	{
4677 leency 612
		img_draw stdcall(skin.image, address_box.left+address_box.width+1, address_box.top-2, 17, skin.h, 131, 0);
4636 leency 613
		http_get stdcall (#URL, #accept_language);
614
		http_transfer = EAX;
4646 leency 615
		if (http_transfer == 0)
616
		{
617
			StopLoading();
618
			bufsize = 0;
4650 leency 619
			bufpointer = mem_Free(bufpointer);
4646 leency 620
			ShowPage();
621
			return;
622
		}
4416 leency 623
	}
4636 leency 624
	else
625
	{
626
		file_size stdcall (#URL);
627
		bufsize = EBX;
4650 leency 628
		if (bufsize)
629
		{
4718 leency 630
			mem_Free(bufpointer);
4650 leency 631
			bufpointer = mem_Alloc(bufsize);
632
			SetPageDefaults();
4718 leency 633
			ReadFile(0, bufsize, bufpointer, #URL);
634
			//ShowSource();
4650 leency 635
		}
4645 leency 636
		ShowPage();
4636 leency 637
	}
4416 leency 638
}
4415 leency 639
 
4718 leency 640
DrawEditBox()
4508 leency 641
{
4718 leency 642
	address_box.size = address_box.pos = address_box.shift = address_box.shift_old = strlen(#editURL);
643
	address_box.offset = 0;
4508 leency 644
	edit_box_draw stdcall(#address_box);
4718 leency 645
}
4415 leency 646
 
4718 leency 647
 
648
void ShowPage()
649
{
650
	DrawEditBox();
4540 leency 651
	if (!bufsize)
4508 leency 652
	{
653
		PageLinks.Clear();
4636 leency 654
		if (http_transfer<>0)
655
		{
656
			WB1.Prepare(#loading, sizeof(loading));
657
		}
4508 leency 658
		else
4636 leency 659
			WB1.Prepare(#page_not_found, sizeof(page_not_found));
4508 leency 660
	}
661
	else
4636 leency 662
		WB1.Parse();
4415 leency 663
 
4508 leency 664
	if (!header) strcpy(#header, #version);
665
	if (!strcmp(#version, #header)) DrawTitle(#header);
666
}
667
 
5493 leency 668
byte UrlExtIs(dword ext)
669
{
670
	if (strcmpi(#URL + strlen(#URL) - strlen(ext), ext)==0) return 1; else return 0;
671
}
4508 leency 672
 
4544 leency 673
 
4636 leency 674
 
5493 leency 675
 
3067 leency 676
stop:
5493 leency 677
 
678
char downloader_stak[4096];