cleanup - minor restructuring, reformatting

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@38112 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
David Surovell
2006-03-15 19:22:01 +00:00
parent 05fd6a8b82
commit 51d4293d68
2 changed files with 321 additions and 307 deletions

View File

@@ -1,5 +1,5 @@
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
// Name: mac/dataobj.cpp // Name: src/mac/carbon/dataobj.cpp
// Purpose: implementation of wxDataObject class // Purpose: implementation of wxDataObject class
// Author: Stefan Csomor // Author: Stefan Csomor
// Modified by: // Modified by:
@@ -9,14 +9,6 @@
// Licence: wxWindows licence // Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
// ============================================================================
// declarations
// ============================================================================
// ----------------------------------------------------------------------------
// headers
// ----------------------------------------------------------------------------
// For compilers that support precompilation, includes "wx.h". // For compilers that support precompilation, includes "wx.h".
#include "wx/wxprec.h" #include "wx/wxprec.h"
@@ -33,13 +25,11 @@
#include "wx/image.h" #include "wx/image.h"
#include "wx/metafile.h" #include "wx/metafile.h"
#include "wx/mac/private.h" #include "wx/mac/private.h"
#ifndef __DARWIN__ #ifndef __DARWIN__
#include <Scrap.h> #include <Scrap.h>
#endif #endif
// ----------------------------------------------------------------------------
// functions
// ----------------------------------------------------------------------------
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
// wxDataFormat // wxDataFormat
@@ -51,45 +41,56 @@ wxDataFormat::wxDataFormat()
m_format = 0; m_format = 0;
} }
wxDataFormat::wxDataFormat( wxDataFormatId vType ) wxDataFormat::wxDataFormat( wxDataFormatId vType )
{ {
SetType(vType); SetType( vType );
} }
wxDataFormat::wxDataFormat( const wxChar* zId) wxDataFormat::wxDataFormat( const wxChar *zId )
{ {
SetId(zId); SetId( zId );
} }
wxDataFormat::wxDataFormat( const wxString& rId) wxDataFormat::wxDataFormat( const wxString& rId )
{ {
SetId(rId); SetId( rId );
} }
wxDataFormat::wxDataFormat( NativeFormat vFormat) wxDataFormat::wxDataFormat( NativeFormat vFormat )
{ {
SetId(vFormat); SetId( vFormat );
} }
void wxDataFormat::SetType( wxDataFormatId Type ) void wxDataFormat::SetType( wxDataFormatId dataType )
{ {
m_type = Type; m_type = dataType;
if (m_type == wxDF_TEXT ) switch (m_type)
m_format = kScrapFlavorTypeText;
else if (m_type == wxDF_UNICODETEXT )
m_format = kScrapFlavorTypeUnicode ;
else if (m_type == wxDF_BITMAP || m_type == wxDF_METAFILE )
m_format = kScrapFlavorTypePicture;
else if (m_type == wxDF_FILENAME)
m_format = kDragFlavorTypeHFS ;
else
{ {
wxFAIL_MSG( wxT("invalid dataformat") ); case wxDF_TEXT:
m_format = kScrapFlavorTypeText;
break;
// this is '????' but it can't be used in the code because ??' is case wxDF_UNICODETEXT:
// parsed as a trigraph! m_format = kScrapFlavorTypeUnicode;
break;
case wxDF_BITMAP:
case wxDF_METAFILE:
m_format = kScrapFlavorTypePicture;
break;
case wxDF_FILENAME:
m_format = kDragFlavorTypeHFS;
break;
default:
wxFAIL_MSG( wxT("invalid data format") );
// NB: this translates to '????' ASCII but it can't be used in the code
// because '??' will get parsed as a trigraph!
m_format = 0x3f3f3f3f; m_format = 0x3f3f3f3f;
break;
} }
} }
@@ -98,48 +99,54 @@ wxString wxDataFormat::GetId() const
wxCHECK_MSG( !IsStandard(), wxEmptyString , wxCHECK_MSG( !IsStandard(), wxEmptyString ,
wxT("name of predefined format cannot be retrieved") ); wxT("name of predefined format cannot be retrieved") );
return m_id ; return m_id;
} }
void wxDataFormat::SetId( NativeFormat format ) void wxDataFormat::SetId( NativeFormat format )
{ {
m_format = format; m_format = format;
if (m_format == kScrapFlavorTypeText) switch (m_format)
m_type = wxDF_TEXT;
else if (m_format == kScrapFlavorTypeUnicode )
m_type = wxDF_UNICODETEXT;
else if (m_format == kScrapFlavorTypePicture)
m_type = wxDF_BITMAP;
else if (m_format == kDragFlavorTypeHFS )
m_type = wxDF_FILENAME;
else
{ {
case kScrapFlavorTypeText:
m_type = wxDF_TEXT;
break;
case kScrapFlavorTypeUnicode:
m_type = wxDF_UNICODETEXT;
break;
case kScrapFlavorTypePicture:
m_type = wxDF_BITMAP;
break;
case kDragFlavorTypeHFS:
m_type = wxDF_FILENAME;
break;
default:
m_type = wxDF_PRIVATE; m_type = wxDF_PRIVATE;
char text[5] ; char text[5];
strncpy( text , (char*) &format , 4 ) ; strncpy( text, (char*)&format, 4 );
text[4] = 0 ; text[4] = 0;
m_id = wxString::FromAscii( text ) ; m_id = wxString::FromAscii( text );
break;
} }
} }
void wxDataFormat::SetId( const wxChar* zId ) void wxDataFormat::SetId( const wxChar* zId )
{ {
m_type = wxDF_PRIVATE; m_type = wxDF_PRIVATE;
m_id = zId ; m_id = zId;
m_format = 'WXPR' ; m_format = 'WXPR';
} }
bool wxDataFormat::operator==(const wxDataFormat& format) const bool wxDataFormat::operator==(const wxDataFormat& format) const
{ {
if ( IsStandard() || format.IsStandard() ) if (IsStandard() || format.IsStandard())
{ return (format.m_type == m_type);
return ( format.m_type == m_type ) ;
}
else else
{ return (m_id == format.m_id);
return ( m_id == format.m_id ) ;
}
} }
//------------------------------------------------------------------------- //-------------------------------------------------------------------------
@@ -150,37 +157,33 @@ wxDataObject::wxDataObject()
{ {
} }
bool wxDataObject::IsSupportedFormat( bool wxDataObject::IsSupportedFormat( const wxDataFormat& rFormat, Direction vDir ) const
const wxDataFormat& rFormat
, Direction vDir
) const
{ {
size_t nFormatCount = GetFormatCount(vDir); size_t nFormatCount = GetFormatCount( vDir );
bool found = false;
if (nFormatCount == 1) if (nFormatCount == 1)
{ {
return rFormat == GetPreferredFormat(); found = (rFormat == GetPreferredFormat());
} }
else else
{ {
wxDataFormat* pFormats = new wxDataFormat[nFormatCount]; wxDataFormat* pFormats = new wxDataFormat[nFormatCount];
GetAllFormats( pFormats GetAllFormats( pFormats, vDir );
,vDir
);
size_t n; for (size_t n = 0; n < nFormatCount; n++)
for (n = 0; n < nFormatCount; n++)
{ {
if (pFormats[n] == rFormat) if (pFormats[n] == rFormat)
{
found = true;
break; break;
}
} }
delete [] pFormats; delete [] pFormats;
// found?
return n < nFormatCount;
} }
return found;
} }
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
@@ -188,23 +191,23 @@ bool wxDataObject::IsSupportedFormat(
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
#if wxUSE_UNICODE #if wxUSE_UNICODE
void wxTextDataObject::GetAllFormats(wxDataFormat *formats, wxDataObjectBase::Direction dir) const void wxTextDataObject::GetAllFormats( wxDataFormat *formats, wxDataObjectBase::Direction dir ) const
{ {
*formats++ = wxDataFormat( wxDF_TEXT ); *formats++ = wxDataFormat( wxDF_TEXT );
*formats = wxDataFormat( wxDF_UNICODETEXT ); *formats = wxDataFormat( wxDF_UNICODETEXT );
} }
#endif #endif
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
// wxFileDataObject // wxFileDataObject
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
bool wxFileDataObject::GetDataHere( bool wxFileDataObject::GetDataHere( void *pBuf ) const
void* pBuf
) const
{ {
wxString sFilenames; if (pBuf == NULL)
return false;
wxString sFilenames;
for (size_t i = 0; i < m_filenames.GetCount(); i++) for (size_t i = 0; i < m_filenames.GetCount(); i++)
{ {
@@ -212,8 +215,9 @@ bool wxFileDataObject::GetDataHere(
sFilenames += (wxChar)0; sFilenames += (wxChar)0;
} }
memcpy(pBuf, sFilenames.mbc_str(), sFilenames.Len() + 1); memcpy( pBuf, sFilenames.mbc_str(), sFilenames.Len() + 1 );
return TRUE;
return true;
} }
size_t wxFileDataObject::GetDataSize() const size_t wxFileDataObject::GetDataSize() const
@@ -229,26 +233,21 @@ size_t wxFileDataObject::GetDataSize() const
return nRes + 1; return nRes + 1;
} }
bool wxFileDataObject::SetData( bool wxFileDataObject::SetData( size_t WXUNUSED(nSize), const void *pBuf )
size_t WXUNUSED(nSize)
, const void* pBuf
)
{ {
m_filenames.Empty(); m_filenames.Empty();
// only add if this is not an empty string // only add if this is not an empty string
// we can therefore clear the list by just setting an empty string // we can therefore clear the list by just setting an empty string
if ( (*(char*)pBuf) != 0 ) if ((*(const char*)pBuf) != 0)
AddFile(wxString::FromAscii((char*)pBuf)); AddFile( wxString::FromAscii( (char*)pBuf) );
return TRUE; return true;
} }
void wxFileDataObject::AddFile( void wxFileDataObject::AddFile( const wxString& rFilename )
const wxString& rFilename
)
{ {
m_filenames.Add(rFilename); m_filenames.Add( rFilename );
} }
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
@@ -260,16 +259,15 @@ wxBitmapDataObject::wxBitmapDataObject()
Init(); Init();
} }
wxBitmapDataObject::wxBitmapDataObject( wxBitmapDataObject::wxBitmapDataObject( const wxBitmap& rBitmap )
const wxBitmap& rBitmap : wxBitmapDataObjectBase( rBitmap )
)
: wxBitmapDataObjectBase(rBitmap)
{ {
Init(); Init();
if ( m_bitmap.Ok() )
if (m_bitmap.Ok())
{ {
m_pictHandle = m_bitmap.GetBitmapData()->GetPictHandle() ; m_pictHandle = m_bitmap.GetBitmapData()->GetPictHandle();
m_pictCreated = false ; m_pictCreated = false;
} }
} }
@@ -278,72 +276,81 @@ wxBitmapDataObject::~wxBitmapDataObject()
Clear(); Clear();
} }
void wxBitmapDataObject::SetBitmap( void wxBitmapDataObject::SetBitmap( const wxBitmap& rBitmap )
const wxBitmap& rBitmap
)
{ {
Clear(); Clear();
wxBitmapDataObjectBase::SetBitmap(rBitmap); wxBitmapDataObjectBase::SetBitmap( rBitmap );
if ( m_bitmap.Ok() ) if (m_bitmap.Ok())
{ {
m_pictHandle = m_bitmap.GetBitmapData()->GetPictHandle() ; m_pictHandle = m_bitmap.GetBitmapData()->GetPictHandle();
m_pictCreated = false ; m_pictCreated = false;
} }
} }
void wxBitmapDataObject::Init() void wxBitmapDataObject::Init()
{ {
m_pictHandle = NULL ; m_pictHandle = NULL;
m_pictCreated = false ; m_pictCreated = false;
} }
void wxBitmapDataObject::Clear() void wxBitmapDataObject::Clear()
{ {
if ( m_pictCreated && m_pictHandle ) if (m_pictHandle != NULL)
{ {
KillPicture( (PicHandle) m_pictHandle ) ; if (m_pictCreated)
KillPicture( (PicHandle)m_pictHandle );
m_pictHandle = NULL;
} }
m_pictHandle = NULL ;
m_pictCreated = false;
} }
bool wxBitmapDataObject::GetDataHere( bool wxBitmapDataObject::GetDataHere( void *pBuf ) const
void* pBuf
) const
{ {
if (!m_pictHandle) if (m_pictHandle == NULL)
{ {
wxFAIL_MSG(wxT("attempt to copy empty bitmap failed")); wxFAIL_MSG( wxT("attempt to copy empty bitmap failed") );
return FALSE; return false;
} }
memcpy(pBuf, *(Handle)m_pictHandle, GetHandleSize((Handle)m_pictHandle));
return TRUE; if (pBuf == NULL)
return false;
memcpy( pBuf, *(Handle)m_pictHandle, GetHandleSize( (Handle)m_pictHandle ) );
return true;
} }
size_t wxBitmapDataObject::GetDataSize() const size_t wxBitmapDataObject::GetDataSize() const
{ {
return GetHandleSize((Handle)m_pictHandle) ; if (m_pictHandle != NULL)
return GetHandleSize( (Handle)m_pictHandle );
else
return 0;
} }
bool wxBitmapDataObject::SetData( bool wxBitmapDataObject::SetData( size_t nSize, const void *pBuf )
size_t nSize
, const void* pBuf
)
{ {
Clear(); Clear();
PicHandle picHandle = (PicHandle) NewHandle( nSize ) ;
memcpy( *picHandle , pBuf , nSize ) ;
m_pictHandle = picHandle ;
// ownership is transferred to the bitmap
m_pictCreated = false ;
Rect frame = (**picHandle).picFrame ;
wxMetafile mf ; if ((pBuf == NULL) || (nSize == 0))
mf.SetHMETAFILE( (WXHMETAFILE) m_pictHandle ) ; return false;
wxMemoryDC mdc ;
m_bitmap.Create( frame.right - frame.left ,frame.bottom - frame.top ) ; PicHandle picHandle = (PicHandle)NewHandle( nSize );
mdc.SelectObject(m_bitmap ) ; memcpy( *picHandle, pBuf, nSize );
mf.Play( &mdc ) ; m_pictHandle = picHandle;
mdc.SelectObject( wxNullBitmap ) ;
// ownership is transferred to the bitmap
m_pictCreated = false;
Rect frame = (**picHandle).picFrame;
wxMetafile mf;
mf.SetHMETAFILE( (WXHMETAFILE)m_pictHandle );
wxMemoryDC mdc;
m_bitmap.Create( frame.right - frame.left, frame.bottom - frame.top );
mdc.SelectObject( m_bitmap );
mf.Play( &mdc );
mdc.SelectObject( wxNullBitmap );
return m_bitmap.Ok(); return m_bitmap.Ok();
} }

