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