Subversion Repositories Kolibri OS

Rev

Rev 4413 | 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"
3107 leency 19
//*.obj libraries
20
#include "..\lib\lib.obj\box_lib.h"
21
#include "..\lib\lib.obj\libio_lib.h"
22
#include "..\lib\lib.obj\libimg_lib.h"
23
//images
3067 leency 24
#include "img\toolbar_icons.c"
25
#include "img\URLgoto.txt";
26
 
4026 leency 27
#ifdef LANG_RUS
4411 leency 28
	char version[]=" ’ҐЄбв®ўл© Ўа г§Ґа 0.99.11";
4026 leency 29
	?define IMAGES_CACHE_CLEARED "Љни Є авЁ­®Є ®зЁйҐ­"
30
#else
4411 leency 31
	char version[]=" Text-based Browser 0.99.11";
4026 leency 32
	?define IMAGES_CACHE_CLEARED "Images cache cleared"
33
#endif
34
 
35
 
3067 leency 36
#define URL param
3449 leency 37
char fontlol[64];
3067 leency 38
 
39
char editURL[sizeof(URL)],
40
	page_links[12000],
3464 leency 41
	header[2048];
3067 leency 42
 
43
 
44
int	mouse_dd;
3466 leency 45
edit_box address_box= {250,207,16,0xffffff,0x94AECE,0xffffff,0xffffff,0,sizeof(editURL),#editURL,#mouse_dd,2,19,19};
3464 leency 46
scroll_bar scroll1 = { 18,200,398, 44,18,0,115,15,0,0xeeeeee,0xD2CED0,0x555555,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1};
3067 leency 47
 
48
 
49
proc_info Form;
50
#define WIN_W 640
51
#define WIN_H 480
52
 
53
 
4074 leency 54
char stak[4096];
3067 leency 55
mouse m;
56
 
4026 leency 57
int action_buf;
58
 
4413 leency 59
#include "history.h"
4411 leency 60
#include "..\TWB\TWB.c"
61
#include "menu_rmb.h"
3067 leency 62
 
63
 
64
void main()
65
{
4081 leency 66
	int key, btn;
3067 leency 67
	int half_scroll_size;
4026 leency 68
	int scroll_used=0, show_menu;
3067 leency 69
 
70
	mem_Init();
3107 leency 71
	if (load_dll2(boxlib, #box_lib_init,0)!=0) {notify("System Error: library doesn't exists /rd/1/lib/box_lib.obj"); ExitProcess();}
72
	if (load_dll2(libio, #libio_init,1)!=0) debug("Error: library doesn't exists - libio"w);
73
	if (load_dll2(libimg, #libimg_init,1)!=0) debug("Error: library doesn't exists - libimg"w);
3067 leency 74
 
3987 leency 75
	if (!URL) strcpy(#URL, "/sys/index.htm");
3067 leency 76
	strcpy(#editURL, #URL);
77
 
78
	Form.width=WIN_W;
79
	Form.height=WIN_H;
80
	SetElementSizes();
81
	WB1.OpenPage();
82
 
83
	SetEventMask(0x27);
84
	loop()
85
	{
86
		WaitEventTimeout(2);
87
		switch(EAX & 0xFF)
88
		{
89
			CASE evMouse:
4414 leency 90
				/*
91
				//not work well, so we are use custom way of processing scroll
92
				scrollbar_v_mouse (#scroll1);
3067 leency 93
				if (lines.first <> scroll1.position)
94
				{
95
					lines.first = scroll1.position;
96
					WB1.ParseHTML(buf, filesize);
4414 leency 97
				};
98
				*/
3067 leency 99
 
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();
105
 
4414 leency 106
				if (m.y>WB1.list.y) && (m.y
3067 leency 107
				{
4026 leency 108
					if (m.pkm)
109
					{
110
						show_menu = 1;
111
					}
112
					if (!m.pkm) && (show_menu)
113
					{
114
						show_menu = 0;
115
						SwitchToAnotherThread();
4074 leency 116
						CreateThread(#menu_rmb,#stak+4092);
4026 leency 117
						break;
118
					}
3067 leency 119
				}
120
 
4026 leency 121
				if (m.vert==65535)
3067 leency 122
				{
3477 leency 123
					if (lines.first==0) break;
124
					if (lines.first>3) lines.first-=2; ELSE lines.first=1;
4413 leency 125
					Scan(ID1);
3067 leency 126
					break;
127
				}
3477 leency 128
				if (m.vert==1)
3067 leency 129
				{
4413 leency 130
					if(lines.visible+lines.first+3>=lines.all) Scan(181);
4026 leency 131
					else
132
					{
3067 leency 133
						lines.first+=2;
4413 leency 134
						Scan(ID2);
3067 leency 135
					}
136
					break;
137
				}
138
 
139
				if (!m.lkm) scroll_used=0;
3477 leency 140
				if (m.x>=scroll1.start_x) && (m.x<=scroll1.start_x+scroll1.size_x)
4026 leency 141
				&& (m.y>=scroll1.start_y+scroll1.btn_height) && (-scroll1.btn_height+scroll1.start_y+scroll1.size_y>m.y)
142
				&& (lines.all>lines.visible) && (m.lkm)
143
				{
144
					scroll_used=1;
145
				}
3067 leency 146
 
147
				if (scroll_used)
148
				{
4414 leency 149
					half_scroll_size = WB1.list.h - 16 * lines.visible / lines.all - 3 /2;
150
					if (half_scroll_size+WB1.list.y>m.y) || (m.y<0) || (m.y>4000) m.y=half_scroll_size+WB1.list.y; //если курсор над окном
3067 leency 151
					btn=lines.first; //сохраняем старое количество
4414 leency 152
					lines.first = m.y -half_scroll_size -WB1.list.y * lines.all / WB1.list.h;
3067 leency 153
					if (lines.visible+lines.first>lines.all) lines.first=lines.all-lines.visible;
154
					if (btn<>lines.first) WB1.ParseHTML(buf); //чтоб лишний раз не перерисовывать
155
				}
156
 
157
				break;
158
			case evButton:
159
				btn=GetButtonID();
3464 leency 160
				if (btn==1)
3067 leency 161
				{
162
					KillProcess(downloader_id);
163
					ExitProcess();
164
				}
165
				ELSE
166
				{
4413 leency 167
					Scan(btn);
3067 leency 168
				}
169
				break;
170
			case evKey:
171
				key = GetKey();
172
 
3466 leency 173
				if (address_box.flags & 0b10) SWITCH(key) //если активна строка адреса игнорируем некоторые кнопки
3067 leency 174
					{ CASE 52: CASE 53: CASE 54: goto _EDIT_MARK; }
175
 
4413 leency 176
				Scan(key);
3067 leency 177
 
178
				_EDIT_MARK:
3990 leency 179
				if (key<>0x0d) && (key<>183) && (key<>184) {EAX=key<<8; edit_box_key stdcall(#address_box);} //адресная строка
3067 leency 180
				break;
181
			case evReDraw:
4413 leency 182
				if (action_buf) { Scan(action_buf); action_buf=0;}
3067 leency 183
				Draw_Window();
184
				break;
185
			default:
186
				if (downloader_id<>0)
187
				{
188
					if (GetProcessSlot(downloader_id)<>0) break;
189
					downloader_id=0;
190
					lines.first = lines.all = 0;
191
					WB1.ReadHtml(_WIN);
192
					Draw_Window();
193
				}
194
		}
195
	}
196
}
197
 
198
void SetElementSizes()
199
{
3466 leency 200
	address_box.width = Form.width-266;
4414 leency 201
	WB1.list.SetSizes(0, 44, Form.width - 10 - scroll1.size_x, Form.cheight - 44, 0, 10);
202
	lines.column_max = WB1.list.w - 30 / 6;
203
	lines.visible = WB1.list.h - 3 / WB1.list.line_h - 2;
3468 leency 204
	DrawBufInit();
3067 leency 205
}
206
 
207
 
208
void Draw_Window()
209
{
210
	int j;
3466 leency 211
	DefineAndDrawWindow(215,100,WIN_W,WIN_H,0x73,0xE4DFE1,0,0);
3067 leency 212
 
213
	GetProcessInfo(#Form, SelfInfo);
3464 leency 214
	if (Form.status_window>2)
3067 leency 215
	{
216
		DrawTitle(#header);
217
		return;
218
	}
219
	if (Form.height<120) MoveSize(OLD,OLD,OLD,120);
220
	if (Form.width<280) MoveSize(OLD,OLD,280,OLD);
221
 
222
	PutPaletteImage(#toolbar,200,42,0,0,8,#toolbar_pal);
3363 leency 223
	if (GetProcessSlot(downloader_id)<>0) _PutImage(88,10, 24,24, #stop_btn);
3067 leency 224
 
3464 leency 225
	DrawBar(200,0,Form.cwidth-200,43,0xE4DFE1);
226
	DrawBar(0,42,Form.cwidth,1,0xE2DBDC);
227
	DrawBar(0,43,Form.cwidth,1,0xD2CED0);
3067 leency 228
	for (j=0; j<5; j++) DefineButton(j*37+11, 7, 29, 29, 300+j+BT_HIDE, 0xE4DFE1);
3464 leency 229
	_PutImage(Form.cwidth-48,14, 40,19, #URLgoto);
230
	DefineButton(Form.cwidth-28,15, 18, 16, GOTOURL+BT_HIDE, 0xE4DFE1);
231
	DefineButton(Form.cwidth-47,15, 17, 16, SEARCHWEB+BT_HIDE, 0xE4DFE1);
232
	DrawRectangle(205,14,Form.cwidth-205-49,18,0x94AECE); //around adress bar
233
	DrawRectangle(206,15,Form.cwidth-205-50,16,0xE4ECF3);
3067 leency 234
 
235
	SetElementSizes();
236
	WB1.ShowPage();
3464 leency 237
 
3067 leency 238
	DefineButton(scroll1.start_x+1, scroll1.start_y+1, 16, 16, ID1+BT_HIDE, 0xE4DFE1);
239
	DefineButton(scroll1.start_x+1, scroll1.start_y+scroll1.size_y-18, 16, 16, ID2+BT_HIDE, 0xE4DFE1);
240
}
241
 
242
 
4413 leency 243
void Scan(int id)
244
{
245
	if (id >= 400)
246
	{
247
		GetURLfromPageLinks(id);
248
 
249
		//#1
250
		if (URL[0] == '#')
251
		{
252
			strcpy(#anchor, #URL+strrchr(#URL, '#'));
253
 
254
			strcpy(#URL, BrowserHistory.CurrentUrl());
255
 
256
			lines.first=lines.all-lines.visible;
257
			WB1.ShowPage();
258
			return;
259
		}
260
		//liner.ru#1
261
		if (strrchr(#URL, '#')<>-1)
262
		{
263
			strcpy(#anchor, #URL+strrchr(#URL, '#'));
264
			URL[strrchr(#URL, '#')-1] = 0x00; //заглушка
265
		}
266
 
267
		WB1.GetNewUrl();
268
 
269
		if (!strcmp(#URL + strlen(#URL) - 4, ".gif")) || (!strcmp(#URL + strlen(#URL) - 4, ".png")) || (!strcmp(#URL + strlen(#URL) - 4, ".jpg"))
270
		{
271
			//if (strstr(#URL,"http:"))
272
			RunProgram("/sys/media/kiv", #URL);
273
			strcpy(#editURL, BrowserHistory.CurrentUrl());
274
			strcpy(#URL, BrowserHistory.CurrentUrl());
275
			return;
276
		}
277
		if (!strcmpn(#URL,"mailto:", 7))
278
		{
279
			RunProgram("@notify", #URL);
280
			strcpy(#editURL, BrowserHistory.CurrentUrl());
281
			strcpy(#URL, BrowserHistory.CurrentUrl());
282
			return;
283
		}
284
 
285
		WB1.OpenPage();
286
		return;
287
	}
288
 
289
	IF(lines.all < lines.visible) SWITCH(id) //если мало строк игнорируем некоторые кнопки
290
	{ CASE 183: CASE 184: CASE 180: CASE 181: return; }
291
 
292
	switch (id)
293
	{
294
		case 011: //Ctrk+K
295
			WB1.ReadHtml(_KOI);
296
			break;
297
		case 021: //Ctrl+U
298
			WB1.ReadHtml(_UTF);
299
			break;
300
		case 004: //Ctrl+D
301
			WB1.ReadHtml(_DOS);
302
			break;
303
		case 002: //free img cache
304
			FreeImgCache();
305
			break;
306
		case BACK:
307
			if (!BrowserHistory.GoBack()) return;
308
			WB1.OpenPage();
309
			return;
310
		case FORWARD:
311
			if (!BrowserHistory.GoForward()) return;
312
			WB1.OpenPage();
313
			return;
314
		case 052:  //F3
315
			if (strcmp(get_URL_part(5),"http:")<>0) RunProgram("/rd/1/tinypad", #URL); else RunProgram("/rd/1/tinypad", #download_path);
316
			return;
317
		case 054: //F5
318
			IF(address_box.flags & 0b10) break;
319
		case REFRESH:
320
			if (GetProcessSlot(downloader_id)<>0)
321
			{
322
				KillProcess(downloader_id);
323
				pause(20);
324
				Draw_Window();
325
				return;
326
			}
327
			anchor_line_num=lines.first; //весёлый костыль :Р
328
			anchor[0]='|';
329
			WB1.OpenPage();
330
			return;
331
		case 014: //Ctrl+N новое окно
332
		case 020: //Ctrl+T новая вкладка
333
		case NEWTAB:
334
			MoveSize(190,80,OLD,OLD);
335
			RunProgram(#program_path, #URL);
336
			return;
337
 
338
		case HOME:
339
			strcpy(#editURL, "http://kolibrios.org/en/index.htm");
340
		case GOTOURL:
341
		case 0x0D: //enter
342
			//почему ttp://? Господа, отличный вопрос. Дело в том, что это хак.
343
			//strstr() если не нашло возвращает 0 и в случае успеха возвращает 0. Так что это хак.
344
			if ((strstr(#editURL,"ttp://")==0) && (editURL[0]!='/')) strcpy(#URL,"http://"); else URL[0] = 0;
345
			strcat(#URL, #editURL);
346
			WB1.OpenPage();
347
			return;
348
		case SEARCHWEB:
349
			strcpy(#URL, #search_path);
350
			strcat(#URL, #editURL);
351
			WB1.OpenPage();
352
			return;
353
 
354
		case ID1: //мотаем вверх
355
			IF(lines.first <= 0) return;
356
			lines.first--;
357
			break;
358
		case ID2: //мотаем вниз
359
			IF(lines.visible + lines.first >= lines.all) return;
360
			lines.first++;
361
			break;
362
		case 183: //PgDown
363
			IF(lines.first == lines.all - lines.visible) return;
364
			lines.first += lines.visible + 2;
365
			IF(lines.visible + lines.first > lines.all) lines.first = lines.all - lines.visible;
366
			break;
367
		case 184: //PgUp
368
			IF(lines.first == 0) return;
369
			lines.first -= lines.visible - 2;
370
			IF(lines.first < 0) lines.first = 0;
371
			break;
372
		case 180: //home
373
			IF(lines.first == 0) return;
374
			lines.first = 0;
375
			break;
376
		case 181: //end
377
			IF (lines.first == lines.all - lines.visible) return;
378
			lines.first = lines.all - lines.visible;
379
			break;
380
		default:
381
			return;
382
	}
383
	WB1.ParseHTML(buf);
384
}
385
 
386
 
387
 
388
 
3067 leency 389
stop: