Subversion Repositories Kolibri OS

Rev

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

Rev 7757 Rev 7758
1
#include "..\TWB\colors.h"
1
#include "..\TWB\colors.h"
2
#include "..\TWB\anchors.h"
2
#include "..\TWB\anchors.h"
3
#include "..\TWB\parce_tag.h"
3
#include "..\TWB\parce_tag.h"
4
#include "..\TWB\absolute_url.h"
4
#include "..\TWB\special.h"
5
#include "..\TWB\unicode_tags.h"
-
 
6
#include "..\TWB\img_cache.h"
5
#include "..\TWB\img_cache.h"
7
dword page_bg;
6
dword page_bg;
8
dword link_color_inactive;
7
dword link_color_inactive;
9
dword link_color_active;
8
dword link_color_active;
10
#include "..\TWB\links.h"
9
#include "..\TWB\links.h"
11
 
10
 
12
enum { ALIGN_LEFT, ALIGN_CENTER, ALIGN_RIGHT};
11
enum { ALIGN_LEFT, ALIGN_CENTER, ALIGN_RIGHT};
13
 
12
 
14
struct _style {
13
struct _style {
15
	bool
14
	bool
16
	b, u, s, h,
15
	b, u, s, h,
17
	pre,
16
	pre,
18
	blq,
17
	blq,
19
	li,
18
	li,
20
	li_tab,
19
	li_tab,
21
	button,
20
	button,
22
	image,
21
	image,
23
	align;
22
	align;
24
	dword bg_color;
23
	dword bg_color;
-
 
24
 
-
 
25
	dword main_title;
25
};
26
};
26
 
27
 
27
struct TWebBrowser {
28
struct TWebBrowser {
28
	llist list;
29
	llist list;
29
	_style style;
30
	_style style;
30
	DrawBufer DrawBuf;
31
	DrawBufer DrawBuf;
31
	dword draw_y, stolbec;
32
	dword draw_y, stolbec;
32
	int zoom;
33
	int zoom;
33
	dword o_bufpointer;
34
	dword o_bufpointer;
34
	void SetPageDefaults();
35
	void SetPageDefaults();
35
	void AddCharToTheLine();
36
	void AddCharToTheLine();
36
	void ParseHtml();
37
	void ParseHtml();
37
	void SetStyle();
38
	void SetStyle();
38
	void DrawStyle();
39
	void DrawStyle();
39
	void DrawPage();
40
	void DrawPage();
40
	void DrawScroller();
41
	void DrawScroller();
41
	void NewLine();
42
	void NewLine();
42
	bool CheckForLineBreak();
43
	bool CheckForLineBreak();
43
	void BufEncode();
44
	void BufEncode();
44
} WB1;
45
} WB1;
45
 
46
 
46
char line[500];
47
char line[500];
47
 
48
 
48
bool link, cur_encoding, t_html, t_body;
49
bool link, cur_encoding, t_html, t_body;
49
 
50
 
50
 
51
 
51
dword bufpointer=0;
52
dword bufpointer=0;
52
dword bufsize=0;
53
dword bufsize=0;
53
 
54
 
54
char header[150];
55
char header[150];
55
 
56
 
56
int body_magrin=6;
57
int body_magrin=6;
57
int basic_line_h=22;
58
int basic_line_h=22;
58
 
59
 
59
scroll_bar scroll_wv = { 15,NULL,NULL,NULL,0,2,NULL,0,0,0xeeeeee,0xBBBbbb,0xeeeeee};
60
scroll_bar scroll_wv = { 15,NULL,NULL,NULL,0,2,NULL,0,0,0xeeeeee,0xBBBbbb,0xeeeeee};
60
 
61
 
61
//============================================================================================
62
//============================================================================================
62
void TWebBrowser::DrawStyle()
63
void TWebBrowser::DrawStyle()
63
{
64
{
64
	dword start_x, line_length, stolbec_len;
65
	dword start_x, line_length, stolbec_len;
65
	
66
	
66
	if (!header)
67
	if (style.main_title)
67
	{
68
	{
-
 
69
		strncpy(#header, #line, sizeof(header)-1);
-
 
70
		strncat(#header, " - ", sizeof(header)-1);
-
 
71
		strncat(#header, #version, sizeof(header)-1);
-
 
72
		line = 0;
-
 
73
		return;
-
 
74
	}
68
		strncpy(#header, #line, sizeof(header)-1);
75
	if (t_html) && (!t_body) {
69
		line = 0;
76
		line = 0;
70
		return;
77
		return;
71
	}
78
	}
72
	if (t_html) && (!t_body) return;
-
 
73
	
79
	
74
	if (line)
80
	if (line)
75
	{
81
	{
76
		start_x = stolbec * list.font_w + body_magrin + list.x;
82
		start_x = stolbec * list.font_w + body_magrin + list.x;
77
		stolbec_len = strlen(#line) * zoom;
83
		stolbec_len = strlen(#line) * zoom;
78
		line_length = stolbec_len * list.font_w;
84
		line_length = stolbec_len * list.font_w;
79
 
85
 
80
		if (debug_mode) {
86
		if (debug_mode) {
81
			DrawBuf.DrawBar(start_x, draw_y, line_length, list.item_h, 0xDDDddd);
87
			DrawBuf.DrawBar(start_x, draw_y, line_length, list.item_h, 0xDDDddd);
82
		}
88
		}
83
 
89
 
84
		if (style.bg_color!=page_bg) {
90
		if (style.bg_color!=page_bg) {
85
			DrawBuf.DrawBar(start_x, draw_y, line_length, list.item_h, style.bg_color);
91
			DrawBuf.DrawBar(start_x, draw_y, line_length, list.item_h, style.bg_color);
86
		}
92
		}
87
 
93
 
88
		if (style.image) {
94
		if (style.image) {
89
			DrawBuf.DrawBar(start_x, draw_y, line_length, list.item_h-1, 0xF9DBCB);
95
			DrawBuf.DrawBar(start_x, draw_y, line_length, list.item_h-1, 0xF9DBCB);
90
		}
96
		}
91
		if (style.button) {
97
		if (style.button) {
92
			DrawBuf.DrawBar(start_x, draw_y, line_length, list.item_h - calc(zoom*2), 0xCCCccc);
98
			DrawBuf.DrawBar(start_x, draw_y, line_length, list.item_h - calc(zoom*2), 0xCCCccc);
93
			DrawBuf.DrawBar(start_x, draw_y + list.item_h - calc(zoom*2), line_length, zoom, 0x999999);
99
			DrawBuf.DrawBar(start_x, draw_y + list.item_h - calc(zoom*2), line_length, zoom, 0x999999);
94
		}
100
		}
95
 
101
 
96
		DrawBuf.WriteText(start_x, draw_y, list.font_type, text_colors[text_color_index], #line);
102
		DrawBuf.WriteText(start_x, draw_y, list.font_type, text_colors[text_color_index], #line);
97
		if (style.b) DrawBuf.WriteText(start_x+1, draw_y, list.font_type, text_colors[text_color_index], #line);
103
		if (style.b) DrawBuf.WriteText(start_x+1, draw_y, list.font_type, text_colors[text_color_index], #line);
98
		if (style.s) DrawBuf.DrawBar(start_x, list.item_h / 2 - zoom + draw_y, line_length, zoom, text_colors[text_color_index]);
104
		if (style.s) DrawBuf.DrawBar(start_x, list.item_h / 2 - zoom + draw_y, line_length, zoom, text_colors[text_color_index]);
99
		if (style.u) DrawBuf.DrawBar(start_x, list.item_h - zoom - zoom + draw_y, line_length, zoom, text_colors[text_color_index]);
105
		if (style.u) DrawBuf.DrawBar(start_x, list.item_h - zoom - zoom + draw_y, line_length, zoom, text_colors[text_color_index]);
100
		if (link) {
106
		if (link) {
101
			if (line[0]==' ') && (line[1]==NULL) {} else {
107
			if (line[0]==' ') && (line[1]==NULL) {} else {
102
				DrawBuf.DrawBar(start_x, draw_y + list.item_h - calc(zoom*2), line_length, zoom, link_color_inactive);
108
				DrawBuf.DrawBar(start_x, draw_y + list.item_h - calc(zoom*2), line_length, zoom, link_color_inactive);
103
				PageLinks.AddText(start_x, draw_y + list.y, line_length, list.item_h - calc(zoom*2), UNDERLINE, zoom);				
109
				PageLinks.AddText(start_x, draw_y + list.y, line_length, list.item_h - calc(zoom*2), UNDERLINE, zoom);				
104
			}
110
			}
105
		}
111
		}
106
		stolbec += stolbec_len;
112
		stolbec += stolbec_len;
107
		if (debug_mode) debug(#line);
113
		if (debug_mode) debug(#line);
108
		line = NULL;
114
		line = NULL;
109
	}
115
	}
110
}
116
}
111
//============================================================================================
117
//============================================================================================
112
void TWebBrowser::SetPageDefaults()
118
void TWebBrowser::SetPageDefaults()
113
{
119
{
114
	style.b = style.u = style.s = style.h = style.blq = t_html = t_body = style.pre =
120
	style.b = style.u = style.s = style.h = style.blq = t_html = t_body = style.pre =
115
	style.li = link = text_color_index = text_colors[0] = style.li_tab = false;
121
	style.li = link = text_color_index = text_colors[0] = style.li_tab = style.main_title = false;
116
	style.align = ALIGN_LEFT;
122
	style.align = ALIGN_LEFT;
117
	link_color_inactive = 0x0000FF;
123
	link_color_inactive = 0x0000FF;
118
	link_color_active = 0xFF0000;
124
	link_color_active = 0xFF0000;
119
	page_bg = 0xFFFFFF;
125
	page_bg = 0xFFFFFF;
120
	style.bg_color = page_bg;
126
	style.bg_color = page_bg;
121
	DrawBuf.Fill(0, page_bg);
127
	DrawBuf.Fill(0, page_bg);
122
	PageLinks.Clear();
128
	PageLinks.Clear();
123
	anchors.clear();
129
	anchors.clear();
124
	strncpy(#header, #version, sizeof(header)-1);
130
	header = NULL;
125
	cur_encoding = CH_NULL;
131
	cur_encoding = CH_NULL;
126
	draw_y = body_magrin;
132
	draw_y = body_magrin;
127
	stolbec = 0;
133
	stolbec = 0;
128
	line = 0;
134
	line = 0;
129
	zoom = 1;
135
	zoom = 1;
130
	//hold original buffer
136
	//hold original buffer
131
	if (o_bufpointer) o_bufpointer=free(o_bufpointer);
137
	if (o_bufpointer) o_bufpointer=free(o_bufpointer);
132
	o_bufpointer = malloc(bufsize);
138
	o_bufpointer = malloc(bufsize);
133
	memmov(o_bufpointer, bufpointer, bufsize);
139
	memmov(o_bufpointer, bufpointer, bufsize);
134
}
140
}
135
//============================================================================================
141
//============================================================================================
136
void TWebBrowser::AddCharToTheLine(unsigned char _char)
142
void TWebBrowser::AddCharToTheLine(unsigned char _char)
137
{
143
{
138
	dword line_len;
144
	dword line_len;
139
	if (_char<=15) _char=' ';
145
	if (_char<=15) _char=' ';
140
	line_len = strlen(#line);
146
	line_len = strlen(#line);
141
	if (!style.pre) && (_char == ' ')
147
	if (!style.pre) && (_char == ' ')
142
	{
148
	{
143
		if (line[line_len-1]==' ') return; //no double spaces
149
		if (line[line_len-1]==' ') return; //no double spaces
144
		if (!stolbec) && (!line) return; //no paces at the beginning of the line
150
		if (!stolbec) && (!line) return; //no paces at the beginning of the line
145
	}
151
	}
146
	if (line_len < sizeof(line)) chrcat(#line, _char);
152
	if (line_len < sizeof(line)) chrcat(#line, _char);
147
	CheckForLineBreak();
153
	CheckForLineBreak();
148
}
154
}
149
//============================================================================================
155
//============================================================================================
150
void TWebBrowser::ParseHtml(){
156
void TWebBrowser::ParseHtml(){
151
	word bukva[2];
157
	word bukva[2];
152
	char unicode_symbol[10];
158
	char unicode_symbol[10];
153
	dword unicode_symbol_result;
159
	dword unicode_symbol_result;
154
	dword j;
160
	dword j;
155
	bool ignor_param=false;
161
	bool ignor_param=false;
156
	int tab_len;
162
	int tab_len;
157
	dword bufpos;
163
	dword bufpos;
158
	SetPageDefaults();
164
	SetPageDefaults();
159
	if (strstri(bufpointer, "
165
	if (strstri(bufpointer, "
160
		t_body = true;
166
		t_body = true;
161
		if (strstri(bufpointer, "
167
		if (strstri(bufpointer, "
162
	} 
168
	} 
163
	for (bufpos=bufpointer ; (bufpos < bufpointer+bufsize) && (ESBYTE[bufpos]!=0) ; bufpos++;)
169
	for (bufpos=bufpointer ; (bufpos < bufpointer+bufsize) && (ESBYTE[bufpos]!=0) ; bufpos++;)
164
	{
170
	{
165
		bukva = ESBYTE[bufpos];
171
		bukva = ESBYTE[bufpos];
166
		switch (bukva)
172
		switch (bukva)
167
		{
173
		{
168
		case 0x0a:
174
		case 0x0a:
169
			if (style.pre) {
175
			if (style.pre) {
170
				DrawStyle();
176
				DrawStyle();
171
				NewLine();
177
				NewLine();
172
			} else {
178
			} else {
173
				AddCharToTheLine(0x0a);
179
				AddCharToTheLine(0x0a);
174
			}
180
			}
175
			break;
181
			break;
176
		case 0x09:
182
		case 0x09:
177
			if (style.pre) {
183
			if (style.pre) {
178
				tab_len = strlen(#line) + stolbec % 4;
184
				tab_len = strlen(#line) + stolbec % 4;
179
				if (!tab_len) tab_len = 4; else tab_len = 4 - tab_len;
185
				if (!tab_len) tab_len = 4; else tab_len = 4 - tab_len;
180
				for (j=0; j
186
				for (j=0; j
181
			} else {
187
			} else {
182
				AddCharToTheLine(0x09);
188
				AddCharToTheLine(0x09);
183
			}
189
			}
184
			break;
190
			break;
185
		case '&': //  and so on
191
		case '&': //  and so on
186
			for (j=1, unicode_symbol=0; (ESBYTE[bufpos+j]<>';') && (j<8); j++)
192
			for (j=1, unicode_symbol=0; (ESBYTE[bufpos+j]<>';') && (j<8); j++)
187
			{
193
			{
188
				bukva = ESBYTE[bufpos+j];
194
				bukva = ESBYTE[bufpos+j];
189
				chrcat(#unicode_symbol, bukva);
195
				chrcat(#unicode_symbol, bukva);
190
			}
196
			}
191
			if (GetUnicodeSymbol(#line, #unicode_symbol, sizeof(line)-1)) {
197
			if (GetUnicodeSymbol(#line, #unicode_symbol, sizeof(line)-1)) {
192
				bufpos += j;
198
				bufpos += j;
193
				CheckForLineBreak();
199
				CheckForLineBreak();
194
			} else {
200
			} else {
195
				AddCharToTheLine('&');
201
				AddCharToTheLine('&');
196
			}
202
			}
197
			break;
203
			break;
198
		case '<':
204
		case '<':
199
			bufpos++;
205
			bufpos++;
200
			if (!strncmp(bufpos,"!--",3))
206
			if (!strncmp(bufpos,"!--",3))
201
			{
207
			{
202
				bufpos+=3;
208
				bufpos+=3;
203
				while (strncmp(bufpos,"-->",3)!=0) && (bufpos < bufpointer + bufsize)
209
				while (strncmp(bufpos,"-->",3)!=0) && (bufpos < bufpointer + bufsize)
204
				{
210
				{
205
					bufpos++;
211
					bufpos++;
206
				}
212
				}
207
				bufpos+=2;
213
				bufpos+=2;
208
				break;
214
				break;
209
			}
215
			}
210
			tag.reset();
216
			tag.reset();
211
			if (ESBYTE[bufpos] == '/') {
217
			if (ESBYTE[bufpos] == '/') {
212
				tag.opened = false;
218
				tag.opened = false;
213
				bufpos++;
219
				bufpos++;
214
			}
220
			}
215
 
221
 
216
			ignor_param=false;
222
			ignor_param=false;
217
			while (ESBYTE[bufpos] !='>') && (bufpos < bufpointer + bufsize) //ïîëó÷àåì òåã è åãî ïàðàìåòðû
223
			while (ESBYTE[bufpos] !='>') && (bufpos < bufpointer + bufsize) //ïîëó÷àåì òåã è åãî ïàðàìåòðû
218
			{
224
			{
219
				bukva = ESBYTE[bufpos];
225
				bukva = ESBYTE[bufpos];
220
				if (bukva == '\9') || (bukva == '\x0a') || (bukva == '\x0d') bukva = ' ';
226
				if (bukva == '\9') || (bukva == '\x0a') || (bukva == '\x0d') bukva = ' ';
221
				if (!ignor_param) && (bukva <>' ')
227
				if (!ignor_param) && (bukva <>' ')
222
				{
228
				{
223
					if (strlen(#tag.name)+1
229
					if (strlen(#tag.name)+1
224
				}
230
				}
225
				else
231
				else
226
				{
232
				{
227
					ignor_param = true;
233
					ignor_param = true;
228
					if (strlen(#tag.params)+1
234
					if (strlen(#tag.params)+1
229
					//	chrncat(#tag.params, bukva, sizeof(tag.params)-1);
235
					//	chrncat(#tag.params, bukva, sizeof(tag.params)-1);
230
				}
236
				}
231
				bufpos++;
237
				bufpos++;
232
			}
238
			}
233
			strlwr(#tag.name);
239
			strlwr(#tag.name);
234
 
240
 
235
			// ignore text inside the next tags
241
			// ignore text inside the next tags
236
			if (tag.is("script")) || (tag.is("style")) || (tag.is("binary")) || (tag.is("select"))  { 
242
			if (tag.is("script")) || (tag.is("style")) || (tag.is("binary")) || (tag.is("select"))  { 
237
				sprintf(#tag.params, "", #tag.name);
243
				sprintf(#tag.params, "", #tag.name);
238
				j = strstri(bufpos, #tag.params);
244
				j = strstri(bufpos, #tag.params);
239
				if (j!=-1) bufpos = j-1;
245
				if (j!=-1) bufpos = j-1;
240
				break;
246
				break;
241
			}
247
			}
242
 
248
 
243
			if (tag.name[strlen(#tag.name)-1]=='/') tag.name[strlen(#tag.name)-1]=NULL; //for br/ !!!!!!!!
249
			if (tag.name[strlen(#tag.name)-1]=='/') tag.name[strlen(#tag.name)-1]=NULL; //for br/ !!!!!!!!
244
			if (tag.params) tag.parse_params();
250
			if (tag.params) tag.parse_params();
245
 
251
 
246
			if (tag.name) {
252
			if (tag.name) {
247
				CheckForLineBreak();
253
				CheckForLineBreak();
248
				DrawStyle();
254
				DrawStyle();
249
				if (tag.name) SetStyle();
255
				if (tag.name) SetStyle();
250
			}
256
			}
251
			break;
257
			break;
252
		default:
258
		default:
253
			AddCharToTheLine(ESBYTE[bufpos]);
259
			AddCharToTheLine(ESBYTE[bufpos]);
254
		}
260
		}
255
	}
261
	}
256
	DrawStyle();
262
	DrawStyle();
257
	NewLine();
263
	NewLine();
258
	list.count = draw_y;
264
	list.count = draw_y;
259
	list.CheckDoesValuesOkey();
265
	list.CheckDoesValuesOkey();
260
	anchors.current = NULL;
266
	anchors.current = NULL;
-
 
267
	if (!header) {
-
 
268
		strncpy(#header, #version, sizeof(header)-1);
-
 
269
		DrawTitle(#header);
-
 
270
	}
261
}
271
}
262
//============================================================================================
272
//============================================================================================
263
bool TWebBrowser::CheckForLineBreak()
273
bool TWebBrowser::CheckForLineBreak()
264
{
274
{
265
	int line_break_pos;
275
	int line_break_pos;
266
	char new_line_text[4096];
276
	char new_line_text[4096];
-
 
277
	//Do we need a line break?
267
	if (strlen(#line)*zoom + stolbec < list.column_max) return false;
278
	if (strlen(#line)*zoom + stolbec < list.column_max) return false;
-
 
279
	//Yes, we do. Lets calculate where...
268
	line_break_pos = strrchr(#line, ' ');
280
	line_break_pos = strrchr(#line, ' ');
-
 
281
	//Is a new line fits in the current line?
269
	if (line_break_pos*zoom + stolbec > list.column_max) {
282
	if (line_break_pos*zoom + stolbec > list.column_max) {
270
		line_break_pos = list.column_max/zoom - stolbec;
283
		line_break_pos = list.column_max/zoom - stolbec;
271
		while(line_break_pos) && (line[line_break_pos]!=' ') line_break_pos--;
284
		while(line_break_pos) && (line[line_break_pos]!=' ') line_break_pos--;
272
	}
285
	}
-
 
286
	//Maybe a new line is too big for the whole new line? Then we have to split it
273
	if (!line_break_pos) && (strlen(#line)*zoom>list.column_max) {
287
	if (!line_break_pos) && (style.li_tab*5 + strlen(#line) * zoom >= list.column_max) {
274
		line_break_pos=list.column_max/zoom; 
288
		line_break_pos = list.column_max/zoom - stolbec;
275
		if (!stolbec)&&(style.pre) draw_y-=list.item_h; //hack to fix https://prnt.sc/rk3kyt
-
 
276
	}
289
	}
277
	strcpy(#new_line_text, #line + line_break_pos);
290
	strcpy(#new_line_text, #line + line_break_pos);
278
	line[line_break_pos] = 0x00;
291
	line[line_break_pos] = 0x00;		
-
 
292
	
279
	DrawStyle();
293
	DrawStyle();
-
 
294
 
280
	strcpy(#line, #new_line_text);
295
	strcpy(#line, #new_line_text);
281
	NewLine();
296
	NewLine();
282
	//if (strlen(#line)*zoom + stolbec > list.column_max)CheckForLineBreak();
297
	//if (strlen(#line)*zoom + stolbec > list.column_max)CheckForLineBreak();
283
	return true;
298
	return true;
284
}
299
}
285
//============================================================================================
300
//============================================================================================
286
void TWebBrowser::SetStyle() {
301
void TWebBrowser::SetStyle() {
287
	char img_path[4096]=0;
302
	char img_path[4096]=0;
288
	int meta_encoding;
303
	int meta_encoding;
289
 
304
 
290
	dword value;
305
	dword value;
291
 
306
 
292
	if (value = tag.get_value_of("name=")) || (value = tag.get_value_of("id=")) {
307
	if (value = tag.get_value_of("name=")) || (value = tag.get_value_of("id=")) {
293
		anchors.add(value, draw_y);
308
		anchors.add(value, draw_y);
294
		if (anchors.current) && (streq(value, #anchors.current+1)) {
309
		if (anchors.current) && (streq(value, #anchors.current+1)) {
295
			list.first = draw_y;
310
			list.first = draw_y;
296
			anchors.current = NULL;
311
			anchors.current = NULL;
297
		}
312
		}
298
	}	
313
	}
299
 
-
 
300
	if (tag.is("html")) {
314
	if (tag.is("html")) {
301
		t_html = tag.opened;
315
		t_html = tag.opened;
302
		return;
316
		return;
303
	}
317
	}
304
	if (tag.is("title")) {
-
 
305
		if (tag.opened) header=NULL;
-
 
306
		return;
-
 
307
	}
-
 
308
	
-
 
309
	if (tag.is("q"))
318
	if (tag.is("q"))
310
	{
319
	{
311
		if (tag.opened)	{
320
		if (tag.opened)	{
312
			meta_encoding = strlen(#line);
321
			meta_encoding = strlen(#line);
313
			if (line[meta_encoding-1] != ' ') chrcat(#line, ' ');
322
			if (line[meta_encoding-1] != ' ') chrcat(#line, ' ');
314
			chrcat(#line, '\"');
323
			chrcat(#line, '\"');
315
		}
324
		}
316
		if (!tag.opened) strcat(#line, "\" ");
325
		if (!tag.opened) strcat(#line, "\" ");
317
		return;
326
		return;
318
	}
327
	}
-
 
328
	if (tag.is("title")) {
-
 
329
		style.main_title = tag.opened;
-
 
330
		if (!tag.opened) DrawTitle(#header);
-
 
331
		return;
-
 
332
	}
319
	if (tag.is("body")) {
333
	if (tag.is("body")) {
320
		t_body = tag.opened;
334
		t_body = tag.opened;
321
		if (value = tag.get_value_of("link="))  link_color_inactive = GetColor(value);
335
		if (value = tag.get_value_of("link="))  link_color_inactive = GetColor(value);
322
		if (value = tag.get_value_of("alink=")) link_color_active = GetColor(value);
336
		if (value = tag.get_value_of("alink=")) link_color_active = GetColor(value);
323
		if (value = tag.get_value_of("text="))  text_colors[0]=GetColor(value);
337
		if (value = tag.get_value_of("text="))  text_colors[0]=GetColor(value);
324
		if (value = tag.get_value_of("bgcolor=")) {
338
		if (value = tag.get_value_of("bgcolor=")) {
325
			style.bg_color = page_bg = GetColor(value);
339
			style.bg_color = page_bg = GetColor(value);
326
			DrawBuf.Fill(0, page_bg);
340
			DrawBuf.Fill(0, page_bg);
327
		}
341
		}
328
		if (tag.opened) {
-
 
329
			if (cur_encoding==CH_NULL) {
-
 
330
				cur_encoding = CH_CP866; 
-
 
331
				//BufEncode(CH_UTF8);
-
 
332
				debugln("Document has no information about encoding!");
-
 
333
			}
-
 
334
			if (!streq(#header, #version)) {
-
 
335
				ChangeCharset(charsets[cur_encoding], "CP866", #header);
-
 
336
				strncat(#header, " - ", sizeof(header)-1);
-
 
337
				strncat(#header, #version, sizeof(header)-1);
-
 
338
			}
-
 
339
			DrawTitle(#header);
-
 
340
		}
-
 
341
		return;
342
		return;
342
	}
343
	}
343
	if (tag.is("a")) {
344
	if (tag.is("a")) {
344
		if (tag.opened)
345
		if (tag.opened)
345
		{
346
		{
346
			if (link) IF(text_color_index > 0) text_color_index--; //åñëè ïðåäûäóùèé òåã à íå áûë çàêðûò
347
			if (link) IF(text_color_index > 0) text_color_index--; //åñëè ïðåäûäóùèé òåã à íå áûë çàêðûò
347
			if (value = tag.get_value_of("href=")) && (!strstr(value,"javascript:"))
348
			if (value = tag.get_value_of("href=")) && (!strstr(value,"javascript:"))
348
			{
349
			{
349
				text_color_index++;
350
				text_color_index++;
350
				text_colors[text_color_index] = text_colors[text_color_index-1];
351
				text_colors[text_color_index] = text_colors[text_color_index-1];
351
				link = 1;
352
				link = 1;
352
				text_colors[text_color_index] = link_color_inactive;
353
				text_colors[text_color_index] = link_color_inactive;
353
				PageLinks.AddLink(value);
354
				PageLinks.AddLink(value);
354
			}
355
			}
355
		} else {
356
		} else {
356
			link = 0;
357
			link = 0;
357
			IF(text_color_index > 0) text_color_index--;
358
			IF(text_color_index > 0) text_color_index--;
358
		}
359
		}
359
		return;
360
		return;
360
	}
361
	}
361
	if (tag.is("font")) {
362
	if (tag.is("font")) {
362
		style.bg_color = page_bg;
363
		style.bg_color = page_bg;
363
		if (tag.opened)
364
		if (tag.opened)
364
		{
365
		{
365
			text_color_index++;
366
			text_color_index++;
366
			text_colors[text_color_index] = text_colors[text_color_index-1];
367
			text_colors[text_color_index] = text_colors[text_color_index-1];
367
			if (value = tag.get_value_of("color=")) text_colors[text_color_index] = GetColor(value);
368
			if (value = tag.get_value_of("color=")) text_colors[text_color_index] = GetColor(value);
368
			if (value = tag.get_value_of("bg=")) style.bg_color = GetColor(value);
369
			if (value = tag.get_value_of("bg=")) style.bg_color = GetColor(value);
369
		}
370
		}
370
		else if (text_color_index > 0) text_color_index--;
371
		else if (text_color_index > 0) text_color_index--;
371
		return;
372
		return;
372
	}
373
	}
373
	if (tag.is("div")) {
374
	if (tag.is("div")) {
374
		if (streq(#tag.prior,"div")) && (tag.opened) return;
375
		if (streq(#tag.prior,"div")) && (tag.opened) return;
375
		NewLine();
376
		NewLine();
376
		return;
377
		return;
377
	}
378
	}
378
	if (tag.is("header")) || (tag.is("article")) || (tag.is("footer")) || (tag.is("figure")) {
379
	if (tag.is("header")) || (tag.is("article")) || (tag.is("footer")) || (tag.is("figure")) {
379
		NewLine();
380
		NewLine();
380
		return;
381
		return;
381
	}
382
	}
382
	if (tag.is("p")) {
383
	if (tag.is("p")) {
383
		IF (tag.prior[0] == 'h') || (streq(#tag.prior,"td")) || (streq(#tag.prior,"p")) return;
384
		IF (tag.prior[0] == 'h') || (streq(#tag.prior,"td")) || (streq(#tag.prior,"p")) return;
384
		NewLine();
385
		NewLine();
385
		return;
386
		return;
386
	}
387
	}
387
	if (tag.is("br")) { NewLine(); return; }
388
	if (tag.is("br")) { NewLine(); return; }
388
	if (tag.is("td")) { if (tag.opened) AddCharToTheLine(' '); return; }
389
	if (tag.is("td")) { if (tag.opened) AddCharToTheLine(' '); return; }
389
	if (tag.is("tr")) { if (tag.opened) NewLine(); return; }
390
	if (tag.is("tr")) { if (tag.opened) NewLine(); return; }
390
	if (tag.is("b")) || (tag.is("strong")) || (tag.is("big")) { style.b = tag.opened; return; }
391
	if (tag.is("b")) || (tag.is("strong")) || (tag.is("big")) { style.b = tag.opened; return; }
391
	if (tag.is("button")) { style.button = tag.opened; stolbec++; return; }
392
	if (tag.is("button")) { style.button = tag.opened; stolbec++; return; }
392
	if (tag.is("u")) || (tag.is("ins")) { style.u=tag.opened; return;}
393
	if (tag.is("u")) || (tag.is("ins")) { style.u=tag.opened; return;}
393
	if (tag.is("s")) || (tag.is("strike")) || (tag.is("del")) { style.s=tag.opened; return; }
394
	if (tag.is("s")) || (tag.is("strike")) || (tag.is("del")) { style.s=tag.opened; return; }
394
	if (tag.is("dd")) { stolbec += 5; return; }
395
	if (tag.is("dd")) { stolbec += 5; return; }
395
	if (tag.is("blockquote")) { style.blq = tag.opened; return; }
396
	if (tag.is("blockquote")) { style.blq = tag.opened; return; }
396
	if (tag.is("pre")) || (tag.is("code")) { style.pre = tag.opened; return; }
397
	if (tag.is("pre")) || (tag.is("code")) { style.pre = tag.opened; return; }
397
	if (tag.is("img")) {
398
	if (tag.is("img")) {
398
		if (value = tag.get_value_of("src=")) strlcpy(#img_path, value, sizeof(img_path)-1);
399
		if (value = tag.get_value_of("src=")) strlcpy(#img_path, value, sizeof(img_path)-1);
399
		if (value = tag.get_value_of("title=")) && (strlen(value)
400
		if (value = tag.get_value_of("title=")) && (strlen(value)
400
		if (value = tag.get_value_of("alt=")) && (strlen(value)
401
		if (value = tag.get_value_of("alt=")) && (strlen(value)
401
		if (!img_path) { line=0; return; }
402
		if (!img_path) { line=0; return; }
402
		style.image = true;
403
		style.image = true;
403
		text_color_index++;
404
		text_color_index++;
404
		text_colors[text_color_index] = 0x9A6F29;
405
		text_colors[text_color_index] = 0x9A6F29;
405
		if (!line) {
406
		if (!line) {
406
			if (!strncmp(#img_path, "data:", 5)) img_path=0;
407
			if (!strncmp(#img_path, "data:", 5)) img_path=0;
407
			replace_char(#img_path, '?', NULL, strlen(#img_path));
408
			replace_char(#img_path, '?', NULL, strlen(#img_path));
408
			sprintf(#line, "[%s]", #img_path+strrchr(#img_path, '/'));
409
			sprintf(#line, "[%s]", #img_path+strrchr(#img_path, '/'));
409
			line[50]= NULL;
410
			line[50]= NULL;
410
		}
411
		}
411
		while (CheckForLineBreak()) {};
412
		while (CheckForLineBreak()) {};
412
		DrawStyle();
413
		DrawStyle();
413
		text_color_index--;
414
		text_color_index--;
414
		style.image = false;
415
		style.image = false;
415
		//ImgCache.Images( list.x, draw_y, WB1.list.w); 
416
		//ImgCache.Images( list.x, draw_y, WB1.list.w); 
416
		return; 
417
		return; 
417
	}
418
	}
-
 
419
	if (tag.is("h4")) {
-
 
420
		NewLine();
-
 
421
		style.h = tag.opened;
-
 
422
		style.b = tag.opened;
-
 
423
	}
418
	if (tag.is("h1")) || (tag.is("h2")) || (tag.is("h3")) || (tag.is("caption")) {
424
	if (tag.is("h1")) || (tag.is("h2")) || (tag.is("h3")) || (tag.is("caption")) {
419
		style.h = tag.opened;
425
		style.h = tag.opened;
420
		if (tag.opened)
426
		if (tag.opened) {
421
		{
-
 
422
			NewLine();
427
			NewLine();
423
			draw_y += 10;
428
			draw_y += 10;
424
			WB1.zoom=2;
429
			WB1.zoom=2;
425
			WB1.list.font_type |= 10011001b;
430
			WB1.list.font_type |= 10011001b;
426
			if (value = tag.get_value_of("align=")) {
-
 
427
				if (streq(value, "center")) style.align = ALIGN_CENTER;
-
 
428
				if (streq(value, "right")) style.align = ALIGN_RIGHT;
-
 
429
			}
-
 
430
			list.item_h = basic_line_h * 2;
431
			list.item_h = basic_line_h * 2 - 2;
431
			if (tag.is("h1")) style.b = true;
432
			if (tag.is("h1")) style.b = true;
432
		}
-
 
433
		else
433
		} else {
434
		{
-
 
435
			if (tag.is("h1")) style.b = false;
434
			if (tag.is("h1")) style.b = false;
436
			NewLine();
435
			NewLine();
437
			WB1.zoom=1;
436
			WB1.zoom=1;
438
			WB1.list.font_type = 10011000b;
437
			WB1.list.font_type = 10011000b;
439
			style.align = ALIGN_LEFT;
-
 
440
			list.item_h = basic_line_h;
438
			list.item_h = basic_line_h;
441
		}
439
		}
442
		return;
440
		return;
443
	}
441
	}
444
	if (tag.is("dt")) {
442
	if (tag.is("dt")) {
445
		style.li = tag.opened;
443
		style.li = tag.opened;
446
		if (tag.opened) NewLine();
444
		if (tag.opened) NewLine();
447
		return;
445
		return;
448
	}
446
	}
449
	if (tag.is("li")) || (tag.is("dt"))
447
	if (tag.is("li")) || (tag.is("dt"))
450
	{
448
	{
451
		style.li = tag.opened;
449
		style.li = tag.opened;
452
		if (tag.opened)
450
		if (tag.opened)
453
		{
451
		{
-
 
452
			if (style.li_tab==0) style.li_tab++;
454
			NewLine();
453
			NewLine();
455
			stolbec = style.li_tab * 5 - 2;
454
			stolbec = style.li_tab * 5 - 2;
456
			strcpy(#line, "\31 ");
455
			strcpy(#line, "\31 ");
457
			//stolbec-=2;
456
			//stolbec-=2;
458
		}
457
		}
459
		return;
458
		return;
460
	}
459
	}
461
	if (tag.is("ul")) || (tag.is("ol")) {
460
	if (tag.is("ul")) || (tag.is("ol")) {
462
		if (!tag.opened)
461
		if (!tag.opened)
463
		{
462
		{
464
			style.li = false;
463
			style.li = false;
465
			style.li_tab--;
464
			if (style.li_tab>0) style.li_tab--;
466
			NewLine();
465
			NewLine();
467
		} 
466
		} 
-
 
467
		else {
468
		else style.li_tab++;
468
			if (style.li_tab<5) style.li_tab++;
-
 
469
		}
469
	}
470
	}
470
	if (tag.is("hr")) {
471
	if (tag.is("hr")) {
471
		if (value = tag.get_value_of("color=")) EDI = GetColor(value); else EDI = 0x999999;
472
		if (value = tag.get_value_of("color=")) EDI = GetColor(value); else EDI = 0x999999;
472
		$push edi;
473
		$push edi;
473
		NewLine();
474
		NewLine();
474
		$pop edi;
475
		$pop edi;
475
		draw_y += 10;
476
		draw_y += 10;
476
		DrawBuf.DrawBar(5, draw_y - 1, list.w-10, 1, EDI);
477
		DrawBuf.DrawBar(5, draw_y - 1, list.w-10, 1, EDI);
477
		NewLine();
478
		NewLine();
478
		draw_y += 10;
479
		draw_y += 10;
479
		return;
480
		return;
480
	}
481
	}
481
	if (tag.is("meta")) || (tag.is("?xml")) {
482
	if (tag.is("meta")) || (tag.is("?xml")) {
482
		meta_encoding = CH_NULL;
483
		meta_encoding = CH_NULL;
483
		if (value = tag.get_value_of("charset=")) || (value = tag.get_value_of("content=")) || (value = tag.get_value_of("encoding="))
484
		if (value = tag.get_value_of("charset=")) || (value = tag.get_value_of("content=")) || (value = tag.get_value_of("encoding="))
484
		{
485
		{
485
			value += strrchr(value, '='); //search in content=
486
			value += strrchr(value, '='); //search in content=
486
			strlwr(value);
487
			strlwr(value);
487
			if      (streq(value,"utf-8"))        || (streq(value,"utf8"))        meta_encoding = CH_UTF8;
488
			if      (streq(value,"utf-8"))        || (streq(value,"utf8"))        meta_encoding = CH_UTF8;
488
			else if (streq(value,"windows-1251")) || (streq(value,"windows1251")) meta_encoding = CH_CP1251;
489
			else if (streq(value,"windows-1251")) || (streq(value,"windows1251")) meta_encoding = CH_CP1251;
489
			else if (streq(value,"dos"))          || (streq(value,"cp-866"))      meta_encoding = CH_CP866;
490
			else if (streq(value,"dos"))          || (streq(value,"cp-866"))      meta_encoding = CH_CP866;
490
			else if (streq(value,"iso-8859-5"))   || (streq(value,"iso8859-5"))   meta_encoding = CH_ISO8859_5;
491
			else if (streq(value,"iso-8859-5"))   || (streq(value,"iso8859-5"))   meta_encoding = CH_ISO8859_5;
491
			else if (streq(value,"koi8-r"))       || (streq(value,"koi8-u"))      meta_encoding = CH_KOI8;
492
			else if (streq(value,"koi8-r"))       || (streq(value,"koi8-u"))      meta_encoding = CH_KOI8;
492
		}
493
		}
493
		if (meta_encoding!=CH_NULL) BufEncode(meta_encoding);
494
		if (meta_encoding!=CH_NULL) {
-
 
495
			BufEncode(meta_encoding);
-
 
496
			if (header) {
-
 
497
				ChangeCharset(charsets[cur_encoding], "CP866", #header);
-
 
498
				DrawTitle(#header);
-
 
499
			}
-
 
500
		}
494
		return;
501
		return;
495
	}
502
	}
496
}
503
}
497
//============================================================================================
504
//============================================================================================
498
void TWebBrowser::BufEncode(dword set_new_encoding)
505
void TWebBrowser::BufEncode(dword set_new_encoding)
499
{
506
{
500
	if (cur_encoding != set_new_encoding) {
507
	if (cur_encoding != set_new_encoding) {
501
		cur_encoding = set_new_encoding;
508
		cur_encoding = set_new_encoding;
502
		bufpointer = ChangeCharset(charsets[cur_encoding], "CP866", bufpointer);		
509
		bufpointer = ChangeCharset(charsets[cur_encoding], "CP866", bufpointer);		
503
	}
510
	}
504
}
511
}
505
//============================================================================================
512
//============================================================================================
506
void TWebBrowser::DrawScroller()
513
void TWebBrowser::DrawScroller()
507
{
514
{
508
	scroll_wv.max_area = list.count;
515
	scroll_wv.max_area = list.count;
509
	scroll_wv.cur_area = list.visible;
516
	scroll_wv.cur_area = list.visible;
510
	scroll_wv.position = list.first;
517
	scroll_wv.position = list.first;
511
	scroll_wv.all_redraw = 0;
518
	scroll_wv.all_redraw = 0;
512
	scroll_wv.start_x = list.x + list.w;
519
	scroll_wv.start_x = list.x + list.w;
513
	scroll_wv.start_y = list.y;
520
	scroll_wv.start_y = list.y;
514
	scroll_wv.size_y = list.h;
521
	scroll_wv.size_y = list.h;
515
	scrollbar_v_draw(#scroll_wv);
522
	scrollbar_v_draw(#scroll_wv);
516
}
523
}
517
//============================================================================================
524
//============================================================================================
518
void TWebBrowser::NewLine()
525
void TWebBrowser::NewLine()
519
{
526
{
520
	dword onleft, ontop;
527
	dword onleft, ontop;
521
	static int empty_line=0;
528
	static int empty_line=0;
522
 
529
 
523
	if (!stolbec) && (draw_y==body_magrin) return;
530
	if (!stolbec) && (draw_y==body_magrin) return;
524
	
531
	
525
	if (style.li) && (stolbec == style.li_tab * 5) { 
532
	if (style.li) && (stolbec == style.li_tab * 5) { 
526
		if (empty_line<1) empty_line++;
533
		if (empty_line<1) empty_line++;
527
		else return;
534
		else return;
528
	} else if (!stolbec) { 
535
	} else if (!stolbec) { 
529
		if (empty_line<1) empty_line++;
536
		if (empty_line<1) empty_line++;
530
		else return;
537
		else return;
531
	} else {
538
	} else {
532
		empty_line=0;
539
		empty_line=0;
533
	}
540
	}
534
 
541
 
535
	onleft = list.x + body_magrin;
542
	onleft = list.x + body_magrin;
536
	ontop = draw_y + list.y;
543
	ontop = draw_y + list.y;
537
	if (t_html) && (!t_body) return;
544
	if (t_html) && (!t_body) return;
538
	draw_y += list.item_h;
545
	draw_y += list.item_h;
539
	if (style.blq) stolbec = 6; else stolbec = 0;
546
	if (style.blq) stolbec = 6; else stolbec = 0;
540
	if (style.li) stolbec = style.li_tab * 5;
547
	if (style.li) stolbec = style.li_tab * 5;
541
	if (debug_mode) debugln(NULL);
548
	if (debug_mode) debugln(NULL);
542
}
549
}
543
//============================================================================================
550
//============================================================================================
544
void TWebBrowser::DrawPage()
551
void TWebBrowser::DrawPage()
545
{
552
{
546
	PutPaletteImage(list.first * DrawBuf.bufw * 4 + buf_data+8, DrawBuf.bufw, list.h, DrawBuf.bufx, DrawBuf.bufy, 32, 0);	
553
	PutPaletteImage(list.first * DrawBuf.bufw * 4 + buf_data+8, DrawBuf.bufw, list.h, DrawBuf.bufx, DrawBuf.bufy, 32, 0);	
547
	DrawScroller();
554
	DrawScroller();
548
}
555
}
549
>
556
>