Subversion Repositories Kolibri OS

Rev

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

  1. //HTML Viewer in C--
  2. //Copyright 2007-2013 by Veliant & Leency
  3. //Asper, lev, Lrz, Barsuk, Nable...
  4. //home icon - rachel fu, GPL licence
  5.  
  6. #ifndef AUTOBUILD
  7.         #include "lang.h--"
  8. #endif
  9.  
  10. //libraries
  11. #define MEMSIZE 0x100000
  12. #include "..\lib\kolibri.h"
  13. #include "..\lib\strings.h"
  14. #include "..\lib\gui.h"
  15. #include "..\lib\encoding.h"
  16. #include "..\lib\file_system.h"
  17. #include "..\lib\mem.h"
  18. #include "..\lib\dll.h"
  19. #include "..\lib\draw_buf.h"
  20. #include "..\lib\list_box.h"
  21. #include "..\lib\cursor.h"
  22.  
  23. //*.obj libraries
  24. #include "..\lib\obj\box_lib.h"
  25. #include "..\lib\obj\libio_lib.h"
  26. #include "..\lib\obj\libimg_lib.h"
  27. #include "..\lib\obj\http.h"
  28.  
  29. //useful patterns
  30. #include "..\lib\patterns\libimg_load_skin.h"
  31.  
  32. char homepage[] = FROM "html\\homepage.htm";
  33.  
  34. #ifdef LANG_RUS
  35.         char version[]=" ’¥ªáâ®¢ë© ¡à ã§¥à 1.11";
  36.         ?define IMAGES_CACHE_CLEARED "Šíè ª à⨭®ª ®ç¨é¥­"
  37.         ?define T_LAST_SLIDE "â® ¯®á«¥¤­¨© á« ©¤"
  38.         char loading[] = "‡ £à㧪  áâà ­¨æë...<br>";
  39.         char page_not_found[] = FROM "html\page_not_found_ru.htm";
  40.         char accept_language[]= "Accept-Language: ru\n";
  41. #else
  42.         char version[]=" Text-based Browser 1.11";
  43.         ?define IMAGES_CACHE_CLEARED "Images cache cleared"
  44.         ?define T_LAST_SLIDE "This slide is the last"
  45.         char loading[] = "Loading...<br>";
  46.         char page_not_found[] = FROM "html\page_not_found_en.htm";
  47.         char accept_language[]= "Accept-Language: en\n";       
  48. #endif
  49.  
  50. proc_info Form;
  51. #define WIN_W 799
  52. #define WIN_H 559
  53.  
  54. char search_path[]="http://nigma.ru/index.php?s=";
  55. char str_location[]="location\0";
  56. int redirected = 0;
  57.  
  58. char stak[4096];
  59. mouse m;
  60. int action_buf;
  61.  
  62. dword http_transfer = 0;
  63. dword http_buffer;
  64.  
  65. dword TAB_H = false; //19;
  66. dword TAB_W = 150;
  67. dword TOOLBAR_H = 31; //50;
  68. dword STATUSBAR_H = 15;
  69. dword col_bg;
  70. dword panel_color;
  71. dword border_color;
  72.  
  73. progress_bar wv_progress_bar = {0, 10, 83, 150, 12, 0, 0, 100, 0xeeeEEE, 8072B7EBh, 0x9F9F9F};
  74. byte souce_mode = false;
  75.  
  76. #include "..\TWB\TWB.c"
  77. #include "menu_rmb.h"
  78. #include "history.h"
  79. #include "show_src.h"
  80. #include "downloader.h"
  81.  
  82. char editURL[sizeof(URL)];
  83. int     mouse_twb;
  84. edit_box address_box = {250,55,34,0xffffff,0x94AECE,0xffffff,0xffffff,0,sizeof(URL),#editURL,#mouse_twb,2,19,19};
  85.  
  86. #define URL_SERVICE_HISTORY "WebView://history"
  87. #define URL_SERVICE_HOME "WebView://home"
  88. #define URL_SERVICE_SOURCE "WebView://source:"
  89.  
  90. enum { BACK=300, FORWARD, REFRESH, HOME, NEWTAB, GOTOURL, SEARCHWEB, INPUT_CH, INPUT_BT, BTN_UP, BTN_DOWN };
  91.  
  92. libimg_image skin;
  93.  
  94. int SetSkinColors()
  95. {
  96.         dword image_data;
  97.         image_data = DSDWORD[skin.image+24];
  98.         col_bg = DSDWORD[image_data];
  99.         panel_color  = DSDWORD[skin.w*4*4 + image_data];
  100.         border_color = DSDWORD[skin.w*4*7 + image_data];
  101.         wv_progress_bar.progress_color = DSDWORD[skin.w*4*10 + image_data];
  102.         $and col_bg, 0x00ffffff
  103.         $and panel_color, 0x00ffffff
  104.         $and border_color, 0x00ffffff
  105.         $and wv_progress_bar.progress_color, 0x00ffffff
  106. }
  107.  
  108. void DrawProgress()
  109. {
  110.         unsigned long btn;
  111.         //progressbar_draw stdcall(#wv_progress_bar);
  112.         wv_progress_bar.width = wv_progress_bar.left = 0;
  113.         if (http_transfer == 0) return;
  114.         if (wv_progress_bar.max) btn = address_box.width*wv_progress_bar.value/wv_progress_bar.max; else btn = 30;
  115.         DrawBar(address_box.left-1, address_box.top+14, btn, 2, wv_progress_bar.progress_color);
  116. }
  117.  
  118.  
  119. void main()
  120. {
  121.         unsigned long key, btn;
  122.         int half_scroll_size;
  123.         int scroll_used=0, show_menu;
  124.        
  125.         mem_Init();
  126.         CursorPointer.Load(#CursorFile);
  127.         if (load_dll2(boxlib, #box_lib_init,0)!=0) notify("Error: library doesn't exists - box_lib");
  128.         if (load_dll2(libio, #libio_init,1)!=0) notify("Error: library doesn't exists - libio");
  129.         if (load_dll2(libimg, #libimg_init,1)!=0) notify("Error: library doesn't exists - libimg");
  130.         if (load_dll2(libHTTP, #http_lib_init,1)!=0) notify("Error: library doesn't exists - http");
  131.         Libimg_LoadImage(#skin, abspath("wv_skin.png"));
  132.         SetSkinColors();
  133.        
  134.         WB1.DrawBuf.zoomf = 1;
  135.         Form.width=WIN_W;
  136.         Form.height=WIN_H;
  137.         SetElementSizes();
  138.         if (param) strcpy(#URL, #param); else strcpy(#URL, URL_SERVICE_HOME);
  139.         OpenPage();
  140.  
  141.         CreateDir("/tmp0/1/downloads");
  142.  
  143.         SetEventMask(0xa7);
  144.         loop()
  145.         {
  146.                 WaitEventTimeout(2);
  147.                 switch(EAX & 0xFF)
  148.                 {
  149.                         CASE evMouse:
  150.                                 if (!CheckActiveProcess(Form.ID)) break;
  151.                                 //Edit URL
  152.                                 edit_box_mouse stdcall (#address_box);
  153.                                 m.get();
  154.                                 //Links hover
  155.                                 if (m.y>WB1.list.y) PageLinks.Hover(m.x, m.y, link_color_inactive, link_color_active, bg_color);
  156.                                 //Menu
  157.                                 if (m.y>WB1.list.y) && (m.y<Form.height) && (bufsize)
  158.                                 {
  159.                                         if (m.pkm)
  160.                                         {
  161.                                                 show_menu = 1;
  162.                                         }
  163.                                         if (!m.pkm) && (show_menu)
  164.                                         {
  165.                                                 show_menu = 0;
  166.                                                 SwitchToAnotherThread();
  167.                                                 CreateThread(#menu_rmb,#stak+4092);
  168.                                                 break;
  169.                                         }
  170.                                 }
  171.                                 //Mouse scroll
  172.                                 if (m.vert)
  173.                                 {
  174.                                         if (WB1.list.MouseScroll(m.vert)) WB1.Parse();
  175.                                 }
  176.                                 //Drag scroller
  177.                                 scroll_wv.all_redraw = 0;
  178.                                 if (!m.lkm) scroll_used=0;
  179.                                 if (m.x>=scroll_wv.start_x) && (m.x<=scroll_wv.start_x+scroll_wv.size_x)
  180.                                 && (m.y>=scroll_wv.start_y+scroll_wv.btn_height) && (-scroll_wv.btn_height+scroll_wv.start_y+scroll_wv.size_y>m.y)
  181.                                 && (WB1.list.count>WB1.list.visible) && (m.lkm)
  182.                                 {
  183.                                         scroll_used=1;
  184.                                 }                              
  185.                                 if (scroll_used)
  186.                                 {
  187.                                         m.y = m.y / WB1.DrawBuf.zoomf + 5;
  188.                                         half_scroll_size = WB1.list.h - 16 * WB1.list.visible / WB1.list.count - 3 /2;
  189.                                         if (half_scroll_size+WB1.list.y>m.y) || (m.y<0) || (m.y>4000) m.y=half_scroll_size+WB1.list.y;
  190.                                         btn=WB1.list.first;
  191.                                         WB1.list.first = m.y -half_scroll_size -WB1.list.y * WB1.list.count / WB1.list.h;
  192.                                         if (WB1.list.visible+WB1.list.first>WB1.list.count) WB1.list.first=WB1.list.count-WB1.list.visible;
  193.                                         if (btn<>WB1.list.first) WB1.Parse();
  194.                                 }
  195.                                 break;
  196.                         case evButton:
  197.                                 btn=GetButtonID();
  198.                                 if (btn==1)     ExitProcess();
  199.                                 Scan(btn);
  200.                                 break;
  201.                         case evKey:
  202.                                 key = GetKey();        
  203.                                 if (address_box.flags & 0b10) && (key!=ASCII_KEY_ENTER)  
  204.                                 {
  205.                                         if (key<>0x0d) && (key<>183) && (key<>184) {EAX=key<<8; edit_box_key stdcall(#address_box);}
  206.                                 }
  207.                                 else Scan(key);
  208.                                 break;
  209.  
  210.                         case evReDraw:
  211.                                 if (action_buf) Scan(action_buf);
  212.                                 DefineAndDrawWindow(GetScreenWidth()-WIN_W/2,GetScreenHeight()-WIN_H/2,WIN_W,WIN_H,0x73,col_bg,0,0);
  213.                                 GetProcessInfo(#Form, SelfInfo);
  214.                                 if (Form.status_window>2) { DrawTitle(#header); break; }
  215.                                 if (Form.height<120) MoveSize(OLD,OLD,OLD,120);
  216.                                 if (Form.width<280) MoveSize(OLD,OLD,280,OLD);
  217.                                 Draw_Window();
  218.                                 break;
  219.                                
  220.                         case evNetwork:
  221.                                 if (http_transfer > 0) {
  222.                                         http_process stdcall (http_transfer);
  223.                                         $push EAX
  224.                                         ESI = http_transfer;
  225.                                         wv_progress_bar.max = ESI.http_msg.content_length;
  226.                                         if (wv_progress_bar.value != ESI.http_msg.content_received)
  227.                                         {
  228.                                                 wv_progress_bar.value = ESI.http_msg.content_received; 
  229.                                                 DrawProgress();
  230.                                         }
  231.                                         $pop EAX
  232.                                         if (EAX == 0) {
  233.                                                 ESI = http_transfer;
  234.                                                 // Handle redirects
  235.                                                 if (ESI.http_msg.status >= 300) && (ESI.http_msg.status < 400)
  236.                                                 {
  237.                                                         redirected++;
  238.                                                         if (redirected<=5)
  239.                                                         {
  240.                                                                 http_find_header_field stdcall (http_transfer, #str_location);
  241.                                                                 if (EAX!=0) {
  242.                                                                         ESI = EAX;
  243.                                                                         EDI = #URL;
  244.                                                                         do {
  245.                                                                                 $lodsb;
  246.                                                                                 $stosb;
  247.                                                                         } while (AL != 0) && (AL != 13) && (AL != 10));
  248.                                                                         DSBYTE[EDI-1]='\0';
  249.                                                                 }
  250.                                                         }
  251.                                                         else
  252.                                                         {
  253.                                                         //TODO: display error (too many redirects)
  254.                                                         }
  255.                                                 }
  256.                                                 else
  257.                                                 {
  258.                                                         redirected = 0;
  259.                                                 }
  260.                                                 // Loading the page is complete, free resources
  261.                                                 if (redirected>0)
  262.                                                 {
  263.                                                         http_free stdcall (http_transfer);
  264.                                                         http_transfer=0;
  265.                                                         PageLinks.GetAbsoluteURL(#URL);
  266.                                                         BrowserHistory.current--;
  267.                                                         strcpy(#editURL, #URL);
  268.                                                         OpenPage();
  269.                                                 }
  270.                                                 else
  271.                                                 {
  272.                                                         BrowserHistory.AddUrl();
  273.                                                         ESI = http_transfer;
  274.                                                         bufpointer = ESI.http_msg.content_ptr;
  275.                                                         bufsize = ESI.http_msg.content_received;
  276.                                                         http_free stdcall (http_transfer);
  277.                                                         http_transfer=0;
  278.                                                         SetPageDefaults();
  279.                                                         Draw_Window();          // stop button => refresh button
  280.                                                 }
  281.                                         }
  282.                                 }
  283.                 }
  284.         }
  285. }
  286.  
  287. void SetElementSizes()
  288. {
  289.         address_box.top = TOOLBAR_H-TAB_H/2-7+TAB_H;
  290.         address_box.width = Form.cwidth - address_box.left - 25 - 22;
  291.         WB1.list.SetSizes(0, TOOLBAR_H, Form.width - 10 - scroll_wv.size_x / WB1.DrawBuf.zoomf, Form.cheight - TOOLBAR_H - STATUSBAR_H / WB1.DrawBuf.zoomf, 0, 11);
  292.         WB1.list.column_max = WB1.list.w - scroll_wv.size_x / 6;
  293.         WB1.list.visible = WB1.list.h - 5 / WB1.list.line_h;
  294.         WB1.DrawBuf.Init(WB1.list.x, WB1.list.y, WB1.list.w, WB1.list.line_h);
  295. }
  296.  
  297. void Draw_Window()
  298. {
  299.         int img_off;
  300.         // tab {
  301.         if (TAB_H)
  302.         {
  303.                 DrawBar(0, 0, TAB_W, TAB_H+1, panel_color);
  304.                 WriteText(5, 7, 0x80, 0xfdfdFd, "Index.htm");
  305.                 WriteText(4, 6, 0x80, 0, "Index.htm");         
  306.                 DrawBar(TAB_W,0, Form.cwidth-TAB_W,TAB_H, col_bg);
  307.                 DrawBar(TAB_W-1,TAB_H, Form.cwidth-TAB_W+1,1, border_color);
  308.                 img_draw stdcall(skin.image, TAB_W-13, 0, 30, skin.h, 101, 0);
  309.         }
  310.         else DrawBar(0,0, Form.cwidth,1, col_bg);
  311.         // }
  312.         DrawBar(0,TAB_H+1, Form.cwidth,TOOLBAR_H-TAB_H-3, panel_color);
  313.         DrawBar(0,TOOLBAR_H-2, Form.cwidth,1, 0xe9e9e9);
  314.         DrawBar(0,TOOLBAR_H-1, Form.cwidth,1, border_color);
  315.         SetElementSizes();
  316.         DrawRectangle(address_box.left-1, address_box.top-1, address_box.width+2, 16,address_box.color);
  317.         DrawRectangle(address_box.left-2, address_box.top-2, address_box.width+4, 18,border_color);
  318.         // < / >
  319.         DefineButton(address_box.left-49, address_box.top-1, 23, skin.h-2, 300+BT_HIDE, 0);
  320.         DefineButton(address_box.left-25, address_box.top-1, 23, skin.h-2, 301+BT_HIDE, 0);
  321.         img_draw stdcall(skin.image, address_box.left-50, address_box.top-2, 48, skin.h, 3, 0);
  322.         // refrash
  323.         DefineButton(address_box.left+address_box.width+1, address_box.top-2, 16, skin.h-1, REFRESH+BT_HIDE+BT_NOFRAME, 0);
  324.         if (http_transfer > 0) img_off = 131; else img_off = 52;
  325.         img_draw stdcall(skin.image, address_box.left+address_box.width+1, address_box.top-2, 17, skin.h, img_off, 0);
  326.         // config
  327.         DefineButton(Form.cwidth-23, address_box.top-2, 17, skin.h-1, 312+BT_HIDE, 0);
  328.         img_draw stdcall(skin.image, Form.cwidth-22, address_box.top-2, 16, skin.h, 85, 0);
  329.         //status bar
  330.         DrawBar(0,Form.cheight - STATUSBAR_H, Form.cwidth,STATUSBAR_H, col_bg);
  331.         DrawBar(0,Form.cheight - STATUSBAR_H, Form.cwidth,1, border_color);
  332.         wv_progress_bar.top = Form.cheight - STATUSBAR_H + 4;
  333.         ShowPage();
  334.         DrawRectangle(scroll_wv.start_x, scroll_wv.start_y, scroll_wv.size_x, scroll_wv.size_y-1, scroll_wv.bckg_col);
  335.         DrawProgress();
  336. }
  337.  
  338.  
  339. void ChangeCharset(byte new_charset)
  340. {
  341.         BufEncode(new_charset);
  342.         WB1.Parse();   
  343. }
  344.  
  345. void Scan(int id)
  346. {
  347.         action_buf=0;
  348.         if (id >= 400)
  349.         {
  350.                 ProcessLinks(id);
  351.                 return;
  352.         }
  353.         switch (id)
  354.         {
  355.                 case 011: //Ctrk+K
  356.                         ChangeCharset(_KOI);
  357.                         return;
  358.  
  359.                 case 021: //Ctrl+U
  360.                         ChangeCharset(_UTF);
  361.                         return;
  362.  
  363.                 case 004: //Ctrl+D
  364.                         ChangeCharset(_DOS);
  365.                         return;
  366.  
  367.                 case 005: //Win encoding
  368.                         ChangeCharset(_WIN);
  369.                         return;
  370.  
  371.                 case 009: //free img cache
  372.                         ImgCache.Free();
  373.                         notify(IMAGES_CACHE_CLEARED);
  374.                         WB1.Parse();
  375.                         return;
  376.  
  377.                 case 003: //history
  378.                         strcpy(#URL, URL_SERVICE_HISTORY);
  379.                         OpenPage();
  380.                         return;
  381.  
  382.                 case 006: //download manager
  383.                         if (!downloader_opened) {
  384.                                 strcpy(#DL_URL, "http://");
  385.                                 CreateThread(#Downloader,#downloader_stak+4092);
  386.                         }
  387.                         return;
  388.  
  389.                 case ASCII_KEY_BS:
  390.                 case BACK:
  391.                         if (!BrowserHistory.GoBack()) return;
  392.                         OpenPage();
  393.                         return;
  394.                 case FORWARD:
  395.                         if (!BrowserHistory.GoForward()) return;
  396.                         OpenPage();
  397.                         return;
  398.                 case 052: //F3
  399.                         WB1.list.first = 0;
  400.                         ShowSource();
  401.                         WB1.Parse();
  402.                         break;
  403.                 case 053: //F4
  404.                         if (strncmp(#URL,"http:",5)==0)
  405.                         {
  406.                                 WriteFile(bufsize, bufpointer, "/tmp0/1/WebView_tmp.htm");
  407.                                 if (EAX==0) RunProgram("/rd/1/tinypad", "/tmp0/1/WebView_tmp.htm");
  408.                         }
  409.                         else
  410.                         {
  411.                                 RunProgram("/rd/1/tinypad", #URL);
  412.                         }
  413.                         return;
  414.                 case 054: //F5
  415.                         IF(address_box.flags & 0b10) return;
  416.                 case REFRESH:
  417.                         if (http_transfer > 0)
  418.                         {
  419.                                 StopLoading();
  420.                                 Draw_Window();
  421.                         }
  422.                         else OpenPage();
  423.                         return;
  424.                 case 014:
  425.                 case 020:
  426.                 case NEWTAB:
  427.                         MoveSize(190,80,OLD,OLD);
  428.                         RunProgram(#program_path, #URL);
  429.                         return;
  430.                 case GOTOURL:
  431.                 case 0x0D: //enter
  432.                         if (!editURL[0]) return;
  433.                         if ((strncmp(#editURL,"http:",5)!=0) && (editURL[0]!='/') && ((strncmp(#editURL,"WebView:",8)!=0))
  434.                         {
  435.                                 strcpy(#URL,"http://");
  436.                         }
  437.                         else
  438.                                 URL[0] = 0;
  439.                         strcat(#URL, #editURL);
  440.                         OpenPage();
  441.                         return;
  442.                 case SEARCHWEB:
  443.                         strcpy(#URL, #search_path);
  444.                         strcat(#URL, #editURL);
  445.                         OpenPage();
  446.                         return;
  447.  
  448.                 case 183: //PgDown
  449.                         if (WB1.list.count < WB1.list.visible) return;
  450.                         IF(WB1.list.first == WB1.list.count - WB1.list.visible) return;
  451.                         WB1.list.first += WB1.list.visible + 2;
  452.                         IF(WB1.list.visible + WB1.list.first > WB1.list.count) WB1.list.first = WB1.list.count - WB1.list.visible;
  453.                         WB1.Parse();
  454.                         return;
  455.  
  456.                 case 184: //PgUp
  457.                         if (WB1.list.count < WB1.list.visible) return;
  458.                         IF(WB1.list.first == 0) return;
  459.                         WB1.list.first -= WB1.list.visible - 2;
  460.                         IF(WB1.list.first < 0) WB1.list.first = 0;
  461.                         WB1.Parse();
  462.                         return;
  463.  
  464.                 case 178:
  465.                 case BTN_UP:
  466.                         if (WB1.list.first <= 0) return;
  467.                         WB1.list.first--;
  468.                         WB1.Parse();
  469.                         return;
  470.  
  471.                 case 177:
  472.                 case BTN_DOWN:
  473.                         if (WB1.list.visible + WB1.list.first >= WB1.list.count) return;
  474.                         WB1.list.first++;
  475.                         WB1.Parse();
  476.                         return;
  477.  
  478.                 case 180: //home
  479.                         if (WB1.list.KeyHome()) WB1.Parse();
  480.                         return;
  481.  
  482.                 case 181: //end
  483.                         if (WB1.list.count < WB1.list.visible) return;
  484.                         if (WB1.list.KeyEnd()) WB1.Parse();
  485.                         return;
  486.                 case 312:
  487.                         SwitchToAnotherThread();
  488.                         m.y = TOOLBAR_H-6;
  489.                         m.x = Form.cwidth - 167;
  490.                         CreateThread(#menu_rmb,#stak+4092);
  491.                         return;
  492.                 case 122:
  493.                         if (WB1.DrawBuf.zoomf==1) WB1.DrawBuf.zoomf=2; else WB1.DrawBuf.zoomf=1;
  494.                         Draw_Window();
  495.         }
  496. }
  497.  
  498.  
  499.  
  500. void ProcessLinks(int id)
  501. {
  502.         if (http_transfer > 0)
  503.         {
  504.                 StopLoading();
  505.                 BrowserHistory.current--;
  506.         }
  507.  
  508.         strcpy(#URL, PageLinks.GetURL(id-401));
  509.         //$1 - Condition Script
  510.         if (URL[0] == '$')
  511.         {
  512.                 if (URL[1]=='-') && (condition_href) condition_href--;
  513.                 if (URL[1]=='+')
  514.                 {
  515.                         if (condition_href<condition_max) condition_href++; else notify(T_LAST_SLIDE);
  516.                 }
  517.                 if (URL[1]!='-') && (URL[1]!='+') condition_href = atoi(#URL+1);
  518.                 strcpy(#URL, BrowserHistory.CurrentUrl());
  519.                 ShowPage();
  520.                 return;
  521.         }
  522.         //#1
  523.         if (URL[0] == '#')
  524.         {
  525.                 strcpy(#anchor, #URL+strrchr(#URL, '#'));              
  526.                 strcpy(#URL, BrowserHistory.CurrentUrl());
  527.                 WB1.list.first=WB1.list.count-WB1.list.visible;
  528.                 ShowPage();
  529.                 return;
  530.         }
  531.         //liner.ru#1
  532.         if (strrchr(#URL, '#')!=-1)
  533.         {
  534.                 strcpy(#anchor, #URL+strrchr(#URL, '#'));
  535.                 URL[strrchr(#URL, '#')-1] = 0x00;
  536.         }
  537.        
  538.         PageLinks.GetAbsoluteURL(#URL);
  539.        
  540.         if (UrlExtIs(".png")==1) || (UrlExtIs(".gif")==1) || (UrlExtIs(".jpg")==1) || (UrlExtIs(".zip")==1) || (UrlExtIs(".kex")==1)
  541.         || (UrlExtIs(".7z")==1) || (UrlExtIs("netcfg")==1)
  542.         {
  543.                 //notify(#URL);
  544.                 if (strcmpn(#URL,"http://", 7)==0)
  545.                 {
  546.                         strcpy(#DL_URL, #URL);
  547.                         CreateThread(#Downloader,#downloader_stak+4092);
  548.                 }
  549.                 else
  550.                 {
  551.                         RunProgram("@open", #URL);
  552.                 }
  553.                 strcpy(#editURL, BrowserHistory.CurrentUrl());
  554.                 strcpy(#URL, BrowserHistory.CurrentUrl());
  555.                 return;
  556.         }
  557.         if (!strcmpn(#URL,"mailto:", 7))
  558.         {
  559.                 notify(#URL);
  560.                 strcpy(#editURL, BrowserHistory.CurrentUrl());
  561.                 strcpy(#URL, BrowserHistory.CurrentUrl());
  562.                 return;
  563.         }
  564.         OpenPage();
  565.         return;
  566. }
  567.  
  568. void StopLoading()
  569. {
  570.         if (http_transfer<>0)
  571.         {
  572.                 EAX = http_transfer;
  573.                 EAX = EAX.http_msg.content_ptr;         // get pointer to data
  574.                 $push   EAX                                                     // save it on the stack
  575.                 http_free stdcall (http_transfer);      // abort connection
  576.                 $pop    EAX                                                    
  577.                 mem_Free(EAX);                                          // free data
  578.                 http_transfer=0;
  579.                 bufsize = 0;
  580.                 bufpointer = mem_Free(bufpointer);
  581.         }
  582.         wv_progress_bar.value = 0;
  583.         img_draw stdcall(skin.image, address_box.left+address_box.width+1, address_box.top-2, 17, skin.h, 52, 0);
  584. }
  585.  
  586. void SetPageDefaults()
  587. {
  588.         strcpy(#header, #version);
  589.         pre_text = 0;
  590.         WB1.list.count = WB1.list.first = 0;
  591.         stroka = 0;
  592.         cur_encoding = _DEFAULT;
  593.         if (o_bufpointer) o_bufpointer = free(o_bufpointer);
  594.         anchor_line_num=WB1.list.first;
  595.         anchor[0]='|';
  596. }
  597.  
  598. void OpenPage()
  599. {
  600.         StopLoading();
  601.         souce_mode = false;
  602.         strcpy(#editURL, #URL);
  603.         BrowserHistory.AddUrl();
  604.         if (strncmp(#URL,"WebView:",8)==0)
  605.         {
  606.                 SetPageDefaults();
  607.                 if (strcmp(#URL, URL_SERVICE_HOME)==0)
  608.                 {
  609.                         WB1.Prepare(#homepage, sizeof(homepage));
  610.                 }
  611.                 if (strcmp(#URL, URL_SERVICE_HISTORY)==0)
  612.                 {
  613.                         ShowHistory();
  614.                 }
  615.                 return;
  616.         }
  617.         if (strncmp(#URL,"http:",5)==0)
  618.         {
  619.                 img_draw stdcall(skin.image, address_box.left+address_box.width+1, address_box.top-2, 17, skin.h, 131, 0);
  620.                 http_get stdcall (#URL, #accept_language);
  621.                 http_transfer = EAX;
  622.                 if (http_transfer == 0)
  623.                 {
  624.                         StopLoading();
  625.                         bufsize = 0;
  626.                         bufpointer = mem_Free(bufpointer);
  627.                         ShowPage();
  628.                         return;
  629.                 }
  630.         }
  631.         else
  632.         {
  633.                 file_size stdcall (#URL);
  634.                 bufsize = EBX;
  635.                 if (bufsize)
  636.                 {
  637.                         mem_Free(bufpointer);
  638.                         bufpointer = mem_Alloc(bufsize);
  639.                         SetPageDefaults();
  640.                         ReadFile(0, bufsize, bufpointer, #URL);
  641.                         //ShowSource();
  642.                 }
  643.                 ShowPage();
  644.         }
  645. }
  646.  
  647. DrawEditBox()
  648. {
  649.         address_box.size = address_box.pos = address_box.shift = address_box.shift_old = strlen(#editURL);
  650.         address_box.offset = 0;
  651.         edit_box_draw stdcall(#address_box);
  652. }
  653.  
  654.  
  655. void ShowPage()
  656. {
  657.         DrawEditBox();
  658.         if (!bufsize)
  659.         {
  660.                 PageLinks.Clear();
  661.                 if (http_transfer<>0)
  662.                 {
  663.                         WB1.Prepare(#loading, sizeof(loading));
  664.                 }
  665.                 else
  666.                         WB1.Prepare(#page_not_found, sizeof(page_not_found));
  667.         }
  668.         else
  669.                 WB1.Parse();
  670.  
  671.         if (!header) strcpy(#header, #version);
  672.         if (!strcmp(#version, #header)) DrawTitle(#header);
  673. }
  674.  
  675. byte UrlExtIs(dword ext)
  676. {
  677.         if (strcmpi(#URL + strlen(#URL) - strlen(ext), ext)==0) return 1; else return 0;
  678. }
  679.  
  680.  
  681.  
  682.  
  683. stop:
  684.  
  685. char downloader_stak[4096];
  686.