Subversion Repositories Kolibri OS

Rev

Rev 7746 | 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\http.h"
  18. #include "..\lib\obj\iconv.h"
  19.  
  20. #include "..\lib\patterns\history.h"
  21. #include "..\lib\patterns\http_downloader.h"
  22.  
  23. _http http = {0, 0, 0, 0, 0, 0, 0};
  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. proc_info Form;
  34.  
  35.  
  36. dword TOOLBAR_H = 40;
  37. dword STATUSBAR_H = 0;
  38.  
  39. dword col_bg = 0xE3E2E2;
  40. dword panel_color  = 0xE3E2E2;
  41. dword border_color = 0x8C8C8C;
  42.  
  43. bool debug_mode = false;
  44.  
  45. bool open_in_a_new_window = false;
  46.  
  47. enum {
  48.         REFRESH_BUTTON,
  49.         EDIT_SOURCE,
  50. };
  51.  
  52. #include "..\TWB\TWB.c"
  53. #include "show_src.h"
  54.  
  55. char editURL[sizeof(URL)];
  56. int     mouse_twb;
  57. edit_box address_box = {250,60,30,0xffffff,0x94AECE,0xffffff,0xffffff,0x10000000,sizeof(URL),#editURL,#mouse_twb,2,19,19};
  58.  
  59. #define SKIN_Y 24
  60.  
  61. void main()
  62. {
  63.         int i;
  64.         int id;
  65.         load_dll(boxlib, #box_lib_init,0);
  66.         load_dll(libio, #libio_init,1);
  67.         load_dll(libimg, #libimg_init,1);
  68.         load_dll(iconv_lib, #iconv_open,0);
  69.         if (param) strcpy(#URL, #param); else strcpy(#URL, URL_SERVICE_HOME);
  70.         WB1.list.SetFont(8, 14, 10011000b);
  71.         WB1.list.no_selection = true;
  72.         SetEventMask(EVM_REDRAW + EVM_KEY + EVM_BUTTON + EVM_MOUSE + EVM_MOUSE_FILTER);
  73.         loop() switch(WaitEvent())
  74.         {
  75.                 case evMouse:
  76.                         edit_box_mouse stdcall (#address_box);
  77.                         mouse.get();
  78.                         if (WB1.list.MouseScroll(mouse.vert)) WB1.DrawPage();
  79.                         scrollbar_v_mouse (#scroll_wv);
  80.                         if (WB1.list.first != scroll_wv.position)
  81.                         {
  82.                                 WB1.list.first = scroll_wv.position;
  83.                                 WB1.DrawPage();
  84.                                 break;
  85.                         }
  86.                         break;
  87.  
  88.                 case evButton:
  89.                         id=GetButtonID();
  90.                         if (1==id) ExitProcess();
  91.                         break;
  92.  
  93.                 case evKey:
  94.                         GetKeys();
  95.  
  96.                         if (SCAN_CODE_F5 == key_scancode) {
  97.                                 OpenPage();
  98.                         }
  99.                         if (SCAN_CODE_F3 == key_scancode) {
  100.                                 RunProgram("/rd/1/tinypad", #URL);
  101.                         }
  102.  
  103.                         if (address_box.flags & 0b10)  
  104.                         {
  105.                                 if (key_ascii == ASCII_KEY_ENTER) EventGoToPage();
  106.                                 else {
  107.                                         EAX = key_editbox;
  108.                                         edit_box_key stdcall(#address_box);
  109.                                 }
  110.                         }
  111.                         else
  112.                         {
  113.                                 #define KEY_SCROLL_N 11
  114.                                 if (SCAN_CODE_UP   == key_scancode) for (i=0;i<KEY_SCROLL_N;i++) WB1.list.KeyUp();
  115.                                 if (SCAN_CODE_DOWN == key_scancode) for (i=0;i<KEY_SCROLL_N;i++) WB1.list.KeyDown();
  116.                                 if (WB1.list.ProcessKey(key_scancode)) WB1.DrawPage();
  117.                         }
  118.                         break;
  119.  
  120.                 case evReDraw:
  121.                         DefineAndDrawWindow(GetScreenWidth()-800/2-random(80),GetScreenHeight()-600/2-random(80),800,600,0x73,col_bg,0,0);
  122.                         GetProcessInfo(#Form, SelfInfo);
  123.                         if (Form.status_window>2) { DrawTitle(#header); break; }
  124.                         if (Form.height<120) { MoveSize(OLD,OLD,OLD,120); break; }
  125.                         if (Form.width<280) { MoveSize(OLD,OLD,280,OLD); break; }
  126.                         Draw_Window();
  127.                         break;
  128.         }
  129. }
  130.  
  131. void SetElementSizes()
  132. {
  133.         address_box.top = TOOLBAR_H/2-10;
  134.         basic_line_h = calc(WB1.list.font_h * 130) / 100;
  135.         address_box.left = address_box.top;
  136.         address_box.width = Form.cwidth - address_box.left - address_box.left -14;
  137.         WB1.list.SetSizes(0, TOOLBAR_H, Form.width - 10 - scroll_wv.size_x,
  138.                 Form.cheight - TOOLBAR_H - STATUSBAR_H, basic_line_h);
  139.         WB1.list.wheel_size = 7 * basic_line_h;
  140.         WB1.list.column_max = WB1.list.w - scroll_wv.size_x / WB1.list.font_w;
  141.         WB1.list.visible = WB1.list.h;
  142.         if (WB1.list.w!=WB1.DrawBuf.bufw) {
  143.                 WB1.DrawBuf.Init(WB1.list.x, WB1.list.y, WB1.list.w, 32700);
  144.                 OpenPage();
  145.         }
  146. }
  147.  
  148. void Draw_Window()
  149. {
  150.         DrawBar(0,0, Form.cwidth,TOOLBAR_H-2, panel_color);
  151.         DrawBar(0,TOOLBAR_H-2, Form.cwidth,1, 0xD7D0D3);
  152.         DrawBar(0,TOOLBAR_H-1, Form.cwidth,1, border_color);
  153.         SetElementSizes();
  154.         DrawRectangle(address_box.left-3, address_box.top-3, address_box.width+4, 25,border_color);
  155.         DrawBar(0,Form.cheight - STATUSBAR_H, Form.cwidth,STATUSBAR_H, col_bg);
  156.         DrawBar(0,Form.cheight - STATUSBAR_H, Form.cwidth,1, border_color);
  157.         DrawEditBoxWebView();
  158.         if (!header)
  159.                 OpenPage();
  160.         else {
  161.                 WB1.DrawPage();
  162.                 DrawEditBoxWebView();
  163.         }
  164.         DrawRectangle(scroll_wv.start_x, scroll_wv.start_y, scroll_wv.size_x, scroll_wv.size_y-1, scroll_wv.bckg_col);
  165. }
  166.  
  167. void EventGoToPage()
  168. {
  169.         if (!editURL[0]) {
  170.                 strcpy(#URL, URL_SERVICE_HOME);
  171.         }
  172.         else
  173.         {
  174.                 strcpy(#URL, #editURL);
  175.         }
  176.         OpenPage();
  177. }
  178.  
  179.  
  180. void SetPageDefaults()
  181. {
  182.         strcpy(#header, #version);
  183.         WB1.list.count = WB1.list.first = 0;
  184.         cur_encoding = CH_NULL;
  185.         if (o_bufpointer) o_bufpointer = free(o_bufpointer);
  186. }
  187.  
  188. void OpenPage()
  189. {
  190.         char getUrl[sizeof(URL)];
  191.         strcpy(#editURL, #URL);
  192.         history.add(#URL);
  193.         if (!strncmp(#URL,"CodeView:",8))
  194.         {
  195.                 SetPageDefaults();
  196.                 if (!strcmp(#URL, URL_SERVICE_HOME)) LoadInternalPage(#homepage, sizeof(homepage));
  197.                 DrawEditBoxWebView();
  198.                 return;
  199.         }
  200.         else
  201.         {
  202.                 file_size stdcall (#URL);
  203.                 bufsize = EBX;
  204.                 if (bufsize)
  205.                 {
  206.                         free(bufpointer);
  207.                         bufpointer = malloc(bufsize);
  208.                         SetPageDefaults();
  209.                         ReadFile(0, bufsize, bufpointer, #URL);
  210.                         ShowCodeSource();
  211.                         LoadInternalPage(bufpointer, bufsize); 
  212.                 }
  213.                 ShowPage();
  214.         }
  215. }
  216.  
  217. DrawEditBoxWebView()
  218. {
  219.         int skin_x_offset;
  220.         DrawBar(address_box.left-2, address_box.top-2, address_box.width+3, 2, address_box.color);
  221.         DrawBar(address_box.left-2, address_box.top, 2, 22, address_box.color);
  222.         address_box.size = address_box.pos = address_box.shift = address_box.shift_old = strlen(#editURL);
  223.         address_box.offset = 0;
  224.         edit_box_draw stdcall(#address_box);
  225.         skin_x_offset = 51;
  226.         img_draw stdcall(skin.image, address_box.left+address_box.width+1, address_box.top-3, 17, skin.h, skin_x_offset, SKIN_Y);
  227. }
  228.  
  229. void LoadInternalPage(dword bufpos, in_filesize){
  230.         bufsize = in_filesize;
  231.         bufpointer = bufpos;
  232.         ShowPage();
  233. }
  234.  
  235. void ShowPage()
  236. {
  237.         DrawEditBoxWebView();
  238.         if (!bufsize) LoadInternalPage(#page_not_found, sizeof(page_not_found));
  239.         WB1.Prepare();
  240. }
  241.  
  242. void DrawStatusBar() {return;};
  243. void EventClickLink() {return;};
  244. void EventShowLinkMenu() {return;};
  245.  
  246. char anchor[256];
  247.  
  248. stop: