View Issue Details

IDProjectCategoryView StatusLast Update
0018486LazarusWidgetsetpublic2015-05-03 22:00
ReporterHans Luijten Assigned ToDmitry Boyarintsev  
PrioritynormalSeverityminorReproducibilityalways
Status closedResolutionfixed 
Product Version0.9.31 (SVN) 
Summary0018486: TForm, onDropFiles does not fire when dropping files on Form (but does fire when dropping files on dock icon)
DescriptionTForm.AllowDropFiles:=TRUE;

The onDropFiles does NOT fire when dropping files from the Finder on the (main and only) form.

However, when you drop the files on the Dock icon, it does fire the onDropFiles event.
Additional InformationMacOS X v10.6.5 and v10.6.6, Xcode 3.2.5 and 3.2.4, Stable build and Nightly builds.

Confirmed by Phil (Lazarus Forum).
TagsNo tags attached.
Fixed in Revision43511
LazTarget-
WidgetsetCarbon
Attached Files

Activities

2011-05-28 20:34

 

DropFiles.zip (3,430 bytes)

2011-05-28 20:40

 

DropFiles2.zip (4,206 bytes)

Frederick

2011-05-28 20:46

reporter   ~0048691

Last edited: 2011-05-28 20:49

Added examples with 1 and 2 forms. Neither can receive dropped files. It would be nice if controls as well as forms could respond to dropped files. Icon and dock file drops work.

Hans Luijten

2012-07-25 02:38

reporter   ~0061227

Just curious, after toying around with a few things; is this bug related to the fact that onActivate and OnDeActivate events do not fire either (MacOS)?

2013-01-11 23:36

 

carbonobject.inc.zip (12,442 bytes)

Dr.Theopolis

2013-01-11 23:41

reporter   ~0064836

To begin fixing this, I added to the file carbonobject.inc the function CarbonApp_DragReceive and added one line of code to the end of the function TCarbonWidgetSet.RegisterEvents. See uploaded file.

It works...for me. If it is the right approach, the code needs grooming and then I would love to see it added to a future release.

C Western

2013-11-17 13:40

reporter   ~0071357

I can confirm the suggested change seems to work for me on 10.9. Added the change in standard patch format.

C Western

2013-11-17 13:40

reporter  

drop.patch (2,682 bytes)   
diff -uwNr --exclude=.svn --exclude=Makefile --exclude=Makefile.fpc --exclude=Makefile.compiled --exclude='*.rst' --exclude='*.po' lazarus/lcl/interfaces/carbon/carbonobject.inc lazarus.w/lcl/interfaces/carbon/carbonobject.inc
--- lazarus/lcl/interfaces/carbon/carbonobject.inc	2013-11-16 10:59:07.000000000 +0000
+++ lazarus.w/lcl/interfaces/carbon/carbonobject.inc	2013-11-16 22:03:34.000000000 +0000
@@ -449,6 +449,62 @@
 end;
 
 {------------------------------------------------------------------------------
+  Name:  CarbonApp_DragReceive
+  Handles dropping files on application
+ ------------------------------------------------------------------------------}
+function CarbonApp_DragReceive(theWindow: WindowRef; handlerRefCon: UnivPtr; theDrag: DragRef): OSErr;  {$IFDEF darwin}mwpascal;{$ENDIF}
+var
+  theItemRef: DragItemRef;
+  theFlavorData: HFSFlavor;
+  theDataSize: Size;
+  theFilename: pchar;
+  theFileRef: FSRef;
+  numItems: UInt16;
+  Files: array of string;
+  itemNum: UInt16;
+begin
+  SetLength(Files, 0);
+
+  numItems := 0;
+
+  if CountDragItems(theDrag, numItems) <> noErr then exit;
+
+  if numItems > 0 then
+    for itemNum := 1 to numItems do
+    begin
+     if GetDragItemReferenceNumber(theDrag, itemNum, theItemRef) <> noErr then continue;
+     theDataSize := sizeof(theFlavorData);
+     if GetFlavorData(theDrag, theItemRef, kDragFlavorTypeHFS, @theFlavorData, theDataSize, 0) <> noErr then continue;
+
+     FSpMakeFSRef(theFlavorData.fileSpec, theFileRef);
+
+     theFilename := stralloc(1024); //PATH_MAX = 1024
+
+     FSRefMakePath(theFileRef, theFilename, StrBufSize(theFilename));
+
+     try
+       SetLength(Files, Length(Files) + 1);
+       Files[High(Files)] := theFilename;
+     finally
+       StrDispose(theFilename);
+     end;
+  end;
+
+  if Length(Files) > 0 then
+  begin
+    if Application <> nil then
+    begin
+      if Application.MainForm <> nil then
+        Application.MainForm.IntfDropFiles(Files);
+
+      Application.IntfDropFiles(Files);
+    end;
+  end;
+
+  Result := noErr;
+end;
+
+{------------------------------------------------------------------------------
   Name:  CarbonApp_Quit
   Handles application quit
  ------------------------------------------------------------------------------}
