Subversion Repositories Kolibri OS

Rev

Rev 5640 | 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.12"
  66. char win_title[4096] = TITLE;
  67. proc_info Form;
  68. system_colors sc;
  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, key;
  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.MouseScrollNoSelection(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.                                                 strcpy(#win_title, TITLE);
  157.                                                 FreeBuf();
  158.                                                 draw_window();
  159.                                                 break;
  160.                                         case 3:
  161.                                                 if (!active_properties)
  162.                                                 {
  163.                                                         SwitchToAnotherThread();
  164.                                                         properties_window = CreateThread(#properties_dialog, #properties_stak+4092);
  165.                                                         break;
  166.                                                 }
  167.                                                 else
  168.                                                 {
  169.                                                         ActivateWindow(GetProcessSlot(properties_window));
  170.                                                 }
  171.                                                 break;
  172.                                         case 4:
  173.                                                 ExitProcess();
  174.                                 }
  175.                         }
  176.                         break;
  177.                
  178.         case evButton:
  179.             id=GetButtonID();              
  180.             if (id==1) ExitProcess();
  181.                         break;
  182.      
  183.         case evKey:
  184.                         if (Form.status_window>2) break;
  185.                         key = GetKey();
  186.                         switch (key)
  187.                         {
  188.                                 case 015:  //Ctrl+O
  189.                                         OpenDialog_start stdcall (#o_dialog);
  190.                                         OpenFile(#openfile_path);
  191.                                         Prepare();
  192.                                         draw_window();
  193.                                         break;
  194.                                 case ASCII_KEY_HOME:
  195.                                 case ASCII_KEY_END:
  196.                                 case ASCII_KEY_UP:
  197.                                 case ASCII_KEY_DOWN:
  198.                                         if (tview.ProcessKey(key)) DrawText();
  199.                                         break;
  200.                                 case ASCII_KEY_PGUP:
  201.                                         if (!tview.current) break;
  202.                                         if (tview.current<tview.visible) tview.current = 0;
  203.                                         else tview.current = tview.current-tview.visible;
  204.                                         DrawText();
  205.                                         break;
  206.                                 case ASCII_KEY_PGDN:
  207.                                         if (tview.current+tview.visible>tview.count) break;
  208.                                         tview.current = tview.current+tview.visible;
  209.                                         DrawText();
  210.                                         break;
  211.                         }
  212.                         break;
  213.          
  214.          case evReDraw:
  215.                         draw_window();
  216.                         break;
  217.       }
  218.    }
  219. }
  220.  
  221.  
  222. void draw_window()
  223. {
  224.         sc.get();
  225.         DefineAndDrawWindow(GetScreenWidth()-WIN_W/2,GetScreenHeight()-WIN_H/2,WIN_W,WIN_H,0x73,0xFFFFFF,#win_title);
  226.         GetProcessInfo(#Form, SelfInfo);
  227.         if (Form.status_window>2) return;
  228.         tview.SetSizes(0, TOPPANELH, Form.cwidth, Form.cheight-BOTPANELH-TOPPANELH, 200, 12);
  229.         DrawBar(0, 0, Form.cwidth, TOPPANELH, sc.work);
  230.         DrawBar(0, Form.cheight-BOTPANELH, Form.cwidth, BOTPANELH, sc.work);
  231.        
  232.         menudata1.bckg_col = sc.work;
  233.         menu_bar_draw stdcall (#menudata1);
  234.        
  235.         if (old_width!=Form.width) || (old_height!=Form.height)
  236.         {
  237.                 old_width = Form.width;
  238.                 old_height = Form.height;
  239.                 if (read==1) Prepare();
  240.                 tview.debug_values();
  241.         }
  242.         if (read==1)
  243.         {
  244.                 DrawText();
  245.         }
  246.         else DrawBar(tview.x, tview.y, tview.w, tview.h, 0xFFFFFF);
  247. }
  248.  
  249. void OpenFile(dword path)
  250. {
  251.         strcpy(#win_title, TITLE);
  252.         strcat(#win_title, " - ");
  253.         strcat(#win_title, path);
  254.         file_size stdcall (path);
  255.         bufsize = EBX;
  256.         if (bufsize)
  257.         {
  258.                 mem_Free(bufpointer);
  259.                 bufpointer = mem_Alloc(bufsize);
  260.                 ReadFile(0, bufsize, bufpointer, path);
  261.                 read=1;
  262.         }
  263. }
  264.  
  265. void FreeBuf()
  266. {
  267.         int i;
  268.         for (i=0; i<tview.count; i++)
  269.         {
  270.                 mem_Free(DSDWORD[i*4+draw_sruct]);
  271.         }
  272.         mem_Free(draw_sruct);
  273.         mem_Free(bufpointer);
  274. }
  275.  
  276. void Prepare()
  277. {
  278.         int i, sub_pos;
  279.         static int cur_pos;
  280.         int len_str = 0;
  281.         byte do_eof = 0;
  282.         word bukva[2];
  283.         dword address;
  284.         tview.count = 0;
  285.         while(1)
  286.         {
  287.                 while(1)
  288.                 {
  289.                         bukva = DSBYTE[bufpointer+cur_pos+len_str];
  290.                         if (bukva=='\0')
  291.                         {
  292.                                 do_eof = 1;
  293.                                 break;
  294.                         }
  295.                         if (bukva==0x0a) break;
  296.                         else len_str++;
  297.                 }
  298.                 if (len_str<=tview.column_max)
  299.                 {
  300.                         cur_pos=cur_pos+len_str+1;
  301.                         tview.count++;
  302.                 }
  303.                 else
  304.                 {
  305.                         cur_pos=cur_pos+tview.column_max;
  306.                         tview.count++;
  307.                 }
  308.                 len_str = 0;
  309.                 if (do_eof) break;
  310.         }
  311.         mem_Free(draw_sruct);
  312.         draw_sruct = mem_Alloc(tview.count*4);
  313.         cur_pos=0;
  314.         sub_pos=0;
  315.         len_str = 0;
  316.         do_eof = 0;
  317.         while(1)
  318.         {
  319.                 while(1)
  320.                 {
  321.                         bukva = DSBYTE[bufpointer+cur_pos+len_str];
  322.                         if (bukva=='\0')
  323.                         {
  324.                                 do_eof = 1;
  325.                                 break;
  326.                         }
  327.                         if (bukva==0x0a) break;
  328.                         else len_str++;
  329.                 }
  330.                 if (len_str<=tview.column_max)
  331.                 {
  332.                         address = mem_Alloc(len_str+1);
  333.                         ESDWORD[sub_pos*4+draw_sruct] = address;
  334.                         strlcpy(DSDWORD[sub_pos*4+draw_sruct], bufpointer+cur_pos, len_str);
  335.                         cur_pos=cur_pos+len_str+1;
  336.                         sub_pos++;
  337.                 }
  338.                 else
  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, tview.column_max);
  343.                         cur_pos=cur_pos+tview.column_max;
  344.                         sub_pos++;
  345.                 }
  346.                 len_str = 0;
  347.                 if (cur_pos>=bufsize-1) break;
  348.         }
  349.         cur_pos=0;
  350. }
  351.  
  352. void DrawText()
  353. {
  354.         int i, top, num_line;
  355.         if (tview.count<tview.visible) top = tview.count;
  356.         else
  357.         {
  358.                 if (tview.count-tview.current<=tview.visible) top = tview.count-tview.current-1;
  359.                 else top = tview.visible;
  360.         }
  361.         DrawBar(tview.x, tview.y, tview.w, 3, 0xFFFFFF);
  362.         for (i=0, num_line = tview.current; i<top; i++, num_line++)
  363.         {
  364.                 DrawBar(tview.x, i * tview.line_h + tview.y + 3, tview.w, tview.line_h, 0xFFFFFF);
  365.                 WriteText(tview.x + 2, i * tview.line_h + tview.y + 3, 0x80, 0x000000, DSDWORD[num_line*4+draw_sruct]);
  366.         }
  367.         DrawBar(0, i * tview.line_h + tview.y + 3, tview.w, -i* tview.line_h + tview.h, 0xFFFFFF);
  368. }
  369.  
  370. stop:
  371. char properties_stak[4096];