Subversion Repositories Kolibri OS

Rev

Rev 7789 | Rev 7796 | 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. enum {
  40.         NEW_TAB=600,
  41.         ENCODINGS=700,
  42.         BACK_BUTTON=800,
  43.         FORWARD_BUTTON,
  44.         REFRESH_BUTTON,
  45.         GOTOURL_BUTTON,
  46.         CHANGE_ENCODING,
  47.         SANDWICH_BUTTON,
  48.         VIEW_SOURCE,
  49.         EDIT_SOURCE,
  50.         OPEN_FILE,
  51.         NEW_WINDOW,
  52.         VIEW_HISTORY,
  53.         DOWNLOAD_MANAGER,
  54.         CLEAR_CACHE,
  55.         UPDATE_BROWSER,
  56.         IN_NEW_TAB,
  57.         IN_NEW_WINDOW,
  58.         COPY_LINK_URL,
  59.         DOWNLOAD_LINK_CONTENTS,
  60.         TAB_ID,
  61.         TAB_CLOSE_ID = 900
  62. };
  63.  
  64. #include "..\TWB\TWB.c" //HTML Parser, a core component
  65.  
  66. TWebBrowser WB1;
  67. _history history;
  68.  
  69. #include "history.h"
  70.  
  71. #define PADDING 9
  72. #define TSZE 25
  73. #define STATUSBAR_H 15
  74. #define TAB_H 20
  75. dword TOOLBAR_H = PADDING+TSZE+PADDING+2;
  76.  
  77. #define URL_SIZE 4000
  78.  
  79. int action_buf;
  80.  
  81. _http http = 0;
  82.  
  83. bool source_mode = false;
  84.  
  85. progress_bar wv_progress_bar;
  86. char stak[4096];
  87. proc_info Form;
  88.  
  89. int menu_id=NULL;
  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.                                         redirect_count = 0;
  239.                                 }
  240.                         } else {
  241.                                 // Loading the page is complete, free resources
  242.                                 redirect_count = 0;
  243.                                 http.free();
  244.                                 pages_cache.add(history.current(), http.content_pointer, http.content_received);
  245.                                 LoadInternalPage(http.content_pointer, http.content_received);
  246.                         }
  247.         }
  248. }
  249.  
  250. bool ProcessCtrlKeyEvent()
  251. {
  252.         if (key_modifier&KEY_LCTRL) || (key_modifier&KEY_RCTRL) switch(key_scancode)
  253.         {
  254.                 case SCAN_CODE_KEY_O:
  255.                         EventOpenDialog();
  256.                         return true;
  257.                 case SCAN_CODE_KEY_H:
  258.                         ProcessEvent(VIEW_HISTORY);
  259.                         return true;
  260.                 case SCAN_CODE_KEY_U:
  261.                         EventViewSource();
  262.                         return true;
  263.                 case SCAN_CODE_KEY_T:
  264.                         EventOpenNewTab(URL_SERVICE_HOMEPAGE);
  265.                         return true;
  266.                 case SCAN_CODE_KEY_N:
  267.                         RunProgram(#program_path, NULL);
  268.                         return true;
  269.                 case SCAN_CODE_KEY_J:
  270.                         ProcessEvent(DOWNLOAD_MANAGER);
  271.                         return true;
  272.                 case SCAN_CODE_KEY_R:
  273.                         ProcessEvent(REFRESH_BUTTON);
  274.                         return true;
  275.                 case SCAN_CODE_ENTER:
  276.                         EventSeachWeb();
  277.                         return true;
  278.                 case SCAN_CODE_LEFT:
  279.                          ProcessEvent(BACK_BUTTON);
  280.                          return true;
  281.                 case SCAN_CODE_RIGHT:
  282.                         ProcessEvent(FORWARD_BUTTON);
  283.                         return true;
  284.                 case SCAN_CODE_KEY_W:
  285.                         EventCloseActiveTab();
  286.                         return true;
  287.                 case SCAN_CODE_TAB:
  288.                         EventActivateNextTab();
  289.                         return true;
  290.         }
  291.         return false;
  292. }
  293.  
  294. void SetElementSizes()
  295. {
  296.         address_box.width = Form.cwidth - address_box.left - 52 - 16;
  297.         WB1.list.SetSizes(0, TOOLBAR_H+TAB_H, Form.width - 10 - scroll_wv.size_x,
  298.                 Form.cheight - TOOLBAR_H - STATUSBAR_H - TAB_H, BASIC_LINE_H);
  299.         WB1.list.wheel_size = 7 * BASIC_LINE_H;
  300.         WB1.list.column_max = WB1.list.w - scroll_wv.size_x / WB1.list.font_w + 1;
  301.         WB1.list.visible = WB1.list.h;
  302. }
  303.  
  304.  
  305. void draw_window()
  306. {
  307.         int i;
  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 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_tab = true;
  439.                         EventClickLink(PageLinks.GetURL(PageLinks.active));
  440.                         open_new_tab = 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 GetLocalFileData(dword _path)
  517. {
  518.         dword data, size;
  519.         file_size stdcall (_path);
  520.         if (!EBX) {
  521.                 return false;
  522.         } else {
  523.                 size = EBX;
  524.                 data = malloc(size);
  525.                 ReadFile(0, size, data, _path);
  526.                 LoadInternalPage(data, size);
  527.                 free(data);
  528.                 return true;
  529.         }
  530. }
  531.  
  532. void OpenPage(dword _open_URL)
  533. {
  534.         char new_url[URL_SIZE+1];
  535.         int unz_id;
  536.  
  537.         StopLoading();
  538.  
  539.         if (open_new_tab) {
  540.                 open_new_tab = false;
  541.                 EventOpenNewTab(_open_URL);
  542.                 return;
  543.         }
  544.  
  545.         SetOmniboxText(_open_URL);
  546.  
  547.         strncpy(#new_url, _open_URL, URL_SIZE);
  548.  
  549.         //Exclude # from the URL to the load page
  550.         //We will bring it back when we get the buffer
  551.         if (strrchr(#new_url, '#')) anchors.take_anchor_from(#new_url);
  552.  
  553.         history.add(#new_url);
  554.  
  555.         if (pages_cache.has(#new_url)) {
  556.                 //CACHED PAGE
  557.                 LoadInternalPage(pages_cache.current_page_buf, pages_cache.current_page_size);
  558.  
  559.         } else if (!strncmp(#new_url,"WebView:",8)) {
  560.                 //INTERNAL PAGE
  561.                 if (!strcmp(#new_url, URL_SERVICE_HOMEPAGE)) LoadInternalPage(#homepage, sizeof(homepage));
  562.                 else if (!strcmp(#new_url, URL_SERVICE_HELP)) LoadInternalPage(#help, sizeof(help));
  563.                 else if (!strcmp(#new_url, URL_SERVICE_HISTORY)) ShowHistory();
  564.                 else LoadInternalPage(#page_not_found, sizeof(page_not_found));
  565.                
  566.         } else if (!strncmp(#new_url,"http:",5)) || (!strncmp(#new_url,"https:",6)) {
  567.                 //WEB PAGE
  568.                 if (ReplaceSpaceInUrl(#new_url, URL_SIZE)) {
  569.                         strcpy(#editURL, #new_url);
  570.                 }
  571.  
  572.                 if (!strncmp(#new_url,"http:",5)) {
  573.                         http.get(#new_url);
  574.                 } else if (!strncmp(#new_url,"https://",8)) {
  575.                         strcpy(#new_url, "http://gate.aspero.pro/?site=");
  576.                         strncat(#new_url, _open_URL, URL_SIZE);
  577.                         http.get(#new_url);
  578.                 }
  579.  
  580.                 DrawOmnibox();
  581.  
  582.                 if (!http.transfer) {
  583.                         StopLoading();
  584.                         LoadInternalPage(#page_not_found, sizeof(page_not_found));
  585.                 }
  586.         } else {
  587.                 //LOCAL PAGE
  588.                 if (UrlExtIs(#new_url,".docx")) {
  589.                         DeleteFile("/tmp0/1/temp/word/document.xml");
  590.                         CreateDir("/tmp0/1/temp");
  591.                         unz_id = RunProgram("/sys/unz", sprintf(#param, "-o \"/tmp0/1/temp\" -h \"%s\"", #new_url));
  592.                         while (GetProcessSlot(unz_id)) pause(2);
  593.                         strcpy(#new_url, "/tmp0/1/temp/word/document.xml");
  594.                 }
  595.                 if (!GetLocalFileData(#new_url)) {
  596.                         LoadInternalPage(#page_not_found, sizeof(page_not_found));
  597.                 }
  598.         }
  599. }
  600.  
  601. void EventClickLink(dword _click_URL)
  602. {
  603.         char new_url[URL_SIZE+1];
  604.  
  605.         if (open_new_window) {
  606.                 strcpy(#new_url, _click_URL);
  607.                 GetAbsoluteURL(#new_url, history.current());
  608.                 RunProgram(#program_path, #new_url);
  609.                 return;
  610.         }
  611.  
  612.         if (ESBYTE[_click_URL]=='#') {
  613.                 if (anchors.get_pos_by_name(_click_URL+1)!=-1) {
  614.                         WB1.list.first = anchors.get_pos_by_name(_click_URL+1);
  615.                         WB1.list.CheckDoesValuesOkey();
  616.                 }
  617.                 strcpy(#editURL, history.current());
  618.                 strcat(#editURL, _click_URL);
  619.                 DrawOmnibox();
  620.                 WB1.DrawPage();
  621.                 return;
  622.         }
  623.  
  624.         if (!strncmp(_click_URL,"mailto:", 7)) || (!strncmp(_click_URL,"tel:", 4)) {
  625.                 notify(_click_URL);
  626.                 return;
  627.         }
  628.  
  629.         if (http.transfer) {
  630.                 StopLoading();
  631.                 history.back();
  632.         }
  633.  
  634.         strcpy(#new_url, _click_URL);
  635.         GetAbsoluteURL(#new_url, history.current());
  636.  
  637.         if (strrchr(#new_url, '#')!=0) {
  638.                 anchors.take_anchor_from(#new_url);
  639.                 OpenPage(#new_url);
  640.                 return;
  641.         }
  642.  
  643.         if (!strncmp(#new_url,"WebView:",8)) {
  644.                 OpenPage(#new_url);
  645.                 return;
  646.         }
  647.  
  648.         if (strncmp(#new_url,"http://",7)!=0) && (strncmp(#new_url,"https://",8)!=0)
  649.         {
  650.                 if (UrlExtIs(#new_url,".htm")!=true) && (UrlExtIs(#new_url,".html")!=true)
  651.                 {      
  652.                         if (strchr(#new_url, '|')) {
  653.                                 ESBYTE[strchr(#new_url, '|')] = NULL;
  654.                                 RunProgram(#new_url, strlen(#new_url)+1+#new_url);
  655.                         } else {
  656.                                 RunProgram("/sys/@open", #new_url);
  657.                         }
  658.                         return;
  659.                 }
  660.         } else {
  661.                 if (UrlExtIs(#new_url,".png")==true) || (UrlExtIs(#new_url,".jpg")==true)
  662.                 || (UrlExtIs(#new_url,".zip")==true) || (UrlExtIs(#new_url,".kex")==true) || (UrlExtIs(#new_url,".pdf")==true)
  663.                 || (UrlExtIs(#new_url,".7z")==true) {
  664.                         if (!downloader_opened) {
  665.                                 strcpy(#downloader_edit, #new_url);
  666.                                 CreateThread(#Downloader,#downloader_stak+4092);
  667.                         }
  668.                         else notify("'WebView\nPlease, start a new download only when previous ended.'Et");
  669.                         return;
  670.                 }
  671.         }
  672.         OpenPage(#new_url);
  673. }
  674.  
  675. void EventSubmitOmnibox()
  676. {
  677.         char new_url[URL_SIZE+1];
  678.         if (!editURL[0]) return;
  679.         if (!strncmp(#editURL,"http:",5)) || (editURL[0]=='/')
  680.         || (!strncmp(#editURL,"https:",6)) || (!strncmp(#editURL,"WebView:",8)) {
  681.                 OpenPage(#editURL);
  682.         } else {
  683.                 strcpy(#new_url, "http://");
  684.                 strncat(#new_url, #editURL, sizeof(new_url)-1);
  685.                 OpenPage(#new_url);
  686.         }
  687. }
  688.  
  689. void LoadInternalPage(dword _bufdata, _in_bufsize){
  690.         if (!_bufdata) || (!_in_bufsize) {
  691.                 LoadInternalPage(#page_not_found, sizeof(page_not_found));
  692.         } else {
  693.                 WB1.list.first = 0; //scroll page to the top
  694.                 DrawOmnibox();
  695.                 if(!strrchr(#editURL, '#')) {
  696.                         strcat(#editURL, #anchors.current);
  697.                         DrawOmnibox();
  698.                 }
  699.                 WB1.ParseHtml(_bufdata, _in_bufsize);
  700.                 DrawStatusBar(NULL);
  701.                 DrawActiveTab();
  702.                 if (source_mode) {
  703.                         source_mode = false;
  704.                         ShowSource(WB1.bufpointer, _in_bufsize);
  705.                 } else {
  706.                         WB1.DrawPage();                
  707.                 }
  708.         }
  709. }
  710.  
  711. byte UrlExtIs(dword base, ext)
  712. {
  713.         if (!strcmpi(base + strlen(base) - strlen(ext), ext)) return true;
  714.         return false;
  715. }
  716.  
  717. void DrawProgress()
  718. {
  719.         dword persent;
  720.         if (http.transfer == 0) return;
  721.         if (wv_progress_bar.max) {
  722.                 persent = wv_progress_bar.value*100/wv_progress_bar.max;
  723.         } else {
  724.                 persent = 10;
  725.         }
  726.         DrawBar(address_box.left-1, address_box.top+20, persent*address_box.width+16/100, 2, 0x72B7EB);
  727. }
  728.  
  729. void EventShowPageMenu()
  730. {
  731.         open_lmenu(Form.left + mouse.x+4, Form.top + skin_height + mouse.y, MENU_ALIGN_TOP_LEFT, NULL, #rmb_menu);
  732.         menu_id = VIEW_SOURCE;
  733. }
  734.  
  735. void EventShowLinkMenu()
  736. {
  737.         open_lmenu(Form.left + mouse.x+4, Form.top + skin_height + mouse.y, MENU_ALIGN_TOP_LEFT, NULL, #link_menu);
  738.         menu_id = IN_NEW_TAB;
  739. }
  740.  
  741. void EventShowMainMenu()
  742. {
  743.         open_lmenu(Form.left + Form.cwidth - PADDING, Form.top + skin_height + PADDING + TSZE + 3,
  744.                 MENU_ALIGN_TOP_RIGHT, NULL, #main_menu);
  745.         menu_id = OPEN_FILE;
  746. }
  747.  
  748. void EventShowEncodingsList()
  749. {
  750.         open_lmenu(Form.left + Form.cwidth, Form.top + skin_height + status_text.start_y + 8,
  751.                 MENU_ALIGN_BOT_RIGHT, WB1.cur_encoding + 1, "UTF-8\nKOI8-RU\nCP1251\nCP1252\nISO8859-5\nCP866");
  752.         menu_id = ENCODINGS;
  753. }
  754.  
  755. void ProcessMenuClick()
  756. {
  757.         int click_id;
  758.         if (menu_id) && (click_id = get_menu_click()) {
  759.                 click_id += menu_id - 1;
  760.                 menu_id = NULL;
  761.                 ProcessEvent(click_id);
  762.         }
  763. }
  764.  
  765. void EventUpdateProgressBar()
  766. {
  767.         wv_progress_bar.max = http.content_length;
  768.         if (wv_progress_bar.value != http.content_received)
  769.         {
  770.                 wv_progress_bar.value = http.content_received; 
  771.                 DrawProgress();
  772.         }
  773. }
  774.  
  775. void EventSeachWeb()
  776. {
  777.         char new_url[URL_SIZE+1];
  778.         replace_char(#editURL, ' ', '_', URL_SIZE);
  779.         strcpy(#new_url, "https://www.google.com/search?q=");
  780.         strncat(#new_url, #editURL, URL_SIZE);
  781.         OpenPage(#new_url);
  782. }
  783.  
  784. void EventOpenDialog()
  785. {
  786.         OpenDialog_start stdcall (#o_dialog);
  787.         if (o_dialog.status) {
  788.                 OpenPage(#openfile_path);
  789.         }
  790. }
  791.  
  792. void EventViewSource()
  793. {
  794.         char source_view_param[URL_SIZE+1];
  795.         //strcpy(#source_view_param, "-source ");
  796.         //strncat(#source_view_param, history.current(), URL_SIZE);
  797.         //RunProgram(#program_path, #source_view_param);
  798.         source_mode = true;
  799.         EventOpenNewTab(history.current());
  800. }
  801.  
  802. dword GetFileSize(dword _path)
  803. {
  804.         BDVK bdvk;
  805.         if (GetFileInfo(_path, #bdvk)!=0) {
  806.                 return 0;
  807.         } else {
  808.                 return bdvk.sizelo;
  809.         }
  810. }
  811.  
  812. void EventUpdateBrowser()
  813. {
  814.         dword downloader_id, slot_n;
  815.         dword current_size;
  816.         dword new_size;
  817.         int error;
  818.  
  819.         draw_window();
  820.  
  821.         downloader_id = RunProgram(#program_path, #update_param);
  822.         do {
  823.                 slot_n = GetProcessSlot(downloader_id);
  824.                 pause(10);
  825.         } while (slot_n!=0);
  826.  
  827.         current_size = GetFileSize(#program_path);
  828.         new_size = GetFileSize("/tmp0/1/Downloads/WebView.com");
  829.  
  830.         if (!new_size) || (new_size<5000) {
  831.                 notify(#update_download_error);
  832.                 return;
  833.         }
  834.  
  835.         if (current_size == new_size) {
  836.                 notify(#update_is_current);
  837.                 return;
  838.         }
  839.  
  840.         if (error = CopyFileAtOnce(new_size, "/tmp0/1/Downloads/WebView.com", #program_path)) {
  841.                 notify(#update_can_not_copy);
  842.         } else {
  843.                 notify(#update_ok);
  844.                 RunProgram(#program_path, history.current());
  845.                 ExitProcess();
  846.         }
  847. }
  848.  
  849. void DrawStatusBar(dword _status_text)
  850. {
  851.         status_text.font_color = system.color.work_text;
  852.         status_text.start_x = 10;
  853.         status_text.start_y = Form.cheight - STATUSBAR_H + 4;
  854.         status_text.area_size_x = Form.cwidth - status_text.start_x -3 - 70;
  855.         //DrawBar(status_text.start_x, status_text.start_y, status_text.area_size_x, 9, system.color.work);
  856.         DrawBar(0,Form.cheight - STATUSBAR_H+1, Form.cwidth,STATUSBAR_H-1, system.color.work);
  857.         if (_status_text) {
  858.                 status_text.text_pointer = _status_text;
  859.                 PathShow_prepare stdcall(#status_text);
  860.                 PathShow_draw stdcall(#status_text);           
  861.         }
  862.         DefineHiddenButton(status_text.start_x+status_text.area_size_x+10, status_text.start_y-3,
  863.                 60, 12, CHANGE_ENCODING);
  864.         WriteTextCenter(status_text.start_x+status_text.area_size_x+10,
  865.                 status_text.start_y, 60, system.color.work_text, WB1.cur_encoding*10+#charsets);
  866. }
  867.  
  868. void DrawOmnibox()
  869. {
  870.         int imgxoff;
  871.        
  872.         DrawOvalBorder(address_box.left-2, address_box.top-3, address_box.width+18, 24, system.color.work_graph,
  873.                 system.color.work_graph, system.color.work_graph, system.color.work_dark);
  874.         DrawBar(address_box.left-1, address_box.top-2, address_box.width+18, 1, 0xD8DCD8);
  875.         DrawBar(address_box.left-1, address_box.top-1, address_box.width+18, 1, address_box.color);
  876.         DrawBar(address_box.left-1, address_box.top, 1, 22, address_box.color);
  877.  
  878.         if (address_box.flags & ed_focus) address_box.flags = ed_focus; else address_box.flags = 0;
  879.         EditBox_UpdateText(#address_box, address_box.flags);
  880.         edit_box_draw stdcall(#address_box);
  881.         if (http.transfer) imgxoff = 16*23*3; else imgxoff = 0;
  882.         _PutImage(address_box.left+address_box.width+1, address_box.top-1, 16, 23, imgxoff + #editbox_icons);
  883.         DefineHiddenButton(address_box.left+address_box.width-1, address_box.top-2, 17, 23, REFRESH_BUTTON);
  884.  
  885.         DrawProgress();
  886. }
  887.  
  888. void SetOmniboxText(dword _text)
  889. {
  890.         strcpy(#editURL, _text);
  891.         address_box.flags=0;
  892.         DrawOmnibox();
  893. }
  894.  
  895.  
  896. stop: