Subversion Repositories Kolibri OS

Rev

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

  1. //HTML Viewer in C--
  2. //Copyright 2007-2012 by Veliant & Leency
  3. //Asper, lev, Lrz, Barsuk, Nable.
  4. //home icon - rachel fu, GPL licence
  5.  
  6. #include "..\lib\kolibri.h"
  7. #include "..\lib\strings.h"
  8. #include "..\lib\encoding.h"
  9. #include "..\lib\file_system.h"
  10. #include "..\lib\mem.h"
  11. #include "..\lib\dll.h"
  12. //áèáëèîòåêè
  13. #include "..\lib\libio_lib.h"
  14. #include "..\lib\libimg_lib.h"
  15. #include "..\lib\edit_box_lib.h"
  16. #include "..\lib\scroll_lib.h"
  17. #include "..\lib\ttf_fonts.h"
  18. //êàðòèíêè
  19. #include "img\toolbar_icons.c"
  20. #include "img\URLgoto.txt";
  21.  
  22.  
  23. //ïåðåìåííûå
  24. char URL[4096],
  25.         editURL[4096],
  26.         page_links[12000],
  27.         header[300];
  28.  
  29. struct lines{
  30.         int visible, all, first, column_max;
  31. };
  32.  
  33. int     mouse_dd;
  34. edit_box edit1= {250,207,16,0xffffff,0x94AECE,0xffffff,0xffffff,0,248,#editURL,#mouse_dd,2,19,19};
  35. 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}; //details in scroll_lib.h--
  36.  
  37. proc_info Form;
  38. dword stak[100]; //ìåíþ ÏÊÌ
  39. mouse m;
  40.  
  41. #include "TWB.h"
  42. #include "include\menu_rmb.h"
  43.  
  44.  
  45. void main()
  46. {
  47.         int btn;
  48.         byte key;
  49.         int half_scroll_size;
  50.        
  51.         mem_Init();
  52.         load_dll2(libio, #libio_init,1);
  53.         load_dll2(libimg, #libimg_init,1);
  54.         load_dll2(boxlib, #edit_box_draw,0);
  55.         load_dll2(#abox_lib, #boxlib_init,0);
  56.         //load_dll2(libtruetype, #truetype,0);
  57.        
  58.         if (param) strcpy(#URL, #param);
  59.                 else strcpy(#URL, "/sys/index.htm");
  60.         strcpy(#editURL, #URL);
  61.        
  62.         lines.column_max = 101;
  63.         WB1.OpenPage();
  64.  
  65.         SetEventMask(0x27);
  66.         loop()
  67.         {
  68.                 WaitEventTimeout(2);
  69.                 switch(EAX & 0xFF)
  70.                 {
  71.                         CASE evMouse:
  72.                                 /*scrollbar_v_mouse (#scroll1);      //êîí÷åíûé ñêðîëë ïðèòîðìàæèìàåò, èä¸ì "ñâîèì ïóò¸ì"
  73.                                 if (lines.first <> scroll1.position)
  74.                                 {
  75.                                         lines.first = scroll1.position;
  76.                                         WB1.ParseHTML(buf, filesize);
  77.                                         //break;
  78.                                 };*/
  79.                                
  80.                                 btn=GetProcessSlot(Form.ID);
  81.                                 IF (btn<>GetActiveProcess()) break; //åñëè îêíî íå àêòèâíî íà ñîáûòèÿ ìûøè íå ðåàãèðóåì
  82.  
  83.                                 edit_box_mouse stdcall (#edit1);
  84.  
  85.                                 m.get();
  86.                                
  87.                                 if (m.pkm) && (m.y>WB1.top) && (m.y<Form.height) && (filesize)
  88.                                 {
  89.                                         SwitchToAnotherThread();
  90.                                         CreateThread(#menu_rmb,#stak);
  91.                                 }
  92.  
  93.                                 IF (m.vert==65535) //ïðîêðóòêà êîë¸ñèêîì
  94.                                 {
  95.                                         IF (lines.first==0) break;
  96.                                         IF (lines.first>3) lines.first-=2; ELSE lines.first=1;
  97.                                         WB1.Scan(ID1);
  98.                                         break;
  99.                                 }
  100.                                 IF (m.vert==1)
  101.                                 {
  102.                                         IF(lines.visible+lines.first+3>=lines.all) WB1.Scan(181);
  103.                                         ELSE    {
  104.                                                 lines.first+=2;
  105.                                                 WB1.Scan(ID2);
  106.                                         }
  107.                                         break;
  108.                                 }
  109.                                
  110.                                 IF (lines.all<lines.visible) break;
  111.                                 half_scroll_size = WB1.height - 16 * lines.visible / lines.all - 3 /2;
  112.                                 if (m.x>=WB1.width-14) && (m.x<=WB1.width+6)
  113.                                 && (m.y>WB1.top+16) && (m.y<WB1.top+WB1.height-16)
  114.                                 && (lines.all>lines.visible) while (m.lkm)
  115.                                 {
  116.                                         IF (half_scroll_size+WB1.top>m.y) || (m.y<0) || (m.y>4000) m.y=half_scroll_size+WB1.top; //åñëè êóðñîð íàä îêíîì
  117.                                         btn=lines.first; //ñîõðàíÿåì ñòàðîå êîëè÷åñòâî
  118.                                         lines.first = m.y -half_scroll_size -WB1.top * lines.all / WB1.height;
  119.                                         IF (lines.visible+lines.first>lines.all) lines.first=lines.all-lines.visible;
  120.                                         IF (btn<>lines.first) WB1.ParseHTML(buf); //÷òîá ëèøíèé ðàç íå ïåðåðèñîâûâàòü
  121.                                         m.get();
  122.                                 }
  123.  
  124.                                 break;
  125.                         case evButton:
  126.                                 btn=GetButtonID();
  127.                                 IF (btn==1)
  128.                                 {
  129.                                         KillProcess(downloader_id);
  130.                                         ExitProcess();
  131.                                 }
  132.                                 ELSE
  133.                                 {
  134.                                         WB1.Scan(btn);
  135.                                 }
  136.                                 break;
  137.                         case evKey:
  138.                                 key = GetKey();
  139.                                
  140.                                 if (edit1.flags == 66) || (edit1.flags == 98) SWITCH(key) //åñëè àêòèâíà ñòðîêà àäðåñà èãíîðèðóåì íåêîòîðûå êíîïêè
  141.                                         { CASE 52: CASE 53: CASE 54: goto _EDIT_MARK; }
  142.  
  143.                                 WB1.Scan(key);
  144.                                
  145.                                 _EDIT_MARK:
  146.                                 IF (key<>0x0d) && (key<>183) && (key<>184) && (key<>173) {EAX=key<<8; edit_box_key stdcall(#edit1);} //àäðåñíàÿ ñòðîêà
  147.                                 break;
  148.                         case evReDraw:
  149.                                 Draw_Window();
  150.                                 break;
  151.                         default:
  152.                                 if (downloader_id<>0)
  153.                                 {
  154.                                         if (GetProcessSlot(downloader_id)<>0) break;
  155.                                         downloader_id=0;
  156.                                         lines.first = lines.all = 0;
  157.                                         WB1.ReadHtml(_WIN);
  158.                                         Draw_Window();
  159.                                 }
  160.                 }
  161.         }
  162. }
  163.  
  164.  
  165. void Draw_Window()
  166. {
  167.         int j;
  168.         DefineAndDrawWindow(215,100,640,480,0x73,0x00E4DFE1,0,0,0);
  169.  
  170.         GetProcessInfo(#Form, SelfInfo);
  171.         if (Form.status_window>2) //åñëè ñâåðíóòî â çàãîëîâîê, íè÷åãî íå ðèñóåì
  172.         {
  173.                 DrawTitle(#header);
  174.                 return;
  175.         }
  176.         if (Form.height<120) MoveSize(OLD,OLD,OLD,120);
  177.         if (Form.width<280) MoveSize(OLD,OLD,280,OLD);
  178.        
  179.         PutPaletteImage(#toolbar,200,42,0,0,8,#toolbar_pal);
  180.         if (GetProcessSlot(downloader_id)<>0) PutImage(#stop_btn,24,24,88,10);
  181.        
  182.         DrawBar(200,0,onLeft(200,9),43,0xE4DFE1); //çàêðàøèâàåì ôîí ïîä òóëáàðîì
  183.         DrawBar(0,42,onLeft(5,4),1,0xE2DBDC); //âûïóêëîñòü
  184.         DrawBar(0,43,onLeft(5,4),1,0xD2CED0); //âûïóêëîñòü
  185.         for (j=0; j<5; j++) DefineButton(j*37+11, 7, 29, 29, 300+j+BT_HIDE, 0xE4DFE1);
  186.         PutImage(#URLgoto,40,19,onLeft(57,0),14);
  187.         DefineButton(onLeft(37,0),15, 18, 16, GOTOURL+BT_HIDE, 0xE4DFE1);
  188.         DefineButton(onLeft(56,0),15, 17, 16, SEARCHWEB+BT_HIDE, 0xE4DFE1);
  189.         DrawRegion(205,14,onLeft(58,205),18,0x94AECE); //îáîäîê ïîëîñû àäðåñà
  190.         DrawRegion(206,15,onLeft(59,205),16,0xE4ECF3);
  191.  
  192.         edit1.width=Form.width-266;
  193.         WB1.top=44;
  194.         WB1.width=Form.width-13;
  195.         WB1.height=onTop(43,5);
  196.         lines.column_max = WB1.width - 30 / 6;
  197.         lines.visible = WB1.height - 3 / 10 - 2;
  198.  
  199.         WB1.ShowPage();
  200.        
  201.         DefineButton(scroll1.start_x+1, scroll1.start_y+1, 16, 16, ID1+BT_HIDE, 0xE4DFE1);
  202.         DefineButton(scroll1.start_x+1, scroll1.start_y+scroll1.size_y-18, 16, 16, ID2+BT_HIDE, 0xE4DFE1);
  203. }
  204.  
  205. int onLeft(dword right,left) {return Form.width-right-left;}
  206. int onTop(dword down,up) {return Form.height-GetSkinWidth()-down-up;}
  207.  
  208.  
  209. stop:
  210.