Subversion Repositories Kolibri OS

Rev

Rev 7758 | Rev 7762 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

  1. //Copyright 2007-2020 by Veliant & Leency
  2. //Asper, lev, Lrz, Barsuk, Nable, hidnplayr...
  3.  
  4. #ifndef AUTOBUILD
  5.         #include "lang.h--"
  6. #endif
  7.  
  8. //libraries
  9. #define MEMSIZE 1024 * 850
  10. #include "..\lib\gui.h"
  11. #include "..\lib\draw_buf.h"
  12. #include "..\lib\list_box.h"
  13. #include "..\lib\cursor.h"
  14. #include "..\lib\collection.h"
  15. #include "..\lib\random.h"
  16. #include "..\lib\clipboard.h"
  17.  
  18. // *.obj libraries
  19. #include "..\lib\obj\box_lib.h"
  20. #include "..\lib\obj\libio.h"
  21. #include "..\lib\obj\libimg.h"
  22. #include "..\lib\obj\http.h"
  23. #include "..\lib\obj\iconv.h"
  24. #include "..\lib\obj\proc_lib.h"
  25.  
  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. #include "..\lib\patterns\toolbar_button.h"
  31.  
  32. #include "show_src.h"
  33. #include "download_manager.h"
  34. _history history;
  35. #include "history.h"
  36. bool debug_mode = false;
  37. #include "..\TWB\TWB.c" //HTML Parser, a core component
  38.  
  39. TWebBrowser WB1;
  40.  
  41. char version[]="WebView 2.1";
  42.  
  43. #ifdef LANG_RUS
  44. char page_not_found[] = FROM "html\\page_not_found_ru.htm""\0";
  45. char homepage[] = FROM "html\\homepage_ru.htm""\0";
  46. char help[] = FROM "html\\help_ru.htm""\0";
  47. char accept_language[]= "Accept-Language: ru\n";
  48. char rmb_menu[] =
  49. "®á¬®âà¥âì ¨á室­¨ª
  50. ¥¤ ªâ¨à®¢ âì ¨á室­¨ª";
  51. char main_menu[] =
  52. "Žâªàëâì ä ©«
  53. ®¢®¥ ®ª­®
  54. ˆáâ®à¨ï
  55. Œ¥­¥¤¦¥à § £à㧮ª";
  56. char link_menu[] =
  57. "Š®¯¨à®¢ âì áá뫪ã
  58. ‘ª ç âì ᮤ¥à¦¨¬®¥ áá뫪¨";
  59. char loading_text[] = "‡ £à㧪 ...";
  60. #else
  61. char page_not_found[] = FROM "html\\page_not_found_en.htm""\0";
  62. char homepage[] = FROM "html\\homepage_en.htm""\0";
  63. char help[] = FROM "html\\help_en.htm""\0";
  64. char accept_language[]= "Accept-Language: en\n";
  65. char rmb_menu[] =
  66. "View source
  67. Edit source";
  68. char main_menu[] =
  69. "Open local file
  70. New window
  71. History
  72. Download Manager";
  73. char link_menu[] =
  74. "Copy link
  75. Download link contents";
  76. char loading_text[] = "Loading...";
  77. #endif
  78.  
  79. #define URL_SIZE 4000
  80.  
  81. #define URL_SERVICE_HISTORY "WebView:history"
  82. #define URL_SERVICE_HOMEPAGE "WebView:home"
  83. #define URL_SERVICE_HELP "WebView:help"
  84.  
  85. #define PADDING 9
  86. #define SKIN_Y 24
  87. #define TSZE 25
  88. dword TOOLBAR_H = PADDING+TSZE+PADDING+2;
  89. dword STATUSBAR_H = 15;
  90.  
  91. int action_buf;
  92.  
  93. _http http = 0;
  94.  
  95. bool source_mode = false;
  96.  
  97. progress_bar wv_progress_bar;
  98. char stak[4096];
  99. proc_info Form;
  100.  
  101. enum {
  102.         ENCODINGS=900,
  103.         BACK_BUTTON=1000,
  104.         FORWARD_BUTTON,
  105.         REFRESH_BUTTON,
  106.         GOTOURL_BUTTON,
  107.         CHANGE_ENCODING,
  108.         SANDWICH_BUTTON,
  109.         VIEW_SOURCE,
  110.         EDIT_SOURCE,
  111.         OPEN_FILE,
  112.         NEW_WINDOW,
  113.         VIEW_HISTORY,
  114.         DOWNLOAD_MANAGER,
  115.         COPY_LINK_URL,
  116.         DOWNLOAD_LINK_CONTENTS,
  117. };
  118.  
  119. char default_dir[] = "/rd/1";
  120. od_filter filter2 = { 16, "TXT\0HTM\0HTML\0\0" };
  121.  
  122. char editURL[URL_SIZE+1];
  123. edit_box address_box = {, PADDING+TSZE*2+PADDING+6, PADDING+3, 0xffffff,
  124.         0x94AECE, 0xffffff, 0xffffff,0x10000000,URL_SIZE-2,#editURL,0,,19,19};
  125.  
  126.  
  127. void LoadLibraries()
  128. {
  129.         load_dll(boxlib,    #box_lib_init,0);
  130.         load_dll(libio,     #libio_init,1);
  131.         load_dll(libimg,    #libimg_init,1);
  132.         load_dll(libHTTP,   #http_lib_init,1);
  133.         load_dll(iconv_lib, #iconv_open,0);
  134.         load_dll(Proc_lib,  #OpenDialog_init,0);
  135.         OpenDialog_init stdcall (#o_dialog);   
  136. }
  137.  
  138. void HandleParam()
  139. {
  140.         if (param) {
  141.                 if (!strncmp(#param, "-d ", 3)) {
  142.                         strcpy(#downloader_edit, #param+3);
  143.                         CreateThread(#Downloader,#downloader_stak+4092);
  144.                         ExitProcess();
  145.                 } else if (!strncmp(#param, "-s ", 3)) {
  146.                         source_mode = true;
  147.                         history.add(#param + 3);
  148.                 } else {
  149.                         history.add(#param);
  150.                 }
  151.         } else {
  152.                 history.add(URL_SERVICE_HOMEPAGE);
  153.         }
  154. }
  155.  
  156. void main()
  157. {
  158.         int i, btn, redirect_count=0;
  159.         LoadLibraries();
  160.         CreateDir("/tmp0/1/downloads");
  161.         Libimg_LoadImage(#skin, "/sys/toolbar.png");
  162.         HandleParam();
  163.         skin.h = 26;
  164.         WB1.list.SetFont(8, 14, 10011000b);
  165.         WB1.list.no_selection = true;
  166.         WB1.custom_encoding = -1;
  167.         SetEventMask(EVM_REDRAW + EVM_KEY + EVM_BUTTON + EVM_MOUSE + EVM_MOUSE_FILTER + EVM_STACK);
  168.         loop() switch(WaitEvent())
  169.         {
  170.                 case evMouse:
  171.                         edit_box_mouse stdcall (#address_box);
  172.                         mouse.get();
  173.                         if (PageLinks.HoverAndProceed(mouse.x, WB1.list.first + mouse.y, WB1.list.y, WB1.list.first))
  174.                         && (mouse.pkm) && (mouse.up) {
  175.                                 if (WB1.list.MouseOver(mouse.x, mouse.y)) EventShowPageMenu(mouse.x, mouse.y);
  176.                                 break;
  177.                         }
  178.                         if (WB1.list.MouseScroll(mouse.vert)) WB1.DrawPage();
  179.                         scrollbar_v_mouse (#scroll_wv);
  180.                         if (WB1.list.first != scroll_wv.position)
  181.                         {
  182.                                 WB1.list.first = scroll_wv.position;
  183.                                 WB1.DrawPage();
  184.                                 break;
  185.                         }
  186.                         if (mouse.up) && (! address_box.flags & ed_focus) && (address_box.flags & ed_shift_bac)
  187.                         {
  188.                                 DrawOmnibox(); //reset text selection
  189.                         }
  190.                         break;
  191.  
  192.                 case evButton:
  193.                         btn = GetButtonID();
  194.                         if (1==btn) ExitProcess(); else ProcessEvent(btn);
  195.                         break;
  196.  
  197.                 case evKey:
  198.                         GetKeys();
  199.                         if (key_modifier&KEY_LCTRL) || (key_modifier&KEY_RCTRL) {
  200.                                 if (key_scancode == SCAN_CODE_KEY_O) {EventOpenDialog();break;}
  201.                                 if (key_scancode == SCAN_CODE_KEY_H) {ProcessEvent(VIEW_HISTORY);break;}
  202.                                 if (key_scancode == SCAN_CODE_KEY_U) {EventViewSource();break;}
  203.                                 if (key_scancode == SCAN_CODE_KEY_T)
  204.                                 || (key_scancode == SCAN_CODE_KEY_N) {RunProgram(#program_path, NULL);break;}
  205.                                 if (key_scancode == SCAN_CODE_KEY_J) {ProcessEvent(DOWNLOAD_MANAGER);break;}
  206.                                 if (key_scancode == SCAN_CODE_KEY_R) {ProcessEvent(REFRESH_BUTTON);break;}
  207.                                 if (key_scancode == SCAN_CODE_ENTER) {EventSeachWeb();break;}
  208.                                 if (key_scancode == SCAN_CODE_LEFT)  {ProcessEvent(BACK_BUTTON);break;}
  209.                                 if (key_scancode == SCAN_CODE_RIGHT) {ProcessEvent(FORWARD_BUTTON);break;}
  210.                                 if (key_scancode == SCAN_CODE_KEY_W) {ExitProcess();break;}
  211.                         }
  212.                        
  213.                         if (key_scancode == SCAN_CODE_F5) ProcessEvent(REFRESH_BUTTON);
  214.                        
  215.                         if (address_box.flags & ed_focus)  
  216.                         {
  217.                                 if (key_scancode == SCAN_CODE_ENTER) {
  218.                                         ProcessEvent(key_scancode);
  219.                                 }
  220.                                 else {
  221.                                         EAX = key_editbox;
  222.                                         edit_box_key stdcall(#address_box);
  223.                                 }
  224.                         }
  225.                         else
  226.                         {
  227.                                 #define KEY_SCROLL_N 11
  228.                                 if (SCAN_CODE_UP   == key_scancode) for (i=0;i<KEY_SCROLL_N;i++) WB1.list.KeyUp();
  229.                                 if (SCAN_CODE_DOWN == key_scancode) for (i=0;i<KEY_SCROLL_N;i++) WB1.list.KeyDown();
  230.                                 if (key_scancode == SCAN_CODE_F6) {address_box.flags=ed_focus; DrawOmnibox();}
  231.                                 if (WB1.list.ProcessKey(key_scancode)) WB1.DrawPage();
  232.                                 else ProcessEvent(key_scancode);
  233.                         }
  234.                         break;
  235.  
  236.                 case evReDraw:
  237.                         if (menu.cur_y) {
  238.                                 ProcessEvent(menu.cur_y);
  239.                                 menu.cur_y = 0;
  240.                         }
  241.                         DefineAndDrawWindow(GetScreenWidth()-800/2-random(80),
  242.                                 GetScreenHeight()-700/2-random(80),800,700,0x73,0,0,0);
  243.                         GetProcessInfo(#Form, SelfInfo);
  244.                         system.color.get();
  245.                         if (Form.status_window>2) break;
  246.                         if (Form.height<120) { MoveSize(OLD,OLD,OLD,120); break; }
  247.                         if (Form.width<280) { MoveSize(OLD,OLD,280,OLD); break; }
  248.                         draw_window();
  249.                         break;
  250.                        
  251.                 case evNetwork:
  252.                         if (http.transfer <= 0) break;
  253.                         http.receive();
  254.                         EventUpdateProgressBar();
  255.                         if (http.receive_result != 0) break;
  256.                         if (http.status_code >= 300) && (http.status_code < 400)
  257.                         {
  258.                                 // Handle redirects
  259.                                 if (redirect_count<=5) {
  260.                                         redirect_count++;
  261.                                         http.handle_redirect();
  262.                                         http.free();
  263.                                         GetAbsoluteURL(#http.redirect_url, history.current());
  264.                                         history.back();
  265.                                         OpenPage(#http.redirect_url);
  266.                                 } else {
  267.                                         notify("'Too many redirects.' -E");
  268.                                         StopLoading();
  269.                                 }
  270.                         } else {
  271.                                 // Loading the page is complete, free resources
  272.                                 redirect_count = 0;
  273.                                 http.free();
  274.                                 LoadInternalPage(http.content_pointer, http.content_received);
  275.                         }
  276.         }
  277. }
  278.  
  279. void SetElementSizes()
  280. {
  281.         address_box.width = Form.cwidth - address_box.left - 52 - 16;
  282.         WB1.list.SetSizes(0, TOOLBAR_H, Form.width - 10 - scroll_wv.size_x,
  283.                 Form.cheight - TOOLBAR_H - STATUSBAR_H, BASIC_LINE_H);
  284.         WB1.list.wheel_size = 7 * BASIC_LINE_H;
  285.         WB1.list.column_max = WB1.list.w - scroll_wv.size_x / WB1.list.font_w + 1;
  286.         WB1.list.visible = WB1.list.h;
  287. }
  288.  
  289.  
  290. void draw_window()
  291. {
  292.         int i;
  293.         SetElementSizes();
  294.  
  295.         DrawBar(0,0, Form.cwidth,PADDING, system.color.work);
  296.         DrawBar(0,PADDING+TSZE+1, Form.cwidth,PADDING-1, system.color.work);
  297.         DrawBar(0,TOOLBAR_H-2, Form.cwidth,1, system.color.work_dark);
  298.         DrawBar(0,TOOLBAR_H-1, Form.cwidth,1, system.color.work_graph);
  299.         DrawBar(0, PADDING, address_box.left-2, TSZE+1, system.color.work);
  300.         DrawBar(address_box.left+address_box.width+18, PADDING, Form.cwidth-address_box.left-address_box.width-18, TSZE+1, system.color.work);
  301.  
  302.         DrawTopPanelButton(BACK_BUTTON, PADDING-1, PADDING, 30);
  303.         DrawTopPanelButton(FORWARD_BUTTON, PADDING+TSZE+PADDING-2, PADDING, 31);
  304.         DrawTopPanelButton(SANDWICH_BUTTON, Form.cwidth-PADDING-TSZE-3, PADDING, -1);
  305.         for (i=0; i<=2; i++) DrawBar(Form.cwidth-PADDING-TSZE+3, i*5+PADDING+7, 15, 3, system.color.work_graph);
  306.  
  307.         DrawBar(0,Form.cheight - STATUSBAR_H, Form.cwidth,1, system.color.work_graph);
  308.  
  309.         DrawRectangle(WB1.list.x + WB1.list.w, WB1.list.y, scroll_wv.size_x,
  310.                 WB1.list.h-1, scroll_wv.bckg_col);
  311.  
  312.         if (WB1.list.w!=WB1.DrawBuf.bufw) {
  313.                 WB1.DrawBuf.Init(WB1.list.x, WB1.list.y, WB1.list.w, 400*20);
  314.                 if (!strncmp(history.current(),"http",4)) {
  315.                         //nihuya ne izyashnoe reshenie, no pust' poka butet tak
  316.                         i=source_mode;
  317.                         LoadInternalPage(#loading_text, sizeof(loading_text));
  318.                         source_mode=i;
  319.                 }
  320.                 OpenPage(history.current());
  321.         } else {
  322.                 WB1.DrawPage();
  323.                 DrawOmnibox();
  324.         }
  325.         DrawProgress();
  326.         DrawStatusBar(NULL);
  327. }
  328.  
  329. void EventChangeEncodingAndLoadPage(int _new_encoding)
  330. {
  331.         dword newbuf, newsize;
  332.         WB1.custom_encoding = _new_encoding;
  333.         newsize = strlen(WB1.o_bufpointer);
  334.         newbuf = malloc(newsize);
  335.         memmov(newbuf, WB1.o_bufpointer, newsize);
  336.         LoadInternalPage(newbuf, newsize);
  337.         free(newbuf);
  338. }
  339.  
  340.  
  341. void ProcessEvent(dword id__)
  342. {
  343.         switch (id__)
  344.         {
  345.                 case ENCODINGS...ENCODINGS+6:
  346.                         EventChangeEncodingAndLoadPage(id__-ENCODINGS);
  347.                         return;
  348.                 case NEW_WINDOW:
  349.                         RunProgram(#program_path, NULL);
  350.                         return;
  351.                 case SCAN_CODE_BS:
  352.                 case BACK_BUTTON:
  353.                         if (history.back()) {
  354.                                 OpenPage(history.current());
  355.                         }
  356.                         return;
  357.                 case FORWARD_BUTTON:
  358.                         if (history.forward()) {
  359.                                 OpenPage(history.current());
  360.                         }
  361.                         return;
  362.                 case GOTOURL_BUTTON:
  363.                 case SCAN_CODE_ENTER:
  364.                         EventSubmitOmnibox();
  365.                         return;
  366.                 case REFRESH_BUTTON:
  367.                         if (http.transfer > 0) {
  368.                                 StopLoading();
  369.                                 draw_window();
  370.                         } else {
  371.                                 OpenPage(history.current());
  372.                         }
  373.                         return;
  374.                 case CHANGE_ENCODING:
  375.                         EventShowEncodingsList(Form.cwidth - 150, status_text.start_y-117);
  376.                         return;
  377.                 case SANDWICH_BUTTON:
  378.                         EventShowMainMenu(Form.cwidth - 215, TOOLBAR_H-6);
  379.                         return;
  380.                 case VIEW_SOURCE:
  381.                         EventViewSource();
  382.                         break;
  383.                 case EDIT_SOURCE:
  384.                         if (check_is_the_adress_local(history.current())) {
  385.                                 RunProgram("/rd/1/tinypad", history.current());
  386.                         } else {
  387.                                 CreateFile(WB1.bufsize, WB1.bufpointer, "/tmp0/1/WebView_tmp.htm");
  388.                                 if (!EAX) RunProgram("/rd/1/tinypad", "/tmp0/1/WebView_tmp.htm");
  389.                         }
  390.                         return;
  391.                 case VIEW_HISTORY:
  392.                         OpenPage(URL_SERVICE_HISTORY);
  393.                         return;
  394.                 case DOWNLOAD_MANAGER:
  395.                         if (!downloader_opened) {
  396.                                 downloader_edit = NULL;
  397.                                 CreateThread(#Downloader,#downloader_stak+4092);
  398.                         }
  399.                         return;
  400.                 case COPY_LINK_URL:
  401.                         Clipboard__CopyText(PageLinks.GetURL(PageLinks.active));
  402.                         notify("'URL copied to clipboard'O");
  403.                         return;
  404.                 case DOWNLOAD_LINK_CONTENTS:
  405.                         if (!downloader_opened) {
  406.                                 strcpy(#downloader_edit, PageLinks.GetURL(PageLinks.active));
  407.                                 CreateThread(#Downloader,#downloader_stak+4092);
  408.                         }
  409.                         return;
  410.                 case OPEN_FILE:
  411.                         EventOpenDialog();
  412.                         return;
  413.                 case SCAN_CODE_F12:
  414.                         debug_mode ^= 1;
  415.                         if (debug_mode) notify("'Debug mode ON'-I");
  416.                         else notify("'Debug mode OFF'-I");
  417.                         return;
  418.         }
  419. }
  420.  
  421. void StopLoading()
  422. {
  423.         if (http.transfer)
  424.         {
  425.                 EAX = http.transfer;
  426.                 EAX = EAX.http_msg.content_ptr;         // get pointer to data
  427.                 $push   EAX                                                     // save it on the stack
  428.                 http_free stdcall (http.transfer);      // abort connection
  429.                 $pop    EAX                                                    
  430.                 free(EAX);                                              // free data
  431.                 http.transfer=0;
  432.                 pause(10);
  433.         }
  434.         wv_progress_bar.value = 0;
  435.         DrawOmnibox();
  436. }
  437.  
  438. //rewrite into
  439. //bool strrpl(dword dst, from, into, dst_len);
  440. bool ReplaceSpaceInUrl(dword url, size) {
  441.         unsigned int i, j;
  442.         bool was_changed=false;
  443.         for (i=url+size-3; i>url; i--)
  444.         {
  445.                 if (ESBYTE[i]!=' ') continue;
  446.                 for (j=url+size-3; j>=i; j--) {
  447.                         ESBYTE[j+3]=ESBYTE[j+2];
  448.                         ESBYTE[j+2]=ESBYTE[j+1];
  449.                         ESBYTE[j+1]=ESBYTE[j];
  450.                 }
  451.                 ESBYTE[i] = '%';
  452.                 ESBYTE[i+1] = '2';
  453.                 ESBYTE[i+2] = '0';
  454.                 was_changed = true;
  455.         }
  456.         return was_changed;
  457. }
  458.  
  459. bool GetLocalFileData(dword _path)
  460. {
  461.         dword data, size;
  462.         file_size stdcall (_path);
  463.         if (!EBX) {
  464.                 return false;
  465.         } else {
  466.                 size = EBX;
  467.                 data = malloc(size);
  468.                 ReadFile(0, size, data, _path);
  469.                 LoadInternalPage(data, size);
  470.                 free(data);
  471.                 return true;
  472.         }
  473. }
  474.  
  475. void OpenPage(dword _open_URL)
  476. {
  477.         char new_url[URL_SIZE+1];
  478.  
  479.         StopLoading();
  480.  
  481.         strcpy(#editURL, _open_URL);
  482.         address_box.flags=0;
  483.         DrawOmnibox();
  484.  
  485.         strncpy(#new_url, _open_URL, URL_SIZE);
  486.  
  487.         //Exclude # from the URL to the load page
  488.         //We will bring it back when we get the buffer
  489.         if (strrchr(#new_url, '#')) anchors.take_anchor_from(#new_url);
  490.  
  491.         history.add(#new_url);
  492.  
  493.         if (!strncmp(#new_url,"WebView:",8)) {
  494.                 //INTERNAL PAGE
  495.                 if (!strcmp(#new_url, URL_SERVICE_HOMEPAGE)) LoadInternalPage(#homepage, sizeof(homepage));
  496.                 else if (!strcmp(#new_url, URL_SERVICE_HELP)) LoadInternalPage(#help, sizeof(help));
  497.                 else if (!strcmp(#new_url, URL_SERVICE_HISTORY)) ShowHistory();
  498.                 else LoadInternalPage(#page_not_found, sizeof(page_not_found));
  499.         } else if (!strncmp(#new_url,"http:",5)) || (!strncmp(#new_url,"https:",6)) {
  500.                 //WEB PAGE
  501.                 if (ReplaceSpaceInUrl(#new_url, URL_SIZE)) {
  502.                         strcpy(#editURL, #new_url);
  503.                 }
  504.  
  505.                 if (!strncmp(#new_url,"http:",5)) {
  506.                         http.get(#new_url);
  507.                 } else if (!strncmp(#new_url,"https://",8)) {
  508.                         strcpy(#new_url, "http://gate.aspero.pro/?site=");
  509.                         strncat(#new_url, _open_URL, URL_SIZE);
  510.                         http.get(#new_url);
  511.                 }
  512.  
  513.                 DrawOmnibox();
  514.  
  515.                 if (!http.transfer) {
  516.                         StopLoading();
  517.                         LoadInternalPage(#page_not_found, sizeof(page_not_found));
  518.                 }
  519.         } else {
  520.                 //LOCAL PAGE
  521.                 if (!GetLocalFileData(#new_url)) {
  522.                         LoadInternalPage(#page_not_found, sizeof(page_not_found));
  523.                 }
  524.         }
  525. }
  526.  
  527. void EventClickLink(dword _click_URL)
  528. {
  529.         char new_url[URL_SIZE+1];
  530.  
  531.         if (open_new_window) {
  532.                 strcpy(#new_url, _click_URL);
  533.                 GetAbsoluteURL(#new_url, history.current());
  534.                 RunProgram(#program_path, #new_url);
  535.                 return;
  536.         }
  537.  
  538.         if (ESBYTE[_click_URL]=='#') {
  539.                 if (anchors.get_pos_by_name(_click_URL+1)!=-1) {
  540.                         WB1.list.first = anchors.get_pos_by_name(_click_URL+1);
  541.                         WB1.list.CheckDoesValuesOkey();
  542.                 }
  543.                 strcpy(#editURL, history.current());
  544.                 strcat(#editURL, _click_URL);
  545.                 DrawOmnibox();
  546.                 WB1.DrawPage();
  547.                 return;
  548.         }
  549.  
  550.         if (!strncmp(_click_URL,"mailto:", 7)) || (!strncmp(_click_URL,"tel:", 4)) {
  551.                 notify(_click_URL);
  552.                 return;
  553.         }
  554.  
  555.         if (http.transfer > 0) {
  556.                 StopLoading();
  557.                 history.back();
  558.         }
  559.  
  560.         strcpy(#new_url, _click_URL);
  561.         GetAbsoluteURL(#new_url, history.current());
  562.  
  563.         if (strrchr(#new_url, '#')!=0) {
  564.                 anchors.take_anchor_from(#new_url);
  565.                 OpenPage(#new_url);
  566.                 return;
  567.         }
  568.  
  569.         if (!strncmp(#new_url,"WebView:",8)) {
  570.                 OpenPage(#new_url);
  571.                 return;
  572.         }
  573.  
  574.         if (strncmp(#new_url,"http://",7)!=0) && (strncmp(#new_url,"https://",8)!=0)
  575.         {
  576.                 if (UrlExtIs(#new_url,".htm")!=true) && (UrlExtIs(#new_url,".html")!=true)
  577.                 {      
  578.                         if (strchr(#new_url, '|')) {
  579.                                 ESBYTE[strchr(#new_url, '|')] = NULL;
  580.                                 RunProgram(#new_url, strlen(#new_url)+1+#new_url);
  581.                         } else {
  582.                                 RunProgram("/sys/@open", #new_url);
  583.                         }
  584.                         return;
  585.                 }
  586.         } else {
  587.                 if (UrlExtIs(#new_url,".png")==true) || (UrlExtIs(#new_url,".jpg")==true)
  588.                 || (UrlExtIs(#new_url,".zip")==true) || (UrlExtIs(#new_url,".kex")==true) || (UrlExtIs(#new_url,".pdf")==true)
  589.                 || (UrlExtIs(#new_url,".7z")==true) {
  590.                         if (!downloader_opened) {
  591.                                 strcpy(#downloader_edit, #new_url);
  592.                                 CreateThread(#Downloader,#downloader_stak+4092);
  593.                         }
  594.                         else notify("'WebView\nPlease, start a new download only when previous ended.'Et");
  595.                         return;
  596.                 }
  597.         }
  598.         OpenPage(#new_url);
  599. }
  600.  
  601. void EventSubmitOmnibox()
  602. {
  603.         char new_url[URL_SIZE+1];
  604.         if (!editURL[0]) return;
  605.         if (!strncmp(#editURL,"http:",5)) || (editURL[0]=='/')
  606.         || (!strncmp(#editURL,"https:",6)) || (!strncmp(#editURL,"WebView:",8)) {
  607.                 OpenPage(#editURL);
  608.         } else {
  609.                 strcpy(#new_url, "http://");
  610.                 strncat(#new_url, #editURL, sizeof(new_url)-1);
  611.                 OpenPage(#new_url);
  612.         }
  613. }
  614.  
  615. void LoadInternalPage(dword _bufdata, _in_bufsize){
  616.         if (!_bufdata) || (!_in_bufsize) {
  617.                 LoadInternalPage(#page_not_found, sizeof(page_not_found));
  618.         } else {
  619.                 WB1.list.first = 0; //scroll page to the top
  620.                 DrawOmnibox();
  621.                 if(!strrchr(#editURL, '#')) {
  622.                         strcat(#editURL, #anchors.current);
  623.                         DrawOmnibox();
  624.                 }
  625.                 WB1.ParseHtml(_bufdata, _in_bufsize);
  626.                 DrawStatusBar(NULL);
  627.                 if (source_mode) {
  628.                         source_mode = false;
  629.                         ShowSource(WB1.bufpointer, _in_bufsize);
  630.                 } else {
  631.                         WB1.DrawPage();                
  632.                 }
  633.         }
  634. }
  635.  
  636. byte UrlExtIs(dword base, ext)
  637. {
  638.         if (!strcmpi(base + strlen(base) - strlen(ext), ext)) return true;
  639.         return false;
  640. }
  641.  
  642. void DrawProgress()
  643. {
  644.         dword persent;
  645.         if (http.transfer == 0) return;
  646.         if (wv_progress_bar.max) {
  647.                 persent = wv_progress_bar.value*100/wv_progress_bar.max;
  648.         } else {
  649.                 persent = 10;
  650.         }
  651.         DrawBar(address_box.left-1, address_box.top+20, persent*address_box.width+16/100, 2, 0x72B7EB);
  652. }
  653.  
  654. void EventShowPageMenu(dword _left, _top)
  655. {
  656.         menu.selected = 0;
  657.         menu.show(Form.left+_left-6,Form.top+_top+skin_height+3, 220, #rmb_menu, VIEW_SOURCE);
  658. }
  659.  
  660. void EventShowEncodingsList(dword _left, _top)
  661. {
  662.         menu.selected = WB1.cur_encoding + 1;
  663.         menu.show(Form.left+_left-6+77,Form.top+_top+skin_height-3, 100,
  664.                 "UTF-8\nKOI8-RU\nCP1251\nCP1252\nISO8859-5\nCP866", ENCODINGS);
  665. }
  666.  
  667. void EventShowMainMenu(dword _left, _top)
  668. {
  669.         menu.selected = 0;
  670.         menu.show(Form.left+_left-6+77,Form.top+_top+skin_height-3, 140, #main_menu, OPEN_FILE);
  671. }
  672.  
  673. void EventShowLinkMenu(dword _left, _top)
  674. {
  675.         menu.selected = 0;
  676.         menu.show(Form.left+_left-6,Form.top+_top+skin_height+3, 220, #link_menu, COPY_LINK_URL);
  677. }
  678.  
  679. void EventUpdateProgressBar()
  680. {
  681.         wv_progress_bar.max = http.content_length;
  682.         if (wv_progress_bar.value != http.content_received)
  683.         {
  684.                 wv_progress_bar.value = http.content_received; 
  685.                 DrawProgress();
  686.         }
  687. }
  688.  
  689. void EventSeachWeb()
  690. {
  691.         char new_url[URL_SIZE+1];
  692.         replace_char(#editURL, ' ', '_', URL_SIZE);
  693.         strcpy(#new_url, "https://www.google.com/search?q=");
  694.         strncat(#new_url, #editURL, URL_SIZE);
  695.         OpenPage(#new_url);
  696. }
  697.  
  698. void EventOpenDialog()
  699. {
  700.         OpenDialog_start stdcall (#o_dialog);
  701.         if (o_dialog.status) {
  702.                 OpenPage(#openfile_path);
  703.         }
  704. }
  705.  
  706. void EventViewSource()
  707. {
  708.         char source_view_param[URL_SIZE+1];
  709.         strcpy(#source_view_param, "-s ");
  710.         strncat(#source_view_param, history.current(), URL_SIZE);
  711.         RunProgram(#program_path, #source_view_param);
  712. }
  713.  
  714. void DrawStatusBar(dword _status_text)
  715. {
  716.         status_text.font_color = system.color.work_text;
  717.         status_text.start_x = 10;
  718.         status_text.start_y = Form.cheight - STATUSBAR_H + 4;
  719.         status_text.area_size_x = Form.cwidth - status_text.start_x -3 - 70;
  720.         //DrawBar(status_text.start_x, status_text.start_y, status_text.area_size_x, 9, system.color.work);
  721.         DrawBar(0,Form.cheight - STATUSBAR_H+1, Form.cwidth,STATUSBAR_H-1, system.color.work);
  722.         if (_status_text) {
  723.                 status_text.text_pointer = _status_text;
  724.                 PathShow_prepare stdcall(#status_text);
  725.                 PathShow_draw stdcall(#status_text);           
  726.         }
  727.         DefineHiddenButton(status_text.start_x+status_text.area_size_x+10, status_text.start_y-3,
  728.                 60, 12, CHANGE_ENCODING);
  729.         WriteTextCenter(status_text.start_x+status_text.area_size_x+10,
  730.                 status_text.start_y, 60, system.color.work_text, WB1.cur_encoding*10+#charsets);
  731. }
  732.  
  733. void DrawOmnibox()
  734. {
  735.         int skin_x_offset;
  736.        
  737.         DrawOvalBorder(address_box.left-2, address_box.top-3, address_box.width+18, 24, system.color.work_graph,
  738.                 system.color.work_graph, system.color.work_graph, system.color.work_dark);
  739.         DrawBar(address_box.left-1, address_box.top-2, address_box.width+18, 1, 0xD8DCD8);
  740.         DrawBar(address_box.left-1, address_box.top-1, address_box.width+18, 1, address_box.color);
  741.         DrawBar(address_box.left-1, address_box.top, 1, 22, address_box.color);
  742.  
  743.         if (address_box.flags & ed_focus) address_box.flags = ed_focus; else address_box.flags = 0;
  744.         EditBox_UpdateText(#address_box, address_box.flags);
  745.         edit_box_draw stdcall(#address_box);
  746.         if (http.transfer > 0) skin_x_offset = 85; else skin_x_offset = 68;
  747.         img_draw stdcall(skin.image, address_box.left+address_box.width+1,
  748.                 address_box.top-1, 16, skin.h-3, skin_x_offset, SKIN_Y+2);
  749.         DefineHiddenButton(address_box.left+address_box.width-1, address_box.top-2, 17, skin.h-3, REFRESH_BUTTON);
  750.  
  751.         DrawProgress();
  752. }
  753.  
  754.  
  755. stop: