Subversion Repositories Kolibri OS

Rev

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