Subversion Repositories Kolibri OS

Rev

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