Subversion Repositories Kolibri OS

Rev

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