Subversion Repositories Kolibri OS

Rev

Rev 7943 | Rev 7970 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

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