Subversion Repositories Kolibri OS

Rev

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