#include <Scrap.h>
#endif
+
// ----------------------------------------------------------------------------
// globals
// ----------------------------------------------------------------------------
typedef struct
{
- wxWindow* m_currentTargetWindow ;
- wxDropTarget* m_currentTarget ;
- wxDropSource* m_currentSource ;
+ wxWindow* m_currentTargetWindow;
+ wxDropTarget* m_currentTarget;
+ wxDropSource* m_currentSource;
}
-MacTrackingGlobals ;
+MacTrackingGlobals;
-MacTrackingGlobals gTrackingGlobals ;
+MacTrackingGlobals gTrackingGlobals;
void wxMacEnsureTrackingHandlersInstalled() ;
FlavorType theType ;
UInt16 flavors = 0 ;
- CountDragItems((DragReference)m_currentDrag, &items);
+ CountDragItems( (DragReference)m_currentDrag, &items );
for (UInt16 index = 1; index <= items && !supported; ++index)
{
flavors = 0 ;
bool wxDropTarget::GetData()
{
- if (!m_dataObject)
+ if (m_dataObject == NULL)
return false;
if ( !CurrentDragHasSupportedFormat() )
flavors = 0 ;
GetDragItemReferenceNumber( (DragReference)m_currentDrag, index, &theItem );
CountDragItemFlavors( (DragReference)m_currentDrag, theItem , &flavors );
+ wxDataFormat preferredFormat = m_dataObject->GetPreferredFormat( wxDataObject::Set );
bool hasPreferredFormat = false ;
- wxDataFormat preferredFormat = m_dataObject->GetPreferredFormat( wxDataObject::Set ) ;
for ( UInt16 flavor = 1 ; flavor <= flavors ; ++flavor )
{
for ( UInt16 flavor = 1 ; flavor <= flavors ; ++flavor )
{
- result = GetFlavorType((DragReference)m_currentDrag, theItem, flavor , &theType);
- wxDataFormat format(theType) ;
+ result = GetFlavorType( (DragReference)m_currentDrag, theItem, flavor, &theType );
+ wxDataFormat format( theType ) ;
if ( (hasPreferredFormat && format == preferredFormat)
|| (!hasPreferredFormat && m_dataObject->IsSupportedFormat( format )))
{
GetFlavorDataSize( (DragReference)m_currentDrag, theItem, theType, &dataSize );
if ( theType == kScrapFlavorTypeText )
{
- // this increment is only valid for allocating, on the next GetFlavorData
- // call it is reset again to the original value
+ // this increment is only valid for allocating:
+ // on the next GetFlavorData call it is reset again to the original value
dataSize++ ;
}
else if ( theType == kScrapFlavorTypeUnicode )
{
- // this increment is only valid for allocating, on the next GetFlavorData
- // call it is reset again to the original value
+ // this increment is only valid for allocating:
+ // on the next GetFlavorData call it is reset again to the original value
dataSize++ ;
dataSize++ ;
}
: wxDropSourceBase(cursorCopy, cursorMove, cursorStop)
{
wxMacEnsureTrackingHandlersInstalled() ;
+
m_window = win;
}
: wxDropSourceBase(cursorCopy, cursorMove, cursorStop)
{
wxMacEnsureTrackingHandlersInstalled() ;
+
SetData( data );
m_window = win;
}
dataPtr[ dataSize ] = 0 ;
}
- AddDragItemFlavor(theDrag, theItem, type , dataPtr, dataSize, 0);
+ AddDragItemFlavor( theDrag, theItem, type , dataPtr, dataSize, 0 );
}
else if (type == kDragFlavorTypeHFS )
{
OSErr err = noErr;
CInfoPBRec cat;
- wxMacFilename2FSSpec( wxString( dataPtr , *wxConvCurrent ) , &theFlavor.fileSpec ) ;
+ wxMacFilename2FSSpec( wxString( dataPtr, *wxConvCurrent ), &theFlavor.fileSpec ) ;
memset( &cat, 0, sizeof(cat) );
cat.hFileInfo.ioNamePtr = theFlavor.fileSpec.name;
cat.hFileInfo.ioVRefNum = theFlavor.fileSpec.vRefNum;
cat.hFileInfo.ioDirID = theFlavor.fileSpec.parID;
cat.hFileInfo.ioFDirIndex = 0;
- err = PBGetCatInfoSync(&cat);
+ err = PBGetCatInfoSync( &cat );
if (err == noErr)
{
theFlavor.fdFlags = cat.hFileInfo.ioFlFndrInfo.fdFlags;
theFlavor.fileType = cat.hFileInfo.ioFlFndrInfo.fdType;
}
- AddDragItemFlavor(theDrag, theItem, type , &theFlavor, sizeof(theFlavor), 0);
+ AddDragItemFlavor( theDrag, theItem, type , &theFlavor, sizeof(theFlavor), 0 );
}
}
else
{
- AddDragItemFlavor(theDrag, theItem, type , dataPtr, dataSize, 0);
+ AddDragItemFlavor( theDrag, theItem, type , dataPtr, dataSize, 0 );
}
delete [] dataPtr ;
DiffRgn( dragRegion , tempRgn , dragRegion ) ;
DisposeRgn( tempRgn ) ;
- // TODO:work with promises in order to return data only when drag
- // was successfully completed
+ // TODO: work with promises in order to return data
+ // only when drag was successfully completed
- gTrackingGlobals.m_currentSource = this ;
- result = TrackDrag(theDrag, ev , dragRegion);
- DisposeRgn(dragRegion);
- DisposeDrag(theDrag);
- gTrackingGlobals.m_currentSource = NULL ;
+ gTrackingGlobals.m_currentSource = this;
+ result = TrackDrag( theDrag, ev, dragRegion );
+ DisposeRgn( dragRegion );
+ DisposeDrag( theDrag );
+ gTrackingGlobals.m_currentSource = NULL;
- bool optionDown = GetCurrentKeyModifiers() & optionKey ;
- wxDragResult dndresult = wxDragCopy ;
+ bool optionDown = GetCurrentKeyModifiers() & optionKey;
+ wxDragResult dndresult = wxDragCopy;
if ( flags != wxDrag_CopyOnly )
// on mac the option key is always the indication for copy
dndresult = optionDown ? wxDragCopy : wxDragMove;
bool result = cursor.Ok();
if ( result )
- cursor.MacInstall() ;
+ cursor.MacInstall();
return result;
}
pascal OSErr wxMacWindowDragTrackingHandler(
DragTrackingMessage theMessage, WindowPtr theWindow,
- void *handlerRefCon, DragReference theDrag) ;
+ void *handlerRefCon, DragReference theDrag );
pascal OSErr wxMacWindowDragReceiveHandler(
WindowPtr theWindow, void *handlerRefCon,
- DragReference theDrag) ;
+ DragReference theDrag );
void wxMacEnsureTrackingHandlersInstalled()
{
{
OSErr result;
- result = InstallTrackingHandler(NewDragTrackingHandlerUPP(wxMacWindowDragTrackingHandler), 0L,&gTrackingGlobals);
- wxASSERT( result == noErr ) ;
+ result = InstallTrackingHandler( NewDragTrackingHandlerUPP(wxMacWindowDragTrackingHandler), 0L, &gTrackingGlobals );
+ wxASSERT( result == noErr );
- result = InstallReceiveHandler(NewDragReceiveHandlerUPP(wxMacWindowDragReceiveHandler), 0L, &gTrackingGlobals);
- wxASSERT( result == noErr ) ;
+ result = InstallReceiveHandler( NewDragReceiveHandlerUPP(wxMacWindowDragReceiveHandler), 0L, &gTrackingGlobals );
+ wxASSERT( result == noErr );
- gTrackingGlobalsInstalled = true ;
+ gTrackingGlobalsInstalled = true;
}
}
pascal OSErr wxMacWindowDragTrackingHandler(
DragTrackingMessage theMessage, WindowPtr theWindow,
- void *handlerRefCon, DragReference theDrag)
+ void *handlerRefCon, DragReference theDrag )
{
MacTrackingGlobals* trackingGlobals = (MacTrackingGlobals*) handlerRefCon;
+
Point mouse, localMouse;
DragAttributes attributes;
- GetDragAttributes(theDrag, &attributes);
+
+ GetDragAttributes( theDrag, &attributes );
+
wxTopLevelWindowMac* toplevel = wxFindWinFromMacWindow( theWindow ) ;
bool optionDown = GetCurrentKeyModifiers() & optionKey ;
break;
case kDragTrackingEnterWindow:
- trackingGlobals->m_currentTargetWindow = NULL ;
- trackingGlobals->m_currentTarget = NULL ;
+ if (trackingGlobals != NULL)
+ {
+ trackingGlobals->m_currentTargetWindow = NULL ;
+ trackingGlobals->m_currentTarget = NULL ;
+ }
break;
case kDragTrackingInWindow:
+ if (trackingGlobals == NULL)
+ break;
if (toplevel == NULL)
break;
- GetDragMouse(theDrag, &mouse, 0L);
+ GetDragMouse( theDrag, &mouse, 0L );
localMouse = mouse;
- GlobalToLocal(&localMouse);
+ GlobalToLocal( &localMouse );
{
wxWindow *win = NULL ;
ControlPartCode controlPart ;
ControlRef control = wxMacFindControlUnderMouse(
- toplevel , localMouse ,
- theWindow , &controlPart ) ;
+ toplevel , localMouse , theWindow , &controlPart ) ;
if ( control )
win = wxFindControlFromMacControl( control ) ;
else
}
// set cursor for OnEnter and OnDragOver
- if ( !trackingGlobals->m_currentSource && trackingGlobals->m_currentSource->GiveFeedback( result ) )
+ if ( trackingGlobals->m_currentSource && !trackingGlobals->m_currentSource->GiveFeedback( result ) )
{
if ( !trackingGlobals->m_currentSource->MacInstallDefaultCursor( result ) )
{
break;
case kDragTrackingLeaveWindow:
+ if (trackingGlobals == NULL)
+ break;
+
if (trackingGlobals->m_currentTarget)
{
trackingGlobals->m_currentTarget->SetCurrentDrag( theDrag );