Subversion Repositories Kolibri OS

Rev

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