Subversion Repositories Kolibri OS

Rev

Rev 3060 | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 3060 Rev 3061
1
int	downloader_id;
1
int	downloader_id;
2
 
2
 
3
dword
3
dword
4
	buf,
4
	buf,
5
	filesize,
5
	filesize,
6
	blink;
6
	blink;
7
 
7
 
8
char download_path[]="/rd/1/.download";
8
char download_path[]="/rd/1/.download";
9
char search_path[]="http://nigma.ru/index.php?s=";
9
char search_path[]="http://nigma.ru/index.php?s=";
10
char version[]=" Text-based Browser 0.97.7";
10
char version[]=" Text-based Browser 0.97.7";
11
 
11
 
12
 
12
 
13
struct TWebBrowser {
13
struct TWebBrowser {
14
	int left, top, width, height;
14
	int left, top, width, height;
15
	void Scan(int);
15
	void Scan(int);
16
	void GetNewUrl();
16
	void GetNewUrl();
17
	void OpenPage();
17
	void OpenPage();
18
	void ReadHtml(byte);
18
	void ReadHtml(byte);
19
	void ShowPage();
19
	void ShowPage();
20
	void ParseHTML(dword);
20
	void ParseHTML(dword);
21
	void WhatTextStyle(int left1, top1, width1);
21
	void WhatTextStyle(int left1, top1, width1);
22
	void DrawPage();
22
	void DrawPage();
23
	void DrawScroller();
23
	void DrawScroller();
24
};
24
};
25
 
25
 
26
TWebBrowser WB1;
26
TWebBrowser WB1;
27
 
27
 
28
byte rez, b_text, i_text, u_text, s_text, pre_text, blq_text, li_text,
28
byte rez, b_text, i_text, u_text, s_text, pre_text, blq_text, li_text,
29
	link, ignor_text, li_tab, first_line_drawed, cur_encoding;
29
	link, ignor_text, li_tab, first_line_drawed, cur_encoding;
30
 
30
 
31
 
31
 
32
dword text_colors[300],
32
dword text_colors[300],
33
	text_color_index,
33
	text_color_index,
34
	link_color,
34
	link_color,
35
	bg_color;
35
	bg_color;
36
 
36
 
37
int stroka,
37
int stroka,
38
	stolbec,
38
	stolbec,
39
	tab_len;
39
	tab_len;
40
 
40
 
41
char anchor[256];
41
char anchor[256];
42
int anchor_line_num;
42
int anchor_line_num;
43
	
43
	
44
char line[500],
44
char line[500],
45
	tag[100],
45
	tag[100],
46
	tagparam[10000],
46
	tagparam[10000],
47
	parametr[1200],
47
	parametr[1200],
48
	options[4096];
48
	options[4096];
49
 
49
 
50
#include "include\history.h"
50
#include "include\history.h"
51
#include "include\colors.h"
51
#include "include\colors.h"
52
#include "include\unicode_tags.h"
52
#include "include\unicode_tags.h"
53
#include "include\some_code.h"
53
#include "include\some_code.h"
54
#include "include\parce_tag.h"
54
#include "include\parce_tag.h"
55
 
55
 
56
 
56
 
