Page 1 of 1
Accept DragDrop Globally?
Posted: Fri Nov 14, 2008 10:33 pm
by Garrett
I'm trying to find a way to get drag drop to work over my entire stack, which is actually small, but there's a menu bar and a button that fill up the entire contents of the card. I can't get the menu or the button to accept dragdrop actions at all.
My first idea was to place a field over the top, remove the borders, set the opaque and turn off everything to it. Which of course accepted dragdrop actions, but then I was unable to click through to the menu
Any suggestions/ideas how to get dragdrop actions over the entire card without blocking off the menu?
Thanks in advance,
~Garrett
Posted: Fri Nov 14, 2008 11:33 pm
by SparkOut
Would merely adding "pass mouseUp" to your field that accepts that dragDrop help?
Posted: Sat Nov 15, 2008 12:39 am
by Garrett
Hmmmmm... I'll give that a try.. thanks

Posted: Sat Nov 15, 2008 1:00 am
by Garrett
Well, that didn't work

But thanks for the suggestion

Posted: Sat Nov 15, 2008 11:02 am
by SparkOut
Hmmm, no, it doesn't work for me either. A button does not seem to inherit the mouseUp message which is passed from a control in a higher layer.
BUT, the card will receive the message.
So you can workaround... albeit kludgy, by having a handler for the mouseUp event in the card script and checking for the clickLoc and seeing if it is within the rect of the buttons:
Code: Select all
--put this in the card script
on mouseUp
if within (button "btnName", the clickLoc) then
send "mouseUp" to button "btnName"
end if
end mouseUp
Look up "within" in the dictionary. You may (for tabbed controls, etc) need to distinguish between "within (button "btnName", the clickLoc)" and "within (the rect of button "btnName", the clickLoc)".
Is it normal behaviour (a "feature") or unexpected behaviour (a "bug") that a button will not inherit a mouseUp from a higher-layered object?
Posted: Sat Nov 15, 2008 12:55 pm
by Klaus
Hi Garret,
could you please post your script(s) that do(es) not work?
Posted: Sat Nov 15, 2008 1:50 pm
by SparkOut
I've been playing a bit more, and checking the dictionary. Something seems to be wrong?
The dragDrop messages is supposed to be sent to a button, but it is not being delivered when a button is the target. I can see dragEnter and dragLeave messages on a button, but never a dragDrop message.
(Rev Studio 3.0.0 build 750 on Windows XP)
Posted: Sat Nov 15, 2008 3:45 pm
by SparkOut
I have played some more, and put a test stack on my Rev space, called DragDropTest.
The card will not accept drag and drop, which is understood. A field with its lockText set to true will not accept dragDrop (despite it being expected that it should, according to the dictionary). The dragEnter and dragLeave messages are still passed to the field though. When the mouse key is released within the field, then a dragLeave message is received. By testing the location of the mouse pointer on dragLeave and checking whether it is still within the field it is possible to collect the dragData at that point instead. The side effect of all this is that the system believes the field to be an invalid destination for a drag and drop event, and so the cursor changes to reflect that, and will probably mislead a user. The reason for setting the lockText on the field is that otherwise a mouseUp event will not be generated for the field. If the lockText is set true, then a mouseUp message will be generated, which (if not handled in the field itself) can then be picked up by the card script, and which can then trigger a mouseUp message to be sent to the button if the clickLoc was in the right place.
So, that's a lot of fuss and fudging. A field with its lockText set to false will have no problem accepting the dragDrop message, but there will be no mouseUp message generated. It does appear that a mouseDown message is generated, which can be handled by the field, however. This can be used to trigger the button on a layer below.
It appears that the neatest way is to use an unlocked field for the dragDrop, and handle the mouseDown message to construct click-through possibilities.
Posted: Sat Nov 15, 2008 8:30 pm
by Garrett
Yeah, I kind of gave up on this already because I ran into some other major problems. Code that works fine while in the IDE won't work at all once it's a standalone... So I'm fighting with that issue right now.
To SparkOut and anyone else who tried to help out on this one, many thanks.
~Garrett
Posted: Fri Mar 27, 2009 4:41 pm
by vamp07
Out of curiosity, why does a card script not accept a dragdata? I wanted to set up my card so I could drop a file on to it anywhere and get the data dumped to a field on that card. After much playing I now understand the message never arrives.
Posted: Fri Mar 27, 2009 7:23 pm
by massung
SparkOut wrote:The card will not accept drag and drop, which is understood. A field with its lockText set to true will not accept dragDrop (despite it being expected that it should, according to the dictionary)....
I recently just spent a few hours with my app trying to get this to work as well.
RevTeam, adding this support would be very handy (as would just accepting dragged items at the card level).
Jeff M.
Posted: Fri Mar 27, 2009 7:52 pm
by Klaus
Hi Jeff,
what do/would you exspect your global dragdrop script to do?
I think I have an old stack on RevOnline that shows a stack wide implementation of drag and drop.
Here is the stack script with some comment from me. Hope this helps

