Subversion Repositories Kolibri OS

Rev

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