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