Rev 7765 | Rev 7770 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
7739 | leency | 1 | //Copyright 2007-2020 by Veliant & Leency |
6978 | leency | 2 | //Asper, lev, Lrz, Barsuk, Nable, hidnplayr... |
3067 | leency | 3 | |
4085 | leency | 4 | #ifndef AUTOBUILD |
5 | #include "lang.h--" |
||
6 | #endif |
||
7 | |||
3107 | leency | 8 | //libraries |
7755 | leency | 9 | #define MEMSIZE 1024 * 850 |
5499 | leency | 10 | #include "..\lib\gui.h" |
4508 | leency | 11 | #include "..\lib\draw_buf.h" |
12 | #include "..\lib\list_box.h" |
||
13 | #include "..\lib\cursor.h" |
||
5978 | leency | 14 | #include "..\lib\collection.h" |
6795 | leency | 15 | #include "..\lib\random.h" |
7037 | leency | 16 | #include "..\lib\clipboard.h" |
5981 | leency | 17 | |
7437 | leency | 18 | // *.obj libraries |
5499 | leency | 19 | #include "..\lib\obj\box_lib.h" |
7049 | leency | 20 | #include "..\lib\obj\libio.h" |
21 | #include "..\lib\obj\libimg.h" |
||
5499 | leency | 22 | #include "..\lib\obj\http.h" |
5690 | leency | 23 | #include "..\lib\obj\iconv.h" |
7748 | leency | 24 | #include "..\lib\obj\proc_lib.h" |
7757 | leency | 25 | |
5408 | leency | 26 | //useful patterns |
5978 | leency | 27 | #include "..\lib\patterns\history.h" |
6058 | leency | 28 | #include "..\lib\patterns\http_downloader.h" |
7748 | leency | 29 | #include "..\lib\patterns\simple_open_dialog.h" |
7759 | leency | 30 | #include "..\lib\patterns\toolbar_button.h" |
5408 | leency | 31 | |
7757 | leency | 32 | #include "show_src.h" |
33 | #include "download_manager.h" |
||
34 | _history history; |
||
35 | #include "history.h" |
||
36 | bool debug_mode = false; |
||
7759 | leency | 37 | #include "..\TWB\TWB.c" //HTML Parser, a core component |
7762 | leency | 38 | #include "texts.h" |
7764 | leency | 39 | #include "cache.h" |
7757 | leency | 40 | |
7759 | leency | 41 | TWebBrowser WB1; |
7758 | leency | 42 | |
7756 | leency | 43 | #define URL_SIZE 4000 |
7752 | leency | 44 | |
7758 | leency | 45 | #define PADDING 9 |
46 | #define SKIN_Y 24 |
||
47 | #define TSZE 25 |
||
48 | dword TOOLBAR_H = PADDING+TSZE+PADDING+2; |
||
5519 | leency | 49 | dword STATUSBAR_H = 15; |
4677 | leency | 50 | |
7750 | leency | 51 | int action_buf; |
7425 | leency | 52 | |
7759 | leency | 53 | _http http = 0; |
7758 | leency | 54 | |
7750 | leency | 55 | bool source_mode = false; |
7282 | leency | 56 | |
5718 | leency | 57 | progress_bar wv_progress_bar; |
7750 | leency | 58 | char stak[4096]; |
59 | proc_info Form; |
||
7748 | leency | 60 | |
5718 | leency | 61 | enum { |
7759 | leency | 62 | ENCODINGS=900, |
5718 | leency | 63 | BACK_BUTTON=1000, |
64 | FORWARD_BUTTON, |
||
65 | REFRESH_BUTTON, |
||
66 | GOTOURL_BUTTON, |
||
7759 | leency | 67 | CHANGE_ENCODING, |
6795 | leency | 68 | SANDWICH_BUTTON, |
7750 | leency | 69 | VIEW_SOURCE, |
5718 | leency | 70 | EDIT_SOURCE, |
7758 | leency | 71 | OPEN_FILE, |
72 | NEW_WINDOW, |
||
5718 | leency | 73 | VIEW_HISTORY, |
6795 | leency | 74 | DOWNLOAD_MANAGER, |
7765 | leency | 75 | UPDATE_BROWSER, |
7750 | leency | 76 | COPY_LINK_URL, |
7208 | leency | 77 | DOWNLOAD_LINK_CONTENTS, |
5718 | leency | 78 | }; |
79 | |||
7748 | leency | 80 | char default_dir[] = "/rd/1"; |
81 | od_filter filter2 = { 16, "TXT\0HTM\0HTML\0\0" }; |
||
82 | |||
7755 | leency | 83 | char editURL[URL_SIZE+1]; |
7758 | leency | 84 | edit_box address_box = {, PADDING+TSZE*2+PADDING+6, PADDING+3, 0xffffff, |
85 | 0x94AECE, 0xffffff, 0xffffff,0x10000000,URL_SIZE-2,#editURL,0,,19,19}; |
||
4534 | leency | 86 | |
87 | |||
7748 | leency | 88 | void LoadLibraries() |
89 | { |
||
90 | load_dll(boxlib, #box_lib_init,0); |
||
91 | load_dll(libio, #libio_init,1); |
||
92 | load_dll(libimg, #libimg_init,1); |
||
93 | load_dll(libHTTP, #http_lib_init,1); |
||
94 | load_dll(iconv_lib, #iconv_open,0); |
||
95 | load_dll(Proc_lib, #OpenDialog_init,0); |
||
96 | OpenDialog_init stdcall (#o_dialog); |
||
97 | } |
||
98 | |||
99 | void HandleParam() |
||
100 | { |
||
101 | if (param) { |
||
7765 | leency | 102 | if (!strncmp(#param, "-download_and_exit ", 19)) { |
103 | download_and_exit = true; |
||
104 | strcpy(#downloader_edit, #param+19); |
||
105 | Downloader(); |
||
7748 | leency | 106 | ExitProcess(); |
7765 | leency | 107 | } else if (!strncmp(#param, "-download ", 10)) { |
108 | strcpy(#downloader_edit, #param+10); |
||
109 | //CreateThread(#Downloader,#downloader_stak+4092); |
||
110 | Downloader(); |
||
111 | ExitProcess(); |
||
112 | } else if (!strncmp(#param, "-source ", 8)) { |
||
7750 | leency | 113 | source_mode = true; |
7765 | leency | 114 | history.add(#param + 8); |
7748 | leency | 115 | } else { |
7755 | leency | 116 | history.add(#param); |
7748 | leency | 117 | } |
118 | } else { |
||
7755 | leency | 119 | history.add(URL_SERVICE_HOMEPAGE); |
7748 | leency | 120 | } |
121 | } |
||
122 | |||
3067 | leency | 123 | void main() |
124 | { |
||
7758 | leency | 125 | int i, btn, redirect_count=0; |
7748 | leency | 126 | LoadLibraries(); |
7762 | leency | 127 | CreateDir("/tmp0/1/Downloads"); |
7764 | leency | 128 | //CreateDir("/tmp0/1/WebView_Cache"); |
7428 | leency | 129 | Libimg_LoadImage(#skin, "/sys/toolbar.png"); |
7748 | leency | 130 | HandleParam(); |
7437 | leency | 131 | skin.h = 26; |
6045 | leency | 132 | WB1.list.SetFont(8, 14, 10011000b); |
5779 | leency | 133 | WB1.list.no_selection = true; |
7759 | leency | 134 | WB1.custom_encoding = -1; |
6978 | leency | 135 | SetEventMask(EVM_REDRAW + EVM_KEY + EVM_BUTTON + EVM_MOUSE + EVM_MOUSE_FILTER + EVM_STACK); |
136 | loop() switch(WaitEvent()) |
||
137 | { |
||
138 | case evMouse: |
||
139 | edit_box_mouse stdcall (#address_box); |
||
140 | mouse.get(); |
||
7757 | leency | 141 | if (PageLinks.HoverAndProceed(mouse.x, WB1.list.first + mouse.y, WB1.list.y, WB1.list.first)) |
7755 | leency | 142 | && (mouse.pkm) && (mouse.up) { |
7282 | leency | 143 | if (WB1.list.MouseOver(mouse.x, mouse.y)) EventShowPageMenu(mouse.x, mouse.y); |
144 | break; |
||
6978 | leency | 145 | } |
7282 | leency | 146 | if (WB1.list.MouseScroll(mouse.vert)) WB1.DrawPage(); |
6978 | leency | 147 | scrollbar_v_mouse (#scroll_wv); |
148 | if (WB1.list.first != scroll_wv.position) |
||
149 | { |
||
150 | WB1.list.first = scroll_wv.position; |
||
151 | WB1.DrawPage(); |
||
3067 | leency | 152 | break; |
6978 | leency | 153 | } |
7758 | leency | 154 | if (mouse.up) && (! address_box.flags & ed_focus) && (address_box.flags & ed_shift_bac) |
155 | { |
||
156 | DrawOmnibox(); //reset text selection |
||
157 | } |
||
6978 | leency | 158 | break; |
5711 | leency | 159 | |
6978 | leency | 160 | case evButton: |
7758 | leency | 161 | btn = GetButtonID(); |
162 | if (1==btn) ExitProcess(); else ProcessEvent(btn); |
||
6978 | leency | 163 | break; |
5711 | leency | 164 | |
6978 | leency | 165 | case evKey: |
166 | GetKeys(); |
||
7742 | leency | 167 | if (key_modifier&KEY_LCTRL) || (key_modifier&KEY_RCTRL) { |
7752 | leency | 168 | if (key_scancode == SCAN_CODE_KEY_O) {EventOpenDialog();break;} |
169 | if (key_scancode == SCAN_CODE_KEY_H) {ProcessEvent(VIEW_HISTORY);break;} |
||
170 | if (key_scancode == SCAN_CODE_KEY_U) {EventViewSource();break;} |
||
7742 | leency | 171 | if (key_scancode == SCAN_CODE_KEY_T) |
7752 | leency | 172 | || (key_scancode == SCAN_CODE_KEY_N) {RunProgram(#program_path, NULL);break;} |
173 | if (key_scancode == SCAN_CODE_KEY_J) {ProcessEvent(DOWNLOAD_MANAGER);break;} |
||
174 | if (key_scancode == SCAN_CODE_KEY_R) {ProcessEvent(REFRESH_BUTTON);break;} |
||
175 | if (key_scancode == SCAN_CODE_ENTER) {EventSeachWeb();break;} |
||
176 | if (key_scancode == SCAN_CODE_LEFT) {ProcessEvent(BACK_BUTTON);break;} |
||
177 | if (key_scancode == SCAN_CODE_RIGHT) {ProcessEvent(FORWARD_BUTTON);break;} |
||
178 | if (key_scancode == SCAN_CODE_KEY_W) {ExitProcess();break;} |
||
7742 | leency | 179 | } |
7743 | leency | 180 | |
181 | if (key_scancode == SCAN_CODE_F5) ProcessEvent(REFRESH_BUTTON); |
||
182 | |||
7506 | leency | 183 | if (address_box.flags & ed_focus) |
6978 | leency | 184 | { |
7742 | leency | 185 | if (key_scancode == SCAN_CODE_ENTER) { |
186 | ProcessEvent(key_scancode); |
||
187 | } |
||
188 | else { |
||
6978 | leency | 189 | EAX = key_editbox; |
190 | edit_box_key stdcall(#address_box); |
||
5530 | leency | 191 | } |
6978 | leency | 192 | } |
193 | else |
||
194 | { |
||
7422 | leency | 195 | #define KEY_SCROLL_N 11 |
196 | if (SCAN_CODE_UP == key_scancode) for (i=0;i |
||
197 | if (SCAN_CODE_DOWN == key_scancode) for (i=0;i |
||
7743 | leency | 198 | if (key_scancode == SCAN_CODE_F6) {address_box.flags=ed_focus; DrawOmnibox();} |
6978 | leency | 199 | if (WB1.list.ProcessKey(key_scancode)) WB1.DrawPage(); |
200 | else ProcessEvent(key_scancode); |
||
201 | } |
||
202 | break; |
||
203 | |||
204 | case evReDraw: |
||
7450 | leency | 205 | if (menu.cur_y) { |
206 | ProcessEvent(menu.cur_y); |
||
207 | menu.cur_y = 0; |
||
6978 | leency | 208 | } |
7755 | leency | 209 | DefineAndDrawWindow(GetScreenWidth()-800/2-random(80), |
210 | GetScreenHeight()-700/2-random(80),800,700,0x73,0,0,0); |
||
6978 | leency | 211 | GetProcessInfo(#Form, SelfInfo); |
7748 | leency | 212 | system.color.get(); |
7759 | leency | 213 | if (Form.status_window>2) break; |
6978 | leency | 214 | if (Form.height<120) { MoveSize(OLD,OLD,OLD,120); break; } |
215 | if (Form.width<280) { MoveSize(OLD,OLD,280,OLD); break; } |
||
7748 | leency | 216 | draw_window(); |
6978 | leency | 217 | break; |
218 | |||
219 | case evNetwork: |
||
7758 | leency | 220 | if (http.transfer <= 0) break; |
221 | http.receive(); |
||
222 | EventUpdateProgressBar(); |
||
223 | if (http.receive_result != 0) break; |
||
224 | if (http.status_code >= 300) && (http.status_code < 400) |
||
225 | { |
||
226 | // Handle redirects |
||
227 | if (redirect_count<=5) { |
||
228 | redirect_count++; |
||
229 | http.handle_redirect(); |
||
7282 | leency | 230 | http.free(); |
7758 | leency | 231 | GetAbsoluteURL(#http.redirect_url, history.current()); |
232 | history.back(); |
||
233 | OpenPage(#http.redirect_url); |
||
234 | } else { |
||
235 | notify("'Too many redirects.' -E"); |
||
236 | StopLoading(); |
||
4536 | leency | 237 | } |
7758 | leency | 238 | } else { |
239 | // Loading the page is complete, free resources |
||
240 | redirect_count = 0; |
||
241 | http.free(); |
||
7764 | leency | 242 | pages_cache.add(history.current(), http.content_pointer, http.content_received); |
7758 | leency | 243 | LoadInternalPage(http.content_pointer, http.content_received); |
6978 | leency | 244 | } |
245 | } |
||
3067 | leency | 246 | } |
247 | |||
248 | void SetElementSizes() |
||
249 | { |
||
7758 | leency | 250 | address_box.width = Form.cwidth - address_box.left - 52 - 16; |
6803 | leency | 251 | WB1.list.SetSizes(0, TOOLBAR_H, Form.width - 10 - scroll_wv.size_x, |
7759 | leency | 252 | Form.cheight - TOOLBAR_H - STATUSBAR_H, BASIC_LINE_H); |
253 | WB1.list.wheel_size = 7 * BASIC_LINE_H; |
||
7746 | leency | 254 | WB1.list.column_max = WB1.list.w - scroll_wv.size_x / WB1.list.font_w + 1; |
6794 | leency | 255 | WB1.list.visible = WB1.list.h; |
3067 | leency | 256 | } |
257 | |||
5981 | leency | 258 | |
7748 | leency | 259 | void draw_window() |
3067 | leency | 260 | { |
7758 | leency | 261 | int i; |
3067 | leency | 262 | SetElementSizes(); |
7758 | leency | 263 | |
264 | DrawBar(0,0, Form.cwidth,PADDING, system.color.work); |
||
265 | DrawBar(0,PADDING+TSZE+1, Form.cwidth,PADDING-1, system.color.work); |
||
266 | DrawBar(0,TOOLBAR_H-2, Form.cwidth,1, system.color.work_dark); |
||
267 | DrawBar(0,TOOLBAR_H-1, Form.cwidth,1, system.color.work_graph); |
||
268 | DrawBar(0, PADDING, address_box.left-2, TSZE+1, system.color.work); |
||
269 | DrawBar(address_box.left+address_box.width+18, PADDING, Form.cwidth-address_box.left-address_box.width-18, TSZE+1, system.color.work); |
||
270 | |||
7759 | leency | 271 | DrawTopPanelButton(BACK_BUTTON, PADDING-1, PADDING, 30); |
272 | DrawTopPanelButton(FORWARD_BUTTON, PADDING+TSZE+PADDING-2, PADDING, 31); |
||
273 | DrawTopPanelButton(SANDWICH_BUTTON, Form.cwidth-PADDING-TSZE-3, PADDING, -1); |
||
7758 | leency | 274 | for (i=0; i<=2; i++) DrawBar(Form.cwidth-PADDING-TSZE+3, i*5+PADDING+7, 15, 3, system.color.work_graph); |
275 | |||
276 | DrawBar(0,Form.cheight - STATUSBAR_H, Form.cwidth,1, system.color.work_graph); |
||
277 | |||
278 | DrawRectangle(WB1.list.x + WB1.list.w, WB1.list.y, scroll_wv.size_x, |
||
279 | WB1.list.h-1, scroll_wv.bckg_col); |
||
280 | |||
281 | if (WB1.list.w!=WB1.DrawBuf.bufw) { |
||
282 | WB1.DrawBuf.Init(WB1.list.x, WB1.list.y, WB1.list.w, 400*20); |
||
283 | if (!strncmp(history.current(),"http",4)) { |
||
7759 | leency | 284 | //nihuya ne izyashnoe reshenie, no pust' poka butet tak |
7758 | leency | 285 | i=source_mode; |
286 | LoadInternalPage(#loading_text, sizeof(loading_text)); |
||
287 | source_mode=i; |
||
288 | } |
||
289 | OpenPage(history.current()); |
||
7757 | leency | 290 | } else { |
7282 | leency | 291 | WB1.DrawPage(); |
7743 | leency | 292 | DrawOmnibox(); |
7282 | leency | 293 | } |
4693 | leency | 294 | DrawProgress(); |
7759 | leency | 295 | DrawStatusBar(NULL); |
3067 | leency | 296 | } |
297 | |||
7759 | leency | 298 | void EventChangeEncodingAndLoadPage(int _new_encoding) |
299 | { |
||
300 | dword newbuf, newsize; |
||
301 | WB1.custom_encoding = _new_encoding; |
||
302 | newsize = strlen(WB1.o_bufpointer); |
||
303 | newbuf = malloc(newsize); |
||
304 | memmov(newbuf, WB1.o_bufpointer, newsize); |
||
305 | LoadInternalPage(newbuf, newsize); |
||
306 | free(newbuf); |
||
307 | } |
||
3067 | leency | 308 | |
7759 | leency | 309 | |
6698 | leency | 310 | void ProcessEvent(dword id__) |
4413 | leency | 311 | { |
6698 | leency | 312 | switch (id__) |
4413 | leency | 313 | { |
7759 | leency | 314 | case ENCODINGS...ENCODINGS+6: |
315 | EventChangeEncodingAndLoadPage(id__-ENCODINGS); |
||
316 | return; |
||
7758 | leency | 317 | case NEW_WINDOW: |
318 | RunProgram(#program_path, NULL); |
||
6698 | leency | 319 | return; |
5711 | leency | 320 | case SCAN_CODE_BS: |
5718 | leency | 321 | case BACK_BUTTON: |
6021 | leency | 322 | if (history.back()) { |
7755 | leency | 323 | OpenPage(history.current()); |
5978 | leency | 324 | } |
5711 | leency | 325 | return; |
5718 | leency | 326 | case FORWARD_BUTTON: |
6021 | leency | 327 | if (history.forward()) { |
7755 | leency | 328 | OpenPage(history.current()); |
5978 | leency | 329 | } |
5711 | leency | 330 | return; |
5718 | leency | 331 | case GOTOURL_BUTTON: |
5772 | leency | 332 | case SCAN_CODE_ENTER: |
7742 | leency | 333 | EventSubmitOmnibox(); |
5711 | leency | 334 | return; |
5718 | leency | 335 | case REFRESH_BUTTON: |
7755 | leency | 336 | if (http.transfer > 0) { |
5713 | leency | 337 | StopLoading(); |
7748 | leency | 338 | draw_window(); |
7755 | leency | 339 | } else { |
340 | OpenPage(history.current()); |
||
5713 | leency | 341 | } |
342 | return; |
||
7759 | leency | 343 | case CHANGE_ENCODING: |
344 | EventShowEncodingsList(Form.cwidth - 150, status_text.start_y-117); |
||
345 | return; |
||
5718 | leency | 346 | case SANDWICH_BUTTON: |
7758 | leency | 347 | EventShowMainMenu(Form.cwidth - 215, TOOLBAR_H-6); |
4415 | leency | 348 | return; |
5718 | leency | 349 | case VIEW_SOURCE: |
7750 | leency | 350 | EventViewSource(); |
5718 | leency | 351 | break; |
352 | case EDIT_SOURCE: |
||
7755 | leency | 353 | if (check_is_the_adress_local(history.current())) { |
354 | RunProgram("/rd/1/tinypad", history.current()); |
||
7750 | leency | 355 | } else { |
7759 | leency | 356 | CreateFile(WB1.bufsize, WB1.bufpointer, "/tmp0/1/WebView_tmp.htm"); |
5718 | leency | 357 | if (!EAX) RunProgram("/rd/1/tinypad", "/tmp0/1/WebView_tmp.htm"); |
358 | } |
||
4415 | leency | 359 | return; |
5718 | leency | 360 | case VIEW_HISTORY: |
7755 | leency | 361 | OpenPage(URL_SERVICE_HISTORY); |
4544 | leency | 362 | return; |
5718 | leency | 363 | case DOWNLOAD_MANAGER: |
5519 | leency | 364 | if (!downloader_opened) { |
6001 | leency | 365 | downloader_edit = NULL; |
5519 | leency | 366 | CreateThread(#Downloader,#downloader_stak+4092); |
367 | } |
||
4413 | leency | 368 | return; |
7765 | leency | 369 | case UPDATE_BROWSER: |
370 | EventUpdateBrowser(); |
||
371 | return; |
||
7282 | leency | 372 | case COPY_LINK_URL: |
7037 | leency | 373 | Clipboard__CopyText(PageLinks.GetURL(PageLinks.active)); |
374 | notify("'URL copied to clipboard'O"); |
||
375 | return; |
||
7208 | leency | 376 | case DOWNLOAD_LINK_CONTENTS: |
377 | if (!downloader_opened) { |
||
378 | strcpy(#downloader_edit, PageLinks.GetURL(PageLinks.active)); |
||
379 | CreateThread(#Downloader,#downloader_stak+4092); |
||
380 | } |
||
381 | return; |
||
7758 | leency | 382 | case OPEN_FILE: |
383 | EventOpenDialog(); |
||
384 | return; |
||
7282 | leency | 385 | case SCAN_CODE_F12: |
386 | debug_mode ^= 1; |
||
387 | if (debug_mode) notify("'Debug mode ON'-I"); |
||
388 | else notify("'Debug mode OFF'-I"); |
||
389 | return; |
||
4413 | leency | 390 | } |
391 | } |
||
392 | |||
4636 | leency | 393 | void StopLoading() |
394 | { |
||
7281 | leency | 395 | if (http.transfer) |
4647 | leency | 396 | { |
7281 | leency | 397 | EAX = http.transfer; |
4647 | leency | 398 | EAX = EAX.http_msg.content_ptr; // get pointer to data |
399 | $push EAX // save it on the stack |
||
7281 | leency | 400 | http_free stdcall (http.transfer); // abort connection |
4647 | leency | 401 | $pop EAX |
5631 | pavelyakov | 402 | free(EAX); // free data |
7281 | leency | 403 | http.transfer=0; |
7746 | leency | 404 | pause(10); |
4647 | leency | 405 | } |
5519 | leency | 406 | wv_progress_bar.value = 0; |
7743 | leency | 407 | DrawOmnibox(); |
4645 | leency | 408 | } |
409 | |||
7756 | leency | 410 | //rewrite into |
7757 | leency | 411 | //bool strrpl(dword dst, from, into, dst_len); |
412 | bool ReplaceSpaceInUrl(dword url, size) { |
||
7756 | leency | 413 | unsigned int i, j; |
7757 | leency | 414 | bool was_changed=false; |
415 | for (i=url+size-3; i>url; i--) |
||
7720 | leency | 416 | { |
7756 | leency | 417 | if (ESBYTE[i]!=' ') continue; |
7757 | leency | 418 | for (j=url+size-3; j>=i; j--) { |
419 | ESBYTE[j+3]=ESBYTE[j+2]; |
||
7756 | leency | 420 | ESBYTE[j+2]=ESBYTE[j+1]; |
421 | ESBYTE[j+1]=ESBYTE[j]; |
||
422 | } |
||
423 | ESBYTE[i] = '%'; |
||
424 | ESBYTE[i+1] = '2'; |
||
425 | ESBYTE[i+2] = '0'; |
||
7757 | leency | 426 | was_changed = true; |
7720 | leency | 427 | } |
7757 | leency | 428 | return was_changed; |
7720 | leency | 429 | } |
430 | |||
7755 | leency | 431 | bool GetLocalFileData(dword _path) |
4416 | leency | 432 | { |
7755 | leency | 433 | dword data, size; |
434 | file_size stdcall (_path); |
||
435 | if (!EBX) { |
||
436 | return false; |
||
437 | } else { |
||
438 | size = EBX; |
||
439 | data = malloc(size); |
||
440 | ReadFile(0, size, data, _path); |
||
441 | LoadInternalPage(data, size); |
||
442 | free(data); |
||
443 | return true; |
||
4692 | leency | 444 | } |
7755 | leency | 445 | } |
7282 | leency | 446 | |
7755 | leency | 447 | void OpenPage(dword _open_URL) |
448 | { |
||
449 | char new_url[URL_SIZE+1]; |
||
450 | |||
451 | StopLoading(); |
||
452 | |||
453 | strcpy(#editURL, _open_URL); |
||
7758 | leency | 454 | address_box.flags=0; |
7755 | leency | 455 | DrawOmnibox(); |
456 | |||
457 | strncpy(#new_url, _open_URL, URL_SIZE); |
||
458 | |||
459 | //Exclude # from the URL to the load page |
||
460 | //We will bring it back when we get the buffer |
||
461 | if (strrchr(#new_url, '#')) anchors.take_anchor_from(#new_url); |
||
462 | |||
463 | history.add(#new_url); |
||
464 | |||
7764 | leency | 465 | if (pages_cache.has(#new_url)) { |
466 | //CACHED PAGE |
||
467 | LoadInternalPage(pages_cache.current_page_buf, pages_cache.current_page_size); |
||
468 | |||
469 | } else if (!strncmp(#new_url,"WebView:",8)) { |
||
7755 | leency | 470 | //INTERNAL PAGE |
471 | if (!strcmp(#new_url, URL_SERVICE_HOMEPAGE)) LoadInternalPage(#homepage, sizeof(homepage)); |
||
472 | else if (!strcmp(#new_url, URL_SERVICE_HELP)) LoadInternalPage(#help, sizeof(help)); |
||
473 | else if (!strcmp(#new_url, URL_SERVICE_HISTORY)) ShowHistory(); |
||
474 | else LoadInternalPage(#page_not_found, sizeof(page_not_found)); |
||
7764 | leency | 475 | |
7755 | leency | 476 | } else if (!strncmp(#new_url,"http:",5)) || (!strncmp(#new_url,"https:",6)) { |
477 | //WEB PAGE |
||
7757 | leency | 478 | if (ReplaceSpaceInUrl(#new_url, URL_SIZE)) { |
479 | strcpy(#editURL, #new_url); |
||
480 | } |
||
481 | |||
7755 | leency | 482 | if (!strncmp(#new_url,"http:",5)) { |
483 | http.get(#new_url); |
||
484 | } else if (!strncmp(#new_url,"https://",8)) { |
||
485 | strcpy(#new_url, "http://gate.aspero.pro/?site="); |
||
486 | strncat(#new_url, _open_URL, URL_SIZE); |
||
487 | http.get(#new_url); |
||
7282 | leency | 488 | } |
7758 | leency | 489 | |
490 | DrawOmnibox(); |
||
491 | |||
7755 | leency | 492 | if (!http.transfer) { |
4646 | leency | 493 | StopLoading(); |
7755 | leency | 494 | LoadInternalPage(#page_not_found, sizeof(page_not_found)); |
4646 | leency | 495 | } |
7755 | leency | 496 | } else { |
497 | //LOCAL PAGE |
||
498 | if (!GetLocalFileData(#new_url)) { |
||
499 | LoadInternalPage(#page_not_found, sizeof(page_not_found)); |
||
4650 | leency | 500 | } |
4636 | leency | 501 | } |
4416 | leency | 502 | } |
4415 | leency | 503 | |
7755 | leency | 504 | void EventClickLink(dword _click_URL) |
4508 | leency | 505 | { |
7756 | leency | 506 | char new_url[URL_SIZE+1]; |
4415 | leency | 507 | |
7758 | leency | 508 | if (open_new_window) { |
509 | strcpy(#new_url, _click_URL); |
||
510 | GetAbsoluteURL(#new_url, history.current()); |
||
511 | RunProgram(#program_path, #new_url); |
||
512 | return; |
||
513 | } |
||
514 | |||
7755 | leency | 515 | if (ESBYTE[_click_URL]=='#') { |
516 | if (anchors.get_pos_by_name(_click_URL+1)!=-1) { |
||
517 | WB1.list.first = anchors.get_pos_by_name(_click_URL+1); |
||
518 | WB1.list.CheckDoesValuesOkey(); |
||
519 | } |
||
520 | strcpy(#editURL, history.current()); |
||
521 | strcat(#editURL, _click_URL); |
||
522 | DrawOmnibox(); |
||
523 | WB1.DrawPage(); |
||
524 | return; |
||
5768 | leency | 525 | } |
7742 | leency | 526 | |
7755 | leency | 527 | if (!strncmp(_click_URL,"mailto:", 7)) || (!strncmp(_click_URL,"tel:", 4)) { |
528 | notify(_click_URL); |
||
529 | return; |
||
7742 | leency | 530 | } |
4508 | leency | 531 | |
7755 | leency | 532 | if (http.transfer > 0) { |
5774 | leency | 533 | StopLoading(); |
6021 | leency | 534 | history.back(); |
5774 | leency | 535 | } |
6730 | leency | 536 | |
7755 | leency | 537 | strcpy(#new_url, _click_URL); |
7757 | leency | 538 | GetAbsoluteURL(#new_url, history.current()); |
7755 | leency | 539 | |
540 | if (strrchr(#new_url, '#')!=0) { |
||
541 | anchors.take_anchor_from(#new_url); |
||
542 | OpenPage(#new_url); |
||
6730 | leency | 543 | return; |
544 | } |
||
545 | |||
7755 | leency | 546 | if (!strncmp(#new_url,"WebView:",8)) { |
547 | OpenPage(#new_url); |
||
7742 | leency | 548 | return; |
549 | } |
||
6730 | leency | 550 | |
7755 | leency | 551 | if (strncmp(#new_url,"http://",7)!=0) && (strncmp(#new_url,"https://",8)!=0) |
5774 | leency | 552 | { |
7755 | leency | 553 | if (UrlExtIs(#new_url,".htm")!=true) && (UrlExtIs(#new_url,".html")!=true) |
6730 | leency | 554 | { |
7755 | leency | 555 | if (strchr(#new_url, '|')) { |
556 | ESBYTE[strchr(#new_url, '|')] = NULL; |
||
557 | RunProgram(#new_url, strlen(#new_url)+1+#new_url); |
||
558 | } else { |
||
559 | RunProgram("/sys/@open", #new_url); |
||
7422 | leency | 560 | } |
6730 | leency | 561 | return; |
562 | } |
||
7755 | leency | 563 | } else { |
564 | if (UrlExtIs(#new_url,".png")==true) || (UrlExtIs(#new_url,".jpg")==true) |
||
565 | || (UrlExtIs(#new_url,".zip")==true) || (UrlExtIs(#new_url,".kex")==true) || (UrlExtIs(#new_url,".pdf")==true) |
||
566 | || (UrlExtIs(#new_url,".7z")==true) { |
||
6986 | leency | 567 | if (!downloader_opened) { |
7755 | leency | 568 | strcpy(#downloader_edit, #new_url); |
6986 | leency | 569 | CreateThread(#Downloader,#downloader_stak+4092); |
570 | } |
||
571 | else notify("'WebView\nPlease, start a new download only when previous ended.'Et"); |
||
6730 | leency | 572 | return; |
5774 | leency | 573 | } |
574 | } |
||
7755 | leency | 575 | OpenPage(#new_url); |
576 | } |
||
577 | |||
578 | void EventSubmitOmnibox() |
||
579 | { |
||
580 | char new_url[URL_SIZE+1]; |
||
581 | if (!editURL[0]) return; |
||
582 | if (!strncmp(#editURL,"http:",5)) || (editURL[0]=='/') |
||
583 | || (!strncmp(#editURL,"https:",6)) || (!strncmp(#editURL,"WebView:",8)) { |
||
584 | OpenPage(#editURL); |
||
585 | } else { |
||
586 | strcpy(#new_url, "http://"); |
||
587 | strncat(#new_url, #editURL, sizeof(new_url)-1); |
||
588 | OpenPage(#new_url); |
||
6931 | leency | 589 | } |
5774 | leency | 590 | } |
591 | |||
7755 | leency | 592 | void LoadInternalPage(dword _bufdata, _in_bufsize){ |
593 | if (!_bufdata) || (!_in_bufsize) { |
||
7752 | leency | 594 | LoadInternalPage(#page_not_found, sizeof(page_not_found)); |
7755 | leency | 595 | } else { |
596 | WB1.list.first = 0; //scroll page to the top |
||
597 | DrawOmnibox(); |
||
598 | if(!strrchr(#editURL, '#')) { |
||
599 | strcat(#editURL, #anchors.current); |
||
600 | DrawOmnibox(); |
||
601 | } |
||
7759 | leency | 602 | WB1.ParseHtml(_bufdata, _in_bufsize); |
603 | DrawStatusBar(NULL); |
||
7756 | leency | 604 | if (source_mode) { |
605 | source_mode = false; |
||
7759 | leency | 606 | ShowSource(WB1.bufpointer, _in_bufsize); |
7757 | leency | 607 | } else { |
608 | WB1.DrawPage(); |
||
7756 | leency | 609 | } |
7742 | leency | 610 | } |
611 | } |
||
612 | |||
7755 | leency | 613 | byte UrlExtIs(dword base, ext) |
7742 | leency | 614 | { |
7755 | leency | 615 | if (!strcmpi(base + strlen(base) - strlen(ext), ext)) return true; |
7742 | leency | 616 | return false; |
617 | } |
||
618 | |||
619 | void DrawProgress() |
||
620 | { |
||
621 | dword persent; |
||
622 | if (http.transfer == 0) return; |
||
7755 | leency | 623 | if (wv_progress_bar.max) { |
624 | persent = wv_progress_bar.value*100/wv_progress_bar.max; |
||
625 | } else { |
||
626 | persent = 10; |
||
627 | } |
||
7758 | leency | 628 | DrawBar(address_box.left-1, address_box.top+20, persent*address_box.width+16/100, 2, 0x72B7EB); |
7742 | leency | 629 | } |
630 | |||
6795 | leency | 631 | void EventShowPageMenu(dword _left, _top) |
6782 | leency | 632 | { |
7759 | leency | 633 | menu.selected = 0; |
6782 | leency | 634 | menu.show(Form.left+_left-6,Form.top+_top+skin_height+3, 220, #rmb_menu, VIEW_SOURCE); |
635 | } |
||
636 | |||
7759 | leency | 637 | void EventShowEncodingsList(dword _left, _top) |
638 | { |
||
639 | menu.selected = WB1.cur_encoding + 1; |
||
640 | menu.show(Form.left+_left-6+77,Form.top+_top+skin_height-3, 100, |
||
641 | "UTF-8\nKOI8-RU\nCP1251\nCP1252\nISO8859-5\nCP866", ENCODINGS); |
||
642 | } |
||
643 | |||
7758 | leency | 644 | void EventShowMainMenu(dword _left, _top) |
645 | { |
||
7759 | leency | 646 | menu.selected = 0; |
7758 | leency | 647 | menu.show(Form.left+_left-6+77,Form.top+_top+skin_height-3, 140, #main_menu, OPEN_FILE); |
648 | } |
||
649 | |||
6795 | leency | 650 | void EventShowLinkMenu(dword _left, _top) |
651 | { |
||
7759 | leency | 652 | menu.selected = 0; |
7282 | leency | 653 | menu.show(Form.left+_left-6,Form.top+_top+skin_height+3, 220, #link_menu, COPY_LINK_URL); |
6795 | leency | 654 | } |
655 | |||
7281 | leency | 656 | void EventUpdateProgressBar() |
657 | { |
||
658 | wv_progress_bar.max = http.content_length; |
||
659 | if (wv_progress_bar.value != http.content_received) |
||
660 | { |
||
661 | wv_progress_bar.value = http.content_received; |
||
662 | DrawProgress(); |
||
663 | } |
||
664 | } |
||
6795 | leency | 665 | |
7743 | leency | 666 | void EventSeachWeb() |
667 | { |
||
7755 | leency | 668 | char new_url[URL_SIZE+1]; |
669 | replace_char(#editURL, ' ', '_', URL_SIZE); |
||
670 | strcpy(#new_url, "https://www.google.com/search?q="); |
||
671 | strncat(#new_url, #editURL, URL_SIZE); |
||
672 | OpenPage(#new_url); |
||
7743 | leency | 673 | } |
674 | |||
7748 | leency | 675 | void EventOpenDialog() |
676 | { |
||
677 | OpenDialog_start stdcall (#o_dialog); |
||
678 | if (o_dialog.status) { |
||
7755 | leency | 679 | OpenPage(#openfile_path); |
7748 | leency | 680 | } |
681 | } |
||
682 | |||
7750 | leency | 683 | void EventViewSource() |
684 | { |
||
7755 | leency | 685 | char source_view_param[URL_SIZE+1]; |
7765 | leency | 686 | strcpy(#source_view_param, "-source "); |
7755 | leency | 687 | strncat(#source_view_param, history.current(), URL_SIZE); |
7750 | leency | 688 | RunProgram(#program_path, #source_view_param); |
689 | } |
||
690 | |||
7765 | leency | 691 | dword GetFileSize(dword _path) |
692 | { |
||
693 | BDVK bdvk; |
||
694 | if (GetFileInfo(_path, #bdvk)!=0) { |
||
695 | return 0; |
||
696 | } else { |
||
697 | return bdvk.sizelo; |
||
698 | } |
||
699 | } |
||
700 | |||
701 | void EventUpdateBrowser() |
||
702 | { |
||
703 | dword downloader_id, slot_n; |
||
704 | dword current_size; |
||
705 | dword new_size; |
||
706 | int error; |
||
707 | |||
708 | draw_window(); |
||
709 | |||
710 | downloader_id = RunProgram(#program_path, #update_param); |
||
711 | do { |
||
712 | slot_n = GetProcessSlot(downloader_id); |
||
713 | pause(10); |
||
714 | } while (slot_n!=0); |
||
715 | |||
716 | current_size = GetFileSize(#program_path); |
||
717 | new_size = GetFileSize("/tmp0/1/Downloads/WebView.com"); |
||
718 | |||
719 | if (!new_size) || (new_size<5000) { |
||
720 | notify(#update_download_error); |
||
721 | return; |
||
722 | } |
||
723 | |||
724 | if (current_size == new_size) { |
||
725 | notify(#update_is_current); |
||
726 | return; |
||
727 | } |
||
728 | |||
729 | if (error = CopyFileAtOnce(new_size, "/tmp0/1/Downloads/WebView.com", #program_path)) { |
||
730 | notify(#update_can_not_copy); |
||
731 | } else { |
||
732 | notify(#update_ok); |
||
733 | RunProgram(#program_path, history.current()); |
||
734 | ExitProcess(); |
||
735 | } |
||
736 | } |
||
737 | |||
7742 | leency | 738 | void DrawStatusBar(dword _status_text) |
6795 | leency | 739 | { |
7759 | leency | 740 | status_text.font_color = system.color.work_text; |
7748 | leency | 741 | status_text.start_x = 10; |
7759 | leency | 742 | status_text.start_y = Form.cheight - STATUSBAR_H + 4; |
743 | status_text.area_size_x = Form.cwidth - status_text.start_x -3 - 70; |
||
744 | //DrawBar(status_text.start_x, status_text.start_y, status_text.area_size_x, 9, system.color.work); |
||
745 | DrawBar(0,Form.cheight - STATUSBAR_H+1, Form.cwidth,STATUSBAR_H-1, system.color.work); |
||
746 | if (_status_text) { |
||
747 | status_text.text_pointer = _status_text; |
||
748 | PathShow_prepare stdcall(#status_text); |
||
749 | PathShow_draw stdcall(#status_text); |
||
7758 | leency | 750 | } |
7759 | leency | 751 | DefineHiddenButton(status_text.start_x+status_text.area_size_x+10, status_text.start_y-3, |
752 | 60, 12, CHANGE_ENCODING); |
||
753 | WriteTextCenter(status_text.start_x+status_text.area_size_x+10, |
||
754 | status_text.start_y, 60, system.color.work_text, WB1.cur_encoding*10+#charsets); |
||
7758 | leency | 755 | } |
756 | |||
757 | void DrawOmnibox() |
||
758 | { |
||
759 | int skin_x_offset; |
||
760 | |||
7759 | leency | 761 | DrawOvalBorder(address_box.left-2, address_box.top-3, address_box.width+18, 24, system.color.work_graph, |
762 | system.color.work_graph, system.color.work_graph, system.color.work_dark); |
||
7758 | leency | 763 | DrawBar(address_box.left-1, address_box.top-2, address_box.width+18, 1, 0xD8DCD8); |
764 | DrawBar(address_box.left-1, address_box.top-1, address_box.width+18, 1, address_box.color); |
||
765 | DrawBar(address_box.left-1, address_box.top, 1, 22, address_box.color); |
||
766 | |||
767 | if (address_box.flags & ed_focus) address_box.flags = ed_focus; else address_box.flags = 0; |
||
768 | EditBox_UpdateText(#address_box, address_box.flags); |
||
769 | edit_box_draw stdcall(#address_box); |
||
770 | if (http.transfer > 0) skin_x_offset = 85; else skin_x_offset = 68; |
||
771 | img_draw stdcall(skin.image, address_box.left+address_box.width+1, |
||
772 | address_box.top-1, 16, skin.h-3, skin_x_offset, SKIN_Y+2); |
||
773 | DefineHiddenButton(address_box.left+address_box.width-1, address_box.top-2, 17, skin.h-3, REFRESH_BUTTON); |
||
774 | |||
775 | DrawProgress(); |
||
776 | } |
||
777 | |||
778 | |||
5631 | pavelyakov | 779 | stop:5000)>=2;>=5)>>=>280)>120)> |