Subversion Repositories Kolibri OS

Rev

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

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