Subversion Repositories Kolibri OS

Rev

Rev 4677 | Rev 4687 | 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
 
4677 leency 29
char homepage[] = FROM "html\homepage.htm";
30
 
4026 leency 31
#ifdef LANG_RUS
4686 leency 32
	char version[]=" Текстовый браузер 1.0 Beta 2";
4416 leency 33
	?define IMAGES_CACHE_CLEARED "Кэш картинок очищен"
4417 leency 34
	?define T_LAST_SLIDE "Это последний слайд"
4550 leency 35
	char loading[] = "Загрузка страницы...
";
4677 leency 36
	char page_not_found[] = FROM "html\page_not_found_ru.htm";
4649 leency 37
	char accept_language[]= "Accept-Language: ru\n";
4026 leency 38
#else
4686 leency 39
	char version[]=" Text-based Browser 1.0 Beta 2";
4026 leency 40
	?define IMAGES_CACHE_CLEARED "Images cache cleared"
4417 leency 41
	?define T_LAST_SLIDE "This slide is the last"
4550 leency 42
	char loading[] = "Loading...
";
4677 leency 43
	char page_not_found[] = FROM "html\page_not_found_en.htm";
4649 leency 44
	char accept_language[]= "Accept-Language: en\n";
4026 leency 45
#endif
46
 
3067 leency 47
proc_info Form;
48
#define WIN_W 640
49
#define WIN_H 480
50
 
4416 leency 51
char search_path[]="http://nigma.ru/index.php?s=";
4558 hidnplayr 52
char str_location[]="location\0";
53
int redirected = 0;
3067 leency 54
 
4074 leency 55
char stak[4096];
3067 leency 56
mouse m;
4026 leency 57
int action_buf;
58
 
4565 leency 59
dword http_transfer = 0;
4537 leency 60
dword http_buffer;
4534 leency 61
 
4677 leency 62
dword TAB_H = 19;
63
dword TAB_W = 150;
64
dword TOOLBAR_H = 50;
65
dword STATUSBAR_H =18;
66
dword col_bg = 0xE4DFE1;
67
dword panel_color = 0xF1F1F1;
68
dword border_color = 0x9F9F9F;
69
 
4686 leency 70
pb progress_bar = {0, 10, 83, 150, 12, 0, 0, 100, 0xeeeEEE, 8072B7EBh, 0x9F9F9F};
4677 leency 71
 
4411 leency 72
#include "..\TWB\TWB.c"
73
#include "menu_rmb.h"
4636 leency 74
#include "history.h"
3067 leency 75
 
