Subversion Repositories Kolibri OS

Rev

Rev 4413 | Go to most recent revision | Blame | Last modification | View Log | Download | RSS feed

  1. //HTML Viewer in C--
  2. //Copyright 2007-2013 by Veliant & Leency
  3. //Asper, lev, Lrz, Barsuk, Nable...
  4. //home icon - rachel fu, GPL licence
  5.  
  6. #ifndef AUTOBUILD
  7.         #include "lang.h--"
  8. #endif
  9.  
  10. //libraries
  11. #define MEMSIZE 0x100000
  12. #include "..\lib\kolibri.h"
  13. #include "..\lib\strings.h"
  14. #include "..\lib\figures.h"
  15. #include "..\lib\encoding.h"
  16. #include "..\lib\file_system.h"
  17. #include "..\lib\mem.h"
  18. #include "..\lib\dll.h"
  19. //*.obj libraries
  20. #include "..\lib\lib.obj\box_lib.h"
  21. #include "..\lib\lib.obj\libio_lib.h"
  22. #include "..\lib\lib.obj\libimg_lib.h"
  23. //images
  24. #include "img\toolbar_icons.c"
  25. #include "img\URLgoto.txt";
  26.  
  27. #ifdef LANG_RUS
  28.         char version[]=" ’¥ªáâ®¢ë© ¡à ã§¥à 0.99.11";
  29.         ?define IMAGES_CACHE_CLEARED "Šíè ª à⨭®ª ®ç¨é¥­"
  30. #else
  31.         char version[]=" Text-based Browser 0.99.11";
  32.         ?define IMAGES_CACHE_CLEARED "Images cache cleared"
  33. #endif
  34.  
  35.  
  36. #define URL param
  37. char fontlol[64];
  38.  
  39. char editURL[sizeof(URL)],
  40.         page_links[12000],
  41.         header[2048];
  42.  
  43.  
  44. int     mouse_dd;
  45. edit_box address_box= {250,207,16,0xffffff,0x94AECE,0xffffff,0xffffff,0,sizeof(editURL),#editURL,#mouse_dd,2,19,19};
  46. scroll_bar scroll1 = { 18,200,398, 44,18,0,115,15,0,0xeeeeee,0xD2CED0,0x555555,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1};
  47.  
  48.  
  49. proc_info Form;
  50. #define WIN_W 640
  51. #define WIN_H 480
  52.  
  53.  
  54. char stak[4096];
  55. mouse m;
  56.  
  57. int action_buf;
  58.  
  59. #include "history.h"
  60. #include "..\TWB\TWB.c"
  61. #include "menu_rmb.h"
  62.  
  63.  
  64. void main()
  65. {
  66.         int key, btn;
  67.         int half_scroll_size;
  68.         int scroll_used=0, show_menu;
  69.        
  70.         mem_Init();
  71.         if (load_dll2(boxlib, #box_lib_init,0)!=0) {notify("System Error: library doesn't exists /rd/1/lib/box_lib.obj"); ExitProcess();}
  72.         if (load_dll2(libio, #libio_init,1)!=0) debug("Error: library doesn't exists - libio"w);
  73.         if (load_dll2(libimg, #libimg_init,1)!=0) debug("Error: library doesn't exists - libimg"w);
  74.        
  75.         if (!URL) strcpy(#URL, "/sys/index.htm");
  76.         strcpy(#editURL, #URL);
  77.        
  78.         Form.width=WIN_W;
  79.         Form.height=WIN_H;
  80.         SetElementSizes();
  81.         WB1.OpenPage();
  82.  
  83.         SetEventMask(0x27);
  84.         loop()
  85.         {
  86.                 WaitEventTimeout(2);
  87.                 switch(EAX & 0xFF)
  88.                 {
  89.                         CASE evMouse:
  90.                                 /*
  91.                                 //not work well, so we are use custom way of processing scroll
  92.                                 scrollbar_v_mouse (#scroll1);
  93.                                 if (lines.first <> scroll1.position)
  94.                                 {
  95.                                         lines.first = scroll1.position;
  96.                                         WB1.ParseHTML(buf, filesize);
  97.                                 };
  98.                                 */
  99.                                
  100.                                 if (!CheckActiveProcess(Form.ID)) break;
  101.  
  102.                                 edit_box_mouse stdcall (#address_box);
  103.  
  104.                                 m.get();
  105.                                
  106.                                 if (m.y>WB1.list.y) && (m.y<Form.height) && (filesize)
  107.                                 {
  108.                                         if (m.pkm)
  109.                                         {
  110.                                                 show_menu = 1;
  111.                                         }
  112.                                         if (!m.pkm) && (show_menu)
  113.                                         {
  114.                                                 show_menu = 0;
  115.                                                 SwitchToAnotherThread();
  116.                                                 CreateThread(#menu_rmb,#stak+4092);
  117.                                                 break;
  118.                                         }
  119.                                 }
  120.  
  121.                                 if (m.vert==65535)
  122.                                 {
  123.                                         if (lines.first==0) break;
  124.                                         if (lines.first>3) lines.first-=2; ELSE lines.first=1;
  125.                                         Scan(ID1);
  126.                                         break;
  127.                                 }
  128.                                 if (m.vert==1)
  129.                                 {
  130.                                         if(lines.visible+lines.first+3>=lines.all) Scan(181);
  131.                                         else
  132.                                         {
  133.                                                 lines.first+=2;
  134.                                                 Scan(ID2);
  135.                                         }
  136.                                         break;
  137.                                 }
  138.                                
  139.                                 if (!m.lkm) scroll_used=0;
  140.                                 if (m.x>=scroll1.start_x) && (m.x<=scroll1.start_x+scroll1.size_x)
  141.                                 && (m.y>=scroll1.start_y+scroll1.btn_height) && (-scroll1.btn_height+scroll1.start_y+scroll1.size_y>m.y)
  142.                                 && (lines.all>lines.visible) && (m.lkm)
  143.                                 {
  144.                                         scroll_used=1;
  145.                                 }
  146.                                
  147.                                 if (scroll_used)
  148.                                 {
  149.                                         half_scroll_size = WB1.list.h - 16 * lines.visible / lines.all - 3 /2;
  150.                                         if (half_scroll_size+WB1.list.y>m.y) || (m.y<0) || (m.y>4000) m.y=half_scroll_size+WB1.list.y; //åñëè êóðñîð íàä îêíîì
  151.                                         btn=lines.first; //ñîõðàíÿåì ñòàðîå êîëè÷åñòâî
  152.                                         lines.first = m.y -half_scroll_size -WB1.list.y * lines.all / WB1.list.h;
  153.                                         if (lines.visible+lines.first>lines.all) lines.first=lines.all-lines.visible;
  154.                                         if (btn<>lines.first) WB1.ParseHTML(buf); //÷òîá ëèøíèé ðàç íå ïåðåðèñîâûâàòü
  155.                                 }
  156.  
  157.                                 break;
  158.                         case evButton:
  159.                                 btn=GetButtonID();
  160.                                 if (btn==1)
  161.                                 {
  162.                                         KillProcess(downloader_id);
  163.                                         ExitProcess();
  164.                                 }
  165.                                 ELSE
  166.                                 {
  167.                                         Scan(btn);
  168.                                 }
  169.                                 break;
  170.                         case evKey:
  171.                                 key = GetKey();
  172.                                
  173.                                 if (address_box.flags & 0b10) SWITCH(key) //åñëè àêòèâíà ñòðîêà àäðåñà èãíîðèðóåì íåêîòîðûå êíîïêè
  174.                                         { CASE 52: CASE 53: CASE 54: goto _EDIT_MARK; }
  175.  
  176.                                 Scan(key);
  177.                                
  178.                                 _EDIT_MARK:
  179.                                 if (key<>0x0d) && (key<>183) && (key<>184) {EAX=key<<8; edit_box_key stdcall(#address_box);} //àäðåñíàÿ ñòðîêà
  180.                                 break;
  181.                         case evReDraw:
  182.                                 if (action_buf) { Scan(action_buf); action_buf=0;}
  183.                                 Draw_Window();
  184.                                 break;
  185.                         default:
  186.                                 if (downloader_id<>0)
  187.                                 {
  188.                                         if (GetProcessSlot(downloader_id)<>0) break;
  189.                                         downloader_id=0;
  190.                                         lines.first = lines.all = 0;
  191.                                         WB1.ReadHtml(_WIN);
  192.                                         Draw_Window();
  193.                                 }
  194.                 }
  195.         }
  196. }
  197.  
  198. void SetElementSizes()
  199. {
  200.         address_box.width = Form.width-266;
  201.         WB1.list.SetSizes(0, 44, Form.width - 10 - scroll1.size_x, Form.cheight - 44, 0, 10);
  202.         lines.column_max = WB1.list.w - 30 / 6;
  203.         lines.visible = WB1.list.h - 3 / WB1.list.line_h - 2;
  204.         DrawBufInit();
  205. }
  206.  
  207.  
  208. void Draw_Window()
  209. {
  210.         int j;
  211.         DefineAndDrawWindow(215,100,WIN_W,WIN_H,0x73,0xE4DFE1,0,0);
  212.  
  213.         GetProcessInfo(#Form, SelfInfo);
  214.         if (Form.status_window>2)
  215.         {
  216.                 DrawTitle(#header);
  217.                 return;
  218.         }
  219.         if (Form.height<120) MoveSize(OLD,OLD,OLD,120);
  220.         if (Form.width<280) MoveSize(OLD,OLD,280,OLD);
  221.        
  222.         PutPaletteImage(#toolbar,200,42,0,0,8,#toolbar_pal);
  223.         if (GetProcessSlot(downloader_id)<>0) _PutImage(88,10, 24,24, #stop_btn);
  224.        
  225.         DrawBar(200,0,Form.cwidth-200,43,0xE4DFE1);
  226.         DrawBar(0,42,Form.cwidth,1,0xE2DBDC);
  227.         DrawBar(0,43,Form.cwidth,1,0xD2CED0);
  228.         for (j=0; j<5; j++) DefineButton(j*37+11, 7, 29, 29, 300+j+BT_HIDE, 0xE4DFE1);
  229.         _PutImage(Form.cwidth-48,14, 40,19, #URLgoto);
  230.         DefineButton(Form.cwidth-28,15, 18, 16, GOTOURL+BT_HIDE, 0xE4DFE1);
  231.         DefineButton(Form.cwidth-47,15, 17, 16, SEARCHWEB+BT_HIDE, 0xE4DFE1);
  232.         DrawRectangle(205,14,Form.cwidth-205-49,18,0x94AECE); //around adress bar
  233.         DrawRectangle(206,15,Form.cwidth-205-50,16,0xE4ECF3);
  234.  
  235.         SetElementSizes();
  236.         WB1.ShowPage();
  237.  
  238.         DefineButton(scroll1.start_x+1, scroll1.start_y+1, 16, 16, ID1+BT_HIDE, 0xE4DFE1);
  239.         DefineButton(scroll1.start_x+1, scroll1.start_y+scroll1.size_y-18, 16, 16, ID2+BT_HIDE, 0xE4DFE1);
  240. }
  241.  
  242.  
  243. void Scan(int id)
  244. {
  245.         if (id >= 400)
  246.         {
  247.                 GetURLfromPageLinks(id);
  248.                
  249.                 //#1
  250.                 if (URL[0] == '#')
  251.                 {
  252.                         strcpy(#anchor, #URL+strrchr(#URL, '#'));
  253.                        
  254.                         strcpy(#URL, BrowserHistory.CurrentUrl());
  255.                        
  256.                         lines.first=lines.all-lines.visible;
  257.                         WB1.ShowPage();
  258.                         return;
  259.                 }
  260.                 //liner.ru#1
  261.                 if (strrchr(#URL, '#')<>-1)
  262.                 {
  263.                         strcpy(#anchor, #URL+strrchr(#URL, '#'));
  264.                         URL[strrchr(#URL, '#')-1] = 0x00; //çàãëóøêà
  265.                 }
  266.                
  267.                 WB1.GetNewUrl();
  268.                
  269.                 if (!strcmp(#URL + strlen(#URL) - 4, ".gif")) || (!strcmp(#URL + strlen(#URL) - 4, ".png")) || (!strcmp(#URL + strlen(#URL) - 4, ".jpg"))
  270.                 {
  271.                         //if (strstr(#URL,"http:"))
  272.                         RunProgram("/sys/media/kiv", #URL);
  273.                         strcpy(#editURL, BrowserHistory.CurrentUrl());
  274.                         strcpy(#URL, BrowserHistory.CurrentUrl());
  275.                         return;
  276.                 }
  277.                 if (!strcmpn(#URL,"mailto:", 7))
  278.                 {
  279.                         RunProgram("@notify", #URL);
  280.                         strcpy(#editURL, BrowserHistory.CurrentUrl());
  281.                         strcpy(#URL, BrowserHistory.CurrentUrl());
  282.                         return;
  283.                 }
  284.  
  285.                 WB1.OpenPage();
  286.                 return;
  287.         }
  288.        
  289.         IF(lines.all < lines.visible) SWITCH(id) //åñëè ìàëî ñòðîê èãíîðèðóåì íåêîòîðûå êíîïêè
  290.         { CASE 183: CASE 184: CASE 180: CASE 181: return; }
  291.        
  292.         switch (id)
  293.         {
  294.                 case 011: //Ctrk+K
  295.                         WB1.ReadHtml(_KOI);
  296.                         break;
  297.                 case 021: //Ctrl+U
  298.                         WB1.ReadHtml(_UTF);
  299.                         break;
  300.                 case 004: //Ctrl+D
  301.                         WB1.ReadHtml(_DOS);
  302.                         break;
  303.                 case 002: //free img cache
  304.                         FreeImgCache();
  305.                         break;                 
  306.                 case BACK:
  307.                         if (!BrowserHistory.GoBack()) return;
  308.                         WB1.OpenPage();
  309.                         return;
  310.                 case FORWARD:
  311.                         if (!BrowserHistory.GoForward()) return;
  312.                         WB1.OpenPage();
  313.                         return;
  314.                 case 052:  //F3
  315.                         if (strcmp(get_URL_part(5),"http:")<>0) RunProgram("/rd/1/tinypad", #URL); else RunProgram("/rd/1/tinypad", #download_path);
  316.                         return;
  317.                 case 054: //F5
  318.                         IF(address_box.flags & 0b10) break;
  319.                 case REFRESH:
  320.                         if (GetProcessSlot(downloader_id)<>0)
  321.                         {
  322.                                 KillProcess(downloader_id);
  323.                                 pause(20);
  324.                                 Draw_Window();
  325.                                 return;
  326.                         }
  327.                         anchor_line_num=lines.first; //âåñ¸ëûé êîñòûëü :Ð
  328.                         anchor[0]='|';
  329.                         WB1.OpenPage();
  330.                         return;
  331.                 case 014: //Ctrl+N íîâîå îêíî
  332.                 case 020: //Ctrl+T íîâàÿ âêëàäêà
  333.                 case NEWTAB:
  334.                         MoveSize(190,80,OLD,OLD);
  335.                         RunProgram(#program_path, #URL);
  336.                         return;
  337.                        
  338.                 case HOME:
  339.                         strcpy(#editURL, "http://kolibrios.org/en/index.htm");
  340.                 case GOTOURL:
  341.                 case 0x0D: //enter
  342.                         //ïî÷åìó ttp://? Ãîñïîäà, îòëè÷íûé âîïðîñ. Äåëî â òîì, ÷òî ýòî õàê.
  343.                         //strstr() åñëè íå íàøëî âîçâðàùàåò 0 è â ñëó÷àå óñïåõà âîçâðàùàåò 0. Òàê ÷òî ýòî õàê.
  344.                         if ((strstr(#editURL,"ttp://")==0) && (editURL[0]!='/')) strcpy(#URL,"http://"); else URL[0] = 0;
  345.                         strcat(#URL, #editURL);
  346.                         WB1.OpenPage();
  347.                         return;
  348.                 case SEARCHWEB:
  349.                         strcpy(#URL, #search_path);
  350.                         strcat(#URL, #editURL);
  351.                         WB1.OpenPage();
  352.                         return;
  353.  
  354.                 case ID1: //ìîòàåì ââåðõ
  355.                         IF(lines.first <= 0) return;
  356.                         lines.first--;
  357.                         break;
  358.                 case ID2: //ìîòàåì âíèç
  359.                         IF(lines.visible + lines.first >= lines.all) return;
  360.                         lines.first++;
  361.                         break;
  362.                 case 183: //PgDown
  363.                         IF(lines.first == lines.all - lines.visible) return;
  364.                         lines.first += lines.visible + 2;
  365.                         IF(lines.visible + lines.first > lines.all) lines.first = lines.all - lines.visible;
  366.                         break;
  367.                 case 184: //PgUp
  368.                         IF(lines.first == 0) return;
  369.                         lines.first -= lines.visible - 2;
  370.                         IF(lines.first < 0) lines.first = 0;
  371.                         break;
  372.                 case 180: //home
  373.                         IF(lines.first == 0) return;
  374.                         lines.first = 0;
  375.                         break;
  376.                 case 181: //end
  377.                         IF (lines.first == lines.all - lines.visible) return;
  378.                         lines.first = lines.all - lines.visible;
  379.                         break;
  380.                 default:
  381.                         return;
  382.         }
  383.         WB1.ParseHTML(buf);
  384. }
  385.  
  386.  
  387.  
  388.  
  389. stop:
  390.