Subversion Repositories Kolibri OS

Rev

Rev 6217 | Go to most recent revision | Blame | Last modification | View Log | Download | RSS feed

  1. #define MEMSIZE 4096*60
  2.  
  3. #include "../lib/font.h"
  4. #include "../lib/io.h"
  5. #include "../lib/gui.h"
  6. #include "../lib/list_box.h"
  7. #include "../lib/menu.h"
  8. #include "../lib/obj/box_lib.h"
  9. #include "../lib/obj/libini.h"
  10. #include "../lib/obj/iconv.h"
  11. #include "../lib/obj/proc_lib.h"
  12. #include "../lib/obj/http.h"
  13. #include "../lib/cursor.h"
  14. #include "../lib/patterns/libimg_load_skin.h"
  15. #include "../lib/patterns/simple_open_dialog.h"
  16. #include "../lib/patterns/history.h"
  17. #include "../lib/patterns/http_downloader.h"
  18. #include "../browser/download_manager.h"
  19.  
  20. char default_dir[] = "/rd/1";
  21. od_filter filter2 = {0,0};
  22.  
  23. char accept_language[]= "Accept-Language: ru\n";
  24.  
  25. #define TOOLBAR_H 36
  26. #define TOOLBAR_ICON_WIDTH  26
  27. #define TOOLBAR_ICON_HEIGHT 24
  28.  
  29. #define DEFAULT_EDITOR "/sys/tinypad"
  30. #define DEFAULT_PREVIEW_PATH "/tmp0/1/aelia_preview.txt"
  31.  
  32. //ATTENTION: each page must have '\0' character at the end of the file
  33. char buidin_page_home[] = FROM "buidin_pages\\home.htm";
  34. char buidin_page_about[] = FROM "buidin_pages\\about.htm";
  35. char buidin_page_not_found[] = FROM "buidin_pages\\not_found.htm";
  36.  
  37. #define UML 4096*2
  38.  
  39. scroll_bar scroll = { 15,200,398,44,0,2,115,15,0,0xeeeeee,0xBBBbbb,0xeeeeee,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1};
  40. llist list;
  41.  
  42. proc_info Form;
  43. char title[4196];
  44.  
  45. enum {
  46.         OPEN_FILE,
  47.         MAGNIFY_MINUS,
  48.         MAGNIFY_PLUS,
  49.         CHANGE_ENCODING,
  50.         RUN_EDIT,
  51.         GO_BACK,
  52.         GO_FORWARD,
  53.         SANDWICH
  54. };
  55.  
  56. char address[UML]="http://";
  57. int     mouse_address_box;
  58. edit_box address_box = {250,56,34,0xffffff,0x94AECE,0xffffff,0xffffff,0,UML,#address,#mouse_address_box,2,19,19};
  59.  
  60. CustomCursor CursorPointer;
  61. dword CursorFile = FROM "pointer.cur";
  62.  
  63. #include "favicon.h"
  64. #include "ini.h"
  65. #include "gui.h"
  66. #include "label.h"
  67. #include "link.h"
  68. #include "tag.h"
  69. #include "prepare_page.h"
  70. //#include "special_symbols.h"
  71.  
  72. #define SANDWICH_MENU "Refresh page\nEdit page\nHistory\nDownloader\nAbout"
  73.  
  74. void InitDlls()
  75. {
  76.         load_dll(boxlib,    #box_lib_init,   0);
  77.         load_dll(libHTTP,   #http_lib_init,  1);
  78.         load_dll(libio,     #libio_init,     1);
  79.         load_dll(libimg,    #libimg_init,    1);
  80.         //load_dll(libini,    #lib_init,       1);
  81.         load_dll(iconv_lib, #iconv_open,     0);
  82.         load_dll(Proc_lib,  #OpenDialog_init,0);
  83. }
  84.  
  85.  
  86. void main()
  87. {  
  88.         InitDlls();    
  89.         OpenDialog_init stdcall (#o_dialog);
  90.         CursorPointer.Load(#CursorFile);
  91.         label.init(DEFAULT_FONT);
  92.         Libimg_LoadImage(#skin, abspath("toolbar.png"));
  93.         LoadIniSettings();
  94.         list.no_selection = true;
  95.         SetEventMask(10000000000000000000000001100111b);
  96.         loop()
  97.         {
  98.                 switch(WaitEvent())
  99.                 {
  100.                         case evMouse:
  101.                                 HandleMouseEvent();
  102.                                 break;
  103.                         case evKey:
  104.                                 HandleKeyEvent();
  105.                                 break;
  106.                         case evButton:
  107.                                 HandleButtonEvent();
  108.                                 break;
  109.                         case evReDraw:
  110.                                 draw_window();
  111.                                 if (menu.list.cur_y>=10) && (menu.list.cur_y<20) {
  112.                                         encoding = menu.list.cur_y - 10;
  113.                                         EventPageRefresh();
  114.                                         menu.list.cur_y = 0;
  115.                                 }
  116.                                 if (menu.list.cur_y>=20) {
  117.                                         menu.list.cur_y-=20;
  118.                                         if (menu.list.cur_y==0) EventPageRefresh();
  119.                                         if (menu.list.cur_y==1) EventRunEdit();
  120.                                         if (menu.list.cur_y==2) EventShowHistory();
  121.                                         if (menu.list.cur_y==3) EventShowDownloader();
  122.                                         if (menu.list.cur_y==4) EventShowInfo();
  123.                                         menu.list.cur_y = 0;
  124.                                 }
  125.                 }
  126.         }
  127. }
  128.  
  129.  
  130. void HandleButtonEvent()
  131. {
  132.         byte btn = GetButtonID();
  133.         if (btn==1) {
  134.                 SaveIniSettings();
  135.                 ExitProcess();
  136.         }
  137.         switch(btn-10)
  138.         {
  139.                 case GO_BACK:
  140.                         EventGoBack();
  141.                         break;
  142.                 case GO_FORWARD:
  143.                         EventGoForward();
  144.                         break;
  145.                 case OPEN_FILE:
  146.                         EventOpenDialog();
  147.                         break;
  148.                 case MAGNIFY_PLUS:
  149.                         EventMagnifyPlus();
  150.                         break;
  151.                 case MAGNIFY_MINUS:
  152.                         EventMagnifyMinus();
  153.                         break;
  154.                 case CHANGE_ENCODING:
  155.                         EventChangeEncoding();
  156.                         break;
  157.                 case RUN_EDIT:
  158.                         EventRunEdit();
  159.                         break;
  160.                 case SANDWICH:
  161.                         EventShowSandwichMenu();
  162.                         break;
  163.         }
  164. }
  165.  
  166.  
  167. void HandleKeyEvent()
  168. {
  169.         GetKeys();
  170.         switch (key_scancode)
  171.         {
  172.                 case 059:
  173.                         EventShowInfo();
  174.                         return;
  175.                 case SCAN_CODE_ENTER:
  176.                         EventOpenAddress(#address);
  177.                         return;
  178.                 case SCAN_CODE_BS:
  179.                         if (! address_box.flags & 0b10) {
  180.                                 EventGoBack();
  181.                                 return;
  182.                         }
  183.         }
  184.         if (key_modifier & KEY_LCTRL) || (key_modifier & KEY_RCTRL) {
  185.                 switch (key_scancode)
  186.                 {
  187.                         case 024: //O
  188.                                 EventOpenDialog();
  189.                                 break;
  190.                         case SCAN_CODE_UP:
  191.                                 EventMagnifyPlus();
  192.                                 break;
  193.                         case SCAN_CODE_DOWN:
  194.                                 EventMagnifyMinus();
  195.                                 break;
  196.                         case 018: //E
  197.                                 EventRunEdit();
  198.                                 break;
  199.                         case 035: //H
  200.                                 EventShowHistory();
  201.                                 break;
  202.                         case SCAN_CODE_TAB:
  203.                                 EventChangeEncoding();
  204.                                 break;
  205.                 }
  206.                 return;
  207.         }
  208.         if (list.ProcessKey(key_scancode)) {
  209.                 DrawPage();
  210.                 return;
  211.         }
  212.         if (key_ascii != 0x0d)
  213.         && (key_ascii != ASCII_KEY_PGDN)
  214.         && (key_ascii != ASCII_KEY_PGUP) {
  215.                 EAX = key_ascii << 8;
  216.                 edit_box_key stdcall(#address_box);
  217.         }
  218. }
  219.  
  220.  
  221. void HandleMouseEvent()
  222. {
  223.         edit_box_mouse stdcall (#address_box);
  224.         mouse.get();
  225.         list.wheel_size = 7;
  226.         link.hover();
  227.         if (list.MouseScroll(mouse.vert)) {
  228.                 DrawPage();
  229.                 return;
  230.         }
  231.         scrollbar_v_mouse (#scroll);
  232.         if (list.first != scroll.position) {
  233.                 list.first = scroll.position;
  234.                 DrawPage();
  235.         }
  236. }
  237.  
  238.  
  239. /* ----------------------------------------------------- */
  240.  
  241. void EventOpenDialog()
  242. {
  243.         OpenDialog_start stdcall (#o_dialog);
  244.         if (o_dialog.status) EventOpenAddress(#openfile_path);
  245. }
  246.  
  247. void EventOpenAddress(dword _new_address)
  248. {
  249. char temp[UML];
  250. char favicon_address[UML];
  251.         if (!ESBYTE[_new_address]) return;
  252.         debugln("====================================");
  253.         debug("address: ");
  254.         debugln(_new_address);
  255.         strlcpy(#address, _new_address, UML);
  256.         strlwr(#address);
  257.         DrawAddressBox();
  258.  
  259.         /*
  260.         There could be several possible types of addresses:
  261.         - build in page
  262.         - local file
  263.         - url
  264.         So we need to detect what incoming address is
  265.         and then halndle it in the propper way.
  266.         */
  267.  
  268.         io.buffer_data = 0;
  269.         favicon.get(NULL);
  270.  
  271.         // - build in page
  272.         if (!strncmp(#address,"aelia:",6)) {
  273.                 debugln("this is buildin page");
  274.                 if (!strcmp(#address,"aelia:home")) io.buffer_data = #buidin_page_home;
  275.                 if (!strcmp(#address,"aelia:about")) io.buffer_data = #buidin_page_about;
  276.                 if (!strcmp(#address,"aelia:history")) io.buffer_data = MakePageWithHistory();
  277.         }
  278.         // - local file
  279.         else if (check_is_the_adress_local(#address)==true) {
  280.                 debugln("this is local address");
  281.                 io.read(#address);
  282.         }
  283.         // - url
  284.         else {
  285.                 debugln("this is url");
  286.                 if (strncmp(#address,"http://",7)!=0) {
  287.                         strcpy(#temp, "http://");
  288.                         strlcpy(#temp, #address, UML);
  289.                         strlcpy(#address, #temp, UML);
  290.                         DrawAddressBox();
  291.                 }
  292.                 if (!downloader.Start(#address)) {
  293.                         downloader.Stop();
  294.                 } else {
  295.                         while (downloader.state!=STATE_COMPLETED)
  296.                         {
  297.                                 downloader.MonitorProgress();
  298.                                 if (downloader.data_full_size>0)
  299.                                         DrawProgress(STEP_2_COUNT_PAGE_HEIGHT-STEP_1_DOWNLOAD_PAGE*downloader.data_downloaded_size/downloader.data_full_size);
  300.                                 else
  301.                                         DrawProgress(STEP_2_COUNT_PAGE_HEIGHT-STEP_1_DOWNLOAD_PAGE/2);
  302.                         }
  303.                         strcpy(#address,downloader.url);
  304.                         DrawAddressBox();
  305.                         io.buffer_data = downloader.bufpointer;
  306.                         get_absolute_url(#favicon_address, #address, "/favicon.ico");
  307.                         favicon.get(#favicon_address);
  308.                 }
  309.         }
  310.  
  311.         if (!io.buffer_data) {
  312.                 debugln("page not found");
  313.                 io.buffer_data = #buidin_page_not_found;
  314.         }
  315.  
  316.         history.add(#address);
  317.         favicon.draw(address_box.left-18, address_box.top-1);
  318.  
  319.         /*
  320.         Great! So we have the page in our buffer.
  321.         We don't know is it a plain text or html.
  322.         So we need to parse it and draw.
  323.         */
  324.  
  325.         list.KeyHome();
  326.         list.ClearList();
  327.         PreparePage();
  328. }
  329.  
  330. void EventMagnifyPlus()
  331. {
  332.         label.size.pt++;
  333.         if(!label.changeSIZE())
  334.                 label.size.pt--;
  335.         else
  336.                 PreparePage();
  337. }
  338.  
  339. void EventMagnifyMinus()
  340. {
  341.         label.size.pt--;
  342.         if(!label.changeSIZE())
  343.                 label.size.pt++;
  344.         else
  345.                 PreparePage();
  346. }
  347.  
  348. void EventRunEdit()
  349. {
  350.         if (check_is_the_adress_local(history.current())==true) {
  351.                 io.run(DEFAULT_EDITOR, history.current());
  352.         }
  353.         else {
  354.                 //io.write(strlen(io.buffer_data), io.buffer_data, DEFAULT_PREVIEW_PATH); // <--- doesn't work, smth odd, need to check
  355.                 WriteFile(strlen(io.buffer_data), io.buffer_data, DEFAULT_PREVIEW_PATH);
  356.                 io.run(DEFAULT_EDITOR, DEFAULT_PREVIEW_PATH);
  357.         }
  358. }
  359.  
  360. void EventChangeEncoding()
  361. {
  362.         menu.selected = encoding + 1;
  363.         menu.show(Form.left+Form.cwidth-97,Form.top+TOOLBAR_H+skin_height-6, 130, "UTF-8\nKOI8-RU\nCP1251\nCP1252\nISO8859-5\nCP866", 10);
  364. }
  365.  
  366. void EventShowInfo() {
  367.         EventOpenAddress("aelia:about");
  368. }
  369.  
  370. void EventShowHistory()
  371. {
  372.         EventOpenAddress("aelia:history");
  373. }
  374.  
  375. void EventGoBack()
  376. {
  377.         if (history.back()) EventOpenAddress(history.current());
  378. }
  379.  
  380. void EventGoForward()
  381. {
  382.         if (history.forward()) EventOpenAddress(history.current());
  383. }
  384.  
  385. void EventShowSandwichMenu()
  386. {
  387.         menu.selected = 0;
  388.         menu.show(Form.left+Form.cwidth-130,Form.top+TOOLBAR_H+skin_height-10, 130, SANDWICH_MENU, 20);
  389. }
  390.  
  391. void EventPageRefresh()
  392. {
  393.         EventOpenAddress(history.current());
  394. }
  395.  
  396. void EventShowDownloader()
  397. {
  398.         if (!downloader_opened) {
  399.                 downloader_edit = NULL;
  400.                 CreateThread(#Downloader,#downloader_stak+4092);
  401.         }
  402. }
  403.  
  404. /* ------------------------------------------- */
  405.  
  406.  
  407. void draw_window()
  408. {
  409.         DefineAndDrawWindow(Form.left,Form.top,Form.width,Form.height,0x73,0,#title);
  410.         GetProcessInfo(#Form, SelfInfo);
  411.         if (Form.status_window>2) return;
  412.  
  413.         if (Form.width  < 200) { MoveSize(OLD,OLD,200,OLD); return; }
  414.         if (Form.height < 200) { MoveSize(OLD,OLD,OLD,200); return; }
  415.        
  416.         DrawBar(0, 0, Form.cwidth, TOOLBAR_H - 2, 0xe1e1e1);
  417.         DrawBar(0, TOOLBAR_H - 2, Form.cwidth, 1, 0xcecece);
  418.         DrawBar(0, TOOLBAR_H - 1, Form.cwidth, 1, 0x7F7F7F);
  419.        
  420.         DrawToolbarButton(GO_BACK,         8);
  421.         DrawToolbarButton(GO_FORWARD,      33);
  422.         DrawToolbarButton(OPEN_FILE,       68);
  423.         DrawToolbarButton(MAGNIFY_PLUS,    Form.cwidth - 125);
  424.         DrawToolbarButton(MAGNIFY_MINUS,   Form.cwidth - 100);
  425.         DrawToolbarButton(CHANGE_ENCODING, Form.cwidth - 64);
  426.         DrawToolbarButton(SANDWICH,        Form.cwidth - 31);
  427.  
  428.         DrawAddressBox();
  429.  
  430.         if ((Form.cwidth-scroll.size_x-1 == list.w) &&
  431.                 (Form.cheight-TOOLBAR_H == list.h) &&
  432.                 (list.count)
  433.         )
  434.         {
  435.                 DrawPage();
  436.         }
  437.         else
  438.         {
  439.                 if (!label.raw) {                           //this code need to be run
  440.                         if (param) EventOpenAddress(#param);    //only once at browser sturtup
  441.                         else EventOpenAddress("aelia:home");
  442.                 }
  443.                 else PreparePage();
  444.         }
  445.  
  446.         DrawRectangle(scroll.start_x, scroll.start_y, scroll.size_x, scroll.size_y-1, scroll.bckg_col);
  447. }
  448.  
  449. void DrawPage()
  450. {
  451.         list.CheckDoesValuesOkey();
  452.         if (list.count) _PutImage(list.x,list.y,list.w,list.h,list.first*list.item_h*list.w*3 + label.raw);
  453.         DrawScroller();
  454. }
  455.  
  456. void DrawAddressBox()
  457. {
  458.         address_box.left = 97+19;
  459.         address_box.top = 11;
  460.         address_box.width = Form.cwidth - address_box.left - 138;
  461.         DrawRectangle(address_box.left-4-19, address_box.top-5, address_box.width+6+19, 23, 0x8C8C8C);
  462.         DrawWideRectangle(address_box.left-3-19, address_box.top-3, address_box.width+5+19, 21, 4, address_box.color);
  463.         address_box.size = address_box.pos = address_box.shift = address_box.shift_old = strlen(#address);
  464.         address_box.offset = 0;
  465.         edit_box_draw stdcall(#address_box);
  466.         favicon.draw(address_box.left-18, address_box.top-1);
  467.         DrawBar(address_box.left-2, address_box.top+1, 2, 13, 0xFFFfff);
  468. }