Subversion Repositories Kolibri OS

Rev

Rev 4540 | Rev 4546 | 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"
3107 leency 28
//images
3067 leency 29
#include "img\toolbar_icons.c"
30
#include "img\URLgoto.txt";
31
 
4026 leency 32
#ifdef LANG_RUS
4544 leency 33
	char version[]=" Текстовый браузер 0.99.66";
4416 leency 34
	?define IMAGES_CACHE_CLEARED "Кэш картинок очищен"
4417 leency 35
	?define T_LAST_SLIDE "Это последний слайд"
4544 leency 36
	char loading[] = "Загрузка страницы...";
37
	unsigned char page_not_found[] = FROM "html\page_not_found_ru.htm";
4026 leency 38
#else
4544 leency 39
	char version[]=" Text-based Browser 0.99.66";
4026 leency 40
	?define IMAGES_CACHE_CLEARED "Images cache cleared"
4417 leency 41
	?define T_LAST_SLIDE "This slide is the last"
4534 leency 42
	char loading[] = "Loading...";
4544 leency 43
	unsigned char page_not_found[] = FROM "html\page_not_found_en.htm";
4026 leency 44
#endif
45
 
3067 leency 46
proc_info Form;
47
#define WIN_W 640
48
#define WIN_H 480
49
 
4416 leency 50
char search_path[]="http://nigma.ru/index.php?s=";
3067 leency 51
 
4074 leency 52
char stak[4096];
3067 leency 53
mouse m;
4026 leency 54
int action_buf;
55
 
4537 leency 56
dword http_transfer = 0;
57
dword http_buffer;
4534 leency 58
 
4540 leency 59
int	downloader_id;
60
 
4411 leency 61
#include "..\TWB\TWB.c"
62
#include "menu_rmb.h"
3067 leency 63
 
