Subversion Repositories Kolibri OS

Rev

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