Subversion Repositories Kolibri OS

Rev

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