Subversion Repositories Kolibri OS

Rev

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

Rev 8454 Rev 8457
Line 37... Line 37...
37
}
37
}
Line 38... Line 38...
38
 
38
 
39
struct TWebBrowser {
39
struct TWebBrowser {
40
	llist list;
40
	llist list;
41
	STYLE style;
41
	STYLE style;
42
	dword draw_y, stolbec;
-
 
43
	int zoom;
42
	dword draw_y, draw_x;
44
	dword o_bufpointer;
43
	dword o_bufpointer;
45
	int cur_encoding, custom_encoding;
44
	int cur_encoding, custom_encoding;
46
	bool link, t_html, t_body;
45
	bool link, t_html, t_body;
47
	dword bufpointer;
46
	dword bufpointer;
Line 84... Line 83...
84
void TWebBrowser::Paint()
83
void TWebBrowser::Paint()
85
{
84
{
86
	unsigned px; //paint x coordinate
85
	unsigned px; //paint x coordinate
87
	unsigned pw; //paint y coordinate
86
	unsigned pw; //paint y coordinate
88
	   dword pc; //paint color
87
	   dword pc; //paint color
-
 
88
	   int zoom;
Line 89... Line 89...
89
	
89
 
90
	if (style.title)
90
	if (style.title)
91
	{
91
	{
92
		strncpy(#header, #line, sizeof(TWebBrowser.header)-1);
92
		strncpy(#header, #line, sizeof(TWebBrowser.header)-1);
Line 100... Line 100...
100
		return;
100
		return;
101
	}
101
	}
Line 102... Line 102...
102
	
102
	
103
	if (line)
103
	if (line)
104
	{
-
 
105
		px = stolbec * list.font_w + BODY_MARGIN + list.x;
104
	{
106
		pw = strlen(#line) * zoom * list.font_w;
105
		pw = strlen(#line) * list.font_w;
Line 107... Line 106...
107
		stolbec += strlen(#line) * zoom;
106
		zoom = list.font_w / BASIC_CHAR_W;
Line 108... Line 107...
108
 
107
 
109
		style.cur_line_h = math.max(style.cur_line_h, list.item_h);
108
		style.cur_line_h = math.max(style.cur_line_h, list.item_h);
110
 
109
 
Line 111... Line 110...
111
		if (bg_colors.get_last() - bg_colors.get(0)) {
110
		if (bg_colors.get_last() - bg_colors.get(0)) {
112
			canvas.DrawBar(px, draw_y, pw, list.item_h, bg_colors.get_last());
111
			canvas.DrawBar(draw_x, draw_y, pw, list.item_h, bg_colors.get_last());
113
		}
112
		}
114
 
113
 
115
		if (style.image) {
114
		if (style.image) {
116
			canvas.DrawBar(px, draw_y, pw, list.item_h-1, 0xF9DBCB);
115
			canvas.DrawBar(draw_x, draw_y, pw, list.item_h-1, 0xF9DBCB);
117
		}
116
		}
Line 118... Line 117...
118
		if (style.button) {
117
		if (style.button) {
119
			canvas.DrawBar(px, draw_y, pw, list.item_h - calc(zoom*2), 0xCCCccc);
118
			canvas.DrawBar(draw_x, draw_y, pw, list.item_h - calc(zoom*2), 0xCCCccc);
Line 120... Line 119...
120
			canvas.DrawBar(px, draw_y + list.item_h - calc(zoom*2), pw, zoom, 0x999999);
119
			canvas.DrawBar(draw_x, draw_y + list.item_h - calc(zoom*2), pw, zoom, 0x999999);
121
		}
120
		}
122
 
121
 
123
		pc = text_colors.get_last();
122
		pc = text_colors.get_last();
124
		if (link) && (pc == text_colors.get(0)) pc = link_color_default;
123
		if (link) && (pc == text_colors.get(0)) pc = link_color_default;
125
 
124
 
126
		canvas.WriteText(px, draw_y, list.font_type, pc, #line, NULL);
125
		canvas.WriteText(draw_x, draw_y, list.font_type, pc, #line, NULL);
127
		if (style.b) canvas.WriteText(px+1, draw_y, list.font_type, pc, #line, NULL);
126
		if (style.b) canvas.WriteText(draw_x+1, draw_y, list.font_type, pc, #line, NULL);
128
		if (style.s) canvas.DrawBar(px, list.item_h / 2 - zoom + draw_y, pw, zoom, pc);
127
		if (style.s) canvas.DrawBar(draw_x, list.item_h / 2 - zoom + draw_y, pw, zoom, pc);
129
		if (style.u) canvas.DrawBar(px, list.item_h - zoom - zoom + draw_y, pw, zoom, pc);
128
		if (style.u) canvas.DrawBar(draw_x, list.item_h - zoom - zoom + draw_y, pw, zoom, pc);
-
 
129
		if (link) {
130
		if (link) {
130
			if (line[0]==' ') && (line[1]==NULL) {} else {
131
			if (line[0]==' ') && (line[1]==NULL) {} else {
131
				canvas.DrawBar(draw_x, draw_y + list.item_h - calc(zoom*2)-1, pw, zoom, link_color_default);
132
				canvas.DrawBar(px, draw_y + list.item_h - calc(zoom*2)-1, pw, zoom, link_color_default);
132
				links.add_text(draw_x, draw_y + list.y, pw, list.item_h - calc(zoom*2)-1, zoom);				
133
				links.add_text(px, draw_y + list.y, pw, list.item_h - calc(zoom*2)-1, zoom);				
133
			}
134
			}
134
		}
Line 154... Line 154...
154
	bg_colors.add(DEFAULT_BG_COL);
154
	bg_colors.add(DEFAULT_BG_COL);
155
	canvas.Fill(0, DEFAULT_BG_COL);
155
	canvas.Fill(0, DEFAULT_BG_COL);
156
	header = NULL;
156
	header = NULL;
157
	cur_encoding = CH_CP866;
157
	cur_encoding = CH_CP866;
158
	draw_y = BODY_MARGIN;
158
	draw_y = BODY_MARGIN;
159
	stolbec = 0;
159
	draw_x = BODY_MARGIN;
160
	line = 0;
160
	line = 0;
161
	zoom = 1;
-
 
162
	redirect = '\0';
161
	redirect = '\0';
163
	//hold original buffer
162
	//hold original buffer
164
	if (o_bufpointer) o_bufpointer=free(o_bufpointer);
163
	if (o_bufpointer) o_bufpointer=free(o_bufpointer);
165
	o_bufpointer = malloc(bufsize);
164
	o_bufpointer = malloc(bufsize);
166
	memmov(o_bufpointer, bufpointer, bufsize);
165
	memmov(o_bufpointer, bufpointer, bufsize);
Line 175... Line 174...
175
	dword j;
174
	dword j;
176
	int tab_len;
175
	int tab_len;
177
	dword bufpos;
176
	dword bufpos;
178
	bufsize = _bufsize;
177
	bufsize = _bufsize;
Line -... Line 178...
-
 
178
 
-
 
179
	if (list.w!=canvas.bufw) canvas.Init(list.x, list.y, list.w, 400*20);
179
 
180
 
180
	if (bufpointer != _bufpointer) {
181
	if (bufpointer != _bufpointer) {
181
		bufpointer = malloc(bufsize);
182
		bufpointer = malloc(bufsize);
182
		memmov(bufpointer, _bufpointer, bufsize);
183
		memmov(bufpointer, _bufpointer, bufsize);
183
	} else {
184
	} else {
Line 204... Line 205...
204
				AddCharToTheLine(0x0a);
205
				AddCharToTheLine(0x0a);
205
			}
206
			}
206
			break;
207
			break;
207
		case 0x09:
208
		case 0x09:
208
			if (style.pre) {
209
			if (style.pre) {
209
				tab_len = strlen(#line) + stolbec % 4;
210
				tab_len = draw_x - BODY_MARGIN / list.font_w + strlen(#line) % 4;
210
				if (!tab_len) tab_len = 4; else tab_len = 4 - tab_len;
211
				if (!tab_len) tab_len = 4; else tab_len = 4 - tab_len;
211
				for (j=0; j
212
				for (j=0; j
212
			} else {
213
			} else {
213
				AddCharToTheLine(0x09);
214
				AddCharToTheLine(0x09);
214
			}
215
			}
Line 278... Line 279...
278
	if (_char<=15) _char=' ';
279
	if (_char<=15) _char=' ';
279
	line_len = strlen(#line);
280
	line_len = strlen(#line);
280
	if (!style.pre) && (_char == ' ')
281
	if (!style.pre) && (_char == ' ')
281
	{
282
	{
282
		if (line[line_len-1]==' ') return; //no double spaces
283
		if (line[line_len-1]==' ') return; //no double spaces
283
		if (!stolbec) && (!line) return; //no paces at the beginning of the line
284
		if (draw_x==BODY_MARGIN) && (!line) return; //no paces at the beginning of the line
284
		if (link) && (line_len==0) return;
285
		if (link) && (line_len==0) return;
285
	}
286
	}
286
	if (line_len < sizeof(line)) chrcat(#line, _char);
287
	if (line_len < sizeof(line)) chrcat(#line, _char);
287
	CheckForLineBreak();
288
	CheckForLineBreak();
288
}
289
}
289
//============================================================================================
290
//============================================================================================
290
bool TWebBrowser::CheckForLineBreak()
291
bool TWebBrowser::CheckForLineBreak()
291
{
292
{
292
	int line_break_pos;
293
	int break_pos;
293
	char new_line_text[4096];
294
	char next_line[4096];
-
 
295
	int zoom = list.font_w / BASIC_CHAR_W;
294
	//Do we need a line break?
296
	//Do we need a line break?
295
	if (strlen(#line)*zoom + stolbec < list.column_max) return false;
297
	if (strlen(#line) * list.font_w + draw_x < list.w) return false;
296
	//Yes, we do. Lets calculate where...
298
	//Yes, we do. Lets calculate where...
297
	line_break_pos = strrchr(#line, ' ');
299
	break_pos = strrchr(#line, ' ');
-
 
300
 
298
	//Is a new line fits in the current line?
301
	//Is a new line fits in the current line?
299
	if (line_break_pos*zoom + stolbec > list.column_max) {
302
	if (break_pos * list.font_w + draw_x > list.w) {
300
		line_break_pos = list.column_max/zoom - stolbec;
303
		break_pos = list.w - draw_x /list.font_w;
301
		while(line_break_pos) && (line[line_break_pos]!=' ') line_break_pos--;
304
		while(break_pos) && (line[break_pos]!=' ') break_pos--;
302
	}
305
	}
303
	//Maybe a new line is too big for the whole new line? Then we have to split it
306
	//Maybe a new line is too big for the whole new line? Then we have to split it
304
	if (!line_break_pos) && (style.tag_list.level*5 + strlen(#line) * zoom >= list.column_max) {
307
	if (!break_pos) && (style.tag_list.level*5 + strlen(#line) * zoom >= list.column_max) {
305
		line_break_pos = list.column_max/zoom - stolbec;
308
		break_pos = list.w  - draw_x / list.font_w;
306
	}
309
	}
-
 
310
 
307
	strcpy(#new_line_text, #line + line_break_pos);
311
	strcpy(#next_line, #line + break_pos);
308
	line[line_break_pos] = 0x00;		
312
	line[break_pos] = 0x00;		
Line 309... Line 313...
309
	
313
	
Line 310... Line 314...
310
	Paint();
314
	Paint();
311
 
315
 
312
	strcpy(#line, #new_line_text);
316
	strcpy(#line, #next_line);
313
	NewLine();
317
	NewLine();
314
	return true;
318
	return true;
315
}
319
}
316
//============================================================================================
320
//============================================================================================
317
void TWebBrowser::NewLine()
321
void TWebBrowser::NewLine()
Line 318... Line 322...
318
{
322
{
-
 
323
	static bool empty_line = true;
Line 319... Line 324...
319
	static int empty_line=0;
324
 
320
 
325
	if (draw_x==BODY_MARGIN) && (draw_y==BODY_MARGIN) return;
321
	if (!stolbec) && (draw_y==BODY_MARGIN) return;
-
 
322
	
-
 
323
	if (style.tag_list.level) && (stolbec == style.tag_list.level * 5) { 
-
 
324
		if (empty_line<1) empty_line++;
-
 
325
		else return;
326
	if (t_html) && (!t_body) return;
326
	} else if (!stolbec) { 
327
	
327
		if (empty_line<1) empty_line++;
328
	if (draw_x == style.tag_list.level * 5 * list.font_w + BODY_MARGIN) { 
Line 328... Line -...
328
		else return;
-
 
329
	} else {
329
		if (!empty_line) empty_line=true; else return;
330
		empty_line=0;
330
	} else {
331
	}
331
		empty_line = false;
332
 
332
	}
333
	if (t_html) && (!t_body) return;
333
 
334
	draw_y += style.cur_line_h;
334
	draw_y += style.cur_line_h;
335
	style.cur_line_h = list.item_h;
335
	style.cur_line_h = list.item_h;
336
	if (style.blq) stolbec = 6; else stolbec = 0;
336
	if (style.blq) draw_x = 6 * list.font_w; else draw_x = 0;
337
	stolbec += style.tag_list.level * 5;
337
	draw_x += style.tag_list.level * 5 * list.font_w + BODY_MARGIN;
Line 352... Line 352...
352
{ 15,NULL,NULL,NULL,0,2,NULL,
352
{ 15,NULL,NULL,NULL,0,2,NULL,
353
  0,0,0xeeeeee,0xBBBbbb,0xeeeeee};
353
  0,0,0xeeeeee,0xBBBbbb,0xeeeeee};
Line 354... Line 354...
354
 
354
 
355
void TWebBrowser::DrawPage()
355
void TWebBrowser::DrawPage()
-
 
356
{
-
 
357
	if (list.w!=canvas.bufw) {
-
 
358
		ParseHtml(bufpointer, bufsize);
-
 
359
	}
-
 
360
	canvas.Show(list.first, list.h);
356
{
361
 
357
	scroll_wv.max_area = list.count;
362
	scroll_wv.max_area = list.count;
358
	scroll_wv.cur_area = list.visible;
363
	scroll_wv.cur_area = list.visible;
359
	scroll_wv.position = list.first;
364
	scroll_wv.position = list.first;
360
	scroll_wv.all_redraw = 0;
365
	scroll_wv.all_redraw = 0;
361
	scroll_wv.start_x = list.x + list.w;
366
	scroll_wv.start_x = list.x + list.w;
362
	scroll_wv.start_y = list.y;
367
	scroll_wv.start_y = list.y;
363
	scroll_wv.size_y = list.h;
368
	scroll_wv.size_y = list.h;
Line 364... Line -...
364
	scrollbar_v_draw(#scroll_wv);
-
 
365
 
369
	scrollbar_v_draw(#scroll_wv);
366
	canvas.Show(list.first, list.h);
370