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