Subversion Repositories Kolibri OS

Rev

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