57
void TWebBrowser::Scan(int id)
57
void TWebBrowser::Scan(int id)
58
{
58
{
59
	if (id >= 400)
59
	if (id >= 400)
60
	{
60
	{
61
		GetURLfromPageLinks(id);
61
		GetURLfromPageLinks(id);
62
		
62
		
63
		//#1
63
		//#1
64
		if (URL[0] == '#')
64
		if (URL[0] == '#')
65
		{
65
		{
66
			strcpy(#anchor, #URL+strrchr(#URL, '#'));
66
			strcpy(#anchor, #URL+strrchr(#URL, '#'));
67
			
67
			
68
			strcpy(#URL, BrowserHistory.CurrentUrl());
68
			strcpy(#URL, BrowserHistory.CurrentUrl());
69
			
69
			
70
			lines.first=lines.all-lines.visible;
70
			lines.first=lines.all-lines.visible;
71
			ShowPage();
71
			ShowPage();
72
			return;
72
			return;
73
		}
73
		}
74
		//liner.ru#1
74
		//liner.ru#1
75
		if (strrchr(#URL, '#')<>-1)
75
		if (strrchr(#URL, '#')<>-1)
76
		{
76
		{
77
			strcpy(#anchor, #URL+strrchr(#URL, '#'));
77
			strcpy(#anchor, #URL+strrchr(#URL, '#'));
78
			URL[strrchr(#URL, '#')-1] = 0x00; //çàãëóøêà
78
			URL[strrchr(#URL, '#')-1] = 0x00; //çàãëóøêà
79
		}
79
		}
80
		
80
		
81
		GetNewUrl();
81
		GetNewUrl();
82
		
82
		
83
		if (!strcmp(#URL + strlen(#URL) - 4, ".gif")) || (!strcmp(#URL + strlen(#URL) - 4, ".png")) || (!strcmp(#URL + strlen(#URL) - 4, ".jpg"))
83
		if (!strcmp(#URL + strlen(#URL) - 4, ".gif")) || (!strcmp(#URL + strlen(#URL) - 4, ".png")) || (!strcmp(#URL + strlen(#URL) - 4, ".jpg"))
84
		{
84
		{
85
			//if (strstr(#URL,"http:")) 
85
			//if (strstr(#URL,"http:")) 
86
			RunProgram("/sys/media/kiv", #URL);
86
			RunProgram("/sys/media/kiv", #URL);
87
			strcpy(#editURL, BrowserHistory.CurrentUrl());
87
			strcpy(#editURL, BrowserHistory.CurrentUrl());
88
			strcpy(#URL, BrowserHistory.CurrentUrl());
88
			strcpy(#URL, BrowserHistory.CurrentUrl());
89
			return;
89
			return;
90
		}
90
		}
91
		if (!strcmpn(#URL,"mailto:", 7))
91
		if (!strcmpn(#URL,"mailto:", 7))
92
		{
92
		{
93
			RunProgram("@notify", #URL);
93
			RunProgram("@notify", #URL);
94
			strcpy(#editURL, BrowserHistory.CurrentUrl());
94
			strcpy(#editURL, BrowserHistory.CurrentUrl());
95
			strcpy(#URL, BrowserHistory.CurrentUrl());
95
			strcpy(#URL, BrowserHistory.CurrentUrl());
96
			return;
96
			return;
97
		}
97
		}
98
 
98
 
99
		OpenPage();
99
		OpenPage();
100
		return;
100
		return;
101
	}
101
	}
102
	
102
	
103
	IF(lines.all < lines.visible) SWITCH(id) //åñëè ìàëî ñòðîê èãíîðèðóåì íåêîòîðûå êíîïêè
103
	IF(lines.all < lines.visible) SWITCH(id) //åñëè ìàëî ñòðîê èãíîðèðóåì íåêîòîðûå êíîïêè
104
	{ CASE 183: CASE 184: CASE 180: CASE 181: return; } 
104
	{ CASE 183: CASE 184: CASE 180: CASE 181: return; } 
105
	
105
	
106
	switch (id)
106
	switch (id)
107
	{
107
	{
108
		case 011: //Ctrk+K 
108
		case 011: //Ctrk+K 
109
			ReadHtml(_KOI);
109
			ReadHtml(_KOI);
110
			break;
110
			break;
111
		case 021: //Ctrl+U
111
		case 021: //Ctrl+U
112
			ReadHtml(_UTF);
112
			ReadHtml(_UTF);
113
			break;
113
			break;
114
		case 004: //Ctrl+D
114
		case 004: //Ctrl+D
115
			ReadHtml(_DOS);
115
			ReadHtml(_DOS);
116
			break;
116
			break;
117
		case 001:
117
		case 001:
118
			if (!pre_text) pre_text=2;
118
			if (!pre_text) pre_text=2;
119
				else pre_text=0;
119
				else pre_text=0;
120
			break;
120
			break;
121
		case 005: //truetype
121
		case 005: //truetype
122
			if (use_truetype == 2) 
122
			if (use_truetype == 2) 
123
			{
123
			{
124
				RunProgram("@notify", "Library does not exists /rd/1/lib/truetype.obj"w);
124
				RunProgram("@notify", "Library does not exists /rd/1/lib/truetype.obj"w);
125
				return;
125
				return;
126
			}
126
			}
127
			if (use_truetype == 1) use_truetype=0; else use_truetype=1;
127
			if (use_truetype == 1) use_truetype=0; else use_truetype=1;
128
			break;
128
			break;
129
		case BACK:
129
		case BACK:
130
			if (!BrowserHistory.GoBack()) return;
130
			if (!BrowserHistory.GoBack()) return;
131
			OpenPage();
131
			OpenPage();
132
			return;
132
			return;
133
		case FORWARD:
133
		case FORWARD:
134
			if (!BrowserHistory.GoForward()) return;
134
			if (!BrowserHistory.GoForward()) return;
135
			OpenPage();
135
			OpenPage();
136
			return;
136
			return;
137
		case 052:  //Íàæàòà F3
137
		case 052:  //Íàæàòà F3
138
			if (strcmp(get_URL_part(5),"http:")<>0) RunProgram("/rd/1/tinypad", #URL); else RunProgram("/rd/1/tinypad", #download_path);
138
			if (strcmp(get_URL_part(5),"http:")<>0) RunProgram("/rd/1/tinypad", #URL); else RunProgram("/rd/1/tinypad", #download_path);
139
			return;
139
			return;
140
		case 054: //F5
140
		case 054: //F5
141
			IF(edit1.flags == 66) break;
141
			IF(edit1.flags == 66) break;
142
		case REFRESH:
142
		case REFRESH:
143
			if (GetProcessSlot(downloader_id)<>0)
143
			if (GetProcessSlot(downloader_id)<>0)
144
			{
144
			{
145
				KillProcess(downloader_id);
145
				KillProcess(downloader_id);
146
				Pause(20);
146
				Pause(20);
147
				Draw_Window();
147
				Draw_Window();
148
				return;
148
				return;
149
			}
149
			}
150
			anchor_line_num=lines.first; //âåñ¸ëûé êîñòûëü :Ð
150
			anchor_line_num=lines.first; //âåñ¸ëûé êîñòûëü :Ð
151
			anchor[0]='|';
151
			anchor[0]='|';
152
			OpenPage();
152
			OpenPage();
153
			return;
153
			return;
154
		case 014: //Ctrl+N íîâîå îêíî
154
		case 014: //Ctrl+N íîâîå îêíî
155
		case 020: //Ctrl+T íîâàÿ âêëàäêà
155
		case 020: //Ctrl+T íîâàÿ âêëàäêà
156
		case NEWTAB:
156
		case NEWTAB:
157
			MoveSize(190,80,OLD,OLD);
157
			MoveSize(190,80,OLD,OLD);
158
			RunProgram(#program_path, #URL);
158
			RunProgram(#program_path, #URL);
159
			return;
159
			return;
160
			
160
			
161
		case HOME:
161
		case HOME:
162
			strcpy(#editURL, "http://kolibri-os.narod.ru");
162
			strcpy(#editURL, "http://kolibri-os.narod.ru");
163
		case GOTOURL:
163
		case GOTOURL:
164
		case 0x0D: //enter
164
		case 0x0D: //enter
165
			strcpy(#URL, #editURL);
165
			strcpy(#URL, #editURL);
166
			OpenPage();
166
			OpenPage();
167
			return;
167
			return;
168
		case 173:	//ctrl+enter
168
		case 173:	//ctrl+enter
169
		case SEARCHWEB:
169
		case SEARCHWEB:
170
			strcpy(#URL, #search_path);
170
			strcpy(#URL, #search_path);
171
			strcat(#URL, #editURL);
171
			strcat(#URL, #editURL);
172
			OpenPage();
172
			OpenPage();
173
			return;
173
			return;
174
 
174
 
175
		case ID1: //ìîòàåì ââåðõ
175
		case ID1: //ìîòàåì ââåðõ
176
			IF(lines.first <= 0) return;
176
			IF(lines.first <= 0) return;
177
			lines.first--;
177
			lines.first--;
178
			break; 
178
			break; 
179
		case ID2: //ìîòàåì âíèç
179
		case ID2: //ìîòàåì âíèç
180
			IF(lines.visible + lines.first >= lines.all) return;
180
			IF(lines.visible + lines.first >= lines.all) return;
181
			lines.first++;
181
			lines.first++;
182
			break; 
182
			break; 
183
		case 183: //PgDown
183
		case 183: //PgDown
184
			IF(lines.first == lines.all - lines.visible) return;
184
			IF(lines.first == lines.all - lines.visible) return;
185
			lines.first += lines.visible + 2;
185
			lines.first += lines.visible + 2;
186
			IF(lines.visible + lines.first > lines.all) lines.first = lines.all - lines.visible;
186
			IF(lines.visible + lines.first > lines.all) lines.first = lines.all - lines.visible;
187
			break;
187
			break;
188
		case 184: //PgUp
188
		case 184: //PgUp
189
			IF(lines.first == 0) return;
189
			IF(lines.first == 0) return;
190
			lines.first -= lines.visible - 2;
190
			lines.first -= lines.visible - 2;
191
			IF(lines.first < 0) lines.first = 0;
191
			IF(lines.first < 0) lines.first = 0;
192
			break;
192
			break;
193
		case 180: //home
193
		case 180: //home
194
			IF(lines.first == 0) return;
194
			IF(lines.first == 0) return;
195
			lines.first = 0;
195
			lines.first = 0;
196
			break; 
196
			break; 
197
		case 181: //end
197
		case 181: //end
198
			IF (lines.first == lines.all - lines.visible) return;
198
			IF (lines.first == lines.all - lines.visible) return;
199
			lines.first = lines.all - lines.visible;
199
			lines.first = lines.all - lines.visible;
200
			break; 
200
			break; 
201
		default:
201
		default:
202
			return;
202
			return;
203
	}
203
	}
204
	ParseHTML(buf);
204
	ParseHTML(buf);
205
}
205
}
206
 
206
 
207
 
207
 
208
char *ABSOLUTE_LINKS[]={ "http:", "mailto:", "ftp:", "/sys/", "/rd/", "/fd/", "/bd/", "/hd/", "/cd/", "/tmp/", 0};
208
char *ABSOLUTE_LINKS[]={ "http:", "mailto:", "ftp:", "/sys/", "/rd/", "/fd/", "/bd/", "/hd/", "/cd/", "/tmp/", 0};
209
 
209
 
210
//dword TWebBrowser::GetNewUrl(dword CUR_URL, NEW_URL){
210
//dword TWebBrowser::GetNewUrl(dword CUR_URL, NEW_URL){
211
void TWebBrowser::GetNewUrl(){
211
void TWebBrowser::GetNewUrl(){
212
	int i, len;
212
	int i, len;
213
	
213
	
214
	for (i=0; ABSOLUTE_LINKS[i]; i++)
214
	for (i=0; ABSOLUTE_LINKS[i]; i++)
215
	{
215
	{
216
		len=strlen(ABSOLUTE_LINKS[i]);
216
		len=strlen(ABSOLUTE_LINKS[i]);
217
		if (!strcmpn(#URL, ABSOLUTE_LINKS[i], len)) return;
217
		if (!strcmpn(#URL, ABSOLUTE_LINKS[i], len)) return;
218
	}
218
	}
219
		
219
		
220
	IF (!strcmpn(#URL,"./", 2)) strcpy(#URL, #URL+2); //èãíîðèì :)
220
	IF (!strcmpn(#URL,"./", 2)) strcpy(#URL, #URL+2); //èãíîðèì :)
221
	if (URL[0] == '/') strcpy(#URL, #URL+1);
221
	if (URL[0] == '/') strcpy(#URL, #URL+1);
222
 
222
 
223
	strcpy(#editURL, BrowserHistory.CurrentUrl()); //äîñòà¸ì àäðåñ òåêóùåé ñòðàíèöû
223
	strcpy(#editURL, BrowserHistory.CurrentUrl()); //äîñòà¸ì àäðåñ òåêóùåé ñòðàíèöû
224
		
224
		
225
	_CUT_ST_LEVEL_MARK:
225
	_CUT_ST_LEVEL_MARK:
226
		
226
		
227
		if (editURL[strrchr(#editURL, '/')-2]<>'/')  // åñëè íå http://
227
		if (editURL[strrchr(#editURL, '/')-2]<>'/')  // åñëè íå http://
228
		{
228
		{
229
			editURL[strrchr(#editURL, '/')] = 0x00; //îáðåçàåì å¸ óðë äî ïîñëåäíåãî /
229
			editURL[strrchr(#editURL, '/')] = 0x00; //îáðåçàåì å¸ óðë äî ïîñëåäíåãî /
230
		}
230
		}
231
		
231
		
232
		IF (!strcmp(get_URL_part(3),"../")) //íà óðîâåíü ââåðõ
232
		IF (!strcmp(get_URL_part(3),"../")) //íà óðîâåíü ââåðõ
233
		{
233
		{
234
			strcpy(#URL,#URL+3);
234
			strcpy(#URL,#URL+3);
235
			editURL[strrchr(#editURL, '/')-1] = 0x00; //îáðåçàåì å¸ óðë äî ïîñëåäíåãî /
235
			editURL[strrchr(#editURL, '/')-1] = 0x00; //îáðåçàåì å¸ óðë äî ïîñëåäíåãî /
236
			goto _CUT_ST_LEVEL_MARK;
236
			goto _CUT_ST_LEVEL_MARK;
237
		}
237
		}
238
		
238
		
239
		if (editURL[strlen(#editURL)-1]<>'/') strcat(#editURL, "/"); 
239
		if (editURL[strlen(#editURL)-1]<>'/') strcat(#editURL, "/"); 
240
		
240
		
241
		strcat(#editURL, #URL); //êëåèì íîâûé àäðåñ
241
		strcat(#editURL, #URL); //êëåèì íîâûé àäðåñ
242
		strcpy(#URL, #editURL);
242
		strcpy(#URL, #editURL);
243
}
243
}
244
 
244
 
245
 
245
 
246
	
246
	
247
void TWebBrowser::ReadHtml(byte encoding)
247
void TWebBrowser::ReadHtml(byte encoding)
248
{
248
{
249
	if (!strcmp(get_URL_part(5),"http:"))) 
249
	if (!strcmp(get_URL_part(5),"http:"))) 
250
		file_size stdcall (#download_path);
250
		file_size stdcall (#download_path);
251
	else
251
	else
252
		file_size stdcall (#URL);
252
		file_size stdcall (#URL);
253
	
253
	
254
	filesize = EBX;
254
	filesize = EBX;
255
	if (!filesize) return;
255
	if (!filesize) return;
256
	
256
	
257
	mem_Free(buf);
257
	mem_Free(buf);
258
	buf = mem_Alloc(filesize);
258
	buf = mem_Alloc(filesize);
259
	if (!strcmp(get_URL_part(5),"http:"))) 
259
	if (!strcmp(get_URL_part(5),"http:"))) 
260
		ReadFile(0, filesize, buf, #download_path);
260
		ReadFile(0, filesize, buf, #download_path);
261
	else
261
	else
262
		ReadFile(0, filesize, buf, #URL);
262
		ReadFile(0, filesize, buf, #URL);
263
		
263
		
264
	cur_encoding = encoding;
264
	cur_encoding = encoding;
265
	if (encoding==_WIN) wintodos(buf);
265
	if (encoding==_WIN) wintodos(buf);
266
	if (encoding==_UTF) utf8rutodos(buf);
266
	if (encoding==_UTF) utf8rutodos(buf);
267
	if (encoding==_KOI) koitodos(buf);
267
	if (encoding==_KOI) koitodos(buf);
268
}
268
}
269
 
269
 
270
 
270
 
271
void TWebBrowser::OpenPage()
271
void TWebBrowser::OpenPage()
272
{
272
{
273
	if (GetProcessSlot(downloader_id)<>0) PutPaletteImage(#toolbar,200,42,0,0,8,#toolbar_pal);
273
	if (GetProcessSlot(downloader_id)<>0) PutPaletteImage(#toolbar,200,42,0,0,8,#toolbar_pal);
274
	KillProcess(downloader_id);
274
	KillProcess(downloader_id);
275
	strcpy(#editURL, #URL);
275
	strcpy(#editURL, #URL);
276
	BrowserHistory.AddUrl();
276
	BrowserHistory.AddUrl();
277
	strcpy(#header, #version);
277
	strcpy(#header, #version);
278
	pre_text =0;
278
	pre_text =0;
279
	if (!strcmp(get_URL_part(5),"http:")))
279
	if (!strcmp(get_URL_part(5),"http:")))
280
	{
280
	{
281
		KillProcess(downloader_id); //óáèâàåì ñòàðûé ïðîöåññ
281
		KillProcess(downloader_id); //óáèâàåì ñòàðûé ïðîöåññ
282
		DeleteFile(#download_path);
282
		DeleteFile(#download_path);
283
		IF (URL[strlen(#URL)-1]=='/') URL[strlen(#URL)-1]='';
283
		IF (URL[strlen(#URL)-1]=='/') URL[strlen(#URL)-1]=NULL;
284
		downloader_id = RunProgram("/sys/network/downloader", #URL);
284
		downloader_id = RunProgram("/sys/network/downloader", #URL);
285
		//Browser Hack v2.0
285
		//Browser Hack v2.0
286
		Pause(60);
286
		Pause(60);
287
		if (GetProcessSlot(downloader_id)<>0)
287
		if (GetProcessSlot(downloader_id)<>0)
288
		{
288
		{
289
			debug("Browser Hack v2.0: Killing downloader and trying to run it one more!");
289
			debug("Browser Hack v2.0: Killing downloader and trying to run it one more!");
290
			KillProcess(downloader_id); //óáèâàåì ñòàðûé ïðîöåññ
290
			KillProcess(downloader_id); //óáèâàåì ñòàðûé ïðîöåññ
291
			downloader_id = RunProgram("/sys/network/downloader", #URL);
291
			downloader_id = RunProgram("/sys/network/downloader", #URL);
292
		}
292
		}
293
		//
293
		//
294
		IF (downloader_id<0) RunProgram("@notify", "Error running Downloader. Internet unavilable.");
294
		IF (downloader_id<0) RunProgram("@notify", "Error running Downloader. Internet unavilable.");
295
		Draw_Window();
295
		Draw_Window();
296
		return;
296
		return;
297
	}
297
	}
298
	lines.first = lines.all =0;
298
	lines.first = lines.all =0;
299
	ReadHtml(_WIN);
299
	ReadHtml(_WIN);
300
	WB1.ShowPage();
300
	WB1.ShowPage();
301
}
301
}
302
 
302
 
303
 
303
 
304
void TWebBrowser::ShowPage()
304
void TWebBrowser::ShowPage()
305
{
305
{
306
	edit1.size = edit1.pos = strlen(#editURL);
306
	edit1.size = edit1.pos = strlen(#editURL);
307
	edit1.offset=0;
307
	edit1.offset=0;
308
	edit_box_draw stdcall(#edit1); //ðèñóåì ñòðîêó àäðåñà
308
	edit_box_draw stdcall(#edit1); //ðèñóåì ñòðîêó àäðåñà
309
	
309
	
310
	if (!filesize)
310
	if (!filesize)
311
	{
311
	{
312
		DrawBar(left, top, width+4, height, 0xFFFFFF); //çàêðàøèâàåì âñ¸ äîíèçó
312
		DrawBar(left, top, width+4, height, 0xFFFFFF); //çàêðàøèâàåì âñ¸ äîíèçó
313
		if (GetProcessSlot(downloader_id)<>0) WriteText(left + 10, top + 18, 0x80, 0, "Loading...", 0);
313
		if (GetProcessSlot(downloader_id)<>0) WriteText(left + 10, top + 18, 0x80, 0, "Loading...", 0);
314
		else
314
		else
315
		{
315
		{
316
			WriteText(left + 10, top + 18, 0x80, 0, "Page not found. May be, URL contains some errors.", 0);
316
			WriteText(left + 10, top + 18, 0x80, 0, "Page not found. May be, URL contains some errors.", 0);
317
			if (!strcmp(get_URL_part(5),"http:"))) WriteText(left + 10, top + 32, 0x80, 0, "Or Internet unavilable for your configuration.", 0);
317
			if (!strcmp(get_URL_part(5),"http:"))) WriteText(left + 10, top + 32, 0x80, 0, "Or Internet unavilable for your configuration.", 0);
318
		}
318
		}
319
		//return;
319
		//return;
320
	}
320
	}
321
	else
321
	else
322
		ParseHTML(buf);
322
		ParseHTML(buf);
323
 
323
 
324
	if (!header) strcpy(#header, #version);
324
	if (!header) strcpy(#header, #version);
325
	if (!strcmp(#version, #header)) DrawTitle(#header);
325
	if (!strcmp(#version, #header)) DrawTitle(#header);
326
}
326
}
327
 
327
 
328
 
328
 
329
 
329
 
330
void TWebBrowser::ParseHTML(dword bword){
330
void TWebBrowser::ParseHTML(dword bword){
331
	word bukva[2];
331
	word bukva[2];
332
	int j, perenos_num;
332
	int j, perenos_num;
333
	byte ignor_param;
333
	byte ignor_param;
334
	char temp[768];
334
	char temp[768];
335
	
335
	
336
	stroka = -lines.first;
336
	stroka = -lines.first;
337
	stolbec = 0;
337
	stolbec = 0;
338
	
338
	
339
	for (j = 400; j < blink + 1; j++;) DeleteButton(j);
339
	for (j = 400; j < blink + 1; j++;) DeleteButton(j);
340
	blink = 400;
340
	blink = 400;
341
 
341
 
342
	b_text = i_text = u_text = s_text = blq_text = first_line_drawed =
342
	b_text = i_text = u_text = s_text = blq_text = first_line_drawed =
343
	li_text = link = ignor_text = text_color_index = text_colors[0] = li_tab = 0; //îáíóëÿåì òåãè
343
	li_text = link = ignor_text = text_color_index = text_colors[0] = li_tab = 0; //îáíóëÿåì òåãè
344
	link_color = 0x0000FF;
344
	link_color = 0x0000FF;
345
	bg_color = 0xFFFFFF;
345
	bg_color = 0xFFFFFF;
346
	line = '';
346
	line = NULL;
347
	strcpy(#page_links,"|");
347
	strcpy(#page_links,"|");
348
	strcpy(#header, #version);
348
	strcpy(#header, #version);
349
 
349
 
350
	if (pre_text<>2)
350
	if (pre_text<>2)
351
	{
351
	{
352
		pre_text=0;
352
		pre_text=0;
353
		if (!strcmp(#URL + strlen(#URL) - 4, ".txt")) pre_text = 1;
353
		if (!strcmp(#URL + strlen(#URL) - 4, ".txt")) pre_text = 1;
354
		if (!strcmp(#URL + strlen(#URL) - 4, ".mht")) ignor_text = 1;
354
		if (!strcmp(#URL + strlen(#URL) - 4, ".mht")) ignor_text = 1;
355
	}
355
	}
356
	
356
	
357
	for ( ; buf+filesize > bword; bword++;)
357
	for ( ; buf+filesize > bword; bword++;)
358
	{
358
	{
359
		bukva = ESBYTE[bword];
359
		bukva = ESBYTE[bword];
360
		if (ignor_text) && (bukva<>'<') continue;
360
		if (ignor_text) && (bukva<>'<') continue;
361
		switch (bukva)
361
		switch (bukva)
362
		{
362
		{
363
		case 0x0a:
363
		case 0x0a:
364
			if (pre_text)
364
			if (pre_text)
365
			{
365
			{
366
				bukva = temp = '';
366
				bukva = temp = NULL;
367
				goto NEXT_MARK;
367
				goto NEXT_MARK;
368
			}
368
			}
369
		case '\9':
369
		case '\9':
370
			if (pre_text) //èíà÷å èä¸ì íà 0x0d	
370
			if (pre_text) //èíà÷å èä¸ì íà 0x0d	
371
			{
371
			{
372
				tab_len=strlen(#line)/8;
372
				tab_len=strlen(#line)/8;
373
				tab_len=tab_len*8;
373
				tab_len=tab_len*8;
374
				tab_len=8+tab_len-strlen(#line);
374
				tab_len=8+tab_len-strlen(#line);
375
				for (j=0; j
375
				for (j=0; j
376
				break;
376
				break;
377
			}		
377
			}		
378
		case 0x0d:
378
		case 0x0d:
379
			bukva = ' ';
379
			bukva = ' ';
380
			goto DEFAULT_MARK;
380
			goto DEFAULT_MARK;
381
		case '=': //ïîääåðæêà øàéòàíñêîé êîäèðîâêè ñòðàíèö, ñîõðàí¸ííûõ ÷åðåç ÈÅ7
381
		case '=': //ïîääåðæêà øàéòàíñêîé êîäèðîâêè ñòðàíèö, ñîõðàí¸ííûõ ÷åðåç ÈÅ7
382
			if (strcmp(#URL + strlen(#URL) - 4, ".mht")<>0) goto DEFAULT_MARK;
382
			if (strcmp(#URL + strlen(#URL) - 4, ".mht")<>0) goto DEFAULT_MARK;
383
 
383
 
384
			bword++;
384
			bword++;
385
			bukva=ESBYTE[bword];
385
			bukva=ESBYTE[bword];
386
			strcpy(#temp,#bukva);
386
			strcpy(#temp,#bukva);
387
			bword++;
387
			bword++;
388
			bukva=ESBYTE[bword];
388
			bukva=ESBYTE[bword];
389
			strcat(#temp,#bukva);
389
			strcat(#temp,#bukva);
390
			
390
			
391
			bukva=Hex2Symb(#temp);
391
			bukva=Hex2Symb(#temp);
392
			if (bukva) goto DEFAULT_MARK;
392
			if (bukva) goto DEFAULT_MARK;
393
			break;
393
			break;
394
			
394
			
395
		case '&': //  and so on
395
		case '&': //  and so on
396
			bword++;
396
			bword++;
397
			tag=0;
397
			tag=0;
398
			for (j=0; (ESBYTE[bword]<>';') && (j<7);   j++, bword++;)
398
			for (j=0; (ESBYTE[bword]<>';') && (j<7);   j++, bword++;)
399
			{
399
			{
400
				bukva = ESBYTE[bword];
400
				bukva = ESBYTE[bword];
401
				strcat(#tag, #bukva);
401
				strcat(#tag, #bukva);
402
			}
402
			}
403
			
403
			
404
			for (j=0; unicode_tags[j]!=0; j+=2;) 
-
 
405
			{
-
 
406
				if (!strcmp(#tag, unicode_tags[j]))
-
 
407
				{
-
 
408
					strcat(#line, unicode_tags[j+1]);
-
 
409
					break 1;
-
 
410
				}
-
 
411
			}
-
 
412
			
-
 
413
			rez = atoi(#tag + 1) - 1040;
-
 
414
			if (tag[1] == '1') && (rez>=0) && (rez<=72) && (strlen(#tag) == 5)
-
 
415
			{
-
 
416
				bukva = unicode_chars[rez];
404
			bukva = GetUnicodeSymbol();
417
				//GOTO DEFAULT_MARK; //îáðàáàòûâàåì áóêâó ëó÷øå íàâåðíî strcat(#line, unicode_tags[j+1]); è break 1; 
-
 
418
				strcat(#line, #bukva);
405
			if (bukva) goto DEFAULT_MARK;
419
				break; 
-
 
420
			}
-
 
421
			
-
 
422
			strcat(#line,#tag); //âûâîäèì íà ýêðàí íåîáðàáîòàííûé òåã, òàê áðàóçåðû çà÷åì-òî äåëàþò
-
 
423
			break;
406
			break;
424
		case '<':
407
		case '<':
425
			bword++; //ïðîìîòàåì ñèìâîë <
408
			bword++; //ïðîìîòàåì ñèìâîë <
426
			tag = parametr = tagparam = ignor_param = NULL;
409
			tag = parametr = tagparam = ignor_param = NULL;
427
			if (ESBYTE[bword] == '!') //ôèëüòðàöèÿ âíóòðè , äåðçêî
410
			if (ESBYTE[bword] == '!') //ôèëüòðàöèÿ âíóòðè , äåðçêî
428
			{
411
			{
429
				bword++;
412
				bword++;
430
				if (ESBYTE[bword] == '-')
413
				if (ESBYTE[bword] == '-')
431
				{
414
				{
432
				HH_:
415
				HH_:
433
					do
416
					do
434
					{
417
					{
435
						bword++;
418
						bword++;
436
						if (buf + filesize <= bword) break 2;
419
						if (buf + filesize <= bword) break 2;
437
					}
420
					}
438
					while (ESBYTE[bword] <>'-');
421
					while (ESBYTE[bword] <>'-');
439
					
422
					
440
					bword++;
423
					bword++;
441
					if (ESBYTE[bword] <>'-') goto HH_;
424
					if (ESBYTE[bword] <>'-') goto HH_;
442
				}
425
				}
443
			}
426
			}
444
			while (ESBYTE[bword] <>'>') && (bword < buf + filesize) //ïîëó÷àåì òåã è åãî ïàðàìåòðû
427
			while (ESBYTE[bword] <>'>') && (bword < buf + filesize) //ïîëó÷àåì òåã è åãî ïàðàìåòðû
445
			{
428
			{
446
				bukva = ESBYTE[bword];
429
				bukva = ESBYTE[bword];
447
				if (bukva == '\9') || (bukva == '\x0a') || (bukva == '\x0d') bukva = ' ';
430
				if (bukva == '\9') || (bukva == '\x0a') || (bukva == '\x0d') bukva = ' ';
448
				if (!ignor_param) && (bukva <>' ')
431
				if (!ignor_param) && (bukva <>' ')
449
				{
432
				{
450
					if (strlen(#tag)
433
					if (strlen(#tag)
451
				}
434
				}
452
				else
435
				else
453
				{
436
				{
454
					ignor_param = true;
437
					ignor_param = true;
455
					if (!ignor_text) && (strlen(#tagparam)+1
438
					if (!ignor_text) && (strlen(#tagparam)+1
456
				}
439
				}
457
				bword++;
440
				bword++;
458
			}
441
			}
459
			strlwr(#tag);
442
			strlwr(#tag);
460
			strlwr(#tagparam);
443
			strlwr(#tagparam);
461
 
444
 
462
			if (tag[strlen(#tag)-1]=='/') tag[strlen(#tag)-1]=NULL; //for br/
445
			if (tag[strlen(#tag)-1]=='/') tag[strlen(#tag)-1]=NULL; //for br/
463
			if (tagparam) && (strlen(#tagparam) < 4000) GetNextParam();
446
			if (tagparam) && (strlen(#tagparam) < 4000) GetNextParam();
464
 
447
 
465
			if (stolbec + strlen(#line) > lines.column_max)
448
			if (stolbec + strlen(#line) > lines.column_max)
466
			{
449
			{
467
				perenos_num = strrchr(#line, ' ');
450
				perenos_num = strrchr(#line, ' ');
468
				if (!perenos_num) && (strlen(#line)>lines.column_max) perenos_num=lines.column_max;
451
				if (!perenos_num) && (strlen(#line)>lines.column_max) perenos_num=lines.column_max;
469
				strcpy(#temp, #line + perenos_num); //ïåðåíîñ ïî ñëîâàì
452
				strcpy(#temp, #line + perenos_num); //ïåðåíîñ ïî ñëîâàì
470
				line[perenos_num] = 0x00;
453
				line[perenos_num] = 0x00;
471
				if (stroka >= lines.visible) && (lines.first <>0) break 1; //óõîäèì...
454
				if (stroka >= lines.visible) && (lines.first <>0) break 1; //óõîäèì...
472
				DrawPage();
455
				DrawPage();
473
				strcpy(#line, #temp);
456
				strcpy(#line, #temp);
474
				
457
				
475
				TextGoDown(left + 5, stroka * 10 + top + 5, width - 20); //çàêðàøèâàåì ñëåäóùóþ ñòðîêó
458
				TextGoDown(left + 5, stroka * 10 + top + 5, width - 20); //çàêðàøèâàåì ñëåäóùóþ ñòðîêó
476
			}
459
			}
477
			DrawPage();
460
			DrawPage();
478
			line=NULL;
461
			line=NULL;
479
 
462
 
480
			if (tag) WhatTextStyle(left + 5, stroka * 10 + top + 5, width - 20); //îáðàáîòêà òåãîâ
463
			if (tag) WhatTextStyle(left + 5, stroka * 10 + top + 5, width - 20); //îáðàáîòêà òåãîâ
481
 
464
 
482
			tag = parametr = tagparam = ignor_param = NULL;
465
			tag = parametr = tagparam = ignor_param = NULL;
483
			break;
466
			break;
484
		default:
467
		default:
485
			DEFAULT_MARK:
468
			DEFAULT_MARK:
486
			if (!pre_text) && (bukva == ' ')
469
			if (!pre_text) && (bukva == ' ')
487
			{
470
			{
488
				if (line[strlen(#line)-1]==' ') break; //óáðàòü 2 ïðîáåëà ïîäðÿä
471
				if (line[strlen(#line)-1]==' ') break; //óáðàòü 2 ïðîáåëà ïîäðÿä
489
				if (!stolbec) && (!line) break; //ñòðîêà íå ìîæåò íà÷èíàòüñÿ ñ ïðîáåëà
472
				if (!stolbec) && (!line) break; //ñòðîêà íå ìîæåò íà÷èíàòüñÿ ñ ïðîáåëà
490
			}
473
			}
491
			if (strlen(#line)
474
			if (strlen(#line)
492
 
475
 
493
			if (stolbec + strlen(#line) > lines.column_max)
476
			if (stolbec + strlen(#line) > lines.column_max)
494
			{
477
			{
495
			NEXT_MARK:
478
			NEXT_MARK:
496
				perenos_num = strrchr(#line, ' ');
479
				perenos_num = strrchr(#line, ' ');
497
				if (!perenos_num) && (strlen(#line)>lines.column_max) perenos_num=lines.column_max;
480
				if (!perenos_num) && (strlen(#line)>lines.column_max) perenos_num=lines.column_max;
498
				strcpy(#temp, #line + perenos_num); //ïåðåíîñ ïî ñëîâàì
481
				strcpy(#temp, #line + perenos_num); //ïåðåíîñ ïî ñëîâàì
499
				line[perenos_num] = 0x00;
482
				line[perenos_num] = 0x00;
500
				if (stroka >= lines.visible) && (lines.first <>0) break 1; //óõîäèì...
483
				if (stroka >= lines.visible) && (lines.first <>0) break 1; //óõîäèì...
501
				DrawPage();
484
				DrawPage();
502
				strcpy(#line, #temp);
485
				strcpy(#line, #temp);
503
				
486
				
504
				TextGoDown(left + 5, stroka * 10 + top + 5, width - 20); //çàêðàøèâàåì ñëåäóùóþ ñòðîêó
487
				TextGoDown(left + 5, stroka * 10 + top + 5, width - 20); //çàêðàøèâàåì ñëåäóùóþ ñòðîêó
505
			}
488
			}
506
		}
489
		}
507
	}
490
	}
508
 
491
 
509
	DrawPage(); //ðèñóåò ïîñëåäíþþ ñòðîêó, ïîòîì ýòî íàäî óáðàòü, îïòèìèçèðîâàâ êîä
492
	DrawPage(); //ðèñóåò ïîñëåäíþþ ñòðîêó, ïîòîì ýòî íàäî óáðàòü, îïòèìèçèðîâàâ êîä
510
	if (lines.visible * 10 + 25 <= height)
493
	if (lines.visible * 10 + 25 <= height)
511
		DrawBar(left, lines.visible * 10 + top + 25, width - 15, -lines.visible * 10 + height - 25, bg_color);
494
		DrawBar(left, lines.visible * 10 + top + 25, width - 15, -lines.visible * 10 + height - 25, bg_color);
512
	if (stroka * 10 + 15 <= height)
495
	if (stroka * 10 + 15 <= height)
513
		DrawBar(left, stroka * 10 + top + 15, width - 15, -stroka * 10 + height - 15, bg_color); //çàêðàøèâàåì âñ¸ äî êîíöà
496
		DrawBar(left, stroka * 10 + top + 15, width - 15, -stroka * 10 + height - 15, bg_color); //çàêðàøèâàåì âñ¸ äî êîíöà
514
	if (lines.first == 0) lines.all = stroka;
497
	if (lines.first == 0) lines.all = stroka;
515
	if (anchor)
498
	if (anchor)
516
	{
499
	{
517
		//åñëè ïîñðåäè òåêñòà ïîÿâèòñÿ íîâûé ÿêîðü - áóäåò áåñêîíå÷íûé öèêë
500
		//åñëè ïîñðåäè òåêñòà ïîÿâèòñÿ íîâûé ÿêîðü - áóäåò áåñêîíå÷íûé öèêë
518
		anchor='';
501
		anchor=NULL;
519
		lines.first=anchor_line_num;
502
		lines.first=anchor_line_num;
520
		ParseHTML(buf);
503
		ParseHTML(buf);
521
	}
504
	}
522
 
505
 
523
	DrawScroller();
506
	DrawScroller();
524
}
507
}
525
 
508
 
526
void TWebBrowser::DrawPage() //ðåçàòü çäåñü!!1!
509
void TWebBrowser::DrawPage() //ðåçàòü çäåñü!!1!
527
{
510
{
528
	int start_x, start_y, line_length;
511
	int start_x, start_y, line_length;
529
	char temp[sizeof(line)];
512
	char temp[sizeof(line)];
530
	
513
	
531
	if (!header) //&& (tag) 
514
	if (!header) //&& (tag) 
532
	{
515
	{
533
		if (strlen(#version)+strlen(#line)+2>sizeof(header))
516
		if (strlen(#version)+strlen(#line)+2>sizeof(header))
534
		{
517
		{
535
			strcpy(#temp, #line);
518
			strcpy(#temp, #line);
536
			temp[sizeof(header)-strlen(#version)-2]=0;
519
			temp[sizeof(header)-strlen(#version)-2]=0;
537
			strcpy(#header, #temp);
520
			strcpy(#header, #temp);
538
			strcpy(#line, #line+strlen(#temp));
521
			strcpy(#line, #line+strlen(#temp));
539
		}
522
		}
540
		else
523
		else
541
		{
524
		{
542
			strcpy(#header, #line);
525
			strcpy(#header, #line);
543
			line=0;
526
			line=0;
544
		}
527
		}
545
			
528
			
546
		strcat(#header, " -");
529
		strcat(#header, " -");
547
		strcat(#header, #version);
530
		strcat(#header, #version);
548
		return;
531
		return;
549
	}
532
	}
550
	
533
	
551
	if (stroka >= 0) && (stroka - 2 < lines.visible) && (line) && (!anchor)
534
	if (stroka >= 0) && (stroka - 2 < lines.visible) && (line) && (!anchor)
552
	{
535
	{
553
		if (!stroka) && (!stolbec)
536
		if (!stroka) && (!stolbec)
554
		{
537
		{
555
			DrawBar(left, top, width-15, 15, bg_color); //çàêðàøèâàåì ïåðâóþ ñòðîêó
538
			DrawBar(left, top, width-15, 15, bg_color); //çàêðàøèâàåì ïåðâóþ ñòðîêó
556
			first_line_drawed=1;
539
			first_line_drawed=1;
557
		}
540
		}
558
		
541
		
559
		start_x=stolbec * 6 + left+5;
542
		start_x=stolbec * 6 + left+5;
560
		start_y=stroka * 10 + top + 5;
543
		start_y=stroka * 10 + top + 5;
561
		line_length=strlen(#line)*6;
544
		line_length=strlen(#line)*6;
562
 
545
 
563
		if (use_truetype == 1)
546
		if (use_truetype == 1)
564
		{
547
		{
565
			//line_length =  get_length stdcall (#line,-1,16,line_length);
548
			//line_length =  get_length stdcall (#line,-1,16,line_length);
566
			text_out stdcall (#line, #fontlol, 17, text_colors[text_color_index], start_x, start_y-3);
549
			text_out stdcall (#line, #fontlol, 17, text_colors[text_color_index], start_x, start_y-3);
567
		}
550
		}
568
		else
551
		else
569
		{
552
		{
570
			WriteText(start_x, start_y, 0x80, text_colors[text_color_index], #line, 0);
553
			WriteText(start_x, start_y, 0x80, text_colors[text_color_index], #line, 0);
571
			IF (b_text)	{ $add ebx, 1<<16   $int 0x40 }
554
			IF (b_text)	{ $add ebx, 1<<16   $int 0x40 }
572
		}
555
		}
573
		IF (i_text) Skew(start_x, start_y, line_length+6, 10);
556
		IF (i_text) Skew(start_x, start_y, line_length+6, 10);
574
		IF (s_text) DrawBar(start_x, start_y + 4, line_length, 1, text_colors[text_color_index]);
557
		IF (s_text) DrawBar(start_x, start_y + 4, line_length, 1, text_colors[text_color_index]);
575
		IF (u_text) DrawBar(start_x, start_y + 8, line_length, 1, text_colors[text_color_index]);
558
		IF (u_text) DrawBar(start_x, start_y + 8, line_length, 1, text_colors[text_color_index]);
576
		IF (link) {
559
		IF (link) {
577
			DefineButton(start_x-2, start_y, line_length + 3, 9, blink + BT_HIDE, 0xB5BFC9);
560
			DefineButton(start_x-2, start_y, line_length + 3, 9, blink + BT_HIDE, 0xB5BFC9);
578
			DrawBar(start_x, start_y + 8, line_length, 1, text_colors[text_color_index]);
561
			DrawBar(start_x, start_y + 8, line_length, 1, text_colors[text_color_index]);
579
		}
562
		}
580
		stolbec += strlen(#line);
563
		stolbec += strlen(#line);
581
	}
564
	}
582
}
565
}
583
 
566
 
584
 
567
 
585
char oldtag[100];
568
char oldtag[100];
586
void TWebBrowser::WhatTextStyle(int left1, top1, width1) {
569
void TWebBrowser::WhatTextStyle(int left1, top1, width1) {
587
	dword hr_color;
570
	dword hr_color;
588
 
571
 
589
    dword image;
572
    dword image;
590
    char temp[4096], alt[4096];
573
    char temp[4096], alt[4096];
591
    int w=0, h=0, img_lines_first=0;
574
    int w=0, h=0, img_lines_first=0;
592
 
575
 
593
	//ïðîâåðÿåì òåã îòêðûâàåòñÿ èëè çàêðûâàåòñÿ
576
	//ïðîâåðÿåì òåã îòêðûâàåòñÿ èëè çàêðûâàåòñÿ
594
	if (tag[0] == '/') 
577
	if (tag[0] == '/') 
595
	{
578
	{
596
		rez = 0;
579
		 rez = 0;
597
		strcpy(#tag, #tag+1);
580
		 strcpy(#tag, #tag+1);
598
	}
581
	}
599
	else
582
	else rez = 1;
600
		rez = 1;
-
 
601
		
583
		
602
	if (!chTag("html")) {
584
	if (!chTag("html"))
-
 
585
	{
603
		IF(!strcmp(#URL + strlen(#URL) - 4, ".mht")) IF (rez==0) ignor_text = 1; ELSE ignor_text = 0;
586
		IF(!strcmp(#URL + strlen(#URL) - 4, ".mht")) IF (rez==0) ignor_text = 1; ELSE ignor_text = 0;
604
		return;
587
		return;
605
	}
588
	}
606
 
589
 
607
	if (!chTag("script")) || (!chTag("style")) || (!chTag("binary")) ignor_text = rez;
590
	if (!chTag("script")) || (!chTag("style")) || (!chTag("binary")) ignor_text = rez;
608
 
591
 
609
	if(!chTag("title"))
592
	if(!chTag("title"))
610
	{
593
	{
611
		if (rez)
594
		if (rez) header=NULL;
612
		{
-
 
613
			header=0;
-
 
614
		}
595
		else if (!stroka) DrawTitle(#header); //òåã çàêðûëñÿ - âûâåëè ñòðîêó
615
		else //òåã çàêðûëñÿ - âûâåëè ñòðîêó
-
 
616
		{
596
		return;
617
			if (stroka==0) DrawTitle(#header);
-
 
618
		}
-
 
619
		return;
-
 
620
	}
597
	}
621
 
598
 
622
	if (ignor_text) return;
599
	if (ignor_text) return;
623
 
600
 
624
 
601
 
625
 
602
 
626
	
603
	
627
	IF(!chTag("q")) strcat(#line, "\"");
604
	IF(!chTag("q")) strcat(#line, "\"");
628
 
605
 
629
 
606
 
630
	if (anchor) && (!strcmp(#parametr, "id=")) //î÷åíü ïëîõî!!! ïîòîìó ÷òî åñëè íå ïîñëåäíèé òåã, ðàáîòàòü íå áóäåò
607
	if (anchor) && (!strcmp(#parametr, "id=")) //î÷åíü ïëîõî!!! ïîòîìó ÷òî åñëè íå ïîñëåäíèé òåã, ðàáîòàòü íå áóäåò
631
	{
608
	{
632
		if (!strcmp(#anchor, #options))
609
		if (!strcmp(#anchor, #options))	anchor_line_num=lines.first+stroka;
633
		{
-
 
634
			anchor_line_num=lines.first+stroka;
-
 
635
		}
610
	}
636
	}
-
 
637
	
611
	
638
	if (!chTag("body"))
612
	if (!chTag("body"))
639
	{
613
	{
640
		BODY_MARK:
614
		do{
641
		
615
			if (!strcmp(#parametr, "link=")) link_color = GetColor(#options);
642
		if (!strcmp(#parametr, "link="))
-
 
643
			link_color = GetColor(#options);
-
 
644
		
616
			if (!strcmp(#parametr, "text=")) text_colors[0]=GetColor(#options);
645
		if (!strcmp(#parametr, "text="))
-
 
646
			text_colors[0]=GetColor(#options);
-
 
647
		
617
			if (!strcmp(#parametr, "bgcolor=")) bg_color=GetColor(#options);
648
		if (!strcmp(#parametr, "bgcolor="))
-
 
649
			bg_color=GetColor(#options);
618
		} while(GetNextParam());
650
		
-
 
651
		IF(tagparam)
-
 
652
		{
-
 
653
			GetNextParam();
-
 
654
			GOTO BODY_MARK;
619
		
655
		}
-
 
656
		
-
 
657
		return;
620
		return;
658
	}
621
	}
659
 
622
 
660
	if (!chTag("a"))
623
	if (!chTag("a"))
661
	{
624
	{
662
		if (rez)
625
		if (rez)
663
		{
626
		{
664
			 
627
			if (link) IF(text_color_index > 0) text_color_index--; //åñëè ïðåäûäóùèé òåã à íå áûë çàêðûò
665
			if (link) IF(text_color_index > 0) text_color_index--; //åñëè ïðåäûäóùèé òåã à íå áûë çàêðûò
-
 
666
 
628
 
667
			_A_MARK:
629
			do{
668
			if (!strcmp(#parametr, "href="))
630
				if (!strcmp(#parametr, "href="))
669
			{
631
				{
670
				if (stroka - 1 > lines.visible) || (stroka < -2) return;
632
					if (stroka - 1 > lines.visible) || (stroka < -2) return;
671
				
633
					
672
				text_color_index++;
634
					text_color_index++;
673
				text_colors[text_color_index] = text_colors[text_color_index-1];
635
					text_colors[text_color_index] = text_colors[text_color_index-1];
674
				
636
					
675
				link = 1;
637
					link = 1;
676
				blink++;
638
					blink++;
677
				text_colors[text_color_index] = link_color;
639
					text_colors[text_color_index] = link_color;
678
				strcat(#page_links, #options);
640
					strcat(#page_links, #options);
679
				strcat(#page_links, "|");
641
					strcat(#page_links, "|");
680
			}
642
				}
681
			if (anchor) && (!strcmp(#parametr, "name="))
643
				if (anchor) && (!strcmp(#parametr, "name="))
682
			{
644
				{
683
				if (!strcmp(#anchor, #options))
645
					if (!strcmp(#anchor, #options))
684
				{
646
					{
685
					anchor_line_num=lines.first+stroka;
647
						anchor_line_num=lines.first+stroka;
686
				}
648
					}
687
			}
649
				}
688
			if (tagparam)
650
			} while(GetNextParam());
689
			{
-
 
690
				GetNextParam();
-
 
691
				GOTO _A_MARK;
651
		}
692
			}
-
 
693
		}
-
 
694
		else {
652
		else {
695
			link = 0;
653
			link = 0;
696
			IF(text_color_index > 0) text_color_index--;
654
			IF(text_color_index > 0) text_color_index--;
697
		}
655
		}
698
		return;
656
		return;
699
	}
657
	}
700
 
658
 
701
 
659
 
702
	if (!chTag("font"))
660
	if (!chTag("font"))
703
	{
661
	{
704
		if (rez)
662
		if (rez)
705
		{
663
		{
706
			text_color_index++;
664
			text_color_index++;
707
			text_colors[text_color_index] = text_colors[text_color_index-1];
665
			text_colors[text_color_index] = text_colors[text_color_index-1];
708
		
666
		
709
			COL_MARK:
667
			do{
710
			if (strcmp(#parametr, "color=") == 0) //&& (parametr[1] == '#')
668
				if (strcmp(#parametr, "color=") == 0) //&& (parametr[1] == '#')
711
			{
669
				{
712
				text_colors[text_color_index] = GetColor(#options);
670
					text_colors[text_color_index] = GetColor(#options);
713
			}
671
				}
714
			IF(tagparam) {
672
			} while(GetNextParam());
715
				GetNextParam();
-
 
716
				GOTO COL_MARK;
673
		}
717
			}
-
 
718
		}
-
 
719
		else
674
		else
720
			if (text_color_index > 0) text_color_index--;
675
			if (text_color_index > 0) text_color_index--;
721
		return;
676
		return;
722
	}
677
	}
723
 
678
 
724
	if(!chTag("tr")) || (!chTag("br")) {
679
	if(!chTag("tr")) || (!chTag("br")) {
725
		TextGoDown(left1, top1, width1);
680
		TextGoDown(left1, top1, width1);
726
		return;
681
		return;
727
	}
682
	}
728
	if (!chTag("div")) {
683
	if (!chTag("div")) {
729
		IF(oldtag[0] <>'h') TextGoDown(left1, top1, width1);
684
		IF(oldtag[0] <>'h') TextGoDown(left1, top1, width1);
730
		return;
685
		return;
731
	}
686
	}
732
	if (!chTag("p")) {
687
	if (!chTag("p")) {
733
		IF(oldtag[0] == 'h') return;
688
		IF(oldtag[0] == 'h') return;
734
		TextGoDown(left1, top1, width1);
689
		TextGoDown(left1, top1, width1);
735
		IF(rez) TextGoDown(left1, top1 + 10, width1);
690
		IF(rez) TextGoDown(left1, top1 + 10, width1);
736
		return;
691
		return;
737
	}
692
	}
738
 
693
 
739
	if (!chTag("h1")) || (!chTag("h2")) || (!chTag("h3")) || (!chTag("h4")) {
694
	if (!chTag("h1")) || (!chTag("h2")) || (!chTag("h3")) || (!chTag("h4")) {
740
		TextGoDown(left1, top1, width1);
695
		TextGoDown(left1, top1, width1);
741
		IF(rez) TextGoDown(left1, top1 + 10, width1);
696
		IF(rez) TextGoDown(left1, top1 + 10, width1);
742
		b_text = rez;
697
		b_text = rez;
743
		strcpy(#oldtag, #tag);
698
		strcpy(#oldtag, #tag);
744
		return;
699
		return;
745
	}
700
	}
746
	else
701
	else
747
		oldtag='';
702
		oldtag=NULL;
748
		
703
		
749
	if (!chTag("b")) || (!chTag("strong")) || (!chTag("big")) {
704
	if (!chTag("b")) || (!chTag("strong")) || (!chTag("big")) {
750
		b_text = rez;
705
		b_text = rez;
751
		return;
706
		return;
752
	}
707
	}
753
	////////////////////////////
708
	////////////////////////////
754
	if(!chTag("i")) || (!chTag("em")) || (!chTag("subtitle")) {
709
	if(!chTag("i")) || (!chTag("em")) || (!chTag("subtitle")) {
755
		i_text = rez;
710
		i_text = rez;
756
		return;
711
		return;
757
	}	
712
	}	
758
	////////////////////////////
713
	////////////////////////////
759
	if (!chTag("dt"))
714
	if (!chTag("dt"))
760
	{
715
	{
761
		li_text = rez;
716
		li_text = rez;
762
		IF(rez == 0) return;
717
		IF(rez == 0) return;
763
		TextGoDown(left1, top1, width1);
718
		TextGoDown(left1, top1, width1);
764
		return;
719
		return;
765
	}
720
	}
766
	/////////////////////////////
721
	/////////////////////////////
767
	if(!chTag("li")) || (!chTag("dt")) //íàäî ñäåëàòü âëîæåííûå ñïèñêè
722
	if(!chTag("li")) || (!chTag("dt")) //íàäî ñäåëàòü âëîæåííûå ñïèñêè
768
	{
723
	{
769
		li_text = rez;
724
		li_text = rez;
770
		IF(rez == 0) return;
725
		IF(rez == 0) return;
771
		TextGoDown(left1, top1, width1);
726
		TextGoDown(left1, top1, width1);
772
		IF(stroka > -1) && (stroka - 2 < lines.visible) DrawBar(li_tab * 5 * 6 + left1 - 5, top1 + 12, 2, 2, 0);
727
		IF(stroka > -1) && (stroka - 2 < lines.visible) DrawBar(li_tab * 5 * 6 + left1 - 5, top1 + 12, 2, 2, 0);
773
		return;
728
		return;
774
	}
729
	}
775
	////////////////////////////
730
	////////////////////////////
776
	IF(!chTag("u")) || (!chTag("ins")) u_text = rez;
731
	IF(!chTag("u")) || (!chTag("ins")) u_text = rez;
777
	IF(!chTag("s")) || (!chTag("strike")) || (!chTag("del")) s_text = rez;
732
	IF(!chTag("s")) || (!chTag("strike")) || (!chTag("del")) s_text = rez;
778
	IF(!chTag("ul")) || (!chTag("ol")) IF(!rez) {
733
	IF(!chTag("ul")) || (!chTag("ol")) IF(!rez) {
779
		li_text = rez;
734
		li_text = rez;
780
		li_tab--;
735
		li_tab--;
781
		TextGoDown(left1, top1, width1);
736
		TextGoDown(left1, top1, width1);
782
	} ELSE li_tab++;
737
	} ELSE li_tab++;
783
	IF(!chTag("dd")) stolbec += 5;
738
	IF(!chTag("dd")) stolbec += 5;
784
	IF(!chTag("blockquote")) blq_text = rez;
739
	IF(!chTag("blockquote")) blq_text = rez;
785
	IF(!chTag("pre")) pre_text = rez; 
740
	IF(!chTag("pre")) pre_text = rez; 
786
	IF(!chTag("hr")) {
741
	IF(!chTag("hr")) {
787
		TextGoDown(left1, top1, width1);
742
		TextGoDown(left1, top1, width1);
788
		TextGoDown(left1, top1 + 10, width1);
743
		TextGoDown(left1, top1 + 10, width1);
789
		IF(strcmp(#parametr, "color=") == 0) hr_color = GetColor(#options);
744
		IF(strcmp(#parametr, "color=") == 0) hr_color = GetColor(#options);
790
		ELSE hr_color = 0x999999;
745
		ELSE hr_color = 0x999999;
791
		IF(stroka > 0) DrawBar(left1, top1 + 14, width1 - 8, 1, hr_color);
746
		IF(stroka > 0) DrawBar(left1, top1 + 14, width1 - 8, 1, hr_color);
792
	}
747
	}
793
 
748
 
794
	if (!chTag("img"))
749
	if (!chTag("img"))
795
	{
750
	{
796
		if (GetFileInfo(libimg)<>0) return;  //åñëè áèáëèîòåêè íåò
751
		if (GetFileInfo(libimg)<>0) return;  //åñëè áèáëèîòåêè íåò
797
		IMG_TAG:
752
		do{
798
			if (!strcmp(#parametr,"src="))   //íàäî îáúåäèíèòü ñ GetNewUrl()
753
			if (!strcmp(#parametr,"src="))   //íàäî îáúåäèíèòü ñ GetNewUrl()
799
			{
754
			{
800
				if (downloader_id) strcpy(#temp, #history_list[history_current-1].Item);
755
				if (downloader_id) strcpy(#temp, #history_list[history_current-1].Item);
801
					else strcpy(#temp, BrowserHistory.CurrentUrl()); //äîñòà¸ì àäðåñ òåêóùåé ñòðàíèöû
756
					else strcpy(#temp, BrowserHistory.CurrentUrl()); //äîñòà¸ì àäðåñ òåêóùåé ñòðàíèöû
802
				if (strcmpn(#temp, "http:", 5)!=0) || (strcmpn(#options, "http:", 5)!=0)
757
				if (strcmpn(#temp, "http:", 5)!=0) || (strcmpn(#options, "http:", 5)!=0)
803
				{
758
				{
804
					temp[strrchr(#temp, '/')] = 0x00; //îáðåçàåì å¸ óðë äî ïîñëåäíåãî /
759
					temp[strrchr(#temp, '/')] = 0x00; //îáðåçàåì å¸ óðë äî ïîñëåäíåãî /
805
					strcat(#temp, #options);
760
					strcat(#temp, #options);
806
					image=load_image(#temp);
761
					image=load_image(#temp);
807
					w=DSWORD[image+4];
762
					w=DSWORD[image+4];
808
					h=DSWORD[image+8];
763
					h=DSWORD[image+8];
809
				}
764
				}
810
			}
765
			}
811
  			if (!strcmp(#parametr,"alt="))
766
  			if (!strcmp(#parametr,"alt="))
812
			{
767
			{
813
				strcpy(#alt, "[");
768
				strcpy(#alt, "[");
814
				strcat(#alt, #options);
769
				strcat(#alt, #options);
815
				strcat(#alt, "]");
770
				strcat(#alt, "]");
816
			}
771
			}
817
 
772
 
818
		IF(tagparam)
-
 
819
		{
-
 
820
			GetNextParam();
773
		} while(GetNextParam());
821
			GOTO IMG_TAG;
-
 
822
		}
-
 
823
		
774
		
824
		if (!image) 
775
		if (!image) 
825
		{
776
		{
826
			if (alt) && (link) strcat(#line, #alt);
777
			if (alt) && (link) strcat(#line, #alt);
827
			return;
778
			return;
828
		}
779
		}
829
		
780
		
830
		if (w>width1) w=width1;
781
		if (w>width1) w=width1;
831
		
782
		
832
		if (stroka==0) DrawBar(left, top, width-15, 15, bg_color); //çàêðàøèâàåì ïåðâóþ ñòðîêó
783
		if (stroka==0) DrawBar(left, top, width-15, 15, bg_color); //çàêðàøèâàåì ïåðâóþ ñòðîêó
833
		stroka+=h/10;
784
		stroka+=h/10;
834
		if (top1+hWB1.top+WB1.height-10) return; //åñëè ÂѨ èçîáðàæåíèå óøëî ÂÅÐÕ èëè ÂÍÈÇ
785
		if (top1+hWB1.top+WB1.height-10) return; //åñëè ÂѨ èçîáðàæåíèå óøëî ÂÅÐÕ èëè ÂÍÈÇ
835
		if (top1
786
		if (top1
836
		{
787
		{
837
			DrawBar(left, top, width-15, 10, bg_color); //çàêðàøèâàåì ïåðâóþ ñòðîêó
788
			DrawBar(left, top, width-15, 10, bg_color); //çàêðàøèâàåì ïåðâóþ ñòðîêó
838
			img_lines_first=WB1.top-top1;
789
			img_lines_first=WB1.top-top1;
839
			h=h-img_lines_first;
790
			h=h-img_lines_first;
840
			top1=WB1.top;
791
			top1=WB1.top;
841
		}
792
		}
842
		if (top1>WB1.top+WB1.height-h-15) //åñëè ÷àñòü èçîáðàæåíèÿ ñíèçó
793
		if (top1>WB1.top+WB1.height-h-15) //åñëè ÷àñòü èçîáðàæåíèÿ ñíèçó
843
		{
794
		{
844
			h=WB1.top+WB1.height-top1-15;
795
			h=WB1.top+WB1.height-top1-15;
845
		}	
796
		}	
846
		if (h<=0) return;
797
		if (h<=0) return;
847
		if (anchor) return;
798
		if (anchor) return;
848
		
799
		
849
		img_draw stdcall (image,left1-5,top1+10,w, h,0,img_lines_first);
800
		img_draw stdcall (image,left1-5,top1+10,w, h,0,img_lines_first);
850
		DrawBar(left1+w - 5, top1 + 10, width1-w + 5, h, bg_color);
801
		DrawBar(left1+w - 5, top1 + 10, width1-w + 5, h, bg_color);
851
		IF (link) DefineButton(left1 - 5, top1+10, w, h, blink + BT_HIDE, 0xB5BFC9);
802
		IF (link) DefineButton(left1 - 5, top1+10, w, h, blink + BT_HIDE, 0xB5BFC9);
852
		return;
803
		return;
853
	}
804
	}
854
 
805
 
855
	if (!chTag("meta")) || (!chTag("?xml"))
806
	if (!chTag("meta")) || (!chTag("?xml"))
856
	{
807
	{
857
		META:
808
		do{
858
		if (!strcmp(#parametr, "charset=")) || (!strcmp(#parametr, "content=")) || (!strcmp(#parametr, "encoding="))
809
			if (!strcmp(#parametr, "charset=")) || (!strcmp(#parametr, "content=")) || (!strcmp(#parametr, "encoding="))
859
		{
810
			{
860
			strcpy(#options, #options[strrchr(#options, '=')]); //ïîèñê â content=
811
				strcpy(#options, #options[strrchr(#options, '=')]); //ïîèñê â content=
861
 
812
 
862
			if (!strcmp(#options,"utf-8"))   || (!strcmp(#options,"utf8"))      ReadHtml(_UTF);
813
				if (!strcmp(#options,"utf-8"))   || (!strcmp(#options,"utf8"))      ReadHtml(_UTF);
863
			if (!strcmp(#options, "koi8-r")) || (!strcmp(#options, "koi8-u"))   ReadHtml(_KOI);
814
				if (!strcmp(#options, "koi8-r")) || (!strcmp(#options, "koi8-u"))   ReadHtml(_KOI);
864
			if (!strcmp(#options, "dos"))    || (!strcmp(#options, "cp-866"))   ReadHtml(_DOS);
815
				if (!strcmp(#options, "dos"))    || (!strcmp(#options, "cp-866"))   ReadHtml(_DOS);
865
		}
816
			}
866
		if (tagparam)
817
		} while(GetNextParam());
867
		{
-
 
868
			GetNextParam();
-
 
869
			goto META;
818
		return;
870
		}
-
 
871
		return;
-
 
872
	}
819
	}
873
}
820
}
874
 
821
 
875
 
822
 
876
void TextGoDown(int left1, top1, width1)
823
void TextGoDown(int left1, top1, width1)
877
{
824
{
878
	if (!stroka) && (!stolbec) && (!first_line_drawed)
825
	if (!stroka) && (!stolbec) && (!first_line_drawed)
879
	{
826
	{
880
		DrawBar(WB1.left, WB1.top, WB1.width-15, 15, bg_color); //çàêðàøèâàåì ïåðâóþ ñòðîêó
827
		DrawBar(WB1.left, WB1.top, WB1.width-15, 15, bg_color); //çàêðàøèâàåì ïåðâóþ ñòðîêó
881
		first_line_drawed=1;
828
		first_line_drawed=1;
882
	}
829
	}
883
	stroka++;
830
	stroka++;
884
	if (blq_text) stolbec = 8;
831
	if (blq_text) stolbec = 8;
885
	ELSE stolbec = 0;
832
	ELSE stolbec = 0;
886
	if (li_text) stolbec = li_tab * 5;
833
	if (li_text) stolbec = li_tab * 5;
887
	IF(stroka >= 0) && (stroka - 2 < lines.visible)  && (!anchor) DrawBar(left1 - 5, top1 + 10, width1 + 5, 10, bg_color);
834
	IF(stroka >= 0) && (stroka - 2 < lines.visible)  && (!anchor) DrawBar(left1 - 5, top1 + 10, width1 + 5, 10, bg_color);
888
}
835
}
889
 
836
 
890
 
837
 
891
//ñêðîëë
838
//ñêðîëë
892
void TWebBrowser::DrawScroller() //íå îïòèìàëüíàÿ îòðèñîâêà, íî çàòî â îäíîì ìåñòå
839
void TWebBrowser::DrawScroller() //íå îïòèìàëüíàÿ îòðèñîâêà, íî çàòî â îäíîì ìåñòå
893
{
840
{
894
	scroll1.max_area = lines.all;
841
	scroll1.max_area = lines.all;
895
	scroll1.cur_area = lines.visible;
842
	scroll1.cur_area = lines.visible;
896
	scroll1.position = lines.first;
843
	scroll1.position = lines.first;
897
 
844
 
898
	scroll1.all_redraw=1;
845
	scroll1.all_redraw=1;
899
	scroll1.start_x=Form.width-28; //left + width - 15
846
	scroll1.start_x=Form.width-28; //left + width - 15
900
	scroll1.size_y=WB1.height;
847
	scroll1.size_y=WB1.height;
901
 
848
 
902
	scrollbar_v_draw(#scroll1);
849
	scrollbar_v_draw(#scroll1);
903
}
850
}
904
>
851
>
905
>
852
>