Subversion Repositories Kolibri OS

Rev

Rev 7750 | Rev 7754 | 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[]="’¥ªáâ®¢ë© ¡à ã§¥à 2.0 beta1";
  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 2.0 beta1";
  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. #define URL_SIZE 4000;
  66.  
  67. dword col_bg = 0xE3E2E2;
  68. dword panel_color  = 0xE3E2E2;
  69. dword border_color = 0x8C8C8C;
  70.  
  71. bool debug_mode = false;
  72. bool open_in_a_new_window = false;
  73.  
  74. _http http = {0, 0, 0, 0, 0, 0, 0};
  75.  
  76. #include "..\TWB\TWB.c"
  77. #include "history.h"
  78. #include "show_src.h"
  79. #include "download_manager.h"
  80.  
  81. #define URL_SERVICE_HISTORY "WebView:history"
  82. #define URL_SERVICE_HOMEPAGE "WebView:home"
  83. #define URL_SERVICE_HELP "WebView:help"
  84.  
  85. dword TOOLBAR_H = 40;
  86. dword STATUSBAR_H = 15;
  87.  
  88. int action_buf;
  89.  
  90. bool source_mode = false;
  91.  
  92. progress_bar wv_progress_bar;
  93. char stak[4096];
  94. proc_info Form;
  95.  
  96. enum {
  97.         BACK_BUTTON=1000,
  98.         FORWARD_BUTTON,
  99.         REFRESH_BUTTON,
  100.         GOTOURL_BUTTON,
  101.         SANDWICH_BUTTON,
  102.         VIEW_SOURCE,
  103.         EDIT_SOURCE,
  104.         VIEW_HISTORY,
  105.         DOWNLOAD_MANAGER,
  106.         COPY_LINK_URL,
  107.         DOWNLOAD_LINK_CONTENTS,
  108. };
  109.  
  110. char default_dir[] = "/rd/1";
  111. od_filter filter2 = { 16, "TXT\0HTM\0HTML\0\0" };
  112.  
  113. char URL[URL_SIZE];
  114. char editURL[URL_SIZE];
  115. edit_box address_box = {250,60,30,0xffffff,0x94AECE,0xffffff,0xffffff,0x10000000,URL_SIZE-2,#editURL,0,NULL,19,19};
  116.  
  117. #define SKIN_Y 24
  118.  
  119. void LoadLibraries()
  120. {
  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.         load_dll(Proc_lib,  #OpenDialog_init,0);
  127.         OpenDialog_init stdcall (#o_dialog);   
  128. }
  129.  
  130. void HandleParam()
  131. {
  132.         if (param) {
  133.                 if (!strncmp(#param, "-d ", 3)) {
  134.                         strcpy(#downloader_edit, #param+3);
  135.                         CreateThread(#Downloader,#downloader_stak+4092);
  136.                         ExitProcess();
  137.                 } else if (!strncmp(#param, "-s ", 3)) {
  138.                         source_mode = true;
  139.                         strcpy(#URL, #param + 3);
  140.                 } else {
  141.                         strcpy(#URL, #param);
  142.                 }
  143.         } else {
  144.                 strcpy(#URL, URL_SERVICE_HOMEPAGE);
  145.         }
  146. }
  147.  
  148. void main()
  149. {
  150.         int redirect_count = 0;
  151.         int i;
  152.         LoadLibraries();
  153.         CreateDir("/tmp0/1/downloads");
  154.         Libimg_LoadImage(#skin, "/sys/toolbar.png");
  155.         HandleParam();
  156.         skin.h = 26;
  157.         WB1.list.SetFont(8, 14, 10011000b);
  158.         WB1.list.no_selection = true;
  159.         SetEventMask(EVM_REDRAW + EVM_KEY + EVM_BUTTON + EVM_MOUSE + EVM_MOUSE_FILTER + EVM_STACK);
  160.         loop() switch(WaitEvent())
  161.         {
  162.                 case evMouse:
  163.                         edit_box_mouse stdcall (#address_box);
  164.                         mouse.get();
  165.                         if (PageLinks.HoverAndProceed(mouse.x, WB1.list.first + mouse.y))
  166.                         && (bufsize) && (mouse.pkm) && (mouse.up) {
  167.                                 if (WB1.list.MouseOver(mouse.x, mouse.y)) EventShowPageMenu(mouse.x, mouse.y);
  168.                                 break;
  169.                         }
  170.                         if (WB1.list.MouseScroll(mouse.vert)) WB1.DrawPage();
  171.                         scrollbar_v_mouse (#scroll_wv);
  172.                         if (WB1.list.first != scroll_wv.position)
  173.                         {
  174.                                 WB1.list.first = scroll_wv.position;
  175.                                 WB1.DrawPage();
  176.                                 break;
  177.                         }
  178.                         break;
  179.  
  180.                 case evButton:
  181.                         ProcessEvent(GetButtonID());
  182.                         break;
  183.  
  184.                 case evKey:
  185.                         GetKeys();
  186.                         if (key_modifier&KEY_LCTRL) || (key_modifier&KEY_RCTRL) {
  187.                                 if (key_scancode == SCAN_CODE_KEY_O) {EventOpenDialog();break;}
  188.                                 if (key_scancode == SCAN_CODE_KEY_H) {ProcessEvent(VIEW_HISTORY);break;}
  189.                                 if (key_scancode == SCAN_CODE_KEY_U) {EventViewSource();break;}
  190.                                 if (key_scancode == SCAN_CODE_KEY_T)
  191.                                 || (key_scancode == SCAN_CODE_KEY_N) {RunProgram(#program_path, NULL);break;}
  192.                                 if (key_scancode == SCAN_CODE_KEY_J) {ProcessEvent(DOWNLOAD_MANAGER);break;}
  193.                                 if (key_scancode == SCAN_CODE_KEY_R) {ProcessEvent(REFRESH_BUTTON);break;}
  194.                                 if (key_scancode == SCAN_CODE_ENTER) {EventSeachWeb();break;}
  195.                                 if (key_scancode == SCAN_CODE_LEFT)  {ProcessEvent(BACK_BUTTON);break;}
  196.                                 if (key_scancode == SCAN_CODE_RIGHT) {ProcessEvent(FORWARD_BUTTON);break;}
  197.                                 if (key_scancode == SCAN_CODE_KEY_W) {ExitProcess();break;}
  198.                         }
  199.                        
  200.                         if (key_scancode == SCAN_CODE_F5) ProcessEvent(REFRESH_BUTTON);
  201.                        
  202.                         if (address_box.flags & ed_focus)  
  203.                         {
  204.                                 if (key_scancode == SCAN_CODE_ENTER) {
  205.                                         ProcessEvent(key_scancode);
  206.                                 }
  207.                                 else {
  208.                                         EAX = key_editbox;
  209.                                         edit_box_key stdcall(#address_box);
  210.                                 }
  211.                         }
  212.                         else
  213.                         {
  214.                                 #define KEY_SCROLL_N 11
  215.                                 if (SCAN_CODE_UP   == key_scancode) for (i=0;i<KEY_SCROLL_N;i++) WB1.list.KeyUp();
  216.                                 if (SCAN_CODE_DOWN == key_scancode) for (i=0;i<KEY_SCROLL_N;i++) WB1.list.KeyDown();
  217.                                 if (key_scancode == SCAN_CODE_F6) {address_box.flags=ed_focus; DrawOmnibox();}
  218.                                 if (WB1.list.ProcessKey(key_scancode)) WB1.DrawPage();
  219.                                 else ProcessEvent(key_scancode);
  220.                         }
  221.                         break;
  222.  
  223.                 case evReDraw:
  224.                         if (menu.cur_y) {
  225.                                 ProcessEvent(menu.cur_y);
  226.                                 menu.cur_y = 0;
  227.                         }
  228.                         DefineAndDrawWindow(GetScreenWidth()-800/2-random(80),GetScreenHeight()-700/2-random(80),800,700,0x73,0,0,0);
  229.                         GetProcessInfo(#Form, SelfInfo);
  230.                         system.color.get();
  231.                         col_bg = system.color.work;
  232.                         if (Form.status_window>2) { DrawTitle(#header); break; }
  233.                         if (Form.height<120) { MoveSize(OLD,OLD,OLD,120); break; }
  234.                         if (Form.width<280) { MoveSize(OLD,OLD,280,OLD); break; }
  235.                         draw_window();
  236.                         break;
  237.                        
  238.                 case evNetwork:
  239.                         if (http.transfer > 0) {
  240.                                 http.receive();
  241.                                 EventUpdateProgressBar();
  242.                                 DrawStatusBar(T_LOADING);
  243.                                 if (http.receive_result == 0) {
  244.                                         // Handle redirects
  245.                                         if (http.status_code >= 300) && (http.status_code < 400)
  246.                                         {
  247.                                                 redirect_count++;
  248.                                                 if (redirect_count>5)
  249.                                                 {
  250.                                                         notify("'Too many redirects.' -E");
  251.                                                         StopLoading();
  252.                                                 }
  253.                                                 else
  254.                                                 {
  255.                                                         http.handle_redirect();
  256.                                                         http.free();
  257.                                                         GetAbsoluteURL(#http.redirect_url);
  258.                                                         debug("Redirect: "); debugln(#http.redirect_url);
  259.                                                         history.back();
  260.                                                         strcpy(#URL, #http.redirect_url);
  261.                                                         strcpy(#editURL, #URL);
  262.                                                         DrawOmnibox();
  263.                                                         OpenPage();
  264.                                                         //ProcessLink(history.current());
  265.                                                 }
  266.                                                 break;
  267.                                         }
  268.                                         redirect_count = 0;
  269.                                         // Loading the page is complete, free resources
  270.                                         history.add(#URL);
  271.                                         bufpointer = http.content_pointer;
  272.                                         bufsize = http.content_received;
  273.                                         http.free();
  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.                 WB1.DrawScroller();
  318.         }
  319.         else {
  320.                 WB1.DrawPage();
  321.                 DrawOmnibox();
  322.         }
  323.         DrawRectangle(scroll_wv.start_x, scroll_wv.start_y, scroll_wv.size_x, scroll_wv.size_y-1, scroll_wv.bckg_col);
  324.         DrawProgress();
  325. }
  326.  
  327.  
  328. void ProcessEvent(dword id__)
  329. {
  330.         switch (id__)
  331.         {
  332.                 case 1:
  333.                         ExitProcess();
  334.                         return;
  335.                 case SCAN_CODE_BS:
  336.                 case BACK_BUTTON:
  337.                         if (history.back()) {
  338.                                 strcpy(#URL, history.current());
  339.                                 OpenPage();
  340.                         }
  341.                         return;
  342.                 case FORWARD_BUTTON:
  343.                         if (history.forward()) {
  344.                                 strcpy(#URL, history.current());
  345.                                 OpenPage();
  346.                         }
  347.                         return;
  348.                 case GOTOURL_BUTTON:
  349.                 case SCAN_CODE_ENTER:
  350.                         EventSubmitOmnibox();
  351.                         return;
  352.                 case REFRESH_BUTTON:
  353.                         if (http.transfer > 0)
  354.                         {
  355.                                 StopLoading();
  356.                                 draw_window();
  357.                         }
  358.                         else OpenPage();
  359.                         return;
  360.                 case SANDWICH_BUTTON:
  361.                         EventShowPageMenu(Form.cwidth - 215, TOOLBAR_H-6);
  362.                         return;
  363.                 case VIEW_SOURCE:
  364.                         EventViewSource();
  365.                         break;
  366.                 case EDIT_SOURCE:
  367.                         if (check_is_the_adress_local(#URL)) {
  368.                                 RunProgram("/rd/1/tinypad", #URL);
  369.                         } else {
  370.                                 CreateFile(bufsize, bufpointer, "/tmp0/1/WebView_tmp.htm");
  371.                                 if (!EAX) RunProgram("/rd/1/tinypad", "/tmp0/1/WebView_tmp.htm");
  372.                         }
  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 ReplaceSpaceInUrl() {
  422.         int i;
  423.         strcpy(#editURL, #URL);
  424.         while (i = strchr(#URL, ' '))
  425.         {
  426.                 i -= #URL;
  427.                 strlcpy(#URL+i+3, #editURL+i+1, sizeof(URL)-i-4);
  428.                 URL[i] = '%';
  429.                 URL[i+1] = '2';
  430.                 URL[i+2] = '0';
  431.         }
  432.         strcpy(#editURL, #URL);
  433. }
  434.  
  435. void OpenPage()
  436. {
  437.         char getUrl[sizeof(URL)];
  438.         StopLoading();
  439.         strcpy(#editURL, #URL);
  440.         history.add(#URL);
  441.         if (!strncmp(#URL,"WebView:",8))
  442.         {
  443.                 if (!strcmp(#URL, URL_SERVICE_HOMEPAGE)) LoadInternalPage(#homepage, sizeof(homepage));
  444.                 else if (!strcmp(#URL, URL_SERVICE_HELP)) LoadInternalPage(#help, sizeof(help));
  445.                 else if (!strcmp(#URL, URL_SERVICE_HISTORY)) ShowHistory();
  446.                 else {bufsize=0; ShowPage();} //page not found
  447.                 DrawOmnibox();
  448.                 return;
  449.         }
  450.         if (!strncmp(#URL,"http:",5)) || (!strncmp(#URL,"https://",8))
  451.         {
  452.                 ReplaceSpaceInUrl();
  453.                 img_draw stdcall(skin.image, address_box.left+address_box.width+1, address_box.top-3, 17, skin.h, 68, SKIN_Y);
  454.  
  455.                 if (!strncmp(#URL,"http:",5)) {
  456.                         http.get(#URL);
  457.                 } else if (!strncmp(#URL,"https://",8)) {
  458.                         sprintf(#getUrl, "http://gate.aspero.pro/?site=%s", #URL);
  459.                         http.get(#getUrl);
  460.                 }
  461.  
  462.                 if (!http.transfer)
  463.                 {
  464.                         StopLoading();
  465.                         bufsize = 0;
  466.                         bufpointer = free(bufpointer);
  467.                         ShowPage();
  468.                         return;
  469.                 }
  470.         }
  471.         else
  472.         {
  473.                 file_size stdcall (#URL);
  474.                 if (EBX) {
  475.                         bufsize = EBX;
  476.                         free(bufpointer);
  477.                         bufpointer = malloc(bufsize);
  478.                         ReadFile(0, bufsize, bufpointer, #URL);
  479.                 } else {
  480.                         bufsize = bufpointer = 0;
  481.                 }
  482.                 ShowPage();
  483.         }
  484. }
  485.  
  486. void ProcessAnchor()
  487. {
  488.         char anchor[256];
  489.         dword anchor_pos;
  490.        
  491.         anchor_pos = strrchr(#URL, '#')-1;
  492.         strlcpy(#anchors.current_anchor_name, #URL+anchor_pos, sizeof(anchor)-1);
  493.         URL[anchor_pos] = 0x00;
  494.  
  495.         if (URL[0] == NULL) {
  496.                 //case when URL consists of anchor only
  497.                 if (anchors.get_pos_by_name(#anchor+1)!=-1) WB1.list.first = anchors.get_pos_by_name(#anchor+1);
  498.                 strcpy(#URL, history.current());
  499.         } else {
  500.                 GetAbsoluteURL(#URL);
  501.                 OpenPage();
  502.                 if (anchors.get_pos_by_name(#anchor+1)!=-1) WB1.list.first = anchors.get_pos_by_name(#anchor+1);
  503.         }
  504.  
  505.         WB1.DrawPage();
  506.         strcpy(#editURL, #URL);
  507.         strcat(#editURL, #anchor);
  508.         DrawOmnibox();
  509. }
  510.  
  511. void EventSubmitOmnibox()
  512. {
  513.         if (!editURL[0]) return;
  514.         if (!strncmp(#editURL,"http:",5)) || (editURL[0]=='/')
  515.         || (!strncmp(#editURL,"https:",6)) || (!strncmp(#editURL,"WebView:",8))
  516.         {
  517.                 strcpy(#URL, #editURL);
  518.         }
  519.         else
  520.         {
  521.                 strlcpy(#URL,"http://",7);
  522.                 strcat(#URL, #editURL);
  523.         }
  524.         OpenPage();
  525. }
  526.  
  527. void EventClickLink()
  528. {
  529.         strcpy(#URL, PageLinks.GetURL(PageLinks.active));
  530.         GetAbsoluteURL(#URL);
  531.         ProcessLink();
  532. }
  533.  
  534. void ProcessLink()
  535. {
  536.         if (http.transfer > 0)
  537.         {
  538.                 StopLoading();
  539.                 history.back();
  540.         }
  541.        
  542.         if (strrchr(#URL, '#')!=0) {
  543.                 ProcessAnchor();
  544.                 return;
  545.         }
  546.  
  547.         if (!strncmp(#URL,"mailto:", 7)) || (!strncmp(#URL,"tel:", 4))
  548.         {
  549.                 notify(#URL);
  550.                 strcpy(#editURL, history.current());
  551.                 strcpy(#URL, history.current());
  552.                 return;
  553.         }
  554.  
  555.         if (!strncmp(#URL,"WebView:",8)) {
  556.                 OpenPage();
  557.                 return;
  558.         }
  559.  
  560.         if (strncmp(#URL,"http://",7)!=0) && (strncmp(#URL,"https://",8)!=0)
  561.         {
  562.                 if (UrlExtIs(".htm")!=true) && (UrlExtIs(".html")!=true)
  563.                 {      
  564.                         if (strchr(#URL, '|')) {
  565.                                 ESBYTE[strchr(#URL, '|')] = NULL;
  566.                                 RunProgram(#URL, strlen(#URL)+1+#URL);
  567.                         }
  568.                         else {
  569.                                 RunProgram("/sys/@open", #URL);
  570.                         }
  571.                         strcpy(#editURL, history.current());
  572.                         strcpy(#URL, history.current());
  573.                         return;
  574.                 }
  575.         }
  576.         else   
  577.         {
  578.                 if (UrlExtIs(".png")==true) || (UrlExtIs(".gif")==true) || (UrlExtIs(".jpg")==true)
  579.                 || (UrlExtIs(".zip")==true) || (UrlExtIs(".kex")==true) || (UrlExtIs(".pdf")==true)
  580.                 || (UrlExtIs(".7z")==true) {
  581.                         if (!downloader_opened) {
  582.                                 strcpy(#downloader_edit, #URL);
  583.                                 CreateThread(#Downloader,#downloader_stak+4092);
  584.                                 strcpy(#editURL, history.current());
  585.                                 strcpy(#URL, history.current());
  586.                         }
  587.                         else notify("'WebView\nPlease, start a new download only when previous ended.'Et");
  588.                         return;
  589.                 }
  590.         }
  591.         if (open_in_a_new_window)
  592.         {
  593.                 RunProgram(#program_path, #URL);
  594.                 strcpy(#editURL, history.current());
  595.                 strcpy(#URL, history.current());
  596.         }
  597.         else
  598.         {
  599.                 OpenPage();
  600.         }
  601.         open_in_a_new_window = false;
  602. }
  603.  
  604. void DrawOmnibox()
  605. {
  606.         int skin_x_offset;
  607.         DrawBar(address_box.left-2, address_box.top-2, address_box.width+3, 2, address_box.color);
  608.         DrawBar(address_box.left-2, address_box.top, 2, 22, address_box.color);
  609.         if (address_box.flags & ed_focus) address_box.flags = ed_focus; else address_box.flags = 0;
  610.         EditBox_UpdateText(#address_box, address_box.flags);
  611.         edit_box_draw stdcall(#address_box);
  612.         if (http.transfer > 0) skin_x_offset = 68; else skin_x_offset = 51;
  613.         img_draw stdcall(skin.image, address_box.left+address_box.width+1, address_box.top-3, 17, skin.h, skin_x_offset, SKIN_Y);
  614. }
  615.  
  616. void LoadInternalPage(dword _bufpos, _in_filesize){
  617.         bufsize = _in_filesize;
  618.         if (bufpointer!=_bufpos) free(bufpointer);
  619.         bufpointer = malloc(bufsize);
  620.         memmov(bufpointer, _bufpos, bufsize);
  621.         ShowPage();
  622. }
  623.  
  624. void ShowPage()
  625. {
  626.         WB1.list.first = 0; //scroll page to the top
  627.         DrawOmnibox();
  628.         if (!bufsize) || (!bufpointer) {
  629.                 LoadInternalPage(#page_not_found, sizeof(page_not_found));
  630.         }
  631.         WB1.ParseHtml();
  632.         if (source_mode) {
  633.                 source_mode = false;
  634.                 ShowSource();
  635.                 LoadInternalPage(bufpointer, bufsize);
  636.         }
  637. }
  638.  
  639. byte UrlExtIs(dword ext)
  640. {
  641.         if (!strcmpi(#URL + strlen(#URL) - strlen(ext), ext)) return true;
  642.         return false;
  643. }
  644.  
  645. void DrawProgress()
  646. {
  647.         dword persent;
  648.         if (http.transfer == 0) return;
  649.         if (wv_progress_bar.max) persent = wv_progress_bar.value*100/wv_progress_bar.max; else persent = 10;
  650.         DrawBar(address_box.left-2, address_box.top+20, persent*address_box.width/100, 2, 0x72B7EB);
  651. }
  652.  
  653. void EventShowPageMenu(dword _left, _top)
  654. {
  655.         menu.show(Form.left+_left-6,Form.top+_top+skin_height+3, 220, #rmb_menu, VIEW_SOURCE);
  656. }
  657.  
  658. void EventShowLinkMenu(dword _left, _top)
  659. {
  660.         menu.show(Form.left+_left-6,Form.top+_top+skin_height+3, 220, #link_menu, COPY_LINK_URL);
  661. }
  662.  
  663. void EventUpdateProgressBar()
  664. {
  665.         wv_progress_bar.max = http.content_length;
  666.         if (wv_progress_bar.value != http.content_received)
  667.         {
  668.                 wv_progress_bar.value = http.content_received; 
  669.                 DrawProgress();
  670.         }
  671. }
  672.  
  673. void EventSeachWeb()
  674. {
  675.         sprintf(#URL, "https://www.google.com/search?q=%s", #editURL);
  676.         replace_char(#URL, ' ', '_', sizeof(URL));
  677.         ProcessLink();
  678. }
  679.  
  680. void EventOpenDialog()
  681. {
  682.         OpenDialog_start stdcall (#o_dialog);
  683.         if (o_dialog.status) {
  684.                 strcpy(#URL, #openfile_path);
  685.                 OpenPage();
  686.         }
  687. }
  688.  
  689. void EventViewSource()
  690. {
  691.         char source_view_param[sizeof(URL)+4];
  692.         strcpy(#source_view_param, "-s ");
  693.         strcat(#source_view_param, #URL);
  694.         RunProgram(#program_path, #source_view_param);
  695. }
  696.  
  697. void DrawStatusBar(dword _status_text)
  698. {
  699.         status_text.start_x = 10;
  700.         status_text.start_y = Form.cheight - STATUSBAR_H + 3;
  701.         status_text.area_size_x = Form.cwidth - status_text.start_x -3;
  702.         DrawBar(status_text.start_x, status_text.start_y, status_text.area_size_x, 9, col_bg);
  703.         status_text.text_pointer = _status_text;
  704.         PathShow_prepare stdcall(#status_text);
  705.         PathShow_draw stdcall(#status_text);
  706. }
  707.  
  708. stop: