Subversion Repositories Kolibri OS

Rev

Rev 7230 | Rev 7244 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

  1. //Leency, Veliant, Punk_Joker, PavelYakov & KolibriOS Team 2008-2018
  2. //GNU GPL licence.
  3.  
  4. #ifndef AUTOBUILD
  5. #include "lang.h--"
  6. #endif
  7.  
  8. //libraries
  9. #define MEMSIZE 1024 * 720
  10. #include "../lib/clipboard.h"
  11. #include "../lib/strings.h"
  12. #include "../lib/mem.h"
  13. #include "../lib/fs.h"
  14. #include "../lib/gui.h"
  15. #include "../lib/list_box.h"
  16. #include "../lib/random.h"
  17. #include "../lib/kfont.h"
  18. #include "../lib/collection.h"
  19. #include "../lib/menu.h"
  20. #include "../lib/copyf.h"
  21.  
  22. #include "../lib/obj/libini.h"
  23. #include "../lib/obj/box_lib.h"
  24. #include "../lib/obj/libimg.h"
  25.  
  26. #include "../lib/patterns/history.h"
  27.  
  28. //images
  29. #include "imgs/left_p.txt"
  30.  
  31. //Button IDs
  32. enum {
  33.         POPUP_BTN1 = 201,
  34.         POPUP_BTN2 = 202,
  35.         BREADCRUMB_ID = 300
  36. };
  37.  
  38. //NewElement options
  39. enum {
  40.         CREATE_FILE=1,
  41.         CREATE_FOLDER,
  42.         RENAME_ITEM
  43. };
  44.  
  45. //OpenDir options
  46. enum {
  47.         ONLY_SHOW,
  48.         WITH_REDRAW,
  49.         ONLY_OPEN
  50. };
  51.  
  52. dword col_padding, col_selec, col_lpanel, col_work, col_graph, col_list_line=0xDDD7CF;
  53.  
  54. int toolbar_buttons_x[7]={9,46,85,134,167,203};
  55.  
  56. byte active_about=0;
  57. word about_window;
  58. word settings_window;
  59. byte active_settings=0;
  60. dword _not_draw = false;
  61. byte menu_call_mouse=0;
  62. byte exif_load=0;
  63.  
  64. byte del_active=0;
  65. byte new_element_active=0;
  66.  
  67. llist files, files_active, files_inactive;
  68.  
  69. byte list_full_redraw;
  70.  
  71. dword buf;
  72. dword file_mas[6898];
  73. int selected_count;
  74. int count_dir;
  75.  
  76. byte
  77.         path[4096],
  78.         file_path[4096],
  79.         file_name[256],
  80.         new_element_name[256],
  81.         temp[4096],
  82.         itdir;
  83.  
  84. char active_path[4096], inactive_path[4096];
  85.  
  86. dword eolite_ini_path[4096];
  87. _ini ini;
  88.  
  89. char scroll_used=false;
  90.  
  91. dword menu_stak,about_stak,properties_stak,settings_stak,copy_stak,delete_stak;
  92.  
  93. proc_info Form;
  94. int mouse_dd, sc_slider_h;
  95. int j, i;
  96. int action_buf;
  97. int rand_n;
  98.  
  99. //struct t_settings {
  100. char sort_num=2;
  101. bool show_dev_name=true,
  102.         real_files_names_case=true,
  103.         info_after_copy=false,
  104.         two_panels=false,
  105.         show_breadcrumb=false,
  106.         show_status_bar=true,
  107.         active_panel=1,
  108.         big_icons=false;
  109. //} settings;
  110.  
  111. libimg_image icons16_default;
  112. libimg_image icons16_selected;
  113.  
  114. libimg_image icons32_default;
  115. libimg_image icons32_selected;
  116.  
  117. #define STATUS_BAR_H 16;
  118. int status_bar_h = 0;
  119.  
  120. int icon_size = 16;
  121.  
  122. edit_box new_file_ed = {200,213,180,0xFFFFFF,0x94AECE,0xFFFFFF,0xFFFFFF,0x10000000,248,#new_element_name,#mouse_dd,100000000000010b,6,0};
  123. PathShow_data FileShow = {0, 56,215, 8, 100, 1, 0, 0x0, 0xFFFfff, #file_name, #temp, 0};
  124. byte cmd_free=0;
  125. #include "include\translations.h"
  126. #include "include\fs.h"
  127.  
  128. #include "include\settings.h"
  129. #include "include\progress_dialog.h"
  130. #include "include\copy.h"
  131. #include "include\gui.h"
  132. #include "include\sorting.h"
  133. #include "include\icons.h"
  134. #include "include\left_panel.h"
  135. #include "include\menu.h"
  136. #include "include\delete.h"
  137. #include "include\about.h"
  138. #include "include\properties.h"
  139. #include "include\breadcrumbs.h"
  140.  
  141. void main()
  142. {
  143.         dword id;
  144.         byte count_sl = 0;
  145.         signed x_old, y_old, dif_x, dif_y, adif_x, adif_y;
  146.         char stats;
  147.         rand_n = random(40);
  148.  
  149.         load_dll(boxlib, #box_lib_init,0);
  150.         load_dll(libini, #lib_init,1);
  151.         load_dll(libio,  #libio_init,1);
  152.         load_dll(libimg, #libimg_init,1);
  153.        
  154.         LoadIniSettings();
  155.         SystemDiscs.Get();
  156.         SetAppColors();
  157.  
  158.         Libimg_LoadImage(#icons16_default, "/sys/icons16.png");
  159.         Libimg_LoadImage(#icons16_selected, "/sys/icons16.png");
  160.         Libimg_ReplaceColor(icons16_selected.image, icons16_selected.w, icons16_selected.h, 0xffFFFfff, col_selec);
  161.         Libimg_ReplaceColor(icons16_selected.image, icons16_selected.w, icons16_selected.h, 0xffCACBD6, MixColors(col_selec, 0, 200));
  162.  
  163.         //-p just show file/folder properties dialog
  164.         if (param) && (param[0]=='-') && (param[1]=='p')
  165.         {
  166.                 strcpy(#file_path, #param + 3);
  167.                 strcpy(#file_name, #param + strrchr(#param, '/'));
  168.                 properties_dialog();
  169.                 ExitProcess(); 
  170.         }
  171.  
  172.         if (param)
  173.         {
  174.                 if (strlen(#param)>1) && (param[strlen(#param)-1]=='/') param[strlen(#param)-1]=NULL; //no "/" in the end
  175.  
  176.                 if (dir_exists(#param)==true)
  177.                 {
  178.                         strcpy(#path, #param);
  179.                 }
  180.                 else
  181.                 {
  182.                         notify(T_NOTIFY_APP_PARAM_WRONG);
  183.                 }
  184.         }
  185.        
  186.         Open_Dir(#path,ONLY_OPEN);
  187.         strcpy(#inactive_path, #path);
  188.         llist_copy(#files_inactive, #files);
  189.         SetEventMask(EVM_REDRAW+EVM_KEY+EVM_BUTTON+EVM_MOUSE+EVM_MOUSE_FILTER);
  190.         loop(){
  191.                 switch(WaitEvent())
  192.                 {
  193.                         case evMouse:
  194.                                 if (del_active) || (Form.status_window>2) break;
  195.                                 if (new_element_active)
  196.                                 {
  197.                                         edit_box_mouse stdcall(#new_file_ed);
  198.                                         break;
  199.                                 }                              
  200.                                
  201.                                 mouse.get();
  202.                                
  203.                                 if (!mouse.mkm) && (stats>0) stats = 0;
  204.                                 if (mouse.mkm) && (!stats)
  205.                                 {
  206.                                         x_old = mouse.x;
  207.                                         y_old = mouse.y;
  208.                                         stats = 1;
  209.                                 }
  210.                                 if (mouse.mkm) && (stats==1)
  211.                                 {
  212.                                         dif_x = mouse.x-x_old;
  213.                                         dif_y = mouse.y-y_old;
  214.                                         adif_x = fabs(dif_x);
  215.                                         adif_y = fabs(dif_y);
  216.                                        
  217.                                         if (adif_x>adif_y)
  218.                                         {
  219.                                                 if (dif_x > 150)
  220.                                                 {
  221.                                                         if (history.forward())
  222.                                                                 {
  223.                                                                         strcpy(#path, history.current());
  224.                                                                         files.KeyHome();
  225.                                                                         Open_Dir(#path,WITH_REDRAW);
  226.                                                                 }
  227.                                                         stats = 0;
  228.                                                 }
  229.                                                 if (dif_x < -150)
  230.                                                 {
  231.                                                         GoBack();
  232.                                                         stats = 0;
  233.                                                 }
  234.                                         }
  235.                                         else
  236.                                         {
  237.                                                 if (dif_y < -100)
  238.                                                 {
  239.                                                         Dir_Up();
  240.                                                         stats = 0;
  241.                                                 }
  242.                                         }
  243.                                 }      
  244.                                 if (files.MouseOver(mouse.x, mouse.y))
  245.                                 {
  246.                                         //select file
  247.                                         if (mouse.key&MOUSE_LEFT) && (mouse.up)
  248.                                         {
  249.                                                 if (files.ProcessMouse(mouse.x, mouse.y)) List_ReDraw(); else {
  250.                                                         if (mouse.y - files.y / files.item_h + files.first == files.cur_y) Open(0);
  251.                                                 }
  252.                                         }
  253.                                         //file menu
  254.                                         if (mouse.key&MOUSE_RIGHT)
  255.                                         {
  256.                                                 menu_call_mouse = 1;
  257.                                                 if (files.ProcessMouse(mouse.x, mouse.y)) List_ReDraw();
  258.                                                 if (getElementSelectedFlag(files.cur_y) == false) selected_count = 0; //on redraw selection would be flashed, see [L001]
  259.                                                 menu_stak = malloc(4096);
  260.                                                 CreateThread(#FileMenu,menu_stak+4092);
  261.                                                 break;
  262.                                         }
  263.                                 }
  264.  
  265.                                 if (mouse.vert)
  266.                                 {
  267.                                         if (files.MouseScroll(mouse.vert)) List_ReDraw();
  268.                                         break;
  269.                                 }
  270.  
  271.                                 if (mouse.x>=files.x+files.w) && (mouse.x<=files.x+files.w+16) && (mouse.y>files.y-17) && (mouse.y<files.y)
  272.                                 {
  273.                                         if (mouse.lkm==1) DrawRectangle3D(files.x+files.w+1,files.y-16,14,14,0xC7C7C7,0xFFFFFF);
  274.                                         WHILE (mouse.lkm==1) && (files.first>0)
  275.                                         {
  276.                                                 pause(8);
  277.                                                 files.first--;
  278.                                                 List_ReDraw();
  279.                                                 mouse.get();
  280.                                         }
  281.                                         DrawRectangle3D(files.x+files.w+1,files.y-16,14,14,0xFFFFFF,0xC7C7C7);
  282.                                 }
  283.  
  284.                                 if (mouse.x>=files.x+files.w) && (mouse.x<=files.x+files.w+16) && (mouse.y>files.y+files.h-16) && (mouse.y<files.y+files.h)
  285.                                 {
  286.                                         if (mouse.lkm==1) DrawRectangle3D(files.x+files.w+1,files.y+files.h-15,14,14,0xC7C7C7,0xFFFFFF);
  287.                                         while (mouse.lkm==1) && (files.first<files.count-files.visible)
  288.                                         {
  289.                                                 pause(8);
  290.                                                 files.first++;
  291.                                                 List_ReDraw();
  292.                                                 mouse.get();
  293.                                         }
  294.                                         DrawRectangle3D(files.x+files.w+1,files.y+files.h-15,14,14,0xFFFFFF,0xC7C7C7);
  295.                                 }
  296.  
  297.                                 //Scrooll
  298.                                 if (!mouse.lkm) && (scroll_used) { scroll_used=false; Scroll(); }
  299.                                 if (mouse.x>=files.x+files.w) && (mouse.x<=files.x+files.w+18) && (mouse.y>files.y) && (mouse.y<files.y+files.h-18) && (mouse.lkm) && (!scroll_used) {scroll_used=true; Scroll();}
  300.                                
  301.                                 if (scroll_used)
  302.                                 {
  303.                                         if (sc_slider_h/2+files.y>mouse.y) || (mouse.y<0) || (mouse.y>4000) mouse.y=sc_slider_h/2+files.y; //anee eo?ni? iaa ieiii
  304.                                         id = files.first;
  305.                                         files.first = -sc_slider_h / 2 + mouse.y -j -files.y * files.count;
  306.                                         files.first /= files.h - 18;
  307.                                         if (files.visible+files.first>files.count) files.first=files.count-files.visible;
  308.                                         if (files.first<0) files.first=0;
  309.                                         if (id!=files.first) List_ReDraw();
  310.                                         break;
  311.                                 }
  312.  
  313.                                 if (two_panels) && (mouse.y > files.y) && (mouse.down) {
  314.                                         if (mouse.x<Form.cwidth/2)
  315.                                         {
  316.                                                 if (active_panel!=1)
  317.                                                 {
  318.                                                         active_panel = 1;
  319.                                                         ChangeActivePanel();
  320.                                                 }
  321.                                         }
  322.                                         else
  323.                                         {
  324.                                                 if (active_panel!=2)
  325.                                                 {
  326.                                                         active_panel = 2;
  327.                                                         ChangeActivePanel();
  328.                                                 }
  329.                                         }
  330.                                 }
  331.                                 break;  
  332.         //Button pressed-----------------------------------------------------------------------------
  333.                         case evButton:
  334.                                 id=GetButtonID();                              
  335.                                 switch(id)
  336.                                 {
  337.                                         case CLOSE_BTN:
  338.                                                         KillProcess(about_window);
  339.                                                         SaveIniSettings();
  340.                                                         ExitProcess();
  341.                                         case 21: //Back
  342.                                                         GoBack();
  343.                                                         break;
  344.                                         case 22: //Forward
  345.                                                         if (history.forward())
  346.                                                         {
  347.                                                                 strcpy(#path, history.current());
  348.                                                                 files.KeyHome();
  349.                                                                 Open_Dir(#path,WITH_REDRAW);
  350.                                                         }
  351.                                                         break;
  352.                                         case 23:
  353.                                                         Dir_Up();
  354.                                                         break;
  355.                                         case 24:
  356.                                                         Copy(#file_path, CUT);
  357.                                                         break;
  358.                                         case 25:
  359.                                                         Copy(#file_path, NOCUT);
  360.                                                         break;
  361.                                         case 26:
  362.                                                         Paste();
  363.                                                         break;
  364.                                         case 31...33: //sorting
  365.                                                         sort_num = id - 30;
  366.                                                         DrawList();
  367.                                                         Open_Dir(#path,WITH_REDRAW);
  368.                                                         break;
  369.                                         case 50...60: //Actions
  370.                                                         FnProcess(id-50);
  371.                                                         break;
  372.                                         case 100...120:
  373.                                                 SystemDiscs.Click(id-100);
  374.                                                 break;
  375.                                         case POPUP_BTN1...POPUP_BTN2:
  376.                                                 if (del_active) Del_File(id-POPUP_BTN2);
  377.                                                 if (new_element_active) NewElement(id-POPUP_BTN2);
  378.                                                 DeleteButton(POPUP_BTN1);
  379.                                                 DeleteButton(POPUP_BTN2);
  380.                                                 break;
  381.                                         case BREADCRUMB_ID...360:
  382.                                                 ClickOnBreadCrumb(id-BREADCRUMB_ID);
  383.                                                 break;
  384.                                 }
  385.                                 break;
  386.                                
  387.         //Key pressed-----------------------------------------------------------------------------
  388.                         case evKey:
  389.                                 GetKeys();
  390.  
  391.                                 if (Form.status_window>2) break;
  392.                                 if (del_active)
  393.                                 {
  394.                                         if (key_scancode == SCAN_CODE_ENTER) Del_File(true);
  395.                                         if (key_scancode == SCAN_CODE_ESC) Del_File(false);
  396.                                         break;
  397.                                 }
  398.                                 if (new_element_active)
  399.                                 {
  400.                                         if (key_scancode == SCAN_CODE_ENTER) NewElement(true);
  401.                                         if (key_scancode == SCAN_CODE_ESC) NewElement(false);
  402.                                         EAX = key_editbox;
  403.                                         edit_box_key stdcall (#new_file_ed);
  404.                                         break;
  405.                                 }
  406.                                 if (files.ProcessKey(key_scancode))
  407.                                 {
  408.                                         List_ReDraw();
  409.                                         break;
  410.                                 }
  411.  
  412.                                 if (key_modifier&KEY_LCTRL) || (key_modifier&KEY_RCTRL)
  413.                                 {
  414.                                         switch(key_scancode)
  415.                                         {
  416.                                                 case 059...068:
  417.                                                                 key_scancode -= 59;
  418.                                                                 if (key_scancode < SystemDiscs.list.count)
  419.                                                                 {
  420.                                                                         if (!two_panels)
  421.                                                                         {
  422.                                                                                 DrawRectangle(17,key_scancode*16+74,159,16, 0); //display click
  423.                                                                                 pause(7);                                                                              
  424.                                                                         }
  425.                                                                         SystemDiscs.Click(key_scancode);
  426.                                                                 }
  427.                                                                 break;
  428.                                                 case 45:  //Ctrl+X
  429.                                                                 Copy(#file_path, CUT);
  430.                                                                 break;                                         
  431.                                                 case 46:  //Ctrl+C
  432.                                                                 Copy(#file_path, NOCUT);
  433.                                                                 break;
  434.                                                 case 47:  //Ctrl+V
  435.                                                                 Paste();
  436.                                                                 break;
  437.                                                 case 032: //Ctrl+D - set as bg
  438.                                                                 strlcpy(#temp, "\\S__",4);
  439.                                                                 strcat(#temp, #file_path);
  440.                                                                 RunProgram("/sys/media/kiv", #temp);
  441.                                                                 break;
  442.                                                 case 049: //Ctrl+N - create new window
  443.                                                                 if (Form.left==98) MoveSize(Form.left-20,Form.top-20,OLD,OLD);
  444.                                                                 RunProgram(I_Path, #path);
  445.                                                                 break;
  446.                                                 case 050: //Ctrl+M
  447.                                                                 Open_Dir(#inactive_path,WITH_REDRAW);
  448.                                                                 break;
  449.                                                 case SCAN_CODE_ENTER: //Ctrl+Enter
  450.                                                                 if (!itdir) ShowOpenWithDialog();
  451.                                                                 else Open(1);
  452.                                                                 break;
  453.                                                 case 030: //Ctrl+A - select all files
  454.                                                                 for (i=0; i<files.count; i++) setElementSelectedFlag(i, true);
  455.                                                                 List_ReDraw();
  456.                                                                 DrawStatusBar();
  457.                                                                 break;
  458.                                                 case 022: //Ctrl+U - unselect all files
  459.                                                                 for (i=0; i<files.count; i++) setElementSelectedFlag(i, false);
  460.                                                                 selected_count = 0;
  461.                                                                 List_ReDraw();
  462.                                                                 DrawStatusBar();
  463.                                                                 break;
  464.                                         }
  465.                                         break;
  466.                                 }
  467.  
  468.                                 switch (key_scancode)
  469.                                 {
  470.                                                 case SCAN_CODE_BS:
  471.                                                                 //GoBack();
  472.                                                                 Dir_Up();
  473.                                                                 break;
  474.                                                 case SCAN_CODE_ENTER:
  475.                                                                 Open(0);
  476.                                                                 break;
  477.                                                 case SCAN_CODE_TAB:
  478.                                                                 if (!two_panels) break;
  479.                                                                 if (active_panel==1) active_panel=2; else active_panel=1;
  480.                                                                 ChangeActivePanel();
  481.                                                                 DrawStatusBar();
  482.                                                                 break;
  483.                                                 case 093: //menu
  484.                                                                 menu_call_mouse=0;
  485.                                                                 menu_stak = malloc(4096);
  486.                                                                 CreateThread(#FileMenu,menu_stak+4092);
  487.                                                                 break;
  488.                                                 case SCAN_CODE_DEL:
  489.                                                                 Del_Form();
  490.                                                                 break;
  491.                                                 case SCAN_CODE_INS:
  492.                                                                 if (getElementSelectedFlag(files.cur_y) == true) setElementSelectedFlag(files.cur_y, false);
  493.                                                                 else setElementSelectedFlag(files.cur_y, true);
  494.                                                                 files.KeyDown();
  495.                                                                 List_ReDraw();
  496.                                                                 DrawStatusBar();
  497.                                                                 break;
  498.                                                 case 059...068: //F1-F10
  499.                                                                 FnProcess(key_scancode-58);
  500.                                                                 break;
  501.                                                 default:
  502.                                                                 for (i=files.cur_y+1; i<files.count; i++)
  503.                                                                 {
  504.                                                                         strcpy(#temp, file_mas[i]*304+buf+72);
  505.                                                                         if (temp[0]==key_ascii) || (temp[0]==key_ascii-32)
  506.                                                                         {
  507.                                                                                 files.cur_y = i - 1;
  508.                                                                                 files.KeyDown();
  509.                                                                                 List_ReDraw();
  510.                                                                                 break;
  511.                                                                         }
  512.                                                                 }
  513.                                 }                        
  514.                         break;
  515.                         case evIPC:
  516.                         case evReDraw:
  517.                                 draw_window();
  518.                                 if (action_buf)
  519.                                 {
  520.                                         if (action_buf==OPERATION_END)
  521.                                         {
  522.                                                 FnProcess(5);
  523.                                                 if (copy_stak) SelectFileByName(#copy_to+strrchr(#copy_to,'/'));
  524.                                         }
  525.                                         if (action_buf==100) Open(0);
  526.                                         if (action_buf==201) ShowOpenWithDialog();
  527.                                         if (action_buf==202) FnProcess(3); //F3
  528.                                         if (action_buf==203) FnProcess(4); //F4
  529.                                         if (action_buf==104) Copy(#file_path, NOCUT);
  530.                                         if (action_buf==105) Copy(#file_path, CUT);
  531.                                         if (action_buf==106) Paste();
  532.                                         if (action_buf==207) FnProcess(2);
  533.                                         if (action_buf==108) Del_Form();
  534.                                         if (action_buf==109) FnProcess(5);
  535.                                         if (action_buf==110) FnProcess(8);
  536.                                         action_buf=0;
  537.                                 }
  538.                 }
  539.                 if(cmd_free)
  540.                 {
  541.                         if(cmd_free==1)      menu_stak=free(menu_stak);
  542.                         else if(cmd_free==2) about_stak=free(about_stak);
  543.                         else if(cmd_free==3) properties_stak=free(properties_stak);
  544.                         else if(cmd_free==4) settings_stak=free(settings_stak);
  545.                         else if(cmd_free==5) copy_stak=free(copy_stak);
  546.                         else if(cmd_free==6) delete_stak=free(delete_stak);
  547.                         cmd_free = false;
  548.                 }
  549.         }
  550. }
  551.  
  552. void DrawFavButton(int x)
  553. {
  554.         _PutImage(x,10,20,22,#fav);
  555.         DefineButton(x,11,20-2,22-2,61+BT_HIDE+BT_NOFRAME,0);
  556. }
  557.  
  558. void draw_window()
  559. {
  560.         if (show_status_bar) status_bar_h = STATUS_BAR_H; else status_bar_h = 0;
  561.         DefineAndDrawWindow(WinX+rand_n,WinY+rand_n,WinW,WinH,0x73,NULL,TITLE,0);
  562.         GetProcessInfo(#Form, SelfInfo);
  563.         if (Form.status_window>2) return;
  564.         if (Form.height < 350) { MoveSize(OLD,OLD,OLD,350); return; }
  565.         if (Form.width  < 480) { MoveSize(OLD,OLD,480,OLD); return; }
  566.         GetProcessInfo(#Form, SelfInfo); //if win_size changed
  567.         _PutImage(0,0,246,34,#toolbar);
  568.         DrawBar(127, 8, 1, 25, col_graph);
  569.         for (j=0; j<3; j++) DefineButton(toolbar_buttons_x[j]+2,5+2,31-5,29-5,21+j+BT_HIDE,NULL);
  570.         for (j=3; j<6; j++) DefineButton(toolbar_buttons_x[j],5,31,29,21+j+BT_HIDE,NULL);
  571.         DrawBar(246,0, Form.cwidth - 246, 34, col_work);
  572.         _PutImage(Form.cwidth-17,11,6,18,#dots);
  573.         DefineButton(Form.cwidth-24,7,20,25,51+BT_HIDE+BT_NOFRAME,0); //dots
  574.         //main rectangles
  575.         DrawRectangle(1,40,Form.cwidth-3,Form.cheight - 42-status_bar_h,col_graph);
  576.         DrawRectangle(0,39,Form.cwidth-1,Form.cheight - 40,col_palette[4]); //bg
  577.         for (i=0; i<5; i++) DrawBar(0, 34+i, Form.cwidth, 1, col_palette[8-i]);
  578.         llist_copy(#files_active, #files);
  579.         strcpy(#active_path, #path);
  580.         DrawStatusBar();
  581.         if (selected_count==0) Open_Dir(#path,ONLY_OPEN); //if there are no selected files -> refresh folder [L001]
  582.         DrawFilePanels();
  583.         if (del_active) Del_Form();
  584.         if (new_element_active) NewElement_Form(new_element_active, #new_element_name);
  585. }
  586.  
  587. void DrawList()
  588. {
  589.         word sorting_arrow_x;
  590.         DrawFlatButtonSmall(files.x, files.y-17,     files.w - 141,16,31,T_FILE);
  591.         DrawFlatButtonSmall(files.x + files.w - 141, files.y-17,73,16,32,T_TYPE);
  592.         DrawFlatButtonSmall(files.x + files.w -  68, files.y-17,68,16,33,T_SIZE);
  593.         DrawFlatButtonSmall(files.x + files.w,       files.y-17,16,16, 0,"\x18");
  594.         DrawFlatButtonSmall(files.x + files.w,files.y+files.h-16,16,16,0,"\x19");
  595.         if (sort_num==1) sorting_arrow_x = files.w - 141 / 2 + files.x + 18;
  596.         if (sort_num==2) sorting_arrow_x = files.x + files.w - 90;
  597.         if (sort_num==3) sorting_arrow_x = strlen(T_SIZE)*3-30+files.x+files.w;
  598.         WriteText(sorting_arrow_x,files.y-12,0x80,col_graph,"\x19");
  599.         DrawBar(files.x+files.w,files.y,1,files.h,col_graph);
  600.         if (two_panels) && (files.x<5) DrawBar(files.x+files.w+16,files.y,1,files.h,col_graph);
  601. }
  602.  
  603. void DrawStatusBar()
  604. {
  605.         char status_bar_str[80];
  606.         int go_up_folder_exists=0;
  607.         if (!show_status_bar) return;
  608.         if (files.count>0) && (strcmp(file_mas[0]*304+buf+72,"..")==0) go_up_folder_exists=1;
  609.         DrawBar(1, Form.cheight - status_bar_h-1, Form.cwidth-2,  status_bar_h, system.color.work);
  610.         sprintf(#status_bar_str, STATUS_STR, files.count-go_up_folder_exists, count_dir-go_up_folder_exists, files.count-count_dir, selected_count);
  611.         WriteText(6,Form.cheight - 13,0x80,system.color.work_text,#status_bar_str);
  612. }
  613.  
  614. void DrawFilePanels()
  615. {
  616.         int files_y;
  617.         if (!two_panels)
  618.         {
  619.                 DrawDeviceAndActionsLeftPanel();
  620.                 files.SetSizes(192, 57, Form.cwidth - 210, Form.cheight - 59 - status_bar_h, files.item_h);
  621.                 DrawList();
  622.                 Open_Dir(#path,ONLY_SHOW);
  623.         }
  624.         else
  625.         {
  626.                 SystemDiscs.Get();
  627.                 llist_copy(#files, #files_inactive);
  628.                 strcpy(#path, #inactive_path);
  629.                 col_selec = 0xCCCccc;
  630.                 SystemDiscs.Draw();
  631.                 files_y = files.y;
  632.  
  633.                 if (active_panel==1)
  634.                 {
  635.                         llist_copy(#files, #files_inactive);
  636.                         strcpy(#path, #inactive_path);
  637.                         col_selec = 0xCCCccc;
  638.                         files.SetSizes(Form.cwidth/2, files_y, Form.cwidth/2 -17, Form.cheight-files_y-2 - status_bar_h, files.item_h);
  639.                         DrawList();
  640.                         Open_Dir(#path,WITH_REDRAW);
  641.                         llist_copy(#files, #files_active);
  642.                         strcpy(#path, #active_path);
  643.                         col_selec = 0x94AECE;
  644.                         files.SetSizes(2, files_y, Form.cwidth/2-2-17, Form.cheight-files_y-2 - status_bar_h, files.item_h);
  645.                         DrawList();
  646.                         Open_Dir(#path,WITH_REDRAW);
  647.                 }
  648.                 if (active_panel==2)
  649.                 {
  650.                         files.SetSizes(2, files_y, Form.cwidth/2-2-17, Form.cheight-files_y-2 - status_bar_h, files.item_h);
  651.                         DrawList();
  652.                         Open_Dir(#path,WITH_REDRAW);
  653.                         llist_copy(#files, #files_active);
  654.                         strcpy(#path, #active_path);
  655.                         col_selec = 0x94AECE;
  656.                         files.SetSizes(Form.cwidth/2, files_y, Form.cwidth/2 -17, Form.cheight-files_y-2 - status_bar_h, files.item_h);
  657.                         DrawList();
  658.                         Open_Dir(#path,WITH_REDRAW);
  659.                 }
  660.         }
  661. }
  662.  
  663.  
  664. void List_ReDraw()
  665. {
  666.         int all_lines_h;
  667.         static int old_cur_y, old_first;
  668.  
  669.         files.CheckDoesValuesOkey(); //prevent some shit
  670.  
  671.         if (list_full_redraw) || (old_first != files.first)
  672.         {
  673.                 old_cur_y = files.cur_y;
  674.                 old_first = files.first;
  675.                 list_full_redraw = false;
  676.                 goto _ALL_LIST_REDRAW;
  677.         }
  678.         if (old_cur_y != files.cur_y)
  679.         {
  680.                 if (old_cur_y-files.first<files.visible) Line_ReDraw(0xFFFFFF, old_cur_y-files.first);
  681.                 Line_ReDraw(col_selec, files.cur_y-files.first);
  682.                 old_cur_y = files.cur_y;
  683.                 return;
  684.         }
  685.  
  686.         _ALL_LIST_REDRAW:
  687.  
  688.         for (j=0; j<files.visible; j++) if (files.cur_y-files.first!=j) Line_ReDraw(0xFFFFFF, j); else Line_ReDraw(col_selec, files.cur_y-files.first);
  689.         //in the bottom
  690.         all_lines_h = j * files.item_h;
  691.         DrawBar(files.x,all_lines_h + files.y,files.w,files.h - all_lines_h,0xFFFFFF);
  692.         DrawBar(files.x+files.w-141,all_lines_h + files.y,1,files.h - all_lines_h,col_list_line);
  693.         DrawBar(files.x+files.w-68,all_lines_h + files.y,1,files.h - all_lines_h,col_list_line);
  694.         Scroll();
  695. }
  696.  
  697.  
  698. void Line_ReDraw(dword bgcol, filenum){
  699.         dword text_col=0,
  700.                   ext1, attr,
  701.                   file_offet,
  702.                   file_name_off,
  703.                   y=filenum*files.item_h+files.y,
  704.                   icon_y = files.item_h-icon_size/2+1+y;
  705.                   BDVK file;
  706.                   char temp_path[sizeof(file_path)];
  707.         char label_file_name[4096];
  708.         if (filenum==-1) return;
  709.         DrawBar(files.x,y,4,files.item_h,bgcol);
  710.         DrawBar(files.x+20,y,files.w-20,files.item_h,bgcol);
  711.         DrawBar(files.x+4,y,icon_size,icon_y-y,bgcol);
  712.         if (files.item_h>icon_size) DrawBar(files.x+4,icon_y+icon_size-1,icon_size,y+files.item_h-icon_y-icon_size+1,bgcol);
  713.  
  714.         file_offet = file_mas[filenum+files.first]*304 + buf+32;
  715.         attr = ESDWORD[file_offet];
  716.         file.selected = ESBYTE[file_offet+7];
  717.         file.sizelo   = ESDWORD[file_offet+32];
  718.         file.sizehi   = ESDWORD[file_offet+36];
  719.         file_name_off = file_offet+40;
  720.  
  721.         if (! TestBit(attr, 4) ) //file or folder?
  722.         {      
  723.                 ext1 = strrchr(file_name_off,'.') + file_name_off;
  724.                 if (ext1==file_name_off) ext1 = NULL; //if no extension then show nothing
  725.                 WriteText(
  726.                         7-strlen(ConvertSize64(file.sizelo, file.sizehi))*6+files.x+files.w - 58,
  727.                         files.text_y+y+1,
  728.                         files.font_type,
  729.                         0,
  730.                         ConvertSize64(file.sizelo, file.sizehi)
  731.                 );
  732.                 if (ext1) && (strlen(ext1)<9) WriteTextCenter(files.x+files.w-140, files.text_y+y+1, 72, 0, ext1);
  733.         }
  734.         else
  735.         {
  736.                 if (!strcmp(file_name_off,"..")) ext1="<up>"; else {
  737.                         ext1="<DIR>";
  738.                         WriteTextCenter(files.x+files.w-140, files.text_y+y+1, 72, 0, ext1);
  739.                 }
  740.         }
  741.         sprintf(#temp_path,"%s/%s",#path,file_name_off);
  742.         DrawIconByExtension(#temp_path, ext1, files.x+4, icon_y, bgcol);
  743.  
  744.         if (TestBit(attr, 1)) || (TestBit(attr, 2)) text_col=0xA6A6B7; //system or hiden?
  745.         if (bgcol!=0xFFFfff)
  746.         {
  747.                 itdir = TestBit(attr, 4);
  748.                 strcpy(#file_name, file_name_off);
  749.                 if (!strcmp(#path,"/")) sprintf(#file_path,"%s%s",#path,file_name_off);
  750.                         else sprintf(#file_path,"%s/%s",#path,file_name_off);
  751.                 if (text_col==0xA6A6B7) text_col=0xFFFFFF;
  752.         }
  753.         if (file.selected) text_col=0xFF0000;
  754.         if (kfont.size.pt==9) || (!kfont.font)
  755.         {
  756.                 if (Form.width>=480)
  757.                 {
  758.                         FileShow.start_x = files.x + 23;
  759.                         FileShow.font_color = text_col;
  760.                         FileShow.area_size_x = files.w - 164;
  761.                         FileShow.text_pointer = file_name_off;
  762.                         FileShow.start_y = files.text_y + y - 3;
  763.                         PathShow_prepare stdcall(#FileShow);
  764.                         PathShow_draw stdcall(#FileShow);
  765.                 }              
  766.         }
  767.         else
  768.         {
  769.                 strcpy(#label_file_name, file_name_off);
  770.                 if (kfont.getsize(kfont.size.pt, #label_file_name) + 141 + 26 > files.w)
  771.                 {
  772.                         while (kfont.getsize(kfont.size.pt, #label_file_name) + 141 + 26 > files.w) {
  773.                                 ESBYTE[#label_file_name+strlen(#label_file_name)-1] = NULL;
  774.                         }
  775.                         strcpy(#label_file_name+strlen(#label_file_name)-2, "...");                    
  776.                 }
  777.                 kfont.WriteIntoWindow(files.x + icon_size+7, files.item_h - kfont.height / 2 + y, bgcol, text_col, kfont.size.pt, #label_file_name);
  778.         }
  779.         DrawBar(files.x+files.w-141,y,1,files.item_h,col_list_line); //gray line 1
  780.         DrawBar(files.x+files.w-68,y,1,files.item_h,col_list_line); //gray line 2
  781. }
  782.  
  783.  
  784. void Open_Dir(dword dir_path, redraw){
  785.         int errornum, maxcount, i;
  786.         if (redraw!=ONLY_SHOW)
  787.         {
  788.                 selected_count = 0;
  789.                 if (buf) free(buf);
  790.                 errornum = GetDir(#buf, #files.count, dir_path, DIRS_NOROOT);
  791.                 if (errornum)
  792.                 {
  793.                         history.add(#path);
  794.                         GoBack();
  795.                         Write_Error(errornum);
  796.                         return;
  797.                 }
  798.                 maxcount = sizeof(file_mas)/sizeof(dword)-1;
  799.                 if (files.count>maxcount) files.count = maxcount;
  800.                 if (files.count>0) && (files.cur_y-files.first==-1) files.cur_y=0;
  801.         }
  802.         if (files.count!=-1)
  803.         {
  804.                 if(!_not_draw) if (show_breadcrumb) DrawBreadCrumbs(); else DrawPathBar();
  805.                 history.add(#path);
  806.                 SystemDiscs.Draw();
  807.                 files.visible = files.h / files.item_h;
  808.                 if (files.count < files.visible) files.visible = files.count;
  809.                 if (redraw!=ONLY_SHOW) Sorting();
  810.                 list_full_redraw = true;
  811.                 if (redraw!=ONLY_OPEN)&&(!_not_draw) {DrawStatusBar(); List_ReDraw();}
  812.                 SetCurDir(dir_path);
  813.         }
  814.         if (files.count==-1) && (redraw!=ONLY_OPEN)
  815.         {
  816.                 files.KeyHome();
  817.                 if(!_not_draw) { list_full_redraw=true; DrawStatusBar(); List_ReDraw(); }
  818.         }
  819. }
  820.  
  821.  
  822. inline Sorting()
  823. {
  824.         dword k=0, l=1;
  825.         dword file_off;
  826.         if (!strcmp(#path,"/")) //do not sort root folder
  827.         {
  828.                 for(k=1;k<files.count;k++;) file_mas[k]=k;
  829.                 count_dir = k;
  830.                 return;
  831.         }
  832.         for (j=files.count-1, file_off=files.count-1*304+buf+32; j>=0; j--, file_off-=304;)  //files | folders
  833.         {
  834.                 if (!real_files_names_case) strttl(file_off+40);
  835.                 if (TestBit(ESDWORD[file_off],4)) //directory?
  836.                 {
  837.                         file_mas[k]=j;
  838.                         k++;
  839.                 }
  840.                 else
  841.                 {
  842.                         file_mas[files.count-l]=j;
  843.                         l++;
  844.                 }
  845.         }
  846.         count_dir = k;
  847.         //sorting: files first, then folders
  848.         Sort_by_Name(0,k-1);
  849.         if (sort_num==1) Sort_by_Name(k,files.count-1);
  850.         if (sort_num==2) Sort_by_Type(k,files.count-1);
  851.         if (sort_num==3) Sort_by_Size(k,files.count-1);
  852.         //make ".." first item in list
  853.         if (k>0) && (strncmp(file_mas[0]*304+buf+72,"..",2)!=0)
  854.                 for(k--; k>0; k--;) if (!strncmp(file_mas[k]*304+buf+72,"..",2)) {file_mas[k]><file_mas[0]; break;}
  855. }
  856.  
  857.  
  858. void Del_Form()
  859. {
  860.         byte f_count[128];
  861.         int dform_x = files.w - 220 / 2 + files.x;
  862.         if (selected_count==0) && (!strncmp(#file_name,"..",2)) return;
  863.         else
  864.         {
  865.                 if (!files.count) return;
  866.                 DrawEolitePopup(T_YES, T_NO);
  867.                 WriteText(-strlen(T_DELETE_FILE)*3+110+dform_x,175,0x80,system.color.work_text,T_DELETE_FILE);
  868.                 if (selected_count)
  869.                 {
  870.                         sprintf(#f_count,"%s%d%s",DEL_MORE_FILES_1,selected_count,DEL_MORE_FILES_2);
  871.                         WriteText(-strlen(#f_count)*3+110+dform_x,190,0x80,system.color.work_text,#f_count);
  872.                 }
  873.                 else
  874.                 {
  875.                         if (strlen(#file_name)<28)
  876.                         {
  877.                                 WriteText(strlen(#file_name)*3+110+dform_x+2,190,0x80,system.color.work_text,"?");
  878.                                 WriteText(-strlen(#file_name)*3+110+dform_x,190,0x80,system.color.work_text,#file_name);
  879.                         }
  880.                         else
  881.                         {
  882.                                 WriteText(164+dform_x,190,0x80,0,"...?");
  883.                                 ESI = 24;
  884.                                 WriteText(dform_x+20,190,0,0,#file_name);
  885.                         }
  886.                 }              
  887.                 del_active=1;
  888.         }
  889. }
  890.  
  891. void SelectFileByName(dword that_file)
  892. {
  893.         int ind;
  894.         files.KeyHome();
  895.         Open_Dir(#path,ONLY_OPEN);
  896.         if (!real_files_names_case) strttl(that_file);
  897.         for (ind=files.count-1; ind>=0; ind--;) { if (!strcmp(file_mas[ind]*304+buf+72,that_file)) break; }
  898.         files.cur_y = ind - 1;
  899.         files.KeyDown();
  900.         DrawStatusBar();
  901.         List_ReDraw();
  902. }
  903.  
  904.  
  905. void Dir_Up()
  906. {
  907.         char old_folder_name[4096];
  908.         i=strlen(#path)-1;
  909.         if (i==0) return;
  910.         //path[i]=0x00;
  911.         i = strrchr(#path, '/');
  912.         strcpy(#old_folder_name, #path+i);
  913.         if (i>1) path[i-1]=NULL; else path[i]=NULL;
  914.         SelectFileByName(#old_folder_name);
  915. }
  916.  
  917. void Open(byte rez)
  918. {
  919.         byte temp[4096];
  920.         selected_count = 0;
  921.         if (rez)
  922.         {
  923.                 if (!strncmp(#file_name,"..",3)) return;
  924.                 strcpy(#temp, #file_path);
  925.                 RunProgram(I_Path, #temp);
  926.                 return;
  927.         }
  928.         if (!files.count) return;
  929.         if (!itdir)
  930.         {
  931.                 if (strrchr(#file_name, '.')==0) RunProgram(#file_path, ""); else RunProgram("/sys/@open", #file_path);
  932.         }
  933.         else
  934.         {
  935.                 if (!strncmp(#file_name,"..",3)) { Dir_Up(); return; }
  936.                 strcpy(#path, #file_path);
  937.                 files.first=files.cur_y=0;
  938.                 Open_Dir(#path,WITH_REDRAW);
  939.         }
  940. }
  941.  
  942. inline fastcall void GoBack()
  943. {
  944.         char cur_folder[4096];
  945.         strcpy(#cur_folder, #path);
  946.         if (history.back()) {
  947.                 strcpy(#path, history.current());
  948.                 SelectFileByName(#cur_folder+strrchr(#cur_folder,'/'));
  949.         }
  950. }
  951.  
  952. void ShowOpenWithDialog()
  953. {
  954.         byte open_param[4097];
  955.         sprintf(#open_param,"~%s",#file_path);
  956.         RunProgram("/sys/@open", #open_param);
  957. }
  958.  
  959. void NewElement(byte newf)
  960. {
  961.         BDVK element_info;
  962.         byte del_rezult, copy_rezult, info_result;
  963.         if (newf)
  964.         {
  965.                 sprintf(#temp,"%s/%s",#path,new_file_ed.text);
  966.                 info_result = GetFileInfo(#temp, #element_info);
  967.                 switch(new_element_active)
  968.                 {
  969.                         case CREATE_FILE:
  970.                                 if (info_result==5)
  971.                                 {
  972.                                         CreateFile(0, 0, #temp);
  973.                                         if (EAX)
  974.                                         {
  975.                                                 if (EAX==5) notify(NOT_CREATE_FILE);
  976.                                                 else Write_Error(EAX);
  977.                                         }
  978.                                 }
  979.                                 else
  980.                                 {
  981.                                         notify(FS_ITEM_ALREADY_EXISTS);
  982.                                 }
  983.                                 break;
  984.                         case CREATE_FOLDER:
  985.                                 if (info_result==5)
  986.                                 {
  987.                                         CreateDir(#temp);
  988.                                         if (EAX)
  989.                                         {
  990.                                                 if (EAX==5) notify(NOT_CREATE_FOLDER);
  991.                                                 else Write_Error(EAX);
  992.                                         }
  993.                                 }
  994.                                 else
  995.                                 {
  996.                                         notify(FS_ITEM_ALREADY_EXISTS);
  997.                                 }
  998.                                 break;
  999.                         case RENAME_ITEM:
  1000.                                 if (info_result==5)
  1001.                                 {
  1002.                                         if (itdir)
  1003.                                         {
  1004.                                                 //rename only empty folders
  1005.                                                 if (del_rezult = DeleteFile(#file_path))
  1006.                                                 {
  1007.                                                         Write_Error(del_rezult);
  1008.                                                         return;
  1009.                                                 }
  1010.                                                 if (CreateDir(#temp)) CreateDir(#file_path);
  1011.                                                 Open_Dir(#path,WITH_REDRAW);
  1012.                                                 SelectFileByName(new_file_ed.text);
  1013.                                         }
  1014.                                         else
  1015.                                         {
  1016.                                                 if (copy_rezult = CopyFile(#file_path,#temp))
  1017.                                                 {
  1018.                                                         Write_Error(copy_rezult);
  1019.                                                 }
  1020.                                                 else
  1021.                                                 {
  1022.                                                         DeleteFile(#file_path);
  1023.                                                         SelectFileByName(new_file_ed.text);
  1024.                                                 }
  1025.                                         }
  1026.                                 }
  1027.                                 else
  1028.                                 {
  1029.                                         notify(FS_ITEM_ALREADY_EXISTS);
  1030.                                 }
  1031.                 }
  1032.                 new_element_active = 0;
  1033.                 Open_Dir(#path,WITH_REDRAW);
  1034.                 SelectFileByName(new_file_ed.text);
  1035.         }
  1036.         new_element_active = 0;
  1037.         Open_Dir(#path,WITH_REDRAW);
  1038. }
  1039.  
  1040. void NewElement_Form(byte crt, dword strng)
  1041. {
  1042.         int dform_x=files.w-220/2+files.x;
  1043.         if (!new_element_active)
  1044.         {
  1045.                 new_element_active = crt;
  1046.                 strcpy(#new_element_name, strng);
  1047.                 new_file_ed.size = new_file_ed.pos = strlen(strng);
  1048.         }
  1049.         if (new_element_active==3) DrawEolitePopup(T_RENAME, T_CANCEL);
  1050.         else DrawEolitePopup(T_CREATE, T_CANCEL);
  1051.         new_file_ed.left = dform_x+10;
  1052.         DrawEditBox(#new_file_ed);
  1053. }
  1054.  
  1055. void FnProcess(byte N)
  1056. {
  1057.         switch(N)
  1058.         {
  1059.                 case 1:
  1060.                         if (!active_about)
  1061.                         {
  1062.                                 about_stak = malloc(4096);
  1063.                                 about_window = CreateThread(#about_dialog,about_stak+4092);
  1064.                                 break;
  1065.                         }
  1066.                         else
  1067.                         {
  1068.                                 ActivateWindow(GetProcessSlot(about_window));
  1069.                         }
  1070.                         break;
  1071.                 case 2:
  1072.                         if (!files.count) break;
  1073.                         NewElement_Form(RENAME_ITEM, #file_name);
  1074.                         break;
  1075.                 case 3:
  1076.                         if (!itdir) RunProgram("/sys/tinypad", #file_path);
  1077.                         break;
  1078.                 case 4:
  1079.                         if (!itdir) RunProgram("/sys/develop/heed", #file_path);
  1080.                         break;
  1081.                 case 5: //refresh cur dir & devs
  1082.                         if (two_panels)
  1083.                         {
  1084.                                 DrawFilePanels();
  1085.                         }
  1086.                         else
  1087.                         {
  1088.                                 Tip(56, T_DEVICES, 55, "-");
  1089.                                 Open_Dir(#path,WITH_REDRAW);
  1090.                                 pause(10);
  1091.                                 SystemDiscs.Get();
  1092.                                 Open_Dir(#path,WITH_REDRAW);
  1093.                                 DrawDeviceAndActionsLeftPanel();                               
  1094.                         }
  1095.                         break;
  1096.                 case 6:
  1097.                         NewElement_Form(CREATE_FOLDER, T_NEW_FOLDER);
  1098.                         break;
  1099.                 case 7:
  1100.                         NewElement_Form(CREATE_FILE, T_NEW_FILE);
  1101.                         break;
  1102.                 case 8:
  1103.                         properties_stak = malloc(8096);
  1104.                         CreateThread(#properties_dialog, properties_stak+8092);
  1105.                         break;
  1106.                 case 10: //F10
  1107.                         if (!active_settings)
  1108.                         {
  1109.                                 settings_stak = malloc(4096);
  1110.                                 settings_window = CreateThread(#settings_dialog, settings_stak+4092);
  1111.                                 break;
  1112.                         }
  1113.                         else
  1114.                         {
  1115.                                 ActivateWindow(GetProcessSlot(settings_window));
  1116.                         }
  1117.                         break;
  1118.         }
  1119. }
  1120.  
  1121. void ChangeActivePanel()
  1122. {
  1123.         llist_copy(#files_active, #files_inactive);
  1124.         llist_copy(#files_inactive, #files);
  1125.         strcpy(#active_path, #inactive_path);
  1126.         strcpy(#inactive_path, #path);
  1127.         DrawFilePanels();
  1128. }
  1129.  
  1130.  
  1131. stop:
  1132.