Subversion Repositories Kolibri OS

Rev

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