Subversion Repositories Kolibri OS

Rev

Rev 8490 | Rev 8492 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 8490 Rev 8491
Line 10... Line 10...
10
 
10
 
11
#define BODY_MARGIN 6
11
#define BODY_MARGIN 6
12
#define BASIC_CHAR_W 8
12
#define BASIC_CHAR_W 8
Line 13... Line -...
13
#define BASIC_LINE_H 18
-
 
14
 
-
 
15
char line[500];
13
#define BASIC_LINE_H 18
16
 
14
 
17
struct STYLE {
15
struct STYLE {
18
	bool
16
	bool
19
	b, u, s, h,
17
	b, u, s, h,
Line 46... Line 44...
46
	dword bufpointer;
44
	dword bufpointer;
47
	dword bufsize;
45
	dword bufsize;
48
	dword is_html;
46
	dword is_html;
49
	collection img_url;
47
	collection img_url;
50
	char header[150];
48
	char header[150];
-
 
49
	char line[500];
51
	char redirect[URL_SIZE];
50
	char redirect[URL_SIZE];
Line 52... Line 51...
52
 
51
 
-
 
52
	void SetStyle();
53
	void SetStyle();
53
	void RenderTextbuf();
54
	void Render();
54
	void RenderLine();
Line 55... Line 55...
55
	bool RenderImage();
55
	bool RenderImage();
56
 
-
 
57
	void SetPageDefaults();
56
 
58
	void AddCharToTheLine();
-
 
59
	void ParseHtml();
57
	void SetPageDefaults();
60
	bool CheckForLineBreak();
58
	void ParseHtml();
-
 
59
	void NewLine();
61
	void NewLine();
60
	void ChangeEncoding();
Line 62... Line 61...
62
	void ChangeEncoding();
61
	void AddCharToTheLine();
63
	void DrawPage();
62
	void DrawPage();
64
 
63
 
Line 117... Line 116...
117
	}
116
	}
118
	list.SetFont(8, 14, 10011000b);
117
	list.SetFont(8, 14, 10011000b);
