Subversion Repositories Kolibri OS

Rev

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