4534 leency 76
char editURL[sizeof(URL)];
77
int	mouse_twb;
4677 leency 78
edit_box address_box = {250,55,34,0xffffff,0x94AECE,0xffffff,0xffffff,0,sizeof(URL),#editURL,#mouse_twb,2,19,19};
4534 leency 79
 
4677 leency 80
#define URL_SERVICE_HISTORY "WebView://history"
81
#define URL_SERVICE_HOME "WebView://home"
4534 leency 82
 
4488 leency 83
enum { BACK=300, FORWARD, REFRESH, HOME, NEWTAB, GOTOURL, SEARCHWEB, INPUT_CH, INPUT_BT, BTN_UP, BTN_DOWN };
3067 leency 84
 
4677 leency 85
struct skin {
86
	dword image, w, h;
87
} skin;
4488 leency 88
 
4677 leency 89
int LoadSkin()
90
{
91
	skin.image = load_image(abspath("wv_skin.png"));
4686 leency 92
	if (!skin.image) notify("WebView skin file 'wv_skin.png' not found, program will terminate");
4677 leency 93
	skin.w = DSWORD[skin.image+4];
94
	skin.h = DSWORD[skin.image+8];
95
}
96
 
4686 leency 97
void DrawProgress()
98
{
99
	unsigned long btn;
100
	//progressbar_draw stdcall(#progress_bar);
101
	progress_bar.width = progress_bar.left = 0;
102
	if (http_transfer == 0) return;
103
	if (progress_bar.max) btn = address_box.width*progress_bar.value/progress_bar.max; else btn = 30;
104
	DrawBar(address_box.left-1, address_box.top+14, btn, 2, progress_bar.progress_color);
105
}
106
 
3067 leency 107
void main()
108
{
4686 leency 109
	unsigned long key, btn;
3067 leency 110
	int half_scroll_size;
4026 leency 111
	int scroll_used=0, show_menu;
3067 leency 112
 
113
	mem_Init();
4536 leency 114
	CursorPointer.Load(#CursorFile);
4686 leency 115
	if (load_dll2(boxlib, #box_lib_init,0)!=0) notify("System Error: library doesn't exists /rd/1/lib/box_lib.obj");
4536 leency 116
	if (load_dll2(libio, #libio_init,1)!=0) notify("Error: library doesn't exists - libio");
117
	if (load_dll2(libimg, #libimg_init,1)!=0) notify("Error: library doesn't exists - libimg");
4540 leency 118
	if (load_dll2(libHTTP, #http_lib_init,1)!=0) notify("Error: library doesn't exists - http");
4677 leency 119
	LoadSkin();
3067 leency 120
 
121
	Form.width=WIN_W;
122
	Form.height=WIN_H;
123
	SetElementSizes();
4677 leency 124
	if (!URL) strcpy(#URL, URL_SERVICE_HOME);
4416 leency 125
	OpenPage();
3067 leency 126
 
4536 leency 127
	SetEventMask(0xa7);
3067 leency 128
	loop()
129
	{
130
		WaitEventTimeout(2);
131
		switch(EAX & 0xFF)
132
		{
133
			CASE evMouse:
4081 leency 134
				if (!CheckActiveProcess(Form.ID)) break;
4636 leency 135
				//Edit URL
3466 leency 136
				edit_box_mouse stdcall (#address_box);
3067 leency 137
				m.get();
4636 leency 138
				//Links hover
4550 leency 139
				if (m.y>WB1.list.y) PageLinks.Hover(m.x, m.y, link_color_inactive, link_color_active, bg_color);
4636 leency 140
				//Menu
4540 leency 141
				if (m.y>WB1.list.y) && (m.y
3067 leency 142
				{
4026 leency 143
					if (m.pkm)
144
					{
145
						show_menu = 1;
146
					}
147
					if (!m.pkm) && (show_menu)
148
					{
149
						show_menu = 0;
150
						SwitchToAnotherThread();
4074 leency 151
						CreateThread(#menu_rmb,#stak+4092);
4026 leency 152
						break;
153
					}
3067 leency 154
				}
4636 leency 155
				//Mouse scroll
4415 leency 156
				if (m.vert)
3067 leency 157
				{
4636 leency 158
					if (WB1.list.MouseScroll(m.vert)) WB1.Parse();
3067 leency 159
				}
4636 leency 160
				//Drag scroller
4677 leency 161
				scroll_wv.all_redraw = 0;
3067 leency 162
				if (!m.lkm) scroll_used=0;
4416 leency 163
				if (m.x>=scroll_wv.start_x) && (m.x<=scroll_wv.start_x+scroll_wv.size_x)
164
				&& (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 165
				&& (WB1.list.count>WB1.list.visible) && (m.lkm)
4026 leency 166
				{
167
					scroll_used=1;
4636 leency 168
				}
3067 leency 169
				if (scroll_used)
170
				{
4415 leency 171
					half_scroll_size = WB1.list.h - 16 * WB1.list.visible / WB1.list.count - 3 /2;
4416 leency 172
					if (half_scroll_size+WB1.list.y>m.y) || (m.y<0) || (m.y>4000) m.y=half_scroll_size+WB1.list.y;
173
					btn=WB1.list.first;
4415 leency 174
					WB1.list.first = m.y -half_scroll_size -WB1.list.y * WB1.list.count / WB1.list.h;
175
					if (WB1.list.visible+WB1.list.first>WB1.list.count) WB1.list.first=WB1.list.count-WB1.list.visible;
4636 leency 176
					if (btn<>WB1.list.first) WB1.Parse();
3067 leency 177
				}
178
				break;
179
			case evButton:
180
				btn=GetButtonID();
4636 leency 181
				if (btn==1)	ExitProcess();
182
				Scan(btn);
3067 leency 183
				break;
184
			case evKey:
185
				key = GetKey();
186
 
4416 leency 187
				if (address_box.flags & 0b10) SWITCH(key)
3067 leency 188
					{ CASE 52: CASE 53: CASE 54: goto _EDIT_MARK; }
189
 
4413 leency 190
				Scan(key);
3067 leency 191
 
192
				_EDIT_MARK:
4416 leency 193
				if (key<>0x0d) && (key<>183) && (key<>184) {EAX=key<<8; edit_box_key stdcall(#address_box);}
3067 leency 194
				break;
195
			case evReDraw:
4636 leency 196
				if (action_buf) Scan(action_buf);
3067 leency 197
				Draw_Window();
198
				break;
4540 leency 199
 
4536 leency 200
			case evNetwork:
4540 leency 201
				if (http_transfer > 0) {
4536 leency 202
					http_process stdcall (http_transfer);
4677 leency 203
					$push EAX
204
					ESI = http_transfer;
205
					progress_bar.max = ESI.http_msg.content_length;
4686 leency 206
					if (progress_bar.value != ESI.http_msg.content_received)
207
					{
208
						progress_bar.value = ESI.http_msg.content_received;
209
						DrawProgress();
210
					}
4677 leency 211
					$pop EAX
212
					if (EAX == 0) {
4558 hidnplayr 213
						ESI = http_transfer;
214
						// Handle redirects
4563 leency 215
						if (ESI.http_msg.status >= 300) && (ESI.http_msg.status < 400)
216
						{
4558 hidnplayr 217
							redirected++;
4563 leency 218
							if (redirected<=5)
219
							{
4558 hidnplayr 220
								http_find_header_field stdcall (http_transfer, #str_location);
221
								if (EAX!=0) {
222
									ESI = EAX;
223
									EDI = #URL;
224
									do {
225
										$lodsb;
226
										$stosb;
227
									} while (AL != 0) && (AL != 13) && (AL != 10));
228
									DSBYTE[EDI-1]='\0';
229
								}
4563 leency 230
							}
231
							else
232
							{
4558 hidnplayr 233
							//TODO: display error (too many redirects)
234
							}
4563 leency 235
						}
236
						else
237
						{
4558 hidnplayr 238
							redirected = 0;
239
						}
4554 leency 240
						// Loading the page is complete, free resources
4563 leency 241
						if (redirected>0)
242
						{
4643 leency 243
							http_free stdcall (http_transfer);
244
							http_transfer=0;
4686 leency 245
							PageLinks.GetAbsoluteURL(#URL);
4558 hidnplayr 246
							strcpy(#editURL, #URL);
247
							OpenPage();
4563 leency 248
						}
249
						else
250
						{
4686 leency 251
							BrowserHistory.AddUrl();
4643 leency 252
							ESI = http_transfer;
253
							bufpointer = ESI.http_msg.content_ptr;
254
							bufsize = ESI.http_msg.content_received;
255
							http_free stdcall (http_transfer);
256
							http_transfer=0;
4645 leency 257
							SetPageDefaults();
4558 hidnplayr 258
							Draw_Window();		// stop button => refresh button
259
						}
4536 leency 260
					}
261
				}
3067 leency 262
		}
263
	}
264
}
265
 
266
void SetElementSizes()
267
{
4677 leency 268
	address_box.top = TOOLBAR_H-TAB_H/2-7+TAB_H;
269
	address_box.width = Form.cwidth - address_box.left - 25 - 22;
270
	WB1.list.SetSizes(0, TOOLBAR_H, Form.width - 10 - scroll_wv.size_x, Form.cheight - TOOLBAR_H - STATUSBAR_H, 0, 10);
4651 leency 271
	WB1.list.column_max = WB1.list.w - scroll_wv.size_x / 6;
4415 leency 272
	WB1.list.visible = WB1.list.h - 3 / WB1.list.line_h - 2;
4674 leency 273
	WB1.DrawBuf.Init(WB1.list.x, WB1.list.y, WB1.list.w, WB1.list.line_h);
3067 leency 274
}
275
 
276
void Draw_Window()
277
{
4677 leency 278
	int img_off;
279
	DefineAndDrawWindow(GetScreenWidth()-WIN_W/2,GetScreenHeight()-WIN_H/2,WIN_W,WIN_H,0x73,col_bg,0,0);
3067 leency 280
	GetProcessInfo(#Form, SelfInfo);
4677 leency 281
	if (Form.status_window>2) { DrawTitle(#header); return; }
3067 leency 282
	if (Form.height<120) MoveSize(OLD,OLD,OLD,120);
283
	if (Form.width<280) MoveSize(OLD,OLD,280,OLD);
4677 leency 284
	// tab {
285
	DrawBar(0, 0, TAB_W, TAB_H+1, panel_color);
286
	WriteText(5, 7, 0x80, 0xfdfdFd, "Index.htm");
287
	WriteText(4, 6, 0x80, 0, "Index.htm");
288
	// }
289
	DrawBar(TAB_W,0, Form.cwidth-TAB_W,TAB_H, col_bg);
290
	DrawBar(TAB_W-1,TAB_H, Form.cwidth-TAB_W+1,1, border_color);
4686 leency 291
	DrawBar(0,TAB_H+1, Form.cwidth,TOOLBAR_H-TAB_H-3, panel_color);
292
	DrawBar(0,TOOLBAR_H-2, Form.cwidth,1, 0xe9e9e9);
4677 leency 293
	DrawBar(0,TOOLBAR_H-1, Form.cwidth,1, border_color);
294
	img_draw stdcall(skin.image, TAB_W-13, 0, 30, skin.h, 101, 0);
3067 leency 295
 
296
	SetElementSizes();
4677 leency 297
	DrawRectangle(address_box.left-1, address_box.top-1, address_box.width+2, 16,address_box.color);
298
	DrawRectangle(address_box.left-2, address_box.top-2, address_box.width+4, 18,border_color);
299
	// < / >
300
	DefineButton(address_box.left-49, address_box.top-1, 23, skin.h-2, 300+BT_HIDE, 0);
301
	DefineButton(address_box.left-25, address_box.top-1, 23, skin.h-2, 301+BT_HIDE, 0);
302
	img_draw stdcall(skin.image, address_box.left-50, address_box.top-2, 48, skin.h, 3, 0);
303
	// refrash
304
	DefineButton(address_box.left+address_box.width+1, address_box.top-2, 16, skin.h-1, REFRESH+BT_HIDE+BT_NOFRAME, 0);
305
	if (http_transfer > 0) img_off = 131; else img_off = 52;
306
	img_draw stdcall(skin.image, address_box.left+address_box.width+1, address_box.top-2, 17, skin.h, img_off, 0);
307
	// config
308
	DefineButton(Form.cwidth-23, address_box.top-2, 17, skin.h-1, 312+BT_HIDE, 0);
309
	img_draw stdcall(skin.image, Form.cwidth-22, address_box.top-2, 16, skin.h, 85, 0);
310
 
4508 leency 311
	ShowPage();
4677 leency 312
	DrawRectangle(scroll_wv.start_x, scroll_wv.start_y, scroll_wv.size_x, scroll_wv.size_y-1, scroll_wv.bckg_col);
313
	//status bar
314
	DrawBar(0,Form.cheight - STATUSBAR_H, Form.cwidth,STATUSBAR_H, col_bg);
315
	DrawBar(0,Form.cheight - STATUSBAR_H, Form.cwidth,1, border_color);
316
	progress_bar.top = Form.cheight - STATUSBAR_H + 4;
4686 leency 317
	DrawProgress();
3067 leency 318
}
319
 
320
 
4636 leency 321
void ChangeCharset(byte new_charset)
322
{
323
	BufEncode(new_charset);
324
	WB1.Parse();
325
}
326
 
4413 leency 327
void Scan(int id)
328
{
4636 leency 329
	action_buf=0;
330
	if (id >= 400)
331
	{
332
		ProcessLinks(id);
333
		return;
334
	}
4413 leency 335
	switch (id)
336
	{
337
		case 011: //Ctrk+K
4636 leency 338
			ChangeCharset(_KOI);
4415 leency 339
			return;
340
 
4413 leency 341
		case 021: //Ctrl+U
4636 leency 342
			ChangeCharset(_UTF);
4415 leency 343
			return;
344
 
4413 leency 345
		case 004: //Ctrl+D
4636 leency 346
			ChangeCharset(_DOS);
4415 leency 347
			return;
348
 
4533 leency 349
		case 005: //Win encoding
4636 leency 350
			ChangeCharset(_WIN);
4533 leency 351
			return;
352
 
353
		case 009: //free img cache
4491 leency 354
			ImgCache.Free();
4416 leency 355
			notify(IMAGES_CACHE_CLEARED);
4636 leency 356
			WB1.Parse();
4415 leency 357
			return;
358
 
4546 leency 359
		case 003: //history
4677 leency 360
			strcpy(#URL, URL_SERVICE_HISTORY);
4544 leency 361
			OpenPage();
362
			return;
363
 
4413 leency 364
		case BACK:
365
			if (!BrowserHistory.GoBack()) return;
4416 leency 366
			OpenPage();
4413 leency 367
			return;
368
		case FORWARD:
369
			if (!BrowserHistory.GoForward()) return;
4416 leency 370
			OpenPage();
4413 leency 371
			return;
372
		case 052:  //F3
4636 leency 373
			if (strncmp(#URL,"http:",5)==0)
374
			{
375
				WriteFile(bufsize, bufpointer, "/tmp0/1/webview.tmp");
376
				if (EAX==0) RunProgram("/rd/1/tinypad", "/tmp0/1/webview.tmp");
377
			}
378
			else
379
			{
380
				RunProgram("/rd/1/tinypad", #URL);
381
			}
4413 leency 382
			return;
383
		case 054: //F5
4636 leency 384
			IF(address_box.flags & 0b10) WB1.Parse();
4415 leency 385
			return;
386
 
4413 leency 387
		case REFRESH:
4643 leency 388
			if (http_transfer > 0)
389
			{
390
				StopLoading();
391
				Draw_Window();
392
			}
4636 leency 393
			else OpenPage();
4413 leency 394
			return;
4415 leency 395
		case 014:
396
		case 020:
4413 leency 397
		case NEWTAB:
398
			MoveSize(190,80,OLD,OLD);
399
			RunProgram(#program_path, #URL);
400
			return;
401
 
402
		case HOME:
4571 hidnplayr 403
			strcpy(#editURL, "http://kolibrios.org/");
4413 leency 404
		case GOTOURL:
405
		case 0x0D: //enter
406
			if ((strstr(#editURL,"ttp://")==0) && (editURL[0]!='/')) strcpy(#URL,"http://"); else URL[0] = 0;
407
			strcat(#URL, #editURL);
4416 leency 408
			OpenPage();
4413 leency 409
			return;
410
		case SEARCHWEB:
411
			strcpy(#URL, #search_path);
412
			strcat(#URL, #editURL);
4416 leency 413
			OpenPage();
4413 leency 414
			return;
415
 
416
		case 183: //PgDown
4415 leency 417
			if (WB1.list.count < WB1.list.visible) return;
418
			IF(WB1.list.first == WB1.list.count - WB1.list.visible) return;
419
			WB1.list.first += WB1.list.visible + 2;
420
			IF(WB1.list.visible + WB1.list.first > WB1.list.count) WB1.list.first = WB1.list.count - WB1.list.visible;
4636 leency 421
			WB1.Parse();
4415 leency 422
			return;
423
 
4413 leency 424
		case 184: //PgUp
4415 leency 425
			if (WB1.list.count < WB1.list.visible) return;
426
			IF(WB1.list.first == 0) return;
427
			WB1.list.first -= WB1.list.visible - 2;
428
			IF(WB1.list.first < 0) WB1.list.first = 0;
4636 leency 429
			WB1.Parse();
4415 leency 430
			return;
431
 
432
		case 178:
4544 leency 433
		case BTN_UP:
4416 leency 434
			if (WB1.list.first <= 0) return;
4415 leency 435
			WB1.list.first--;
4636 leency 436
			WB1.Parse();
4415 leency 437
			return;
438
 
439
		case 177:
4544 leency 440
		case BTN_DOWN:
4416 leency 441
			if (WB1.list.visible + WB1.list.first >= WB1.list.count) return;
4415 leency 442
			WB1.list.first++;
4636 leency 443
			WB1.Parse();
4415 leency 444
			return;
445
 
4413 leency 446
		case 180: //home
4636 leency 447
			if (WB1.list.KeyHome()) WB1.Parse();
4415 leency 448
			return;
449
 
4413 leency 450
		case 181: //end
4415 leency 451
			if (WB1.list.count < WB1.list.visible) return;
4636 leency 452
			if (WB1.list.KeyEnd()) WB1.Parse();
4413 leency 453
			return;
4677 leency 454
		case 312:
455
			SwitchToAnotherThread();
456
			m.y = TOOLBAR_H-6;
457
			m.x = Form.cwidth - 167;
458
			CreateThread(#menu_rmb,#stak+4092);
4413 leency 459
	}
460
}
461
 
462
 
463
 
4415 leency 464
void ProcessLinks(int id)
465
{
4544 leency 466
	strcpy(#URL, PageLinks.GetURL(id-401));
4417 leency 467
	//$1 - Condition Script
468
	if (URL[0] == '$')
469
	{
470
		if (URL[1]=='-') && (condition_href) condition_href--;
471
		if (URL[1]=='+')
472
		{
473
			if (condition_href
474
		}
475
		if (URL[1]!='-') && (URL[1]!='+') condition_href = atoi(#URL+1);
476
		strcpy(#URL, BrowserHistory.CurrentUrl());
4508 leency 477
		ShowPage();
4417 leency 478
		return;
479
	}
4415 leency 480
	//#1
481
	if (URL[0] == '#')
482
	{
4417 leency 483
		strcpy(#anchor, #URL+strrchr(#URL, '#'));
4415 leency 484
		strcpy(#URL, BrowserHistory.CurrentUrl());
485
		WB1.list.first=WB1.list.count-WB1.list.visible;
4508 leency 486
		ShowPage();
4415 leency 487
		return;
488
	}
489
	//liner.ru#1
4417 leency 490
	if (strrchr(#URL, '#')!=-1)
4415 leency 491
	{
492
		strcpy(#anchor, #URL+strrchr(#URL, '#'));
4416 leency 493
		URL[strrchr(#URL, '#')-1] = 0x00;
4415 leency 494
	}
495
 
4686 leency 496
	PageLinks.GetAbsoluteURL(#URL);
4415 leency 497
 
498
	if (!strcmp(#URL + strlen(#URL) - 4, ".gif")) || (!strcmp(#URL + strlen(#URL) - 4, ".png")) || (!strcmp(#URL + strlen(#URL) - 4, ".jpg"))
499
	{
500
		//if (strstr(#URL,"http:"))
501
		RunProgram("/sys/media/kiv", #URL);
502
		strcpy(#editURL, BrowserHistory.CurrentUrl());
503
		strcpy(#URL, BrowserHistory.CurrentUrl());
504
		return;
505
	}
506
	if (!strcmpn(#URL,"mailto:", 7))
507
	{
508
		notify(#URL);
509
		strcpy(#editURL, BrowserHistory.CurrentUrl());
510
		strcpy(#URL, BrowserHistory.CurrentUrl());
511
		return;
512
	}
4416 leency 513
	OpenPage();
4415 leency 514
	return;
515
}
516
 
4636 leency 517
void StopLoading()
518
{
4647 leency 519
	if (http_transfer<>0)
520
	{
521
		EAX = http_transfer;
522
		EAX = EAX.http_msg.content_ptr;		// get pointer to data
523
		$push	EAX							// save it on the stack
524
		http_free stdcall (http_transfer);	// abort connection
525
		$pop	EAX
526
		mem_Free(EAX);						// free data
527
		http_transfer=0;
528
		bufsize = 0;
4650 leency 529
		bufpointer = mem_Free(bufpointer);
4647 leency 530
	}
4677 leency 531
	progress_bar.value = 0;
532
	img_draw stdcall(skin.image, address_box.left+address_box.width+1, address_box.top-2, 17, skin.h, 52, 0);
4645 leency 533
}
534
 
535
void SetPageDefaults()
536
{
537
	strcpy(#header, #version);
538
	pre_text = 0;
539
	WB1.list.count = WB1.list.first = 0;
540
	stroka = 0;
541
	cur_encoding = _DEFAULT;
542
	if (o_bufpointer) o_bufpointer = free(o_bufpointer);
4636 leency 543
	anchor_line_num=WB1.list.first;
544
	anchor[0]='|';
545
}
546
 
4416 leency 547
void OpenPage()
548
{
4636 leency 549
	StopLoading();
4416 leency 550
	strcpy(#editURL, #URL);
4677 leency 551
	if (strncmp(#URL,"WebView:",8)==0) return;
4636 leency 552
	if (strncmp(#URL,"http:",5)==0)
4416 leency 553
	{
4677 leency 554
		img_draw stdcall(skin.image, address_box.left+address_box.width+1, address_box.top-2, 17, skin.h, 131, 0);
4636 leency 555
		http_get stdcall (#URL, #accept_language);
556
		http_transfer = EAX;
4646 leency 557
		if (http_transfer == 0)
558
		{
559
			StopLoading();
560
			bufsize = 0;
4650 leency 561
			bufpointer = mem_Free(bufpointer);
4646 leency 562
			ShowPage();
563
			return;
564
		}
4416 leency 565
	}
4636 leency 566
	else
567
	{
4686 leency 568
		BrowserHistory.AddUrl();
4636 leency 569
		file_size stdcall (#URL);
570
		bufsize = EBX;
4650 leency 571
		if (bufsize)
572
		{
573
			bufpointer = mem_Free(bufpointer);
574
			bufpointer = mem_Alloc(bufsize);
575
			SetPageDefaults();
576
			ReadFile(0, bufsize, bufpointer, #URL);
577
		}
4645 leency 578
		ShowPage();
4636 leency 579
	}
4416 leency 580
}
4415 leency 581
 
4508 leency 582
void ShowPage()
583
{
584
	address_box.size = address_box.pos = strlen(#editURL);
585
	address_box.offset=0;
586
	edit_box_draw stdcall(#address_box);
4415 leency 587
 
4677 leency 588
	if (strcmp(#URL, URL_SERVICE_HOME)==0) WB1.Prepare(#homepage, sizeof(homepage)); else
589
	if (strcmp(#URL, URL_SERVICE_HISTORY)==0) ShowHistory(); else
4540 leency 590
	if (!bufsize)
4508 leency 591
	{
592
		PageLinks.Clear();
4636 leency 593
		if (http_transfer<>0)
594
		{
595
			WB1.Prepare(#loading, sizeof(loading));
596
		}
4508 leency 597
		else
4636 leency 598
			WB1.Prepare(#page_not_found, sizeof(page_not_found));
4508 leency 599
	}
600
	else
4636 leency 601
		WB1.Parse();
4415 leency 602
 
4508 leency 603
	if (!header) strcpy(#header, #version);
604
	if (!strcmp(#version, #header)) DrawTitle(#header);
605
}
606
 
607
 
4544 leency 608
 
4636 leency 609
 
3067 leency 610
stop: