Subversion Repositories Kolibri OS

Rev

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