Subversion Repositories Kolibri OS

Rev

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