@@ -1213,6 +1269,8 @@
   InstallApplicationEventHandler(RegisterEventHandler(@CarbonApp_LazWake),
     1, @TmpSpec, nil, @FAEventHandlerRef[5]);
 
+  InstallReceiveHandler(@CarbonApp_DragReceive, nil, nil);
+
   FOpenEventHandlerUPP := NewAEEventHandlerUPP(AEEventHandlerProcPtr(@CarbonApp_Open));
   FQuitEventHandlerUPP := NewAEEventHandlerUPP(AEEventHandlerProcPtr(@CarbonApp_Quit));
   OSError(
drop.patch (2,682 bytes)   

Frederick

2013-12-03 00:12

reporter   ~0071739

Dr. Theopolis's patch worked for me in Lazarus_1.0.12. It has not been fixed as of release 14.

Dmitry Boyarintsev

2013-12-03 05:39

developer   ~0071740

patch applied! thank you!

if the reporter won't close the item, it can be closed based on confirmation by Frederick

Frederick

2014-01-14 21:45

reporter   ~0072442

Excellent! I am using Dr. Theopolis's fix. Many thanks for patch C Western.

I am not currently running snapshots, but will confirm on next stable release.

Frederick

2014-03-08 14:16

reporter   ~0073557

I can confirm that the patch has been applied in 1.2.

Note that dropping a file on an OpenDialog causes the main form to accept the dropped files. Not a huge problem I guess, but this causes unexpected behavior, as normally an open dialog accepts the files.

This can be closed. Thanks!

Issue History

Date Modified Username Field Change
2011-01-13 06:13 Hans Luijten New Issue
2011-01-13 06:13 Hans Luijten Widgetset => Carbon
2011-01-23 00:52 Dmitry Boyarintsev LazTarget => -
2011-01-23 00:52 Dmitry Boyarintsev Status new => acknowledged
2011-05-28 20:34 Frederick File Added: DropFiles.zip
2011-05-28 20:40 Frederick File Added: DropFiles2.zip
2011-05-28 20:46 Frederick Note Added: 0048691
2011-05-28 20:47 Frederick Note Edited: 0048691
2011-05-28 20:49 Frederick Note Edited: 0048691
2012-07-25 02:38 Hans Luijten Note Added: 0061227
2013-01-11 23:36 Dr.Theopolis File Added: carbonobject.inc.zip
2013-01-11 23:41 Dr.Theopolis Note Added: 0064836
2013-11-17 13:40 C Western Note Added: 0071357
2013-11-17 13:40 C Western File Added: drop.patch
2013-12-03 00:12 Frederick Note Added: 0071739
2013-12-03 05:39 Dmitry Boyarintsev Fixed in Revision => 43511
2013-12-03 05:39 Dmitry Boyarintsev Note Added: 0071740
2013-12-03 05:39 Dmitry Boyarintsev Status acknowledged => resolved
2013-12-03 05:39 Dmitry Boyarintsev Resolution open => fixed
2013-12-03 05:39 Dmitry Boyarintsev Assigned To => Dmitry Boyarintsev
2014-01-14 21:45 Frederick Note Added: 0072442
2014-03-08 14:16 Frederick Note Added: 0073557
2015-05-03 22:00 Hans Luijten Status resolved => closed