Subversion Repositories Kolibri OS

Rev

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