Subversion Repositories Kolibri OS

Rev

Rev 4414 | Rev 4416 | 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"
4415 leency 19
#include "..\lib\list_box.h"
3107 leency 20
//*.obj libraries
21
#include "..\lib\lib.obj\box_lib.h"
22
#include "..\lib\lib.obj\libio_lib.h"
23
#include "..\lib\lib.obj\libimg_lib.h"
24
//images
3067 leency 25
#include "img\toolbar_icons.c"
26
#include "img\URLgoto.txt";
27
 
4026 leency 28
#ifdef LANG_RUS
4415 leency 29
	char version[]=" ’ҐЄбв®ўл© Ўа г§Ґа 0.99.3";
30
	?define IMAGES_CACHE_CLEARED "Љни Є авЁ­®Є ®зЁйҐ­"
4026 leency 31
#else
4415 leency 32
	char version[]=" Text-based Browser 0.99.3";
4026 leency 33
	?define IMAGES_CACHE_CLEARED "Images cache cleared"
34
#endif
35
 
36
 
3067 leency 37
#define URL param
3449 leency 38
char fontlol[64];
3067 leency 39
 
40
char editURL[sizeof(URL)],
41
	page_links[12000],
3464 leency 42
	header[2048];
3067 leency 43
 
44
 
45
int	mouse_dd;
3466 leency 46
edit_box address_box= {250,207,16,0xffffff,0x94AECE,0xffffff,0xffffff,0,sizeof(editURL),#editURL,#mouse_dd,2,19,19};
3464 leency 47
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 48
 
49
 
50
proc_info Form;
51
#define WIN_W 640
52
#define WIN_H 480
53
 
54
 
4074 leency 55
char stak[4096];
3067 leency 56
mouse m;
57
 
4026 leency 58
int action_buf;
59
 
4413 leency 60
#include "history.h"
4411 leency 61
#include "..\TWB\TWB.c"
62
#include "menu_rmb.h"
3067 leency 63
 
64
 
65
void main()
66
{
4081 leency 67
	int key, btn;
3067 leency 68
	int half_scroll_size;
4026 leency 69
	int scroll_used=0, show_menu;
3067 leency 70
 
71
	mem_Init();
3107 leency 72
	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 73
	if (load_dll2(libio, #libio_init,1)!=0) debug("Error: library doesn't exists - libio");
74
	if (load_dll2(libimg, #libimg_init,1)!=0) debug("Error: library doesn't exists - libimg");
3067 leency 75
 
3987 leency 76
	if (!URL) strcpy(#URL, "/sys/index.htm");
3067 leency 77
	strcpy(#editURL, #URL);
78
 
79
	Form.width=WIN_W;
80
	Form.height=WIN_H;
81
	SetElementSizes();
82
	WB1.OpenPage();
83
 
84
	SetEventMask(0x27);
85
	loop()
86
	{
87
		WaitEventTimeout(2);
88
		switch(EAX & 0xFF)
89
		{
90
			CASE evMouse:
4414 leency 91
				/*
92
				//not work well, so we are use custom way of processing scroll
93
				scrollbar_v_mouse (#scroll1);
4415 leency 94
				if (WB1.list.first <> scroll1.position)
3067 leency 95
				{
4415 leency 96
					WB1.list.first = scroll1.position;
3067 leency 97
					WB1.ParseHTML(buf, filesize);
4414 leency 98
				};
99
				*/
3067 leency 100
 
4081 leency 101
				if (!CheckActiveProcess(Form.ID)) break;
3067 leency 102
 
3466 leency 103
				edit_box_mouse stdcall (#address_box);
3067 leency 104
 
105
				m.get();
106
 
4414 leency 107
				if (m.y>WB1.list.y) && (m.y
3067 leency 108
				{
4026 leency 109
					if (m.pkm)
110
					{
111
						show_menu = 1;
112
					}
113
					if (!m.pkm) && (show_menu)
114
					{
115
						show_menu = 0;
116
						SwitchToAnotherThread();
4074 leency 117
						CreateThread(#menu_rmb,#stak+4092);
4026 leency 118
						break;
119
					}
3067 leency 120
				}
121
 
4415 leency 122
				if (m.vert)
3067 leency 123
				{
4415 leency 124
					if (WB1.list.MouseScroll(m.vert)) WB1.ParseHTML(buf);
3067 leency 125
				}
126
 
127
				if (!m.lkm) scroll_used=0;
3477 leency 128
				if (m.x>=scroll1.start_x) && (m.x<=scroll1.start_x+scroll1.size_x)
4026 leency 129
				&& (m.y>=scroll1.start_y+scroll1.btn_height) && (-scroll1.btn_height+scroll1.start_y+scroll1.size_y>m.y)
4415 leency 130
				&& (WB1.list.count>WB1.list.visible) && (m.lkm)
4026 leency 131
				{
132
					scroll_used=1;
133
				}
3067 leency 134
 
135
				if (scroll_used)
136
				{
4415 leency 137
					half_scroll_size = WB1.list.h - 16 * WB1.list.visible / WB1.list.count - 3 /2;
138
					if (half_scroll_size+WB1.list.y>m.y) || (m.y<0) || (m.y>4000) m.y=half_scroll_size+WB1.list.y; //åñëè êóðñîð íàä îêíîì
139
					btn=WB1.list.first; //ñîõðàíÿåì ñòàðîå êîëè÷åñòâî
140
					WB1.list.first = m.y -half_scroll_size -WB1.list.y * WB1.list.count / WB1.list.h;
141
					if (WB1.list.visible+WB1.list.first>WB1.list.count) WB1.list.first=WB1.list.count-WB1.list.visible;
142
					if (btn<>WB1.list.first) WB1.ParseHTML(buf); //÷òîá ëèøíèé ðàç íå ïåðåðèñîâûâàòü
3067 leency 143
				}
144
 
145
				break;
146
			case evButton:
147
				btn=GetButtonID();
3464 leency 148
				if (btn==1)
3067 leency 149
				{
150
					KillProcess(downloader_id);
151
					ExitProcess();
152
				}
153
				ELSE
154
				{
4413 leency 155
					Scan(btn);
3067 leency 156
				}
157
				break;
158
			case evKey:
159
				key = GetKey();
160
 
4415 leency 161
				if (address_box.flags & 0b10) SWITCH(key) //åñëè àêòèâíà ñòðîêà àäðåñà èãíîðèðóåì íåêîòîðûå êíîïêè
3067 leency 162
					{ CASE 52: CASE 53: CASE 54: goto _EDIT_MARK; }
163
 
4413 leency 164
				Scan(key);
3067 leency 165
 
166
				_EDIT_MARK:
4415 leency 167
				if (key<>0x0d) && (key<>183) && (key<>184) {EAX=key<<8; edit_box_key stdcall(#address_box);} //àäðåñíàÿ ñòðîêà
3067 leency 168
				break;
169
			case evReDraw:
4413 leency 170
				if (action_buf) { Scan(action_buf); action_buf=0;}
3067 leency 171
				Draw_Window();
172
				break;
173
			default:
174
				if (downloader_id<>0)
175
				{
176
					if (GetProcessSlot(downloader_id)<>0) break;
177
					downloader_id=0;
4415 leency 178
					WB1.list.first = WB1.list.count = 0;
3067 leency 179
					WB1.ReadHtml(_WIN);
180
					Draw_Window();
181
				}
182
		}
183
	}
184
}
185
 
186
void SetElementSizes()
187
{
3466 leency 188
	address_box.width = Form.width-266;
4414 leency 189
	WB1.list.SetSizes(0, 44, Form.width - 10 - scroll1.size_x, Form.cheight - 44, 0, 10);
4415 leency 190
	WB1.list.column_max = WB1.list.w - 30 / 6;
191
	WB1.list.visible = WB1.list.h - 3 / WB1.list.line_h - 2;
3468 leency 192
	DrawBufInit();
3067 leency 193
}
194
 
195
 
196
void Draw_Window()
197
{
198
	int j;
3466 leency 199
	DefineAndDrawWindow(215,100,WIN_W,WIN_H,0x73,0xE4DFE1,0,0);
3067 leency 200
 
201
	GetProcessInfo(#Form, SelfInfo);
3464 leency 202
	if (Form.status_window>2)
3067 leency 203
	{
204
		DrawTitle(#header);
205
		return;
206
	}
207
	if (Form.height<120) MoveSize(OLD,OLD,OLD,120);
208
	if (Form.width<280) MoveSize(OLD,OLD,280,OLD);
209
 
210
	PutPaletteImage(#toolbar,200,42,0,0,8,#toolbar_pal);
3363 leency 211
	if (GetProcessSlot(downloader_id)<>0) _PutImage(88,10, 24,24, #stop_btn);
3067 leency 212
 
3464 leency 213
	DrawBar(200,0,Form.cwidth-200,43,0xE4DFE1);
214
	DrawBar(0,42,Form.cwidth,1,0xE2DBDC);
215
	DrawBar(0,43,Form.cwidth,1,0xD2CED0);
3067 leency 216
	for (j=0; j<5; j++) DefineButton(j*37+11, 7, 29, 29, 300+j+BT_HIDE, 0xE4DFE1);
3464 leency 217
	_PutImage(Form.cwidth-48,14, 40,19, #URLgoto);
218
	DefineButton(Form.cwidth-28,15, 18, 16, GOTOURL+BT_HIDE, 0xE4DFE1);
219
	DefineButton(Form.cwidth-47,15, 17, 16, SEARCHWEB+BT_HIDE, 0xE4DFE1);
220
	DrawRectangle(205,14,Form.cwidth-205-49,18,0x94AECE); //around adress bar
221
	DrawRectangle(206,15,Form.cwidth-205-50,16,0xE4ECF3);
3067 leency 222
 
223
	SetElementSizes();
224
	WB1.ShowPage();
3464 leency 225
 
4415 leency 226
	DefineButton(scroll1.start_x+1, scroll1.start_y+1, 16, 16, BTN_UP+BT_HIDE, 0xE4DFE1);
227
	DefineButton(scroll1.start_x+1, scroll1.start_y+scroll1.size_y-18, 16, 16, BTN_DOWN+BT_HIDE, 0xE4DFE1);
3067 leency 228
}
229
 
230
 
4413 leency 231
void Scan(int id)
232
{
4415 leency 233
	if (id >= 400) ProcessLinks(id);
4413 leency 234
 
235
	switch (id)
236
	{
237
		case 011: //Ctrk+K
238
			WB1.ReadHtml(_KOI);
4415 leency 239
			WB1.ParseHTML(buf);
240
			return;
241
 
4413 leency 242
		case 021: //Ctrl+U
243
			WB1.ReadHtml(_UTF);
4415 leency 244
			WB1.ParseHTML(buf);
245
			return;
246
 
4413 leency 247
		case 004: //Ctrl+D
248
			WB1.ReadHtml(_DOS);
4415 leency 249
			WB1.ParseHTML(buf);
250
			return;
251
 
4413 leency 252
		case 002: //free img cache
253
			FreeImgCache();
4415 leency 254
			WB1.ParseHTML(buf);
255
			return;
256
 
4413 leency 257
		case BACK:
258
			if (!BrowserHistory.GoBack()) return;
259
			WB1.OpenPage();
260
			return;
261
		case FORWARD:
262
			if (!BrowserHistory.GoForward()) return;
263
			WB1.OpenPage();
264
			return;
265
		case 052:  //F3
4415 leency 266
			if (strcmp(get_URL_part(5),"http:")<>0) RunProgram("/rd/1/tinypad", #URL);
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]='|';
283
			WB1.OpenPage();
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);
298
			WB1.OpenPage();
299
			return;
300
		case SEARCHWEB:
301
			strcpy(#URL, #search_path);
302
			strcat(#URL, #editURL);
303
			WB1.OpenPage();
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:
323
		case BTN_UP: //мотаем вверх
324
			IF(WB1.list.first <= 0) return;
325
			WB1.list.first--;
326
			WB1.ParseHTML(buf);
327
			return;
328
 
329
		case 177:
330
		case BTN_DOWN: //мотаем вниз
331
			IF(WB1.list.visible + WB1.list.first >= WB1.list.count) return;
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
{
351
	GetURLfromPageLinks(id);
352
 
353
	//#1
354
	if (URL[0] == '#')
355
	{
356
		strcpy(#anchor, #URL+strrchr(#URL, '#'));
357
 
358
		strcpy(#URL, BrowserHistory.CurrentUrl());
359
 
360
		WB1.list.first=WB1.list.count-WB1.list.visible;
361
		WB1.ShowPage();
362
		return;
363
	}
364
	//liner.ru#1
365
	if (strrchr(#URL, '#')<>-1)
366
	{
367
		strcpy(#anchor, #URL+strrchr(#URL, '#'));
368
		URL[strrchr(#URL, '#')-1] = 0x00; //çàãëóøêà
369
	}
370
 
371
	WB1.GetNewUrl();
372
 
373
	if (!strcmp(#URL + strlen(#URL) - 4, ".gif")) || (!strcmp(#URL + strlen(#URL) - 4, ".png")) || (!strcmp(#URL + strlen(#URL) - 4, ".jpg"))
374
	{
375
		//if (strstr(#URL,"http:"))
376
		RunProgram("/sys/media/kiv", #URL);
377
		strcpy(#editURL, BrowserHistory.CurrentUrl());
378
		strcpy(#URL, BrowserHistory.CurrentUrl());
379
		return;
380
	}
381
	if (!strcmpn(#URL,"mailto:", 7))
382
	{
383
		notify(#URL);
384
		strcpy(#editURL, BrowserHistory.CurrentUrl());
385
		strcpy(#URL, BrowserHistory.CurrentUrl());
386
		return;
387
	}
4413 leency 388
 
4415 leency 389
	WB1.OpenPage();
390
	return;
391
}
392
 
393
 
394
 
395
 
396
 
3067 leency 397
stop: