Subversion Repositories Kolibri OS

Rev

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

  1. #ifndef AUTOBUILD
  2.         #include "lang.h--"
  3. #endif
  4.  
  5. #define MEMSIZE 0x100000
  6. #include "..\lib\kolibri.h"
  7. #include "..\lib\strings.h"
  8. #include "..\lib\mem.h"
  9. #include "..\lib\file_system.h"
  10. #include "..\lib\dll.h"
  11. #include "..\lib\gui.h"
  12. #include "..\lib\list_box.h"
  13.  
  14. #include "..\lib\obj\box_lib.h"
  15. #include "..\lib\obj\proc_lib.h"
  16. #include "..\lib\obj\libio_lib.h"
  17.  
  18. #ifdef LANG_RUS
  19.         ?define T_FILE "” ©«"
  20.         ?define T_TYPE "’¨¯"
  21.         ?define T_SIZE " §¬¥à"
  22.         ?define MENU1 "” ©«"
  23.         ?define MENU1_SUBMENU1 "Žâªàëâì"
  24.         ?define MENU1_SUBMENU2 "‡ ªàëâì"
  25.         ?define MENU1_SUBMENU3 "‘¢®©á⢠"
  26.         ?define MENU1_SUBMENU4 "‚ë室"
  27. #else
  28.         ?define T_FILE "File"
  29.         ?define T_TYPE "Type"
  30.         ?define T_SIZE "Size"
  31.         ?define MENU1 "File"
  32.         ?define MENU1_SUBMENU1 "Open"
  33.         ?define MENU1_SUBMENU2 "Close"
  34.         ?define MENU1_SUBMENU3 "Properties"
  35.         ?define MENU1_SUBMENU4 "Exit"
  36. #endif
  37.  
  38. #ifdef LANG_RUS
  39. struct menu_text_struct
  40. {
  41.         char menu[5];
  42.         char sub_menu1[8];
  43.         char sub_menu2[8];
  44.         //char sub_menu3[9];
  45.         char sub_menu4[6];
  46.         byte end;
  47. };
  48. #else
  49. struct menu_text_struct
  50. {
  51.         char menu[5];
  52.         char sub_menu1[5];
  53.         char sub_menu2[6];
  54.         //char sub_menu3[11];
  55.         char sub_menu4[5];
  56.         byte end;
  57. };
  58. #endif
  59.  
  60. #define TOPPANELH 19
  61. #define BOTPANELH 10
  62. #define WIN_W 600
  63. #define WIN_H 400
  64.  
  65. #define TITLE "Calypte v0.13"
  66. char win_title[4096] = TITLE;
  67. proc_info Form;
  68.  
  69. dword old_width,old_height;
  70. llist tview;
  71.  
  72. byte active_properties = 0;
  73. dword properties_window;
  74.  
  75. #include "include\gui.h"
  76. #include "include\properties.h"
  77. // #include "include\top_menu.h"
  78. // #include "include\open_dial.h"
  79.  
  80. struct filter
  81. {
  82.         dword size;
  83.         char ext1[4];
  84.         //char ext2[4];
  85.         //char ext3[4];
  86.         //char ext4[4];
  87.         byte end;
  88. };
  89.  
  90. filter filter2;
  91. menu_text_struct menu_text_area1;
  92.  
  93. int read=0;
  94.  
  95.  
  96. proc_info pr_inf;
  97. char communication_area_name[] = "FFFFFFFF_open_dialog";
  98. byte plugin_path[4096];
  99. char default_dir[] = "/rd/1";
  100. char open_dialog_path[] = "/rd/1/File managers/opendial"; //opendial
  101. byte openfile_path[2048];
  102. byte filename_area[4096];
  103.  
  104. opendialog o_dialog = {0, #pr_inf, #communication_area_name, 0, #plugin_path, #default_dir, #open_dialog_path, #draw_window, 0, #openfile_path, #filename_area, #filter2, 420, 200, 320, 120};
  105.  
  106. dword bufpointer;
  107. dword bufsize;
  108. dword draw_sruct;
  109.  
  110. menu_data menudata1 = {0, 40, 2, 15, 2, #menu_text_area1.menu, #menu_text_area1.sub_menu1, #menu_text_area1.end, 0, 0, 80, 2, 100, 18, 0xEEEEEE, 0xFF, 0xEEEEEE, 0, 0, 0, #Form, 0, 0, 0, 16, 0, 0, 0x00CC00, 0, 0xFFFFFF, 0, 8, 0, 0};
  111.  
  112. void main()
  113. {  
  114.         int id;
  115.        
  116.         strcpy(#filter2.ext1, "TXT");
  117.         //strcpy(#filter2.ext2, "ASM");
  118.         //strcpy(#filter2.ext3, "INC\0");
  119.         //strcpy(#filter2.ext4, "\0");
  120.         filter2.size = 8;
  121.         filter2.end = 0;
  122.  
  123.         strcpy(#menu_text_area1.menu, MENU1);
  124.         strcpy(#menu_text_area1.sub_menu1, MENU1_SUBMENU1);
  125.         strcpy(#menu_text_area1.sub_menu2, MENU1_SUBMENU2);
  126.         //strcpy(#menu_text_area1.sub_menu3, MENU1_SUBMENU3);
  127.         strcpy(#menu_text_area1.sub_menu4, MENU1_SUBMENU4);
  128.         menu_text_area1.end = 0;
  129.        
  130.         load_dll(boxlib, #box_lib_init,0);
  131.         load_dll(libio, #libio_init,1);
  132.         load_dll(Proc_lib, #OpenDialog_init,0);
  133.         OpenDialog_init stdcall (#o_dialog);
  134.         SetEventMask(0x27);
  135.         loop()
  136.         {
  137.       switch(WaitEvent())
  138.       {
  139.                 case evMouse:
  140.                         mouse.get();
  141.                         if (tview.MouseScroll(mouse.vert)) DrawText();
  142.                
  143.                         menu_bar_mouse stdcall (#menudata1);                   
  144.                         if (menudata1.click)
  145.                         {
  146.                                 switch(menudata1.cursor_out)
  147.                                 {
  148.                                         case 1:
  149.                                                 OpenDialog_start stdcall (#o_dialog);
  150.                                                 OpenFile(#openfile_path);
  151.                                                 Prepare();
  152.                                                 draw_window();
  153.                                                 break;
  154.                                         case 2:
  155.                                                 read = 0;
  156.                                                 tview.current = 0;
  157.                                                 strcpy(#win_title, TITLE);
  158.                                                 FreeBuf();
  159.                                                 draw_window();
  160.                                                 break;
  161.                                         case 3:
  162.                                                 if (!active_properties)
  163.                                                 {
  164.                                                         SwitchToAnotherThread();
  165.                                                         properties_window = CreateThread(#properties_dialog, #properties_stak+4092);
  166.                                                         break;
  167.                                                 }
  168.                                                 else
  169.                                                 {
  170.                                                         ActivateWindow(GetProcessSlot(properties_window));
  171.                                                 }
  172.                                                 break;
  173.                                         case 4:
  174.                                                 ExitProcess();
  175.                                 }
  176.                         }
  177.                         break;
  178.                
  179.         case evButton:
  180.             id=GetButtonID();              
  181.             if (id==1) ExitProcess();
  182.                         break;
  183.      
  184.         case evKey:
  185.                         if (Form.status_window>2) break;
  186.                         GetKeys();
  187.                         if (tview.ProcessKey(key_scancode)) DrawText();
  188.                         if (TestBit(key_modifier, 2))
  189.                         {
  190.                                 switch(key_scancode)
  191.                                 {
  192.                                         case 024:  //Ctrl+O
  193.                                                 OpenDialog_start stdcall (#o_dialog);
  194.                                                 OpenFile(#openfile_path);
  195.                                                 Prepare();
  196.                                                 draw_window();
  197.                                                 break;
  198.                                 }
  199.                                 break;
  200.                         }
  201.                         switch (key_scancode)
  202.                         {
  203.                                 /*case SCAN_CODE_HOME:
  204.                                 case SCAN_CODE_END:
  205.                                 case SCAN_CODE_UP:
  206.                                 case SCAN_CODE_DOWN:
  207.                                         if (tview.ProcessKey(key_scancode)) DrawText();
  208.                                         break;*/
  209.                                 case SCAN_CODE_PGUP:
  210.                                         if (!tview.current) break;
  211.                                         if (tview.current<tview.visible) tview.current = 0;
  212.                                         else tview.current = tview.current-tview.visible;
  213.                                         DrawText();
  214.                                         break;
  215.                                 case SCAN_CODE_PGDN:
  216.                                         if (tview.current+tview.visible>tview.count) break;
  217.                                         tview.current = tview.current+tview.visible;
  218.                                         DrawText();
  219.                                         break;
  220.                         }
  221.                         break;
  222.          
  223.          case evReDraw:
  224.                         draw_window();
  225.                         break;
  226.       }
  227.    }
  228. }
  229.  
  230.  
  231. void draw_window()
  232. {
  233.         system.color.get();
  234.         DefineAndDrawWindow(GetScreenWidth()-WIN_W/2,GetScreenHeight()-WIN_H/2,WIN_W,WIN_H,0x73,0xFFFFFF,#win_title);
  235.         GetProcessInfo(#Form, SelfInfo);
  236.         if (Form.status_window>2) return;
  237.         tview.SetSizes(0, TOPPANELH, Form.cwidth, Form.cheight-BOTPANELH-TOPPANELH, 12);
  238.         DrawBar(0, 0, Form.cwidth, TOPPANELH, system.color.work);
  239.         DrawBar(0, Form.cheight-BOTPANELH, Form.cwidth, BOTPANELH, system.color.work);
  240.        
  241.         menudata1.bckg_col = system.color.work;
  242.         menu_bar_draw stdcall (#menudata1);
  243.        
  244.         if (old_width!=Form.width) || (old_height!=Form.height)
  245.         {
  246.                 old_width = Form.width;
  247.                 old_height = Form.height;
  248.                 if (read==1) Prepare();
  249.                 tview.debug_values();
  250.         }
  251.         if (read==1)
  252.         {
  253.                 DrawText();
  254.         }
  255.         else DrawBar(tview.x, tview.y, tview.w, tview.h, 0xFFFFFF);
  256. }
  257.  
  258. void OpenFile(dword path)
  259. {
  260.         strcpy(#win_title, TITLE);
  261.         strcat(#win_title, " - ");
  262.         strcat(#win_title, path);
  263.         file_size stdcall (path);
  264.         bufsize = EBX;
  265.         if (bufsize)
  266.         {
  267.                 mem_Free(bufpointer);
  268.                 bufpointer = mem_Alloc(bufsize);
  269.                 ReadFile(0, bufsize, bufpointer, path);
  270.                 read=1;
  271.         }
  272. }
  273.  
  274. void FreeBuf()
  275. {
  276.         int i;
  277.         for (i=0; i<tview.count; i++)
  278.         {
  279.                 mem_Free(DSDWORD[i*4+draw_sruct]);
  280.         }
  281.         mem_Free(draw_sruct);
  282.         mem_Free(bufpointer);
  283. }
  284.  
  285. void Prepare()
  286. {
  287.         int i, sub_pos;
  288.         static int cur_pos;
  289.         int len_str = 0;
  290.         byte do_eof = 0;
  291.         word bukva[2];
  292.         dword address;
  293.         tview.count = 0;
  294.         while(1)
  295.         {
  296.                 while(1)
  297.                 {
  298.                         bukva = DSBYTE[bufpointer+cur_pos+len_str];
  299.                         if (bukva=='\0')
  300.                         {
  301.                                 do_eof = 1;
  302.                                 break;
  303.                         }
  304.                         if (bukva==0x0a) break;
  305.                         else len_str++;
  306.                 }
  307.                 if (len_str<=tview.column_max)
  308.                 {
  309.                         cur_pos=cur_pos+len_str+1;
  310.                         tview.count++;
  311.                 }
  312.                 else
  313.                 {
  314.                         cur_pos=cur_pos+tview.column_max;
  315.                         tview.count++;
  316.                 }
  317.                 len_str = 0;
  318.                 if (do_eof) break;
  319.         }
  320.         mem_Free(draw_sruct);
  321.         draw_sruct = mem_Alloc(tview.count*4);
  322.         cur_pos=0;
  323.         sub_pos=0;
  324.         len_str = 0;
  325.         do_eof = 0;
  326.         while(1)
  327.         {
  328.                 while(1)
  329.                 {
  330.                         bukva = DSBYTE[bufpointer+cur_pos+len_str];
  331.                         if (bukva=='\0')
  332.                         {
  333.                                 do_eof = 1;
  334.                                 break;
  335.                         }
  336.                         if (bukva==0x0a) break;
  337.                         else len_str++;
  338.                 }
  339.                 if (len_str<=tview.column_max)
  340.                 {
  341.                         address = mem_Alloc(len_str+1);
  342.                         ESDWORD[sub_pos*4+draw_sruct] = address;
  343.                         strlcpy(DSDWORD[sub_pos*4+draw_sruct], bufpointer+cur_pos, len_str);
  344.                         cur_pos=cur_pos+len_str+1;
  345.                         sub_pos++;
  346.                 }
  347.                 else
  348.                 {
  349.                         address = mem_Alloc(len_str+1);
  350.                         ESDWORD[sub_pos*4+draw_sruct] = address;
  351.                         strlcpy(DSDWORD[sub_pos*4+draw_sruct], bufpointer+cur_pos, tview.column_max);
  352.                         cur_pos=cur_pos+tview.column_max;
  353.                         sub_pos++;
  354.                 }
  355.                 len_str = 0;
  356.                 if (cur_pos>=bufsize-1) break;
  357.         }
  358.         cur_pos=0;
  359. }
  360.  
  361. void DrawText()
  362. {
  363.         int i, top, num_line;
  364.         if (tview.count<tview.visible) top = tview.count;
  365.         else
  366.         {
  367.                 if (tview.count-tview.current<=tview.visible) top = tview.count-tview.current-1;
  368.                 else top = tview.visible;
  369.         }
  370.         DrawBar(tview.x, tview.y, tview.w, 3, 0xFFFFFF);
  371.         for (i=0, num_line = tview.current; i<top; i++, num_line++)
  372.         {
  373.                 DrawBar(tview.x, i * tview.line_h + tview.y + 3, tview.w, tview.line_h, 0xFFFFFF);
  374.                 WriteText(tview.x + 2, i * tview.line_h + tview.y + 3, 0x80, 0x000000, DSDWORD[num_line*4+draw_sruct]);
  375.         }
  376.         DrawBar(0, i * tview.line_h + tview.y + 3, tview.w, -i* tview.line_h + tview.h, 0xFFFFFF);
  377. }
  378.  
  379. stop:
  380. char properties_stak[4096];