Subversion Repositories Kolibri OS

Rev

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

Rev Author Line No. Line
8330 leency 1
#include "TWB\colors.h"
2
#include "TWB\anchors.h"
3
#include "TWB\parse_tag.h"
4
#include "TWB\special.h"
5
#include "TWB\tag_list.h"
7757 leency 6
dword page_bg;
7759 leency 7
dword link_color_default;
7757 leency 8
dword link_color_active;
8330 leency 9
#include "TWB\links.h"
4411 leency 10
 
7759 leency 11
#define BODY_MARGIN 6
12
#define BASIC_LINE_H 18
4416 leency 13
 
7771 leency 14
DrawBufer DrawBuf;
15
char line[500];
16
 
5746 leency 17
struct _style {
7752 leency 18
	bool
6794 leency 19
	b, u, s, h,
8016 leency 20
	font,
5746 leency 21
	pre,
22
	blq,
7742 leency 23
	button,
7759 leency 24
	image;
7752 leency 25
	dword bg_color;
7759 leency 26
	LIST tag_list;
27
	dword tag_title;
5746 leency 28
};
29
 
4411 leency 30
struct TWebBrowser {
4540 leency 31
	llist list;
5746 leency 32
	_style style;
7752 leency 33
	dword draw_y, stolbec;
6803 leency 34
	int zoom;
7752 leency 35
	dword o_bufpointer;
7759 leency 36
	int cur_encoding, custom_encoding;
37
	bool link, t_html, t_body;
38
	dword bufpointer;
39
	dword bufsize;
7945 leency 40
	dword is_html;
8396 leency 41
	collection img_url;
7759 leency 42
 
7771 leency 43
	void Paint();
7746 leency 44
	void SetPageDefaults();
7752 leency 45
	void AddCharToTheLine();
46
	void ParseHtml();
5766 leency 47
	void SetStyle();
7762 leency 48
	bool CheckForLineBreak();
49
	void NewLine();
50
	void DrawScroller();
51
	void ChangeEncoding();
4411 leency 52
	void DrawPage();
7759 leency 53
	char header[150];
8302 leency 54
	char redirect[URL_SIZE];
7759 leency 55
};
4486 leency 56
 
7757 leency 57
scroll_bar scroll_wv = { 15,NULL,NULL,NULL,0,2,NULL,0,0,0xeeeeee,0xBBBbbb,0xeeeeee};
4411 leency 58
 
