Subversion Repositories Kolibri OS

Rev

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