Subversion Repositories Kolibri OS

Rev

Rev 4688 | Rev 4693 | 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
4692 leency 32
	char version[]=" Текстовый браузер 1.0 Beta 3";
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
4692 leency 39
	char version[]=" Text-based Browser 1.0 Beta 3";
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
 
4692 leency 62
dword TAB_H = false; //19;
4677 leency 63
dword TAB_W = 150;
4692 leency 64
dword TOOLBAR_H = 31; //50;
65
dword STATUSBAR_H =16;
4677 leency 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);
4687 leency 246
							BrowserHistory.current--;
4558 hidnplayr 247
							strcpy(#editURL, #URL);
248
							OpenPage();
4563 leency 249
						}
250
						else
251
						{
4686 leency 252
							BrowserHistory.AddUrl();
4643 leency 253
							ESI = http_transfer;
254
							bufpointer = ESI.http_msg.content_ptr;
255
							bufsize = ESI.http_msg.content_received;
256
							http_free stdcall (http_transfer);
257
							http_transfer=0;
4645 leency 258
							SetPageDefaults();
4558 hidnplayr 259
							Draw_Window();		// stop button => refresh button
260
						}
4536 leency 261
					}
262
				}
3067 leency 263
		}
264
	}
265
}
266
 
267
void SetElementSizes()
268
{
4677 leency 269
	address_box.top = TOOLBAR_H-TAB_H/2-7+TAB_H;
270
	address_box.width = Form.cwidth - address_box.left - 25 - 22;
271
	WB1.list.SetSizes(0, TOOLBAR_H, Form.width - 10 - scroll_wv.size_x, Form.cheight - TOOLBAR_H - STATUSBAR_H, 0, 10);
4651 leency 272
	WB1.list.column_max = WB1.list.w - scroll_wv.size_x / 6;
4692 leency 273
	WB1.list.visible = WB1.list.h - 5 / WB1.list.line_h;
4674 leency 274
	WB1.DrawBuf.Init(WB1.list.x, WB1.list.y, WB1.list.w, WB1.list.line_h);
3067 leency 275
}
276
 