4534 leency 64
char editURL[sizeof(URL)];
65
int	mouse_twb;
66
edit_box address_box= {250,207,16,0xffffff,0x94AECE,0xffffff,0xffffff,0,sizeof(URL),#editURL,#mouse_twb,2,19,19};
67
 
4544 leency 68
#define URL_HISTORY "WebView://history"
4534 leency 69
 
4488 leency 70
enum { BACK=300, FORWARD, REFRESH, HOME, NEWTAB, GOTOURL, SEARCHWEB, INPUT_CH, INPUT_BT, BTN_UP, BTN_DOWN };
3067 leency 71
 
4488 leency 72
 
3067 leency 73
void main()
74
{
4081 leency 75
	int key, btn;
3067 leency 76
	int half_scroll_size;
4026 leency 77
	int scroll_used=0, show_menu;
3067 leency 78
 
79
	mem_Init();
4536 leency 80
	CursorPointer.Load(#CursorFile);
3107 leency 81
	if (load_dll2(boxlib, #box_lib_init,0)!=0) {notify("System Error: library doesn't exists /rd/1/lib/box_lib.obj"); ExitProcess();}
4536 leency 82
	if (load_dll2(libio, #libio_init,1)!=0) notify("Error: library doesn't exists - libio");
83
	if (load_dll2(libimg, #libimg_init,1)!=0) notify("Error: library doesn't exists - libimg");
4540 leency 84
	if (load_dll2(libHTTP, #http_lib_init,1)!=0) notify("Error: library doesn't exists - http");
3067 leency 85
 
4536 leency 86
	if (!URL) strcpy(#URL, "/sys/index.htm");
3067 leency 87
	Form.width=WIN_W;
88
	Form.height=WIN_H;
89
	SetElementSizes();
4416 leency 90
	OpenPage();
3067 leency 91
 
4536 leency 92
	SetEventMask(0xa7);
3067 leency 93
	loop()
94
	{
95
		WaitEventTimeout(2);
96
		switch(EAX & 0xFF)
97
		{
98
			CASE evMouse:
4081 leency 99
				if (!CheckActiveProcess(Form.ID)) break;
3067 leency 100
 
3466 leency 101
				edit_box_mouse stdcall (#address_box);
3067 leency 102
 
103
				m.get();
4492 leency 104
				PageLinks.Hover(m.x, m.y, link_color_inactive, link_color_active, bg_color);
3067 leency 105
 
4540 leency 106
				if (m.y>WB1.list.y) && (m.y
3067 leency 107
				{
4026 leency 108
					if (m.pkm)
109
					{
110
						show_menu = 1;
111
					}
112
					if (!m.pkm) && (show_menu)
113
					{
114
						show_menu = 0;
115
						SwitchToAnotherThread();
4074 leency 116
						CreateThread(#menu_rmb,#stak+4092);
4026 leency 117
						break;
118
					}
3067 leency 119
				}
120
 
4415 leency 121
				if (m.vert)
3067 leency 122
				{
4540 leency 123
					if (WB1.list.MouseScroll(m.vert)) WB1.ParseHTML(bufpointer);
3067 leency 124
				}
125
 
126
				if (!m.lkm) scroll_used=0;
4416 leency 127
				if (m.x>=scroll_wv.start_x) && (m.x<=scroll_wv.start_x+scroll_wv.size_x)
128
				&& (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 129
				&& (WB1.list.count>WB1.list.visible) && (m.lkm)
4026 leency 130
				{
131
					scroll_used=1;
132
				}
3067 leency 133
 
134
				if (scroll_used)
135
				{
4415 leency 136
					half_scroll_size = WB1.list.h - 16 * WB1.list.visible / WB1.list.count - 3 /2;
4416 leency 137
					if (half_scroll_size+WB1.list.y>m.y) || (m.y<0) || (m.y>4000) m.y=half_scroll_size+WB1.list.y;
138
					btn=WB1.list.first;
4415 leency 139
					WB1.list.first = m.y -half_scroll_size -WB1.list.y * WB1.list.count / WB1.list.h;
140
					if (WB1.list.visible+WB1.list.first>WB1.list.count) WB1.list.first=WB1.list.count-WB1.list.visible;
4540 leency 141
					if (btn<>WB1.list.first) WB1.ParseHTML(bufpointer);
3067 leency 142
				}
143
 
144
				break;
145
			case evButton:
146
				btn=GetButtonID();
3464 leency 147
				if (btn==1)
3067 leency 148
				{
149
					KillProcess(downloader_id);
150
					ExitProcess();
151
				}
152
				ELSE
153
				{
4413 leency 154
					Scan(btn);
3067 leency 155
				}
156
				break;
157
			case evKey:
158
				key = GetKey();
159
 
4416 leency 160
				if (address_box.flags & 0b10) SWITCH(key)
3067 leency 161
					{ CASE 52: CASE 53: CASE 54: goto _EDIT_MARK; }
162
 
4413 leency 163
				Scan(key);
3067 leency 164
 
165
				_EDIT_MARK:
4416 leency 166
				if (key<>0x0d) && (key<>183) && (key<>184) {EAX=key<<8; edit_box_key stdcall(#address_box);}
3067 leency 167
				break;
168
			case evReDraw:
4413 leency 169
				if (action_buf) { Scan(action_buf); action_buf=0;}
3067 leency 170
				Draw_Window();
171
				break;
4540 leency 172
 
4536 leency 173
			case evNetwork:
174
				return;
4540 leency 175
				http_get stdcall (#search_path, 0);
4536 leency 176
				http_transfer = EAX;
4540 leency 177
				IF (http_transfer < 0) notify("Error from HTTP lib");
178
 
179
				if (http_transfer > 0) {
4536 leency 180
					http_process stdcall (http_transfer);
181
					$push EAX
182
					ESI = http_transfer;
4540 leency 183
					bufpointer = ESI.http_msg.content_ptr;
184
					debug(bufpointer);
185
					//bufsize = ESI.http_msg.content_received;
186
					bufsize = strlen(bufpointer)-2;
187
					debugi(bufsize);
188
					WB1.ParseHTML(bufpointer);
4536 leency 189
					$pop EAX
190
					if (EAX == 0) {
191
						http_free stdcall (http_transfer);
192
						http_transfer=0;
193
					}
4540 leency 194
					pause(10);
4536 leency 195
				}
3067 leency 196
			default:
197
				if (downloader_id<>0)
198
				{
199
					if (GetProcessSlot(downloader_id)<>0) break;
200
					downloader_id=0;
4415 leency 201
					WB1.list.first = WB1.list.count = 0;
3067 leency 202
					WB1.ReadHtml(_WIN);
203
					Draw_Window();
204
				}
205
		}
206
	}
207
}
208
 
209
void SetElementSizes()
210
{
4416 leency 211
	address_box.width = Form.width - 266;
212
	WB1.list.SetSizes(0, 44, Form.width - 10 - scroll_wv.size_x, Form.cheight - 44, 0, 10);
4415 leency 213
	WB1.list.column_max = WB1.list.w - 30 / 6;
214
	WB1.list.visible = WB1.list.h - 3 / WB1.list.line_h - 2;
4475 leency 215
	WB1.DrawBuf.Init(WB1.list.x, WB1.list.y, WB1.list.w, WB1.list.h, WB1.list.line_h);
3067 leency 216
}
217
 
218
 
219
void Draw_Window()
220
{
221
	int j;
3466 leency 222
	DefineAndDrawWindow(215,100,WIN_W,WIN_H,0x73,0xE4DFE1,0,0);
3067 leency 223
 
224
	GetProcessInfo(#Form, SelfInfo);
3464 leency 225
	if (Form.status_window>2)
3067 leency 226
	{
227
		DrawTitle(#header);
228
		return;
229
	}
230
	if (Form.height<120) MoveSize(OLD,OLD,OLD,120);
231
	if (Form.width<280) MoveSize(OLD,OLD,280,OLD);
232
 
233
	PutPaletteImage(#toolbar,200,42,0,0,8,#toolbar_pal);
3363 leency 234
	if (GetProcessSlot(downloader_id)<>0) _PutImage(88,10, 24,24, #stop_btn);
3067 leency 235
 
3464 leency 236
	DrawBar(200,0,Form.cwidth-200,43,0xE4DFE1);
237
	DrawBar(0,42,Form.cwidth,1,0xE2DBDC);
238
	DrawBar(0,43,Form.cwidth,1,0xD2CED0);
3067 leency 239
	for (j=0; j<5; j++) DefineButton(j*37+11, 7, 29, 29, 300+j+BT_HIDE, 0xE4DFE1);
3464 leency 240
	_PutImage(Form.cwidth-48,14, 40,19, #URLgoto);
241
	DefineButton(Form.cwidth-28,15, 18, 16, GOTOURL+BT_HIDE, 0xE4DFE1);
242
	DefineButton(Form.cwidth-47,15, 17, 16, SEARCHWEB+BT_HIDE, 0xE4DFE1);
243
	DrawRectangle(205,14,Form.cwidth-205-49,18,0x94AECE); //around adress bar
244
	DrawRectangle(206,15,Form.cwidth-205-50,16,0xE4ECF3);
3067 leency 245
 
246
	SetElementSizes();
4508 leency 247
	ShowPage();
3464 leency 248
 
4416 leency 249
	DefineButton(scroll_wv.start_x+1, scroll_wv.start_y+1, 16, 16, BTN_UP+BT_HIDE, 0xE4DFE1);
250
	DefineButton(scroll_wv.start_x+1, scroll_wv.start_y+scroll_wv.size_y-18, 16, 16, BTN_DOWN+BT_HIDE, 0xE4DFE1);
3067 leency 251
}
252
 
253
 
4413 leency 254
void Scan(int id)
255
{
4415 leency 256
	if (id >= 400) ProcessLinks(id);
4413 leency 257
 
258
	switch (id)
259
	{
260
		case 011: //Ctrk+K
261
			WB1.ReadHtml(_KOI);
4540 leency 262
			WB1.ParseHTML(bufpointer);
4415 leency 263
			return;
264
 
4413 leency 265
		case 021: //Ctrl+U
266
			WB1.ReadHtml(_UTF);
4540 leency 267
			WB1.ParseHTML(bufpointer);
4415 leency 268
			return;
269
 
4413 leency 270
		case 004: //Ctrl+D
271
			WB1.ReadHtml(_DOS);
4540 leency 272
			WB1.ParseHTML(bufpointer);
4415 leency 273
			return;
274
 
4533 leency 275
		case 005: //Win encoding
276
			WB1.ReadHtml(_WIN);
4540 leency 277
			WB1.ParseHTML(bufpointer);
4533 leency 278
			return;
279
 
280
		case 009: //free img cache
4491 leency 281
			ImgCache.Free();
4416 leency 282
			notify(IMAGES_CACHE_CLEARED);
4540 leency 283
			WB1.ParseHTML(bufpointer);
4415 leency 284
			return;
285
 
4544 leency 286
		case 008: //history
287
			strcpy(#URL, URL_HISTORY);
288
			OpenPage();
289
			return;
290
 
4413 leency 291
		case BACK:
292
			if (!BrowserHistory.GoBack()) return;
4416 leency 293
			OpenPage();
4413 leency 294
			return;
295
		case FORWARD:
296
			if (!BrowserHistory.GoForward()) return;
4416 leency 297
			OpenPage();
4413 leency 298
			return;
299
		case 052:  //F3
4488 leency 300
			if (strncmp(#URL,"http:",5)<>0) RunProgram("/rd/1/tinypad", #URL);
4415 leency 301
			else RunProgram("/rd/1/tinypad", #download_path);
4413 leency 302
			return;
303
		case 054: //F5
4540 leency 304
			IF(address_box.flags & 0b10) WB1.ParseHTML(bufpointer);
4415 leency 305
			return;
306
 
4413 leency 307
		case REFRESH:
308
			if (GetProcessSlot(downloader_id)<>0)
309
			{
310
				KillProcess(downloader_id);
311
				pause(20);
312
				Draw_Window();
313
				return;
314
			}
4415 leency 315
			anchor_line_num=WB1.list.first;
4413 leency 316
			anchor[0]='|';
4416 leency 317
			OpenPage();
4413 leency 318
			return;
4415 leency 319
		case 014:
320
		case 020:
4413 leency 321
		case NEWTAB:
322
			MoveSize(190,80,OLD,OLD);
323
			RunProgram(#program_path, #URL);
324
			return;
325
 
326
		case HOME:
327
			strcpy(#editURL, "http://kolibrios.org/en/index.htm");
328
		case GOTOURL:
329
		case 0x0D: //enter
330
			if ((strstr(#editURL,"ttp://")==0) && (editURL[0]!='/')) strcpy(#URL,"http://"); else URL[0] = 0;
331
			strcat(#URL, #editURL);
4416 leency 332
			OpenPage();
4413 leency 333
			return;
334
		case SEARCHWEB:
335
			strcpy(#URL, #search_path);
336
			strcat(#URL, #editURL);
4416 leency 337
			OpenPage();
4413 leency 338
			return;
339
 
340
		case 183: //PgDown
4415 leency 341
			if (WB1.list.count < WB1.list.visible) return;
342
			IF(WB1.list.first == WB1.list.count - WB1.list.visible) return;
343
			WB1.list.first += WB1.list.visible + 2;
344
			IF(WB1.list.visible + WB1.list.first > WB1.list.count) WB1.list.first = WB1.list.count - WB1.list.visible;
4540 leency 345
			WB1.ParseHTML(bufpointer);
4415 leency 346
			return;
347
 
4413 leency 348
		case 184: //PgUp
4415 leency 349
			if (WB1.list.count < WB1.list.visible) return;
350
			IF(WB1.list.first == 0) return;
351
			WB1.list.first -= WB1.list.visible - 2;
352
			IF(WB1.list.first < 0) WB1.list.first = 0;
4540 leency 353
			WB1.ParseHTML(bufpointer);
4415 leency 354
			return;
355
 
356
		case 178:
4544 leency 357
		case BTN_UP:
4416 leency 358
			if (WB1.list.first <= 0) return;
4415 leency 359
			WB1.list.first--;
4540 leency 360
			WB1.ParseHTML(bufpointer);
4415 leency 361
			return;
362
 
363
		case 177:
4544 leency 364
		case BTN_DOWN:
4416 leency 365
			if (WB1.list.visible + WB1.list.first >= WB1.list.count) return;
4415 leency 366
			WB1.list.first++;
4540 leency 367
			WB1.ParseHTML(bufpointer);
4415 leency 368
			return;
369
 
4413 leency 370
		case 180: //home
4540 leency 371
			if (WB1.list.KeyHome()) WB1.ParseHTML(bufpointer);
4415 leency 372
			return;
373
 
4413 leency 374
		case 181: //end
4415 leency 375
			if (WB1.list.count < WB1.list.visible) return;
4540 leency 376
			if (WB1.list.KeyEnd()) WB1.ParseHTML(bufpointer);
4413 leency 377
			return;
378
	}
379
}
380
 
381
 
382
 
4415 leency 383
void ProcessLinks(int id)
384
{
4544 leency 385
	strcpy(#URL, PageLinks.GetURL(id-401));
4417 leency 386
	//$1 - Condition Script
387
	if (URL[0] == '$')
388
	{
389
		if (URL[1]=='-') && (condition_href) condition_href--;
390
		if (URL[1]=='+')
391
		{
392
			if (condition_href
393
		}
394
		if (URL[1]!='-') && (URL[1]!='+') condition_href = atoi(#URL+1);
395
		strcpy(#URL, BrowserHistory.CurrentUrl());
4508 leency 396
		ShowPage();
4417 leency 397
		return;
398
	}
4415 leency 399
	//#1
400
	if (URL[0] == '#')
401
	{
4417 leency 402
		strcpy(#anchor, #URL+strrchr(#URL, '#'));
4415 leency 403
		strcpy(#URL, BrowserHistory.CurrentUrl());
404
		WB1.list.first=WB1.list.count-WB1.list.visible;
4508 leency 405
		ShowPage();
4415 leency 406
		return;
407
	}
408
	//liner.ru#1
4417 leency 409
	if (strrchr(#URL, '#')!=-1)
4415 leency 410
	{
411
		strcpy(#anchor, #URL+strrchr(#URL, '#'));
4416 leency 412
		URL[strrchr(#URL, '#')-1] = 0x00;
4415 leency 413
	}
414
 
415
	WB1.GetNewUrl();
416
 
417
	if (!strcmp(#URL + strlen(#URL) - 4, ".gif")) || (!strcmp(#URL + strlen(#URL) - 4, ".png")) || (!strcmp(#URL + strlen(#URL) - 4, ".jpg"))
418
	{
419
		//if (strstr(#URL,"http:"))
420
		RunProgram("/sys/media/kiv", #URL);
421
		strcpy(#editURL, BrowserHistory.CurrentUrl());
422
		strcpy(#URL, BrowserHistory.CurrentUrl());
423
		return;
424
	}
425
	if (!strcmpn(#URL,"mailto:", 7))
426
	{
427
		notify(#URL);
428
		strcpy(#editURL, BrowserHistory.CurrentUrl());
429
		strcpy(#URL, BrowserHistory.CurrentUrl());
430
		return;
431
	}
4413 leency 432
 
4416 leency 433
	OpenPage();
4415 leency 434
	return;
435
}
436
 
4416 leency 437
void OpenPage()
438
{
439
	if (GetProcessSlot(downloader_id)<>0) PutPaletteImage(#toolbar,200,42,0,0,8,#toolbar_pal);
440
	KillProcess(downloader_id);
441
	strcpy(#editURL, #URL);
442
	BrowserHistory.AddUrl();
443
	strcpy(#header, #version);
444
	pre_text =0;
4488 leency 445
	if (!strncmp(#URL,"http:",5))
4416 leency 446
	{
447
		KillProcess(downloader_id);
448
		DeleteFile(#download_path);
449
		IF (URL[strlen(#URL)-1]=='/') URL[strlen(#URL)-1]=NULL;
450
		downloader_id = RunProgram("/sys/network/downloader", #URL);
451
		IF (downloader_id<0) notify("Error running Downloader. Internet unavilable.");
452
		Draw_Window();
453
		return;
454
	}
455
	WB1.list.first = WB1.list.count =0;
456
	WB1.ReadHtml(_WIN);
4508 leency 457
	ShowPage();
4416 leency 458
}
4415 leency 459
 
4508 leency 460
void ShowPage()
461
{
462
	address_box.size = address_box.pos = strlen(#editURL);
463
	address_box.offset=0;
464
	edit_box_draw stdcall(#address_box);
4415 leency 465
 
4544 leency 466
	if (strcmp(#URL, URL_HISTORY)==0) ShowHistory(); else
4540 leency 467
	if (!bufsize)
4508 leency 468
	{
469
		PageLinks.Clear();
4534 leency 470
		if (GetProcessSlot(downloader_id)<>0)
471
		{
4544 leency 472
			bufsize = sizeof(loading);
473
			WB1.ParseHTML(#loading);
4534 leency 474
		}
4508 leency 475
		else
476
		{
4544 leency 477
			bufsize = sizeof(page_not_found);
478
			WB1.ParseHTML(#page_not_found);
4508 leency 479
		}
4544 leency 480
		bufsize = 0;
4508 leency 481
	}
482
	else
4540 leency 483
		WB1.ParseHTML(bufpointer);
4415 leency 484
 
4508 leency 485
	if (!header) strcpy(#header, #version);
486
	if (!strcmp(#version, #header)) DrawTitle(#header);
487
}
488
 
4544 leency 489
ShowHistory()
490
{
491
		int i;
492
		static int history_pointer;
493
 
494
		free(history_pointer);
495
		history_pointer = malloc(64000);
496
		strcat(history_pointer, "

History

");
497
		strcat(history_pointer, "

Visited pages


");
498
		for (i=1; i
499
		{
500
			strcat(history_pointer, "");
503
			strcat(history_pointer, BrowserHistory.GetUrl(i));
504
			strcat(history_pointer, "
");
505
		}
506
		strcat(history_pointer, "

Cached images


");
507
		for (i=1; i
508
		{
509
			strcat(history_pointer, "
");
512
		}
513
		bufsize = strlen(history_pointer);
514
		bufpointer = history_pointer;
515
		WB1.ParseHTML(history_pointer);
516
}
4508 leency 517
 
4544 leency 518
 
3067 leency 519
stop: