Subversion Repositories Kolibri OS

Rev

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

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