Rev 8457 | Rev 8490 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 8457 | Rev 8462 | ||
---|---|---|---|
Line 7... | Line 7... | ||
7 | dword link_color_default; |
7 | dword link_color_default; |
8 | dword link_color_active; |
8 | dword link_color_active; |
9 | #include "TWB\links.h" |
9 | #include "TWB\links.h" |
Line 10... | Line 10... | ||
10 | 10 | ||
- | 11 | #define BODY_MARGIN 6 |
|
11 | #define BODY_MARGIN 6 |
12 | #define BASIC_CHAR_W 8 |
Line 12... | Line -... | ||
12 | #define BASIC_LINE_H 18 |
- | |
13 | 13 | #define BASIC_LINE_H 18 |
|
Line 14... | Line 14... | ||
14 | CANVAS canvas; |
14 | |
15 | char line[500]; |
15 | char line[500]; |
16 | 16 | ||
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, draw_x; |
42 | dword draw_y, draw_x, draw_w, left_gap; |
43 | dword o_bufpointer; |
43 | dword o_bufpointer; |
44 | int cur_encoding, custom_encoding; |
44 | int cur_encoding, custom_encoding; |
45 | bool link, t_html, t_body; |
45 | bool link, t_html, t_body; |
46 | dword bufpointer; |
46 | dword bufpointer; |
47 | dword bufsize; |
47 | dword bufsize; |
48 | dword is_html; |
48 | dword is_html; |
49 | collection img_url; |
49 | collection img_url; |
50 | char header[150]; |
50 | char header[150]; |
Line -... | Line 51... | ||
- | 51 | char redirect[URL_SIZE]; |
|
51 | char redirect[URL_SIZE]; |
52 | |
- | 53 | void SetStyle(); |
|
- | 54 | void Render(); |
|
52 | 55 | bool RenderImage(); |
|
53 | void Paint(); |
56 | |
54 | void SetPageDefaults(); |
57 | void SetPageDefaults(); |
55 | void AddCharToTheLine(); |
- | |
56 | void ParseHtml(); |
58 | void AddCharToTheLine(); |
57 | void SetStyle(); |
59 | void ParseHtml(); |
58 | bool CheckForLineBreak(); |
60 | bool CheckForLineBreak(); |
59 | void NewLine(); |
61 | void NewLine(); |
Line 73... | Line 75... | ||
73 | void tag_meta_xml(); |
75 | void tag_meta_xml(); |
74 | void tag_body(); |
76 | void tag_body(); |
75 | void tag_iframe(); |
77 | void tag_iframe(); |
76 | void tag_title(); |
78 | void tag_title(); |
77 | void tag_font(); |
79 | void tag_font(); |
- | 80 | void tag_table(); |
|
- | 81 | void tag_td(); |
|
- | 82 | void tag_tr(); |
|
78 | }; |
83 | }; |
Line -... | Line 84... | ||
- | 84 | ||
79 | 85 | #include "TWB\render.h" |
|
80 | #include "TWB\set_style.h" |
- | |
81 | - | ||
82 | //============================================================================================ |
- | |
83 | void TWebBrowser::Paint() |
- | |
84 | { |
- | |
85 | unsigned px; //paint x coordinate |
- | |
86 | unsigned pw; //paint y coordinate |
- | |
87 | dword pc; //paint color |
- | |
88 | int zoom; |
- | |
89 | - | ||
90 | if (style.title) |
- | |
91 | { |
- | |
92 | strncpy(#header, #line, sizeof(TWebBrowser.header)-1); |
- | |
93 | strncat(#header, " - ", sizeof(TWebBrowser.header)-1); |
- | |
94 | strncat(#header, #version, sizeof(TWebBrowser.header)-1); |
- | |
95 | line = 0; |
- | |
96 | return; |
- | |
97 | } |
- | |
98 | if (t_html) && (!t_body) { |
- | |
99 | line = 0; |
- | |
100 | return; |
- | |
101 | } |
- | |
102 | - | ||
103 | if (line) |
- | |
104 | { |
- | |
105 | pw = strlen(#line) * list.font_w; |
- | |
106 | zoom = list.font_w / BASIC_CHAR_W; |
- | |
107 | - | ||
108 | style.cur_line_h = math.max(style.cur_line_h, list.item_h); |
- | |
109 | - | ||
110 | if (bg_colors.get_last() - bg_colors.get(0)) { |
- | |
111 | canvas.DrawBar(draw_x, draw_y, pw, list.item_h, bg_colors.get_last()); |
- | |
112 | } |
- | |
113 | - | ||
114 | if (style.image) { |
- | |
115 | canvas.DrawBar(draw_x, draw_y, pw, list.item_h-1, 0xF9DBCB); |
- | |
116 | } |
- | |
117 | if (style.button) { |
- | |
118 | canvas.DrawBar(draw_x, draw_y, pw, list.item_h - calc(zoom*2), 0xCCCccc); |
- | |
119 | canvas.DrawBar(draw_x, draw_y + list.item_h - calc(zoom*2), pw, zoom, 0x999999); |
- | |
120 | } |
- | |
121 | - | ||
122 | pc = text_colors.get_last(); |
- | |
123 | if (link) && (pc == text_colors.get(0)) pc = link_color_default; |
- | |
124 | - | ||
125 | canvas.WriteText(draw_x, 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); |
- | |
127 | if (style.s) canvas.DrawBar(draw_x, list.item_h / 2 - 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 (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 | links.add_text(draw_x, draw_y + list.y, pw, list.item_h - calc(zoom*2)-1, zoom); |
- | |
133 | } |
- | |
134 | } |
- | |
135 | draw_x += pw; |
- | |
136 | if (debug_mode) debugln(#line); |
- | |
137 | line = NULL; |
- | |
138 | } |
- | |
139 | } |
86 | #include "TWB\set_style.h" |
140 | //============================================================================================ |
87 | //============================================================================================ |
141 | void TWebBrowser::SetPageDefaults() |
88 | void TWebBrowser::SetPageDefaults() |
142 | { |
89 | { |
143 | t_html = t_body = link = false; |
90 | t_html = t_body = link = false; |
Line 154... | Line 101... | ||
154 | bg_colors.add(DEFAULT_BG_COL); |
101 | bg_colors.add(DEFAULT_BG_COL); |
155 | canvas.Fill(0, DEFAULT_BG_COL); |
102 | canvas.Fill(0, DEFAULT_BG_COL); |
156 | header = NULL; |
103 | header = NULL; |
157 | cur_encoding = CH_CP866; |
104 | cur_encoding = CH_CP866; |
158 | draw_y = BODY_MARGIN; |
105 | draw_y = BODY_MARGIN; |
- | 106 | draw_x = left_gap = BODY_MARGIN; |
|
159 | draw_x = BODY_MARGIN; |
107 | draw_w = list.w - BODY_MARGIN; |
160 | line = 0; |
108 | line = 0; |
161 | redirect = '\0'; |
109 | redirect = '\0'; |
162 | //hold original buffer |
110 | //hold original buffer |
163 | if (o_bufpointer) o_bufpointer=free(o_bufpointer); |
111 | if (o_bufpointer) o_bufpointer=free(o_bufpointer); |
164 | o_bufpointer = malloc(bufsize); |
112 | o_bufpointer = malloc(bufsize); |
Line 197... | Line 145... | ||
197 | { |
145 | { |
198 | switch (ESBYTE[bufpos]) |
146 | switch (ESBYTE[bufpos]) |
199 | { |
147 | { |
200 | case 0x0a: |
148 | case 0x0a: |
201 | if (style.pre) { |
149 | if (style.pre) { |
202 | Paint(); |
150 | Render(); |
203 | NewLine(); |
151 | NewLine(); |
204 | } else { |
152 | } else { |
205 | AddCharToTheLine(0x0a); |
153 | AddCharToTheLine(0x0a); |
206 | } |
154 | } |
207 | break; |
155 | break; |
208 | case 0x09: |
156 | case 0x09: |
209 | if (style.pre) { |
157 | if (style.pre) { |
210 | tab_len = draw_x - BODY_MARGIN / list.font_w + strlen(#line) % 4; |
158 | tab_len = draw_x - left_gap / list.font_w + strlen(#line) % 4; |
211 | if (!tab_len) tab_len = 4; else tab_len = 4 - tab_len; |
159 | if (!tab_len) tab_len = 4; else tab_len = 4 - tab_len; |
212 | for (j=0; j |
160 | for (j=0; j |
213 | } else { |
161 | } else { |
214 | AddCharToTheLine(0x09); |
162 | AddCharToTheLine(0x09); |
215 | } |
163 | } |
Line 237... | Line 185... | ||
237 | goto _DEFAULT; |
185 | goto _DEFAULT; |
238 | } |
186 | } |
239 | _TAG: |
187 | _TAG: |
240 | if (tag.parse(#bufpos, bufpointer + bufsize)) { |
188 | if (tag.parse(#bufpos, bufpointer + bufsize)) { |
241 | CheckForLineBreak(); |
189 | CheckForLineBreak(); |
242 | Paint(); |
190 | Render(); |
243 | $push cur_encoding |
191 | $push cur_encoding |
244 | SetStyle(); |
192 | SetStyle(); |
245 | $pop eax |
193 | $pop eax |
246 | // The thing is that UTF if longer than other encodings. |
194 | // The thing is that UTF if longer than other encodings. |
247 | // So if encoding was changed from UTF to DOS than $bufpos position got wrong, |
195 | // So if encoding was changed from UTF to DOS than $bufpos position got wrong, |
Line 255... | Line 203... | ||
255 | default: |
203 | default: |
256 | _DEFAULT: |
204 | _DEFAULT: |
257 | AddCharToTheLine(ESBYTE[bufpos]); |
205 | AddCharToTheLine(ESBYTE[bufpos]); |
258 | } |
206 | } |
259 | } |
207 | } |
260 | Paint(); |
208 | Render(); |
261 | NewLine(); |
209 | NewLine(); |
262 | list.count = draw_y; |
210 | list.count = draw_y; |
Line 263... | Line 211... | ||
263 | 211 | ||
264 | canvas.bufh = math.max(list.visible, draw_y); |
212 | canvas.bufh = math.max(list.visible, draw_y); |
Line 279... | Line 227... | ||
279 | if (_char<=15) _char=' '; |
227 | if (_char<=15) _char=' '; |
280 | line_len = strlen(#line); |
228 | line_len = strlen(#line); |
281 | if (!style.pre) && (_char == ' ') |
229 | if (!style.pre) && (_char == ' ') |
282 | { |
230 | { |
283 | if (line[line_len-1]==' ') return; //no double spaces |
231 | if (line[line_len-1]==' ') return; //no double spaces |
284 | if (draw_x==BODY_MARGIN) && (!line) return; //no paces at the beginning of the line |
232 | if (draw_x==left_gap) && (!line) return; //no paces at the beginning of the line |
285 | if (link) && (line_len==0) return; |
233 | if (link) && (line_len==0) return; |
286 | } |
234 | } |
287 | if (line_len < sizeof(line)) chrcat(#line, _char); |
235 | if (line_len < sizeof(line)) chrcat(#line, _char); |
288 | CheckForLineBreak(); |
236 | CheckForLineBreak(); |
289 | } |
237 | } |
Line 292... | Line 240... | ||
292 | { |
240 | { |
293 | int break_pos; |
241 | int break_pos; |
294 | char next_line[4096]; |
242 | char next_line[4096]; |
295 | int zoom = list.font_w / BASIC_CHAR_W; |
243 | int zoom = list.font_w / BASIC_CHAR_W; |
296 | //Do we need a line break? |
244 | //Do we need a line break? |
297 | if (strlen(#line) * list.font_w + draw_x < list.w) return false; |
245 | if (strlen(#line) * list.font_w + draw_x < draw_w) return false; |
298 | //Yes, we do. Lets calculate where... |
246 | //Yes, we do. Lets calculate where... |
299 | break_pos = strrchr(#line, ' '); |
247 | break_pos = strrchr(#line, ' '); |
Line 300... | Line 248... | ||
300 | 248 | ||
301 | //Is a new line fits in the current line? |
249 | //Is a new line fits in the current line? |
302 | if (break_pos * list.font_w + draw_x > list.w) { |
250 | if (break_pos * list.font_w + draw_x > draw_w) { |
303 | break_pos = list.w - draw_x /list.font_w; |
251 | break_pos = draw_w - draw_x /list.font_w; |
304 | while(break_pos) && (line[break_pos]!=' ') break_pos--; |
252 | while(break_pos) && (line[break_pos]!=' ') break_pos--; |
305 | } |
253 | } |
306 | //Maybe a new line is too big for the whole new line? Then we have to split it |
254 | //Maybe a new line is too big for the whole new line? Then we have to split it |
307 | if (!break_pos) && (style.tag_list.level*5 + strlen(#line) * zoom >= list.column_max) { |
255 | if (!break_pos) && (style.tag_list.level*5 + strlen(#line) * zoom >= list.column_max) { |
308 | break_pos = list.w - draw_x / list.font_w; |
256 | break_pos = draw_w - draw_x / list.font_w; |
Line 309... | Line 257... | ||
309 | } |
257 | } |
310 | 258 | ||
Line 311... | Line 259... | ||
311 | strcpy(#next_line, #line + break_pos); |
259 | strcpy(#next_line, #line + break_pos); |
Line 312... | Line 260... | ||
312 | line[break_pos] = 0x00; |
260 | line[break_pos] = 0x00; |
313 | 261 | ||
314 | Paint(); |
262 | Render(); |
315 | 263 | ||
316 | strcpy(#line, #next_line); |
264 | strcpy(#line, #next_line); |
317 | NewLine(); |
265 | NewLine(); |
318 | return true; |
266 | return true; |
319 | } |
267 | } |
Line 320... | Line 268... | ||
320 | //============================================================================================ |
268 | //============================================================================================ |
321 | void TWebBrowser::NewLine() |
269 | void TWebBrowser::NewLine() |
Line 322... | Line 270... | ||
322 | { |
270 | { |
323 | static bool empty_line = true; |
271 | static bool empty_line = true; |
324 | 272 | ||
325 | if (draw_x==BODY_MARGIN) && (draw_y==BODY_MARGIN) return; |
273 | if (draw_x==left_gap) && (draw_y==BODY_MARGIN) return; |
326 | if (t_html) && (!t_body) return; |
274 | if (t_html) && (!t_body) return; |
Line 327... | Line 275... | ||
327 | 275 | ||
328 | if (draw_x == style.tag_list.level * 5 * list.font_w + BODY_MARGIN) { |
276 | if (draw_x == style.tag_list.level * 5 * list.font_w + left_gap) { |
329 | if (!empty_line) empty_line=true; else return; |
277 | if (!empty_line) empty_line=true; else return; |
330 | } else { |
278 | } else { |
331 | empty_line = false; |
279 | empty_line = false; |
332 | } |
280 | } |
333 | 281 | ||
334 | draw_y += style.cur_line_h; |
282 | draw_y += style.cur_line_h; |
335 | style.cur_line_h = list.item_h; |
283 | style.cur_line_h = list.item_h; |