Subversion Repositories Kolibri OS

Rev

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

Rev Author Line No. Line
4411 leency 1
 
2
3
 
4
	buf,
5
	filesize,
6
	blink;
7
8
 
4416 leency 9
10
 
11
edit_box address_box= {250,207,16,0xffffff,0x94AECE,0xffffff,0xffffff,0,sizeof(URL),#editURL,#mouse_twb,2,19,19};
12
scroll_bar scroll_wv = { 18,200,398, 44,18,0,115,15,0,0xeeeeee,0xD2CED0,0x555555,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1};
13
14
 
15
	page_links[12000],
16
	header[2048];
17
18
 
19
 
20
 
4411 leency 21
22
 
23
 
24
	llist list; //need #include "..\lib\list_box.h"
4415 leency 25
	void GetNewUrl();
4411 leency 26
	void ReadHtml(byte);
27
	void ShowPage();
28
	void ParseHTML(dword);
29
	void WhatTextStyle(int left1, top1, width1);
30
	void DrawPage();
31
	void DrawScroller();
32
};
33
TWebBrowser WB1;
34
35
 
36
	link, ignor_text, li_tab, cur_encoding, text_align;
37
38
 
39
40
 
41
	text_color_index,
42
	link_color,
43
	bg_color;
44
45
 
46
	stolbec,
47
	tab_len,
48
	anchor_line_num;
49
50
 
51
	tag[100],
52
	tagparam[10000],
53
	parametr[1200],
54
	options[4096],
55
	anchor[256];
56
57
 
4416 leency 58
#include "..\TWB\colors.h"
4411 leency 59
#include "..\TWB\unicode_tags.h"
60
#include "..\TWB\img_cache.h"
61
#include "..\TWB\some_code.h"
62
#include "..\TWB\parce_tag.h"
63
#include "..\TWB\draw_buf.h"
64
65
 
66
67
 
68
 
