Subversion Repositories Kolibri OS

Rev

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

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