Subversion Repositories Kolibri OS

Rev

Rev 5614 | 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.         ?define ERROR_LOAD_BOX_LIB "Žè¨¡ª  ¯à¨ § £à㧪¥ ¡¨¡«¨®â¥ª¨ - box_lib.obj"
  28.         ?define ERROR_LOAD_LIBIO "Žè¨¡ª  ¯à¨ § £à㧪¥ ¡¨¡«¨®â¥ª¨ - libio.obj"
  29.         ?define ERROR_LOAD_PROC_LIB "Žè¨¡ª  ¯à¨ § £à㧪¥ ¡¨¡«¨®â¥ª¨ - proc_lib.obj"
  30. #else
  31.         ?define T_FILE "File"
  32.         ?define T_TYPE "Type"
  33.         ?define T_SIZE "Size"
  34.         ?define MENU1 "File"
  35.         ?define MENU1_SUBMENU1 "Open"
  36.         ?define MENU1_SUBMENU2 "Close"
  37.         ?define MENU1_SUBMENU3 "Properties"
  38.         ?define MENU1_SUBMENU4 "Exit"
  39.         ?define ERROR_LOAD_BOX_LIB "Error while loading library - box_lib.obj"
  40.         ?define ERROR_LOAD_LIBIO "Error while loading library - libio.obj"
  41.         ?define ERROR_LOAD_PROC_LIB "Error while loading library - proc_lib.obj"
  42. #endif
  43.  
  44. #ifdef LANG_RUS
  45. struct menu_text_struct
  46. {
  47.         char menu[5];
  48.         char sub_menu1[8];
  49.         char sub_menu2[8];
  50.         //char sub_menu3[9];
  51.         char sub_menu4[6];
  52.         byte end;
  53. };
  54. #else
  55. struct menu_text_struct
  56. {
  57.         char menu[5];
  58.         char sub_menu1[5];
  59.         char sub_menu2[6];
  60.         //char sub_menu3[11];
  61.         char sub_menu4[5];
  62.         byte end;
  63. };
  64. #endif
  65.  
  66. #define TOPPANELH 19
  67. #define BOTPANELH 10
  68. #define WIN_W 600
  69. #define WIN_H 400
  70.  
  71. #define TITLE "Calypte v0.12"
  72. char win_title[4096] = TITLE;
  73. proc_info Form;
  74. system_colors sc;
  75. dword old_width,old_height;
  76. llist tview;
  77.  
  78. byte active_properties = 0;
  79. dword properties_window;
  80.  
  81. #include "include\gui.h"
  82. #include "include\properties.h"
  83. // #include "include\top_menu.h"
  84. // #include "include\open_dial.h"
  85.  
  86. struct filter
  87. {
  88.         dword size;
  89.         char ext1[4];
  90.         //char ext2[4];
  91.         //char ext3[4];
  92.         //char ext4[4];
  93.         byte end;
  94. };
  95.  
  96. filter filter2;
  97. menu_text_struct menu_text_area1;
  98.  
  99. int read=0;
  100.  
  101.  
  102. proc_info pr_inf;
  103. char communication_area_name[] = "FFFFFFFF_open_dialog";
  104. byte plugin_path[4096];
  105. char default_dir[] = "/rd/1";
  106. char open_dialog_path[] = "/rd/1/File managers/opendial"; //opendial
  107. byte openfile_path[2048];
  108. byte filename_area[4096];
  109.  
  110. 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};
  111.  
  112. dword bufpointer;
  113. dword bufsize;
  114. dword draw_sruct;
  115.  
  116. 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};
  117.  
  118. void main()
  119. {  
  120.         int id, key;
  121.         mouse m;
  122.        
  123.         strcpy(#filter2.ext1, "TXT");
  124.         //strcpy(#filter2.ext2, "ASM");
  125.         //strcpy(#filter2.ext3, "INC\0");
  126.         //strcpy(#filter2.ext4, "\0");
  127.         filter2.size = 8;
  128.         filter2.end = 0;
  129.  
  130.         strcpy(#menu_text_area1.menu, MENU1);
  131.         strcpy(#menu_text_area1.sub_menu1, MENU1_SUBMENU1);
  132.         strcpy(#menu_text_area1.sub_menu2, MENU1_SUBMENU2);
  133.         //strcpy(#menu_text_area1.sub_menu3, MENU1_SUBMENU3);
  134.         strcpy(#menu_text_area1.sub_menu4, MENU1_SUBMENU4);
  135.         menu_text_area1.end = 0;
  136.        
  137.         mem_Init();
  138.         if (load_dll2(boxlib, #box_lib_init,0)!=0) notify(ERROR_LOAD_BOX_LIB);
  139.         if (load_dll2(libio, #libio_init,1)!=0) notify(ERROR_LOAD_LIBIO);
  140.         if (load_dll2(Proc_lib, #OpenDialog_init,0)!=0) notify(ERROR_LOAD_PROC_LIB);
  141.         OpenDialog_init stdcall (#o_dialog);
  142.         SetEventMask(0x27);
  143.         loop()
  144.         {
  145.       switch(WaitEvent())
  146.       {
  147.                 case evMouse:
  148.                         m.get();
  149.                         if (tview.MouseScrollNoSelection(m.vert)) DrawText();
  150.                
  151.                         menu_bar_mouse stdcall (#menudata1);                   
  152.                         if (menudata1.click)
  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) ExitProcess();
  189.                         break;
  190.      
  191.         case evKey:
  192.                         if (Form.status_window>2) break;
  193.                         key = GetKey();
  194.                         switch (key)
  195.                         {
  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.                                 case ASCII_KEY_END:
  204.                                 case ASCII_KEY_UP:
  205.                                 case ASCII_KEY_DOWN:
  206.                                         if (tview.ProcessKey(key)) DrawText();
  207.                                         break;
  208.                                 case ASCII_KEY_PGUP:
  209.                                         if (!tview.current) break;
  210.                                         if (tview.current<tview.visible) tview.current = 0;
  211.                                         else tview.current = tview.current-tview.visible;
  212.                                         DrawText();
  213.                                         break;
  214.                                 case ASCII_KEY_PGDN:
  215.                                         if (tview.current+tview.visible>tview.count) break;
  216.                                         tview.current = tview.current+tview.visible;
  217.                                         DrawText();
  218.                                         break;
  219.                         }
  220.                         break;
  221.          
  222.          case evReDraw:
  223.                         draw_window();
  224.                         break;
  225.       }
  226.    }
  227. }
  228.  
  229.  
  230. void draw_window()
  231. {
  232.         sc.get();
  233.         DefineAndDrawWindow(GetScreenWidth()-WIN_W/2,GetScreenHeight()-WIN_H/2,WIN_W,WIN_H,0x73,0xFFFFFF,#win_title);
  234.         GetProcessInfo(#Form, SelfInfo);
  235.         if (Form.status_window>2) return;
  236.         tview.SetSizes(0, TOPPANELH, Form.cwidth, Form.cheight-BOTPANELH-TOPPANELH, 200, 12);
  237.         DrawBar(0, 0, Form.cwidth, TOPPANELH, sc.work);
  238.         DrawBar(0, Form.cheight-BOTPANELH, Form.cwidth, BOTPANELH, sc.work);
  239.        
  240.         menudata1.bckg_col = sc.work;
  241.         menu_bar_draw stdcall (#menudata1);
  242.        
  243.         if (old_width!=Form.width) || (old_height!=Form.height)
  244.         {
  245.                 old_width = Form.width;
  246.                 old_height = Form.height;
  247.                 if (read==1) Prepare();
  248.                 tview.debug_values();
  249.         }
  250.         if (read==1)
  251.         {
  252.                 DrawText();
  253.         }
  254.         else DrawBar(tview.x, tview.y, tview.w, tview.h, 0xFFFFFF);
  255. }
  256.  
  257. void OpenFile(dword path)
  258. {
  259.         strcpy(#win_title, TITLE);
  260.         strcat(#win_title, " - ");
  261.         strcat(#win_title, path);
  262.         file_size stdcall (path);
  263.         bufsize = EBX;
  264.         if (bufsize)
  265.         {
  266.                 mem_Free(bufpointer);
  267.                 bufpointer = mem_Alloc(bufsize);
  268.                 ReadFile(0, bufsize, bufpointer, path);
  269.                 read=1;
  270.         }
  271. }
  272.  
  273. void FreeBuf()
  274. {
  275.         int i;
  276.         for (i=0; i<tview.count; i++)
  277.         {
  278.                 mem_Free(DSDWORD[i*4+draw_sruct]);
  279.         }
  280.         mem_Free(draw_sruct);
  281.         mem_Free(bufpointer);
  282. }
  283.  
  284. void Prepare()
  285. {
  286.         int i, sub_pos;
  287.         static int cur_pos;
  288.         int len_str = 0;
  289.         byte do_eof = 0;
  290.         word bukva[2];
  291.         dword address;
  292.         tview.count = 0;
  293.         while(1)
  294.         {
  295.                 while(1)
  296.                 {
  297.                         bukva = DSBYTE[bufpointer+cur_pos+len_str];
  298.                         if (bukva=='\0')
  299.                         {
  300.                                 do_eof = 1;
  301.                                 break;
  302.                         }
  303.                         if (bukva==0x0a) break;
  304.                         else len_str++;
  305.                 }
  306.                 if (len_str<=tview.column_max)
  307.                 {
  308.                         cur_pos=cur_pos+len_str+1;
  309.                         tview.count++;
  310.                 }
  311.                 else
  312.                 {
  313.                         cur_pos=cur_pos+tview.column_max;
  314.                         tview.count++;
  315.                 }
  316.                 len_str = 0;
  317.                 if (do_eof) break;
  318.         }
  319.         mem_Free(draw_sruct);
  320.         draw_sruct = mem_Alloc(tview.count*4);
  321.         cur_pos=0;
  322.         sub_pos=0;
  323.         len_str = 0;
  324.         do_eof = 0;
  325.         while(1)
  326.         {
  327.                 while(1)
  328.                 {
  329.                         bukva = DSBYTE[bufpointer+cur_pos+len_str];
  330.                         if (bukva=='\0')
  331.                         {
  332.                                 do_eof = 1;
  333.                                 break;
  334.                         }
  335.                         if (bukva==0x0a) break;
  336.                         else len_str++;
  337.                 }
  338.                 if (len_str<=tview.column_max)
  339.                 {
  340.                         address = mem_Alloc(len_str+1);
  341.                         ESDWORD[sub_pos*4+draw_sruct] = address;
  342.                         strlcpy(DSDWORD[sub_pos*4+draw_sruct], bufpointer+cur_pos, len_str);
  343.                         cur_pos=cur_pos+len_str+1;
  344.                         sub_pos++;
  345.                 }
  346.                 else
  347.                 {
  348.                         address = mem_Alloc(len_str+1);
  349.                         ESDWORD[sub_pos*4+draw_sruct] = address;
  350.                         strlcpy(DSDWORD[sub_pos*4+draw_sruct], bufpointer+cur_pos, tview.column_max);
  351.                         cur_pos=cur_pos+tview.column_max;
  352.                         sub_pos++;
  353.                 }
  354.                 len_str = 0;
  355.                 if (cur_pos>=bufsize-1) break;
  356.         }
  357.         cur_pos=0;
  358. }
  359.  
  360. void DrawText()
  361. {
  362.         int i, top, num_line;
  363.         if (tview.count<tview.visible) top = tview.count;
  364.         else
  365.         {
  366.                 if (tview.count-tview.current<=tview.visible) top = tview.count-tview.current-1;
  367.                 else top = tview.visible;
  368.         }
  369.         DrawBar(tview.x, tview.y, tview.w, 3, 0xFFFFFF);
  370.         for (i=0, num_line = tview.current; i<top; i++, num_line++)
  371.         {
  372.                 DrawBar(tview.x, i * tview.line_h + tview.y + 3, tview.w, tview.line_h, 0xFFFFFF);
  373.                 WriteText(tview.x + 2, i * tview.line_h + tview.y + 3, 0x80, 0x000000, DSDWORD[num_line*4+draw_sruct]);
  374.         }
  375.         DrawBar(0, i * tview.line_h + tview.y + 3, tview.w, -i* tview.line_h + tview.h, 0xFFFFFF);
  376. }
  377.  
  378. stop:
  379. char properties_stak[4096];