Scripting problem, UIParent and OnReceiveDrag

I’m writing a button addon called MagnetButtons (on WowInterface), and I want to receive OnReceiveDrag events from UIParent. I’ve recently run in to a weird snag…

-- This doesn't receive events, unless I also specify the OnMouseUp script...
-- But setting the OnMouseUp script breaks the ability to move by pressing
-- both mouse buttons down.
UIParent:SetScript("OnReceiveDrag", function (self)

end);

-- Can't use HookScript since UIParent:GetScript("OnMouseUp") == nil
-- Can't use HookScript with OnReceiveDrag for the same reason.
UIParent:SetScript("OnMouseUp", function (self, button)

end);

Any suggestions?

Without more information, I’m not sure why you would want to use OnReceiveDrag for UIParent instead of OnDragStop for the frame being dragged/dropped. If it can be dragged it’s always going to be dropped over UIParent.

It’s a button addon, I want to create buttons automatically when UIParent receives OnReceiveDrop event.

OnReceiveDrag: Called whenever the user has released the cursor over the frame while dragging something.

What is being dragged/dropped and why can’t it trigger the action on drop (OnDragStop, OnMouseUp)?

So I can grab a spell (for example), out of my spell book and drop it on UIParent (the background), and it will create a button right there and then. UIParent is the drop target here.

Edit: Look at version 0.8.11 of my addon if you want to see it in action.

UIParent is the target for cancelling “bad pickups” for the entire UI, overwriting that as per the OP, may be problematic.

You will probably need to be creative about specifying when items are being dragged/dropped for the purposes of your addon and then create a “target” frame that works for your purposes.

Interesting, that gave me an idea, thank you. :slight_smile:

Edit: When an item is picked up, I’ll just create a transparent frame that follows the cursor. Providing a frame drop target. It will be tricky, but I think it will work. :slight_smile:

You don’t want to get rid of the ability to cancel pickups, drop junk etc.

Maybe something like a keybind to signify/toggle a drop incomming for your addon to create/position the target.

I’m just going to use OnDragStop, OnDragStart hooks for all buttons that can drag an item/spell/object that can be put in a button… “SpellButtonXX”, “ActionButtonXX”, etc…

Edit: I ended up ultimately solving this by watching the OnDropStart’s, when one is detected, I show a “drop target frame” just above UIParent frame (strata-wise) to receive the drop.