Subversion Repositories Kolibri OS

Rev

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