Drop a line if you need more info or help.
Code: Select all
#################################
# Drag and Drop routines by Klaus Major, www.major-k.de 2004
# Enjoy! :-)
on dragenter
set the acceptdrop to true
## The "nowadays" syntax ia bit different, see "dragaction" in the docs
end dragenter
##Handle ALL dropped stuff according to the TARGET!
on dragdrop
put line 1 of the dragdata into ddd
set itemdel to "."
put item -1 of ddd into endung
## ENDUNG = suffix in german
switch endung
case ".gif"
case ".giff"
case ".jpg"
case ".jpeg"
case ".png"
case ".bmp"
if the target contains "image" then
if the altkey = "down" then
## Import buinary data!
put url("binfile:" & ddd) into the target
else
## Only refernce file
set the filename of the target to ddd
end if
end if
break
case ".tif"
case ".tiff"
case ".psd"
case ".tga"
if the char 1 of the qtversion >=5 then
if the target contains "player" then
set the filename of the target to ddd
end if
else
beep
answer "You need QuickTime version >= 5 installed to use this feature!"
exit switch
end if
break
case ".txt"
if the target contains "field" then put url("file:" & ddd) into the target
break
case ".html"
case ".htm"
if the target contains "field" then set the htmltext of the target to url("file:" & ddd)
break
case ".rtf"
if the target contains "field" then set the rtftext of the target to url("file:" & ddd)
break
case ".avi"
case ".mpg"
case ".mpeg"
case ".wav"
case ".aif"
case ".au"
case ".mov"
case ".swf"
case ".au"
case ".dv"
if the char 1 of the qtversion >=5 then
if the target contains "player" then
set the filename of the target to ddd
end if
else
beep
answer "You need QuickTime version >= 5 installed to use this feature!"
exit switch
end if
break
## Quicktime can display PDF on OS X!
case ".pdf"
if the platform contains "Mac" AND char 1 to 2 of the systemversion = "10" then
if the target contains "player" then
set the filename of the target to ddd
end if
else
beep
end if
break
end switch
end dragdrop
#################################
Posted: Fri Mar 27, 2009 10:32 pm
by massung
Klaus wrote:Hi Jeff,
what do/would you exspect your global dragdrop script to do?
Just execute the code in the dragDrop handler. I suppose at the card level there is a question as to the default behavior that would be supported. In my mind, that should just be a NOP (do nothing).
To me, being able to accept dragDrop events in a field that has locked text is much more important. I don't care if passing it on doesn't update the text itself, but I'd like to be able to handle the drop.
In my particular case, I use the field as a simple HTML view, which I don't want the user editing. But I'd like the user to be able to drop certain objects onto it and get the custom view that I provide for them. Since the field wouldn't accept the drop, the next best thing was the card, which didn't receive the message either.
Thanks for the code!
Jeff M.