View File

@@ -31,15 +31,15 @@
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();
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
// wxDropTarget // wxDropTarget
@@ -48,12 +48,12 @@ void wxMacEnsureTrackingHandlersInstalled() ;
wxDropTarget::wxDropTarget( wxDataObject *data ) wxDropTarget::wxDropTarget( wxDataObject *data )
: wxDropTargetBase( data ) : wxDropTargetBase( data )
{ {
wxMacEnsureTrackingHandlersInstalled() ; wxMacEnsureTrackingHandlersInstalled();
} }
wxDragResult wxDropTarget::OnDragOver( wxCoord WXUNUSED(x), wxDragResult wxDropTarget::OnDragOver(
wxCoord WXUNUSED(y), wxCoord WXUNUSED(x), wxCoord WXUNUSED(y),
wxDragResult def ) wxDragResult def )
{ {
return CurrentDragHasSupportedFormat() ? def : wxDragNone; return CurrentDragHasSupportedFormat() ? def : wxDragNone;
} }
@@ -63,11 +63,12 @@ bool wxDropTarget::OnDrop( wxCoord WXUNUSED(x), wxCoord WXUNUSED(y) )
if (m_dataObject == NULL) if (m_dataObject == NULL)
return false; return false;
return CurrentDragHasSupportedFormat() ; return CurrentDragHasSupportedFormat();
} }
wxDragResult wxDropTarget::OnData( wxCoord WXUNUSED(x), wxCoord WXUNUSED(y), wxDragResult wxDropTarget::OnData(
wxDragResult def ) wxCoord WXUNUSED(x), wxCoord WXUNUSED(y),
wxDragResult def )
{ {
if (m_dataObject == NULL) if (m_dataObject == NULL)
return wxDragNone; return wxDragNone;
@@ -80,59 +81,59 @@ wxDragResult wxDropTarget::OnData( wxCoord WXUNUSED(x), wxCoord WXUNUSED(y),
bool wxDropTarget::CurrentDragHasSupportedFormat() bool wxDropTarget::CurrentDragHasSupportedFormat()
{ {
bool supported = false ; bool supported = false;
if ( gTrackingGlobals.m_currentSource != NULL ) if ( gTrackingGlobals.m_currentSource != NULL )
{ {
wxDataObject* data = gTrackingGlobals.m_currentSource->GetDataObject() ; wxDataObject* data = gTrackingGlobals.m_currentSource->GetDataObject();
if ( data ) if ( data )
{ {
size_t formatcount = data->GetFormatCount() ; size_t formatcount = data->GetFormatCount();
wxDataFormat *array = new wxDataFormat[formatcount]; wxDataFormat *array = new wxDataFormat[formatcount];
data->GetAllFormats( array ); data->GetAllFormats( array );
for (size_t i = 0; !supported && i < formatcount ; i++) for (size_t i = 0; !supported && i < formatcount; i++)
{ {
wxDataFormat format = array[i] ; wxDataFormat format = array[i];
if ( m_dataObject->IsSupported( format ) ) if ( m_dataObject->IsSupported( format ) )
{ {
supported = true ; supported = true;
break ; break;
} }
} }
delete [] array ; delete [] array;
} }
} }
if ( !supported ) if ( !supported )
{ {
UInt16 items ; UInt16 items;
OSErr result; OSErr result;
ItemReference theItem; ItemReference theItem;
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;
GetDragItemReferenceNumber( (DragReference)m_currentDrag, index, &theItem ); GetDragItemReferenceNumber( (DragReference)m_currentDrag, index, &theItem );
CountDragItemFlavors( (DragReference)m_currentDrag, theItem, &flavors ); CountDragItemFlavors( (DragReference)m_currentDrag, theItem, &flavors );
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 );
if ( m_dataObject->IsSupportedFormat( wxDataFormat( theType ) ) ) if ( m_dataObject->IsSupportedFormat( wxDataFormat( theType ) ) )
{ {
supported = true ; supported = true;
break ; break;
} }
} }
} }
} }
return supported ; return supported;
} }
bool wxDropTarget::GetData() bool wxDropTarget::GetData()
@@ -181,60 +182,60 @@ bool wxDropTarget::GetData()
if ( !transferred ) if ( !transferred )
{ {
UInt16 items ; UInt16 items;
OSErr result; OSErr result;
ItemReference theItem; ItemReference theItem;
FlavorType theType ; FlavorType theType;
FlavorFlags theFlags; FlavorFlags theFlags;
UInt16 flavors ; UInt16 flavors;
bool firstFileAdded = false ; bool firstFileAdded = false;
CountDragItems( (DragReference)m_currentDrag, &items ); CountDragItems( (DragReference)m_currentDrag, &items );
for (UInt16 index = 1; index <= items; ++index) for (UInt16 index = 1; index <= items; ++index)
{ {
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 ); wxDataFormat preferredFormat = m_dataObject->GetPreferredFormat( wxDataObject::Set );
bool hasPreferredFormat = false ; bool hasPreferredFormat = false;
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 ( preferredFormat == format ) if ( preferredFormat == format )
{ {
hasPreferredFormat = true ; hasPreferredFormat = true;
break ; break;
} }
} }
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 )))
{ {
result = GetFlavorFlags( (DragReference)m_currentDrag, theItem, theType, &theFlags ); result = GetFlavorFlags( (DragReference)m_currentDrag, theItem, theType, &theFlags );
if (result == noErr) if (result == noErr)
{ {
Size dataSize ; Size dataSize;
Ptr theData ; Ptr theData;
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: // this increment is only valid for allocating:
// on the next GetFlavorData 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: // this increment is only valid for allocating:
// on the next GetFlavorData 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++;
} }
if (dataSize > 0) if (dataSize > 0)
@@ -243,54 +244,58 @@ bool wxDropTarget::GetData()
theData = NULL; theData = NULL;
GetFlavorData( (DragReference)m_currentDrag, theItem, theType, (void*) theData, &dataSize, 0L ); GetFlavorData( (DragReference)m_currentDrag, theItem, theType, (void*) theData, &dataSize, 0L );
if ( theType == kScrapFlavorTypeText ) switch (theType)
{ {
theData[dataSize] = 0 ; case kScrapFlavorTypeText:
m_dataObject->SetData( wxDataFormat(wxDF_TEXT), dataSize , theData ); theData[dataSize] = 0;
} m_dataObject->SetData( wxDataFormat(wxDF_TEXT), dataSize, theData );
break;
#if wxUSE_UNICODE #if wxUSE_UNICODE
else if ( theType == kScrapFlavorTypeUnicode ) case kScrapFlavorTypeUnicode:
{
theData[dataSize + 0] = theData[dataSize + 0] =
theData[dataSize + 1] = 0 ; theData[dataSize + 1] = 0;
m_dataObject->SetData( wxDataFormat(wxDF_UNICODETEXT), dataSize , theData ); m_dataObject->SetData( wxDataFormat(wxDF_UNICODETEXT), dataSize, theData );
} break;
#endif #endif
else if ( theType == kDragFlavorTypeHFS )
{
wxFileDataObject *fdo = dynamic_cast<wxFileDataObject*>(m_dataObject);
wxASSERT( fdo != NULL );
if ((theData != NULL) && (fdo != NULL)) case kDragFlavorTypeHFS:
{ {
HFSFlavor* theFile = (HFSFlavor*) theData ; wxFileDataObject *fdo = dynamic_cast<wxFileDataObject*>(m_dataObject);
wxString name = wxMacFSSpec2MacFilename( &theFile->fileSpec ) ; wxASSERT( fdo != NULL );
if ( !firstFileAdded ) if ((theData != NULL) && (fdo != NULL))
{ {
// reset file list HFSFlavor* theFile = (HFSFlavor*) theData;
fdo->SetData( 0 , "" ) ; wxString name = wxMacFSSpec2MacFilename( &theFile->fileSpec );
firstFileAdded = true ;
}
if (!name.IsEmpty()) if ( !firstFileAdded )
fdo->AddFile( name ) ; {
// reset file list
fdo->SetData( 0, "" );
firstFileAdded = true;
}
if (!name.IsEmpty())
fdo->AddFile( name );
}
} }
} break;
else
{ default:
m_dataObject->SetData( format, dataSize, theData ); m_dataObject->SetData( format, dataSize, theData );
break;
} }
delete [] theData; delete [] theData;
} }
break ; break;
} }
} }
} }
} }
return true ; return true;
} }
//------------------------------------------------------------------------- //-------------------------------------------------------------------------
@@ -306,7 +311,7 @@ wxDropSource::wxDropSource(wxWindow *win,
const wxCursor &cursorStop) const wxCursor &cursorStop)
: wxDropSourceBase(cursorCopy, cursorMove, cursorStop) : wxDropSourceBase(cursorCopy, cursorMove, cursorStop)
{ {
wxMacEnsureTrackingHandlersInstalled() ; wxMacEnsureTrackingHandlersInstalled();
m_window = win; m_window = win;
} }
@@ -318,7 +323,7 @@ wxDropSource::wxDropSource(wxDataObject& data,
const wxCursor &cursorStop) const wxCursor &cursorStop)
: wxDropSourceBase(cursorCopy, cursorMove, cursorStop) : wxDropSourceBase(cursorCopy, cursorMove, cursorStop)
{ {
wxMacEnsureTrackingHandlersInstalled() ; wxMacEnsureTrackingHandlersInstalled();
SetData( data ); SetData( data );
m_window = win; m_window = win;
@@ -341,41 +346,41 @@ wxDragResult wxDropSource::DoDragDrop(int flags)
DragReference theDrag; DragReference theDrag;
RgnHandle dragRegion; RgnHandle dragRegion;
if ((result = NewDrag(&theDrag)) != noErr) if ((result = NewDrag(&theDrag)) != noErr)
return wxDragNone ; return wxDragNone;
// add data to drag // add data to drag
size_t formatCount = m_data->GetFormatCount() ; size_t formatCount = m_data->GetFormatCount();
wxDataFormat *formats = new wxDataFormat[formatCount] ; wxDataFormat *formats = new wxDataFormat[formatCount];
m_data->GetAllFormats( formats ) ; m_data->GetAllFormats( formats );
ItemReference theItem = 1 ; ItemReference theItem = 1;
for ( size_t i = 0 ; i < formatCount ; ++i ) for ( size_t i = 0; i < formatCount; ++i )
{ {
size_t dataSize = m_data->GetDataSize( formats[i] ) ; size_t dataSize = m_data->GetDataSize( formats[i] );
Ptr dataPtr = new char[dataSize] ; Ptr dataPtr = new char[dataSize];
m_data->GetDataHere( formats[i] , dataPtr ) ; m_data->GetDataHere( formats[i], dataPtr );
OSType type = formats[i].GetFormatId() ; OSType type = formats[i].GetFormatId();
if ( type == 'TEXT' || type == 'utxt' ) if ( type == 'TEXT' || type == 'utxt' )
{ {
if ( dataSize > 0 ) if ( dataSize > 0 )
dataSize-- ; dataSize--;
dataPtr[ dataSize ] = 0 ; dataPtr[ dataSize ] = 0;
if ( type == 'utxt' ) if ( type == 'utxt' )
{ {
if ( dataSize > 0 ) if ( dataSize > 0 )
dataSize-- ; dataSize--;
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 )
{ {
HFSFlavor theFlavor ; HFSFlavor theFlavor;
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;
@@ -402,51 +407,53 @@ 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;
} }
delete [] formats ; delete [] formats;
dragRegion = NewRgn(); dragRegion = NewRgn();
RgnHandle tempRgn = NewRgn() ; RgnHandle tempRgn = NewRgn();
EventRecord* ev = NULL ; EventRecord* ev = NULL;
#if !TARGET_CARBON // TODO #if !TARGET_CARBON // TODO
ev = (EventRecord*) wxTheApp->MacGetCurrentEvent() ; ev = (EventRecord*) wxTheApp->MacGetCurrentEvent();
#else #else
{ {
EventRecord rec ; EventRecord rec;
ev = &rec ; ev = &rec;
wxMacConvertEventToRecord( (EventRef) wxTheApp->MacGetCurrentEvent() , &rec ) ; wxMacConvertEventToRecord( (EventRef) wxTheApp->MacGetCurrentEvent(), &rec );
} }
#endif #endif
const short dragRegionOuterBoundary = 10 ; const short dragRegionOuterBoundary = 10;
const short dragRegionInnerBoundary = 9 ; const short dragRegionInnerBoundary = 9;
SetRectRgn( SetRectRgn(
dragRegion , ev->where.h - dragRegionOuterBoundary , dragRegion,
ev->where.v - dragRegionOuterBoundary , ev->where.h - dragRegionOuterBoundary,
ev->where.h + dragRegionOuterBoundary , ev->where.v - dragRegionOuterBoundary,
ev->where.v + dragRegionOuterBoundary ) ; ev->where.h + dragRegionOuterBoundary,
ev->where.v + dragRegionOuterBoundary );
SetRectRgn( SetRectRgn(
tempRgn , ev->where.h - dragRegionInnerBoundary , tempRgn,
ev->where.v - dragRegionInnerBoundary , ev->where.h - dragRegionInnerBoundary,
ev->where.h + dragRegionInnerBoundary , ev->where.v - dragRegionInnerBoundary,
ev->where.v + dragRegionInnerBoundary ) ; ev->where.h + dragRegionInnerBoundary,
ev->where.v + dragRegionInnerBoundary );
DiffRgn( dragRegion , tempRgn , dragRegion ) ; DiffRgn( dragRegion, tempRgn, dragRegion );
DisposeRgn( tempRgn ) ; DisposeRgn( tempRgn );
// TODO: work with promises in order to return data // TODO: work with promises in order to return data
// only when drag was successfully completed // only when drag was successfully completed
@@ -477,7 +484,7 @@ bool wxDropSource::MacInstallDefaultCursor(wxDragResult effect)
return result; return result;
} }
bool gTrackingGlobalsInstalled = false ; bool gTrackingGlobalsInstalled = false;
// passing the globals via refcon is not needed by the CFM and later architectures anymore // passing the globals via refcon is not needed by the CFM and later architectures anymore
// but I'll leave it in there, just in case... // but I'll leave it in there, just in case...
@@ -516,9 +523,9 @@ pascal OSErr wxMacWindowDragTrackingHandler(
GetDragAttributes( theDrag, &attributes ); GetDragAttributes( theDrag, &attributes );
wxTopLevelWindowMac* toplevel = wxFindWinFromMacWindow( theWindow ) ; wxTopLevelWindowMac* toplevel = wxFindWinFromMacWindow( theWindow );
bool optionDown = GetCurrentKeyModifiers() & optionKey ; bool optionDown = GetCurrentKeyModifiers() & optionKey;
wxDragResult result = optionDown ? wxDragCopy : wxDragMove; wxDragResult result = optionDown ? wxDragCopy : wxDragMove;
switch (theMessage) switch (theMessage)
@@ -530,8 +537,8 @@ pascal OSErr wxMacWindowDragTrackingHandler(
case kDragTrackingEnterWindow: case kDragTrackingEnterWindow:
if (trackingGlobals != NULL) if (trackingGlobals != NULL)
{ {
trackingGlobals->m_currentTargetWindow = NULL ; trackingGlobals->m_currentTargetWindow = NULL;
trackingGlobals->m_currentTarget = NULL ; trackingGlobals->m_currentTarget = NULL;
} }
break; break;
@@ -546,21 +553,21 @@ pascal OSErr wxMacWindowDragTrackingHandler(
GlobalToLocal( &localMouse ); GlobalToLocal( &localMouse );
{ {
wxWindow *win = NULL ; wxWindow *win = NULL;
ControlPartCode controlPart ; ControlPartCode controlPart;
ControlRef control = wxMacFindControlUnderMouse( ControlRef control = wxMacFindControlUnderMouse(
toplevel , localMouse , theWindow , &controlPart ) ; toplevel, localMouse, theWindow, &controlPart );
if ( control ) if ( control )
win = wxFindControlFromMacControl( control ) ; win = wxFindControlFromMacControl( control );
else else
win = toplevel ; win = toplevel;
int localx , localy ; int localx, localy;
localx = localMouse.h ; localx = localMouse.h;
localy = localMouse.v ; localy = localMouse.v;
if ( win ) if ( win )
win->MacRootWindowToWindow( &localx , &localy ) ; win->MacRootWindowToWindow( &localx, &localy );
if ( win != trackingGlobals->m_currentTargetWindow ) if ( win != trackingGlobals->m_currentTargetWindow )
{ {
if ( trackingGlobals->m_currentTargetWindow ) if ( trackingGlobals->m_currentTargetWindow )
@@ -579,26 +586,26 @@ pascal OSErr wxMacWindowDragTrackingHandler(
if ( win ) if ( win )
{ {
// this window is entered // this window is entered
trackingGlobals->m_currentTargetWindow = win ; trackingGlobals->m_currentTargetWindow = win;
trackingGlobals->m_currentTarget = win->GetDropTarget() ; trackingGlobals->m_currentTarget = win->GetDropTarget();
{ {
if ( trackingGlobals->m_currentTarget ) if ( trackingGlobals->m_currentTarget )
{ {
trackingGlobals->m_currentTarget->SetCurrentDrag( theDrag ) ; trackingGlobals->m_currentTarget->SetCurrentDrag( theDrag );
result = trackingGlobals->m_currentTarget->OnEnter( localx , localy , result ) ; result = trackingGlobals->m_currentTarget->OnEnter( localx, localy, result );
} }
if ( result != wxDragNone ) if ( result != wxDragNone )
{ {
int x , y ; int x, y;
x = y = 0 ; x = y = 0;
win->MacWindowToRootWindow( &x , &y ) ; win->MacWindowToRootWindow( &x, &y );
RgnHandle hiliteRgn = NewRgn() ; RgnHandle hiliteRgn = NewRgn();
Rect r = { y , x , y + win->GetSize().y , x + win->GetSize().x } ; Rect r = { y, x, y + win->GetSize().y, x + win->GetSize().x };
RectRgn( hiliteRgn , &r ) ; RectRgn( hiliteRgn, &r );
ShowDragHilite( theDrag, hiliteRgn, true ); ShowDragHilite( theDrag, hiliteRgn, true );
DisposeRgn( hiliteRgn ) ; DisposeRgn( hiliteRgn );
} }
} }
} }
@@ -607,8 +614,8 @@ pascal OSErr wxMacWindowDragTrackingHandler(
{ {
if ( trackingGlobals->m_currentTarget ) if ( trackingGlobals->m_currentTarget )
{ {
trackingGlobals->m_currentTarget->SetCurrentDrag( theDrag ) ; trackingGlobals->m_currentTarget->SetCurrentDrag( theDrag );
trackingGlobals->m_currentTarget->OnDragOver( localx , localy , result ) ; trackingGlobals->m_currentTarget->OnDragOver( localx, localy, result );
} }
} }
@@ -621,24 +628,24 @@ pascal OSErr wxMacWindowDragTrackingHandler(
{ {
case wxDragCopy: case wxDragCopy:
{ {
wxCursor cursor(wxCURSOR_COPY_ARROW) ; wxCursor cursor(wxCURSOR_COPY_ARROW);
cursor.MacInstall() ; cursor.MacInstall();
} }
break ; break;
case wxDragMove: case wxDragMove:
{ {
wxCursor cursor(wxCURSOR_ARROW) ; wxCursor cursor(wxCURSOR_ARROW);
cursor.MacInstall() ; cursor.MacInstall();
} }
break ; break;
case wxDragNone: case wxDragNone:
{ {
wxCursor cursor(wxCURSOR_NO_ENTRY) ; wxCursor cursor(wxCURSOR_NO_ENTRY);
cursor.MacInstall() ; cursor.MacInstall();
} }
break ; break;
case wxDragError: case wxDragError:
case wxDragLink: case wxDragLink:
@@ -681,24 +688,24 @@ pascal OSErr wxMacWindowDragReceiveHandler(
MacTrackingGlobals* trackingGlobals = (MacTrackingGlobals*)handlerRefCon; MacTrackingGlobals* trackingGlobals = (MacTrackingGlobals*)handlerRefCon;
if ( trackingGlobals->m_currentTarget ) if ( trackingGlobals->m_currentTarget )
{ {
Point mouse, localMouse ; Point mouse, localMouse;
int localx, localy ; int localx, localy;
trackingGlobals->m_currentTarget->SetCurrentDrag( theDrag ) ; trackingGlobals->m_currentTarget->SetCurrentDrag( theDrag );
GetDragMouse(theDrag, &mouse, 0L); GetDragMouse( theDrag, &mouse, 0L );
localMouse = mouse; localMouse = mouse;
GlobalToLocal(&localMouse); GlobalToLocal( &localMouse );
localx = localMouse.h ; localx = localMouse.h;
localy = localMouse.v ; localy = localMouse.v;
// TODO : should we use client coordinates? // TODO : should we use client coordinates?
if ( trackingGlobals->m_currentTargetWindow ) if ( trackingGlobals->m_currentTargetWindow )
trackingGlobals->m_currentTargetWindow->MacRootWindowToWindow( &localx , &localy ) ; trackingGlobals->m_currentTargetWindow->MacRootWindowToWindow( &localx, &localy );
if ( trackingGlobals->m_currentTarget->OnDrop( localx , localy ) ) if ( trackingGlobals->m_currentTarget->OnDrop( localx, localy ) )
{ {
bool optionDown = GetCurrentKeyModifiers() & optionKey ; bool optionDown = GetCurrentKeyModifiers() & optionKey;
wxDragResult result = optionDown ? wxDragCopy : wxDragMove; wxDragResult result = optionDown ? wxDragCopy : wxDragMove;
trackingGlobals->m_currentTarget->OnData( localx , localy , result ) ; trackingGlobals->m_currentTarget->OnData( localx, localy, result );
} }
} }