Subversion Repositories Kolibri OS

Rev

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