home *** CD-ROM | disk | FTP | other *** search
/ Delphi 2 - Developers' Solutions / Delphi 2 Developers' Solutions.iso / dds / chap02 / howto07 / delphi10 / drwsutl2.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  1995-10-13  |  76.0 KB  |  2,025 lines

  1. unit Drwsutl2;
  2.  
  3. interface
  4.  
  5. uses
  6.   SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics, Controls,
  7.   Forms, Dialogs, StdCtrls, Buttons, ExtCtrls, ShellAPI, FileCtrl, DRWSUtl1;
  8.  
  9. const
  10.   EOC_CHANGEDIR = 1;  { Error Operation Code for change directory failure }
  11.   EOC_SOURCECOPY = 2; { Error Operation Code for source copy failure      }
  12.   EOC_DESTCOPY = 3;   { Error Operation Code for destination copy failure }
  13.   EOC_DELETEFILE = 4; { Error Operation Code for file delete failure      }
  14.   EOC_DELETEDIR = 5;  { Error Operation Code for directory delete failure }
  15.   EOC_RENAMEFILE = 6; { Error Operation Code for renaming failure         }
  16.   EOC_MAKEDIR = 7;    { Error Operation Code for MkDir failure            }
  17.   EOC_SETATTR = 8;    { Error Operation Code for Set Attributes failure   }
  18.  
  19.   FAC_COPY = 1;       { File Action Code for recursive copying            }
  20.   FAC_MOVE = 2;       { File Action Code for recursive moving             }
  21.   FAC_DELETE = 3;     { File Action Code for recursive deletion           }
  22. type
  23.   { This is a descendant of TFileListbox }
  24.   { Which puts icons of files into the   }
  25.   { Objects array rather than the stand- }
  26.   { ard bitmaps.                         }
  27.   TIconFileListBox = class( TFileListBox )
  28.   public
  29.     { public methods and data }
  30.     procedure ReadFileNames; override;
  31.     function GetNextSelection( SourceDirectory : String;
  32.               var CurrentItem : Integer ) : String;
  33.   end;
  34.   TFileWorkBench = class( TComponent )
  35.   public
  36.     GlobalError        : Integer;  { This is used by FMXUCopyFile for er code }
  37.     GlobalErrorType    : Integer;  { This holds the Operation code            }
  38.     function ForceTrailingBackSlash( const TheFileName : String ) : String;
  39.     function StripNonRootTrailingBackSlash(
  40.               const TheFileName : String ) : String;
  41.     procedure GetFileAttributes( TheFile : String; var IsDirectory , IsArchive ,
  42.                 IsVolumeID , IsHidden , IsReadOnly , IsSysFile : Boolean );
  43.     procedure HandleIOException( TheOpCode : Integer; ThePath : String;
  44.                                  TheMessage : String; TheCode : Integer );
  45.     procedure HandleDOSError( TheOpCode : Integer; ThePath : String;
  46.                 TheCode : Integer );
  47.     procedure FMXUCopyFile(const FileName, DestName: String);
  48.     function CopyFile( TargetPath ,
  49.                DestinationPath : String ) : Boolean;
  50.     procedure ChangeTheDirectory( NewPath : String );
  51.     procedure ChangeTheDriveAndDirectory( NewDrive : Integer );
  52.     procedure CopyTheFile( OldPath , NewPath : String );
  53.     procedure MoveTheFile( OldPath , NewPath : String );
  54.     procedure DeleteTheFile( ThePath : String );
  55.     procedure RenameTheFile( OldPath , NewName : String );
  56.     procedure CreateNewDirectory( NewPath : String );
  57.     procedure RemoveDirectory( ThePath : String );
  58.     procedure RecursivelyCopyDirectory( OldPath , NewPath : String );
  59.     procedure RecursivelyMoveDirectory( OldPath , NewPath : String );
  60.     procedure RecursivelyDeleteDirectory( ThePath : String );
  61.     procedure HandleRecursiveAction( StartingPath , NewPath : String;
  62.                ActionCode : Integer );
  63.   end;
  64.   TFileIconPanel = class( TPanel )
  65.   private
  66.     { Private declarations }
  67.     FHighlightColor : TColor;                 { This holds bright edge bevel }
  68.     FShadowColor    : TColor;                 { This holds dark edge bevel   }
  69.     procedure TheClick( Sender : TObject );   { This holds override click    }
  70.     procedure TheDblClick( Sender : TObject );{ This holds override dblclick }
  71.   protected                                   { event method procedure.      }
  72.     { Protected declarations }
  73.     procedure Paint; override;                { This allows custom painting  }
  74.   public
  75.     { Public declarations }
  76.     FTheIcon : TIcon;                         { This is the display icon    }
  77.     FTheName : String;                        { This is the filename        }
  78.     FTheLabel : TLabel;                       { This is the display label   }
  79.     Selected : Boolean;                       { This holds selection status }
  80.     constructor Create(AOwner : TComponent); override; { override create    }
  81.     procedure Initialize( PanelX              ,             { Left          }
  82.                           PanelY              ,             { Top           }
  83.                           PanelWidth          ,             { Width         }
  84.                           PanelHeight         ,             { Height        }
  85.                           PanelBevelWidth     ,             { Bevel Width   }
  86.                           LabelFontSize         : Integer;  { Font size     }
  87.                           PanelColor          ,             { Main color    }
  88.                           PanelHighlightColor ,             { Bright color  }
  89.                           PanelShadowColor    ,             { Dark color    }
  90.                           LabelTextColor        : TColor;   { Text color    }
  91.                           TheFilename         ,             { Filename      }
  92.                           LabelFontName         : String;   { Font name     }
  93.                           LabelFontStyle        : TFontStyles;  { Font style}
  94.                           ExtraData             : Integer       );  { Drive }
  95.     destructor Destroy; override;             { override destroy to free    }
  96.   end;
  97.   TFileIconPanelScrollBox = class( TScrollBox )
  98.   public
  99.     { Public methods and data }
  100.     TheFWB              : TFileWorkBench; { Used for file manipulation         }
  101.     IconsNeedRefreshing : Boolean;                   { Flag to redo display    }
  102.     TheIconSize        : Integer;   { Holds Individual Icon size               }
  103.     TheIconSpacing     : Integer;   { Holds total icon footprint               }
  104.     MaxIconsInARow     : Integer;   { Set for screen size.                     }
  105.     TheStoredHandle    : HWnd;
  106.     procedure Update;                                { Called to reset display }
  107.     constructor Create( AOwner : TComponent ); override;  { Override inherited }
  108.     procedure ClearTheFIPs;                          { Clears the FIPs safely  }
  109.     procedure AddDriveIcons( var XCounter , YCounter : Integer ); { Add drives }
  110.     procedure GetColorsForFileIcon( TheFile : String;
  111.                var BC , HC , SC , TC : TColor );
  112.     procedure GetIconsForEntireDirectory( TargetPath  : String );
  113.     function GetNextSelection( SourceDirectory : String;
  114.               var CurrentItem : Integer ) : String;
  115.     procedure DisplayRecursiveSearchResults(
  116.       TheStartingDirectory : String );
  117.   end;
  118.  
  119.   { This procedure gets an icon for a file using FindExecutable  }
  120.   { and ExtractIcon. (assumes file/dir is passed)                }
  121.   procedure GetIconForFile( TheName : String; var TheIcon : TIcon );
  122.   { This procedure spaces out the bitbtn components on a tpanel }
  123.   procedure SpacePanelButtons( WhichPanel : TPanel );
  124.  
  125. implementation
  126. {$R DRWSUTL2.RES}                 { Import custom resource file }
  127.  
  128. { This procedure spaces out the bitbtn components on a tpanel }
  129. procedure SpacePanelButtons( WhichPanel : TPanel );
  130. var TheCalculatedSpacing     ,            { Holds primary spacing }
  131.     TheFullCalculatedSpacing   : Integer; { Holds full spacing    }
  132.     Counter_1                  : Integer; { Loop counter          }
  133.     TotalIBs                   : Integer; { Gets total buttons    }
  134. begin
  135.   { Set up spacing values }
  136.   TotalIBs := WhichPanel.ControlCount;
  137.   TheCalculatedSpacing := (( WhichPanel.Width - 6 - ( TotalIbs * 49 ))
  138.    div ( TotalIbs + 1 ));
  139.   TheFullCalculatedSpacing := TheCalculatedSpacing + 49;
  140.   { Loop through all imported buttons and set their Left values }
  141.   for Counter_1 := 1 to WhichPanel.ControlCount do
  142.   begin
  143.     if Counter_1 = 1 then
  144.     begin
  145.       TBitBtn( WhichPanel.Controls[ Counter_1 - 1 ] ).Left := 3 +
  146.        TheCalculatedSpacing;
  147.     end
  148.     else
  149.     begin
  150.       TBitBtn( WhichPanel.Controls[ Counter_1 - 1 ] ).Left := 3 +
  151.        (( Counter_1 - 1 ) * TheFullCalculatedSpacing ) + TheCalculatedSpacing;
  152.     end;
  153.   end;
  154. end;
  155.  
  156. { This procedure gets an icon for a file using FindExecutable  }
  157. { and ExtractIcon. (assumes file/dir is passed)                }
  158. procedure GetIconForFile( TheName : String; var TheIcon : TIcon );
  159. var TheExt           : String; { File extension holder }
  160.     TheOtherPChar  ,           { Windows ASCIIZ string }
  161.     TheResultPChar ,           { Windows ASCIIZ string }
  162.     ThePChar         : PChar;  { Windows ASCIIZ string }
  163. begin
  164.   { Check for directory and if so get directory icon from RES file }
  165.   if (( FileGetAttr( TheName ) and faDirectory ) = faDirectory ) then
  166.   begin
  167.     { Set up the PChar to communicate with Windows }
  168.     GetMem( TheOtherPChar , 255 );
  169.     { Convert Pascal-style string to ASCIIZ Pchar }
  170.     StrPCopy( TheOtherPChar , 'DIRECTORY' );
  171.     { Use API call to return icon handle of Icon Resource in FILECTRL.RES }
  172.     TheIcon.Handle := LoadIcon( hInstance , TheOtherPChar );
  173.     { Release memory from PChar }
  174.     FreeMem( TheOtherPChar , 255 );
  175.     { Leave }
  176.     exit;
  177.   end;
  178.   { Assume archive file; get its extension }
  179.   TheExt := Uppercase( ExtractFileExt( TheName ));
  180.   { If not an executable/image file then use FindExecutable to get icon }
  181.   if (( TheExt <> '.EXE' ) and ( TheExt <> '.BAT' ) and
  182.       ( TheExt <> '.PIF' ) and ( TheExt <> '.COM' )) then
  183.   begin
  184.     { Grab three chunks of memory }
  185.     GetMem( TheOtherPChar , 255 );
  186.     GetMem( TheResultPChar , 255 );
  187.     GetMem( ThePChar , 255 );
  188.     { Set up the name and its directory in Windows string formats }
  189.     StrPCopy( ThePChar, TheName );
  190.     StrPCopy( TheOtherPChar , ExtractFilePath( TheName ));
  191.     { Use FindExecutable API call to get path and name of owning file }
  192.     if FindExecutable( ThePChar , TheOtherPChar , TheResultPChar ) > 31 then
  193.     begin
  194.       { If get a result of 32 or more then try to get first icon of owner }
  195.       { Using ExtractIcon API call; 0 indicates first icon.               }
  196.       TheIcon.Handle := ExtractIcon( hInstance , TheResultPchar , 0 );
  197.       { If a handle is 0 then no icon in owner, get default icon from RES file }
  198.       if TheIcon.Handle = 0 then
  199.       begin
  200.         GetMem( TheOtherPChar , 255 );
  201.         StrPCopy( TheOtherPChar , 'NOICON' );
  202.         TheIcon.Handle := LoadIcon( hInstance , TheOtherPChar );
  203.         FreeMem( TheOtherPChar , 255 );
  204.         exit;
  205.       end;
  206.     end
  207.     else
  208.     { if no assigned executable, then get default icon from RES file }
  209.     begin
  210.       GetMem( TheOtherPChar , 255 );
  211.       StrPCopy( TheOtherPChar , 'NOICON' );
  212.       TheIcon.Handle := LoadIcon( hInstance , TheOtherPChar );
  213.       FreeMem( TheOtherPChar , 255 );
  214.       exit;
  215.     end;
  216.     FreeMem( TheOtherPChar , 255 );
  217.     FreeMem( TheResultPChar , 255 );
  218.     FreeMem( ThePChar , 255 );
  219.   end
  220.   else
  221.   { Assume Windows Executable file, so get icon from it with ExtractIcon API }
  222.   begin
  223.     GetMem( ThePChar , 255 );
  224.     StrPCopy( ThePChar , TheName );
  225.     { If no icons in file then get default icon (note use FFFF for -1) }
  226.     if ExtractIcon( hInstance , ThePchar , 65535 ) = 0 then
  227.     begin
  228.       Freemem( ThePChar , 255 );
  229.       GetMem( TheOtherPChar , 255 );
  230.       StrPCopy( TheOtherPChar , 'NOICON' );
  231.       TheIcon.Handle := LoadIcon( hInstance , TheOtherPChar );
  232.       FreeMem( TheOtherPChar , 255 );
  233.       exit;
  234.     end
  235.     else
  236.     begin
  237.       { Try to get first icon for file }
  238.       TheIcon.Handle := ExtractIcon( hInstance , ThePChar , 0 );
  239.       FreeMem( ThePChar , 255 );
  240.       { If handle is 0 invalid icon format so use default from RES file }
  241.       if TheIcon.Handle = 0 then
  242.       begin
  243.         GetMem( TheOtherPChar , 255 );
  244.         StrPCopy( TheOtherPChar , 'NOICON' );
  245.         TheIcon.Handle := LoadIcon( hInstance , TheOtherPChar );
  246.         FreeMem( TheOtherPChar , 255 );
  247.         exit;
  248.       end;
  249.     end;
  250.   end;
  251. end;
  252.  
  253. { This procedure does a fully error-trapped change directory }
  254. procedure TFileWorkBench.ChangeTheDirectory( NewPath : String );
  255. var CurrentDirectory : String;
  256. begin
  257.   if NewPath = '..' then
  258.   begin { Back up one level }
  259.     {$I+}
  260.     try
  261.       { Find the current directory }
  262.       GetDir( 0 , CurrentDirectory );
  263.       { Use EFP to move up one level }
  264.       CurrentDirectory := ExtractFilePath( CurrentDirectory );
  265.       { Strip trailing \ if not root }
  266.       CurrentDirectory := StripNonRootTrailingBackSlash( CurrentDirectory );
  267.       { Try the change to the new drive }
  268.       ChDir( CurrentDirectory );
  269.     except
  270.       { if any exception occurs instantiate exception and show }
  271.       On E:EInOutError do
  272.       begin
  273.         { Call custom error display/lookup procedure }
  274.         HandleIOException( EOC_CHANGEDIR , CurrentDirectory ,
  275.          E.Message , E.ErrorCode );
  276.       end;
  277.     end;
  278.   end
  279.   else
  280.   begin { Change to explicit path }
  281.     {$I+}
  282.     try
  283.       { Get target directory path }
  284.       CurrentDirectory := NewPath;
  285.       { Strip trailing \ if not root }
  286.       CurrentDirectory := StripNonRootTrailingBackSlash( CurrentDirectory );
  287.       { Try the change to the new drive }
  288.       ChDir( CurrentDirectory );
  289.     except
  290.       { if any exception occurs instantiate exception and show }
  291.       On E:EInOutError do
  292.       begin
  293.         { Call custom error display/lookup procedure }
  294.         HandleIOException( EOC_CHANGEDIR , CurrentDirectory ,
  295.          E.Message , E.ErrorCode );
  296.       end;
  297.     end;
  298.   end;
  299. end;
  300.  
  301. { This procedure does a fully error-trapped change directory }
  302. procedure TFileWorkBench.ChangeTheDriveAndDirectory( NewDrive : Integer );
  303. var CurrentDirectory : String;
  304. begin
  305.   {$I+}
  306.   try
  307.     { Find the working directory on new drive }
  308.     GetDir( NewDrive , CurrentDirectory );
  309.     { Try the change to the new drive }
  310.     ChDir( CurrentDirectory );
  311.   except
  312.     { if any exception occurs instantiate exception and show }
  313.     On E:EInOutError do
  314.     begin
  315.       { Call custom error display/lookup procedure }
  316.       HandleIOException( EOC_CHANGEDIR , CurrentDirectory ,
  317.        E.Message , E.ErrorCode );
  318.     end;
  319.   end;
  320. end;
  321.  
  322. { This procedure copies a single file with error trapping }
  323. procedure TFileWorkBench.CopyTheFile( OldPath , NewPath : String );
  324. var AResult : Boolean; { Internal data flag }
  325. begin
  326.   { If Copyfile returns false an error occurred }
  327.   AResult := CopyFile( OldPath , NewPath +
  328.    ExtractFileName( OldPath ));
  329.   { Display meaningful error message }
  330.   if not AResult then HandleDOSError( GlobalErrorType ,
  331.    ExtractFileName( OldPath ) , GlobalError );
  332. end;
  333.  
  334. { This procedure moves a file by copying and delete it }
  335. procedure TFileWorkBench.MoveTheFile( OldPath , NewPath : String );
  336. var AResult : Boolean; { Internal data flag }
  337.     TheFile : File;    { Use to get errors  }
  338. begin
  339.   { If Copyfile returns false an error occurred }
  340.   AResult := CopyFile( OldPath , NewPath +
  341.     ExtractFileName( OldPath ));
  342.   { Display meaningful error message }
  343.   if not AResult then HandleDOSError( GlobalErrorType ,
  344.    ExtractFileName( OldPath ), GlobalError );
  345.   { After valid copying, delete source file }
  346.   {$I+}
  347.   if AResult then try
  348.     { Use this trick to get valid exception handling }
  349.     AssignFile( TheFile , OldPath );
  350.     { Use erase because Deletefile doesn't give exceptions! }
  351.     Erase( TheFile );
  352.   except
  353.     { if any exception occurs instantiate exception and show }
  354.     On E:EInOutError do
  355.     begin
  356.       { Call custom error display/lookup procedure }
  357.       HandleIOException( EOC_DELETEFILE , ExtractFileName( OldPath ) ,
  358.        E.Message , E.ErrorCode );
  359.     end;
  360.   end;
  361. end;
  362.  
  363. { This procedure safely deletes a single file }
  364. procedure TFileWorkBench.DeleteTheFile( ThePath : String );
  365. var TheFile : File; { Internal file handle }
  366. begin
  367.   {$I+}
  368.   try
  369.     { Use this trick to get valid exception handling }
  370.     AssignFile( TheFile , ThePath );
  371.     { Use erase because Deletefile doesn't give exceptions! }
  372.     Erase( TheFile );
  373.   except
  374.     { if any exception occurs instantiate exception and show }
  375.     On E:EInOutError do
  376.     begin
  377.       { Call custom error display/lookup procedure }
  378.       HandleIOException( EOC_DELETEFILE , ExtractFileName( ThePath ) ,
  379.        E.Message , E.ErrorCode );
  380.     end;
  381.   end;
  382. end;
  383.  
  384. { This procedure renames a file with full error trapping }
  385. procedure TFileWorkBench.RenameTheFile( OldPath , NewName : String );
  386. var TheFile : File; { Internal file handle }
  387. begin
  388.   {$I+}
  389.   try
  390.     { Use this trick to get valid exception handling }
  391.     AssignFile( TheFile , OldPath );
  392.     { Use this because RenameFile doesn't give exceptions! }
  393.     Rename( TheFile , NewName );
  394.   except
  395.     { if any exception occurs instantiate exception and show }
  396.     On E:EInOutError do
  397.     begin
  398.       { Call custom error display/lookup procedure }
  399.       HandleIOException( EOC_RENAMEFILE , ExtractFileName( OldPath ) ,
  400.        E.Message , E.ErrorCode );
  401.     end;
  402.   end;
  403. end;
  404.  
  405. { This procedure creates a new directory with full error trapping }
  406. procedure TFileWorkBench.CreateNewDirectory( NewPath : String );
  407. begin
  408.   {$I+}
  409.   try
  410.     Mkdir( NewPath );
  411.   except
  412.     { if any exception occurs instantiate exception and show }
  413.     On E:EInOutError do
  414.     begin
  415.       { Call custom error display/lookup procedure }
  416.       HandleIOException( EOC_MAKEDIR , ExtractFileName( NewPath ) ,
  417.        E.Message , E.ErrorCode );
  418.     end;
  419.   end;
  420. end;
  421.  
  422. { This procedure remove a directory with full error trapping }
  423. procedure TFileWorkBench.RemoveDirectory( ThePath : String );
  424. begin
  425.   {$I+}
  426.   try
  427.     Rmdir( ThePath );
  428.   except
  429.     { if any exception occurs instantiate exception and show }
  430.     On E:EInOutError do
  431.     begin
  432.       { Call custom error display/lookup procedure }
  433.       HandleIOException( EOC_DELETEDIR , ExtractFileName( ThePath ) ,
  434.        E.Message , E.ErrorCode );
  435.     end;
  436.   end;
  437. end;
  438.  
  439. { This procedure recursively copies a directory to a new path }
  440. procedure TFileWorkBench.RecursivelyCopyDirectory( OldPath , NewPath : String );
  441. var TheDir : String; { Holds source directory }
  442. begin
  443.   { Get the source directory to copy }
  444.   TheDir := ExtractFileName( OldPath );
  445.   { Force a backslash to the newpath variable }
  446.   NewPath := ForceTrailingBackSlash( NewPath );
  447.   { Add the source directory to the target path }
  448.   NewPath := NewPath + TheDir;
  449.   { Create a new directory with the new name }
  450.   CreateNewDirectory( NewPath );
  451.   { Force a backslash for compatibility }
  452.   NewPath := FOrcetrailingBackSlash( NewPath );
  453.   { Do the recursive call }
  454.   HandleRecursiveAction( OldPath , NewPath , FAC_COPY );
  455. end;
  456.  
  457. { This procedure recursively moves a directory tree }
  458. procedure TFileWorkBench.RecursivelyMoveDirectory( OldPath , NewPath : String );
  459. var TheDir    : String; { Holds source directory  }
  460.     SavedPath : String; { Holds saved dir to kill }
  461. begin
  462.   { Get the source directory to move }
  463.   TheDir := ExtractFileName( OldPath );
  464.   { Force a backslash to the newpath variable }
  465.   NewPath := ForceTrailingBackSlash( NewPath );
  466.   { Save the starting path just in case }
  467.   SavedPath := OldPath;
  468.   { Add the source directory to the target path }
  469.   NewPath := NewPath + TheDir;
  470.   { Create a new directory with the new name }
  471.   CreateNewDirectory( NewPath );
  472.   { Force a backslash for compatibility }
  473.   NewPath := FOrcetrailingBackSlash( NewPath );
  474.   { Do the recursive call }
  475.   HandleRecursiveAction( OldPath , NewPath , FAC_MOVE );
  476.   { Remove the source directory }
  477.   RemoveDirectory( SavedPath );
  478. end;
  479.  
  480. { This procedure handles recursively deleting an entire directory tree }
  481. procedure TFileWorkBench.RecursivelyDeleteDirectory( ThePath : String );
  482. begin
  483.   HandleRecursiveAction( ThePath , '' , FAC_DELETE );
  484. end;
  485.  
  486.  
  487. { This is the generic routine to copy, move, and delete whole directory trees }
  488. procedure TFileWorkBench.HandleRecursiveAction( StartingPath , NewPath : String;
  489.            ActionCode : Integer );
  490. { VITAL!!! These variables MUST be local for recursrion to work! }
  491. var
  492.     Finished        : Boolean;         { Loop flag              }
  493.     TheSR           : TSearchRec;      { Searchrecord for FF/FN }
  494.     TheResult       : Integer;         { return variable        }
  495.     TargetPath ,
  496.     FileMask   ,
  497.     TheWorkingDirectory ,
  498.     TheStoredWorkingDirectory ,
  499.     ModifiedDirectory  : String;       { path for FF/FN         }
  500.     TheFIP          : TFileIconPanel;  { generic FIP holder     }
  501.     ButtonColor   ,                    { main panel color       }
  502.     ButtonHLColor ,                    { bright panel color     }
  503.     ButtonSColor  ,                    { dark panel color       }
  504.     Textcolor       : TColor;          { label text color       }
  505.     TheFile         : File;
  506.  
  507. begin
  508.   { Set up the initial variables }
  509.   Finished := false;
  510.   TheWorkingDirectory := StartingPath;
  511.   TheStoredWorkingDirectory := TheWorkingDirectory;
  512.   TheWorkingDirectory := TheWorkingDirectory + '\*.*';
  513.   TargetPath := ExtractFilePath( TheWorkingDirectory );
  514.   { Make the call to FindFirst set to get any file }
  515.   TheResult := FindFirst( TheWorkingDirectory , faAnyFile , TheSR );
  516.   { loop through all files in the directory and delete them }
  517.   while not Finished do
  518.   begin
  519.     { Make call to FindNext, using only SearchRecord from FindFirst }
  520.     TheResult := FindNext( TheSR );
  521.     { A -1 result means no more files so exit }
  522.     if TheResult < 0 then finished := true else
  523.     begin
  524.       if (( FileGetAttr( TargetPath + TheSR.Name ) and faDirectory )
  525.        <> faDirectory ) then
  526.       begin { A File }
  527.         case ActionCode of
  528.           FAC_COPY :
  529.               begin
  530.                 CopyTheFile( TargetPath + TheSR.Name , NewPath );
  531.               end;
  532.           FAC_MOVE :
  533.               begin
  534.                 MoveTheFile( TargetPath + TheSR.Name , NewPath );
  535.               end;
  536.           FAC_DELETE :
  537.               begin { Delete }
  538.                 if MessageDlg( 'Delete file ' + TargetPath + TheSR.Name + '?',
  539.                    mtConfirmation , mbYesNoCancel , 0 ) = mrYes then
  540.                     DeleteTheFile( TargetPath + TheSR.Name );
  541.               end;
  542.         end;
  543.       end;
  544.     end;
  545.   end;
  546.   { Call FindClose for Windows NT/Windows 95 compatibility }
  547.   FindClose( TheSR );
  548.   { Set up the variables to do recursive calls on all directories}
  549.   Finished := false;
  550.   ModifiedDirectory := TheStoredWorkingdirectory + '\*.*';
  551.   { Make the call to FindFirst set to get any file, ignore result }
  552.   TheResult := FindFirst( ModifiedDirectory , faDirectory , TheSR );
  553.   while not Finished do
  554.   begin
  555.     { Make call to FindNext, using only SearchRecord from FindFirst }
  556.     TheResult := FindNext( TheSR );
  557.     { A -1 result means no more files so exit }
  558.     if TheResult < 0 then
  559.       finished := true
  560.     else
  561.     begin
  562.       if TheSR.Name <> '..' then { Ignore backup in this case }
  563.       begin
  564.         if (( FileGetAttr( TargetPath + TheSR.Name ) and faDirectory )
  565.          = faDirectory ) then
  566.         begin
  567.           { Send in the new directory name }
  568.           ModifiedDirectory := TheStoredWorkingDirectory  + '\' +
  569.            TheSR.Name;
  570.           { Reproduce directory structure for recursion in copy/move }
  571.           NewPath := NewPath + TheSR.Name;
  572.           case ActionCode of
  573.             FAC_COPY , FAC_MOVE :
  574.                begin { Create ahead for move and copy }
  575.                  { Make the new directory for moving and copying }
  576.                  CreateNewDirectory( NewPath );
  577.                  { Force a backslash for compatibility }
  578.                  NewPath := ForceTrailingBackSlash( NewPath );
  579.                end;
  580.             FAC_DELETE :
  581.                begin  { No prior action needed for Delete }
  582.                end;
  583.           end;
  584.           { Do the recursive call }
  585.           HandleRecursiveAction( ModifiedDirectory , NewPath , ActionCode );
  586.           case ActionCode of
  587.             FAC_COPY :
  588.                begin { no action for copy }
  589.                end;
  590.             FAC_MOVE , FAC_DELETE :
  591.                begin  { Delete }
  592.                  { Get a confirmation }
  593.                  if MessageDlg( 'Remove Directory ' + TargetPath + TheSR.Name
  594.                   + '?', mtConfirmation , mbYesNoCancel , 0 ) = mrYes then
  595.                    RemoveDirectory( TargetPath + TheSR.Name );
  596.                end;
  597.           end;
  598.         end;
  599.       end;
  600.     end;
  601.   end;
  602. end;
  603.  
  604. { This is a generic copy routine taken from Delphi sample code }
  605. { It has been edited to return viable error codes!             }
  606. procedure TFileWorkBench.FMXUCopyFile(const FileName, DestName: String);
  607. var
  608.   CopyBuffer: Pointer; { buffer for copying }
  609.   BytesCopied: Longint;
  610.   TheAttr : Integer;
  611.   Source, Dest: Integer; { handles }
  612. const
  613.   ChunkSize: Longint = 8192; { copy in 8K chunks }
  614. begin
  615.   GetMem(CopyBuffer, ChunkSize); { allocate the buffer }
  616.   Source := FileOpen(FileName, fmShareDenyWrite); { open source file }
  617.   if Source < 0 then
  618.   begin  { error creating source file }
  619.     GlobalErrorType := EOC_SOURCECOPY;
  620.     GlobalError := -IOResult;
  621.     if GlobalError = 0 then GlobalError := -157;
  622.     FreeMem( CopyBuffer, ChunkSize );
  623.     exit;
  624.   end;
  625.   Dest := FileCreate(DestName); { create output file; overwrite existing }
  626.   if Dest < 0 then
  627.   begin  { error creating destination file }
  628.     FileClose( Source );
  629.     GlobalErrorType := EOC_DESTCOPY;
  630.     GlobalError := -IOResult;
  631.     if GlobalError = 0 then GlobalError := -159;
  632.     FreeMem( CopyBuffer , ChunkSize );
  633.     exit;
  634.   end;
  635.   {$I-}
  636.   repeat
  637.     BytesCopied := FileRead(Source, CopyBuffer^, ChunkSize); { read chunk}
  638.     if BytesCopied > 0 then { if we read anything... }
  639.     FileWrite(Dest, CopyBuffer^, BytesCopied); { ...write chunk }
  640.   until BytesCopied < ChunkSize; { until we run out of chunks }
  641.   {$I+}
  642.   GlobalError := -IOResult;  { get any error code which happens during copying }
  643.   FileClose(Dest); { close the destination file }
  644.   FileClose(Source); { close the source file }
  645.   FreeMem(CopyBuffer, ChunkSize); { free the buffer }
  646. end;
  647.  
  648. { This function calls the sample Copy code and handles errors }
  649. function TFileWorkBench.CopyFile( TargetPath ,
  650.           DestinationPath : String ) : Boolean;
  651. begin
  652.   { Set global error value to no error }
  653.   GlobalError := 0;
  654.   { Call the sample procedure to do the copy }
  655.   FMXUCopyFile( TargetPath, DestinationPath );
  656.   { If no error return true else return false }
  657.   if GlobalError < 0 then CopyFile := false else
  658.    CopyFile := true;
  659. end;
  660.  
  661. { This procedure handles displaying a user-friendly Dialog box with a }
  662. { Message for Delphi IO exception errors.                             }
  663. procedure TFileWorkBench.HandleIOException( TheOpCode : Integer;
  664.            ThePath : String; TheMessage : String; TheCode : Integer );
  665. var ErrorMessageString : String;  { Holds internal data }
  666.     OperationString    : String;  { Holds internal data }
  667. begin
  668.   { clear to check for unrecognized code }
  669.   ErrorMessageString := '';
  670.   { Check against imported code }
  671.   case TheCode of
  672.     2    : ErrorMessageString := 'File not found';
  673.     3    : ErrorMessageString := 'Path not found';
  674.     4    : ErrorMessageString := 'Too many open files';
  675.     5    : ErrorMessageString := 'File access denied';
  676.     6    : ErrorMessageString := 'Invalid file handle';
  677.     12    : ErrorMessageString := 'Invalid file access code';
  678.     15    : ErrorMessageString := 'Invalid drive number';
  679.     16  : ErrorMessageString := 'Cannot remove current directory';
  680.     17    : ErrorMessageString := 'Cannot rename across drives';
  681.     100    : ErrorMessageString := 'Disk read error';
  682.     101    : ErrorMessageString := 'Disk write error';
  683.     102    : ErrorMessageString := 'File not assigned';
  684.     103    : ErrorMessageString := 'File not open';
  685.     104    : ErrorMessageString := 'File not open for input';
  686.     105    : ErrorMessageString := 'File not open for output';
  687.   end;
  688.   case TheOpCode of
  689.     EOC_CHANGEDIR : OperationString := 'Unable to Change Directory due to ';
  690.     EOC_SOURCECOPY : OperationString := 'Unable to Copy due to Source File ';
  691.     EOC_DESTCOPY : OperationString := 'Unable to Copy due to Destination File ';
  692.     EOC_DELETEFILE : OperationString := 'Unable to Delete File due to ';
  693.     EOC_DELETEDIR : OperationString := 'Unable to Delete Directory due to ';
  694.     EOC_RENAMEFILE : OperationString := 'Unable to Rename File due to ';
  695.     EOC_MAKEDIR : OperationString := 'Unable to Create New Directory due to ';
  696.     EOC_SETATTR : OperationString := 'Unable to Set File Attributes due to ';
  697.   end;
  698.   { If not recognized use message; not a DOS error; reset cursor for neatness }
  699.   if ErrorMessageString = '' then
  700.   begin
  701.     Screen.Cursor := crDefault;
  702.     MessageDlg( OperationString + ExtractFileName( ThePath ) + ' ' +
  703.      TheMessage , mtError , [mbOK],0);
  704.   end
  705.   else
  706.   begin
  707.     { Recognized DOS exception, reset cursor for neatness }
  708.     Screen.Cursor := crDefault;
  709.     MessageDlg( OperationString + ExtractFileName( ThePath ) + ' ' +
  710.      ErrorMessageString , mtError , [mbOK], 0 );
  711.   end;
  712. end;
  713.  
  714. { This procedure handles displaying a user-friendly Dialog box with a }
  715. { Message for DOS error codes.                                        }
  716. procedure TFileWorkBench.HandleDOSError( TheOpCode : Integer;
  717.            ThePath : String;  TheCode : Integer );
  718. var ErrorMessageString : String;  { internal message holder }
  719.     OperationString : String;     { internal message holder }
  720. begin
  721.   { clear the message holder to check for unrecognized code }
  722.   ErrorMessageString := '';
  723.   { Negate the code back to normal number and check to set string }
  724.   case -TheCode of
  725.     2    : ErrorMessageString := 'File not found';
  726.     3    : ErrorMessageString := 'Path not found';
  727.     4    : ErrorMessageString := 'Too many open files';
  728.     5    : ErrorMessageString := 'File access denied';
  729.     6    : ErrorMessageString := 'Invalid file handle';
  730.     12    : ErrorMessageString := 'Invalid file access code';
  731.     15    : ErrorMessageString := 'Invalid drive number';
  732.     16  : ErrorMessageString := 'Cannot remove current directory';
  733.     17    : ErrorMessageString := 'Cannot rename across drives';
  734.     100    : ErrorMessageString := 'Disk read error';
  735.     101    : ErrorMessageString := 'Disk write error';
  736.     102    : ErrorMessageString := 'File not assigned';
  737.     103    : ErrorMessageString := 'File not open';
  738.     104    : ErrorMessageString := 'File not open for input';
  739.     105    : ErrorMessageString := 'File not open for output';
  740.     157 : ErrormessageString := 'Could not open Source File';
  741.     159 : ErrormessageString := 'Could not open Target File';
  742.   end;
  743.   case TheOpCode of
  744.     EOC_CHANGEDIR : OperationString := 'Unable to Change Directory due to ';
  745.     EOC_SOURCECOPY : OperationString := 'Unable to Copy due to Source File ';
  746.     EOC_DESTCOPY : OperationString := 'Unable to Copy due to Destination File ';
  747.     EOC_DELETEFILE : OperationString := 'Unable to Delete File due to ';
  748.     EOC_DELETEDIR : OperationString := 'Unable to Delete Directory due to ';
  749.     EOC_RENAMEFILE : OperationString := 'Unable to Rename File due to ';
  750.     EOC_MAKEDIR : OperationString := 'Unable to Create New Directory due to ';
  751.     EOC_SETATTR : OperationString := 'Unable to Set File Attributes due to ';
  752.   end;
  753.   { If the string is empty an unrecognized code was sent in }
  754.   if ErrorMessageString = '' then
  755.   begin
  756.     { Sent up db based on source or target error; reset cursor for neatness }
  757.     Screen.Cursor := crDefault;
  758.     MessageDlg( OperationString + ExtractFileName( ThePath ) + ' Error Code: ' +
  759.      IntToStr( TheCode ) , mtError , [mbOK],0);
  760.   end
  761.   else  { Code is recognized, use message from case statement }
  762.   begin
  763.     { Format the output for source or target error }
  764.     Screen.Cursor := crDefault;
  765.     MessageDlg( OperationString + ExtractFilePath( ThePath ) + ' ' +
  766.      ErrorMessageString , mtError , [mbOK], 0 );
  767.   end;
  768. end;
  769.  
  770. { This procedure sets the imported booleans to the file's attributes }
  771. procedure TFileWorkBench.GetFileAttributes( TheFile : String; var IsDirectory ,
  772.            IsArchive , IsVolumeID , IsHidden , IsReadOnly ,
  773.             IsSysFile : Boolean );
  774. var TheResult : Integer; { Traps for error code on VolumeID }
  775. begin
  776.   { Clear the imported flags for default }
  777.   IsDirectory := false;
  778.   IsArchive := false;
  779.   IsVolumeID := false;
  780.   IsHidden := False;
  781.   IsReadOnly := false;
  782.   IsSysFile := false;
  783.   { Make the Dos call }
  784.   TheResult := FileGetAttr( TheFile );
  785.   if TheResult < 0 then
  786.   begin
  787.     { Volume ID returns -2 (?) }
  788.     IsVolumeID := true;
  789.     { It has no other properties }
  790.     exit;
  791.   end;
  792.   { Use AND test to set all other properties }
  793.   if (( TheResult and faDirectory ) = faDirectory ) then IsDirectory := true;
  794.   if (( TheResult and faArchive ) = faArchive ) then IsArchive := true;
  795.   if (( TheResult and faVolumeID ) = faVolumeID ) then IsVolumeID := true;
  796.   if (( TheResult and faReadOnly ) = faReadOnly ) then IsReadOnly := true;
  797.   if (( TheResult and faHidden ) = faHidden ) then IsHidden := true;
  798.   if (( TheResult and faSysFile ) = faSysFile ) then IsSysFile := true;
  799. end;
  800.  
  801. { This function makes sure a pathname has a trailing \ }
  802. function TFileWorkBench.ForceTrailingBackSlash(
  803.           const TheFileName : String ) : String;
  804. var TempString : String;  { Used to hold function result }
  805. begin
  806.   { If no trailing \ add one (root will already have one.) }
  807.   if TheFileName[ Length( TheFileName ) ] <> '\' then
  808.    TempString := TheFileName + '\' else TempString := TheFileName;
  809.   { Return modified or non-modified string }
  810.   ForceTrailingBackslash := TempString;
  811. end;
  812.  
  813. { This function makes sure a non-root dir has no trailing \ }
  814. function TFileWorkBench.StripNonRootTrailingBackSlash(
  815.           const TheFileName : String ) : String;
  816. var TempString : String ; { Used to hold function result }
  817. begin
  818.   { Default is no change }
  819.   TempString := TheFileName;
  820.   { If not root then }
  821.   if Length( TheFileName ) > 3 then
  822.   begin
  823.     { If has a trailing backslash remove it }
  824.     if TheFileName[ Length( TheFileName )] = '\' then
  825.     begin
  826.       TempString := Copy( TheFileName , 1 ,
  827.        Length( TheFileName ) - 1 );
  828.     end;
  829.   end;
  830.   { Export the final result }
  831.   StripNonRootTrailingBackSlash := TempString;
  832. end;
  833.  
  834. { This gets the next selected listbox item }
  835. function TIconFileListBox.GetNextSelection( SourceDirectory : String;
  836.           var CurrentItem : Integer ): String;
  837. var TheResult : String;  { Internal storage }
  838.     finished  : boolean; { Loop flag        }
  839. begin
  840.   { If out of items to check signal and exit }
  841.   if CurrentItem > Items.Count then TheResult := '' else
  842.   begin
  843.     { Otherwise scan from current position till match or end }
  844.     finished := false;
  845.     while not finished do
  846.     begin
  847.       { Check against selected property }
  848.       if Selected[ CurrentItem - 1 ] then
  849.       begin
  850.         { If selected then return it and abort loop }
  851.         TheResult := SourceDirectory + Items[ CurrentItem - 1 ];
  852.         finished := true;
  853.         { Increment current position }
  854.         CurrentItem := CurrentItem + 1;
  855.      end
  856.       else
  857.       begin
  858.         { Increment current position }
  859.         CurrentItem := CurrentItem + 1;
  860.         { Otherwise check for end of data and abort if out of entries }
  861.         if CurrentItem > Items.Count then
  862.         begin
  863.           TheResult := '';
  864.           finished := true;
  865.         end;
  866.       end;
  867.     end;
  868.   end;
  869.   { Return stored result }
  870.   GetNextSelection := TheResult;
  871. end;
  872.  
  873. { Modified from VCL Source Copyright 1995 }
  874. { Borland International, Inc.             }
  875. { Use this to override display with icons }
  876. procedure TIconFileListBox.ReadFileNames;
  877. var
  878.   AttrIndex   : TFileAttr;
  879.   i           : Integer;
  880.   FileExt     : string;
  881.   MaskPtr     : PChar;
  882.   Ptr         : PChar;
  883.   AttrWord    : Word;
  884.   TempPicture : TPicture;
  885.   TempBmp     : TBitmap;
  886.   TempIcon    : TIcon;
  887. const
  888.   Attributes: array[TFileAttr] of Word =
  889.   ( DDL_READONLY , DDL_HIDDEN , DDL_SYSTEM , $0008 , DDL_DIRECTORY ,
  890.     DDL_ARCHIVE  , DDL_EXCLUSIVE );
  891. begin
  892.   { if no handle allocated yet, this call will force         }
  893.   { one to be allocated incorrectly (i.e. at the wrong time. }
  894.   { In due time, one will be allocated appropriately.        }
  895.   AttrWord := DDL_READWRITE;
  896.   if HandleAllocated then
  897.   begin
  898.     { Set attribute flags based on values in FileType }
  899.     for AttrIndex := ftReadOnly to ftArchive do
  900.      if AttrIndex in FileType then
  901.       AttrWord := AttrWord or Attributes[ AttrIndex ];
  902.  
  903.     { Use Exclusive bit to exclude normal files }
  904.     if not ( ftNormal in FileType ) then
  905.       AttrWord := AttrWord or DDL_EXCLUSIVE;
  906.  
  907.     ChDir( FDirectory ); { go to the directory we want }
  908.     Clear;               { clear the list }
  909.  
  910.     MaskPtr := FMask;
  911.     while MaskPtr <> nil do
  912.     begin
  913.       Ptr := StrScan ( MaskPtr , ';' );
  914.       if Ptr <> nil then  Ptr^ := #0;
  915.       { build the list }
  916.       SendMessage( Handle , LB_DIR , AttrWord , Longint( MaskPtr ));
  917.       if Ptr <> nil then
  918.       begin
  919.         Ptr^ := ';';
  920.         Inc ( Ptr );
  921.       end;
  922.       MaskPtr := Ptr;
  923.     end;
  924.     { Now add the bitmaps }
  925.     {---------------------------- begin custom code --------------------------}
  926.     { Create the TPicture for exchange purposes }
  927.     TempPicture := TPicture.Create;
  928.     { Set it to icon widths }
  929.     TempPicture.Bitmap.Width := 32;
  930.     TempPicture.Bitmap.Height := 32;
  931.     { Run down the list }
  932.     for i := 0 to Items.Count - 1 do
  933.     begin
  934.       { Create a new temporary icon }
  935.       TempIcon := TIcon.Create;
  936.       { Call the custom DRWS routine to get icon for a file }
  937.       GetIconForFile( Items[ i ] , TempIcon );
  938.       { Put the icon on the bitmap for the picture via draw }
  939.       { Note 1 , 1 due to bug in Draw?                      }
  940.       TempPicture.Bitmap.Canvas.Draw( 1 , 1 , TempIcon );
  941.       { Create a temporary bitmap }
  942.       TempBmp := TBitmap.Create;
  943.       { Set its width to those of the previous object's bitmaps }
  944.       TempBmp.Width := 16;
  945.       TempBmp.Height := 15;
  946.       { Resize the icon's bitmap to the smaller size with stretchdraw }
  947.       TempBmp.Canvas.StretchDraw( Rect( 1 , 1 , 15 , 14 ) ,
  948.        TempPicture.Bitmap );
  949.       { Set the Objects list to the bitmap }
  950.       Items.Objects[ i ] := TempBmp;
  951.       { Free the icon each iteration; don't free the TempBmp as list does }
  952.       TempIcon.Free;
  953.     end;
  954.     { Free the TPicture exchange element }
  955.     TempPicture.Free;
  956.     {------------------------ end custom code --------------------------------}
  957.     Change;
  958.   end;
  959. end;
  960.  
  961. { Create method for FIP                                }
  962. constructor TFileIconPanel.Create( AOwner : TComponent );
  963. begin
  964.   { call inherited -- VITAL! }
  965.   inherited Create( AOwner );
  966.   { create icon and label components, making self owner/displayer }
  967.   FTheIcon := TIcon.Create;
  968.   FTheLabel := TLabel.Create( Self );
  969.   FThelabel.Parent := Self;
  970.   { Set own and labels mouse methods to stored methods }
  971.   OnClick := TheClick;
  972.   OnDblClick := TheDblClick;
  973.   FTheLabel.OnClick := TheClick;
  974.   FTheLabel.OnDblClick := TheDblClick;
  975.   { Set alignment and autosize properties of the label }
  976.   FTheLabel.Autosize := false;
  977.   FTheLabel.Alignment := taCenter;
  978.   { Set selected to false }
  979.   Selected := false;
  980. end;
  981.  
  982. { Initialization method for FIP                                         }
  983. procedure TFileIconPanel.Initialize( PanelX              ,
  984.                                      PanelY              ,
  985.                                      PanelWidth          ,
  986.                                      PanelHeight         ,
  987.                                      PanelBevelWidth     ,
  988.                                      LabelFontSize         : Integer;
  989.                                      PanelColor          ,
  990.                                      PanelHighlightColor ,
  991.                                      PanelShadowColor    ,
  992.                                      LabelTextColor        : TColor;
  993.                                      TheFilename         ,
  994.                                      LabelFontName         : String;
  995.                                      LabelFontStyle        : TFontStyles;
  996.                                      ExtraData             : Integer );
  997.  
  998. var TheLabelHeight ,             { Holder for label pixel height }
  999.     TheLabelWidth    : Integer;  { Holder for label pixel width  }
  1000.     TheOtherPChar    : PChar;    { Windows ASCIIZ string         }
  1001. begin
  1002.   { Set the basic properties based on imported parameters }
  1003.   Left := PanelX;
  1004.   Top := PanelY;
  1005.   Width := PanelWidth;
  1006.   Height := PanelHeight;
  1007.   Color := PanelColor;
  1008.   BevelWidth := PanelBevelWidth;
  1009.   FHighlightColor := PanelHighlightColor;
  1010.   FShadowColor := PanelShadowColor;
  1011.   FTheName := TheFilename;
  1012.   { If the ExtraData field is non-0 then a drive is being sent in }
  1013.   if ExtraData <> 0 then
  1014.   begin
  1015.     { Use the data field value to determine which icon to get from RES file }
  1016.     case ExtraData of
  1017.       1 : begin
  1018.             GetMem( TheOtherPChar , 255 );
  1019.             StrPCopy( TheOtherPChar , 'FLOPPY35' );
  1020.             FTheIcon.Handle := LoadIcon( hInstance , TheOtherPChar );
  1021.             FreeMem( TheOtherPChar , 255 );
  1022.           end;
  1023.       2 : begin
  1024.             GetMem( TheOtherPChar , 255 );
  1025.             StrPCopy( TheOtherPChar , 'FIXEDHD' );
  1026.             FTheIcon.Handle := LoadIcon( hInstance , TheOtherPChar );
  1027.             FreeMem( TheOtherPChar , 255 );
  1028.           end;
  1029.       3 : begin
  1030.             GetMem( TheOtherPChar , 255 );
  1031.             StrPCopy( TheOtherPChar , 'NETWORKHD' );
  1032.             FTheIcon.Handle := LoadIcon( hInstance , TheOtherPChar );
  1033.             FreeMem( TheOtherPChar , 255 );
  1034.           end;
  1035.       4 : begin
  1036.             GetMem( TheOtherPChar , 255 );
  1037.             StrPCopy( TheOtherPChar , 'CDROM' );
  1038.             FTheIcon.Handle := LoadIcon( hInstance , TheOtherPChar );
  1039.             FreeMem( TheOtherPChar , 255 );
  1040.           end;
  1041.       5 : begin
  1042.             GetMem( TheOtherPChar , 255 );
  1043.             StrPCopy( TheOtherPChar , 'RAM' );
  1044.             FTheIcon.Handle := LoadIcon( hInstance , TheOtherPChar );
  1045.             FreeMem( TheOtherPChar , 255 );
  1046.           end;
  1047.     end;
  1048.     { The FileNme property is already set up for the caption; use directly }
  1049.     FTheLabel.Caption := TheFilename;
  1050.     { Set up the hint for later use (make sure to set ShowHint) }
  1051.     Hint := 'Change to ' + TheFileName;
  1052.     ShowHint := true;
  1053.     { Set up all imported label properties and center it for drawing }
  1054.     with FTheLabel do
  1055.     begin
  1056.       Font.Name := LabelFontName;
  1057.       Font.Size := LabelFontSize;
  1058.       Font.Style := LabelFontStyle;
  1059.       Font.Color := LabelTextColor;
  1060.       Canvas.Brush.Color := PanelColor;
  1061.       Canvas.Font := Font;
  1062.       TheLabelHeight := Canvas.Textheight( Caption ) + 4;
  1063.       TheLabelWidth := Canvas.Textwidth( Caption ) + 4;
  1064.       Left := (( Self.Width - TheLabelWidth ) div 2 ) + 1;
  1065.       Top := ((( Round( Self.Height * 0.25 ) - 6 ) - TheLabelHeight) div 2) + 1;
  1066.       Top := Top + Round( Self.Height * 0.75 );
  1067.       Height := TheLabelHeight;
  1068.       Width := TheLabelWidth;
  1069.     end;
  1070.   end
  1071.   else
  1072.   begin
  1073.     { A file or directory has been sent in; use GetIconForFile to obtain an }
  1074.     { icon either from the file, its owner, or a RES file default.          }
  1075.     GetIconForFile( FTheName , FTheIcon );
  1076.     { Check for the Backup caption and set it specially }
  1077.     if ExtractfileName( FThename ) = '..' then
  1078.     begin
  1079.       FTheLabel.Caption := '..';
  1080.       Hint := 'Up One Level';
  1081.     end
  1082.     else
  1083.     begin
  1084.       { Otherwise just get the filename for the label caption }
  1085.       { And the full path for the hint (used later.)          }
  1086.       FTheLabel.caption := ExtractFileName( UpperCase( FTheName ));
  1087.       Hint := FTheName;
  1088.     end;
  1089.     { Activate showhint so hints are seen }
  1090.     ShowHint := true;
  1091.     { Set label properties with imported values and center for display }
  1092.     with FTheLabel do
  1093.     begin
  1094.       Font.Name := LabelFontName;
  1095.       Font.Size := LabelFontSize;
  1096.       Font.Style := LabelFontStyle;
  1097.       Font.Color := LabelTextColor;
  1098.       Canvas.Brush.Color := PanelColor;
  1099.       Canvas.Font := Font;
  1100.       TheLabelHeight := Canvas.Textheight( Caption ) + 4;
  1101.       TheLabelWidth := Canvas.Textwidth( Caption ) + 4;
  1102.       Left := (( Self.Width - TheLabelWidth ) div 2 ) + 1;
  1103.       Top := ((( Round( Self.Height * 0.25 ) - 6 ) - TheLabelHeight) div 2) + 1;
  1104.       Top := Top + Round( Self.Height * 0.75 );
  1105.       Height := TheLabelHeight;
  1106.       Width := TheLabelWidth;
  1107.     end;
  1108.   end;
  1109. end;
  1110.  
  1111. { Destroy method for FIP }
  1112. destructor TFileIconPanel.Destroy;
  1113. begin
  1114.   { free component resources }
  1115.   FTheIcon.Free;
  1116.   FTheLabel.Free;
  1117.   { call inherited -- VITAL! }
  1118.   inherited Destroy;
  1119. end;
  1120.  
  1121. { TheClick method for FIP; used for event responses }
  1122. procedure TFileIconPanel.TheClick( Sender : TObject );
  1123. begin
  1124.   { Currently ignore drive clicks }
  1125.   if Pos( 'DRIVE' , FTheName ) > 0 then exit;
  1126.   { Flip status of bevels }
  1127.   if BevelOuter = bvRaised then BevelOuter := bvLowered else
  1128.    BevelOuter := bvRaised;
  1129.   { Flip selected variable }
  1130.   Selected := not Selected;
  1131.   { Set redisplay }
  1132.   Invalidate;
  1133. end;
  1134.  
  1135. { TheDblClick method for FIP; used for event responses }
  1136. procedure TFileIconPanel.TheDblClick( Sender : TObject );
  1137. var CurrentDirectory : String;    { Use to store dirs }
  1138.     TheDrive         : String;    { Get drive letter  }
  1139.     WhichDrive       : Integer;   { Get drive number  }
  1140.     ErrorCheck       : Integer;
  1141.     TheFWB           : TFileWorkBench;
  1142. begin
  1143.   { Create FileWorkBench for later use }
  1144.   TheFWB := TFileWorkBench.Create( Self );
  1145.   { Check for label or FIP sender }
  1146.   if Sender is TFileIconPanel then
  1147.   begin
  1148.     if FTheLabel.Caption = '..' then
  1149.     begin { deal with backup request }
  1150.       { Change to new directory }
  1151.       TheFWB.ChangeTheDirectory( '..' );
  1152.       { Call special method due to SendMessage problem! }
  1153.       TFileIconPanelScrollBox( Parent ).Update;
  1154.     end
  1155.     else
  1156.     begin
  1157.       { Check for DRIVE id in name }
  1158.       if Pos( 'DRIVE' , FTheName ) <> 0 then
  1159.       begin { Double Click on a Drive Icon }
  1160.         { Pull out the letter from name }
  1161.         TheDrive := Copy( FtheName , 7 , 1 );
  1162.         { Convert it to a number }
  1163.         WhichDrive := ( Ord( TheDrive[ 1 ] ) - Ord( 'A' )) + 1;
  1164.         TheFWB.ChangeTheDriveAndDirectory( WhichDrive );
  1165.         { Call special method due to SendMessage problem! }
  1166.         TFileIconPanelScrollBox( Parent ).Update;
  1167.       end
  1168.       else
  1169.       begin { Double click on a dir/file icon }
  1170.         if (( FileGetAttr( FTheName ) and faDirectory ) = faDirectory ) then
  1171.         begin { A directory, change to it }
  1172.           { Since full path in name, simply change to it! }
  1173.           TheFWB.ChangeTheDirectory( FTheName );
  1174.           { Call special method due to SendMessage problem! }
  1175.           TFileIconPanelScrollBox( Parent ).Update;
  1176.         end
  1177.         else
  1178.         begin { A file; attempt to shellexecute it }
  1179.           { Call shellexec as a wrapper around ShellExecute API call }
  1180.           { False indicates failure, signal error                    }
  1181.           if not ShellExec( FTheName , '' , '', false , SW_SHOWNORMAL , false )
  1182.            then MessageDlg('Could not Shell out to ' + FTheName , mtError,
  1183.             [mbOK], 0);
  1184.         end;
  1185.       end;
  1186.     end;
  1187.   end
  1188.   else
  1189.   begin
  1190.     with Sender as TLabel do
  1191.     begin
  1192.       if Caption = '..' then
  1193.       begin { Deal with backup request }
  1194.         { Change to new directory }
  1195.         TheFWB.ChangeTheDirectory( '..' );
  1196.         { Call special method due to SendMessage problem! }
  1197.         TFileIconPanelScrollBox( Parent ).Update;
  1198.       end
  1199.       else
  1200.       begin
  1201.         with Parent as TFileIconPanel do
  1202.         begin
  1203.           { Check for DRIVE id in name }
  1204.           if Pos( 'DRIVE' , FTheName ) <> 0 then
  1205.           begin { Double Click on a Drive Icon }
  1206.             { Pull out the letter from name }
  1207.             TheDrive := Copy( FtheName , 7 , 1 );
  1208.             { Convert it to a number }
  1209.             WhichDrive := ( Ord( TheDrive[ 1 ] ) - Ord( 'A' )) + 1;
  1210.             { Call the method to change to default dir on new drive }
  1211.             TheFWB.ChangeTheDriveAndDirectory( WhichDrive );
  1212.             { Call special method due to SendMessage problem! }
  1213.             TFileIconPanelScrollBox( Parent ).Update;
  1214.           end
  1215.           else
  1216.           begin { Double click on a dir/file icon }
  1217.             if (( FileGetAttr( FTheName ) and faDirectory ) = faDirectory ) then
  1218.             begin { A directory, change to it }
  1219.               { Since full path in name, simply change to it! }
  1220.               TheFWB.ChangeTheDirectory( FTheName );
  1221.               { Call special method due to SendMessage problem! }
  1222.               TFileIconPanelScrollBox( Parent ).Update;
  1223.             end
  1224.             else
  1225.             begin { A file; attempt to shellexecute it }
  1226.               { Call shellexec as a wrapper around ShellExecute API call }
  1227.               { False indicates failure, signal error                    }
  1228.               if not ShellExec( FTheName , '' , '', false , SW_SHOWNORMAL ,
  1229.                false ) then MessageDlg('Could not Shell out to ' + FTheName ,
  1230.                 mtError, [mbOK], 0);
  1231.             end;
  1232.           end;
  1233.         end;
  1234.       end;
  1235.     end;
  1236.   end;
  1237.   TheFWB.Free; { This prevents resource leak }
  1238. end;
  1239.  
  1240. { Paint method for FIP; overrides normal paint }
  1241. procedure TFileIconPanel.Paint;
  1242. var
  1243.   TheOtherRect   : TRect;   { Holds clientrect   }
  1244.   TopColor     ,            { Holds bright color }
  1245.   BottomColor    : TColor;  { Holds dark color   }
  1246.  
  1247. { These methods are from Borland Intl., copyright 1995 }
  1248. procedure Frame3D(    Canvas       : TCanvas;
  1249.                   var TheRect      : TRect;
  1250.                       TopColor   ,
  1251.                       BottomColor  : TColor;
  1252.                       Width        : Integer );
  1253.  
  1254. procedure DoRect;
  1255. var
  1256.   TopRight, BottomLeft: TPoint;
  1257. begin
  1258.   with Canvas, TheRect do
  1259.   begin
  1260.     TopRight.X := Right;
  1261.     TopRight.Y := Top;
  1262.     BottomLeft.X := Left;
  1263.     BottomLeft.Y := Bottom;
  1264.     Pen.Color := TopColor;
  1265.     PolyLine([BottomLeft, TopLeft, TopRight]);
  1266.     Pen.Color := BottomColor;
  1267.     Dec(BottomLeft.X);
  1268.     PolyLine([TopRight, BottomRight, BottomLeft]);
  1269.   end;
  1270. end;
  1271.  
  1272. begin
  1273.   Canvas.Pen.Width := 1;
  1274.   Dec(TheRect.Bottom); Dec(TheRect.Right);
  1275.   while Width > 0 do
  1276.   begin
  1277.     Dec(Width);
  1278.     DoRect;
  1279.     InflateRect(TheRect, -1, -1);
  1280.   end;
  1281.   Inc(TheRect.Bottom); Inc(TheRect.Right);
  1282. end;
  1283.  
  1284. procedure AdjustColors(Bevel: TPanelBevel);
  1285. begin
  1286.   TopColor := FHighlightColor;
  1287.   if Bevel = bvLowered then TopColor := FShadowColor;
  1288.   BottomColor := FShadowColor;
  1289.   if Bevel = bvLowered then BottomColor := FHighlightColor;
  1290. end;
  1291.  
  1292. { Custom code begins here }
  1293. begin
  1294.   { Get the rectangle of the control with API/method call }
  1295.   TheOtherRect := GetClientRect;
  1296.   { draw basic rectangle with basic color }
  1297.   with Canvas do
  1298.   begin
  1299.     Brush.Color := Color;
  1300.     FillRect(TheOtherRect);
  1301.   end;
  1302.   { Set up for top "icon" frame  and draw it with frame3d }
  1303.   TheOtherRect.Right := Width;
  1304.   TheOtherRect.Bottom := Round( Height * 0.75 ) - 6 ;
  1305.   if BevelOuter <> bvNone then
  1306.   begin
  1307.     AdjustColors(BevelOuter);
  1308.     Frame3D(Canvas, TheOtherRect, TopColor, BottomColor, BevelWidth);
  1309.   end;
  1310.   Frame3D(Canvas, TheOtherRect, Color, Color, BorderWidth);
  1311.   if BevelInner <> bvNone then
  1312.   begin
  1313.     AdjustColors(BevelInner);
  1314.     Frame3D(Canvas, TheOtherRect, TopColor, BottomColor, BevelWidth);
  1315.   end;
  1316.   { Do the same for the lower "label" frame }
  1317.   TheOtherRect.Top := Round( Height * 0.75 ) - 5;
  1318.   TheOtherRect.Left := 0;
  1319.   TheOtherRect.Bottom := Height;
  1320.   TheOtherRect.Right := Width;
  1321.   if BevelOuter <> bvNone then
  1322.   begin
  1323.     AdjustColors(BevelOuter);
  1324.     Frame3D(Canvas, TheOtherRect, TopColor, BottomColor, BevelWidth);
  1325.   end;
  1326.   Frame3D(Canvas, TheOtherRect, Color, Color, BorderWidth);
  1327.   if BevelInner <> bvNone then
  1328.   begin
  1329.     AdjustColors(BevelInner);
  1330.     Frame3D(Canvas, TheOtherRect, TopColor, BottomColor, BevelWidth);
  1331.   end;
  1332.   { Then draw the icon using canvas draw method }
  1333.   Canvas.Draw( (( Width - 32 ) div 2 ) + 1 ,
  1334.   ((( Round( Height * 0.75 ) - 6 ) - 32 ) div 2 ) + 1 , FTheIcon );
  1335. end;
  1336.  
  1337. { This procedure clears a scrollbox of all FileIconPanels }
  1338. procedure TFileIconPanelScrollbox.ClearTheFIPs;
  1339. var Counter_1 : Integer;
  1340.     TheComponent : TComponent;
  1341. begin
  1342.   { Note that must use while loop since component count continually }
  1343.   { decreases as removes are made!                                  }
  1344.   while ComponentCount > 0 do
  1345.   begin
  1346.     { Save the component as a generic TComponent }
  1347.     TheComponent := Components[ 0 ];
  1348.     { Call removecomponent to pull it out of the owner list for sb }
  1349.     { This avoids GPF when freeing the sb.                         }
  1350.     RemoveComponent( Components[ 0 ]);
  1351.     { Typecast the pointer and free it to release memory and res. }
  1352.     TFileIconPanel( TheComponent ).Free;
  1353.   end;
  1354. end;
  1355.  
  1356. { This procedure scans for drives and obtains their type and creates file }
  1357. { icon panels to represent them.                                          }
  1358. procedure TFileIconPanelScrollBox.AddDriveIcons( var XCounter ,
  1359.            YCounter : Integer );
  1360. type
  1361.   { This if from filectrl unit; reproduce here for completeness }
  1362.   TDriveType = (dtUnknown, dtNoDrive, dtFloppy, dtFixed, dtNetwork, dtCDROM,
  1363.                 dtRAM);
  1364. var
  1365.   DriveNum        : Integer;         { Used to get next drive via DOS fn   }
  1366.   IconType        : Integer;         { Used to hold icon type (defacto dt) }
  1367.   DriveChar       : Char;            { Used to hold drive letter           }
  1368.   DriveType       : TDriveType;      { Used for set-valued drive type      }
  1369.   Finished        : Boolean;         { Loop flag                           }
  1370.   TheFIP          : TFileIconPanel;  { Generic FileIconPanel variable      }
  1371.   ButtonColor   ,                    { Main panel color                    }
  1372.   ButtonHLColor ,                    { Bright panel color                  }
  1373.   ButtonSColor  ,                    { Dark panel color                    }
  1374.   Textcolor       : TColor;          { Label text color                    }
  1375.  
  1376. { This code is from the FileCtrl Unit; copyright Borland Intl 1995      }
  1377. { Check whether drive is a CD-ROM.  Returns True if MSCDEX is installed }
  1378. {  and the drive is using a CD driver                                   }
  1379.  
  1380. function IsCDROM(DriveNum: Integer): Boolean; assembler;
  1381. asm
  1382.   MOV   AX,1500h { look for MSCDEX }
  1383.   XOR   BX,BX
  1384.   INT   2fh
  1385.   OR    BX,BX
  1386.   JZ    @Finish
  1387.   MOV   AX,150Bh { check for using CD driver }
  1388.   MOV   CX,DriveNum
  1389.   INT   2fh
  1390.   OR    AX,AX
  1391.   @Finish:
  1392. end;
  1393.  
  1394. { This code is from the FileCtrl Unit; copyright Borland Intl 1995      }
  1395. { Check whether drive is a RAM drive.                                   }
  1396. function IsRAMDrive(DriveNum: Integer): Boolean; assembler;
  1397. var
  1398.   TempResult: Boolean;
  1399. asm
  1400.   MOV   TempResult,False
  1401.   PUSH  DS
  1402.   MOV   BX,SS
  1403.   MOV   DS,BX
  1404.   SUB   SP,0200h
  1405.   MOV   BX,SP
  1406.   MOV   AX,DriveNum
  1407.   MOV   CX,1
  1408.   XOR   DX,DX
  1409.   INT   25h  { read boot sector }
  1410.   ADD   SP,2
  1411.   JC    @ItsNot
  1412.   MOV   BX,SP
  1413.   CMP   BYTE PTR SS:[BX+15h],0F8h  { reverify fixed disk }
  1414.   JNE   @ItsNot
  1415.   CMP   BYTE PTR SS:[BX+10h],1  { check for single FAT }
  1416.   JNE   @ItsNot
  1417.   MOV   TempResult,True
  1418.   @ItsNot:
  1419.   ADD   SP,0200h
  1420.   POP   DS
  1421.   MOV   AL, TempResult
  1422. end;
  1423.  
  1424. { This code is from the FileCtrl Unit; copyright Borland Intl 1995      }
  1425. { Finds the type of a drive letter.                                     }
  1426. function FindDriveType(DriveNum: Integer): TDriveType;
  1427. begin
  1428.   Result := TDriveType(GetDriveType(DriveNum));
  1429.   if (Result = dtFixed) or (Result = dtNetwork) then
  1430.   begin
  1431.     if IsCDROM(DriveNum) then Result := dtCDROM
  1432.     else if (Result = dtFixed) then
  1433.     begin
  1434.         { do not check for RAMDrive under Windows NT }
  1435.       if ((GetWinFlags and $4000) = 0) and IsRAMDrive(DriveNum) then
  1436.         Result := dtRAM;
  1437.     end;
  1438.   end;
  1439. end;
  1440.  
  1441. begin
  1442.   { Set the button colors to an aquamarine color scheme for drives }
  1443.   ButtonColor := clTeal;
  1444.   ButtonHLColor := clAqua;
  1445.   ButtonSColor := clNavy;
  1446.   TextColor := clblack;
  1447.   { Set initial variables before looping for all drives }
  1448.   finished := false;
  1449.   DriveNum := 0;
  1450.   while not finished do
  1451.   begin
  1452.     { Start with no drive found }
  1453.     IconType := 0;
  1454.     { Call the Borland method to get the drive info }
  1455.     DriveType := FindDriveType(DriveNum);
  1456.     { Set its letter and make it uppercase }
  1457.     DriveChar := Chr(DriveNum + ord('a'));
  1458.     DriveChar := Upcase(DriveChar);
  1459.     { Assign an icon based on the drive type; if no drive exists type is nil }
  1460.     case DriveType of
  1461.       dtFloppy  : IconType := 1;
  1462.       dtFixed   : IconType := 2;
  1463.       dtNetwork : IconType := 3;
  1464.       dtCDROM   : IconType := 4;
  1465.       dtRAM     : IconType := 5;
  1466.     end;
  1467.     { Set to check next drive letter }
  1468.     DriveNum := DriveNum + 1;
  1469.     { But if no match then out of drives so set exit flag }
  1470.     if IconType = 0 then finished := true;
  1471.     { If drive was valid then set up the new FileIconPanel on the imported }
  1472.     { Scrollbox                                                            }
  1473.     if not finished then
  1474.     begin
  1475.       { Create the FileIconPanel and set its parent for memory mgmt and display}
  1476.       TheFIP := TFileIconPanel.Create( Self );
  1477.       TheFIP.Parent := Self;
  1478.       { Call its initialize method with imported position values and the   }
  1479.       { preset color scheme, a drive caption, and a minimum font. Note the }
  1480.       { setting of the ExtraData field to non-zero; this signals a drive   }
  1481.       { rather than a file being sent in.                                  }
  1482.       TheFIP.Initialize((( XCounter - 1 ) * TheIconSpacing ),
  1483.        (( YCounter - 1  ) * TheIconSpacing ) , TheIconSize , TheIconSize , 3 ,
  1484.         7 , ButtonColor, ButtonHLColor,
  1485.        ButtonSColor , TextColor , 'DRIVE ' + DriveChar + ':' , 'MS Serif' , [] ,
  1486.        IconType );
  1487.       { Increment the column counter; if it exceeds max move to new row      }
  1488.       { Note that these are 'var' parameters and will export final position. }
  1489.       XCounter := XCounter + 1;
  1490.       if XCounter > MaxIconsInARow then
  1491.       begin
  1492.         XCounter := 1;
  1493.         YCounter := YCounter + 1;
  1494.       end;
  1495.     end;
  1496.   end;
  1497. end;
  1498.  
  1499. { This procedure assigns colors to FIP's based on file attributes }
  1500. procedure TFileIconPanelScrollBox.GetColorsForFileIcon( TheFile : String;
  1501.            var BC , HC , SC , TC : TColor );
  1502. var AmADir      ,             { Booleans hold file attribs }
  1503.     AmAnArchive ,
  1504.     AmAVolumeId ,
  1505.     AmHidden    ,
  1506.     AmReadOnly  ,
  1507.     AmSystem      : Boolean;
  1508. begin
  1509.   { Make the call to internal fileworkbench to set attributes }
  1510.   TheFWB.GetFileAttributes( TheFile , AmADir , AmAnArchive , AmAVolumeId ,
  1511.    AmHidden , AmReadOnly , AmSystem );
  1512.   { Volume ID has no subtypes }
  1513.   if AmAVolumeID then
  1514.   begin
  1515.     BC := clOlive;
  1516.     HC := clYellow;
  1517.     SC := clBlack;
  1518.     TC := clWhite;
  1519.     exit;
  1520.   end;
  1521.   { Check all directory combinations }
  1522.   if AmADir then
  1523.   begin
  1524.     BC := clNavy;
  1525.     HC := clBlue;
  1526.     SC := clBlack;
  1527.     TC := clWhite;
  1528.     if AmHidden then
  1529.     begin
  1530.       if AmReadOnly then
  1531.       begin
  1532.         if AmSystem then
  1533.         begin { One HECK of a file! }
  1534.           BC := clBlack;
  1535.           HC := clSilver;
  1536.           SC := clGray;
  1537.           TC := clWhite;
  1538.         end
  1539.         else
  1540.         begin { Dir,RO,Hid }
  1541.           BC := clMaroon;
  1542.           HC := clFuchsia;
  1543.           SC := clGreen;
  1544.           TC := clWhite;
  1545.         end;
  1546.       end
  1547.       else
  1548.       begin { Dir,Hid }
  1549.         BC := clPurple;
  1550.         HC := clFuchsia;
  1551.         SC := clBlack;
  1552.         TC := clWhite;
  1553.       end;
  1554.     end
  1555.     else
  1556.     begin
  1557.       if AmReadOnly then
  1558.       begin
  1559.         if AmSystem then
  1560.         begin { Dir,RO,Sys }
  1561.           BC := clMaroon;
  1562.           HC := clLime;
  1563.           SC := clGreen;
  1564.           TC := clWhite;
  1565.         end
  1566.         else
  1567.         begin { Dir,RO }
  1568.           BC := clGreen;
  1569.           HC := clLime;
  1570.           SC := clBlack;
  1571.           TC := clWhite;
  1572.         end;
  1573.       end
  1574.       else
  1575.       begin
  1576.         if AmSystem then
  1577.         begin { Dir,Sys }
  1578.           BC := clMaroon;
  1579.           HC := clRed;
  1580.           SC := clBlack;
  1581.           TC := clWhite;
  1582.         end;
  1583.       end;
  1584.     end;
  1585.   end
  1586.   else { Archive Only; check all combinations }
  1587.   begin
  1588.     BC := clSilver;
  1589.     HC := clWhite;
  1590.     SC := clGray;
  1591.     TC := clBlack;
  1592.     if AmHidden then
  1593.     begin
  1594.       if AmReadOnly then
  1595.       begin
  1596.         if AmSystem then
  1597.         begin { Hid,RO,Sys }
  1598.           BC := clRed;
  1599.           HC := clLime;
  1600.           SC := clPurple;
  1601.           TC := clBlack;
  1602.         end
  1603.         else
  1604.         begin { RO,Hid }
  1605.           BC := clLime;
  1606.           HC := clFuchsia;
  1607.           SC := clMaroon;
  1608.           TC := clBlack;
  1609.         end;
  1610.       end
  1611.       else
  1612.       begin { Hid }
  1613.         BC := clFuchsia;
  1614.         HC := clWhite;
  1615.         SC := clPurple;
  1616.         TC := clBlack;
  1617.       end;
  1618.     end
  1619.     else
  1620.     begin
  1621.       if AmReadOnly then
  1622.       begin
  1623.         if AmSystem then
  1624.         begin { RO,Sys }
  1625.           BC := clRed;
  1626.           HC := clLime;
  1627.           SC := clMaroon;
  1628.           TC := clBlack;
  1629.         end
  1630.         else
  1631.         begin { RO }
  1632.           BC := clLime;
  1633.           HC := clWhite;
  1634.           SC := clGreen;
  1635.           TC := clBlack;
  1636.         end;
  1637.       end
  1638.       else
  1639.       begin
  1640.         if AmSystem then
  1641.         begin { System }
  1642.           BC := clRed;
  1643.           HC := clWhite;
  1644.           SC := clMaroon;
  1645.           TC := clBlack;
  1646.         end;
  1647.       end;
  1648.     end;
  1649.   end;
  1650. end;
  1651.  
  1652. { This procedure gets all icons for an given directory, including drives and }
  1653. { standard subdirectories. It does not get special combinations or h/ro/sys  }
  1654. procedure TFileIconPanelScrollbox.GetIconsForEntireDirectory(
  1655.             TargetPath  : String );
  1656. var Finished        : Boolean;         { Loop flag              }
  1657.     TheSR           : TSearchRec;      { Searchrecord for FF/FN }
  1658.     TheResult       : Integer;         { return variable        }
  1659.     TempPath        : String;          { path for FF/FN         }
  1660.     TheFIP          : TFileIconPanel;  { generic FIP holder     }
  1661.     RowCounter    ,                    { position in row of FIP }
  1662.     ColumnCounter   : Integer;         { position in col of FIP }
  1663.     ButtonColor   ,                    { main panel color       }
  1664.     ButtonHLColor ,                    { bright panel color     }
  1665.     ButtonSColor  ,                    { dark panel color       }
  1666.     Textcolor       : TColor;          { label text color       }
  1667.     IsADir ,                           { Variable for file attr }
  1668.     IsAnArchive ,
  1669.     IsAVolumeID,
  1670.     IsAReadOnlyFile,
  1671.     IsAHiddenFile ,
  1672.     IsASystemFile     : Boolean;
  1673.     MaxTextLength     : Integer;       { Used to safely set size}
  1674. begin
  1675.   { hide during refresh }
  1676.   Visible := false;
  1677.   { Delete the current set, if any }
  1678.   ClearTheFIPs;
  1679.   { Get the icon sizes }
  1680.   TheFIP := TFileIconPanel.Create( Self );
  1681.   TheFIP.Parent := Self;
  1682.   TheFIP.FTheLabel.Canvas.Font.Name := 'MS Serif';
  1683.   TheFIP.FTheLabel.Canvas.Font.Size := 7;
  1684.   MaxTextLength := TheFIP.FTheLabel.Canvas.TextWidth( 'COMMAND.COM' );
  1685.   TheFIP.Free;
  1686.   TheIconSize := MaxTextLength + 13;
  1687.   TheIconSpacing := TheIconSize + 5;
  1688.   { Set up maximum icons per row based on screen size }
  1689.   MaxIconsInARow := ( Screen.Width div TheIconSpacing );
  1690.   { Set up the position counters }
  1691.   RowCounter := 1;
  1692.   ColumnCounter := 1;
  1693.   { Get the drives for the current machine }
  1694.   AddDriveIcons( ColumnCounter , RowCounter  );
  1695.   { Set up the initial variables }
  1696.   Finished := false;
  1697.   TempPath := TargetPath + '*.*';
  1698.   { Make the call to FindFirst set to get any file; will return '.' }
  1699.   { so discard it.                                                  }
  1700.   TheResult := FindFirst( TempPath , faAnyFile , TheSR );
  1701.   { loop through all files in the directory and look for directories }
  1702.   while not Finished do
  1703.   begin
  1704.     { Make call to FindNext, using only SearchRecord from FindFirst }
  1705.     TheResult := FindNext( TheSR );
  1706.     { A -1 result means no more files so exit }
  1707.     if TheResult < 0 then finished := true else
  1708.     begin
  1709.       { Otherwise check for a directory attribute }
  1710.       if (( FileGetAttr( TargetPath + TheSR.Name ) and faDirectory ) =
  1711.        faDirectory ) then
  1712.       begin
  1713.         GetColorsForFileIcon( TargetPath + TheSR.Name , ButtonColor ,
  1714.          ButtonHLColor , ButtonSColor , TextColor );
  1715.         { If found create a new FileIconPanel on the imported scrollbox }
  1716.         { Note sending 0 ExtraData parameter to indicate file not drive }
  1717.         TheFIP := TFileIconPanel.Create( Self );
  1718.         TheFIP.Parent := Self;
  1719.         TheFIP.Initialize((( ColumnCounter - 1 ) * TheIconSpacing ),
  1720.          (( RowCounter - 1  ) * TheIconSpacing ) , TheIconSize, TheIconSize ,
  1721.           3 , 7 , ButtonColor, ButtonHLColor , ButtonSColor , TextColor ,
  1722.            TargetPath + TheSr.Name , 'MS Serif' , [] , 0 );
  1723.         { Increment column counter and move to new row if past limit }
  1724.         ColumnCounter := ColumnCounter + 1;
  1725.         if ColumnCounter > MaxIconsInARow then
  1726.         begin
  1727.           ColumnCounter := 1;
  1728.           RowCounter := RowCounter + 1;
  1729.         end;
  1730.       end;
  1731.     end;
  1732.   end;
  1733.   { Call FindClose for Windows NT/Windows 95 compatibility }
  1734.   FindClose( TheSR );
  1735.   { Set up new initialization variables }
  1736.   Finished := false;
  1737.   TempPath := TargetPath + '*.*';
  1738.   { Make needed call to FindFirst and discard '.' }
  1739.   TheResult := FindFirst( TempPath , faAnyFile , TheSR );
  1740.   while not Finished do
  1741.   begin
  1742.     { Loop through file again, this time getting only archive files }
  1743.     TheResult := FindNext( TheSR );
  1744.     { Result of -1 indicates no more files }
  1745.     if TheResult < 0 then Finished := true else
  1746.     begin
  1747.       { If faArchive file then add new FileIconPanel }
  1748.       TheFWB.GetFileAttributes(( Targetpath + TheSR.Name ) , IsADir ,
  1749.        IsAnArchive , IsAVolumeId , IsAHiddenFile , IsAReadOnlyFile ,
  1750.         IsASystemFile );
  1751.       if (( IsAnArchive ) and ( not IsADir )) then
  1752.       begin
  1753.         GetColorsForFileIcon( TargetPath + TheSR.Name , ButtonColor ,
  1754.          ButtonHLColor , ButtonSColor , TextColor );
  1755.         { Initialize new FileIconPanel and call initialize, sending 0 ED }
  1756.         TheFIP := TFileIconPanel.Create( Self );
  1757.         TheFIP.Parent := Self;
  1758.         TheFIP.Initialize((( ColumnCounter - 1 ) * TheIconSpacing ),
  1759.          (( RowCounter - 1  ) * TheIconSpacing ) , TheIconSize , TheIconSize ,
  1760.           3 , 7 , ButtonColor, ButtonHLColor , ButtonSColor , TextColor ,
  1761.            TargetPath + TheSr.Name , 'MS Serif' , [] , 0 );
  1762.         { Increment column counter and if needed row counter }
  1763.         ColumnCounter := ColumnCounter + 1;
  1764.         if ColumnCounter > MaxIconsInARow then
  1765.         begin
  1766.           ColumnCounter := 1;
  1767.           RowCounter := RowCounter + 1;
  1768.         end;
  1769.       end;
  1770.     end;
  1771.   end;
  1772.   { Call findclose for w95 and exit }
  1773.   FindClose( TheSR );
  1774.   { Reset to visible }
  1775.   Visible := true;
  1776. end;
  1777.  
  1778. { Update method for FIPscrollbox }
  1779. procedure TFileIconPanelScrollBox.Update;
  1780. begin
  1781.   IconsNeedRefreshing := true;
  1782.   { Force a repaint }
  1783.   InvalidateRect( TheStoredHandle , nil , true );
  1784. end;
  1785.  
  1786. { Create method for FIPScrollbox }
  1787. constructor TFileIconPanelScrollBox.Create( AOwner : TComponent );
  1788. begin
  1789.   inherited Create( AOwner );
  1790.   TheFWB := TFileWorkBench.Create( Self );
  1791. end;
  1792.  
  1793. { This function returns the next selected file's name }
  1794. function TFileIconPanelScrollBox.GetNextSelection( SourceDirectory : String;
  1795.                            var CurrentItem : Integer ) : String;
  1796. var TheResult    : String;      { Holds result of function }
  1797.     TheComponent : TComponent;  { Used for typecast        }
  1798.     finished     : boolean;     { Loop control variable    }
  1799.     TheComponentCount : Integer;
  1800. begin
  1801.   TheComponentCount := ComponentCount;
  1802.   { If past end of components exit with no result }
  1803.   if CurrentItem > TheComponentCount then TheResult := '' else
  1804.   begin
  1805.     { Set loop counter and run till find match or run out }
  1806.     finished := false;
  1807.     while not finished do
  1808.     begin
  1809.       { Pull component out of the list and check it }
  1810.       TheComponent := Components[ CurrentItem - 1 ];
  1811.       { Increment counter for later }
  1812.       CurrentItem := CurrentItem + 1;
  1813.       { Do the typecast with AS }
  1814.       with TheComponent as TFileIconPanel do
  1815.       begin
  1816.         { If its selected make sure OK }
  1817.         if Selected then
  1818.         begin
  1819.           { Don't accept backup for this level of operation }
  1820.           if FTheLabel.Caption <> '..' then
  1821.           begin
  1822.             { Otherwise return the name and abort the loop }
  1823.             TheResult := FTheName;
  1824.             finished := true;
  1825.           end;
  1826.         end
  1827.         else
  1828.         begin
  1829.           { Check to see if out of components }
  1830.           if CurrentItem > TheComponentCount then
  1831.           begin
  1832.             { If so signal error and abort }
  1833.             TheResult := '';
  1834.             finished := true;
  1835.           end;
  1836.         end;
  1837.       end;
  1838.     end;
  1839.   end;
  1840.   GetNextSelection := TheResult;
  1841. end;
  1842.  
  1843. { This procedure places a selection of files in the display based on wildcards }
  1844. procedure TFileIconPanelScrollBox.DisplayRecursiveSearchResults(
  1845.            TheStartingDirectory : String );
  1846. var XCounter ,
  1847.     YCounter   : Integer;
  1848.  
  1849. { This procedure does a recursive file search by first getting all matches (in-}
  1850. { cluding directories) and adding them to the list. Then it checks for ALL the }
  1851. { subdirectories and does the same trick on them til there are no more matches }
  1852. { and no more subdirectories, at which point it exits and recurses back up.    }
  1853. procedure RecursiveFileSearch( TheWorkingDirectory : String; var XCounter ,
  1854.                                YCounter : Integer );
  1855.  
  1856. { VITAL!!! These variables MUST be local for recursrion to work! }
  1857. var
  1858.     Finished        : Boolean;         { Loop flag              }
  1859.     TheSR           : TSearchRec;      { Searchrecord for FF/FN }
  1860.     TheResult       : Integer;         { return variable        }
  1861.     TargetPath ,
  1862.     FileMask   ,
  1863.     TheStoredWorkingDirectory ,
  1864.     ModifiedDirectory  : String;       { path for FF/FN         }
  1865.     TheFIP          : TFileIconPanel;  { generic FIP holder     }
  1866.     ButtonColor   ,                    { main panel color       }
  1867.     ButtonHLColor ,                    { bright panel color     }
  1868.     ButtonSColor  ,                    { dark panel color       }
  1869.     Textcolor       : TColor;          { label text color       }
  1870.  
  1871. begin
  1872.   { Set up the initial variables }
  1873.   Finished := false;
  1874.   TheStoredWorkingDirectory := TheWorkingDirectory;
  1875.   Targetpath := ExtractFilePath( TheWorkingDirectory );
  1876.   FileMask := ExtractFileName( TheWorkingDirectory );
  1877.   { Make the call to FindFirst set to get any file }
  1878.   TheResult := FindFirst( TheWorkingDirectory , faAnyFile , TheSR );
  1879.   if TheResult < 0 then finished := true;
  1880.   if (( TheSr.Name <> '.' ) and ( TheSr.Name <> '..' ) and ( TheResult >= 0 ))
  1881.   then begin
  1882.     if (( FileGetAttr( TargetPath + TheSR.Name ) and faDirectory ) =
  1883.      faDirectory ) then
  1884.     begin { A directory }
  1885.       GetColorsForFileIcon( TargetPath + TheSR.Name , ButtonColor ,
  1886.        ButtonHLColor , ButtonSColor , TextColor );
  1887.       { If found create a new FileIconPanel on the imported scrollbox }
  1888.       { Note sending 0 ExtraData parameter to indicate file not drive }
  1889.       TheFIP := TFileIconPanel.Create( Self );
  1890.       TheFIP.Parent := Self;
  1891.       TheFIP.Initialize((( XCounter - 1 ) * TheIconSpacing ),
  1892.        (( YCounter - 1  ) * TheIconSpacing ) , TheIconSize , TheIconSize , 3 ,
  1893.         7 , ButtonColor, ButtonHLColor , ButtonSColor , TextColor , TargetPath
  1894.          + TheSr.Name , 'MS Serif' , [] , 0 );
  1895.       { Increment column counter and move to new row if past limit }
  1896.       XCounter := XCounter + 1;
  1897.       if XCounter > MaxIconsInARow then
  1898.       begin
  1899.         XCounter := 1;
  1900.         YCounter := YCounter + 1;
  1901.       end;
  1902.     end
  1903.     else
  1904.     begin { A File }
  1905.       { Set up the default color scheme for files }
  1906.       GetColorsForFileIcon( TargetPath + TheSR.Name , ButtonColor ,
  1907.        ButtonHLColor , ButtonSColor , TextColor );
  1908.       { If found create a new FileIconPanel on the imported scrollbox }
  1909.       { Note sending 0 ExtraData parameter to indicate file not drive }
  1910.       TheFIP := TFileIconPanel.Create( Self );
  1911.       TheFIP.Parent := Self;
  1912.       TheFIP.Initialize((( XCounter - 1 ) * TheIconSpacing ),
  1913.        (( YCounter - 1  ) * TheIconSpacing ) , TheIconSize, TheIconSize , 3 ,
  1914.         7 , ButtonColor, ButtonHLColor , ButtonSColor , TextColor , TargetPath
  1915.          + TheSr.Name , 'MS Serif' , [] , 0 );
  1916.       { Increment column counter and move to new row if past limit }
  1917.       XCounter := XCounter + 1;
  1918.       if XCounter > MaxIconsInARow then
  1919.       begin
  1920.         XCounter := 1;
  1921.         YCounter := YCounter + 1;
  1922.       end;
  1923.     end;
  1924.   end;
  1925.   { loop through all files in the directory and look for matches }
  1926.   while not Finished do
  1927.   begin
  1928.     { Make call to FindNext, using only SearchRecord from FindFirst }
  1929.     TheResult := FindNext( TheSR );
  1930.     { A -1 result means no more files so exit }
  1931.     if TheResult < 0 then finished := true else
  1932.     begin
  1933.       if (( FileGetAttr( TargetPath + TheSR.Name ) and faDirectory ) =
  1934.        faDirectory ) then
  1935.       begin { A directory }
  1936.         { Set up the blue color scheme for directories }
  1937.         GetColorsForFileIcon( TargetPath + TheSR.Name , ButtonColor ,
  1938.          ButtonHLColor , ButtonSColor , TextColor );
  1939.         { If found create a new FileIconPanel on the imported scrollbox }
  1940.         { Note sending 0 ExtraData parameter to indicate file not drive }
  1941.         TheFIP := TFileIconPanel.Create( Self );
  1942.         TheFIP.Parent := Self;
  1943.         TheFIP.Initialize((( XCounter - 1 ) * TheIconSpacing ),
  1944.          (( YCounter - 1  ) * TheIconSpacing ) , TheIconSize , TheIconSize , 3 ,
  1945.            7 , ButtonColor, ButtonHLColor , ButtonSColor , TextColor ,
  1946.             TargetPath + TheSr.Name , 'MS Serif' , [] , 0 );
  1947.         { Increment column counter and move to new row if past limit }
  1948.         XCounter := XCounter + 1;
  1949.         if XCounter > MaxIconsInARow then
  1950.         begin
  1951.           XCounter := 1;
  1952.           YCounter := YCounter + 1;
  1953.         end;
  1954.       end
  1955.       else
  1956.       begin { A File }
  1957.         { Set up the default color scheme for files }
  1958.         GetColorsForFileIcon( TargetPath + TheSR.Name , ButtonColor ,
  1959.          ButtonHLColor , ButtonSColor , TextColor );
  1960.         { If found create a new FileIconPanel on the imported scrollbox }
  1961.         { Note sending 0 ExtraData parameter to indicate file not drive }
  1962.         TheFIP := TFileIconPanel.Create( Self );
  1963.         TheFIP.Parent := Self;
  1964.         TheFIP.Initialize((( XCounter - 1 ) * TheIconSpacing ),
  1965.          (( YCounter - 1  ) * TheIconSpacing ) , TheIconSize , TheIconSize , 3 ,
  1966.           7 , ButtonColor, ButtonHLColor , ButtonSColor , TextColor ,
  1967.            TargetPath + TheSr.Name , 'MS Serif' , [] , 0 );
  1968.         { Increment column counter and move to new row if past limit }
  1969.         XCounter := XCounter + 1;
  1970.         if XCounter > MaxIconsInARow then
  1971.         begin
  1972.           XCounter := 1;
  1973.           YCounter := YCounter + 1;
  1974.         end;
  1975.       end;
  1976.     end;
  1977.   end;
  1978.   { Call FindClose for Windows NT/Windows 95 compatibility }
  1979.   FindClose( TheSR );
  1980.   { Set up the variables to do recursive calls on all directories}
  1981.   Finished := false;
  1982.   ModifiedDirectory := ExtractFilePath( TheWorkingdirectory ) + '*.*';
  1983.   { Make the call to FindFirst set to get any file, ignore result }
  1984.   TheResult := FindFirst( ModifiedDirectory , faDirectory , TheSR );
  1985.   while not Finished do
  1986.   begin
  1987.     { Make call to FindNext, using only SearchRecord from FindFirst }
  1988.     TheResult := FindNext( TheSR );
  1989.     { A -1 result means no more files so exit }
  1990.     if TheResult < 0 then finished := true
  1991.     else
  1992.     begin
  1993.       if TheSR.Name <> '..' then { Ignore backup in this case }
  1994.       begin
  1995.         { Do second check due to bug in FindNext }
  1996.         if (( FileGetAttr( TargetPath + TheSR.Name ) and faDirectory )
  1997.         = faDirectory ) then
  1998.         begin
  1999.           { Set up modified directory to recurse into }
  2000.           ModifiedDirectory := ExtractFilePath( TheStoredWorkingDirectory ) +
  2001.            TheSR.Name + '\' + FileMask;
  2002.           { Perform the recursion }
  2003.           RecursiveFileSearch( ModifiedDirectory , XCounter , YCounter );
  2004.         end;
  2005.       end;
  2006.     end;
  2007.   end;
  2008. end;
  2009.  
  2010. begin
  2011.   { Keep the scrollbox from updating during refresh }
  2012.   Visible := false;
  2013.   { Make the clear call }
  2014.   ClearTheFIPs;
  2015.   XCounter := 1;
  2016.   YCounter := 1;
  2017.   { Get the drives for the current machine }
  2018.   AddDriveIcons( XCounter , YCounter );
  2019.   RecursiveFileSearch( TheStartingDirectory , XCounter , YCounter );
  2020.   { Make the scrollbox visible again }
  2021.   Visible := true;
  2022. end;
  2023.  
  2024. end.
  2025.