Subversion Repositories Kolibri OS

Rev

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

Rev Author Line No. Line
4411 leency 1
 
2
3
 
4
	buf,
5
	filesize,
6
	blink;
7
8
 
9
char search_path[]="http://nigma.ru/index.php?s=";
10
11
 
12
 
13
	llist list; //need #include "..\lib\list_box.h"
4415 leency 14
	void GetNewUrl();
4411 leency 15
	void OpenPage();
16
	void ReadHtml(byte);
17
	void ShowPage();
18
	void ParseHTML(dword);
19
	void WhatTextStyle(int left1, top1, width1);
20
	void DrawPage();
21
	void DrawScroller();
22
};
23
TWebBrowser WB1;
24
25
 
26
	link, ignor_text, li_tab, cur_encoding, text_align;
27
28
 
29
30
 
31
	text_color_index,
32
	link_color,
33
	bg_color;
34
35
 
36
	stolbec,
37
	tab_len,
38
	anchor_line_num;
39
40
 
41
	tag[100],
42
	tagparam[10000],
43
	parametr[1200],
44
	options[4096],
45
	anchor[256];
46
47
 
48
#include "..\TWB\unicode_tags.h"
49
#include "..\TWB\img_cache.h"
50
#include "..\TWB\some_code.h"
51
#include "..\TWB\parce_tag.h"
52
#include "..\TWB\draw_buf.h"
53
54
 
55
56
 
57
 
