Subversion Repositories Kolibri OS

Rev

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

  1.  
  2. #define MEMSIZE 4096 * 200
  3. #define NO_IMG true
  4.  
  5. //libraries
  6. #include "..\lib\gui.h"
  7. #include "..\lib\draw_buf.h"
  8. #include "..\lib\list_box.h"
  9. #include "..\lib\cursor.h"
  10. #include "..\lib\collection.h"
  11. #include "..\lib\random.h"
  12. #include "..\lib\clipboard.h"
  13.  
  14. // *.obj libraries
  15. #include "..\lib\obj\box_lib.h"
  16. #include "..\lib\obj\libio.h"
  17. #include "..\lib\obj\libimg.h"
  18. #include "..\lib\obj\iconv.h"
  19. #include "..\lib\obj\proc_lib.h"
  20.  
  21. //useful patterns
  22. #include "..\lib\patterns\simple_open_dialog.h"
  23. #include "..\lib\patterns\toolbar_button.h"
  24.  
  25. char homepage[] = FROM "html\\homepage.htm""\0";
  26. char page_not_found[] = FROM "html\\page_not_found_en.htm""\0";
  27.  
  28. char version[]="C-- Code View";
  29. char accept_language[]= "Accept-Language: en\n";
  30.  
  31. #define URL_SERVICE_HOME "CodeView:home"
  32.  
  33.  
  34.  
  35. proc_info Form;
  36.  
  37.  
  38. dword TOOLBAR_H = 40;
  39. dword STATUSBAR_H = 0;
  40.  
  41.  
  42. bool debug_mode = false;
  43.  
  44. bool open_in_a_new_window = false;
  45.  
  46. enum {
  47.         REFRESH_BUTTON,
  48.         EDIT_SOURCE,
  49.         OPEN_PAGE,
  50. };
  51.  
  52. #define URL_SIZE 4000;
  53. #include "..\TWB\TWB.c"
  54. TWebBrowser WB1;
  55. #include "highlight_c.h"
  56.  
  57. char default_dir[] = "/rd/1";
  58. od_filter filter2 = { 16, "C\0H\0C--\0H--\0CPP\0\0" };
  59.  
  60. char current_path[URL_SIZE+1];
  61. char edit_path[URL_SIZE+1];
  62. int     mouse_twb;
  63. edit_box address_box = {250,60,30,0xffffff,0x94AECE,0xffffff,0xffffff,0x10000000,URL_SIZE-2,#edit_path,#mouse_twb,2,19,19};
  64.  
  65. #define SKIN_Y 24
  66.  
  67. void LoadLibraries()
  68. {
  69.         load_dll(boxlib, #box_lib_init,0);
  70.         load_dll(libio, #libio_init,1);
  71.         load_dll(libimg, #libimg_init,1);
  72.         load_dll(iconv_lib, #iconv_open,0);
  73.         load_dll(Proc_lib,  #OpenDialog_init,0);
  74.         OpenDialog_init stdcall (#o_dialog);
  75. }
  76.  
  77. void main()
  78. {
  79.         int i, id;
  80.         LoadLibraries();
  81.         if (param) strcpy(#current_path, #param); else strcpy(#current_path, URL_SERVICE_HOME);
  82.         WB1.list.SetFont(8, 14, 10011000b);
  83.         WB1.list.no_selection = true;
  84.         SetEventMask(EVM_REDRAW + EVM_KEY + EVM_BUTTON + EVM_MOUSE + EVM_MOUSE_FILTER);
  85.         loop() switch(WaitEvent())
  86.         {
  87.                 case evMouse:
  88.                         edit_box_mouse stdcall (#address_box);
  89.                         mouse.get();
  90.                         if (WB1.list.MouseScroll(mouse.vert)) WB1.DrawPage();
  91.                         scrollbar_v_mouse (#scroll_wv);
  92.                         if (WB1.list.first != scroll_wv.position)
  93.                         {
  94.                                 WB1.list.first = scroll_wv.position;
  95.                                 WB1.DrawPage();
  96.                                 break;
  97.                         }
  98.                         break;
  99.  
  100.                 case evButton:
  101.                         id = GetButtonID();
  102.                         if (1==id) ExitProcess();
  103.                         if (OPEN_PAGE==id) EventOpenDialog();
  104.                         break;
  105.  
  106.                 case evKey:
  107.                         GetKeys();
  108.  
  109.                         if (SCAN_CODE_F5 == key_scancode) {
  110.                                 OpenPage(#current_path);
  111.                         }
  112.                         if (SCAN_CODE_F3 == key_scancode) {
  113.                                 RunProgram("/rd/1/tinypad", #current_path);
  114.                         }
  115.  
  116.                         if (key_modifier&KEY_LCTRL) || (key_modifier&KEY_RCTRL) {
  117.                                 if (key_scancode == SCAN_CODE_KEY_O) {EventOpenDialog();break;}
  118.                         }
  119.  
  120.                         if (address_box.flags & 0b10)  
  121.                         {
  122.                                 if (key_ascii == ASCII_KEY_ENTER) {
  123.                                         OpenPage(#edit_path);
  124.                                 }
  125.                                 else {
  126.                                         EAX = key_editbox;
  127.                                         edit_box_key stdcall(#address_box);
  128.                                 }
  129.                         }
  130.                         else
  131.                         {
  132.                                 #define KEY_SCROLL_N 11
  133.                                 if (SCAN_CODE_UP   == key_scancode) for (i=0;i<KEY_SCROLL_N;i++) WB1.list.KeyUp();
  134.                                 if (SCAN_CODE_DOWN == key_scancode) for (i=0;i<KEY_SCROLL_N;i++) WB1.list.KeyDown();
  135.                                 if (WB1.list.ProcessKey(key_scancode)) WB1.DrawPage();
  136.                         }
  137.                         break;
  138.  
  139.                 case evReDraw:
  140.                         DefineAndDrawWindow(GetScreenWidth()-800/2-random(80),GetScreenHeight()-600/2-random(80),800,600,0x73,sc.work,0,0);
  141.                         GetProcessInfo(#Form, SelfInfo);
  142.                         sc.get();
  143.                         if (Form.status_window>2) break;
  144.                         if (Form.height<120) { MoveSize(OLD,OLD,OLD,120); break; }
  145.                         if (Form.width<280) { MoveSize(OLD,OLD,280,OLD); break; }
  146.                         SetElementSizes();
  147.                         draw_window();
  148.                         break;
  149.         }
  150. }
  151.  
  152. void SetElementSizes()
  153. {
  154.         address_box.top = TOOLBAR_H/2-10;
  155.         address_box.left = address_box.top+43;
  156.         address_box.width = Form.cwidth - address_box.left - address_box.left -14;
  157.         WB1.list.SetSizes(0, TOOLBAR_H, Form.width - 10 - scroll_wv.size_x,
  158.                 Form.cheight - TOOLBAR_H - STATUSBAR_H, BASIC_LINE_H);
  159.         WB1.list.wheel_size = 7 * BASIC_LINE_H;
  160.         WB1.list.column_max = WB1.list.w - scroll_wv.size_x / WB1.list.font_w;
  161.         WB1.list.visible = WB1.list.h;
  162.         if (WB1.list.w!=DrawBuf.bufw) {
  163.                 DrawBuf.Init(WB1.list.x, WB1.list.y, WB1.list.w, 32700);
  164.                 OpenPage(#current_path);
  165.         }
  166. }
  167.  
  168. void draw_window()
  169. {
  170.         DrawBar(0,0, Form.cwidth,TOOLBAR_H-2, sc.work);
  171.         DrawBar(0,TOOLBAR_H-2, Form.cwidth,1, 0xD7D0D3);
  172.         DrawBar(0,TOOLBAR_H-1, Form.cwidth,1, sc.work_graph);
  173.         DrawRectangle(address_box.left-3, address_box.top-3, address_box.width+4, 25,sc.work_graph);
  174.         DrawBar(0,Form.cheight - STATUSBAR_H, Form.cwidth,STATUSBAR_H, sc.work);
  175.         DrawBar(0,Form.cheight - STATUSBAR_H, Form.cwidth,1, sc.work_graph);
  176.         DrawEditBoxWebView();
  177.         if (!WB1.header) {
  178.                 OpenPage(#current_path);
  179.         } else {
  180.                 WB1.DrawPage();
  181.                 DrawEditBoxWebView();
  182.         }
  183.         DrawRectangle(scroll_wv.start_x, scroll_wv.start_y, scroll_wv.size_x, scroll_wv.size_y-1, scroll_wv.bckg_col);
  184.         DrawTopPanelButton(OPEN_PAGE, 10, address_box.top-3, 0, false);
  185. }
  186.  
  187.  
  188. void OpenPage(dword _path)
  189. {
  190.         dword buf, size;
  191.         strcpy(#current_path, _path);
  192.         if (streq(_path, URL_SERVICE_HOME)) {
  193.                 LoadInternalPage(#homepage, sizeof(homepage));
  194.                 return;
  195.         }
  196.         file_size stdcall (_path);
  197.         if (EBX)
  198.         {
  199.                 size = EBX;
  200.                 buf = malloc(size);
  201.                 ReadFile(0, size, buf, _path);
  202.                 ShowCodeSource();
  203.                 free(buf);
  204.                 return;
  205.         }
  206.         LoadInternalPage(NULL,NULL);
  207. }
  208.  
  209. DrawEditBoxWebView()
  210. {
  211.         int skin_x_offset;
  212.         DrawBar(address_box.left-2, address_box.top-2, address_box.width+3, 2, address_box.color);
  213.         DrawBar(address_box.left-2, address_box.top, 2, 22, address_box.color);
  214.         address_box.size = address_box.pos = address_box.shift = address_box.shift_old = strlen(#edit_path);
  215.         address_box.offset = 0;
  216.         edit_box_draw stdcall(#address_box);
  217.         skin_x_offset = 51;
  218. }
  219.  
  220. void LoadInternalPage(dword _bufpos, _bufsize)
  221. {
  222.         if (!_bufpos) || (!_bufsize) {
  223.                 LoadInternalPage(#page_not_found, sizeof(page_not_found));
  224.                 return;
  225.         }
  226.         strcpy(#edit_path, #current_path);
  227.         DrawEditBoxWebView();
  228.  
  229.         WB1.list.first = 0;
  230.         WB1.ParseHtml(_bufpos, _bufsize);
  231.         WB1.DrawPage();
  232. }
  233.  
  234. void EventOpenDialog()
  235. {
  236.         OpenDialog_start stdcall (#o_dialog);
  237.         if (o_dialog.status) {
  238.                 OpenPage(#openfile_path);
  239.         }
  240. }
  241.  
  242.  
  243. void DrawStatusBar() {return;};
  244. void EventClickLink() {return;};
  245. void EventShowLinkMenu() {return;};
  246.  
  247. char anchor[256];
  248.  
  249. stop: