Subversion Repositories Kolibri OS

Rev

Rev 5749 | Rev 5768 | 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.3 UNSTABLE";
  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.3 UNSTABLE";
  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;
  74. byte souce_mode = false;
  75.  
  76. enum {
  77.         BACK_BUTTON=1000,
  78.         FORWARD_BUTTON,
  79.         REFRESH_BUTTON,
  80.         GOTOURL_BUTTON,
  81.         SEARCHWEB_BUTTON,
  82.         SANDWICH_BUTTON
  83. };
  84.  
  85. enum {
  86.         ZOOM2x=1100,
  87.         VIEW_SOURCE,
  88.         EDIT_SOURCE,
  89.         VIEW_HISTORY,
  90.         FREE_IMG_CACHE,
  91.         DOWNLOAD_MANAGER
  92. };
  93.  
  94. #include "..\TWB\TWB.c"
  95. #include "menu_rmb.h"
  96. #include "history.h"
  97. #include "show_src.h"
  98. #include "network_get.h"
  99. #include "downloader.h"
  100.  
  101. char editURL[sizeof(URL)];
  102. int     mouse_twb;
  103. edit_box address_box = {250,55,34,0xffffff,0x94AECE,0xffffff,0xffffff,0,sizeof(URL),#editURL,#mouse_twb,2,19,19};
  104.  
  105. #define URL_SERVICE_HISTORY "WebView://history"
  106. #define URL_SERVICE_HOME "WebView://home"
  107. #define URL_SERVICE_SOURCE "WebView://source:"
  108.  
  109.  
  110. libimg_image skin;
  111.  
  112. int SetSkinColors()
  113. {
  114.         dword image_data;
  115.         image_data = DSDWORD[skin.image+24];
  116.         col_bg = DSDWORD[image_data];
  117.         panel_color  = DSDWORD[skin.w*4*4 + image_data];
  118.         border_color = DSDWORD[skin.w*4*7 + image_data];
  119.         wv_progress_bar.progress_color = DSDWORD[skin.w*4*10 + image_data];
  120.         $and col_bg, 0x00ffffff
  121.         $and panel_color, 0x00ffffff
  122.         $and border_color, 0x00ffffff
  123.         $and wv_progress_bar.progress_color, 0x00ffffff
  124. }
  125.  
  126. void DrawProgress()
  127. {
  128.         unsigned long btn;
  129.         if (http_transfer == 0) return;
  130.         if (wv_progress_bar.max) btn = address_box.width*wv_progress_bar.value/wv_progress_bar.max; else btn = 30;
  131.         DrawBar(address_box.left-1, address_box.top+15, btn, 2, wv_progress_bar.progress_color);
  132. }
  133.  
  134.  
  135. void main()
  136. {
  137.         dword btn;
  138.         int half_scroll_size;
  139.         int scroll_used=0, show_menu;
  140.  
  141.         CursorPointer.Load(#CursorFile);
  142.         load_dll(boxlib, #box_lib_init,0);
  143.         load_dll(libio, #libio_init,1);
  144.         load_dll(libimg, #libimg_init,1);
  145.         load_dll(libHTTP, #http_lib_init,1);
  146.         load_dll(iconv_lib, #iconv_open,0);
  147.         //load_dll(kmenu, #akmenu_init,0);
  148.         Libimg_LoadImage(#skin, abspath("wv_skin.png"));
  149.         SetSkinColors();
  150.        
  151.         WB1.DrawBuf.zoom = 1;
  152.         WB1.list.SetFont(8, 14, 10111000b);
  153.         Form.width=WIN_W;
  154.         Form.height=WIN_H;
  155.         SetElementSizes();
  156.         if (param) strcpy(#URL, #param); else strcpy(#URL, URL_SERVICE_HOME);
  157.         OpenPage();
  158.  
  159.         CreateDir("/tmp0/1/downloads");
  160.  
  161.         SetEventMask(0xa7);
  162.         BEGIN_LOOP_APPLICATION:
  163.                 WaitEventTimeout(2);
  164.                 switch(EAX & 0xFF)
  165.                 {
  166.                         CASE evMouse:
  167.                                 if (!CheckActiveProcess(Form.ID)) break;
  168.                                 //Edit URL
  169.                                 edit_box_mouse stdcall (#address_box);
  170.                                 mouse.get();
  171.                                 //Links hover
  172.                                 if (mouse.y>WB1.list.y) PageLinks.Hover(mouse.x, mouse.y, link_color_inactive, link_color_active, bg_color);
  173.                                 //Menu
  174.                                 if (mouse.y>WB1.list.y) && (mouse.y<Form.height) && (bufsize)
  175.                                 {
  176.                                         if (mouse.pkm) && (mouse.up)
  177.                                         {
  178.                                                 CreateThread(#menu_rmb,#stak+4092);
  179.                                                 break;
  180.                                         }
  181.                                 }
  182.                                 //Mouse scroll
  183.                                 if (mouse.vert)
  184.                                 {
  185.                                         if (WB1.list.MouseScroll(mouse.vert)) WB1.DrawPage();
  186.                                 }
  187.                                 //Drag scroller
  188.                                 scroll_wv.all_redraw = 0;
  189.                                 if (!mouse.lkm) scroll_used=0;
  190.                                 if (mouse.x>=scroll_wv.start_x) && (mouse.x<=scroll_wv.start_x+scroll_wv.size_x)
  191.                                 && (mouse.y>=scroll_wv.start_y+scroll_wv.btn_height) && (-scroll_wv.btn_height+scroll_wv.start_y+scroll_wv.size_y>mouse.y)
  192.                                 && (WB1.list.count>WB1.list.visible) && (mouse.lkm)
  193.                                 {
  194.                                         scroll_used=1;
  195.                                 }                              
  196.                                 if (scroll_used)
  197.                                 {
  198.                                         mouse.y = mouse.y + 5;
  199.                                         half_scroll_size = WB1.list.h - 16 * WB1.list.visible / WB1.list.count - 3 /2;
  200.                                         if (half_scroll_size+WB1.list.y>mouse.y) || (mouse.y<0) || (mouse.y>4000) mouse.y=half_scroll_size+WB1.list.y;
  201.                                         btn=WB1.list.first;
  202.                                         WB1.list.first = mouse.y -half_scroll_size -WB1.list.y * WB1.list.count / WB1.list.h;
  203.                                         if (WB1.list.visible+WB1.list.first>WB1.list.count) WB1.list.first=WB1.list.count-WB1.list.visible;
  204.                                         if (btn!=WB1.list.first) WB1.DrawPage();
  205.                                 }
  206.                                 break;
  207.  
  208.                         case evButton:
  209.                                 btn=GetButtonID();
  210.                                 if (btn==1)     ExitProcess();
  211.                                 Scan(btn);
  212.                                 break;
  213.  
  214.                         case evKey:
  215.                                 GetKeys();
  216.                                 if (address_box.flags & 0b10)  
  217.                                 {
  218.                                         if (key_ascii == ASCII_KEY_ENTER) Scan(key_scancode); else
  219.                                         if (key_ascii != 0x0d) && (key_ascii != 183) && (key_ascii != 184) {EAX = key_ascii << 8; edit_box_key stdcall(#address_box);}
  220.                                 }
  221.                                 else
  222.                                 {
  223.                                         Scan(key_scancode);
  224.                                 }
  225.                                 break;
  226.  
  227.                         case evReDraw:
  228.                                 if (action_buf) Scan(action_buf);
  229.                                 DefineAndDrawWindow(GetScreenWidth()-WIN_W/2,GetScreenHeight()-WIN_H/2,WIN_W,WIN_H,0x73,col_bg,0,0);
  230.                                 GetProcessInfo(#Form, SelfInfo);
  231.                                 if (Form.status_window>2) { DrawTitle(#header); break; }
  232.                                 if (Form.height<120) MoveSize(OLD,OLD,OLD,120);
  233.                                 if (Form.width<280) MoveSize(OLD,OLD,280,OLD);
  234.                                 Draw_Window();
  235.                                 break;
  236.                                
  237.                         case evNetwork:
  238.                                 if (http_transfer > 0) {
  239.                                         http_receive stdcall (http_transfer);
  240.                                         $push EAX
  241.                                         ESI = http_transfer;
  242.                                         wv_progress_bar.max = ESI.http_msg.content_length;
  243.                                         if (wv_progress_bar.value != ESI.http_msg.content_received)
  244.                                         {
  245.                                                 wv_progress_bar.value = ESI.http_msg.content_received; 
  246.                                                 DrawProgress();
  247.                                         }
  248.                                         $pop EAX
  249.                                         if (EAX == 0) {
  250.                                                 ESI = http_transfer;
  251.                                                 // Handle redirects
  252.                                                 if (ESI.http_msg.status >= 300) && (ESI.http_msg.status < 400)
  253.                                                 {
  254.                                                         redirected++;
  255.                                                         if (redirected<=5)
  256.                                                         {
  257.                                                                 http_find_header_field stdcall (http_transfer, #str_location);
  258.                                                                 if (EAX!=0) {
  259.                                                                         ESI = EAX;
  260.                                                                         EDI = #URL;
  261.                                                                         do {
  262.                                                                                 $lodsb;
  263.                                                                                 $stosb;
  264.                                                                         } while (AL != 0) && (AL != 13) && (AL != 10));
  265.                                                                         DSBYTE[EDI-1]='\0';
  266.                                                                 }
  267.                                                         }
  268.                                                         else
  269.                                                         {
  270.                                                         //TODO: display error (too many redirects)
  271.                                                         }
  272.                                                 }
  273.                                                 else
  274.                                                 {
  275.                                                         redirected = 0;
  276.                                                 }
  277.                                                 // Loading the page is complete, free resources
  278.                                                 if (redirected>0)
  279.                                                 {
  280.                                                         http_free stdcall (http_transfer);
  281.                                                         http_transfer=0;
  282.                                                         PageLinks.GetAbsoluteURL(#URL);
  283.                                                         BrowserHistory.current--;
  284.                                                         strcpy(#editURL, #URL);
  285.                                                         DrawEditBox();
  286.                                                         OpenPage();
  287.                                                 }
  288.                                                 else
  289.                                                 {
  290.                                                         BrowserHistory.AddUrl();
  291.                                                         ESI = http_transfer;
  292.                                                         bufpointer = ESI.http_msg.content_ptr;
  293.                                                         bufsize = ESI.http_msg.content_received;
  294.                                                         http_free stdcall (http_transfer);
  295.                                                         http_transfer=0;
  296.                                                         SetPageDefaults();
  297.                                                         Draw_Window();          // stop button => refresh button
  298.                                                 }
  299.                                         }
  300.                                 }
  301.                 }
  302.         goto BEGIN_LOOP_APPLICATION;
  303. }
  304.  
  305. void SetElementSizes()
  306. {
  307.         address_box.top = TOOLBAR_H-TAB_H/2-7+TAB_H;
  308.         address_box.width = Form.cwidth - address_box.left - 25 - 22;
  309.         WB1.list.SetSizes(0, TOOLBAR_H, Form.width - 10 - scroll_wv.size_x / WB1.DrawBuf.zoom,
  310.                 Form.cheight - TOOLBAR_H - STATUSBAR_H, WB1.list.font_h + WB1.DrawBuf.zoom + WB1.DrawBuf.zoom * WB1.DrawBuf.zoom);
  311.         WB1.list.wheel_size = 7;
  312.         WB1.list.column_max = WB1.list.w - scroll_wv.size_x / WB1.list.font_w;
  313.         WB1.list.visible = WB1.list.h - 5 / WB1.list.line_h;
  314.         WB1.DrawBuf.Init(WB1.list.x, WB1.list.y, WB1.list.w, WB1.list.h * 20);
  315. }
  316.  
  317. void Draw_Window()
  318. {
  319.         int img_off;
  320.         // tab {
  321.         /*
  322.         if (TAB_H)
  323.         {
  324.                 DrawBar(0, 0, TAB_W, TAB_H+1, panel_color);
  325.                 WriteText(5, 7, 0x80, 0xfdfdFd, "Index.htm");
  326.                 WriteText(4, 6, 0x80, 0, "Index.htm");         
  327.                 DrawBar(TAB_W,0, Form.cwidth-TAB_W,TAB_H, col_bg);
  328.                 DrawBar(TAB_W-1,TAB_H, Form.cwidth-TAB_W+1,1, border_color);
  329.                 img_draw stdcall(skin.image, TAB_W-13, 0, 30, skin.h, 101, 0);
  330.         }
  331.         else */ DrawBar(0,0, Form.cwidth,1, col_bg);
  332.         // }
  333.         DrawBar(0,TAB_H+1, Form.cwidth,TOOLBAR_H-TAB_H-3, panel_color);
  334.         DrawBar(0,TOOLBAR_H-2, Form.cwidth,1, 0xD7D0D3);
  335.         DrawBar(0,TOOLBAR_H-1, Form.cwidth,1, border_color);
  336.         SetElementSizes();
  337.         DrawRectangle(address_box.left-2, address_box.top-3, address_box.width+4, 20,border_color);
  338.         DrawRectangle(address_box.left-1, address_box.top-2, address_box.width+2, 18,address_box.color);
  339.         DrawRectangle(address_box.left-1, address_box.top-1, address_box.width+2, 16,address_box.color);
  340.         // < / >
  341.         DefineButton(address_box.left-49, address_box.top-2, 23, skin.h-2, BACK_BUTTON+BT_HIDE, 0);
  342.         DefineButton(address_box.left-25, address_box.top-2, 23, skin.h-2, FORWARD_BUTTON+BT_HIDE, 0);
  343.         img_draw stdcall(skin.image, address_box.left-50, address_box.top-3, 48, skin.h, 3, 0);
  344.         // refresh_BUTTON
  345.         DefineButton(address_box.left+address_box.width+1, address_box.top-3, 16, skin.h-1, REFRESH_BUTTON+BT_HIDE+BT_NOFRAME, 0);
  346.         if (http_transfer > 0) img_off = 131; else img_off = 52;
  347.         img_draw stdcall(skin.image, address_box.left+address_box.width+1, address_box.top-3, 17, skin.h, img_off, 0);
  348.         // config
  349.         DefineButton(Form.cwidth-24, address_box.top-3, 19, skin.h-1, SANDWICH_BUTTON+BT_HIDE, 0);
  350.         img_draw stdcall(skin.image, Form.cwidth-22, address_box.top-3, 16, skin.h, 85, 0);
  351.         //status bar
  352.         DrawBar(0,Form.cheight - STATUSBAR_H, Form.cwidth,STATUSBAR_H, col_bg);
  353.         DrawBar(0,Form.cheight - STATUSBAR_H, Form.cwidth,1, border_color);
  354.         ShowPage();
  355.         DrawRectangle(scroll_wv.start_x, scroll_wv.start_y, scroll_wv.size_x, scroll_wv.size_y-1, scroll_wv.bckg_col);
  356.         DrawProgress();
  357. }
  358.  
  359.  
  360. void Scan(dword id__)
  361. {
  362.         action_buf=0;
  363.         if (id__ >= 400) && (id__ < 1000)
  364.         {
  365.                 ProcessLinks(id__);
  366.                 return;
  367.         }
  368.         switch (id__)
  369.         {
  370.                 case SCAN_CODE_BS:
  371.                 case BACK_BUTTON:
  372.                         if (!BrowserHistory.GoBack()) return;
  373.                         OpenPage();
  374.                         return;
  375.  
  376.                 case FORWARD_BUTTON:
  377.                         if (!BrowserHistory.GoForward()) return;
  378.                         OpenPage();
  379.                         return;
  380.  
  381.                 case SCAN_CODE_HOME:
  382.                 case SCAN_CODE_END:
  383.                 case SCAN_CODE_PGUP:
  384.                 case SCAN_CODE_PGDN:
  385.                         if (WB1.list.ProcessKey(key_scancode)) WB1.DrawPage();
  386.                         return;
  387.  
  388.                 case SCAN_CODE_UP:
  389.                         if (WB1.list.first <= 0) return;
  390.                         WB1.list.first--;
  391.                         WB1.DrawPage();
  392.                         return;
  393.  
  394.                 case SCAN_CODE_DOWN:
  395.                         if (WB1.list.visible + WB1.list.first >= WB1.list.count) return;
  396.                         WB1.list.first++;
  397.                         WB1.DrawPage();
  398.                         return;
  399.  
  400.                 case GOTOURL_BUTTON:
  401.                 case SCAN_CODE_ENTER: //enter
  402.                         if (!editURL[0]) return;
  403.                         if (strncmp(#editURL,"http:",5)) && (editURL[0]!='/') && (strncmp(#editURL,"WebView:",9)) strncpy(#URL,"http://",7);
  404.                         else
  405.                                 URL[0] = 0;
  406.                         strcat(#URL, #editURL);
  407.                         OpenPage();
  408.                         return;
  409.  
  410.                 case 063: //F5
  411.                         IF(address_box.flags & 0b10) return;
  412.                 case REFRESH_BUTTON:
  413.                         if (http_transfer > 0)
  414.                         {
  415.                                 StopLoading();
  416.                                 Draw_Window();
  417.                         }
  418.                         else OpenPage();
  419.                         return;
  420.  
  421.                 case SANDWICH_BUTTON:
  422.                         mouse.y = TOOLBAR_H-6;
  423.                         mouse.x = Form.cwidth - 167;
  424.                         CreateThread(#menu_rmb,#stak+4092);
  425.                         return;
  426.  
  427.                 case ZOOM2x:
  428.                         if (WB1.DrawBuf.zoom==2)
  429.                         {
  430.                                 WB1.DrawBuf.zoom=1;
  431.                                 WB1.list.SetFont(8, 14, 10111000b);
  432.                         }
  433.                         else
  434.                         {
  435.                                 WB1.DrawBuf.zoom=2;
  436.                                 WB1.list.SetFont(8, 14, 10111001b);
  437.                         }
  438.                         Draw_Window();
  439.                         return;
  440.  
  441.                 case VIEW_SOURCE:
  442.                         WB1.list.first = 0;
  443.                         ShowSource();
  444.                         WB1.DrawPage();
  445.                         break;
  446.  
  447.                 case EDIT_SOURCE:
  448.                         if (!strncmp(#URL,"http:",5))
  449.                         {
  450.                                 WriteFile(bufsize, bufpointer, "/tmp0/1/WebView_tmp.htm");
  451.                                 if (!EAX) RunProgram("/rd/1/tinypad", "/tmp0/1/WebView_tmp.htm");
  452.                         }
  453.                         else RunProgram("/rd/1/tinypad", #URL);
  454.                         return;
  455.  
  456.                 case FREE_IMG_CACHE:
  457.                         ImgCache.Free();
  458.                         notify(IMAGES_CACHE_CLEARED);
  459.                         WB1.DrawPage();
  460.                         return;
  461.  
  462.                 case VIEW_HISTORY:
  463.                         strcpy(#URL, URL_SERVICE_HISTORY);
  464.                         OpenPage();
  465.                         return;
  466.  
  467.                 case DOWNLOAD_MANAGER:
  468.                         if (!downloader_opened) {
  469.                                 strncpy(#DL_URL, "http://",7);
  470.                                 CreateThread(#Downloader,#downloader_stak+4092);
  471.                         }
  472.                         return;
  473. /*
  474.                 case 020:
  475.                 case NEWTAB:
  476.                         MoveSize(190,80,OLD,OLD);
  477.                         RunProgram(#program_path, #URL);
  478.                         return;
  479.  
  480.                 case SEARCHWEB_BUTTON:
  481.                         sprintf(#URL,"%s%s",#search_path,#editURL);
  482.                         OpenPage();
  483.                         return;
  484. */
  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
  500.         if (URL[0] == '#')
  501.         {
  502.                 strcpy(#anchor, #URL+strrchr(#URL, '#'));              
  503.                 strcpy(#URL, BrowserHistory.CurrentUrl());
  504.                 WB1.list.first=WB1.list.count-WB1.list.visible;
  505.                 ShowPage();
  506.                 return;
  507.         }
  508.         //liner.ru#1
  509.         if (strrchr(#URL, '#')!=-1)
  510.         {
  511.                 strcpy(#anchor, #URL+strrchr(#URL, '#'));
  512.                 URL[strrchr(#URL, '#')-1] = 0x00;
  513.         }
  514.        
  515.         PageLinks.GetAbsoluteURL(#URL);
  516.        
  517.         if (UrlExtIs(".png")==1) || (UrlExtIs(".gif")==1) || (UrlExtIs(".jpg")==1) || (UrlExtIs(".zip")==1) || (UrlExtIs(".kex")==1)
  518.         || (UrlExtIs(".7z")==1) || (UrlExtIs("netcfg")==1)
  519.         {
  520.                 //notify(#URL);
  521.                 if (!strncmp(#URL,"http://", 7))
  522.                 {
  523.                         strcpy(#DL_URL, #URL);
  524.                         CreateThread(#Downloader,#downloader_stak+4092);
  525.                 }
  526.                 else RunProgram("@open", #URL);
  527.                 strcpy(#editURL, BrowserHistory.CurrentUrl());
  528.                 strcpy(#URL, BrowserHistory.CurrentUrl());
  529.                 return;
  530.         }
  531.         if (!strncmp(#URL,"mailto:", 7))
  532.         {
  533.                 notify(#URL);
  534.                 strcpy(#editURL, BrowserHistory.CurrentUrl());
  535.                 strcpy(#URL, BrowserHistory.CurrentUrl());
  536.                 return;
  537.         }
  538.         OpenPage();
  539.         return;
  540. }
  541.  
  542. void StopLoading()
  543. {
  544.         if (http_transfer)
  545.         {
  546.                 EAX = http_transfer;
  547.                 EAX = EAX.http_msg.content_ptr;         // get pointer to data
  548.                 $push   EAX                                                     // save it on the stack
  549.                 http_free stdcall (http_transfer);      // abort connection
  550.                 $pop    EAX                                                    
  551.                 free(EAX);                                              // free data
  552.                 http_transfer=0;
  553.                 bufsize = 0;
  554.                 bufpointer = free(bufpointer);
  555.         }
  556.         wv_progress_bar.value = 0;
  557.         img_draw stdcall(skin.image, address_box.left+address_box.width+1, address_box.top-3, 17, skin.h, 52, 0);
  558. }
  559.  
  560. void SetPageDefaults()
  561. {
  562.         strcpy(#header, #version);
  563.         WB1.list.count = WB1.list.first = 0;
  564.         stroka = 0;
  565.         cur_encoding = CH_NULL;
  566.         if (o_bufpointer) o_bufpointer = free(o_bufpointer);
  567.         anchor_line_num=WB1.list.first;
  568.         anchor[0]='|';
  569. }
  570.  
  571. void OpenPage()
  572. {
  573.         StopLoading();
  574.         souce_mode = false;
  575.         strcpy(#editURL, #URL);
  576.         BrowserHistory.AddUrl();
  577.         if (!strncmp(#URL,"WebView:",8))
  578.         {
  579.                 SetPageDefaults();
  580.                 if (!strcmp(#URL, URL_SERVICE_HOME)) WB1.LoadInternalPage(#homepage, sizeof(homepage));
  581.                 else if (!strcmp(#URL, URL_SERVICE_HISTORY)) ShowHistory();
  582.                 return;
  583.         }
  584.         if (!strncmp(#URL,"http:",5))
  585.         {
  586.                 img_draw stdcall(skin.image, address_box.left+address_box.width+1, address_box.top-3, 17, skin.h, 131, 0);
  587.                 http_get stdcall (#URL, 0, 0, #accept_language);
  588.                 http_transfer = EAX;
  589.                 if (!http_transfer)
  590.                 {
  591.                         StopLoading();
  592.                         bufsize = 0;
  593.                         bufpointer = free(bufpointer);
  594.                         ShowPage();
  595.                         return;
  596.                 }
  597.         }
  598.         else
  599.         {
  600.                 file_size stdcall (#URL);
  601.                 bufsize = EBX;
  602.                 if (bufsize)
  603.                 {
  604.                         free(bufpointer);
  605.                         bufpointer = malloc(bufsize);
  606.                         SetPageDefaults();
  607.                         ReadFile(0, bufsize, bufpointer, #URL);
  608.                         //ShowSource();
  609.                 }
  610.                 ShowPage();
  611.         }
  612. }
  613.  
  614. DrawEditBox()
  615. {
  616.         address_box.size = address_box.pos = address_box.shift = address_box.shift_old = strlen(#editURL);
  617.         address_box.offset = 0;
  618.         edit_box_draw stdcall(#address_box);
  619. }
  620.  
  621.  
  622. void ShowPage()
  623. {
  624.         DrawEditBox();
  625.         if (!bufsize)
  626.         {
  627.                 PageLinks.Clear();
  628.                 if (http_transfer)
  629.                 {
  630.                         WB1.LoadInternalPage(#loading, sizeof(loading));
  631.                 }
  632.                 else
  633.                         WB1.LoadInternalPage(#page_not_found, sizeof(page_not_found));
  634.         }
  635.         else
  636.                 WB1.Prepare();
  637.  
  638.         if (!header) strcpy(#header, #version);
  639.         if (!strcmp(#version, #header)) DrawTitle(#header);
  640. }
  641.  
  642. byte UrlExtIs(dword ext)
  643. {
  644.         if (!strcmpi(#URL + strlen(#URL) - strlen(ext), ext)) return true;
  645.         return false;
  646. }
  647.  
  648.  
  649.  
  650. char downloader_stak[4096];
  651. stop: