Subversion Repositories Kolibri OS

Rev

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