Subversion Repositories Kolibri OS

Rev

Rev 3006 | 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\truetype.h"
  18. //êàðòèíêè
  19. #include "img\toolbar_icons.c"
  20. #include "img\URLgoto.txt";
  21.  
  22.  
  23. #define URL param
  24. int use_truetype = 0;
  25.  
  26. char editURL[sizeof(URL)],
  27.         page_links[12000],
  28.         header[300];
  29.  
  30. struct lines{
  31.         int visible, all, first, column_max;
  32. };
  33.  
  34. int     mouse_dd;
  35. edit_box edit1= {250,207,16,0xffffff,0x94AECE,0xffffff,0xffffff,0,sizeof(editURL),#editURL,#mouse_dd,2,19,19};
  36. 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--
  37.  
  38.  
  39. proc_info Form;
  40. #define WIN_W 640
  41. #define WIN_H 480
  42.  
  43.  
  44. dword stak[100]; //ìåíþ ÏÊÌ
  45. mouse m;
  46.  
  47. #include "TWB.h"
  48. #include "include\menu_rmb.h"
  49.  
  50. /*void tre()
  51. {
  52.         char *font_picture;
  53.         char text[12];
  54.         int width=600;
  55.         int height=40;
  56.         char palette[256*4];
  57.         int x;
  58.  
  59.  
  60.         strcpy(#text, "hello world\0");
  61.  
  62.         get_width stdcall (#text, -1, height);
  63.         width=EAX;
  64.  
  65.         font_picture=mem_Alloc(width*height);
  66.         truetype stdcall (#text, -1, font_picture,  width, height);
  67.  
  68.         for (x=0;x<256;x++) {
  69.         palette[x*4]=255-x;
  70.         palette[x*4+1]=255-x;
  71.         palette[x*4+2]=255-x;
  72.         palette[x*4+3]=0;
  73.         }
  74.  
  75.         PutPaletteImage(font_picture,width,height,0,0,8,#palette);
  76.         mem_Free(font_picture);
  77. };*/
  78.  
  79.  
  80. void main()
  81. {
  82.         int btn;
  83.         byte key;
  84.         int half_scroll_size;
  85.         int scroll_used=0;
  86.        
  87.         mem_Init();
  88.         if (load_dll2(libio, #libio_init,1)!=0) debug("Íå óäàëîñü ïîäêëþ÷èòü áèáëèîòåêó libio"w);
  89.         if (load_dll2(libimg, #libimg_init,1)!=0) debug("Íå óäàëîñü ïîäêëþ÷èòü áèáëèîòåêó libimg"w);
  90.         if (load_dll2(boxlib, #edit_box_draw,0)!=0) {RunProgram("@notify", "System Error: library doesn't exists /rd/1/lib/box_lib.obj"); ExitProcess();}
  91.         load_dll2(#abox_lib, #boxlib_init,0);
  92.         if (load_dll2(libtruetype, #truetype,0)!=0) {debug("Íå óäàëîñü ïîäêëþ÷èòü áèáëèîòåêó TrueType"w); use_truetype = 2;}
  93.        
  94.         if (!URL) strcpy(#URL, "/sys/home.htm");
  95.         strcpy(#editURL, #URL);
  96.        
  97.         Form.width=WIN_W;
  98.         Form.height=WIN_H;
  99.        
  100.         SetElementSizes();
  101.  
  102.         WB1.OpenPage();
  103.  
  104.         SetEventMask(0x27);
  105.         loop()
  106.         {
  107.                 WaitEventTimeout(2);
  108.                 switch(EAX & 0xFF)
  109.                 {
  110.                         CASE evMouse:
  111.                                 /*scrollbar_v_mouse (#scroll1);      //êîí÷åíûé ñêðîëë ïðèòîðìàæèìàåò, èä¸ì "ñâîèì ïóò¸ì"
  112.                                 if (lines.first <> scroll1.position)
  113.                                 {
  114.                                         lines.first = scroll1.position;
  115.                                         WB1.ParseHTML(buf, filesize);
  116.                                         //break;
  117.                                 };*/
  118.                                
  119.                                 btn=GetProcessSlot(Form.ID);
  120.                                 IF (btn<>GetActiveProcess()) break; //åñëè îêíî íå àêòèâíî íà ñîáûòèÿ ìûøè íå ðåàãèðóåì
  121.  
  122.                                 edit_box_mouse stdcall (#edit1);
  123.  
  124.                                 m.get();
  125.                                
  126.                                 if (m.pkm) && (m.y>WB1.top) && (m.y<Form.height) && (filesize)
  127.                                 {
  128.                                         SwitchToAnotherThread();
  129.                                         CreateThread(#menu_rmb,#stak);
  130.                                 }
  131.  
  132.                                 IF (m.vert==65535) //ïðîêðóòêà êîë¸ñèêîì
  133.                                 {
  134.                                         IF (lines.first==0) break;
  135.                                         IF (lines.first>3) lines.first-=2; ELSE lines.first=1;
  136.                                         WB1.Scan(ID1);
  137.                                         break;
  138.                                 }
  139.                                 IF (m.vert==1)
  140.                                 {
  141.                                         IF(lines.visible+lines.first+3>=lines.all) WB1.Scan(181);
  142.                                         ELSE    {
  143.                                                 lines.first+=2;
  144.                                                 WB1.Scan(ID2);
  145.                                         }
  146.                                         break;
  147.                                 }
  148.                                
  149.                                 if (!m.lkm) scroll_used=0;
  150.                                 if (m.x>=WB1.width-14) && (m.x<=WB1.width+6) && (m.y>WB1.top+16)
  151.                                 && (m.y<WB1.top+WB1.height-16) && (lines.all>lines.visible) && (m.lkm)
  152.                                         scroll_used=1;
  153.                                
  154.                                 if (scroll_used)
  155.                                 {
  156.                                         half_scroll_size = WB1.height - 16 * lines.visible / lines.all - 3 /2;
  157.                                         IF (half_scroll_size+WB1.top>m.y) || (m.y<0) || (m.y>4000) m.y=half_scroll_size+WB1.top; //åñëè êóðñîð íàä îêíîì
  158.                                         btn=lines.first; //ñîõðàíÿåì ñòàðîå êîëè÷åñòâî
  159.                                         lines.first = m.y -half_scroll_size -WB1.top * lines.all / WB1.height;
  160.                                         if (lines.visible+lines.first>lines.all) lines.first=lines.all-lines.visible;
  161.                                         if (btn<>lines.first) WB1.ParseHTML(buf); //÷òîá ëèøíèé ðàç íå ïåðåðèñîâûâàòü
  162.                                 }
  163.  
  164.                                 break;
  165.                         case evButton:
  166.                                 btn=GetButtonID();
  167.                                 IF (btn==1)
  168.                                 {
  169.                                         KillProcess(downloader_id);
  170.                                         ExitProcess();
  171.                                 }
  172.                                 ELSE
  173.                                 {
  174.                                         WB1.Scan(btn);
  175.                                 }
  176.                                 break;
  177.                         case evKey:
  178.                                 key = GetKey();
  179.                                
  180.                                 if (edit1.flags == 66) || (edit1.flags == 98) SWITCH(key) //åñëè àêòèâíà ñòðîêà àäðåñà èãíîðèðóåì íåêîòîðûå êíîïêè
  181.                                         { CASE 52: CASE 53: CASE 54: goto _EDIT_MARK; }
  182.  
  183.                                 WB1.Scan(key);
  184.                                
  185.                                 _EDIT_MARK:
  186.                                 IF (key<>0x0d) && (key<>183) && (key<>184) && (key<>173) {EAX=key<<8; edit_box_key stdcall(#edit1);} //àäðåñíàÿ ñòðîêà
  187.                                 break;
  188.                         case evReDraw:
  189.                                 Draw_Window();
  190.                                 break;
  191.                         default:
  192.                                 if (downloader_id<>0)
  193.                                 {
  194.                                         if (GetProcessSlot(downloader_id)<>0) break;
  195.                                         downloader_id=0;
  196.                                         lines.first = lines.all = 0;
  197.                                         WB1.ReadHtml(_WIN);
  198.                                         Draw_Window();
  199.                                 }
  200.                 }
  201.         }
  202. }
  203.  
  204. void SetElementSizes()
  205. {
  206.         edit1.width=Form.width-266;
  207.         WB1.top=44;
  208.         WB1.width=Form.width-13;
  209.         WB1.height=onTop(43,5);
  210.         lines.column_max = WB1.width - 30 / 6;
  211.         lines.visible = WB1.height - 3 / 10 - 2;
  212. }
  213.  
  214.  
  215. void Draw_Window()
  216. {
  217.         int j;
  218.         DefineAndDrawWindow(215,100,WIN_W,WIN_H,0x73,0x00E4DFE1,0);
  219.  
  220.         GetProcessInfo(#Form, SelfInfo);
  221.         if (Form.status_window>2) //åñëè ñâåðíóòî â çàãîëîâîê, íè÷åãî íå ðèñóåì
  222.         {
  223.                 DrawTitle(#header);
  224.                 return;
  225.         }
  226.         if (Form.height<120) MoveSize(OLD,OLD,OLD,120);
  227.         if (Form.width<280) MoveSize(OLD,OLD,280,OLD);
  228.        
  229.         PutPaletteImage(#toolbar,200,42,0,0,8,#toolbar_pal);
  230.         if (GetProcessSlot(downloader_id)<>0) PutImage(#stop_btn,24,24,88,10);
  231.        
  232.         DrawBar(200,0,onLeft(200,9),43,0xE4DFE1); //çàêðàøèâàåì ôîí ïîä òóëáàðîì
  233.         DrawBar(0,42,onLeft(5,4),1,0xE2DBDC); //âûïóêëîñòü
  234.         DrawBar(0,43,onLeft(5,4),1,0xD2CED0); //âûïóêëîñòü
  235.         for (j=0; j<5; j++) DefineButton(j*37+11, 7, 29, 29, 300+j+BT_HIDE, 0xE4DFE1);
  236.         PutImage(#URLgoto,40,19,onLeft(57,0),14);
  237.         DefineButton(onLeft(37,0),15, 18, 16, GOTOURL+BT_HIDE, 0xE4DFE1);
  238.         DefineButton(onLeft(56,0),15, 17, 16, SEARCHWEB+BT_HIDE, 0xE4DFE1);
  239.         DrawRegion(205,14,onLeft(58,205),18,0x94AECE); //îáîäîê ïîëîñû àäðåñà
  240.         DrawRegion(206,15,onLeft(59,205),16,0xE4ECF3);
  241.  
  242.         SetElementSizes();
  243.         WB1.ShowPage();
  244.        
  245.         DefineButton(scroll1.start_x+1, scroll1.start_y+1, 16, 16, ID1+BT_HIDE, 0xE4DFE1);
  246.         DefineButton(scroll1.start_x+1, scroll1.start_y+scroll1.size_y-18, 16, 16, ID2+BT_HIDE, 0xE4DFE1);
  247. }
  248.  
  249. int onLeft(dword right,left) {return Form.width-right-left;}
  250. int onTop(dword down,up) {return Form.height-GetSkinHeight()-down-up;}
  251.  
  252.  
  253. stop:
  254.