Subversion Repositories Kolibri OS

Rev

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