277
void Draw_Window()
278
{
4677 leency 279
	int img_off;
280
	DefineAndDrawWindow(GetScreenWidth()-WIN_W/2,GetScreenHeight()-WIN_H/2,WIN_W,WIN_H,0x73,col_bg,0,0);
3067 leency 281
	GetProcessInfo(#Form, SelfInfo);
4677 leency 282
	if (Form.status_window>2) { DrawTitle(#header); return; }
3067 leency 283
	if (Form.height<120) MoveSize(OLD,OLD,OLD,120);
284
	if (Form.width<280) MoveSize(OLD,OLD,280,OLD);
4677 leency 285
	// tab {
4692 leency 286
	if (TAB_H)
287
	{
288
		DrawBar(0, 0, TAB_W, TAB_H+1, panel_color);
289
		WriteText(5, 7, 0x80, 0xfdfdFd, "Index.htm");
290
		WriteText(4, 6, 0x80, 0, "Index.htm");
291
		DrawBar(TAB_W,0, Form.cwidth-TAB_W,TAB_H, col_bg);
292
		DrawBar(TAB_W-1,TAB_H, Form.cwidth-TAB_W+1,1, border_color);
293
		img_draw stdcall(skin.image, TAB_W-13, 0, 30, skin.h, 101, 0);
294
	}
295
	else DrawBar(0,0, Form.cwidth,1, col_bg);
4677 leency 296
	// }
4686 leency 297
	DrawBar(0,TAB_H+1, Form.cwidth,TOOLBAR_H-TAB_H-3, panel_color);
298
	DrawBar(0,TOOLBAR_H-2, Form.cwidth,1, 0xe9e9e9);
4677 leency 299
	DrawBar(0,TOOLBAR_H-1, Form.cwidth,1, border_color);
3067 leency 300
	SetElementSizes();
4677 leency 301
	DrawRectangle(address_box.left-1, address_box.top-1, address_box.width+2, 16,address_box.color);
302
	DrawRectangle(address_box.left-2, address_box.top-2, address_box.width+4, 18,border_color);
303
	// < / >
304
	DefineButton(address_box.left-49, address_box.top-1, 23, skin.h-2, 300+BT_HIDE, 0);
305
	DefineButton(address_box.left-25, address_box.top-1, 23, skin.h-2, 301+BT_HIDE, 0);
306
	img_draw stdcall(skin.image, address_box.left-50, address_box.top-2, 48, skin.h, 3, 0);
307
	// refrash
308
	DefineButton(address_box.left+address_box.width+1, address_box.top-2, 16, skin.h-1, REFRESH+BT_HIDE+BT_NOFRAME, 0);
309
	if (http_transfer > 0) img_off = 131; else img_off = 52;
310
	img_draw stdcall(skin.image, address_box.left+address_box.width+1, address_box.top-2, 17, skin.h, img_off, 0);
311
	// config
312
	DefineButton(Form.cwidth-23, address_box.top-2, 17, skin.h-1, 312+BT_HIDE, 0);
4692 leency 313
	img_draw stdcall(skin.image, Form.cwidth-22, address_box.top-2, 16, skin.h, 85, 0);
4677 leency 314
	//status bar
315
	DrawBar(0,Form.cheight - STATUSBAR_H, Form.cwidth,STATUSBAR_H, col_bg);
316
	DrawBar(0,Form.cheight - STATUSBAR_H, Form.cwidth,1, border_color);
317
	progress_bar.top = Form.cheight - STATUSBAR_H + 4;
4686 leency 318
	DrawProgress();
4692 leency 319
	ShowPage();
320
	DrawRectangle(scroll_wv.start_x, scroll_wv.start_y, scroll_wv.size_x, scroll_wv.size_y-1, scroll_wv.bckg_col);
3067 leency 321
}
322
 
323
 
4636 leency 324
void ChangeCharset(byte new_charset)
325
{
326
	BufEncode(new_charset);
327
	WB1.Parse();
328
}
329
 
4413 leency 330
void Scan(int id)
331
{
4636 leency 332
	action_buf=0;
333
	if (id >= 400)
334
	{
335
		ProcessLinks(id);
336
		return;
337
	}
4413 leency 338
	switch (id)
339
	{
340
		case 011: //Ctrk+K
4636 leency 341
			ChangeCharset(_KOI);
4415 leency 342
			return;
343
 
4413 leency 344
		case 021: //Ctrl+U
4636 leency 345
			ChangeCharset(_UTF);
4415 leency 346
			return;
347
 
4413 leency 348
		case 004: //Ctrl+D
4636 leency 349
			ChangeCharset(_DOS);
4415 leency 350
			return;
351
 
4533 leency 352
		case 005: //Win encoding
4636 leency 353
			ChangeCharset(_WIN);
4533 leency 354
			return;
355
 
356
		case 009: //free img cache
4491 leency 357
			ImgCache.Free();
4416 leency 358
			notify(IMAGES_CACHE_CLEARED);
4636 leency 359
			WB1.Parse();
4415 leency 360
			return;
361
 
4546 leency 362
		case 003: //history
4677 leency 363
			strcpy(#URL, URL_SERVICE_HISTORY);
4544 leency 364
			OpenPage();
365
			return;
366
 
4413 leency 367
		case BACK:
368
			if (!BrowserHistory.GoBack()) return;
4416 leency 369
			OpenPage();
4413 leency 370
			return;
371
		case FORWARD:
372
			if (!BrowserHistory.GoForward()) return;
4416 leency 373
			OpenPage();
4413 leency 374
			return;
375
		case 052:  //F3
4636 leency 376
			if (strncmp(#URL,"http:",5)==0)
377
			{
378
				WriteFile(bufsize, bufpointer, "/tmp0/1/webview.tmp");
379
				if (EAX==0) RunProgram("/rd/1/tinypad", "/tmp0/1/webview.tmp");
380
			}
381
			else
382
			{
383
				RunProgram("/rd/1/tinypad", #URL);
384
			}
4413 leency 385
			return;
386
		case 054: //F5
4688 leency 387
			IF(address_box.flags & 0b10) return;
4413 leency 388
		case REFRESH:
4643 leency 389
			if (http_transfer > 0)
390
			{
391
				StopLoading();
392
				Draw_Window();
393
			}
4636 leency 394
			else OpenPage();
4413 leency 395
			return;
4415 leency 396
		case 014:
397
		case 020:
4413 leency 398
		case NEWTAB:
399
			MoveSize(190,80,OLD,OLD);
400
			RunProgram(#program_path, #URL);
401
			return;
402
 
403
		case HOME:
4571 hidnplayr 404
			strcpy(#editURL, "http://kolibrios.org/");
4413 leency 405
		case GOTOURL:
406
		case 0x0D: //enter
4692 leency 407
			if ((strncmp(#editURL,"http:",5)!=0) && (editURL[0]!='/') && ((strncmp(#editURL,"WebView:",8)!=0))
408
			{
409
				strcpy(#URL,"http://");
410
			}
411
			else
412
				URL[0] = 0;
4413 leency 413
			strcat(#URL, #editURL);
4416 leency 414
			OpenPage();
4413 leency 415
			return;
416
		case SEARCHWEB:
417
			strcpy(#URL, #search_path);
418
			strcat(#URL, #editURL);
4416 leency 419
			OpenPage();
4413 leency 420
			return;
421
 
422
		case 183: //PgDown
4415 leency 423
			if (WB1.list.count < WB1.list.visible) return;
424
			IF(WB1.list.first == WB1.list.count - WB1.list.visible) return;
425
			WB1.list.first += WB1.list.visible + 2;
426
			IF(WB1.list.visible + WB1.list.first > WB1.list.count) WB1.list.first = WB1.list.count - WB1.list.visible;
4636 leency 427
			WB1.Parse();
4415 leency 428
			return;
429
 
4413 leency 430
		case 184: //PgUp
4415 leency 431
			if (WB1.list.count < WB1.list.visible) return;
432
			IF(WB1.list.first == 0) return;
433
			WB1.list.first -= WB1.list.visible - 2;
434
			IF(WB1.list.first < 0) WB1.list.first = 0;
4636 leency 435
			WB1.Parse();
4415 leency 436
			return;
437
 
438
		case 178:
4544 leency 439
		case BTN_UP:
4416 leency 440
			if (WB1.list.first <= 0) return;
4415 leency 441
			WB1.list.first--;
4636 leency 442
			WB1.Parse();
4415 leency 443
			return;
444
 
445
		case 177:
4544 leency 446
		case BTN_DOWN:
4416 leency 447
			if (WB1.list.visible + WB1.list.first >= WB1.list.count) return;
4415 leency 448
			WB1.list.first++;
4636 leency 449
			WB1.Parse();
4415 leency 450
			return;
451
 
4413 leency 452
		case 180: //home
4636 leency 453
			if (WB1.list.KeyHome()) WB1.Parse();
4415 leency 454
			return;
455
 
4413 leency 456
		case 181: //end
4415 leency 457
			if (WB1.list.count < WB1.list.visible) return;
4636 leency 458
			if (WB1.list.KeyEnd()) WB1.Parse();
4413 leency 459
			return;
4677 leency 460
		case 312:
461
			SwitchToAnotherThread();
462
			m.y = TOOLBAR_H-6;
463
			m.x = Form.cwidth - 167;
464
			CreateThread(#menu_rmb,#stak+4092);
4413 leency 465
	}
466
}
467
 
468
 
469
 
4415 leency 470
void ProcessLinks(int id)
471
{
4687 leency 472
	if (http_transfer > 0)
473
	{
474
		StopLoading();
475
		BrowserHistory.current--;
476
	}
477
 
4544 leency 478
	strcpy(#URL, PageLinks.GetURL(id-401));
4417 leency 479
	//$1 - Condition Script
480
	if (URL[0] == '$')
481
	{
482
		if (URL[1]=='-') && (condition_href) condition_href--;
483
		if (URL[1]=='+')
484
		{
485
			if (condition_href
486
		}
487
		if (URL[1]!='-') && (URL[1]!='+') condition_href = atoi(#URL+1);
488
		strcpy(#URL, BrowserHistory.CurrentUrl());
4508 leency 489
		ShowPage();
4417 leency 490
		return;
491
	}
4415 leency 492
	//#1
493
	if (URL[0] == '#')
494
	{
4417 leency 495
		strcpy(#anchor, #URL+strrchr(#URL, '#'));
4415 leency 496
		strcpy(#URL, BrowserHistory.CurrentUrl());
497
		WB1.list.first=WB1.list.count-WB1.list.visible;
4508 leency 498
		ShowPage();
4415 leency 499
		return;
500
	}
501
	//liner.ru#1
4417 leency 502
	if (strrchr(#URL, '#')!=-1)
4415 leency 503
	{
504
		strcpy(#anchor, #URL+strrchr(#URL, '#'));
4416 leency 505
		URL[strrchr(#URL, '#')-1] = 0x00;
4415 leency 506
	}
507
 
4686 leency 508
	PageLinks.GetAbsoluteURL(#URL);
4415 leency 509
 
510
	if (!strcmp(#URL + strlen(#URL) - 4, ".gif")) || (!strcmp(#URL + strlen(#URL) - 4, ".png")) || (!strcmp(#URL + strlen(#URL) - 4, ".jpg"))
511
	{
512
		//if (strstr(#URL,"http:"))
513
		RunProgram("/sys/media/kiv", #URL);
514
		strcpy(#editURL, BrowserHistory.CurrentUrl());
515
		strcpy(#URL, BrowserHistory.CurrentUrl());
516
		return;
517
	}
518
	if (!strcmpn(#URL,"mailto:", 7))
519
	{
520
		notify(#URL);
521
		strcpy(#editURL, BrowserHistory.CurrentUrl());
522
		strcpy(#URL, BrowserHistory.CurrentUrl());
523
		return;
524
	}
4416 leency 525
	OpenPage();
4415 leency 526
	return;
527
}
528
 
4636 leency 529
void StopLoading()
530
{
4647 leency 531
	if (http_transfer<>0)
532
	{
533
		EAX = http_transfer;
534
		EAX = EAX.http_msg.content_ptr;		// get pointer to data
535
		$push	EAX							// save it on the stack
536
		http_free stdcall (http_transfer);	// abort connection
537
		$pop	EAX
538
		mem_Free(EAX);						// free data
539
		http_transfer=0;
540
		bufsize = 0;
4650 leency 541
		bufpointer = mem_Free(bufpointer);
4647 leency 542
	}
4677 leency 543
	progress_bar.value = 0;
544
	img_draw stdcall(skin.image, address_box.left+address_box.width+1, address_box.top-2, 17, skin.h, 52, 0);
4645 leency 545
}
546
 
547
void SetPageDefaults()
548
{
549
	strcpy(#header, #version);
550
	pre_text = 0;
551
	WB1.list.count = WB1.list.first = 0;
552
	stroka = 0;
553
	cur_encoding = _DEFAULT;
554
	if (o_bufpointer) o_bufpointer = free(o_bufpointer);
4636 leency 555
	anchor_line_num=WB1.list.first;
556
	anchor[0]='|';
557
}
558
 
4416 leency 559
void OpenPage()
560
{
4636 leency 561
	StopLoading();
4416 leency 562
	strcpy(#editURL, #URL);
4687 leency 563
	BrowserHistory.AddUrl();
4692 leency 564
	if (strncmp(#URL,"WebView:",8)==0)
565
	{
566
		SetPageDefaults();
567
		if (strcmp(#URL, URL_SERVICE_HOME)==0)
568
		{
569
			WB1.Prepare(#homepage, sizeof(homepage));
570
		}
571
		if (strcmp(#URL, URL_SERVICE_HISTORY)==0)
572
		{
573
			ShowHistory();
574
		}
575
		return;
576
	}
4636 leency 577
	if (strncmp(#URL,"http:",5)==0)
4416 leency 578
	{
4677 leency 579
		img_draw stdcall(skin.image, address_box.left+address_box.width+1, address_box.top-2, 17, skin.h, 131, 0);
4636 leency 580
		http_get stdcall (#URL, #accept_language);
581
		http_transfer = EAX;
4646 leency 582
		if (http_transfer == 0)
583
		{
584
			StopLoading();
585
			bufsize = 0;
4650 leency 586
			bufpointer = mem_Free(bufpointer);
4646 leency 587
			ShowPage();
588
			return;
589
		}
4416 leency 590
	}
4636 leency 591
	else
592
	{
593
		file_size stdcall (#URL);
594
		bufsize = EBX;
4650 leency 595
		if (bufsize)
596
		{
597
			bufpointer = mem_Free(bufpointer);
598
			bufpointer = mem_Alloc(bufsize);
599
			SetPageDefaults();
600
			ReadFile(0, bufsize, bufpointer, #URL);
601
		}
4645 leency 602
		ShowPage();
4636 leency 603
	}
4416 leency 604
}
4415 leency 605
 
4508 leency 606
void ShowPage()
607
{
608
	address_box.size = address_box.pos = strlen(#editURL);
609
	address_box.offset=0;
610
	edit_box_draw stdcall(#address_box);
4415 leency 611
 
4540 leency 612
	if (!bufsize)
4508 leency 613
	{
614
		PageLinks.Clear();
4636 leency 615
		if (http_transfer<>0)
616
		{
617
			WB1.Prepare(#loading, sizeof(loading));
618
		}
4508 leency 619
		else
4636 leency 620
			WB1.Prepare(#page_not_found, sizeof(page_not_found));
4508 leency 621
	}
622
	else
4636 leency 623
		WB1.Parse();
4415 leency 624
 
4508 leency 625
	if (!header) strcpy(#header, #version);
626
	if (!strcmp(#version, #header)) DrawTitle(#header);
627
}
628
 
629
 
4544 leency 630
 
4636 leency 631
 
3067 leency 632
stop: