Lazarus

Programming => Widgetset => Carbon => Topic started by: Hansaplast on January 09, 2011, 09:35:32 pm

Title: [SOLVED] OnDropFiles - Only works with dock icon, not with Application Form
Post by: Hansaplast on January 09, 2011, 09:35:32 pm
When enabling "AllowdropFiles" on the mainform, the OnDropFiles event only gets fired when I drop something on the dock icon. Dropping files on the form doesn't do anything.
Is this by design? Or am I overlooking something?

OS: 10.6.6, Mac Intel (i386-darwin-carbon)
XCode: 3.2.5
Lazarus nightly build: 0.9.31 (2011-01-08)
FPC: 2.4.2 (SVN 28900)


Update: Just tested this in 1.4.2 and now it works as expected.
Title: Re: OnDropFiles - Only works with dock icon, not with Application Form
Post by: typo on January 09, 2011, 09:39:23 pm
No. OnDropFiles should get fired at any place you drop the file.

At least it is so on Windows.
Title: Re: OnDropFiles - Only works with dock icon, not with Application Form
Post by: Hansaplast on January 10, 2011, 12:07:54 am
That's what I was hoping for ... hmm

Mainform (and only form) AllowDropFiles = TRUE,
under Events "OnDropFiles" -> procedure that shows a simple "hello" message.

Drag file from Finder window to the mainform (after first making sure that the mainform is the frontmost and active application); nothing happens, the onDropFiles event does not get fired.
I tried to drop the file(s) in different locations; on components, on areas where there are no components, on the titlebar ,... nothing happens.

Dropping the file(s) on the dock icon of the application: onDropFiles get fired ...!?
Title: Re: OnDropFiles - Only works with dock icon, not with Application Form
Post by: Phil on January 10, 2011, 12:12:57 am
Right, that doesn't work here either.

I seem to recall this question asked before. You might to search the forum.

And file a bug report if you can't find a solution.

Thanks.

-Phil
Title: Re: OnDropFiles - Only works with dock icon, not with Application Form
Post by: Hansaplast on January 10, 2011, 12:15:29 am
Does anyone know how to search the bugtracker to see if this is an existing issue?  :'(

I did find two related posts (from 2008), but no answers there either ...
Title: Re: OnDropFiles - Only works with dock icon, not with Application Form
Post by: rajivsoft on February 03, 2011, 11:05:57 am
When enabling "AllowdropFiles" on the mainform, the OnDropFiles event only gets fired when I drop something on the dock icon. Dropping files on the form doesn't do anything.
Is this by design? Or am I overlooking something?

OS: 10.6.6, Mac Intel (i386-darwin-carbon)
XCode: 3.2.5
Lazarus nightly build: 0.9.31 (2011-01-08)
FPC: 2.4.2 (SVN 28900)
Also I'v tried to use AllowDropFiles, and the example application, with onDropFile and simple message and only drop on dock icon fires onDropFile event...
Title: Re: OnDropFiles - Only works with dock icon, not with Application Form
Post by: Hansaplast on February 03, 2011, 09:14:01 pm
Thanks for confirming :)

I posted a bug for this. (link to bug 18486 (http://bugs.freepascal.org/view.php?id=18486))
Title: Re: OnDropFiles - Only works with dock icon, not with Application Form
Post by: VTwin on February 28, 2011, 12:43:36 am
Thanks for posting the bug, this is not working for me either.
Title: Re: OnDropFiles - Only works with dock icon, not with Application Form
Post by: jwdietrich on March 04, 2011, 09:10:29 pm
Did you read the topic http://www.lazarus.freepascal.org/index.php/topic,12231.0.html ?

It may be of limited help at present, but the link may be useful, anyway.
Title: Re: OnDropFiles - Only works with dock icon, not with Application Form
Post by: Dr.Theopolis on May 09, 2012, 07:41:46 am
Is there any new information about this? As of Lazarus 0.9.30.4 and fpc 2.6.0 w carbon widgetset, this problem is still there.

In researching it, it looks like apps have to call an api function (registerForDraggedTypes) to register the types of files they can accept, otherwise the OS will not even send the appropriate messages to the app when files are dropped.

Then, when files are dropped on the app certain messages need to be responded to, and when I looked at the source code in the place where it deals with kAEOpenDocument, I did not see any mention of the other messages that need to be responded to.

registerForDraggedTypes is a procedure of the NSview class. I'm trying to figure out what that is exactly, but it seems like it is just a rectangle representing a visible area. I'm trying to figure out if I can create an NSview object for my main form window and then call registerForDraggedTypes. But this is my first time at doing any programming on Mac so I really don't know what I'm doing.

If anyone has any new info on getting onDropFiles to fire when dropping files onto the running app itself (not just the dock icon), please let me know.
Title: Re: OnDropFiles - Only works with dock icon, not with Application Form
Post by: jwdietrich on June 03, 2012, 01:11:35 pm
Unfortunately, many bugs that are called to be "resolved" in the bug tracker are in fact not fixed in the latest Lazarus versions for Mac.

See

http://bugs.freepascal.org/view.php?id=20298
http://bugs.freepascal.org/view.php?id=20331
http://bugs.freepascal.org/view.php?id=20425

to mention just a view examples of many.
Title: Re: OnDropFiles - Only works with dock icon, not with Application Form
Post by: leosok on June 13, 2012, 06:06:26 am
It still does not work.
Title: Re: OnDropFiles - Only works with dock icon, not with Application Form
Post by: typo on June 13, 2012, 07:45:13 am
Try the bugtracker.
Title: Re: OnDropFiles - Only works with dock icon, not with Application Form
Post by: Shebuka on June 13, 2012, 09:59:40 am
Try the bugtracker.
It is on bugtracker, or you mean that one must first check on bugtracker if the issue was resolved?  8)
Title: Re: OnDropFiles - Only works with dock icon, not with Application Form
Post by: typo on June 13, 2012, 11:09:58 am
Often they come here first. So, if it is not resolved, go to the bugtracker.

This thread has been resurrected and something may have changed in the interim. Some newbies do not feel comfortable to create a new thread.

Noting that the thread is old, he could go directly to the bugtracker, probably searching for some related bug or eventually reporting it.

The bug is here ( http://bugs.freepascal.org/view.php?id=18486 ), marked as acknowledged. Maybe he can add some note.
Title: Re: OnDropFiles - Only works with dock icon, not with Application Form
Post by: Hansaplast on July 24, 2012, 04:55:41 am
I guess keeping a thread alive isn't necessarily a bad thing.
Newbies, including myself, will have an indication that this is still an open issue.
Specially when not comfortable of familiar with the Bugtracker.

ps. Application.AddOnDropFilesHandler shows exactly the same issue - which makes me think that it is actually the only thing that works and allows dropping files on Applications. Adding a handler to the TApplication only picks up files dropped on the dock icon :(

So the code below doesn't work either;

Code: [Select]
procedure TForm1.FormCreate(Sender: TObject);
begin
  Application.AddOnDropFilesHandler(@OnApplicationDropFiles);
end;

...

procedure TForm1.OnApplicationDropFiles(Sender: TObject; const FileNames: array of String);
begin
  ShowMessage('Files dropped');
end;
Title: Re: OnDropFiles - Only works with dock icon, not with Application Form
Post by: Hansaplast on July 31, 2012, 08:03:02 pm
...
registerForDraggedTypes is a procedure of the NSview class. I'm trying to figure out what that is exactly, but it seems like it is just a rectangle representing a visible area. I'm trying to figure out if I can create an NSview object for my main form window and then call registerForDraggedTypes. But this is my first time at doing any programming on Mac so I really don't know what I'm doing.
...

Did you make any progress with insight into the NSView object?
I'm rather confused about NSView as well (see my VLC post (http://www.lazarus.freepascal.org/index.php/topic,17536.0.html)) for different purposes.
As far as I know the NSView is Apple specific and indicates a drawable area ...!?
Title: Re: OnDropFiles - Only works with dock icon, not with Application Form
Post by: Phil on August 01, 2012, 04:40:02 am

Did you make any progress with insight into the NSView object?
I'm rather confused about NSView as well (see my VLC post (http://www.lazarus.freepascal.org/index.php/topic,17536.0.html)) for different purposes.
As far as I know the NSView is Apple specific and indicates a drawable area ...!?

NSView is an Objective-C class in Cocoa's AppKit framework. It doesn't make sense to talk about it if you're using the Carbon widgetset.

To use with Cocoa, here's docs and example:

http://developer.apple.com/library/mac/#documentation/Cocoa/Reference/ApplicationKit/Classes/NSView_Class/Reference/NSView.html#//apple_ref/doc/uid/TP40004149

http://juliuspaintings.co.uk/cgi-bin/paint_css/animatedPaint/072-NSView-drag-and-drop.pl

Thanks.

-Phil
Title: Re: OnDropFiles - Only works with dock icon, not with Application Form
Post by: Hansaplast on August 02, 2012, 05:20:32 am
As usual; Phil helps out :)
Thanks Phil.

Well, I was already afraid of that - poking around, reading etc ... couldn't find how to get this to work in Carbon :(
I guess some low level work is needed to get even close.

The alternative would be a "drawable is an NSObject that follow the VLCOpenGLVideoViewEmbedding", which sounds equally difficult ,.. :(
Title: Re: OnDropFiles - Only works with dock icon, not with Application Form
Post by: Dr.Theopolis on January 11, 2013, 11:48:38 pm
I think I've made a good start at fixing the problem. The fix involves code utilizing the Drag Manager (see https://developer.apple.com/legacy/mac/library/#documentation/Carbon/Reference/Drag_Manager/Reference/reference.html).

I have updated the bugtracker issue# 18486 and uploaded a file. It needs more work I'm sure, but at least onDropFiles fires when dragging files to the application.
Title: Re: OnDropFiles - Only works with dock icon, not with Application Form
Post by: VTwin on November 11, 2013, 03:57:56 pm
That seems to have fixed it! I just tried the "dropfiles" example and it works properly. I hope your fix can be incorporated into the next release.

Many thanks Dr.Theopolis.

Cheers,
Frederick
Title: Re: OnDropFiles - Only works with dock icon, not with Application Form
Post by: VTwin on December 03, 2013, 12:39:36 am
It is not fixed in Lazarus 1.0.14, maybe the next release.
TinyPortal © 2005-2018