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