Subversion Repositories Kolibri OS

Rev

Rev 7799 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

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