| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859 |
- unit DragDropFile;
- // -----------------------------------------------------------------------------
- // Project: Drag and Drop Component Suite.
- // Module: DragDropFile
- // Description: Implements Dragging and Dropping of files and folders.
- // Version: 4.0
- // Date: 18-MAY-2001
- // Target: Win32, Delphi 5-6
- // Authors: Anders Melander, anders@melander.dk, http://www.melander.dk
- // Copyright © 1997-2001 Angus Johnson & Anders Melander
- // -----------------------------------------------------------------------------
- interface
- uses
- DragDrop,
- DropTarget,
- DropSource,
- DragDropFormats,
- ActiveX,
- Windows,
- Classes;
- type
- ////////////////////////////////////////////////////////////////////////////////
- //
- // TFileClipboardFormat
- //
- ////////////////////////////////////////////////////////////////////////////////
- TFileClipboardFormat = class(TCustomSimpleClipboardFormat)
- private
- FFiles: TStrings;
- protected
- function ReadData(Value: pointer; Size: integer): boolean; override;
- function WriteData(Value: pointer; Size: integer): boolean; override;
- function GetSize: integer; override;
- public
- constructor Create; override;
- destructor Destroy; override;
- function GetClipboardFormat: TClipFormat; override;
- function Assign(Source: TCustomDataFormat): boolean; override;
- function AssignTo(Dest: TCustomDataFormat): boolean; override;
- procedure Clear; override;
- function HasData: boolean; override;
- property Files: TStrings read FFiles;
- end;
- ////////////////////////////////////////////////////////////////////////////////
- //
- // TFilenameClipboardFormat
- //
- ////////////////////////////////////////////////////////////////////////////////
- TFilenameClipboardFormat = class(TCustomTextClipboardFormat)
- public
- function GetClipboardFormat: TClipFormat; override;
- function Assign(Source: TCustomDataFormat): boolean; override;
- function AssignTo(Dest: TCustomDataFormat): boolean; override;
- property Filename: string read GetString write SetString;
- end;
- ////////////////////////////////////////////////////////////////////////////////
- //
- // TFilenameWClipboardFormat
- //
- ////////////////////////////////////////////////////////////////////////////////
- TFilenameWClipboardFormat = class(TCustomWideTextClipboardFormat)
- public
- function GetClipboardFormat: TClipFormat; override;
- function Assign(Source: TCustomDataFormat): boolean; override;
- function AssignTo(Dest: TCustomDataFormat): boolean; override;
- property Filename: WideString read GetText write SetText;
- end;
- ////////////////////////////////////////////////////////////////////////////////
- //
- // TFilenameMapClipboardFormat
- //
- ////////////////////////////////////////////////////////////////////////////////
- // DONE -oanme -cStopShip : Rename TFilenameMapClipboardFormat to TFilenameMapClipboardFormat. Also wide version.
- TFilenameMapClipboardFormat = class(TCustomSimpleClipboardFormat)
- private
- FFileMaps : TStrings;
- protected
- function ReadData(Value: pointer; Size: integer): boolean; override;
- function WriteData(Value: pointer; Size: integer): boolean; override;
- function GetSize: integer; override;
- public
- constructor Create; override;
- destructor Destroy; override;
- function GetClipboardFormat: TClipFormat; override;
- procedure Clear; override;
- function HasData: boolean; override;
- property FileMaps: TStrings read FFileMaps;
- end;
- ////////////////////////////////////////////////////////////////////////////////
- //
- // TFilenameMapWClipboardFormat
- //
- ////////////////////////////////////////////////////////////////////////////////
- TFilenameMapWClipboardFormat = class(TCustomSimpleClipboardFormat)
- private
- FFileMaps : TStrings;
- protected
- function ReadData(Value: pointer; Size: integer): boolean; override;
- function WriteData(Value: pointer; Size: integer): boolean; override;
- function GetSize: integer; override;
- public
- constructor Create; override;
- destructor Destroy; override;
- function GetClipboardFormat: TClipFormat; override;
- procedure Clear; override;
- function HasData: boolean; override;
- property FileMaps: TStrings read FFileMaps;
- end;
- ////////////////////////////////////////////////////////////////////////////////
- //
- // TFileMapDataFormat
- //
- ////////////////////////////////////////////////////////////////////////////////
- TFileMapDataFormat = class(TCustomDataFormat)
- private
- FFileMaps : TStrings;
- public
- constructor Create(AOwner: TDragDropComponent); override;
- destructor Destroy; override;
- function Assign(Source: TClipboardFormat): boolean; override;
- function AssignTo(Dest: TClipboardFormat): boolean; override;
- procedure Clear; override;
- function HasData: boolean; override;
- function NeedsData: boolean; override;
- property FileMaps: TStrings read FFileMaps;
- end;
- ////////////////////////////////////////////////////////////////////////////////
- //
- // TFileDataFormat
- //
- ////////////////////////////////////////////////////////////////////////////////
- TFileDataFormat = class(TCustomDataFormat)
- private
- FFiles : TStrings;
- protected
- public
- constructor Create(AOwner: TDragDropComponent); override;
- destructor Destroy; override;
- function Assign(Source: TClipboardFormat): boolean; override;
- function AssignTo(Dest: TClipboardFormat): boolean; override;
- procedure Clear; override;
- function HasData: boolean; override;
- function NeedsData: boolean; override;
- property Files: TStrings read FFiles;
- end;
- ////////////////////////////////////////////////////////////////////////////////
- //
- // TDropFileTarget
- //
- ////////////////////////////////////////////////////////////////////////////////
- TDropFileTarget = class(TCustomDropMultiTarget)
- private
- FFileFormat : TFileDataFormat;
- FFileMapFormat : TFileMapDataFormat;
- protected
- function GetFiles: TStrings;
- function GetMappedNames: TStrings;
- function GetPreferredDropEffect: LongInt; override;
- public
- constructor Create(AOwner: TComponent); override;
- destructor Destroy; override;
- property Files: TStrings read GetFiles;
- property MappedNames: TStrings read GetMappedNames;
- end;
- ////////////////////////////////////////////////////////////////////////////////
- //
- // TDropFileSource
- //
- ////////////////////////////////////////////////////////////////////////////////
- TDropFileSource = class(TCustomDropMultiSource)
- private
- FFileFormat : TFileDataFormat;
- FFileMapFormat : TFileMapDataFormat;
- function GetFiles: TStrings;
- function GetMappedNames: TStrings;
- protected
- procedure SetFiles(AFiles: TStrings);
- procedure SetMappedNames(ANames: TStrings);
- public
- constructor Create(aOwner: TComponent); override;
- destructor Destroy; override;
- published
- property Files: TStrings read GetFiles write SetFiles;
- // MappedNames is only needed if files need to be renamed during a drag op.
- // E.g. dragging from 'Recycle Bin'.
- property MappedNames: TStrings read GetMappedNames write SetMappedNames;
- end;
- ////////////////////////////////////////////////////////////////////////////////
- //
- // Component registration
- //
- ////////////////////////////////////////////////////////////////////////////////
- procedure Register;
- ////////////////////////////////////////////////////////////////////////////////
- //
- // Misc.
- //
- ////////////////////////////////////////////////////////////////////////////////
- function ReadFilesFromHGlobal(const HGlob: HGlobal; Files: TStrings): boolean; // V4: renamed
- function ReadFilesFromData(Data: pointer; Size: integer; Files: TStrings): boolean;
- function ReadFilesFromZeroList(Data: pointer; Size: integer;
- Wide: boolean; Files: TStrings): boolean;
- function WriteFilesToZeroList(Data: pointer; Size: integer;
- Wide: boolean; Files: TStrings): boolean;
- ////////////////////////////////////////////////////////////////////////////////
- ////////////////////////////////////////////////////////////////////////////////
- //
- // IMPLEMENTATION
- //
- ////////////////////////////////////////////////////////////////////////////////
- ////////////////////////////////////////////////////////////////////////////////
- implementation
- uses
- DragDropPIDL,
- SysUtils,
- ShlObj;
- ////////////////////////////////////////////////////////////////////////////////
- //
- // Component registration
- //
- ////////////////////////////////////////////////////////////////////////////////
- procedure Register;
- begin
- RegisterComponents(DragDropComponentPalettePage, [TDropFileTarget,
- TDropFileSource]);
- end;
- ////////////////////////////////////////////////////////////////////////////////
- //
- // Utilities
- //
- ////////////////////////////////////////////////////////////////////////////////
- function ReadFilesFromHGlobal(const HGlob: HGlobal; Files: TStrings): boolean;
- var
- DropFiles : PDropFiles;
- begin
- DropFiles := PDropFiles(GlobalLock(HGlob));
- try
- Result := ReadFilesFromData(DropFiles, GlobalSize(HGlob), Files)
- finally
- GlobalUnlock(HGlob);
- end;
- end;
- function ReadFilesFromData(Data: pointer; Size: integer; Files: TStrings): boolean;
- var
- Wide : boolean;
- begin
- Files.Clear;
- if (Data <> nil) then
- begin
- Wide := PDropFiles(Data)^.fWide;
- dec(Size, PDropFiles(Data)^.pFiles);
- inc(PChar(Data), PDropFiles(Data)^.pFiles);
- ReadFilesFromZeroList(Data, Size, Wide, Files);
- end;
- Result := (Files.Count > 0);
- end;
- function ReadFilesFromZeroList(Data: pointer; Size: integer;
- Wide: boolean; Files: TStrings): boolean;
- var
- StringSize : integer;
- begin
- Result := False;
- if (Data <> nil) then
- while (Size > 0) and (PChar(Data)^ <> #0) do
- begin
- if (Wide) then
- begin
- Files.Add(PWideChar(Data));
- StringSize := (Length(PWideChar(Data)) + 1) * 2;
- end else
- begin
- Files.Add(PChar(Data));
- StringSize := Length(PChar(Data)) + 1;
- end;
- inc(PChar(Data), StringSize);
- dec(Size, StringSize);
- Result := True;
- end;
- end;
- function WriteFilesToZeroList(Data: pointer; Size: integer;
- Wide: boolean; Files: TStrings): boolean;
- var
- i : integer;
- begin
- Result := False;
- if (Data <> nil) then
- begin
- i := 0;
- dec(Size);
- while (Size > 0) and (i < Files.Count) do
- begin
- if (Wide) then
- begin
- StringToWideChar(Files[i], Data, Size);
- dec(Size, (Length(Files[i])+1)*2);
- end else
- begin
- StrPLCopy(Data, Files[i], Size);
- dec(Size, Length(Files[i])+1);
- end;
- inc(PChar(Data), Length(Files[i])+1);
- inc(i);
- Result := True;
- end;
- // Final teminating zero.
- if (Size >= 0) then
- PChar(Data)^ := #0;
- end;
- end;
- ////////////////////////////////////////////////////////////////////////////////
- //
- // TFileClipboardFormat
- //
- ////////////////////////////////////////////////////////////////////////////////
- constructor TFileClipboardFormat.Create;
- begin
- inherited Create;
- FFiles := TStringList.Create;
- // Note: Setting dwAspect to DVASPECT_SHORT will request that the data source
- // returns the file names in short (8.3) format.
- // FFormatEtc.dwAspect := DVASPECT_SHORT;
- end;
- destructor TFileClipboardFormat.Destroy;
- begin
- FFiles.Free;
- inherited Destroy;
- end;
- function TFileClipboardFormat.GetClipboardFormat: TClipFormat;
- begin
- Result := CF_HDROP;
- end;
- procedure TFileClipboardFormat.Clear;
- begin
- FFiles.Clear;
- end;
- function TFileClipboardFormat.HasData: boolean;
- begin
- Result := (FFiles.Count > 0);
- end;
- function TFileClipboardFormat.GetSize: integer;
- var
- i : integer;
- begin
- Result := SizeOf(TDropFiles) + FFiles.Count + 1;
- for i := 0 to FFiles.Count-1 do
- inc(Result, Length(FFiles[i]));
- end;
- function TFileClipboardFormat.ReadData(Value: pointer;
- Size: integer): boolean;
- begin
- Result := (Size > SizeOf(TDropFiles));
- if (not Result) then
- exit;
- Result := ReadFilesFromData(Value, Size, FFiles);
- end;
- function TFileClipboardFormat.WriteData(Value: pointer;
- Size: integer): boolean;
- begin
- Result := (Size > SizeOf(TDropFiles));
- if (not Result) then
- exit;
- PDropFiles(Value)^.pfiles := SizeOf(TDropFiles);
- PDropFiles(Value)^.fwide := False;
- inc(PChar(Value), SizeOf(TDropFiles));
- dec(Size, SizeOf(TDropFiles));
- WriteFilesToZeroList(Value, Size, False, FFiles);
- end;
- function TFileClipboardFormat.Assign(Source: TCustomDataFormat): boolean;
- begin
- if (Source is TFileDataFormat) then
- begin
- FFiles.Assign(TFileDataFormat(Source).Files);
- Result := True;
- end else
- Result := inherited Assign(Source);
- end;
- function TFileClipboardFormat.AssignTo(Dest: TCustomDataFormat): boolean;
- begin
- if (Dest is TFileDataFormat) then
- begin
- TFileDataFormat(Dest).Files.Assign(FFiles);
- Result := True;
- end else
- Result := inherited AssignTo(Dest);
- end;
- ////////////////////////////////////////////////////////////////////////////////
- //
- // TFilenameClipboardFormat
- //
- ////////////////////////////////////////////////////////////////////////////////
- var
- CF_FILENAMEA: TClipFormat = 0;
- function TFilenameClipboardFormat.GetClipboardFormat: TClipFormat;
- begin
- if (CF_FILENAMEA = 0) then
- CF_FILENAMEA := RegisterClipboardFormat(CFSTR_FILENAMEA);
- Result := CF_FILENAMEA;
- end;
- function TFilenameClipboardFormat.Assign(Source: TCustomDataFormat): boolean;
- begin
- if (Source is TFileDataFormat) then
- begin
- Result := (TFileDataFormat(Source).Files.Count > 0);
- if (Result) then
- Filename := TFileDataFormat(Source).Files[0];
- end else
- Result := inherited Assign(Source);
- end;
- function TFilenameClipboardFormat.AssignTo(Dest: TCustomDataFormat): boolean;
- begin
- if (Dest is TFileDataFormat) then
- begin
- TFileDataFormat(Dest).Files.Add(Filename);
- Result := True;
- end else
- Result := inherited AssignTo(Dest);
- end;
- ////////////////////////////////////////////////////////////////////////////////
- //
- // TFilenameWClipboardFormat
- //
- ////////////////////////////////////////////////////////////////////////////////
- var
- CF_FILENAMEW: TClipFormat = 0;
- function TFilenameWClipboardFormat.GetClipboardFormat: TClipFormat;
- begin
- if (CF_FILENAMEW = 0) then
- CF_FILENAMEW := RegisterClipboardFormat(CFSTR_FILENAMEW);
- Result := CF_FILENAMEW;
- end;
- function TFilenameWClipboardFormat.Assign(Source: TCustomDataFormat): boolean;
- begin
- if (Source is TFileDataFormat) then
- begin
- Result := (TFileDataFormat(Source).Files.Count > 0);
- if (Result) then
- Filename := TFileDataFormat(Source).Files[0];
- end else
- Result := inherited Assign(Source);
- end;
- function TFilenameWClipboardFormat.AssignTo(Dest: TCustomDataFormat): boolean;
- begin
- if (Dest is TFileDataFormat) then
- begin
- TFileDataFormat(Dest).Files.Add(Filename);
- Result := True;
- end else
- Result := inherited AssignTo(Dest);
- end;
- ////////////////////////////////////////////////////////////////////////////////
- //
- // TFilenameMapClipboardFormat
- //
- ////////////////////////////////////////////////////////////////////////////////
- var
- CF_FILENAMEMAP: TClipFormat = 0;
- constructor TFilenameMapClipboardFormat.Create;
- begin
- inherited Create;
- FFileMaps := TStringList.Create;
- end;
- destructor TFilenameMapClipboardFormat.Destroy;
- begin
- FFileMaps.Free;
- inherited Destroy;
- end;
- function TFilenameMapClipboardFormat.GetClipboardFormat: TClipFormat;
- begin
- if (CF_FILENAMEMAP = 0) then
- CF_FILENAMEMAP := RegisterClipboardFormat(CFSTR_FILENAMEMAPA);
- Result := CF_FILENAMEMAP;
- end;
- procedure TFilenameMapClipboardFormat.Clear;
- begin
- FFileMaps.Clear;
- end;
- function TFilenameMapClipboardFormat.HasData: boolean;
- begin
- Result := (FFileMaps.Count > 0);
- end;
- function TFilenameMapClipboardFormat.GetSize: integer;
- var
- i : integer;
- begin
- Result := FFileMaps.Count + 1;
- for i := 0 to FFileMaps.Count-1 do
- inc(Result, Length(FFileMaps[i]));
- end;
- function TFilenameMapClipboardFormat.ReadData(Value: pointer;
- Size: integer): boolean;
- begin
- Result := ReadFilesFromZeroList(Value, Size, False, FFileMaps);
- end;
- function TFilenameMapClipboardFormat.WriteData(Value: pointer;
- Size: integer): boolean;
- begin
- Result := WriteFilesToZeroList(Value, Size, False, FFileMaps);
- end;
- ////////////////////////////////////////////////////////////////////////////////
- //
- // TFilenameMapWClipboardFormat
- //
- ////////////////////////////////////////////////////////////////////////////////
- var
- CF_FILENAMEMAPW: TClipFormat = 0;
- constructor TFilenameMapWClipboardFormat.Create;
- begin
- inherited Create;
- FFileMaps := TStringList.Create;
- end;
- destructor TFilenameMapWClipboardFormat.Destroy;
- begin
- FFileMaps.Free;
- inherited Destroy;
- end;
- function TFilenameMapWClipboardFormat.GetClipboardFormat: TClipFormat;
- begin
- if (CF_FILENAMEMAPW = 0) then
- CF_FILENAMEMAPW := RegisterClipboardFormat(CFSTR_FILENAMEMAPW);
- Result := CF_FILENAMEMAPW;
- end;
- procedure TFilenameMapWClipboardFormat.Clear;
- begin
- FFileMaps.Clear;
- end;
- function TFilenameMapWClipboardFormat.HasData: boolean;
- begin
- Result := (FFileMaps.Count > 0);
- end;
- function TFilenameMapWClipboardFormat.GetSize: integer;
- var
- i : integer;
- begin
- Result := FFileMaps.Count + 1;
- for i := 0 to FFileMaps.Count-1 do
- inc(Result, Length(FFileMaps[i]));
- inc(Result, Result);
- end;
- function TFilenameMapWClipboardFormat.ReadData(Value: pointer;
- Size: integer): boolean;
- begin
- Result := ReadFilesFromZeroList(Value, Size, True, FFileMaps);
- end;
- function TFilenameMapWClipboardFormat.WriteData(Value: pointer;
- Size: integer): boolean;
- begin
- Result := WriteFilesToZeroList(Value, Size, True, FFileMaps);
- end;
- ////////////////////////////////////////////////////////////////////////////////
- //
- // TFileMapDataFormat
- //
- ////////////////////////////////////////////////////////////////////////////////
- constructor TFileMapDataFormat.Create(AOwner: TDragDropComponent);
- begin
- inherited Create(AOwner);
- FFileMaps := TStringList.Create;
- TStringList(FFileMaps).OnChanging := DoOnChanging;
- end;
- destructor TFileMapDataFormat.Destroy;
- begin
- FFileMaps.Free;
- inherited Destroy;
- end;
- function TFileMapDataFormat.Assign(Source: TClipboardFormat): boolean;
- begin
- Result := True;
- if (Source is TFilenameMapClipboardFormat) then
- FFileMaps.Assign(TFilenameMapClipboardFormat(Source).FileMaps)
- else if (Source is TFilenameMapWClipboardFormat) then
- FFileMaps.Assign(TFilenameMapWClipboardFormat(Source).FileMaps)
- else
- Result := inherited Assign(Source);
- end;
- function TFileMapDataFormat.AssignTo(Dest: TClipboardFormat): boolean;
- begin
- Result := True;
- if (Dest is TFilenameMapClipboardFormat) then
- TFilenameMapClipboardFormat(Dest).FileMaps.Assign(FFileMaps)
- else if (Dest is TFilenameMapWClipboardFormat) then
- TFilenameMapWClipboardFormat(Dest).FileMaps.Assign(FFileMaps)
- else
- Result := inherited AssignTo(Dest);
- end;
- procedure TFileMapDataFormat.Clear;
- begin
- FFileMaps.Clear;
- end;
- function TFileMapDataFormat.HasData: boolean;
- begin
- Result := (FFileMaps.Count > 0);
- end;
- function TFileMapDataFormat.NeedsData: boolean;
- begin
- Result := (FFileMaps.Count = 0);
- end;
- ////////////////////////////////////////////////////////////////////////////////
- //
- // TFileDataFormat
- //
- ////////////////////////////////////////////////////////////////////////////////
- constructor TFileDataFormat.Create(AOwner: TDragDropComponent);
- begin
- inherited Create(AOwner);
- FFiles := TStringList.Create;
- TStringList(FFiles).OnChanging := DoOnChanging;
- end;
- destructor TFileDataFormat.Destroy;
- begin
- FFiles.Free;
- inherited Destroy;
- end;
- function TFileDataFormat.Assign(Source: TClipboardFormat): boolean;
- begin
- Result := True;
- if (Source is TFileClipboardFormat) then
- FFiles.Assign(TFileClipboardFormat(Source).Files)
- else if (Source is TPIDLClipboardFormat) then
- FFiles.Assign(TPIDLClipboardFormat(Source).Filenames)
- else
- Result := inherited Assign(Source);
- end;
- function TFileDataFormat.AssignTo(Dest: TClipboardFormat): boolean;
- begin
- Result := True;
- if (Dest is TFileClipboardFormat) then
- TFileClipboardFormat(Dest).Files.Assign(FFiles)
- else if (Dest is TPIDLClipboardFormat) then
- TPIDLClipboardFormat(Dest).Filenames.Assign(FFiles)
- else
- Result := inherited AssignTo(Dest);
- end;
- procedure TFileDataFormat.Clear;
- begin
- FFiles.Clear;
- end;
- function TFileDataFormat.HasData: boolean;
- begin
- Result := (FFiles.Count > 0);
- end;
- function TFileDataFormat.NeedsData: boolean;
- begin
- Result := (FFiles.Count = 0);
- end;
- ////////////////////////////////////////////////////////////////////////////////
- //
- // TDropFileTarget
- //
- ////////////////////////////////////////////////////////////////////////////////
- constructor TDropFileTarget.Create(AOwner: TComponent);
- begin
- inherited Create(AOwner);
- OptimizedMove := True;
- FFileFormat := TFileDataFormat.Create(Self);
- FFileMapFormat := TFileMapDataFormat.Create(Self);
- end;
- destructor TDropFileTarget.Destroy;
- begin
- FFileFormat.Free;
- FFileMapFormat.Free;
- inherited Destroy;
- end;
- function TDropFileTarget.GetFiles: TStrings;
- begin
- Result := FFileFormat.Files;
- end;
- function TDropFileTarget.GetMappedNames: TStrings;
- begin
- Result := FFileMapFormat.FileMaps;
- end;
- function TDropFileTarget.GetPreferredDropEffect: LongInt;
- begin
- Result := inherited GetPreferredDropEffect;
- if (Result = DROPEFFECT_NONE) then
- Result := DROPEFFECT_COPY;
- end;
- ////////////////////////////////////////////////////////////////////////////////
- //
- // TDropFileSource
- //
- ////////////////////////////////////////////////////////////////////////////////
- constructor TDropFileSource.Create(aOwner: TComponent);
- begin
- inherited Create(AOwner);
- FFileFormat := TFileDataFormat.Create(Self);
- FFileMapFormat := TFileMapDataFormat.Create(Self);
- end;
- destructor TDropFileSource.Destroy;
- begin
- FFileFormat.Free;
- FFileMapFormat.Free;
- inherited Destroy;
- end;
- function TDropFileSource.GetFiles: TStrings;
- begin
- Result := FFileFormat.Files;
- end;
- function TDropFileSource.GetMappedNames: TStrings;
- begin
- Result := FFileMapFormat.FileMaps;
- end;
- procedure TDropFileSource.SetFiles(AFiles: TStrings);
- begin
- FFileFormat.Files.Assign(AFiles);
- end;
- procedure TDropFileSource.SetMappedNames(ANames: TStrings);
- begin
- FFileMapFormat.FileMaps.Assign(ANames);
- end;
- ////////////////////////////////////////////////////////////////////////////////
- //
- // Initialization/Finalization
- //
- ////////////////////////////////////////////////////////////////////////////////
- initialization
- // Data format registration
- TFileDataFormat.RegisterDataFormat;
- TFileMapDataFormat.RegisterDataFormat;
- // Clipboard format registration
- TFileDataFormat.RegisterCompatibleFormat(TFileClipboardFormat, 0, csSourceTarget, [ddRead]);
- TFileDataFormat.RegisterCompatibleFormat(TPIDLClipboardFormat, 1, csSourceTarget, [ddRead]);
- TFileDataFormat.RegisterCompatibleFormat(TFilenameClipboardFormat, 2, csSourceTarget, [ddRead]);
- TFileDataFormat.RegisterCompatibleFormat(TFilenameWClipboardFormat, 2, csSourceTarget, [ddRead]);
- TFileMapDataFormat.RegisterCompatibleFormat(TFilenameMapClipboardFormat, 0, csSourceTarget, [ddRead]);
- TFileMapDataFormat.RegisterCompatibleFormat(TFilenameMapWClipboardFormat, 0, csSourceTarget, [ddRead]);
- finalization
- // Data format unregistration
- TFileDataFormat.UnregisterDataFormat;
- TFileMapDataFormat.UnregisterDataFormat;
- // Clipboard format unregistration
- TFileClipboardFormat.UnregisterClipboardFormat;
- TFilenameClipboardFormat.UnregisterClipboardFormat;
- TFilenameWClipboardFormat.UnregisterClipboardFormat;
- TFilenameMapClipboardFormat.UnregisterClipboardFormat;
- TFilenameMapWClipboardFormat.UnregisterClipboardFormat;
- end.
|