Subversion Repositories Kolibri OS

Rev

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