Subversion Repositories Kolibri OS

Rev

Rev 7743 | Rev 7748 | 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 * 800
  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. //useful patterns
  26. #include "..\lib\patterns\history.h"
  27. #include "..\lib\patterns\http_downloader.h"
  28.  
  29. _http http = {0, 0, 0, 0, 0, 0, 0};
  30.  
  31.  
  32. #ifdef LANG_RUS
  33. char version[]="’¥ªáâ®¢ë© ¡à ã§¥à 1.9";
  34. ?define IMAGES_CACHE_CLEARED "Šíè ª à⨭®ª ®ç¨é¥­"
  35. ?define T_LAST_SLIDE "â® ¯®á«¥¤­¨© á« ©¤"
  36. char loading[] = "‡ £à㧪  áâà ­¨æë...<br>";
  37. char page_not_found[] = FROM "html\\page_not_found_ru.htm""\0";
  38. char homepage[] = FROM "html\\homepage_ru.htm""\0";
  39. char help[] = FROM "html\\help_ru.htm""\0";
  40. char accept_language[]= "Accept-Language: ru\n";
  41. char rmb_menu[] =
  42. "®á¬®âà¥âì ¨á室­¨ª
  43. ¥¤ ªâ¨à®¢ âì ¨á室­¨ª
  44. ˆáâ®à¨ï
  45. Œ¥­¥¤¦¥à § £à㧮ª";
  46. char link_menu[] =
  47. "Š®¯¨à®¢ âì áá뫪ã
  48. ‘ª ç âì ᮤ¥à¦¨¬®¥ áá뫪¨";
  49. #else
  50. char version[]="Text-based Browser 1.9";
  51. ?define IMAGES_CACHE_CLEARED "Images cache cleared"
  52. ?define T_LAST_SLIDE "This slide is the last"
  53. char loading[] = "Loading...<br>";
  54. char page_not_found[] = FROM "html\\page_not_found_en.htm""\0";
  55. char homepage[] = FROM "html\\homepage_en.htm""\0";
  56. char help[] = FROM "html\\help_en.htm""\0";
  57. char accept_language[]= "Accept-Language: en\n";
  58. char rmb_menu[] =
  59. "View source
  60. Edit source
  61. History
  62. Download Manager";
  63. char link_menu[] =
  64. "Copy link
  65. Download link contents";
  66. #endif
  67.  
  68.  
  69. #define URL_SERVICE_HISTORY "WebView://history"
  70. #define URL_SERVICE_HOMEPAGE "WebView://home"
  71. #define URL_SERVICE_HELP "WebView://help"
  72. #define URL_SERVICE_SOURCE "WebView://source:"
  73.  
  74. proc_info Form;
  75.  
  76. //char search_path[]="http://nigma.ru/index.php?s=";
  77. int redirected = 0;
  78.  
  79. char stak[4096];
  80.  
  81. int action_buf;
  82.  
  83. dword TOOLBAR_H = 40;
  84. dword STATUSBAR_H = 15;
  85.  
  86. dword col_bg = 0xE3E2E2;
  87. dword panel_color  = 0xE3E2E2;
  88. dword border_color = 0x8C8C8C;
  89.  
  90. bool debug_mode = false;
  91.  
  92. progress_bar wv_progress_bar;
  93. bool souce_mode = false;
  94. bool open_in_a_new_window = false;
  95.  
  96. enum {
  97.         BACK_BUTTON=1000,
  98.         FORWARD_BUTTON,
  99.         REFRESH_BUTTON,
  100.         GOTOURL_BUTTON,
  101.         SANDWICH_BUTTON,
  102.         VIEW_SOURCE=1100,
  103.         EDIT_SOURCE,
  104.         VIEW_HISTORY,
  105.         //FREE_IMG_CACHE,
  106.         DOWNLOAD_MANAGER,
  107.         COPY_LINK_URL=1200,
  108.         DOWNLOAD_LINK_CONTENTS,
  109. };
  110.  
  111. #include "..\TWB\TWB.c"
  112. #include "history.h"
  113. #include "show_src.h"
  114. #include "download_manager.h"
  115.  
  116. char editURL[sizeof(URL)];
  117. edit_box address_box = {250,60,30,0xffffff,0x94AECE,0xffffff,0xffffff,0x10000000,sizeof(URL)-2,#editURL,0,NULL,19,19};
  118.  
  119. #define SKIN_Y 24
  120.  
  121. void main()
  122. {
  123.         int i;
  124.         load_dll(boxlib, #box_lib_init,0);
  125.         load_dll(libio, #libio_init,1);
  126.         load_dll(libimg, #libimg_init,1);
  127.         load_dll(libHTTP, #http_lib_init,1);
  128.         load_dll(iconv_lib, #iconv_open,0);
  129.         Libimg_LoadImage(#skin, "/sys/toolbar.png");
  130.         skin.h = 26;
  131.         wv_progress_bar.progress_color = 0x72B7EB;
  132.         CreateDir("/tmp0/1/downloads");
  133.         if (param) && (param[0]=='-') && (param[1]=='d') {
  134.                 strcpy(#downloader_edit, #param+3);
  135.                 CreateThread(#Downloader,#downloader_stak+4092);
  136.                 ExitProcess();
  137.         }
  138.         else if (param) strcpy(#URL, #param); else strcpy(#URL, URL_SERVICE_HOMEPAGE);
  139.         WB1.list.SetFont(8, 14, 10011000b);
  140.         WB1.list.no_selection = true;
  141.         SetEventMask(EVM_REDRAW + EVM_KEY + EVM_BUTTON + EVM_MOUSE + EVM_MOUSE_FILTER + EVM_STACK);
  142.         loop() switch(WaitEvent())
  143.         {
  144.                 case evMouse:
  145.                         edit_box_mouse stdcall (#address_box);
  146.                         mouse.get();
  147.                         if (PageLinks.HoverAndProceed(mouse.x, WB1.list.first + mouse.y))
  148.                         && (bufsize) && (mouse.pkm) && (mouse.up) {
  149.                                 if (WB1.list.MouseOver(mouse.x, mouse.y)) EventShowPageMenu(mouse.x, mouse.y);
  150.                                 break;
  151.                         }
  152.                         if (WB1.list.MouseScroll(mouse.vert)) WB1.DrawPage();
  153.                         scrollbar_v_mouse (#scroll_wv);
  154.                         if (WB1.list.first != scroll_wv.position)
  155.                         {
  156.                                 WB1.list.first = scroll_wv.position;
  157.                                 WB1.DrawPage();
  158.                                 break;
  159.                         }
  160.                         break;
  161.  
  162.                 case evButton:
  163.                         ProcessEvent(GetButtonID());
  164.                         break;
  165.  
  166.                 case evKey:
  167.                         GetKeys();
  168.                         if (key_modifier&KEY_LCTRL) || (key_modifier&KEY_RCTRL) {
  169.                                 if (key_scancode == SCAN_CODE_KEY_H) ProcessEvent(VIEW_HISTORY);
  170.                                 if (key_scancode == SCAN_CODE_KEY_U) ProcessEvent(VIEW_SOURCE);
  171.                                 if (key_scancode == SCAN_CODE_KEY_T)
  172.                                 || (key_scancode == SCAN_CODE_KEY_N) RunProgram(#program_path, NULL);
  173.                                 if (key_scancode == SCAN_CODE_KEY_W) ExitProcess();
  174.                                 if (key_scancode == SCAN_CODE_KEY_J) ProcessEvent(DOWNLOAD_MANAGER);
  175.                                 if (key_scancode == SCAN_CODE_KEY_R) ProcessEvent(REFRESH_BUTTON);
  176.                                 if (key_scancode == SCAN_CODE_ENTER) EventSeachWeb();
  177.                                 if (key_scancode == SCAN_CODE_LEFT)  ProcessEvent(BACK_BUTTON);
  178.                                 if (key_scancode == SCAN_CODE_RIGHT) ProcessEvent(FORWARD_BUTTON);
  179.                         }
  180.                        
  181.                         if (key_scancode == SCAN_CODE_F5) ProcessEvent(REFRESH_BUTTON);
  182.                        
  183.                         if (address_box.flags & ed_focus)  
  184.                         {
  185.                                 if (key_scancode == SCAN_CODE_ENTER) {
  186.                                         ProcessEvent(key_scancode);
  187.                                 }
  188.                                 else {
  189.                                         EAX = key_editbox;
  190.                                         edit_box_key stdcall(#address_box);
  191.                                 }
  192.                         }
  193.                         else
  194.                         {
  195.                                 #define KEY_SCROLL_N 11
  196.                                 if (SCAN_CODE_UP   == key_scancode) for (i=0;i<KEY_SCROLL_N;i++) WB1.list.KeyUp();
  197.                                 if (SCAN_CODE_DOWN == key_scancode) for (i=0;i<KEY_SCROLL_N;i++) WB1.list.KeyDown();
  198.                                 if (key_scancode == SCAN_CODE_F6) {address_box.flags=ed_focus; DrawOmnibox();}
  199.                                 if (WB1.list.ProcessKey(key_scancode)) WB1.DrawPage();
  200.                                 else ProcessEvent(key_scancode);
  201.                         }
  202.                         break;
  203.  
  204.                 case evReDraw:
  205.                         if (menu.cur_y) {
  206.                                 ProcessEvent(menu.cur_y);
  207.                                 menu.cur_y = 0;
  208.                         }
  209.                         DefineAndDrawWindow(GetScreenWidth()-800/2-random(80),GetScreenHeight()-600/2-random(80),800,600,0x73,col_bg,0,0);
  210.                         GetProcessInfo(#Form, SelfInfo);
  211.                         if (Form.status_window>2) { DrawTitle(#header); break; }
  212.                         if (Form.height<120) { MoveSize(OLD,OLD,OLD,120); break; }
  213.                         if (Form.width<280) { MoveSize(OLD,OLD,280,OLD); break; }
  214.                         Draw_Window();
  215.                         break;
  216.                        
  217.                 case evNetwork:
  218.                         if (http.transfer > 0) {
  219.                                 http.receive();
  220.                                 EventUpdateProgressBar();
  221.                                 if (http.receive_result == 0) {
  222.                                         // Handle redirects
  223.                                         if (http.status_code >= 300) && (http.status_code < 400)
  224.                                         {
  225.                                                 redirected++;
  226.                                                 if (redirected>5)
  227.                                                 {
  228.                                                         notify("'Too many redirects.' -E");
  229.                                                         StopLoading();
  230.                                                 }
  231.                                                 else
  232.                                                 {
  233.                                                         http.handle_redirect();
  234.                                                         http.free();
  235.                                                         GetAbsoluteURL(#http.redirect_url);
  236.                                                         history.back();
  237.                                                         strcpy(#editURL, #URL);
  238.                                                         DrawOmnibox();
  239.                                                         OpenPage();
  240.                                                         //ProcessLink(history.current());
  241.                                                 }
  242.                                                 break;
  243.                                         }
  244.                                         redirected = 0;
  245.                                         // Loading the page is complete, free resources
  246.                                         history.add(#URL);
  247.                                         bufpointer = http.content_pointer;
  248.                                         bufsize = http.content_received;
  249.                                         http.free();
  250.                                         SetPageDefaults();
  251.                                         ShowPage();
  252.                                 }
  253.                         }
  254.         }
  255. }
  256.  
  257. void SetElementSizes()
  258. {
  259.         address_box.top = TOOLBAR_H/2-10;
  260.         basic_line_h = calc(WB1.list.font_h * 130) / 100;
  261.         address_box.width = Form.cwidth - address_box.left - 50;
  262.         WB1.list.SetSizes(0, TOOLBAR_H, Form.width - 10 - scroll_wv.size_x,
  263.                 Form.cheight - TOOLBAR_H - STATUSBAR_H, basic_line_h);
  264.         WB1.list.wheel_size = 7 * basic_line_h;
  265.         WB1.list.column_max = WB1.list.w - scroll_wv.size_x / WB1.list.font_w + 1;
  266.         WB1.list.visible = WB1.list.h;
  267.         if (WB1.list.w!=WB1.DrawBuf.bufw) {
  268.                 WB1.DrawBuf.Init(WB1.list.x, WB1.list.y, WB1.list.w, 800*20);
  269.                 ProcessEvent(REFRESH_BUTTON);
  270.         }
  271. }
  272.  
  273.  
  274.  
  275. void Draw_Window()
  276. {
  277.         DrawBar(0,0, Form.cwidth,TOOLBAR_H-2, panel_color);
  278.         DrawBar(0,TOOLBAR_H-2, Form.cwidth,1, 0xD7D0D3);
  279.         DrawBar(0,TOOLBAR_H-1, Form.cwidth,1, border_color);
  280.         SetElementSizes();
  281.         DrawRectangle(address_box.left-3, address_box.top-3, address_box.width+5, 25,border_color);
  282.         DefineButton(address_box.left-52, address_box.top-2, 24, skin.h-2, BACK_BUTTON+BT_HIDE, 0);
  283.         DefineButton(address_box.left-27, address_box.top-2, 24, skin.h-2, FORWARD_BUTTON+BT_HIDE, 0);
  284.         img_draw stdcall(skin.image, address_box.left-53, address_box.top-3, 51, skin.h, 0, SKIN_Y);
  285.         DefineButton(address_box.left+address_box.width+1, address_box.top-3, 16, skin.h-1, REFRESH_BUTTON+BT_HIDE+BT_NOFRAME, 0);
  286.         DefineButton(Form.cwidth-27, address_box.top-3, 23, skin.h-1, SANDWICH_BUTTON+BT_HIDE, 0);
  287.         img_draw stdcall(skin.image, Form.cwidth-24, address_box.top-3, 17, skin.h, 102, SKIN_Y);
  288.         DrawBar(0,Form.cheight - STATUSBAR_H, Form.cwidth,STATUSBAR_H, col_bg);
  289.         DrawBar(0,Form.cheight - STATUSBAR_H, Form.cwidth,1, border_color);
  290.         if (!header)
  291.                 OpenPage();
  292.         else {
  293.                 WB1.DrawPage();
  294.                 DrawOmnibox();
  295.         }
  296.         DrawRectangle(scroll_wv.start_x, scroll_wv.start_y, scroll_wv.size_x, scroll_wv.size_y-1, scroll_wv.bckg_col);
  297.         DrawProgress();
  298. }
  299.  
  300.  
  301. void ProcessEvent(dword id__)
  302. {
  303.         switch (id__)
  304.         {
  305.                 case 1:
  306.                         ExitProcess();
  307.                         return;
  308.                 case SCAN_CODE_BS:
  309.                 case BACK_BUTTON:
  310.                         if (history.back()) {
  311.                                 strcpy(#URL, history.current());
  312.                                 OpenPage();
  313.                         }
  314.                         return;
  315.                 case FORWARD_BUTTON:
  316.                         if (history.forward()) {
  317.                                 strcpy(#URL, history.current());
  318.                                 OpenPage();
  319.                         }
  320.                         return;
  321.                 case GOTOURL_BUTTON:
  322.                 case SCAN_CODE_ENTER:
  323.                         EventSubmitOmnibox();
  324.                         return;
  325.                 case REFRESH_BUTTON:
  326.                         if (http.transfer > 0)
  327.                         {
  328.                                 StopLoading();
  329.                                 Draw_Window();
  330.                         }
  331.                         else OpenPage();
  332.                         return;
  333.                 case SANDWICH_BUTTON:
  334.                         EventShowPageMenu(Form.cwidth - 215, TOOLBAR_H-6);
  335.                         return;
  336.                 case VIEW_SOURCE:
  337.                         WB1.list.first = 0;
  338.                         ShowSource();
  339.                         WB1.LoadInternalPage(bufpointer, bufsize);
  340.                         break;
  341.                 case EDIT_SOURCE:
  342.                         if (!strncmp(#URL,"http",4))
  343.                         {
  344.                                 CreateFile(bufsize, bufpointer, "/tmp0/1/WebView_tmp.htm");
  345.                                 if (!EAX) RunProgram("/rd/1/tinypad", "/tmp0/1/WebView_tmp.htm");
  346.                         }
  347.                         else RunProgram("/rd/1/tinypad", #URL);
  348.                         return;
  349.                 // case FREE_IMG_CACHE:
  350.                 //      ImgCache.Free();
  351.                 //      notify(IMAGES_CACHE_CLEARED);
  352.                 //      WB1.DrawPage();
  353.                 //      return;
  354.                 case VIEW_HISTORY:
  355.                         strcpy(#URL, URL_SERVICE_HISTORY);
  356.                         OpenPage();
  357.                         return;
  358.                 case DOWNLOAD_MANAGER:
  359.                         if (!downloader_opened) {
  360.                                 downloader_edit = NULL;
  361.                                 CreateThread(#Downloader,#downloader_stak+4092);
  362.                         }
  363.                         return;
  364.                 case COPY_LINK_URL:
  365.                         Clipboard__CopyText(PageLinks.GetURL(PageLinks.active));
  366.                         notify("'URL copied to clipboard'O");
  367.                         return;
  368.                 case DOWNLOAD_LINK_CONTENTS:
  369.                         if (!downloader_opened) {
  370.                                 strcpy(#downloader_edit, PageLinks.GetURL(PageLinks.active));
  371.                                 CreateThread(#Downloader,#downloader_stak+4092);
  372.                         }
  373.                         return;
  374.                 case SCAN_CODE_F12:
  375.                         debug_mode ^= 1;
  376.                         if (debug_mode) notify("'Debug mode ON'-I");
  377.                         else notify("'Debug mode OFF'-I");
  378.                         return;
  379.         }
  380. }
  381.  
  382. void StopLoading()
  383. {
  384.         if (http.transfer)
  385.         {
  386.                 EAX = http.transfer;
  387.                 EAX = EAX.http_msg.content_ptr;         // get pointer to data
  388.                 $push   EAX                                                     // save it on the stack
  389.                 http_free stdcall (http.transfer);      // abort connection
  390.                 $pop    EAX                                                    
  391.                 free(EAX);                                              // free data
  392.                 http.transfer=0;
  393.                 bufsize = 0;
  394.                 bufpointer = free(bufpointer);
  395.                 pause(10);
  396.         }
  397.         wv_progress_bar.value = 0;
  398.         DrawOmnibox();
  399. }
  400.  
  401. void SetPageDefaults()
  402. {
  403.         strcpy(#header, #version);
  404.         WB1.list.count = WB1.list.first = 0;
  405.         cur_encoding = CH_NULL;
  406.         if (o_bufpointer) o_bufpointer = free(o_bufpointer);
  407. }
  408.  
  409. void ReplaceSpaceInUrl() {
  410.         int i;
  411.         strcpy(#editURL, #URL);
  412.         while (i = strchr(#URL, ' '))
  413.         {
  414.                 i -= #URL;
  415.                 strlcpy(#URL+i+3, #editURL+i+1, sizeof(URL)-i-4);
  416.                 URL[i] = '%';
  417.                 URL[i+1] = '2';
  418.                 URL[i+2] = '0';
  419.         }
  420.         strcpy(#editURL, #URL);
  421. }
  422.  
  423. void OpenPage()
  424. {
  425.         char getUrl[sizeof(URL)];
  426.         StopLoading();
  427.         souce_mode = false;
  428.         strcpy(#editURL, #URL);
  429.         history.add(#URL);
  430.         if (!strncmp(#URL,"WebView:",8))
  431.         {
  432.                 SetPageDefaults();
  433.                 if (!strcmp(#URL, URL_SERVICE_HOMEPAGE)) WB1.LoadInternalPage(#homepage, sizeof(homepage));
  434.                 else if (!strcmp(#URL, URL_SERVICE_HELP)) WB1.LoadInternalPage(#help, sizeof(help));
  435.                 else if (!strcmp(#URL, URL_SERVICE_HISTORY)) ShowHistory();
  436.                 else {bufsize=0; ShowPage();} //page not found
  437.                 DrawOmnibox();
  438.                 return;
  439.         }
  440.         if (!strncmp(#URL,"http:",5)) || (!strncmp(#URL,"https://",8))
  441.         {
  442.                 ReplaceSpaceInUrl();
  443.                 img_draw stdcall(skin.image, address_box.left+address_box.width+1, address_box.top-3, 17, skin.h, 68, SKIN_Y);
  444.  
  445.                 if (!strncmp(#URL,"http:",5)) {
  446.                         http.get(#URL);
  447.                 }
  448.                 if (!strncmp(#URL,"https://",8)) {
  449.                         sprintf(#getUrl, "http://gate.aspero.pro/?site=%s", #URL);
  450.                         http.get(#getUrl);
  451.                 }
  452.                 //http.get(#URL);
  453.                 if (!http.transfer)
  454.                 {
  455.                         StopLoading();
  456.                         bufsize = 0;
  457.                         bufpointer = free(bufpointer);
  458.                         ShowPage();
  459.                         return;
  460.                 }
  461.         }
  462.         else
  463.         {
  464.                 file_size stdcall (#URL);
  465.                 if (EBX)
  466.                 {
  467.                         bufsize = EBX;
  468.                         free(bufpointer);
  469.                         bufpointer = malloc(bufsize);
  470.                         SetPageDefaults();
  471.                         ReadFile(0, bufsize, bufpointer, #URL);
  472.                 }
  473.                 ShowPage();
  474.         }
  475. }
  476.  
  477. void ProcessAnchor()
  478. {
  479.         char anchor[256];
  480.         int anchor_pos;
  481.        
  482.         anchor_pos = strrchr(#URL, '#')-1;
  483.         strlcpy(#anchor, #URL+anchor_pos, sizeof(anchor));
  484.         URL[anchor_pos] = 0x00;
  485.  
  486.         //#1
  487.         if (URL[0] == NULL)
  488.         {
  489.                 if (anchor[1] == NULL) {
  490.                         WB1.list.first = 0;
  491.                 }
  492.                 else {
  493.                         if (anchors.get_anchor_pos(#anchor+1)!=-1) WB1.list.first = anchors.get_anchor_pos(#anchor+1);
  494.                 }
  495.                 strcpy(#URL, history.current());
  496.         }
  497.         //liner.ru#1
  498.         else
  499.         {
  500.                 GetAbsoluteURL(#URL);
  501.                 OpenPage();
  502.                 if (anchors.get_anchor_pos(#anchor+1)!=-1) WB1.list.first = anchors.get_anchor_pos(#anchor+1);
  503.         }
  504.  
  505.         WB1.DrawPage();
  506.         strcpy(#editURL, #URL);
  507.         strcat(#editURL, #anchor);
  508.         DrawOmnibox();
  509. }
  510.  
  511. void EventSubmitOmnibox()
  512. {
  513.         if (!editURL[0]) return;
  514.         if (!strncmp(#editURL,"http:",5)) || (editURL[0]=='/')
  515.         || (!strncmp(#editURL,"https:",6)) || (!strncmp(#editURL,"WebView:",8))
  516.         {
  517.                 strcpy(#URL, #editURL);
  518.         }
  519.         else
  520.         {
  521.                 strlcpy(#URL,"http://",7);
  522.                 strcat(#URL, #editURL);
  523.         }
  524.         ProcessLink();
  525. }
  526.  
  527. void EventClickLink()
  528. {
  529.         strcpy(#URL, PageLinks.GetURL(PageLinks.active));
  530.         GetAbsoluteURL(#URL);
  531.         ProcessLink();
  532. }
  533.  
  534. void ProcessLink()
  535. {
  536.         if (http.transfer > 0)
  537.         {
  538.                 StopLoading();
  539.                 history.back();
  540.         }
  541.        
  542.         if (strrchr(#URL, '#')!=0) {
  543.                 ProcessAnchor();
  544.                 return;
  545.         }
  546.  
  547.         if (!strncmp(#URL,"mailto:", 7)) || (!strncmp(#URL,"tel:", 4))
  548.         {
  549.                 notify(#URL);
  550.                 strcpy(#editURL, history.current());
  551.                 strcpy(#URL, history.current());
  552.                 return;
  553.         }
  554.  
  555.         if (!strncmp(#URL,"WebView:",8)) {
  556.                 OpenPage();
  557.                 return;
  558.         }
  559.  
  560.         if (strncmp(#URL,"http://",7)!=0) && (strncmp(#URL,"https://",8)!=0)
  561.         {
  562.                 if (UrlExtIs(".htm")!=true) && (UrlExtIs(".html")!=true)
  563.                 {      
  564.                         if (strchr(#URL, '|')) {
  565.                                 ESBYTE[strchr(#URL, '|')] = NULL;
  566.                                 RunProgram(#URL, strlen(#URL)+1+#URL);
  567.                         }
  568.                         else {
  569.                                 RunProgram("/sys/@open", #URL);
  570.                         }
  571.                         strcpy(#editURL, history.current());
  572.                         strcpy(#URL, history.current());
  573.                         return;
  574.                 }
  575.         }
  576.         else   
  577.         {
  578.                 if (UrlExtIs(".png")==true) || (UrlExtIs(".gif")==true) || (UrlExtIs(".jpg")==true)
  579.                 || (UrlExtIs(".zip")==true) || (UrlExtIs(".kex")==true) || (UrlExtIs(".pdf")==true)
  580.                 || (UrlExtIs(".7z")==true) {
  581.                         if (!downloader_opened) {
  582.                                 strcpy(#downloader_edit, #URL);
  583.                                 CreateThread(#Downloader,#downloader_stak+4092);
  584.                                 strcpy(#editURL, history.current());
  585.                                 strcpy(#URL, history.current());
  586.                         }
  587.                         else notify("'WebView\nPlease, start a new download only when previous ended.'Et");
  588.                         return;
  589.                 }
  590.         }
  591.         if (open_in_a_new_window)
  592.         {
  593.                 RunProgram(#program_path, #URL);
  594.                 strcpy(#editURL, history.current());
  595.                 strcpy(#URL, history.current());
  596.         }
  597.         else
  598.         {
  599.                 OpenPage();
  600.         }
  601.         open_in_a_new_window = false;
  602. }
  603.  
  604. void DrawOmnibox()
  605. {
  606.         int skin_x_offset;
  607.         DrawBar(address_box.left-2, address_box.top-2, address_box.width+3, 2, address_box.color);
  608.         DrawBar(address_box.left-2, address_box.top, 2, 22, address_box.color);
  609.         //address_box.size = address_box.pos = address_box.shift = address_box.shift_old = strlen(#editURL);
  610.         //address_box.offset = 0;
  611.         EditBox_UpdateText(#address_box, address_box.flags);
  612.         edit_box_draw stdcall(#address_box);
  613.         if (http.transfer > 0) skin_x_offset = 68; else skin_x_offset = 51;
  614.         img_draw stdcall(skin.image, address_box.left+address_box.width+1, address_box.top-3, 17, skin.h, skin_x_offset, SKIN_Y);
  615. }
  616.  
  617.  
  618. void ShowPage()
  619. {
  620.         DrawOmnibox();
  621.         if (!bufsize)
  622.         {
  623.                 if (http.transfer) WB1.LoadInternalPage(#loading, sizeof(loading));
  624.                 else WB1.LoadInternalPage(#page_not_found, sizeof(page_not_found));
  625.         }
  626.         else
  627.         {
  628.                 WB1.Prepare();
  629.         }
  630. }
  631.  
  632. byte UrlExtIs(dword ext)
  633. {
  634.         if (!strcmpi(#URL + strlen(#URL) - strlen(ext), ext)) return true;
  635.         return false;
  636. }
  637.  
  638. void DrawProgress()
  639. {
  640.         dword persent;
  641.         if (http.transfer == 0) return;
  642.         if (wv_progress_bar.max) persent = wv_progress_bar.value*100/wv_progress_bar.max; else persent = 10;
  643.         DrawBar(address_box.left-2, address_box.top+20, persent*address_box.width/100, 2, wv_progress_bar.progress_color);
  644. }
  645.  
  646. void EventShowPageMenu(dword _left, _top)
  647. {
  648.         menu.show(Form.left+_left-6,Form.top+_top+skin_height+3, 220, #rmb_menu, VIEW_SOURCE);
  649. }
  650.  
  651. void EventShowLinkMenu(dword _left, _top)
  652. {
  653.         menu.show(Form.left+_left-6,Form.top+_top+skin_height+3, 220, #link_menu, COPY_LINK_URL);
  654. }
  655.  
  656. void EventUpdateProgressBar()
  657. {
  658.         wv_progress_bar.max = http.content_length;
  659.         if (wv_progress_bar.value != http.content_received)
  660.         {
  661.                 wv_progress_bar.value = http.content_received; 
  662.                 DrawProgress();
  663.         }
  664. }
  665.  
  666. void EventSeachWeb()
  667. {
  668.         sprintf(#URL, "https://www.google.com/search?q=%s", #editURL);
  669.         ProcessLink();
  670. }
  671.  
  672. void DrawStatusBar(dword _status_text)
  673. {
  674.         status_text.start_x = wv_progress_bar.left + wv_progress_bar.width + 10;
  675.         status_text.start_y = Form.cheight - STATUSBAR_H + 3;
  676.         status_text.area_size_x = Form.cwidth - status_text.start_x -3;
  677.         DrawBar(status_text.start_x, status_text.start_y, status_text.area_size_x, 9, col_bg);
  678.         status_text.text_pointer = _status_text;
  679.         PathShow_prepare stdcall(#status_text);
  680.         PathShow_draw stdcall(#status_text);
  681. }
  682.  
  683. stop: