Manage hilighting with Drag & Drop
I have an application that displays a grid of images.
I am able to drag one cell to another and successfully swap the contents.
It's not working perfectly however...
The drag-to rect does not always 'light up' but drag and drop works fine, whether or not the drag-to rect lights up'...
After stepping through the debugger for hours, it's time for a fresh perspective.....
Your tracking routine is either letting something slip through, or the window isn't getting refreshed!
Usually you let the system handle drag feedbeck by 'declaring' the window. however when you drag'n'drop in your own document, it's not the window that you're concerned with but the precise place where the thingy must be droppped... so you have to write a tracking proc. (Writing one for text is a bit hell because of a 'documented' bug on the last line of text edit fields.) In your case you must be seeing if the mosepoint is in an acceptable destination rect, and if it is then drawing a 'light' round it (and not forgetting to erase the previous.
There are 2 ways to do this (and I have an idea which you chose!):
- do the drawing in the tracking proc
- do the drawing in an update event
The Drag Manager docs would encourage you to do the first. You just pass the pointer to the routine and it does all. And of course, no handlevents get thru while you're doing this.
Or you can have an internal drag routine and only use the drag manager when you leave your window - for dragging one of your rects to another window,
for example. in this case, you need 2 things:
- an internal modal state 'aDragInProgress'
- a record of your rects, with a flag for 'canTakeADrag'
In your event loop you will then detect the aDragInProgress state
DO HANDLEVENTS IF myModalState% = aDragInProgress THEN FN myTrackDrag UNTIL thisThingFinallyWorksYour FN myTrackDrag will then track the mousepoint and see if if it is a rect that will accept a drag. It will also, to reduce flicker, see if this is the same rect as last time. If it isn't you will do an INVALRECT on the old rect, if there was one, and an INVALRECT on the new rect. It will zero the 'canTakeADrag' flag on the old rect, and set it to true on the new rect.
Then in your window drawing routine, the rectdrawing part will look at the 'canTakeADrag' flag, and if it is true, draw your 'light' indicating that a drag would work here. No flag, no light.