Rev 7720 | Rev 7739 | 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-- |
7606 | leency | 2 | //Copyright 2007-2019 by Veliant & Leency |
6978 | leency | 3 | //Asper, lev, Lrz, Barsuk, Nable, hidnplayr... |
3067 | leency | 4 | |
4085 | leency | 5 | #ifndef AUTOBUILD |
6 | #include "lang.h--" |
||
7 | #endif |
||
8 | |||
3107 | leency | 9 | //libraries |
7738 | leency | 10 | #define MEMSIZE 1024 * 800 |
5499 | leency | 11 | #include "..\lib\gui.h" |
4508 | leency | 12 | #include "..\lib\draw_buf.h" |
13 | #include "..\lib\list_box.h" |
||
14 | #include "..\lib\cursor.h" |
||
5978 | leency | 15 | #include "..\lib\collection.h" |
6795 | leency | 16 | #include "..\lib\random.h" |
7037 | leency | 17 | #include "..\lib\clipboard.h" |
5981 | leency | 18 | |
7437 | leency | 19 | // *.obj libraries |
5499 | leency | 20 | #include "..\lib\obj\box_lib.h" |
7049 | leency | 21 | #include "..\lib\obj\libio.h" |
22 | #include "..\lib\obj\libimg.h" |
||
5499 | leency | 23 | #include "..\lib\obj\http.h" |
5690 | leency | 24 | #include "..\lib\obj\iconv.h" |
5408 | leency | 25 | //useful patterns |
5978 | leency | 26 | #include "..\lib\patterns\history.h" |
6058 | leency | 27 | #include "..\lib\patterns\http_downloader.h" |
5408 | leency | 28 | |
7281 | leency | 29 | _http http = {0, 0, 0, 0, 0, 0, 0}; |
30 | |||
6698 | leency | 31 | char homepage[] = FROM "html\\homepage.htm""\0"; |
4677 | leency | 32 | |
4026 | leency | 33 | #ifdef LANG_RUS |
7738 | leency | 34 | char version[]="Текстовый браузер 1.82"; |
6045 | leency | 35 | ?define IMAGES_CACHE_CLEARED "Кэш картинок очищен" |
36 | ?define T_LAST_SLIDE "Это последний слайд" |
||
37 | char loading[] = "Загрузка страницы... |
||
6698 | leency | 38 | char page_not_found[] = FROM "html\\page_not_found_ru.htm""\0"; |
6045 | leency | 39 | char accept_language[]= "Accept-Language: ru\n"; |
40 | char rmb_menu[] = |
||
41 | "Посмотреть исходник |
||
42 | Редактировать исходник |
||
43 | История |
||
44 | Менеджер загрузок"; |
||
7037 | leency | 45 | char link_menu[] = |
7208 | leency | 46 | "Копировать ссылку |
47 | Скачать содержимое ссылки"; |
||
4026 | leency | 48 | #else |
7738 | leency | 49 | char version[]="Text-based Browser 1.82"; |
6045 | leency | 50 | ?define IMAGES_CACHE_CLEARED "Images cache cleared" |
51 | ?define T_LAST_SLIDE "This slide is the last" |
||
52 | char loading[] = "Loading... |
||
6698 | leency | 53 | char page_not_found[] = FROM "html\\page_not_found_en.htm""\0"; |
6045 | leency | 54 | char accept_language[]= "Accept-Language: en\n"; |
55 | char rmb_menu[] = |
||
56 | "View source |
||
57 | Edit source |
||
58 | History |
||
59 | Download Manager"; |
||
7037 | leency | 60 | char link_menu[] = |
7208 | leency | 61 | "Copy link |
62 | Download link contents"; |
||
4026 | leency | 63 | #endif |
64 | |||
6795 | leency | 65 | |
5773 | leency | 66 | #define URL_SERVICE_HISTORY "WebView://history" |
67 | #define URL_SERVICE_HOME "WebView://home" |
||
68 | #define URL_SERVICE_SOURCE "WebView://source:" |
||
5631 | pavelyakov | 69 | |
3067 | leency | 70 | proc_info Form; |
71 | |||
5772 | leency | 72 | //char search_path[]="http://nigma.ru/index.php?s="; |
4558 | hidnplayr | 73 | int redirected = 0; |
3067 | leency | 74 | |
4074 | leency | 75 | char stak[4096]; |
5640 | pavelyakov | 76 | |
4026 | leency | 77 | int action_buf; |
78 | |||
6731 | leency | 79 | dword TOOLBAR_H = 40; |
5519 | leency | 80 | dword STATUSBAR_H = 15; |
4677 | leency | 81 | |
7425 | leency | 82 | dword col_bg = 0xE3E2E2; |
83 | dword panel_color = 0xE3E2E2; |
||
84 | dword border_color = 0x8C8C8C; |
||
85 | |||
7282 | leency | 86 | bool debug_mode = false; |
87 | bool old_tag_parser_mode = false; |
||
88 | |||
5718 | leency | 89 | progress_bar wv_progress_bar; |
6931 | leency | 90 | bool souce_mode = false; |
91 | bool open_in_a_new_window = false; |
||
4677 | leency | 92 | |
5718 | leency | 93 | enum { |
94 | BACK_BUTTON=1000, |
||
95 | FORWARD_BUTTON, |
||
96 | REFRESH_BUTTON, |
||
97 | GOTOURL_BUTTON, |
||
6795 | leency | 98 | SANDWICH_BUTTON, |
5768 | leency | 99 | VIEW_SOURCE=1100, |
5718 | leency | 100 | EDIT_SOURCE, |
101 | VIEW_HISTORY, |
||
7037 | leency | 102 | //FREE_IMG_CACHE, |
6795 | leency | 103 | DOWNLOAD_MANAGER, |
7282 | leency | 104 | COPY_LINK_URL=1200, |
7208 | leency | 105 | DOWNLOAD_LINK_CONTENTS, |
5718 | leency | 106 | }; |
107 | |||
4411 | leency | 108 | #include "..\TWB\TWB.c" |
4636 | leency | 109 | #include "history.h" |
4718 | leency | 110 | #include "show_src.h" |
6001 | leency | 111 | #include "download_manager.h" |
3067 | leency | 112 | |
4534 | leency | 113 | char editURL[sizeof(URL)]; |
7506 | leency | 114 | edit_box address_box = {250,60,30,0xffffff,0x94AECE,0xffffff,0xffffff,0x10000000,sizeof(URL)-2,#editURL,0,2,19,19}; |
4534 | leency | 115 | |
7428 | leency | 116 | #define SKIN_Y 24 |
4534 | leency | 117 | |
3067 | leency | 118 | void main() |
119 | { |
||
7422 | leency | 120 | int i; |
5626 | leency | 121 | load_dll(boxlib, #box_lib_init,0); |
122 | load_dll(libio, #libio_init,1); |
||
123 | load_dll(libimg, #libimg_init,1); |
||
124 | load_dll(libHTTP, #http_lib_init,1); |
||
5690 | leency | 125 | load_dll(iconv_lib, #iconv_open,0); |
7428 | leency | 126 | Libimg_LoadImage(#skin, "/sys/toolbar.png"); |
7437 | leency | 127 | skin.h = 26; |
7425 | leency | 128 | wv_progress_bar.progress_color = 0x72B7EB; |
5772 | leency | 129 | CreateDir("/tmp0/1/downloads"); |
7521 | leency | 130 | if (param) && (param[0]=='-') && (param[1]=='d') { |
131 | strcpy(#downloader_edit, #param+3); |
||
132 | CreateThread(#Downloader,#downloader_stak+4092); |
||
133 | ExitProcess(); |
||
134 | } |
||
135 | else if (param) strcpy(#URL, #param); else strcpy(#URL, URL_SERVICE_HOME); |
||
6045 | leency | 136 | WB1.list.SetFont(8, 14, 10011000b); |
5779 | leency | 137 | WB1.list.no_selection = true; |
6978 | leency | 138 | SetEventMask(EVM_REDRAW + EVM_KEY + EVM_BUTTON + EVM_MOUSE + EVM_MOUSE_FILTER + EVM_STACK); |
139 | loop() switch(WaitEvent()) |
||
140 | { |
||
141 | case evMouse: |
||
142 | edit_box_mouse stdcall (#address_box); |
||
143 | mouse.get(); |
||
7282 | leency | 144 | if (PageLinks.HoverAndProceed(mouse.x, WB1.list.first + mouse.y)) |
145 | && (bufsize) && (mouse.pkm) && (mouse.up) { |
||
146 | if (WB1.list.MouseOver(mouse.x, mouse.y)) EventShowPageMenu(mouse.x, mouse.y); |
||
147 | break; |
||
6978 | leency | 148 | } |
7282 | leency | 149 | if (WB1.list.MouseScroll(mouse.vert)) WB1.DrawPage(); |
6978 | leency | 150 | scrollbar_v_mouse (#scroll_wv); |
151 | if (WB1.list.first != scroll_wv.position) |
||
152 | { |
||
153 | WB1.list.first = scroll_wv.position; |
||
154 | WB1.DrawPage(); |
||
3067 | leency | 155 | break; |
6978 | leency | 156 | } |
157 | break; |
||
5711 | leency | 158 | |
6978 | leency | 159 | case evButton: |
160 | ProcessEvent(GetButtonID()); |
||
161 | break; |
||
5711 | leency | 162 | |
6978 | leency | 163 | case evKey: |
164 | GetKeys(); |
||
7506 | leency | 165 | if (address_box.flags & ed_focus) |
6978 | leency | 166 | { |
167 | if (key_ascii == ASCII_KEY_ENTER) ProcessEvent(key_scancode); else { |
||
168 | EAX = key_editbox; |
||
169 | edit_box_key stdcall(#address_box); |
||
5530 | leency | 170 | } |
6978 | leency | 171 | } |
172 | else |
||
173 | { |
||
7422 | leency | 174 | #define KEY_SCROLL_N 11 |
175 | if (SCAN_CODE_UP == key_scancode) for (i=0;i |
||
176 | if (SCAN_CODE_DOWN == key_scancode) for (i=0;i |
||
6978 | leency | 177 | if (WB1.list.ProcessKey(key_scancode)) WB1.DrawPage(); |
178 | else ProcessEvent(key_scancode); |
||
179 | } |
||
180 | break; |
||
181 | |||
182 | case evReDraw: |
||
7450 | leency | 183 | if (menu.cur_y) { |
184 | ProcessEvent(menu.cur_y); |
||
185 | menu.cur_y = 0; |
||
6978 | leency | 186 | } |
187 | DefineAndDrawWindow(GetScreenWidth()-800/2-random(80),GetScreenHeight()-600/2-random(80),800,600,0x73,col_bg,0,0); |
||
188 | GetProcessInfo(#Form, SelfInfo); |
||
189 | if (Form.status_window>2) { DrawTitle(#header); break; } |
||
190 | if (Form.height<120) { MoveSize(OLD,OLD,OLD,120); break; } |
||
191 | if (Form.width<280) { MoveSize(OLD,OLD,280,OLD); break; } |
||
192 | Draw_Window(); |
||
193 | break; |
||
194 | |||
195 | case evNetwork: |
||
7281 | leency | 196 | if (http.transfer > 0) { |
197 | http.receive(); |
||
198 | EventUpdateProgressBar(); |
||
199 | if (http.receive_result == 0) { |
||
6978 | leency | 200 | // Handle redirects |
7281 | leency | 201 | if (http.status_code >= 300) && (http.status_code < 400) |
4686 | leency | 202 | { |
6978 | leency | 203 | redirected++; |
7282 | leency | 204 | if (redirected>5) |
4563 | leency | 205 | { |
7282 | leency | 206 | notify("'Too many redirects.' -E"); |
207 | StopLoading(); |
||
4558 | hidnplayr | 208 | } |
4563 | leency | 209 | else |
210 | { |
||
7282 | leency | 211 | http.handle_redirect(); |
212 | http.free(); |
||
213 | GetAbsoluteURL(#http.redirect_url); |
||
214 | history.back(); |
||
215 | strcpy(#editURL, #URL); |
||
216 | DrawEditBoxWebView(); |
||
217 | OpenPage(); |
||
4558 | hidnplayr | 218 | } |
7282 | leency | 219 | break; |
6978 | leency | 220 | } |
7282 | leency | 221 | redirected = 0; |
6978 | leency | 222 | // Loading the page is complete, free resources |
7282 | leency | 223 | history.add(#URL); |
224 | bufpointer = http.content_pointer; |
||
225 | bufsize = http.content_received; |
||
226 | http.free(); |
||
227 | SetPageDefaults(); |
||
228 | ShowPage(); |
||
4536 | leency | 229 | } |
6978 | leency | 230 | } |
231 | } |
||
3067 | leency | 232 | } |
233 | |||
234 | void SetElementSizes() |
||
235 | { |
||
6731 | leency | 236 | address_box.top = TOOLBAR_H/2-10; |
6794 | leency | 237 | basic_line_h = calc(WB1.list.font_h * 130) / 100; |
6731 | leency | 238 | address_box.width = Form.cwidth - address_box.left - 50; |
6803 | leency | 239 | WB1.list.SetSizes(0, TOOLBAR_H, Form.width - 10 - scroll_wv.size_x, |
6794 | leency | 240 | Form.cheight - TOOLBAR_H - STATUSBAR_H, basic_line_h); |
241 | WB1.list.wheel_size = 7 * basic_line_h; |
||
5710 | leency | 242 | WB1.list.column_max = WB1.list.w - scroll_wv.size_x / WB1.list.font_w; |
6794 | leency | 243 | WB1.list.visible = WB1.list.h; |
6045 | leency | 244 | if (WB1.list.w!=WB1.DrawBuf.bufw) { |
7738 | leency | 245 | WB1.DrawBuf.Init(WB1.list.x, WB1.list.y, WB1.list.w, 800*20); |
6698 | leency | 246 | ProcessEvent(REFRESH_BUTTON); |
6045 | leency | 247 | } |
3067 | leency | 248 | } |
249 | |||
5981 | leency | 250 | |
5982 | leency | 251 | |
3067 | leency | 252 | void Draw_Window() |
253 | { |
||
5772 | leency | 254 | DrawBar(0,0, Form.cwidth,TOOLBAR_H-2, panel_color); |
5718 | leency | 255 | DrawBar(0,TOOLBAR_H-2, Form.cwidth,1, 0xD7D0D3); |
4677 | leency | 256 | DrawBar(0,TOOLBAR_H-1, Form.cwidth,1, border_color); |
3067 | leency | 257 | SetElementSizes(); |
6731 | leency | 258 | DrawRectangle(address_box.left-3, address_box.top-3, address_box.width+5, 25,border_color); |
259 | DefineButton(address_box.left-52, address_box.top-2, 24, skin.h-2, BACK_BUTTON+BT_HIDE, 0); |
||
260 | DefineButton(address_box.left-27, address_box.top-2, 24, skin.h-2, FORWARD_BUTTON+BT_HIDE, 0); |
||
7428 | leency | 261 | img_draw stdcall(skin.image, address_box.left-53, address_box.top-3, 51, skin.h, 0, SKIN_Y); |
5718 | leency | 262 | DefineButton(address_box.left+address_box.width+1, address_box.top-3, 16, skin.h-1, REFRESH_BUTTON+BT_HIDE+BT_NOFRAME, 0); |
6731 | leency | 263 | DefineButton(Form.cwidth-27, address_box.top-3, 23, skin.h-1, SANDWICH_BUTTON+BT_HIDE, 0); |
7428 | leency | 264 | img_draw stdcall(skin.image, Form.cwidth-24, address_box.top-3, 17, skin.h, 102, SKIN_Y); |
4677 | leency | 265 | DrawBar(0,Form.cheight - STATUSBAR_H, Form.cwidth,STATUSBAR_H, col_bg); |
266 | DrawBar(0,Form.cheight - STATUSBAR_H, Form.cwidth,1, border_color); |
||
7282 | leency | 267 | if (!header) |
268 | OpenPage(); |
||
269 | else { |
||
270 | WB1.DrawPage(); |
||
271 | DrawEditBoxWebView(); |
||
272 | } |
||
4692 | leency | 273 | DrawRectangle(scroll_wv.start_x, scroll_wv.start_y, scroll_wv.size_x, scroll_wv.size_y-1, scroll_wv.bckg_col); |
4693 | leency | 274 | DrawProgress(); |
3067 | leency | 275 | } |
276 | |||
277 | |||
6698 | leency | 278 | void ProcessEvent(dword id__) |
4413 | leency | 279 | { |
6698 | leency | 280 | switch (id__) |
4413 | leency | 281 | { |
6698 | leency | 282 | case 1: |
283 | ExitProcess(); |
||
284 | return; |
||
5711 | leency | 285 | case SCAN_CODE_BS: |
5718 | leency | 286 | case BACK_BUTTON: |
6021 | leency | 287 | if (history.back()) { |
288 | strcpy(#URL, history.current()); |
||
5978 | leency | 289 | OpenPage(); |
290 | } |
||
5711 | leency | 291 | return; |
5718 | leency | 292 | case FORWARD_BUTTON: |
6021 | leency | 293 | if (history.forward()) { |
294 | strcpy(#URL, history.current()); |
||
5978 | leency | 295 | OpenPage(); |
296 | } |
||
5711 | leency | 297 | return; |
5718 | leency | 298 | case GOTOURL_BUTTON: |
5772 | leency | 299 | case SCAN_CODE_ENTER: |
7282 | leency | 300 | if (!editURL[0]) { |
301 | strcpy(#URL, URL_SERVICE_HOME); |
||
302 | } |
||
303 | else if (!strncmp(#editURL,"http:",5)) || (editURL[0]=='/') |
||
6730 | leency | 304 | || (!strncmp(#editURL,"https:",6)) || (!strncmp(#editURL,"WebView:",8)) |
5772 | leency | 305 | { |
306 | strcpy(#URL, #editURL); |
||
307 | } |
||
5711 | leency | 308 | else |
5772 | leency | 309 | { |
5803 | leency | 310 | strlcpy(#URL,"http://",7); |
5772 | leency | 311 | strcat(#URL, #editURL); |
312 | } |
||
5711 | leency | 313 | OpenPage(); |
314 | return; |
||
5718 | leency | 315 | case REFRESH_BUTTON: |
7281 | leency | 316 | if (http.transfer > 0) |
5713 | leency | 317 | { |
318 | StopLoading(); |
||
319 | Draw_Window(); |
||
320 | } |
||
321 | else OpenPage(); |
||
322 | return; |
||
5718 | leency | 323 | case SANDWICH_BUTTON: |
6795 | leency | 324 | EventShowPageMenu(Form.cwidth - 215, TOOLBAR_H-6); |
4415 | leency | 325 | return; |
5718 | leency | 326 | case VIEW_SOURCE: |
327 | WB1.list.first = 0; |
||
328 | ShowSource(); |
||
5773 | leency | 329 | WB1.LoadInternalPage(bufpointer, bufsize); |
5718 | leency | 330 | break; |
331 | case EDIT_SOURCE: |
||
7282 | leency | 332 | if (!strncmp(#URL,"http",4)) |
5718 | leency | 333 | { |
7227 | leency | 334 | CreateFile(bufsize, bufpointer, "/tmp0/1/WebView_tmp.htm"); |
5718 | leency | 335 | if (!EAX) RunProgram("/rd/1/tinypad", "/tmp0/1/WebView_tmp.htm"); |
336 | } |
||
337 | else RunProgram("/rd/1/tinypad", #URL); |
||
4415 | leency | 338 | return; |
7037 | leency | 339 | // case FREE_IMG_CACHE: |
340 | // ImgCache.Free(); |
||
341 | // notify(IMAGES_CACHE_CLEARED); |
||
342 | // WB1.DrawPage(); |
||
343 | // return; |
||
5718 | leency | 344 | case VIEW_HISTORY: |
4677 | leency | 345 | strcpy(#URL, URL_SERVICE_HISTORY); |
4544 | leency | 346 | OpenPage(); |
347 | return; |
||
5718 | leency | 348 | case DOWNLOAD_MANAGER: |
5519 | leency | 349 | if (!downloader_opened) { |
6001 | leency | 350 | downloader_edit = NULL; |
5519 | leency | 351 | CreateThread(#Downloader,#downloader_stak+4092); |
352 | } |
||
4413 | leency | 353 | return; |
7282 | leency | 354 | case COPY_LINK_URL: |
7037 | leency | 355 | Clipboard__CopyText(PageLinks.GetURL(PageLinks.active)); |
356 | notify("'URL copied to clipboard'O"); |
||
357 | return; |
||
7208 | leency | 358 | case DOWNLOAD_LINK_CONTENTS: |
359 | if (!downloader_opened) { |
||
360 | strcpy(#downloader_edit, PageLinks.GetURL(PageLinks.active)); |
||
361 | CreateThread(#Downloader,#downloader_stak+4092); |
||
362 | } |
||
363 | return; |
||
7282 | leency | 364 | case SCAN_CODE_F12: |
365 | debug_mode ^= 1; |
||
366 | if (debug_mode) notify("'Debug mode ON'-I"); |
||
367 | else notify("'Debug mode OFF'-I"); |
||
368 | return; |
||
369 | case SCAN_CODE_F11: |
||
370 | old_tag_parser_mode ^= 1; |
||
371 | if (old_tag_parser_mode) notify("'Old tag parser ON'-I"); |
||
372 | else notify("'Old tag parser OFF'-I"); |
||
373 | return; |
||
4413 | leency | 374 | } |
375 | } |
||
376 | |||
4636 | leency | 377 | void StopLoading() |
378 | { |
||
7281 | leency | 379 | if (http.transfer) |
4647 | leency | 380 | { |
7281 | leency | 381 | EAX = http.transfer; |
4647 | leency | 382 | EAX = EAX.http_msg.content_ptr; // get pointer to data |
383 | $push EAX // save it on the stack |
||
7281 | leency | 384 | http_free stdcall (http.transfer); // abort connection |
4647 | leency | 385 | $pop EAX |
5631 | pavelyakov | 386 | free(EAX); // free data |
7281 | leency | 387 | http.transfer=0; |
4647 | leency | 388 | bufsize = 0; |
5631 | pavelyakov | 389 | bufpointer = free(bufpointer); |
4647 | leency | 390 | } |
5519 | leency | 391 | wv_progress_bar.value = 0; |
6731 | leency | 392 | DrawEditBoxWebView(); |
4645 | leency | 393 | } |
394 | |||
395 | void SetPageDefaults() |
||
396 | { |
||
397 | strcpy(#header, #version); |
||
398 | WB1.list.count = WB1.list.first = 0; |
||
5704 | leency | 399 | cur_encoding = CH_NULL; |
4645 | leency | 400 | if (o_bufpointer) o_bufpointer = free(o_bufpointer); |
4636 | leency | 401 | } |
402 | |||
7720 | leency | 403 | void ReplaceSpaceInUrl() { |
404 | int i; |
||
405 | strcpy(#editURL, #URL); |
||
406 | while (i = strchr(#URL, ' ')) |
||
407 | { |
||
408 | i -= #URL; |
||
409 | strlcpy(#URL+i+3, #editURL+i+1, sizeof(URL)-i-4); |
||
410 | URL[i] = '%'; |
||
411 | URL[i+1] = '2'; |
||
412 | URL[i+2] = '0'; |
||
413 | } |
||
414 | strcpy(#editURL, #URL); |
||
415 | } |
||
416 | |||
4416 | leency | 417 | void OpenPage() |
418 | { |
||
7282 | leency | 419 | char getUrl[sizeof(URL)]; |
4636 | leency | 420 | StopLoading(); |
4718 | leency | 421 | souce_mode = false; |
4416 | leency | 422 | strcpy(#editURL, #URL); |
6021 | leency | 423 | history.add(#URL); |
5631 | pavelyakov | 424 | if (!strncmp(#URL,"WebView:",8)) |
4692 | leency | 425 | { |
426 | SetPageDefaults(); |
||
5747 | leency | 427 | if (!strcmp(#URL, URL_SERVICE_HOME)) WB1.LoadInternalPage(#homepage, sizeof(homepage)); |
5631 | pavelyakov | 428 | else if (!strcmp(#URL, URL_SERVICE_HISTORY)) ShowHistory(); |
6278 | leency | 429 | DrawEditBoxWebView(); |
4692 | leency | 430 | return; |
431 | } |
||
7282 | leency | 432 | if (!strncmp(#URL,"http:",5)) || (!strncmp(#URL,"https://",8)) |
4416 | leency | 433 | { |
7720 | leency | 434 | ReplaceSpaceInUrl(); |
7428 | leency | 435 | img_draw stdcall(skin.image, address_box.left+address_box.width+1, address_box.top-3, 17, skin.h, 68, SKIN_Y); |
7282 | leency | 436 | |
437 | if (!strncmp(#URL,"http:",5)) { |
||
438 | http.get(#URL); |
||
439 | } |
||
440 | if (!strncmp(#URL,"https://",8)) { |
||
441 | sprintf(#getUrl, "http://gate.aspero.pro/?site=%s", #URL); |
||
442 | http.get(#getUrl); |
||
443 | } |
||
444 | //http.get(#URL); |
||
7281 | leency | 445 | if (!http.transfer) |
4646 | leency | 446 | { |
447 | StopLoading(); |
||
448 | bufsize = 0; |
||
5631 | pavelyakov | 449 | bufpointer = free(bufpointer); |
4646 | leency | 450 | ShowPage(); |
451 | return; |
||
452 | } |
||
4416 | leency | 453 | } |
4636 | leency | 454 | else |
455 | { |
||
456 | file_size stdcall (#URL); |
||
457 | bufsize = EBX; |
||
4650 | leency | 458 | if (bufsize) |
459 | { |
||
5631 | pavelyakov | 460 | free(bufpointer); |
461 | bufpointer = malloc(bufsize); |
||
4650 | leency | 462 | SetPageDefaults(); |
4718 | leency | 463 | ReadFile(0, bufsize, bufpointer, #URL); |
4650 | leency | 464 | } |
4645 | leency | 465 | ShowPage(); |
4636 | leency | 466 | } |
4416 | leency | 467 | } |
4415 | leency | 468 | |
6278 | leency | 469 | DrawEditBoxWebView() |
4508 | leency | 470 | { |
7428 | leency | 471 | int skin_x_offset; |
6731 | leency | 472 | DrawBar(address_box.left-2, address_box.top-2, address_box.width+3, 2, address_box.color); |
473 | DrawBar(address_box.left-2, address_box.top, 2, 22, address_box.color); |
||
7506 | leency | 474 | //address_box.size = address_box.pos = address_box.shift = address_box.shift_old = strlen(#editURL); |
475 | //address_box.offset = 0; |
||
476 | EditBox_UpdateText(#address_box, address_box.flags); |
||
4508 | leency | 477 | edit_box_draw stdcall(#address_box); |
7428 | leency | 478 | if (http.transfer > 0) skin_x_offset = 68; else skin_x_offset = 51; |
479 | img_draw stdcall(skin.image, address_box.left+address_box.width+1, address_box.top-3, 17, skin.h, skin_x_offset, SKIN_Y); |
||
4718 | leency | 480 | } |
4415 | leency | 481 | |
4718 | leency | 482 | |
483 | void ShowPage() |
||
484 | { |
||
6278 | leency | 485 | DrawEditBoxWebView(); |
4540 | leency | 486 | if (!bufsize) |
4508 | leency | 487 | { |
7281 | leency | 488 | if (http.transfer) WB1.LoadInternalPage(#loading, sizeof(loading)); |
5773 | leency | 489 | else WB1.LoadInternalPage(#page_not_found, sizeof(page_not_found)); |
4508 | leency | 490 | } |
491 | else |
||
5768 | leency | 492 | { |
5766 | leency | 493 | WB1.Prepare(); |
5768 | leency | 494 | } |
4508 | leency | 495 | } |
496 | |||
5493 | leency | 497 | byte UrlExtIs(dword ext) |
498 | { |
||
5631 | pavelyakov | 499 | if (!strcmpi(#URL + strlen(#URL) - strlen(ext), ext)) return true; |
500 | return false; |
||
5493 | leency | 501 | } |
4508 | leency | 502 | |
5772 | leency | 503 | void DrawProgress() |
504 | { |
||
7282 | leency | 505 | dword persent; |
7281 | leency | 506 | if (http.transfer == 0) return; |
7282 | leency | 507 | if (wv_progress_bar.max) persent = wv_progress_bar.value*100/wv_progress_bar.max; else persent = 10; |
508 | DrawBar(address_box.left-2, address_box.top+20, persent*address_box.width/100, 2, wv_progress_bar.progress_color); |
||
5772 | leency | 509 | } |
5746 | leency | 510 | |
6931 | leency | 511 | |
6803 | leency | 512 | char anchor[256]; |
5774 | leency | 513 | void ClickLink() |
514 | { |
||
7281 | leency | 515 | if (http.transfer > 0) |
5774 | leency | 516 | { |
517 | StopLoading(); |
||
6021 | leency | 518 | history.back(); |
5774 | leency | 519 | } |
7282 | leency | 520 | strcpy(#URL, PageLinks.GetURL(PageLinks.active)); |
7720 | leency | 521 | ReplaceSpaceInUrl(); |
5774 | leency | 522 | //#1 |
523 | if (URL[0] == '#') |
||
524 | { |
||
6730 | leency | 525 | if (URL[1] == NULL) { |
526 | WB1.list.first = 0; |
||
527 | } |
||
528 | else { |
||
7738 | leency | 529 | if (anchors.get_anchor_pos(#URL+1)!=-1) WB1.list.first = anchors.get_anchor_pos(#URL+1); |
6730 | leency | 530 | } |
7738 | leency | 531 | strlcpy(#anchor, #URL, sizeof(anchor)); |
532 | strcpy(#URL, history.current()); |
||
533 | strcpy(#editURL, #URL); |
||
534 | strcat(#editURL, #anchor); |
||
535 | DrawEditBoxWebView(); |
||
536 | WB1.DrawPage(); |
||
5774 | leency | 537 | return; |
538 | } |
||
539 | //liner.ru#1 |
||
6730 | leency | 540 | if (strrchr(#URL, '#')!=0) |
5774 | leency | 541 | { |
6803 | leency | 542 | strlcpy(#anchor, #URL+strrchr(#URL, '#'), sizeof(anchor)); |
5774 | leency | 543 | URL[strrchr(#URL, '#')-1] = 0x00; |
544 | } |
||
6730 | leency | 545 | |
546 | if (!strncmp(#URL,"mailto:", 7)) |
||
547 | { |
||
548 | notify(#URL); |
||
549 | strcpy(#editURL, history.current()); |
||
550 | strcpy(#URL, history.current()); |
||
551 | return; |
||
552 | } |
||
553 | |||
5990 | leency | 554 | GetAbsoluteURL(#URL); |
6730 | leency | 555 | |
7282 | leency | 556 | if (strncmp(#URL,"http://",7)!=0) && (strncmp(#URL,"https://",8)!=0) |
5774 | leency | 557 | { |
6730 | leency | 558 | if (UrlExtIs(".htm")!=true) && (UrlExtIs(".html")!=true) |
559 | { |
||
7422 | leency | 560 | if (strchr(#URL, '|')) { |
561 | ESBYTE[strchr(#URL, '|')] = NULL; |
||
562 | RunProgram(#URL, strlen(#URL)+1+#URL); |
||
563 | } |
||
564 | else { |
||
565 | RunProgram("/sys/@open", #URL); |
||
566 | } |
||
6730 | leency | 567 | strcpy(#editURL, history.current()); |
568 | strcpy(#URL, history.current()); |
||
569 | return; |
||
570 | } |
||
571 | } |
||
572 | else |
||
573 | { |
||
574 | if (UrlExtIs(".png")==true) || (UrlExtIs(".gif")==true) || (UrlExtIs(".jpg")==true) |
||
6794 | leency | 575 | || (UrlExtIs(".zip")==true) || (UrlExtIs(".kex")==true) || (UrlExtIs(".pdf")==true) |
576 | || (UrlExtIs(".7z")==true) { |
||
6986 | leency | 577 | if (!downloader_opened) { |
578 | strcpy(#downloader_edit, #URL); |
||
579 | CreateThread(#Downloader,#downloader_stak+4092); |
||
580 | strcpy(#editURL, history.current()); |
||
581 | strcpy(#URL, history.current()); |
||
582 | } |
||
583 | else notify("'WebView\nPlease, start a new download only when previous ended.'Et"); |
||
6730 | leency | 584 | return; |
5774 | leency | 585 | } |
586 | } |
||
6931 | leency | 587 | if (open_in_a_new_window) |
588 | { |
||
589 | RunProgram(#program_path, #URL); |
||
590 | strcpy(#editURL, history.current()); |
||
591 | strcpy(#URL, history.current()); |
||
592 | } |
||
593 | else |
||
594 | { |
||
595 | OpenPage(); |
||
596 | } |
||
597 | open_in_a_new_window = false; |
||
5774 | leency | 598 | } |
599 | |||
6795 | leency | 600 | void EventShowPageMenu(dword _left, _top) |
6782 | leency | 601 | { |
602 | menu.show(Form.left+_left-6,Form.top+_top+skin_height+3, 220, #rmb_menu, VIEW_SOURCE); |
||
603 | } |
||
604 | |||
6795 | leency | 605 | void EventShowLinkMenu(dword _left, _top) |
606 | { |
||
7282 | leency | 607 | menu.show(Form.left+_left-6,Form.top+_top+skin_height+3, 220, #link_menu, COPY_LINK_URL); |
6795 | leency | 608 | } |
609 | |||
7281 | leency | 610 | void EventUpdateProgressBar() |
611 | { |
||
612 | wv_progress_bar.max = http.content_length; |
||
613 | if (wv_progress_bar.value != http.content_received) |
||
614 | { |
||
615 | wv_progress_bar.value = http.content_received; |
||
616 | DrawProgress(); |
||
617 | } |
||
618 | } |
||
6795 | leency | 619 | |
620 | DrawStatusBar(dword _status_text) |
||
621 | { |
||
622 | status_text.start_x = wv_progress_bar.left + wv_progress_bar.width + 10; |
||
623 | status_text.start_y = Form.cheight - STATUSBAR_H + 3; |
||
624 | status_text.area_size_x = Form.cwidth - status_text.start_x -3; |
||
625 | DrawBar(status_text.start_x, status_text.start_y, status_text.area_size_x, 9, col_bg); |
||
626 | status_text.text_pointer = _status_text; |
||
627 | PathShow_prepare stdcall(#status_text); |
||
628 | PathShow_draw stdcall(#status_text); |
||
629 | } |
||
630 | |||
5631 | pavelyakov | 631 | stop:>280)>120)> |