Subversion Repositories Kolibri OS

Rev

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

Rev Author Line No. Line
2413 leency 1
//идея - левые файлы открывать соответствующими прогами
2
//ol - циферки
3
 
4
//из хттп-лоад в реадхтмл
5
 
2433 leency 6
 
2413 leency 7
int	downloader_id;
8
 
9
dword j,
10
	buf,
11
	filesize,
12
	blink = 400;
13
 int i;
14
 
15
 char download_path[]="/rd/1/.download";
16
//char search_path[]="http://nova.rambler.ru/search?words=";
17
 char search_path[]="http://nigma.ru/index.php?s=";
2660 leency 18
 char version[]=" Text-based Browser 0.81";
2413 leency 19
 
20
 
21
struct TWebBrowser {
22
	int left,
23
	top,
24
	width,
25
	height;
26
	void DrawScroller();
27
	void ShowPage();
28
	void ParseHTML(dword, dword);
29
	void Scan(dword);
30
	void WhatTextStyle(int left1, top1, width1);
31
};
32
 
33
TWebBrowser WB1;
34
 
2420 leency 35
byte rez, b_text, i_text, u_text, s_text, pre_text, blq_text, li_text, link, ignor_text, li_tab, body_present;
2413 leency 36
 
37
 
38
dword text_colors[10],
2605 leency 39
	text_color_index,
2420 leency 40
	link_color,
2660 leency 41
	bg_color;
2413 leency 42
 
43
int stroka,
44
	stolbec,
45
	tab_len;
46
 
47
char line[330],
48
	tag[100],
49
	tagparam[10000],
50
	parametr[1200],
51
	options[1000];
52
 
53
 
54
#include "include\history.h"
55
#include "include\colors.h"
56
#include "include\unicode_tags.h"
57
#include "include\some_code.h"
58
 
59
 
