Subversion Repositories Kolibri OS

Rev

Rev 4415 | Go to most recent revision | 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. #include "..\lib\list_box.h"
  20. //*.obj libraries
  21. #include "..\lib\lib.obj\box_lib.h"
  22. #include "..\lib\lib.obj\libio_lib.h"
  23. #include "..\lib\lib.obj\libimg_lib.h"
  24. //images
  25. #include "img\toolbar_icons.c"
  26. #include "img\URLgoto.txt";
  27.  
  28. #ifdef LANG_RUS
  29.         char version[]=" ’¥ªáâ®¢ë© ¡à ã§¥à 0.99.31";
  30.         ?define IMAGES_CACHE_CLEARED "Šíè ª à⨭®ª ®ç¨é¥­"
  31. #else
  32.         char version[]=" Text-based Browser 0.99.31";
  33.         ?define IMAGES_CACHE_CLEARED "Images cache cleared"
  34. #endif
  35.  
  36. proc_info Form;
  37. #define WIN_W 640
  38. #define WIN_H 480
  39.  
  40. char search_path[]="http://nigma.ru/index.php?s=";
  41.  
  42. char stak[4096];
  43. mouse m;
  44. int action_buf;
  45.  
  46.  
  47.  
  48. #include "..\TWB\TWB.c"
  49. #include "menu_rmb.h"
  50.  
  51.  
  52. void main()
  53. {
  54.         int key, btn;
  55.         int half_scroll_size;
  56.         int scroll_used=0, show_menu;
  57.        
  58.         mem_Init();
  59.         if (load_dll2(boxlib, #box_lib_init,0)!=0) {notify("System Error: library doesn't exists /rd/1/lib/box_lib.obj"); ExitProcess();}
  60.         if (load_dll2(libio, #libio_init,1)!=0) debug("Error: library doesn't exists - libio");
  61.         if (load_dll2(libimg, #libimg_init,1)!=0) debug("Error: library doesn't exists - libimg");
  62.        
  63.         if (!URL) strcpy(#URL, "/sys/index.htm");
  64.         strcpy(#editURL, #URL);
  65.        
  66.         Form.width=WIN_W;
  67.         Form.height=WIN_H;
  68.         SetElementSizes();
  69.         OpenPage();
  70.  
  71.         SetEventMask(0x27);
  72.         loop()
  73.         {
  74.                 WaitEventTimeout(2);
  75.                 switch(EAX & 0xFF)
  76.                 {
  77.                         CASE evMouse:
  78.                                 /*
  79.                                 //not work well, so we are use custom way of processing scroll
  80.                                 scrollbar_v_mouse (#scroll_wv);
  81.                                 if (WB1.list.first <> scroll_wv.position)
  82.                                 {
  83.                                         WB1.list.first = scroll_wv.position;
  84.                                         WB1.ParseHTML(buf, filesize);
  85.                                 };
  86.                                 */
  87.                                
  88.                                 if (!CheckActiveProcess(Form.ID)) break;
  89.  
  90.                                 edit_box_mouse stdcall (#address_box);
  91.  
  92.                                 m.get();
  93.                                
  94.                                 if (m.y>WB1.list.y) && (m.y<Form.height) && (filesize)
  95.                                 {
  96.                                         if (m.pkm)
  97.                                         {
  98.                                                 show_menu = 1;
  99.                                         }
  100.                                         if (!m.pkm) && (show_menu)
  101.                                         {
  102.                                                 show_menu = 0;
  103.                                                 SwitchToAnotherThread();
  104.                                                 CreateThread(#menu_rmb,#stak+4092);
  105.                                                 break;
  106.                                         }
  107.                                 }
  108.  
  109.                                 if (m.vert)
  110.                                 {
  111.                                         if (WB1.list.MouseScroll(m.vert)) WB1.ParseHTML(buf);
  112.                                 }
  113.                                
  114.                                 if (!m.lkm) scroll_used=0;
  115.                                 if (m.x>=scroll_wv.start_x) && (m.x<=scroll_wv.start_x+scroll_wv.size_x)
  116.                                 && (m.y>=scroll_wv.start_y+scroll_wv.btn_height) && (-scroll_wv.btn_height+scroll_wv.start_y+scroll_wv.size_y>m.y)
  117.                                 && (WB1.list.count>WB1.list.visible) && (m.lkm)
  118.                                 {
  119.                                         scroll_used=1;
  120.                                 }
  121.                                
  122.                                 if (scroll_used)
  123.                                 {
  124.                                         half_scroll_size = WB1.list.h - 16 * WB1.list.visible / WB1.list.count - 3 /2;
  125.                                         if (half_scroll_size+WB1.list.y>m.y) || (m.y<0) || (m.y>4000) m.y=half_scroll_size+WB1.list.y;
  126.                                         btn=WB1.list.first;
  127.                                         WB1.list.first = m.y -half_scroll_size -WB1.list.y * WB1.list.count / WB1.list.h;
  128.                                         if (WB1.list.visible+WB1.list.first>WB1.list.count) WB1.list.first=WB1.list.count-WB1.list.visible;
  129.                                         if (btn<>WB1.list.first) WB1.ParseHTML(buf);
  130.                                 }
  131.  
  132.                                 break;
  133.                         case evButton:
  134.                                 btn=GetButtonID();
  135.                                 if (btn==1)
  136.                                 {
  137.                                         KillProcess(downloader_id);
  138.                                         ExitProcess();
  139.                                 }
  140.                                 ELSE
  141.                                 {
  142.                                         Scan(btn);
  143.                                 }
  144.                                 break;
  145.                         case evKey:
  146.                                 key = GetKey();
  147.                                
  148.                                 if (address_box.flags & 0b10) SWITCH(key)
  149.                                         { CASE 52: CASE 53: CASE 54: goto _EDIT_MARK; }
  150.  
  151.                                 Scan(key);
  152.                                
  153.                                 _EDIT_MARK:
  154.                                 if (key<>0x0d) && (key<>183) && (key<>184) {EAX=key<<8; edit_box_key stdcall(#address_box);}
  155.                                 break;
  156.                         case evReDraw:
  157.                                 if (action_buf) { Scan(action_buf); action_buf=0;}
  158.                                 Draw_Window();
  159.                                 break;
  160.                         default:
  161.                                 if (downloader_id<>0)
  162.                                 {
  163.                                         if (GetProcessSlot(downloader_id)<>0) break;
  164.                                         downloader_id=0;
  165.                                         WB1.list.first = WB1.list.count = 0;
  166.                                         WB1.ReadHtml(_WIN);
  167.                                         Draw_Window();
  168.                                 }
  169.                 }
  170.         }
  171. }
  172.  
  173. void SetElementSizes()
  174. {
  175.         address_box.width = Form.width - 266;
  176.         WB1.list.SetSizes(0, 44, Form.width - 10 - scroll_wv.size_x, Form.cheight - 44, 0, 10);
  177.         WB1.list.column_max = WB1.list.w - 30 / 6;
  178.         WB1.list.visible = WB1.list.h - 3 / WB1.list.line_h - 2;
  179.         DrawBufInit();
  180. }
  181.  
  182.  
  183. void Draw_Window()
  184. {
  185.         int j;
  186.         DefineAndDrawWindow(215,100,WIN_W,WIN_H,0x73,0xE4DFE1,0,0);
  187.  
  188.         GetProcessInfo(#Form, SelfInfo);
  189.         if (Form.status_window>2)
  190.         {
  191.                 DrawTitle(#header);
  192.                 return;
  193.         }
  194.         if (Form.height<120) MoveSize(OLD,OLD,OLD,120);
  195.         if (Form.width<280) MoveSize(OLD,OLD,280,OLD);
  196.        
  197.         PutPaletteImage(#toolbar,200,42,0,0,8,#toolbar_pal);
  198.         if (GetProcessSlot(downloader_id)<>0) _PutImage(88,10, 24,24, #stop_btn);
  199.        
  200.         DrawBar(200,0,Form.cwidth-200,43,0xE4DFE1);
  201.         DrawBar(0,42,Form.cwidth,1,0xE2DBDC);
  202.         DrawBar(0,43,Form.cwidth,1,0xD2CED0);
  203.         for (j=0; j<5; j++) DefineButton(j*37+11, 7, 29, 29, 300+j+BT_HIDE, 0xE4DFE1);
  204.         _PutImage(Form.cwidth-48,14, 40,19, #URLgoto);
  205.         DefineButton(Form.cwidth-28,15, 18, 16, GOTOURL+BT_HIDE, 0xE4DFE1);
  206.         DefineButton(Form.cwidth-47,15, 17, 16, SEARCHWEB+BT_HIDE, 0xE4DFE1);
  207.         DrawRectangle(205,14,Form.cwidth-205-49,18,0x94AECE); //around adress bar
  208.         DrawRectangle(206,15,Form.cwidth-205-50,16,0xE4ECF3);
  209.  
  210.         SetElementSizes();
  211.         WB1.ShowPage();
  212.  
  213.         DefineButton(scroll_wv.start_x+1, scroll_wv.start_y+1, 16, 16, BTN_UP+BT_HIDE, 0xE4DFE1);
  214.         DefineButton(scroll_wv.start_x+1, scroll_wv.start_y+scroll_wv.size_y-18, 16, 16, BTN_DOWN+BT_HIDE, 0xE4DFE1);
  215. }
  216.  
  217.  
  218. void Scan(int id)
  219. {
  220.         if (id >= 400) ProcessLinks(id);
  221.        
  222.         switch (id)
  223.         {
  224.                 case 011: //Ctrk+K
  225.                         WB1.ReadHtml(_KOI);
  226.                         WB1.ParseHTML(buf);
  227.                         return;
  228.  
  229.                 case 021: //Ctrl+U
  230.                         WB1.ReadHtml(_UTF);
  231.                         WB1.ParseHTML(buf);
  232.                         return;
  233.  
  234.                 case 004: //Ctrl+D
  235.                         WB1.ReadHtml(_DOS);
  236.                         WB1.ParseHTML(buf);
  237.                         return;
  238.  
  239.                 case 002: //free img cache
  240.                         FreeImgCache();
  241.                         notify(IMAGES_CACHE_CLEARED);
  242.                         WB1.ParseHTML(buf);
  243.                         return;
  244.  
  245.                 case BACK:
  246.                         if (!BrowserHistory.GoBack()) return;
  247.                         OpenPage();
  248.                         return;
  249.                 case FORWARD:
  250.                         if (!BrowserHistory.GoForward()) return;
  251.                         OpenPage();
  252.                         return;
  253.                 case 052:  //F3
  254.                         if (strcmp(get_URL_part(5),"http:")<>0) RunProgram("/rd/1/tinypad", #URL);
  255.                         else RunProgram("/rd/1/tinypad", #download_path);
  256.                         return;
  257.                 case 054: //F5
  258.                         IF(address_box.flags & 0b10) WB1.ParseHTML(buf);
  259.                         return;
  260.  
  261.                 case REFRESH:
  262.                         if (GetProcessSlot(downloader_id)<>0)
  263.                         {
  264.                                 KillProcess(downloader_id);
  265.                                 pause(20);
  266.                                 Draw_Window();
  267.                                 return;
  268.                         }
  269.                         anchor_line_num=WB1.list.first;
  270.                         anchor[0]='|';
  271.                         OpenPage();
  272.                         return;
  273.                 case 014:
  274.                 case 020:
  275.                 case NEWTAB:
  276.                         MoveSize(190,80,OLD,OLD);
  277.                         RunProgram(#program_path, #URL);
  278.                         return;
  279.                        
  280.                 case HOME:
  281.                         strcpy(#editURL, "http://kolibrios.org/en/index.htm");
  282.                 case GOTOURL:
  283.                 case 0x0D: //enter
  284.                         if ((strstr(#editURL,"ttp://")==0) && (editURL[0]!='/')) strcpy(#URL,"http://"); else URL[0] = 0;
  285.                         strcat(#URL, #editURL);
  286.                         OpenPage();
  287.                         return;
  288.                 case SEARCHWEB:
  289.                         strcpy(#URL, #search_path);
  290.                         strcat(#URL, #editURL);
  291.                         OpenPage();
  292.                         return;
  293.  
  294.                 case 183: //PgDown
  295.                         if (WB1.list.count < WB1.list.visible) return;
  296.                         IF(WB1.list.first == WB1.list.count - WB1.list.visible) return;
  297.                         WB1.list.first += WB1.list.visible + 2;
  298.                         IF(WB1.list.visible + WB1.list.first > WB1.list.count) WB1.list.first = WB1.list.count - WB1.list.visible;
  299.                         WB1.ParseHTML(buf);
  300.                         return;
  301.  
  302.                 case 184: //PgUp
  303.                         if (WB1.list.count < WB1.list.visible) return;
  304.                         IF(WB1.list.first == 0) return;
  305.                         WB1.list.first -= WB1.list.visible - 2;
  306.                         IF(WB1.list.first < 0) WB1.list.first = 0;
  307.                         WB1.ParseHTML(buf);
  308.                         return;
  309.  
  310.                 case 178:
  311.                 case BTN_UP: //ìîòàåì ââåðõ
  312.                         if (WB1.list.first <= 0) return;
  313.                         WB1.list.first--;
  314.                         WB1.ParseHTML(buf);
  315.                         return;
  316.  
  317.                 case 177:
  318.                 case BTN_DOWN: //ìîòàåì âíèç
  319.                         if (WB1.list.visible + WB1.list.first >= WB1.list.count) return;
  320.                         WB1.list.first++;
  321.                         WB1.ParseHTML(buf);
  322.                         return;
  323.  
  324.                 case 180: //home
  325.                         if (WB1.list.KeyHome()) WB1.ParseHTML(buf);
  326.                         return;
  327.  
  328.                 case 181: //end
  329.                         if (WB1.list.count < WB1.list.visible) return;
  330.                         if (WB1.list.KeyEnd()) WB1.ParseHTML(buf);
  331.                         return;
  332.         }
  333. }
  334.  
  335.  
  336.  
  337. void ProcessLinks(int id)
  338. {
  339.         GetURLfromPageLinks(id);
  340.        
  341.         //#1
  342.         if (URL[0] == '#')
  343.         {
  344.                 strcpy(#anchor, #URL+strrchr(#URL, '#'));
  345.                
  346.                 strcpy(#URL, BrowserHistory.CurrentUrl());
  347.                
  348.                 WB1.list.first=WB1.list.count-WB1.list.visible;
  349.                 WB1.ShowPage();
  350.                 return;
  351.         }
  352.         //liner.ru#1
  353.         if (strrchr(#URL, '#')<>-1)
  354.         {
  355.                 strcpy(#anchor, #URL+strrchr(#URL, '#'));
  356.                 URL[strrchr(#URL, '#')-1] = 0x00;
  357.         }
  358.        
  359.         WB1.GetNewUrl();
  360.        
  361.         if (!strcmp(#URL + strlen(#URL) - 4, ".gif")) || (!strcmp(#URL + strlen(#URL) - 4, ".png")) || (!strcmp(#URL + strlen(#URL) - 4, ".jpg"))
  362.         {
  363.                 //if (strstr(#URL,"http:"))
  364.                 RunProgram("/sys/media/kiv", #URL);
  365.                 strcpy(#editURL, BrowserHistory.CurrentUrl());
  366.                 strcpy(#URL, BrowserHistory.CurrentUrl());
  367.                 return;
  368.         }
  369.         if (!strcmpn(#URL,"mailto:", 7))
  370.         {
  371.                 notify(#URL);
  372.                 strcpy(#editURL, BrowserHistory.CurrentUrl());
  373.                 strcpy(#URL, BrowserHistory.CurrentUrl());
  374.                 return;
  375.         }
  376.  
  377.         OpenPage();
  378.         return;
  379. }
  380.  
  381. void OpenPage()
  382. {
  383.         if (GetProcessSlot(downloader_id)<>0) PutPaletteImage(#toolbar,200,42,0,0,8,#toolbar_pal);
  384.         KillProcess(downloader_id);
  385.         strcpy(#editURL, #URL);
  386.         BrowserHistory.AddUrl();
  387.         strcpy(#header, #version);
  388.         pre_text =0;
  389.         if (!strcmp(get_URL_part(5),"http:")))
  390.         {
  391.                 KillProcess(downloader_id);
  392.                 DeleteFile(#download_path);
  393.                 IF (URL[strlen(#URL)-1]=='/') URL[strlen(#URL)-1]=NULL;
  394.                 downloader_id = RunProgram("/sys/network/downloader", #URL);
  395.                 IF (downloader_id<0) notify("Error running Downloader. Internet unavilable.");
  396.                 Draw_Window();
  397.                 return;
  398.         }
  399.         WB1.list.first = WB1.list.count =0;
  400.         WB1.ReadHtml(_WIN);
  401.         WB1.ShowPage();
  402. }
  403.  
  404.  
  405.  
  406. stop:
  407.