Subversion Repositories Kolibri OS

Rev

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