Rev 8499 | Rev 8572 | 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" |
||
8451 | leency | 6 | #define DEFAULT_BG_COL 0xffEBE8E9; |
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 |
8462 | leency | 12 | #define BASIC_CHAR_W 8 |
7759 | leency | 13 | #define BASIC_LINE_H 18 |
4416 | leency | 14 | |
8439 | leency | 15 | struct STYLE { |
7752 | leency | 16 | bool |
6794 | leency | 17 | b, u, s, h, |
8016 | leency | 18 | font, |
5746 | leency | 19 | pre, |
20 | blq, |
||
7742 | leency | 21 | button, |
7759 | leency | 22 | image; |
23 | LIST tag_list; |
||
8439 | leency | 24 | dword title; |
8451 | leency | 25 | dword cur_line_h; |
8439 | leency | 26 | void reset(); |
5746 | leency | 27 | }; |
28 | |||
8439 | leency | 29 | void STYLE::reset() |
30 | { |
||
31 | b = u = s = h = blq = pre = title = false; |
||
32 | font = false; |
||
8451 | leency | 33 | cur_line_h = NULL; |
8439 | leency | 34 | tag_list.reset(); |
35 | } |
||
36 | |||
4411 | leency | 37 | struct TWebBrowser { |
4540 | leency | 38 | llist list; |
8439 | leency | 39 | STYLE style; |
8462 | leency | 40 | dword draw_y, draw_x, draw_w, left_gap; |
7752 | leency | 41 | dword o_bufpointer; |
7759 | leency | 42 | int cur_encoding, custom_encoding; |
43 | bool link, t_html, t_body; |
||
44 | dword bufpointer; |
||
45 | dword bufsize; |
||
7945 | leency | 46 | dword is_html; |
8396 | leency | 47 | collection img_url; |
8439 | leency | 48 | char header[150]; |
8492 | leency | 49 | char linebuf[500]; |
8439 | leency | 50 | char redirect[URL_SIZE]; |
7759 | leency | 51 | |
8462 | leency | 52 | void SetStyle(); |
8491 | leency | 53 | void RenderTextbuf(); |
54 | void RenderLine(); |
||
8462 | leency | 55 | bool RenderImage(); |
56 | |||
7746 | leency | 57 | void SetPageDefaults(); |
7752 | leency | 58 | void ParseHtml(); |
8500 | leency | 59 | void Reparse(); |
7762 | leency | 60 | void NewLine(); |
61 | void ChangeEncoding(); |
||
8491 | leency | 62 | void AddCharToTheLine(); |
4411 | leency | 63 | void DrawPage(); |
8439 | leency | 64 | |
65 | void tag_a(); |
||
66 | void tag_p(); |
||
67 | void tag_img(); |
||
68 | void tag_div(); |
||
69 | void tag_h1234_caption(); |
||
70 | void tag_ol_ul_dt(); |
||
71 | void tag_li(); |
||
72 | void tag_q(); |
||
73 | void tag_hr(); |
||
74 | void tag_code(); |
||
75 | void tag_meta_xml(); |
||
76 | void tag_body(); |
||
77 | void tag_iframe(); |
||
78 | void tag_title(); |
||
79 | void tag_font(); |
||
8492 | leency | 80 | void tag_table_reset(); |
8462 | leency | 81 | void tag_table(); |
82 | void tag_td(); |
||
83 | void tag_tr(); |
||
7759 | leency | 84 | }; |
4486 | leency | 85 | |
8462 | leency | 86 | #include "TWB\render.h" |
8439 | leency | 87 | #include "TWB\set_style.h" |
5747 | leency | 88 | //============================================================================================ |
7746 | leency | 89 | void TWebBrowser::SetPageDefaults() |
90 | { |
||
8439 | leency | 91 | t_html = t_body = link = false; |
92 | style.reset(); |
||
7759 | leency | 93 | link_color_default = 0x0000FF; |
4491 | leency | 94 | link_color_active = 0xFF0000; |
8454 | leency | 95 | style.cur_line_h = list.item_h; |
7970 | leency | 96 | links.clear(); |
7752 | leency | 97 | anchors.clear(); |
8396 | leency | 98 | img_url.drop(); |
8016 | leency | 99 | text_colors.drop(); |
100 | text_colors.add(0); |
||
8451 | leency | 101 | bg_colors.drop(); |
102 | bg_colors.add(DEFAULT_BG_COL); |
||
103 | canvas.Fill(0, DEFAULT_BG_COL); |
||
7758 | leency | 104 | header = NULL; |
7759 | leency | 105 | draw_y = BODY_MARGIN; |
8462 | leency | 106 | draw_x = left_gap = BODY_MARGIN; |
107 | draw_w = list.w - BODY_MARGIN; |
||
8492 | leency | 108 | linebuf = 0; |
8302 | leency | 109 | redirect = '\0'; |
8490 | leency | 110 | list.SetFont(8, 14, 10011000b); |
8492 | leency | 111 | tag_table_reset(); |
7746 | leency | 112 | } |
113 | //============================================================================================ |
||
8500 | leency | 114 | void TWebBrowser::Reparse() |
115 | { |
||
116 | ParseHtml(bufpointer, bufsize); |
||
117 | } |
||
118 | //============================================================================================ |
||
7759 | leency | 119 | void TWebBrowser::ParseHtml(dword _bufpointer, _bufsize){ |
7752 | leency | 120 | int tab_len; |
7746 | leency | 121 | dword bufpos; |
7759 | leency | 122 | bufsize = _bufsize; |
8439 | leency | 123 | |
8457 | leency | 124 | if (list.w!=canvas.bufw) canvas.Init(list.x, list.y, list.w, 400*20); |
125 | |||
8492 | leency | 126 | if (bufpointer == _bufpointer) { |
127 | custom_encoding = cur_encoding; |
||
128 | } else { |
||
7771 | leency | 129 | bufpointer = malloc(bufsize); |
130 | memmov(bufpointer, _bufpointer, bufsize); |
||
8492 | leency | 131 | |
132 | //hold original buffer |
||
133 | o_bufpointer = malloc(bufsize); |
||
134 | memmov(o_bufpointer, bufpointer, bufsize); |
||
135 | |||
136 | cur_encoding = CH_CP866; |
||
137 | if (custom_encoding != -1) { |
||
138 | cur_encoding = custom_encoding; |
||
139 | bufpointer = ChangeCharset(cur_encoding, "CP866", bufpointer); |
||
140 | bufsize = strlen(bufpointer); |
||
141 | } |
||
7771 | leency | 142 | } |
8492 | leency | 143 | |
144 | |||
7746 | leency | 145 | SetPageDefaults(); |
7945 | leency | 146 | is_html = true; |
147 | if (!strstri(bufpointer, " |
||
7749 | leency | 148 | t_body = true; |
7991 | leency | 149 | if (!strstri(bufpointer, " |
7945 | leency | 150 | style.pre = true; //show linebreaks for a plaint text |
151 | is_html = false; |
||
152 | } |
||
7749 | leency | 153 | } |
5773 | leency | 154 | for (bufpos=bufpointer ; (bufpos < bufpointer+bufsize) && (ESBYTE[bufpos]!=0) ; bufpos++;) |
4411 | leency | 155 | { |
8330 | leency | 156 | switch (ESBYTE[bufpos]) |
4411 | leency | 157 | { |
158 | case 0x0a: |
||
7752 | leency | 159 | if (style.pre) { |
8491 | leency | 160 | RenderTextbuf(); |
5781 | leency | 161 | NewLine(); |
7752 | leency | 162 | } else { |
8491 | leency | 163 | goto _DEFAULT; |
4411 | leency | 164 | } |
7752 | leency | 165 | break; |
166 | case 0x09: |
||
167 | if (style.pre) { |
||
8492 | leency | 168 | tab_len = draw_x - left_gap / list.font_w + strlen(#linebuf) % 4; |
7752 | leency | 169 | if (!tab_len) tab_len = 4; else tab_len = 4 - tab_len; |
8492 | leency | 170 | while (tab_len) {chrcat(#linebuf,' '); tab_len--;} |
7752 | leency | 171 | } else { |
8491 | leency | 172 | goto _DEFAULT; |
4411 | leency | 173 | } |
7752 | leency | 174 | break; |
4411 | leency | 175 | case '&': // and so on |
8492 | leency | 176 | bufpos = GetUnicodeSymbol(#linebuf, sizeof(TWebBrowser.linebuf), bufpos+1, bufpointer+bufsize); |
4411 | leency | 177 | break; |
178 | case '<': |
||
8330 | leency | 179 | if (!is_html) goto _DEFAULT; |
8490 | leency | 180 | if (!strchr("!/?abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ", ESBYTE[bufpos+1])) goto _DEFAULT; |
5749 | leency | 181 | bufpos++; |
8440 | leency | 182 | if (tag.parse(#bufpos, bufpointer + bufsize)) { |
8491 | leency | 183 | RenderTextbuf(); |
8439 | leency | 184 | $push cur_encoding |
185 | SetStyle(); |
||
186 | $pop eax |
||
187 | // The thing is that UTF if longer than other encodings. |
||
188 | // So if encoding was changed from UTF to DOS than $bufpos position got wrong, |
||
189 | // and we have to start parse from the very beginning |
||
190 | if (EAX != cur_encoding) && (cur_encoding == CH_UTF8) { |
||
8492 | leency | 191 | ParseHtml(bufpointer, strlen(bufpointer)); |
8439 | leency | 192 | return; |
8407 | leency | 193 | } |
7746 | leency | 194 | } |
4411 | leency | 195 | break; |
196 | default: |
||
8330 | leency | 197 | _DEFAULT: |
7752 | leency | 198 | AddCharToTheLine(ESBYTE[bufpos]); |
4411 | leency | 199 | } |
200 | } |
||
8491 | leency | 201 | RenderTextbuf(); |
202 | list.count = draw_y + style.cur_line_h; |
||
8425 | leency | 203 | |
8491 | leency | 204 | canvas.bufh = math.max(list.visible, list.count); |
8439 | leency | 205 | buf_data = realloc(buf_data, canvas.bufh * canvas.bufw * 4 + 8); |
8425 | leency | 206 | |
7755 | leency | 207 | list.CheckDoesValuesOkey(); |
208 | anchors.current = NULL; |
||
7758 | leency | 209 | if (!header) { |
7759 | leency | 210 | strncpy(#header, #version, sizeof(TWebBrowser.header)-1); |
7758 | leency | 211 | DrawTitle(#header); |
212 | } |
||
4411 | leency | 213 | } |
5747 | leency | 214 | //============================================================================================ |
8444 | leency | 215 | void TWebBrowser::AddCharToTheLine(unsigned char _char) |
216 | { |
||
8492 | leency | 217 | dword line_len = strlen(#linebuf); |
8444 | leency | 218 | if (_char<=15) _char=' '; |
219 | if (!style.pre) && (_char == ' ') |
||
220 | { |
||
8492 | leency | 221 | if (linebuf[line_len-1]==' ') return; //no double spaces |
222 | if (draw_x==left_gap) && (!linebuf) return; //no paces at the beginning of the line |
||
8444 | leency | 223 | if (link) && (line_len==0) return; |
224 | } |
||
8499 | leency | 225 | if (line_len < sizeof(TWebBrowser.linebuf)) { |
226 | chrcat(#linebuf+line_len, _char); |
||
227 | } else { |
||
228 | RenderTextbuf(); |
||
229 | } |
||
8444 | leency | 230 | } |
231 | //============================================================================================ |
||
232 | void TWebBrowser::ChangeEncoding(int _new_encoding) |
||
233 | { |
||
234 | if (cur_encoding == _new_encoding) return; |
||
235 | cur_encoding = _new_encoding; |
||
236 | bufpointer = ChangeCharset(cur_encoding, "CP866", bufpointer); |
||
237 | if (header) { |
||
238 | ChangeCharset(cur_encoding, "CP866", #header); |
||
239 | DrawTitle(#header); |
||
240 | } |
||
241 | } |
||
242 | //============================================================================================ |
||
8491 | leency | 243 | scroll_bar scroll_wv = { 15,NULL,NULL,NULL, |
244 | 0,2,NULL,0,0,0xeeeeee,0xBBBbbb,0xeeeeee}; |
||
8439 | leency | 245 | |
5766 | leency | 246 | void TWebBrowser::DrawPage() |
247 | { |
||
8500 | leency | 248 | if (list.w!=canvas.bufw) Reparse(); |
8457 | leency | 249 | canvas.Show(list.first, list.h); |
250 | |||
8439 | leency | 251 | scroll_wv.max_area = list.count; |
252 | scroll_wv.cur_area = list.visible; |
||
253 | scroll_wv.position = list.first; |
||
254 | scroll_wv.all_redraw = 0; |
||
255 | scroll_wv.start_x = list.x + list.w; |
||
256 | scroll_wv.start_y = list.y; |
||
257 | scroll_wv.size_y = list.h; |
||
258 | |||
8490 | leency | 259 | if (list.count <= list.visible) { |
260 | DrawBar(scroll_wv.start_x, scroll_wv.start_y, scroll_wv.size_x, |
||
261 | scroll_wv.size_y, bg_colors.get(0) & 0x00FFFFFF); |
||
262 | } else { |
||
263 | scrollbar_v_draw(#scroll_wv); |
||
264 | } |
||
5766 | leency | 265 | }=>>=15)>': |