Subversion Repositories Kolibri OS

Rev

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

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