Rev 5774 | Rev 5781 | 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 |
5499 | leency | 12 | #include "..\lib\gui.h" |
4508 | leency | 13 | #include "..\lib\draw_buf.h" |
14 | #include "..\lib\list_box.h" |
||
15 | #include "..\lib\cursor.h" |
||
3107 | leency | 16 | //*.obj libraries |
5499 | leency | 17 | #include "..\lib\obj\box_lib.h" |
18 | #include "..\lib\obj\libio_lib.h" |
||
19 | #include "..\lib\obj\libimg_lib.h" |
||
20 | #include "..\lib\obj\http.h" |
||
5690 | leency | 21 | #include "..\lib\obj\iconv.h" |
5408 | leency | 22 | //useful patterns |
23 | #include "..\lib\patterns\libimg_load_skin.h" |
||
24 | |||
5493 | leency | 25 | char homepage[] = FROM "html\\homepage.htm"; |
4677 | leency | 26 | |
4026 | leency | 27 | #ifdef LANG_RUS |
5773 | leency | 28 | char version[]=" Текстовый браузер 1.38"; |
4416 | leency | 29 | ?define IMAGES_CACHE_CLEARED "Кэш картинок очищен" |
4417 | leency | 30 | ?define T_LAST_SLIDE "Это последний слайд" |
4550 | leency | 31 | char loading[] = "Загрузка страницы... |
4677 | leency | 32 | char page_not_found[] = FROM "html\page_not_found_ru.htm"; |
4649 | leency | 33 | char accept_language[]= "Accept-Language: ru\n"; |
4026 | leency | 34 | #else |
5773 | leency | 35 | char version[]=" Text-based Browser 1.38"; |
4026 | leency | 36 | ?define IMAGES_CACHE_CLEARED "Images cache cleared" |
4417 | leency | 37 | ?define T_LAST_SLIDE "This slide is the last" |
4550 | leency | 38 | char loading[] = "Loading... |
4677 | leency | 39 | char page_not_found[] = FROM "html\page_not_found_en.htm"; |
4649 | leency | 40 | char accept_language[]= "Accept-Language: en\n"; |
4026 | leency | 41 | #endif |
42 | |||
5773 | leency | 43 | #define URL_SERVICE_HISTORY "WebView://history" |
44 | #define URL_SERVICE_HOME "WebView://home" |
||
45 | #define URL_SERVICE_SOURCE "WebView://source:" |
||
5631 | pavelyakov | 46 | |
47 | |||
3067 | leency | 48 | proc_info Form; |
49 | |||
5772 | leency | 50 | //char search_path[]="http://nigma.ru/index.php?s="; |
4558 | hidnplayr | 51 | int redirected = 0; |
3067 | leency | 52 | |
4074 | leency | 53 | char stak[4096]; |
5640 | pavelyakov | 54 | |
4026 | leency | 55 | int action_buf; |
56 | |||
4565 | leency | 57 | dword http_transfer = 0; |
4537 | leency | 58 | dword http_buffer; |
4534 | leency | 59 | |
5772 | leency | 60 | dword TOOLBAR_H = 33; |
5519 | leency | 61 | dword STATUSBAR_H = 15; |
4718 | leency | 62 | dword col_bg; |
63 | dword panel_color; |
||
64 | dword border_color; |
||
4677 | leency | 65 | |
5718 | leency | 66 | progress_bar wv_progress_bar; |
4718 | leency | 67 | byte souce_mode = false; |
4677 | leency | 68 | |
5718 | leency | 69 | enum { |
70 | BACK_BUTTON=1000, |
||
71 | FORWARD_BUTTON, |
||
72 | REFRESH_BUTTON, |
||
73 | GOTOURL_BUTTON, |
||
74 | SANDWICH_BUTTON |
||
75 | }; |
||
76 | |||
77 | enum { |
||
5768 | leency | 78 | VIEW_SOURCE=1100, |
5718 | leency | 79 | EDIT_SOURCE, |
80 | VIEW_HISTORY, |
||
81 | FREE_IMG_CACHE, |
||
82 | DOWNLOAD_MANAGER |
||
83 | }; |
||
84 | |||
4411 | leency | 85 | #include "..\TWB\TWB.c" |
5768 | leency | 86 | #include "menu.h" |
4636 | leency | 87 | #include "history.h" |
4718 | leency | 88 | #include "show_src.h" |
5685 | leency | 89 | #include "network_get.h" |
5493 | leency | 90 | #include "downloader.h" |
3067 | leency | 91 | |
4534 | leency | 92 | char editURL[sizeof(URL)]; |
93 | int mouse_twb; |
||
5772 | leency | 94 | edit_box address_box = {250,56,34,0xffffff,0x94AECE,0xffffff,0xffffff,0,sizeof(URL),#editURL,#mouse_twb,2,19,19}; |
4534 | leency | 95 | |
96 | |||
3067 | leency | 97 | void main() |
98 | { |
||
5711 | leency | 99 | dword btn; |
3067 | leency | 100 | int half_scroll_size; |
4026 | leency | 101 | int scroll_used=0, show_menu; |
4536 | leency | 102 | CursorPointer.Load(#CursorFile); |
5626 | leency | 103 | load_dll(boxlib, #box_lib_init,0); |
104 | load_dll(libio, #libio_init,1); |
||
105 | load_dll(libimg, #libimg_init,1); |
||
106 | load_dll(libHTTP, #http_lib_init,1); |
||
5690 | leency | 107 | load_dll(iconv_lib, #iconv_open,0); |
5718 | leency | 108 | //load_dll(kmenu, #akmenu_init,0); |
5408 | leency | 109 | Libimg_LoadImage(#skin, abspath("wv_skin.png")); |
110 | SetSkinColors(); |
||
5772 | leency | 111 | CreateDir("/tmp0/1/downloads"); |
112 | if (param) strcpy(#URL, #param); else strcpy(#URL, URL_SERVICE_HOME); |
||
5678 | leency | 113 | WB1.DrawBuf.zoom = 1; |
5712 | leency | 114 | WB1.list.SetFont(8, 14, 10111000b); |
5779 | leency | 115 | WB1.list.no_selection = true; |
4536 | leency | 116 | SetEventMask(0xa7); |
5631 | pavelyakov | 117 | BEGIN_LOOP_APPLICATION: |
3067 | leency | 118 | WaitEventTimeout(2); |
119 | switch(EAX & 0xFF) |
||
120 | { |
||
121 | CASE evMouse: |
||
4081 | leency | 122 | if (!CheckActiveProcess(Form.ID)) break; |
3466 | leency | 123 | edit_box_mouse stdcall (#address_box); |
5640 | pavelyakov | 124 | mouse.get(); |
5772 | leency | 125 | if (WB1.list.MouseOver(mouse.x, mouse.y)) |
3067 | leency | 126 | { |
5772 | leency | 127 | PageLinks.Hover(mouse.x, WB1.list.first*WB1.list.line_h + mouse.y, link_color_inactive, link_color_active, bg_color); |
128 | if (bufsize) && (mouse.pkm) && (mouse.up) { CreateThread(#menu_rmb,#stak+4092); break; } |
||
129 | if (WB1.list.MouseScroll(mouse.vert)) WB1.DrawPage(); |
||
3067 | leency | 130 | } |
4636 | leency | 131 | //Drag scroller |
4677 | leency | 132 | scroll_wv.all_redraw = 0; |
5640 | pavelyakov | 133 | if (!mouse.lkm) scroll_used=0; |
134 | if (mouse.x>=scroll_wv.start_x) && (mouse.x<=scroll_wv.start_x+scroll_wv.size_x) |
||
135 | && (mouse.y>=scroll_wv.start_y+scroll_wv.btn_height) && (-scroll_wv.btn_height+scroll_wv.start_y+scroll_wv.size_y>mouse.y) |
||
5772 | leency | 136 | && (WB1.list.count>WB1.list.visible) && (mouse.lkm) scroll_used=1; |
3067 | leency | 137 | if (scroll_used) |
138 | { |
||
5678 | leency | 139 | mouse.y = mouse.y + 5; |
4415 | leency | 140 | half_scroll_size = WB1.list.h - 16 * WB1.list.visible / WB1.list.count - 3 /2; |
5640 | pavelyakov | 141 | if (half_scroll_size+WB1.list.y>mouse.y) || (mouse.y<0) || (mouse.y>4000) mouse.y=half_scroll_size+WB1.list.y; |
4416 | leency | 142 | btn=WB1.list.first; |
5640 | pavelyakov | 143 | WB1.list.first = mouse.y -half_scroll_size -WB1.list.y * WB1.list.count / WB1.list.h; |
4415 | leency | 144 | if (WB1.list.visible+WB1.list.first>WB1.list.count) WB1.list.first=WB1.list.count-WB1.list.visible; |
5766 | leency | 145 | if (btn!=WB1.list.first) WB1.DrawPage(); |
3067 | leency | 146 | } |
147 | break; |
||
5711 | leency | 148 | |
3067 | leency | 149 | case evButton: |
150 | btn=GetButtonID(); |
||
4636 | leency | 151 | if (btn==1) ExitProcess(); |
152 | Scan(btn); |
||
3067 | leency | 153 | break; |
5711 | leency | 154 | |
3067 | leency | 155 | case evKey: |
5711 | leency | 156 | GetKeys(); |
5531 | leency | 157 | if (address_box.flags & 0b10) |
5530 | leency | 158 | { |
5711 | leency | 159 | if (key_ascii == ASCII_KEY_ENTER) Scan(key_scancode); else |
160 | if (key_ascii != 0x0d) && (key_ascii != 183) && (key_ascii != 184) {EAX = key_ascii << 8; edit_box_key stdcall(#address_box);} |
||
5530 | leency | 161 | } |
5711 | leency | 162 | else |
163 | { |
||
164 | Scan(key_scancode); |
||
165 | } |
||
5530 | leency | 166 | break; |
3067 | leency | 167 | |
168 | case evReDraw: |
||
4636 | leency | 169 | if (action_buf) Scan(action_buf); |
5773 | leency | 170 | DefineAndDrawWindow(GetScreenWidth()-800/2,GetScreenHeight()-600/2,800,600,0x73,col_bg,0,0); |
4725 | leency | 171 | GetProcessInfo(#Form, SelfInfo); |
4727 | leency | 172 | if (Form.status_window>2) { DrawTitle(#header); break; } |
4725 | leency | 173 | if (Form.height<120) MoveSize(OLD,OLD,OLD,120); |
174 | if (Form.width<280) MoveSize(OLD,OLD,280,OLD); |
||
3067 | leency | 175 | Draw_Window(); |
176 | break; |
||
4540 | leency | 177 | |
4536 | leency | 178 | case evNetwork: |
4540 | leency | 179 | if (http_transfer > 0) { |
5534 | hidnplayr | 180 | http_receive stdcall (http_transfer); |
4677 | leency | 181 | $push EAX |
182 | ESI = http_transfer; |
||
5519 | leency | 183 | wv_progress_bar.max = ESI.http_msg.content_length; |
184 | if (wv_progress_bar.value != ESI.http_msg.content_received) |
||
4686 | leency | 185 | { |
5519 | leency | 186 | wv_progress_bar.value = ESI.http_msg.content_received; |
4686 | leency | 187 | DrawProgress(); |
188 | } |
||
4677 | leency | 189 | $pop EAX |
190 | if (EAX == 0) { |
||
4558 | hidnplayr | 191 | ESI = http_transfer; |
192 | // Handle redirects |
||
4563 | leency | 193 | if (ESI.http_msg.status >= 300) && (ESI.http_msg.status < 400) |
194 | { |
||
4558 | hidnplayr | 195 | redirected++; |
4563 | leency | 196 | if (redirected<=5) |
197 | { |
||
5773 | leency | 198 | http_find_header_field stdcall (http_transfer, "location\0"); |
4558 | hidnplayr | 199 | if (EAX!=0) { |
200 | ESI = EAX; |
||
201 | EDI = #URL; |
||
202 | do { |
||
203 | $lodsb; |
||
204 | $stosb; |
||
205 | } while (AL != 0) && (AL != 13) && (AL != 10)); |
||
206 | DSBYTE[EDI-1]='\0'; |
||
207 | } |
||
4563 | leency | 208 | } |
209 | else |
||
210 | { |
||
5772 | leency | 211 | notify("Too many redirects"); |
212 | StopLoading(); |
||
213 | break; |
||
4558 | hidnplayr | 214 | } |
4563 | leency | 215 | } |
216 | else |
||
217 | { |
||
4558 | hidnplayr | 218 | redirected = 0; |
219 | } |
||
4554 | leency | 220 | // Loading the page is complete, free resources |
4563 | leency | 221 | if (redirected>0) |
222 | { |
||
4643 | leency | 223 | http_free stdcall (http_transfer); |
224 | http_transfer=0; |
||
4686 | leency | 225 | PageLinks.GetAbsoluteURL(#URL); |
4687 | leency | 226 | BrowserHistory.current--; |
4558 | hidnplayr | 227 | strcpy(#editURL, #URL); |
5718 | leency | 228 | DrawEditBox(); |
4558 | hidnplayr | 229 | OpenPage(); |
4563 | leency | 230 | } |
231 | else |
||
232 | { |
||
4686 | leency | 233 | BrowserHistory.AddUrl(); |
4643 | leency | 234 | ESI = http_transfer; |
235 | bufpointer = ESI.http_msg.content_ptr; |
||
236 | bufsize = ESI.http_msg.content_received; |
||
237 | http_free stdcall (http_transfer); |
||
238 | http_transfer=0; |
||
4645 | leency | 239 | SetPageDefaults(); |
5772 | leency | 240 | ShowPage(); |
4558 | hidnplayr | 241 | } |
4536 | leency | 242 | } |
243 | } |
||
3067 | leency | 244 | } |
5631 | pavelyakov | 245 | goto BEGIN_LOOP_APPLICATION; |
3067 | leency | 246 | } |
247 | |||
248 | void SetElementSizes() |
||
249 | { |
||
5772 | leency | 250 | address_box.top = TOOLBAR_H/2-7; |
4677 | leency | 251 | address_box.width = Form.cwidth - address_box.left - 25 - 22; |
5678 | leency | 252 | WB1.list.SetSizes(0, TOOLBAR_H, Form.width - 10 - scroll_wv.size_x / WB1.DrawBuf.zoom, |
5711 | leency | 253 | Form.cheight - TOOLBAR_H - STATUSBAR_H, WB1.list.font_h + WB1.DrawBuf.zoom + WB1.DrawBuf.zoom * WB1.DrawBuf.zoom); |
5749 | leency | 254 | WB1.list.wheel_size = 7; |
5710 | leency | 255 | WB1.list.column_max = WB1.list.w - scroll_wv.size_x / WB1.list.font_w; |
4692 | leency | 256 | WB1.list.visible = WB1.list.h - 5 / WB1.list.line_h; |
5773 | leency | 257 | if (WB1.list.w!=WB1.DrawBuf.bufw) WB1.DrawBuf.Init(WB1.list.x, WB1.list.y, WB1.list.w, WB1.list.h * 30); |
3067 | leency | 258 | } |
259 | |||
260 | void Draw_Window() |
||
261 | { |
||
5772 | leency | 262 | DrawBar(0,0, Form.cwidth,TOOLBAR_H-2, panel_color); |
5718 | leency | 263 | DrawBar(0,TOOLBAR_H-2, Form.cwidth,1, 0xD7D0D3); |
4677 | leency | 264 | DrawBar(0,TOOLBAR_H-1, Form.cwidth,1, border_color); |
3067 | leency | 265 | SetElementSizes(); |
5772 | leency | 266 | DrawRectangle(address_box.left-3, address_box.top-3, address_box.width+5, 20,border_color); |
267 | DefineButton(address_box.left-50, address_box.top-2, 23, skin.h-2, BACK_BUTTON+BT_HIDE, 0); |
||
268 | DefineButton(address_box.left-26, address_box.top-2, 23, skin.h-2, FORWARD_BUTTON+BT_HIDE, 0); |
||
269 | img_draw stdcall(skin.image, address_box.left-51, address_box.top-3, 48, skin.h, 3, 0); |
||
5718 | leency | 270 | DefineButton(address_box.left+address_box.width+1, address_box.top-3, 16, skin.h-1, REFRESH_BUTTON+BT_HIDE+BT_NOFRAME, 0); |
271 | DefineButton(Form.cwidth-24, address_box.top-3, 19, skin.h-1, SANDWICH_BUTTON+BT_HIDE, 0); |
||
272 | img_draw stdcall(skin.image, Form.cwidth-22, address_box.top-3, 16, skin.h, 85, 0); |
||
4677 | leency | 273 | DrawBar(0,Form.cheight - STATUSBAR_H, Form.cwidth,STATUSBAR_H, col_bg); |
274 | DrawBar(0,Form.cheight - STATUSBAR_H, Form.cwidth,1, border_color); |
||
5772 | leency | 275 | if (!header) OpenPage(); else { WB1.DrawPage(); DrawEditBox(); } |
4692 | leency | 276 | DrawRectangle(scroll_wv.start_x, scroll_wv.start_y, scroll_wv.size_x, scroll_wv.size_y-1, scroll_wv.bckg_col); |
4693 | leency | 277 | DrawProgress(); |
3067 | leency | 278 | } |
279 | |||
280 | |||
5711 | leency | 281 | void Scan(dword id__) |
4413 | leency | 282 | { |
4636 | leency | 283 | action_buf=0; |
5779 | leency | 284 | if (WB1.list.ProcessKey(key_scancode)) WB1.DrawPage(); |
285 | else switch (id__) |
||
4413 | leency | 286 | { |
5711 | leency | 287 | case SCAN_CODE_BS: |
5718 | leency | 288 | case BACK_BUTTON: |
5711 | leency | 289 | if (!BrowserHistory.GoBack()) return; |
290 | OpenPage(); |
||
291 | return; |
||
5718 | leency | 292 | case FORWARD_BUTTON: |
5711 | leency | 293 | if (!BrowserHistory.GoForward()) return; |
294 | OpenPage(); |
||
295 | return; |
||
5718 | leency | 296 | case GOTOURL_BUTTON: |
5772 | leency | 297 | case SCAN_CODE_ENTER: |
298 | if (!strncmp(#editURL,"http:",5)) || (editURL[0]=='/') || (!strncmp(#editURL,"WebView:",9)) |
||
299 | { |
||
300 | strcpy(#URL, #editURL); |
||
301 | } |
||
5711 | leency | 302 | else |
5772 | leency | 303 | { |
304 | strncpy(#URL,"http://",7); |
||
305 | strcat(#URL, #editURL); |
||
306 | } |
||
5711 | leency | 307 | OpenPage(); |
308 | return; |
||
5718 | leency | 309 | case 063: //F5 |
310 | IF(address_box.flags & 0b10) return; |
||
311 | case REFRESH_BUTTON: |
||
5713 | leency | 312 | if (http_transfer > 0) |
313 | { |
||
314 | StopLoading(); |
||
315 | Draw_Window(); |
||
316 | } |
||
317 | else OpenPage(); |
||
318 | return; |
||
5718 | leency | 319 | case SANDWICH_BUTTON: |
320 | mouse.y = TOOLBAR_H-6; |
||
321 | mouse.x = Form.cwidth - 167; |
||
322 | CreateThread(#menu_rmb,#stak+4092); |
||
4415 | leency | 323 | return; |
5718 | leency | 324 | case VIEW_SOURCE: |
325 | WB1.list.first = 0; |
||
326 | ShowSource(); |
||
5773 | leency | 327 | WB1.LoadInternalPage(bufpointer, bufsize); |
5718 | leency | 328 | break; |
329 | case EDIT_SOURCE: |
||
330 | if (!strncmp(#URL,"http:",5)) |
||
331 | { |
||
332 | WriteFile(bufsize, bufpointer, "/tmp0/1/WebView_tmp.htm"); |
||
333 | if (!EAX) RunProgram("/rd/1/tinypad", "/tmp0/1/WebView_tmp.htm"); |
||
334 | } |
||
335 | else RunProgram("/rd/1/tinypad", #URL); |
||
4415 | leency | 336 | return; |
5718 | leency | 337 | case FREE_IMG_CACHE: |
4491 | leency | 338 | ImgCache.Free(); |
4416 | leency | 339 | notify(IMAGES_CACHE_CLEARED); |
5766 | leency | 340 | WB1.DrawPage(); |
4415 | leency | 341 | return; |
5718 | leency | 342 | case VIEW_HISTORY: |
4677 | leency | 343 | strcpy(#URL, URL_SERVICE_HISTORY); |
4544 | leency | 344 | OpenPage(); |
345 | return; |
||
5718 | leency | 346 | case DOWNLOAD_MANAGER: |
5519 | leency | 347 | if (!downloader_opened) { |
5631 | pavelyakov | 348 | strncpy(#DL_URL, "http://",7); |
5519 | leency | 349 | CreateThread(#Downloader,#downloader_stak+4092); |
350 | } |
||
5772 | leency | 351 | return; /* |
4415 | leency | 352 | case 020: |
4413 | leency | 353 | case NEWTAB: |
354 | MoveSize(190,80,OLD,OLD); |
||
355 | RunProgram(#program_path, #URL); |
||
356 | return; |
||
5718 | leency | 357 | case SEARCHWEB_BUTTON: |
5631 | pavelyakov | 358 | sprintf(#URL,"%s%s",#search_path,#editURL); |
4416 | leency | 359 | OpenPage(); |
5772 | leency | 360 | return; */ |
4413 | leency | 361 | } |
362 | } |
||
363 | |||
364 | |||
4636 | leency | 365 | void StopLoading() |
366 | { |
||
5631 | pavelyakov | 367 | if (http_transfer) |
4647 | leency | 368 | { |
369 | EAX = http_transfer; |
||
370 | EAX = EAX.http_msg.content_ptr; // get pointer to data |
||
371 | $push EAX // save it on the stack |
||
372 | http_free stdcall (http_transfer); // abort connection |
||
373 | $pop EAX |
||
5631 | pavelyakov | 374 | free(EAX); // free data |
4647 | leency | 375 | http_transfer=0; |
376 | bufsize = 0; |
||
5631 | pavelyakov | 377 | bufpointer = free(bufpointer); |
4647 | leency | 378 | } |
5519 | leency | 379 | wv_progress_bar.value = 0; |
5718 | leency | 380 | img_draw stdcall(skin.image, address_box.left+address_box.width+1, address_box.top-3, 17, skin.h, 52, 0); |
4645 | leency | 381 | } |
382 | |||
383 | void SetPageDefaults() |
||
384 | { |
||
385 | strcpy(#header, #version); |
||
386 | WB1.list.count = WB1.list.first = 0; |
||
387 | stroka = 0; |
||
5704 | leency | 388 | cur_encoding = CH_NULL; |
4645 | leency | 389 | if (o_bufpointer) o_bufpointer = free(o_bufpointer); |
4636 | leency | 390 | anchor_line_num=WB1.list.first; |
391 | anchor[0]='|'; |
||
392 | } |
||
393 | |||
4416 | leency | 394 | void OpenPage() |
395 | { |
||
4636 | leency | 396 | StopLoading(); |
4718 | leency | 397 | souce_mode = false; |
4416 | leency | 398 | strcpy(#editURL, #URL); |
4687 | leency | 399 | BrowserHistory.AddUrl(); |
5631 | pavelyakov | 400 | if (!strncmp(#URL,"WebView:",8)) |
4692 | leency | 401 | { |
402 | SetPageDefaults(); |
||
5747 | leency | 403 | if (!strcmp(#URL, URL_SERVICE_HOME)) WB1.LoadInternalPage(#homepage, sizeof(homepage)); |
5631 | pavelyakov | 404 | else if (!strcmp(#URL, URL_SERVICE_HISTORY)) ShowHistory(); |
5772 | leency | 405 | DrawEditBox(); |
4692 | leency | 406 | return; |
407 | } |
||
5631 | pavelyakov | 408 | if (!strncmp(#URL,"http:",5)) |
4416 | leency | 409 | { |
5718 | leency | 410 | img_draw stdcall(skin.image, address_box.left+address_box.width+1, address_box.top-3, 17, skin.h, 131, 0); |
5534 | hidnplayr | 411 | http_get stdcall (#URL, 0, 0, #accept_language); |
4636 | leency | 412 | http_transfer = EAX; |
5631 | pavelyakov | 413 | if (!http_transfer) |
4646 | leency | 414 | { |
415 | StopLoading(); |
||
416 | bufsize = 0; |
||
5631 | pavelyakov | 417 | bufpointer = free(bufpointer); |
4646 | leency | 418 | ShowPage(); |
419 | return; |
||
420 | } |
||
4416 | leency | 421 | } |
4636 | leency | 422 | else |
423 | { |
||
424 | file_size stdcall (#URL); |
||
425 | bufsize = EBX; |
||
4650 | leency | 426 | if (bufsize) |
427 | { |
||
5631 | pavelyakov | 428 | free(bufpointer); |
429 | bufpointer = malloc(bufsize); |
||
4650 | leency | 430 | SetPageDefaults(); |
4718 | leency | 431 | ReadFile(0, bufsize, bufpointer, #URL); |
4650 | leency | 432 | } |
4645 | leency | 433 | ShowPage(); |
4636 | leency | 434 | } |
4416 | leency | 435 | } |
4415 | leency | 436 | |
4718 | leency | 437 | DrawEditBox() |
4508 | leency | 438 | { |
5772 | leency | 439 | DrawWideRectangle(address_box.left-2, address_box.top-2, address_box.width+3, 19, 2, address_box.color); |
4718 | leency | 440 | address_box.size = address_box.pos = address_box.shift = address_box.shift_old = strlen(#editURL); |
441 | address_box.offset = 0; |
||
4508 | leency | 442 | edit_box_draw stdcall(#address_box); |
5772 | leency | 443 | if (http_transfer > 0) EAX = 131; else EAX = 52; |
444 | img_draw stdcall(skin.image, address_box.left+address_box.width+1, address_box.top-3, 17, skin.h, EAX, 0); |
||
4718 | leency | 445 | } |
4415 | leency | 446 | |
4718 | leency | 447 | |
448 | void ShowPage() |
||
449 | { |
||
450 | DrawEditBox(); |
||
4540 | leency | 451 | if (!bufsize) |
4508 | leency | 452 | { |
5773 | leency | 453 | if (http_transfer) WB1.LoadInternalPage(#loading, sizeof(loading)); |
454 | else WB1.LoadInternalPage(#page_not_found, sizeof(page_not_found)); |
||
4508 | leency | 455 | } |
456 | else |
||
5768 | leency | 457 | { |
5766 | leency | 458 | WB1.Prepare(); |
5768 | leency | 459 | } |
4415 | leency | 460 | |
5773 | leency | 461 | //if (!header) strcpy(#header, #version); |
4508 | leency | 462 | if (!strcmp(#version, #header)) DrawTitle(#header); |
463 | } |
||
464 | |||
5493 | leency | 465 | byte UrlExtIs(dword ext) |
466 | { |
||
5631 | pavelyakov | 467 | if (!strcmpi(#URL + strlen(#URL) - strlen(ext), ext)) return true; |
468 | return false; |
||
5493 | leency | 469 | } |
4508 | leency | 470 | |
5772 | leency | 471 | int SetSkinColors() |
472 | { |
||
473 | dword image_data; |
||
474 | image_data = DSDWORD[skin.image+24]; |
||
475 | col_bg = DSDWORD[image_data]; |
||
476 | panel_color = DSDWORD[skin.w*4*4 + image_data]; |
||
477 | border_color = DSDWORD[skin.w*4*7 + image_data]; |
||
478 | wv_progress_bar.progress_color = DSDWORD[skin.w*4*10 + image_data]; |
||
479 | $and col_bg, 0x00ffffff |
||
480 | $and panel_color, 0x00ffffff |
||
481 | $and border_color, 0x00ffffff |
||
482 | $and wv_progress_bar.progress_color, 0x00ffffff |
||
483 | } |
||
4544 | leency | 484 | |
5772 | leency | 485 | void DrawProgress() |
486 | { |
||
487 | unsigned long btn; |
||
488 | if (http_transfer == 0) return; |
||
489 | if (wv_progress_bar.max) btn = address_box.width*wv_progress_bar.value/wv_progress_bar.max; else btn = 30; |
||
490 | DrawBar(address_box.left-2, address_box.top+15, btn, 2, wv_progress_bar.progress_color); |
||
491 | } |
||
5746 | leency | 492 | |
5774 | leency | 493 | void ClickLink() |
494 | { |
||
495 | if (http_transfer > 0) |
||
496 | { |
||
497 | StopLoading(); |
||
498 | BrowserHistory.current--; |
||
499 | } |
||
5772 | leency | 500 | |
5774 | leency | 501 | strcpy(#URL, PageLinks.GetURL(PageLinks.active)); |
502 | //#1 |
||
503 | if (URL[0] == '#') |
||
504 | { |
||
505 | strcpy(#anchor, #URL+strrchr(#URL, '#')); |
||
506 | strcpy(#URL, BrowserHistory.CurrentUrl()); |
||
507 | WB1.list.first=WB1.list.count-WB1.list.visible; |
||
508 | ShowPage(); |
||
509 | return; |
||
510 | } |
||
511 | //liner.ru#1 |
||
512 | if (strrchr(#URL, '#')!=-1) |
||
513 | { |
||
514 | strcpy(#anchor, #URL+strrchr(#URL, '#')); |
||
515 | URL[strrchr(#URL, '#')-1] = 0x00; |
||
516 | } |
||
517 | |||
518 | PageLinks.GetAbsoluteURL(#URL); |
||
519 | |||
520 | if (UrlExtIs(".png")==1) || (UrlExtIs(".gif")==1) || (UrlExtIs(".jpg")==1) || (UrlExtIs(".zip")==1) || (UrlExtIs(".kex")==1) |
||
521 | || (UrlExtIs(".7z")==1) || (UrlExtIs("netcfg")==1) |
||
522 | { |
||
523 | //notify(#URL); |
||
524 | if (!strncmp(#URL,"http://", 7)) |
||
525 | { |
||
526 | strcpy(#DL_URL, #URL); |
||
527 | CreateThread(#Downloader,#downloader_stak+4092); |
||
528 | } |
||
529 | else RunProgram("@open", #URL); |
||
530 | strcpy(#editURL, BrowserHistory.CurrentUrl()); |
||
531 | strcpy(#URL, BrowserHistory.CurrentUrl()); |
||
532 | return; |
||
533 | } |
||
534 | if (!strncmp(#URL,"mailto:", 7)) |
||
535 | { |
||
536 | notify(#URL); |
||
537 | strcpy(#editURL, BrowserHistory.CurrentUrl()); |
||
538 | strcpy(#URL, BrowserHistory.CurrentUrl()); |
||
539 | return; |
||
540 | } |
||
541 | OpenPage(); |
||
542 | return; |
||
543 | } |
||
544 | |||
545 | |||
5493 | leency | 546 | char downloader_stak[4096]; |
5631 | pavelyakov | 547 | stop:=5) |