Subversion Repositories Kolibri OS

Rev

Rev 4692 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 4692 Rev 4718
1
dword bufpointer;
1
dword bufpointer;
2
dword o_bufpointer;
2
dword o_bufpointer;
3
dword bufsize;
3
dword bufsize;
4
 
4
 
5
#define URL param
5
#define URL param
6
 
6
 
7
scroll_bar scroll_wv = { 15,200,398,44,0,2,115,15,0,0xeeeeee,0xBBBbbb,0xeeeeee,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1};
7
scroll_bar scroll_wv = { 15,200,398,44,0,2,115,15,0,0xeeeeee,0xBBBbbb,0xeeeeee,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1};
8
 
8
 
9
char header[2048];
9
char header[2048];
10
 
10
 
11
struct TWebBrowser {
11
struct TWebBrowser {
12
	llist list;
12
	llist list;
13
	DrawBufer DrawBuf;
13
	DrawBufer DrawBuf;
14
	void Prepare();
14
	void Prepare();
15
	void Parse();
15
	void Parse();
16
	void SetTextStyle();
16
	void SetTextStyle();
17
	void DrawPage();
17
	void DrawPage();
18
	void DrawScroller();
18
	void DrawScroller();
19
	void NewLine();
19
	void NewLine();
-
 
20
	void Perenos();
-
 
21
	byte end_parsing;
20
} WB1;
22
} WB1;
21
 
23
 
22
byte b_text, i_text, u_text, s_text, pre_text, blq_text, li_text, li_tab, 
24
byte b_text, i_text, u_text, s_text, pre_text, blq_text, li_text, li_tab, 
23
	link, ignor_text, cur_encoding, text_align, t_html, t_body;
25
	link, ignor_text, cur_encoding, text_align, t_html, t_body;
24
byte condition_text_active, condition_text_val, condition_href, condition_max;
26
byte condition_text_active, condition_text_val, condition_href, condition_max;
25
 
27
 
26
enum { _WIN, _DOS, _KOI, _UTF, _DEFAULT };
28
enum { _WIN, _DOS, _KOI, _UTF, _DEFAULT };
27
 
29
 
28
enum { ALIGN_LEFT, ALIGN_CENTER, ALIGN_RIGHT};
30
enum { ALIGN_LEFT, ALIGN_CENTER, ALIGN_RIGHT};
29
 
31
 
30
dword text_colors[300];
32
dword text_colors[300];
31
dword text_color_index;
33
dword text_color_index;
32
dword link_color_inactive;
34
dword link_color_inactive;
33
dword link_color_active;
35
dword link_color_active;
34
dword bg_color;
36
dword bg_color;
35
 
37
 
36
int stroka;
38
int stroka;
37
int stolbec;
39
int stolbec;
38
int tab_len;
40
int tab_len;
39
int anchor_line_num;
41
int anchor_line_num;
40
 
42
 
41
char line[500];
43
char line[500];
42
char tag[100];
44
char tag[100];
43
char tagparam[10000];
45
char tagparam[10000];
44
char parametr[1200];
46
char parametr[1200];
45
char options[4096];
47
char options[4096];
46
char anchor[256];
48
char anchor[256];
47
 
49
 
48
#include "..\TWB\history.h"
50
#include "..\TWB\history.h"
49
#include "..\TWB\links.h"
51
#include "..\TWB\links.h"
50
#include "..\TWB\colors.h"
52
#include "..\TWB\colors.h"
51
#include "..\TWB\unicode_tags.h"
53
#include "..\TWB\unicode_tags.h"
52
#include "..\TWB\img_cache.h"
54
#include "..\TWB\img_cache.h"
53
#include "..\TWB\parce_tag.h"
55
#include "..\TWB\parce_tag.h"
54
#include "..\TWB\table.h"
56
#include "..\TWB\table.h"
55
 
57
 
56
 
-
 
57
 
58
 
58
//=======================================================================
59
//=======================================================================
59
 
60
 
60
 
61
 
