Subversion Repositories Kolibri OS

Rev

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