Subversion Repositories Kolibri OS

Rev

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