cleanup - reformat ()

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@36870 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
David Surovell
2006-01-14 08:25:42 +00:00
parent 876b960ac2
commit e22ab33a47

View File

@@ -24,19 +24,20 @@
#include <Scrap.h> #include <Scrap.h>
#endif #endif
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
// globals // globals
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
typedef struct typedef struct
{ {
wxWindow* m_currentTargetWindow ; wxWindow* m_currentTargetWindow;
wxDropTarget* m_currentTarget ; wxDropTarget* m_currentTarget;
wxDropSource* m_currentSource ; wxDropSource* m_currentSource;
} }
MacTrackingGlobals ; MacTrackingGlobals;
MacTrackingGlobals gTrackingGlobals ; MacTrackingGlobals gTrackingGlobals;
void wxMacEnsureTrackingHandlersInstalled() ; void wxMacEnsureTrackingHandlersInstalled() ;
@@ -112,7 +113,7 @@ bool wxDropTarget::CurrentDragHasSupportedFormat()
FlavorType theType ; FlavorType theType ;
UInt16 flavors = 0 ; UInt16 flavors = 0 ;
CountDragItems((DragReference)m_currentDrag, &items); CountDragItems( (DragReference)m_currentDrag, &items );
for (UInt16 index = 1; index <= items && !supported; ++index) for (UInt16 index = 1; index <= items && !supported; ++index)
{ {
flavors = 0 ; flavors = 0 ;
@@ -136,7 +137,7 @@ bool wxDropTarget::CurrentDragHasSupportedFormat()
bool wxDropTarget::GetData() bool wxDropTarget::GetData()
{ {
if (!m_dataObject) if (m_dataObject == NULL)
return false; return false;
if ( !CurrentDragHasSupportedFormat() ) if ( !CurrentDragHasSupportedFormat() )
@@ -194,8 +195,8 @@ bool wxDropTarget::GetData()
flavors = 0 ; flavors = 0 ;
GetDragItemReferenceNumber( (DragReference)m_currentDrag, index, &theItem ); GetDragItemReferenceNumber( (DragReference)m_currentDrag, index, &theItem );
CountDragItemFlavors( (DragReference)m_currentDrag, theItem , &flavors ); CountDragItemFlavors( (DragReference)m_currentDrag, theItem , &flavors );
wxDataFormat preferredFormat = m_dataObject->GetPreferredFormat( wxDataObject::Set );
bool hasPreferredFormat = false ; bool hasPreferredFormat = false ;
wxDataFormat preferredFormat = m_dataObject->GetPreferredFormat( wxDataObject::Set ) ;
for ( UInt16 flavor = 1 ; flavor <= flavors ; ++flavor ) for ( UInt16 flavor = 1 ; flavor <= flavors ; ++flavor )
{ {
@@ -210,8 +211,8 @@ bool wxDropTarget::GetData()
for ( UInt16 flavor = 1 ; flavor <= flavors ; ++flavor ) for ( UInt16 flavor = 1 ; flavor <= flavors ; ++flavor )
{ {
result = GetFlavorType((DragReference)m_currentDrag, theItem, flavor , &theType); result = GetFlavorType( (DragReference)m_currentDrag, theItem, flavor, &theType );
wxDataFormat format(theType) ; wxDataFormat format( theType ) ;
if ( (hasPreferredFormat && format == preferredFormat) if ( (hasPreferredFormat && format == preferredFormat)
|| (!hasPreferredFormat && m_dataObject->IsSupportedFormat( format ))) || (!hasPreferredFormat && m_dataObject->IsSupportedFormat( format )))
{ {
@@ -224,14 +225,14 @@ bool wxDropTarget::GetData()
GetFlavorDataSize( (DragReference)m_currentDrag, theItem, theType, &dataSize ); GetFlavorDataSize( (DragReference)m_currentDrag, theItem, theType, &dataSize );
if ( theType == kScrapFlavorTypeText ) if ( theType == kScrapFlavorTypeText )
{ {
// this increment is only valid for allocating, on the next GetFlavorData // this increment is only valid for allocating:
// call it is reset again to the original value // on the next GetFlavorData call it is reset again to the original value
dataSize++ ; dataSize++ ;
} }
else if ( theType == kScrapFlavorTypeUnicode ) else if ( theType == kScrapFlavorTypeUnicode )
{ {
// this increment is only valid for allocating, on the next GetFlavorData // this increment is only valid for allocating:
// call it is reset again to the original value // on the next GetFlavorData call it is reset again to the original value
dataSize++ ; dataSize++ ;
dataSize++ ; dataSize++ ;
} }
@@ -295,6 +296,7 @@ wxDropSource::wxDropSource(wxWindow *win,
: wxDropSourceBase(cursorCopy, cursorMove, cursorStop) : wxDropSourceBase(cursorCopy, cursorMove, cursorStop)
{ {
wxMacEnsureTrackingHandlersInstalled() ; wxMacEnsureTrackingHandlersInstalled() ;
m_window = win; m_window = win;
} }
@@ -306,6 +308,7 @@ wxDropSource::wxDropSource(wxDataObject& data,
: wxDropSourceBase(cursorCopy, cursorMove, cursorStop) : wxDropSourceBase(cursorCopy, cursorMove, cursorStop)
{ {
wxMacEnsureTrackingHandlersInstalled() ; wxMacEnsureTrackingHandlersInstalled() ;
SetData( data ); SetData( data );
m_window = win; m_window = win;
} }
@@ -353,7 +356,7 @@ wxDragResult wxDropSource::DoDragDrop(int flags)
dataPtr[ dataSize ] = 0 ; dataPtr[ dataSize ] = 0 ;
} }
AddDragItemFlavor(theDrag, theItem, type , dataPtr, dataSize, 0); AddDragItemFlavor( theDrag, theItem, type , dataPtr, dataSize, 0 );
} }
else if (type == kDragFlavorTypeHFS ) else if (type == kDragFlavorTypeHFS )
{ {
@@ -361,14 +364,14 @@ wxDragResult wxDropSource::DoDragDrop(int flags)
OSErr err = noErr; OSErr err = noErr;
CInfoPBRec cat; CInfoPBRec cat;
wxMacFilename2FSSpec( wxString( dataPtr , *wxConvCurrent ) , &theFlavor.fileSpec ) ; wxMacFilename2FSSpec( wxString( dataPtr, *wxConvCurrent ), &theFlavor.fileSpec ) ;
memset( &cat, 0, sizeof(cat) ); memset( &cat, 0, sizeof(cat) );
cat.hFileInfo.ioNamePtr = theFlavor.fileSpec.name; cat.hFileInfo.ioNamePtr = theFlavor.fileSpec.name;
cat.hFileInfo.ioVRefNum = theFlavor.fileSpec.vRefNum; cat.hFileInfo.ioVRefNum = theFlavor.fileSpec.vRefNum;
cat.hFileInfo.ioDirID = theFlavor.fileSpec.parID; cat.hFileInfo.ioDirID = theFlavor.fileSpec.parID;
cat.hFileInfo.ioFDirIndex = 0; cat.hFileInfo.ioFDirIndex = 0;
err = PBGetCatInfoSync(&cat); err = PBGetCatInfoSync( &cat );
if (err == noErr) if (err == noErr)
{ {
theFlavor.fdFlags = cat.hFileInfo.ioFlFndrInfo.fdFlags; theFlavor.fdFlags = cat.hFileInfo.ioFlFndrInfo.fdFlags;
@@ -388,12 +391,12 @@ wxDragResult wxDropSource::DoDragDrop(int flags)
theFlavor.fileType = cat.hFileInfo.ioFlFndrInfo.fdType; theFlavor.fileType = cat.hFileInfo.ioFlFndrInfo.fdType;
} }
AddDragItemFlavor(theDrag, theItem, type , &theFlavor, sizeof(theFlavor), 0); AddDragItemFlavor( theDrag, theItem, type , &theFlavor, sizeof(theFlavor), 0 );
} }
} }
else else
{ {
AddDragItemFlavor(theDrag, theItem, type , dataPtr, dataSize, 0); AddDragItemFlavor( theDrag, theItem, type , dataPtr, dataSize, 0 );
} }
delete [] dataPtr ; delete [] dataPtr ;
@@ -434,17 +437,17 @@ wxDragResult wxDropSource::DoDragDrop(int flags)
DiffRgn( dragRegion , tempRgn , dragRegion ) ; DiffRgn( dragRegion , tempRgn , dragRegion ) ;
DisposeRgn( tempRgn ) ; DisposeRgn( tempRgn ) ;
// TODO:work with promises in order to return data only when drag // TODO: work with promises in order to return data
// was successfully completed // only when drag was successfully completed
gTrackingGlobals.m_currentSource = this ; gTrackingGlobals.m_currentSource = this;
result = TrackDrag(theDrag, ev , dragRegion); result = TrackDrag( theDrag, ev, dragRegion );
DisposeRgn(dragRegion); DisposeRgn( dragRegion );
DisposeDrag(theDrag); DisposeDrag( theDrag );
gTrackingGlobals.m_currentSource = NULL ; gTrackingGlobals.m_currentSource = NULL;
bool optionDown = GetCurrentKeyModifiers() & optionKey ; bool optionDown = GetCurrentKeyModifiers() & optionKey;
wxDragResult dndresult = wxDragCopy ; wxDragResult dndresult = wxDragCopy;
if ( flags != wxDrag_CopyOnly ) if ( flags != wxDrag_CopyOnly )
// on mac the option key is always the indication for copy // on mac the option key is always the indication for copy
dndresult = optionDown ? wxDragCopy : wxDragMove; dndresult = optionDown ? wxDragCopy : wxDragMove;
@@ -458,7 +461,7 @@ bool wxDropSource::MacInstallDefaultCursor(wxDragResult effect)
bool result = cursor.Ok(); bool result = cursor.Ok();
if ( result ) if ( result )
cursor.MacInstall() ; cursor.MacInstall();
return result; return result;
} }
@@ -470,10 +473,10 @@ bool gTrackingGlobalsInstalled = false ;
pascal OSErr wxMacWindowDragTrackingHandler( pascal OSErr wxMacWindowDragTrackingHandler(
DragTrackingMessage theMessage, WindowPtr theWindow, DragTrackingMessage theMessage, WindowPtr theWindow,
void *handlerRefCon, DragReference theDrag) ; void *handlerRefCon, DragReference theDrag );
pascal OSErr wxMacWindowDragReceiveHandler( pascal OSErr wxMacWindowDragReceiveHandler(
WindowPtr theWindow, void *handlerRefCon, WindowPtr theWindow, void *handlerRefCon,
DragReference theDrag) ; DragReference theDrag );
void wxMacEnsureTrackingHandlersInstalled() void wxMacEnsureTrackingHandlersInstalled()
{ {
@@ -481,24 +484,27 @@ void wxMacEnsureTrackingHandlersInstalled()
{ {
OSErr result; OSErr result;
result = InstallTrackingHandler(NewDragTrackingHandlerUPP(wxMacWindowDragTrackingHandler), 0L,&gTrackingGlobals); result = InstallTrackingHandler( NewDragTrackingHandlerUPP(wxMacWindowDragTrackingHandler), 0L, &gTrackingGlobals );
wxASSERT( result == noErr ) ; wxASSERT( result == noErr );
result = InstallReceiveHandler(NewDragReceiveHandlerUPP(wxMacWindowDragReceiveHandler), 0L, &gTrackingGlobals); result = InstallReceiveHandler( NewDragReceiveHandlerUPP(wxMacWindowDragReceiveHandler), 0L, &gTrackingGlobals );
wxASSERT( result == noErr ) ; wxASSERT( result == noErr );
gTrackingGlobalsInstalled = true ; gTrackingGlobalsInstalled = true;
} }
} }
pascal OSErr wxMacWindowDragTrackingHandler( pascal OSErr wxMacWindowDragTrackingHandler(
DragTrackingMessage theMessage, WindowPtr theWindow, DragTrackingMessage theMessage, WindowPtr theWindow,
void *handlerRefCon, DragReference theDrag) void *handlerRefCon, DragReference theDrag )
{ {
MacTrackingGlobals* trackingGlobals = (MacTrackingGlobals*) handlerRefCon; MacTrackingGlobals* trackingGlobals = (MacTrackingGlobals*) handlerRefCon;
Point mouse, localMouse; Point mouse, localMouse;
DragAttributes attributes; DragAttributes attributes;
GetDragAttributes(theDrag, &attributes);
GetDragAttributes( theDrag, &attributes );
wxTopLevelWindowMac* toplevel = wxFindWinFromMacWindow( theWindow ) ; wxTopLevelWindowMac* toplevel = wxFindWinFromMacWindow( theWindow ) ;
bool optionDown = GetCurrentKeyModifiers() & optionKey ; bool optionDown = GetCurrentKeyModifiers() & optionKey ;
@@ -511,24 +517,28 @@ pascal OSErr wxMacWindowDragTrackingHandler(
break; break;
case kDragTrackingEnterWindow: case kDragTrackingEnterWindow:
trackingGlobals->m_currentTargetWindow = NULL ; if (trackingGlobals != NULL)
trackingGlobals->m_currentTarget = NULL ; {
trackingGlobals->m_currentTargetWindow = NULL ;
trackingGlobals->m_currentTarget = NULL ;
}
break; break;
case kDragTrackingInWindow: case kDragTrackingInWindow:
if (trackingGlobals == NULL)
break;
if (toplevel == NULL) if (toplevel == NULL)
break; break;
GetDragMouse(theDrag, &mouse, 0L); GetDragMouse( theDrag, &mouse, 0L );
localMouse = mouse; localMouse = mouse;
GlobalToLocal(&localMouse); GlobalToLocal( &localMouse );
{ {
wxWindow *win = NULL ; wxWindow *win = NULL ;
ControlPartCode controlPart ; ControlPartCode controlPart ;
ControlRef control = wxMacFindControlUnderMouse( ControlRef control = wxMacFindControlUnderMouse(
toplevel , localMouse , toplevel , localMouse , theWindow , &controlPart ) ;
theWindow , &controlPart ) ;
if ( control ) if ( control )
win = wxFindControlFromMacControl( control ) ; win = wxFindControlFromMacControl( control ) ;
else else
@@ -632,6 +642,9 @@ pascal OSErr wxMacWindowDragTrackingHandler(
break; break;
case kDragTrackingLeaveWindow: case kDragTrackingLeaveWindow:
if (trackingGlobals == NULL)
break;
if (trackingGlobals->m_currentTarget) if (trackingGlobals->m_currentTarget)
{ {
trackingGlobals->m_currentTarget->SetCurrentDrag( theDrag ); trackingGlobals->m_currentTarget->SetCurrentDrag( theDrag );