Subversion Repositories Kolibri OS

Rev

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

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