5747 leency 59
//============================================================================================
7771 leency 60
void TWebBrowser::Paint()
4411 leency 61
{
6803 leency 62
	dword start_x, line_length, stolbec_len;
7762 leency 63
	dword text_color__;
4411 leency 64
 
7759 leency 65
	if (style.tag_title)
4411 leency 66
	{
7759 leency 67
		strncpy(#header, #line, sizeof(TWebBrowser.header)-1);
68
		strncat(#header, " - ", sizeof(TWebBrowser.header)-1);
69
		strncat(#header, #version, sizeof(TWebBrowser.header)-1);
4411 leency 70
		line = 0;
71
		return;
72
	}
7758 leency 73
	if (t_html) && (!t_body) {
74
		line = 0;
75
		return;
76
	}
4411 leency 77
 
6803 leency 78
	if (line)
4411 leency 79
	{
7759 leency 80
		start_x = stolbec * list.font_w + BODY_MARGIN + list.x;
6803 leency 81
		stolbec_len = strlen(#line) * zoom;
5768 leency 82
		line_length = stolbec_len * list.font_w;
4411 leency 83
 
7749 leency 84
		if (debug_mode) {
7750 leency 85
			DrawBuf.DrawBar(start_x, draw_y, line_length, list.item_h, 0xDDDddd);
7749 leency 86
		}
87
 
7743 leency 88
		if (style.bg_color!=page_bg) {
7750 leency 89
			DrawBuf.DrawBar(start_x, draw_y, line_length, list.item_h, style.bg_color);
7743 leency 90
		}
91
 
7742 leency 92
		if (style.image) {
7743 leency 93
			DrawBuf.DrawBar(start_x, draw_y, line_length, list.item_h-1, 0xF9DBCB);
7742 leency 94
		}
95
		if (style.button) {
96
			DrawBuf.DrawBar(start_x, draw_y, line_length, list.item_h - calc(zoom*2), 0xCCCccc);
97
			DrawBuf.DrawBar(start_x, draw_y + list.item_h - calc(zoom*2), line_length, zoom, 0x999999);
98
		}
99
 
8016 leency 100
		text_color__ = text_colors.get_last();
101
		if (link) && (text_color__ == text_colors.get(0)) text_color__ = link_color_default;
7762 leency 102
 
7889 leency 103
		DrawBuf.WriteText(start_x, draw_y, list.font_type, text_color__, #line, NULL);
104
		if (style.b) DrawBuf.WriteText(start_x+1, draw_y, list.font_type, text_color__, #line, NULL);
7762 leency 105
		if (style.s) DrawBuf.DrawBar(start_x, list.item_h / 2 - zoom + draw_y, line_length, zoom, text_color__);
106
		if (style.u) DrawBuf.DrawBar(start_x, list.item_h - zoom - zoom + draw_y, line_length, zoom, text_color__);
5519 leency 107
		if (link) {
7747 leency 108
			if (line[0]==' ') && (line[1]==NULL) {} else {
7759 leency 109
				DrawBuf.DrawBar(start_x, draw_y + list.item_h - calc(zoom*2)-1, line_length, zoom, link_color_default);
7970 leency 110
				links.add_text(start_x, draw_y + list.y, line_length, list.item_h - calc(zoom*2)-1, zoom);
7746 leency 111
			}
4411 leency 112
		}
4718 leency 113
		stolbec += stolbec_len;
7750 leency 114
		if (debug_mode) debug(#line);
115
		line = NULL;
4411 leency 116
	}
117
}
5747 leency 118
//============================================================================================
7746 leency 119
void TWebBrowser::SetPageDefaults()
120
{
121
	style.b = style.u = style.s = style.h = style.blq = t_html = t_body = style.pre =
8016 leency 122
	link = style.tag_title = style.font = false;
7759 leency 123
	style.tag_list.reset();
124
	link_color_default = 0x0000FF;
4491 leency 125
	link_color_active = 0xFF0000;
8396 leency 126
	page_bg = 0xffEBE8E9; //E0E3E3 EBE8E9
7743 leency 127
	style.bg_color = page_bg;
128
	DrawBuf.Fill(0, page_bg);
7970 leency 129
	links.clear();
7752 leency 130
	anchors.clear();
8396 leency 131
	img_url.drop();
8016 leency 132
	text_colors.drop();
133
	text_colors.add(0);
7758 leency 134
	header = NULL;
7759 leency 135
	cur_encoding = CH_CP866;
136
	draw_y = BODY_MARGIN;
4411 leency 137
	stolbec = 0;
138
	line = 0;
7752 leency 139
	zoom = 1;
8302 leency 140
	redirect = '\0';
7757 leency 141
	//hold original buffer
142
	if (o_bufpointer) o_bufpointer=free(o_bufpointer);
143
	o_bufpointer = malloc(bufsize);
144
	memmov(o_bufpointer, bufpointer, bufsize);
7759 leency 145
	if (custom_encoding != -1) {
146
		cur_encoding = custom_encoding;
7781 leency 147
		bufpointer = ChangeCharset(cur_encoding, "CP866", bufpointer);
7759 leency 148
	}
7746 leency 149
}
150
//============================================================================================
7752 leency 151
void TWebBrowser::AddCharToTheLine(unsigned char _char)
152
{
153
	dword line_len;
154
	if (_char<=15) _char=' ';
155
	line_len = strlen(#line);
156
	if (!style.pre) && (_char == ' ')
157
	{
158
		if (line[line_len-1]==' ') return; //no double spaces
159
		if (!stolbec) && (!line) return; //no paces at the beginning of the line
8350 leency 160
		if (link) && (line_len==0) return;
7752 leency 161
	}
7771 leency 162
	if (line_len < sizeof(line)) chrcat(#line, _char);
7752 leency 163
	CheckForLineBreak();
164
}
165
//============================================================================================
7759 leency 166
void TWebBrowser::ParseHtml(dword _bufpointer, _bufsize){
7746 leency 167
	word bukva[2];
7752 leency 168
	char unicode_symbol[10];
169
	dword unicode_symbol_result;
7746 leency 170
	dword j;
7752 leency 171
	bool ignor_param=false;
172
	int tab_len;
7746 leency 173
	dword bufpos;
7759 leency 174
	bufsize = _bufsize;
7771 leency 175
	if (bufpointer != _bufpointer) {
176
		bufpointer = malloc(bufsize);