Subversion Repositories Kolibri OS

Rev

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