Subversion Repositories Kolibri OS

Rev

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