Skip to content

Commit

Permalink
move the caching of the filelist into the win32 implementation becaus…
Browse files Browse the repository at this point in the history
…e only there the problem ever happens in the first place
  • Loading branch information
prof7bit committed Aug 26, 2012
1 parent 11f5c5f commit da01d7d
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 19 deletions.
7 changes: 4 additions & 3 deletions dragdropgtk2.pas
Expand Up @@ -94,17 +94,18 @@ procedure GtkDragDataGet(GtkW: PGtkWidget;

FMT_FILELIST:
begin
FileList := Src.CallOnDragGetFileList;
FileList := TStringList.Create;
Src.CallOnDragGetFileList(FileList);
if FileList.Count > 0 then begin
SetLength(A, FileList.Count);
for I := 0 to FileList.Count - 1 do begin
if LeftStr(FileList.Strings[I], 7) <> 'file://' then
FileList.Strings[I] := 'file://' + FileList.Strings[i];
FileList.Strings[I] := 'file://' + FileList.Strings[i];
A[i] := PChar(FileList.Strings[I]);
end;
A[FileList.Count] := nil;
gtk_selection_data_set_uris(SelData, @A[0]);
end;
FileList.Free;
end;
end;
end;
Expand Down
4 changes: 3 additions & 1 deletion dragdropqt4.pas
Expand Up @@ -88,7 +88,8 @@ procedure StartDrag(Src: TNativeDragSource);
end;

if Assigned(Src.OnDragGetFileList) then begin
FileList := Src.CallOnDragGetFileList;
FileList := TStringList.Create;
Src.CallOnDragGetFileList(FileList);
if FileList.Count > 0 then begin
// we don't have QMimeData_setUrls() in libQt4Pas
// unfortunately, so we must fiddle around with the
Expand All @@ -101,6 +102,7 @@ procedure StartDrag(Src: TNativeDragSource);
MimeName := 'text/uri-list';
QMimeData_setData(MimeObj, @MimeName, ByteArray);
end;
FileList.Free;
end;

if Assigned(Mime) then begin
Expand Down
22 changes: 21 additions & 1 deletion dragdropwin32.pas
Expand Up @@ -102,6 +102,7 @@ TDropSource = class(TInterfacedObject, IDropSource)
TDataObject = class(TInterfacedObject, IDataObject)
public
constructor Create(Src: TNativeDragSource);
destructor Destroy; override;
function GetData(const formatetcIn: FORMATETC; out medium: STGMEDIUM): HRESULT; STDCALL;
function GetDataHere(const pformatetc: FormatETC; out medium: STGMEDIUM): HRESULT; STDCALL;
function QueryGetData(const pformatetc: FORMATETC): HRESULT; STDCALL;
Expand All @@ -113,9 +114,11 @@ TDataObject = class(TInterfacedObject, IDataObject)
function EnumDAdvise(out enumAdvise: IEnumStatData): HResult; StdCall;
private
FSrc: TNativeDragSource;
FFileList: TStringList;
FFmtList: array of FORMATETC;
function HaveThisFormat(const AFmt: TFORMATETC): Boolean;
procedure AddFormat(Fmt: FORMATETC);
function GetSrcFileList: TStringList;
end;

{$note SHCreateStdEnumFmtEtc() definition in shlobj is wrong, report this bug}
Expand All @@ -139,6 +142,7 @@ constructor TDataObject.Create(Src: TNativeDragSource);
begin
inherited Create;
FSrc := Src;
FFileList := nil;
if Assigned(Src.OnDragGetFileList) then begin
AddFormat(TGT_FILELIST);
end;
Expand All @@ -148,6 +152,13 @@ constructor TDataObject.Create(Src: TNativeDragSource);
end;
end;

destructor TDataObject.Destroy;
begin
if Assigned(FFileList) then
FreeAndNil(FFileList);
inherited Destroy;
end;

function TDataObject.GetData(const formatetcIn: FORMATETC; out medium: STGMEDIUM): HRESULT; STDCALL;
var
FileList: TStringList; // Filenames must be UTF8 encoded
Expand Down Expand Up @@ -181,7 +192,7 @@ function TDataObject.GetData(const formatetcIn: FORMATETC; out medium: STGMEDIUM
case formatetcIn.CfFormat of
CF_HDROP:
begin
FileList := FSrc.CallOnDragGetFileList;
FileList := GetSrcFileList;

// First we need a widestring #0 sepatated and #0#0 at the end.
WideStringData := '';
Expand Down Expand Up @@ -315,6 +326,15 @@ procedure TDataObject.AddFormat(Fmt: FORMATETC);
FFmtList[I] := Fmt;
end;

function TDataObject.GetSrcFileList: TStringList;
begin
if not Assigned(FFileList) then begin
FFileList := TStringList.Create;
FSrc.CallOnDragGetFileList(FFileList);
end;
Result := FFileList;
end;

{ TDragSource }

constructor TDropSource.Create(Src: TNativeDragSource);
Expand Down
18 changes: 4 additions & 14 deletions nativednd.pas
Expand Up @@ -83,7 +83,6 @@ TNativeDragSource = class(TComponent)
FOldMouseMove: TMouseMoveEvent;
FMouseDownPos: TPoint;
FIsDragging: Boolean;
FFileListCache: TStringList;
procedure UnsetControl;
procedure SetControl(AControl: TWinControl);
procedure MouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
Expand All @@ -94,7 +93,7 @@ TNativeDragSource = class(TComponent)
InternalData: TObject; // widgetset code may store internal stuff here
procedure CallOnDragBegin;
procedure CallOnDragEnd;
function CallOnDragGetFileList: TStringList;
procedure CallOnDragGetFileList(FileList: TStringList);
procedure CallOnDragStringData(out StringData: UTF8String);
property IsDragging: Boolean read FIsDragging;
published
Expand Down Expand Up @@ -128,7 +127,6 @@ constructor TNativeDragSource.Create(AOwner: TComponent);
FEndEvent := nil;
FMouseDownPos := Point(-1, -1);
FIsDragging := False;
FFileListCache := nil;
end;

procedure TNativeDragSource.UnsetControl;
Expand Down Expand Up @@ -204,14 +202,10 @@ procedure TNativeDragSource.CallOnDragBegin;
OnDragBegin(Control, FMouseDownPos.X, FMouseDownPos.Y);
end;

function TNativeDragSource.CallOnDragGetFileList: TStringList;
procedure TNativeDragSource.CallOnDragGetFileList(FileList: TStringList);
begin
if not Assigned(FFileListCache) then begin
FFileListCache := TStringList.Create;
if Assigned(OnDragGetFileList) then
OnDragGetFileList(Control, FFileListCache);
end;
Result := FFileListCache;
if Assigned(OnDragGetFileList) then
OnDragGetFileList(Control, FileList);
end;

procedure TNativeDragSource.CallOnDragStringData(out StringData: UTF8String);
Expand All @@ -225,10 +219,6 @@ procedure TNativeDragSource.CallOnDragEnd;
FIsDragging := False;
if Assigned(OnDragEnd) then
OnDragEnd(Control);
if Assigned(FFileListCache) then begin
FFileListCache.Free;
FFileListCache := nil;
end;
end;

procedure Register;
Expand Down

0 comments on commit da01d7d

Please sign in to comment.