Subversion Repositories Kolibri OS

Rev

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