Subversion Repositories Kolibri OS

Rev

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