69
{
70
	int start_x, start_y, line_length, magrin_left=5;
71
72
 
73
	{
74
		strcpy(#header, #line);
75
		strcat(#header, " -");
76
		strcat(#header, #version);
77
		line = 0;
78
		return;
79
	}
80
81
 
4415 leency 82
	{
4411 leency 83
		start_x = stolbec * 6 + list.x + magrin_left;
4414 leency 84
		start_y = stroka * 10 + list.y + magrin_left;
85
		line_length = strlen(#line) * 6;
4411 leency 86
87
 
88
		IF (b_text)	WriteBufText(start_x+1, 0, 0x88, text_colors[text_color_index], #line, drawbuf);
89
		IF (i_text) DrawBufSkew(start_x, 0, line_length, list.line_h);
4414 leency 90
		IF (s_text) DrawBufBar(start_x, 4, line_length, 1, text_colors[text_color_index]);
4411 leency 91
		IF (u_text) DrawBufBar(start_x, 8, line_length, 1, text_colors[text_color_index]);
92
		IF (link) {
93
			UnsafeDefineButton(start_x-2, start_y, line_length + 3, 9, blink + BT_HIDE, 0xB5BFC9);
94
			DrawBufBar(start_x, 8, line_length, 1, text_colors[text_color_index]);
95
		}
96
		stolbec += strlen(#line);
97
	}
98
}
99
//=======================================================================
100
101
 
102
 
103
 
104
//dword TWebBrowser::GetNewUrl(dword CUR_URL, NEW_URL){
105
void TWebBrowser::GetNewUrl(){
106
	int i, len;
107
108
 
109
	{
110
		len=strlen(ABSOLUTE_LINKS[i]);
111
		if (!strcmpn(#URL, ABSOLUTE_LINKS[i], len)) return;
112
	}
113
114
 
115
	strcpy(#editURL, BrowserHistory.CurrentUrl()); //достаём адрес текущей страницы
116
117
 
118
	{
119
		i = strchr(#editURL+8, '/');
120
		editURL[i+7]=0;
121
		strcpy(#URL, #URL+1);
122
	}
123
124
 
125
126
 
127
		{
128
			editURL[strrchr(#editURL, '/')] = 0x00; //обрезаем её урл до последнего /
129
		}
130
131
 
132
		{
133
			strcpy(#URL,#URL+3);
134
			editURL[strrchr(#editURL, '/')-1] = 0x00; //обрезаем её урл до последнего /
135
			goto _CUT_ST_LEVEL_MARK;
136
		}
137
138
 
139
140
 
141
		strcpy(#URL, #editURL);
142
}
143
144
 
145
 
146
 
147
{
148
	if (!strcmp(get_URL_part(5),"http:")))
149
		file_size stdcall (#download_path);
150
	else
151
		file_size stdcall (#URL);
152
153
 
154
	if (!filesize) return;
155
156
 
157
	buf = mem_Alloc(filesize);
158
	if (!strcmp(get_URL_part(5),"http:")))
159
		ReadFile(0, filesize, buf, #download_path);
160
	else
161
		ReadFile(0, filesize, buf, #URL);
162
163
 
164
	if (encoding==_WIN) wintodos(buf);
165
	if (encoding==_UTF) utf8rutodos(buf);
166
	if (encoding==_KOI) koitodos(buf);
167
}
168
169
 
170
 
171
{
172
	address_box.size = address_box.pos = strlen(#editURL);
173
	address_box.offset=0;
174
	edit_box_draw stdcall(#address_box);
175
176
 
177
	{
178
		DrawBar(list.x, list.y, list.w+scroll_wv.size_x+1, list.h, 0xFFFFFF); //fill all
4416 leency 179
		if (GetProcessSlot(downloader_id)<>0) WriteText(list.x + 10, list.y + 18, 0x80, 0, "Loading...");
4414 leency 180
		else
4411 leency 181
		{
182
			WriteText(list.x + 10, list.y + 18, 0x80, 0, "Page not found. May be, URL contains some errors.");
4414 leency 183
			if (!strcmp(get_URL_part(5),"http:"))) WriteText(list.x + 10, list.y + 32, 0x80, 0, "Or Internet unavilable for your configuration.");
184
		}
4411 leency 185
		//return;
186
	}
187
	else
188
		ParseHTML(buf);
189
190
 
191
	if (!strcmp(#version, #header)) DrawTitle(#header);
192
}
193
194
 
195
 
196
 
197
	word bukva[2];
198
	int j, perenos_num;
199
	byte ignor_param;
200
	char temp[768];
201
202
 
203
	b_text = i_text = u_text = s_text = blq_text =
204
	li_text = link = ignor_text = text_color_index = text_colors[0] = li_tab = 0; //обнуляем теги
205
	text_align = ALIGN_LEFT;
206
	link_color = 0x0000FF;
207
	bg_color = 0xFFFFFF;
208
	DrawBufFill();
209
	strcpy(#page_links,"|");
210
	strcpy(#header, #version);
211
	stroka = -list.first;
4415 leency 212
	stolbec = 0;
4411 leency 213
	line = 0;
214
215
 
216
	{
217
		pre_text=0;
218
		if (!strcmp(#URL + strlen(#URL) - 4, ".txt")) pre_text = 1;
219
		if (!strcmp(#URL + strlen(#URL) - 4, ".mht")) ignor_text = 1;
220
	}
221
222
 
223
	{
224
		bukva = ESBYTE[bword];
225
		if (ignor_text) && (bukva<>'<') continue;
226
		switch (bukva)
227
		{
228
		case 0x0a:
229
			if (pre_text)
230
			{
231
				bukva = temp = NULL;
232
				goto NEXT_MARK;
233
			}
234
		case '\9':
235
			if (pre_text) //иначе идём на 0x0d
236
			{
237
				tab_len=strlen(#line)/8;
238
				tab_len=tab_len*8;
239
				tab_len=8+tab_len-strlen(#line);
240
				for (j=0; j
241
				break;
242
			}
243
			goto DEFAULT_MARK;
244
		case '=': //quoted printable
245
			if (strcmp(#URL + strlen(#URL) - 4, ".mht")<>0) goto DEFAULT_MARK;
246
247
 
248
			temp[1] = ESBYTE[bword+2];
249
			temp[2] = '\0';
250
			if (bukva = Hex2Symb(#temp))
251
			{
252
				bword+=2;
253
				goto DEFAULT_MARK;
254
			}
255
			break;
256
257
 
258
			bword++;
259
			tag=0;
260
			for (j=0; (ESBYTE[bword]<>';') && (j<7);   j++, bword++;)
261
			{
262
				bukva = ESBYTE[bword];
263
				chrcat(#tag, bukva);
264
			}
265
			bukva = GetUnicodeSymbol();
266
			if (bukva) goto DEFAULT_MARK;
267
			break;
268
		case '<':
269
			bword++; //промотаем символ <
270
			tag = parametr = tagparam = ignor_param = NULL;
271
			if (ESBYTE[bword] == '!') //фильтрация внутри , дерзко
272
			{
273
				bword++;
274
				if (ESBYTE[bword] == '-')
275
				{
276
				HH_:
277
					do
278
					{
279
						bword++;
280
						if (buf + filesize <= bword) break 2;
281
					}
282
					while (ESBYTE[bword] <>'-');
283
284
 
285
					if (ESBYTE[bword] <>'-') goto HH_;
286
				}
287
			}
288
			while (ESBYTE[bword] !='>') && (bword < buf + filesize) //получаем тег и его параметры
289
			{
290
				bukva = ESBYTE[bword];
291
				if (bukva == '\9') || (bukva == '\x0a') || (bukva == '\x0d') bukva = ' ';
292
				if (!ignor_param) && (bukva <>' ')
293
				{
294
					if (strlen(#tag)
295
				}
296
				else
297
				{
298
					ignor_param = true;
299
					if (!ignor_text) && (strlen(#tagparam)+1
300
				}
301
				bword++;
302
			}
303
			strlwr(#tag);
304
			strlwr(#tagparam);
305
306
 
307
			if (tagparam) && (strlen(#tagparam) < 4000) GetNextParam();
308
309
 
4415 leency 310
			{
4411 leency 311
				perenos_num = strrchr(#line, ' ');
312
				if (!perenos_num) && (strlen(#line)>list.column_max) perenos_num=list.column_max;
4415 leency 313
				strcpy(#temp, #line + perenos_num); //перенос по словам
4411 leency 314
				line[perenos_num] = 0x00;
315
				if (stroka-1 > list.visible) && (list.first <>0) break 1; //уходим...
4415 leency 316
				DrawPage();
4411 leency 317
				strcpy(#line, #temp);
318
				TextGoDown(list.x + 5, stroka * 10 + list.y + 5, list.w - 20); //закрашиваем следущую строку
4414 leency 319
			}
4411 leency 320
			DrawPage();
321
			line=NULL;
322
323
 
4414 leency 324
4411 leency 325
 
326
			break;
327
		default:
328
			DEFAULT_MARK:
329
			if (bukva<=15) bukva=' ';
330
			if (!pre_text) && (bukva == ' ')
331
			{
332
				if (line[strlen(#line)-1]==' ') break; //убрать 2 пробела подряд
333
				if (!stolbec) && (!line) break; //строка не может начинаться с пробела
334
			}
335
			if (strlen(#line)
336
337
 
4415 leency 338
			{
4411 leency 339
			NEXT_MARK:
340
				perenos_num = strrchr(#line, ' ');
341
				if (!perenos_num) && (strlen(#line)>list.column_max) perenos_num=list.column_max;
4415 leency 342
				strcpy(#temp, #line + perenos_num); //перенос по словам
4411 leency 343
				line[perenos_num] = 0x00;
344
				if (stroka-1 > list.visible) && (list.first <>0) break 1; //уходим...
4415 leency 345
				DrawPage();
4411 leency 346
				strcpy(#line, #temp);
347
				TextGoDown(list.x + 5, stroka * 10 + list.y + 5, list.w - 20); //закрашиваем следущую строку
4414 leency 348
			}
4411 leency 349
		}
350
	}
351
352
 
353
	TextGoDown(list.x + 5, stroka * 10 + list.y + 5, list.w - 20); //закрашиваем следущую строку
4414 leency 354
4411 leency 355
 
4415 leency 356
		DrawBar(list.x, list.visible * 10 + list.y + 25, list.w, -list.visible * 10 + list.h - 25, bg_color);
357
	if (stroka * 10 + 5 <= list.h)
4414 leency 358
		DrawBar(list.x, stroka * 10 + list.y + 5, list.w, -stroka * 10 + list.h - 5, bg_color); //закрашиваем всё до конца
359
	if (list.first == 0) list.count = stroka;
4415 leency 360
	if (anchor) //если посреди текста появится новый якорь - будет бесконечный цикл
4411 leency 361
	{
362
		anchor=NULL;
363
		list.first=anchor_line_num;
4415 leency 364
		ParseHTML(buf);
4411 leency 365
	}
366
	DrawScroller();
367
}
368
369
 
370
 
371
 
372
void TWebBrowser::WhatTextStyle(int left1, top1, width1) {
373
	dword hr_color;
374
375
 
376
	if (tag[0] == '/')
377
	{
378
		 rez = 0;
379
		 strcpy(#tag, #tag+1);
380
	}
381
	else rez = 1;
382
383
 
384
	{
385
		IF(!strcmp(#URL + strlen(#URL) - 4, ".mht")) IF (rez==0) ignor_text = 1; ELSE ignor_text = 0;
386
		return;
387
	}
388
389
 
390
391
 
392
	{
393
		if (rez) header=NULL;
394
		else if (!stroka) DrawTitle(#header); //тег закрылся - вывели строку
395
		return;
396
	}
397
398
 
399
400
 
401
 
402
 
403
404
 
405
	{
406
		if (!strcmp(#anchor, #options))	anchor_line_num=list.first+stroka;
4415 leency 407
	}
4411 leency 408
409
 
410
	{
411
		do{
412
			if (!strcmp(#parametr, "link=")) link_color = GetColor(#options);
413
			if (!strcmp(#parametr, "text=")) text_colors[0]=GetColor(#options);
414
			if (!strcmp(#parametr, "bgcolor="))
415
			{
416
				bg_color=GetColor(#options);
417
				DrawBufFill();
418
			}
419
		} while(GetNextParam());
420
		return;
421
	}
422
423
 
424
	{
425
		if (rez)
426
		{
427
			if (link) IF(text_color_index > 0) text_color_index--; //если предыдущий тег а не был закрыт
428
429
 
430
				if (!strcmp(#parametr, "href="))
431
				{
432
					if (stroka - 1 > list.visible) || (stroka < -2) return;
4415 leency 433
4411 leency 434
 
435
					text_colors[text_color_index] = text_colors[text_color_index-1];
436
437
 
438
					blink++;
439
					text_colors[text_color_index] = link_color;
440
					strcat(#page_links, #options);
441
					strcat(#page_links, "|");
442
				}
443
				if (anchor) && (!strcmp(#parametr, "name="))
444
				{
445
					if (!strcmp(#anchor, #options))
446
					{
447
						anchor_line_num=list.first+stroka;
4415 leency 448
					}
4411 leency 449
				}
450
			} while(GetNextParam());
451
		}
452
		else {
453
			link = 0;
454
			IF(text_color_index > 0) text_color_index--;
455
		}
456
		return;
457
	}
458
459
 
460
	{
461
		if (rez)
462
		{
463
			text_color_index++;
464
			text_colors[text_color_index] = text_colors[text_color_index-1];
465
466
 
467
				if (strcmp(#parametr, "color=") == 0) //&& (parametr[1] == '#')
468
				{
469
					text_colors[text_color_index] = GetColor(#options);
470
				}
471
			} while(GetNextParam());
472
		}
473
		else
474
			if (text_color_index > 0) text_color_index--;
475
		return;
476
	}
477
	if(!chTag("tr")) || (!chTag("br")) {
478
		TextGoDown(left1, top1, width1);
479
		return;
480
	}
481
	if (!chTag("div")) {
482
		IF(oldtag[0] <>'h') TextGoDown(left1, top1, width1);
483
		return;
484
	}
485
	if (!chTag("p")) {
486
		IF(oldtag[0] == 'h') return;
487
		TextGoDown(left1, top1, width1);
488
		IF(rez) TextGoDown(left1, top1 + 10, width1);
489
		return;
490
	}
491
	if (!chTag("center"))
492
	{
493
		if (rez) text_align = ALIGN_CENTER;
494
		if (!rez)
495
		{
496
			TextGoDown(left1, top1, width1);
497
			text_align = ALIGN_LEFT;
498
		}
499
		return;
500
	}
501
	if (!chTag("right"))
502
	{
503
		if (rez) text_align = ALIGN_RIGHT;
504
		if (!rez)
505
		{
506
			TextGoDown(left1, top1, width1);
507
			text_align = ALIGN_LEFT;
508
		}
509
		return;
510
	}
511
	if (!chTag("h1")) || (!chTag("h2")) || (!chTag("h3")) || (!chTag("h4")) {
512
		TextGoDown(left1, top1, width1);
513
		if (rez) && (stroka>1) TextGoDown(left1, top1 + 10, width1);
514
		strcpy(#oldtag, #tag);
515
		if (rez)
516
		{
517
			if (!strcmp(#parametr, "align=")) && (!strcmp(#options,"center")) text_align = ALIGN_CENTER;
518
			if (!strcmp(#parametr, "align=")) && (!strcmp(#options,"right")) text_align = ALIGN_RIGHT;
519
			b_text = 1;
520
		}
521
		if (!rez)
522
		{
523
			text_align = ALIGN_LEFT;
524
			b_text = 0;
525
		}
526
		return;
527
	}
528
	else
529
		oldtag=NULL;
530
531
 
532
		b_text = rez;
533
		return;
534
	}
535
	if(!chTag("i")) || (!chTag("em")) || (!chTag("subtitle")) {
536
		i_text = rez;
537
		return;
538
	}
539
	if (!chTag("dt"))
540
	{
541
		li_text = rez;
542
		IF(rez == 0) return;
543
		TextGoDown(left1, top1, width1);
544
		return;
545
	}
546
	if(!chTag("li")) || (!chTag("dt")) //надо сделать вложенные списки
547
	{
548
		li_text = rez;
549
		if (rez)
550
		{
551
			TextGoDown(left1, top1, width1);
552
			if (stroka > -1) && (stroka - 2 < list.visible) DrawBufBar(li_tab * 5 * 6 + left1 - 5, list.line_h/2-3, 2, 2, 0x555555);
4415 leency 553
		}
4411 leency 554
		return;
555
	}
556
	if (!chTag("u")) || (!chTag("ins")) u_text = rez;
557
	if (!chTag("s")) || (!chTag("strike")) || (!chTag("del")) s_text = rez;
558
	if (!chTag("ul")) || (!chTag("ol")) IF(!rez)
559
	{
560
		li_text = rez;
561
		li_tab--;
562
		TextGoDown(left1, top1, width1);
563
	} ELSE li_tab++;
564
	if (!chTag("dd")) stolbec += 5;
565
	if (!chTag("blockquote")) blq_text = rez;
566
	if (!chTag("pre")) pre_text = rez;
567
	if (!chTag("hr"))
568
	{
569
		if (anchor) || (stroka < -1)
570
		{
571
			stroka+=2;
572
			return;
573
		}
574
		if (strcmp(#parametr, "color=") == 0) hr_color = GetColor(#options); else hr_color = 0x999999;
575
		TextGoDown(left1, top1, width1);
576
		DrawBufBar(5, WB1.list.line_h/2, WB1.list.w-10, 1, hr_color);
4414 leency 577
		TextGoDown(left1, top1+WB1.list.line_h, width1);
578
	}
4411 leency 579
	if (!chTag("img"))
580
	{
581
		Images( left1, top1, width1);
582
		return;
583
	}
584
	if (!chTag("meta")) || (!chTag("?xml"))
585
	{
586
		do{
587
			if (!strcmp(#parametr, "charset=")) || (!strcmp(#parametr, "content=")) || (!strcmp(#parametr, "encoding="))
588
			{
589
				strcpy(#options, #options[strrchr(#options, '=')]); //поиск в content=
590
				if (!strcmp(#options,"utf-8"))   || (!strcmp(#options,"utf8"))      ReadHtml(_UTF);
591
				if (!strcmp(#options, "koi8-r")) || (!strcmp(#options, "koi8-u"))   ReadHtml(_KOI);
592
				if (!strcmp(#options, "dos"))    || (!strcmp(#options, "cp-866"))   ReadHtml(_DOS);
593
			}
594
		} while(GetNextParam());
595
		return;
596
	}
597
}
598
599
 
600
 
601
 
602
{
603
	scroll_wv.max_area = list.count;
4416 leency 604
	scroll_wv.cur_area = list.visible;
605
	scroll_wv.position = list.first;
606
4411 leency 607
 
4416 leency 608
	scroll_wv.start_x = WB1.list.x + WB1.list.w;
609
	scroll_wv.size_y=WB1.list.h;
610
4411 leency 611
 
4416 leency 612
}
4411 leency 613
>
614