Subversion Repositories Kolibri OS

Rev

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

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