Subversion Repositories Kolibri OS

Rev

Rev 7757 | Rev 7759 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

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