Subversion Repositories Kolibri OS

Rev

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