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