Subversion Repositories Kolibri OS

Rev

Rev 5825 | 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\gui.h"
  122. #include "include\properties.h"
  123.  
  124. struct filter
  125. {
  126.         dword size;
  127.         char ext1[4];
  128.         //char ext2[4];
  129.         //char ext3[4];
  130.         //char ext4[4];
  131.         byte end;
  132. };
  133.  
  134. filter filter2;
  135. menu1_text_struct menu1_text_area1;
  136. menu2_text_struct menu2_text_area2;
  137.  
  138. char win_title[4096] = "Calypte v0.15";
  139.  
  140. int
  141.         cur_row=0,
  142.         read=0,
  143.         pos=0,
  144.         row_num=0,
  145.         col_count=0,
  146.         row_count=0;   
  147.        
  148. dword old_width,old_height;
  149.  
  150. proc_info pr_inf;
  151. char communication_area_name[] = "FFFFFFFF_open_dialog";
  152. byte plugin_path[4096];
  153. char default_dir[] = "/rd/1";
  154. char open_dialog_path[] = "/rd/1/File managers/opendial"; //opendial
  155. byte openfile_path[2048];
  156. byte filename_area[4096];
  157.  
  158. 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};
  159.  
  160. dword bufpointer;
  161. dword bufsize;
  162. dword draw_sruct;
  163.  
  164. 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};
  165. 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};
  166.  
  167. void main()
  168. {  
  169.         int id;
  170.        
  171.         strcpy(#filter2.ext1, "TXT");
  172.         //strcpy(#filter2.ext2, "ASM");
  173.         //strcpy(#filter2.ext3, "INC\0");
  174.         //strcpy(#filter2.ext4, "\0");
  175.         filter2.size = 8;
  176.         filter2.end = 0;
  177.  
  178.         strcpy(#menu1_text_area1.menu, MENU1);
  179.         strcpy(#menu1_text_area1.sub_menu1, MENU1_SUBMENU1);
  180.         strcpy(#menu1_text_area1.sub_menu2, MENU1_SUBMENU2);
  181.         //strcpy(#menu1_text_area1.sub_menu3, MENU1_SUBMENU3);
  182.         strcpy(#menu1_text_area1.sub_menu4, MENU1_SUBMENU4);
  183.         menu1_text_area1.end = 0;
  184.        
  185.         strcpy(#menu2_text_area2.menu, MENU2);
  186.         strcpy(#menu2_text_area2.sub_menu1, MENU2_SUBMENU1);
  187.         strcpy(#menu2_text_area2.sub_menu2, MENU2_SUBMENU2);
  188.         strcpy(#menu2_text_area2.sub_menu3, MENU2_SUBMENU3);
  189.         strcpy(#menu2_text_area2.sub_menu4, MENU2_SUBMENU4);
  190.         strcpy(#menu2_text_area2.sub_menu5, MENU2_SUBMENU5);
  191.         strcpy(#menu2_text_area2.sub_menu6, MENU2_SUBMENU6);
  192.         menu2_text_area2.end = 0;
  193.        
  194.         //mem_Init();
  195.         load_dll(boxlib, #box_lib_init,0);
  196.         load_dll(libio, #libio_init,1);
  197.         load_dll(iconv_lib, #iconv_open,0);
  198.         load_dll(Proc_lib, #OpenDialog_init,0);
  199.         OpenDialog_init stdcall (#o_dialog);
  200.        
  201.         SetEventMask(0x27);
  202.         loop()
  203.         {
  204.       switch(WaitEvent())
  205.       {
  206.                 case evMouse:
  207.                         menu_bar_mouse stdcall (#menudata1);
  208.                         menu_bar_mouse stdcall (#menudata2);
  209.                         if (menudata1.click==1)
  210.                         {
  211.                                 switch(menudata1.cursor_out)
  212.                                 {
  213.                                         case 1:
  214.                                                 OpenDialog_start stdcall (#o_dialog);
  215.                                                 OpenFile(#openfile_path);
  216.                                                 Prepare();
  217.                                                 draw_window();
  218.                                                 break;
  219.                                         case 2:
  220.                                                 read = 0;
  221.                                                 strcpy(#win_title, TITLE);
  222.                                                 FreeBuf();
  223.                                                 draw_window();
  224.                                                 break;
  225.                                         case 3:
  226.                                                 if (!active_properties)
  227.                                                 {
  228.                                                         SwitchToAnotherThread();
  229.                                                         properties_window = CreateThread(#properties_dialog, #properties_stak+4092);
  230.                                                         break;
  231.                                                 }
  232.                                                 else
  233.                                                 {
  234.                                                         ActivateWindow(GetProcessSlot(properties_window));
  235.                                                 }
  236.                                                 break;
  237.                                         case 4:
  238.                                                 ExitProcess();
  239.                                 }
  240.                         }
  241.                         if (menudata2.click==1)
  242.                         {
  243.                                 encoding = menudata2.cursor_out - 1;
  244.                                 OpenFile(#openfile_path);
  245.                                 Prepare();
  246.                                 draw_window();
  247.                         }
  248.                         break;
  249.                
  250.         case evButton:
  251.                         id=GetButtonID();              
  252.             if (id==1) || (id==10) ExitProcess();
  253.                         break;
  254.                
  255.         case evKey:
  256.             GetKeys();
  257.                         if (TestBit(key_modifier, 2))
  258.                         {
  259.                                 switch(key_scancode)
  260.                                 {
  261.                                         case 024:  //Ctrl+O
  262.                                                 OpenDialog_start stdcall (#o_dialog);
  263.                                                 OpenFile(#openfile_path);
  264.                                                 Prepare();
  265.                                                 draw_window();
  266.                                                 break;
  267.                                 }
  268.                                 break;
  269.                         }
  270.                         switch (key_scancode)
  271.                         {
  272.                                 if (Form.status_window>2) break;
  273.                                 case SCAN_CODE_HOME:
  274.                                         cur_row = 0;
  275.                                         DrawText();
  276.                                         break;
  277.                                 case SCAN_CODE_END:
  278.                                         cur_row = row_num - row_count - 1;
  279.                                         DrawText();
  280.                                         break;
  281.                                 case SCAN_CODE_UP:
  282.                                         if (!cur_row) break;
  283.                                         else cur_row = cur_row-1;
  284.                                         DrawText();
  285.                                         break;
  286.                                 case SCAN_CODE_DOWN:
  287.                                         if (cur_row+row_count>=row_num) break;
  288.                                         cur_row = cur_row+1;
  289.                                         DrawText();
  290.                                         break;
  291.                                 case SCAN_CODE_PGUP:
  292.                                         if (!cur_row) break;
  293.                                         if (cur_row<row_count) cur_row = 0;
  294.                                         else cur_row = cur_row-row_count;
  295.                                         DrawText();
  296.                                         break;
  297.                                 case SCAN_CODE_PGDN:
  298.                                         if (cur_row+row_count>row_num) break;
  299.                                         cur_row = cur_row+row_count;
  300.                                         DrawText();
  301.                                         break;
  302.                         }
  303.                         break;
  304.          
  305.          case evReDraw:
  306.                         draw_window();
  307.                         break;
  308.       }
  309.    }
  310. }
  311.  
  312.  
  313. void draw_window()
  314. {
  315.         system.color.get();
  316.         DefineAndDrawWindow(GetScreenWidth()-WIN_W/2,GetScreenHeight()-WIN_H/2,WIN_W,WIN_H,0x73,0xFFFFFF,#win_title);
  317.         GetProcessInfo(#Form, SelfInfo);
  318.         DrawBar(0, 0, Form.cwidth, TOPPANELH, system.color.work);
  319.         DrawBar(0, Form.cheight-BOTPANELH, Form.cwidth, BOTPANELH, system.color.work);
  320.        
  321.         menudata1.bckg_col = system.color.work;
  322.         menudata2.bckg_col = system.color.work;
  323.         menu_bar_draw stdcall (#menudata1);
  324.         menu_bar_draw stdcall (#menudata2);
  325.        
  326.         if (old_width!=Form.width) || (old_height!=Form.height)
  327.         {
  328.                 old_width = Form.width;
  329.                 old_height = Form.height;
  330.                
  331.                 col_count = Form.cwidth/6;
  332.                 row_count = Form.cheight-BOTPANELH-TOPPANELH-2;
  333.                 row_count = row_count/10;
  334.        
  335.                 if (read==1) Prepare();
  336.         }
  337.         if (read==1)
  338.         {
  339.                 DrawText();
  340.         }
  341.         else DrawBar(0, TOPPANELH, Form.cwidth, Form.cheight-BOTPANELH-TOPPANELH, 0xFFFFFF);
  342. }
  343.  
  344. void OpenFile(dword path)
  345. {
  346.         strcpy(#win_title, TITLE);
  347.         strcat(#win_title, " - ");
  348.         strcat(#win_title, path);
  349.         file_size stdcall (path);
  350.         bufsize = EBX;
  351.         if (bufsize)
  352.         {
  353.                 mem_Free(bufpointer);
  354.                 bufpointer = mem_Alloc(bufsize);
  355.                 ReadFile(0, bufsize, bufpointer, path);
  356.                 read=1;
  357.         }
  358.         if (encoding!=CH_CP866) ChangeCharset(charsets[encoding], "CP866", bufpointer);
  359. }
  360.  
  361. void FreeBuf()
  362. {
  363.         int i;
  364.         for (i=0; i<row_num; i++)
  365.         {
  366.                 mem_Free(DSDWORD[i*4+draw_sruct]);
  367.         }
  368.         mem_Free(draw_sruct);
  369.         mem_Free(bufpointer);
  370. }
  371.  
  372. void Prepare()
  373. {
  374.         int i, sub_pos;
  375.         int len_str = 0;
  376.         byte do_eof = 0;
  377.         word bukva[2];
  378.         dword address;
  379.         row_num = 0;
  380.         while(1)
  381.         {
  382.                 while(1)
  383.                 {
  384.                         bukva = DSBYTE[bufpointer+pos+len_str];
  385.                         if (bukva=='\0')
  386.                         {
  387.                                 do_eof = 1;
  388.                                 break;
  389.                         }
  390.                         if (bukva==0x0a) break;
  391.                         else len_str++;
  392.                 }
  393.                 if (len_str<=col_count)
  394.                 {
  395.                         pos=pos+len_str+1;
  396.                         row_num++;
  397.                 }
  398.                 else
  399.                 {
  400.                         pos=pos+col_count;
  401.                         row_num++;
  402.                 }
  403.                 len_str = 0;
  404.                 if (do_eof) break;
  405.         }
  406.         mem_Free(draw_sruct);
  407.         draw_sruct = mem_Alloc(row_num*4);
  408.         pos=0;
  409.         sub_pos=0;
  410.         len_str = 0;
  411.         do_eof = 0;
  412.         while(1)
  413.         {
  414.                 while(1)
  415.                 {
  416.                         bukva = DSBYTE[bufpointer+pos+len_str];
  417.                         if (bukva=='\0')
  418.                         {
  419.                                 do_eof = 1;
  420.                                 break;
  421.                         }
  422.                         if (bukva==0x0a) break;
  423.                         else len_str++;
  424.                 }
  425.                 if (len_str<=col_count)
  426.                 {
  427.                         address = mem_Alloc(len_str+1);
  428.                         ESDWORD[sub_pos*4+draw_sruct] = address;
  429.                         strlcpy(DSDWORD[sub_pos*4+draw_sruct], bufpointer+pos, len_str);
  430.                         pos=pos+len_str+1;
  431.                         sub_pos++;
  432.                 }
  433.                 else
  434.                 {
  435.                         address = mem_Alloc(len_str+1);
  436.                         ESDWORD[sub_pos*4+draw_sruct] = address;
  437.                         strlcpy(DSDWORD[sub_pos*4+draw_sruct], bufpointer+pos, col_count);
  438.                         pos=pos+col_count;
  439.                         sub_pos++;
  440.                 }
  441.                 len_str = 0;
  442.                 if (pos>=bufsize-1) break;
  443.         }
  444.         pos=0;
  445. }
  446.  
  447. void DrawText()
  448. {
  449.         int i, top, num_line;
  450.         if (row_num<row_count) top = row_num;
  451.         else
  452.         {
  453.                 if (row_num-cur_row<=row_count) top = row_num-cur_row-1;
  454.                 else top = row_count;
  455.         }
  456.         DrawBar(0, TOPPANELH, Form.cwidth, 3, 0xFFFFFF);
  457.         for (i=0, num_line = cur_row; i<top; i++, num_line++)
  458.         {
  459.                 DrawBar(0, i*10+TOPPANELH+3, Form.cwidth, 10, 0xFFFFFF);
  460.                 WriteText(2, i*10+TOPPANELH+3, 0x80, 0x000000, DSDWORD[num_line*4+draw_sruct]);
  461.         }
  462.         DrawBar(0, i*10+TOPPANELH+3, Form.cwidth, -i*10-TOPPANELH-BOTPANELH+Form.cheight, 0xFFFFFF);
  463. }
  464.  
  465. stop:
  466. char properties_stak[4096];