Subversion Repositories Kolibri OS

Rev

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

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