119
}
118
}
120
//============================================================================================
119
//============================================================================================
121
void TWebBrowser::ParseHtml(dword _bufpointer, _bufsize){
120
void TWebBrowser::ParseHtml(dword _bufpointer, _bufsize){
122
	char unicode_symbol[10];
-
 
123
	dword j;
-
 
124
	int tab_len;
121
	int tab_len;
125
	dword bufpos;
122
	dword bufpos;
126
	bufsize = _bufsize;
123
	bufsize = _bufsize;
Line 127... Line 124...
127
 
124
 
Line 146... Line 143...
146
	{
143
	{
147
		switch (ESBYTE[bufpos])
144
		switch (ESBYTE[bufpos])
148
		{
145
		{
149
		case 0x0a:
146
		case 0x0a:
150
			if (style.pre) {
147
			if (style.pre) {
151
				Render();
148
				RenderTextbuf();
152
				NewLine();
149
				NewLine();
153
			} else {
150
			} else {
154
				AddCharToTheLine(' ');
151
				goto _DEFAULT;
155
			}
152
			}
156
			break;
153
			break;
157
		case 0x09:
154
		case 0x09:
158
			if (style.pre) {
155
			if (style.pre) {
159
				tab_len = draw_x - left_gap / list.font_w + strlen(#line) % 4;
156
				tab_len = draw_x - left_gap / list.font_w + strlen(#line) % 4;
160
				if (!tab_len) tab_len = 4; else tab_len = 4 - tab_len;
157
				if (!tab_len) tab_len = 4; else tab_len = 4 - tab_len;
161
				for (j=0; j
158
				while (tab_len) {chrcat(#line,' '); tab_len--;}
162
			} else {
159
			} else {
163
				AddCharToTheLine(' ');
160
				goto _DEFAULT;
164
			}
161
			}
165
			break;
162
			break;
166
		case '&': //  and so on
163
		case '&': //  and so on
167
			for (j=1, unicode_symbol=0; (ESBYTE[bufpos+j]<>';') && (!__isWhite(ESBYTE[bufpos+j])) && (j<8); j++)
-
 
168
			{
-
 
169
				chrcat(#unicode_symbol, ESBYTE[bufpos+j]);
-
 
170
			}
-
 
171
			if (GetUnicodeSymbol(#line, #unicode_symbol, sizeof(line)-1)) {
164
			bufpos = GetUnicodeSymbol(#line, sizeof(TWebBrowser.line), bufpos+1, bufpointer+bufsize);
172
				bufpos += j;
-
 
173
				CheckForLineBreak();
-
 
174
			} else {
-
 
175
				AddCharToTheLine('&');
-
 
176
			}
-
 
177
			break;
165
			break;
178
		case '<':
166
		case '<':
179
			if (!is_html) goto _DEFAULT;
167
			if (!is_html) goto _DEFAULT;
180
			if (!strchr("!/?abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ", ESBYTE[bufpos+1])) goto _DEFAULT;
168
			if (!strchr("!/?abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ", ESBYTE[bufpos+1])) goto _DEFAULT;
181
			bufpos++;
169
			bufpos++;
182
			if (tag.parse(#bufpos, bufpointer + bufsize)) {
170
			if (tag.parse(#bufpos, bufpointer + bufsize)) {
183
				CheckForLineBreak();
-
 
184
				Render();
171
				RenderTextbuf();
185
				$push cur_encoding
172
				$push cur_encoding
186
				SetStyle();
173
				SetStyle();
187
				$pop eax
174
				$pop eax
188
				// The thing is that UTF if longer than other encodings.
175
				// The thing is that UTF if longer than other encodings.
189
				// So if encoding was changed from UTF to DOS than $bufpos position got wrong,
176
				// So if encoding was changed from UTF to DOS than $bufpos position got wrong,
Line 197... Line 184...
197
		default:
184
		default:
198
			_DEFAULT:
185
			_DEFAULT:
199
			AddCharToTheLine(ESBYTE[bufpos]);
186
			AddCharToTheLine(ESBYTE[bufpos]);
200
		}
187
		}
201
	}
188
	}
202
	Render();
189
	RenderTextbuf();
203
	NewLine();
-
 
204
	list.count = draw_y;
190
	list.count = draw_y + style.cur_line_h;
Line 205... Line 191...
205
 
191
 
206
	canvas.bufh = math.max(list.visible, draw_y);
192
	canvas.bufh = math.max(list.visible, list.count);
Line 207... Line 193...
207
	buf_data = realloc(buf_data, canvas.bufh * canvas.bufw * 4 + 8);
193
	buf_data = realloc(buf_data, canvas.bufh * canvas.bufw * 4 + 8);
208
 
194
 
209
	list.CheckDoesValuesOkey();
195
	list.CheckDoesValuesOkey();
Line 215... Line 201...
215
	}
201
	}
216
}
202
}
217
//============================================================================================
203
//============================================================================================
218
void TWebBrowser::AddCharToTheLine(unsigned char _char)
204
void TWebBrowser::AddCharToTheLine(unsigned char _char)
219
{
205
{
220
	dword line_len;
206
	dword line_len = strlen(#line);
221
	if (_char<=15) _char=' ';
207
	if (_char<=15) _char=' ';
222
	line_len = strlen(#line);
-
 
223
	if (!style.pre) && (_char == ' ')
208
	if (!style.pre) && (_char == ' ')
224
	{
209
	{
225
		if (line[line_len-1]==' ') return; //no double spaces
210
		if (line[line_len-1]==' ') return; //no double spaces
226
		if (draw_x==left_gap) && (!line) return; //no paces at the beginning of the line
211
		if (draw_x==left_gap) && (!line) return; //no paces at the beginning of the line
227
		if (link) && (line_len==0) return;
212
		if (link) && (line_len==0) return;
228
	}
213
	}
229
	if (line_len < sizeof(line)) chrcat(#line, _char);
214
	if (line_len < sizeof(TWebBrowser.line)) chrcat(#line+line_len, _char);
230
	CheckForLineBreak();
-
 
231
}
-
 
232
//============================================================================================
-
 
233
bool TWebBrowser::CheckForLineBreak()
-
 
234
{
-
 
235
	int break_pos;
-
 
236
	char next_line[4096];
-
 
237
	int zoom = list.font_w / BASIC_CHAR_W;
-
 
238
	//Do we need a line break?
-
 
239
	if (strlen(#line) * list.font_w + draw_x < draw_w) return false;
215
	if (line_len+1 * list.font_w + draw_x >= draw_w) RenderTextbuf();
240
	//Yes, we do. Lets calculate where...
-
 
241
	break_pos = strrchr(#line, ' ');
-
 
242
 
-
 
243
	//Is a new line fits in the current line?
-
 
244
	if (break_pos * list.font_w + draw_x > draw_w) {
-
 
245
		break_pos = draw_w - draw_x /list.font_w;
-
 
246
		while(break_pos) && (line[break_pos]!=' ') break_pos--;
-
 
247
	}
-
 
248
	//Maybe a new line is too big for the whole new line? Then we have to split it
-
 
249
	if (!break_pos) && (style.tag_list.level*5 + strlen(#line) * zoom >= list.column_max) {
-
 
250
		break_pos = draw_w  - draw_x / list.font_w;
-
 
251
	}
-
 
252
 
-
 
253
	strcpy(#next_line, #line + break_pos);
-
 
254
	line[break_pos] = 0x00;		
-
 
255
	
-
 
256
	Render();
-
 
257
 
-
 
258
	strcpy(#line, #next_line);
-
 
259
	NewLine();
-
 
260
	return true;
-
 
261
}
216
}
262
//============================================================================================
217
//============================================================================================
263
void TWebBrowser::NewLine()
218
void TWebBrowser::NewLine()
264
{
219
{
265
	static bool empty_line = true;
220
	static bool empty_line = true;
Line 288... Line 243...
288
		ChangeCharset(cur_encoding, "CP866", #header);
243
		ChangeCharset(cur_encoding, "CP866", #header);
289
		DrawTitle(#header);
244
		DrawTitle(#header);
290
	}
245
	}
291
}
246
}
292
//============================================================================================
247
//============================================================================================
293
scroll_bar scroll_wv = 
248
scroll_bar scroll_wv = { 15,NULL,NULL,NULL,
294
{ 15,NULL,NULL,NULL,0,2,NULL,
-
 
295
  0,0,0xeeeeee,0xBBBbbb,0xeeeeee};
249
  0,2,NULL,0,0,0xeeeeee,0xBBBbbb,0xeeeeee};
Line 296... Line 250...
296
 
250
 
297
void TWebBrowser::DrawPage()
251
void TWebBrowser::DrawPage()
298
{
252
{
299
	if (list.w!=canvas.bufw) {
253
	if (list.w!=canvas.bufw) {