Rev 4486 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
4475 | leency | 1 | #include "..\lib\draw_buf.h" |
4488 | leency | 2 | #include "..\lib\list_box.h" |
4411 | leency | 3 | |
4488 | leency | 4 | |
4411 | leency | 5 | int downloader_id; |
6 | |||
4417 | leency | 7 | dword buf; |
8 | dword filesize; |
||
9 | dword blink; |
||
4411 | leency | 10 | |
4416 | leency | 11 | #define URL param |
12 | |||
13 | int mouse_twb; |
||
14 | edit_box address_box= {250,207,16,0xffffff,0x94AECE,0xffffff,0xffffff,0,sizeof(URL),#editURL,#mouse_twb,2,19,19}; |
||
15 | scroll_bar scroll_wv = { 18,200,398, 44,18,0,115,15,0,0xeeeeee,0xD2CED0,0x555555,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1}; |
||
16 | |||
4417 | leency | 17 | char editURL[sizeof(URL)]; |
18 | char header[2048]; |
||
4416 | leency | 19 | |
20 | |||
4411 | leency | 21 | char download_path[]="/rd/1/.download"; |
22 | |||
23 | struct TWebBrowser { |
||
4415 | leency | 24 | llist list; //need #include "..\lib\list_box.h" |
4475 | leency | 25 | DrawBufer DrawBuf; |
4411 | leency | 26 | void GetNewUrl(); |
4475 | leency | 27 | void ReadHtml(); |
4411 | leency | 28 | void ShowPage(); |
4475 | leency | 29 | void ParseHTML(); |
30 | void WhatTextStyle(); |
||
4411 | leency | 31 | void DrawPage(); |
32 | void DrawScroller(); |
||
4475 | leency | 33 | void TextGoDown(); |
4486 | leency | 34 | }; |
35 | |||
4411 | leency | 36 | TWebBrowser WB1; |
37 | |||
4417 | leency | 38 | byte rez, b_text, i_text, u_text, s_text, pre_text, blq_text, li_text, li_tab, |
39 | link, ignor_text, cur_encoding, text_align; |
||
40 | byte condition_text_active, condition_text_val, condition_href, condition_max; |
||
4411 | leency | 41 | |
4488 | leency | 42 | enum { _WIN, _DOS, _KOI, _UTF }; |
4475 | leency | 43 | |
4411 | leency | 44 | enum { ALIGN_LEFT, ALIGN_CENTER, ALIGN_RIGHT}; |
45 | |||
4417 | leency | 46 | dword text_colors[300]; |
47 | dword text_color_index; |
||
48 | dword link_color; |
||
49 | dword bg_color; |
||
4411 | leency | 50 | |
4417 | leency | 51 | int stroka; |
52 | int stolbec; |
||
53 | int tab_len; |
||
54 | int anchor_line_num; |
||
4411 | leency | 55 | |
4417 | leency | 56 | char line[500]; |
57 | char tag[100]; |
||
58 | char tagparam[10000]; |
||
59 | char parametr[1200]; |
||
60 | char options[4096]; |
||
61 | char anchor[256]; |
||
4411 | leency | 62 | |
4416 | leency | 63 | #include "..\TWB\history.h" |
4411 | leency | 64 | #include "..\TWB\colors.h" |
65 | #include "..\TWB\unicode_tags.h" |
||
66 | #include "..\TWB\img_cache.h" |
||
67 | #include "..\TWB\parce_tag.h" |
||
4488 | leency | 68 | #include "..\TWB\links.h" |
4411 | leency | 69 | |
4475 | leency | 70 | |
71 | |||
4411 | leency | 72 | //======================================================================= |
73 | |||
74 | |||
75 | void TWebBrowser::DrawPage() |
||
76 | { |
||
77 | int start_x, start_y, line_length, magrin_left=5; |
||
78 | |||
79 | if (!header) |
||
80 | { |
||
81 | strcpy(#header, #line); |
||
82 | strcat(#header, " -"); |
||
83 | strcat(#header, #version); |
||
84 | line = 0; |
||
85 | return; |
||
86 | } |
||
87 | |||
4415 | leency | 88 | if (stroka >= 0) && (stroka - 2 < list.visible) && (line) && (!anchor) |
4411 | leency | 89 | { |
4414 | leency | 90 | start_x = stolbec * 6 + list.x + magrin_left; |
91 | start_y = stroka * 10 + list.y + magrin_left; |
||
4411 | leency | 92 | line_length = strlen(#line) * 6; |
93 | |||
4475 | leency | 94 | WriteBufText(start_x, 0, 0x88, text_colors[text_color_index], #line, buf_data); |
95 | IF (b_text) WriteBufText(start_x+1, 0, 0x88, text_colors[text_color_index], #line, buf_data); |
||
96 | IF (i_text) { stolbec++; DrawBuf.Skew(start_x, 0, line_length, list.line_h); } |
||
97 | IF (s_text) DrawBuf.DrawBar(start_x, 4, line_length, 1, text_colors[text_color_index]); |
||
98 | IF (u_text) DrawBuf.DrawBar(start_x, 8, line_length, 1, text_colors[text_color_index]); |
||
4411 | leency | 99 | IF (link) { |
100 | UnsafeDefineButton(start_x-2, start_y, line_length + 3, 9, blink + BT_HIDE, 0xB5BFC9); |
||
4475 | leency | 101 | DrawBuf.DrawBar(start_x, 8, line_length, 1, text_colors[text_color_index]); |
4411 | leency | 102 | } |
103 | stolbec += strlen(#line); |
||
104 | } |
||
105 | } |
||
106 | //======================================================================= |
||
107 | |||
108 | |||
109 | |||
110 | char *ABSOLUTE_LINKS[]={ "http:", "mailto:", "ftp:", "/sys/", "/kolibrios/", "/rd/", "/bd", "/hd", "/cd", "/tmp", "/usbhd", 0}; |
||
111 | //dword TWebBrowser::GetNewUrl(dword CUR_URL, NEW_URL){ |
||
112 | void TWebBrowser::GetNewUrl(){ |
||
113 | int i, len; |
||
114 | |||
115 | for (i=0; ABSOLUTE_LINKS[i]; i++) |
||
116 | { |
||
117 | len=strlen(ABSOLUTE_LINKS[i]); |
||
118 | if (!strcmpn(#URL, ABSOLUTE_LINKS[i], len)) return; |
||
119 | } |
||
120 | |||
121 | IF (!strcmpn(#URL,"./", 2)) strcpy(#URL, #URL+2); //игнорим :) |
||
122 | strcpy(#editURL, BrowserHistory.CurrentUrl()); //достаём адрес текущей страницы |
||
123 | |||
124 | if (URL[0] == '/') |
||
125 | { |
||
126 | i = strchr(#editURL+8, '/'); |
||
127 | editURL[i+7]=0; |
||
128 | strcpy(#URL, #URL+1); |
||
129 | } |
||
130 | |||
131 | _CUT_ST_LEVEL_MARK: |
||
132 | |||
133 | if (editURL[strrchr(#editURL, '/')-2]<>'/') // если не http:// |
||
134 | { |
||
135 | editURL[strrchr(#editURL, '/')] = 0x00; //обрезаем её урл до последнего / |
||
136 | } |
||
137 | |||
4488 | leency | 138 | IF (!strncmp(#URL,"../",3)) //на уровень вверх |
4411 | leency | 139 | { |
140 | strcpy(#URL,#URL+3); |
||
141 | editURL[strrchr(#editURL, '/')-1] = 0x00; //обрезаем её урл до последнего / |
||
142 | goto _CUT_ST_LEVEL_MARK; |
||
143 | } |
||
144 | |||
145 | if (editURL[strlen(#editURL)-1]<>'/') strcat(#editURL, "/"); |
||
146 | |||
147 | strcat(#editURL, #URL); //клеим новый адрес |
||
148 | strcpy(#URL, #editURL); |
||
149 | } |
||
150 | |||
151 | |||
152 | |||
153 | void TWebBrowser::ReadHtml(byte encoding) |
||
154 | { |
||
4488 | leency | 155 | if (!strncmp(#URL,"http:",5)) |
4411 | leency | 156 | file_size stdcall (#download_path); |
157 | else |
||
158 | file_size stdcall (#URL); |
||
159 | |||
160 | filesize = EBX; |
||
161 | if (!filesize) return; |
||
162 | |||
163 | mem_Free(buf); |
||
164 | buf = mem_Alloc(filesize); |
||
4488 | leency | 165 | if (!strncmp(#URL,"http:",5)) |
4411 | leency | 166 | ReadFile(0, filesize, buf, #download_path); |
167 | else |
||
168 | ReadFile(0, filesize, buf, #URL); |
||
169 | |||
170 | cur_encoding = encoding; |
||
171 | if (encoding==_WIN) wintodos(buf); |
||
172 | if (encoding==_UTF) utf8rutodos(buf); |
||
173 | if (encoding==_KOI) koitodos(buf); |
||
174 | } |
||
175 | |||
176 | |||
177 | void TWebBrowser::ShowPage() |
||
178 | { |
||
179 | address_box.size = address_box.pos = strlen(#editURL); |
||
180 | address_box.offset=0; |
||
181 | edit_box_draw stdcall(#address_box); |
||
182 | |||
183 | if (!filesize) |
||
184 | { |
||
4416 | leency | 185 | DrawBar(list.x, list.y, list.w+scroll_wv.size_x+1, list.h, 0xFFFFFF); //fill all |
4414 | leency | 186 | if (GetProcessSlot(downloader_id)<>0) WriteText(list.x + 10, list.y + 18, 0x80, 0, "Loading..."); |
4411 | leency | 187 | else |
188 | { |
||
4414 | leency | 189 | WriteText(list.x + 10, list.y + 18, 0x80, 0, "Page not found. May be, URL contains some errors."); |
4488 | leency | 190 | if (!strncmp(#URL,"http:",5)) WriteText(list.x + 10, list.y + 32, 0x80, 0, "Or Internet unavilable for your configuration."); |
4411 | leency | 191 | } |
192 | //return; |
||
193 | } |
||
194 | else |
||
195 | ParseHTML(buf); |
||
196 | |||
197 | if (!header) strcpy(#header, #version); |
||
198 | if (!strcmp(#version, #header)) DrawTitle(#header); |
||
199 | } |
||
200 | |||
201 | |||
202 | |||
203 | void TWebBrowser::ParseHTML(dword bword){ |
||
204 | word bukva[2]; |
||
205 | int j, perenos_num; |
||
206 | byte ignor_param; |
||
207 | char temp[768]; |
||
208 | |||
209 | if (blink<400) blink=400; else for ( ; blink>400; blink--;) DeleteButton(blink); |
||
210 | b_text = i_text = u_text = s_text = blq_text = |
||
4417 | leency | 211 | li_text = link = ignor_text = text_color_index = text_colors[0] = li_tab = |
212 | condition_text_val = condition_text_active = 0; //обнуляем теги |
||
4475 | leency | 213 | condition_max = 255; |
4411 | leency | 214 | text_align = ALIGN_LEFT; |
215 | link_color = 0x0000FF; |
||
216 | bg_color = 0xFFFFFF; |
||
4475 | leency | 217 | DrawBuf.Fill(bg_color); |
4488 | leency | 218 | PageLinks.Clear(); |
4411 | leency | 219 | strcpy(#header, #version); |
4415 | leency | 220 | stroka = -list.first; |
4411 | leency | 221 | stolbec = 0; |
222 | line = 0; |
||
223 | |||
224 | if (pre_text<>2) |
||
225 | { |
||
226 | pre_text=0; |
||
227 | if (!strcmp(#URL + strlen(#URL) - 4, ".txt")) pre_text = 1; |
||
228 | if (!strcmp(#URL + strlen(#URL) - 4, ".mht")) ignor_text = 1; |
||
229 | } |
||
230 | |||
231 | for ( ; buf+filesize > bword; bword++;) |
||
232 | { |
||
233 | bukva = ESBYTE[bword]; |
||
4417 | leency | 234 | if (ignor_text) && (bukva!='<') continue; |
235 | if (condition_text_active) && (condition_text_val != condition_href) && (bukva!='<') continue; |
||
4411 | leency | 236 | switch (bukva) |
237 | { |
||
238 | case 0x0a: |
||
239 | if (pre_text) |
||
240 | { |
||
241 | bukva = temp = NULL; |
||
242 | goto NEXT_MARK; |
||
243 | } |
||
244 | case '\9': |
||
245 | if (pre_text) //иначе идём на 0x0d |
||
246 | { |
||
247 | tab_len=strlen(#line)/8; |
||
248 | tab_len=tab_len*8; |
||
249 | tab_len=8+tab_len-strlen(#line); |
||
250 | for (j=0; j |
||
251 | break; |
||
252 | } |
||
253 | goto DEFAULT_MARK; |
||
254 | case '=': //quoted printable |
||
255 | if (strcmp(#URL + strlen(#URL) - 4, ".mht")<>0) goto DEFAULT_MARK; |
||
256 | |||
257 | temp[0] = ESBYTE[bword+1]; |
||
258 | temp[1] = ESBYTE[bword+2]; |
||
259 | temp[2] = '\0'; |
||
260 | if (bukva = Hex2Symb(#temp)) |
||
261 | { |
||
262 | bword+=2; |
||
263 | goto DEFAULT_MARK; |
||
264 | } |
||
265 | break; |
||
266 | |||
267 | case '&': // and so on |
||
268 | bword++; |
||
269 | tag=0; |
||
270 | for (j=0; (ESBYTE[bword]<>';') && (j<7); j++, bword++;) |
||
271 | { |
||
272 | bukva = ESBYTE[bword]; |
||
273 | chrcat(#tag, bukva); |
||
274 | } |
||
4417 | leency | 275 | if (bukva = GetUnicodeSymbol()) goto DEFAULT_MARK; |
4411 | leency | 276 | break; |
277 | case '<': |
||
278 | bword++; //промотаем символ < |
||
279 | tag = parametr = tagparam = ignor_param = NULL; |
||
280 | if (ESBYTE[bword] == '!') //фильтрация внутри , дерзко |
||
281 | { |
||
282 | bword++; |
||
283 | if (ESBYTE[bword] == '-') |
||
284 | { |
||
285 | HH_: |
||
286 | do |
||
287 | { |
||
288 | bword++; |
||
289 | if (buf + filesize <= bword) break 2; |
||
290 | } |
||
291 | while (ESBYTE[bword] <>'-'); |
||
292 | |||
293 | bword++; |
||
294 | if (ESBYTE[bword] <>'-') goto HH_; |
||
295 | } |
||
296 | } |
||
297 | while (ESBYTE[bword] !='>') && (bword < buf + filesize) //получаем тег и его параметры |
||
298 | { |
||
299 | bukva = ESBYTE[bword]; |
||
300 | if (bukva == '\9') || (bukva == '\x0a') || (bukva == '\x0d') bukva = ' '; |
||
301 | if (!ignor_param) && (bukva <>' ') |
||
302 | { |
||
303 | if (strlen(#tag) |
||
304 | } |
||
305 | else |
||
306 | { |
||
307 | ignor_param = true; |
||
308 | if (!ignor_text) && (strlen(#tagparam)+1 |
||
309 | } |
||
310 | bword++; |
||
311 | } |
||
312 | strlwr(#tag); |
||
313 | strlwr(#tagparam); |
||
314 | |||
4417 | leency | 315 | if (condition_text_active) && (condition_text_val != condition_href) |
316 | { |
||
317 | if (strcmp(#tag, "/condition")!=0) break; |
||
318 | } |
||
4411 | leency | 319 | if (tag[strlen(#tag)-1]=='/') tag[strlen(#tag)-1]=NULL; //for br/ |
320 | if (tagparam) && (strlen(#tagparam) < 4000) GetNextParam(); |
||
321 | |||
4415 | leency | 322 | if (stolbec + strlen(#line) > list.column_max) //============the same as NEXT_MARK |
4411 | leency | 323 | { |
324 | perenos_num = strrchr(#line, ' '); |
||
4415 | leency | 325 | if (!perenos_num) && (strlen(#line)>list.column_max) perenos_num=list.column_max; |
4411 | leency | 326 | strcpy(#temp, #line + perenos_num); //перенос по словам |
327 | line[perenos_num] = 0x00; |
||
4415 | leency | 328 | if (stroka-1 > list.visible) && (list.first <>0) break 1; //уходим... |
4411 | leency | 329 | DrawPage(); |
330 | strcpy(#line, #temp); |
||
4414 | leency | 331 | TextGoDown(list.x + 5, stroka * 10 + list.y + 5, list.w - 20); //закрашиваем следущую строку |
4411 | leency | 332 | } |
333 | DrawPage(); |
||
334 | line=NULL; |
||
335 | |||
4414 | leency | 336 | if (tag) WhatTextStyle(list.x + 5, stroka * 10 + list.y + 5, list.w - 20); //обработка тегов |
4411 | leency | 337 | |
338 | tag = parametr = tagparam = ignor_param = NULL; |
||
339 | break; |
||
340 | default: |
||
341 | DEFAULT_MARK: |
||
342 | if (bukva<=15) bukva=' '; |
||
343 | if (!pre_text) && (bukva == ' ') |
||
344 | { |
||
345 | if (line[strlen(#line)-1]==' ') break; //убрать 2 пробела подряд |
||
346 | if (!stolbec) && (!line) break; //строка не может начинаться с пробела |
||
347 | } |
||
348 | if (strlen(#line) |
||
349 | |||
4415 | leency | 350 | if (stolbec + strlen(#line) > list.column_max) |
4411 | leency | 351 | { |
352 | NEXT_MARK: |
||
353 | perenos_num = strrchr(#line, ' '); |
||
4415 | leency | 354 | if (!perenos_num) && (strlen(#line)>list.column_max) perenos_num=list.column_max; |
4411 | leency | 355 | strcpy(#temp, #line + perenos_num); //перенос по словам |
356 | line[perenos_num] = 0x00; |
||
4415 | leency | 357 | if (stroka-1 > list.visible) && (list.first <>0) break 1; //уходим... |
4411 | leency | 358 | DrawPage(); |
359 | strcpy(#line, #temp); |
||
4414 | leency | 360 | TextGoDown(list.x + 5, stroka * 10 + list.y + 5, list.w - 20); //закрашиваем следущую строку |
4411 | leency | 361 | } |
362 | } |
||
363 | } |
||
364 | |||
365 | DrawPage(); //рисует последнюю строку, потом это надо убрать, оптимизировав код |
||
4414 | leency | 366 | TextGoDown(list.x + 5, stroka * 10 + list.y + 5, list.w - 20); //закрашиваем следущую строку |
4411 | leency | 367 | |
4415 | leency | 368 | if (list.visible * 10 + 25 <= list.h) |
369 | DrawBar(list.x, list.visible * 10 + list.y + 25, list.w, -list.visible * 10 + list.h - 25, bg_color); |
||
4414 | leency | 370 | if (stroka * 10 + 5 <= list.h) |
371 | DrawBar(list.x, stroka * 10 + list.y + 5, list.w, -stroka * 10 + list.h - 5, bg_color); //закрашиваем всё до конца |
||
4415 | leency | 372 | if (list.first == 0) list.count = stroka; |
4411 | leency | 373 | if (anchor) //если посреди текста появится новый якорь - будет бесконечный цикл |
374 | { |
||
375 | anchor=NULL; |
||
4415 | leency | 376 | list.first=anchor_line_num; |
4411 | leency | 377 | ParseHTML(buf); |
378 | } |
||
379 | DrawScroller(); |
||
380 | } |
||
381 | |||
382 | |||
383 | |||
384 | char oldtag[100]; |
||
385 | void TWebBrowser::WhatTextStyle(int left1, top1, width1) { |
||
386 | dword hr_color; |
||
387 | |||
388 | //проверяем тег открывается или закрывается |
||
389 | if (tag[0] == '/') |
||
390 | { |
||
391 | rez = 0; |
||
392 | strcpy(#tag, #tag+1); |
||
393 | } |
||
394 | else rez = 1; |
||
395 | |||
4488 | leency | 396 | if (isTag("html")) |
4411 | leency | 397 | { |
398 | IF(!strcmp(#URL + strlen(#URL) - 4, ".mht")) IF (rez==0) ignor_text = 1; ELSE ignor_text = 0; |
||
399 | return; |
||
400 | } |
||
401 | |||
4488 | leency | 402 | if (isTag("script")) || (isTag("style")) || (isTag("binary")) ignor_text = rez; |
4411 | leency | 403 | |
4488 | leency | 404 | if(isTag("title")) |
4411 | leency | 405 | { |
406 | if (rez) header=NULL; |
||
407 | else if (!stroka) DrawTitle(#header); //тег закрылся - вывели строку |
||
408 | return; |
||
409 | } |
||
410 | |||
411 | if (ignor_text) return; |
||
412 | |||
413 | |||
414 | |||
4488 | leency | 415 | IF(isTag("q")) chrcat(#line, '\"'); |
4411 | leency | 416 | |
417 | if (anchor) && (!strcmp(#parametr, "id=")) //очень плохо!!! потому что если не последний тег, работать не будет |
||
418 | { |
||
4415 | leency | 419 | if (!strcmp(#anchor, #options)) anchor_line_num=list.first+stroka; |
4411 | leency | 420 | } |
421 | |||
4488 | leency | 422 | if (isTag("body")) |
4411 | leency | 423 | { |
424 | do{ |
||
4475 | leency | 425 | if (!strcmp(#parametr, "condition_max=")) { condition_max = atoi(#options); debugi(condition_max); } |
4411 | leency | 426 | if (!strcmp(#parametr, "link=")) link_color = GetColor(#options); |
427 | if (!strcmp(#parametr, "text=")) text_colors[0]=GetColor(#options); |
||
428 | if (!strcmp(#parametr, "bgcolor=")) |
||
429 | { |
||
430 | bg_color=GetColor(#options); |
||
4475 | leency | 431 | DrawBuf.Fill(bg_color); |
4411 | leency | 432 | } |
433 | } while(GetNextParam()); |
||
434 | return; |
||
435 | } |
||
436 | |||
4488 | leency | 437 | if (isTag("a")) |
4411 | leency | 438 | { |
439 | if (rez) |
||
440 | { |
||
441 | if (link) IF(text_color_index > 0) text_color_index--; //если предыдущий тег а не был закрыт |
||
442 | |||
443 | do{ |
||
444 | if (!strcmp(#parametr, "href=")) |
||
445 | { |
||
4415 | leency | 446 | if (stroka - 1 > list.visible) || (stroka < -2) return; |
4411 | leency | 447 | |
448 | text_color_index++; |
||
449 | text_colors[text_color_index] = text_colors[text_color_index-1]; |
||
450 | |||
451 | link = 1; |
||
452 | blink++; |
||
453 | text_colors[text_color_index] = link_color; |
||
4488 | leency | 454 | PageLinks.Add(#options); |
4411 | leency | 455 | } |
456 | if (anchor) && (!strcmp(#parametr, "name=")) |
||
457 | { |
||
458 | if (!strcmp(#anchor, #options)) |
||
459 | { |
||
4415 | leency | 460 | anchor_line_num=list.first+stroka; |
4411 | leency | 461 | } |
462 | } |
||
463 | } while(GetNextParam()); |
||
464 | } |
||
465 | else { |
||
466 | link = 0; |
||
467 | IF(text_color_index > 0) text_color_index--; |
||
468 | } |
||
469 | return; |
||
470 | } |
||
471 | |||
4488 | leency | 472 | if (isTag("font")) |
4411 | leency | 473 | { |
474 | if (rez) |
||
475 | { |
||
476 | text_color_index++; |
||
477 | text_colors[text_color_index] = text_colors[text_color_index-1]; |
||
478 | |||
479 | do{ |
||
480 | if (strcmp(#parametr, "color=") == 0) //&& (parametr[1] == '#') |
||
481 | { |
||
482 | text_colors[text_color_index] = GetColor(#options); |
||
483 | } |
||
484 | } while(GetNextParam()); |
||
485 | } |
||
486 | else |
||
487 | if (text_color_index > 0) text_color_index--; |
||
488 | return; |
||
489 | } |
||
4488 | leency | 490 | if(isTag("tr")) || (isTag("br")) { |
4411 | leency | 491 | TextGoDown(left1, top1, width1); |
492 | return; |
||
493 | } |
||
4488 | leency | 494 | if (isTag("div")) { |
4411 | leency | 495 | IF(oldtag[0] <>'h') TextGoDown(left1, top1, width1); |
496 | return; |
||
497 | } |
||
4488 | leency | 498 | if (isTag("p")) { |
4411 | leency | 499 | IF(oldtag[0] == 'h') return; |
500 | TextGoDown(left1, top1, width1); |
||
501 | IF(rez) TextGoDown(left1, top1 + 10, width1); |
||
502 | return; |
||
503 | } |
||
4475 | leency | 504 | /* |
4488 | leency | 505 | if (isTag("center")) |
4411 | leency | 506 | { |
507 | if (rez) text_align = ALIGN_CENTER; |
||
508 | if (!rez) |
||
509 | { |
||
510 | TextGoDown(left1, top1, width1); |
||
511 | text_align = ALIGN_LEFT; |
||
512 | } |
||
513 | return; |
||
514 | } |
||
4488 | leency | 515 | if (isTag("right")) |
4411 | leency | 516 | { |
517 | if (rez) text_align = ALIGN_RIGHT; |
||
518 | if (!rez) |
||
519 | { |
||
520 | TextGoDown(left1, top1, width1); |
||
521 | text_align = ALIGN_LEFT; |
||
522 | } |
||
523 | return; |
||
524 | } |
||
4475 | leency | 525 | */ |
4488 | leency | 526 | if (isTag("h1")) || (isTag("h2")) || (isTag("h3")) || (isTag("h4")) { |
4411 | leency | 527 | TextGoDown(left1, top1, width1); |
528 | if (rez) && (stroka>1) TextGoDown(left1, top1 + 10, width1); |
||
529 | strcpy(#oldtag, #tag); |
||
530 | if (rez) |
||
531 | { |
||
532 | if (!strcmp(#parametr, "align=")) && (!strcmp(#options,"center")) text_align = ALIGN_CENTER; |
||
533 | if (!strcmp(#parametr, "align=")) && (!strcmp(#options,"right")) text_align = ALIGN_RIGHT; |
||
534 | b_text = 1; |
||
535 | } |
||
536 | if (!rez) |
||
537 | { |
||
538 | text_align = ALIGN_LEFT; |
||
539 | b_text = 0; |
||
540 | } |
||
541 | return; |
||
542 | } |
||
543 | else |
||
544 | oldtag=NULL; |
||
545 | |||
4488 | leency | 546 | if (isTag("b")) || (isTag("strong")) || (isTag("big")) { |
4411 | leency | 547 | b_text = rez; |
548 | return; |
||
549 | } |
||
4488 | leency | 550 | if(isTag("i")) || (isTag("em")) || (isTag("subtitle")) { |
4411 | leency | 551 | i_text = rez; |
552 | return; |
||
553 | } |
||
4488 | leency | 554 | if (isTag("dt")) |
4411 | leency | 555 | { |
556 | li_text = rez; |
||
557 | IF(rez == 0) return; |
||
558 | TextGoDown(left1, top1, width1); |
||
559 | return; |
||
560 | } |
||
4488 | leency | 561 | if (isTag("condition")) |
4417 | leency | 562 | { |
563 | condition_text_active = rez; |
||
564 | if (rez) && (!strcmp(#parametr, "show_if=")) condition_text_val = atoi(#options); |
||
565 | return; |
||
566 | } |
||
4488 | leency | 567 | if (isTag("li")) || (isTag("dt")) //надо сделать вложенные списки |
4411 | leency | 568 | { |
569 | li_text = rez; |
||
570 | if (rez) |
||
571 | { |
||
572 | TextGoDown(left1, top1, width1); |
||
4475 | leency | 573 | if (stroka > -1) && (stroka - 2 < list.visible) DrawBuf.DrawBar(li_tab * 5 * 6 + left1 - 5, list.line_h/2-3, 2, 2, 0x555555); |
4411 | leency | 574 | } |
575 | return; |
||
576 | } |
||
4488 | leency | 577 | if (isTag("u")) || (isTag("ins")) u_text = rez; |
578 | if (isTag("s")) || (isTag("strike")) || (isTag("del")) s_text = rez; |
||
579 | if (isTag("ul")) || (isTag("ol")) IF(!rez) |
||
4411 | leency | 580 | { |
581 | li_text = rez; |
||
582 | li_tab--; |
||
583 | TextGoDown(left1, top1, width1); |
||
584 | } ELSE li_tab++; |
||
4488 | leency | 585 | if (isTag("dd")) stolbec += 5; |
586 | if (isTag("blockquote")) blq_text = rez; |
||
587 | if (isTag("pre")) pre_text = rez; |
||
588 | if (isTag("hr")) |
||
4411 | leency | 589 | { |
590 | if (anchor) || (stroka < -1) |
||
591 | { |
||
592 | stroka+=2; |
||
593 | return; |
||
594 | } |
||
595 | if (strcmp(#parametr, "color=") == 0) hr_color = GetColor(#options); else hr_color = 0x999999; |
||
596 | TextGoDown(left1, top1, width1); |
||
4486 | leency | 597 | DrawBuf.DrawBar(5, list.line_h/2, list.w-10, 1, hr_color); |
598 | TextGoDown(left1, top1+list.line_h, width1); |
||
4411 | leency | 599 | } |
4488 | leency | 600 | if (isTag("img")) |
4411 | leency | 601 | { |
4486 | leency | 602 | ImgCache1.Images( left1, top1, width1); |
4411 | leency | 603 | return; |
604 | } |
||
4488 | leency | 605 | if (isTag("meta")) || (isTag("?xml")) |
4411 | leency | 606 | { |
607 | do{ |
||
608 | if (!strcmp(#parametr, "charset=")) || (!strcmp(#parametr, "content=")) || (!strcmp(#parametr, "encoding=")) |
||
609 | { |
||
610 | strcpy(#options, #options[strrchr(#options, '=')]); //поиск в content= |
||
4475 | leency | 611 | if (!strcmp(#options, "utf-8")) || (!strcmp(#options,"utf8")) ReadHtml(_UTF); |
4411 | leency | 612 | if (!strcmp(#options, "koi8-r")) || (!strcmp(#options, "koi8-u")) ReadHtml(_KOI); |
613 | if (!strcmp(#options, "dos")) || (!strcmp(#options, "cp-866")) ReadHtml(_DOS); |
||
614 | } |
||
615 | } while(GetNextParam()); |
||
616 | return; |
||
617 | } |
||
618 | } |
||
619 | |||
620 | |||
621 | void TWebBrowser::DrawScroller() //не оптимальная отрисовка, но зато в одном месте |
||
622 | { |
||
4416 | leency | 623 | scroll_wv.max_area = list.count; |
624 | scroll_wv.cur_area = list.visible; |
||
625 | scroll_wv.position = list.first; |
||
4411 | leency | 626 | |
4416 | leency | 627 | scroll_wv.all_redraw=1; |
4486 | leency | 628 | scroll_wv.start_x = list.x + list.w; |
629 | scroll_wv.size_y=list.h; |
||
4411 | leency | 630 | |
4416 | leency | 631 | scrollbar_v_draw(#scroll_wv); |
4411 | leency | 632 | } |
633 | |||
4475 | leency | 634 | |
635 | void TWebBrowser::TextGoDown(int left1, top1, width1) |
||
636 | { |
||
4486 | leency | 637 | if (!stroka) DrawBar(list.x, list.y, list.w, 5, bg_color); //закрашиваем фон над первой строкой |
638 | if (top1>=list.y) && ( top1 < list.h+list.y-10) && (!anchor) |
||
4475 | leency | 639 | { |
4486 | leency | 640 | if (text_align == ALIGN_CENTER) DrawBuf.AlignCenter(left1,top1,list.w,list.line_h,stolbec * 6); |
641 | if (text_align == ALIGN_RIGHT) DrawBuf.AlignRight(left1,top1,list.w,list.line_h,stolbec * 6); |
||
642 | PutPaletteImage(buf_data+8, list.w, list.line_h, left1-5, top1, 32,0); |
||
4475 | leency | 643 | DrawBuf.Fill(bg_color); |
644 | } |
||
645 | stroka++; |
||
646 | if (blq_text) stolbec = 8; else stolbec = 0; |
||
647 | if (li_text) stolbec = li_tab * 5; |
||
4488 | leency | 648 | } |
649 | |||
650 | |||
651 | |||
652 | int isTag(dword text) |
||
653 | { |
||
654 | if (!strcmp(#tag,text)) return 1; else return 0; |
||
655 | }>>>>>=>=>>=15)>>>>>>>=>!--> |