58
{
59
	int start_x, start_y, line_length, magrin_left=5;
60
61
 
62
	{
63
		strcpy(#header, #line);
64
		strcat(#header, " -");
65
		strcat(#header, #version);
66
		line = 0;
67
		return;
68
	}
69
70
 
4415 leency 71
	{
4411 leency 72
		start_x = stolbec * 6 + list.x + magrin_left;
4414 leency 73
		start_y = stroka * 10 + list.y + magrin_left;
74
		line_length = strlen(#line) * 6;
4411 leency 75
76
 
77
		IF (b_text)	WriteBufText(start_x+1, 0, 0x88, text_colors[text_color_index], #line, drawbuf);
78
		IF (i_text) DrawBufSkew(start_x, 0, line_length, list.line_h);
4414 leency 79
		IF (s_text) DrawBufBar(start_x, 4, line_length, 1, text_colors[text_color_index]);
4411 leency 80
		IF (u_text) DrawBufBar(start_x, 8, line_length, 1, text_colors[text_color_index]);
81
		IF (link) {
82
			UnsafeDefineButton(start_x-2, start_y, line_length + 3, 9, blink + BT_HIDE, 0xB5BFC9);
83
			DrawBufBar(start_x, 8, line_length, 1, text_colors[text_color_index]);
84
		}
85
		stolbec += strlen(#line);
86
	}
87
}
88
//=======================================================================
89
90
 
91
 
92
 
93
//dword TWebBrowser::GetNewUrl(dword CUR_URL, NEW_URL){
94
void TWebBrowser::GetNewUrl(){
95
	int i, len;
96
97
 
98
	{
99
		len=strlen(ABSOLUTE_LINKS[i]);
100
		if (!strcmpn(#URL, ABSOLUTE_LINKS[i], len)) return;
101
	}
102
103
 
104
	strcpy(#editURL, BrowserHistory.CurrentUrl()); //достаём адрес текущей страницы
105
106
 
107
	{
108
		i = strchr(#editURL+8, '/');
109
		editURL[i+7]=0;
110
		strcpy(#URL, #URL+1);
111
	}
112
113
 
114
115
 
116
		{
117
			editURL[strrchr(#editURL, '/')] = 0x00; //обрезаем её урл до последнего /
118
		}
119
120
 
121
		{
122
			strcpy(#URL,#URL+3);
123
			editURL[strrchr(#editURL, '/')-1] = 0x00; //обрезаем её урл до последнего /
124
			goto _CUT_ST_LEVEL_MARK;
125
		}
126
127
 
128
129
 
130
		strcpy(#URL, #editURL);
131
}
132
133
 
134
 
135
 
136
{
137
	if (!strcmp(get_URL_part(5),"http:")))
138
		file_size stdcall (#download_path);
139
	else
140
		file_size stdcall (#URL);
141
142
 
143
	if (!filesize) return;
144
145
 
146
	buf = mem_Alloc(filesize);
147
	if (!strcmp(get_URL_part(5),"http:")))
148
		ReadFile(0, filesize, buf, #download_path);
149
	else
150
		ReadFile(0, filesize, buf, #URL);
151
152
 
153
	if (encoding==_WIN) wintodos(buf);
154
	if (encoding==_UTF) utf8rutodos(buf);
155
	if (encoding==_KOI) koitodos(buf);
156
}
157
158
 
159
 
160
{
161
	if (GetProcessSlot(downloader_id)<>0) PutPaletteImage(#toolbar,200,42,0,0,8,#toolbar_pal);
162
	KillProcess(downloader_id);
163
	strcpy(#editURL, #URL);
164
	BrowserHistory.AddUrl();
165
	strcpy(#header, #version);
166
	pre_text =0;
167
	if (!strcmp(get_URL_part(5),"http:")))
168
	{
169
		KillProcess(downloader_id);
4415 leency 170
		DeleteFile(#download_path);
4411 leency 171
		IF (URL[strlen(#URL)-1]=='/') URL[strlen(#URL)-1]=NULL;
172
		downloader_id = RunProgram("/sys/network/downloader", #URL);
173
		IF (downloader_id<0) notify("Error running Downloader. Internet unavilable.");
4415 leency 174
		Draw_Window();
4411 leency 175
		return;
176
	}
177
	list.first = list.count =0;
4415 leency 178
	ReadHtml(_WIN);
4411 leency 179
	WB1.ShowPage();
180
}
181
182
 
183
 
184
{
185
	address_box.size = address_box.pos = strlen(#editURL);
186
	address_box.offset=0;
187
	edit_box_draw stdcall(#address_box);
188
189
 
190
	{
191
		DrawBar(list.x, list.y, list.w+scroll1.size_x+1, list.h, 0xFFFFFF); //fill all
4414 leency 192
		if (GetProcessSlot(downloader_id)<>0) WriteText(list.x + 10, list.y + 18, 0x80, 0, "Loading...");
193
		else
4411 leency 194
		{
195
			WriteText(list.x + 10, list.y + 18, 0x80, 0, "Page not found. May be, URL contains some errors.");
4414 leency 196
			if (!strcmp(get_URL_part(5),"http:"))) WriteText(list.x + 10, list.y + 32, 0x80, 0, "Or Internet unavilable for your configuration.");
197
		}
4411 leency 198
		//return;
199
	}
200
	else
201
		ParseHTML(buf);
202
203
 
204
	if (!strcmp(#version, #header)) DrawTitle(#header);
205
}
206
207
 
208
 
209
 
210
	word bukva[2];
211
	int j, perenos_num;
212
	byte ignor_param;
213
	char temp[768];
214
215
 
216
	b_text = i_text = u_text = s_text = blq_text =
217
	li_text = link = ignor_text = text_color_index = text_colors[0] = li_tab = 0; //обнуляем теги
218
	text_align = ALIGN_LEFT;
219
	link_color = 0x0000FF;
220
	bg_color = 0xFFFFFF;
221
	DrawBufFill();
222
	strcpy(#page_links,"|");
223
	strcpy(#header, #version);
224
	stroka = -list.first;
4415 leency 225
	stolbec = 0;
4411 leency 226
	line = 0;
227
228
 
229
	{
230
		pre_text=0;
231
		if (!strcmp(#URL + strlen(#URL) - 4, ".txt")) pre_text = 1;
232
		if (!strcmp(#URL + strlen(#URL) - 4, ".mht")) ignor_text = 1;
233
	}
234
235
 
236
	{
237
		bukva = ESBYTE[bword];
238
		if (ignor_text) && (bukva<>'<') continue;
239
		switch (bukva)
240
		{
241
		case 0x0a:
242
			if (pre_text)
243
			{
244
				bukva = temp = NULL;
245
				goto NEXT_MARK;
246
			}
247
		case '\9':
248
			if (pre_text) //иначе идём на 0x0d
249
			{
250
				tab_len=strlen(#line)/8;
251
				tab_len=tab_len*8;
252
				tab_len=8+tab_len-strlen(#line);
253
				for (j=0; j
254
				break;
255
			}
256
			goto DEFAULT_MARK;
257
		case '=': //quoted printable
258
			if (strcmp(#URL + strlen(#URL) - 4, ".mht")<>0) goto DEFAULT_MARK;
259
260
 
261
			temp[1] = ESBYTE[bword+2];
262
			temp[2] = '\0';
263
			if (bukva = Hex2Symb(#temp))
264
			{
265
				bword+=2;
266
				goto DEFAULT_MARK;
267
			}
268
			break;
269
270
 
271
			bword++;
272
			tag=0;
273
			for (j=0; (ESBYTE[bword]<>';') && (j<7);   j++, bword++;)
274
			{
275
				bukva = ESBYTE[bword];
276
				chrcat(#tag, bukva);
277
			}
278
			bukva = GetUnicodeSymbol();
279
			if (bukva) goto DEFAULT_MARK;
280
			break;
281
		case '<':
282
			bword++; //промотаем символ <
283
			tag = parametr = tagparam = ignor_param = NULL;
284
			if (ESBYTE[bword] == '!') //фильтрация внутри , дерзко
285
			{
286
				bword++;
287
				if (ESBYTE[bword] == '-')
288
				{
289
				HH_:
290
					do
291
					{
292
						bword++;
293
						if (buf + filesize <= bword) break 2;
294
					}
295
					while (ESBYTE[bword] <>'-');
296
297
 
298
					if (ESBYTE[bword] <>'-') goto HH_;
299
				}
300
			}
301
			while (ESBYTE[bword] !='>') && (bword < buf + filesize) //получаем тег и его параметры
302
			{
303
				bukva = ESBYTE[bword];
304
				if (bukva == '\9') || (bukva == '\x0a') || (bukva == '\x0d') bukva = ' ';
305
				if (!ignor_param) && (bukva <>' ')
306
				{
307
					if (strlen(#tag)
308
				}
309
				else
310
				{
311
					ignor_param = true;
312
					if (!ignor_text) && (strlen(#tagparam)+1
313
				}
314
				bword++;
315
			}
316
			strlwr(#tag);
317
			strlwr(#tagparam);
318
319
 
320
			if (tagparam) && (strlen(#tagparam) < 4000) GetNextParam();
321
322
 
4415 leency 323
			{
4411 leency 324
				perenos_num = strrchr(#line, ' ');
325
				if (!perenos_num) && (strlen(#line)>list.column_max) perenos_num=list.column_max;
4415 leency 326
				strcpy(#temp, #line + perenos_num); //перенос по словам
4411 leency 327
				line[perenos_num] = 0x00;
328
				if (stroka-1 > list.visible) && (list.first <>0) break 1; //уходим...
4415 leency 329
				DrawPage();
4411 leency 330
				strcpy(#line, #temp);
331
				TextGoDown(list.x + 5, stroka * 10 + list.y + 5, list.w - 20); //закрашиваем следущую строку
4414 leency 332
			}
4411 leency 333
			DrawPage();
334
			line=NULL;
335
336
 
4414 leency 337
4411 leency 338
 
339
			break;
340
		default:
341
			DEFAULT_MARK:
342
			if (bukva<=15) bukva=' ';
343
			if (!pre_text) && (bukva == ' ')
344
			{
345
				if (line[strlen(#line)-1]==' ') break; //убрать 2 пробела подряд
346
				if (!stolbec) && (!line) break; //строка не может начинаться с пробела
347
			}
348
			if (strlen(#line)
349
350
 
4415 leency 351
			{
4411 leency 352
			NEXT_MARK:
353
				perenos_num = strrchr(#line, ' ');
354
				if (!perenos_num) && (strlen(#line)>list.column_max) perenos_num=list.column_max;
4415 leency 355
				strcpy(#temp, #line + perenos_num); //перенос по словам
4411 leency 356
				line[perenos_num] = 0x00;
357
				if (stroka-1 > list.visible) && (list.first <>0) break 1; //уходим...
4415 leency 358
				DrawPage();
4411 leency 359
				strcpy(#line, #temp);
360
				TextGoDown(list.x + 5, stroka * 10 + list.y + 5, list.w - 20); //закрашиваем следущую строку
4414 leency 361
			}
4411 leency 362
		}
363
	}
364
365
 
366
	TextGoDown(list.x + 5, stroka * 10 + list.y + 5, list.w - 20); //закрашиваем следущую строку
4414 leency 367
4411 leency 368
 
4415 leency 369
		DrawBar(list.x, list.visible * 10 + list.y + 25, list.w, -list.visible * 10 + list.h - 25, bg_color);
370
	if (stroka * 10 + 5 <= list.h)
4414 leency 371
		DrawBar(list.x, stroka * 10 + list.y + 5, list.w, -stroka * 10 + list.h - 5, bg_color); //закрашиваем всё до конца
372
	if (list.first == 0) list.count = stroka;
4415 leency 373
	if (anchor) //если посреди текста появится новый якорь - будет бесконечный цикл
4411 leency 374
	{
375
		anchor=NULL;
376
		list.first=anchor_line_num;
4415 leency 377
		ParseHTML(buf);
4411 leency 378
	}
379
	DrawScroller();
380
}
381
382
 
383
 
384
 
385
void TWebBrowser::WhatTextStyle(int left1, top1, width1) {
386
	dword hr_color;
387
388
 
389
	if (tag[0] == '/')
390
	{
391
		 rez = 0;
392
		 strcpy(#tag, #tag+1);
393
	}
394
	else rez = 1;
395
396
 
397
	{
398
		IF(!strcmp(#URL + strlen(#URL) - 4, ".mht")) IF (rez==0) ignor_text = 1; ELSE ignor_text = 0;
399
		return;
400
	}
401
402
 
403
404
 
405
	{
406
		if (rez) header=NULL;
407
		else if (!stroka) DrawTitle(#header); //тег закрылся - вывели строку
408
		return;
409
	}
410
411
 
412
413
 
414
 
415
 
416
417
 
418
	{
419
		if (!strcmp(#anchor, #options))	anchor_line_num=list.first+stroka;
4415 leency 420
	}
4411 leency 421
422
 
423
	{
424
		do{
425
			if (!strcmp(#parametr, "link=")) link_color = GetColor(#options);
426
			if (!strcmp(#parametr, "text=")) text_colors[0]=GetColor(#options);
427
			if (!strcmp(#parametr, "bgcolor="))
428
			{
429
				bg_color=GetColor(#options);
430
				DrawBufFill();
431
			}
432
		} while(GetNextParam());
433
		return;
434
	}
435
436
 
437
	{
438
		if (rez)
439
		{
440
			if (link) IF(text_color_index > 0) text_color_index--; //если предыдущий тег а не был закрыт
441
442
 
443
				if (!strcmp(#parametr, "href="))
444
				{
445
					if (stroka - 1 > list.visible) || (stroka < -2) return;
4415 leency 446
4411 leency 447
 
448
					text_colors[text_color_index] = text_colors[text_color_index-1];
449
450
 
451
					blink++;
452
					text_colors[text_color_index] = link_color;
453
					strcat(#page_links, #options);
454
					strcat(#page_links, "|");
455
				}
456
				if (anchor) && (!strcmp(#parametr, "name="))
457
				{
458
					if (!strcmp(#anchor, #options))
459
					{
460
						anchor_line_num=list.first+stroka;
4415 leency 461
					}
4411 leency 462
				}
463
			} while(GetNextParam());
464
		}
465
		else {
466
			link = 0;
467
			IF(text_color_index > 0) text_color_index--;
468
		}
469
		return;
470
	}
471
472
 
473
	{
474
		if (rez)
475
		{
476
			text_color_index++;
477
			text_colors[text_color_index] = text_colors[text_color_index-1];
478
479
 
480
				if (strcmp(#parametr, "color=") == 0) //&& (parametr[1] == '#')
481
				{
482
					text_colors[text_color_index] = GetColor(#options);
483
				}
484
			} while(GetNextParam());
485
		}
486
		else
487
			if (text_color_index > 0) text_color_index--;
488
		return;
489
	}
490
	if(!chTag("tr")) || (!chTag("br")) {
491
		TextGoDown(left1, top1, width1);
492
		return;
493
	}
494
	if (!chTag("div")) {
495
		IF(oldtag[0] <>'h') TextGoDown(left1, top1, width1);
496
		return;
497
	}
498
	if (!chTag("p")) {
499
		IF(oldtag[0] == 'h') return;
500
		TextGoDown(left1, top1, width1);
501
		IF(rez) TextGoDown(left1, top1 + 10, width1);
502
		return;
503
	}
504
	if (!chTag("center"))
505
	{
506
		if (rez) text_align = ALIGN_CENTER;
507
		if (!rez)
508
		{
509
			TextGoDown(left1, top1, width1);
510
			text_align = ALIGN_LEFT;
511
		}
512
		return;
513
	}
514
	if (!chTag("right"))
515
	{
516
		if (rez) text_align = ALIGN_RIGHT;
517
		if (!rez)
518
		{
519
			TextGoDown(left1, top1, width1);
520
			text_align = ALIGN_LEFT;
521
		}
522
		return;
523
	}
524
	if (!chTag("h1")) || (!chTag("h2")) || (!chTag("h3")) || (!chTag("h4")) {
525
		TextGoDown(left1, top1, width1);
526
		if (rez) && (stroka>1) TextGoDown(left1, top1 + 10, width1);
527
		strcpy(#oldtag, #tag);
528
		if (rez)
529
		{
530
			if (!strcmp(#parametr, "align=")) && (!strcmp(#options,"center")) text_align = ALIGN_CENTER;
531
			if (!strcmp(#parametr, "align=")) && (!strcmp(#options,"right")) text_align = ALIGN_RIGHT;
532
			b_text = 1;
533
		}
534
		if (!rez)
535
		{
536
			text_align = ALIGN_LEFT;
537
			b_text = 0;
538
		}
539
		return;
540
	}
541
	else
542
		oldtag=NULL;
543
544
 
545
		b_text = rez;
546
		return;
547
	}
548
	if(!chTag("i")) || (!chTag("em")) || (!chTag("subtitle")) {
549
		i_text = rez;
550
		return;
551
	}
552
	if (!chTag("dt"))
553
	{
554
		li_text = rez;
555
		IF(rez == 0) return;
556
		TextGoDown(left1, top1, width1);
557
		return;
558
	}
559
	if(!chTag("li")) || (!chTag("dt")) //надо сделать вложенные списки
560
	{
561
		li_text = rez;
562
		if (rez)
563
		{
564
			TextGoDown(left1, top1, width1);
565
			if (stroka > -1) && (stroka - 2 < list.visible) DrawBufBar(li_tab * 5 * 6 + left1 - 5, list.line_h/2-3, 2, 2, 0x555555);
4415 leency 566
		}
4411 leency 567
		return;
568
	}
569
	if (!chTag("u")) || (!chTag("ins")) u_text = rez;
570
	if (!chTag("s")) || (!chTag("strike")) || (!chTag("del")) s_text = rez;
571
	if (!chTag("ul")) || (!chTag("ol")) IF(!rez)
572
	{
573
		li_text = rez;
574
		li_tab--;
575
		TextGoDown(left1, top1, width1);
576
	} ELSE li_tab++;
577
	if (!chTag("dd")) stolbec += 5;
578
	if (!chTag("blockquote")) blq_text = rez;
579
	if (!chTag("pre")) pre_text = rez;
580
	if (!chTag("hr"))
581
	{
582
		if (anchor) || (stroka < -1)
583
		{
584
			stroka+=2;
585
			return;
586
		}
587
		if (strcmp(#parametr, "color=") == 0) hr_color = GetColor(#options); else hr_color = 0x999999;
588
		TextGoDown(left1, top1, width1);
589
		DrawBufBar(5, WB1.list.line_h/2, WB1.list.w-10, 1, hr_color);
4414 leency 590
		TextGoDown(left1, top1+WB1.list.line_h, width1);
591
	}
4411 leency 592
	if (!chTag("img"))
593
	{
594
		Images( left1, top1, width1);
595
		return;
596
	}
597
	if (!chTag("meta")) || (!chTag("?xml"))
598
	{
599
		do{
600
			if (!strcmp(#parametr, "charset=")) || (!strcmp(#parametr, "content=")) || (!strcmp(#parametr, "encoding="))
601
			{
602
				strcpy(#options, #options[strrchr(#options, '=')]); //поиск в content=
603
				if (!strcmp(#options,"utf-8"))   || (!strcmp(#options,"utf8"))      ReadHtml(_UTF);
604
				if (!strcmp(#options, "koi8-r")) || (!strcmp(#options, "koi8-u"))   ReadHtml(_KOI);
605
				if (!strcmp(#options, "dos"))    || (!strcmp(#options, "cp-866"))   ReadHtml(_DOS);
606
			}
607
		} while(GetNextParam());
608
		return;
609
	}
610
}
611
612
 
613
 
614
 
615
{
616
	scroll1.max_area = list.count;
4415 leency 617
	scroll1.cur_area = list.visible;
618
	scroll1.position = list.first;
619
4411 leency 620
 
621
	scroll1.start_x = WB1.list.x + WB1.list.w;
4414 leency 622
	scroll1.size_y=WB1.list.h;
623
4411 leency 624
 
625
}
626
>
627