Subversion Repositories Kolibri OS

Rev

Rev 6050 | 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\iconv.h"
  13. #include "..\lib\obj\box_lib.h"
  14. #include "..\lib\obj\proc_lib.h"
  15. #include "..\lib\obj\libio_lib.h"
  16. //#include "..\lib\obj\wword.h"
  17.  
  18. #ifdef LANG_RUS
  19.         ?define T_FILE "” ©«"
  20.         ?define T_TYPE "’¨¯"
  21.         ?define T_SIZE " §¬¥à"
  22.  
  23.         ?define MENU1 "” ©«"
  24.         ?define MENU1_SUBMENU1 "Žâªàëâì"
  25.         ?define MENU1_SUBMENU2 "‡ ªàëâì"
  26.         ?define MENU1_SUBMENU3 "‘¢®©á⢠"
  27.         ?define MENU1_SUBMENU4 "‚ë室"
  28.  
  29.         ?define MENU2 "Š®¤¨à®¢ª "
  30.         ?define MENU2_SUBMENU1 "UTF-8"
  31.         ?define MENU2_SUBMENU2 "KOI8-RU"
  32.         ?define MENU2_SUBMENU3 "CP1251"
  33.         ?define MENU2_SUBMENU4 "CP1252"
  34.         ?define MENU2_SUBMENU5 "ISO8859-5"
  35.         ?define MENU2_SUBMENU6 "CP866"
  36.  
  37.         ?define ERROR_LOAD_BOX_LIB "Žè¨¡ª  ¯à¨ § £à㧪¥ ¡¨¡«¨®â¥ª¨ - box_lib.obj"
  38.         ?define ERROR_LOAD_LIBIO "Žè¨¡ª  ¯à¨ § £à㧪¥ ¡¨¡«¨®â¥ª¨ - libio.obj"
  39.         ?define ERROR_LOAD_PROC_LIB "Žè¨¡ª  ¯à¨ § £à㧪¥ ¡¨¡«¨®â¥ª¨ - proc_lib.obj"
  40. #else
  41.         ?define T_FILE "File"
  42.         ?define T_TYPE "Type"
  43.         ?define T_SIZE "Size"
  44.         ?define MENU1 "File"
  45.  
  46.         ?define MENU1_SUBMENU1 "Open"
  47.         ?define MENU1_SUBMENU2 "Close"
  48.         ?define MENU1_SUBMENU3 "Properties"
  49.         ?define MENU1_SUBMENU4 "Exit"
  50.  
  51.         ?define MENU2 "Encoding"
  52.         ?define MENU2_SUBMENU1 "UTF-8"
  53.         ?define MENU2_SUBMENU2 "KOI8-RU"
  54.         ?define MENU2_SUBMENU3 "CP1251"
  55.         ?define MENU2_SUBMENU4 "CP1252"
  56.         ?define MENU2_SUBMENU5 "ISO8859-5"
  57.         ?define MENU2_SUBMENU6 "CP866"
  58.  
  59.         ?define ERROR_LOAD_BOX_LIB "Error while loading library - box_lib.obj"
  60.         ?define ERROR_LOAD_LIBIO "Error while loading library - libio.obj"
  61.         ?define ERROR_LOAD_PROC_LIB "Error while loading library - proc_lib.obj"
  62. #endif
  63.  
  64. #ifdef LANG_RUS
  65. struct menu1_text_struct
  66. {
  67.         char menu[5];
  68.         char sub_menu1[8];
  69.         char sub_menu2[8];
  70.         //char sub_menu3[9];
  71.         char sub_menu4[6];
  72.         byte end;
  73. };
  74. struct menu2_text_struct
  75. {
  76.         char menu[10];
  77.         char sub_menu1[6];
  78.         char sub_menu2[8];
  79.         char sub_menu3[7];
  80.         char sub_menu4[7];
  81.         char sub_menu5[10];
  82.         char sub_menu6[6];
  83.         byte end;
  84. };
  85. #else
  86. struct menu1_text_struct
  87. {
  88.         char menu[5];
  89.         char sub_menu1[5];
  90.         char sub_menu2[6];
  91.         //char sub_menu3[11];
  92.         char sub_menu4[5];
  93.         byte end;
  94. };
  95. struct menu2_text_struct
  96. {
  97.         char menu[9];
  98.         char sub_menu1[6];
  99.         char sub_menu2[8];
  100.         char sub_menu3[7];
  101.         char sub_menu4[7];
  102.         char sub_menu5[10];
  103.         char sub_menu6[6];
  104.         byte end;
  105. };
  106. #endif
  107.  
  108. #define TITLE "Calypte v0.15"
  109.  
  110. #define TOPPANELH 19
  111. #define BOTPANELH 10
  112. #define WIN_W 600
  113. #define WIN_H 400
  114.  
  115. proc_info Form;
  116.  
  117. byte active_properties = 0;
  118. int encoding;
  119. dword properties_window;
  120.  
  121. #include "include\properties.h"
  122.  
  123. struct filter
  124. {
  125.         dword size;
  126.         char ext1[4];
  127.         //char ext2[4];
  128.         //char ext3[4];
  129.         //char ext4[4];
  130.         byte end;
  131. };
  132.  
  133. filter filter2;
  134. menu1_text_struct menu1_text_area1;
  135. menu2_text_struct menu2_text_area2;
  136.  
  137. char win_title[4096] = "Calypte v0.15";
  138.  
  139. int
  140.         cur_row=0,
  141.         read=0,
  142.         pos=0,
  143.         row_num=0,
  144.         col_count=0,
  145.         row_count=0;   
  146.        
  147. dword old_width,old_height;
  148.  
  149. proc_info pr_inf;
  150. char communication_area_name[] = "FFFFFFFF_open_dialog";
  151. byte plugin_path[4096];
  152. char default_dir[] = "/rd/1";
  153. char open_dialog_path[] = "/rd/1/File managers/opendial"; //opendial
  154. byte openfile_path[2048];
  155. byte filename_area[4096];
  156.  
  157. 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};
  158.  
  159. dword bufpointer;
  160. dword bufsize;
  161. dword draw_sruct;
  162.  
  163. menu_data menudata1 = {0, 40, 2, 15, 2, #menu1_text_area1.menu, #menu1_text_area1.sub_menu1, #menu1_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};
  164. menu_data menudata2 = {0, 70, 44, 15, 2, #menu2_text_area2.menu, #menu2_text_area2.sub_menu1, #menu2_text_area2.end, 0, 0, 80, 44, 100, 18, 0xEEEEEE, 0xFF, 0xEEEEEE, 0, 0, 0, #Form, 0, 0, 0, 16, 0, 0, 0x00CC00, 0, 0xFFFFFF, 0, 8, 0, 0};
  165.  
  166. void main()
  167. {  
  168.         int id;
  169.        
  170.         strcpy(#filter2.ext1, "TXT");
  171.         //strcpy(#filter2.ext2, "ASM");
  172.         //strcpy(#filter2.ext3, "INC\0");
  173.         //strcpy(#filter2.ext4, "\0");
  174.         filter2.size = 8;
  175.         filter2.end = 0;
  176.  
  177.         strcpy(#menu1_text_area1.menu, MENU1);
  178.         strcpy(#menu1_text_area1.sub_menu1, MENU1_SUBMENU1);
  179.         strcpy(#menu1_text_area1.sub_menu2, MENU1_SUBMENU2);
  180.         //strcpy(#menu1_text_area1.sub_menu3, MENU1_SUBMENU3);
  181.         strcpy(#menu1_text_area1.sub_menu4, MENU1_SUBMENU4);
  182.         menu1_text_area1.end = 0;
  183.        
  184.         strcpy(#menu2_text_area2.menu, MENU2);
  185.         strcpy(#menu2_text_area2.sub_menu1, MENU2_SUBMENU1);
  186.         strcpy(#menu2_text_area2.sub_menu2, MENU2_SUBMENU2);
  187.         strcpy(#menu2_text_area2.sub_menu3, MENU2_SUBMENU3);
  188.         strcpy(#menu2_text_area2.sub_menu4, MENU2_SUBMENU4);
  189.         strcpy(#menu2_text_area2.sub_menu5, MENU2_SUBMENU5);
  190.         strcpy(#menu2_text_area2.sub_menu6, MENU2_SUBMENU6);
  191.         menu2_text_area2.end = 0;
  192.        
  193.         //mem_Init();
  194.         load_dll(boxlib, #box_lib_init,0);
  195.         load_dll(libio, #libio_init,1);
  196.         load_dll(iconv_lib, #iconv_open,0);
  197.         load_dll(Proc_lib, #OpenDialog_init,0);
  198.         OpenDialog_init stdcall (#o_dialog);
  199.        
  200.         SetEventMask(0x27);
  201.         loop()
  202.         {
  203.       switch(WaitEvent())
  204.       {
  205.                 case evMouse:
  206.                         menu_bar_mouse stdcall (#menudata1);
  207.                         menu_bar_mouse stdcall (#menudata2);
  208.                         if (menudata1.click==1)
  209.                         {
  210.                                 switch(menudata1.cursor_out)
  211.                                 {
  212.                                         case 1:
  213.                                                 OpenDialog_start stdcall (#o_dialog);
  214.                                                 OpenFile(#openfile_path);
  215.                                                 Prepare();
  216.                                                 draw_window();
  217.                                                 break;
  218.                                         case 2:
  219.                                                 read = 0;
  220.                                                 strcpy(#win_title, TITLE);
  221.                                                 FreeBuf();
  222.                                                 draw_window();
  223.                                                 break;
  224.                                         case 3:
  225.                                                 if (!active_properties)
  226.                                                 {
  227.                                                         SwitchToAnotherThread();
  228.                                                         properties_window = CreateThread(#properties_dialog, #properties_stak+4092);
  229.                                                         break;
  230.                                                 }
  231.                                                 else
  232.                                                 {
  233.                                                         ActivateWindow(GetProcessSlot(properties_window));
  234.                                                 }
  235.                                                 break;
  236.                                         case 4:
  237.                                                 ExitProcess();
  238.                                 }
  239.                         }
  240.                         if (menudata2.click==1)
  241.                         {
  242.                                 encoding = menudata2.cursor_out - 1;
  243.                                 OpenFile(#openfile_path);
  244.                                 Prepare();
  245.                                 draw_window();
  246.                         }
  247.                         break;
  248.                
  249.         case evButton:
  250.                         id=GetButtonID();              
  251.             if (id==1) || (id==10) ExitProcess();
  252.                         break;
  253.                
  254.         case evKey:
  255.             GetKeys();
  256.                         if (TestBit(key_modifier, 2))
  257.                         {
  258.                                 switch(key_scancode)
  259.                                 {
  260.                                         case 024:  //Ctrl+O
  261.                                                 OpenDialog_start stdcall (#o_dialog);
  262.                                                 OpenFile(#openfile_path);
  263.                                                 Prepare();
  264.                                                 draw_window();
  265.                                                 break;
  266.                                 }
  267.                                 break;
  268.                         }
  269.                         switch (key_scancode)
  270.                         {
  271.                                 if (Form.status_window>2) break;
  272.                                 case SCAN_CODE_HOME:
  273.                                         cur_row = 0;
  274.                                         DrawText();
  275.                                         break;
  276.                                 case SCAN_CODE_END:
  277.                                         cur_row = row_num - row_count - 1;
  278.                                         DrawText();
  279.                                         break;
  280.                                 case SCAN_CODE_UP:
  281.                                         if (!cur_row) break;
  282.                                         else cur_row = cur_row-1;
  283.                                         DrawText();
  284.                                         break;
  285.                                 case SCAN_CODE_DOWN:
  286.                                         if (cur_row+row_count>=row_num) break;
  287.                                         cur_row = cur_row+1;
  288.                                         DrawText();
  289.                                         break;
  290.                                 case SCAN_CODE_PGUP:
  291.                                         if (!cur_row) break;
  292.                                         if (cur_row<row_count) cur_row = 0;
  293.                                         else cur_row = cur_row-row_count;
  294.                                         DrawText();
  295.                                         break;
  296.                                 case SCAN_CODE_PGDN:
  297.                                         if (cur_row+row_count>row_num) break;
  298.                                         cur_row = cur_row+row_count;
  299.                                         DrawText();
  300.                                         break;
  301.                         }
  302.                         break;
  303.          
  304.          case evReDraw:
  305.                         draw_window();
  306.                         break;
  307.       }
  308.    }
  309. }
  310.  
  311.  
  312. void draw_window()
  313. {
  314.         system.color.get();
  315.         DefineAndDrawWindow(GetScreenWidth()-WIN_W/2,GetScreenHeight()-WIN_H/2,WIN_W,WIN_H,0x73,0xFFFFFF,#win_title,0);
  316.         GetProcessInfo(#Form, SelfInfo);
  317.         DrawBar(0, 0, Form.cwidth, TOPPANELH, system.color.work);
  318.         DrawBar(0, Form.cheight-BOTPANELH, Form.cwidth, BOTPANELH, system.color.work);
  319.        
  320.         menudata1.bckg_col = system.color.work;
  321.         menudata2.bckg_col = system.color.work;
  322.         menu_bar_draw stdcall (#menudata1);
  323.         menu_bar_draw stdcall (#menudata2);
  324.        
  325.         if (old_width!=Form.width) || (old_height!=Form.height)
  326.         {
  327.                 old_width = Form.width;
  328.                 old_height = Form.height;
  329.                
  330.                 col_count = Form.cwidth/6;
  331.                 row_count = Form.cheight-BOTPANELH-TOPPANELH-2;
  332.                 row_count = row_count/10;
  333.        
  334.                 if (read==1) Prepare();
  335.         }
  336.         if (read==1)
  337.         {
  338.                 DrawText();
  339.         }
  340.         else DrawBar(0, TOPPANELH, Form.cwidth, Form.cheight-BOTPANELH-TOPPANELH, 0xFFFFFF);
  341. }
  342.  
  343. void OpenFile(dword path)
  344. {
  345.         strcpy(#win_title, TITLE);
  346.         strcat(#win_title, " - ");
  347.         strcat(#win_title, path);
  348.         file_size stdcall (path);
  349.         bufsize = EBX;
  350.         if (bufsize)
  351.         {
  352.                 mem_Free(bufpointer);
  353.                 bufpointer = mem_Alloc(bufsize);
  354.                 ReadFile(0, bufsize, bufpointer, path);
  355.                 read=1;
  356.         }
  357.         if (encoding!=CH_CP866) ChangeCharset(charsets[encoding], "CP866", bufpointer);
  358. }
  359.  
  360. void FreeBuf()
  361. {
  362.         int i;
  363.         for (i=0; i<row_num; i++)
  364.         {
  365.                 mem_Free(DSDWORD[i*4+draw_sruct]);
  366.         }
  367.         mem_Free(draw_sruct);
  368.         mem_Free(bufpointer);
  369. }
  370.  
  371. void Prepare()
  372. {
  373.         int i, sub_pos;
  374.         int len_str = 0;
  375.         byte do_eof = 0;
  376.         word bukva[2];
  377.         dword address;
  378.         row_num = 0;
  379.         while(1)
  380.         {
  381.                 while(1)
  382.                 {
  383.                         bukva = DSBYTE[bufpointer+pos+len_str];
  384.                         if (bukva=='\0')
  385.                         {
  386.                                 do_eof = 1;
  387.                                 break;
  388.                         }
  389.                         if (bukva==0x0a) break;
  390.                         else len_str++;
  391.                 }
  392.                 if (len_str<=col_count)
  393.                 {
  394.                         pos=pos+len_str+1;
  395.                         row_num++;
  396.                 }
  397.                 else
  398.                 {
  399.                         pos=pos+col_count;
  400.                         row_num++;
  401.                 }
  402.                 len_str = 0;
  403.                 if (do_eof) break;
  404.         }
  405.         mem_Free(draw_sruct);
  406.         draw_sruct = mem_Alloc(row_num*4);
  407.         pos=0;
  408.         sub_pos=0;
  409.         len_str = 0;
  410.         do_eof = 0;
  411.         while(1)
  412.         {
  413.                 while(1)
  414.                 {
  415.                         bukva = DSBYTE[bufpointer+pos+len_str];
  416.                         if (bukva=='\0')
  417.                         {
  418.                                 do_eof = 1;
  419.                                 break;
  420.                         }
  421.                         if (bukva==0x0a) break;
  422.                         else len_str++;
  423.                 }
  424.                 if (len_str<=col_count)
  425.                 {
  426.                         address = mem_Alloc(len_str+1);
  427.                         ESDWORD[sub_pos*4+draw_sruct] = address;
  428.                         strlcpy(DSDWORD[sub_pos*4+draw_sruct], bufpointer+pos, len_str);
  429.                         pos=pos+len_str+1;
  430.                         sub_pos++;
  431.                 }
  432.                 else
  433.                 {
  434.                         address = mem_Alloc(len_str+1);
  435.                         ESDWORD[sub_pos*4+draw_sruct] = address;
  436.                         strlcpy(DSDWORD[sub_pos*4+draw_sruct], bufpointer+pos, col_count);
  437.                         pos=pos+col_count;
  438.                         sub_pos++;
  439.                 }
  440.                 len_str = 0;
  441.                 if (pos>=bufsize-1) break;
  442.         }
  443.         pos=0;
  444. }
  445.  
  446. void DrawText()
  447. {
  448.         int i, top, num_line;
  449.         if (row_num<row_count) top = row_num;
  450.         else
  451.         {
  452.                 if (row_num-cur_row<=row_count) top = row_num-cur_row-1;
  453.                 else top = row_count;
  454.         }
  455.         DrawBar(0, TOPPANELH, Form.cwidth, 3, 0xFFFFFF);
  456.         for (i=0, num_line = cur_row; i<top; i++, num_line++)
  457.         {
  458.                 DrawBar(0, i*10+TOPPANELH+3, Form.cwidth, 10, 0xFFFFFF);
  459.                 WriteText(2, i*10+TOPPANELH+3, 0x80, 0x000000, DSDWORD[num_line*4+draw_sruct]);
  460.         }
  461.         DrawBar(0, i*10+TOPPANELH+3, Form.cwidth, -i*10-TOPPANELH-BOTPANELH+Form.cheight, 0xFFFFFF);
  462. }
  463.  
  464. stop:
  465. char properties_stak[4096];