ADC Home > Reference Library > Technical Q&As > Legacy Documents > Mac OS 9 & Earlier >

Legacy Documentclose button

Important: This document is part of the Legacy section of the ADC Reference Library. This information should not be used for new development.

Current information on this Reference Library topic can be found here:

Avoiding DragDrawingProc Pixel Trails

Q I've just implemented a DragDrawingProc. To start, I've tried simply to duplicate the default behavior of the Drag Manager (so it will look as if I had not in fact attached a DragDrawingProc). Unfortunately, when the user drags into a valid drop area and the potential drop receiver calls ShowDragHilite, my DragDrawingProc seems to be responsible for leaving a trail of pixels on the screen. What am I doing wrong?

A This happens because Drag Manager does not always pass the entire "old" or "new" region to the DragDrawingProc. Here's a function which mimics what Drag Manager does when you don't attach a DragDrawingProc to a DragReference before calling TrackDrag:
static pascal OSErr LikeDefaultDragDrawingProc
        (   DragRegionMessage message,
            RgnHandle showRegion, Point showOrigin,
            RgnHandle hideRegion, Point hideOrigin,
            void *dragDrawingRefCon, DragReference theDragRef   )
    {
        OSErr err = noErr;

        RgnHandle   xorMe;
        long        oldA5;
        Pattern     gray;

        switch (message)
        {
            case dragRegionBegin:

                oldA5 = SetA5 ((long) dragDrawingRefCon);
                gray = qd.gray;
                SetA5 (oldA5);

                PenPat (&gray);
                PenMode (notPatXor);

                break;

            case dragRegionDraw:

                xorMe = NewRgn ( );
                if (!(err = MemError ( )))
                {
                    XorRgn (showRegion, hideRegion, xorMe);
                    PaintRgn (xorMe);
                    DisposeRgn (xorMe);
                }
                break;

            case dragRegionHide:

                PaintRgn (hideRegion);
                break;
        }

        return err;
    }

The call to XorRgn is the key. It's also very important to pass the correct value for the 'dragDrawingRefCon' to SetDragDrawingProc:

    SetDragDrawingProc (dragRef,LikeDefaultDragDrawingProc,
        (void*)SetCurrentA5 ( ));

(The above works for 68K code; UniversalProcPtr creation omitted for simplicity.)

By the way, be careful not to mix the use of SetDragDrawingProc and SetDragImage. See Technote 1043:On Drag Manager Additions for details.

[Oct 25 1996]


Did this document help you?
Yes: Tell us what works for you.
It’s good, but: Report typos, inaccuracies, and so forth.
It wasn’t helpful: Tell us what would have helped.