Subversion Repositories Kolibri OS

Rev

Rev 4085 | 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. #include "..\lib\list_box.h"
  24. //images
  25. #include "img\toolbar_icons.c"
  26. #include "img\URLgoto.txt";
  27.  
  28. #ifdef LANG_RUS
  29.         char version[]=" ’¥ªáâ®¢ë© ¡à ã§¥à 0.99.1";
  30.         ?define IMAGES_CACHE_CLEARED "Šíè ª à⨭®ª ®ç¨é¥­"
  31. #else
  32.         char version[]=" Text-based Browser 0.99.1";
  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. struct lines{
  45.         int visible, all, first, column_max;
  46. };
  47.  
  48. int     mouse_dd;
  49. edit_box address_box= {250,207,16,0xffffff,0x94AECE,0xffffff,0xffffff,0,sizeof(editURL),#editURL,#mouse_dd,2,19,19};
  50. 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};
  51.  
  52.  
  53. proc_info Form;
  54. #define WIN_W 640
  55. #define WIN_H 480
  56.  
  57.  
  58. char stak[4096];
  59. mouse m;
  60.  
  61. int action_buf;
  62.  
  63. #include "TWB.h"
  64. #include "include\menu_rmb.h"
  65.  
  66.  
  67. void main()
  68. {
  69.         int key, btn;
  70.         int half_scroll_size;
  71.         int scroll_used=0, show_menu;
  72.        
  73.         mem_Init();
  74.         if (load_dll2(boxlib, #box_lib_init,0)!=0) {notify("System Error: library doesn't exists /rd/1/lib/box_lib.obj"); ExitProcess();}
  75.         if (load_dll2(libio, #libio_init,1)!=0) debug("Error: library doesn't exists - libio"w);
  76.         if (load_dll2(libimg, #libimg_init,1)!=0) debug("Error: library doesn't exists - libimg"w);
  77.        
  78.         if (!URL) strcpy(#URL, "/sys/index.htm");
  79.         strcpy(#editURL, #URL);
  80.        
  81.         Form.width=WIN_W;
  82.         Form.height=WIN_H;
  83.         SetElementSizes();
  84.         WB1.OpenPage();
  85.  
  86.         SetEventMask(0x27);
  87.         loop()
  88.         {
  89.                 WaitEventTimeout(2);
  90.                 switch(EAX & 0xFF)
  91.                 {
  92.                         CASE evMouse:
  93.                                 /*scrollbar_v_mouse (#scroll1);      //êîí÷åíûé ñêðîëë ïðèòîðìàæèìàåò, èä¸ì "ñâîèì ïóò¸ì"
  94.                                 if (lines.first <> scroll1.position)
  95.                                 {
  96.                                         lines.first = scroll1.position;
  97.                                         WB1.ParseHTML(buf, filesize);
  98.                                         //break;
  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.top) && (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==65535)
  123.                                 {
  124.                                         if (lines.first==0) break;
  125.                                         if (lines.first>3) lines.first-=2; ELSE lines.first=1;
  126.                                         WB1.Scan(ID1);
  127.                                         break;
  128.                                 }
  129.                                 if (m.vert==1)
  130.                                 {
  131.                                         if(lines.visible+lines.first+3>=lines.all) WB1.Scan(181);
  132.                                         else
  133.                                         {
  134.                                                 lines.first+=2;
  135.                                                 WB1.Scan(ID2);
  136.                                         }
  137.                                         break;
  138.                                 }
  139.                                
  140.                                 if (!m.lkm) scroll_used=0;
  141.                                 if (m.x>=scroll1.start_x) && (m.x<=scroll1.start_x+scroll1.size_x)
  142.                                 && (m.y>=scroll1.start_y+scroll1.btn_height) && (-scroll1.btn_height+scroll1.start_y+scroll1.size_y>m.y)
  143.                                 && (lines.all>lines.visible) && (m.lkm)
  144.                                 {
  145.                                         scroll_used=1;
  146.                                 }
  147.                                
  148.                                 if (scroll_used)
  149.                                 {
  150.                                         half_scroll_size = WB1.height - 16 * lines.visible / lines.all - 3 /2;
  151.                                         if (half_scroll_size+WB1.top>m.y) || (m.y<0) || (m.y>4000) m.y=half_scroll_size+WB1.top; //åñëè êóðñîð íàä îêíîì
  152.                                         btn=lines.first; //ñîõðàíÿåì ñòàðîå êîëè÷åñòâî
  153.                                         lines.first = m.y -half_scroll_size -WB1.top * lines.all / WB1.height;
  154.                                         if (lines.visible+lines.first>lines.all) lines.first=lines.all-lines.visible;
  155.                                         if (btn<>lines.first) WB1.ParseHTML(buf); //÷òîá ëèøíèé ðàç íå ïåðåðèñîâûâàòü
  156.                                 }
  157.  
  158.                                 break;
  159.                         case evButton:
  160.                                 btn=GetButtonID();
  161.                                 if (btn==1)
  162.                                 {
  163.                                         KillProcess(downloader_id);
  164.                                         ExitProcess();
  165.                                 }
  166.                                 ELSE
  167.                                 {
  168.                                         WB1.Scan(btn);
  169.                                 }
  170.                                 break;
  171.                         case evKey:
  172.                                 key = GetKey();
  173.                                
  174.                                 if (address_box.flags & 0b10) SWITCH(key) //åñëè àêòèâíà ñòðîêà àäðåñà èãíîðèðóåì íåêîòîðûå êíîïêè
  175.                                         { CASE 52: CASE 53: CASE 54: goto _EDIT_MARK; }
  176.  
  177.                                 WB1.Scan(key);
  178.                                
  179.                                 _EDIT_MARK:
  180.                                 if (key<>0x0d) && (key<>183) && (key<>184) {EAX=key<<8; edit_box_key stdcall(#address_box);} //àäðåñíàÿ ñòðîêà
  181.                                 break;
  182.                         case evReDraw:
  183.                                 if (action_buf) { WB1.Scan(action_buf); action_buf=0;}
  184.                                 Draw_Window();
  185.                                 break;
  186.                         default:
  187.                                 if (downloader_id<>0)
  188.                                 {
  189.                                         if (GetProcessSlot(downloader_id)<>0) break;
  190.                                         downloader_id=0;
  191.                                         lines.first = lines.all = 0;
  192.                                         WB1.ReadHtml(_WIN);
  193.                                         Draw_Window();
  194.                                 }
  195.                 }
  196.         }
  197. }
  198.  
  199. void SetElementSizes()
  200. {
  201.         address_box.width = Form.width-266;
  202.         WB1.top = 44;
  203.         WB1.width = Form.width - 10 - scroll1.size_x;
  204.         WB1.height = Form.height - WB1.top - GetSkinHeight() - 4;
  205.         WB1.line_h = 10;
  206.         lines.column_max = WB1.width - 30 / 6;
  207.         lines.visible = WB1.height - 3 / WB1.line_h - 2;
  208.         DrawBufInit();
  209. }
  210.  
  211.  
  212. void Draw_Window()
  213. {
  214.         int j;
  215.         DefineAndDrawWindow(215,100,WIN_W,WIN_H,0x73,0xE4DFE1,0,0);
  216.  
  217.         GetProcessInfo(#Form, SelfInfo);
  218.         if (Form.status_window>2)
  219.         {
  220.                 DrawTitle(#header);
  221.                 return;
  222.         }
  223.         if (Form.height<120) MoveSize(OLD,OLD,OLD,120);
  224.         if (Form.width<280) MoveSize(OLD,OLD,280,OLD);
  225.        
  226.         PutPaletteImage(#toolbar,200,42,0,0,8,#toolbar_pal);
  227.         if (GetProcessSlot(downloader_id)<>0) _PutImage(88,10, 24,24, #stop_btn);
  228.        
  229.         DrawBar(200,0,Form.cwidth-200,43,0xE4DFE1);
  230.         DrawBar(0,42,Form.cwidth,1,0xE2DBDC);
  231.         DrawBar(0,43,Form.cwidth,1,0xD2CED0);
  232.         for (j=0; j<5; j++) DefineButton(j*37+11, 7, 29, 29, 300+j+BT_HIDE, 0xE4DFE1);
  233.         _PutImage(Form.cwidth-48,14, 40,19, #URLgoto);
  234.         DefineButton(Form.cwidth-28,15, 18, 16, GOTOURL+BT_HIDE, 0xE4DFE1);
  235.         DefineButton(Form.cwidth-47,15, 17, 16, SEARCHWEB+BT_HIDE, 0xE4DFE1);
  236.         DrawRectangle(205,14,Form.cwidth-205-49,18,0x94AECE); //around adress bar
  237.         DrawRectangle(206,15,Form.cwidth-205-50,16,0xE4ECF3);
  238.  
  239.         SetElementSizes();
  240.         WB1.ShowPage();
  241.  
  242.         DefineButton(scroll1.start_x+1, scroll1.start_y+1, 16, 16, ID1+BT_HIDE, 0xE4DFE1);
  243.         DefineButton(scroll1.start_x+1, scroll1.start_y+scroll1.size_y-18, 16, 16, ID2+BT_HIDE, 0xE4DFE1);
  244. }
  245.  
  246.  
  247. stop:
  248.