Subversion Repositories Kolibri OS

Rev

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