Subversion Repositories Kolibri OS

Rev

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