Subversion Repositories Kolibri OS

Rev

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