Subversion Repositories Kolibri OS

Rev

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

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