Subversion Repositories Kolibri OS

Rev

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