Subversion Repositories Kolibri OS

Rev

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