#include "..\TWB\colors.h" #include "..\TWB\anchors.h" #include "..\TWB\parse_tag.h" #include "..\TWB\special.h" #include "..\TWB\img_cache.h" #include "..\TWB\tag_list.h" dword page_bg; dword link_color_default; dword link_color_active; #include "..\TWB\links.h" #define BODY_MARGIN 6 #define BASIC_LINE_H 18 DrawBufer DrawBuf; char line[500]; struct _style { bool b, u, s, h, pre, blq, button, image; dword bg_color; LIST tag_list; dword tag_title; }; struct TWebBrowser { llist list; _style style; dword draw_y, stolbec; int zoom; dword o_bufpointer; int cur_encoding, custom_encoding; bool link, t_html, t_body; dword link_bg; dword bufpointer; dword bufsize; dword is_html; void Paint(); void SetPageDefaults(); void AddCharToTheLine(); void ParseHtml(); void SetStyle(); bool CheckForLineBreak(); void NewLine(); void DrawScroller(); void ChangeEncoding(); void DrawPage(); char header[150]; }; scroll_bar scroll_wv = { 15,NULL,NULL,NULL,0,2,NULL,0,0,0xeeeeee,0xBBBbbb,0xeeeeee}; //============================================================================================ void TWebBrowser::Paint() { dword start_x, line_length, stolbec_len; dword text_color__; if (style.tag_title) { strncpy(#header, #line, sizeof(TWebBrowser.header)-1); strncat(#header, " - ", sizeof(TWebBrowser.header)-1); strncat(#header, #version, sizeof(TWebBrowser.header)-1); line = 0; return; } if (t_html) && (!t_body) { line = 0; return; } if (line) { start_x = stolbec * list.font_w + BODY_MARGIN + list.x; stolbec_len = strlen(#line) * zoom; line_length = stolbec_len * list.font_w; if (debug_mode) { DrawBuf.DrawBar(start_x, draw_y, line_length, list.item_h, 0xDDDddd); } if (style.bg_color!=page_bg) { DrawBuf.DrawBar(start_x, draw_y, line_length, list.item_h, style.bg_color); } if (style.image) { DrawBuf.DrawBar(start_x, draw_y, line_length, list.item_h-1, 0xF9DBCB); } if (style.button) { DrawBuf.DrawBar(start_x, draw_y, line_length, list.item_h - calc(zoom*2), 0xCCCccc); DrawBuf.DrawBar(start_x, draw_y + list.item_h - calc(zoom*2), line_length, zoom, 0x999999); } text_color__ = text_colors[text_color_index]; if (link) && (text_colors[text_color_index]==text_colors[0]) text_color__ = link_color_default; DrawBuf.WriteText(start_x, draw_y, list.font_type, text_color__, #line, NULL); if (style.b) DrawBuf.WriteText(start_x+1, draw_y, list.font_type, text_color__, #line, NULL); if (style.s) DrawBuf.DrawBar(start_x, list.item_h / 2 - zoom + draw_y, line_length, zoom, text_color__); if (style.u) DrawBuf.DrawBar(start_x, list.item_h - zoom - zoom + draw_y, line_length, zoom, text_color__); if (link) { if (line[0]==' ') && (line[1]==NULL) {} else { DrawBuf.DrawBar(start_x, draw_y + list.item_h - calc(zoom*2)-1, line_length, zoom, link_color_default); PageLinks.AddText(start_x, draw_y + list.y, line_length, list.item_h - calc(zoom*2)-1, UNDERLINE, zoom); } } stolbec += stolbec_len; if (debug_mode) debug(#line); line = NULL; } } //============================================================================================ void TWebBrowser::SetPageDefaults() { style.b = style.u = style.s = style.h = style.blq = t_html = t_body = style.pre = link = text_color_index = text_colors[0] = style.tag_title = false; style.tag_list.reset(); link_color_default = 0x0000FF; link_color_active = 0xFF0000; page_bg = 0xFFFFFF; link_bg = 0xFFFFFF; style.bg_color = page_bg; DrawBuf.Fill(0, page_bg); PageLinks.Clear(); anchors.clear(); header = NULL; cur_encoding = CH_CP866; draw_y = BODY_MARGIN; stolbec = 0; line = 0; zoom = 1; //hold original buffer if (o_bufpointer) o_bufpointer=free(o_bufpointer); o_bufpointer = malloc(bufsize); memmov(o_bufpointer, bufpointer, bufsize); if (custom_encoding != -1) { cur_encoding = custom_encoding; bufpointer = ChangeCharset(cur_encoding, "CP866", bufpointer); } } //============================================================================================ void TWebBrowser::AddCharToTheLine(unsigned char _char) { dword line_len; if (_char<=15) _char=' '; line_len = strlen(#line); if (!style.pre) && (_char == ' ') { if (line[line_len-1]==' ') return; //no double spaces if (!stolbec) && (!line) return; //no paces at the beginning of the line } if (line_len < sizeof(line)) chrcat(#line, _char); CheckForLineBreak(); } //============================================================================================ void TWebBrowser::ParseHtml(dword _bufpointer, _bufsize){ word bukva[2]; char unicode_symbol[10]; dword unicode_symbol_result; dword j; bool ignor_param=false; int tab_len; dword bufpos; bufsize = _bufsize; if (bufpointer != _bufpointer) { bufpointer = malloc(bufsize); memmov(bufpointer, _bufpointer, bufsize); } else { custom_encoding = CH_CP866; } SetPageDefaults(); is_html = true; if (!strstri(bufpointer, "
';') && (j<8); j++) { bukva = ESBYTE[bufpos+j]; chrcat(#unicode_symbol, bukva); } if (GetUnicodeSymbol(#line, #unicode_symbol, sizeof(line)-1)) { bufpos += j; CheckForLineBreak(); } else { AddCharToTheLine('&'); } break; case '<': if (!is_html) goto _default; bufpos++; if (!strncmp(bufpos,"!--",3)) { bufpos+=3; while (strncmp(bufpos,"-->",3)!=0) && (bufpos < bufpointer + bufsize) { bufpos++; } bufpos+=2; break; } tag.reset(); if (ESBYTE[bufpos] == '/') { tag.opened = false; bufpos++; } ignor_param=false; while (ESBYTE[bufpos] !='>') && (bufpos < bufpointer + bufsize) //ïîëó÷àåì òåã è åãî ïàðàìåòðû { bukva = ESBYTE[bufpos]; if (bukva == '\x9') || (bukva == '\x0a') || (bukva == '\x0d') bukva = ' '; if (!ignor_param) && (bukva <>' ') { if (strlen(#tag.name)+1