Subversion Repositories Kolibri OS

Rev

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