60
void TWebBrowser::Scan(dword id) {
61
	if (id > 399)
62
	{
2428 leency 63
		GetURLfromPageLinks(id);
64
 
65
		//эту всю хрень нужно в GetNewUrl() переместить
2413 leency 66
		IF (URL[0] == '#') {  //мы не умеем переходить по ссылке внутри документа. Пока что...
2433 leency 67
			copystr(BrowserHistory.CurrentUrl(), #editURL);
68
			copystr(#URL, #editURL + strlen(#editURL));
69
 
70
			//edit1.size = edit1.pos = strlen(#editURL);
71
			//edit_box_draw stdcall(#edit1); //рисуем строку адреса
72
 
73
			copystr(BrowserHistory.CurrentUrl(), #URL);
74
			ShowPage(#URL);
2413 leency 75
			return;
76
		}
77
 
2433 leency 78
		URL[find_symbol(#URL, '#')-1] = 0x00; //заглушка, лучше, чем ничего (хабр, например, будет работать)  //это не совсем правильно - в едитурл должно оставаться
2428 leency 79
 
2413 leency 80
		GetNewUrl();
81
 
2444 leency 82
		//полоса, белая рисуется снизу
2428 leency 83
		if (!strcmp(#URL + strlen(#URL) - 4, ".gif")) || (!strcmp(#URL + strlen(#URL) - 4, ".png")) || (!strcmp(#URL + strlen(#URL) - 4, ".jpg"))
84
		{
85
			RunProgram("/sys/media/kiv", #URL);
2433 leency 86
			copystr(BrowserHistory.CurrentUrl(), #URL);
2428 leency 87
			return;
88
		}
89
 
2416 leency 90
		copystr(#URL, #editURL);
2418 leency 91
		za_kadrom = count = 0;
2428 leency 92
 
93
		if (!strcmp(get_URL_part(5),"http:")) HttpLoad();
94
 
2418 leency 95
		ShowPage(#URL);
2413 leency 96
		return;
97
	}
98
 
99
	//edit1.flags=64;
100
	IF(count < max_kolvo_strok) SWITCH(id) //если мало строк игнорируем некоторые кнопки
101
	{ CASE 183: CASE 184: CASE 180: CASE 181: return; }
102
 
103
	switch (id)
104
	{
105
		case 011: //Ctrk+K
106
			ReadHtml();
107
			koitodos(buf);
108
			break;
2660 leency 109
		case 021: //Ctrl+U
110
			ReadHtml();
111
			utf8rutodos(buf);
112
			break;
2413 leency 113
		case BACK:
114
			BrowserHistory.GoBack();
2605 leency 115
 
116
			copystr(#URL, #editURL);
117
			za_kadrom = count = 0;
118
			if (!strcmp(get_URL_part(5),"http:"))) HttpLoad();
119
			ShowPage(#URL);
2413 leency 120
			return;
121
		case FORWARD:
2605 leency 122
			BrowserHistory.GoForward();
123
 
124
			copystr(#URL, #editURL);
125
			za_kadrom = count = 0;
126
			if (!strcmp(get_URL_part(5),"http:"))) HttpLoad();
127
			ShowPage(#URL);
2413 leency 128
			return;
129
		case 054: //F5
130
			IF(edit1.flags == 66) break;
131
		case REFRESH:
132
			if (GetProcessSlot(downloader_id)<>0)
133
			{
134
				KillProcess(downloader_id);
135
				Pause(20);
136
				Draw_Window();
137
				return;
138
			}
139
			copystr(#URL, #editURL);
140
			if (!strcmp(get_URL_part(5),"http:"))) HttpLoad();
141
			ShowPage(#URL);
142
			return;
143
		case 014: //Ctrl+N новое окно
144
		case 020: //Ctrl+T новая вкладка
145
		case NEWTAB:
146
			MoveSize(190,80,OLD,OLD);
147
			RunProgram(#program_path, #URL);
148
			return;
149
		case 052:  //Нажата F3
150
			IF(edit1.flags <> 66)
151
			IF (strcmp(get_URL_part(5),"http:")<>0) RunProgram("tinypad", #URL); ELSE RunProgram("tinypad", #download_path);
152
			return;
153
 
154
		case HOME:
155
			copystr("http://bash.org.ru", #editURL);
156
		case GOTOURL:
157
		case 0x0D: //enter
158
			copystr(#editURL, #URL);
159
			if (!strcmp(get_URL_part(5),"http:"))) HttpLoad();
2418 leency 160
			za_kadrom = count = 0;
2413 leency 161
			ShowPage(#URL);
162
			return;
163
		case 173:	//ctrl+enter
164
		case SEARCHWEB:
165
			copystr(#search_path, #URL);
166
			copystr(#editURL, #URL + strlen(#URL));
167
			if (!strcmp(get_URL_part(5),"http:"))) HttpLoad();
2418 leency 168
			za_kadrom = count = 0;
2413 leency 169
			ShowPage(#URL);
170
			return;
171
 
172
		case ID1: //мотаем вверх
173
			IF(za_kadrom <= 0) return;
174
			za_kadrom--;
175
			break;
176
		case ID2: //мотаем вниз
177
			IF(max_kolvo_strok + za_kadrom >= count) return;
178
			za_kadrom++;
179
			break;
180
		case 183: //PgDown
181
			IF(za_kadrom == count - max_kolvo_strok) return;
182
			za_kadrom += max_kolvo_strok + 2;
183
			IF(max_kolvo_strok + za_kadrom > count) za_kadrom = count - max_kolvo_strok;
184
			BREAK;
185
		case 184: //PgUp
186
			IF(za_kadrom == 0) RETURN;
187
			za_kadrom -= max_kolvo_strok - 2;
188
			IF(za_kadrom < 0) za_kadrom = 0;
189
			BREAK;
190
		case 180: //home
191
			IF(za_kadrom == 0) RETURN;
192
			za_kadrom = 0;
193
			BREAK;
194
		case 181: //end
195
			IF (za_kadrom == count - max_kolvo_strok) RETURN;
196
			za_kadrom = count - max_kolvo_strok;
197
			BREAK;
198
		default:
199
			RETURN;
200
	}
201
	ParseHTML(buf, filesize);
202
}
203
 
204
void GetNewUrl(){
2433 leency 205
	IF (!strcmp(get_URL_part(2),"./")) copystr(#URL+2,#URL); //игнорим :)
2428 leency 206
 
207
	if (URL[0] <> '/')
2413 leency 208
	&& (strcmp(get_URL_part(5),"http:")<>0)	&& (strcmp(get_URL_part(5),"mailt")<>0)	&& (strcmp(get_URL_part(5),"ftp:/")<>0)
209
	{
210
		copystr(BrowserHistory.CurrentUrl(), #editURL); //достаём адрес текущей страницы
211
 
2428 leency 212
		_CUT_ST_LEVEL_MARK:
213
 
2444 leency 214
		if (editURL[find_symbol(#editURL, '/')-2]<>'/')  // если не http://pagename.ua <-- нахрена эта строка???
2413 leency 215
		{
216
			editURL[find_symbol(#editURL, '/')] = 0x00; //обрезаем её урл до последнего /
217
		}
2428 leency 218
 
219
		IF (!strcmp(get_URL_part(3),"../")) //на уровень вверх
220
		{
221
			copystr(#URL+3,#URL);
222
			editURL[find_symbol(#editURL, '/')-1] = 0x00; //обрезаем её урл до последнего /
223
			goto _CUT_ST_LEVEL_MARK;
224
		}
225
 
2444 leency 226
		if (editURL[strlen(#editURL)-1]<>'/') copystr("/", #editURL + strlen(#editURL));
2413 leency 227
		copystr(#URL, #editURL + strlen(#editURL)); //клеим новый адрес
228
		copystr(#editURL, #URL);
229
	}
230
}
231
 
232
 
233
void HttpLoad()
2418 leency 234
{
235
	//count = 0; я думаю ему место здесь
2420 leency 236
	copystr(#version, #header);
2413 leency 237
	KillProcess(downloader_id); //убиваем старый процесс
238
	DeleteFile(#download_path);
239
	IF (URL[strlen(#URL)-1]=='/') URL[strlen(#URL)-1]='';
240
	downloader_id = RunProgram("/sys/network/downloader", #URL);
241
	IF (downloader_id<0) RunProgram("@notify", "Error running Downloader. Internet unavilable.");
242
	Draw_Window();
243
}
244
 
245
 
246
void ReadHtml()
247
{
248
	if (!strcmp(get_URL_part(5),"http:")))
249
		file_size stdcall (#download_path);
250
	else
251
		file_size stdcall (#URL);
252
 
253
	filesize = EBX;
254
	if (!filesize) /*{Pause(200); ReadHtml();}*/ return;
255
	mem_Free(buf);
256
	buf = mem_Alloc(filesize);
257
	if (!strcmp(get_URL_part(5),"http:")))
258
		ReadFile(0, filesize, buf, #download_path);
259
	else
260
		ReadFile(0, filesize, buf, #URL);
261
}
262
 
263
 
264
 
265
void TWebBrowser::ShowPage(dword adress) {
266
	max_kolvo_stolbcov = width - 30 / 6;
267
	max_kolvo_strok = height - 3 / 10 - 2;
268
	edit1.size = edit1.pos = strlen(#editURL);
269
	edit_box_draw stdcall(#edit1); //рисуем строку адреса
270
 
2419 leency 271
	BrowserHistory.AddUrl();
272
 
2413 leency 273
	//LETS_LOAD
274
	ReadHtml();
275
 
276
	if (!filesize)
277
	{
278
		DrawBar(left, top, width+2, height, 0xFFFFFF); //закрашиваем всё донизу
279
		if (GetProcessSlot(downloader_id)<>0) WriteText(left + 10, top + 18, 0x80, 0, "Loading...", 0);
280
		else
281
		{
282
			WriteText(left + 10, top + 18, 0x80, 0, "Page not found. May be, URL contains some errors.", 0);
283
			if (!strcmp(get_URL_part(5),"http:"))) WriteText(left + 10, top + 32, 0x80, 0, "Or Internet unavilable for your configuration.", 0);
284
		}
285
		DrawTitle(#version); //?
286
		return;
287
	}
288
 
289
	wintodos(buf);
290
	ParseHTML(buf, filesize);
291
	IF (!strcmp(#version, #header)) DrawTitle(#header);
292
}
293
 
294
 
295
 
296
void TWebBrowser::ParseHTML(dword bword, fsize){
297
	word bukva[1];
298
	byte ignor_param = 0;
299
	char temp[768];
300
	stroka = -za_kadrom;
301
	stolbec = 0;
302
	FOR(j = 400; j < blink + 1; j++;) DeleteButton(j);
2420 leency 303
	b_text = i_text = u_text = s_text = pre_text = blq_text = body_present =
2413 leency 304
	li_text = link = ignor_text = text_color_index = text_colors[0] = li_tab = 0; //обнуляем теги
305
	link_color = 0x0000FF;
2420 leency 306
	bg_color = 0xFFFFFF;
2413 leency 307
	blink = 400;
308
	line = '';
309
	copystr("|", #page_links);
2418 leency 310
	copystr(#version, #header);
2420 leency 311
	IF(!strcmp(#URL + strlen(#URL) - 4, ".txt"))
312
	{
313
		DrawBar(left, top, width-15, 15, bg_color); //закрашиваем первую строку
314
		pre_text = 1; //зачётное отображение текста
315
	}
2413 leency 316
	IF(!strcmp(#URL + strlen(#URL) - 4, ".mht")) ignor_text = 1;
2660 leency 317
	for (bword = buf; buf + fsize > bword; bword++;) {
2413 leency 318
	  bukva = ESBYTE[bword];
319
	  switch (bukva) {
320
		case 0x0a:
321
			IF(pre_text == 1) {
322
				bukva = '';
323
				temp = '';
324
				goto NEXT_MARK;
325
			}
2605 leency 326
		case '\9':
2413 leency 327
			if (pre_text == 1) //иначе идём на 0x0d
328
			{
329
				tab_len=strlen(#line)/8;
330
				tab_len=tab_len*8;
331
				tab_len=8+tab_len-strlen(#line);
332
				for (i=0; i
333
				break;
334
			}
335
		case 0x0d:
336
			bukva = ' ';
337
			goto DEFAULT_MARK;
338
		case '<':
339
			bword++; //промотаем символ <
340
			IF(ESBYTE[bword] == '!') //фильтрация внутри , дерзко
341
			{
342
				bword++;
343
				IF(ESBYTE[bword] == '-') {
344
					HH_: do {
345
						bword++;
346
						IF(bword >= buf + fsize) break 1;
347
					} while (ESBYTE[bword] <>'-');
348
					bword++;
349
					IF(ESBYTE[bword] <>'-') GOTO HH_;
350
				}
351
			}
352
			WHILE (ESBYTE[bword] <>'>') && (bword < buf + fsize) //получаем тег и его параметры
353
			{
354
				bukva = ESBYTE[bword];
355
				IF(bukva == '\9') || (bukva == '\x0a') || (bukva == '\x0d') bukva = ' ';
356
				IF(!ignor_param) && (bukva <>' ') copystr(#bukva, #tag + strlen(#tag));
357
				ELSE {
358
					ignor_param = true;
359
					copystr(#bukva, #tagparam + strlen(#tagparam));
360
				}
361
				bword++;
362
			}
363
			lowcase(#tag);
364
			lowcase(#tagparam);
2418 leency 365
 
2413 leency 366
			IF (tag[strlen(#tag)-1]=='/') tag[strlen(#tag)-1]=''; //небольшой фикс для работы с XHTML-тегами типа br/
367
			IF(strlen(#tagparam) > 0) && (strlen(#tagparam) < 4000) GetNextParam();
368
			WhatTextStyle(left + 5, stroka * 10 + top + 5, width - 20); //обработка тегов
369
 
370
			line = tag = parametr = tagparam = ignor_param = 0; //всё обнуляем
371
			break;
372
		case '=': //поддержка шайтанской кодировки страниц, сохранённых через ИЕ7
373
			IF(strcmp(#URL + strlen(#URL) - 4, ".mht")<>0) goto DEFAULT_MARK;
374
 
375
			bword++;
376
			bukva=ESBYTE[bword];
377
			copystr(#bukva, #temp);
378
 
379
			bword++;
380
			bukva=ESBYTE[bword];
381
			copystr(#bukva, #temp + strlen(#temp));
382
 
383
			bukva=Hex2Symb(#temp);
384
			IF (bukva) goto DEFAULT_MARK;
385
			break;
386
 
387
		case '&': //обработка тегов типа  
388
			IF(ignor_text) break;
389
			bword++;
390
			tag='';
391
			FOR (j=0;   (ESBYTE[bword] <>';') && (j < 7);     j++; bword++;)
392
			{
393
				bukva = ESBYTE[bword];
394
				copystr(#bukva, #tag + strlen(#tag));
395
			}
396
 
397
			FOR (j=0; unicode_tags[j]!=0; j+=2;)
398
			{
399
				IF(!strcmp(#tag, unicode_tags[j]))
400
				{
401
					copystr(unicode_tags[j+1], #line + strlen(#line));
402
					break 1;
403
				}
404
			}
405
 
406
			rez = StrToInt(#tag + 1) - 1040;
407
			IF(tag[1] == '1') && (rez>=0) && (rez<=72) && (strlen(#tag) == 5)
408
				{
409
					bukva = unicode_chars[rez];
410
					GOTO DEFAULT_MARK; //обрабатываем букву
411
				}
412
 
413
			WriteDebug(#tag); //тэг не найден - выводим на доску отладки
414
			copystr(#tag, #line + strlen(#line)); //выводим на экран необработанный тег, так браузеры зачем-то делают
415
			break;
416
		default:
417
			DEFAULT_MARK:
418
			IF(ignor_text) break;
419
			IF(pre_text == 0) && (bukva == ' ') && (strcmp(#line + strlen(#line) - 1, " ") == 0) continue;
420
			//
421
			if (stolbec + strlen(#line) > max_kolvo_stolbcov)
422
			{
423
				copystr(#line + find_symbol(#line, ' '), #temp); //перенос по словам
424
				line[find_symbol(#line, ' ')] = 0x00;
425
				NEXT_MARK: IF(stroka - 1 > max_kolvo_strok) && (za_kadrom <>0) break 1; //уходим...
426
				WhatTextStyle(left + 5, stroka * 10 + top + 5, width - 20); //вывод строки
427
				TextGoDown(left + 5, stroka * 10 + top + 5, width - 20); //закрашиваем следущую строку
428
				copystr(#temp, #line);
429
			}
430
			IF(pre_text == 0) && (bukva == ' ') && (stolbec == 0) && (strlen(#line) == 0) CONTINUE;
431
			copystr(#bukva, #line + strlen(#line));
432
	  }
433
	}
2420 leency 434
	if (strcmp(#URL + strlen(#URL) - 4, ".txt")<>0) && (body_present==0)
435
		DrawBar(left, top, width-15, 15, bg_color); //закрашиваем первую строку если какой-то рахит не создал тег боди
436
 
437
	if (max_kolvo_strok * 10 + 25 <= height)
438
		DrawBar(left, max_kolvo_strok * 10 + top + 25, width - 15, -max_kolvo_strok * 10 + height - 25, bg_color);
439
	if (stroka * 10 + 15 <= height)
440
		DrawBar(left, stroka * 10 + top + 15, width - 15, -stroka * 10 + height - 15, bg_color); //закрашиваем всё до конца
441
	if (za_kadrom == 0) count = stroka;
2413 leency 442
	DrawScroller(); //рисуем скролл
443
}
444
 
445
 
446
void GetNextParam()
447
{
448
	byte	kavichki = false;
449
	int		i = strlen(#tagparam) - 1;
450
 
451
	WHILE((i > 0) && ((tagparam[i] == '"') || (tagparam[i] == ' ') || (tagparam[i] == '\'') || (tagparam[i] == '/')))
452
	{
453
		IF (tagparam[i] == '"') || (tagparam[i] == '\'') kavichki=tagparam[i];
454
		tagparam[i] = 0x00;
455
		i--;
456
	}
457
 
458
	IF (kavichki)
459
	{
460
		i=find_symbol(#tagparam, kavichki);
461
		copystr(#tagparam + i, #options);
462
	}
463
	ELSE
464
	{
465
		WHILE((i > 0) && (tagparam[i] <>'=')) i--; //i=find_symbol(#tagparam, '=')+1;
466
		i++;
467
 
468
		copystr(#tagparam + i, #options); //копируем опцию
469
		WHILE (options[0] == ' ') copystr(#options + 1, #options);
470
	}
471
	tagparam[i] = 0x00;
472
 
473
	FOR ( ; ((tagparam[i] <>' ') && (i > 0); i--)
474
	{
475
		IF (tagparam[i] == '=') //дерзкая заглушка
476
		{
477
			//copystr(#tagparam+i+2,#options);
478
			tagparam[i + 1] = 0x00;
479
		}
480
	}
481
 
482
	copystr(#tagparam + i + 1, #parametr); //копируем параметр
483
	tagparam[i] = 0x00;
484
}
485
 
486
 
487
 
488
char oldtag[100];
489
void TWebBrowser::WhatTextStyle(int left1, top1, width1) {
490
	dword hr_color;
491
 
492
    dword image=0;
493
    char temp[4096];
494
    int w, h, img_za_kadrom=0;
495
 
496
	//проверяем тег открывается или закрывается
497
	IF(tag[0] == '/')
498
	{
499
		rez = 0;
500
		copystr(#tag + 1, #tag);
501
	}
502
	ELSE
503
		rez = 1;
504
 
505
	//
506
	IF(!chTag("html")) {
507
		IF(!strcmp(#URL + strlen(#URL) - 4, ".mht")) IF (rez==0) ignor_text = 1; ELSE ignor_text = 0;
508
		return;
509
	}
2660 leency 510
	IF(!chTag("script")) || (!chTag("style")) || (!chTag("binary")) ignor_text = rez;
2413 leency 511
 
2418 leency 512
	if(!chTag("title")) && (!rez)
2413 leency 513
	{
514
		copystr(#line, #header);
515
		copystr(" -", #header + strlen(#header));
516
		copystr(#version, #header + strlen(#header));
2418 leency 517
		if (stroka==0) DrawTitle(#header);
2413 leency 518
		return;
519
	}
520
 
2418 leency 521
	IF (ignor_text == 1) return;
2413 leency 522
	//
2418 leency 523
 
524
	//
2413 leency 525
	IF(!chTag("q")) copystr("\"", #line + strlen(#line));
526
 
527
	//вывод на экран
528
	if (stroka >= 0) && (stroka - 2 < max_kolvo_strok) && (line)
529
	{
2444 leency 530
		WriteText(stolbec * 6 + left1, top1, 0x80, text_colors[text_color_index], #line, 0); //может тут рисовать белую строку?
2413 leency 531
		IF (b_text) WriteText(stolbec * 6 + left1 + 1, top1, 0x80, text_colors[text_color_index], #line, 0);
532
		IF (i_text) Skew(stolbec * 6 + left1, top1, strlen(#line)+1*6, 10); //наклонный текст
533
		IF (s_text) DrawBar(stolbec * 6 + left1, top1 + 4, strlen(#line) * 6, 1, text_colors[text_color_index]); //зачёркнутый
534
		IF (u_text) DrawBar(stolbec * 6 + left1, top1 + 8, strlen(#line) * 6, 1, text_colors[text_color_index]); //подчёркнутый
535
		IF (link) {
536
			DefineButton(stolbec * 6 + left1 - 2, top1, strlen(#line) * 6 + 3, 9, blink + BT_HIDE, 0xB5BFC9); //
537
			DrawBar(stolbec * 6 + left1, top1 + 8, strlen(#line) * 6, 1, text_colors[text_color_index]);
538
		}
539
	}
540
	//
541
	IF(!tag) return;
542
	stolbec += strlen(#line);
2420 leency 543
 
2413 leency 544
	if (!chTag("body"))
545
	{
546
		BODY_MARK:
547
 
548
		if (strcmp(#parametr, "link=") == 0)
549
			link_color = GetColor(#options);
550
 
2420 leency 551
		if (strcmp(#parametr, "text=") == 0)
2413 leency 552
		{
553
			text_colors[0]=GetColor(#options);
554
		}
555
 
556
		if (strcmp(#parametr, "bgcolor=") == 0)
557
		{
2420 leency 558
			bg_color=GetColor(#options);
559
		}
2413 leency 560
 
561
		IF(tagparam) {
562
			GetNextParam();
563
			GOTO BODY_MARK;
2420 leency 564
		}
565
 
566
		body_present = 1; //если калич не создал тег боди нужно извращаться
567
 
568
		if (rez) DrawBar(WB1.left, WB1.top, WB1.width-15, 15, bg_color); //закрашиваем первую строку
569
		return;
2413 leency 570
	}
571
	//////////////////////////
572
	if (!chTag("a")) {
573
		IF (stroka - 1 > max_kolvo_strok) || (stroka < -2) return;
574
		if (rez) {
575
			HREF: IF(strcmp(#parametr, "href=") == 0) {
576
				IF(link == 1) text_color_index--; //если какой-то долбоёб не закрыл тэг
577
				link = 1;
578
				blink++;
579
				text_color_index++;
580
				text_colors[text_color_index] = link_color;
581
				copystr(#options, #page_links + strlen(#page_links));
582
				copystr("|", #page_links + strlen(#page_links));
583
			}
584
			IF(tagparam) {
585
				GetNextParam();
586
				GOTO HREF;
587
			}
588
		}
589
		ELSE {
590
			link = 0;
591
			IF(text_color_index > 0) text_color_index--;
592
		}
593
		return;
594
	}
595
	/////////////////////////
596
	if (!chTag("font"))
597
	{
598
		IF(stroka < 0) || (stroka - 1 > max_kolvo_strok) return;
599
		COL_MARK:
600
		if (strcmp(#parametr, "color=") == 0) //&& (parametr[1] == '#')
601
		{
602
			text_color_index++;
603
			text_colors[text_color_index] = GetColor(#options);
604
		}
605
		IF(tagparam) {
606
			GetNextParam();
607
			GOTO COL_MARK;
608
		}
609
		IF(!rez) && (text_color_index > 0) text_color_index--;
610
		return;
611
	}
612
	//////////////////////////
613
	IF(!chTag("tr")) || (!chTag("br")) {
614
		TextGoDown(left1, top1, width1);
615
		return;
616
	}
617
	IF(!chTag("div")) {
618
		IF(oldtag[0] <>'h') TextGoDown(left1, top1, width1);
619
		return;
620
	}
621
	IF(!chTag("p")) {
622
		IF(oldtag[0] == 'h') return;
623
		TextGoDown(left1, top1, width1);
624
		IF(rez) TextGoDown(left1, top1 + 10, width1);
625
		return;
626
	}
627
	////////////////////////////
628
	IF(!chTag("h1")) || (!chTag("h2")) || (!chTag("h3")) || (!chTag("h4")) {
629
		TextGoDown(left1, top1, width1);
630
		IF(rez) TextGoDown(left1, top1 + 10, width1);
631
		b_text = rez;
632
		copystr(#tag, #oldtag);
633
		return;
634
	} ELSE copystr("", #oldtag);
635
	IF(!chTag("b")) || (!chTag("strong")) || (!chTag("big")) {
636
		b_text = rez;
637
		return;
638
	}
639
	////////////////////////////
2660 leency 640
	IF(!chTag("i")) || (!chTag("em")) || (!chTag("subtitle")) {
2413 leency 641
		i_text = rez;
642
		return;
643
	}
644
	////////////////////////////
645
	if(!chTag("li")) || (!chTag("dt")) //надо сделать вложенные списки
646
	{
647
		li_text = rez;
648
		IF(rez == 0) return;
649
		TextGoDown(left1, top1, width1);
650
		IF(stroka > -1) && (stroka - 2 < max_kolvo_strok) IF(!chTag("li")) DrawBar(li_tab * 5 * 6 + left1 - 5, top1 + 12, 2, 2, 0);
651
		return;
652
	}
653
	////////////////////////////
654
	IF(!chTag("u")) || (!chTag("ins")) u_text = rez;
655
	IF(!chTag("s")) || (!chTag("strike")) || (!chTag("del")) s_text = rez;
656
	IF(!chTag("ul")) || (!chTag("ol")) IF(!rez) {
657
		li_text = rez;
658
		li_tab--;
659
		TextGoDown(left1, top1, width1);
660
	} ELSE li_tab++;
661
	IF(!chTag("dd")) stolbec += 5;
662
	IF(!chTag("blockquote")) blq_text = rez;
663
	IF(!chTag("pre")) pre_text = rez;
664
	IF(!chTag("hr")) {
665
		TextGoDown(left1, top1, width1);
666
		TextGoDown(left1, top1 + 10, width1);
667
		IF(strcmp(#parametr, "color=") == 0) hr_color = GetColor(#options);
668
		ELSE hr_color = 0x999999;
669
		IF(stroka > 0) DrawBar(left1, top1 + 14, width1 - 8, 1, hr_color);
670
	}
671
 
672
	if (!chTag("img"))
673
	{
674
		//IF (GetFileInfo(#libimg)<>0) return;  //если библиотеки нет
675
		IMG_TAG:
676
			IF (strcmp(#parametr,"src=")==0)   //надо объединить с GetNewUrl()
677
	          {
678
				copystr(BrowserHistory.CurrentUrl(), #temp); //достаём адрес текущей страницы
679
				temp[find_symbol(#temp, '/')] = 0x00; //обрезаем её урл до последнего /
680
				copystr(#options,#temp+strlen(#temp));
681
				image=load_image(#temp);
682
 
683
	                w=DSWORD[image+4];
684
	                h=DSWORD[image+8];
685
	          }
686
		IF(tagparam) {
687
			GetNextParam();
688
			GOTO IMG_TAG;
689
		}
690
 
691
		if (w>width1) w=width1;
692
 
693
        if (image)
694
        {
695
			stroka+=h/10;
696
 
697
			if (top1+hWB1.top+WB1.height-10) //если ВСЁ изображение ушло ВЕРХ или ВНИЗ
698
				return;
699
 
700
			if (top1
701
			{
702
				img_za_kadrom=WB1.top-top1;
703
				h=h-img_za_kadrom;
2433 leency 704
				top1=WB1.top;
2413 leency 705
			}
706
 
2566 leency 707
			if (top1>WB1.top+WB1.height-h-15) //если часть изображения снизу     IF (stroka - 2 < max_kolvo_strok)
2413 leency 708
			{
2566 leency 709
				h=WB1.top+WB1.height-top1-15;
2413 leency 710
			}
711
 
712
			IF (h<=0) return;
713
 
714
			img_draw stdcall (image,left1-5,top1+10,w, h,0,img_za_kadrom);
2420 leency 715
			DrawBar(left1+w - 5, top1 + 10, width1-w + 5, h, bg_color);
2433 leency 716
			IF (link)
717
			{
718
				DefineButton(left1 - 5, top1+10, w, h, blink + BT_HIDE, 0xB5BFC9);
719
			}
720
 
2413 leency 721
        }
722
		/*else
723
		{
724
			IF (strcmp(#parametr,"alt=")==0) copystr(#options,#line+strlen(#line));
725
		}*/
726
		return;
727
	}
728
 
2605 leency 729
	if (!chTag("meta")) || (!chTag("?xml"))
2413 leency 730
	{
731
		META:
2605 leency 732
		if (!strcmp(#parametr, "charset=")) || (!strcmp(#parametr, "content=")) || (!strcmp(#parametr, "encoding="))
2413 leency 733
		{
734
			copystr(#options[find_symbol(#options, '=')],#options); //поиск в content=
735
 
736
			IF (!strcmp(#options,"utf-8")) || (!strcmp(#options,"utf8"))
737
			{
738
				ReadHtml();
739
				utf8rutodos(buf);
740
			}
741
			IF(!strcmp(#options, "koi8-r")) || (!strcmp(#options, "koi8-u"))
742
			{
743
				ReadHtml();
744
				koitodos(buf);
745
			}
746
			IF(!strcmp(#options, "dos")) || (!strcmp(#options, "cp-866"))
747
			{
748
				ReadHtml();
749
			}
750
		}
751
		IF(tagparam)
752
		{
753
			GetNextParam();
754
			goto META;
755
		}
756
		return;
757
	}
758
}
759
 
760
 
761
void TextGoDown(int left1, top1, width1) {
762
	stroka++;
763
	IF(blq_text == 1) stolbec = 8;
764
	ELSE stolbec = 0;
765
	IF(li_text == 1) stolbec = li_tab * 5;
2420 leency 766
	IF(stroka >= 0) && (stroka - 2 < max_kolvo_strok) DrawBar(left1 - 5, top1 + 10, width1 + 5, 10, bg_color);
2413 leency 767
}
768
 
769
 
770
//скролл
771
void TWebBrowser::DrawScroller() {
772
	dword on_y;
773
	DrawBar(left + width - 15, top + 17, 1, height - 34, 0x94AECE); //линия слева от прокрутки
774
	DrawFlatButton(left + width - 15, top + height - 17, 16, 16, ID2, 0xE4DFE1, "\x19");
775
	DrawFlatButton(left + width - 15, top, 16, 16, ID1, 0xE4DFE1, "\x18");
776
 
777
	IF(count <= max_kolvo_strok) {
2418 leency 778
		DrawBar(left + width - 14, top+17, 16, height - 34, 0xCED0D0);
2413 leency 779
		return;
780
	}
781
 
782
	scroll_size = height - 16 * max_kolvo_strok / count - 3;
783
	IF(scroll_size < 10) scroll_size = 10;
784
	IF(za_kadrom + max_kolvo_strok >= count) on_y = height - scroll_size + top - 17;
785
	ELSE on_y = height - 32 * za_kadrom / count + top + 16;
786
	DrawFlatButton(left + width - 15, on_y, 16, scroll_size, 0, 0xE4DFE1, ""); //ползунок
787
	IF(on_y > top + 17) DrawBar(left + width - 14, top + 17, 16, on_y - top - 17, 0xCED0D0); //поле до ползунка
788
	IF(height - scroll_size + top - 17 > on_y)
789
		DrawBar(left + width - 14, on_y + scroll_size + 1, 16, height - scroll_size - on_y + top - 18, 0xCED0D0); //поле после ползунка
790
}