Subversion Repositories Kolibri OS

Rev

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