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