Subversion Repositories Kolibri OS

Rev

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