Subversion Repositories Kolibri OS

Rev

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