Rev 4650 | Rev 4653 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
3067 | leency | 1 | //HTML Viewer in C-- |
3987 | leency | 2 | //Copyright 2007-2013 by Veliant & Leency |
3107 | leency | 3 | //Asper, lev, Lrz, Barsuk, Nable... |
3067 | leency | 4 | //home icon - rachel fu, GPL licence |
5 | |||
4085 | leency | 6 | #ifndef AUTOBUILD |
7 | #include "lang.h--" |
||
8 | #endif |
||
9 | |||
3107 | leency | 10 | //libraries |
3363 | leency | 11 | #define MEMSIZE 0x100000 |
3067 | leency | 12 | #include "..\lib\kolibri.h" |
13 | #include "..\lib\strings.h" |
||
14 | #include "..\lib\figures.h" |
||
15 | #include "..\lib\encoding.h" |
||
16 | #include "..\lib\file_system.h" |
||
17 | #include "..\lib\mem.h" |
||
18 | #include "..\lib\dll.h" |
||
4508 | leency | 19 | #include "..\lib\draw_buf.h" |
20 | #include "..\lib\list_box.h" |
||
21 | #include "..\lib\cursor.h" |
||
22 | |||
3107 | leency | 23 | //*.obj libraries |
24 | #include "..\lib\lib.obj\box_lib.h" |
||
25 | #include "..\lib\lib.obj\libio_lib.h" |
||
26 | #include "..\lib\lib.obj\libimg_lib.h" |
||
4536 | leency | 27 | #include "..\lib\lib.obj\http.h" |
3107 | leency | 28 | //images |
3067 | leency | 29 | #include "img\toolbar_icons.c" |
30 | #include "img\URLgoto.txt"; |
||
31 | |||
4026 | leency | 32 | #ifdef LANG_RUS |
4651 | leency | 33 | char version[]=" Текстовый браузер 0.99.75"; |
4416 | leency | 34 | ?define IMAGES_CACHE_CLEARED "Кэш картинок очищен" |
4417 | leency | 35 | ?define T_LAST_SLIDE "Это последний слайд" |
4550 | leency | 36 | char loading[] = "Загрузка страницы... |
4544 | leency | 37 | unsigned char page_not_found[] = FROM "html\page_not_found_ru.htm"; |
4649 | leency | 38 | char accept_language[]= "Accept-Language: ru\n"; |
4026 | leency | 39 | #else |
4651 | leency | 40 | char version[]=" Text-based Browser 0.99.75"; |
4026 | leency | 41 | ?define IMAGES_CACHE_CLEARED "Images cache cleared" |
4417 | leency | 42 | ?define T_LAST_SLIDE "This slide is the last" |
4550 | leency | 43 | char loading[] = "Loading... |
4544 | leency | 44 | unsigned char page_not_found[] = FROM "html\page_not_found_en.htm"; |
4649 | leency | 45 | char accept_language[]= "Accept-Language: en\n"; |
4026 | leency | 46 | #endif |
47 | |||
3067 | leency | 48 | proc_info Form; |
49 | #define WIN_W 640 |
||
50 | #define WIN_H 480 |
||
51 | |||
4416 | leency | 52 | char search_path[]="http://nigma.ru/index.php?s="; |
4558 | hidnplayr | 53 | char str_location[]="location\0"; |
54 | int redirected = 0; |
||
3067 | leency | 55 | |
4074 | leency | 56 | char stak[4096]; |
3067 | leency | 57 | mouse m; |
4026 | leency | 58 | int action_buf; |
59 | |||
4565 | leency | 60 | dword http_transfer = 0; |
4537 | leency | 61 | dword http_buffer; |
4534 | leency | 62 | |
4411 | leency | 63 | #include "..\TWB\TWB.c" |
64 | #include "menu_rmb.h" |
||
4636 | leency | 65 | #include "history.h" |
3067 | leency | 66 | |
4534 | leency | 67 | char editURL[sizeof(URL)]; |
68 | int mouse_twb; |
||
69 | edit_box address_box= {250,207,16,0xffffff,0x94AECE,0xffffff,0xffffff,0,sizeof(URL),#editURL,#mouse_twb,2,19,19}; |
||
70 | |||
4544 | leency | 71 | #define URL_HISTORY "WebView://history" |
4534 | leency | 72 | |
4488 | leency | 73 | enum { BACK=300, FORWARD, REFRESH, HOME, NEWTAB, GOTOURL, SEARCHWEB, INPUT_CH, INPUT_BT, BTN_UP, BTN_DOWN }; |
3067 | leency | 74 | |
4488 | leency | 75 | |
3067 | leency | 76 | void main() |
77 | { |
||
4081 | leency | 78 | int key, btn; |
3067 | leency | 79 | int half_scroll_size; |
4026 | leency | 80 | int scroll_used=0, show_menu; |
3067 | leency | 81 | |
82 | mem_Init(); |
||
4536 | leency | 83 | CursorPointer.Load(#CursorFile); |
3107 | leency | 84 | if (load_dll2(boxlib, #box_lib_init,0)!=0) {notify("System Error: library doesn't exists /rd/1/lib/box_lib.obj"); ExitProcess();} |
4536 | leency | 85 | if (load_dll2(libio, #libio_init,1)!=0) notify("Error: library doesn't exists - libio"); |
86 | if (load_dll2(libimg, #libimg_init,1)!=0) notify("Error: library doesn't exists - libimg"); |
||
4540 | leency | 87 | if (load_dll2(libHTTP, #http_lib_init,1)!=0) notify("Error: library doesn't exists - http"); |
3067 | leency | 88 | |
4536 | leency | 89 | if (!URL) strcpy(#URL, "/sys/index.htm"); |
3067 | leency | 90 | Form.width=WIN_W; |
91 | Form.height=WIN_H; |
||
92 | SetElementSizes(); |
||
4416 | leency | 93 | OpenPage(); |
3067 | leency | 94 | |
4536 | leency | 95 | SetEventMask(0xa7); |
3067 | leency | 96 | loop() |
97 | { |
||
98 | WaitEventTimeout(2); |
||
99 | switch(EAX & 0xFF) |
||
100 | { |
||
101 | CASE evMouse: |
||
4081 | leency | 102 | if (!CheckActiveProcess(Form.ID)) break; |
4636 | leency | 103 | //Edit URL |
3466 | leency | 104 | edit_box_mouse stdcall (#address_box); |
3067 | leency | 105 | m.get(); |
4636 | leency | 106 | //Links hover |
4550 | leency | 107 | if (m.y>WB1.list.y) PageLinks.Hover(m.x, m.y, link_color_inactive, link_color_active, bg_color); |
4636 | leency | 108 | //Menu |
4540 | leency | 109 | if (m.y>WB1.list.y) && (m.y |
3067 | leency | 110 | { |
4026 | leency | 111 | if (m.pkm) |
112 | { |
||
113 | show_menu = 1; |
||
114 | } |
||
115 | if (!m.pkm) && (show_menu) |
||
116 | { |
||
117 | show_menu = 0; |
||
118 | SwitchToAnotherThread(); |
||
4074 | leency | 119 | CreateThread(#menu_rmb,#stak+4092); |
4026 | leency | 120 | break; |
121 | } |
||
3067 | leency | 122 | } |
4636 | leency | 123 | //Mouse scroll |
4415 | leency | 124 | if (m.vert) |
3067 | leency | 125 | { |
4636 | leency | 126 | if (WB1.list.MouseScroll(m.vert)) WB1.Parse(); |
3067 | leency | 127 | } |
4636 | leency | 128 | //Drag scroller |
3067 | leency | 129 | if (!m.lkm) scroll_used=0; |
4416 | leency | 130 | if (m.x>=scroll_wv.start_x) && (m.x<=scroll_wv.start_x+scroll_wv.size_x) |
131 | && (m.y>=scroll_wv.start_y+scroll_wv.btn_height) && (-scroll_wv.btn_height+scroll_wv.start_y+scroll_wv.size_y>m.y) |
||
4415 | leency | 132 | && (WB1.list.count>WB1.list.visible) && (m.lkm) |
4026 | leency | 133 | { |
134 | scroll_used=1; |
||
4636 | leency | 135 | } |
3067 | leency | 136 | if (scroll_used) |
137 | { |
||
4415 | leency | 138 | half_scroll_size = WB1.list.h - 16 * WB1.list.visible / WB1.list.count - 3 /2; |
4416 | leency | 139 | if (half_scroll_size+WB1.list.y>m.y) || (m.y<0) || (m.y>4000) m.y=half_scroll_size+WB1.list.y; |
140 | btn=WB1.list.first; |
||
4415 | leency | 141 | WB1.list.first = m.y -half_scroll_size -WB1.list.y * WB1.list.count / WB1.list.h; |
142 | if (WB1.list.visible+WB1.list.first>WB1.list.count) WB1.list.first=WB1.list.count-WB1.list.visible; |
||
4636 | leency | 143 | if (btn<>WB1.list.first) WB1.Parse(); |
3067 | leency | 144 | } |
145 | break; |
||
146 | case evButton: |
||
147 | btn=GetButtonID(); |
||
4636 | leency | 148 | if (btn==1) ExitProcess(); |
149 | Scan(btn); |
||
3067 | leency | 150 | break; |
151 | case evKey: |
||
152 | key = GetKey(); |
||
153 | |||
4416 | leency | 154 | if (address_box.flags & 0b10) SWITCH(key) |
3067 | leency | 155 | { CASE 52: CASE 53: CASE 54: goto _EDIT_MARK; } |
156 | |||
4413 | leency | 157 | Scan(key); |
3067 | leency | 158 | |
159 | _EDIT_MARK: |
||
4416 | leency | 160 | if (key<>0x0d) && (key<>183) && (key<>184) {EAX=key<<8; edit_box_key stdcall(#address_box);} |
3067 | leency | 161 | break; |
162 | case evReDraw: |
||
4636 | leency | 163 | if (action_buf) Scan(action_buf); |
3067 | leency | 164 | Draw_Window(); |
165 | break; |
||
4540 | leency | 166 | |
4536 | leency | 167 | case evNetwork: |
4540 | leency | 168 | if (http_transfer > 0) { |
4536 | leency | 169 | http_process stdcall (http_transfer); |
4554 | leency | 170 | if (EAX == 0) { |
4558 | hidnplayr | 171 | ESI = http_transfer; |
172 | // Handle redirects |
||
4563 | leency | 173 | if (ESI.http_msg.status >= 300) && (ESI.http_msg.status < 400) |
174 | { |
||
4558 | hidnplayr | 175 | redirected++; |
4563 | leency | 176 | if (redirected<=5) |
177 | { |
||
4558 | hidnplayr | 178 | http_find_header_field stdcall (http_transfer, #str_location); |
179 | if (EAX!=0) { |
||
180 | ESI = EAX; |
||
181 | EDI = #URL; |
||
182 | do { |
||
183 | $lodsb; |
||
184 | $stosb; |
||
185 | } while (AL != 0) && (AL != 13) && (AL != 10)); |
||
186 | DSBYTE[EDI-1]='\0'; |
||
187 | } |
||
4563 | leency | 188 | } |
189 | else |
||
190 | { |
||
4558 | hidnplayr | 191 | //TODO: display error (too many redirects) |
192 | } |
||
4563 | leency | 193 | } |
194 | else |
||
195 | { |
||
4558 | hidnplayr | 196 | redirected = 0; |
197 | } |
||
4554 | leency | 198 | // Loading the page is complete, free resources |
4563 | leency | 199 | if (redirected>0) |
200 | { |
||
4643 | leency | 201 | http_free stdcall (http_transfer); |
202 | http_transfer=0; |
||
4558 | hidnplayr | 203 | WB1.GetNewUrl(); |
204 | strcpy(#editURL, #URL); |
||
4563 | leency | 205 | BrowserHistory.current--; |
4558 | hidnplayr | 206 | OpenPage(); |
4563 | leency | 207 | } |
208 | else |
||
209 | { |
||
4643 | leency | 210 | ESI = http_transfer; |
211 | bufpointer = ESI.http_msg.content_ptr; |
||
212 | bufsize = ESI.http_msg.content_received; |
||
213 | http_free stdcall (http_transfer); |
||
214 | http_transfer=0; |
||
4645 | leency | 215 | SetPageDefaults(); |
4558 | hidnplayr | 216 | Draw_Window(); // stop button => refresh button |
217 | } |
||
4536 | leency | 218 | } |
219 | } |
||
3067 | leency | 220 | } |
221 | } |
||
222 | } |
||
223 | |||
224 | void SetElementSizes() |
||
225 | { |
||
4416 | leency | 226 | address_box.width = Form.width - 266; |
227 | WB1.list.SetSizes(0, 44, Form.width - 10 - scroll_wv.size_x, Form.cheight - 44, 0, 10); |
||
4651 | leency | 228 | WB1.list.column_max = WB1.list.w - scroll_wv.size_x / 6; |
4415 | leency | 229 | WB1.list.visible = WB1.list.h - 3 / WB1.list.line_h - 2; |
4475 | leency | 230 | WB1.DrawBuf.Init(WB1.list.x, WB1.list.y, WB1.list.w, WB1.list.h, WB1.list.line_h); |
3067 | leency | 231 | } |
232 | |||
233 | |||
234 | void Draw_Window() |
||
235 | { |
||
236 | int j; |
||
3466 | leency | 237 | DefineAndDrawWindow(215,100,WIN_W,WIN_H,0x73,0xE4DFE1,0,0); |
3067 | leency | 238 | |
239 | GetProcessInfo(#Form, SelfInfo); |
||
3464 | leency | 240 | if (Form.status_window>2) |
3067 | leency | 241 | { |
242 | DrawTitle(#header); |
||
243 | return; |
||
244 | } |
||
245 | if (Form.height<120) MoveSize(OLD,OLD,OLD,120); |
||
246 | if (Form.width<280) MoveSize(OLD,OLD,280,OLD); |
||
247 | |||
248 | PutPaletteImage(#toolbar,200,42,0,0,8,#toolbar_pal); |
||
4636 | leency | 249 | if (http_transfer > 0) _PutImage(88,10, 24,24, #stop_btn); |
3067 | leency | 250 | |
3464 | leency | 251 | DrawBar(200,0,Form.cwidth-200,43,0xE4DFE1); |
252 | DrawBar(0,42,Form.cwidth,1,0xE2DBDC); |
||
253 | DrawBar(0,43,Form.cwidth,1,0xD2CED0); |
||
3067 | leency | 254 | for (j=0; j<5; j++) DefineButton(j*37+11, 7, 29, 29, 300+j+BT_HIDE, 0xE4DFE1); |
3464 | leency | 255 | _PutImage(Form.cwidth-48,14, 40,19, #URLgoto); |
256 | DefineButton(Form.cwidth-28,15, 18, 16, GOTOURL+BT_HIDE, 0xE4DFE1); |
||
257 | DefineButton(Form.cwidth-47,15, 17, 16, SEARCHWEB+BT_HIDE, 0xE4DFE1); |
||
258 | DrawRectangle(205,14,Form.cwidth-205-49,18,0x94AECE); //around adress bar |
||
259 | DrawRectangle(206,15,Form.cwidth-205-50,16,0xE4ECF3); |
||
3067 | leency | 260 | |
261 | SetElementSizes(); |
||
4508 | leency | 262 | ShowPage(); |
3464 | leency | 263 | |
4416 | leency | 264 | DefineButton(scroll_wv.start_x+1, scroll_wv.start_y+1, 16, 16, BTN_UP+BT_HIDE, 0xE4DFE1); |
265 | DefineButton(scroll_wv.start_x+1, scroll_wv.start_y+scroll_wv.size_y-18, 16, 16, BTN_DOWN+BT_HIDE, 0xE4DFE1); |
||
3067 | leency | 266 | } |
267 | |||
268 | |||
4636 | leency | 269 | void ChangeCharset(byte new_charset) |
270 | { |
||
271 | BufEncode(new_charset); |
||
272 | WB1.Parse(); |
||
273 | } |
||
274 | |||
4413 | leency | 275 | void Scan(int id) |
276 | { |
||
4636 | leency | 277 | action_buf=0; |
278 | if (id >= 400) |
||
279 | { |
||
280 | ProcessLinks(id); |
||
281 | return; |
||
282 | } |
||
4413 | leency | 283 | switch (id) |
284 | { |
||
285 | case 011: //Ctrk+K |
||
4636 | leency | 286 | ChangeCharset(_KOI); |
4415 | leency | 287 | return; |
288 | |||
4413 | leency | 289 | case 021: //Ctrl+U |
4636 | leency | 290 | ChangeCharset(_UTF); |
4415 | leency | 291 | return; |
292 | |||
4413 | leency | 293 | case 004: //Ctrl+D |
4636 | leency | 294 | ChangeCharset(_DOS); |
4415 | leency | 295 | return; |
296 | |||
4533 | leency | 297 | case 005: //Win encoding |
4636 | leency | 298 | ChangeCharset(_WIN); |
4533 | leency | 299 | return; |
300 | |||
301 | case 009: //free img cache |
||
4491 | leency | 302 | ImgCache.Free(); |
4416 | leency | 303 | notify(IMAGES_CACHE_CLEARED); |
4636 | leency | 304 | WB1.Parse(); |
4415 | leency | 305 | return; |
306 | |||
4546 | leency | 307 | case 003: //history |
4544 | leency | 308 | strcpy(#URL, URL_HISTORY); |
309 | OpenPage(); |
||
310 | return; |
||
311 | |||
4413 | leency | 312 | case BACK: |
313 | if (!BrowserHistory.GoBack()) return; |
||
4416 | leency | 314 | OpenPage(); |
4413 | leency | 315 | return; |
316 | case FORWARD: |
||
317 | if (!BrowserHistory.GoForward()) return; |
||
4416 | leency | 318 | OpenPage(); |
4413 | leency | 319 | return; |
320 | case 052: //F3 |
||
4636 | leency | 321 | if (strncmp(#URL,"http:",5)==0) |
322 | { |
||
323 | WriteFile(bufsize, bufpointer, "/tmp0/1/webview.tmp"); |
||
324 | if (EAX==0) RunProgram("/rd/1/tinypad", "/tmp0/1/webview.tmp"); |
||
325 | } |
||
326 | else |
||
327 | { |
||
328 | RunProgram("/rd/1/tinypad", #URL); |
||
329 | } |
||
4413 | leency | 330 | return; |
331 | case 054: //F5 |
||
4636 | leency | 332 | IF(address_box.flags & 0b10) WB1.Parse(); |
4415 | leency | 333 | return; |
334 | |||
4413 | leency | 335 | case REFRESH: |
4643 | leency | 336 | if (http_transfer > 0) |
337 | { |
||
338 | StopLoading(); |
||
339 | Draw_Window(); |
||
340 | } |
||
4636 | leency | 341 | else OpenPage(); |
4413 | leency | 342 | return; |
4415 | leency | 343 | case 014: |
344 | case 020: |
||
4413 | leency | 345 | case NEWTAB: |
346 | MoveSize(190,80,OLD,OLD); |
||
347 | RunProgram(#program_path, #URL); |
||
348 | return; |
||
349 | |||
350 | case HOME: |
||
4571 | hidnplayr | 351 | strcpy(#editURL, "http://kolibrios.org/"); |
4413 | leency | 352 | case GOTOURL: |
353 | case 0x0D: //enter |
||
354 | if ((strstr(#editURL,"ttp://")==0) && (editURL[0]!='/')) strcpy(#URL,"http://"); else URL[0] = 0; |
||
355 | strcat(#URL, #editURL); |
||
4416 | leency | 356 | OpenPage(); |
4413 | leency | 357 | return; |
358 | case SEARCHWEB: |
||
359 | strcpy(#URL, #search_path); |
||
360 | strcat(#URL, #editURL); |
||
4416 | leency | 361 | OpenPage(); |
4413 | leency | 362 | return; |
363 | |||
364 | case 183: //PgDown |
||
4415 | leency | 365 | if (WB1.list.count < WB1.list.visible) return; |
366 | IF(WB1.list.first == WB1.list.count - WB1.list.visible) return; |
||
367 | WB1.list.first += WB1.list.visible + 2; |
||
368 | IF(WB1.list.visible + WB1.list.first > WB1.list.count) WB1.list.first = WB1.list.count - WB1.list.visible; |
||
4636 | leency | 369 | WB1.Parse(); |
4415 | leency | 370 | return; |
371 | |||
4413 | leency | 372 | case 184: //PgUp |
4415 | leency | 373 | if (WB1.list.count < WB1.list.visible) return; |
374 | IF(WB1.list.first == 0) return; |
||
375 | WB1.list.first -= WB1.list.visible - 2; |
||
376 | IF(WB1.list.first < 0) WB1.list.first = 0; |
||
4636 | leency | 377 | WB1.Parse(); |
4415 | leency | 378 | return; |
379 | |||
380 | case 178: |
||
4544 | leency | 381 | case BTN_UP: |
4416 | leency | 382 | if (WB1.list.first <= 0) return; |
4415 | leency | 383 | WB1.list.first--; |
4636 | leency | 384 | WB1.Parse(); |
4415 | leency | 385 | return; |
386 | |||
387 | case 177: |
||
4544 | leency | 388 | case BTN_DOWN: |
4416 | leency | 389 | if (WB1.list.visible + WB1.list.first >= WB1.list.count) return; |
4415 | leency | 390 | WB1.list.first++; |
4636 | leency | 391 | WB1.Parse(); |
4415 | leency | 392 | return; |
393 | |||
4413 | leency | 394 | case 180: //home |
4636 | leency | 395 | if (WB1.list.KeyHome()) WB1.Parse(); |
4415 | leency | 396 | return; |
397 | |||
4413 | leency | 398 | case 181: //end |
4415 | leency | 399 | if (WB1.list.count < WB1.list.visible) return; |
4636 | leency | 400 | if (WB1.list.KeyEnd()) WB1.Parse(); |
4413 | leency | 401 | return; |
402 | } |
||
403 | } |
||
404 | |||
405 | |||
406 | |||
4415 | leency | 407 | void ProcessLinks(int id) |
408 | { |
||
4544 | leency | 409 | strcpy(#URL, PageLinks.GetURL(id-401)); |
4417 | leency | 410 | //$1 - Condition Script |
411 | if (URL[0] == '$') |
||
412 | { |
||
413 | if (URL[1]=='-') && (condition_href) condition_href--; |
||
414 | if (URL[1]=='+') |
||
415 | { |
||
416 | if (condition_href |
||
417 | } |
||
418 | if (URL[1]!='-') && (URL[1]!='+') condition_href = atoi(#URL+1); |
||
419 | strcpy(#URL, BrowserHistory.CurrentUrl()); |
||
4508 | leency | 420 | ShowPage(); |
4417 | leency | 421 | return; |
422 | } |
||
4415 | leency | 423 | //#1 |
424 | if (URL[0] == '#') |
||
425 | { |
||
4417 | leency | 426 | strcpy(#anchor, #URL+strrchr(#URL, '#')); |
4415 | leency | 427 | strcpy(#URL, BrowserHistory.CurrentUrl()); |
428 | WB1.list.first=WB1.list.count-WB1.list.visible; |
||
4508 | leency | 429 | ShowPage(); |
4415 | leency | 430 | return; |
431 | } |
||
432 | //liner.ru#1 |
||
4417 | leency | 433 | if (strrchr(#URL, '#')!=-1) |
4415 | leency | 434 | { |
435 | strcpy(#anchor, #URL+strrchr(#URL, '#')); |
||
4416 | leency | 436 | URL[strrchr(#URL, '#')-1] = 0x00; |
4415 | leency | 437 | } |
438 | |||
439 | WB1.GetNewUrl(); |
||
440 | |||
441 | if (!strcmp(#URL + strlen(#URL) - 4, ".gif")) || (!strcmp(#URL + strlen(#URL) - 4, ".png")) || (!strcmp(#URL + strlen(#URL) - 4, ".jpg")) |
||
442 | { |
||
443 | //if (strstr(#URL,"http:")) |
||
444 | RunProgram("/sys/media/kiv", #URL); |
||
445 | strcpy(#editURL, BrowserHistory.CurrentUrl()); |
||
446 | strcpy(#URL, BrowserHistory.CurrentUrl()); |
||
447 | return; |
||
448 | } |
||
449 | if (!strcmpn(#URL,"mailto:", 7)) |
||
450 | { |
||
451 | notify(#URL); |
||
452 | strcpy(#editURL, BrowserHistory.CurrentUrl()); |
||
453 | strcpy(#URL, BrowserHistory.CurrentUrl()); |
||
454 | return; |
||
455 | } |
||
4416 | leency | 456 | OpenPage(); |
4415 | leency | 457 | return; |
458 | } |
||
459 | |||
4636 | leency | 460 | void StopLoading() |
461 | { |
||
4647 | leency | 462 | if (http_transfer<>0) |
463 | { |
||
464 | EAX = http_transfer; |
||
465 | EAX = EAX.http_msg.content_ptr; // get pointer to data |
||
466 | $push EAX // save it on the stack |
||
467 | http_free stdcall (http_transfer); // abort connection |
||
468 | $pop EAX |
||
469 | mem_Free(EAX); // free data |
||
470 | http_transfer=0; |
||
471 | bufsize = 0; |
||
4650 | leency | 472 | bufpointer = mem_Free(bufpointer); |
4647 | leency | 473 | } |
4646 | leency | 474 | PutPaletteImage(#toolbar,200,42,0,0,8,#toolbar_pal); |
4645 | leency | 475 | } |
476 | |||
477 | void SetPageDefaults() |
||
478 | { |
||
479 | strcpy(#header, #version); |
||
480 | pre_text = 0; |
||
481 | WB1.list.count = WB1.list.first = 0; |
||
482 | stroka = 0; |
||
483 | cur_encoding = _DEFAULT; |
||
484 | if (o_bufpointer) o_bufpointer = free(o_bufpointer); |
||
4636 | leency | 485 | anchor_line_num=WB1.list.first; |
486 | anchor[0]='|'; |
||
487 | } |
||
488 | |||
4416 | leency | 489 | void OpenPage() |
490 | { |
||
4636 | leency | 491 | StopLoading(); |
4416 | leency | 492 | strcpy(#editURL, #URL); |
493 | BrowserHistory.AddUrl(); |
||
4636 | leency | 494 | if (strncmp(#URL,"http:",5)==0) |
4416 | leency | 495 | { |
4645 | leency | 496 | _PutImage(88,10, 24,24, #stop_btn); |
4636 | leency | 497 | http_get stdcall (#URL, #accept_language); |
498 | http_transfer = EAX; |
||
4646 | leency | 499 | if (http_transfer == 0) |
500 | { |
||
501 | StopLoading(); |
||
502 | bufsize = 0; |
||
4650 | leency | 503 | bufpointer = mem_Free(bufpointer); |
4646 | leency | 504 | ShowPage(); |
505 | return; |
||
506 | } |
||
4416 | leency | 507 | } |
4636 | leency | 508 | else |
509 | { |
||
510 | file_size stdcall (#URL); |
||
511 | bufsize = EBX; |
||
4650 | leency | 512 | if (bufsize) |
513 | { |
||
514 | bufpointer = mem_Free(bufpointer); |
||
515 | bufpointer = mem_Alloc(bufsize); |
||
516 | SetPageDefaults(); |
||
517 | ReadFile(0, bufsize, bufpointer, #URL); |
||
518 | } |
||
4645 | leency | 519 | ShowPage(); |
4636 | leency | 520 | } |
4416 | leency | 521 | } |
4415 | leency | 522 | |
4508 | leency | 523 | void ShowPage() |
524 | { |
||
525 | address_box.size = address_box.pos = strlen(#editURL); |
||
526 | address_box.offset=0; |
||
527 | edit_box_draw stdcall(#address_box); |
||
4415 | leency | 528 | |
4544 | leency | 529 | if (strcmp(#URL, URL_HISTORY)==0) ShowHistory(); else |
4540 | leency | 530 | if (!bufsize) |
4508 | leency | 531 | { |
532 | PageLinks.Clear(); |
||
4636 | leency | 533 | if (http_transfer<>0) |
534 | { |
||
535 | WB1.Prepare(#loading, sizeof(loading)); |
||
536 | } |
||
4508 | leency | 537 | else |
4636 | leency | 538 | WB1.Prepare(#page_not_found, sizeof(page_not_found)); |
4508 | leency | 539 | } |
540 | else |
||
4636 | leency | 541 | WB1.Parse(); |
4415 | leency | 542 | |
4508 | leency | 543 | if (!header) strcpy(#header, #version); |
544 | if (!strcmp(#version, #header)) DrawTitle(#header); |
||
545 | } |
||
546 | |||
547 | |||
4544 | leency | 548 | |
4636 | leency | 549 | |
3067 | leency | 550 | stop:>>>=>>>>5;>280)>120)>=5) |