Subversion Repositories Kolibri OS

Rev

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