Subversion Repositories Kolibri OS

Rev

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