Subversion Repositories Kolibri OS

Rev

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