61
void TWebBrowser::DrawPage()
62
void TWebBrowser::DrawPage()
62
{
63
{
63
	int start_x, start_y, line_length, magrin_left=5;
64
	int start_x, start_y, line_length, stolbec_len, magrin_left=5;
64
	
65
	
65
	if (!header)
66
	if (!header)
66
	{
67
	{
67
		strcpy(#header, #line);
68
		strcpy(#header, #line);
68
		strcat(#header, " -");
69
		strcat(#header, " -");
69
		strcat(#header, #version);
70
		strcat(#header, #version);
70
		line = 0;
71
		line = 0;
71
		return;
72
		return;
72
	}
73
	}
73
	if (t_html) && (!t_body) return;
74
	if (t_html) && (!t_body) return;
74
	
75
	
75
	if (stroka >= 0) && (stroka - 2 < list.visible) && (line) && (!anchor)
76
	if (stroka >= 0) && (stroka - 2 < list.visible) && (line) && (!anchor)
76
	{
77
	{
77
		start_x = stolbec * 6 + list.x + magrin_left;
78
		start_x = stolbec * 6 + list.x + magrin_left;
78
		start_y = stroka * 10 + list.y + magrin_left;
79
		start_y = stroka * list.line_h + list.y + magrin_left;
-
 
80
		stolbec_len = strlen(#line);
79
		line_length = strlen(#line) * 6;
81
		line_length = stolbec_len * 6;
80
 
82
 
81
		WriteBufText(start_x, 0, 0x88, text_colors[text_color_index], #line, buf_data);
83
		WriteBufText(start_x, 0, 0x88, text_colors[text_color_index], #line, buf_data);
82
		IF (b_text)	WriteBufText(start_x+1, 0, 0x88, text_colors[text_color_index], #line, buf_data);
84
		IF (b_text)	WriteBufText(start_x+1, 0, 0x88, text_colors[text_color_index], #line, buf_data);
83
		IF (i_text) { stolbec++; DrawBuf.Skew(start_x, 0, line_length, list.line_h); }
85
		IF (i_text) { stolbec++; DrawBuf.Skew(start_x, 0, line_length, list.line_h); }
84
		IF (s_text) DrawBuf.DrawBar(start_x, 4, line_length, 1, text_colors[text_color_index]);
86
		IF (s_text) DrawBuf.DrawBar(start_x, 4, line_length, 1, text_colors[text_color_index]);
85
		IF (u_text) DrawBuf.DrawBar(start_x, 8, line_length, 1, text_colors[text_color_index]);
87
		IF (u_text) DrawBuf.DrawBar(start_x, 8, line_length, 1, text_colors[text_color_index]);
86
		IF (link) {
88
		IF (link) {
87
			UnsafeDefineButton(start_x-2, start_y, line_length + 3, 9, PageLinks.count + 400 + BT_HIDE, 0xB5BFC9);
89
			UnsafeDefineButton(start_x-2, start_y-1, line_length + 3, 10, PageLinks.count + 400 + BT_HIDE, 0xB5BFC9);
88
			DrawBuf.DrawBar(start_x, 8, line_length, 1, text_colors[text_color_index]);
90
			DrawBuf.DrawBar(start_x, 8, line_length, 1, text_colors[text_color_index]);
89
			PageLinks.AddText(#line, line_length, list.line_h, UNDERLINE);
91
			PageLinks.AddText(#line, line_length, list.line_h, UNDERLINE);
90
		}
92
		}
91
		stolbec += strlen(#line);
93
		stolbec += stolbec_len;
92
	}
94
	}
93
}
95
}
94
//=======================================================================
96
//=======================================================================
95
 
97
 
96
 
98
 
97
void BufEncode(int set_new_encoding)
99
void BufEncode(int set_new_encoding)
98
{
100
{
99
	int bufpointer_realsize;
101
	int bufpointer_realsize;
100
	cur_encoding = set_new_encoding;
102
	cur_encoding = set_new_encoding;
101
	if (o_bufpointer==0)
103
	if (o_bufpointer==0)
102
	{
104
	{
103
		o_bufpointer = malloc(bufsize);
105
		o_bufpointer = malloc(bufsize);
104
		strcpy(o_bufpointer, bufpointer);
106
		strcpy(o_bufpointer, bufpointer);
105
	}
107
	}
106
	else
108
	else
107
	{
109
	{
108
		strcpy(bufpointer, o_bufpointer);
110
		strcpy(bufpointer, o_bufpointer);
109
	}
111
	}
110
	if (set_new_encoding==_WIN) wintodos(bufpointer);
112
	if (set_new_encoding==_WIN) wintodos(bufpointer);
111
	if (set_new_encoding==_UTF) utf8rutodos(bufpointer);
113
	if (set_new_encoding==_UTF) utf8rutodos(bufpointer);
112
	if (set_new_encoding==_KOI) koitodos(bufpointer);
114
	if (set_new_encoding==_KOI) koitodos(bufpointer);
113
}
115
}
114
 
116
 
115
void TWebBrowser::Prepare(dword bufpos, in_filesize){
117
void TWebBrowser::Prepare(dword bufpos, in_filesize){
116
	bufsize = in_filesize;
118
	bufsize = in_filesize;
117
	bufpointer = bufpos;
119
	bufpointer = bufpos;
118
	Parse();
120
	Parse();
119
}
121
}
120
 
122
 
121
 
123
 
122
void TWebBrowser::Parse(){
124
void TWebBrowser::Parse(){
123
	word bukva[2];
125
	word bukva[2];
124
	int j, perenos_num;
126
	int j;
125
	byte ignor_param;
127
	byte ignor_param;
126
	char temp[768];
128
	char temp[768];
127
	dword bufpos = bufpointer;
129
	dword bufpos = bufpointer;
128
	
130
	
129
	b_text = i_text = u_text = s_text = blq_text = t_html = t_body =
131
	b_text = i_text = u_text = s_text = blq_text = t_html = t_body =
130
	li_text = link = ignor_text = text_color_index = text_colors[0] = li_tab = 
132
	li_text = link = ignor_text = text_color_index = text_colors[0] = li_tab = 
131
	condition_text_val = condition_text_active = 0; //îáíóëÿåì òåãè
133
	condition_text_val = condition_text_active = 0; //îáíóëÿåì òåãè
-
 
134
	end_parsing = false;
132
	condition_max = 255;
135
	condition_max = 255;
133
	text_align = ALIGN_LEFT;
136
	text_align = ALIGN_LEFT;
134
	link_color_inactive = 0x0000FF;
137
	link_color_inactive = 0x0000FF;
135
	link_color_active = 0xFF0000;
138
	link_color_active = 0xFF0000;
136
	bg_color = 0xFFFFFF;
139
	bg_color = 0xFFFFFF;
137
	DrawBuf.Fill(bg_color);
140
	DrawBuf.Fill(bg_color);
138
	PageLinks.Clear();
141
	PageLinks.Clear();
139
	strcpy(#header, #version);
142
	strcpy(#header, #version);
140
	stroka = -list.first;
143
	stroka = -list.first;
141
	stolbec = 0;
144
	stolbec = 0;
142
	line = 0;
145
	line = 0;
143
 
146
 
144
	if (pre_text<>2)
147
	if (pre_text<>2)
145
	{
148
	{
146
		pre_text=0;
149
		pre_text=0;
147
		if (!strcmp(#URL + strlen(#URL) - 4, ".txt")) pre_text = 1;
150
		if (!strcmp(#URL + strlen(#URL) - 4, ".txt")) pre_text = 1;
148
		if (!strcmp(#URL + strlen(#URL) - 4, ".mht")) ignor_text = 1;
151
		if (!strcmp(#URL + strlen(#URL) - 4, ".mht")) ignor_text = 1;
149
	}
152
	}
150
	
153
	
151
	for ( ; bufpointer+bufsize > bufpos; bufpos++;)
154
	for ( ; (bufpointer+bufsize > bufpos) && (ESBYTE[bufpos]!=0); bufpos++;)
-
 
155
	{
152
	{
156
		if (end_parsing) break;
153
		bukva = ESBYTE[bufpos];
157
		bukva = ESBYTE[bufpos];
154
		if (ignor_text) && (bukva!='<') continue;
158
		if (ignor_text) && (bukva!='<') continue;
155
		if (condition_text_active) && (condition_text_val != condition_href) && (bukva!='<') continue;
159
		if (condition_text_active) && (condition_text_val != condition_href) && (bukva!='<') continue;
156
		switch (bukva)
160
		switch (bukva)
157
		{
161
		{
158
		case 0x0a:
162
		case 0x0a:
159
			if (pre_text)
163
			if (pre_text)
160
			{
164
			{
161
				chrcat(#line, ' ');
165
				chrcat(#line, ' ');
162
				bukva = temp = NULL;
166
				bukva = temp = NULL;
163
				goto NEXT_MARK;
167
				Perenos();
164
			}
168
			}
165
		case '\9':
169
		case '\9':
166
			if (pre_text) //èíà÷å èä¸ì íà 0x0d	
170
			if (pre_text) //èíà÷å èä¸ì íà 0x0d	
167
			{
171
			{
168
				tab_len=strlen(#line)/8;
172
				tab_len=strlen(#line)/8;
169
				tab_len=tab_len*8;
173
				tab_len=tab_len*8;
170
				tab_len=8+tab_len-strlen(#line);
174
				tab_len=8+tab_len-strlen(#line);
171
				for (j=0; j
175
				for (j=0; j
172
				break;
176
				break;
173
			}
177
			}
174
			goto DEFAULT_MARK;		
178
			goto DEFAULT_MARK;		
175
		case '=': //quoted printable
179
		case '=': //quoted printable
176
			if (strcmp(#URL + strlen(#URL) - 4, ".mht")<>0) goto DEFAULT_MARK;
180
			if (strcmp(#URL + strlen(#URL) - 4, ".mht")<>0) goto DEFAULT_MARK;
177
 
181
 
178
			temp[0] = ESBYTE[bufpos+1];
182
			temp[0] = ESBYTE[bufpos+1];
179
			temp[1] = ESBYTE[bufpos+2];
183
			temp[1] = ESBYTE[bufpos+2];
180
			temp[2] = '\0';
184
			temp[2] = '\0';
181
			if (bukva = Hex2Symb(#temp))
185
			if (bukva = Hex2Symb(#temp))
182
			{
186
			{
183
				bufpos+=2;
187
				bufpos+=2;
184
				goto DEFAULT_MARK;
188
				goto DEFAULT_MARK;
185
			}
189
			}
186
			break;
190
			break;
187
			
191
			
188
		case '&': //  and so on
192
		case '&': //  and so on
189
			bufpos++;
193
			bufpos++;
190
			tag=0;
194
			tag=0;
191
			for (j=0; (ESBYTE[bufpos]<>';') && (j<7);   j++, bufpos++;)
195
			for (j=0; (ESBYTE[bufpos]<>';') && (j<7);   j++, bufpos++;)
192
			{
196
			{
193
				bukva = ESBYTE[bufpos];
197
				bukva = ESBYTE[bufpos];
194
				chrcat(#tag, bukva);
198
				chrcat(#tag, bukva);
195
			}
199
			}
196
			if (bukva = GetUnicodeSymbol()) goto DEFAULT_MARK;
200
			if (bukva = GetUnicodeSymbol()) goto DEFAULT_MARK;
197
			break;
201
			break;
198
		case '<':
202
		case '<':
199
			bufpos++; //ïðîìîòàåì ñèìâîë <
203
			bufpos++; //ïðîìîòàåì ñèìâîë <
200
			tag = parametr = tagparam = ignor_param = NULL;
204
			tag = parametr = tagparam = ignor_param = NULL;
201
			if (ESBYTE[bufpos] == '!') //ôèëüòðàöèÿ âíóòðè , äåðçêî
205
			if (ESBYTE[bufpos] == '!') //ôèëüòðàöèÿ âíóòðè , äåðçêî
202
			{
206
			{
203
				bufpos++;
207
				bufpos++;
204
				if (ESBYTE[bufpos] == '-')
208
				if (ESBYTE[bufpos] == '-')
205
				{
209
				{
206
				HH_:
210
				HH_:
207
					do
211
					do
208
					{
212
					{
209
						bufpos++;
213
						bufpos++;
210
						if (bufpointer + bufsize <= bufpos) break 2;
214
						if (bufpointer + bufsize <= bufpos) break 2;
211
					}
215
					}
212
					while (ESBYTE[bufpos] <>'-');
216
					while (ESBYTE[bufpos] <>'-');
213
					
217
					
214
					bufpos++;
218
					bufpos++;
215
					if (ESBYTE[bufpos] <>'-') goto HH_;
219
					if (ESBYTE[bufpos] <>'-') goto HH_;
216
				}
220
				}
217
			}
221
			}
218
			while (ESBYTE[bufpos] !='>') && (bufpos < bufpointer + bufsize) //ïîëó÷àåì òåã è åãî ïàðàìåòðû
222
			while (ESBYTE[bufpos] !='>') && (bufpos < bufpointer + bufsize) //ïîëó÷àåì òåã è åãî ïàðàìåòðû
219
			{
223
			{
220
				bukva = ESBYTE[bufpos];
224
				bukva = ESBYTE[bufpos];
221
				if (bukva == '\9') || (bukva == '\x0a') || (bukva == '\x0d') bukva = ' ';
225
				if (bukva == '\9') || (bukva == '\x0a') || (bukva == '\x0d') bukva = ' ';
222
				if (!ignor_param) && (bukva <>' ')
226
				if (!ignor_param) && (bukva <>' ')
223
				{
227
				{
224
					if (strlen(#tag)
228
					if (strlen(#tag)
225
				}
229
				}
226
				else
230
				else
227
				{
231
				{
228
					ignor_param = true;
232
					ignor_param = true;
229
					if (!ignor_text) && (strlen(#tagparam)+1
233
					if (!ignor_text) && (strlen(#tagparam)+1
230
				}
234
				}
231
				bufpos++;
235
				bufpos++;
232
			}
236
			}
233
			strlwr(#tag);
237
			strlwr(#tag);
234
 
238
 
235
			if (condition_text_active) && (condition_text_val != condition_href) 
239
			if (condition_text_active) && (condition_text_val != condition_href) 
236
			{
240
			{
237
				if (strcmp(#tag, "/condition")!=0) break;
241
				if (strcmp(#tag, "/condition")!=0) break;
238
			}
242
			}
239
			if (tag[strlen(#tag)-1]=='/') tag[strlen(#tag)-1]=NULL; //for br/
243
			if (tag[strlen(#tag)-1]=='/') tag[strlen(#tag)-1]=NULL; //for br/
240
			if (tagparam) && (strlen(#tagparam) < 4000) GetNextParam();
244
			if (tagparam) && (strlen(#tagparam) < 4000) GetNextParam();
241
 
245
 
242
			if (stolbec + strlen(#line) > list.column_max) //============the same as NEXT_MARK
-
 
243
			{
-
 
244
				perenos_num = strrchr(#line, ' ');
-
 
245
				if (!perenos_num) && (strlen(#line)>list.column_max) perenos_num=list.column_max;
-
 
246
				strcpy(#temp, #line + perenos_num); //ïåðåíîñ ïî ñëîâàì
-
 
247
				line[perenos_num] = 0x00;
-
 
248
				if (stroka-1 > list.visible) && (list.first <>0) break 1; //óõîäèì...
-
 
249
				DrawPage();
-
 
250
				strcpy(#line, #temp);
-
 
251
				NewLine(); //çàêðàøèâàåì ñëåäóùóþ ñòðîêó
-
 
252
			}
246
			if (stolbec + strlen(#line) > list.column_max) Perenos();
253
			DrawPage();
247
			DrawPage();
254
			line = NULL;
248
			line = NULL;
255
			if (tag) SetTextStyle(list.x + 5, stroka * list.line_h + list.y + 5); //îáðàáîòêà òåãîâ
249
			if (tag) SetTextStyle(list.x + 5, stroka * list.line_h + list.y + 5); //îáðàáîòêà òåãîâ
256
			tag = parametr = tagparam = ignor_param = NULL;
250
			tag = parametr = tagparam = ignor_param = NULL;
257
			break;
251
			break;
258
		default:
252
		default:
259
			DEFAULT_MARK:
253
			DEFAULT_MARK:
260
			if (bukva<=15) bukva=' ';
254
			if (bukva<=15) bukva=' ';
261
			if (!pre_text) && (bukva == ' ')
255
			if (!pre_text) && (bukva == ' ')
262
			{
256
			{
263
				if (line[strlen(#line)-1]==' ') break; //óáðàòü 2 ïðîáåëà ïîäðÿä
257
				if (line[strlen(#line)-1]==' ') break; //óáðàòü 2 ïðîáåëà ïîäðÿä
264
				if (!stolbec) && (!line) break; //ñòðîêà íå ìîæåò íà÷èíàòüñÿ ñ ïðîáåëà
258
				if (!stolbec) && (!line) break; //ñòðîêà íå ìîæåò íà÷èíàòüñÿ ñ ïðîáåëà
265
			}
259
			}
266
			if (strlen(#line)
260
			if (strlen(#line)
267
 
-
 
268
			if (stolbec + strlen(#line) > list.column_max)
261
			if (stolbec + strlen(#line) > list.column_max) Perenos();
269
			{
-
 
270
			NEXT_MARK:
-
 
271
				perenos_num = strrchr(#line, ' ');
-
 
272
				if (!perenos_num) && (strlen(#line)>list.column_max) perenos_num=list.column_max;
-
 
273
				strcpy(#temp, #line + perenos_num);
-
 
274
				line[perenos_num] = 0x00;
-
 
275
				if (stroka-1 > list.visible) && (list.first <>0) break 1;
-
 
276
				DrawPage();
-
 
277
				strcpy(#line, #temp);
-
 
278
				NewLine();
-
 
279
			}
-
 
280
		}
262
		}
281
	}
263
	}
282
 
-
 
283
	DrawPage();
264
	DrawPage();
284
	NewLine();
265
	NewLine();
285
	DrawBar(list.x, stroka * list.line_h + list.y + 5, list.w, -stroka * list.line_h + list.h - 5, bg_color);
266
	DrawBar(list.x, stroka * list.line_h + list.y + 5, list.w, -stroka * list.line_h + list.h - 5, bg_color);
286
	DrawBar(list.x, list.visible * list.line_h + list.y + 4, list.w, -list.visible * list.line_h + list.h - 4, bg_color);
267
	DrawBar(list.x, list.visible * list.line_h + list.y + 4, list.w, -list.visible * list.line_h + list.h - 4, bg_color);
287
	if (list.first == 0) list.count = stroka;
268
	if (list.first == 0) list.count = stroka;
288
	if (anchor) //åñëè ïîñðåäè òåêñòà ïîÿâèòñÿ íîâûé ÿêîðü - áóäåò áåñêîíå÷íûé öèêë
269
	if (anchor) //åñëè ïîñðåäè òåêñòà ïîÿâèòñÿ íîâûé ÿêîðü - áóäåò áåñêîíå÷íûé öèêë
289
	{
270
	{
290
		anchor=NULL;
271
		anchor=NULL;
291
		list.first=anchor_line_num;
272
		list.first=anchor_line_num;
292
		Parse();
273
		Parse();
293
	}
274
	}
294
	DrawScroller();
275
	DrawScroller();
295
}
276
}
-
 
277
 
-
 
278
void TWebBrowser::Perenos()
-
 
279
{
-
 
280
	int perenos_num;
-
 
281
	char new_line_text[4096];
-
 
282
	perenos_num = strrchr(#line, ' ');
-
 
283
	if (!perenos_num) && (strlen(#line)>list.column_max) perenos_num=list.column_max;
-
 
284
	strcpy(#new_line_text, #line + perenos_num);
-
 
285
	line[perenos_num] = 0x00;
-
 
286
	if (stroka-1 > list.visible) && (list.first <>0) end_parsing=true;
-
 
287
	DrawPage();
-
 
288
	strcpy(#line, #new_line_text);
-
 
289
	NewLine();
296
 
290
}
297
 
291
 
298
 
292
 
299
char oldtag[100];
293
char oldtag[100];
300
void TWebBrowser::SetTextStyle(int left1, top1) {
294
void TWebBrowser::SetTextStyle(int left1, top1) {
301
	dword hr_color;
295
	dword hr_color;
302
	byte opened;
296
	byte opened;
303
	byte meta_encoding;
297
	byte meta_encoding;
304
	//ïðîâåðÿåì òåã îòêðûâàåòñÿ èëè çàêðûâàåòñÿ
298
	//ïðîâåðÿåì òåã îòêðûâàåòñÿ èëè çàêðûâàåòñÿ
305
	if (tag[0] == '/') 
299
	if (tag[0] == '/') 
306
	{
300
	{
307
		 opened = 0;
301
		 opened = 0;
308
		 strcpy(#tag, #tag+1);
302
		 strcpy(#tag, #tag+1);
309
	}
303
	}
310
	else opened = 1;
304
	else opened = 1;
311
		
305
		
312
	if (isTag("html"))
306
	if (isTag("html"))
313
	{
307
	{
314
		IF(!strcmp(#URL + strlen(#URL) - 4, ".mht")) IF (opened==0) ignor_text = 1; ELSE ignor_text = 0;
308
		IF(!strcmp(#URL + strlen(#URL) - 4, ".mht")) IF (opened==0) ignor_text = 1; ELSE ignor_text = 0;
315
		t_html = opened;
309
		t_html = opened;
316
		return;
310
		return;
317
	}
311
	}
318
 
312
 
319
	if (isTag("script")) || (isTag("style")) || (isTag("binary")) || (isTag("select")) ignor_text = opened;
313
	if (isTag("script")) || (isTag("style")) || (isTag("binary")) || (isTag("select")) ignor_text = opened;
320
 
314
 
321
	if(isTag("title"))
315
	if(isTag("title"))
322
	{
316
	{
323
		if (opened) header=NULL;
317
		if (opened) header=NULL;
324
		else if (!stroka) DrawTitle(#header); //òåã çàêðûëñÿ - âûâåëè ñòðîêó
318
		else if (!stroka) DrawTitle(#header); //òåã çàêðûëñÿ - âûâåëè ñòðîêó
325
		return;
319
		return;
326
	}
320
	}
327
 
321
 
328
	if (ignor_text) return;
322
	if (ignor_text) return;
329
	
323
	
330
	IF(isTag("q"))
324
	IF(isTag("q"))
331
	{
325
	{
332
		if (opened)
326
		if (opened)
333
		{
327
		{
334
			NewLine();
328
			NewLine();
335
			strcat(#line, ' \"');
329
			strcat(#line, ' \"');
336
		}
330
		}
337
		if (!opened)
331
		if (!opened)
338
		{
332
		{
339
			chrcat(#line, '\"');
333
			chrcat(#line, '\"');
340
			NewLine();
334
			NewLine();
341
		} 
335
		} 
342
	}
336
	}
343
 
337
 
344
	if (anchor) && (!strcmp(#parametr, "id=")) //î÷åíü ïëîõî!!! ïîòîìó ÷òî åñëè íå ïîñëåäíèé òåã, ðàáîòàòü íå áóäåò
338
	if (anchor) && (!strcmp(#parametr, "id=")) //î÷åíü ïëîõî!!! ïîòîìó ÷òî åñëè íå ïîñëåäíèé òåã, ðàáîòàòü íå áóäåò
345
	{
339
	{
346
		if (!strcmp(#anchor, #options))	anchor_line_num=list.first+stroka;
340
		if (!strcmp(#anchor, #options))	anchor_line_num=list.first+stroka;
347
	}
341
	}
348
	
342
	
349
	if (isTag("body"))
343
	if (isTag("body"))
350
	{
344
	{
351
		t_body = opened;
345
		t_body = opened;
352
		do{
346
		do{
353
			if (!strcmp(#parametr, "condition_max=")) condition_max = atoi(#options);
347
			if (!strcmp(#parametr, "condition_max=")) condition_max = atoi(#options);
354
			if (!strcmp(#parametr, "link=")) link_color_inactive = GetColor(#options);
348
			if (!strcmp(#parametr, "link=")) link_color_inactive = GetColor(#options);
355
			if (!strcmp(#parametr, "alink=")) link_color_active = GetColor(#options);
349
			if (!strcmp(#parametr, "alink=")) link_color_active = GetColor(#options);
356
			if (!strcmp(#parametr, "text=")) text_colors[0]=GetColor(#options);
350
			if (!strcmp(#parametr, "text=")) text_colors[0]=GetColor(#options);
357
			if (!strcmp(#parametr, "bgcolor="))
351
			if (!strcmp(#parametr, "bgcolor="))
358
			{
352
			{
359
				bg_color=GetColor(#options);
353
				bg_color=GetColor(#options);
360
				DrawBuf.Fill(bg_color);
354
				DrawBuf.Fill(bg_color);
361
			}
355
			}
362
		} while(GetNextParam());
356
		} while(GetNextParam());
363
		if (opened) && (cur_encoding==_DEFAULT)
357
		if (opened) && (cur_encoding==_DEFAULT)
364
		{
358
		{
365
			debugln("Document has no information about encoding, UTF will be used");
359
			debugln("Document has no information about encoding, UTF will be used");
366
			BufEncode(_UTF);
360
			BufEncode(_UTF);
367
		}
361
		}
368
		return;
362
		return;
369
	}
363
	}
370
 
364
 
371
	if (isTag("a"))
365
	if (isTag("a"))
372
	{
366
	{
373
		if (opened)
367
		if (opened)
374
		{
368
		{
375
			if (link) IF(text_color_index > 0) text_color_index--; //åñëè ïðåäûäóùèé òåã à íå áûë çàêðûò
369
			if (link) IF(text_color_index > 0) text_color_index--; //åñëè ïðåäûäóùèé òåã à íå áûë çàêðûò
376
 
370
 
377
			do{
371
			do{
378
				if (!strcmp(#parametr, "href="))
372
				if (!strcmp(#parametr, "href="))
379
				{
373
				{
380
					if (stroka - 1 > list.visible) || (stroka < -2) return;
374
					if (stroka - 1 > list.visible) || (stroka < -2) return;
381
					
375
					
382
					text_color_index++;
376
					text_color_index++;
383
					text_colors[text_color_index] = text_colors[text_color_index-1];
377
					text_colors[text_color_index] = text_colors[text_color_index-1];
384
					
378
					
385
					link = 1;
379
					link = 1;
386
					text_colors[text_color_index] = link_color_inactive;
380
					text_colors[text_color_index] = link_color_inactive;
387
					PageLinks.AddLink(#options, stolbec*6+left1, top1);
381
					PageLinks.AddLink(#options, stolbec*6+left1, top1-2);
388
				}
382
				}
389
				if (anchor) && (!strcmp(#parametr, "name="))
383
				if (anchor) && (!strcmp(#parametr, "name="))
390
				{
384
				{
391
					if (!strcmp(#anchor, #options))
385
					if (!strcmp(#anchor, #options))
392
					{
386
					{
393
						anchor_line_num=list.first+stroka;
387
						anchor_line_num=list.first+stroka;
394
					}
388
					}
395
				}
389
				}
396
			} while(GetNextParam());
390
			} while(GetNextParam());
397
		}
391
		}
398
		else {
392
		else {
399
			link = 0;
393
			link = 0;
400
			IF(text_color_index > 0) text_color_index--;
394
			IF(text_color_index > 0) text_color_index--;
401
		}
395
		}
402
		return;
396
		return;
403
	}
397
	}
404
 
398
 
405
	if (isTag("font"))
399
	if (isTag("font"))
406
	{
400
	{
407
		if (opened)
401
		if (opened)
408
		{
402
		{
409
			text_color_index++;
403
			text_color_index++;
410
			text_colors[text_color_index] = text_colors[text_color_index-1];
404
			text_colors[text_color_index] = text_colors[text_color_index-1];
411
		
405
		
412
			do{
406
			do{
413
				if (strcmp(#parametr, "color=") == 0) //&& (parametr[1] == '#')
407
				if (strcmp(#parametr, "color=") == 0) //&& (parametr[1] == '#')
414
				{
408
				{
415
					text_colors[text_color_index] = GetColor(#options);
409
					text_colors[text_color_index] = GetColor(#options);
416
				}
410
				}
417
			} while(GetNextParam());
411
			} while(GetNextParam());
418
		}
412
		}
419
		else
413
		else
420
			if (text_color_index > 0) text_color_index--;
414
			if (text_color_index > 0) text_color_index--;
421
		return;
415
		return;
422
	}
416
	}
423
	if (isTag("br")) {
417
	if (isTag("br")) {
424
		NewLine();
418
		NewLine();
425
		return;
419
		return;
426
	}
420
	}
427
	if (isTag("div")) || (isTag("header")) || (isTag("article")) || (isTag("footer")) {
421
	if (isTag("div")) || (isTag("header")) || (isTag("article")) || (isTag("footer")) {
428
		IF(oldtag[0] <>'h') NewLine();
422
		IF(oldtag[0] <>'h') NewLine();
429
		return;
423
		return;
430
	}
424
	}
431
	if (isTag("p")) {
425
	if (isTag("p")) {
432
		IF(oldtag[0] == 'h') return;
426
		IF(oldtag[0] == 'h') return;
433
		NewLine();
427
		NewLine();
434
		IF(opened) NewLine();
428
		IF(opened) NewLine();
435
		return;
429
		return;
436
	}
430
	}
437
 
431
 
438
	if(isTag("table")) {
432
	if(isTag("table")) {
439
		table.active = opened;
433
		table.active = opened;
440
		NewLine();
434
		NewLine();
441
		if (opened)	table.NewTable();
435
		if (opened)	table.NewTable();
442
	}
436
	}
443
 
437
 
444
	if(isTag("td")) {
438
	if(isTag("td")) {
445
		if (opened)
439
		if (opened)
446
		{
440
		{
447
			table.cur_col++;
441
			table.cur_col++;
448
			table.row_h = 0;
442
			table.row_h = 0;
449
			do {
443
			do {
450
				if (!strcmp(#parametr, "width="))
444
				if (!strcmp(#parametr, "width="))
451
				{
445
				{
452
					table.col_w[table.cur_col] = atoi(#options);
446
					table.col_w[table.cur_col] = atoi(#options);
453
					// NewLine();
447
					// NewLine();
454
					// strcpy(#line, #options);
448
					// strcpy(#line, #options);
455
					// NewLine();
449
					// NewLine();
456
				}
450
				}
457
			} while(GetNextParam());
451
			} while(GetNextParam());
458
		}
452
		}
459
		else
453
		else
460
		{
454
		{
461
			if (table.row_h > table.row_max_h) table.row_max_h = table.row_h;
455
			if (table.row_h > table.row_max_h) table.row_max_h = table.row_h;
462
		}
456
		}
463
	}
457
	}
464
 
458
 
465
	if(isTag("tr")) {
459
	if(isTag("tr")) {
466
		if (opened)
460
		if (opened)
467
		{
461
		{
468
			table.cur_col = 0;
462
			table.cur_col = 0;
469
			table.row_max_h = 0;
463
			table.row_max_h = 0;
470
			table.row_start = stroka;
464
			table.row_start = stroka;
471
		}
465
		}
472
		else
466
		else
473
		{
467
		{
474
			NewLine();
468
			NewLine();
475
			if (table.cur_row == 0) table.max_cols = table.cur_col;
469
			if (table.cur_row == 0) table.max_cols = table.cur_col;
476
			table.cur_row++;
470
			table.cur_row++;
477
			table.max_cols = table.cur_col;
471
			table.max_cols = table.cur_col;
478
		}
472
		}
479
	}
473
	}
480
 
474
 
481
	/*
475
	/*
482
	if (isTag("center"))
476
	if (isTag("center"))
483
	{
477
	{
484
		if (opened) text_align = ALIGN_CENTER;
478
		if (opened) text_align = ALIGN_CENTER;
485
		if (!opened)
479
		if (!opened)
486
		{
480
		{
487
			NewLine();
481
			NewLine();
488
			text_align = ALIGN_LEFT;
482
			text_align = ALIGN_LEFT;
489
		}
483
		}
490
		return;
484
		return;
491
	}
485
	}
492
	if (isTag("right"))
486
	if (isTag("right"))
493
	{
487
	{
494
		if (opened) text_align = ALIGN_RIGHT;
488
		if (opened) text_align = ALIGN_RIGHT;
495
		if (!opened)
489
		if (!opened)
496
		{
490
		{
497
			NewLine();
491
			NewLine();
498
			text_align = ALIGN_LEFT;
492
			text_align = ALIGN_LEFT;
499
		}
493
		}
500
		return;
494
		return;
501
	}
495
	}
502
	*/
496
	*/
503
	if (isTag("h1")) || (isTag("h2")) || (isTag("h3")) || (isTag("h4")) {
497
	if (isTag("h1")) || (isTag("h2")) || (isTag("h3")) || (isTag("h4")) {
504
		NewLine();
498
		NewLine();
505
		if (opened) && (stroka>1) NewLine();
499
		if (opened) && (stroka>1) NewLine();
506
		strcpy(#oldtag, #tag);
500
		strcpy(#oldtag, #tag);
507
		if (opened)
501
		if (opened)
508
		{
502
		{
509
			if (!strcmp(#parametr, "align=")) && (!strcmp(#options,"center")) text_align = ALIGN_CENTER;
503
			if (!strcmp(#parametr, "align=")) && (!strcmp(#options,"center")) text_align = ALIGN_CENTER;
510
			if (!strcmp(#parametr, "align=")) && (!strcmp(#options,"right")) text_align = ALIGN_RIGHT;
504
			if (!strcmp(#parametr, "align=")) && (!strcmp(#options,"right")) text_align = ALIGN_RIGHT;
511
			b_text = 1;
505
			b_text = 1;
512
		}
506
		}
513
		if (!opened)
507
		if (!opened)
514
		{
508
		{
515
			text_align = ALIGN_LEFT;
509
			text_align = ALIGN_LEFT;
516
			b_text = 0;
510
			b_text = 0;
517
		}
511
		}
518
		return;
512
		return;
519
	}
513
	}
520
	else
514
	else
521
		oldtag=NULL;
515
		oldtag=NULL;
522
		
516
		
523
	if (isTag("b")) || (isTag("strong")) || (isTag("big")) {
517
	if (isTag("b")) || (isTag("strong")) || (isTag("big")) {
524
		b_text = opened;
518
		b_text = opened;
525
		return;
519
		return;
526
	}
520
	}
527
	if(isTag("i")) || (isTag("em")) || (isTag("subtitle")) {
521
	if(isTag("i")) || (isTag("em")) || (isTag("subtitle")) {
528
		i_text = opened;
522
		i_text = opened;
529
		return;
523
		return;
530
	}	
524
	}	
531
	if (isTag("dt"))
525
	if (isTag("dt"))
532
	{
526
	{
533
		li_text = opened;
527
		li_text = opened;
534
		IF(opened == 0) return;
528
		IF(opened == 0) return;
535
		NewLine();
529
		NewLine();
536
		return;
530
		return;
537
	}
531
	}
538
	if (isTag("condition"))
532
	if (isTag("condition"))
539
	{
533
	{
540
		condition_text_active = opened;
534
		condition_text_active = opened;
541
		if (opened) && (!strcmp(#parametr, "show_if=")) condition_text_val = atoi(#options);
535
		if (opened) && (!strcmp(#parametr, "show_if=")) condition_text_val = atoi(#options);
542
		return;
536
		return;
543
	}
537
	}
544
	if (isTag("li")) || (isTag("dt")) //íàäî ñäåëàòü âëîæåííûå ñïèñêè
538
	if (isTag("li")) || (isTag("dt")) //íàäî ñäåëàòü âëîæåííûå ñïèñêè
545
	{
539
	{
546
		li_text = opened;
540
		li_text = opened;
547
		if (opened)
541
		if (opened)
548
		{
542
		{
549
			NewLine();
543
			NewLine();
550
			if (stroka > -1) && (stroka - 2 < list.visible) DrawBuf.DrawBar(li_tab * 5 * 6 + left1 - 5, list.line_h/2-3, 2, 2, 0x555555);
544
			if (stroka > -1) && (stroka - 2 < list.visible) DrawBuf.DrawBar(li_tab * 5 * 6 + left1 - 5, list.line_h/2-2, 2, 2, 0x555555);
551
		}
545
		}
552
		return;
546
		return;
553
	}
547
	}
554
	if (isTag("u")) || (isTag("ins")) u_text = opened;
548
	if (isTag("u")) || (isTag("ins")) u_text = opened;
555
	if (isTag("s")) || (isTag("strike")) || (isTag("del")) s_text = opened;
549
	if (isTag("s")) || (isTag("strike")) || (isTag("del")) s_text = opened;
556
	if (isTag("ul")) || (isTag("ol")) IF(!opened)
550
	if (isTag("ul")) || (isTag("ol")) IF(!opened)
557
	{
551
	{
558
		li_text = opened;
552
		li_text = opened;
559
		li_tab--;
553
		li_tab--;
560
		NewLine();
554
		NewLine();
561
	} ELSE li_tab++;
555
	} ELSE li_tab++;
562
	if (isTag("dd")) stolbec += 5;
556
	if (isTag("dd")) stolbec += 5;
563
	if (isTag("blockquote")) blq_text = opened;
557
	if (isTag("blockquote")) blq_text = opened;
564
	if (isTag("pre")) || (isTag("code")) pre_text = opened; 
558
	if (isTag("pre")) || (isTag("code")) pre_text = opened; 
565
	if (isTag("hr"))
559
	if (isTag("hr"))
566
	{
560
	{
567
		if (anchor) || (stroka < -1)
561
		if (anchor) || (stroka < -1)
568
		{
562
		{
569
			stroka+=2;
563
			stroka+=2;
570
			return;
564
			return;
571
		}
565
		}
572
		if (strcmp(#parametr, "color=") == 0) hr_color = GetColor(#options); else hr_color = 0x999999;
566
		if (strcmp(#parametr, "color=") == 0) hr_color = GetColor(#options); else hr_color = 0x999999;
573
		NewLine();
567
		NewLine();
574
		DrawBuf.DrawBar(5, list.line_h/2, list.w-10, 1, hr_color);
568
		DrawBuf.DrawBar(5, list.line_h/2, list.w-10, 1, hr_color);
575
		NewLine();
569
		NewLine();
576
	}
570
	}
577
	if (isTag("img"))
571
	if (isTag("img"))
578
	{
572
	{
579
		ImgCache.Images( left1, top1, WB1.list.w);
573
		ImgCache.Images( left1, top1, WB1.list.w);
580
		return;
574
		return;
581
	}
575
	}
582
	if (isTag("meta")) || (isTag("?xml"))
576
	if (isTag("meta")) || (isTag("?xml"))
583
	{
577
	{
584
		do{
578
		do{
585
			if (!strcmp(#parametr, "charset=")) || (!strcmp(#parametr, "content=")) || (!strcmp(#parametr, "encoding="))
579
			if (!strcmp(#parametr, "charset=")) || (!strcmp(#parametr, "content=")) || (!strcmp(#parametr, "encoding="))
586
			{
580
			{
587
				strcpy(#options, #options[strrchr(#options, '=')]); //ïîèñê â content=
581
				strcpy(#options, #options[strrchr(#options, '=')]); //ïîèñê â content=
588
				strlwr(#options);
582
				strlwr(#options);
589
				meta_encoding = _DEFAULT;
583
				meta_encoding = _DEFAULT;
590
				if (!strcmp(#options, "utf-8"))  || (!strcmp(#options,"utf8")) meta_encoding = _UTF;
584
				if (!strcmp(#options, "utf-8"))  || (!strcmp(#options,"utf8")) meta_encoding = _UTF;
591
				if (!strcmp(#options, "koi8-r")) || (!strcmp(#options, "koi8-u")) meta_encoding = _KOI;
585
				if (!strcmp(#options, "koi8-r")) || (!strcmp(#options, "koi8-u")) meta_encoding = _KOI;
592
				if (!strcmp(#options, "windows-1251")) || (!strcmp(#options, "windows1251")) meta_encoding = _WIN;
586
				if (!strcmp(#options, "windows-1251")) || (!strcmp(#options, "windows1251")) meta_encoding = _WIN;
593
				if (!strcmp(#options, "dos"))    || (!strcmp(#options, "cp-866"))   meta_encoding = _DOS;
587
				if (!strcmp(#options, "dos"))    || (!strcmp(#options, "cp-866"))   meta_encoding = _DOS;
594
				if (cur_encoding==_DEFAULT) BufEncode(meta_encoding);
588
				if (cur_encoding==_DEFAULT) BufEncode(meta_encoding);
595
				return;
589
				return;
596
			}
590
			}
597
		} while(GetNextParam());
591
		} while(GetNextParam());
598
		return;
592
		return;
599
	}
593
	}
600
}
594
}
601
 
595
 
602
void TWebBrowser::DrawScroller()
596
void TWebBrowser::DrawScroller()
603
{
597
{
604
	scroll_wv.max_area = list.count;
598
	scroll_wv.max_area = list.count;
605
	scroll_wv.cur_area = list.visible;
599
	scroll_wv.cur_area = list.visible;
606
	scroll_wv.position = list.first;
600
	scroll_wv.position = list.first;
607
 
601
 
608
	scroll_wv.all_redraw=0;
602
	scroll_wv.all_redraw=0;
609
	scroll_wv.start_x = list.x + list.w;
603
	scroll_wv.start_x = list.x + list.w;
610
	scroll_wv.start_y = list.y;
604
	scroll_wv.start_y = list.y;
611
	scroll_wv.size_y=list.h;
605
	scroll_wv.size_y=list.h;
612
 
606
 
613
	scrollbar_v_draw(#scroll_wv);
607
	scrollbar_v_draw(#scroll_wv);
614
}
608
}
615
 
609
 
616
 
610
 
617
void TWebBrowser::NewLine()
611
void TWebBrowser::NewLine()
618
{
612
{
619
	int onleft;
613
	int onleft;
620
	int ontop;
614
	int ontop;
621
 
615
 
622
	onleft = list.x + 5;
616
	onleft = list.x + 5;
623
	ontop = stroka * list.line_h + list.y + 5;
617
	ontop = stroka * list.line_h + list.y + 5;
624
	if (!stroka) DrawBar(list.x, list.y, list.w, 5, bg_color);
618
	if (!stroka) DrawBar(list.x, list.y, list.w, 5, bg_color);
625
	if (t_html) && (!t_body) return;
619
	if (t_html) && (!t_body) return;
626
	if (ontop>=list.y) && ( ontop < list.h+list.y-10)  && (!anchor)
620
	if (ontop>=list.y) && ( ontop < list.h+list.y-10)  && (!anchor)
627
	{
621
	{
628
		if (text_align == ALIGN_CENTER) DrawBuf.AlignCenter(onleft,ontop,list.w,list.line_h,stolbec * 6);
622
		if (text_align == ALIGN_CENTER) DrawBuf.AlignCenter(onleft,ontop,list.w,list.line_h,stolbec * 6);
629
		if (text_align == ALIGN_RIGHT) DrawBuf.AlignRight(onleft,ontop,list.w,list.line_h,stolbec * 6);
623
		if (text_align == ALIGN_RIGHT) DrawBuf.AlignRight(onleft,ontop,list.w,list.line_h,stolbec * 6);
630
		DrawBuf.bufy = ontop;
624
		DrawBuf.bufy = ontop;
631
		DrawBuf.Show();
625
		DrawBuf.Show();
632
		DrawBuf.Fill(bg_color);
626
		DrawBuf.Fill(bg_color);
633
	}
627
	}
634
	stroka++;
628
	stroka++;
635
	if (blq_text) stolbec = 6; else stolbec = 0;
629
	if (blq_text) stolbec = 6; else stolbec = 0;
636
	if (li_text) stolbec = li_tab * 5;
630
	if (li_text) stolbec = li_tab * 5;
637
}
631
}
638
 
632
 
639
 
633
 
640
 
634
 
641
int isTag(dword text) 
635
int isTag(dword text) 
642
{ 
636
{ 
643
	if (!strcmp(#tag,text)) return 1; else return 0;
637
	if (!strcmp(#tag,text)) return 1; else return 0;
644
}
638
}
645
>
639
>
646
>
640
>